summaryrefslogtreecommitdiff
path: root/usr/src/lib
diff options
context:
space:
mode:
authorHans Rosenfeld <hans.rosenfeld@joyent.com>2018-12-20 09:58:04 +0000
committerHans Rosenfeld <hans.rosenfeld@joyent.com>2018-12-20 11:19:36 +0100
commit4650832b29268c92656cbcbc0b543402b8c3f6fa (patch)
treeb85ce1c4494b64e43f835189ef01c5e57c9f40a9 /usr/src/lib
parentc80a96f941e57993b407b02fe55a9f725a070282 (diff)
downloadillumos-joyent-4650832b29268c92656cbcbc0b543402b8c3f6fa.tar.gz
OS-7402 libvmmapi: vm_open destroys VM on error, vm_close is missing
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com> Reviewed by: John Levon <john.levon@joyent.com> Approved by: John Levon <john.levon@joyent.com>
Diffstat (limited to 'usr/src/lib')
-rw-r--r--usr/src/lib/libvmmapi/common/mapfile-vers1
-rw-r--r--usr/src/lib/libvmmapi/common/vmmapi.c22
-rw-r--r--usr/src/lib/libvmmapi/common/vmmapi.h3
3 files changed, 26 insertions, 0 deletions
diff --git a/usr/src/lib/libvmmapi/common/mapfile-vers b/usr/src/lib/libvmmapi/common/mapfile-vers
index ad47407281..024411efee 100644
--- a/usr/src/lib/libvmmapi/common/mapfile-vers
+++ b/usr/src/lib/libvmmapi/common/mapfile-vers
@@ -40,6 +40,7 @@ SYMBOL_VERSION ILLUMOSprivate {
vm_assign_pptdev;
vm_capability_name2type;
vm_capability_type2name;
+ vm_close;
vm_copy_setup;
vm_copy_teardown;
vm_copyin;
diff --git a/usr/src/lib/libvmmapi/common/vmmapi.c b/usr/src/lib/libvmmapi/common/vmmapi.c
index 7d20a3b323..de5acddc4c 100644
--- a/usr/src/lib/libvmmapi/common/vmmapi.c
+++ b/usr/src/lib/libvmmapi/common/vmmapi.c
@@ -179,10 +179,32 @@ vm_open(const char *name)
return (vm);
err:
+#ifdef __FreeBSD__
vm_destroy(vm);
+#else
+ /*
+ * As libvmmapi is used by other programs to query and control bhyve
+ * VMs, destroying a VM just because the open failed isn't useful. We
+ * have to free what we have allocated, though.
+ */
+ free(vm);
+#endif
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)
{
diff --git a/usr/src/lib/libvmmapi/common/vmmapi.h b/usr/src/lib/libvmmapi/common/vmmapi.h
index 43481fefbe..6c28b2137d 100644
--- a/usr/src/lib/libvmmapi/common/vmmapi.h
+++ b/usr/src/lib/libvmmapi/common/vmmapi.h
@@ -123,6 +123,9 @@ int vm_mmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, int segid,
int vm_create(const char *name);
int vm_get_device_fd(struct vmctx *ctx);
struct vmctx *vm_open(const char *name);
+#ifndef __FreeBSD__
+void vm_close(struct vmctx *ctx);
+#endif
void vm_destroy(struct vmctx *ctx);
int vm_parse_memsize(const char *optarg, size_t *memsize);
int vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);