diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2018-07-11 13:19:48 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2018-07-11 13:19:48 +0000 |
commit | 086fb89ddce69eda23ca9772b51da5a824e164ba (patch) | |
tree | 91575a8755c1ff3f13d0b40230b491b14de36dc2 /usr.sbin/vmctl | |
parent | 64023a9a5ca6c9d8e91b62e58ba084396cdbccff (diff) |
Add -w option to vmctl stop to wait for completion of VM termination.
Use it in /etc/rc.d/vmd accordingly.
OK sthen@
Diffstat (limited to 'usr.sbin/vmctl')
-rw-r--r-- | usr.sbin/vmctl/main.c | 18 | ||||
-rw-r--r-- | usr.sbin/vmctl/vmctl.8 | 16 | ||||
-rw-r--r-- | usr.sbin/vmctl/vmctl.c | 24 | ||||
-rw-r--r-- | usr.sbin/vmctl/vmctl.h | 9 |
4 files changed, 40 insertions, 27 deletions
diff --git a/usr.sbin/vmctl/main.c b/usr.sbin/vmctl/main.c index 69d93d1a771..7b288d5255c 100644 --- a/usr.sbin/vmctl/main.c +++ b/usr.sbin/vmctl/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.36 2018/07/11 09:35:44 reyk Exp $ */ +/* $OpenBSD: main.c,v 1.37 2018/07/11 13:19:47 reyk Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -73,7 +73,7 @@ struct ctl_command ctl_commands[] = { " [-Lc] [-b image] [-r image] [-m size]\n" "\t\t[-n switch] [-i count] [-d disk]*" }, { "status", CMD_STATUS, ctl_status, "[id]" }, - { "stop", CMD_STOP, ctl_stop, "id [-f]" }, + { "stop", CMD_STOP, ctl_stop, "id [-fw]" }, { "pause", CMD_PAUSE, ctl_pause, "id" }, { "unpause", CMD_UNPAUSE, ctl_unpause, "id" }, { "send", CMD_SEND, ctl_send, "id", 1}, @@ -182,6 +182,7 @@ vmmaction(struct parse_result *res) int done = 0; int n; int ret, action; + unsigned int flags; if (ctl_sock == -1) { if ((ctl_sock = socket(AF_UNIX, @@ -212,7 +213,7 @@ vmmaction(struct parse_result *res) } break; case CMD_STOP: - terminate_vm(res->id, res->name, res->force); + terminate_vm(res->id, res->name, res->flags); break; case CMD_STATUS: get_info_vm(res->id, res->name, 0); @@ -254,6 +255,7 @@ vmmaction(struct parse_result *res) } action = res->action; + flags = res->flags; parse_free(res); while (ibuf->w.queued) @@ -292,7 +294,8 @@ vmmaction(struct parse_result *res) tty_autoconnect); break; case CMD_STOP: - done = terminate_vm_complete(&imsg, &ret); + done = terminate_vm_complete(&imsg, &ret, + flags); break; case CMD_CONSOLE: case CMD_STATUS: @@ -652,10 +655,13 @@ ctl_stop(struct parse_result *res, int argc, char *argv[]) argc--; argv++; - while ((ch = getopt(argc, argv, "f")) != -1) { + while ((ch = getopt(argc, argv, "fw")) != -1) { switch (ch) { case 'f': - res->force = 1; + res->flags |= VMOP_FORCE; + break; + case 'w': + res->flags |= VMOP_WAIT; break; default: ctl_usage(res->ctl); diff --git a/usr.sbin/vmctl/vmctl.8 b/usr.sbin/vmctl/vmctl.8 index 4bd39460e6f..878b0b6a462 100644 --- a/usr.sbin/vmctl/vmctl.8 +++ b/usr.sbin/vmctl/vmctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: vmctl.8,v 1.40 2018/07/11 09:35:44 reyk Exp $ +.\" $OpenBSD: vmctl.8,v 1.41 2018/07/11 13:19:47 reyk Exp $ .\" .\" Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> .\" @@ -147,7 +147,7 @@ with '.', '-' or '_'. .It Cm status Op Ar id Lists VMs running on the host, optionally listing just the selected VM .Ar id . -.It Cm stop Ar id Op Fl f +.It Cm stop Ar id Op Fl fw Stops (terminates) a VM defined by the specified VM .Ar id . By default, @@ -156,9 +156,15 @@ a graceful shutdown will be attempted if the VM supports the device. Once stopped, if the VM was not defined in a configuration file, then it is removed. -The -.Fl f -option forcefully stops the VM without attempting a graceful shutdown. +.Pp +The following options can be specified when stopping a VM: +.Bl -tag -width "-w" +.It Fl f +Forcefully stop the VM without attempting a graceful shutdown. +.It Fl w +Wait until the VM has been terminated. +.El +.Pp .It Cm unpause Ar id Unpause (resume from a paused state) a VM with the specified .Ar id . diff --git a/usr.sbin/vmctl/vmctl.c b/usr.sbin/vmctl/vmctl.c index fff8afcf680..bfbc2c22801 100644 --- a/usr.sbin/vmctl/vmctl.c +++ b/usr.sbin/vmctl/vmctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmctl.c,v 1.51 2018/07/11 09:35:44 reyk Exp $ */ +/* $OpenBSD: vmctl.c,v 1.52 2018/07/11 13:19:47 reyk Exp $ */ /* * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> @@ -410,25 +410,22 @@ unpause_vm_complete(struct imsg *imsg, int *ret) * Parameters: * terminate_id: ID of the vm to be terminated * name: optional name of the VM to be terminated - * force: forcefully kill the VM process + * flags: VMOP_FORCE or VMOP_WAIT flags */ void -terminate_vm(uint32_t terminate_id, const char *name, int force) +terminate_vm(uint32_t terminate_id, const char *name, unsigned int flags) { struct vmop_id vid; - int cmd; memset(&vid, 0, sizeof(vid)); vid.vid_id = terminate_id; if (name != NULL) (void)strlcpy(vid.vid_name, name, sizeof(vid.vid_name)); - if (force) - cmd = IMSG_VMDOP_KILL_VM_REQUEST; - else - cmd = IMSG_VMDOP_TERMINATE_VM_REQUEST; + vid.vid_flags = flags & (VMOP_FORCE|VMOP_WAIT); - imsg_compose(ibuf, cmd, 0, 0, -1, &vid, sizeof(vid)); + imsg_compose(ibuf, IMSG_VMDOP_TERMINATE_VM_REQUEST, + 0, 0, -1, &vid, sizeof(vid)); } /* @@ -441,6 +438,7 @@ terminate_vm(uint32_t terminate_id, const char *name, int force) * Parameters: * imsg : response imsg received from vmd * ret : return value + * flags: VMOP_FORCE or VMOP_WAIT flags * * Return: * Always 1 to indicate we have processed the return message (even if it @@ -452,7 +450,7 @@ terminate_vm(uint32_t terminate_id, const char *name, int force) * EIO : terminate_vm command failed */ int -terminate_vm_complete(struct imsg *imsg, int *ret) +terminate_vm_complete(struct imsg *imsg, int *ret, unsigned int flags) { struct vmop_result *vmr; int res; @@ -475,8 +473,12 @@ terminate_vm_complete(struct imsg *imsg, int *ret) warn("terminate vm command failed"); *ret = EIO; } + } else if (flags & VMOP_WAIT) { + warnx("terminated vm %d", vmr->vmr_id); + } else if (flags & VMOP_FORCE) { + warnx("requested to terminate vm %d", vmr->vmr_id); } else { - warnx("sent request to terminate vm %d", vmr->vmr_id); + warnx("requested to shutdown vm %d", vmr->vmr_id); *ret = 0; } } else { diff --git a/usr.sbin/vmctl/vmctl.h b/usr.sbin/vmctl/vmctl.h index 337a5382f86..7fc8af8cbeb 100644 --- a/usr.sbin/vmctl/vmctl.h +++ b/usr.sbin/vmctl/vmctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmctl.h,v 1.19 2018/07/11 09:35:44 reyk Exp $ */ +/* $OpenBSD: vmctl.h,v 1.20 2018/07/11 13:19:47 reyk Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -52,9 +52,8 @@ struct parse_result { int nnets; size_t ndisks; char **disks; - int disable; int verbose; - int force; + unsigned int flags; unsigned int mode; struct ctl_command *ctl; }; @@ -86,8 +85,8 @@ int create_imagefile(const char *, long); int vm_start(uint32_t, const char *, int, int, char **, int, char **, char *, char *); int vm_start_complete(struct imsg *, int *, int); -void terminate_vm(uint32_t, const char *, int); -int terminate_vm_complete(struct imsg *, int *); +void terminate_vm(uint32_t, const char *, unsigned int); +int terminate_vm_complete(struct imsg *, int *, unsigned int); void pause_vm(uint32_t, const char *); int pause_vm_complete(struct imsg *, int *); void unpause_vm(uint32_t, const char *); |