@@ -418,21 +418,15 @@ static int acrnctl_do_add(int argc, char *argv[])
418
418
static int acrnctl_do_stop (int argc , char * argv [])
419
419
{
420
420
struct vmmngr_struct * s ;
421
- int i ;
422
421
423
- for (i = 1 ; i < argc ; i ++ ) {
424
- s = vmmngr_find (argv [i ]);
425
- if (!s ) {
426
- printf ("can't find %s\n" , argv [i ]);
427
- continue ;
428
- }
429
- if (s -> state == VM_CREATED ) {
430
- printf ("%s is already (%s)\n" , argv [i ],
431
- state_str [s -> state ]);
432
- continue ;
433
- }
434
- stop_vm (argv [i ]);
422
+ s = vmmngr_find (argv [1 ]);
423
+ if (!s ) {
424
+ printf ("can't find %s\n" , argv [1 ]);
425
+ }
426
+ if (s -> state == VM_CREATED ) {
427
+ printf ("%s is already (%s)\n" , argv [1 ],state_str [s -> state ]);
435
428
}
429
+ stop_vm (argv [1 ]);
436
430
437
431
return 0 ;
438
432
}
@@ -487,36 +481,28 @@ static inline int del_runC(char *argv)
487
481
static int acrnctl_do_del (int argc , char * argv [])
488
482
{
489
483
struct vmmngr_struct * s ;
490
- int i ;
491
484
char cmd [PATH_LEN ];
492
485
493
- for (i = 1 ; i < argc ; i ++ ) {
494
- s = vmmngr_find (argv [i ]);
495
- if (!s ) {
496
- printf ("can't find %s\n" , argv [i ]);
497
- continue ;
498
- }
499
- if (s -> state != VM_CREATED ) {
500
- printf ("can't delete %s(%s)\n" , argv [i ],
501
- state_str [s -> state ]);
502
- continue ;
503
- }
504
- if (snprintf (cmd , sizeof (cmd ), "rm -f %s/%s.sh" ,
505
- ACRN_CONF_PATH_ADD , argv [i ]) >= sizeof (cmd )) {
506
- printf ("WARN: cmd is truncated\n" );
507
- return -1 ;
508
- }
509
- system (cmd );
510
- if (snprintf (cmd , sizeof (cmd ), "rm -f %s/%s.args" ,
511
- ACRN_CONF_PATH_ADD , argv [i ]) >= sizeof (cmd )) {
512
- printf ("WARN: cmd is truncated\n" );
513
- return -1 ;
514
- }
515
- system (cmd );
516
- if (del_runC (argv [i ]) < 0 ) {
517
- printf ("ERROR: del runC failed!\n" );
518
- return -1 ;
519
- }
486
+ s = vmmngr_find (argv [1 ]);
487
+ if (!s ) {
488
+ printf ("can't find %s\n" , argv [1 ]);
489
+ }
490
+ if (s -> state != VM_CREATED ) {
491
+ printf ("can't delete %s(%s)\n" , argv [1 ],state_str [s -> state ]);
492
+ }
493
+ if (snprintf (cmd , sizeof (cmd ), "rm -f %s/%s.sh" ,ACRN_CONF_PATH_ADD , argv [1 ]) >= sizeof (cmd )) {
494
+ printf ("WARN: cmd is truncated\n" );
495
+ return -1 ;
496
+ }
497
+ system (cmd );
498
+ if (snprintf (cmd , sizeof (cmd ), "rm -f %s/%s.args" ,ACRN_CONF_PATH_ADD , argv [1 ]) >= sizeof (cmd )) {
499
+ printf ("WARN: cmd is truncated\n" );
500
+ return -1 ;
501
+ }
502
+ system (cmd );
503
+ if (del_runC (argv [1 ]) < 0 ) {
504
+ printf ("ERROR: del runC failed!\n" );
505
+ return -1 ;
520
506
}
521
507
522
508
return 0 ;
@@ -545,24 +531,19 @@ static int acrnctl_do_start(int argc, char *argv[])
545
531
static int acrnctl_do_pause (int argc , char * argv [])
546
532
{
547
533
struct vmmngr_struct * s ;
548
- int i ;
549
534
550
- for (i = 1 ; i < argc ; i ++ ) {
551
- s = vmmngr_find (argv [i ]);
552
- if (!s ) {
553
- printf ("Can't find vm %s\n" , argv [i ]);
554
- continue ;
555
- }
535
+ s = vmmngr_find (argv [1 ]);
536
+ if (!s ) {
537
+ printf ("Can't find vm %s\n" , argv [1 ]);
538
+ }
556
539
557
- /* Send pause cmd to arcn-dm only when vm is in VM_STARTED */
558
- switch (s -> state ) {
559
- case VM_STARTED :
560
- pause_vm (argv [i ]);
561
- break ;
562
- default :
563
- printf ("%s current state %s, can't pause\n" ,
564
- argv [i ], state_str [s -> state ]);
565
- }
540
+ /* Send pause cmd to arcn-dm only when vm is in VM_STARTED */
541
+ switch (s -> state ) {
542
+ case VM_STARTED :
543
+ pause_vm (argv [1 ]);
544
+ break ;
545
+ default :
546
+ printf ("%s current state %s, can't pause\n" ,argv [1 ], state_str [s -> state ]);
566
547
}
567
548
568
549
return 0 ;
@@ -571,27 +552,22 @@ static int acrnctl_do_pause(int argc, char *argv[])
571
552
static int acrnctl_do_continue (int argc , char * argv [])
572
553
{
573
554
struct vmmngr_struct * s ;
574
- int i ;
575
555
576
- for (i = 1 ; i < argc ; i ++ ) {
577
- s = vmmngr_find (argv [i ]);
578
- if (!s ) {
579
- printf ("Can't find vm %s\n" , argv [i ]);
580
- continue ;
581
- }
556
+ s = vmmngr_find (argv [1 ]);
557
+ if (!s ) {
558
+ printf ("Can't find vm %s\n" , argv [1 ]);
559
+ }
582
560
583
- /* Per current implemention, we can't know if vm is in paused
584
- state. Send continue cmd to acrn-dm when VM_STARTED and will
585
- correct it later when we have a way to check if vm has been
586
- paused */
587
- switch (s -> state ) {
588
- case VM_STARTED :
589
- continue_vm (argv [i ]);
590
- break ;
591
- default :
592
- printf ("%s current state %s, can't continue\n" ,
593
- argv [i ], state_str [s -> state ]);
594
- }
561
+ /* Per current implemention, we can't know if vm is in paused
562
+ state. Send continue cmd to acrn-dm when VM_STARTED and will
563
+ correct it later when we have a way to check if vm has been
564
+ paused */
565
+ switch (s -> state ) {
566
+ case VM_STARTED :
567
+ continue_vm (argv [1 ]);
568
+ break ;
569
+ default :
570
+ printf ("%s current state %s, can't continue\n" ,argv [1 ], state_str [s -> state ]);
595
571
}
596
572
597
573
return 0 ;
@@ -600,24 +576,19 @@ static int acrnctl_do_continue(int argc, char *argv[])
600
576
static int acrnctl_do_suspend (int argc , char * argv [])
601
577
{
602
578
struct vmmngr_struct * s ;
603
- int i ;
604
579
605
- for (i = 1 ; i < argc ; i ++ ) {
606
- s = vmmngr_find (argv [1 ]);
607
- if (!s ) {
608
- printf ("Can't find vm %s\n" , argv [i ]);
609
- continue ;
610
- }
580
+ s = vmmngr_find (argv [1 ]);
581
+ if (!s ) {
582
+ printf ("Can't find vm %s\n" , argv [1 ]);
583
+ }
611
584
612
- /* Only send suspend cmd to acrn-dm now when VM_STARTED */
613
- switch (s -> state ) {
614
- case VM_STARTED :
615
- suspend_vm (argv [i ]);
616
- break ;
617
- default :
618
- printf ("%s current state %s, can't suspend\n" ,
619
- argv [i ], state_str [s -> state ]);
620
- }
585
+ /* Only send suspend cmd to acrn-dm now when VM_STARTED */
586
+ switch (s -> state ) {
587
+ case VM_STARTED :
588
+ suspend_vm (argv [1 ]);
589
+ break ;
590
+ default :
591
+ printf ("%s current state %s, can't suspend\n" ,argv [1 ], state_str [s -> state ]);
621
592
}
622
593
623
594
return 0 ;
@@ -646,8 +617,7 @@ static int acrnctl_do_resume(int argc, char *argv[])
646
617
printf ("resume %s reason(0x%x\n" , argv [1 ], reason );
647
618
break ;
648
619
default :
649
- printf ("%s current state %s, can't resume\n" ,
650
- argv [1 ], state_str [s -> state ]);
620
+ printf ("%s current state %s, can't resume\n" ,argv [1 ], state_str [s -> state ]);
651
621
}
652
622
653
623
return 0 ;
@@ -682,30 +652,24 @@ static int wait_vm_stop(const char * vmname, unsigned int timeout)
682
652
static int acrnctl_do_reset (int argc , char * argv [])
683
653
{
684
654
struct vmmngr_struct * s ;
685
- int i ;
686
655
687
- for (i = 1 ; i < argc ; i ++ ) {
688
- s = vmmngr_find (argv [i ]);
689
- if (!s ) {
690
- printf ("Can't find vm %s\n" , argv [i ]);
691
- continue ;
692
- }
656
+ s = vmmngr_find (argv [1 ]);
657
+ if (!s ) {
658
+ printf ("Can't find vm %s\n" , argv [1 ]);
659
+ }
693
660
694
- switch (s -> state ) {
695
- case VM_STARTED :
696
- case VM_SUSPENDED :
697
- stop_vm (argv [i ]);
698
- if (wait_vm_stop (argv [i ], STOP_TIMEOUT )) {
699
- printf ("Failed to stop %s in %u sec, reset failed\n" ,
700
- argv [i ], STOP_TIMEOUT );
701
- return -1 ;
702
- }
703
- start_vm (argv [i ]);
704
- break ;
705
- default :
706
- printf ("%s current state: %s, can't reset\n" ,
707
- argv [i ], state_str [s -> state ]);
708
- }
661
+ switch (s -> state ) {
662
+ case VM_STARTED :
663
+ case VM_SUSPENDED :
664
+ stop_vm (argv [1 ]);
665
+ if (wait_vm_stop (argv [1 ], STOP_TIMEOUT )) {
666
+ printf ("Failed to stop %s in %u sec, reset failed\n" ,argv [1 ], STOP_TIMEOUT );
667
+ return -1 ;
668
+ }
669
+ start_vm (argv [1 ]);
670
+ break ;
671
+ default :
672
+ printf ("%s current state: %s, can't reset\n" ,argv [1 ], state_str [s -> state ]);
709
673
}
710
674
return 0 ;
711
675
}
0 commit comments