From nobody Fri Jan 14 11:42:12 2022 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 E46BD195FA2F; Fri, 14 Jan 2022 11:42:12 +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 4JZztD50Ntz3MK0; Fri, 14 Jan 2022 11:42:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642160532; 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=qfzyKKWDpZMTEbPCyWTbwZPW3szi1yjZhh4bCVgewkM=; b=VxwD743kNR6lFEtUF+IoMP5LD+lUzCcN4jPj+6rRvBIkxNPEbYsIRQvFbJvoI4EC1zGbke 5mDdlL4WJyRAQaPNa1o6jSd55UCFpceNFCAewlZYrUh5EBUC6cBERqkNFDJSpncXLpU7gx YEa0jODI3XvlCH7+fMjS+kgF6uLmTqpNtne8ozH7zDNYdpP27Jg0dbaXNKLtFFej6Ocr5g TCCSBoQ8svi1ROLB4c/e5cojmSh0G0JYhFsjxLgGatSIVHF6bmElJK8V3d1gFBj8c+dUnO BsdQF74MG3bR3+OCXlQpA8R5Hl6sgg7sRmdE1wUQHN7gA1w16fuoZ5biDztm9Q== 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 78A291331A; Fri, 14 Jan 2022 11:42:12 +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 20EBgChA076952; Fri, 14 Jan 2022 11:42:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20EBgCBW076951; Fri, 14 Jan 2022 11:42:12 GMT (envelope-from git) Date: Fri, 14 Jan 2022 11:42:12 GMT Message-Id: <202201141142.20EBgCBW076951@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: fe453891d7cc - main - bhyve: add nvlist functions for setting unset nodes 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: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fe453891d7ccc8e173d9293b67f5b4608c5378dd Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642160532; 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=qfzyKKWDpZMTEbPCyWTbwZPW3szi1yjZhh4bCVgewkM=; b=Izp10nxMcgVpY0cx8K5OCr+buIo35rdxxkUI8HAUHFgrmOIWdVdCTHGOiEKnSRYRIXNkfS 57E3Ts0Gu0bcA+8+8R02Jz9h5mNRgTUcVHBmjErZMiZNf6Iad6VNkjwMa5ULIEIfqDuKoL 0wGQ1sLObwZT1Htm74r4K7P9X/UjgazhyftNd5i2Wq+UOoL7PRyH++YuNGAU7gM6RtWduh DT6uDkPhQx9R5KqMOTZXdxAeHAhpuhtlBkS4HGHtqLihLMBqLowDK7rpffQTH35J+QE4Z/ Phl+mPBEwuArUnv+tsxeMsvgFvPV0mxdFlhO5/xoo2ydclJYSdwTl80CGzj/fw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642160532; a=rsa-sha256; cv=none; b=vIfJZ95hi7XoFwpHBuL19v/GL2tphImHDeW4qChCRq+43yQiSZY5GZz0KcCsGhw+jU8mcD YS0bbySLUSD/zdzcXDD2Mf3LPCWS8XWH+zwta1oXx4cgS0KpTib/nXfJl+g7+DUNAGQ3Cy RDP7w2FwguH4PbUgF0vXBa/+dLf6jTWJe9f1bx48TdMtGcw8Ky30gP86YClgAIUmEXiacl oUK9Jk9puyywsEbJgyLpSWGZqK/QpgkgnvlrTrKqOy65/9r2yirT1879M8l0kUNIpMUURR ECgTu9lx44pi4YvGYJ+18uds4KSGaASBcjhNsUPFCDTYmXPcF57H2VvFeLzLTA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=fe453891d7ccc8e173d9293b67f5b4608c5378dd commit fe453891d7ccc8e173d9293b67f5b4608c5378dd Author: Corvin Köhne AuthorDate: 2022-01-14 10:00:08 +0000 Commit: Emmanuel Vadot CommitDate: 2022-01-14 11:41:44 +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 --- 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 c9ac9f0a1905..cdea2f4fed01 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 574da966df74..8d3f6f90b2dc 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);