summaryrefslogtreecommitdiff
path: root/usr/src/lib
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2018-02-12 17:08:40 +0000
committerPatrick Mooney <pmooney@pfmooney.com>2018-03-07 15:52:37 +0000
commitd895d9b0600a1c4955ffc6aa3a34a22c69154b43 (patch)
tree59af0cc2968c02c1fd4c841c722355349284480e /usr/src/lib
parent7570433cf8265bc05b2f886601908b42eaff28c0 (diff)
downloadillumos-joyent-d895d9b0600a1c4955ffc6aa3a34a22c69154b43.tar.gz
OS-6675 need tool to detect bhyve support
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com> Reviewed by: Mike Gerdts <mike.gerdts@joyent.com> Approved by: John Levon <john.levon@joyent.com>
Diffstat (limited to 'usr/src/lib')
-rw-r--r--usr/src/lib/brand/bhyve/zone/Makefile7
-rw-r--r--usr/src/lib/brand/bhyve/zone/bhhwcompat.c71
2 files changed, 77 insertions, 1 deletions
diff --git a/usr/src/lib/brand/bhyve/zone/Makefile b/usr/src/lib/brand/bhyve/zone/Makefile
index 8e9586f525..f778fda27a 100644
--- a/usr/src/lib/brand/bhyve/zone/Makefile
+++ b/usr/src/lib/brand/bhyve/zone/Makefile
@@ -18,9 +18,14 @@ include $(SRC)/cmd/Makefile.cmd.64
PROGS = attach detach statechange uninstall
PROG1 = boot
-PROGS += $(PROG1)
+PROG2 = bhhwcompat
+PROGS += $(PROG1) $(PROG2)
CLEANFILES += $(PROGS)
+
$(PROG1) := LDLIBS += -lnvpair
+$(PROG2) := CPPFLAGS = -I$(COMPAT)/freebsd -I$(CONTRIB)/freebsd \
+ $(CPPFLAGS.master) -I$(SRC)/uts/i86pc \
+ -I$(COMPAT)/freebsd/amd64 -I$(CONTRIB)/freebsd/amd64
TEMPLATES = SYSbhyve.xml
XMLDOCS = config.xml platform.xml
diff --git a/usr/src/lib/brand/bhyve/zone/bhhwcompat.c b/usr/src/lib/brand/bhyve/zone/bhhwcompat.c
new file mode 100644
index 0000000000..8d8d10cf96
--- /dev/null
+++ b/usr/src/lib/brand/bhyve/zone/bhhwcompat.c
@@ -0,0 +1,71 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2018, Joyent, Inc.
+ */
+
+/*
+ * Exit 0 if the current hardware is bhyve-compatible, non-zero otherwise.
+ * A '-v' option can be used to print the incompatibility reason provided by
+ * the kernel.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+#include <sys/param.h>
+#include <sys/cpuset.h>
+#include <sys/vmm.h>
+#include <sys/vmm_dev.h>
+
+static void
+usage()
+{
+ fprintf(stderr, "bhhwcompat [-v]\n");
+ exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int fd, c;
+ char emsg[128];
+ boolean_t verbose = B_FALSE;
+
+ while ((c = getopt(argc, argv, "v")) != -1) {
+ switch (c) {
+ case 'v':
+ verbose = B_TRUE;
+ break;
+ default:
+ usage();
+ }
+ }
+
+ if ((fd = open(VMM_CTL_DEV, O_RDONLY | O_EXCL)) < 0) {
+ if (verbose)
+ fprintf(stderr, "missing %s\n", VMM_CTL_DEV);
+ exit(1);
+ }
+
+ emsg[0] = '\0';
+ if (ioctl(fd, VMM_VM_SUPPORTED, emsg) < 0) {
+ if (verbose)
+ fprintf(stderr, "%s\n", emsg);
+ exit(1);
+ }
+
+ (void) close(fd);
+ return (0);
+}