diff options
author | pd <pd@cvs.openbsd.org> | 2017-07-09 00:51:41 +0000 |
---|---|---|
committer | pd <pd@cvs.openbsd.org> | 2017-07-09 00:51:41 +0000 |
commit | 301ef29f7b226bb27f8ca368b7f86fef176240a8 (patch) | |
tree | 434eb35db4880f6c54308bc693c9ff0cd60c37b8 /usr.sbin/vmctl/vmctl.c | |
parent | 219d945ea49f381a3f0a44f958efefcd9b19dc3e (diff) |
vmd/vmctl: Add ability to pause / unpause vms
With help from Ashwin Agrawal
ok reyk@ mlarkin@
Diffstat (limited to 'usr.sbin/vmctl/vmctl.c')
-rw-r--r-- | usr.sbin/vmctl/vmctl.c | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/usr.sbin/vmctl/vmctl.c b/usr.sbin/vmctl/vmctl.c index ee9c6db0e9d..1ae0e1d42e6 100644 --- a/usr.sbin/vmctl/vmctl.c +++ b/usr.sbin/vmctl/vmctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmctl.c,v 1.30 2017/04/19 15:38:32 reyk Exp $ */ +/* $OpenBSD: vmctl.c,v 1.31 2017/07/09 00:51:40 pd Exp $ */ /* * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> @@ -196,6 +196,84 @@ vm_start_complete(struct imsg *imsg, int *ret, int autoconnect) return (1); } +void +pause_vm(uint32_t pause_id, const char *name) +{ + struct vmop_id vid; + + memset(&vid, 0, sizeof(vid)); + vid.vid_id = pause_id; + if (name != NULL) + (void)strlcpy(vid.vid_name, name, sizeof(vid.vid_name)); + + imsg_compose(ibuf, IMSG_VMDOP_PAUSE_VM, 0, 0, -1, + &vid, sizeof(vid)); +} + +int +pause_vm_complete(struct imsg *imsg, int *ret) +{ + struct vmop_result *vmr; + int res; + + if (imsg->hdr.type == IMSG_VMDOP_PAUSE_VM_RESPONSE) { + vmr = (struct vmop_result *)imsg->data; + res = vmr->vmr_result; + if (res) { + errno = res; + warn("pause vm command failed"); + *ret = EIO; + } else { + warnx("paused vm %d successfully", vmr->vmr_id); + *ret = 0; + } + } else { + warnx("unexpected response received from vmd"); + *ret = EINVAL; + } + + return (1); +} + +void +unpause_vm(uint32_t pause_id, const char *name) +{ + struct vmop_id vid; + + memset(&vid, 0, sizeof(vid)); + vid.vid_id = pause_id; + if (name != NULL) + (void)strlcpy(vid.vid_name, name, sizeof(vid.vid_name)); + + imsg_compose(ibuf, IMSG_VMDOP_UNPAUSE_VM, 0, 0, -1, + &vid, sizeof(vid)); +} + +int +unpause_vm_complete(struct imsg *imsg, int *ret) +{ + struct vmop_result *vmr; + int res; + + if (imsg->hdr.type == IMSG_VMDOP_UNPAUSE_VM_RESPONSE) { + vmr = (struct vmop_result *)imsg->data; + res = vmr->vmr_result; + if (res) { + errno = res; + warn("unpause vm command failed"); + *ret = EIO; + } else { + warnx("unpaused vm %d successfully", vmr->vmr_id); + *ret = 0; + } + } else { + warnx("unexpected response received from vmd"); + *ret = EINVAL; + } + + return (1); +} + /* * terminate_vm * |