From owner-dev-commits-src-main@freebsd.org Sat Feb 27 21:45:45 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 256605547EE; Sat, 27 Feb 2021 21:45:45 +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 4Dp0Sm6RrJz4Qn1; Sat, 27 Feb 2021 21:45:44 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 A8B9824D4C; Sat, 27 Feb 2021 21:45:44 +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 11RLji1G047364; Sat, 27 Feb 2021 21:45:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 11RLjikV047363; Sat, 27 Feb 2021 21:45:44 GMT (envelope-from git) Date: Sat, 27 Feb 2021 21:45:44 GMT Message-Id: <202102272145.11RLjikV047363@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: da9713917eb2 - main - bhyvectl: reduce code duplication 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: da9713917eb26b67bafc740384ccd44f7dff09f2 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Feb 2021 21:45:45 -0000 The branch main has been updated by rew: URL: https://cgit.FreeBSD.org/src/commit/?id=da9713917eb26b67bafc740384ccd44f7dff09f2 commit da9713917eb26b67bafc740384ccd44f7dff09f2 Author: Robert Wing AuthorDate: 2021-02-27 21:05:52 +0000 Commit: Robert Wing CommitDate: 2021-02-27 21:05:52 +0000 bhyvectl: reduce code duplication Combine send_start_checkpoint() and send_start_suspend() into a single function named snapshot_request(). snapshot_request() is equivalent to send_start_checkpoint() and send_start_suspend() except that it takes an additional argument. The additional argument, enum ipc_opcode, is used to determine the type of snapshot request being performed. Also, switch to using strlcpy instead of strncpy. Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D28878 --- usr.sbin/bhyvectl/bhyvectl.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/usr.sbin/bhyvectl/bhyvectl.c b/usr.sbin/bhyvectl/bhyvectl.c index 7b3a73cc3668..f9a790f5402e 100644 --- a/usr.sbin/bhyvectl/bhyvectl.c +++ b/usr.sbin/bhyvectl/bhyvectl.c @@ -1734,25 +1734,12 @@ done: } static int -send_start_checkpoint(struct vmctx *ctx, const char *checkpoint_file) +snapshot_request(struct vmctx *ctx, const char *file, enum ipc_opcode code) { struct checkpoint_op op; - op.op = START_CHECKPOINT; - strncpy(op.snapshot_filename, checkpoint_file, MAX_SNAPSHOT_VMNAME); - op.snapshot_filename[MAX_SNAPSHOT_VMNAME - 1] = 0; - - return (send_checkpoint_op_req(ctx, &op)); -} - -static int -send_start_suspend(struct vmctx *ctx, const char *suspend_file) -{ - struct checkpoint_op op; - - op.op = START_SUSPEND; - strncpy(op.snapshot_filename, suspend_file, MAX_SNAPSHOT_VMNAME); - op.snapshot_filename[MAX_SNAPSHOT_VMNAME - 1] = 0; + op.op = code; + strlcpy(op.snapshot_filename, file, MAX_SNAPSHOT_VMNAME); return (send_checkpoint_op_req(ctx, &op)); } @@ -2416,10 +2403,10 @@ main(int argc, char *argv[]) #ifdef BHYVE_SNAPSHOT if (!error && vm_checkpoint_opt) - error = send_start_checkpoint(ctx, checkpoint_file); + error = snapshot_request(ctx, checkpoint_file, START_CHECKPOINT); if (!error && vm_suspend_opt) - error = send_start_suspend(ctx, suspend_file); + error = snapshot_request(ctx, suspend_file, START_SUSPEND); #endif free (opts);