Skip to contentSkip to conversation

master - config: use config checks and add support for creating trees from config definition (config_def_create_tree fn)

PATCH Peter Rajnoha 1 participant 1 message Mar 6, 2013

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=245b85692ec9f30153c1aa7216d81e65bb132792
Commit:        245b85692ec9f30153c1aa7216d81e65bb132792
Parent:        e38aaddb5e72a2123a03dedbb40c2aa594495c17
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Tue Mar 5 17:36:10 2013 +0100
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Wed Mar 6 10:46:35 2013 +0100

config: use config checks and add support for creating trees from config definition (config_def_create_tree fn)

Configuration checking is initiated during config load/processing (_process_config fn) which is part of the command context creation/refresh.

This patch also defines 5 types of trees that could be created from the configuration definition (config_settings.h), the cfg_def_tree_t:

- CFG_DEF_TREE_CURRENT that denotes a tree of all the configuration nodes that are explicitly defined in lvm.conf/--config

- CFG_DEF_TREE_MISSING that denotes a tree of all missing configuration nodes for which default valus are used since they're not explicitly used in lvm.conf/--config

- CFG_DEF_TREE_DEFAULT that denotes a tree of all possible configuration nodes with default values assigned, no matter what the actual lvm.conf/--config is

- CFG_DEF_TREE_NEW that denotes a tree of all new configuration nodes that appeared in given version

- CFG_DEF_TREE_COMPLETE that denotes a tree of the whole configuration tree that is used in LVM2 (a combination of CFG_DEF_TREE_CURRENT + CFG_DEF_TREE_MISSING). This is not implemented yet, it will be added later...

The function that creates the definition tree of given type:

  struct dm_config_tree *config_def_create_tree(struct config_def_tree_spec *spec);

Where the "spec" specifies the tree type to be created:

struct config_def_tree_spec {
cfg_def_tree_t type; /* tree type */
uint16_t version; /* tree at this LVM2 version */
int ignoreadvanced; /* do not include advanced configs */
int ignoreunsupported; /* do not include unsupported configs */
};

This tree can be passed to already existing functions that write the tree on output (like we already do with cmd->cft).

There is a new lvm.conf section called "config" with two new options:

- config/checks which enables/disables checking (enabled by default)

- config/abort_on_errors which enables/disables aborts on any type of mismatch found in the config (disabled by default)

---
 doc/example.conf.in          |   15 +++-
 lib/commands/toolcontext.c   |    5 +
 lib/config/config.c          |  235 ++++++++++++++++++++++++++++++++++++++++++
 lib/config/config.h          |   21 ++++-
 lib/config/config_settings.h |    2 +-
 5 files changed, 274 insertions(+), 4 deletions(-)
doc/example.conf.in +14 -1
index ab83c0c..9670b92 100644
@@ -10,6 +10,20 @@
 # N.B. Take care that each setting only appears once if uncommenting
 # example settings in this file.
 
+# This section allows you to set the way the configuration settings are handled.
+config {
+
+    # If enabled, any LVM2 configuration mismatch is reported.
+    # This implies checking that the configuration key is understood
+    # by LVM2 and that the value of the key is of a proper type.
+    # If disabled, any configuration mismatch is ignored and default
+    # value is used instead without any warning (a message about the
+    # configuration key not being found is issued in verbose mode only).
+    checks = 1
+
+    # If enabled, any configuration mismatch aborts the LVM2 process.
+    abort_on_errors = 0
+}
 
 # This section allows you to configure which block devices should
 # be used by the LVM system.
@@ -359,7 +373,6 @@ shell {
 
 # Miscellaneous global LVM2 settings
 global {
-
     # The file creation mask for any files and directories created.
     # Interpreted as octal if the first digit is zero.
     umask = 077
lib/commands/toolcontext.c +5 -0
index 1cee204..5dff340 100644
@@ -290,6 +290,11 @@ static int _process_config(struct cmd_context *cmd)
 	const char *lvmetad_socket;
 	int udev_disabled = 0;
 
+	if (!config_def_check(cmd, 0, 0, 0) && find_config_tree_bool(cmd, config_abort_on_errors_CFG)) {
+		log_error("LVM configuration invalid.");
+		return 0;
+	}
+
 	/* umask */
 	cmd->default_settings.umask = find_config_tree_int(cmd, global_umask_CFG);
 
lib/config/config.c +235 -0

244 lines not on this page · raw message

lib/config/config.h +19 -2
index 624ef59..fb4993a 100644
@@ -76,6 +76,23 @@ typedef struct cfg_def_item {
 	const char *comment;		/* brief comment */
 } cfg_def_item_t;
 
+/* configuration definition tree types */
+typedef enum {
+	CFG_DEF_TREE_CURRENT,		/* tree of nodes with values currently set in the config */
+	CFG_DEF_TREE_MISSING,		/* tree of nodes missing in current config using default values */
+	CFG_DEF_TREE_COMPLETE,		/* CURRENT + MISSING, the tree actually used within execution, not implemented yet */
+	CFG_DEF_TREE_DEFAULT,		/* tree of all possible config nodes with default values */
+	CFG_DEF_TREE_NEW		/* tree of all new nodes that appeared in given version */
+} cfg_def_tree_t;
+
+/* configuration definition tree specification */
+struct config_def_tree_spec {
+	cfg_def_tree_t type;		/* tree type */
+	uint16_t version;		/* tree at this LVM2 version */
+	int ignoreadvanced;		/* do not include advanced configs */
+	int ignoreunsupported;		/* do not include unsupported configs */
+};
+
 /*
  * Register ID for each possible item in the configuration tree.
  */
@@ -103,8 +120,8 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev,
 			off_t offset, size_t size, off_t offset2, size_t size2,
 			checksum_fn_t checksum_fn, uint32_t checksum);
 int config_file_read(struct dm_config_tree *cft);
-int config_write(struct dm_config_tree *cft, const char *file,
-		 int argc, char **argv);
+int config_write(struct dm_config_tree *cft, const char *file, int argc, char **argv);
+struct dm_config_tree *config_def_create_tree(struct config_def_tree_spec *spec);
 void config_file_destroy(struct dm_config_tree *cft);
 
 time_t config_file_timestamp(struct dm_config_tree *cft);
lib/config/config_settings.h +1 -1
index a7d2625..6229f2e 100644
@@ -67,7 +67,7 @@ cfg_section(dmeventd_CFG_SECTION, "dmeventd", root_CFG_SECTION, 0, vsn(1, 2, 3),
 cfg_section(tags_CFG_SECTION, "tags", root_CFG_SECTION, 0, vsn(1, 0, 18), NULL)
 
 cfg(config_checks_CFG, "checks", config_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2, 2, 99), "Configuration tree check on each LVM command execution.")
-cfg(config_abort_on_errors_CFG, "abort_on_errors", config_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2,2,99), "Abort LVM command execution if configuration is invalid.")
+cfg(config_abort_on_errors_CFG, "abort_on_errors", config_CFG_SECTION, 0, CFG_TYPE_BOOL, 0, vsn(2,2,99), "Abort LVM command execution if configuration is invalid.")
 
 cfg(devices_dir_CFG, "dir", devices_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_DEV_DIR, vsn(1, 0, 0), NULL)
 cfg_array(devices_scan_CFG, "scan", devices_CFG_SECTION, 0, CFG_TYPE_STRING, "#S/dev", vsn(1, 0, 0), NULL)