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
This commit is contained in:
parent
6171e026be
commit
fe453891d7
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user