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