master - dumpconfig: add --withcomments and --withversions switch
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=088d88cfe27ba6...
Commit: 088d88cfe27ba6f5f78812af778cde54d4aed9c1
Parent: e29cd366a24859195f92b874d4bf260a3cc63bc2
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Mar 5 18:21:13 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Mar 6 10:46:36 2013 +0100
dumpconfig: add --withcomments and --withversions switch
lvm dumpconfig [--withcomments] [--withversions]
The --withcomments causes the comments to appear on output before each
config node (if they were defined in config_settings.h).
The --withversions causes a one line extra comment to appear on output
before each config node with the version information in which the
configuration setting first appeared.
---
lib/config/config.c | 83 +++++++++++++++++++++++++++++++++++++++++++-------
lib/config/config.h | 4 ++-
tools/args.h | 2 +
tools/commands.h | 5 ++-
tools/dumpconfig.c | 4 ++-
5 files changed, 83 insertions(+), 15 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index 5a51a29..e8e0379 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -808,36 +808,95 @@ int merge_config_tree(struct cmd_context *cmd, struct dm_config_tree *cft,
return 1;
}
-static int _putline_fn(const char *line, void *baton) {
- FILE *fp = baton;
- fprintf(fp, "%s\n", line);
- return 1;
+struct out_baton {
+ FILE *fp;
+ int withcomment;
+ int withversion;
};
-int config_write(struct dm_config_tree *cft, const char *file,
- int argc, char **argv)
+static int _out_prefix_fn(const struct dm_config_node *cn, const char *line, void *baton)
+{
+ struct out_baton *out = baton;
+ struct cfg_def_item *cfg_def;
+ char version[9]; /* 8+1 chars for max version of 7.15.511 */
+ const char *path;
+ const char *node_type_name = cn->v ? "option" : "section";
+
+ if (cn->id < 0)
+ return 1;
+
+ if (!cn->id) {
+ log_error(INTERNAL_ERROR "Configuration node %s has invalid id.", cn->key);
+ return 0;
+ }
+
+ cfg_def = cfg_def_get_item_p(cn->id);
+
+ if (out->withcomment) {
+ path = cfg_def_get_path(cfg_def);
+ fprintf(out->fp, "%s# Configuration %s %s.\n", line, node_type_name, path);
+
+ if (cfg_def->comment)
+ fprintf(out->fp, "%s# %s\n", line, cfg_def->comment);
+ }
+
+ if (out->withversion) {
+ if (dm_snprintf(version, 9, "%u.%u.%u",
+ (cfg_def->since_version & 0xE000) >> 13,
+ (cfg_def->since_version & 0x1E00) >> 9,
+ (cfg_def->since_version & 0x1FF)) == -1) {
+ log_error("_out_prefix_fn: couldn't create version string");
+ return 0;
+ }
+ fprintf(out->fp, "%s# Since version %s.\n", line, version);
+ }
+
+ return 1;
+}
+
+static int _out_line_fn(const struct dm_config_node *cn, const char *line, void *baton)
+{
+ struct out_baton *out = baton;
+ fprintf(out->fp, "%s\n", line);
+ return 1;
+}
+
+static int _out_suffix_fn(const struct dm_config_node *cn, const char *line, void *baton)
{
+ return 1;
+}
+
+int config_write(struct dm_config_tree *cft,
+ int withcomment, int withversion,
+ const char *file, int argc, char **argv)
+{
+ struct out_baton baton = {0, 0, 0};
const struct dm_config_node *cn;
+ const struct dm_config_node_out_spec out_spec = {.prefix_fn = _out_prefix_fn,
+ .line_fn = _out_line_fn,
+ .suffix_fn = _out_suffix_fn};
int r = 1;
- FILE *fp = NULL;
+
+ baton.withcomment = withcomment;
+ baton.withversion = withversion;
if (!file) {
- fp = stdout;
+ baton.fp = stdout;
file = "stdout";
- } else if (!(fp = fopen(file, "w"))) {
+ } else if (!(baton.fp = fopen(file, "w"))) {
log_sys_error("open", file);
return 0;
}
log_verbose("Dumping configuration to %s", file);
if (!argc) {
- if (!dm_config_write_node(cft->root, _putline_fn, fp)) {
+ if (!dm_config_write_node_out(cft->root, &out_spec, &baton)) {
log_error("Failure while writing to %s", file);
r = 0;
}
} else while (argc--) {
if ((cn = dm_config_find_node(cft->root, *argv))) {
- if (!dm_config_write_one_node(cn, _putline_fn, fp)) {
+ if (!dm_config_write_one_node_out(cn, &out_spec, &baton)) {
log_error("Failure while writing to %s", file);
r = 0;
}
@@ -848,7 +907,7 @@ int config_write(struct dm_config_tree *cft, const char *file,
argv++;
}
- if (fp && dm_fclose(fp)) {
+ if (baton.fp && dm_fclose(baton.fp)) {
stack;
r = 0;
}
diff --git a/lib/config/config.h b/lib/config/config.h
index fb4993a..7e40420 100644
--- a/lib/config/config.h
+++ b/lib/config/config.h
@@ -120,7 +120,9 @@ 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,
+ int withcomment, int withversion,
+ 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);
diff --git a/tools/args.h b/tools/args.h
index 8d9abd5..1e85096 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -80,6 +80,8 @@ arg(stripes_long_ARG, '\0', "stripes", int_arg, 0)
arg(sysinit_ARG, '\0', "sysinit", NULL, 0)
arg(thinpool_ARG, '\0', "thinpool", string_arg, 0)
arg(configtype_ARG, '\0', "type", string_arg, 0)
+arg(withcomments_ARG, '\0', "withcomments", NULL, 0)
+arg(withversions_ARG, '\0', "withversions", NULL, 0)
arg(atversion_ARG, '\0', "atversion", string_arg, 0)
arg(validate_ARG, '\0', "validate", NULL, 0)
diff --git a/tools/commands.h b/tools/commands.h
index dc245b9..36928c0 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -34,10 +34,13 @@ xx(dumpconfig,
"dumpconfig\n"
"\t[-f|--file filename] \n"
"\t[--type {current|default|missing|new} \n"
+ "\t[--withcomments] \n"
+ "\t[--withversions] \n"
"\t[--atversion version]] \n"
"\t[--validate]\n"
"\t[ConfigurationNode...]\n",
- file_ARG, configtype_ARG, atversion_ARG, validate_ARG)
+ file_ARG, configtype_ARG, withcomments_ARG, atversion_ARG,
+ withversions_ARG, validate_ARG)
xx(formats,
"List available metadata formats",
diff --git a/tools/dumpconfig.c b/tools/dumpconfig.c
index ac90a95..384f52d 100644
--- a/tools/dumpconfig.c
+++ b/tools/dumpconfig.c
@@ -89,7 +89,9 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
cft = config_def_create_tree(&tree_spec);
}
- if (!config_write(cft, file, argc, argv)) {
+ if (!config_write(cft, arg_count(cmd, withcomments_ARG),
+ arg_count(cmd, withversions_ARG),
+ file, argc, argv)) {
stack;
r = ECMD_FAILED;
}
10 years, 9 months
master - config: add support for enhanced config node output
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e29cd366a24859...
Commit: e29cd366a24859195f92b874d4bf260a3cc63bc2
Parent: 34350963d1b02d54205b1bdaa0c7778f4c5601fe
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Mar 5 18:02:13 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Mar 6 10:46:36 2013 +0100
config: add support for enhanced config node output
There's a possibility to interconnect the dm_config_node with an
ID, which in our case is used to reference the configuration
definition ID from config_settings.h. So simply interconnecting
struct dm_config_node with struct cfg_def_item.
This patch also adds support for enhanced config node output besides
existing "output line by line". This patch adds a possibility to
register a callback that gets called *before* the config node is
processed line by line (for example to include any headers on output)
and *after* the config node is processed line by line (to include any
footers on output). Also, it adds the config node reference itself
as the callback arg in addition to have a possibility to extract more
information from the config node itself if needed when processing the
output callback (e.g. the key name, the id, or whether this is a
section or a value etc...).
If the config node from lvm.conf/--config tree is recognized and valid,
it's always coupled with the config node definition ID from
config_settings.h:
struct dm_config_node {
int id;
const char *key;
struct dm_config_node *parent, *sib, *child;
struct dm_config_value *v;
}
For example if the dm_config_node *cn holds "devices/dev" configuration,
then the cn->id holds "devices_dev_CFG" ID from config_settings.h, -1 if
not found in config_settings.h and 0 if matching has not yet been done.
To support the enhanced config node output, a new structure has been
defined in libdevmapper to register it:
struct dm_config_node_out_spec {
dm_config_node_out_fn prefix_fn; /* called before processing config node lines */
dm_config_node_out_fn line_fn; /* called for each config node line */
dm_config_node_out_fn suffix_fn; /* called after processing config node lines */
};
Where dm_config_node_out_fn is:
typedef int (*dm_config_node_out_fn)(const struct dm_config_node *cn, const char *line, void *baton);
(so in comparison to existing callbacks for config node output, it has
an extra dm_config_node *cn arg in addition)
This patch also adds these functions to libdevmapper:
- dm_config_write_node_out
- dm_config_write_one_node_out
...which have exactly the same functionality as their counterparts
without the "out" suffix. The "*_out" functions adds the extra hooks
for enhanced config output (prefix_fn and suffix_fn mentioned above).
One can still use the old interface for config node output, this is
just an enhancement for those who'd like to modify the output more
extensively.
---
lib/config/config.c | 6 +++
libdm/libdevmapper.h | 17 +++++++++
libdm/libdm-config.c | 91 +++++++++++++++++++++++++++++++++-----------------
3 files changed, 83 insertions(+), 31 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index a02f478..5a51a29 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -472,6 +472,7 @@ static int _config_def_check_node(const char *vp, char *pvp, char *rp, char *prp
if (cn->v) {
log_warn_suppress(suppress_messages,
"Configuration setting \"%s\" unknown.", rp);
+ cn->id = -1;
return 0;
}
@@ -482,11 +483,14 @@ static int _config_def_check_node(const char *vp, char *pvp, char *rp, char *prp
if (!(def = (cfg_def_item_t *) dm_hash_lookup(ht, vp))) {
log_warn_suppress(suppress_messages,
"Configuration section \"%s\" unknown.", rp);
+ cn->id = -1;
return 0;
}
}
def->flags |= CFG_USED;
+ cn->id = def->id;
+
if (!_config_def_check_node_value(rp, cn->v, def, suppress_messages))
return 0;
@@ -962,6 +966,8 @@ static struct dm_config_node *_add_def_node(struct dm_config_tree *cft,
return NULL;
}
+ cn->id = def->id;
+
if (!(def->type & CFG_TYPE_ARRAY)) {
switch (def->type) {
case CFG_TYPE_SECTION:
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index 8c349c5..0460afa 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -1496,6 +1496,7 @@ struct dm_config_value {
};
struct dm_config_node {
+ int id;
const char *key;
struct dm_config_node *parent, *sib, *child;
struct dm_config_value *v;
@@ -1528,11 +1529,27 @@ struct dm_config_tree *dm_config_remove_cascaded_tree(struct dm_config_tree *cft
void dm_config_destroy(struct dm_config_tree *cft);
+/* Simple output line by line. */
typedef int (*dm_putline_fn)(const char *line, void *baton);
+/* More advaced output with config node reference. */
+typedef int (*dm_config_node_out_fn)(const struct dm_config_node *cn, const char *line, void *baton);
+
+/*
+ * Specification for advanced config node output.
+ */
+struct dm_config_node_out_spec {
+ dm_config_node_out_fn prefix_fn; /* called before processing config node lines */
+ dm_config_node_out_fn line_fn; /* called for each config node line */
+ dm_config_node_out_fn suffix_fn; /* called after processing config node lines */
+};
+
/* Write the node and any subsequent siblings it has. */
int dm_config_write_node(const struct dm_config_node *cn, dm_putline_fn putline, void *baton);
+int dm_config_write_node_out(const struct dm_config_node *cn, const struct dm_config_node_out_spec *out_spec, void *baton);
+
/* Write given node only without subsequent siblings. */
int dm_config_write_one_node(const struct dm_config_node *cn, dm_putline_fn putline, void *baton);
+int dm_config_write_one_node_out(const struct dm_config_node *cn, const struct dm_config_node_out_spec *out_spec, void *baton);
struct dm_config_node *dm_config_find_node(const struct dm_config_node *cn, const char *path);
int dm_config_has_node(const struct dm_config_node *cn, const char *path);
diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c
index 4705a1c..368f9e3 100644
--- a/libdm/libdm-config.c
+++ b/libdm/libdm-config.c
@@ -50,10 +50,11 @@ struct parser {
struct dm_pool *mem;
};
-struct output_line {
+struct config_output {
struct dm_pool *mem;
dm_putline_fn putline;
- void *putline_baton;
+ const struct dm_config_node_out_spec *spec;
+ void *baton;
};
static void _get_token(struct parser *p, int tok_prev);
@@ -189,9 +190,9 @@ struct dm_config_tree *dm_config_from_string(const char *config_settings)
return cft;
}
-static int _line_start(struct output_line *outline)
+static int _line_start(struct config_output *out)
{
- if (!dm_pool_begin_object(outline->mem, 128)) {
+ if (!dm_pool_begin_object(out->mem, 128)) {
log_error("dm_pool_begin_object failed for config line");
return 0;
}
@@ -200,7 +201,7 @@ static int _line_start(struct output_line *outline)
}
__attribute__ ((format(printf, 2, 3)))
-static int _line_append(struct output_line *outline, const char *fmt, ...)
+static int _line_append(struct config_output *out, const char *fmt, ...)
{
char buf[4096];
va_list ap;
@@ -215,7 +216,7 @@ static int _line_append(struct output_line *outline, const char *fmt, ...)
return 0;
}
- if (!dm_pool_grow_object(outline->mem, &buf[0], strlen(buf))) {
+ if (!dm_pool_grow_object(out->mem, &buf[0], strlen(buf))) {
log_error("dm_pool_grow_object failed for config line");
return 0;
}
@@ -223,28 +224,32 @@ static int _line_append(struct output_line *outline, const char *fmt, ...)
return 1;
}
-#define line_append(args...) do {if (!_line_append(outline, args)) {return_0;}} while (0)
+#define line_append(args...) do {if (!_line_append(out, args)) {return_0;}} while (0)
-static int _line_end(struct output_line *outline)
+static int _line_end(const struct dm_config_node *cn, struct config_output *out)
{
const char *line;
- if (!dm_pool_grow_object(outline->mem, "\0", 1)) {
+ if (!dm_pool_grow_object(out->mem, "\0", 1)) {
log_error("dm_pool_grow_object failed for config line");
return 0;
}
- line = dm_pool_end_object(outline->mem);
+ line = dm_pool_end_object(out->mem);
- if (!outline->putline)
+ if (!out->putline && !out->spec)
return 0;
- outline->putline(line, outline->putline_baton);
+ if (out->putline)
+ out->putline(line, out->baton);
+
+ if (out->spec && out->spec->line_fn)
+ out->spec->line_fn(cn, line, out->baton);
return 1;
}
-static int _write_value(struct output_line *outline, const struct dm_config_value *v)
+static int _write_value(struct config_output *out, const struct dm_config_value *v)
{
char *buf;
@@ -279,7 +284,7 @@ static int _write_value(struct output_line *outline, const struct dm_config_valu
}
static int _write_config(const struct dm_config_node *n, int only_one,
- struct output_line *outline, int level)
+ struct config_output *out, int level)
{
char space[MAX_INDENT + 1];
int l = (level < MAX_INDENT) ? level : MAX_INDENT;
@@ -293,16 +298,19 @@ static int _write_config(const struct dm_config_node *n, int only_one,
space[i] = '\0';
do {
- if (!_line_start(outline))
+ if (out->spec && out->spec->prefix_fn)
+ out->spec->prefix_fn(n, space, out->baton);
+
+ if (!_line_start(out))
return_0;
line_append("%s%s", space, n->key);
if (!n->v) {
/* it's a sub section */
line_append(" {");
- if (!_line_end(outline))
+ if (!_line_end(n, out))
return_0;
- _write_config(n->child, 0, outline, level + 1);
- if (!_line_start(outline))
+ _write_config(n->child, 0, out, level + 1);
+ if (!_line_start(out))
return_0;
line_append("%s}", space);
} else {
@@ -312,7 +320,7 @@ static int _write_config(const struct dm_config_node *n, int only_one,
if (v->next) {
line_append("[");
while (v && v->type != DM_CFG_EMPTY_ARRAY) {
- if (!_write_value(outline, v))
+ if (!_write_value(out, v))
return_0;
v = v->next;
if (v && v->type != DM_CFG_EMPTY_ARRAY)
@@ -320,11 +328,15 @@ static int _write_config(const struct dm_config_node *n, int only_one,
}
line_append("]");
} else
- if (!_write_value(outline, v))
+ if (!_write_value(out, v))
return_0;
}
- if (!_line_end(outline))
+ if (!_line_end(n, out))
return_0;
+
+ if (out->spec && out->spec->suffix_fn)
+ out->spec->suffix_fn(n, space, out->baton);
+
n = n->sib;
} while (n && !only_one);
/* FIXME: add error checking */
@@ -332,29 +344,46 @@ static int _write_config(const struct dm_config_node *n, int only_one,
}
static int _write_node(const struct dm_config_node *cn, int only_one,
- dm_putline_fn putline, void *baton)
+ dm_putline_fn putline,
+ const struct dm_config_node_out_spec *out_spec,
+ void *baton)
{
- struct output_line outline;
- if (!(outline.mem = dm_pool_create("config_line", 1024)))
+ struct config_output out;
+ if (!(out.mem = dm_pool_create("config_output", 1024)))
return_0;
- outline.putline = putline;
- outline.putline_baton = baton;
- if (!_write_config(cn, only_one, &outline, 0)) {
- dm_pool_destroy(outline.mem);
+ out.putline = putline;
+ out.spec = out_spec;
+ out.baton = baton;
+ if (!_write_config(cn, only_one, &out, 0)) {
+ dm_pool_destroy(out.mem);
return_0;
}
- dm_pool_destroy(outline.mem);
+ dm_pool_destroy(out.mem);
return 1;
}
int dm_config_write_one_node(const struct dm_config_node *cn, dm_putline_fn putline, void *baton)
{
- return _write_node(cn, 1, putline, baton);
+ return _write_node(cn, 1, putline, NULL, baton);
}
int dm_config_write_node(const struct dm_config_node *cn, dm_putline_fn putline, void *baton)
{
- return _write_node(cn, 0, putline, baton);
+ return _write_node(cn, 0, putline, NULL, baton);
+}
+
+int dm_config_write_one_node_out(const struct dm_config_node *cn,
+ const struct dm_config_node_out_spec *out_spec,
+ void *baton)
+{
+ return _write_node(cn, 1, NULL, out_spec, baton);
+}
+
+int dm_config_write_node_out(const struct dm_config_node *cn,
+ const struct dm_config_node_out_spec *out_spec,
+ void *baton)
+{
+ return _write_node(cn, 0, NULL, out_spec, baton);
}
/*
10 years, 9 months
master - dumpconfig: add --type, --atversion and --validate arg
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=34350963d1b02d...
Commit: 34350963d1b02d54205b1bdaa0c7778f4c5601fe
Parent: 245b85692ec9f30153c1aa7216d81e65bb132792
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Mar 5 17:48:29 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Mar 6 10:46:36 2013 +0100
dumpconfig: add --type, --atversion and --validate arg
lvm dumpconfig [--type {current|default|missing|new}] [--atversion] [--validate]
This patch adds above-mentioned args to lvm dumpconfig and it maps them
to creation and writing out a configuration tree of a specific type
(see also previous commit):
- current maps to CFG_TYPE_CURRENT
- default maps to CFG_TYPE_DEFAULT
- missing maps to CFG_TYPE_MISSING
- new maps to CFG_TYPE_NEW
If --type is not defined, dumpconfig defaults to "--type current"
which is the original behaviour of dumpconfig before all these changes.
The --validate option just validates current configuration tree
(lvm.conf/--config) and it writes a simple status message:
"LVM configuration valid" or "LVM configuration invalid"
---
lib/config/config.c | 2 +-
tools/args.h | 3 ++
tools/commands.h | 13 +++++---
tools/dumpconfig.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++--
tools/tools.h | 1 +
5 files changed, 90 insertions(+), 9 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index 43f9d21..a02f478 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -488,7 +488,7 @@ static int _config_def_check_node(const char *vp, char *pvp, char *rp, char *prp
def->flags |= CFG_USED;
if (!_config_def_check_node_value(rp, cn->v, def, suppress_messages))
- return 0;
+ return 0;
def->flags |= CFG_VALID;
return 1;
diff --git a/tools/args.h b/tools/args.h
index 08ace69..8d9abd5 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -79,6 +79,9 @@ arg(force_long_ARG, '\0', "force", NULL, ARG_COUNTABLE)
arg(stripes_long_ARG, '\0', "stripes", int_arg, 0)
arg(sysinit_ARG, '\0', "sysinit", NULL, 0)
arg(thinpool_ARG, '\0', "thinpool", string_arg, 0)
+arg(configtype_ARG, '\0', "type", string_arg, 0)
+arg(atversion_ARG, '\0', "atversion", string_arg, 0)
+arg(validate_ARG, '\0', "validate", NULL, 0)
/* Allow some variations */
arg(resizable_ARG, '\0', "resizable", yes_no_arg, 0)
diff --git a/tools/commands.h b/tools/commands.h
index dedba54..dc245b9 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -29,12 +29,15 @@ xx(e2fsadm,
*********/
xx(dumpconfig,
- "Dump active configuration",
+ "Dump configuration",
PERMITTED_READ_ONLY,
- "dumpconfig "
- "\t[-f|--file filename] " "\n"
- "[ConfigurationVariable...]\n",
- file_ARG)
+ "dumpconfig\n"
+ "\t[-f|--file filename] \n"
+ "\t[--type {current|default|missing|new} \n"
+ "\t[--atversion version]] \n"
+ "\t[--validate]\n"
+ "\t[ConfigurationNode...]\n",
+ file_ARG, configtype_ARG, atversion_ARG, validate_ARG)
xx(formats,
"List available metadata formats",
diff --git a/tools/dumpconfig.c b/tools/dumpconfig.c
index c5f5226..ac90a95 100644
--- a/tools/dumpconfig.c
+++ b/tools/dumpconfig.c
@@ -15,14 +15,88 @@
#include "tools.h"
+static int _get_vsn(struct cmd_context *cmd, unsigned int *major,
+ unsigned int *minor, unsigned int *patchlevel)
+{
+ const char *atversion = arg_str_value(cmd, atversion_ARG, NULL);
+
+ if (!atversion)
+ atversion = LVM_VERSION;
+
+ if (sscanf(atversion, "%u.%u.%u", major, minor, patchlevel) != 3) {
+ log_error("Incorrect version format.");
+ return 0;
+ }
+
+ return 1;
+}
+
int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
{
const char *file = arg_str_value(cmd, file_ARG, NULL);
+ const char *type = arg_str_value(cmd, configtype_ARG, "current");
+ unsigned int major, minor, patchlevel;
+ struct config_def_tree_spec tree_spec = {0};
+ struct dm_config_tree *cft;
+ int r = ECMD_PROCESSED;
+
+ if (arg_count(cmd, configtype_ARG) && arg_count(cmd, validate_ARG)) {
+ log_error("Only one of --type and --validate permitted.");
+ return EINVALID_CMD_LINE;
+ }
+
+ if (arg_count(cmd, atversion_ARG) && !arg_count(cmd, configtype_ARG)) {
+ log_error("--atversion requires --type");
+ return EINVALID_CMD_LINE;
+ }
+
+ if (arg_count(cmd, validate_ARG)) {
+ if (config_def_check(cmd, 1, 1, 0)) {
+ log_print("LVM configuration valid.");
+ return ECMD_PROCESSED;
+ } else {
+ log_error("LVM configuration invalid.");
+ return ECMD_FAILED;
+ }
+ }
+
+ if (!strcmp(type, "current")) {
+ if (arg_count(cmd, atversion_ARG)) {
+ log_error("--atversion has no effect with --type current");
+ return EINVALID_CMD_LINE;
+ }
+ cft = cmd->cft;
+ tree_spec.type = CFG_DEF_TREE_CURRENT;
+ config_def_check(cmd, 1, 1, 1);
+ }
- if (!config_write(cmd->cft, file, argc, argv)) {
+ else if (!strcmp(type, "default"))
+ tree_spec.type = CFG_DEF_TREE_DEFAULT;
+ else if (!strcmp(type, "missing"))
+ tree_spec.type = CFG_DEF_TREE_MISSING;
+ else if (!strcmp(type, "new"))
+ tree_spec.type = CFG_DEF_TREE_NEW;
+ else {
+ log_error("Incorrect type of configuration specified. "
+ "Expected one of: current, default, missing, new.");
+ return EINVALID_CMD_LINE;
+ }
+
+ if (tree_spec.type != CFG_DEF_TREE_CURRENT) {
+ if (!_get_vsn(cmd, &major, &minor, &patchlevel))
+ return EINVALID_CMD_LINE;
+ tree_spec.version = vsn(major, minor, patchlevel);
+ cft = config_def_create_tree(&tree_spec);
+ }
+
+ if (!config_write(cft, file, argc, argv)) {
stack;
- return ECMD_FAILED;
+ r = ECMD_FAILED;
}
- return ECMD_PROCESSED;
+ /* cmd->cft (the "current" tree) is destroyed with cmd context destroy! */
+ if (tree_spec.type != CFG_DEF_TREE_CURRENT && cft)
+ dm_pool_destroy(cft->mem);
+
+ return r;
}
diff --git a/tools/tools.h b/tools/tools.h
index a3ad9fd..673e40b 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -29,6 +29,7 @@
#include "archiver.h"
#include "lvmcache.h"
#include "lvmetad.h"
+#include "lvm-version.h"
#include "config.h"
#include "defaults.h"
#include "dev-cache.h"
10 years, 9 months
master - config: use config checks and add support for creating trees from config definition (config_def_create_tree fn)
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=245b85692ec9f3...
Commit: 245b85692ec9f30153c1aa7216d81e65bb132792
Parent: e38aaddb5e72a2123a03dedbb40c2aa594495c17
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Mar 5 17:36:10 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
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(-)
diff --git a/doc/example.conf.in b/doc/example.conf.in
index ab83c0c..9670b92 100644
--- a/doc/example.conf.in
+++ b/doc/example.conf.in
@@ -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
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 1cee204..5dff340 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -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);
diff --git a/lib/config/config.c b/lib/config/config.c
index 6f33c12..43f9d21 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -28,6 +28,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
+#include <ctype.h>
struct config_file {
time_t timestamp;
@@ -851,3 +852,237 @@ int config_write(struct dm_config_tree *cft, const char *file,
return r;
}
+static struct dm_config_value *_get_def_array_values(struct dm_config_tree *cft,
+ cfg_def_item_t *def)
+{
+ char *enc_value, *token, *p, *r;
+ struct dm_config_value *array = NULL, *v = NULL, *oldv = NULL;
+
+ if (!def->default_value.v_CFG_TYPE_STRING) {
+ if (!(array = dm_config_create_value(cft))) {
+ log_error("Failed to create default empty array for %s.", def->name);
+ return NULL;
+ }
+ array->type = DM_CFG_EMPTY_ARRAY;
+ return array;
+ }
+
+ if (!(p = token = enc_value = dm_strdup(def->default_value.v_CFG_TYPE_STRING))) {
+ log_error("_get_def_array_values: dm_strdup failed");
+ return NULL;
+ }
+ /* Proper value always starts with '#'. */
+ if (token[0] != '#')
+ goto bad;
+
+ while (token) {
+ /* Move to type identifier. Error on no char. */
+ token++;
+ if (!token[0])
+ goto bad;
+
+ /* Move to the actual value and decode any "##" into "#". */
+ p = token + 1;
+ while ((p = strchr(p, '#')) && p[1] == '#') {
+ memmove(p, p + 1, strlen(p));
+ p++;
+ }
+ /* Separate the value out of the whole string. */
+ if (p)
+ p[0] = '\0';
+
+ if (!(v = dm_config_create_value(cft))) {
+ log_error("Failed to create default config array value for %s.", def->name);
+ dm_free(enc_value);
+ }
+ if (oldv)
+ oldv->next = v;
+ if (!array)
+ array = v;
+
+ switch (toupper(token[0])) {
+ case 'I':
+ case 'B':
+ v->v.i = strtoll(token + 1, &r, 10);
+ if (*r)
+ goto bad;
+ v->type = DM_CFG_INT;
+ break;
+ case 'F':
+ v->v.f = strtod(token + 1, &r);
+ if (*r)
+ goto bad;
+ v->type = DM_CFG_FLOAT;
+ break;
+ case 'S':
+ if (!(r = dm_pool_alloc(cft->mem, strlen(token + 1)))) {
+ dm_free(enc_value);
+ log_error("Failed to duplicate token for default "
+ "array value of %s.", def->name);
+ return NULL;
+ }
+ memcpy(r, token + 1, strlen(token + 1));
+ v->v.str = r;
+ v->type = DM_CFG_STRING;
+ break;
+ default:
+ goto bad;
+ }
+
+ oldv = v;
+ token = p;
+ }
+
+ dm_free(enc_value);
+ return array;
+bad:
+ log_error(INTERNAL_ERROR "Default array value malformed for \"%s\", "
+ "value: \"%s\", token: \"%s\".", def->name,
+ def->default_value.v_CFG_TYPE_STRING, token);
+ dm_free(enc_value);
+ return NULL;
+}
+
+static struct dm_config_node *_add_def_node(struct dm_config_tree *cft,
+ struct config_def_tree_spec *spec,
+ struct dm_config_node *parent,
+ struct dm_config_node *relay,
+ cfg_def_item_t *def)
+{
+ struct dm_config_node *cn;
+ const char *str;
+
+ if (!(cn = dm_config_create_node(cft, def->name))) {
+ log_error("Failed to create default config setting node.");
+ return NULL;
+ }
+
+ if (!(def->type & CFG_TYPE_SECTION) && (!(cn->v = dm_config_create_value(cft)))) {
+ log_error("Failed to create default config setting node value.");
+ return NULL;
+ }
+
+ if (!(def->type & CFG_TYPE_ARRAY)) {
+ switch (def->type) {
+ case CFG_TYPE_SECTION:
+ cn->v = NULL;
+ break;
+ case CFG_TYPE_BOOL:
+ cn->v->type = DM_CFG_INT;
+ cn->v->v.i = cfg_def_get_default_value(def, CFG_TYPE_BOOL);
+ break;
+ case CFG_TYPE_INT:
+ cn->v->type = DM_CFG_INT;
+ cn->v->v.i = cfg_def_get_default_value(def, CFG_TYPE_INT);
+ break;
+ case CFG_TYPE_FLOAT:
+ cn->v->type = DM_CFG_FLOAT;
+ cn->v->v.f = cfg_def_get_default_value(def, CFG_TYPE_FLOAT);
+ break;
+ case CFG_TYPE_STRING:
+ cn->v->type = DM_CFG_STRING;
+ if (!(str = cfg_def_get_default_value(def, CFG_TYPE_STRING)))
+ str = "";
+ cn->v->v.str = str;
+ break;
+ default:
+ log_error(INTERNAL_ERROR "_add_def_node: unknown type");
+ return NULL;
+ break;
+ }
+ } else
+ cn->v = _get_def_array_values(cft, def);
+
+ cn->child = NULL;
+ if (parent) {
+ cn->parent = parent;
+ if (!parent->child)
+ parent->child = cn;
+ } else
+ cn->parent = cn;
+
+ if (relay)
+ relay->sib = cn;
+
+ return cn;
+}
+
+static int _should_skip_def_node(struct config_def_tree_spec *spec, int section_id, cfg_def_item_t *def)
+{
+ if (def->parent != section_id)
+ return 1;
+
+ switch (spec->type) {
+ case CFG_DEF_TREE_MISSING:
+ if ((def->flags & CFG_USED) ||
+ (def->flags & CFG_NAME_VARIABLE) ||
+ (def->since_version > spec->version))
+ return 1;
+ break;
+ case CFG_DEF_TREE_NEW:
+ if (def->since_version != spec->version)
+ return 1;
+ break;
+ default:
+ if (def->since_version > spec->version)
+ return 1;
+ break;
+ }
+
+ return 0;
+}
+
+static struct dm_config_node *_add_def_section_subtree(struct dm_config_tree *cft,
+ struct config_def_tree_spec *spec,
+ struct dm_config_node *parent,
+ struct dm_config_node *relay,
+ int section_id)
+{
+ struct dm_config_node *cn = NULL, *relay_sub = NULL, *tmp;
+ cfg_def_item_t *def;
+ int id;
+
+ for (id = 0; id < CFG_COUNT; id++) {
+ def = cfg_def_get_item_p(id);
+ if (_should_skip_def_node(spec, section_id, def))
+ continue;
+
+ if (!cn && !(cn = _add_def_node(cft, spec, parent, relay, cfg_def_get_item_p(section_id))))
+ goto bad;
+
+ if ((tmp = def->type == CFG_TYPE_SECTION ? _add_def_section_subtree(cft, spec, cn, relay_sub, id)
+ : _add_def_node(cft, spec, cn, relay_sub, def)))
+ relay_sub = tmp;
+ }
+
+ return cn;
+bad:
+ log_error("Failed to create default config section node.");
+ return NULL;
+}
+
+struct dm_config_tree *config_def_create_tree(struct config_def_tree_spec *spec)
+{
+ struct dm_config_tree *cft;
+ struct dm_config_node *root = NULL, *relay = NULL, *tmp;
+ int id;
+
+ if (!(cft = dm_config_create())) {
+ log_error("Failed to create default config tree.");
+ return NULL;
+ }
+
+ for (id = root_CFG_SECTION + 1; id < CFG_COUNT; id++) {
+ if (cfg_def_get_item_p(id)->parent != root_CFG_SECTION)
+ continue;
+
+ if ((tmp = _add_def_section_subtree(cft, spec, root, relay, id))) {
+ relay = tmp;
+ if (!root)
+ root = relay;
+ }
+ }
+
+ cft->root = root;
+ return cft;
+}
diff --git a/lib/config/config.h b/lib/config/config.h
index 624ef59..fb4993a 100644
--- a/lib/config/config.h
+++ b/lib/config/config.h
@@ -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);
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index a7d2625..6229f2e 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -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)
10 years, 9 months
master - config: add support for configuration check (config_def_check fn)
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e38aaddb5e72a2...
Commit: e38aaddb5e72a2123a03dedbb40c2aa594495c17
Parent: 296385c0f3fa5176704c42f92210e7c5d38996ad
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Mar 5 17:14:18 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Mar 6 10:17:18 2013 +0100
config: add support for configuration check (config_def_check fn)
Add support for configuration checking - type checking and recognition
of registered configuration settings that LVM2 understands and also
check the structure of the configuration. Log error on any mismatch
found.
A hash over all allowed configuration paths is created which helps
with matching the exact configuration (lvm.conf/--config tree) with
the configuration item definition from config_settings.h in an
efficient and one-step way.
Two more helper flags are introduced for each configuration definition
item:
- CFG_USED which marks the item as being used (lvm.conf/--config)
This helps with identifying missing configuration options
(and for which defaults were used) when traversing the tree later.
- CFG_VALID which denotes that the item has already been checked and
it was found valid. This improves performance, so if the check
is called once again on the same tree which was not reloaded, we
can just return the state from previous check (with a possibility
to force the check if needed).
The new function that config.h exports and which is going to be used
to perform the configuration checking is:
int config_def_check(struct cmd_context *cmd, int force, int skip, int suppress_messages)
...which is exported internally via config.h.
---
lib/config/config.c | 283 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib/config/config.h | 5 +
2 files changed, 288 insertions(+), 0 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index 8234cf4..6f33c12 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -334,6 +334,289 @@ int config_def_get_path(char *buf, size_t buf_size, int id)
return _cfg_def_make_path(buf, buf_size, id, cfg_def_get_item_p(id));
}
+static void _get_type_name(char *buf, size_t buf_size, cfg_def_type_t type)
+{
+ buf[0] = '\0';
+
+ if (type & CFG_TYPE_ARRAY) {
+ if (type & ~CFG_TYPE_ARRAY)
+ strncat(buf, " array with values of type:", buf_size);
+ else {
+ strncat(buf, " array", buf_size);
+ return;
+ }
+ }
+
+ if (type & CFG_TYPE_SECTION)
+ strncat(buf, " section", buf_size);
+ if (type & CFG_TYPE_BOOL)
+ strncat(buf, " boolean", buf_size);
+ if (type & CFG_TYPE_INT)
+ strncat(buf, " integer", buf_size);
+ if (type & CFG_TYPE_FLOAT)
+ strncat(buf, " float", buf_size);
+ if (type & CFG_TYPE_STRING)
+ strncat(buf, " string", buf_size);
+}
+
+static void _log_type_error(const char *path, cfg_def_type_t actual,
+ cfg_def_type_t expected, int suppress_messages)
+{
+ static char actual_type_name[64];
+ static char expected_type_name[64];
+
+ _get_type_name(actual_type_name, sizeof(actual_type_name), actual);
+ _get_type_name(expected_type_name, sizeof(expected_type_name), expected);
+
+ log_warn_suppress(suppress_messages, "Configuration setting \"%s\" has invalid type. "
+ "Found%s, expected%s.", path,
+ actual_type_name, expected_type_name);
+}
+
+static int _config_def_check_node_single_value(const char *rp, const struct dm_config_value *v,
+ const cfg_def_item_t *def, int suppress_messages)
+{
+ /* Check empty array first if present. */
+ if (v->type == DM_CFG_EMPTY_ARRAY) {
+ if (!(def->type & CFG_TYPE_ARRAY)) {
+ _log_type_error(rp, CFG_TYPE_ARRAY, def->type, suppress_messages);
+ return 0;
+ }
+ if (!(def->flags & CFG_ALLOW_EMPTY)) {
+ log_warn_suppress(suppress_messages,
+ "Configuration setting \"%s\" invalid. Empty value not allowed.", rp);
+ return 0;
+ }
+ return 1;
+ }
+
+ switch (v->type) {
+ case DM_CFG_INT:
+ if (!(def->type & CFG_TYPE_INT) && !(def->type & CFG_TYPE_BOOL)) {
+ _log_type_error(rp, CFG_TYPE_INT, def->type, suppress_messages);
+ return 0;
+ }
+ break;
+ case DM_CFG_FLOAT:
+ if (!(def->type & CFG_TYPE_FLOAT)) {
+ _log_type_error(rp, CFG_TYPE_FLOAT, def->type, suppress_messages);
+ return 0;
+ }
+ break;
+ case DM_CFG_STRING:
+ if (def->type & CFG_TYPE_BOOL) {
+ if (!dm_config_value_is_bool(v)) {
+ log_warn_suppress(suppress_messages,
+ "Configuration setting \"%s\" invalid. "
+ "Found string value \"%s\", "
+ "expected boolean value: 0/1, \"y/n\", "
+ "\"yes/no\", \"on/off\", "
+ "\"true/false\".", rp, v->v.str);
+ return 0;
+ }
+ } else if (!(def->type & CFG_TYPE_STRING)) {
+ _log_type_error(rp, CFG_TYPE_STRING, def->type, suppress_messages);
+ return 0;
+ }
+ break;
+ default: ;
+ }
+
+ return 1;
+}
+
+static int _config_def_check_node_value(const char *rp, const struct dm_config_value *v,
+ const cfg_def_item_t *def, int suppress_messages)
+{
+ if (!v) {
+ if (def->type != CFG_TYPE_SECTION) {
+ _log_type_error(rp, CFG_TYPE_SECTION, def->type, suppress_messages);
+ return 0;
+ }
+ return 1;
+ }
+
+ if (v->next) {
+ if (!(def->type & CFG_TYPE_ARRAY)) {
+ _log_type_error(rp, CFG_TYPE_ARRAY, def->type, suppress_messages);
+ return 0;
+ }
+ }
+
+ do {
+ if (!_config_def_check_node_single_value(rp, v, def, suppress_messages))
+ return 0;
+ v = v->next;
+ } while (v);
+
+ return 1;
+}
+
+static int _config_def_check_node(const char *vp, char *pvp, char *rp, char *prp,
+ size_t buf_size, struct dm_config_node *cn,
+ struct dm_hash_table *ht, int suppress_messages)
+{
+ cfg_def_item_t *def;
+ int sep = vp != pvp; /* don't use '/' separator for top-level node */
+
+ if (dm_snprintf(pvp, buf_size, "%s%s", sep ? "/" : "", cn->key) < 0 ||
+ dm_snprintf(prp, buf_size, "%s%s", sep ? "/" : "", cn->key) < 0) {
+ log_error("Failed to construct path for configuration node %s.", cn->key);
+ return 0;
+ }
+
+
+ if (!(def = (cfg_def_item_t *) dm_hash_lookup(ht, vp))) {
+ /* If the node is not a section but a setting, fail now. */
+ if (cn->v) {
+ log_warn_suppress(suppress_messages,
+ "Configuration setting \"%s\" unknown.", rp);
+ return 0;
+ }
+
+ /* If the node is a section, try if the section name is variable. */
+ /* Modify virtual path vp in situ and replace the key name with a '#'. */
+ /* The real path without '#' is still stored in rp variable. */
+ pvp[sep] = '#', pvp[sep + 1] = '\0';
+ if (!(def = (cfg_def_item_t *) dm_hash_lookup(ht, vp))) {
+ log_warn_suppress(suppress_messages,
+ "Configuration section \"%s\" unknown.", rp);
+ return 0;
+ }
+ }
+
+ def->flags |= CFG_USED;
+ if (!_config_def_check_node_value(rp, cn->v, def, suppress_messages))
+ return 0;
+
+ def->flags |= CFG_VALID;
+ return 1;
+}
+
+static int _config_def_check_tree(const char *vp, char *pvp, char *rp, char *prp,
+ size_t buf_size, struct dm_config_node *root,
+ struct dm_hash_table *ht, int suppress_messages)
+{
+ struct dm_config_node *cn;
+ int valid, r = 1;
+ size_t len;
+
+ for (cn = root->child; cn; cn = cn->sib) {
+ if ((valid = _config_def_check_node(vp, pvp, rp, prp, buf_size,
+ cn, ht, suppress_messages)) && !cn->v) {
+ len = strlen(rp);
+ valid = _config_def_check_tree(vp, pvp + strlen(pvp),
+ rp, prp + len, buf_size - len, cn, ht,
+ suppress_messages);
+ }
+ if (!valid)
+ r = 0;
+ }
+
+ return r;
+}
+
+int config_def_check(struct cmd_context *cmd, int force, int skip, int suppress_messages)
+{
+ cfg_def_item_t *def;
+ struct dm_config_node *cn;
+ char *vp = _cfg_path, rp[CFG_PATH_MAX_LEN];
+ size_t rplen;
+ int id, r = 1;
+
+ /*
+ * vp = virtual path, it might contain substitutes for variable parts
+ * of the path, used while working with the hash
+ * rp = real path, the real path of the config element as found in the
+ * configuration, used for message output
+ */
+
+ /*
+ * If the check has already been done and 'skip' is set,
+ * skip the actual check and use last result if available.
+ * If not available, we must do the check. The global status
+ * is stored in root node.
+ */
+ def = cfg_def_get_item_p(root_CFG_SECTION);
+ if (skip && (def->flags & CFG_USED))
+ return def->flags & CFG_VALID;
+
+ /* Clear 'used' and 'valid' status flags. */
+ for (id = 0; id < CFG_COUNT; id++) {
+ def = cfg_def_get_item_p(id);
+ def->flags &= ~(CFG_USED | CFG_VALID);
+ }
+
+ if (!force && !find_config_tree_bool(cmd, config_checks_CFG)) {
+ if (cmd->cft_def_hash) {
+ dm_hash_destroy(cmd->cft_def_hash);
+ cmd->cft_def_hash = NULL;
+ }
+ return 1;
+ }
+
+ /*
+ * Create a hash of all possible configuration
+ * sections and settings with full path as a key.
+ * If section name is variable, use '#' as a substitute.
+ */
+ if (!cmd->cft_def_hash) {
+ if (!(cmd->cft_def_hash = dm_hash_create(64))) {
+ log_error("Failed to create configuration definition hash.");
+ r = 0; goto out;
+ }
+ for (id = 1; id < CFG_COUNT; id++) {
+ def = cfg_def_get_item_p(id);
+ if (!cfg_def_get_path(def)) {
+ dm_hash_destroy(cmd->cft_def_hash);
+ cmd->cft_def_hash = NULL;
+ r = 0; goto out;
+ }
+ dm_hash_insert(cmd->cft_def_hash, dm_strdup(vp), def);
+ }
+ }
+
+ cfg_def_get_item_p(root_CFG_SECTION)->flags |= CFG_USED;
+
+ /*
+ * Allow only sections as top-level elements.
+ * Iterate top-level sections and dive deeper.
+ * If any of subsequent checks fails, the whole check fails.
+ */
+ for (cn = cmd->cft->root; cn; cn = cn->sib) {
+ if (!cn->v) {
+ /* top level node: vp=vp, rp=rp */
+ if (!_config_def_check_node(vp, vp, rp, rp,
+ CFG_PATH_MAX_LEN,
+ cn, cmd->cft_def_hash,
+ suppress_messages)) {
+ r = 0; continue;
+ }
+ rplen = strlen(rp);
+ if (!_config_def_check_tree(vp, vp + strlen(vp),
+ rp, rp + rplen,
+ CFG_PATH_MAX_LEN - rplen,
+ cn, cmd->cft_def_hash,
+ suppress_messages))
+ r = 0;
+ } else {
+ log_error_suppress(suppress_messages,
+ "Configuration setting \"%s\" invalid. "
+ "It's not part of any section.", cn->key);
+ r = 0;
+ }
+ }
+out:
+ if (r) {
+ cfg_def_get_item_p(root_CFG_SECTION)->flags |= CFG_VALID;
+ def->flags |= CFG_VALID;
+ } else {
+ cfg_def_get_item_p(root_CFG_SECTION)->flags &= ~CFG_VALID;
+ def->flags &= ~CFG_VALID;
+ }
+ return r;
+}
+
const struct dm_config_node *find_config_tree_node(struct cmd_context *cmd, int id)
{
return dm_config_tree_find_node(cmd->cft, cfg_def_get_path(cfg_def_get_item_p(id)));
diff --git a/lib/config/config.h b/lib/config/config.h
index a239e1d..624ef59 100644
--- a/lib/config/config.h
+++ b/lib/config/config.h
@@ -59,6 +59,10 @@ typedef union {
#define CFG_ADVANCED 0x04
/* whether the configuraton item is not officially supported */
#define CFG_UNSUPPORTED 0x08
+/* helper flag to mark the item as used in a config tree instance */
+#define CFG_USED 0x10
+/* helper flag to mark the item as valid in a config tree instance */
+#define CFG_VALID 0x20
/* configuration definition item structure */
typedef struct cfg_def_item {
@@ -86,6 +90,7 @@ enum {
};
int config_def_get_path(char *buf, size_t buf_size, int id);
+int config_def_check(struct cmd_context *cmd, int force, int skip, int suppress_messages);
int override_config_tree_from_string(struct cmd_context *cmd,
const char *config_settings);
10 years, 9 months
master - libdevmapper: add dm_config_value_is_bool function
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=296385c0f3fa51...
Commit: 296385c0f3fa5176704c42f92210e7c5d38996ad
Parent: 386886f71c3da0945f47edf1a7063a04ba9b56d1
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Mar 5 17:10:30 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Mar 6 10:14:33 2013 +0100
libdevmapper: add dm_config_value_is_bool function
Export this functionality from libdevmapper just for
convenience and general use when reading boolean values
which could be defined either in a numeric way with 0/1
or by using strings with "true"/"false", "yes"/"no",
"on"/"off", "y"/"n".
---
libdm/libdevmapper.h | 1 +
libdm/libdm-config.c | 14 ++++++++++++++
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index b08a549..8c349c5 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -1555,6 +1555,7 @@ int dm_config_tree_find_bool(const struct dm_config_tree *cft, const char *path,
* off), (true, false).
*/
int dm_config_find_bool(const struct dm_config_node *cn, const char *path, int fail);
+int dm_config_value_is_bool(const struct dm_config_value *v);
int dm_config_get_uint32(const struct dm_config_node *cn, const char *path, uint32_t *result);
int dm_config_get_uint64(const struct dm_config_node *cn, const char *path, uint64_t *result);
diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c
index bd29d32..4705a1c 100644
--- a/libdm/libdm-config.c
+++ b/libdm/libdm-config.c
@@ -928,6 +928,20 @@ int dm_config_find_bool(const struct dm_config_node *cn, const char *path, int f
return _find_config_bool(cn, _find_config_node, path, fail);
}
+int dm_config_value_is_bool(const struct dm_config_value *v) {
+ if (!v)
+ return 0;
+
+ switch(v->type) {
+ case DM_CFG_INT:
+ return 1;
+ case DM_CFG_STRING:
+ return _str_to_bool(v->v.str, -1) != -1;
+ default:
+ return 0;
+ }
+}
+
/***********************************
* tree-based lookup
**/
10 years, 9 months
master - config: refer to config nodes using assigned IDs
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=386886f71c3da0...
Commit: 386886f71c3da0945f47edf1a7063a04ba9b56d1
Parent: a3d891a29042e51a0f43ed02273a6dce194d6569
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Mar 5 17:00:43 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Mar 6 10:14:33 2013 +0100
config: refer to config nodes using assigned IDs
For example, the old call and reference:
find_config_tree_str(cmd, "devices/dir", DEFAULT_DEV_DIR)
...now becomes:
find_config_tree_str(cmd, devices_dir_CFG)
So we're referring to the named configuration ID instead
of passing the configuration path and the default value
is taken from central config definition in config_settings.h
automatically.
---
daemons/clvmd/lvm-functions.c | 7 +-
lib/activate/activate.c | 18 +++--
lib/activate/dev_manager.c | 6 +-
lib/commands/toolcontext.c | 175 ++++++++++++++++------------------------
lib/commands/toolcontext.h | 1 +
lib/config/config.c | 71 ++++++++++++-----
lib/config/config.h | 21 ++---
lib/config/defaults.h | 1 -
lib/device/dev-cache.c | 2 +-
lib/display/display.c | 3 +-
lib/format_text/format-text.c | 8 +-
lib/locking/external_locking.c | 4 +-
lib/locking/file_locking.c | 6 +-
lib/locking/locking.c | 13 +--
lib/metadata/lv_manip.c | 17 ++---
lib/metadata/metadata.c | 15 +---
lib/metadata/mirror.c | 15 ++--
lib/metadata/pv_manip.c | 3 +-
lib/metadata/thin_manip.c | 4 +-
lib/mirror/mirrored.c | 3 +-
lib/misc/sharedlib.c | 2 +-
lib/mm/memlock.c | 15 +---
lib/raid/raid.c | 3 +-
lib/snapshot/snapshot.c | 3 +-
lib/thin/thin.c | 5 +-
liblvm/lvm_base.c | 4 +-
tools/lvconvert.c | 13 +--
tools/lvcreate.c | 8 +-
tools/lvm.c | 3 +-
tools/lvmcmdline.c | 3 +-
tools/lvresize.c | 16 +---
tools/polldaemon.c | 6 +-
tools/pvcreate.c | 4 +-
tools/pvscan.c | 4 +-
tools/reporter.c | 76 +++++------------
tools/toollib.c | 46 +++-------
tools/vgconvert.c | 8 +--
37 files changed, 246 insertions(+), 366 deletions(-)
diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c
index 6793752..416d4f0 100644
--- a/daemons/clvmd/lvm-functions.c
+++ b/daemons/clvmd/lvm-functions.c
@@ -808,7 +808,7 @@ static void check_config(void)
{
int locking_type;
- locking_type = find_config_tree_int(cmd, "global/locking_type", 1);
+ locking_type = find_config_tree_int(cmd, global_locking_type_CFG);
if (locking_type == 3) /* compiled-in cluster support */
return;
@@ -816,9 +816,8 @@ static void check_config(void)
if (locking_type == 2) { /* External library, check name */
const char *libname;
- libname = find_config_tree_str(cmd, "global/locking_library",
- "");
- if (strstr(libname, "liblvm2clusterlock.so"))
+ libname = find_config_tree_str(cmd, global_locking_library_CFG);
+ if (libname && strstr(libname, "liblvm2clusterlock.so"))
return;
log_error("Incorrect LVM locking library specified in lvm.conf, cluster operations may not work.");
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index f19dff7..26d357b 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -333,12 +333,14 @@ int activation(void)
}
static int _lv_passes_volumes_filter(struct cmd_context *cmd, struct logical_volume *lv,
- const struct dm_config_node *cn, const char *config_path)
+ const struct dm_config_node *cn, const int cfg_id)
{
const struct dm_config_value *cv;
const char *str;
+ static char config_path[PATH_MAX];
static char path[PATH_MAX];
+ config_def_get_path(config_path, sizeof(config_path), cfg_id);
log_verbose("%s configuration setting defined: "
"Checking the list to match %s/%s",
config_path, lv->vg->name, lv->name);
@@ -413,7 +415,7 @@ static int _passes_activation_filter(struct cmd_context *cmd,
{
const struct dm_config_node *cn;
- if (!(cn = find_config_tree_node(cmd, "activation/volume_list"))) {
+ if (!(cn = find_config_tree_node(cmd, activation_volume_list_CFG))) {
log_verbose("activation/volume_list configuration setting "
"not defined: Checking only host tags for %s/%s",
lv->vg->name, lv->name);
@@ -434,7 +436,7 @@ static int _passes_activation_filter(struct cmd_context *cmd,
return 0;
}
- return _lv_passes_volumes_filter(cmd, lv, cn, "activation/volume_list");
+ return _lv_passes_volumes_filter(cmd, lv, cn, activation_volume_list_CFG);
}
static int _passes_readonly_filter(struct cmd_context *cmd,
@@ -442,10 +444,10 @@ static int _passes_readonly_filter(struct cmd_context *cmd,
{
const struct dm_config_node *cn;
- if (!(cn = find_config_tree_node(cmd, "activation/read_only_volume_list")))
+ if (!(cn = find_config_tree_node(cmd, activation_read_only_volume_list_CFG)))
return 0;
- return _lv_passes_volumes_filter(cmd, lv, cn, "activation/read_only_volume_list");
+ return _lv_passes_volumes_filter(cmd, lv, cn, activation_read_only_volume_list_CFG);
}
@@ -453,13 +455,13 @@ int lv_passes_auto_activation_filter(struct cmd_context *cmd, struct logical_vol
{
const struct dm_config_node *cn;
- if (!(cn = find_config_tree_node(cmd, "activation/auto_activation_volume_list"))) {
+ if (!(cn = find_config_tree_node(cmd, activation_auto_activation_volume_list_CFG))) {
log_verbose("activation/auto_activation_volume_list configuration setting "
"not defined: All logical volumes will be auto-activated.");
return 1;
}
- return _lv_passes_volumes_filter(cmd, lv, cn, "activation/auto_activation_volume_list");
+ return _lv_passes_volumes_filter(cmd, lv, cn, activation_auto_activation_volume_list_CFG);
}
int library_version(char *version, size_t size)
@@ -1152,7 +1154,7 @@ static struct dm_event_handler *_create_dm_event_handler(struct cmd_context *cmd
if (!(dmevh = dm_event_handler_create()))
return_NULL;
- if (dm_event_handler_set_dmeventd_path(dmevh, find_config_tree_str(cmd, "dmeventd/executable", NULL)))
+ if (dm_event_handler_set_dmeventd_path(dmevh, find_config_tree_str(cmd, dmeventd_executable_CFG)))
goto_bad;
if (dm_event_handler_set_dso(dmevh, dso))
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index bffa8a5..8aa49fc 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -1450,9 +1450,7 @@ static int _thin_pool_callback(struct dm_tree_node *node,
const struct dm_config_node *cn;
const struct dm_config_value *cv;
const char *thin_check =
- find_config_tree_str_allow_empty(data->pool_lv->vg->cmd,
- "global/thin_check_executable",
- THIN_CHECK_CMD);
+ find_config_tree_str_allow_empty(data->pool_lv->vg->cmd, global_thin_check_executable_CFG);
const struct logical_volume *mlv = first_seg(data->pool_lv)->metadata_lv;
size_t len = strlen(dmdir) + 2 * (strlen(mlv->vg->name) + strlen(mlv->name)) + 3;
char meta_path[len];
@@ -1470,7 +1468,7 @@ static int _thin_pool_callback(struct dm_tree_node *node,
return 0;
}
- if ((cn = find_config_tree_node(mlv->vg->cmd, "global/thin_check_options"))) {
+ if ((cn = find_config_tree_node(mlv->vg->cmd, global_thin_check_options_CFG))) {
for (cv = cn->v; cv && args < 16; cv = cv->next) {
if (cv->type != DM_CFG_STRING) {
log_error("Invalid string in config file: "
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index d5dd430..1cee204 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -128,7 +128,7 @@ static int _parse_debug_classes(struct cmd_context *cmd)
const struct dm_config_value *cv;
int debug_classes = 0;
- if (!(cn = find_config_tree_node(cmd, "log/debug_classes")))
+ if (!(cn = find_config_tree_node(cmd, log_debug_classes_CFG)))
return DEFAULT_LOGGED_DEBUG_CLASSES;
for (cv = cn->v; cv; cv = cv->next) {
@@ -173,8 +173,7 @@ static void _init_logging(struct cmd_context *cmd)
char timebuf[26];
/* Syslog */
- cmd->default_settings.syslog =
- find_config_tree_int(cmd, "log/syslog", DEFAULT_SYSLOG);
+ cmd->default_settings.syslog = find_config_tree_bool(cmd, log_syslog_CFG);
if (cmd->default_settings.syslog != 1)
fin_syslog();
@@ -182,8 +181,7 @@ static void _init_logging(struct cmd_context *cmd)
init_syslog(cmd->default_settings.syslog);
/* Debug level for log file output */
- cmd->default_settings.debug =
- find_config_tree_int(cmd, "log/level", DEFAULT_LOGLEVEL);
+ cmd->default_settings.debug = find_config_tree_int(cmd, log_level_CFG);
init_debug(cmd->default_settings.debug);
/*
@@ -192,40 +190,33 @@ static void _init_logging(struct cmd_context *cmd)
* Once set to 1, there is no facility to change it back to 0.
*/
cmd->default_settings.silent = silent_mode() ? :
- find_config_tree_int(cmd, "log/silent", DEFAULT_SILENT);
+ find_config_tree_bool(cmd, log_silent_CFG);
init_silent(cmd->default_settings.silent);
/* Verbose level for tty output */
- cmd->default_settings.verbose =
- find_config_tree_int(cmd, "log/verbose", DEFAULT_VERBOSE);
+ cmd->default_settings.verbose = find_config_tree_bool(cmd, log_verbose_CFG);
init_verbose(cmd->default_settings.verbose + VERBOSE_BASE_LEVEL);
/* Log message formatting */
- init_indent(find_config_tree_int(cmd, "log/indent",
- DEFAULT_INDENT));
- 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_allow_empty(cmd, "log/prefix", DEFAULT_MSG_PREFIX);
+ init_indent(find_config_tree_bool(cmd, log_indent_CFG));
+ init_abort_on_internal_errors(find_config_tree_bool(cmd, global_abort_on_internal_errors_CFG));
+ cmd->default_settings.msg_prefix = find_config_tree_str_allow_empty(cmd, log_prefix_CFG);
init_msg_prefix(cmd->default_settings.msg_prefix);
- cmd->default_settings.cmd_name = find_config_tree_int(cmd,
- "log/command_names",
- DEFAULT_CMD_NAME);
+ cmd->default_settings.cmd_name = find_config_tree_bool(cmd, log_command_names_CFG);
init_cmd_name(cmd->default_settings.cmd_name);
/* Test mode */
cmd->default_settings.test =
- find_config_tree_int(cmd, "global/test", 0);
+ find_config_tree_bool(cmd, global_test_CFG);
init_test(cmd->default_settings.test);
/* Settings for logging to file */
- if (find_config_tree_int(cmd, "log/overwrite", DEFAULT_OVERWRITE))
+ if (find_config_tree_bool(cmd, log_overwrite_CFG))
append = 0;
- log_file = find_config_tree_str(cmd, "log/file", 0);
+ log_file = find_config_tree_str(cmd, log_file_CFG);
if (log_file) {
release_log_memory();
@@ -233,12 +224,11 @@ static void _init_logging(struct cmd_context *cmd)
init_log_file(log_file, append);
}
- log_file = find_config_tree_str(cmd, "log/activate_file", 0);
+ log_file = find_config_tree_str(cmd, log_activate_file_CFG);
if (log_file)
init_log_direct(log_file, append);
- init_log_while_suspended(find_config_tree_int(cmd,
- "log/activation", 0));
+ init_log_while_suspended(find_config_tree_bool(cmd, log_activation_CFG));
cmd->default_settings.debug_classes = _parse_debug_classes(cmd);
log_debug("Setting log debug classes to %d", cmd->default_settings.debug_classes);
@@ -301,9 +291,7 @@ static int _process_config(struct cmd_context *cmd)
int udev_disabled = 0;
/* umask */
- cmd->default_settings.umask = find_config_tree_int(cmd,
- "global/umask",
- DEFAULT_UMASK);
+ cmd->default_settings.umask = find_config_tree_int(cmd, global_umask_CFG);
if ((old_umask = umask((mode_t) cmd->default_settings.umask)) !=
(mode_t) cmd->default_settings.umask)
@@ -312,8 +300,7 @@ static int _process_config(struct cmd_context *cmd)
/* dev dir */
if (dm_snprintf(cmd->dev_dir, sizeof(cmd->dev_dir), "%s/",
- find_config_tree_str(cmd, "devices/dir",
- DEFAULT_DEV_DIR)) < 0) {
+ find_config_tree_str(cmd, devices_dir_CFG)) < 0) {
log_error("Device directory given in config file too long");
return 0;
}
@@ -326,8 +313,7 @@ static int _process_config(struct cmd_context *cmd)
/* proc dir */
if (dm_snprintf(cmd->proc_dir, sizeof(cmd->proc_dir), "%s",
- find_config_tree_str(cmd, "global/proc",
- DEFAULT_PROC_DIR)) < 0) {
+ find_config_tree_str(cmd, global_proc_CFG)) < 0) {
log_error("Device directory given in config file too long");
return 0;
}
@@ -344,25 +330,19 @@ static int _process_config(struct cmd_context *cmd)
dm_set_sysfs_dir(cmd->sysfs_dir);
/* activation? */
- cmd->default_settings.activation = find_config_tree_int(cmd,
- "global/activation",
- DEFAULT_ACTIVATION);
+ cmd->default_settings.activation = find_config_tree_bool(cmd, global_activation_CFG);
set_activation(cmd->default_settings.activation);
- cmd->default_settings.suffix = find_config_tree_int(cmd,
- "global/suffix",
- DEFAULT_SUFFIX);
+ cmd->default_settings.suffix = find_config_tree_bool(cmd, global_suffix_CFG);
if (!(cmd->default_settings.unit_factor =
- units_to_bytes(find_config_tree_str(cmd,
- "global/units",
- DEFAULT_UNITS),
+ units_to_bytes(find_config_tree_str(cmd, global_units_CFG),
&cmd->default_settings.unit_type))) {
log_error("Invalid units specification");
return 0;
}
- read_ahead = find_config_tree_str(cmd, "activation/readahead", DEFAULT_READ_AHEAD);
+ read_ahead = find_config_tree_str(cmd, activation_readahead_CFG);
if (!strcasecmp(read_ahead, "auto"))
cmd->default_settings.read_ahead = DM_READ_AHEAD_AUTO;
else if (!strcasecmp(read_ahead, "none"))
@@ -382,16 +362,14 @@ static int _process_config(struct cmd_context *cmd)
udev_disabled = _check_disable_udev("manage logical volume symlinks in device directory");
cmd->default_settings.udev_rules = udev_disabled ? 0 :
- find_config_tree_int(cmd, "activation/udev_rules", DEFAULT_UDEV_RULES);
+ find_config_tree_bool(cmd, activation_udev_rules_CFG);
cmd->default_settings.udev_sync = udev_disabled ? 0 :
- find_config_tree_int(cmd, "activation/udev_sync", DEFAULT_UDEV_SYNC);
+ find_config_tree_bool(cmd, activation_udev_sync_CFG);
- init_retry_deactivation(find_config_tree_int(cmd, "activation/retry_deactivation",
- DEFAULT_RETRY_DEACTIVATION));
+ init_retry_deactivation(find_config_tree_bool(cmd, activation_retry_deactivation_CFG));
- init_activation_checks(find_config_tree_int(cmd, "activation/checks",
- DEFAULT_ACTIVATION_CHECKS));
+ init_activation_checks(find_config_tree_bool(cmd, activation_checks_CFG));
#ifdef UDEV_SYNC_SUPPORT
/*
@@ -400,7 +378,7 @@ static int _process_config(struct cmd_context *cmd)
* variable or udev rules are switched off.
*/
cmd->default_settings.udev_fallback = !cmd->default_settings.udev_rules || udev_disabled ? 1 :
- find_config_tree_int(cmd, "activation/verify_udev_operations", DEFAULT_VERIFY_UDEV_OPERATIONS);
+ find_config_tree_bool(cmd, activation_verify_udev_operations_CFG);
/* Do not rely fully on udev if the udev support is known to be incomplete. */
if (!cmd->default_settings.udev_fallback && !_dm_driver_has_stable_udev_support()) {
@@ -414,13 +392,9 @@ static int _process_config(struct cmd_context *cmd)
cmd->default_settings.udev_fallback = 1;
#endif
- cmd->use_linear_target = find_config_tree_int(cmd,
- "activation/use_linear_target",
- DEFAULT_USE_LINEAR_TARGET);
+ cmd->use_linear_target = find_config_tree_bool(cmd, activation_use_linear_target_CFG);
- cmd->stripe_filler = find_config_tree_str(cmd,
- "activation/missing_stripe_filler",
- DEFAULT_STRIPE_FILLER);
+ cmd->stripe_filler = find_config_tree_str(cmd, activation_missing_stripe_filler_CFG);
/* FIXME Missing error code checks from the stats, not log_warn?, notify if setting overridden, delay message/check till it is actually used (eg consider if lvm shell - file could appear later after this check)? */
if (!strcmp(cmd->stripe_filler, "/dev/ioerror") &&
@@ -442,19 +416,16 @@ static int _process_config(struct cmd_context *cmd)
}
}
- cmd->si_unit_consistency = find_config_tree_int(cmd,
- "global/si_unit_consistency",
- DEFAULT_SI_UNIT_CONSISTENCY);
+ cmd->si_unit_consistency = find_config_tree_bool(cmd, global_si_unit_consistency_CFG);
- if ((cn = find_config_tree_node(cmd, "activation/mlock_filter")))
+ if ((cn = find_config_tree_node(cmd, activation_mlock_filter_CFG)))
for (cv = cn->v; cv; cv = cv->next)
if ((cv->type != DM_CFG_STRING) || !cv->v.str[0])
log_error("Ignoring invalid activation/mlock_filter entry in config file");
- cmd->metadata_read_only = find_config_tree_int(cmd, "global/metadata_read_only",
- DEFAULT_METADATA_READ_ONLY);
+ cmd->metadata_read_only = find_config_tree_bool(cmd, global_metadata_read_only_CFG);
- pv_min_kb = find_config_tree_int64(cmd, "devices/pv_min_size", DEFAULT_PV_MIN_SIZE_KB);
+ pv_min_kb = find_config_tree_int64(cmd, devices_pv_min_size_CFG);
if (pv_min_kb < PV_MIN_SIZE_KB) {
log_warn("Ignoring too small pv_min_size %" PRId64 "KB, using default %dKB.",
pv_min_kb, PV_MIN_SIZE_KB);
@@ -464,8 +435,7 @@ static int _process_config(struct cmd_context *cmd)
init_pv_min_size((uint64_t)pv_min_kb * (1024 >> SECTOR_SHIFT));
init_detect_internal_vg_cache_corruption
- (find_config_tree_int(cmd, "global/detect_internal_vg_cache_corruption",
- DEFAULT_DETECT_INTERNAL_VG_CACHE_CORRUPTION));
+ (find_config_tree_bool(cmd, global_detect_internal_vg_cache_corruption_CFG));
lvmetad_disconnect();
@@ -478,16 +448,16 @@ static int _process_config(struct cmd_context *cmd)
DEFAULT_RUN_DIR "/lvmetad.socket");
*/
lvmetad_set_socket(lvmetad_socket);
- cn = find_config_tree_node(cmd, "devices/global_filter");
+ cn = find_config_tree_node(cmd, devices_global_filter_CFG);
lvmetad_set_token(cn ? cn->v : NULL);
- if (find_config_tree_int(cmd, "global/locking_type", 1) == 3 &&
- find_config_tree_int(cmd, "global/use_lvmetad", 0)) {
+ if (find_config_tree_int(cmd, global_locking_type_CFG) == 3 &&
+ find_config_tree_bool(cmd, global_use_lvmetad_CFG)) {
log_warn("WARNING: configuration setting use_lvmetad overriden to 0 due to locking_type 3. "
"Clustered environment not supported by lvmetad yet.");
lvmetad_set_active(0);
} else
- lvmetad_set_active(find_config_tree_int(cmd, "global/use_lvmetad", 0));
+ lvmetad_set_active(find_config_tree_bool(cmd, global_use_lvmetad_CFG));
lvmetad_init(cmd);
@@ -548,12 +518,11 @@ static int _init_tags(struct cmd_context *cmd, struct dm_config_tree *cft)
const char *tag;
int passes;
- if (!(tn = dm_config_find_node(cft->root, "tags")) || !tn->child)
+ if (!(tn = find_config_tree_node(cmd, tags_CFG_SECTION)) || !tn->child)
return 1;
/* NB hosttags 0 when already 1 intentionally does not delete the tag */
- if (!cmd->hosttags && dm_config_find_int(cft->root, "tags/hosttags",
- DEFAULT_HOSTTAGS)) {
+ if (!cmd->hosttags && find_config_tree_bool(cmd, tags_hosttags_CFG)) {
/* FIXME Strip out invalid chars: only A-Za-z0-9_+.- */
if (!_set_tag(cmd, cmd->hostname))
return_0;
@@ -754,8 +723,7 @@ static int _init_dev_cache(struct cmd_context *cmd)
int device_list_from_udev;
init_dev_disable_after_error_count(
- find_config_tree_int(cmd, "devices/disable_after_error_count",
- DEFAULT_DISABLE_AFTER_ERROR_COUNT));
+ find_config_tree_int(cmd, devices_disable_after_error_count_CFG));
if (!dev_cache_init(cmd))
return_0;
@@ -769,12 +737,11 @@ static int _init_dev_cache(struct cmd_context *cmd)
device_list_from_udev = 0;
else
device_list_from_udev = udev_is_running() ?
- find_config_tree_bool(cmd, "devices/obtain_device_list_from_udev",
- DEFAULT_OBTAIN_DEVICE_LIST_FROM_UDEV) : 0;
+ find_config_tree_bool(cmd, devices_obtain_device_list_from_udev_CFG) : 0;
init_obtain_device_list_from_udev(device_list_from_udev);
- if (!(cn = find_config_tree_node(cmd, "devices/scan"))) {
+ if (!(cn = find_config_tree_node(cmd, devices_scan_CFG))) {
if (!dev_cache_add_dir("/dev")) {
log_error("Failed to add /dev to internal "
"device cache");
@@ -817,7 +784,7 @@ static int _init_dev_cache(struct cmd_context *cmd)
}
}
- if (!(cn = find_config_tree_node(cmd, "devices/loopfiles")))
+ if (!(cn = find_config_tree_node(cmd, devices_loopfiles_CFG)))
return 1;
for (cv = cn->v; cv; cv = cv->next) {
@@ -858,14 +825,13 @@ static struct dev_filter *_init_filter_components(struct cmd_context *cmd)
* Listed first because it's very efficient at eliminating
* unavailable devices.
*/
- if (find_config_tree_bool(cmd, "devices/sysfs_scan",
- DEFAULT_SYSFS_SCAN)) {
+ if (find_config_tree_bool(cmd, devices_sysfs_scan_CFG)) {
if ((filters[nr_filt] = sysfs_filter_create(cmd->sysfs_dir)))
nr_filt++;
}
/* regex filter. Optional. */
- if (!(cn = find_config_tree_node(cmd, "devices/filter")))
+ if (!(cn = find_config_tree_node(cmd, devices_filter_CFG)))
log_very_verbose("devices/filter not found in config file: "
"no regex filter installed");
@@ -876,7 +842,7 @@ static struct dev_filter *_init_filter_components(struct cmd_context *cmd)
nr_filt++;
/* device type filter. Required. */
- cn = find_config_tree_node(cmd, "devices/types");
+ cn = find_config_tree_node(cmd, devices_types_CFG);
if (!(filters[nr_filt] = lvm_type_filter_create(cmd->proc_dir, cn))) {
log_error("Failed to create lvm type filter");
goto bad;
@@ -884,16 +850,14 @@ static struct dev_filter *_init_filter_components(struct cmd_context *cmd)
nr_filt++;
/* md component filter. Optional, non-critical. */
- if (find_config_tree_bool(cmd, "devices/md_component_detection",
- DEFAULT_MD_COMPONENT_DETECTION)) {
+ if (find_config_tree_bool(cmd, devices_md_component_detection_CFG)) {
init_md_filtering(1);
if ((filters[nr_filt] = md_filter_create()))
nr_filt++;
}
/* mpath component filter. Optional, non-critical. */
- if (find_config_tree_bool(cmd, "devices/multipath_component_detection",
- DEFAULT_MULTIPATH_COMPONENT_DETECTION)) {
+ if (find_config_tree_bool(cmd, devices_multipath_component_detection_CFG)) {
if ((filters[nr_filt] = mpath_filter_create(cmd->sysfs_dir)))
nr_filt++;
}
@@ -926,14 +890,13 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
if (!(f3 = _init_filter_components(cmd)))
goto_bad;
- init_ignore_suspended_devices(find_config_tree_int(cmd,
- "devices/ignore_suspended_devices", DEFAULT_IGNORE_SUSPENDED_DEVICES));
+ init_ignore_suspended_devices(find_config_tree_bool(cmd, devices_ignore_suspended_devices_CFG));
/*
* If 'cache_dir' or 'cache_file_prefix' is set, ignore 'cache'.
*/
- cache_dir = find_config_tree_str(cmd, "devices/cache_dir", NULL);
- cache_file_prefix = find_config_tree_str(cmd, "devices/cache_file_prefix", NULL);
+ cache_dir = find_config_tree_str(cmd, devices_cache_dir_CFG);
+ cache_file_prefix = find_config_tree_str(cmd, devices_cache_file_prefix_CFG);
if (cache_dir || cache_file_prefix) {
if (dm_snprintf(cache_file, sizeof(cache_file),
@@ -945,7 +908,7 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
log_error("Persistent cache filename too long.");
goto bad;
}
- } else if (!(dev_cache = find_config_tree_str(cmd, "devices/cache", NULL)) &&
+ } else if (!(dev_cache = find_config_tree_str(cmd, devices_cache_CFG)) &&
(dm_snprintf(cache_file, sizeof(cache_file),
"%s/%s/%s.cache",
cmd->system_dir, DEFAULT_CACHE_SUBDIR,
@@ -964,7 +927,7 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
}
/* Should we ever dump persistent filter state? */
- if (find_config_tree_int(cmd, "devices/write_cache_state", 1))
+ if (find_config_tree_bool(cmd, devices_write_cache_state_CFG));
cmd->dump_filter = 1;
if (!*cmd->system_dir)
@@ -981,7 +944,7 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
log_verbose("Failed to load existing device cache from %s",
dev_cache);
- if (!(cn = find_config_tree_node(cmd, "devices/global_filter"))) {
+ if (!(cn = find_config_tree_node(cmd, devices_global_filter_CFG))) {
cmd->filter = f4;
} else if (!(cmd->lvmetad_filter = regex_filter_create(cn->v)))
goto_bad;
@@ -1043,7 +1006,7 @@ static int _init_formats(struct cmd_context *cmd)
#ifdef HAVE_LIBDL
/* Load any formats in shared libs if not static */
if (!is_static() &&
- (cn = find_config_tree_node(cmd, "global/format_libraries"))) {
+ (cn = find_config_tree_node(cmd, global_format_libraries_CFG))) {
const struct dm_config_value *cv;
struct format_type *(*init_format_fn) (struct cmd_context *);
@@ -1084,8 +1047,7 @@ static int _init_formats(struct cmd_context *cmd)
cmd->fmt_backup = fmt;
- format = find_config_tree_str(cmd, "global/format",
- DEFAULT_FORMAT);
+ format = find_config_tree_str(cmd, global_format_CFG);
dm_list_iterate_items(fmt, &cmd->formats) {
if (!strcasecmp(fmt->name, format) ||
@@ -1206,7 +1168,7 @@ static int _init_segtypes(struct cmd_context *cmd)
#ifdef HAVE_LIBDL
/* Load any formats in shared libs unless static */
if (!is_static() &&
- (cn = find_config_tree_node(cmd, "global/segment_libraries"))) {
+ (cn = find_config_tree_node(cmd, global_segment_libraries_CFG))) {
const struct dm_config_value *cv;
int (*init_multiple_segtypes_fn) (struct cmd_context *,
@@ -1294,14 +1256,11 @@ static int _init_backup(struct cmd_context *cmd)
/* set up archiving */
cmd->default_settings.archive =
- find_config_tree_bool(cmd, "backup/archive",
- DEFAULT_ARCHIVE_ENABLED);
+ find_config_tree_bool(cmd, backup_archive_CFG);
- days = (uint32_t) find_config_tree_int(cmd, "backup/retain_days",
- DEFAULT_ARCHIVE_DAYS);
+ days = (uint32_t) find_config_tree_int(cmd, backup_retain_days_CFG);
- min = (uint32_t) find_config_tree_int(cmd, "backup/retain_min",
- DEFAULT_ARCHIVE_NUMBER);
+ min = (uint32_t) find_config_tree_int(cmd, backup_retain_min_CFG);
if (dm_snprintf
(default_dir, sizeof(default_dir), "%s/%s", cmd->system_dir,
@@ -1311,8 +1270,8 @@ static int _init_backup(struct cmd_context *cmd)
return 0;
}
- dir = find_config_tree_str(cmd, "backup/archive_dir",
- default_dir);
+ if (!(dir = find_config_tree_str(cmd, backup_archive_dir_CFG)))
+ dir = default_dir;
if (!archive_init(cmd, dir, days, min,
cmd->default_settings.archive)) {
@@ -1321,9 +1280,7 @@ static int _init_backup(struct cmd_context *cmd)
}
/* set up the backup */
- cmd->default_settings.backup =
- find_config_tree_bool(cmd, "backup/backup",
- DEFAULT_BACKUP_ENABLED);
+ cmd->default_settings.backup = find_config_tree_bool(cmd, backup_backup_CFG);
if (dm_snprintf
(default_dir, sizeof(default_dir), "%s/%s", cmd->system_dir,
@@ -1333,7 +1290,8 @@ static int _init_backup(struct cmd_context *cmd)
return 0;
}
- dir = find_config_tree_str(cmd, "backup/backup_dir", default_dir);
+ if (!(dir = find_config_tree_str(cmd, backup_backup_dir_CFG)))
+ dir = default_dir;
if (!backup_init(cmd, dir, cmd->default_settings.backup)) {
log_debug("backup_init failed.");
@@ -1758,6 +1716,9 @@ void destroy_toolcontext(struct cmd_context *cmd)
}
#endif
+ if (cmd->cft_def_hash)
+ dm_hash_destroy(cmd->cft_def_hash);
+
dm_free(cmd);
lvmetad_release_token();
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index c21ec13..b79ebe2 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -100,6 +100,7 @@ struct cmd_context {
struct dm_config_tree *cft;
struct config_info default_settings;
struct config_info current_settings;
+ struct dm_hash_table *cft_def_hash; /* cft definition hash used for validity check */
struct archive_params *archive_params;
struct backup_params *backup_params;
diff --git a/lib/config/config.c b/lib/config/config.c
index f2ee9e7..8234cf4 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -334,44 +334,77 @@ int config_def_get_path(char *buf, size_t buf_size, int id)
return _cfg_def_make_path(buf, buf_size, id, cfg_def_get_item_p(id));
}
-const struct dm_config_node *find_config_tree_node(struct cmd_context *cmd,
- const char *path)
+const struct dm_config_node *find_config_tree_node(struct cmd_context *cmd, int id)
{
- return dm_config_tree_find_node(cmd->cft, path);
+ return dm_config_tree_find_node(cmd->cft, cfg_def_get_path(cfg_def_get_item_p(id)));
}
-const char *find_config_tree_str(struct cmd_context *cmd,
- const char *path, const char *fail)
+const char *find_config_tree_str(struct cmd_context *cmd, int id)
{
- return dm_config_tree_find_str(cmd->cft, path, fail);
+ cfg_def_item_t *item = cfg_def_get_item_p(id);
+ const char *path = cfg_def_get_path(item);
+
+ if (item->type != CFG_TYPE_STRING)
+ log_error(INTERNAL_ERROR "%s cfg tree element not declared as string.", path);
+
+ return dm_config_tree_find_str(cmd->cft, path, cfg_def_get_default_value(item, CFG_TYPE_STRING));
}
-const char *find_config_tree_str_allow_empty(struct cmd_context *cmd,
- const char *path, const char *fail)
+const char *find_config_tree_str_allow_empty(struct cmd_context *cmd, int id)
{
- return dm_config_tree_find_str_allow_empty(cmd->cft, path, fail);
+ cfg_def_item_t *item = cfg_def_get_item_p(id);
+ const char *path = cfg_def_get_path(item);
+
+ if (item->type != CFG_TYPE_STRING)
+ log_error(INTERNAL_ERROR "%s cfg tree element not declared as string.", path);
+ if (!(item->flags & CFG_ALLOW_EMPTY))
+ log_error(INTERNAL_ERROR "%s cfg tree element not declared to allow empty values.", path);
+
+ return dm_config_tree_find_str_allow_empty(cmd->cft, path, cfg_def_get_default_value(item, CFG_TYPE_STRING));
}
-int find_config_tree_int(struct cmd_context *cmd, const char *path,
- int fail)
+int find_config_tree_int(struct cmd_context *cmd, int id)
{
- return dm_config_tree_find_int(cmd->cft, path, fail);
+ cfg_def_item_t *item = cfg_def_get_item_p(id);
+ const char *path = cfg_def_get_path(item);
+
+ if (item->type != CFG_TYPE_INT)
+ log_error(INTERNAL_ERROR "%s cfg tree element not declared as integer.", path);
+
+ return dm_config_tree_find_int(cmd->cft, path, cfg_def_get_default_value(item, CFG_TYPE_INT));
}
-int64_t find_config_tree_int64(struct cmd_context *cmd, const char *path, int64_t fail)
+int64_t find_config_tree_int64(struct cmd_context *cmd, int id)
{
- return dm_config_tree_find_int64(cmd->cft, path, fail);
+ cfg_def_item_t *item = cfg_def_get_item_p(id);
+ const char *path = cfg_def_get_path(item);
+
+ if (item->type != CFG_TYPE_INT)
+ log_error(INTERNAL_ERROR "%s cfg tree element not declared as integer.", path);
+
+ return dm_config_tree_find_int64(cmd->cft, path, cfg_def_get_default_value(item, CFG_TYPE_INT));
}
-float find_config_tree_float(struct cmd_context *cmd, const char *path,
- float fail)
+float find_config_tree_float(struct cmd_context *cmd, int id)
{
- return dm_config_tree_find_float(cmd->cft, path, fail);
+ cfg_def_item_t *item = cfg_def_get_item_p(id);
+ const char *path = cfg_def_get_path(item);
+
+ if (item->type != CFG_TYPE_FLOAT)
+ log_error(INTERNAL_ERROR "%s cfg tree element not declared as float.", path);
+
+ return dm_config_tree_find_float(cmd->cft, path, cfg_def_get_default_value(item, CFG_TYPE_FLOAT));
}
-int find_config_tree_bool(struct cmd_context *cmd, const char *path, int fail)
+int find_config_tree_bool(struct cmd_context *cmd, int id)
{
- return dm_config_tree_find_bool(cmd->cft, path, fail);
+ cfg_def_item_t *item = cfg_def_get_item_p(id);
+ const char *path = cfg_def_get_path(item);
+
+ if (item->type != CFG_TYPE_BOOL)
+ log_error(INTERNAL_ERROR "%s cfg tree element not declared as boolean.", path);
+
+ return dm_config_tree_find_bool(cmd->cft, path, cfg_def_get_default_value(item, CFG_TYPE_BOOL));
}
/* Insert cn2 after cn1 */
diff --git a/lib/config/config.h b/lib/config/config.h
index 2317348..a239e1d 100644
--- a/lib/config/config.h
+++ b/lib/config/config.h
@@ -113,19 +113,12 @@ int merge_config_tree(struct cmd_context *cmd, struct dm_config_tree *cft,
/*
* These versions check an override tree, if present, first.
*/
-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,
- int64_t fail);
-float find_config_tree_float(struct cmd_context *cmd, const char *path,
- float fail);
-
-int find_config_tree_bool(struct cmd_context *cmd, const char *path, int fail);
+const struct dm_config_node *find_config_tree_node(struct cmd_context *cmd, int id);
+const char *find_config_tree_str(struct cmd_context *cmd, int id);
+const char *find_config_tree_str_allow_empty(struct cmd_context *cmd, int id);
+int find_config_tree_int(struct cmd_context *cmd, int id);
+int64_t find_config_tree_int64(struct cmd_context *cmd, int id);
+float find_config_tree_float(struct cmd_context *cmd, int id);
+int find_config_tree_bool(struct cmd_context *cmd, int id);
#endif
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index d39995e..cad9862 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -86,7 +86,6 @@
#define DEFAULT_STRIPESIZE 64 /* KB */
#define DEFAULT_PVMETADATAIGNORE 0
-#define DEFAULT_PVMETADATAIGNORE_STR "n"
#define DEFAULT_PVMETADATASIZE 255
#define DEFAULT_PVMETADATACOPIES 1
#define DEFAULT_VGMETADATACOPIES 0
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 9905045..0933549 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -675,7 +675,7 @@ static int _init_preferred_names(struct cmd_context *cmd)
_cache.preferred_names_matcher = NULL;
- if (!(cn = find_config_tree_node(cmd, "devices/preferred_names")) ||
+ if (!(cn = find_config_tree_node(cmd, devices_preferred_names_CFG)) ||
cn->v->type == DM_CFG_EMPTY_ARRAY) {
log_very_verbose("devices/preferred_names not found in config file: "
"using built-in preferences");
diff --git a/lib/display/display.c b/lib/display/display.c
index c0d0cd9..c766674 100644
--- a/lib/display/display.c
+++ b/lib/display/display.c
@@ -526,8 +526,7 @@ int lvdisplay_full(struct cmd_context *cmd,
log_print("--- Logical volume ---");
- lvm1compat = find_config_tree_int(cmd, "global/lvdisplay_shows_full_device_path",
- DEFAULT_LVDISPLAY_SHOWS_FULL_DEVICE_PATH);
+ lvm1compat = find_config_tree_bool(cmd, global_lvdisplay_shows_full_device_path_CFG);
if (lvm1compat)
/* /dev/vgname/lvname doen't actually exist for internal devices */
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index 774f6ce..951ec76 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -1477,9 +1477,7 @@ static int _text_pv_initialise(const struct format_type *fmt,
unsigned long adjustment, final_alignment = 0;
if (!data_alignment)
- data_alignment = find_config_tree_int(pv->fmt->cmd,
- "devices/data_alignment",
- 0) * 2;
+ data_alignment = find_config_tree_int(pv->fmt->cmd, devices_data_alignment_CFG) * 2;
if (set_pe_align(pv, data_alignment) != data_alignment &&
data_alignment) {
@@ -2443,7 +2441,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
goto bad;
}
- if ((cn = find_config_tree_node(cmd, "metadata/dirs"))) {
+ if ((cn = find_config_tree_node(cmd, metadata_dirs_CFG))) {
for (cv = cn->v; cv; cv = cv->next) {
if (cv->type != DM_CFG_STRING) {
log_error("Invalid string in config file: "
@@ -2460,7 +2458,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
}
}
- if ((cn = find_config_tree_node(cmd, "metadata/disk_areas"))) {
+ if ((cn = find_config_tree_node(cmd, metadata_disk_areas_CFG))) {
for (cn = cn->child; cn; cn = cn->sib) {
if (!_get_config_disk_area(cmd, cn, &mda_lists->raws))
goto_bad;
diff --git a/lib/locking/external_locking.c b/lib/locking/external_locking.c
index 4dacbe4..1076174 100644
--- a/lib/locking/external_locking.c
+++ b/lib/locking/external_locking.c
@@ -80,8 +80,8 @@ int init_external_locking(struct locking_type *locking, struct cmd_context *cmd,
locking->reset_locking = _reset_external_locking;
locking->flags = 0;
- libname = find_config_tree_str(cmd, "global/locking_library",
- DEFAULT_LOCKING_LIB);
+ if (!(libname = find_config_tree_str(cmd, global_locking_library_CFG)))
+ libname = DEFAULT_LOCKING_LIB;
if (!(_locking_lib = load_shared_library(cmd, libname, "locking", 1)))
return_0;
diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c
index 2b7bfe2..4711fa2 100644
--- a/lib/locking/file_locking.c
+++ b/lib/locking/file_locking.c
@@ -346,8 +346,7 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd,
locking->flags = 0;
/* Get lockfile directory from config file */
- locking_dir = find_config_tree_str(cmd, "global/locking_dir",
- DEFAULT_LOCK_DIR);
+ locking_dir = find_config_tree_str(cmd, global_locking_dir_CFG);
if (strlen(locking_dir) >= sizeof(_lock_dir)) {
log_error("Path for locking_dir %s is invalid.", locking_dir);
return 0;
@@ -356,8 +355,7 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd,
strcpy(_lock_dir, locking_dir);
_prioritise_write_locks =
- find_config_tree_bool(cmd, "global/prioritise_write_locks",
- DEFAULT_PRIORITISE_WRITE_LOCKS);
+ find_config_tree_bool(cmd, global_prioritise_write_locks_CFG);
(void) dm_prepare_selinux_context(_lock_dir, S_IFDIR);
r = dm_create_dir(_lock_dir);
diff --git a/lib/locking/locking.c b/lib/locking/locking.c
index 6f31ba8..63f946f 100644
--- a/lib/locking/locking.c
+++ b/lib/locking/locking.c
@@ -225,10 +225,9 @@ int init_locking(int type, struct cmd_context *cmd, int suppress_messages)
suppress_messages = 1;
if (type < 0)
- type = find_config_tree_int(cmd, "global/locking_type", 1);
+ type = find_config_tree_int(cmd, global_locking_type_CFG);
- _blocking_supported = find_config_tree_int(cmd,
- "global/wait_for_locks", DEFAULT_WAIT_FOR_LOCKS);
+ _blocking_supported = find_config_tree_bool(cmd, global_wait_for_locks_CFG);
switch (type) {
case 0:
@@ -255,9 +254,7 @@ int init_locking(int type, struct cmd_context *cmd, int suppress_messages)
if (init_external_locking(&_locking, cmd, suppress_messages))
return 1;
}
- if (!find_config_tree_int(cmd, "locking/fallback_to_clustered_locking",
- find_config_tree_int(cmd, "global/fallback_to_clustered_locking",
- DEFAULT_FALLBACK_TO_CLUSTERED_LOCKING))) {
+ if (!find_config_tree_bool(cmd, global_fallback_to_clustered_locking_CFG)) {
log_error_suppress(suppress_messages, "External locking initialisation failed.");
break;
}
@@ -290,9 +287,7 @@ int init_locking(int type, struct cmd_context *cmd, int suppress_messages)
}
if ((type == 2 || type == 3) &&
- find_config_tree_int(cmd, "locking/fallback_to_local_locking",
- find_config_tree_int(cmd, "global/fallback_to_local_locking",
- DEFAULT_FALLBACK_TO_LOCAL_LOCKING))) {
+ find_config_tree_bool(cmd, global_fallback_to_local_locking_CFG)) {
log_warn_suppress(suppress_messages, "WARNING: Falling back to local file-based locking.");
log_warn_suppress(suppress_messages,
"Volume Groups with the clustered attribute will "
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index ef9f643..ad8160e 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -95,8 +95,8 @@ int get_default_region_size(struct cmd_context *cmd)
* 'mirror_region_size' is the old setting. It is overridden
* by the new setting, 'raid_region_size'.
*/
- mrs = 2 * find_config_tree_int(cmd, "activation/mirror_region_size", 0);
- rrs = 2 * find_config_tree_int(cmd, "activation/raid_region_size", 0);
+ mrs = 2 * find_config_tree_int(cmd, activation_mirror_region_size_CFG);
+ rrs = 2 * find_config_tree_int(cmd, activation_raid_region_size_CFG);
if (!mrs && !rrs)
return DEFAULT_RAID_REGION_SIZE * 2;
@@ -921,8 +921,7 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
* a correct area_multiple.
*/
ah->area_multiple = _calc_area_multiple(segtype, area_count + parity_count, stripes);
- ah->mirror_logs_separate = find_config_tree_bool(cmd, "allocation/mirror_logs_require_separate_pvs",
- DEFAULT_MIRROR_LOGS_REQUIRE_SEPARATE_PVS);
+ ah->mirror_logs_separate = find_config_tree_bool(cmd, allocation_mirror_logs_require_separate_pvs_CFG);
if (segtype_is_raid(segtype)) {
if (metadata_area_count) {
@@ -949,8 +948,7 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
ah->log_len = ah->region_size;
ah->region_size = 0;
ah->mirror_logs_separate =
- find_config_tree_bool(cmd, "allocation/thin_pool_metadata_require_separate_pvs",
- DEFAULT_THIN_POOL_METADATA_REQUIRE_SEPARATE_PVS);
+ find_config_tree_bool(cmd, allocation_thin_pool_metadata_require_separate_pvs_CFG);
} else {
ah->log_area_count = metadata_area_count;
ah->log_len = !metadata_area_count ? 0 :
@@ -963,9 +961,9 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
ah->parallel_areas = parallel_areas;
- ah->cling_tag_list_cn = find_config_tree_node(cmd, "allocation/cling_tag_list");
+ ah->cling_tag_list_cn = find_config_tree_node(cmd, allocation_cling_tag_list_CFG);
- ah->maximise_cling = find_config_tree_bool(cmd, "allocation/maximise_cling", DEFAULT_MAXIMISE_CLING);
+ ah->maximise_cling = find_config_tree_bool(cmd, allocation_maximise_cling_CFG);
return ah;
}
@@ -3389,8 +3387,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
}
/* FIXME Ensure not referred to by another existing LVs */
- ask_discard = find_config_tree_bool(cmd,
- "devices/issue_discards", DEFAULT_ISSUE_DISCARDS);
+ ask_discard = find_config_tree_bool(cmd, devices_issue_discards_CFG);
if (lv_info(cmd, lv, 0, &info, 1, 0)) {
if (!lv_check_not_in_use(cmd, lv, &info))
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 0996184..403d86d 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -74,9 +74,7 @@ unsigned long set_pe_align(struct physical_volume *pv, unsigned long data_alignm
goto out;
}
- default_pe_align = find_config_tree_int(pv->fmt->cmd,
- "devices/default_data_alignment",
- DEFAULT_DATA_ALIGNMENT);
+ default_pe_align = find_config_tree_int(pv->fmt->cmd, devices_default_data_alignment_CFG);
if (default_pe_align)
/* align on 1 MiB multiple */
@@ -94,8 +92,7 @@ unsigned long set_pe_align(struct physical_volume *pv, unsigned long data_alignm
/*
* Align to stripe-width of underlying md device if present
*/
- if (find_config_tree_bool(pv->fmt->cmd, "devices/md_chunk_alignment",
- DEFAULT_MD_CHUNK_ALIGNMENT)) {
+ if (find_config_tree_bool(pv->fmt->cmd, devices_md_chunk_alignment_CFG)) {
temp_pe_align = dev_md_stripe_width(pv->fmt->cmd->sysfs_dir, pv->dev);
if (_alignment_overrides_default(temp_pe_align, default_pe_align))
pv->pe_align = MAX(pv->pe_align, temp_pe_align);
@@ -108,9 +105,7 @@ unsigned long set_pe_align(struct physical_volume *pv, unsigned long data_alignm
* - optimal_io_size - the device's preferred unit of receiving I/O
* (e.g. MD's stripe width)
*/
- if (find_config_tree_bool(pv->fmt->cmd,
- "devices/data_alignment_detection",
- DEFAULT_DATA_ALIGNMENT_DETECTION)) {
+ if (find_config_tree_bool(pv->fmt->cmd, devices_data_alignment_detection_CFG)) {
temp_pe_align = dev_minimum_io_size(pv->fmt->cmd->sysfs_dir, pv->dev);
if (_alignment_overrides_default(temp_pe_align, default_pe_align))
pv->pe_align = MAX(pv->pe_align, temp_pe_align);
@@ -142,9 +137,7 @@ unsigned long set_pe_align_offset(struct physical_volume *pv,
if (!pv->dev)
goto out;
- if (find_config_tree_bool(pv->fmt->cmd,
- "devices/data_alignment_offset_detection",
- DEFAULT_DATA_ALIGNMENT_OFFSET_DETECTION)) {
+ if (find_config_tree_bool(pv->fmt->cmd, devices_data_alignment_offset_detection_CFG)) {
int align_offset = dev_alignment_offset(pv->fmt->cmd->sysfs_dir,
pv->dev);
/* must handle a -1 alignment_offset; means dev is misaligned */
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index 2a78508..04a5638 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -1230,19 +1230,16 @@ int collapse_mirrored_lv(struct logical_volume *lv)
static int _get_mirror_fault_policy(struct cmd_context *cmd __attribute__((unused)),
int log_policy)
{
- const char *policy;
-
+ const char *policy = NULL;
+/*
if (log_policy)
- policy = dm_config_find_str(NULL, "activation/mirror_log_fault_policy",
- DEFAULT_MIRROR_LOG_FAULT_POLICY);
+ policy = find_config_tree_str(cmd, activation_mirror_log_fault_policy_CFG);
else {
- policy = dm_config_find_str(NULL, "activation/mirror_image_fault_policy",
- NULL);
+ policy = find_config_tree_str(cmd, activation_mirror_image_fault_policy_CFG);
if (!policy)
- policy = dm_config_find_str(NULL, "activation/mirror_device_fault_policy",
- DEFAULT_MIRROR_IMAGE_FAULT_POLICY);
+ policy = find_config_tree_str(cmd, activation_mirror_device_fault_policy_CFG);
}
-
+*/
if (!strcmp(policy, "remove"))
return MIRROR_REMOVE;
else if (!strcmp(policy, "allocate"))
diff --git a/lib/metadata/pv_manip.c b/lib/metadata/pv_manip.c
index 83aa9af..4a65a3e 100644
--- a/lib/metadata/pv_manip.c
+++ b/lib/metadata/pv_manip.c
@@ -203,8 +203,7 @@ int discard_pv_segment(struct pv_segment *peg, uint32_t discard_area_reduction)
* Only issue discards if enabled in lvm.conf and both
* the device and kernel (>= 2.6.35) supports discards.
*/
- if (!find_config_tree_bool(peg->pv->fmt->cmd,
- "devices/issue_discards", DEFAULT_ISSUE_DISCARDS))
+ if (!find_config_tree_bool(peg->pv->fmt->cmd, devices_issue_discards_CFG))
return 1;
/* Missing PV? */
diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c
index 59748de..c994a2e 100644
--- a/lib/metadata/thin_manip.c
+++ b/lib/metadata/thin_manip.c
@@ -312,9 +312,7 @@ int pool_below_threshold(const struct lv_segment *pool_seg)
{
percent_t percent;
int threshold = PERCENT_1 *
- find_config_tree_int(pool_seg->lv->vg->cmd,
- "activation/thin_pool_autoextend_threshold",
- DEFAULT_THIN_POOL_AUTOEXTEND_THRESHOLD);
+ find_config_tree_int(pool_seg->lv->vg->cmd, activation_thin_pool_autoextend_threshold_CFG);
/* Data */
if (!lv_thin_pool_percent(pool_seg->lv, 0, &percent))
diff --git a/lib/mirror/mirrored.c b/lib/mirror/mirrored.c
index 58afab3..6ce929d 100644
--- a/lib/mirror/mirrored.c
+++ b/lib/mirror/mirrored.c
@@ -540,8 +540,7 @@ static int _mirrored_target_present(struct cmd_context *cmd,
#ifdef DMEVENTD
static const char *_get_mirror_dso_path(struct cmd_context *cmd)
{
- return get_monitor_dso_path(cmd, find_config_tree_str(cmd, "dmeventd/mirror_library",
- DEFAULT_DMEVENTD_MIRROR_LIB));
+ return get_monitor_dso_path(cmd, find_config_tree_str(cmd, dmeventd_mirror_library_CFG));
}
/* FIXME Cache this */
diff --git a/lib/misc/sharedlib.c b/lib/misc/sharedlib.c
index 4c2d178..b899781 100644
--- a/lib/misc/sharedlib.c
+++ b/lib/misc/sharedlib.c
@@ -30,7 +30,7 @@ void get_shared_library_path(struct cmd_context *cmd, const char *libname,
/* If libname doesn't begin with '/' then use lib_dir/libname,
* if present */
if (libname[0] == '/' ||
- !(lib_dir = find_config_tree_str(cmd, "global/library_dir", 0)) ||
+ !(lib_dir = find_config_tree_str(cmd, global_library_dir_CFG)) ||
(dm_snprintf(path, path_len, "%s/%s", lib_dir,
libname) == -1) || stat(path, &info) == -1) {
strncpy(path, libname, path_len - 1);
diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c
index 6defa66..098de9e 100644
--- a/lib/mm/memlock.c
+++ b/lib/mm/memlock.c
@@ -290,7 +290,7 @@ static int _memlock_maps(struct cmd_context *cmd, lvmlock_t lock, size_t *mstats
}
line = _maps_buffer;
- cn = find_config_tree_node(cmd, "activation/mlock_filter");
+ cn = find_config_tree_node(cmd, activation_mlock_filter_CFG);
while ((line_end = strchr(line, '\n'))) {
*line_end = '\0'; /* remove \n */
@@ -317,7 +317,7 @@ static void _lock_mem(struct cmd_context *cmd)
* Note: assuming _memlock_count_daemon is updated before _memlock_count
*/
_use_mlockall = _memlock_count_daemon ? 1 :
- find_config_tree_bool(cmd, "activation/use_mlockall", DEFAULT_USE_MLOCKALL);
+ find_config_tree_bool(cmd, activation_use_mlockall_CFG);
if (!_use_mlockall) {
if (!*_procselfmaps &&
@@ -453,14 +453,9 @@ void memlock_init(struct cmd_context *cmd)
{
/* When threaded, caller already limited stack size so just use the default. */
_size_stack = 1024ULL * (cmd->threaded ? DEFAULT_RESERVED_STACK :
- find_config_tree_int(cmd, "activation/reserved_stack",
- DEFAULT_RESERVED_STACK));
- _size_malloc_tmp = find_config_tree_int(cmd,
- "activation/reserved_memory",
- DEFAULT_RESERVED_MEMORY) * 1024ULL;
- _default_priority = find_config_tree_int(cmd,
- "activation/process_priority",
- DEFAULT_PROCESS_PRIORITY);
+ find_config_tree_int(cmd, activation_reserved_stack_CFG));
+ _size_malloc_tmp = find_config_tree_int(cmd, activation_reserved_memory_CFG) * 1024ULL;
+ _default_priority = find_config_tree_int(cmd, activation_process_priority_CFG);
}
void memlock_reset(void)
diff --git a/lib/raid/raid.c b/lib/raid/raid.c
index 78fe074..1e28c73 100644
--- a/lib/raid/raid.c
+++ b/lib/raid/raid.c
@@ -282,8 +282,7 @@ static void _raid_destroy(struct segment_type *segtype)
#ifdef DMEVENTD
static const char *_get_raid_dso_path(struct cmd_context *cmd)
{
- const char *config_str = find_config_tree_str(cmd, "dmeventd/raid_library",
- DEFAULT_DMEVENTD_RAID_LIB);
+ const char *config_str = find_config_tree_str(cmd, dmeventd_raid_library_CFG);
return get_monitor_dso_path(cmd, config_str);
}
diff --git a/lib/snapshot/snapshot.c b/lib/snapshot/snapshot.c
index 662614c..3c03ea9 100644
--- a/lib/snapshot/snapshot.c
+++ b/lib/snapshot/snapshot.c
@@ -175,8 +175,7 @@ static int _snap_target_present(struct cmd_context *cmd,
static const char *_get_snapshot_dso_path(struct cmd_context *cmd)
{
- return get_monitor_dso_path(cmd, find_config_tree_str(cmd, "dmeventd/snapshot_library",
- DEFAULT_DMEVENTD_SNAPSHOT_LIB));
+ return get_monitor_dso_path(cmd, find_config_tree_str(cmd, dmeventd_snapshot_library_CFG));
}
/* FIXME Cache this */
diff --git a/lib/thin/thin.c b/lib/thin/thin.c
index 3e1da91..4bfae33 100644
--- a/lib/thin/thin.c
+++ b/lib/thin/thin.c
@@ -379,8 +379,7 @@ static int _thin_pool_target_percent(void **target_state __attribute__((unused))
# ifdef DMEVENTD
static const char *_get_thin_dso_path(struct cmd_context *cmd)
{
- return get_monitor_dso_path(cmd, find_config_tree_str(cmd, "dmeventd/thin_library",
- DEFAULT_DMEVENTD_THIN_LIB));
+ return get_monitor_dso_path(cmd, find_config_tree_str(cmd, dmeventd_thin_library_CFG));
}
/* FIXME Cache this */
@@ -596,7 +595,7 @@ static int _thin_target_present(struct cmd_context *cmd,
if (attributes) {
if (!_feature_mask) {
/* Support runtime lvm.conf changes, N.B. avoid 32 feature */
- if ((cn = find_config_tree_node(cmd, _lvmconf))) {
+ if ((cn = find_config_tree_node(cmd, global_thin_disabled_features_CFG))) {
for (cv = cn->v; cv; cv = cv->next) {
if (cv->type != DM_CFG_STRING) {
log_error("Ignoring invalid string in config file %s.",
diff --git a/liblvm/lvm_base.c b/liblvm/lvm_base.c
index b4911df..53be709 100644
--- a/liblvm/lvm_base.c
+++ b/liblvm/lvm_base.c
@@ -96,7 +96,9 @@ int lvm_config_override(lvm_t libh, const char *config_settings)
int lvm_config_find_bool(lvm_t libh, const char *config_path, int fail)
{
- return find_config_tree_bool((struct cmd_context *)libh, config_path, fail);
+ struct cmd_context *cmd = (struct cmd_context *)libh;
+
+ return dm_config_tree_find_bool(cmd->cft, config_path, fail);
}
int lvm_errno(lvm_t libh)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 234eb41..fcfcddb 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -837,15 +837,10 @@ static void _lvconvert_mirrors_repair_ask(struct cmd_context *cmd,
*replace_log = *replace_mirrors = 1;
if (arg_count(cmd, use_policies_ARG)) {
- leg_policy = find_config_tree_str(cmd,
- "activation/mirror_image_fault_policy", NULL);
+ leg_policy = find_config_tree_str(cmd, activation_mirror_image_fault_policy_CFG);
if (!leg_policy)
- leg_policy = find_config_tree_str(cmd,
- "activation/mirror_device_fault_policy",
- DEFAULT_MIRROR_DEVICE_FAULT_POLICY);
- log_policy = find_config_tree_str(cmd,
- "activation/mirror_log_fault_policy",
- DEFAULT_MIRROR_LOG_FAULT_POLICY);
+ leg_policy = find_config_tree_str(cmd, activation_mirror_device_fault_policy_CFG);
+ log_policy = find_config_tree_str(cmd, activation_mirror_log_fault_policy_CFG);
*replace_mirrors = strcmp(leg_policy, "remove");
*replace_log = strcmp(log_policy, "remove");
return;
@@ -1571,7 +1566,7 @@ static void _lvconvert_raid_repair_ask(struct cmd_context *cmd, int *replace_dev
*replace_dev = 1;
if (arg_count(cmd, use_policies_ARG)) {
- dev_policy = find_config_tree_str(cmd, "activation/raid_fault_policy", DEFAULT_RAID_FAULT_POLICY);
+ dev_policy = find_config_tree_str(cmd, activation_raid_fault_policy_CFG);
if (!strcmp(dev_policy, "allocate") ||
!strcmp(dev_policy, "replace"))
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index a2626c0..4618321 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -506,9 +506,7 @@ static int _read_raid_params(struct lvcreate_params *lp,
}
/* No stripe argument was given - default to 2 */
lp->stripes = 2;
- lp->stripe_size = find_config_tree_int(cmd,
- "metadata/stripesize",
- DEFAULT_STRIPESIZE) * 2;
+ lp->stripe_size = find_config_tree_int(cmd, metadata_stripesize_CFG) * 2;
}
/*
@@ -675,9 +673,9 @@ static int _lvcreate_params(struct lvcreate_params *lp,
if (arg_count(cmd, mirrors_ARG))
if (arg_uint_value(cmd, arg_count(cmd, stripes_long_ARG) ?
stripes_long_ARG : stripes_ARG, 1) > 1) {
- segtype_str = find_config_tree_str(cmd, "global/raid10_segtype_default", DEFAULT_RAID10_SEGTYPE);
+ segtype_str = find_config_tree_str(cmd, global_raid10_segtype_default_CFG);;
} else {
- segtype_str = find_config_tree_str(cmd, "global/mirror_segtype_default", DEFAULT_MIRROR_SEGTYPE);
+ segtype_str = find_config_tree_str(cmd, global_mirror_segtype_default_CFG);
}
else if (arg_count(cmd, thin_ARG) || arg_count(cmd, thinpool_ARG))
segtype_str = "thin";
diff --git a/tools/lvm.c b/tools/lvm.c
index ec9674e..9b66516 100644
--- a/tools/lvm.c
+++ b/tools/lvm.c
@@ -158,8 +158,7 @@ static void _read_history(struct cmd_context *cmd)
if (read_history(hist_file))
log_very_verbose("Couldn't read history from %s.", hist_file);
- stifle_history(find_config_tree_int(cmd, "shell/history_size",
- DEFAULT_MAX_HISTORY));
+ stifle_history(find_config_tree_int(cmd, shell_history_size_CFG));
}
static void _write_history(void)
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index c37ae25..c7820e0 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1443,8 +1443,7 @@ static int _lvm1_fallback(struct cmd_context *cmd)
char vsn[80];
int dm_present;
- if (!find_config_tree_int(cmd, "global/fallback_to_lvm1",
- DEFAULT_FALLBACK_TO_LVM1) ||
+ if (!find_config_tree_bool(cmd, global_fallback_to_lvm1_CFG) ||
strncmp(cmd->kernel_vsn, "2.4.", 4))
return 0;
diff --git a/tools/lvresize.c b/tools/lvresize.c
index d49da8a..e44fd82 100644
--- a/tools/lvresize.c
+++ b/tools/lvresize.c
@@ -288,20 +288,16 @@ static int _adjust_policy_params(struct cmd_context *cmd,
if (lv_is_thin_pool(lv)) {
policy_threshold =
- find_config_tree_int(cmd, "activation/thin_pool_autoextend_threshold",
- DEFAULT_THIN_POOL_AUTOEXTEND_THRESHOLD) * PERCENT_1;
+ find_config_tree_int(cmd, activation_thin_pool_autoextend_threshold_CFG) * PERCENT_1;
policy_amount =
- find_config_tree_int(cmd, "activation/thin_pool_autoextend_percent",
- DEFAULT_THIN_POOL_AUTOEXTEND_PERCENT);
+ find_config_tree_int(cmd, activation_thin_pool_autoextend_percent_CFG);
if (!policy_amount && policy_threshold < PERCENT_100)
return 0;
} else {
policy_threshold =
- find_config_tree_int(cmd, "activation/snapshot_autoextend_threshold",
- DEFAULT_SNAPSHOT_AUTOEXTEND_THRESHOLD) * PERCENT_1;
+ find_config_tree_int(cmd, activation_snapshot_autoextend_threshold_CFG) * PERCENT_1;
policy_amount =
- find_config_tree_int(cmd, "activation/snapshot_autoextend_percent",
- DEFAULT_SNAPSHOT_AUTOEXTEND_PERCENT);
+ find_config_tree_int(cmd, activation_snapshot_autoextend_percent_CFG);
}
if (policy_threshold >= PERCENT_100)
@@ -652,9 +648,7 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
lp->stripe_size = seg_stripesize;
} else {
lp->stripe_size =
- find_config_tree_int(cmd,
- "metadata/stripesize",
- DEFAULT_STRIPESIZE) * 2;
+ find_config_tree_int(cmd, metadata_stripesize_CFG) * 2;
log_print_unless_silent("Using default stripesize %s",
display_size(cmd, (uint64_t) lp->stripe_size));
}
diff --git a/tools/polldaemon.c b/tools/polldaemon.c
index a9138a1..5724623 100644
--- a/tools/polldaemon.c
+++ b/tools/polldaemon.c
@@ -319,8 +319,7 @@ int poll_daemon(struct cmd_context *cmd, const char *name, const char *uuid,
if (interval_sign == SIGN_MINUS)
log_error("Argument to --interval cannot be negative");
parms.interval = arg_uint_value(cmd, interval_ARG,
- find_config_tree_int(cmd, "activation/polling_interval",
- DEFAULT_INTERVAL));
+ find_config_tree_int(cmd, activation_polling_interval_CFG));
parms.wait_before_testing = (interval_sign == SIGN_PLUS);
parms.progress_display = 1;
parms.progress_title = progress_title;
@@ -337,8 +336,7 @@ int poll_daemon(struct cmd_context *cmd, const char *name, const char *uuid,
/* FIXME Disabled multiple-copy wait_event */
if (!name)
- parms.interval = find_config_tree_int(cmd, "activation/polling_interval",
- DEFAULT_INTERVAL);
+ parms.interval = find_config_tree_int(cmd, activation_polling_interval_CFG);
}
if (parms.background) {
diff --git a/tools/pvcreate.c b/tools/pvcreate.c
index 5b83a18..da51eec 100644
--- a/tools/pvcreate.c
+++ b/tools/pvcreate.c
@@ -38,9 +38,7 @@ static int pvcreate_restore_params_validate(struct cmd_context *cmd,
if (!arg_count(cmd, restorefile_ARG) && arg_count(cmd, uuidstr_ARG)) {
if (!arg_count(cmd, norestorefile_ARG) &&
- find_config_tree_bool(cmd,
- "devices/require_restorefile_with_uuid",
- DEFAULT_REQUIRE_RESTOREFILE_WITH_UUID)) {
+ find_config_tree_bool(cmd, devices_require_restorefile_with_uuid_CFG)) {
log_error("--restorefile is required with --uuid");
return 0;
}
diff --git a/tools/pvscan.c b/tools/pvscan.c
index ff5ced2..ab58c5f 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -146,8 +146,8 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
* and to prevent hangs in clustered environment.
*/
/* TODO: Remove this once lvmetad + cluster supported! */
- if (find_config_tree_int(cmd, "global/locking_type", 1) == 3 ||
- !find_config_tree_int(cmd, "global/use_lvmetad", 0)) {
+ if (find_config_tree_int(cmd, global_locking_type_CFG) == 3 ||
+ !find_config_tree_bool(cmd, global_use_lvmetad_CFG)) {
log_debug_lvmetad("_pvscan_lvmetad: immediate return");
return ret;
}
diff --git a/tools/reporter.c b/tools/reporter.c
index 1c8e39d..3db8b83 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -234,20 +234,13 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
int columns_as_rows;
unsigned args_are_pvs;
- aligned = find_config_tree_int(cmd, "report/aligned",
- DEFAULT_REP_ALIGNED);
- buffered = find_config_tree_int(cmd, "report/buffered",
- DEFAULT_REP_BUFFERED);
- headings = find_config_tree_int(cmd, "report/headings",
- DEFAULT_REP_HEADINGS);
- separator = find_config_tree_str(cmd, "report/separator",
- DEFAULT_REP_SEPARATOR);
- field_prefixes = find_config_tree_int(cmd, "report/prefixes",
- DEFAULT_REP_PREFIXES);
- quoted = find_config_tree_int(cmd, "report/quoted",
- DEFAULT_REP_QUOTED);
- columns_as_rows = find_config_tree_int(cmd, "report/columns_as_rows",
- DEFAULT_REP_COLUMNS_AS_ROWS);
+ aligned = find_config_tree_bool(cmd, report_aligned_CFG);
+ buffered = find_config_tree_bool(cmd, report_buffered_CFG);
+ headings = find_config_tree_bool(cmd, report_headings_CFG);
+ separator = find_config_tree_str(cmd, report_separator_CFG);
+ field_prefixes = find_config_tree_bool(cmd, report_prefixes_CFG);
+ quoted = find_config_tree_bool(cmd, report_quoted_CFG);
+ columns_as_rows = find_config_tree_bool(cmd, report_colums_as_rows_CFG);
args_are_pvs = (report_type == PVS ||
report_type == LABEL ||
@@ -255,65 +248,40 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
switch (report_type) {
case LVS:
- keys = find_config_tree_str(cmd, "report/lvs_sort",
- DEFAULT_LVS_SORT);
+ keys = find_config_tree_str(cmd, report_lvs_sort_CFG);
if (!arg_count(cmd, verbose_ARG))
- options = find_config_tree_str(cmd,
- "report/lvs_cols",
- DEFAULT_LVS_COLS);
+ options = find_config_tree_str(cmd, report_lvs_cols_CFG);
else
- options = find_config_tree_str(cmd,
- "report/lvs_cols_verbose",
- DEFAULT_LVS_COLS_VERB);
+ options = find_config_tree_str(cmd, report_lvs_cols_verbose_CFG);
break;
case VGS:
- keys = find_config_tree_str(cmd, "report/vgs_sort",
- DEFAULT_VGS_SORT);
+ keys = find_config_tree_str(cmd, report_vgs_sort_CFG);
if (!arg_count(cmd, verbose_ARG))
- options = find_config_tree_str(cmd,
- "report/vgs_cols",
- DEFAULT_VGS_COLS);
+ options = find_config_tree_str(cmd, report_vgs_cols_CFG);
else
- options = find_config_tree_str(cmd,
- "report/vgs_cols_verbose",
- DEFAULT_VGS_COLS_VERB);
+ options = find_config_tree_str(cmd, report_vgs_cols_verbose_CFG);
break;
case LABEL:
case PVS:
- keys = find_config_tree_str(cmd, "report/pvs_sort",
- DEFAULT_PVS_SORT);
+ keys = find_config_tree_str(cmd, report_pvs_sort_CFG);
if (!arg_count(cmd, verbose_ARG))
- options = find_config_tree_str(cmd,
- "report/pvs_cols",
- DEFAULT_PVS_COLS);
+ options = find_config_tree_str(cmd, report_pvs_cols_CFG);
else
- options = find_config_tree_str(cmd,
- "report/pvs_cols_verbose",
- DEFAULT_PVS_COLS_VERB);
+ options = find_config_tree_str(cmd, report_pvs_cols_verbose_CFG);
break;
case SEGS:
- keys = find_config_tree_str(cmd, "report/segs_sort",
- DEFAULT_SEGS_SORT);
+ keys = find_config_tree_str(cmd, report_segs_sort_CFG);
if (!arg_count(cmd, verbose_ARG))
- options = find_config_tree_str(cmd,
- "report/segs_cols",
- DEFAULT_SEGS_COLS);
+ options = find_config_tree_str(cmd, report_segs_cols_CFG);
else
- options = find_config_tree_str(cmd,
- "report/segs_cols_verbose",
- DEFAULT_SEGS_COLS_VERB);
+ options = find_config_tree_str(cmd, report_segs_cols_verbose_CFG);
break;
case PVSEGS:
- keys = find_config_tree_str(cmd, "report/pvsegs_sort",
- DEFAULT_PVSEGS_SORT);
+ keys = find_config_tree_str(cmd, report_pvsegs_sort_CFG);
if (!arg_count(cmd, verbose_ARG))
- options = find_config_tree_str(cmd,
- "report/pvsegs_cols",
- DEFAULT_PVSEGS_COLS);
+ options = find_config_tree_str(cmd, report_pvsegs_cols_CFG);
else
- options = find_config_tree_str(cmd,
- "report/pvsegs_cols_verbose",
- DEFAULT_PVSEGS_COLS_VERB);
+ options = find_config_tree_str(cmd, report_pvsegs_cols_verbose_CFG);
break;
default:
log_error(INTERNAL_ERROR "Unknown report type.");
diff --git a/tools/toollib.c b/tools/toollib.c
index 7043ea4..6b00155 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1290,9 +1290,7 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
vp_new->vgmetadatacopies = arg_int_value(cmd, vgmetadatacopies_ARG,
DEFAULT_VGMETADATACOPIES);
} else {
- vp_new->vgmetadatacopies = find_config_tree_int(cmd,
- "metadata/vgmetadatacopies",
- DEFAULT_VGMETADATACOPIES);
+ vp_new->vgmetadatacopies = find_config_tree_int(cmd, metadata_vgmetadatacopies_CFG);
}
return 1;
@@ -1426,17 +1424,12 @@ int pvcreate_params_validate(struct cmd_context *cmd,
return 0;
}
- if (arg_count(cmd, metadataignore_ARG)) {
- pp->metadataignore = !strcmp(arg_str_value(cmd,
- metadataignore_ARG,
- DEFAULT_PVMETADATAIGNORE_STR),
- "y");
- } else {
- pp->metadataignore = !strcmp(find_config_tree_str(cmd,
- "metadata/pvmetadataignore",
- DEFAULT_PVMETADATAIGNORE_STR),
- "y");
- }
+ if (arg_count(cmd, metadataignore_ARG))
+ pp->metadataignore = arg_int_value(cmd, metadataignore_ARG,
+ DEFAULT_PVMETADATAIGNORE);
+ else
+ pp->metadataignore = find_config_tree_bool(cmd, metadata_pvmetadataignore_CFG);
+
if (arg_count(cmd, pvmetadatacopies_ARG) &&
!arg_int_value(cmd, pvmetadatacopies_ARG, -1) &&
pp->metadataignore) {
@@ -1496,15 +1489,11 @@ int pvcreate_params_validate(struct cmd_context *cmd,
pp->pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG, UINT64_C(0));
if (!pp->pvmetadatasize)
- pp->pvmetadatasize = find_config_tree_int(cmd,
- "metadata/pvmetadatasize",
- DEFAULT_PVMETADATASIZE);
+ pp->pvmetadatasize = find_config_tree_int(cmd, metadata_pvmetadatasize_CFG);
pp->pvmetadatacopies = arg_int_value(cmd, pvmetadatacopies_ARG, -1);
if (pp->pvmetadatacopies < 0)
- pp->pvmetadatacopies = find_config_tree_int(cmd,
- "metadata/pvmetadatacopies",
- DEFAULT_PVMETADATACOPIES);
+ pp->pvmetadatacopies = find_config_tree_int(cmd, metadata_pvmetadatacopies_CFG);
pp->rp.ea_size = arg_uint64_value(cmd, embeddingareasize_ARG, pp->rp.ea_size);
@@ -1528,8 +1517,7 @@ int get_activation_monitoring_mode(struct cmd_context *cmd,
DEFAULT_DMEVENTD_MONITOR);
else if (is_static() || arg_count(cmd, ignoremonitoring_ARG) ||
arg_count(cmd, sysinit_ARG) ||
- !find_config_tree_bool(cmd, "activation/monitoring",
- DEFAULT_DMEVENTD_MONITOR))
+ !find_config_tree_bool(cmd, activation_monitoring_CFG))
*monitoring_mode = DMEVENTD_MONITOR_IGNORE;
return 1;
@@ -1547,18 +1535,14 @@ int get_pool_params(struct cmd_context *cmd,
*zero = strcmp(arg_str_value(cmd, zero_ARG, "y"), "n");
log_very_verbose("Setting pool zeroing: %u", *zero);
} else
- *zero = find_config_tree_int(cmd,
- "allocation/thin_pool_zero",
- DEFAULT_THIN_POOL_ZERO);
+ *zero = find_config_tree_bool(cmd, allocation_thin_pool_zero_CFG);
if (arg_count(cmd, discards_ARG)) {
*discards = (thin_discards_t) arg_uint_value(cmd, discards_ARG, 0);
log_very_verbose("Setting pool discards: %s",
get_pool_discards_name(*discards));
} else {
- dstr = find_config_tree_str(cmd,
- "allocation/thin_pool_discards",
- DEFAULT_THIN_POOL_DISCARDS);
+ dstr = find_config_tree_str(cmd, allocation_thin_pool_discards_CFG);
if (!get_pool_discards(dstr, discards))
return_0;
}
@@ -1573,9 +1557,7 @@ int get_pool_params(struct cmd_context *cmd,
log_very_verbose("Setting pool chunk size: %s",
display_size(cmd, *chunk_size));
} else
- *chunk_size = find_config_tree_int(cmd,
- "allocation/thin_pool_chunk_size",
- DEFAULT_THIN_POOL_CHUNK_SIZE) * 2;
+ *chunk_size = find_config_tree_int(cmd, allocation_thin_pool_chunk_size_CFG) * 2;
if ((*chunk_size < DM_THIN_MIN_DATA_BLOCK_SIZE) ||
(*chunk_size > DM_THIN_MAX_DATA_BLOCK_SIZE)) {
@@ -1737,7 +1719,7 @@ static int _validate_stripe_params(struct cmd_context *cmd, uint32_t *stripes,
}
if (*stripes > 1 && !*stripe_size) {
- *stripe_size = find_config_tree_int(cmd, "metadata/stripesize", DEFAULT_STRIPESIZE) * 2;
+ *stripe_size = find_config_tree_int(cmd, metadata_stripesize_CFG) * 2;
log_print_unless_silent("Using default stripesize %s",
display_size(cmd, (uint64_t) *stripe_size));
}
diff --git a/tools/vgconvert.c b/tools/vgconvert.c
index 3671767..cdadd9a 100644
--- a/tools/vgconvert.c
+++ b/tools/vgconvert.c
@@ -51,16 +51,12 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
UINT64_C(0));
if (!pvmetadatasize)
pvmetadatasize =
- find_config_tree_int(cmd,
- "metadata/pvmetadatasize",
- DEFAULT_PVMETADATASIZE);
+ find_config_tree_int(cmd, metadata_pvmetadatasize_CFG);
pvmetadatacopies = arg_int_value(cmd, pvmetadatacopies_ARG, -1);
if (pvmetadatacopies < 0)
pvmetadatacopies =
- find_config_tree_int(cmd,
- "metadata/pvmetadatacopies",
- DEFAULT_PVMETADATACOPIES);
+ find_config_tree_int(cmd, metadata_pvmetadatacopies_CFG);
}
if (cmd->fmt->features & FMT_EAS) {
10 years, 9 months
master - config: add structs to represent config definition and register config_settings.h content
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a3d891a29042e5...
Commit: a3d891a29042e51a0f43ed02273a6dce194d6569
Parent: e947c362dd0ae1da2d76925fe6b38244c5f46d25
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Mar 5 16:49:42 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Mar 6 10:14:33 2013 +0100
config: add structs to represent config definition and register config_settings.h content
This patch adds basic structures that encapsulate the config_settings.h
content - it takes each item and puts it in structures:
- cfg_def_type_t to define config item type
- cfg_def_value_t to define config item (default) value
- flags used to define the nature and use of the config item:
- CFG_NAME_VARIABLE for items with variable names (e.g. tags)
- CFG_ALLOW_EMPTY for items where empty value is allowed
- CFG_ADVANCED for items which are considered as "advanced settings"
- CFG_UNSUPPORTED for items which are not officially supported
(config options mostly for internal use and testing/debugging)
- cfg_def_item_t to encapsulate the whole definition of the config
definition itself
Each config item is referenced by named ID, e.g. "devices_dir_CFG"
instead of directly typing the path "devices/dir" as it was before.
This patch also adds cfg_def_get_path helper function to get the
config setting path up to the root for given config ID
(it returns the path in form of "abc/def/.../xyz" where the "abc"
is the topmost element).
---
lib/config/config.c | 45 +++++++++++++++++++++++++++++++++++++
lib/config/config.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 107 insertions(+), 0 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index 0820594..f2ee9e7 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -38,6 +38,21 @@ struct config_file {
struct device *dev;
};
+static char _cfg_path[CFG_PATH_MAX_LEN];
+
+/*
+ * Map each ID to respective definition of the configuration item.
+ */
+static struct cfg_def_item _cfg_def_items[CFG_COUNT + 1] = {
+#define cfg_section(id, name, parent, flags, since_version, comment) {id, parent, name, CFG_TYPE_SECTION, {0}, flags, since_version, comment},
+#define cfg(id, name, parent, flags, type, default_value, since_version, comment) {id, parent, name, type, {.v_##type = default_value}, flags, since_version, comment},
+#define cfg_array(id, name, parent, flags, types, default_value, since_version, comment) {id, parent, name, CFG_TYPE_ARRAY | types, {.v_CFG_TYPE_STRING = default_value}, flags, since_version, comment},
+#include "config_settings.h"
+#undef cfg_section
+#undef cfg
+#undef cfg_array
+};
+
/*
* public interface
*/
@@ -289,6 +304,36 @@ time_t config_file_timestamp(struct dm_config_tree *cft)
return cf->timestamp;
}
+#define cfg_def_get_item_p(id) (&_cfg_def_items[id])
+#define cfg_def_get_default_value(item,type) item->default_value.v_##type
+#define cfg_def_get_path(item) (_cfg_def_make_path(_cfg_path,CFG_PATH_MAX_LEN,item->id,item),_cfg_path)
+
+static int _cfg_def_make_path(char *buf, size_t buf_size, int id, cfg_def_item_t *item)
+{
+ int parent_id = item->parent;
+ int count, n;
+
+ if (id == parent_id)
+ return 0;
+
+ count = _cfg_def_make_path(buf, buf_size, parent_id, cfg_def_get_item_p(parent_id));
+ if ((n = dm_snprintf(buf + count, buf_size - count, "%s%s",
+ count ? "/" : "",
+ item->flags & CFG_NAME_VARIABLE ? "#" : item->name)) < 0) {
+ log_error(INTERNAL_ERROR "_cfg_def_make_path: supplied buffer too small for %s/%s",
+ cfg_def_get_item_p(parent_id)->name, item->name);
+ buf[0] = '\0';
+ return 0;
+ }
+
+ return count + n;
+}
+
+int config_def_get_path(char *buf, size_t buf_size, int id)
+{
+ return _cfg_def_make_path(buf, buf_size, id, cfg_def_get_item_p(id));
+}
+
const struct dm_config_node *find_config_tree_node(struct cmd_context *cmd,
const char *path)
{
diff --git a/lib/config/config.h b/lib/config/config.h
index 079e9d1..2317348 100644
--- a/lib/config/config.h
+++ b/lib/config/config.h
@@ -17,6 +17,7 @@
#define _LVM_CONFIG_H
#include "lvm-types.h"
+#include "defaults.h"
/* 16 bits: 3 bits for major, 4 bits for minor, 9 bits for patchlevel */
/* Max LVM version supported: 7.15.511. Just extend bits if ever needed. */
@@ -25,6 +26,67 @@
struct device;
struct cmd_context;
+#define CFG_PATH_MAX_LEN 64
+
+/*
+ * Structures used for definition of a configuration tree.
+ */
+
+/* configuration definition item type (for item's accepted types) */
+typedef enum {
+ CFG_TYPE_SECTION = 0, /* section */
+ CFG_TYPE_ARRAY = 1, /* setting */
+ CFG_TYPE_BOOL = 2, /* setting */
+ CFG_TYPE_INT = 4, /* setting */
+ CFG_TYPE_FLOAT = 8, /* setting */
+ CFG_TYPE_STRING = 16 /* setting */
+} cfg_def_type_t;
+
+/* configuration definition item value (for item's default value) */
+typedef union {
+ const int v_CFG_TYPE_BOOL, v_CFG_TYPE_INT;
+ const float v_CFG_TYPE_FLOAT;
+ const char *v_CFG_TYPE_STRING, *v_CFG_TYPE_ARRAY;
+} cfg_def_value_t;
+
+/* configuration definition item flags: */
+
+/* whether the configuration item name is variable */
+#define CFG_NAME_VARIABLE 0x01
+/* whether empty value is allowed */
+#define CFG_ALLOW_EMPTY 0x02
+/* whether the configuration item is for advanced use only */
+#define CFG_ADVANCED 0x04
+/* whether the configuraton item is not officially supported */
+#define CFG_UNSUPPORTED 0x08
+
+/* configuration definition item structure */
+typedef struct cfg_def_item {
+ int id; /* ID of this item */
+ int parent; /* ID of parent item */
+ const char *name; /* name of the item in configuration tree */
+ cfg_def_type_t type; /* configuration item type */
+ cfg_def_value_t default_value; /* default value (only for settings) */
+ uint16_t flags; /* configuration item definition flags */
+ uint16_t since_version; /* version this item appeared in */
+ const char *comment; /* brief comment */
+} cfg_def_item_t;
+
+/*
+ * Register ID for each possible item in the configuration tree.
+ */
+enum {
+#define cfg_section(id, name, parent, flags, since_version, comment) id,
+#define cfg(id, name, parent, flags, type, default_value, since_version, comment) id,
+#define cfg_array(id, name, parent, flags, types, default_value, since_version, comment) id,
+#include "config_settings.h"
+#undef cfg_section
+#undef cfg
+#undef cfg_array
+};
+
+int config_def_get_path(char *buf, size_t buf_size, int id);
+
int override_config_tree_from_string(struct cmd_context *cmd,
const char *config_settings);
struct dm_config_tree *remove_overridden_config_tree(struct cmd_context *cmd);
10 years, 9 months
master - config: add config_settings.h
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e947c362dd0ae1...
Commit: e947c362dd0ae1da2d76925fe6b38244c5f46d25
Parent: 6ea68f233c2196856fbc008e30b1eb17deb62701
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Mar 5 16:42:32 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Mar 6 10:14:32 2013 +0100
config: add config_settings.h
This file centrally defines all recognized LVM2 configuration
sections and settings. Each item here has its parent, set of
allowed types, default value, brief comment, version the setting
first appeared in and flags that further define the nature of
the configuration setting and its use.
---
include/.symlinks.in | 1 +
lib/config/config_settings.h | 229 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 230 insertions(+), 0 deletions(-)
diff --git a/include/.symlinks.in b/include/.symlinks.in
index e94ff84..1c883ae 100644
--- a/include/.symlinks.in
+++ b/include/.symlinks.in
@@ -9,6 +9,7 @@
@top_srcdir(a)/lib/commands/errors.h
@top_srcdir(a)/lib/commands/toolcontext.h
@top_srcdir(a)/lib/config/config.h
+@top_srcdir(a)/lib/config/config_settings.h
@top_srcdir(a)/lib/config/defaults.h
@top_srcdir(a)/lib/datastruct/btree.h
@top_srcdir(a)/lib/datastruct/lvm-types.h
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
new file mode 100644
index 0000000..a7d2625
--- /dev/null
+++ b/lib/config/config_settings.h
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/*
+ * MACROS:
+ * cfg_section(id, name, parent, flags, since_version, comment)
+ * cfg(id, name, parent, flags, type, default_value, since_version, comment)
+ * cfg_array(id, name, parent, flags, types, default_value, since_version, comment)
+ *
+ * VARIABLES:
+ * cfg_section: define a new configuration section
+ * cfg: define a new configuration setting of a simple type
+ * cfg_array: define a new configuration setting of array type
+ *
+ * id: unique identifier
+ * name: configuration node name
+ * parent: id of parent configuration node
+ * flags: configuration item flags:
+ * CFG_NAME_VARIABLE - configuration node name is variable
+ * CFG_ALLOW_EMPTY - node value can be emtpy
+ * CFG_ADVANCED - this node belongs to advanced config set
+ * CFG_UNSUPPORTED - this node belongs to unsupported config set
+ * type: allowed type for the value of simple configuation setting
+ * types: allowed types for the values of array configuration setting
+ * (use logical "OR" to define more than one allowed type,
+ * e.g. CFG_TYPE_STRING | CFG_TYPE_INT)
+ * default_value: default value of type 'type' for the configuration node,
+ * if this is an array with several 'types' defined then
+ * default value is a string where each string representation
+ * of each value is prefixed by '#X' where X is one of:
+ * 'B' for boolean value
+ * 'I' for integer value
+ * 'F' for float value
+ * 'S' for string value
+ * '#' for the '#' character itself
+ * For example, "#Sfd#I16" means default value [ "fd", 16 ].
+ * comment: brief comment used in configuration dumps
+ * since_version: the version this configuration node first appeared in (be sure
+ * that parent nodes are consistent with versioning, no check done
+ * if parent node is older or the same age as any child node!)
+ */
+
+cfg_section(root_CFG_SECTION, "(root)", root_CFG_SECTION, 0, vsn(0, 0, 0), NULL)
+
+cfg_section(config_CFG_SECTION, "config", root_CFG_SECTION, 0, vsn(2, 2, 99), "Configuration handling.")
+cfg_section(devices_CFG_SECTION, "devices", root_CFG_SECTION, 0, vsn(1, 0, 0), NULL)
+cfg_section(allocation_CFG_SECTION, "allocation", root_CFG_SECTION, 0, vsn(2, 2, 77), NULL)
+cfg_section(log_CFG_SECTION, "log", root_CFG_SECTION, 0, vsn(1, 0, 0), NULL)
+cfg_section(backup_CFG_SECTION, "backup", root_CFG_SECTION, 0, vsn(1, 0, 0), NULL)
+cfg_section(shell_CFG_SECTION, "shell", root_CFG_SECTION, 0, vsn(1, 0, 0), NULL)
+cfg_section(global_CFG_SECTION, "global", root_CFG_SECTION, 0, vsn(1, 0, 0), NULL)
+cfg_section(activation_CFG_SECTION, "activation", root_CFG_SECTION, 0, vsn(1, 0, 0), NULL)
+cfg_section(metadata_CFG_SECTION, "metadata", root_CFG_SECTION, CFG_ADVANCED, vsn(1, 0, 0), NULL)
+cfg_section(report_CFG_SECTION, "report", root_CFG_SECTION, CFG_ADVANCED, vsn(1, 0, 0), NULL)
+cfg_section(dmeventd_CFG_SECTION, "dmeventd", root_CFG_SECTION, 0, vsn(1, 2, 3), NULL)
+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(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)
+cfg_array(devices_loopfiles_CFG, "loopfiles", devices_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 2, 0), NULL)
+cfg(devices_obtain_device_list_from_udev_CFG, "obtain_device_list_from_udev", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_OBTAIN_DEVICE_LIST_FROM_UDEV, vsn(2, 2, 85), NULL)
+cfg_array(devices_preferred_names_CFG, "preferred_names", devices_CFG_SECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, NULL, vsn(1, 2, 19), NULL)
+cfg_array(devices_filter_CFG, "filter", devices_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+cfg_array(devices_global_filter_CFG, "global_filter", devices_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(2, 2, 98), NULL)
+cfg(devices_cache_CFG, "cache", devices_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+cfg(devices_cache_dir_CFG, "cache_dir", devices_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 2, 19), NULL)
+cfg(devices_cache_file_prefix_CFG, "cache_file_prefix", devices_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 2, 19), NULL)
+cfg(devices_write_cache_state_CFG, "write_cache_state", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(1, 0, 0), NULL)
+cfg_array(devices_types_CFG, "types", devices_CFG_SECTION, 0, CFG_TYPE_INT | CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+cfg(devices_sysfs_scan_CFG, "sysfs_scan", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_SYSFS_SCAN, vsn(1, 0, 8), NULL)
+cfg(devices_multipath_component_detection_CFG, "multipath_component_detection", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MULTIPATH_COMPONENT_DETECTION, vsn(2, 2, 89), NULL)
+cfg(devices_md_component_detection_CFG, "md_component_detection", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MD_COMPONENT_DETECTION, vsn(1, 0, 18), NULL)
+cfg(devices_md_chunk_alignment_CFG, "md_chunk_alignment", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MD_CHUNK_ALIGNMENT, vsn(2, 2, 48), NULL)
+cfg(devices_default_data_alignment_CFG, "default_data_alignment", devices_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_DATA_ALIGNMENT, vsn(2, 2, 75), NULL)
+cfg(devices_data_alignment_detection_CFG, "data_alignment_detection", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_DATA_ALIGNMENT_DETECTION, vsn(2, 2, 51), NULL)
+cfg(devices_data_alignment_CFG, "data_alignment", devices_CFG_SECTION, 0, CFG_TYPE_INT, 0, vsn(2, 2, 45), NULL)
+cfg(devices_data_alignment_offset_detection_CFG, "data_alignment_offset_detection", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_DATA_ALIGNMENT_OFFSET_DETECTION, vsn(2, 2, 50), NULL)
+cfg(devices_ignore_suspended_devices_CFG, "ignore_suspended_devices", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_IGNORE_SUSPENDED_DEVICES, vsn(1, 2, 19), NULL)
+cfg(devices_disable_after_error_count_CFG, "disable_after_error_count", devices_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_DISABLE_AFTER_ERROR_COUNT, vsn(2, 2, 75), NULL)
+cfg(devices_require_restorefile_with_uuid_CFG, "require_restorefile_with_uuid", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_REQUIRE_RESTOREFILE_WITH_UUID, vsn(2, 2, 73), NULL)
+cfg(devices_pv_min_size_CFG, "pv_min_size", devices_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_PV_MIN_SIZE_KB, vsn(2, 2, 85), NULL)
+cfg(devices_issue_discards_CFG, "issue_discards", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_ISSUE_DISCARDS, vsn(2, 2, 85), NULL)
+
+cfg_array(allocation_cling_tag_list_CFG, "cling_tag_list", allocation_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(2, 2, 77), NULL)
+cfg(allocation_maximise_cling_CFG, "maximise_cling", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MAXIMISE_CLING, vsn(2, 2, 85), NULL)
+cfg(allocation_mirror_logs_require_separate_pvs_CFG, "mirror_logs_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MIRROR_LOGS_REQUIRE_SEPARATE_PVS, vsn(2, 2, 85), NULL)
+cfg(allocation_thin_pool_metadata_require_separate_pvs_CFG, "thin_pool_metadata_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_THIN_POOL_METADATA_REQUIRE_SEPARATE_PVS, vsn(2, 2, 89), NULL)
+cfg(allocation_thin_pool_zero_CFG, "thin_pool_zero", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_THIN_POOL_ZERO, vsn(2, 2, 99), NULL)
+cfg(allocation_thin_pool_discards_CFG, "thin_pool_discards", allocation_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_THIN_POOL_DISCARDS, vsn(2, 2, 99), NULL)
+cfg(allocation_thin_pool_chunk_size_CFG, "thin_pool_chunk_size", allocation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_THIN_POOL_CHUNK_SIZE, vsn(2, 2, 99), NULL)
+
+cfg(log_verbose_CFG, "verbose", log_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_VERBOSE, vsn(1, 0, 0), NULL)
+cfg(log_silent_CFG, "silent", log_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_SILENT, vsn(2, 2, 98), NULL)
+cfg(log_syslog_CFG, "syslog", log_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_SYSLOG, vsn(1, 0, 0), NULL)
+cfg(log_file_CFG, "file", log_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+cfg(log_overwrite_CFG, "overwrite", log_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_OVERWRITE, vsn(1, 0, 0), NULL)
+cfg(log_level_CFG, "level", log_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_LOGLEVEL, vsn(1, 0, 0), NULL)
+cfg(log_indent_CFG, "indent", log_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_INDENT, vsn(1, 0, 0), NULL)
+cfg(log_command_names_CFG, "command_names", log_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_CMD_NAME, vsn(1, 0, 0), NULL)
+cfg(log_prefix_CFG, "prefix", log_CFG_SECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, DEFAULT_MSG_PREFIX, vsn(1, 0, 0), NULL)
+cfg(log_activation_CFG, "activation", log_CFG_SECTION, 0, CFG_TYPE_BOOL, 0, vsn(1, 0, 0), NULL)
+cfg(log_activate_file_CFG, "activate_file", log_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+cfg_array(log_debug_classes_CFG, "debug_classes", log_CFG_SECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, "#Smemory#Sdevices#Sactivation#Sallocation#Slvmetad#Smetadata#Scache#Slocking", vsn(2, 2, 99), NULL)
+
+cfg(backup_backup_CFG, "backup", backup_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_BACKUP_ENABLED, vsn(1, 0, 0), NULL)
+cfg(backup_backup_dir_CFG, "backup_dir", backup_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+cfg(backup_archive_CFG, "archive", backup_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_ARCHIVE_ENABLED, vsn(1, 0, 0), NULL)
+cfg(backup_archive_dir_CFG, "archive_dir", backup_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+cfg(backup_retain_min_CFG, "retain_min", backup_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_ARCHIVE_NUMBER, vsn(1, 0, 0), NULL)
+cfg(backup_retain_days_CFG, "retain_days", backup_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_ARCHIVE_DAYS, vsn(1, 0, 0), NULL)
+
+cfg(shell_history_size_CFG, "history_size", shell_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_MAX_HISTORY, vsn(1, 0, 0), NULL)
+
+cfg(global_umask_CFG, "umask", global_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_UMASK, vsn(1, 0, 0), NULL)
+cfg(global_test_CFG, "test", global_CFG_SECTION, 0, CFG_TYPE_BOOL, 0, vsn(1, 0, 0), NULL)
+cfg(global_units_CFG, "units", global_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_UNITS, vsn(1, 0, 0), NULL)
+cfg(global_si_unit_consistency_CFG, "si_unit_consistency", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_SI_UNIT_CONSISTENCY, vsn(2, 2, 54), NULL)
+cfg(global_activation_CFG, "activation", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_ACTIVATION, vsn(1, 0, 0), NULL)
+cfg(global_suffix_CFG, "suffix", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_SUFFIX, vsn(1, 0, 0), NULL)
+cfg(global_fallback_to_lvm1_CFG, "fallback_to_lvm1", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_FALLBACK_TO_LVM1, vsn(1, 0, 18), NULL)
+cfg(global_format_CFG, "format", global_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_FORMAT, vsn(1, 0, 0), NULL)
+cfg_array(global_format_libraries_CFG, "format_libraries", global_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+cfg_array(global_segment_libraries_CFG, "segment_libraries", global_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 0, 18), NULL)
+cfg(global_proc_CFG, "proc", global_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_PROC_DIR, vsn(1, 0, 0), NULL)
+cfg(global_locking_type_CFG, "locking_type", global_CFG_SECTION, 0, CFG_TYPE_INT, 1, vsn(1, 0, 0), NULL)
+cfg(global_wait_for_locks_CFG, "wait_for_locks", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_WAIT_FOR_LOCKS, vsn(2, 2, 50), NULL)
+cfg(global_fallback_to_clustered_locking_CFG, "fallback_to_clustered_locking", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_FALLBACK_TO_CLUSTERED_LOCKING, vsn(2, 2, 42), NULL)
+cfg(global_fallback_to_local_locking_CFG, "fallback_to_local_locking", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_FALLBACK_TO_LOCAL_LOCKING, vsn(2, 2, 42), NULL)
+cfg(global_locking_dir_CFG, "locking_dir", global_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_LOCK_DIR, vsn(1, 0, 0), NULL)
+cfg(global_prioritise_write_locks_CFG, "prioritise_write_locks", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_PRIORITISE_WRITE_LOCKS, vsn(2, 2, 52), NULL)
+cfg(global_library_dir_CFG, "library_dir", global_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+cfg(global_locking_library_CFG, "locking_library", global_CFG_SECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+cfg(global_abort_on_internal_errors_CFG, "abort_on_internal_errors", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_ABORT_ON_INTERNAL_ERRORS, vsn(2, 2, 57), NULL)
+cfg(global_detect_internal_vg_cache_corruption_CFG, "detect_internal_vg_cache_corruption", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_DETECT_INTERNAL_VG_CACHE_CORRUPTION, vsn(2, 2, 96), NULL)
+cfg(global_metadata_read_only_CFG, "metadata_read_only", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_METADATA_READ_ONLY, vsn(2, 2, 75), NULL)
+cfg(global_mirror_segtype_default_CFG, "mirror_segtype_default", global_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_MIRROR_SEGTYPE, vsn(2, 2, 87), NULL)
+cfg(global_raid10_segtype_default_CFG, "raid10_segtype_default", global_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_RAID10_SEGTYPE, vsn(2, 2, 99), NULL)
+cfg(global_lvdisplay_shows_full_device_path_CFG, "lvdisplay_shows_full_device_path", global_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_LVDISPLAY_SHOWS_FULL_DEVICE_PATH, vsn(2, 2, 89), NULL)
+cfg(global_use_lvmetad_CFG, "use_lvmetad", global_CFG_SECTION, 0, CFG_TYPE_BOOL, 0, vsn(2, 2, 93), NULL)
+cfg(global_thin_check_executable_CFG, "thin_check_executable", global_CFG_SECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, THIN_CHECK_CMD, vsn(2, 2, 94), NULL)
+cfg_array(global_thin_check_options_CFG, "thin_check_options", global_CFG_SECTION, 0, CFG_TYPE_STRING, "#S" DEFAULT_THIN_CHECK_OPTIONS, vsn(2, 2, 96), NULL)
+cfg_array(global_thin_disabled_features_CFG, "thin_disabled_features", global_CFG_SECTION, 0, CFG_TYPE_STRING, "#S", vsn(2, 2, 99), NULL)
+
+cfg(activation_checks_CFG, "checks", activation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_ACTIVATION_CHECKS, vsn(2, 2, 86), NULL)
+cfg(activation_udev_sync_CFG, "udev_sync", activation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_UDEV_SYNC, vsn(2, 2, 51), NULL)
+cfg(activation_udev_rules_CFG, "udev_rules", activation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_UDEV_RULES, vsn(2, 2, 57), NULL)
+cfg(activation_verify_udev_operations_CFG, "verify_udev_operations", activation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_VERIFY_UDEV_OPERATIONS, vsn(2, 2, 86), NULL)
+cfg(activation_retry_deactivation_CFG, "retry_deactivation", activation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_RETRY_DEACTIVATION, vsn(2, 2, 89), NULL)
+cfg(activation_missing_stripe_filler_CFG, "missing_stripe_filler", activation_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_STRIPE_FILLER, vsn(1, 0, 0), NULL)
+cfg(activation_use_linear_target_CFG, "use_linear_target", activation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_USE_LINEAR_TARGET, vsn(2, 2, 89), NULL)
+cfg(activation_reserved_stack_CFG, "reserved_stack", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_RESERVED_STACK, vsn(1, 0, 0), NULL)
+cfg(activation_reserved_memory_CFG, "reserved_memory", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_RESERVED_MEMORY, vsn(1, 0, 0), NULL)
+cfg(activation_process_priority_CFG, "process_priority", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_PROCESS_PRIORITY, vsn(1, 0, 0), NULL)
+cfg_array(activation_volume_list_CFG, "volume_list", activation_CFG_SECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, NULL, vsn(1, 0, 18), NULL)
+cfg_array(activation_auto_activation_volume_list_CFG, "auto_activation_volume_list", activation_CFG_SECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, NULL, vsn(2, 2, 97), NULL)
+cfg_array(activation_read_only_volume_list_CFG, "read_only_volume_list", activation_CFG_SECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, NULL, vsn(2, 2, 89), NULL)
+cfg(activation_mirror_region_size_CFG, "mirror_region_size", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_RAID_REGION_SIZE, vsn(1, 0, 0), NULL)
+cfg(activation_raid_region_size_CFG, "raid_region_size", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_RAID_REGION_SIZE, vsn(2, 2, 99), NULL)
+cfg(activation_readahead_CFG, "readahead", activation_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_READ_AHEAD, vsn(1, 0, 23), NULL)
+cfg(activation_raid_fault_policy_CFG, "raid_fault_policy", activation_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_RAID_FAULT_POLICY, vsn(2, 2, 89), NULL)
+cfg(activation_mirror_device_fault_policy_CFG, "mirror_device_fault_policy", activation_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_MIRROR_DEVICE_FAULT_POLICY, vsn(1, 2, 10), NULL)
+cfg(activation_mirror_log_fault_policy_CFG, "mirror_log_fault_policy", activation_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_MIRROR_LOG_FAULT_POLICY, vsn(1, 2, 18), NULL)
+cfg(activation_mirror_image_fault_policy_CFG, "mirror_image_fault_policy", activation_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(2, 2, 57), NULL)
+cfg(activation_snapshot_autoextend_threshold_CFG, "snapshot_autoextend_threshold", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_SNAPSHOT_AUTOEXTEND_THRESHOLD, vsn(2, 2, 75), NULL)
+cfg(activation_snapshot_autoextend_percent_CFG, "snapshot_autoextend_percent", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_SNAPSHOT_AUTOEXTEND_PERCENT, vsn(2, 2, 75), NULL)
+cfg(activation_thin_pool_autoextend_threshold_CFG, "thin_pool_autoextend_threshold", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_THIN_POOL_AUTOEXTEND_THRESHOLD, vsn(2, 2, 89), NULL)
+cfg(activation_thin_pool_autoextend_percent_CFG, "thin_pool_autoextend_percent", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_THIN_POOL_AUTOEXTEND_PERCENT, vsn(2, 2, 89), NULL)
+cfg_array(activation_mlock_filter_CFG, "mlock_filter", activation_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(2, 2, 62), NULL)
+cfg(activation_use_mlockall_CFG, "use_mlockall", activation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_USE_MLOCKALL, vsn(2, 2, 62), NULL)
+cfg(activation_monitoring_CFG, "monitoring", activation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_DMEVENTD_MONITOR, vsn(2, 2, 63), NULL)
+cfg(activation_polling_interval_CFG, "polling_interval", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_INTERVAL, vsn(2, 2, 63), NULL)
+
+cfg(metadata_pvmetadatacopies_CFG, "pvmetadatacopies", metadata_CFG_SECTION, CFG_ADVANCED, CFG_TYPE_INT, DEFAULT_PVMETADATACOPIES, vsn(1, 0, 0), NULL)
+cfg(metadata_vgmetadatacopies_CFG, "vgmetadatacopies", metadata_CFG_SECTION, CFG_ADVANCED, CFG_TYPE_INT, DEFAULT_VGMETADATACOPIES, vsn(2, 2, 69), NULL)
+cfg(metadata_pvmetadatasize_CFG, "pvmetadatasize", metadata_CFG_SECTION, CFG_ADVANCED, CFG_TYPE_INT, DEFAULT_PVMETADATASIZE, vsn(1, 0, 0), NULL)
+cfg(metadata_pvmetadataignore_CFG, "pvmetadataignore", metadata_CFG_SECTION, CFG_ADVANCED, CFG_TYPE_BOOL, DEFAULT_PVMETADATAIGNORE, vsn(2, 2, 69), NULL)
+cfg(metadata_stripesize_CFG, "stripesize", metadata_CFG_SECTION, CFG_ADVANCED, CFG_TYPE_INT, DEFAULT_STRIPESIZE, vsn(1, 0, 0), NULL)
+cfg_array(metadata_dirs_CFG, "dirs", metadata_CFG_SECTION, CFG_ADVANCED, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+cfg(metadata_disk_areas_CFG, "disk_areas", metadata_CFG_SECTION, CFG_ALLOW_EMPTY | CFG_ADVANCED | CFG_UNSUPPORTED, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
+
+cfg(report_aligned_CFG, "aligned", report_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_REP_ALIGNED, vsn(1, 0, 0), NULL)
+cfg(report_buffered_CFG, "buffered", report_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_REP_BUFFERED, vsn(1, 0, 0), NULL)
+cfg(report_headings_CFG, "headings", report_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_REP_HEADINGS, vsn(1, 0, 0), NULL)
+cfg(report_separator_CFG, "separator", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_REP_SEPARATOR, vsn(1, 0, 0), NULL)
+cfg(report_prefixes_CFG, "prefixes", report_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_REP_PREFIXES, vsn(2, 2, 36), NULL)
+cfg(report_quoted_CFG, "quoted", report_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_REP_QUOTED, vsn(2, 2, 39), NULL)
+cfg(report_colums_as_rows_CFG, "colums_as_rows", report_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_REP_COLUMNS_AS_ROWS, vsn(1, 0, 0), NULL)
+cfg(report_lvs_sort_CFG, "lvs_sort", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_LVS_SORT, vsn(1, 0, 0), NULL)
+cfg(report_lvs_cols_CFG, "lvs_cols", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_LVS_COLS, vsn(1, 0, 0), NULL)
+cfg(report_lvs_cols_verbose_CFG, "lvs_cols_verbose", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_LVS_COLS_VERB, vsn(1, 0, 0), NULL)
+cfg(report_vgs_sort_CFG, "vgs_sort", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_VGS_SORT, vsn(1, 0, 0), NULL)
+cfg(report_vgs_cols_CFG, "vgs_cols", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_VGS_COLS, vsn(1, 0, 0), NULL)
+cfg(report_vgs_cols_verbose_CFG, "vgs_cols_verbose", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_VGS_COLS_VERB, vsn(1, 0, 0), NULL)
+cfg(report_pvs_sort_CFG, "pvs_sort", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_PVS_SORT, vsn(1, 0, 0), NULL)
+cfg(report_pvs_cols_CFG, "pvs_cols", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_PVS_COLS, vsn(1, 0, 0), NULL)
+cfg(report_pvs_cols_verbose_CFG, "pvs_cols_verbose", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_PVS_COLS_VERB, vsn(1, 0, 0), NULL)
+cfg(report_segs_sort_CFG, "segs_sort", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_SEGS_SORT, vsn(1, 0, 0), NULL)
+cfg(report_segs_cols_CFG, "segs_cols", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_SEGS_COLS, vsn(1, 0, 0), NULL)
+cfg(report_segs_cols_verbose_CFG, "segs_cols_verbose", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_SEGS_COLS_VERB, vsn(1, 0, 0), NULL)
+cfg(report_pvsegs_sort_CFG, "pvsegs_sort", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_PVSEGS_SORT, vsn(1, 1, 3), NULL)
+cfg(report_pvsegs_cols_CFG, "pvsegs_cols", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_PVSEGS_COLS, vsn(1, 1, 3), NULL)
+cfg(report_pvsegs_cols_verbose_CFG, "pvsegs_cols_verbose", report_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_PVSEGS_COLS_VERB, vsn(1, 1, 3), NULL)
+
+cfg(dmeventd_mirror_library_CFG, "mirror_library", dmeventd_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_DMEVENTD_MIRROR_LIB, vsn(1, 2, 3), NULL)
+cfg(dmeventd_raid_library_CFG, "raid_library", dmeventd_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_DMEVENTD_RAID_LIB, vsn(2, 2, 87), NULL)
+cfg(dmeventd_snapshot_library_CFG, "snapshot_library", dmeventd_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_DMEVENTD_SNAPSHOT_LIB, vsn(1, 2, 26), NULL)
+cfg(dmeventd_thin_library_CFG, "thin_library", dmeventd_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_DMEVENTD_THIN_LIB, vsn(2, 2, 89), NULL)
+cfg(dmeventd_executable_CFG, "executable", dmeventd_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(2, 2, 73), NULL)
+
+cfg(tags_hosttags_CFG, "hosttags", tags_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_HOSTTAGS, vsn(1, 0, 18), NULL)
+
+cfg_section(tag_CFG_SUBSECTION, "tag", tags_CFG_SECTION, CFG_NAME_VARIABLE, vsn(1, 0, 18), NULL)
+cfg(tag_host_list_CFG, "host_list", tag_CFG_SUBSECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, NULL, vsn(1, 0, 18), NULL)
+
+cfg(CFG_COUNT, NULL, root_CFG_SECTION, 0, CFG_TYPE_INT, 0, vsn(0, 0, 0), NULL)
10 years, 9 months
master - config: add vsn macro
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6ea68f233c2196...
Commit: 6ea68f233c2196856fbc008e30b1eb17deb62701
Parent: 6c81cd26ccb03f3452fedca651c876f2709ff0b8
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Mar 5 16:39:36 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Mar 6 08:52:55 2013 +0100
config: add vsn macro
The 'vsn' macro encodes the LVM2 version major, minor
and patchlevel number in a packed form using 16 bits.
---
lib/config/config.h | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/lib/config/config.h b/lib/config/config.h
index 5c36f4d..079e9d1 100644
--- a/lib/config/config.h
+++ b/lib/config/config.h
@@ -18,6 +18,10 @@
#include "lvm-types.h"
+/* 16 bits: 3 bits for major, 4 bits for minor, 9 bits for patchlevel */
+/* Max LVM version supported: 7.15.511. Just extend bits if ever needed. */
+#define vsn(major, minor, patchlevel) (major << 13 | minor << 9 | patchlevel)
+
struct device;
struct cmd_context;
10 years, 9 months