[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] [PATCH] LVM2: (2/2) Use dm_report filter



Hi,

This patch adds '--filter' option to reporting commands: lvs, vgs and pvs.

The patch depends on the following patches:
[PATCH] libdevmapper: (4/6) Add filtering feature to dm_report
https://www.redhat.com/archives/dm-devel/2007-April/msg00029.html
[PATCH] libdevmapper: (7/6) Add dm_report_get_report_types()
https://www.redhat.com/archives/dm-devel/2007-April/msg00035.html

Examples:

Find PVs used for VG vg0
# pvs --filter 'vg_name == "vg0"'

Find PVs not used by any LVs
# pvs --filter 'used == 0'

Find PVs satisfying both of the aboves
# pvs --filter 'vg_name == "vg0" && used == 0'

Find PVs not satisfying the above
# pvs --filter '! (vg_name == "vg0" && used == 0)'

Find VGs with more than 2 PVs and with more than 400 extents
# vgs --filter 'pv_count > 2 && free_count > 400'

Find active snapshot LVs
# lvs --filter 'attr =~ /^s...a/'

Find LVs using /dev/sdc
# lvs --filter 'devices =~ |/dev/sdc|'

..

Possible future enhancements:
  - Cope with units.
    I.e. lvs --filter 'size > 4G' to find LVs larger than 4GB
    Currently, the filter can handle only the raw value of the field.

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America
Add --filter/-F option to utilize dm_report's filtering feature.

---
 lib/report/report.c |   18 +++++++++++++++---
 lib/report/report.h |    2 +-
 man/lvs.8           |    2 +-
 man/pvs.8           |    2 +-
 man/vgs.8           |    2 +-
 tools/args.h        |    1 +
 tools/commands.h    |    9 ++++++---
 tools/reporter.c    |    7 +++++--
 8 files changed, 31 insertions(+), 12 deletions(-)

