svn commit: r241486 - projects/bhyve/lib/libvmmapi

Neel Natu neel at FreeBSD.org
Fri Oct 12 17:39:29 UTC 2012


Author: neel
Date: Fri Oct 12 17:39:28 2012
New Revision: 241486
URL: http://svn.freebsd.org/changeset/base/241486

Log:
  Add an api to map a vm capability type into a string to be used for display
  purposes.

Modified:
  projects/bhyve/lib/libvmmapi/vmmapi.c
  projects/bhyve/lib/libvmmapi/vmmapi.h

Modified: projects/bhyve/lib/libvmmapi/vmmapi.c
==============================================================================
--- projects/bhyve/lib/libvmmapi/vmmapi.c	Fri Oct 12 17:18:24 2012	(r241485)
+++ projects/bhyve/lib/libvmmapi/vmmapi.c	Fri Oct 12 17:39:28 2012	(r241486)
@@ -370,22 +370,22 @@ vm_inject_nmi(struct vmctx *ctx, int vcp
 	return (ioctl(ctx->fd, VM_INJECT_NMI, &vmnmi));
 }
 
+static struct {
+	const char	*name;
+	int		type;
+} capstrmap[] = {
+	{ "hlt_exit",		VM_CAP_HALT_EXIT },
+	{ "mtrap_exit",		VM_CAP_MTRAP_EXIT },
+	{ "pause_exit",		VM_CAP_PAUSE_EXIT },
+	{ "unrestricted_guest",	VM_CAP_UNRESTRICTED_GUEST },
+	{ 0 }
+};
+
 int
 vm_capability_name2type(const char *capname)
 {
 	int i;
 
-	static struct {
-		const char	*name;
-		int		type;
-	} capstrmap[] = {
-		{ "hlt_exit",		VM_CAP_HALT_EXIT },
-		{ "mtrap_exit",		VM_CAP_MTRAP_EXIT },
-		{ "pause_exit",		VM_CAP_PAUSE_EXIT },
-		{ "unrestricted_guest",	VM_CAP_UNRESTRICTED_GUEST },
-		{ 0 }
-	};
-
 	for (i = 0; capstrmap[i].name != NULL && capname != NULL; i++) {
 		if (strcmp(capstrmap[i].name, capname) == 0)
 			return (capstrmap[i].type);
@@ -394,6 +394,19 @@ vm_capability_name2type(const char *capn
 	return (-1);
 }
 
+const char *
+vm_capability_type2name(int type)
+{
+	int i;
+
+	for (i = 0; capstrmap[i].name != NULL; i++) {
+		if (capstrmap[i].type == type)
+			return (capstrmap[i].name);
+	}
+
+	return (NULL);
+}
+
 int
 vm_get_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap,
 		  int *retval)

Modified: projects/bhyve/lib/libvmmapi/vmmapi.h
==============================================================================
--- projects/bhyve/lib/libvmmapi/vmmapi.h	Fri Oct 12 17:18:24 2012	(r241485)
+++ projects/bhyve/lib/libvmmapi/vmmapi.h	Fri Oct 12 17:39:28 2012	(r241486)
@@ -70,6 +70,7 @@ int	vm_inject_event2(struct vmctx *ctx, 
 int	vm_lapic_irq(struct vmctx *ctx, int vcpu, int vector);
 int	vm_inject_nmi(struct vmctx *ctx, int vcpu);
 int	vm_capability_name2type(const char *capname);
+const char *vm_capability_type2name(int type);
 int	vm_get_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap,
 			  int *retval);
 int	vm_set_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap,


More information about the svn-src-projects mailing list