diff options
author | 2018-12-04 08:15:09 +0000 | |
---|---|---|
committer | 2018-12-04 08:15:09 +0000 | |
commit | 9517648255699db6074ae99eb6c0c85e51ca996e (patch) | |
tree | 0bbf7bc77481c0517f264d653a81e640bcfa2467 /usr.sbin | |
parent | Update bgpd result files after the community change. Forgot this bit of (diff) | |
download | wireguard-openbsd-9517648255699db6074ae99eb6c0c85e51ca996e.tar.xz wireguard-openbsd-9517648255699db6074ae99eb6c0c85e51ca996e.zip |
Introduce IMSG_VMDOP_WAIT_VM_REQUEST a control message that registers a
vmctl peerid that should be informed when the VM is stopped (like when the
guest does a shutdown). Uses the same logic as using the VMOP_WAIT flag on
IMSG_VMDOP_TERMINATE_VM_REQUEST.
Ok ccardenas@, reyk@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/vmd/control.c | 4 | ||||
-rw-r--r-- | usr.sbin/vmd/vmd.c | 3 | ||||
-rw-r--r-- | usr.sbin/vmd/vmd.h | 3 | ||||
-rw-r--r-- | usr.sbin/vmd/vmm.c | 38 |
4 files changed, 40 insertions, 8 deletions
diff --git a/usr.sbin/vmd/control.c b/usr.sbin/vmd/control.c index 2d3f0b804ec..119fe460ca7 100644 --- a/usr.sbin/vmd/control.c +++ b/usr.sbin/vmd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.29 2018/08/05 08:20:54 mestre Exp $ */ +/* $OpenBSD: control.c,v 1.30 2018/12/04 08:15:09 claudio Exp $ */ /* * Copyright (c) 2010-2015 Reyk Floeter <reyk@openbsd.org> @@ -341,6 +341,7 @@ control_dispatch_imsg(int fd, short event, void *arg) switch (imsg.hdr.type) { case IMSG_VMDOP_GET_INFO_VM_REQUEST: + case IMSG_VMDOP_WAIT_VM_REQUEST: case IMSG_VMDOP_TERMINATE_VM_REQUEST: case IMSG_VMDOP_START_VM_REQUEST: case IMSG_VMDOP_PAUSE_VM: @@ -399,6 +400,7 @@ control_dispatch_imsg(int fd, short event, void *arg) return; } break; + case IMSG_VMDOP_WAIT_VM_REQUEST: case IMSG_VMDOP_TERMINATE_VM_REQUEST: if (IMSG_DATA_SIZE(&imsg) < sizeof(vid)) goto fail; diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c index 2afc11f63c5..ee4481711f8 100644 --- a/usr.sbin/vmd/vmd.c +++ b/usr.sbin/vmd/vmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.c,v 1.106 2018/11/26 05:44:46 ori Exp $ */ +/* $OpenBSD: vmd.c,v 1.107 2018/12/04 08:15:09 claudio Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -116,6 +116,7 @@ vmd_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg) cmd = IMSG_VMDOP_START_VM_RESPONSE; } break; + case IMSG_VMDOP_WAIT_VM_REQUEST: case IMSG_VMDOP_TERMINATE_VM_REQUEST: IMSG_SIZE_CHECK(imsg, &vid); memcpy(&vid, imsg->data, sizeof(vid)); diff --git a/usr.sbin/vmd/vmd.h b/usr.sbin/vmd/vmd.h index c7ee8ecac14..1335d198d01 100644 --- a/usr.sbin/vmd/vmd.h +++ b/usr.sbin/vmd/vmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.h,v 1.86 2018/11/26 05:44:46 ori Exp $ */ +/* $OpenBSD: vmd.h,v 1.87 2018/12/04 08:15:09 claudio Exp $ */ /* * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> @@ -98,6 +98,7 @@ enum imsg_type { IMSG_VMDOP_RECEIVE_VM_REQUEST, IMSG_VMDOP_RECEIVE_VM_RESPONSE, IMSG_VMDOP_RECEIVE_VM_END, + IMSG_VMDOP_WAIT_VM_REQUEST, IMSG_VMDOP_TERMINATE_VM_REQUEST, IMSG_VMDOP_TERMINATE_VM_RESPONSE, IMSG_VMDOP_TERMINATE_VM_EVENT, diff --git a/usr.sbin/vmd/vmm.c b/usr.sbin/vmd/vmm.c index 9bbbf266fb4..a3b20e282e4 100644 --- a/usr.sbin/vmd/vmm.c +++ b/usr.sbin/vmd/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.90 2018/10/08 16:32:01 reyk Exp $ */ +/* $OpenBSD: vmm.c,v 1.91 2018/12/04 08:15:09 claudio Exp $ */ /* * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> @@ -109,7 +109,7 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) struct vmop_id vid; struct vmop_result vmr; struct vmop_create_params vmc; - uint32_t id = 0; + uint32_t id = 0, peerid = imsg->hdr.peerid; pid_t pid = 0; unsigned int mode, flags; @@ -149,6 +149,30 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) res = ENOENT; cmd = IMSG_VMDOP_START_VM_RESPONSE; break; + case IMSG_VMDOP_WAIT_VM_REQUEST: + IMSG_SIZE_CHECK(imsg, &vid); + memcpy(&vid, imsg->data, sizeof(vid)); + id = vid.vid_id; + + DPRINTF("%s: recv'ed WAIT_VM for %d", __func__, id); + + cmd = IMSG_VMDOP_TERMINATE_VM_RESPONSE; + if (id == 0) { + res = ENOENT; + } else if ((vm = vm_getbyvmid(id)) != NULL) { + if (vm->vm_peerid != (uint32_t)-1) { + peerid = vm->vm_peerid; + res = EINTR; + } else + cmd = 0; + vm->vm_peerid = imsg->hdr.peerid; + } else { + /* vm doesn't exist, cannot stop vm */ + log_debug("%s: cannot stop vm that is not running", + __func__); + res = VMD_VM_STOP_INVALID; + } + break; case IMSG_VMDOP_TERMINATE_VM_REQUEST: IMSG_SIZE_CHECK(imsg, &vid); memcpy(&vid, imsg->data, sizeof(vid)); @@ -199,8 +223,12 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) } if ((flags & VMOP_WAIT) && res == 0 && vm->vm_shutdown == 1) { + if (vm->vm_peerid != (uint32_t)-1) { + peerid = vm->vm_peerid; + res = EINTR; + } else + cmd = 0; vm->vm_peerid = imsg->hdr.peerid; - cmd = 0; } } else { /* vm doesn't exist, cannot stop vm */ @@ -329,12 +357,12 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) vmr.vmr_id = id; vmr.vmr_pid = pid; if (proc_compose_imsg(ps, PROC_PARENT, -1, cmd, - imsg->hdr.peerid, -1, &vmr, sizeof(vmr)) == -1) + peerid, -1, &vmr, sizeof(vmr)) == -1) return (-1); break; default: if (proc_compose_imsg(ps, PROC_PARENT, -1, cmd, - imsg->hdr.peerid, -1, &res, sizeof(res)) == -1) + peerid, -1, &res, sizeof(res)) == -1) return (-1); break; } |