diff options
author | pd <pd@openbsd.org> | 2017-07-09 00:51:40 +0000 |
---|---|---|
committer | pd <pd@openbsd.org> | 2017-07-09 00:51:40 +0000 |
commit | 52e954a3fad37facf0321bc5eab1a89fc28f90a7 (patch) | |
tree | 2d9d19d0ecc85e98b1b7cb5695ca0e63dc20e8ca /usr.sbin/vmctl | |
parent | this program was infected with lint era casts. i think we're past that now. (diff) | |
download | wireguard-openbsd-52e954a3fad37facf0321bc5eab1a89fc28f90a7.tar.xz wireguard-openbsd-52e954a3fad37facf0321bc5eab1a89fc28f90a7.zip |
vmd/vmctl: Add ability to pause / unpause vms
With help from Ashwin Agrawal
ok reyk@ mlarkin@
Diffstat (limited to 'usr.sbin/vmctl')
-rw-r--r-- | usr.sbin/vmctl/main.c | 42 | ||||
-rw-r--r-- | usr.sbin/vmctl/vmctl.c | 80 | ||||
-rw-r--r-- | usr.sbin/vmctl/vmctl.h | 8 |
3 files changed, 127 insertions, 3 deletions
diff --git a/usr.sbin/vmctl/main.c b/usr.sbin/vmctl/main.c index 632c22150e2..d1c0badf8ce 100644 --- a/usr.sbin/vmctl/main.c +++ b/usr.sbin/vmctl/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.29 2017/06/07 23:15:49 mlarkin Exp $ */ +/* $OpenBSD: main.c,v 1.30 2017/07/09 00:51:40 pd Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -56,6 +56,8 @@ int ctl_reset(struct parse_result *, int, char *[]); int ctl_start(struct parse_result *, int, char *[]); int ctl_status(struct parse_result *, int, char *[]); int ctl_stop(struct parse_result *, int, char *[]); +int ctl_pause(struct parse_result *, int, char *[]); +int ctl_unpause(struct parse_result *, int, char *[]); struct ctl_command ctl_commands[] = { { "console", CMD_CONSOLE, ctl_console, "id" }, @@ -69,6 +71,8 @@ struct ctl_command ctl_commands[] = { "\t\t[-n switch] [-i count] [-d disk]*" }, { "status", CMD_STATUS, ctl_status, "[id]" }, { "stop", CMD_STOP, ctl_stop, "id" }, + { "pause", CMD_PAUSE, ctl_pause, "id" }, + { "unpause", CMD_UNPAUSE, ctl_unpause, "id" }, { NULL } }; @@ -225,6 +229,12 @@ vmmaction(struct parse_result *res) imsg_compose(ibuf, IMSG_CTL_RESET, 0, 0, -1, &res->mode, sizeof(res->mode)); break; + case CMD_PAUSE: + pause_vm(res->id, res->name); + break; + case CMD_UNPAUSE: + unpause_vm(res->id, res->name); + break; case CMD_CREATE: case NONE: break; @@ -275,6 +285,12 @@ vmmaction(struct parse_result *res) case CMD_STATUS: done = add_info(&imsg, &ret); break; + case CMD_PAUSE: + done = pause_vm_complete(&imsg, &ret); + break; + case CMD_UNPAUSE: + done = unpause_vm_complete(&imsg, &ret); + break; default: done = 1; break; @@ -616,6 +632,30 @@ ctl_console(struct parse_result *res, int argc, char *argv[]) return (vmmaction(res)); } +int +ctl_pause(struct parse_result *res, int argc, char *argv[]) +{ + if (argc == 2) { + if (parse_vmid(res, argv[1]) == -1) + errx(1, "invalid id: %s", argv[1]); + } else if (argc != 2) + ctl_usage(res->ctl); + + return (vmmaction(res)); +} + +int +ctl_unpause(struct parse_result *res, int argc, char *argv[]) +{ + if (argc == 2) { + if (parse_vmid(res, argv[1]) == -1) + errx(1, "invalid id: %s", argv[1]); + } else if (argc != 2) + ctl_usage(res->ctl); + + return (vmmaction(res)); +} + __dead void ctl_openconsole(const char *name) { 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 * diff --git a/usr.sbin/vmctl/vmctl.h b/usr.sbin/vmctl/vmctl.h index 58d03d20bd1..ca851dc8933 100644 --- a/usr.sbin/vmctl/vmctl.h +++ b/usr.sbin/vmctl/vmctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmctl.h,v 1.14 2017/04/06 18:07:13 reyk Exp $ */ +/* $OpenBSD: vmctl.h,v 1.15 2017/07/09 00:51:40 pd Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -32,6 +32,8 @@ enum actions { CMD_START, CMD_STATUS, CMD_STOP, + CMD_PAUSE, + CMD_UNPAUSE, }; struct ctl_command; @@ -82,6 +84,10 @@ int vm_start(uint32_t, const char *, int, int, char **, int, int vm_start_complete(struct imsg *, int *, int); void terminate_vm(uint32_t, const char *); int terminate_vm_complete(struct imsg *, int *); +void pause_vm(uint32_t, const char *); +int pause_vm_complete(struct imsg *, int *); +void unpause_vm(uint32_t, const char *); +int unpause_vm_complete(struct imsg *, int *); int check_info_id(const char *, uint32_t); void get_info_vm(uint32_t, const char *, int); int add_info(struct imsg *, int *); |