1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

dumpconfig: add dumpconfig --type diff to show differences from defaults

This commit is contained in:
Peter Rajnoha 2014-03-24 13:19:15 +01:00
parent 76ff38fa5c
commit 5dcec1734e
5 changed files with 31 additions and 7 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.106 -
====================================
Add 'lvm dumpconfig --type diff' to show differences from defaults.
Fix swap signature detection for devices smaller then 2MB.
Reindent some clvmd.c code.
Use dm_malloc function in clvmd.c.

View File

@ -1283,6 +1283,10 @@ static int _out_prefix_fn(const struct dm_config_node *cn, const char *line, voi
return 0;
}
if ((out->tree_spec->type == CFG_DEF_TREE_DIFF) &&
(!(out->tree_spec->check_status[cn->id] & CFG_DIFF)))
return 1;
cfg_def = cfg_def_get_item_p(cn->id);
if (out->tree_spec->withcomments) {
@ -1324,7 +1328,12 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void
struct out_baton *out = baton;
struct cfg_def_item *cfg_def = cfg_def_get_item_p(cn->id);
if ((out->tree_spec->type == CFG_DEF_TREE_DIFF) &&
(!(out->tree_spec->check_status[cn->id] & CFG_DIFF)))
return 1;
fprintf(out->fp, "%s%s\n", (out->tree_spec->type != CFG_DEF_TREE_CURRENT) &&
(out->tree_spec->type != CFG_DEF_TREE_DIFF) &&
(cfg_def->flags & CFG_DEFAULT_UNDEFINED) ? "#" : "", line);
return 1;
}

View File

@ -121,7 +121,8 @@ typedef enum {
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_PROFILABLE /* tree of all nodes that are customizable by profiles */
CFG_DEF_TREE_PROFILABLE, /* tree of all nodes that are customizable by profiles */
CFG_DEF_TREE_DIFF, /* tree of all nodes that differ from defaults */
} cfg_def_tree_t;
/* configuration definition tree specification */

View File

@ -57,7 +57,7 @@ xx(dumpconfig,
PERMITTED_READ_ONLY,
"dumpconfig\n"
"\t[-f|--file filename] \n"
"\t[--type {current|default|missing|new|profilable} \n"
"\t[--type {current|default|diff|missing|new|profilable} \n"
"\t[--atversion version]] \n"
"\t[--ignoreadvanced] \n"
"\t[--ignoreunsupported] \n"

View File

@ -56,18 +56,23 @@ static struct cft_check_handle *_get_cft_check_handle(struct cmd_context *cmd, s
return handle;
}
static int _do_def_check(struct cmd_context *cmd, struct dm_config_tree *cft,
static int _do_def_check(struct config_def_tree_spec *spec,
struct dm_config_tree *cft,
struct cft_check_handle **cft_check_handle)
{
struct cft_check_handle *handle;
if (!(handle = _get_cft_check_handle(cmd, cft)))
if (!(handle = _get_cft_check_handle(spec->cmd, cft)))
return 0;
handle->force_check = 1;
handle->skip_if_checked = 1;
handle->suppress_messages = 1;
if (spec->type == CFG_DEF_TREE_DIFF)
handle->check_diff = 1;
else
handle->skip_if_checked = 1;
config_def_check(handle);
*cft_check_handle = handle;
@ -168,14 +173,14 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
if (!strcmp(type, "current")) {
tree_spec.type = CFG_DEF_TREE_CURRENT;
if (!_do_def_check(cmd, cft, &cft_check_handle)) {
if (!_do_def_check(&tree_spec, cft, &cft_check_handle)) {
r = ECMD_FAILED;
goto_out;
}
}
else if (!strcmp(type, "missing")) {
tree_spec.type = CFG_DEF_TREE_MISSING;
if (!_do_def_check(cmd, cft, &cft_check_handle)) {
if (!_do_def_check(&tree_spec, cft, &cft_check_handle)) {
r = ECMD_FAILED;
goto_out;
}
@ -184,6 +189,13 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
tree_spec.type = CFG_DEF_TREE_DEFAULT;
/* default type does not require check status */
}
else if (!strcmp(type, "diff")) {
tree_spec.type = CFG_DEF_TREE_DIFF;
if (!_do_def_check(&tree_spec, cft, &cft_check_handle)) {
r = ECMD_FAILED;
goto_out;
}
}
else if (!strcmp(type, "new")) {
tree_spec.type = CFG_DEF_TREE_NEW;
/* new type does not require check status */
@ -209,6 +221,7 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
tree_spec.check_status = cft_check_handle->status;
if ((tree_spec.type != CFG_DEF_TREE_CURRENT) &&
(tree_spec.type != CFG_DEF_TREE_DIFF) &&
!(cft = config_def_create_tree(&tree_spec))) {
r = ECMD_FAILED;
goto_out;