From nobody Thu Jan 26 18:54:32 2023 X-Original-To: dev-commits-src-branches@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 4P2qd439zlz3bPLS; Thu, 26 Jan 2023 18:54:32 +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 4P2qd42YvHz46TN; Thu, 26 Jan 2023 18:54:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674759272; 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=VmrEj0YMJP78d8ScfC7NGVU18Wn+LzbKdD10L7UUfhU=; b=SQS7iMUIGp509WPfKdePrL5IsXm3G0ykQA9WJEu6EbLINn3NfKiyLMvT0NpF1c8QMXZvOA Vst/QtwDXT30rDGa6FDVVw6e6RH7yCeIqqMfzblFYOUGsUmKkMHz9P0qaAzHWumbQ8mEuk aFf2FY/6ImLwiW0pfWT/hZaWeoRvokKeXSGW45SB9awIZPJjQXXRlaBtvxVCsaIZdAUUtD hKhOdvtWnVExwyJMT6odpn06KLmUngCEeCNWj2UoHROjeRt64dFRid1+upiUkjyWhyJrMb dsPKZho4/SPwIFxCVpPzmljOY782peOuV0sMs32dLhSBpf40DlAzlJNwxszQzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674759272; 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=VmrEj0YMJP78d8ScfC7NGVU18Wn+LzbKdD10L7UUfhU=; b=rb5OzNozRfvBEmMfvdNPYm0UEd5KoiNQllW9A6AyYgZ6sxOGT4QfCCGrcfS0xxR+HNFWVU 4WKScqEGRxtPKmzBIASyZpiTn5mFDNeCC1rR6WyZcgmEEGkwfRbCPnmM70upMGrhGcdHC3 9WNvFU3zRQ2kqZTfzn9Sj7RIe+cFS9CqpssPUlTDoTNwEpjFFb6o7rLMSCvnErUqZJsEa4 xY5iEVqej+TcYkXjUZXd3vVt/avU5CaCQGobd6L8lZpRbcu3rsSVcjznG9t+iV7K3hebvp 9vsUtmiSfG/TaTwSmUT9HBaTwN6wb4SJAQ4Y6pSsRLrLPjeoOMmiwhGGtpvgcA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674759272; a=rsa-sha256; cv=none; b=vCCUcb8Hi6qm4C4G/uCNpC8tEyDaVRjOpE8m0IIsagfWCYGq+XvxOQYeFhJRYGcFSe8Gos 5Dz47VKhVDiQ4yBirGpzUcIpdIU3G94RNb42Lc9d5drmTCfkqesw+b809eJ0UAaj9wJtRE epCKIH9gqlUjPb2HAKQDjMfHCYy1x04BwHiTiEyQ+PD4eyAGgZHThzbipjbctnLPHDjEyM ywaY0yx+VLX0jkfczDcn0BMipHQWColydpeZTpmc5R2QJvbNgarYppeN9jqJQVw5e+4VP0 6J2i/L9RiqWHFpoyvgS90VyLml8mQTZ9z5yhRQrbljaFMhYCrxyFratRBedmfA== 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 4P2qd41GphzgKy; Thu, 26 Jan 2023 18:54:32 +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 30QIsWuQ034347; Thu, 26 Jan 2023 18:54:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30QIsWVv034346; Thu, 26 Jan 2023 18:54:32 GMT (envelope-from git) Date: Thu, 26 Jan 2023 18:54:32 GMT Message-Id: <202301261854.30QIsWVv034346@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: 0c10a2255084 - stable/13 - bhyve: use linker set for ipc commands List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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: 0c10a2255084711e1ddaa0f43ce1245f49194da3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=0c10a2255084711e1ddaa0f43ce1245f49194da3 commit 0c10a2255084711e1ddaa0f43ce1245f49194da3 Author: Robert Wing AuthorDate: 2022-04-10 02:46:00 +0000 Commit: John Baldwin CommitDate: 2023-01-26 18:49:41 +0000 bhyve: use linker set for ipc commands Reviewed by: markj, jhb Differential Revision: https://reviews.freebsd.org/D34760 (cherry picked from commit c79331a42c308139828c1117f49224bb83617a53) --- usr.sbin/bhyve/ipc.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++ usr.sbin/bhyve/snapshot.c | 42 +++++++++++++++++++++++---------------- 2 files changed, 75 insertions(+), 17 deletions(-) diff --git a/usr.sbin/bhyve/ipc.h b/usr.sbin/bhyve/ipc.h new file mode 100644 index 000000000000..38faf69eb5f4 --- /dev/null +++ b/usr.sbin/bhyve/ipc.h @@ -0,0 +1,50 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2022 Rob Wing + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef _IPC_H_ +#define _IPC_H_ + +#include +#include +#include + +struct ipc_command { + char *name; + int (*handler)(struct vmctx *ctx, const nvlist_t *nvl); +}; + +#define IPC_COMMAND(set, name, function) \ + static struct ipc_command name ## _ipc_command = \ + { #name, function }; \ + DATA_SET(set, name ## _ipc_command); + +#define IPC_COMMAND_FOREACH(pvar, set) SET_FOREACH(pvar, set) + +SET_DECLARE(ipc_cmd_set, struct ipc_command); + +#endif /* _IPC_H_ */ diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c index ee709147cec4..7c34a9b2f0ea 100644 --- a/usr.sbin/bhyve/snapshot.c +++ b/usr.sbin/bhyve/snapshot.c @@ -81,6 +81,7 @@ __FBSDID("$FreeBSD$"); #include "atkbdc.h" #include "debug.h" #include "inout.h" +#include "ipc.h" #include "fwctl.h" #include "ioapic.h" #include "mem.h" @@ -1428,30 +1429,19 @@ done: static int handle_message(struct vmctx *ctx, nvlist_t *nvl) { - int err; const char *cmd; + struct ipc_command **ipc_cmd; if (!nvlist_exists_string(nvl, "cmd")) - return (-1); + return (EINVAL); cmd = nvlist_get_string(nvl, "cmd"); - if (strcmp(cmd, "checkpoint") == 0) { - if (!nvlist_exists_string(nvl, "filename") || - !nvlist_exists_bool(nvl, "suspend")) - err = -1; - else - err = vm_checkpoint(ctx, nvlist_get_string(nvl, "filename"), - nvlist_get_bool(nvl, "suspend")); - } else { - EPRINTLN("Unrecognized checkpoint operation\n"); - err = -1; + IPC_COMMAND_FOREACH(ipc_cmd, ipc_cmd_set) { + if (strcmp(cmd, (*ipc_cmd)->name) == 0) + return ((*ipc_cmd)->handler(ctx, nvl)); } - if (err != 0) - EPRINTLN("Unable to perform the requested operation\n"); - - nvlist_destroy(nvl); - return (err); + return (EOPNOTSUPP); } /* @@ -1472,11 +1462,29 @@ checkpoint_thread(void *param) handle_message(thread_info->ctx, nvl); else EPRINTLN("nvlist_recv() failed: %s", strerror(errno)); + + nvlist_destroy(nvl); } return (NULL); } +static int +vm_do_checkpoint(struct vmctx *ctx, const nvlist_t *nvl) +{ + int error; + + if (!nvlist_exists_string(nvl, "filename") || + !nvlist_exists_bool(nvl, "suspend")) + error = EINVAL; + else + error = vm_checkpoint(ctx, nvlist_get_string(nvl, "filename"), + nvlist_get_bool(nvl, "suspend")); + + return (error); +} +IPC_COMMAND(ipc_cmd_set, checkpoint, vm_do_checkpoint); + void init_snapshot(void) {