From nobody Fri Mar 18 05:45:37 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 71EB11A2A9B3; Fri, 18 Mar 2022 05:45:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KKXzj2kL8z4fV6; Fri, 18 Mar 2022 05:45:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647582337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rdGL5HL6/5CNlWojE2Q6fkZEHzUEV1tDDkXRgKMSbMk=; b=Wd10nKLUbsMChu+lLzlaDLmrZXvBoBqJhl8phuvQ9NUuXb76NMkdzragn6wlBphfj3BwEl ZBaS7G1KEmgHTLhKMnjqR1VlHDSi5y5EVyLhcH1Ej3v20SYnsgrqaWyZPWTtxyNAv51etH BR1az4z77XENl/qcrEeadmHav8spyCoH4lU9sZbwIl9ru97x/sYfQ2Ki7HWdmD6yJ4v7nR 8Z7fIx7uAppC8RZfgbJ0rVy3dfZBnTPlXICrE96URHERMMhTHKIVQlFlC1GOb98nLmx6Aj y8mVj7UtgjvssgdLSxWPIfUPhg6vf1NFCUHv9QSNHjE1/9Q7kiB3jv+xC0JVMA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 383B5192CC; Fri, 18 Mar 2022 05:45:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22I5jb4g084096; Fri, 18 Mar 2022 05:45:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22I5jbk5084095; Fri, 18 Mar 2022 05:45:37 GMT (envelope-from git) Date: Fri, 18 Mar 2022 05:45:37 GMT Message-Id: <202203180545.22I5jbk5084095@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Robert Wing Subject: git: 3efc45f34e13 - main - libvmm: constify vm_get_name() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3efc45f34e13c63cb37a77a67fea39937004b75a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647582337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rdGL5HL6/5CNlWojE2Q6fkZEHzUEV1tDDkXRgKMSbMk=; b=jFHs1h/uRMr/OjN4WI3zrwOBvutFlh7IeicCQ672KtiPItYvuoaJEzjvg4q4ItovpIIUMG ZSN90jZIx7zC2IvnjFp7QAHj72uRCwccdqC5FlCk8h7N73CkK47Xbs41fF3RgHBBmR50um 6Iq+X0RrjWejTMsQRWU+ykxSELJzeFA2wUkCsBjYUcU8/NM3qQRcTXp3w7X4Sa+7GlXIv5 xnDV0jQe/x3D9VuxtKRiPI1u5wItmjQkrSC5HKx5/vyin8SqxympKmJIwcD9hCTaA4PqRs 1T/Va/O5sdcODzaIEMywxQLyj/lBXuwJBLngF0OfZVmjNsO/o5RX8QA1Wk0BrA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647582337; a=rsa-sha256; cv=none; b=vjjkGV4ScUoIjDz4zeOdsde1elEo9jM7b8CEl3vcWYaCdYUUBqxmr/oEIrBgycmUjml9Zo 5aA+j7y6UEcPQr1UR8mUC9QDbX2wQ7QLaT7NVTiVomsJiSIPDqshLiNUYU6yU+GUFStwGs wJ//sLgOSHWbrPl1IZK83T7e5k82EuNu6mCBc/EEOcUDXEEZngv/+hk4KvDp2g9evyarSg ZDKxPeyKyuYL1Yrl5NTgGbxBV2kBRulhKnKVTYUc6Z2gxXhbyknq7grlp5Xv5lYpeHHG8v sCwNyphki8fXz1lCcs6j1aMChsjcGvQ37+p1wu+QmVL+ceD5D396i9/FuNjxPw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by rew: URL: https://cgit.FreeBSD.org/src/commit/?id=3efc45f34e13c63cb37a77a67fea39937004b75a commit 3efc45f34e13c63cb37a77a67fea39937004b75a Author: Robert Wing AuthorDate: 2022-03-18 05:26:54 +0000 Commit: Robert Wing CommitDate: 2022-03-18 05:38:21 +0000 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 --- lib/libvmmapi/vmmapi.c | 9 +++------ lib/libvmmapi/vmmapi.h | 2 +- usr.sbin/bhyve/snapshot.c | 28 ++++------------------------ 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c index 0291e4a10c33..e92b3199381f 100644 --- a/lib/libvmmapi/vmmapi.c +++ b/lib/libvmmapi/vmmapi.c @@ -496,14 +496,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 08945309cbd5..87051973225a 100644 --- a/lib/libvmmapi/vmmapi.h +++ b/lib/libvmmapi/vmmapi.h @@ -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_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 b0cc8095c3cb..13154c68c3e7 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);