From nobody Thu Jan 26 18:54:18 2023 X-Original-To: dev-commits-src-all@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 4P2qcp6k15z3bPHq; Thu, 26 Jan 2023 18:54:18 +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 4P2qcp6GP7z45kp; Thu, 26 Jan 2023 18:54:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674759258; 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=/k1z6XSdpnOwi6W0u/67DkRWLcrLnAeQj/nyeWQYRCw=; b=Xz994bp3K2L1vScpxHOUxEZldWAVEEvZ/TA5Gbggyyhe4eyqOSMbPSK8R7inDeQg3Vi7AU z2hzTND6C+IHN+Xyxek55hOdElvyNI4/TFJDPMSwxBmdeWzT8KsacwZMXxqupzYbGX41Fx 9Lb1iBtskD9fTnPw7XrN5ZP7JR9mYSKhChmSkbSqK7gwQfuxkL8BlGc0oFbtghaL/osPvQ CFCvkkG7KEsbrvyFF0AFiY+TcixZTuWkInsW5/4QYtVVSJbSVg3u+dfAwjvC1S0imI487h MFrcEBiafbomAFruBUF4tfQUEM91fbtmXA+zH1Qr7f+B8z5gi8CQFDWrSWJgTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674759258; 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=/k1z6XSdpnOwi6W0u/67DkRWLcrLnAeQj/nyeWQYRCw=; b=IwIiht/QwSN6J7mtcCSLHrzN8JX0hezPDAN8hhHFJKfqBiqCJ+xODtIPpcPPka/PcLaD0/ njMlEj/tvYytQpftyrfa/AMAfoowATW2CLGrxQ5jj80PSD6+m/NDJ1S6pEaAEWdhN4SbjX 9EJdlSnu7nkI4UWJeB4J9XFCEoS9ERmdfpVyebBbrQuH08qFVaHnDFCYcVdqVx1oVfJW40 PvouothW76/YrCbK8Pladzqv5IfZ+EEs1yNZStRPuqhSC8DDWRzO/sh80lkPbtQ1x4LtTy fa0ak6URWqUwC/GU8qpzaWcI+vn2Uh6pz8DjyvLZ0+AAV8si71ARd49/lO3ibQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674759258; a=rsa-sha256; cv=none; b=ckfJ6BKYIgH4xUPB4NckON70Wcd+lYKbLCgu6lEwEUd5ODPqUv9TxvPgFuCcXnDwqSMqxp AhmS8sWX8Rl/55d4LAbk9t/ov/N2T80HX+28cJ3X175BhU+5tbHNbLrDrNcW2BoOeF8iP8 pCMqB24ilY3GyCz5l7OWLUHnVCYXsJCas/Y6fLcdF1k+nxFgPSmLaCmjprUkvm1MWN+cBB 5p1TpKCEG8m59CwGqjUz5IeB3sum/sAoI8Dv5EdFgMm9qmJgEqlNvd3TkrVerzRxxbjqKv bKxKYvVfFoiQlIJk96LNWPyDok7GkhZ8DGx5blywloN7rLoN/dRmxPpQZx8p1g== 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 4P2qcp5HCYzgPn; Thu, 26 Jan 2023 18:54:18 +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 30QIsISM034030; Thu, 26 Jan 2023 18:54:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30QIsIv9034029; Thu, 26 Jan 2023 18:54:18 GMT (envelope-from git) Date: Thu, 26 Jan 2023 18:54:18 GMT Message-Id: <202301261854.30QIsIv9034029@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 2ba5f9560750 - stable/13 - bhyvectl: reduce code duplication List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2ba5f95607505eccfd8dd3271463fa769809480b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=2ba5f95607505eccfd8dd3271463fa769809480b commit 2ba5f95607505eccfd8dd3271463fa769809480b Author: Robert Wing AuthorDate: 2021-02-27 21:05:52 +0000 Commit: John Baldwin CommitDate: 2023-01-26 18:45:40 +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 (cherry picked from commit da9713917eb26b67bafc740384ccd44f7dff09f2) --- 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 6cf5db0ef42f..5683a84c0242 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)); } @@ -2418,10 +2405,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);