aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorvin Köhne <CorvinK@beckhoff.com>2022-01-14 10:00:08 +0000
committerEmmanuel Vadot <manu@FreeBSD.org>2022-01-14 11:41:44 +0000
commitfe453891d7ccc8e173d9293b67f5b4608c5378dd (patch)
tree5937926a497ed3f15c8ddda4f2076e52ed26a7e0
parent6171e026be11824495cebe8baf559af673a8e533 (diff)
downloadsrc-fe453891d7ccc8e173d9293b67f5b4608c5378dd.tar.gz
src-fe453891d7ccc8e173d9293b67f5b4608c5378dd.zip
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
-rw-r--r--usr.sbin/bhyve/config.c21
-rw-r--r--usr.sbin/bhyve/config.h12
2 files changed, 33 insertions, 0 deletions
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
@@ -136,6 +136,17 @@ set_config_value_node(nvlist_t *parent, const char *name, const char *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)
{
const char *name;
@@ -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
@@ -100,11 +100,23 @@ 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);