diff options
| author | Dan McDonald <danmcd@joyent.com> | 2021-07-27 17:10:56 -0400 |
|---|---|---|
| committer | Dan McDonald <danmcd@joyent.com> | 2021-07-27 17:11:06 -0400 |
| commit | f296fe3752760624e99cd00a72103976ed6b38b5 (patch) | |
| tree | 515c78f0c06d5be242e568944b78c3a6305af825 /usr/src/lib/libvmmapi/common/vmmapi.c | |
| parent | 23cf9d8375c8b9f39f05db37ede85475b2225ddd (diff) | |
| parent | ff5d40392f371e5d7648aef49cd3ce3834e48611 (diff) | |
| download | illumos-joyent-f296fe3752760624e99cd00a72103976ed6b38b5.tar.gz | |
[illumos-gate merge]
commit ff5d40392f371e5d7648aef49cd3ce3834e48611
13816 loader: BIOS build should not use -fPIC
commit b57f5d3e6a2df8d435e606797cf3934811848343
13833 want bhyve memory reservoir
13822 bhyve memory should exert memory pressure
13834 want extensible page_resv
13821 vmmctl ioctls should have more structure
commit ed1e93792d7c9ea04a0cb44cffe34c24c135b002
13882 libipadm ipadm_if_info() is not 64bit safe
commit f3a2bc1eccb884e62be4c0b42935466b79b1342d
6161 zero-sized kmem_alloc() in zfs`spa_load_l2cache
Conflicts:
manifest
usr/src/cmd/cmd-inet/lib/ipmgmtd/ipmgmt_main.c
usr/src/uts/common/vm/page.h
usr/src/uts/i86pc/Makefile.files
usr/src/uts/i86pc/io/vmm/vmm.c
Diffstat (limited to 'usr/src/lib/libvmmapi/common/vmmapi.c')
| -rw-r--r-- | usr/src/lib/libvmmapi/common/vmmapi.c | 106 |
1 files changed, 65 insertions, 41 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) |
