aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Wing <rew@FreeBSD.org>2022-03-18 05:26:54 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2023-01-26 18:48:47 +0000
commit51b1d348203d57bc5562e98cba25a2223e5c839a (patch)
treeff81a86eb24c8996a26b4634f40729e126182527
parenta7148002833387848a707b77f2ef2ea3dbece09c (diff)
downloadsrc-51b1d348203d57bc5562e98cba25a2223e5c839a.tar.gz
src-51b1d348203d57bc5562e98cba25a2223e5c839a.zip
libvmm: constify vm_get_name()
Allows callers of vm_get_name() to retrieve the vm name without having to allocate a buffer. While in the vicinity, do minor cleanup in vm_snapshot_basic_metadata(). Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D34290 (cherry picked from commit 3efc45f34e13c63cb37a77a67fea39937004b75a)
-rw-r--r--lib/libvmmapi/vmmapi.c9
-rw-r--r--lib/libvmmapi/vmmapi.h2
-rw-r--r--usr.sbin/bhyve/snapshot.c28
3 files changed, 8 insertions, 31 deletions
diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c
index f6d83dd0e08f..4fc9c4dc69e9 100644
--- a/lib/libvmmapi/vmmapi.c
+++ b/lib/libvmmapi/vmmapi.c
@@ -498,14 +498,11 @@ vm_rev_map_gpa(struct vmctx *ctx, void *addr)
return ((vm_paddr_t)-1);
}
-/* TODO: maximum size for vmname */
-int
-vm_get_name(struct vmctx *ctx, char *buf, size_t max_len)
+const char *
+vm_get_name(struct vmctx *ctx)
{
- if (strlcpy(buf, ctx->name, max_len) >= max_len)
- return (EINVAL);
- return (0);
+ return (ctx->name);
}
size_t
diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h
index 586392a0ff29..c8454150f0b1 100644
--- a/lib/libvmmapi/vmmapi.h
+++ b/lib/libvmmapi/vmmapi.h
@@ -135,7 +135,7 @@ uint32_t vm_get_lowmem_limit(struct vmctx *ctx);
void vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit);
void vm_set_memflags(struct vmctx *ctx, int flags);
int vm_get_memflags(struct vmctx *ctx);
-int vm_get_name(struct vmctx *ctx, char *buffer, size_t max_len);
+const char *vm_get_name(struct vmctx *ctx);
size_t vm_get_lowmem_size(struct vmctx *ctx);
size_t vm_get_highmem_size(struct vmctx *ctx);
int vm_set_desc(struct vmctx *ctx, int vcpu, int reg,
diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c
index aae8353b89db..4bd2ea273171 100644
--- a/usr.sbin/bhyve/snapshot.c
+++ b/usr.sbin/bhyve/snapshot.c
@@ -1123,28 +1123,15 @@ err_vm_snapshot_kern_data:
static int
vm_snapshot_basic_metadata(struct vmctx *ctx, xo_handle_t *xop, size_t memsz)
{
- int error;
- int memflags;
- char vmname_buf[MAX_VMNAME];
-
- memset(vmname_buf, 0, MAX_VMNAME);
- error = vm_get_name(ctx, vmname_buf, MAX_VMNAME - 1);
- if (error != 0) {
- perror("Failed to get VM name");
- goto err;
- }
-
- memflags = vm_get_memflags(ctx);
xo_open_container_h(xop, JSON_BASIC_METADATA_KEY);
xo_emit_h(xop, "{:" JSON_NCPUS_KEY "/%ld}\n", guest_ncpus);
- xo_emit_h(xop, "{:" JSON_VMNAME_KEY "/%s}\n", vmname_buf);
+ xo_emit_h(xop, "{:" JSON_VMNAME_KEY "/%s}\n", vm_get_name(ctx));
xo_emit_h(xop, "{:" JSON_MEMSIZE_KEY "/%lu}\n", memsz);
- xo_emit_h(xop, "{:" JSON_MEMFLAGS_KEY "/%d}\n", memflags);
+ xo_emit_h(xop, "{:" JSON_MEMFLAGS_KEY "/%d}\n", vm_get_memflags(ctx));
xo_close_container_h(xop, JSON_BASIC_METADATA_KEY);
-err:
- return (error);
+ return (0);
}
static int
@@ -1518,7 +1505,6 @@ init_checkpoint_thread(struct vmctx *ctx)
struct sockaddr_un addr;
int socket_fd;
pthread_t checkpoint_pthread;
- char vmname_buf[MAX_VMNAME];
int err;
memset(&addr, 0, sizeof(addr));
@@ -1532,14 +1518,8 @@ init_checkpoint_thread(struct vmctx *ctx)
addr.sun_family = AF_UNIX;
- err = vm_get_name(ctx, vmname_buf, MAX_VMNAME - 1);
- if (err != 0) {
- perror("Failed to get VM name");
- goto fail;
- }
-
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s%s",
- BHYVE_RUN_DIR, vmname_buf);
+ BHYVE_RUN_DIR, vm_get_name(ctx));
addr.sun_len = SUN_LEN(&addr);
unlink(addr.sun_path);