Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 Jan 2023 19:47:40 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: fca65e1baa1d - stable/13 - libvmmapi: Add vm_close()
Message-ID:  <202301261947.30QJlelR006933@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=fca65e1baa1d05d7e98e0f05193cc94c637944b0

commit fca65e1baa1d05d7e98e0f05193cc94c637944b0
Author:     Vitaliy Gusev <gusev.vitaliy@gmail.com>
AuthorDate: 2022-06-30 21:21:57 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-01-26 19:29:22 +0000

    libvmmapi: Add vm_close()
    
    Currently there is no way to safely free a vm structure without
    leaking the fd.  vm_destroy() closes the fd but also destroys the VM
    whereas in some cases a VM needs to be opened (vm_open) and then
    closed (vm_close).
    
    Reviewed by:    jhb
    Sponsored by:   vStack
    Differential Revision:  https://reviews.freebsd.org/D35073
    
    (cherry picked from commit f0880ab791a510391a12f2ab7b01889b6774bca0)
---
 lib/libvmmapi/vmmapi.c | 9 +++++++++
 lib/libvmmapi/vmmapi.h | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c
index 4fc9c4dc69e9..454d7ee21b36 100644
--- a/lib/libvmmapi/vmmapi.c
+++ b/lib/libvmmapi/vmmapi.c
@@ -142,6 +142,15 @@ err:
 	return (NULL);
 }
 
+void
+vm_close(struct vmctx *vm)
+{
+	assert(vm != NULL);
+
+	close(vm->fd);
+	free(vm);
+}
+
 void
 vm_destroy(struct vmctx *vm)
 {
diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h
index c8454150f0b1..b26f12f7c60e 100644
--- a/lib/libvmmapi/vmmapi.h
+++ b/lib/libvmmapi/vmmapi.h
@@ -34,6 +34,7 @@
 #include <sys/cdefs.h>
 #include <sys/param.h>
 #include <sys/cpuset.h>
+#include <machine/vmm.h>
 #include <machine/vmm_dev.h>
 
 #include <stdbool.h>
@@ -118,6 +119,7 @@ int	vm_munmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, size_t len);
 
 int	vm_create(const char *name);
 struct vmctx *vm_open(const char *name);
+void	vm_close(struct vmctx *ctx);
 void	vm_destroy(struct vmctx *ctx);
 int	vm_limit_rights(struct vmctx *ctx);
 int	vm_parse_memsize(const char *optarg, size_t *memsize);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202301261947.30QJlelR006933>