- Turn tracing messages into DPRINTF (only compiled with DEBUG).
- Pass __func__ to vm_stop and vm_remove: this way we can track who
called the function in the async context. It replaces the manual
log_debug in front of each vm_stop/vm_remove. This debug logging
trick can be removed in the future once we are more confident about
it.
OK ccardenas@ mlarkin@
-/* $OpenBSD: config.c,v 1.44 2018/06/19 18:15:01 reyk Exp $ */
+/* $OpenBSD: config.c,v 1.45 2018/07/10 16:15:51 reyk Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
struct vmd_switch *vsw;
unsigned int what;
- log_debug("%s: %s purging vms and switches",
+ DPRINTF("%s: %s purging vms and switches",
__func__, ps->ps_title[privsep_process]);
+
/* Reset global configuration (prefix was verified before) */
(void)host(VMD_DHCP_PREFIX, &env->vmd_cfg.cfg_localprefix);
what = ps->ps_what[privsep_process] & reset;
if (what & CONFIG_VMS && env->vmd_vms != NULL) {
while ((vm = TAILQ_FIRST(env->vmd_vms)) != NULL) {
- log_debug("%s: calling vm_remove", __func__);
- vm_remove(vm);
+ vm_remove(vm, __func__);
}
env->vmd_nvm = 0;
}
struct privsep *ps = &env->vmd_ps;
unsigned int id;
- log_debug("%s: setting config", __func__);
+ DPRINTF("%s: setting config", __func__);
+
for (id = 0; id < PROC_MAX; id++) {
if (id == privsep_process)
continue;
struct privsep *ps = &env->vmd_ps;
unsigned int id;
- log_debug("%s: resetting state", __func__);
+ DPRINTF("%s: resetting state", __func__);
+
for (id = 0; id < PROC_MAX; id++) {
if ((reset & ps->ps_what[id]) == 0 ||
id == privsep_process)
int
config_getreset(struct vmd *env, struct imsg *imsg)
{
- struct privsep *ps = &env->vmd_ps;
unsigned int mode;
IMSG_SIZE_CHECK(imsg, &mode);
memcpy(&mode, imsg->data, sizeof(mode));
log_debug("%s: %s resetting state",
- __func__, ps->ps_title[privsep_process]);
+ __func__, env->vmd_ps.ps_title[privsep_process]);
+
config_purge(env, mode);
return (0);
}
if (vm->vm_from_config) {
- log_debug("%s: calling stop vm %d", __func__, vm->vm_vmid);
- vm_stop(vm, 0);
+ vm_stop(vm, 0, __func__);
} else {
- log_debug("%s: calling remove vm %d", __func__, vm->vm_vmid);
- vm_remove(vm);
+ vm_remove(vm, __func__);
}
errno = saved_errno;
if (errno == 0)
imsg->fd = -1;
}
- log_debug("%s: calling vm_remove", __func__);
- vm_remove(vm);
+ vm_remove(vm, __func__);
if (errno == 0)
errno = EINVAL;
if (n >= vm->vm_params.vmc_params.vcp_ndisks ||
vm->vm_disks[n] != -1 || imsg->fd == -1) {
- log_debug("invalid disk id");
+ log_warnx("invalid disk id");
errno = EINVAL;
return (-1);
}
memcpy(&n, imsg->data, sizeof(n));
if (n >= vm->vm_params.vmc_params.vcp_nnics ||
vm->vm_ifs[n].vif_fd != -1 || imsg->fd == -1) {
- log_debug("invalid interface id");
+ log_warnx("invalid interface id");
goto fail;
}
vm->vm_ifs[n].vif_fd = imsg->fd;
}
if (imsg->fd == -1) {
- log_debug("invalid cdrom id");
+ log_warnx("invalid cdrom id");
goto fail;
}
-/* $OpenBSD: vmd.c,v 1.87 2018/06/26 10:00:08 reyk Exp $ */
+/* $OpenBSD: vmd.c,v 1.88 2018/07/10 16:15:51 reyk Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
errno = vmr.vmr_result;
log_warn("%s: failed to foward vm result",
vcp->vcp_name);
- vm_remove(vm);
+ vm_remove(vm, __func__);
return (-1);
}
}
if (vmr.vmr_result) {
errno = vmr.vmr_result;
log_warn("%s: failed to start vm", vcp->vcp_name);
- vm_remove(vm);
+ vm_remove(vm, __func__);
break;
}
/* Now configure all the interfaces */
if (vm_priv_ifconfig(ps, vm) == -1) {
log_warn("%s: failed to configure vm", vcp->vcp_name);
- vm_remove(vm);
+ vm_remove(vm, __func__);
break;
}
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",
+ DPRINTF("%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)
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 ret %d",
+ DPRINTF("%s: handling TERMINATE_EVENT for vm id %d ret %d",
__func__, vmr.vmr_id, vmr.vmr_result);
if ((vm = vm_getbyvmid(vmr.vmr_id)) == NULL) {
log_debug("%s: vm %d is no longer available",
}
if (vmr.vmr_result != EAGAIN) {
if (vm->vm_from_config) {
- log_debug("%s: about to stop vm id %d",
- __func__, vm->vm_vmid);
- vm_stop(vm, 0);
+ vm_stop(vm, 0, __func__);
} else {
- log_debug("%s: about to remove vm %d",
- __func__, vm->vm_vmid);
- vm_remove(vm);
+ vm_remove(vm, __func__);
}
} else {
/* 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);
+ vm_stop(vm, 1, __func__);
config_setvm(ps, vm, (uint32_t)-1, vm->vm_uid);
}
break;
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);
+ vm_remove(vm, __func__);
return (-1);
}
break;
sizeof(vir)) == -1) {
log_debug("%s: GET_INFO_VM_END failed",
__func__);
- vm_remove(vm);
+ vm_remove(vm, __func__);
return (-1);
}
}
TAILQ_FOREACH_SAFE(vm, env->vmd_vms, vm_entry,
next_vm) {
if (vm->vm_running == 0) {
- log_debug("%s: calling vm_remove",
+ DPRINTF("%s: calling vm_remove",
__func__);
- vm_remove(vm);
+ vm_remove(vm, __func__);
}
}
}
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);
+ vm_remove(vm, __func__);
}
proc_kill(&env->vmd_ps);
}
void
-vm_stop(struct vmd_vm *vm, int keeptty)
+vm_stop(struct vmd_vm *vm, int keeptty, const char *caller)
{
+ struct privsep *ps = &env->vmd_ps;
unsigned int i;
if (vm == NULL)
return;
- log_debug("%s: stopping vm %d", __func__, vm->vm_vmid);
+ log_debug("%s: %s %s stopping vm %d%s",
+ __func__, ps->ps_title[privsep_process], caller,
+ vm->vm_vmid, keeptty ? ", keeping tty open" : "");
+
vm->vm_running = 0;
vm->vm_shutdown = 0;
}
void
-vm_remove(struct vmd_vm *vm)
+vm_remove(struct vmd_vm *vm, const char *caller)
{
+ struct privsep *ps = &env->vmd_ps;
+
if (vm == NULL)
return;
- log_debug("%s: removing vm id %d from running config",
- __func__, vm->vm_vmid);
+ log_debug("%s: %s %s removing vm %d from running config",
+ __func__, ps->ps_title[privsep_process], caller,
+ vm->vm_vmid);
+
TAILQ_REMOVE(env->vmd_vms, vm, vm_entry);
- log_debug("%s: calling vm_stop", __func__);
- vm_stop(vm, 0);
+
+ vm_stop(vm, 0, caller);
free(vm);
}
-/* $OpenBSD: vmd.h,v 1.70 2018/07/09 08:43:09 mlarkin Exp $ */
+/* $OpenBSD: vmd.h,v 1.71 2018/07/10 16:15:51 reyk Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
uint32_t vm_vmid2id(uint32_t, struct vmd_vm *);
struct vmd_vm *vm_getbyname(const char *);
struct vmd_vm *vm_getbypid(pid_t);
-void vm_stop(struct vmd_vm *, int);
-void vm_remove(struct vmd_vm *);
+void vm_stop(struct vmd_vm *, int, const char *);
+void vm_remove(struct vmd_vm *, const char *);
int vm_register(struct privsep *, struct vmop_create_params *,
struct vmd_vm **, uint32_t, uid_t);
int vm_checkperm(struct vmd_vm *, uid_t);
-/* $OpenBSD: vmm.c,v 1.81 2018/04/13 17:12:44 martijn Exp $ */
+/* $OpenBSD: vmm.c,v 1.82 2018/07/10 16:15:51 reyk Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
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);
+
+ DPRINTF("%s: recv'ed TERMINATE_VM for %d", __func__, id);
if (id == 0) {
res = ENOENT;
} else if ((vm = vm_getbyvmid(id)) != NULL) {
if (vm->vm_shutdown == 0) {
- log_debug("%s: sending shutdown req to vm %d",
- __func__, id);
+ log_debug("%s: sending shutdown request"
+ " to vm %d", __func__, id);
/*
* Request reboot but mark the VM as shutting
if ((vm = vm_getbyvmid(imsg->hdr.peerid)) != NULL) {
log_debug("%s: removing vm, START_VM_RESPONSE",
__func__);
- vm_remove(vm);
+ vm_remove(vm, __func__);
}
}
if (id == 0)
log_warnx("could not terminate VM %u",
vm->vm_vmid);
- log_debug("%s: calling vm_remove", __func__);
- vm_remove(vm);
+ vm_remove(vm, __func__);
} else
fatalx("unexpected cause of SIGCHLD");
} while (pid > 0 || (pid == -1 && errno == EINTR));
/* XXX suspend or request graceful shutdown */
(void)terminate_vm(&vtp);
- log_debug("%s: calling vm_remove", __func__);
- vm_remove(vm);
+ vm_remove(vm, __func__);
}
}
IMSG_SIZE_CHECK(&imsg, &vmr);
memcpy(&vmr, imsg.data, sizeof(vmr));
if (!vmr.vmr_result) {
- log_debug("%s: calling vm_remove", __func__);
- vm_remove(vm);
+ vm_remove(vm, __func__);
}
case IMSG_VMDOP_PAUSE_VM_RESPONSE:
case IMSG_VMDOP_UNPAUSE_VM_RESPONSE:
return (0);
err:
- log_debug("%s: calling vm_remove", __func__);
- vm_remove(vm);
+ vm_remove(vm, __func__);
return (ret);
}