summaryrefslogtreecommitdiff
path: root/usr.sbin/vmctl
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2017-04-06 18:07:14 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2017-04-06 18:07:14 +0000
commit3801c20c40b7c6a41c59e74b30fe0bd1a17322fd (patch)
tree509b36fb5f993b6b08aa30b57ae604d82f038270 /usr.sbin/vmctl
parent1ea85205533926f391fc2bc566af965c8f6267bf (diff)
Do not expose vmm(4) VM IDs to the user, use vmd(8)'s IDs instead.
Each VM has two IDs: one from the kernel (vmm) and a different one from userland (vmd). The vmm ID is not consistent and incremented on every boot during runtimg of the host system. The vmd ID remains the same during the lifetime of a configured VM, even after reboots. Configured VMs will even get and keep their IDs when the configuration is loaded. This is more what users expect. Pointed out and tested by otto@ OK deraadt@
Diffstat (limited to 'usr.sbin/vmctl')
-rw-r--r--usr.sbin/vmctl/main.c11
-rw-r--r--usr.sbin/vmctl/vmctl.c14
-rw-r--r--usr.sbin/vmctl/vmctl.h5
3 files changed, 17 insertions, 13 deletions
diff --git a/usr.sbin/vmctl/main.c b/usr.sbin/vmctl/main.c
index c50cdaceec0..da27fd6c913 100644
--- a/usr.sbin/vmctl/main.c
+++ b/usr.sbin/vmctl/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.24 2017/03/25 16:28:25 reyk Exp $ */
+/* $OpenBSD: main.c,v 1.25 2017/04/06 18:07:13 reyk Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -194,8 +194,8 @@ vmmaction(struct parse_result *res)
switch (res->action) {
case CMD_START:
- ret = vm_start(res->name, res->size, res->nifs, res->nets,
- res->ndisks, res->disks, res->path);
+ ret = vm_start(res->id, res->name, res->size, res->nifs,
+ res->nets, res->ndisks, res->disks, res->path);
if (ret) {
errno = ret;
err(1, "start VM operation failed");
@@ -533,8 +533,9 @@ ctl_start(struct parse_result *res, int argc, char *argv[])
if (argc < 2)
ctl_usage(res->ctl);
- if ((res->name = strdup(argv[1])) == NULL)
- errx(1, "strdup");
+ if (parse_vmid(res, argv[1]) == -1)
+ errx(1, "invalid id: %s", argv[1]);
+
argc--;
argv++;
diff --git a/usr.sbin/vmctl/vmctl.c b/usr.sbin/vmctl/vmctl.c
index 038f3b11c92..39d1615d8f2 100644
--- a/usr.sbin/vmctl/vmctl.c
+++ b/usr.sbin/vmctl/vmctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmctl.c,v 1.28 2017/03/30 03:39:35 claudio Exp $ */
+/* $OpenBSD: vmctl.c,v 1.29 2017/04/06 18:07:13 reyk Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
@@ -52,6 +52,7 @@ int info_console;
* Request vmd to start the VM defined by the supplied parameters
*
* Parameters:
+ * start_id: optional ID of the VM
* name: optional name of the VM
* memsize: memory size (MB) of the VM to create
* nnics: number of vionet network interfaces to create
@@ -65,8 +66,8 @@ int info_console;
* ENOMEM if a memory allocation failure occurred.
*/
int
-vm_start(const char *name, int memsize, int nnics, char **nics,
- int ndisks, char **disks, char *kernel)
+vm_start(uint32_t start_id, const char *name, int memsize, int nnics,
+ char **nics, int ndisks, char **disks, char *kernel)
{
struct vmop_create_params *vmc;
struct vm_create_params *vcp;
@@ -117,6 +118,7 @@ vm_start(const char *name, int memsize, int nnics, char **nics,
vcp->vcp_ncpus = 1;
vcp->vcp_ndisks = ndisks;
vcp->vcp_nnics = nnics;
+ vcp->vcp_id = start_id;
for (i = 0 ; i < ndisks; i++)
strlcpy(vcp->vcp_disks[i], disks[i], VMM_MAX_PATH_DISK);
@@ -410,7 +412,7 @@ print_vm_info(struct vmop_info_result *list, size_t ct)
(void)fmt_scaled(vir->vir_memory_size * 1024 * 1024,
maxmem);
- if (vir->vir_id != 0) {
+ if (vir->vir_creator_pid != 0 && vir->vir_id != 0) {
if (*vmi->vir_ttyname == '\0')
tty = "-";
/* get tty - skip /dev/ path */
@@ -427,8 +429,8 @@ print_vm_info(struct vmop_info_result *list, size_t ct)
tty, user, vir->vir_name);
} else {
/* disabled vm */
- printf("%5s %5s %5zd %7s %7s %7s %12s %s\n",
- "-", "-",
+ printf("%5u %5s %5zd %7s %7s %7s %12s %s\n",
+ vir->vir_id, "-",
vir->vir_ncpus, maxmem, curmem,
"-", user, vir->vir_name);
}
diff --git a/usr.sbin/vmctl/vmctl.h b/usr.sbin/vmctl/vmctl.h
index e47944f3b12..58d03d20bd1 100644
--- a/usr.sbin/vmctl/vmctl.h
+++ b/usr.sbin/vmctl/vmctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmctl.h,v 1.13 2017/03/01 21:22:57 reyk Exp $ */
+/* $OpenBSD: vmctl.h,v 1.14 2017/04/06 18:07:13 reyk Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -77,7 +77,8 @@ __dead void
/* vmctl.c */
int create_imagefile(const char *, long);
-int vm_start(const char *, int, int, char **, int, char **, char *);
+int vm_start(uint32_t, const char *, int, int, char **, int,
+ char **, char *);
int vm_start_complete(struct imsg *, int *, int);
void terminate_vm(uint32_t, const char *);
int terminate_vm_complete(struct imsg *, int *);