summaryrefslogtreecommitdiff
path: root/usr/src/lib/libvmmapi
diff options
context:
space:
mode:
authorPatrick Mooney <pmooney@pfmooney.com>2021-05-28 21:07:11 +0000
committerPatrick Mooney <pmooney@oxide.computer>2021-07-27 19:26:22 +0000
commitb57f5d3e6a2df8d435e606797cf3934811848343 (patch)
tree31d0b366057848a88837b15524905a703c3bdf9c /usr/src/lib/libvmmapi
parented1e93792d7c9ea04a0cb44cffe34c24c135b002 (diff)
downloadillumos-joyent-b57f5d3e6a2df8d435e606797cf3934811848343.tar.gz
13833 want bhyve memory reservoir
13822 bhyve memory should exert memory pressure 13834 want extensible page_resv 13821 vmmctl ioctls should have more structure Reviewed by: Andy Fiddaman <andy@omnios.org> Reviewed by: Jason King <jason.brian.king@gmail.com> Reviewed by: Dan Cross <cross@oxidecomputer.com> Reviewed by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> Reviewed by: Mike Zeller <mike.zeller@joyent.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/lib/libvmmapi')
-rw-r--r--usr/src/lib/libvmmapi/common/vmmapi.c106
-rw-r--r--usr/src/lib/libvmmapi/common/vmmapi.h6
2 files changed, 70 insertions, 42 deletions
diff --git a/usr/src/lib/libvmmapi/common/vmmapi.c b/usr/src/lib/libvmmapi/common/vmmapi.c
index ba3fb7f8dd..ec27949a43 100644
--- a/usr/src/lib/libvmmapi/common/vmmapi.c
+++ b/usr/src/lib/libvmmapi/common/vmmapi.c
@@ -39,7 +39,7 @@
*
* Copyright 2015 Pluribus Networks Inc.
* Copyright 2019 Joyent, Inc.
- * Copyright 2020 Oxide Computer Company
+ * Copyright 2021 Oxide Computer Company
*/
#include <sys/cdefs.h>
@@ -109,12 +109,31 @@ struct vmctx {
#ifdef __FreeBSD__
#define CREATE(x) sysctlbyname("hw.vmm.create", NULL, NULL, (x), strlen((x)))
#define DESTROY(x) sysctlbyname("hw.vmm.destroy", NULL, NULL, (x), strlen((x)))
-#else
-#define CREATE(x) vm_do_ctl(VMM_CREATE_VM, (x))
-#define DESTROY(x) vm_do_ctl(VMM_DESTROY_VM, (x))
+int
+vm_create(const char *name)
+{
+ /* Try to load vmm(4) module before creating a guest. */
+ if (modfind("vmm") < 0)
+ kldload("vmm");
+ return (CREATE((char *)name));
+}
+
+void
+vm_destroy(struct vmctx *vm)
+{
+ assert(vm != NULL);
+
+ if (vm->fd >= 0)
+ close(vm->fd);
+ DESTROY(vm->name);
+
+ free(vm);
+}
+
+#else
static int
-vm_do_ctl(int cmd, const char *name)
+vm_do_ctl(int cmd, void *req)
{
int ctl_fd;
@@ -123,7 +142,7 @@ vm_do_ctl(int cmd, const char *name)
return (-1);
}
- if (ioctl(ctl_fd, cmd, name) == -1) {
+ if (ioctl(ctl_fd, cmd, req) == -1) {
int err = errno;
/* Do not lose ioctl errno through the close(2) */
@@ -135,6 +154,46 @@ vm_do_ctl(int cmd, const char *name)
return (0);
}
+
+int
+vm_create(const char *name, uint64_t flags)
+{
+ struct vm_create_req req;
+
+ (void) strncpy(req.name, name, VM_MAX_NAMELEN);
+ req.flags = flags;
+
+ return (vm_do_ctl(VMM_CREATE_VM, &req));
+}
+
+void
+vm_close(struct vmctx *vm)
+{
+ assert(vm != NULL);
+ assert(vm->fd >= 0);
+
+ (void) close(vm->fd);
+
+ free(vm);
+}
+
+void
+vm_destroy(struct vmctx *vm)
+{
+ struct vm_destroy_req req;
+
+ assert(vm != NULL);
+
+ if (vm->fd >= 0) {
+ (void) close(vm->fd);
+ vm->fd = -1;
+ }
+
+ (void) strncpy(req.name, vm->name, VM_MAX_NAMELEN);
+ (void) vm_do_ctl(VMM_DESTROY_VM, &req);
+
+ free(vm);
+}
#endif
static int
@@ -155,17 +214,6 @@ vm_device_open(const char *name)
return (fd);
}
-int
-vm_create(const char *name)
-{
-#ifdef __FreeBSD__
- /* Try to load vmm(4) module before creating a guest. */
- if (modfind("vmm") < 0)
- kldload("vmm");
-#endif
- return (CREATE((char *)name));
-}
-
struct vmctx *
vm_open(const char *name)
{
@@ -189,30 +237,6 @@ err:
return (NULL);
}
-#ifndef __FreeBSD__
-void
-vm_close(struct vmctx *vm)
-{
- assert(vm != NULL);
- assert(vm->fd >= 0);
-
- (void) close(vm->fd);
-
- free(vm);
-}
-#endif
-
-void
-vm_destroy(struct vmctx *vm)
-{
- assert(vm != NULL);
-
- if (vm->fd >= 0)
- close(vm->fd);
- DESTROY(vm->name);
-
- free(vm);
-}
int
vm_parse_memsize(const char *optarg, size_t *ret_memsize)
diff --git a/usr/src/lib/libvmmapi/common/vmmapi.h b/usr/src/lib/libvmmapi/common/vmmapi.h
index 79c7dc02ee..e239b70a56 100644
--- a/usr/src/lib/libvmmapi/common/vmmapi.h
+++ b/usr/src/lib/libvmmapi/common/vmmapi.h
@@ -39,7 +39,7 @@
*
* Copyright 2015 Pluribus Networks Inc.
* Copyright 2019 Joyent, Inc.
- * Copyright 2020 Oxide Computer Company
+ * Copyright 2021 Oxide Computer Company
*/
#ifndef _VMMAPI_H_
@@ -134,7 +134,11 @@ int vm_mmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, int segid,
int vm_munmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, size_t len);
+#ifndef __FreeBSD__
+int vm_create(const char *name, uint64_t flags);
+#else
int vm_create(const char *name);
+#endif /* __FreeBSD__ */
int vm_get_device_fd(struct vmctx *ctx);
struct vmctx *vm_open(const char *name);
#ifndef __FreeBSD__