summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2011-10-28 20:06:49 +0000
committerZdenek Kabelac <zkabelac@redhat.com>2011-10-28 20:06:49 +0000
commit7ad1c43b485108bffaf860c6d868a36051b17df2 (patch)
treed76d9671051d85827c7d17aa13c1f02409b66867
parent35d462dafc47a026b2aed55d0ebd769ccbf39473 (diff)
downloadlvm2-7ad1c43b485108bffaf860c6d868a36051b17df2.tar.gz
lvm2-7ad1c43b485108bffaf860c6d868a36051b17df2.tar.xz
lvm2-7ad1c43b485108bffaf860c6d868a36051b17df2.zip
Add find_config_tree_str_allow_empty
Add function to allow read of empty strings as valid arguments. Add a warning message if string argument has ignored value.
-rw-r--r--WHATS_NEW1
-rw-r--r--WHATS_NEW_DM1
-rw-r--r--lib/commands/toolcontext.c6
-rw-r--r--lib/config/config.c6
-rw-r--r--lib/config/config.h2
-rw-r--r--libdm/libdevmapper.h2
-rw-r--r--libdm/libdm-config.c19
7 files changed, 29 insertions, 8 deletions
diff --git a/WHATS_NEW b/WHATS_NEW
index 305ead87..92d33199 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.89 -
==================================
+ Support empty string for log/prefix.
Fix regression that allowed mirrored logs for cluster mirrors.
Don't print char type[8] as a plain string in pvck PV type.
Use vg memory pool implicitely for vg read.
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 79be18f2..cebe079e 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.68 -
==================================
+ Add dm_config_tree_find_str_allow_empty.
Fix compile-time pool memory locking with DEBUG_MEM.
Fix valgrind error reports in free of pool chunks with DEBUG_MEM.
Align size of structure chunk for fast pool allocator to 8 bytes.
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index db5ef030..4dc4c266 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -153,9 +153,9 @@ static void _init_logging(struct cmd_context *cmd)
init_abort_on_internal_errors(find_config_tree_int(cmd, "global/abort_on_internal_errors",
DEFAULT_ABORT_ON_INTERNAL_ERRORS));
- cmd->default_settings.msg_prefix = find_config_tree_str(cmd,
- "log/prefix",
- DEFAULT_MSG_PREFIX);
+ cmd->default_settings.msg_prefix =
+ find_config_tree_str_allow_empty(cmd, "log/prefix", DEFAULT_MSG_PREFIX);
+
init_msg_prefix(cmd->default_settings.msg_prefix);
cmd->default_settings.cmd_name = find_config_tree_int(cmd,
diff --git a/lib/config/config.c b/lib/config/config.c
index cb143367..b7859303 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -183,6 +183,12 @@ const char *find_config_tree_str(struct cmd_context *cmd,
return dm_config_tree_find_str(cmd->cft, path, fail);
}
+const char *find_config_tree_str_allow_empty(struct cmd_context *cmd,
+ const char *path, const char *fail)
+{
+ return dm_config_tree_find_str_allow_empty(cmd->cft, path, fail);
+}
+
int find_config_tree_int(struct cmd_context *cmd, const char *path,
int fail)
{
diff --git a/lib/config/config.h b/lib/config/config.h
index 5edc6cc4..dd6daebd 100644
--- a/lib/config/config.h
+++ b/lib/config/config.h
@@ -44,6 +44,8 @@ const struct dm_config_node *find_config_tree_node(struct cmd_context *cmd,
const char *path);
const char *find_config_tree_str(struct cmd_context *cmd,
const char *path, const char *fail);
+const char *find_config_tree_str_allow_empty(struct cmd_context *cmd,
+ const char *path, const char *fail);
int find_config_tree_int(struct cmd_context *cmd, const char *path,
int fail);
int64_t find_config_tree_int64(struct cmd_context *cmd, const char *path,
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index 84a1786b..3f730ada 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -1385,6 +1385,8 @@ float dm_config_find_float(const struct dm_config_node *cn, const char *path, fl
const struct dm_config_node *dm_config_tree_find_node(const struct dm_config_tree *cft, const char *path);
const char *dm_config_tree_find_str(const struct dm_config_tree *cft,
const char *path, const char *fail);
+const char *dm_config_tree_find_str_allow_empty(const struct dm_config_tree *cft,
+ const char *path, const char *fail);
int dm_config_tree_find_int(const struct dm_config_tree *cft,
const char *path, int fail);
int64_t dm_config_tree_find_int64(const struct dm_config_tree *cft,
diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c
index a831936e..8fee4ecc 100644
--- a/libdm/libdm-config.c
+++ b/libdm/libdm-config.c
@@ -919,15 +919,18 @@ static const struct dm_config_node *_find_first_config_node(const void *start, c
}
static const char *_find_config_str(const void *start, node_lookup_fn find_fn,
- const char *path, const char *fail)
+ const char *path, const char *fail, int allow_empty)
{
const struct dm_config_node *n = find_fn(start, path);
/* Empty strings are ignored */
- if ((n && n->v && n->v->type == DM_CFG_STRING) && (*n->v->v.str)) {
+ if ((n && n->v && n->v->type == DM_CFG_STRING) &&
+ (allow_empty || (*n->v->v.str))) {
log_very_verbose("Setting %s to %s", path, n->v->v.str);
return n->v->v.str;
- }
+ } else if (n && (!n->v || (n->v->type != DM_CFG_STRING) ||
+ (!allow_empty && fail)))
+ log_warn("WARNING: Ignoring unsupported value for %s.", path);
if (fail)
log_very_verbose("%s not found in config: defaulting to %s",
@@ -938,7 +941,7 @@ static const char *_find_config_str(const void *start, node_lookup_fn find_fn,
const char *dm_config_find_str(const struct dm_config_node *cn,
const char *path, const char *fail)
{
- return _find_config_str(cn, _find_config_node, path, fail);
+ return _find_config_str(cn, _find_config_node, path, fail, 0);
}
static int64_t _find_config_int64(const void *start, node_lookup_fn find,
@@ -1060,7 +1063,13 @@ const struct dm_config_node *dm_config_tree_find_node(const struct dm_config_tre
const char *dm_config_tree_find_str(const struct dm_config_tree *cft, const char *path,
const char *fail)
{
- return _find_config_str(cft, _find_first_config_node, path, fail);
+ return _find_config_str(cft, _find_first_config_node, path, fail, 0);
+}
+
+const char *dm_config_tree_find_str_allow_empty(const struct dm_config_tree *cft, const char *path,
+ const char *fail)
+{
+ return _find_config_str(cft, _find_first_config_node, path, fail, 1);
}
int dm_config_tree_find_int(const struct dm_config_tree *cft, const char *path, int fail)