summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2016-05-26 15:50:52 +0200
committerPeter Rajnoha <prajnoha@redhat.com>2016-06-02 14:08:12 +0200
commit2df4fa4c9c8b0e992c5044bb0bd532a8a24bbc70 (patch)
tree4c0071d5dbaa2cbb43ee6755b891cbad37b3bbdc
parent5fa495eeb1de0c236e8150adc8b99f1ca5077ee4 (diff)
downloadlvm2-2df4fa4c9c8b0e992c5044bb0bd532a8a24bbc70.tar.gz
report: add _get_report_idx and _should_process_report_idx helper fns
-rw-r--r--tools/reporter.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/reporter.c b/tools/reporter.c
index f74279a59..7a7eb36f7 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -720,6 +720,62 @@ static void _del_option_from_list(struct dm_list *sll, const char *prefix,
}
}
+static report_idx_t _get_report_idx_from_name(const char *name, size_t len)
+{
+ report_idx_t idx = REPORT_IDX_NULL;
+
+ if (!strncasecmp(name, "status", len))
+ idx = REPORT_IDX_STATUS;
+ else if (!strncasecmp(name, "vg", len))
+ idx = REPORT_IDX_FULL_VGS;
+ else if (!strncasecmp(name, "pv", len))
+ idx = REPORT_IDX_FULL_PVS;
+ else if (!strncasecmp(name, "lv", len))
+ idx = REPORT_IDX_FULL_LVS;
+ else if (!strncasecmp(name, "pvseg", len))
+ idx = REPORT_IDX_FULL_PVSEGS;
+ else if (!strncasecmp(name, "seg", len))
+ idx = REPORT_IDX_FULL_SEGS;
+ else
+ log_error("Unknonwn report specifier in "
+ "report option list: %s.", name);
+
+ return idx;
+}
+
+static const char *_get_report_idx(const char *opts, report_idx_t *idx)
+{
+ char *p;
+
+ if (*opts != '/') {
+ *idx = REPORT_IDX_SINGLE;
+ return opts;
+ }
+
+ opts++;
+ if (!(p = strchr(opts, '/'))) {
+ log_error("Unfinished report specifier in "
+ "report options list: %s.", opts);
+ *idx = -1;
+ return NULL;
+ }
+
+ if ((*idx = _get_report_idx_from_name(opts, p - opts)) == -1)
+ return_NULL;
+
+ return p + 1;
+}
+
+static int _should_process_report_idx(report_type_t report_type, report_idx_t idx)
+{
+ if (((idx == REPORT_IDX_STATUS) && (report_type != CMDSTATUS)) ||
+ ((idx == REPORT_IDX_SINGLE) && ((report_type == FULL) || (report_type == CMDSTATUS))) ||
+ ((idx > REPORT_IDX_STATUS) && report_type != FULL))
+ return 0;
+
+ return 1;
+}
+
static int _get_report_options(struct cmd_context *cmd,
struct report_args *args,
struct single_report_args *single_args)