From patchwork Fri Jul 21 18:39:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9857501 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 B8DC260392 for ; Fri, 21 Jul 2017 18:46:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABE1828672 for ; Fri, 21 Jul 2017 18:46:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A096328678; Fri, 21 Jul 2017 18:46:37 +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 229A628672 for ; Fri, 21 Jul 2017 18:46:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C97A921D1B292; Fri, 21 Jul 2017 11:44:38 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 E3AAB21CE748E for ; Fri, 21 Jul 2017 11:44:37 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP; 21 Jul 2017 11:46:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.40,391,1496127600"; d="scan'208"; a="1198068041" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by fmsmga002.fm.intel.com with ESMTP; 21 Jul 2017 11:46:27 -0700 Subject: [ndctl PATCH] ndctl, list: always show 'name' if it is available From: Dan Williams To: linux-nvdimm@lists.01.org Date: Fri, 21 Jul 2017 11:39:59 -0700 Message-ID: <150066239948.20775.13756890159711008729.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 The user-friendly name of a namespace should always be emitted. Reported-by: Linda Knippers Signed-off-by: Dan Williams --- util/json.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/util/json.c b/util/json.c index 559a022ae405..2b2b5af16504 100644 --- a/util/json.c +++ b/util/json.c @@ -558,7 +558,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, struct json_object *jobj, *jbbs = NULL; unsigned long long size = ULLONG_MAX; enum ndctl_namespace_mode mode; - const char *bdev = NULL; + const char *bdev = NULL, *name; unsigned int bb_count; struct ndctl_btt *btt; struct ndctl_pfn *pfn; @@ -654,7 +654,6 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, json_object_object_add(jndns, "daxregion", jobj); } else if (dax_region) { struct daxctl_dev *dev; - const char *name; dev = daxctl_dev_get_first(dax_region); name = daxctl_dev_get_devname(dev); @@ -664,22 +663,12 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, json_object_object_add(jndns, "chardev", jobj); } } else if (ndctl_namespace_get_type(ndns) != ND_DEVICE_NAMESPACE_IO) { - const char *name; - ndctl_namespace_get_uuid(ndns, uuid); uuid_unparse(uuid, buf); jobj = json_object_new_string(buf); if (!jobj) goto err; json_object_object_add(jndns, "uuid", jobj); - - name = ndctl_namespace_get_alt_name(ndns); - if (name[0]) { - jobj = json_object_new_string(name); - if (!jobj) - goto err; - json_object_object_add(jndns, "name", jobj); - } bdev = ndctl_namespace_get_block_device(ndns); } else bdev = ndctl_namespace_get_block_device(ndns); @@ -698,6 +687,14 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, json_object_object_add(jndns, "state", jobj); } + name = ndctl_namespace_get_alt_name(ndns); + if (name && name[0]) { + jobj = json_object_new_string(name); + if (!jobj) + goto err; + json_object_object_add(jndns, "name", jobj); + } + numa = ndctl_namespace_get_numa_node(ndns); if (numa >= 0) { jobj = json_object_new_int(numa);