From patchwork Thu May 11 22:01:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9723203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 50CFC601E7 for ; Thu, 11 May 2017 22:07:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F11828724 for ; Thu, 11 May 2017 22:07:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 427A62873A; Thu, 11 May 2017 22:07:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F0B5928724 for ; Thu, 11 May 2017 22:07:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DF6D921A04E19; Thu, 11 May 2017 15:07:38 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 18CFC21A16E28 for ; Thu, 11 May 2017 15:07:38 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 May 2017 15:07:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.38,326,1491289200"; d="scan'208"; a="1129213735" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by orsmga001.jf.intel.com with ESMTP; 11 May 2017 15:07:37 -0700 Subject: [ndctl PATCH 4/4] ndctl, list: hide badblock_count by default From: Dan Williams To: linux-nvdimm@lists.01.org Date: Thu, 11 May 2017 15:01:46 -0700 Message-ID: <149454010604.30857.15214297566335127724.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <149454009049.30857.6643219237076670086.stgit@dwillia2-desk3.amr.corp.intel.com> References: <149454009049.30857.6643219237076670086.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP In order to keep the default listing as compact as possible, hide badblock_count when it is zero. Cc: Dave Jiang Cc: Vishal Verma Cc: Toshi Kani Signed-off-by: Dan Williams Tested-by: Toshi Kani --- ndctl/list.c | 12 +++++++----- util/json.c | 14 ++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) 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: