diff mbox

[ndctl,7/8] ndctl: add filter-by-type to the 'list' command

Message ID 20160308233704.18628.58923.stgit@dwillia2-desk3.jf.intel.com (mailing list archive)
State Accepted
Commit b419a0ab83ff
Headers show

Commit Message

Dan Williams March 8, 2016, 11:37 p.m. UTC
Limit region, and subsequently namespace, scanning by interface type
('pmem' or 'blk').

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 Documentation/ndctl-list.txt |    4 ++++
 builtin-list.c               |   21 +++++++++++++++++++++
 2 files changed, 25 insertions(+)
diff mbox

Patch

diff --git a/Documentation/ndctl-list.txt b/Documentation/ndctl-list.txt
index 53847c56236e..abf3ff07cfa9 100644
--- a/Documentation/ndctl-list.txt
+++ b/Documentation/ndctl-list.txt
@@ -60,6 +60,10 @@  OPTIONS
 --region=::
 include::xable-region-options.txt[]
 
+-t::
+--type=::
+	Filter listing by region type ('pmem' or 'blk')
+
 -B::
 --buses::
 	Include bus info in the listing
diff --git a/builtin-list.c b/builtin-list.c
index 12a6d32b124a..413b36ac0208 100644
--- a/builtin-list.c
+++ b/builtin-list.c
@@ -29,6 +29,7 @@  static struct {
 static struct {
 	const char *bus;
 	const char *region;
+	const char *type;
 } param;
 
 static int did_fail;
@@ -197,6 +198,8 @@  int cmd_list(int argc, const char **argv)
 		OPT_STRING('b', "bus", &param.bus, "bus-id", "filter by bus"),
 		OPT_STRING('r', "region", &param.region, "region-id",
 				"filter by region"),
+		OPT_STRING('t', "type", &param.type, "region-type",
+				"filter by region-type"),
 		OPT_BOOLEAN('B', "buses", &list.buses, "include bus info"),
 		OPT_BOOLEAN('D', "dimms", &list.dimms, "include dimm info"),
 		OPT_BOOLEAN('R', "regions", &list.regions,
@@ -216,14 +219,29 @@  int cmd_list(int argc, const char **argv)
 	struct json_object *jbuses = NULL;
 	struct ndctl_ctx *ctx;
 	struct ndctl_bus *bus;
+	unsigned int type = 0;
 	int i, rc;
 
         argc = parse_options(argc, argv, options, u, 0);
 	for (i = 0; i < argc; i++)
 		error("unknown parameter \"%s\"\n", argv[i]);
+	if (param.type && (strcmp(param.type, "pmem") != 0
+				&& strcmp(param.type, "blk") != 0)) {
+		error("unknown type \"%s\" must be \"pmem\" or \"blk\"\n",
+				param.type);
+		argc++;
+	}
+
 	if (argc)
 		usage_with_options(u, options);
 
+	if (param.type) {
+		if (strcmp(param.type, "pmem") == 0)
+			type = ND_DEVICE_REGION_PMEM;
+		else
+			type = ND_DEVICE_REGION_BLK;
+	}
+
 	rc = ndctl_new(&ctx);
 	if (rc < 0)
 		return rc;
@@ -293,6 +311,9 @@  int cmd_list(int argc, const char **argv)
 			if (!util_region_filter(region, param.region))
 				continue;
 
+			if (type && ndctl_region_get_type(region) != type)
+				continue;
+
 			if (!list.regions) {
 				jnamespaces = list_namespaces(region, jbus,
 						jnamespaces, true);