From patchwork Tue Mar 13 23:33:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10281275 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 819F1601A0 for ; Tue, 13 Mar 2018 23:42:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71A91285CA for ; Tue, 13 Mar 2018 23:42:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 662DC285CC; Tue, 13 Mar 2018 23:42:18 +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 C95C3285CA for ; Tue, 13 Mar 2018 23:42:17 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E1FB8223DB108; Tue, 13 Mar 2018 16:35:54 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 7A5E621E4905F for ; Tue, 13 Mar 2018 16:35:52 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Mar 2018 16:42:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,466,1515484800"; d="scan'208";a="24399720" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga007.jf.intel.com with ESMTP; 13 Mar 2018 16:42:14 -0700 Subject: [ndctl PATCH v2] ndctl, list: fix namespace json object parenting From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 13 Mar 2018 16:33:10 -0700 Message-ID: <152098394967.38244.14033629842721195081.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.23 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 When listing namespaces and regions a generic jplatform object is created to house the regions array. However, commit f8cc6fee4e4d "ndctl, list: refactor core topology walking into util_filter_walk()" inadvertently added namespaces to that jplatform, and otherwise failed to parent namespaces to their proper parent region. # ndctl list -RNu { "regions":[ { "dev":"region1", "size":"511.00 GiB (548.68 GB)", "available_size":0, "type":"pmem", "numa_node":0, "namespaces":[ { "dev":"namespace1.0", "mode":"raw", "size":"511.00 GiB (548.68 GB)", "sector_size":512, "blockdev":"pmem1", "numa_node":0 }, { "dev":"namespace0.0", <------- wrong region "mode":"fsdax", "size":"4.00 GiB (4.29 GB)", "sector_size":512, "blockdev":"pmem0", "numa_node":0 } ] }, { "dev":"region0", "size":"4.00 GiB (4.29 GB)", "available_size":0, "type":"pmem" } ], "namespaces":[ <------ we already listed the namespaces { "dev":"namespace1.0", "mode":"raw", "size":"511.00 GiB (548.68 GB)", "sector_size":512, "blockdev":"pmem1", "numa_node":0 }, { "dev":"namespace0.0", "mode":"fsdax", "size":"4.00 GiB (4.29 GB)", "sector_size":512, "blockdev":"pmem0", "numa_node":0 } ] } ndctl: json_object.c:188: json_object_put: Assertion `jso->_ref_count > 0' failed. Aborted (core dumped) <------ not ideal Clear out the jnamespaces tracking as the filter walk transitions to the next region, and make sure that jnamepsaces is not added to jplatform when regions are being displayed. Fixes: f8cc6fee4e4d(" ndctl, list: refactor core topology walking...") Signed-off-by: Dan Williams --- v2: fix breaking namespace arrays on region boundaries ndctl/list.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ndctl/list.c b/ndctl/list.c index 0ca5b6dee5eb..fe8036eabc3b 100644 --- a/ndctl/list.c +++ b/ndctl/list.c @@ -245,6 +245,13 @@ static bool filter_region(struct ndctl_region *region, lfa->jregion = jregion; /* + * We've started a new region, any previous jnamespaces will + * have been parented to the last region. Clear out jnamespaces + * so we start a new array per region. + */ + lfa->jnamespaces = NULL; + + /* * Without a bus we are collecting regions anonymously across * the platform. */ @@ -366,7 +373,7 @@ static int list_display(struct list_filter_arg *lfa) json_object_object_add(jplatform, "dimms", jdimms); if (jregions) json_object_object_add(jplatform, "regions", jregions); - if (jnamespaces) + if (jnamespaces && !jregions) json_object_object_add(jplatform, "namespaces", jnamespaces); printf("%s\n", json_object_to_json_string_ext(jplatform,