diff mbox series

[ndctl,03/36] ndctl/list: Drop named list objects from verbose listing

Message ID 158300762015.2141307.366599346193388777.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show
Series Multiple topics / backlog for v68 | expand

Commit Message

Dan Williams Feb. 29, 2020, 8:20 p.m. UTC
The only expected difference between "ndctl list -R" and "ndctl list
-Rv" is some additional output fields. Instead it currently results in
the region array being contained in a named "regions" list object.

# ndctl list -R -r 0
[
  {
    "dev":"region0",
    "size":4294967296,
    "available_size":0,
    "max_available_extent":0,
    "type":"pmem",
    "persistence_domain":"unknown"
  }
]

# ndctl list -Rv -r 0
{
  "regions":[
    {
      "dev":"region0",
      "size":4294967296,
      "available_size":0,
      "max_available_extent":0,
      "type":"pmem",
      "numa_node":0,
      "target_node":2,
      "persistence_domain":"unknown",
      "namespaces":[
        {
          "dev":"namespace0.0",
          "mode":"fsdax",
          "map":"mem",
          "size":4294967296,
          "sector_size":512,
          "blockdev":"pmem0",
          "numa_node":0,
          "target_node":2
        }
      ]
    }
  ]
}

Drop the named list, by not including namespaces in the listing. Extra
objects only appear at the -vv level. "ndctl list -v" and "ndctl list
-Nv" are synonyms and behave as expected.

# export NDCTL_LIST_LINT=1
# ndctl list -Rv -r 0
[
  {
    "dev":"region0",
    "size":4294967296,
    "available_size":0,
    "max_available_extent":0,
    "type":"pmem",
    "numa_node":0,
    "target_node":2,
    "persistence_domain":"unknown"
  }
]

Another side effect of this change is that it allows for:

    ndctl list -Rvvv

...to only show the verbose region details vs assuming that namespaces
and dimms etc also need to be added.

Note that a new NDCTL_LIST_LINT environment variable is added to limit
this output cleanup to environments that were not dependent on the
legacy behavior.

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

Patch

diff --git a/Documentation/ndctl/ndctl-list.txt b/Documentation/ndctl/ndctl-list.txt
index f9c7434d3b0b..bc725baa6656 100644
--- a/Documentation/ndctl/ndctl-list.txt
+++ b/Documentation/ndctl/ndctl-list.txt
@@ -234,6 +234,52 @@  include::xable-bus-options.txt[]
 	- *-vvv*
 	  Everything '-vv' provides, plus --health, --capabilities,
 	  --idle, and --firmware.
+::
+	The verbosity can also be scoped by the object type. For example
+	to just list regions with capabilities and media error info.
+----
+# ndctl list -Ru -vvv -r 0
+{
+  "dev":"region0",
+  "size":"4.00 GiB (4.29 GB)",
+  "available_size":0,
+  "max_available_extent":0,
+  "type":"pmem",
+  "numa_node":0,
+  "target_node":2,
+  "capabilities":[
+    {
+      "mode":"sector",
+      "sector_sizes":[
+        512,
+        520,
+        528,
+        4096,
+        4104,
+        4160,
+        4224
+      ]
+    },
+    {
+      "mode":"fsdax",
+      "alignments":[
+        4096,
+        2097152,
+        1073741824
+      ]
+    },
+    {
+      "mode":"devdax",
+      "alignments":[
+        4096,
+        2097152,
+        1073741824
+      ]
+    }
+  ],
+  "persistence_domain":"unknown"
+}
+----
 
 include::human-option.txt[]
 
@@ -261,6 +307,18 @@  include::human-option.txt[]
 }
 ----
 
+ENVIRONMENT VARIABLES
+---------------------
+'NDCTL_LIST_LINT'::
+	A bug in the "ndctl list" output needs to be fixed with care for
+	other tooling that may have developed a dependency on the buggy
+	behavior. The NDCTL_LIST_LINT variable is an opt-in to apply
+	fixes, and not regress previously shipped behavior by default.
+	This environment variable applies the following fixups:
+	- Fix "ndctl list -Rv" to only show region objects and not include
+	  namespace objects.
+::
+
 include::../copyright.txt[]
 
 SEE ALSO
diff --git a/ndctl/list.c b/ndctl/list.c
index 86ffbcfe8560..7d7835247005 100644
--- a/ndctl/list.c
+++ b/ndctl/list.c
@@ -481,6 +481,7 @@  int cmd_list(int argc, const char **argv, struct ndctl_ctx *ctx)
 		"ndctl list [<options>]",
 		NULL
 	};
+	bool lint = !!secure_getenv("NDCTL_LIST_LINT");
 	struct util_filter_ctx fctx = { 0 };
 	struct list_filter_arg lfa = { 0 };
 	int i, rc;
@@ -507,12 +508,20 @@  int cmd_list(int argc, const char **argv, struct ndctl_ctx *ctx)
 		list.health = true;
 		list.capabilities = true;
 	case 2:
-		list.dimms = true;
-		list.buses = true;
-		list.regions = true;
+		if (!lint) {
+			list.dimms = true;
+			list.buses = true;
+			list.regions = true;
+		} else if (num_list_flags() == 0) {
+			list.dimms = true;
+			list.buses = true;
+			list.regions = true;
+			list.namespaces = true;
+		}
 	case 1:
 		list.media_errors = true;
-		list.namespaces = true;
+		if (!lint)
+			list.namespaces = true;
 		list.dax = true;
 	case 0:
 		break;