diff mbox

[ndctl,4/4] ndctl, list: hide badblock_count by default

Message ID 149454010604.30857.15214297566335127724.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State Accepted
Commit 4e080076be50
Headers show

Commit Message

Dan Williams May 11, 2017, 10:01 p.m. UTC
In order to keep the default listing as compact as possible, hide
badblock_count when it is zero.

Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Toshi Kani <toshi.kani@hpe.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/list.c |   12 +++++++-----
 util/json.c  |   14 ++++++++------
 2 files changed, 15 insertions(+), 11 deletions(-)

Comments

Kani, Toshi May 11, 2017, 10:33 p.m. UTC | #1
On Thu, 2017-05-11 at 15:01 -0700, Dan Williams wrote:
> In order to keep the default listing as compact as possible, hide
> badblock_count when it is zero.
> 
> Cc: Dave Jiang <dave.jiang@intel.com>
> Cc: Vishal Verma <vishal.l.verma@intel.com>
> Cc: Toshi Kani <toshi.kani@hpe.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>

Works as expected.  For the series:

Tested-by: Toshi Kani <toshi.kani@hpe.com>

Thanks!
-Toshi
diff mbox

Patch

diff --git a/ndctl/list.c b/ndctl/list.c
index cf26d8c08183..befb3cfc6ffd 100644
--- a/ndctl/list.c
+++ b/ndctl/list.c
@@ -209,12 +209,14 @@  static struct json_object *region_to_json(struct ndctl_region *region,
 
 	jbbs = util_region_badblocks_to_json(region, include_media_errors,
 			&bb_count);
-	jobj = json_object_new_int(bb_count);
-	if (!jobj) {
-		json_object_put(jbbs);
-		goto err;
+	if (bb_count) {
+		jobj = json_object_new_int(bb_count);
+		if (!jobj) {
+			json_object_put(jbbs);
+			goto err;
+		}
+		json_object_object_add(jregion, "badblock_count", jobj);
 	}
-	json_object_object_add(jregion, "badblock_count", jobj);
 	if (include_media_errors && jbbs)
 		json_object_object_add(jregion, "badblocks", jbbs);
 
diff --git a/util/json.c b/util/json.c
index 17595267c34c..4ca33a628381 100644
--- a/util/json.c
+++ b/util/json.c
@@ -568,15 +568,17 @@  struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 				ndctl_namespace_get_region(ndns),
 				include_media_errors, &bb_count);
 
-	jobj = json_object_new_int(bb_count);
-	if (!jobj) {
-		json_object_put(jbbs);
-		goto err;
+	if (bb_count) {
+		jobj = json_object_new_int(bb_count);
+		if (!jobj) {
+			json_object_put(jbbs);
+			goto err;
+		}
+		json_object_object_add(jndns, "badblock_count", jobj);
 	}
 
-	json_object_object_add(jndns, "badblock_count", jobj);
 	if (include_media_errors && jbbs)
-			json_object_object_add(jndns, "badblocks", jbbs);
+		json_object_object_add(jndns, "badblocks", jbbs);
 
 	return jndns;
  err: