mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 17:18:32 +00:00
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
This commit is contained in:
parent
ee0ebaa420
commit
3efc45f34e
|
@ -496,14 +496,11 @@ vm_rev_map_gpa(struct vmctx *ctx, void *addr)
|
||||||
return ((vm_paddr_t)-1);
|
return ((vm_paddr_t)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: maximum size for vmname */
|
const char *
|
||||||
int
|
vm_get_name(struct vmctx *ctx)
|
||||||
vm_get_name(struct vmctx *ctx, char *buf, size_t max_len)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if (strlcpy(buf, ctx->name, max_len) >= max_len)
|
return (ctx->name);
|
||||||
return (EINVAL);
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
|
|
|
@ -133,7 +133,7 @@ uint32_t vm_get_lowmem_limit(struct vmctx *ctx);
|
||||||
void vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit);
|
void vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit);
|
||||||
void vm_set_memflags(struct vmctx *ctx, int flags);
|
void vm_set_memflags(struct vmctx *ctx, int flags);
|
||||||
int vm_get_memflags(struct vmctx *ctx);
|
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_lowmem_size(struct vmctx *ctx);
|
||||||
size_t vm_get_highmem_size(struct vmctx *ctx);
|
size_t vm_get_highmem_size(struct vmctx *ctx);
|
||||||
int vm_set_desc(struct vmctx *ctx, int vcpu, int reg,
|
int vm_set_desc(struct vmctx *ctx, int vcpu, int reg,
|
||||||
|
|
|
@ -1123,28 +1123,15 @@ vm_snapshot_kern_structs(struct vmctx *ctx, int data_fd, xo_handle_t *xop)
|
||||||
static int
|
static int
|
||||||
vm_snapshot_basic_metadata(struct vmctx *ctx, xo_handle_t *xop, size_t memsz)
|
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_open_container_h(xop, JSON_BASIC_METADATA_KEY);
|
||||||
xo_emit_h(xop, "{:" JSON_NCPUS_KEY "/%ld}\n", guest_ncpus);
|
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_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);
|
xo_close_container_h(xop, JSON_BASIC_METADATA_KEY);
|
||||||
|
|
||||||
err:
|
return (0);
|
||||||
return (error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -1518,7 +1505,6 @@ init_checkpoint_thread(struct vmctx *ctx)
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
int socket_fd;
|
int socket_fd;
|
||||||
pthread_t checkpoint_pthread;
|
pthread_t checkpoint_pthread;
|
||||||
char vmname_buf[MAX_VMNAME];
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
@ -1532,14 +1518,8 @@ init_checkpoint_thread(struct vmctx *ctx)
|
||||||
|
|
||||||
addr.sun_family = AF_UNIX;
|
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",
|
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);
|
addr.sun_len = SUN_LEN(&addr);
|
||||||
unlink(addr.sun_path);
|
unlink(addr.sun_path);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue