tools: acrnctl: Add support for pausing vm

Add command pasue to pause 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>
This commit is contained in:
Kaige Fu 2018-05-31 10:03:09 +08:00 committed by lijinxia
parent 3000edc6ad
commit 1933d60c29
4 changed files with 49 additions and 0 deletions

View File

@ -27,6 +27,7 @@ You can see the available ``acrnctl`` commands by running:
stop
del
add
pause
Use acrnctl [cmd] help for details
Here are some usage examples:

View File

@ -201,3 +201,22 @@ int stop_vm(char *vmname)
return ack.err;
}
int pause_vm(char *vmname)
{
struct req_dm_pause req;
struct ack_dm_pause ack;
req.msg.magic = MNGR_MSG_MAGIC;
req.msg.msgid = DM_PAUSE;
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 pause vm. errno(%d)\n", ack.err);
}
return ack.err;
}

View File

@ -32,6 +32,7 @@
#define STOP_DESC "Stop virtual machine VM_NAME"
#define DEL_DESC "Delete virtual machine VM_NAME"
#define ADD_DESC "Add one virtual machine with SCRIPTS and OPTIONS"
#define PAUSE_DESC "Block all vCPUs of virtual machine VM_NAME"
struct acrnctl_cmd {
const char *cmd;
@ -377,6 +378,32 @@ static int acrnctl_do_start(int argc, char *argv[])
return 0;
}
static int acrnctl_do_pause(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;
}
/* Send pause cmd to arcn-dm only when vm is in VM_STARTED */
switch (s->state) {
case VM_STARTED:
pause_vm(argv[i]);
break;
default:
printf("%s current state %s, can't pause\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[])
{
@ -430,6 +457,7 @@ struct acrnctl_cmd acmds[] = {
ACMD("stop", acrnctl_do_stop, STOP_DESC, df_valid_args),
ACMD("del", acrnctl_do_del, DEL_DESC, df_valid_args),
ACMD("add", acrnctl_do_add, ADD_DESC, valid_add_args),
ACMD("pause", acrnctl_do_pause, PAUSE_DESC, df_valid_args),
};
#define NCMD (sizeof(acmds)/sizeof(struct acrnctl_cmd))

View File

@ -59,5 +59,6 @@ int shell_cmd(const char *cmd, char *outbuf, int len);
int list_vm(void);
int stop_vm(char *vmname);
int start_vm(char *vmname);
int pause_vm(char *vmname);
#endif /* _ACRNCTL_H_ */