mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
lvmconfig: add --valuesonly option
The new --valuesonly option causes the lvmconfig output to contain only values without keys for each config node. This is practical mainly in case where we use lvmconfig in scripts and we want to assign the value to a different custom key or simply output the value itself without the key. For example: # lvmconfig --type full activation/raid_fault_policy raid_fault_policy="warn" # lvmconfig --type full activation/raid_fault_policy --valuesonly "warn" # my_var=$(lvmconfig --type full activation/raid_fault_policy --valuesonly) # echo $my_var "warn"
This commit is contained in:
parent
81839cc4eb
commit
b4cc28c2ef
@ -1,5 +1,6 @@
|
|||||||
Version 2.03.17 -
|
Version 2.03.17 -
|
||||||
===============================
|
===============================
|
||||||
|
Add --valuesonly option to lvmconfig to print only values without keys.
|
||||||
Updates configure with recent autoconf tooling.
|
Updates configure with recent autoconf tooling.
|
||||||
Fix lvconvert --test --type vdo-pool execution.
|
Fix lvconvert --test --type vdo-pool execution.
|
||||||
Add json_std output format for more JSON standard compliant version of output.
|
Add json_std output format for more JSON standard compliant version of output.
|
||||||
|
@ -1830,8 +1830,10 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void
|
|||||||
char summary[MAX_COMMENT_LINE+1];
|
char summary[MAX_COMMENT_LINE+1];
|
||||||
char version[9];
|
char version[9];
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
size_t len;
|
int space_prefix_len;
|
||||||
char *space_prefix;
|
char *space_prefix;
|
||||||
|
const char *p;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
if ((out->tree_spec->type == CFG_DEF_TREE_DIFF) &&
|
if ((out->tree_spec->type == CFG_DEF_TREE_DIFF) &&
|
||||||
(!(out->tree_spec->check_status[cn->id] & CFG_DIFF)))
|
(!(out->tree_spec->check_status[cn->id] & CFG_DIFF)))
|
||||||
@ -1865,9 +1867,24 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void
|
|||||||
|
|
||||||
/* Usual tree view with nodes and their values. */
|
/* Usual tree view with nodes and their values. */
|
||||||
|
|
||||||
|
if (out->tree_spec->valuesonly && !(cfg_def->type & CFG_TYPE_SECTION)) {
|
||||||
|
if ((space_prefix_len = strspn(line, "\t "))) {
|
||||||
|
len = strlen(line);
|
||||||
|
p = line + space_prefix_len;
|
||||||
|
|
||||||
|
/* copy space_prefix, skip key and '=', copy value */
|
||||||
|
dm_pool_begin_object(out->mem, len);
|
||||||
|
dm_pool_grow_object(out->mem, line, space_prefix_len);
|
||||||
|
dm_pool_grow_object(out->mem, p + strcspn(p, "=") + 1, len + 1);
|
||||||
|
line = dm_pool_end_object(out->mem);
|
||||||
|
} else
|
||||||
|
line = strchr(line, '=') + 1;
|
||||||
|
}
|
||||||
|
|
||||||
if ((out->tree_spec->type != CFG_DEF_TREE_CURRENT) &&
|
if ((out->tree_spec->type != CFG_DEF_TREE_CURRENT) &&
|
||||||
(out->tree_spec->type != CFG_DEF_TREE_DIFF) &&
|
(out->tree_spec->type != CFG_DEF_TREE_DIFF) &&
|
||||||
(out->tree_spec->type != CFG_DEF_TREE_FULL) &&
|
(out->tree_spec->type != CFG_DEF_TREE_FULL) &&
|
||||||
|
!out->tree_spec->valuesonly &&
|
||||||
(cfg_def->flags & (CFG_DEFAULT_UNDEFINED | CFG_DEFAULT_COMMENTED))) {
|
(cfg_def->flags & (CFG_DEFAULT_UNDEFINED | CFG_DEFAULT_COMMENTED))) {
|
||||||
/* print with # at the front to comment out the line */
|
/* print with # at the front to comment out the line */
|
||||||
if (_should_print_cfg_with_undef_def_val(out, cfg_def, cn)) {
|
if (_should_print_cfg_with_undef_def_val(out, cfg_def, cn)) {
|
||||||
@ -1883,6 +1900,9 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void
|
|||||||
if (_should_print_cfg_with_undef_def_val(out, cfg_def, cn))
|
if (_should_print_cfg_with_undef_def_val(out, cfg_def, cn))
|
||||||
fprintf(out->fp, "%s\n", line);
|
fprintf(out->fp, "%s\n", line);
|
||||||
|
|
||||||
|
if (out->tree_spec->valuesonly && !(cfg_def->type & CFG_TYPE_SECTION) && space_prefix_len)
|
||||||
|
dm_pool_free(out->mem, (char *) line);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +176,7 @@ struct config_def_tree_spec {
|
|||||||
unsigned unconfigured:1; /* use unconfigured path strings */
|
unsigned unconfigured:1; /* use unconfigured path strings */
|
||||||
unsigned withgeneralpreamble:1; /* include preamble for a general config file */
|
unsigned withgeneralpreamble:1; /* include preamble for a general config file */
|
||||||
unsigned withlocalpreamble:1; /* include preamble for a local config file */
|
unsigned withlocalpreamble:1; /* include preamble for a local config file */
|
||||||
|
unsigned valuesonly:1; /* print only values without keys */
|
||||||
uint8_t *check_status; /* status of last tree check (currently needed for CFG_DEF_TREE_MISSING only) */
|
uint8_t *check_status; /* status of last tree check (currently needed for CFG_DEF_TREE_MISSING only) */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ line settings from --config.
|
|||||||
.br
|
.br
|
||||||
[ \fB--validate\fP ]
|
[ \fB--validate\fP ]
|
||||||
.br
|
.br
|
||||||
|
[ \fB--valuesonly\fP ]
|
||||||
|
.br
|
||||||
[ \fB--withsummary\fP ]
|
[ \fB--withsummary\fP ]
|
||||||
.br
|
.br
|
||||||
[ \fB--withcomments\fP ]
|
[ \fB--withcomments\fP ]
|
||||||
@ -369,6 +371,11 @@ merged configuration tree, also use --mergedconfig.
|
|||||||
The validation is done even if \fBlvm.conf\fP(5) \fBconfig/checks\fP is disabled.
|
The validation is done even if \fBlvm.conf\fP(5) \fBconfig/checks\fP is disabled.
|
||||||
.
|
.
|
||||||
.HP
|
.HP
|
||||||
|
\fB--valuesonly\fP
|
||||||
|
.br
|
||||||
|
When printing config settings, print only values without keys.
|
||||||
|
.
|
||||||
|
.HP
|
||||||
\fB-v\fP|\fB--verbose\fP ...
|
\fB-v\fP|\fB--verbose\fP ...
|
||||||
.br
|
.br
|
||||||
Set verbose level. Repeat from 1 to 4 times to increase the detail
|
Set verbose level. Repeat from 1 to 4 times to increase the detail
|
||||||
|
@ -905,6 +905,9 @@ arg(validate_ARG, '\0', "validate", 0, 0, 0,
|
|||||||
"merged configuration tree, also use --mergedconfig.\n"
|
"merged configuration tree, also use --mergedconfig.\n"
|
||||||
"The validation is done even if \\fBlvm.conf\\fP(5) \\fBconfig/checks\\fP is disabled.\n")
|
"The validation is done even if \\fBlvm.conf\\fP(5) \\fBconfig/checks\\fP is disabled.\n")
|
||||||
|
|
||||||
|
arg(valuesonly_ARG, '\0', "valuesonly", 0, 0, 0,
|
||||||
|
"When printing config settings, print only values without keys.\n")
|
||||||
|
|
||||||
arg(vdo_ARG, '\0', "vdo", 0, 0, 0,
|
arg(vdo_ARG, '\0', "vdo", 0, 0, 0,
|
||||||
"Specifies the command is handling VDO LV.\n"
|
"Specifies the command is handling VDO LV.\n"
|
||||||
"See --type vdo.\n"
|
"See --type vdo.\n"
|
||||||
|
@ -221,8 +221,9 @@ OO_REPORT: --aligned, --all, --binary, --configreport ConfigReport, --foreign,
|
|||||||
#
|
#
|
||||||
OO_CONFIG: --atversion String, --typeconfig ConfigType, --file String, --ignoreadvanced,
|
OO_CONFIG: --atversion String, --typeconfig ConfigType, --file String, --ignoreadvanced,
|
||||||
--ignoreunsupported, --ignorelocal, --list, --mergedconfig, --metadataprofile String,
|
--ignoreunsupported, --ignorelocal, --list, --mergedconfig, --metadataprofile String,
|
||||||
--sinceversion String, --showdeprecated, --showunsupported, --validate, --withsummary,
|
--sinceversion String, --showdeprecated, --showunsupported, --validate, --valuesonly,
|
||||||
--withcomments, --withgeneralpreamble, --withlocalpreamble, --withspaces, --unconfigured, --withversions
|
--withsummary, --withcomments, --withgeneralpreamble, --withlocalpreamble, --withspaces,
|
||||||
|
--unconfigured, --withversions
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -242,6 +242,10 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
log_error("--withgeneralpreamble has no effect with --type list");
|
log_error("--withgeneralpreamble has no effect with --type list");
|
||||||
return EINVALID_CMD_LINE;
|
return EINVALID_CMD_LINE;
|
||||||
}
|
}
|
||||||
|
if (arg_is_set(cmd, valuesonly_ARG)) {
|
||||||
|
log_err("--valuesonly has no effect with --type list");
|
||||||
|
return EINVALID_CMD_LINE;
|
||||||
|
}
|
||||||
/* list type does not require status check */
|
/* list type does not require status check */
|
||||||
} else if (!strcmp(type, "full")) {
|
} else if (!strcmp(type, "full")) {
|
||||||
tree_spec.type = CFG_DEF_TREE_FULL;
|
tree_spec.type = CFG_DEF_TREE_FULL;
|
||||||
@ -320,6 +324,9 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
if (arg_is_set(cmd, withspaces_ARG))
|
if (arg_is_set(cmd, withspaces_ARG))
|
||||||
tree_spec.withspaces = 1;
|
tree_spec.withspaces = 1;
|
||||||
|
|
||||||
|
if (arg_is_set(cmd, valuesonly_ARG))
|
||||||
|
tree_spec.valuesonly = 1;
|
||||||
|
|
||||||
if (cft_check_handle)
|
if (cft_check_handle)
|
||||||
tree_spec.check_status = cft_check_handle->status;
|
tree_spec.check_status = cft_check_handle->status;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user