Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/config.h
Show All 39 Lines | |||||
* other configuration variables using a '%(name)' syntax. In this | * other configuration variables using a '%(name)' syntax. In this | ||||
* case, the name must be the the full path of the configuration | * case, the name must be the the full path of the configuration | ||||
* variable. The % character can be escaped with a preceding \ to | * variable. The % character can be escaped with a preceding \ to | ||||
* avoid expansion. Any \ characters must be escaped. | * avoid expansion. Any \ characters must be escaped. | ||||
* | * | ||||
* Configuration variables are stored in a tree. The full path of a | * Configuration variables are stored in a tree. The full path of a | ||||
* variable is specified as a dot-separated name similar to sysctl(8) | * variable is specified as a dot-separated name similar to sysctl(8) | ||||
* OIDs. | * OIDs. | ||||
*/ | */ | ||||
typedef nvlist_t config_node_t; | |||||
#define NODE_TYPE_NODE NV_TYPE_NVLIST | |||||
#define NODE_TYPE_STRING NV_TYPE_STRING | |||||
/* | /* | ||||
* Fetches the value of a configuration variable. If the "raw" value | * Fetches the value of a configuration variable. If the "raw" value | ||||
* contains references to other configuration variables, this function | * contains references to other configuration variables, this function | ||||
* expands those references and returns a pointer to the parsed | * expands those references and returns a pointer to the parsed | ||||
* string. The string's storage is only stable until the next call to | * string. The string's storage is only stable until the next call to | ||||
* this function. | * this function. | ||||
* | * | ||||
* If no node is found, returns NULL. | * If no node is found, returns NULL. | ||||
* | * | ||||
* If 'parent' is NULL, 'name' is assumed to be a top-level variable. | * If 'parent' is NULL, 'name' is assumed to be a top-level variable. | ||||
*/ | */ | ||||
const char *get_config_value_node(const nvlist_t *parent, const char *name); | const char *get_config_value_node(const config_node_t *parent, | ||||
const char *name); | |||||
/* | /* | ||||
* Similar to get_config_value_node but expects a full path to the | * Similar to get_config_value_node but expects a full path to the | ||||
* leaf node. | * leaf node. | ||||
*/ | */ | ||||
const char *get_config_value(const char *path); | const char *get_config_value(const char *path); | ||||
/* Initializes the tree to an empty state. */ | /* Initializes the tree to an empty state. */ | ||||
void init_config(void); | void init_config(void); | ||||
/* | /* | ||||
* Creates an existing configuration node via a dot-separated OID | * Creates an existing configuration node via a dot-separated OID | ||||
* path. Will fail if the path names an existing leaf configuration | * path. Will fail if the path names an existing leaf configuration | ||||
* variable. If the node already exists, this returns a pointer to | * variable. If the node already exists, this returns a pointer to | ||||
* the existing node. | * the existing node. | ||||
*/ | */ | ||||
nvlist_t *create_config_node(const char *path); | config_node_t *create_config_node(const char *path); | ||||
/* | /* | ||||
* Looks for an existing configuration node via a dot-separated OID | * Looks for an existing configuration node via a dot-separated OID | ||||
* path. Will fail if the path names an existing leaf configuration | * path. Will fail if the path names an existing leaf configuration | ||||
* variable. | * variable. | ||||
*/ | */ | ||||
nvlist_t *find_config_node(const char *path); | config_node_t *find_config_node(const char *path); | ||||
/* | /* | ||||
* Similar to the above, but treats the path relative to an existing | * Similar to the above, but treats the path relative to an existing | ||||
* 'parent' node rather than as an absolute path. | * 'parent' node rather than as an absolute path. | ||||
*/ | */ | ||||
nvlist_t *create_relative_config_node(nvlist_t *parent, const char *path); | config_node_t *create_relative_config_node(const config_node_t *parent, | ||||
nvlist_t *find_relative_config_node(nvlist_t *parent, const char *path); | const char *path); | ||||
config_node_t *find_relative_config_node(const config_node_t *parent, | |||||
const char *path); | |||||
jhb: I would not add the 'const' here. 'create' is definitely modifying `*parent`. Perhaps… | |||||
/* | /* | ||||
* Adds or replaces the value of the specified variable. | * Adds or replaces the value of the specified variable. | ||||
* | * | ||||
* If 'parent' is NULL, 'name' is assumed to be a top-level variable. | * If 'parent' is NULL, 'name' is assumed to be a top-level variable. | ||||
*/ | */ | ||||
void set_config_value_node(nvlist_t *parent, const char *name, | void set_config_value_node(const config_node_t *parent, const char *name, | ||||
Not Done Inline ActionsSimilarly, I would not add a 'const' that has to be casted away. jhb: Similarly, I would not add a 'const' that has to be casted away. | |||||
const char *value); | const char *value); | ||||
/* | /* | ||||
* Similar to set_config_value_node but expects a full path to the | * Similar to set_config_value_node but expects a full path to the | ||||
* leaf node. | * leaf node. | ||||
*/ | */ | ||||
void set_config_value(const char *path, const char *value); | void set_config_value(const char *path, const char *value); | ||||
/* Convenience wrappers for boolean variables. */ | /* Convenience wrappers for boolean variables. */ | ||||
bool get_config_bool(const char *path); | bool get_config_bool(const char *path); | ||||
bool get_config_bool_node(const nvlist_t *parent, const char *name); | bool get_config_bool_node(const config_node_t *parent, const char *name); | ||||
bool get_config_bool_default(const char *path, bool def); | bool get_config_bool_default(const char *path, bool def); | ||||
bool get_config_bool_node_default(const nvlist_t *parent, const char *name, | bool get_config_bool_node_default(const config_node_t *parent, | ||||
bool def); | const char *name, bool def); | ||||
void set_config_bool(const char *path, bool value); | void set_config_bool(const char *path, bool value); | ||||
void set_config_bool_node(nvlist_t *parent, const char *name, bool value); | void set_config_bool_node(config_node_t *parent, const char *name, | ||||
bool value); | |||||
/* Node iterator. */ | |||||
const char *config_node_next(const config_node_t *node, int *type, | |||||
void **cookie); | |||||
void dump_config(void); | void dump_config(void); | ||||
#endif /* !__CONFIG_H__ */ | #endif /* !__CONFIG_H__ */ |
I would not add the 'const' here. 'create' is definitely modifying *parent. Perhaps 'find' could use 'const', but it requires you to add -Wcast-qual breaking casts, so it seems simpler to just leave it off as the current API does.