diff options
author | Peter Rajnoha <prajnoha@redhat.com> | 2013-03-05 17:48:29 +0100 |
---|---|---|
committer | Peter Rajnoha <prajnoha@redhat.com> | 2013-03-06 10:46:36 +0100 |
commit | 34350963d1b02d54205b1bdaa0c7778f4c5601fe (patch) | |
tree | b9322a603af832b86bdbfb6d521823e555ef99f5 /tools/dumpconfig.c | |
parent | 245b85692ec9f30153c1aa7216d81e65bb132792 (diff) | |
download | lvm2-34350963d1b02d54205b1bdaa0c7778f4c5601fe.tar.gz |
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"
Diffstat (limited to 'tools/dumpconfig.c')
-rw-r--r-- | tools/dumpconfig.c | 80 |
1 files changed, 77 insertions, 3 deletions
diff --git a/tools/dumpconfig.c b/tools/dumpconfig.c index c5f522652..ac90a95c3 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; } |