Index: LVM2.work/lib/report/report.c
===================================================================
--- LVM2.work.orig/lib/report/report.c
+++ LVM2.work/lib/report/report.c
@@ -881,9 +881,10 @@ static struct dm_report_field_type _fiel
 
 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 aligned, int buffered, int headings, const char *filters)
 {
 	uint32_t report_flags = 0;
+	struct dm_report *rh;
 
 	if (aligned)
 		report_flags |= DM_REPORT_OUTPUT_ALIGNED;
@@ -894,8 +895,19 @@ void *report_init(struct cmd_context *cm
 	if (headings)
 		report_flags |= DM_REPORT_OUTPUT_HEADINGS;
 
-        return dm_report_init(report_type, _report_types, _fields, format,
-			      separator, report_flags, keys, cmd);
+        rh = dm_report_init(report_type, _report_types, _fields, format,
+			    separator, report_flags, keys, cmd);
+
+	if (rh && filters) {
+		if (!dm_report_set_filter(rh, filters, 0)) {
+			dm_report_free(rh);
+			rh = NULL;
+		}
+		if (report_type)
+			*report_type = dm_report_get_report_types(rh);
+	}
+
+	return rh;
 }
 
 /*
Index: LVM2.work/tools/args.h
===================================================================
--- LVM2.work.orig/tools/args.h
+++ LVM2.work/tools/args.h
@@ -51,6 +51,7 @@ arg(corelog_ARG, '\0', "corelog", NULL)
 arg(monitor_ARG, '\0', "monitor", yes_no_arg)
 arg(config_ARG, '\0', "config", string_arg)
 arg(trustcache_ARG, '\0', "trustcache", NULL)
+arg(filter_ARG, '\0', "filter", string_arg)
 
 /* Allow some variations */
 arg(resizable_ARG, '\0', "resizable", yes_no_arg)
Index: LVM2.work/tools/commands.h
===================================================================
--- LVM2.work.orig/tools/commands.h
+++ LVM2.work/tools/commands.h
@@ -341,6 +341,7 @@ xx(lvs,
    "\t[-a|--all]\n"
    "\t[--aligned]\n"
    "\t[-d|--debug]\n"
+   "\t[--filter Filter]\n"
    "\t[-h|--help]\n"
    "\t[--ignorelockingfailure]\n"
    "\t[--noheadings]\n"
@@ -357,7 +358,7 @@ xx(lvs,
    "\t[--version]" "\n"
    "\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
 
-   aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
+   aligned_ARG, all_ARG, filter_ARG, ignorelockingfailure_ARG, noheadings_ARG,
    nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, segments_ARG,
    separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG)
 
@@ -535,6 +536,7 @@ xx(pvs,
    "\t[--aligned]\n"
    "\t[-a|--all]\n"
    "\t[-d|--debug]" "\n"
+   "\t[--filter Filter]\n"
    "\t[-h|-?|--help] " "\n"
    "\t[--noheadings]\n"
    "\t[--ignorelockingfailure]\n"
@@ -551,7 +553,7 @@ xx(pvs,
    "\t[--version]\n"
    "\t[PhysicalVolume [PhysicalVolume...]]\n",
 
-   aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
+   aligned_ARG, all_ARG, filter_ARG, ignorelockingfailure_ARG, noheadings_ARG,
    nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, segments_ARG,
    separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG)
 
@@ -830,6 +832,7 @@ xx(vgs,
    "\t[--aligned]\n"
    "\t[-a|--all]\n"
    "\t[-d|--debug]\n"
+   "\t[--filter Filter]\n"
    "\t[-h|--help]\n"
    "\t[--ignorelockingfailure]\n"
    "\t[--noheadings]\n"
@@ -845,7 +848,7 @@ xx(vgs,
    "\t[--version]\n"
    "\t[VolumeGroupName [VolumeGroupName...]]\n",
 
-   aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
+   aligned_ARG, all_ARG, filter_ARG, ignorelockingfailure_ARG, noheadings_ARG,
    nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, separator_ARG,
    sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG)
 
Index: LVM2.work/tools/reporter.c
===================================================================
--- LVM2.work.orig/tools/reporter.c
+++ LVM2.work/tools/reporter.c
@@ -168,7 +168,7 @@ static int _report(struct cmd_context *c
 	void *report_handle;
 	const char *opts;
 	char *str;
-	const char *keys = NULL, *options = NULL, *separator;
+	const char *keys = NULL, *options = NULL, *filters = NULL, *separator;
 	int r = ECMD_PROCESSED;
 	int aligned, buffered, headings;
 	unsigned args_are_pvs;
@@ -283,9 +283,12 @@ static int _report(struct cmd_context *c
 	if (arg_count(cmd, noheadings_ARG))
 		headings = 0;
 
+	if (arg_count(cmd, filter_ARG))
+		filters = arg_str_value(cmd, filter_ARG, "");
+
 	if (!(report_handle = report_init(cmd, options, keys, &report_type,
 					  separator, aligned, buffered,
-					  headings)))
+					  headings, filters)))
 		return_0;
 
 	/* Ensure options selected are compatible */
Index: LVM2.work/lib/report/report.h
===================================================================
--- LVM2.work.orig/lib/report/report.h
+++ LVM2.work/lib/report/report.h
@@ -28,7 +28,7 @@ typedef int (*field_report_fn) (struct r
 
 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 aligned, int buffered, int headings, const char *fitlers);
 void report_free(void *handle);
 int report_object(void *handle, struct volume_group *vg,
 		  struct logical_volume *lv, struct physical_volume *pv,
Index: LVM2.work/man/lvs.8
===================================================================
--- LVM2.work.orig/man/lvs.8
+++ LVM2.work/man/lvs.8
@@ -3,7 +3,7 @@
 lvs \- report information about logical volumes
 .SH SYNOPSIS
 .B lvs
-[\-\-aligned] [\-d/\-\-debug] [\-h/\-?/\-\-help]
+[\-\-aligned] [\-d/\-\-debug] [\-\-filter Filter] [\-h/\-?/\-\-help]
 [\-\-ignorelockingfailure] [\-\-noheadings] [\-\-nosuffix]
 [\-o/\-\-options [+]Field[,Field]]
 [\-O/\-\-sort [+/-]Key1[,[+/-]Key2[,...]]]
Index: LVM2.work/man/pvs.8
===================================================================
--- LVM2.work.orig/man/pvs.8
+++ LVM2.work/man/pvs.8
@@ -3,7 +3,7 @@
 pvs \- report information about physical volumes
 .SH SYNOPSIS
 .B pvs
-[\-\-aligned] [\-d/\-\-debug] [\-h/\-?/\-\-help]
+[\-\-aligned] [\-d/\-\-debug] [\-\-filter Filter] [\-h/\-?/\-\-help]
 [\-\-ignorelockingfailure] [\-\-noheadings] [\-\-nosuffix]
 [\-o/\-\-options [+]Field[,Field]]
 [\-O/\-\-sort [+/-]Key1[,[+/-]Key2[,...]]]
Index: LVM2.work/man/vgs.8
===================================================================
--- LVM2.work.orig/man/vgs.8
+++ LVM2.work/man/vgs.8
@@ -3,7 +3,7 @@
 vgs \- report information about volume groups
 .SH SYNOPSIS
 .B vgs
-[\-\-aligned] [\-d/\-\-debug] [\-h/\-?/\-\-help]
+[\-\-aligned] [\-d/\-\-debug] [\-\-filter Filter] [\-h/\-?/\-\-help]
 [\-\-ignorelockingfailure] [\-\-noheadings] [\-\-nosuffix]
 [\-o/\-\-options [+]Field[,Field]]
 [\-O/\-\-sort [+/-]Key1[,[+/-]Key2[,...]]]

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]