@@ -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);
@@ -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:
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(-)