Skip to contentSkip to conversation

master - config: make it possible to do a raw config tree merge

PATCH Peter Rajnoha 1 participant 1 message Jul 8, 2013

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f1e289001286f978630f5e6423acca1af322ebd7
Commit:        f1e289001286f978630f5e6423acca1af322ebd7
Parent:        661406a417e3cbf2170ba7c3debd767d50e99cae
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Mon Jul 8 14:31:44 2013 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Mon Jul 8 15:59:25 2013 +0200

config: make it possible to do a raw config tree merge

Till now, we needed the config tree merge only for merging tag configs with lvm.conf. However, this type of merging did a few extra exceptions:

- leaving out the tags section
- merging values in activation/volume_list
- merging values in devices/filter
- merging values in devices/types

Any other config values were replaced by new values. However, we'd like to do a 'raw merge' as well, simply bypassing the exceptions listed above. This will help us to create a single tree representing the cascaded configs like CONFIG_STRING -> CONFIG_PROFILE -> ...

The reason for this patch is that when trees are cascaded, the first value found while traversing the cascade is used, not making any exceptions like we do for tag configs.

---
 lib/commands/toolcontext.c |    2 +-
 lib/config/config.c        |   69 +++++++++++++++++++++++++-------------------
 lib/config/config.h        |   13 +++++++-
 3 files changed, 52 insertions(+), 32 deletions(-)
lib/commands/toolcontext.c +1 -1
index 4919b93..2c4a698 100644
@@ -659,7 +659,7 @@ static struct dm_config_tree *_merge_config_files(struct cmd_context *cmd, struc
 
 	dm_list_iterate_items(cfl, &cmd->config_files) {
 		/* Merge all config trees into cmd->cft using merge/tag rules */
-		if (!merge_config_tree(cmd, cft, cfl->cft))
+		if (!merge_config_tree(cmd, cft, cfl->cft, CONFIG_MERGE_TYPE_TAGS))
 			return_0;
 	}
 
lib/config/config.c +39 -30

107 lines not on this page · raw message

lib/config/config.h +12 -1
index 9f54af6..94fd1d9 100644
@@ -173,8 +173,19 @@ int config_file_changed(struct dm_config_tree *cft);
 int config_file_check(struct dm_config_tree *cft, const char **filename, struct stat *info);
 
 
+typedef enum {
+	CONFIG_MERGE_TYPE_RAW,	/* always replace old config values with new config values when merging */
+	CONFIG_MERGE_TYPE_TAGS	/* apply some exceptions when merging tag configs:
+				     - skip tags section
+				     - do not replace, but merge values of these settings:
+					activation/volume_list
+					devices/filter
+					devices/types
+				 */
+} config_merge_t;
+
 int merge_config_tree(struct cmd_context *cmd, struct dm_config_tree *cft,
-		      struct dm_config_tree *newdata);
+		      struct dm_config_tree *newdata, config_merge_t);
 
 /*
  * These versions check an override tree, if present, first.