Skip to content

Commit

Permalink
tools: acrnctl: Add support for reseting vm
Browse files Browse the repository at this point in the history
Add command reset to stop and then start vm.

Signed-off-by: Kaige Fu <kaige.fu@intel.com>
Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
Reviewed-by: Yan, Like <like.yan@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
  • Loading branch information
KaigeFu authored and lijinxia committed Jun 7, 2018
1 parent 7a0e8dd commit 2dd4e8f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/acrn-manager/README.rst
Expand Up @@ -31,6 +31,7 @@ You can see the available ``acrnctl`` commands by running:
continue
suspend
resume
reset
Use acrnctl [cmd] help for details
Here are some usage examples:
Expand Down
31 changes: 31 additions & 0 deletions tools/acrn-manager/acrnctl.c
Expand Up @@ -36,6 +36,7 @@
#define CONTINUE_DESC "Start virtual machine from pause state"
#define SUSPEND_DESC "Switch virtual machine to suspend state"
#define RESUME_DESC "Resume virtual machine from suspend state"
#define RESET_DESC "Stop and then start virtual machine VM_NAME"

struct acrnctl_cmd {
const char *cmd;
Expand Down Expand Up @@ -491,6 +492,35 @@ static int acrnctl_do_resume(int argc, char *argv[])
return 0;
}

static int acrnctl_do_reset(int argc, char *argv[])
{
struct vmmngr_struct *s;
int i;

for (i = 1; i < argc; i++) {
s = vmmngr_find(argv[i]);
if (!s) {
printf("Can't find vm %s\n", argv[i]);
continue;
}

switch(s->state) {
case VM_CREATED:
start_vm(argv[i]);
break;
case VM_STARTED:
case VM_PAUSED:
stop_vm(argv[i]);
start_vm(argv[i]);
break;
default:
printf("%s current state: %s, can't reset\n",
argv[i], state_str[s->state]);
}
}
return 0;
}

/* Default args validation function */
int df_valid_args(struct acrnctl_cmd *cmd, int argc, char *argv[])
{
Expand Down Expand Up @@ -548,6 +578,7 @@ struct acrnctl_cmd acmds[] = {
ACMD("continue", acrnctl_do_continue, CONTINUE_DESC, df_valid_args),
ACMD("suspend", acrnctl_do_suspend, SUSPEND_DESC, df_valid_args),
ACMD("resume", acrnctl_do_resume, RESUME_DESC, df_valid_args),
ACMD("reset", acrnctl_do_reset, RESET_DESC, df_valid_args),
};

#define NCMD (sizeof(acmds)/sizeof(struct acrnctl_cmd))
Expand Down

0 comments on commit 2dd4e8f

Please sign in to comment.