Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153242057
D2838.id6231.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D2838.id6231.diff
View Options
Index: usr.sbin/bhyvectl/bhyvectl.c
===================================================================
--- usr.sbin/bhyvectl/bhyvectl.c
+++ usr.sbin/bhyvectl/bhyvectl.c
@@ -35,6 +35,7 @@
#include <sys/errno.h>
#include <sys/mman.h>
+#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -74,6 +75,7 @@
" [--cpu=<vcpu_number>]\n"
" [--create]\n"
" [--destroy]\n"
+ " [--list]\n"
" [--get-all]\n"
" [--get-stats]\n"
" [--set-desc-ds]\n"
@@ -236,7 +238,7 @@
static int inject_nmi, assert_lapic_lvt;
static int force_reset, force_poweroff;
static const char *capname;
-static int create, destroy, get_lowmem, get_highmem;
+static int create, destroy, list, get_lowmem, get_highmem;
static int get_intinfo;
static int get_active_cpus, get_suspended_cpus;
static uint64_t memsize;
@@ -582,6 +584,25 @@
printf("\n");
}
+/*
+ * Parse the number of CPU specified to a VM and
+ * returns the total number of it.
+ */
+static int
+count_vcpus(const cpuset_t *cpus)
+{
+ int i, count = 0;
+
+ if (!CPU_EMPTY(cpus)) {
+ for (i = 0; i < CPU_SETSIZE; i++) {
+ if (CPU_ISSET(count, cpus))
+ count++;
+ }
+ }
+
+ return count;
+}
+
static void
print_intinfo(const char *banner, uint64_t info)
{
@@ -1373,6 +1394,7 @@
{ "run", NO_ARG, &run, 1 },
{ "create", NO_ARG, &create, 1 },
{ "destroy", NO_ARG, &destroy, 1 },
+ { "list", NO_ARG, &list, 1},
{ "inject-nmi", NO_ARG, &inject_nmi, 1 },
{ "force-reset", NO_ARG, &force_reset, 1 },
{ "force-poweroff", NO_ARG, &force_poweroff, 1 },
@@ -1520,6 +1542,53 @@
return ("UNK");
}
+static void
+list_vm(char *vmname)
+{
+ DIR *path_vmm;
+ struct dirent *dir;
+ struct vmctx *ctx;
+ size_t memory_size;
+ int error, wired, vcpus = 0;
+ vm_paddr_t gpa;
+ cpuset_t cpus;
+
+ printf("NAME\t\t MEM\t\t\t VCPU\n");
+
+ path_vmm = opendir("/dev/vmm");
+ if (path_vmm) {
+ while ((dir = readdir(path_vmm)) != NULL) {
+ if (strcmp(".", dir->d_name) != 0 &&
+ strcmp("..", dir->d_name) != 0) {
+
+ ctx = vm_open(dir->d_name);
+ gpa = 0;
+
+ error = vm_get_memory_seg(ctx, gpa, &memory_size,
+ &wired);
+ if (error)
+ printf("Error to get memory segment information.\n");
+
+ error = vm_active_cpus(ctx, &cpus);
+ if (!error)
+ vcpus = count_vcpus(&cpus);
+ else
+ printf("Error to get the number of vcpus.\n");
+
+ if (memory_size && vcpus) {
+ if (vmname && strcmp(vmname, dir->d_name) == 0) {
+ printf("%s\t\t %zu\t\t %d\n", dir->d_name, memory_size,
+ vcpus);
+ break;
+ } else if (!vmname)
+ printf("%s\t\t %zu\t\t %d\n", dir->d_name, memory_size,
+ vcpus);
+ }
+ }
+ }
+ }
+}
+
int
main(int argc, char *argv[])
{
@@ -1686,7 +1755,16 @@
argc -= optind;
argv += optind;
- if (vmname == NULL)
+ if (list) {
+ if (vmname)
+ list_vm(vmname);
+ else
+ list_vm(NULL);
+
+ exit (0);
+ }
+
+ if (vmname == NULL && !list)
usage(cpu_intel);
error = 0;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Apr 21, 12:37 AM (6 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31875082
Default Alt Text
D2838.id6231.diff (2 KB)
Attached To
Mode
D2838: Add on bhyvectl the capability to list the running vms.
Attached
Detach File
Event Timeline
Log In to Comment