mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
cleanup: cleanup dumpconfig code
This commit is contained in:
parent
985251c8f3
commit
f5584d4203
@ -15,19 +15,17 @@
|
||||
|
||||
#include "tools.h"
|
||||
|
||||
static int _get_vsn(struct cmd_context *cmd, unsigned int *major,
|
||||
unsigned int *minor, unsigned int *patchlevel)
|
||||
static int _get_vsn(struct cmd_context *cmd, uint16_t *version)
|
||||
{
|
||||
const char *atversion = arg_str_value(cmd, atversion_ARG, NULL);
|
||||
const char *atversion = arg_str_value(cmd, atversion_ARG, LVM_VERSION);
|
||||
unsigned int major, minor, patchlevel;
|
||||
|
||||
if (!atversion)
|
||||
atversion = LVM_VERSION;
|
||||
|
||||
if (sscanf(atversion, "%u.%u.%u", major, minor, patchlevel) != 3) {
|
||||
if (sscanf(atversion, "%u.%u.%u", &major, &minor, &patchlevel) != 3) {
|
||||
log_error("Incorrect version format.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
*version = vsn(major, minor, patchlevel);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -51,9 +49,8 @@ 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 = cmd->cft;
|
||||
struct dm_config_tree *cft = NULL;
|
||||
struct cft_check_handle *cft_check_handle;
|
||||
int r = ECMD_PROCESSED;
|
||||
|
||||
@ -73,6 +70,22 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
|
||||
if (arg_count(cmd, ignoreunsupported_ARG))
|
||||
tree_spec.ignoreunsupported = 1;
|
||||
|
||||
if (!strcmp(type, "current")) {
|
||||
if (arg_count(cmd, atversion_ARG)) {
|
||||
log_error("--atversion has no effect with --type current");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
|
||||
if ((tree_spec.ignoreadvanced || tree_spec.ignoreunsupported)) {
|
||||
log_error("--ignoreadvanced and --ignoreunsupported has "
|
||||
"no effect with --type current");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_get_vsn(cmd, &tree_spec.version))
|
||||
return EINVALID_CMD_LINE;
|
||||
|
||||
if (arg_count(cmd, validate_ARG)) {
|
||||
if (!(cft_check_handle = _get_cft_check_handle(cmd)))
|
||||
return ECMD_FAILED;
|
||||
@ -91,10 +104,6 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
|
||||
}
|
||||
|
||||
if (!strcmp(type, "current")) {
|
||||
if (arg_count(cmd, atversion_ARG)) {
|
||||
log_error("--atversion has no effect with --type current");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
tree_spec.type = CFG_DEF_TREE_CURRENT;
|
||||
|
||||
if (!(cft_check_handle = _get_cft_check_handle(cmd)))
|
||||
@ -119,18 +128,10 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
|
||||
if ((tree_spec.ignoreadvanced || tree_spec.ignoreunsupported) &&
|
||||
(tree_spec.type == CFG_DEF_TREE_CURRENT)) {
|
||||
log_error("--ignoreadvanced and --ignoreunsupported has no effect with --type current");
|
||||
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);
|
||||
if (tree_spec.type == CFG_DEF_TREE_CURRENT)
|
||||
cft = cmd->cft;
|
||||
else
|
||||
cft = config_def_create_tree(&tree_spec);
|
||||
}
|
||||
|
||||
if (!config_write(cft, arg_count(cmd, withcomments_ARG),
|
||||
arg_count(cmd, withversions_ARG),
|
||||
@ -139,9 +140,13 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
|
||||
r = ECMD_FAILED;
|
||||
}
|
||||
|
||||
/* cmd->cft (the "current" tree) is destroyed with cmd context destroy! */
|
||||
if (tree_spec.type != CFG_DEF_TREE_CURRENT && cft)
|
||||
if (cft != cmd->cft)
|
||||
dm_pool_destroy(cft->mem);
|
||||
|
||||
/*
|
||||
* The cmd->cft (the "current" tree) is destroyed
|
||||
* together with cmd context destroy...
|
||||
*/
|
||||
|
||||
return r;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user