summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Lievisse Adriaanse <jasper@cvs.openbsd.org>2019-05-11 23:07:47 +0000
committerJasper Lievisse Adriaanse <jasper@cvs.openbsd.org>2019-05-11 23:07:47 +0000
commita35a7bbd630cde023fe3cc894f2c0138a2c622d6 (patch)
treec6100a24882f1b28c97becf20c4d90fcc8981283
parentef43555774ddeef0c55f3a7f94be011175d08a5d (diff)
report vm state through 'vmctl status'; whereas previously this would display the state of
the vcpu (which is why it got removed), it now actually reports the correct state (running, stopped, disabled, paused, etc) ok ccardenas@ mlarkin@
-rw-r--r--usr.sbin/vmctl/vmctl.c48
-rw-r--r--usr.sbin/vmctl/vmctl.h4
-rw-r--r--usr.sbin/vmd/vmd.c14
-rw-r--r--usr.sbin/vmd/vmd.h3
4 files changed, 48 insertions, 21 deletions
diff --git a/usr.sbin/vmctl/vmctl.c b/usr.sbin/vmctl/vmctl.c
index f1610d9959b..efdc2a23329 100644
--- a/usr.sbin/vmctl/vmctl.c
+++ b/usr.sbin/vmctl/vmctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmctl.c,v 1.66 2019/04/02 03:58:57 kn Exp $ */
+/* $OpenBSD: vmctl.c,v 1.67 2019/05/11 23:07:46 jasper Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
@@ -703,6 +703,34 @@ add_info(struct imsg *imsg, int *ret)
}
/*
+ * vm_state
+ *
+ * Returns a string representing the current VM state, note that the order
+ * matters. A paused VM does have the VM_STATE_RUNNING bit set, but
+ * VM_STATE_PAUSED is more significant to report.
+ *
+ * Parameters
+ * vm_state: mask indicating the vm state
+ */
+const char *
+vm_state(unsigned int mask)
+{
+ /* Presence of absence of other flags */
+ if (!mask)
+ return "stopped";
+ else if (mask & VM_STATE_PAUSED)
+ return "paused";
+ else if (mask & VM_STATE_SHUTDOWN)
+ return "stopping";
+ else if (mask & VM_STATE_RUNNING)
+ return "running";
+ else if (mask & VM_STATE_DISABLED)
+ return "disabled";
+
+ return "unknown";
+}
+
+/*
* print_vm_info
*
* Prints the vm information returned from vmd in 'list' to stdout.
@@ -724,8 +752,8 @@ print_vm_info(struct vmop_info_result *list, size_t ct)
const char *name;
int running;
- printf("%5s %5s %5s %7s %7s %7s %12s %s\n", "ID", "PID", "VCPUS",
- "MAXMEM", "CURMEM", "TTY", "OWNER", "NAME");
+ printf("%5s %5s %5s %7s %7s %7s %12s %8s %s\n", "ID", "PID", "VCPUS",
+ "MAXMEM", "CURMEM", "TTY", "OWNER", "STATE", "NAME");
for (i = 0; i < ct; i++) {
vmi = &list[i];
@@ -770,22 +798,20 @@ print_vm_info(struct vmop_info_result *list, size_t ct)
(void)fmt_scaled(vir->vir_used_size, curmem);
/* running vm */
- printf("%5u %5u %5zd %7s %7s %7s %12s %s\n",
+ printf("%5u %5u %5zd %7s %7s %7s %12s %8s %s\n",
vir->vir_id, vir->vir_creator_pid,
vir->vir_ncpus, maxmem, curmem,
- tty, user, vir->vir_name);
+ tty, user, vm_state(vmi->vir_state),
+ vir->vir_name);
} else {
/* disabled vm */
- printf("%5u %5s %5zd %7s %7s %7s %12s %s\n",
+ printf("%5u %5s %5zd %7s %7s %7s %12s %8s %s\n",
vir->vir_id, "-",
vir->vir_ncpus, maxmem, curmem,
- "-", user, vir->vir_name);
+ "-", user, vm_state(vmi->vir_state),
+ vir->vir_name);
}
}
- if (check_info_id(vir->vir_name, vir->vir_id) > 0) {
- printf("STATE: %s\n",
- running ? "RUNNING" : "STOPPED");
- }
}
}
diff --git a/usr.sbin/vmctl/vmctl.h b/usr.sbin/vmctl/vmctl.h
index 613621e8a1a..e20ce1a43d4 100644
--- a/usr.sbin/vmctl/vmctl.h
+++ b/usr.sbin/vmctl/vmctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmctl.h,v 1.31 2019/05/10 18:11:27 jasper Exp $ */
+/* $OpenBSD: vmctl.h,v 1.32 2019/05/11 23:07:46 jasper Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -108,6 +108,8 @@ void vm_receive(uint32_t, const char *);
int check_info_id(const char *, uint32_t);
void get_info_vm(uint32_t, const char *, enum actions, unsigned int);
int add_info(struct imsg *, int *);
+const char
+ *vm_state(unsigned int);
void print_vm_info(struct vmop_info_result *, size_t);
void terminate_all(struct vmop_info_result *, size_t, unsigned int);
__dead void
diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c
index 197566df4ef..8d4ece30c7a 100644
--- a/usr.sbin/vmd/vmd.c
+++ b/usr.sbin/vmd/vmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmd.c,v 1.111 2019/05/11 19:59:32 jasper Exp $ */
+/* $OpenBSD: vmd.c,v 1.112 2019/05/11 23:07:46 jasper Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -484,14 +484,9 @@ vmd_dispatch_vmm(int fd, struct privsep_proc *p, struct imsg *imsg)
if (vm->vm_ttyname != NULL)
strlcpy(vir.vir_ttyname, vm->vm_ttyname,
sizeof(vir.vir_ttyname));
- if (vm->vm_state & VM_STATE_SHUTDOWN) {
- /* XXX there might be a nicer way */
- (void)strlcat(vir.vir_info.vir_name,
- " - stopping",
- sizeof(vir.vir_info.vir_name));
- }
- log_debug("%s: vm: %d, vm_state: 0x%x",
+ log_debug("%s: running vm: %d, vm_state: 0x%x",
__func__, vm->vm_vmid, vm->vm_state);
+ vir.vir_state = vm->vm_state;
/* get the user id who started the vm */
vir.vir_uid = vm->vm_uid;
vir.vir_gid = vm->vm_params.vmc_owner.gid;
@@ -525,6 +520,9 @@ vmd_dispatch_vmm(int fd, struct privsep_proc *p, struct imsg *imsg)
/* get the configured user id for this vm */
vir.vir_uid = vm->vm_params.vmc_owner.uid;
vir.vir_gid = vm->vm_params.vmc_owner.gid;
+ log_debug("%s: vm: %d, vm_state: 0x%x",
+ __func__, vm->vm_vmid, vm->vm_state);
+ vir.vir_state = vm->vm_state;
if (proc_compose_imsg(ps, PROC_CONTROL, -1,
IMSG_VMDOP_GET_INFO_VM_DATA,
imsg->hdr.peerid, -1, &vir,
diff --git a/usr.sbin/vmd/vmd.h b/usr.sbin/vmd/vmd.h
index b9a2ac28d0f..7e40b38f51d 100644
--- a/usr.sbin/vmd/vmd.h
+++ b/usr.sbin/vmd/vmd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmd.h,v 1.93 2019/05/11 19:58:02 jasper Exp $ */
+/* $OpenBSD: vmd.h,v 1.94 2019/05/11 23:07:46 jasper Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@@ -134,6 +134,7 @@ struct vmop_info_result {
char vir_ttyname[VM_TTYNAME_MAX];
uid_t vir_uid;
int64_t vir_gid;
+ unsigned int vir_state;
};
struct vmop_id {