diff options
-rw-r--r-- | usr.sbin/vmctl/vmctl.c | 22 | ||||
-rw-r--r-- | usr.sbin/vmd/parse.y | 14 | ||||
-rw-r--r-- | usr.sbin/vmd/vmd.c | 39 | ||||
-rw-r--r-- | usr.sbin/vmd/vmd.h | 6 |
4 files changed, 66 insertions, 15 deletions
diff --git a/usr.sbin/vmctl/vmctl.c b/usr.sbin/vmctl/vmctl.c index a590220987f..c4861260513 100644 --- a/usr.sbin/vmctl/vmctl.c +++ b/usr.sbin/vmctl/vmctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmctl.c,v 1.16 2016/10/06 16:53:39 reyk Exp $ */ +/* $OpenBSD: vmctl.c,v 1.17 2016/11/22 11:31:38 edd Exp $ */ /* * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> @@ -353,11 +353,21 @@ print_vm_info(struct vmop_info_result *list, size_t ct) for (i = 0; i < ct; i++) { vir = &list[i].vir_info; if (check_info_id(vir->vir_name, vir->vir_id)) { - printf("%5u %5u %5zd %7zdMB %7zdMB %*s %s\n", - vir->vir_id, vir->vir_creator_pid, - vir->vir_ncpus, vir->vir_memory_size, - vir->vir_used_size / 1024 / 1024 , VM_TTYNAME_MAX, - list[i].vir_ttyname, vir->vir_name); + if (vir->vir_id != 0) { + /* running vm */ + printf("%5u %5u %5zd %7zdMB %7zdMB %*s %s\n", + vir->vir_id, vir->vir_creator_pid, + vir->vir_ncpus, vir->vir_memory_size, + vir->vir_used_size / 1024 / 1024 , VM_TTYNAME_MAX, + list[i].vir_ttyname, vir->vir_name); + } else { + /* disabled vm */ + printf("%5s %5s %5zd %7zdMB %9s %*s %s\n", + "-", "-", + vir->vir_ncpus, vir->vir_memory_size, + "-", VM_TTYNAME_MAX, + "-", vir->vir_name); + } } if (check_info_id(vir->vir_name, vir->vir_id) > 0) { for (j = 0; j < vir->vir_ncpus; j++) { diff --git a/usr.sbin/vmd/parse.y b/usr.sbin/vmd/parse.y index 10dc3db03bc..691f7c8e2b6 100644 --- a/usr.sbin/vmd/parse.y +++ b/usr.sbin/vmd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.15 2016/11/04 15:16:44 reyk Exp $ */ +/* $OpenBSD: parse.y,v 1.16 2016/11/22 11:31:38 edd Exp $ */ /* * Copyright (c) 2007-2016 Reyk Floeter <reyk@openbsd.org> @@ -267,10 +267,7 @@ vm : VM string { if (vcp_nnics > vcp->vcp_nnics) vcp->vcp_nnics = vcp_nnics; - if (vcp_disable) { - log_debug("%s:%d: vm \"%s\" skipped (disabled)", - file->name, yylval.lineno, vcp->vcp_name); - } else if (!env->vmd_noaction) { + if (!env->vmd_noaction) { ret = vm_register(&env->vmd_ps, &vmc, &vm, 0); if (ret == -1 && errno == EALREADY) { log_debug("%s:%d: vm \"%s\"" @@ -284,9 +281,12 @@ vm : VM string { vcp->vcp_name); YYERROR; } else { - log_debug("%s:%d: vm \"%s\" registered", + if (vcp_disable) + vm->vm_disabled = 1; + log_debug("%s:%d: vm \"%s\" registered (%s)", file->name, yylval.lineno, - vcp->vcp_name); + vcp->vcp_name, + vcp_disable ? "disabled" : "enabled"); } } } diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c index 39ac0e3c44f..c89b66ca5ba 100644 --- a/usr.sbin/vmd/vmd.c +++ b/usr.sbin/vmd/vmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.c,v 1.39 2016/11/04 15:16:44 reyk Exp $ */ +/* $OpenBSD: vmd.c,v 1.40 2016/11/22 11:31:38 edd Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -235,6 +235,31 @@ vmd_dispatch_vmm(int fd, struct privsep_proc *p, struct imsg *imsg) } break; case IMSG_VMDOP_GET_INFO_VM_END_DATA: + /* + * PROC_VMM has responded with the *running* VMs, now we + * append the others. These use the special value 0 for their + * kernel id to indicate that they are not running. + */ + TAILQ_FOREACH(vm, env->vmd_vms, vm_entry) { + if (!vm->vm_running) { + memset(&vir, 0, sizeof(vir)); + vir.vir_info.vir_id = 0; + strlcpy(vir.vir_info.vir_name, + vm->vm_params.vmc_params.vcp_name, + VMM_MAX_NAME_LEN); + vir.vir_info.vir_memory_size = + vm->vm_params.vmc_params.vcp_memranges[0].vmr_size; + vir.vir_info.vir_ncpus = + vm->vm_params.vmc_params.vcp_ncpus; + if (proc_compose_imsg(ps, PROC_CONTROL, -1, + IMSG_VMDOP_GET_INFO_VM_DATA, + imsg->hdr.peerid, -1, &vir, + sizeof(vir)) == -1) { + vm_remove(vm); + return (-1); + } + } + } IMSG_SIZE_CHECK(imsg, &res); proc_forward_imsg(ps, imsg, PROC_CONTROL, -1); break; @@ -466,6 +491,12 @@ vmd_configure(void) } TAILQ_FOREACH(vm, env->vmd_vms, vm_entry) { + if (vm->vm_disabled) { + log_debug("%s: not creating vm %s (disabled)", + __func__, + vm->vm_params.vmc_params.vcp_name); + continue; + } res = config_setvm(&env->vmd_ps, vm, -1); if (res == -1) { log_warn("%s: failed to create vm %s", @@ -516,6 +547,12 @@ vmd_reload(unsigned int reset, const char *filename) TAILQ_FOREACH(vm, env->vmd_vms, vm_entry) { if (vm->vm_running == 0) { + if (vm->vm_disabled) { + log_debug("%s: not creating vm %s" + " (disabled)", __func__, + vm->vm_params.vmc_params.vcp_name); + continue; + } res = config_setvm(&env->vmd_ps, vm, -1); if (res == -1) { log_warn("%s: failed to create vm %s", diff --git a/usr.sbin/vmd/vmd.h b/usr.sbin/vmd/vmd.h index 47ce36e0ad6..ab414049e80 100644 --- a/usr.sbin/vmd/vmd.h +++ b/usr.sbin/vmd/vmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.h,v 1.34 2016/11/04 15:16:44 reyk Exp $ */ +/* $OpenBSD: vmd.h,v 1.35 2016/11/22 11:31:38 edd Exp $ */ /* * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> @@ -128,6 +128,7 @@ TAILQ_HEAD(switchlist, vmd_switch); struct vmd_vm { struct vmop_create_params vm_params; pid_t vm_pid; + /* Userspace ID of VM. The user never sees this */ uint32_t vm_vmid; int vm_kernel; int vm_disks[VMM_MAX_DISKS_PER_VM]; @@ -135,7 +136,10 @@ struct vmd_vm { char *vm_ttyname; int vm_tty; uint32_t vm_peerid; + /* When set, VM is running now (PROC_PARENT only) */ int vm_running; + /* When set, VM is not started by default (PROC_PARENT only) */ + int vm_disabled; TAILQ_ENTRY(vmd_vm) vm_entry; }; TAILQ_HEAD(vmlist, vmd_vm); |