summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2014-04-25 11:48:59 +0200
committerPeter Rajnoha <prajnoha@redhat.com>2014-04-25 11:48:59 +0200
commit862c2a73ad04b6c57b376a9582344f918e3e81c1 (patch)
tree11d669d27cd1c51617c651673dbf9652618f5904
parenta95f07ec740461c21ab3be87b1c567e40bf9d08b (diff)
downloadlvm2-862c2a73ad04b6c57b376a9582344f918e3e81c1.tar.gz
condout: add --condition arg to pvs, vgs and lvs
-rw-r--r--lib/report/report.c13
-rw-r--r--lib/report/report.h2
-rw-r--r--tools/args.h1
-rw-r--r--tools/commands.h28
-rw-r--r--tools/reporter.c7
5 files changed, 32 insertions, 19 deletions
diff --git a/lib/report/report.c b/lib/report/report.c
index 7a51c815c..e18994cf0 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -1234,7 +1234,7 @@ static const struct dm_report_field_type _devtypes_fields[] = {
void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
report_type_t *report_type, const char *separator,
int aligned, int buffered, int headings, int field_prefixes,
- int quoted, int columns_as_rows)
+ int quoted, int columns_as_rows, const char *condition)
{
uint32_t report_flags = 0;
int devtypes_report = *report_type & DEVTYPES ? 1 : 0;
@@ -1262,8 +1262,15 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
devtypes_report ? _devtypes_fields : _fields, format,
separator, report_flags, keys, cmd);
- if (rh && field_prefixes)
- dm_report_set_output_field_name_prefix(rh, "lvm2_");
+ if (rh) {
+ if (field_prefixes)
+ dm_report_set_output_field_name_prefix(rh, "lvm2_");
+
+ if (condition && !dm_report_set_output_condition(rh, condition)) {
+ dm_report_free(rh);
+ rh = NULL;
+ }
+ }
return rh;
}
diff --git a/lib/report/report.h b/lib/report/report.h
index 2c093b0cd..d4c5729c0 100644
--- a/lib/report/report.h
+++ b/lib/report/report.h
@@ -38,7 +38,7 @@ typedef int (*field_report_fn) (struct report_handle * dh, struct field * field,
void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
report_type_t *report_type, const char *separator,
int aligned, int buffered, int headings, int field_prefixes,
- int quoted, int columns_as_rows);
+ int quoted, int columns_as_rows, const char *condition);
void report_free(void *handle);
int report_object(void *handle, struct volume_group *vg,
struct logical_volume *lv, struct physical_volume *pv,
diff --git a/tools/args.h b/tools/args.h
index 2e63adbf6..46715ccb2 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -105,6 +105,7 @@ arg(mergedconfig_ARG, '\0', "mergedconfig", NULL, 0)
arg(ignoreskippedcluster_ARG, '\0', "ignoreskippedcluster", NULL, 0)
arg(splitsnapshot_ARG, '\0', "splitsnapshot", NULL, 0)
arg(readonly_ARG, '\0', "readonly", NULL, 0)
+arg(condition_ARG, '\0', "condition", string_arg, 0)
/* Allow some variations */
arg(resizable_ARG, '\0', "resizable", yes_no_arg, 0)
diff --git a/tools/commands.h b/tools/commands.h
index 21a2075a8..3e1e30ea7 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -532,6 +532,7 @@ xx(lvs,
"lvs" "\n"
"\t[-a|--all]\n"
"\t[--aligned]\n"
+ "\t[--condition Condition]\n"
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
@@ -554,10 +555,9 @@ xx(lvs,
"\t[--version]" "\n"
"\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
- aligned_ARG, all_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG,
- nameprefixes_ARG,
- noheadings_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG,
- readonly_ARG,
+ aligned_ARG, all_ARG, condition_ARG, ignorelockingfailure_ARG,
+ ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG,
+ nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG,
rows_ARG, segments_ARG, separator_ARG, sort_ARG, trustcache_ARG,
unbuffered_ARG, units_ARG, unquoted_ARG)
@@ -763,6 +763,7 @@ xx(pvs,
"pvs" "\n"
"\t[-a|--all]\n"
"\t[--aligned]\n"
+ "\t[--condition Condition]\n"
"\t[-d|--debug]" "\n"
"\t[-h|-?|--help] " "\n"
"\t[--ignorelockingfailure]\n"
@@ -785,10 +786,11 @@ xx(pvs,
"\t[--version]\n"
"\t[PhysicalVolume [PhysicalVolume...]]\n",
- aligned_ARG, all_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG,
- nameprefixes_ARG, noheadings_ARG, nolocking_ARG, nosuffix_ARG, options_ARG,
- partial_ARG, readonly_ARG, rows_ARG, segments_ARG, separator_ARG, sort_ARG,
- trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG)
+ aligned_ARG, all_ARG, condition_ARG, ignorelockingfailure_ARG,
+ ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG,
+ nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, rows_ARG,
+ segments_ARG, separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG,
+ units_ARG, unquoted_ARG)
xx(pvscan,
"List all physical volumes",
@@ -1132,6 +1134,7 @@ xx(vgs,
"vgs" "\n"
"\t[--aligned]\n"
"\t[-a|--all]\n"
+ "\t[--condition Condition]\n"
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
@@ -1153,11 +1156,10 @@ xx(vgs,
"\t[--version]\n"
"\t[VolumeGroupName [VolumeGroupName...]]\n",
- aligned_ARG, all_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG,
- nameprefixes_ARG,
- noheadings_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG,
- readonly_ARG,
- rows_ARG, separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG,
+ aligned_ARG, all_ARG, condition_ARG, ignorelockingfailure_ARG,
+ ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG,
+ nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, rows_ARG,
+ separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG,
unquoted_ARG)
xx(vgscan,
diff --git a/tools/reporter.c b/tools/reporter.c
index 2591fd5b2..bd3f7b8f9 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -253,7 +253,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
void *report_handle;
const char *opts;
char *str;
- const char *keys = NULL, *options = NULL, *separator;
+ const char *keys = NULL, *options = NULL, *condition = NULL, *separator;
int r = ECMD_PROCESSED;
int aligned, buffered, headings, field_prefixes, quoted;
int columns_as_rows;
@@ -366,10 +366,13 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
if (arg_count(cmd, rows_ARG))
columns_as_rows = 1;
+ if (arg_count(cmd, condition_ARG))
+ condition = arg_str_value(cmd, condition_ARG, NULL);
+
if (!(report_handle = report_init(cmd, options, keys, &report_type,
separator, aligned, buffered,
headings, field_prefixes, quoted,
- columns_as_rows))) {
+ columns_as_rows, condition))) {
if (!strcasecmp(options, "help") || !strcmp(options, "?"))
return r;
return_ECMD_FAILED;