From nobody Fri Jan 28 10:34:35 2022 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 E07A8197D57E; Fri, 28 Jan 2022 10:34:36 +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 4JlYjl6xmPz3tLg; Fri, 28 Jan 2022 10:34:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643366076; 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=X8F7dldS6qd++lVEMI1PUJEIJ9t38xDo3NqCfio6Puc=; b=mX2FbuNebfbg63PgAAIbG2iSvmEiBl7ERus9mmLPW5NwtwgiW94j+RzPO3LxvHeltWMgvL fOyrmKe4EiO/Ag4McBZBmzivTD5q+gWIpD1ktbycrYUUjAttbQRE4028UIwL+QbLwQtY6Z DZ22qYQntdIobWw15zxyll/u4j0O1hO43TX1aA2bEvOcjIhOUMtts3Nd4Qns7cp+jW9jRL EbyvEEdoBoge5Sy6PlRlMFn7WU0BP5d7oSK3JY4ll6PkuzDXvEFENOWEEPheVlnird7ACR tHkxOsThongQ8iqKbX+dsMtNU2iWxGxk3REPXUJ+8seiINClzRqGVW13mya1UA== 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 B49AE285F2; Fri, 28 Jan 2022 10:34:35 +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 20SAYZTm058779; Fri, 28 Jan 2022 10:34:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20SAYZwV058778; Fri, 28 Jan 2022 10:34:35 GMT (envelope-from git) Date: Fri, 28 Jan 2022 10:34:35 GMT Message-Id: <202201281034.20SAYZwV058778@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Emmanuel Vadot Subject: git: 9e502c25f7ba - stable/13 - bhyve: add nvlist functions for setting unset nodes 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: manu X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9e502c25f7ba4843192aabb82c012691d57b2ab8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643366076; 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=X8F7dldS6qd++lVEMI1PUJEIJ9t38xDo3NqCfio6Puc=; b=vzGzIJK2G2kCIFtslNjjX7KXzz+XpwrdjDrNPCuwsr7Ci+GVwIpL7B/WfFCTia37t24uzK MUFw8JaZp9GFupr8KZ9LXHV0hOnWTQWXTIGyYrTUkSX7n54oHDh7Y/Xomqs/n5qpQVSj+u YCMEQIu5zlTkduzThPNDSXjanjxhFisx3/niZqEoFYixhLvyRxQlg3/gLg6REljkxU3igW 4K1RTgcIAyryLZmhmvk8Uxh/J55Bu2LbjwmL21SdmzoIrJB5ui4OXFY9RCro5vdTDyBiQV yLR7WY8nstWzIESTf1jNTWzkl4uZcB+42NiebFkYaqaaGSh6aHIhSEElTWCWCA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643366076; a=rsa-sha256; cv=none; b=o+gO9yjN1uwA7Ber4TZsDIuaU48NvT7LhQh7d/Ui4yMT++5ShAeHD5qfuVlqXeRzci7rcd DHfF9SqTSBCKLcSpeXtWb1KMnDr3rIIy2vE/KYYDzOfVG40G09VYDTwX90Rk2xwpp/MMV8 5G5WilLaqqYAuWmwNK4AZZjkVH9xNN38GPkzrlb2n4x2+QlFmGj45yrswzUS5D/nepCopA lkwTDKd0Q4S8SevUgVJTdluU8Q07GzwruCoIdZ0ff29ZnYKnrDJB2yPLNJuDRwDvFeF7DI I8Houky38KSyszzz7i5w3oOEZ9ROZRxy0Dcg9Ywvu8C5DkFr+0PRYGT0U0Arkw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=9e502c25f7ba4843192aabb82c012691d57b2ab8 commit 9e502c25f7ba4843192aabb82c012691d57b2ab8 Author: Corvin Köhne AuthorDate: 2022-01-14 10:00:08 +0000 Commit: Emmanuel Vadot CommitDate: 2022-01-28 07:11:03 +0000 bhyve: add nvlist functions for setting unset nodes If an emulation uses those functions instead of set_config_value_node or set_config_value, it allows the config values to get overwritten. Introducing new functions is much more readable than if else statements in the emulation code. Reviewed by: khng MFC after: 2 weeks Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D33770 (cherry picked from commit fe453891d7ccc8e173d9293b67f5b4608c5378dd) --- usr.sbin/bhyve/config.c | 21 +++++++++++++++++++++ usr.sbin/bhyve/config.h | 12 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/usr.sbin/bhyve/config.c b/usr.sbin/bhyve/config.c index 1df750e9576c..05eb57e32c8e 100644 --- a/usr.sbin/bhyve/config.c +++ b/usr.sbin/bhyve/config.c @@ -135,6 +135,17 @@ set_config_value_node(nvlist_t *parent, const char *name, const char *value) nvlist_add_string(parent, name, value); } +void +set_config_value_node_if_unset(nvlist_t *const parent, const char *const name, + const char *const value) +{ + if (get_config_value_node(parent, name) != NULL) { + return; + } + + set_config_value_node(parent, name, value); +} + void set_config_value(const char *path, const char *value) { @@ -167,6 +178,16 @@ set_config_value(const char *path, const char *value) set_config_value_node(nvl, name, value); } +void +set_config_value_if_unset(const char *const path, const char *const value) +{ + if (get_config_value(path) != NULL) { + return; + } + + set_config_value(path, value); +} + static const char * get_raw_config_value(const char *path) { diff --git a/usr.sbin/bhyve/config.h b/usr.sbin/bhyve/config.h index 9f82afb267b2..ae6c8df64c6f 100644 --- a/usr.sbin/bhyve/config.h +++ b/usr.sbin/bhyve/config.h @@ -99,12 +99,24 @@ nvlist_t *find_relative_config_node(nvlist_t *parent, const char *path); void set_config_value_node(nvlist_t *parent, const char *name, const char *value); +/* + * Similar to set_config_value_node but only sets value if it's unset yet. + */ +void set_config_value_node_if_unset(nvlist_t *const parent, + const char *const name, const char *const value); + /* * Similar to set_config_value_node but expects a full path to the * leaf node. */ void set_config_value(const char *path, const char *value); +/* + * Similar to set_config_value but only sets the value if it's unset yet. + */ +void set_config_value_if_unset(const char *const path, + const char *const value); + /* Convenience wrappers for boolean variables. */ bool get_config_bool(const char *path); bool get_config_bool_node(const nvlist_t *parent, const char *name);