File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ static pthread_mutex_t vmmngr_mutex = PTHREAD_MUTEX_INITIALIZER;
50
50
struct vmmngr_list_struct vmmngr_head ;
51
51
static unsigned long update_count = 0 ;
52
52
53
- struct vmmngr_struct * vmmngr_find (char * name )
53
+ struct vmmngr_struct * vmmngr_find (const char * name )
54
54
{
55
55
struct vmmngr_struct * s ;
56
56
Original file line number Diff line number Diff line change 38
38
#define RESUME_DESC "Resume virtual machine from suspend state"
39
39
#define RESET_DESC "Stop and then start virtual machine VM_NAME"
40
40
41
+ #define STOP_TIMEOUT 10U
42
+
41
43
struct acrnctl_cmd {
42
44
const char * cmd ;
43
45
const char desc [128 ]; /* Description of the cmd */
@@ -492,6 +494,25 @@ static int acrnctl_do_resume(int argc, char *argv[])
492
494
return 0 ;
493
495
}
494
496
497
+ static int wait_vm_stop (const char * vmname , unsigned int timeout )
498
+ {
499
+ unsigned long t = timeout ;
500
+ struct vmmngr_struct * s ;
501
+
502
+ do {
503
+ /* list and update the vm status */
504
+ vmmngr_update ();
505
+
506
+ s = vmmngr_find (vmname );
507
+ if (s -> state == VM_CREATED )
508
+ return 0 ;
509
+
510
+ sleep (1 );
511
+ } while (t -- );
512
+
513
+ return -1 ;
514
+ }
515
+
495
516
static int acrnctl_do_reset (int argc , char * argv [])
496
517
{
497
518
struct vmmngr_struct * s ;
@@ -511,6 +532,11 @@ static int acrnctl_do_reset(int argc, char *argv[])
511
532
case VM_STARTED :
512
533
case VM_PAUSED :
513
534
stop_vm (argv [i ]);
535
+ if (wait_vm_stop (argv [i ], STOP_TIMEOUT )) {
536
+ printf ("Failed to stop %s in %u sec\n" ,
537
+ argv [i ], STOP_TIMEOUT );
538
+ break ;
539
+ }
514
540
start_vm (argv [i ]);
515
541
break ;
516
542
default :
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ extern const char *state_str[];
28
28
*
29
29
* @return vmmngr_struct * if find, NULL not find
30
30
*/
31
- struct vmmngr_struct * vmmngr_find (char * vmname );
31
+ struct vmmngr_struct * vmmngr_find (const char * vmname );
32
32
33
33
/* Per-vm vm managerment struct */
34
34
struct vmmngr_struct {
You can’t perform that action at this time.
0 commit comments