summaryrefslogtreecommitdiff
path: root/usr.sbin/vmctl/vmctl.c
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 /usr.sbin/vmctl/vmctl.c
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@
Diffstat (limited to 'usr.sbin/vmctl/vmctl.c')
-rw-r--r--usr.sbin/vmctl/vmctl.c48
1 files changed, 37 insertions, 11 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");
- }
}
}