From 7a0e8ddeec5ba79597eb8e210683436e6a6db48f Mon Sep 17 00:00:00 2001 From: Kaige Fu Date: Thu, 31 May 2018 10:41:06 +0800 Subject: [PATCH] tools: acrnctl: Add support for resuming vm Add command resume to resume vm from suspend state. Signed-off-by: Kaige Fu Reviewed-by: Geoffroy Van Cutsem Reviewed-by: Yan, Like Acked-by: Eddie Dong --- tools/acrn-manager/README.rst | 1 + tools/acrn-manager/acrn_vm_ops.c | 20 ++++++++++++++++++++ tools/acrn-manager/acrnctl.c | 31 +++++++++++++++++++++++++++++++ tools/acrn-manager/acrnctl.h | 1 + 4 files changed, 53 insertions(+) diff --git a/tools/acrn-manager/README.rst b/tools/acrn-manager/README.rst index 592347c42..b753fbf51 100644 --- a/tools/acrn-manager/README.rst +++ b/tools/acrn-manager/README.rst @@ -30,6 +30,7 @@ You can see the available ``acrnctl`` commands by running: pause continue suspend + resume Use acrnctl [cmd] help for details Here are some usage examples: diff --git a/tools/acrn-manager/acrn_vm_ops.c b/tools/acrn-manager/acrn_vm_ops.c index 56dd7a24d..5d5a94b5b 100644 --- a/tools/acrn-manager/acrn_vm_ops.c +++ b/tools/acrn-manager/acrn_vm_ops.c @@ -260,3 +260,23 @@ int suspend_vm(char *vmname) return ack.err; } + +int resume_vm(char *vmname) +{ + struct req_dm_resume req; + struct ack_dm_resume ack; + + req.msg.magic = MNGR_MSG_MAGIC; + req.msg.msgid = DM_RESUME; + req.msg.timestamp = time(NULL); + req.msg.len = sizeof(req); + + send_msg(vmname, (struct mngr_msg *)&req, + (struct mngr_msg *)&ack, sizeof(ack)); + + if (ack.err) { + printf("Unable to resume vm. errno(%d)\n", ack.err); + } + + return ack.err; +} diff --git a/tools/acrn-manager/acrnctl.c b/tools/acrn-manager/acrnctl.c index 630aff34d..f0c7004cb 100644 --- a/tools/acrn-manager/acrnctl.c +++ b/tools/acrn-manager/acrnctl.c @@ -35,6 +35,7 @@ #define PAUSE_DESC "Block all vCPUs of virtual machine VM_NAME" #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" struct acrnctl_cmd { const char *cmd; @@ -461,6 +462,35 @@ static int acrnctl_do_suspend(int argc, char *argv[]) return 0; } +static int acrnctl_do_resume(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; + } + + /* Per current implemention, we can't know if vm is in suspended + state. Send reume cmd to acrn-dm when VM_STARTED and will + correct it later when we have a way to check if vm has been + suspended */ + switch (s->state) { + case VM_STARTED: + resume_vm(argv[i]); + break; + default: + printf("%s current state %s, can't resume\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[]) { @@ -517,6 +547,7 @@ struct acrnctl_cmd acmds[] = { ACMD("pause", acrnctl_do_pause, PAUSE_DESC, df_valid_args), 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), }; #define NCMD (sizeof(acmds)/sizeof(struct acrnctl_cmd)) diff --git a/tools/acrn-manager/acrnctl.h b/tools/acrn-manager/acrnctl.h index ffcb9d9fe..d44beefe5 100644 --- a/tools/acrn-manager/acrnctl.h +++ b/tools/acrn-manager/acrnctl.h @@ -62,5 +62,6 @@ int start_vm(char *vmname); int pause_vm(char *vmname); int continue_vm(char *vmname); int suspend_vm(char *vmname); +int resume_vm(char *vmname); #endif /* _ACRNCTL_H_ */