summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/vmd/config.c14
-rw-r--r--usr.sbin/vmd/control.c7
-rw-r--r--usr.sbin/vmd/proc.c4
-rw-r--r--usr.sbin/vmd/vmd.c33
-rw-r--r--usr.sbin/vmd/vmm.c16
5 files changed, 63 insertions, 11 deletions
diff --git a/usr.sbin/vmd/config.c b/usr.sbin/vmd/config.c
index 9ea87eb86e8..d39f3635c75 100644
--- a/usr.sbin/vmd/config.c
+++ b/usr.sbin/vmd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.34 2017/08/31 06:23:37 mlarkin Exp $ */
+/* $OpenBSD: config.c,v 1.35 2017/09/08 06:24:31 mlarkin Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -81,14 +81,18 @@ config_purge(struct vmd *env, unsigned int reset)
struct vmd_switch *vsw;
unsigned int what;
+ log_debug("%s: purging vms and switches from running config",
+ __func__);
/* Reset global configuration (prefix was verified before) */
(void)host(VMD_DHCP_PREFIX, &env->vmd_cfg.cfg_localprefix);
/* Reset other configuration */
what = ps->ps_what[privsep_process] & reset;
if (what & CONFIG_VMS && env->vmd_vms != NULL) {
- while ((vm = TAILQ_FIRST(env->vmd_vms)) != NULL)
+ while ((vm = TAILQ_FIRST(env->vmd_vms)) != NULL) {
+ log_debug("%s: calling vm_remove", __func__);
vm_remove(vm);
+ }
env->vmd_nvm = 0;
}
if (what & CONFIG_SWITCHES && env->vmd_switches != NULL) {
@@ -104,6 +108,7 @@ config_setconfig(struct vmd *env)
struct privsep *ps = &env->vmd_ps;
unsigned int id;
+ log_debug("%s: setting config", __func__);
for (id = 0; id < PROC_MAX; id++) {
if (id == privsep_process)
continue;
@@ -117,6 +122,7 @@ config_setconfig(struct vmd *env)
int
config_getconfig(struct vmd *env, struct imsg *imsg)
{
+ log_debug("%s: retrieving config", __func__);
IMSG_SIZE_CHECK(imsg, &env->vmd_cfg);
memcpy(&env->vmd_cfg, imsg->data, sizeof(env->vmd_cfg));
@@ -129,6 +135,7 @@ config_setreset(struct vmd *env, unsigned int reset)
struct privsep *ps = &env->vmd_ps;
unsigned int id;
+ log_debug("%s: resetting state", __func__);
for (id = 0; id < PROC_MAX; id++) {
if ((reset & ps->ps_what[id]) == 0 ||
id == privsep_process)
@@ -147,6 +154,7 @@ config_getreset(struct vmd *env, struct imsg *imsg)
IMSG_SIZE_CHECK(imsg, &mode);
memcpy(&mode, imsg->data, sizeof(mode));
+ log_debug("%s: resetting state", __func__);
config_purge(env, mode);
return (0);
@@ -374,6 +382,7 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, uint32_t peerid, uid_t uid)
free(tapfds);
}
+ log_debug("%s: calling vm_remove", __func__);
vm_remove(vm);
errno = saved_errno;
if (errno == 0)
@@ -406,6 +415,7 @@ config_getvm(struct privsep *ps, struct imsg *imsg)
imsg->fd = -1;
}
+ log_debug("%s: calling vm_remove", __func__);
vm_remove(vm);
if (errno == 0)
errno = EINVAL;
diff --git a/usr.sbin/vmd/control.c b/usr.sbin/vmd/control.c
index 1af8a0d5e14..1a3aefe7d49 100644
--- a/usr.sbin/vmd/control.c
+++ b/usr.sbin/vmd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.21 2017/07/15 05:05:36 pd Exp $ */
+/* $OpenBSD: control.c,v 1.22 2017/09/08 06:24:31 mlarkin Exp $ */
/*
* Copyright (c) 2010-2015 Reyk Floeter <reyk@openbsd.org>
@@ -401,9 +401,14 @@ control_dispatch_imsg(int fd, short event, void *arg)
goto fail;
memcpy(&vid, imsg.data, sizeof(vid));
vid.vid_uid = c->peercred.uid;
+ log_debug("%s id: %d, name: %s, uid: %d",
+ __func__, vid.vid_id, vid.vid_name,
+ vid.vid_uid);
if (proc_compose_imsg(ps, PROC_PARENT, -1,
imsg.hdr.type, fd, -1, &vid, sizeof(vid)) == -1) {
+ log_debug("%s: proc_compose_imsg failed",
+ __func__);
control_close(fd, cs);
return;
}
diff --git a/usr.sbin/vmd/proc.c b/usr.sbin/vmd/proc.c
index 183db93a678..afa9b223649 100644
--- a/usr.sbin/vmd/proc.c
+++ b/usr.sbin/vmd/proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.c,v 1.14 2017/05/29 12:56:26 benno Exp $ */
+/* $OpenBSD: proc.c,v 1.15 2017/09/08 06:24:31 mlarkin Exp $ */
/*
* Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org>
@@ -756,6 +756,8 @@ proc_compose_imsg(struct privsep *ps, enum privsep_procid id, int n,
proc_range(ps, id, &n, &m);
for (; n < m; n++) {
+ log_debug("%s: about to compose_event to proc %d",
+ __func__, id);
if (imsg_compose_event(&ps->ps_ievs[id][n],
type, peerid, ps->ps_instance + 1, fd, data, datalen) == -1)
return (-1);
diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c
index c7b9247d326..f1abc54d9a3 100644
--- a/usr.sbin/vmd/vmd.c
+++ b/usr.sbin/vmd/vmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmd.c,v 1.68 2017/08/20 21:15:32 pd Exp $ */
+/* $OpenBSD: vmd.c,v 1.69 2017/09/08 06:24:31 mlarkin Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -372,6 +372,8 @@ vmd_dispatch_vmm(int fd, struct privsep_proc *p, struct imsg *imsg)
case IMSG_VMDOP_TERMINATE_VM_RESPONSE:
IMSG_SIZE_CHECK(imsg, &vmr);
memcpy(&vmr, imsg->data, sizeof(vmr));
+ log_debug("%s: forwarding TERMINATE VM for vm id %d",
+ __func__, vmr.vmr_id);
proc_forward_imsg(ps, imsg, PROC_CONTROL, -1);
if ((vm = vm_getbyvmid(vmr.vmr_id)) == NULL)
break;
@@ -392,15 +394,24 @@ vmd_dispatch_vmm(int fd, struct privsep_proc *p, struct imsg *imsg)
case IMSG_VMDOP_TERMINATE_VM_EVENT:
IMSG_SIZE_CHECK(imsg, &vmr);
memcpy(&vmr, imsg->data, sizeof(vmr));
+ log_debug("%s: handling TERMINATE_EVENT for vm id %d",
+ __func__, vmr.vmr_id);
if ((vm = vm_getbyvmid(vmr.vmr_id)) == NULL)
break;
if (vmr.vmr_result == 0) {
- if (vm->vm_from_config)
+ if (vm->vm_from_config) {
+ log_debug("%s: about to stop vm id %d",
+ __func__, vm->vm_vmid);
vm_stop(vm, 0);
- else
+ } else {
+ log_debug("%s: about to remove vm %d",
+ __func__, vm->vm_vmid);
vm_remove(vm);
+ }
} else if (vmr.vmr_result == EAGAIN) {
/* Stop VM instance but keep the tty open */
+ log_debug("%s: about to stop vm id %d with tty open",
+ __func__, vm->vm_vmid);
vm_stop(vm, 1);
config_setvm(ps, vm, (uint32_t)-1, 0);
}
@@ -425,6 +436,8 @@ vmd_dispatch_vmm(int fd, struct privsep_proc *p, struct imsg *imsg)
}
if (proc_compose_imsg(ps, PROC_CONTROL, -1, imsg->hdr.type,
imsg->hdr.peerid, -1, &vir, sizeof(vir)) == -1) {
+ log_debug("%s: GET_INFO_VM failed for vm %d, removing",
+ __func__, vm->vm_vmid);
vm_remove(vm);
return (-1);
}
@@ -453,6 +466,8 @@ vmd_dispatch_vmm(int fd, struct privsep_proc *p, struct imsg *imsg)
IMSG_VMDOP_GET_INFO_VM_DATA,
imsg->hdr.peerid, -1, &vir,
sizeof(vir)) == -1) {
+ log_debug("%s: GET_INFO_VM_END failed",
+ __func__);
vm_remove(vm);
return (-1);
}
@@ -592,6 +607,7 @@ vmd_sighdlr(int sig, short event, void *arg)
{
if (privsep_process != PROC_PARENT)
return;
+ log_debug("%s: handling signal", __func__);
switch (sig) {
case SIGHUP:
@@ -862,8 +878,11 @@ vmd_reload(unsigned int reset, const char *filename)
if (reload) {
TAILQ_FOREACH_SAFE(vm, env->vmd_vms, vm_entry, next_vm) {
- if (vm->vm_running == 0)
+ if (vm->vm_running == 0) {
+ log_debug("%s: calling vm_remove",
+ __func__);
vm_remove(vm);
+ }
}
/* Update shared global configuration in all children */
@@ -914,6 +933,7 @@ vmd_shutdown(void)
{
struct vmd_vm *vm, *vm_next;
+ log_debug("%s: performing shutdown", __func__);
TAILQ_FOREACH_SAFE(vm, env->vmd_vms, vm_entry, vm_next) {
vm_remove(vm);
}
@@ -1011,6 +1031,7 @@ vm_stop(struct vmd_vm *vm, int keeptty)
if (vm == NULL)
return;
+ log_debug("%s: stopping vm %d", __func__, vm->vm_vmid);
vm->vm_running = 0;
vm->vm_shutdown = 0;
@@ -1051,7 +1072,10 @@ vm_remove(struct vmd_vm *vm)
if (vm == NULL)
return;
+ log_debug("%s: removing vm id %d from running config",
+ __func__, vm->vm_vmid);
TAILQ_REMOVE(env->vmd_vms, vm, vm_entry);
+ log_debug("%s: calling vm_stop", __func__);
vm_stop(vm, 0);
free(vm);
}
@@ -1178,6 +1202,7 @@ vm_register(struct privsep *ps, struct vmop_create_params *vmc,
/* Assign a new internal Id if not specified */
vm->vm_vmid = id == 0 ? env->vmd_nvm : id;
+ log_debug("%s: registering vm %d", __func__, vm->vm_vmid);
TAILQ_INSERT_TAIL(env->vmd_vms, vm, vm_entry);
*ret_vm = vm;
diff --git a/usr.sbin/vmd/vmm.c b/usr.sbin/vmd/vmm.c
index 73a895f726e..5bbab0597d7 100644
--- a/usr.sbin/vmd/vmm.c
+++ b/usr.sbin/vmd/vmm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmm.c,v 1.72 2017/08/15 15:10:35 pd Exp $ */
+/* $OpenBSD: vmm.c,v 1.73 2017/09/08 06:24:31 mlarkin Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@@ -146,6 +146,7 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
IMSG_SIZE_CHECK(imsg, &vtp);
memcpy(&vtp, imsg->data, sizeof(vtp));
id = vtp.vtp_vm_id;
+ log_debug("%s: recv'ed TERMINATE_VM for %d", __func__, id);
if (id == 0) {
res = ENOENT;
@@ -278,8 +279,11 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
case IMSG_VMDOP_START_VM_RESPONSE:
if (res != 0) {
/* Remove local reference if it exists */
- if ((vm = vm_getbyvmid(imsg->hdr.peerid)) != NULL)
+ if ((vm = vm_getbyvmid(imsg->hdr.peerid)) != NULL) {
+ log_debug("%s: removing vm, START_VM_RESPONSE",
+ __func__);
vm_remove(vm);
+ }
}
if (id == 0)
id = imsg->hdr.peerid;
@@ -314,6 +318,7 @@ vmm_sighdlr(int sig, short event, void *arg)
struct vmd_vm *vm;
struct vm_terminate_params vtp;
+ log_debug("%s: handling signal", __func__);
switch (sig) {
case SIGCHLD:
do {
@@ -355,6 +360,7 @@ vmm_sighdlr(int sig, short event, void *arg)
log_warnx("could not terminate VM %u",
vm->vm_vmid);
+ log_debug("%s: calling vm_remove", __func__);
vm_remove(vm);
} else
fatalx("unexpected cause of SIGCHLD");
@@ -381,6 +387,7 @@ vmm_shutdown(void)
/* XXX suspend or request graceful shutdown */
(void)terminate_vm(&vtp);
+ log_debug("%s: calling vm_remove", __func__);
vm_remove(vm);
}
}
@@ -465,8 +472,10 @@ vmm_dispatch_vm(int fd, short event, void *arg)
case IMSG_VMDOP_SEND_VM_RESPONSE:
IMSG_SIZE_CHECK(&imsg, &vmr);
memcpy(&vmr, imsg.data, sizeof(vmr));
- if(!vmr.vmr_result)
+ if(!vmr.vmr_result) {
+ log_debug("%s: calling vm_remove", __func__);
vm_remove(vm);
+ }
case IMSG_VMDOP_PAUSE_VM_RESPONSE:
case IMSG_VMDOP_UNPAUSE_VM_RESPONSE:
for (i = 0; i < sizeof(procs); i++) {
@@ -639,6 +648,7 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id)
return (0);
err:
+ log_debug("%s: calling vm_remove", __func__);
vm_remove(vm);
return (ret);