Skip to contentSkip to conversation

master - config: add find_config_tree_array

PATCH Peter Rajnoha 1 participant 1 message Jul 8, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=67a61cce1b26e91eb765a682f66be67bd997f09f
Commit:        67a61cce1b26e91eb765a682f66be67bd997f09f
Parent:        d9d47b7b88b47719ff972f27a448f9cdf6982c4a
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Wed Jul 8 10:43:59 2015 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Wed Jul 8 12:59:22 2015 +0200

config: add find_config_tree_array

Before, we used general find_config_tree_node function to retrieve array values. This had a downside where if the node was not found, we had to insert default values directly in-situ after the find_config_tree_node call. This way, we had two copies of default values - one in config_settings.h and the other one directly in the code where we found out that find_config_tree_node returned NULL and hence we needed to fall back to defaults.

With separate find_config_tree_array used for array config values, we keep all the defaults centrally in config_settings.h because the new find_config_tree_array automatically returns these defaults if it can't find any value set in the configuration.

This patch just makes the behaviour exactly the same for arrays as for any other non-array type where we call find_config_tree_<type> already, hence making the internal interface for handling array values consistent with the rest of the config types.

---
 lib/commands/toolcontext.c |    2 +
 lib/config/config.c        |   59 ++++++++++++++++++++++++++++++++++++++++---
 lib/config/config.h        |    1 +
 3 files changed, 57 insertions(+), 5 deletions(-)
lib/commands/toolcontext.c +2 -0
index 4265954..00db078 100644
@@ -1235,6 +1235,8 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
 		cmd->lvmetad_filter = NULL;
 	}
 
+	cn = find_config_tree_array(cmd, devices_filter_CFG, NULL);
+
 	/* filter component 1 */
 	if ((cn = find_config_tree_node(cmd, devices_filter_CFG, NULL))) {
 		if (!(filter_components[1] = regex_filter_create(cn->v)))
lib/config/config.c +54 -5

95 lines not on this page · raw message

lib/config/config.h +1 -0
index 24d1f3f..a20fd8f 100644
@@ -272,6 +272,7 @@ int find_config_tree_int(struct cmd_context *cmd, int id, struct profile *profil
 int64_t find_config_tree_int64(struct cmd_context *cmd, int id, struct profile *profile);
 float find_config_tree_float(struct cmd_context *cmd, int id, struct profile *profile);
 int find_config_tree_bool(struct cmd_context *cmd, int id, struct profile *profile);
+struct dm_config_node *find_config_tree_array(struct cmd_context *cmd, int id, struct profile *profile);
 
 /*
  * Functions for configuration settings for which the default