From patchwork Sat Aug 12 19:25:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9897471 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 3B974603B4 for ; Sat, 12 Aug 2017 19:31:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B1842892E for ; Sat, 12 Aug 2017 19:31:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FC0D2899C; Sat, 12 Aug 2017 19:31: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 B514F2892E for ; Sat, 12 Aug 2017 19:31:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9E61C21E2572D; Sat, 12 Aug 2017 12:29:14 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 AA0B221D4911E for ; Sat, 12 Aug 2017 12:29:13 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Aug 2017 12:31:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,364,1498546800"; d="scan'208"; a="1205037558" 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; 12 Aug 2017 12:31:34 -0700 Subject: [ndctl PATCH 2/2] ndctl, list: add the remaining set of 'filter_by' helpers From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 12 Aug 2017 12:25:11 -0700 Message-ID: <150256591112.13073.15791513451022118526.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <150256590603.13073.16819489053604962816.stgit@dwillia2-desk3.amr.corp.intel.com> References: <150256590603.13073.16819489053604962816.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: , Cc: Keith Hazelet Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP We already support filtering region and bus listings by dimm, lets extend that to the other object types. I.e. permit buses to be filtered by regions, dimms, and namespaces; allow regions to be filtered by dimms, and namespaces etc... For example, to list all the DIMMs that comprise a given namespace: # ndctl list --dimms --namespace=7.0 [ { "dev":"nmem1", "id":"cdab-0a-07e0-ffffffff", "handle":0, "phys_id":0 }, { "dev":"nmem3", "id":"cdab-0a-07e0-fffeffff", "handle":256, "phys_id":2 }, { "dev":"nmem2", "id":"cdab-0a-07e0-feffffff", "handle":1, "phys_id":1 }, { "dev":"nmem4", "id":"cdab-0a-07e0-fefeffff", "handle":257, "phys_id":3 } ] Reported-by: Keith Hazelet Signed-off-by: Dan Williams --- ndctl/list.c | 14 +++++++-- util/filter.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ util/filter.h | 10 ++++++ 3 files changed, 111 insertions(+), 3 deletions(-) diff --git a/ndctl/list.c b/ndctl/list.c index c910c776c61d..1960e9f8d7b5 100644 --- a/ndctl/list.c +++ b/ndctl/list.c @@ -344,7 +344,9 @@ int cmd_list(int argc, const char **argv, void *ctx) struct ndctl_dimm *dimm; if (!util_bus_filter(bus, param.bus) - || !util_bus_filter_by_dimm(bus, param.dimm)) + || !util_bus_filter_by_dimm(bus, param.dimm) + || !util_bus_filter_by_region(bus, param.region) + || !util_bus_filter_by_namespace(bus, param.namespace)) continue; if (list.buses) { @@ -371,7 +373,11 @@ int cmd_list(int argc, const char **argv, void *ctx) if (!list.dimms) break; - if (!util_dimm_filter(dimm, param.dimm)) + if (!util_dimm_filter(dimm, param.dimm) + || !util_dimm_filter_by_region(dimm, + param.region) + || !util_dimm_filter_by_namespace(dimm, + param.namespace)) continue; if (!list.idle && !ndctl_dimm_is_enabled(dimm)) @@ -425,7 +431,9 @@ int cmd_list(int argc, const char **argv, void *ctx) if (!util_region_filter(region, param.region) || !util_region_filter_by_dimm(region, - param.dimm)) + param.dimm) + || !util_region_filter_by_namespace(region, + param.namespace)) continue; if (type && ndctl_region_get_type(region) != type) diff --git a/util/filter.c b/util/filter.c index 400c11a3a80a..acc006cd1d41 100644 --- a/util/filter.c +++ b/util/filter.c @@ -130,6 +130,37 @@ struct ndctl_bus *util_bus_filter_by_dimm(struct ndctl_bus *bus, return NULL; } +struct ndctl_bus *util_bus_filter_by_region(struct ndctl_bus *bus, + const char *ident) +{ + struct ndctl_region *region; + + if (!ident || strcmp(ident, "all") == 0) + return bus; + + ndctl_region_foreach(bus, region) + if (util_region_filter(region, ident)) + return bus; + return NULL; +} + + +struct ndctl_bus *util_bus_filter_by_namespace(struct ndctl_bus *bus, + const char *ident) +{ + struct ndctl_region *region; + struct ndctl_namespace *ndns; + + if (!ident || strcmp(ident, "all") == 0) + return bus; + + ndctl_region_foreach(bus, region) + ndctl_namespace_foreach(region, ndns) + if (util_namespace_filter(ndns, ident)) + return bus; + return NULL; +} + struct ndctl_region *util_region_filter_by_dimm(struct ndctl_region *region, const char *ident) { @@ -145,6 +176,65 @@ struct ndctl_region *util_region_filter_by_dimm(struct ndctl_region *region, return NULL; } +struct ndctl_dimm *util_dimm_filter_by_region(struct ndctl_dimm *dimm, + const char *ident) +{ + struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm); + struct ndctl_region *region; + struct ndctl_dimm *check; + + if (!ident || strcmp(ident, "all") == 0) + return dimm; + + ndctl_region_foreach(bus, region) { + if (!util_region_filter(region, ident)) + continue; + ndctl_dimm_foreach_in_region(region, check) + if (check == dimm) + return dimm; + } + + return NULL; +} + +struct ndctl_dimm *util_dimm_filter_by_namespace(struct ndctl_dimm *dimm, + const char *ident) +{ + struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm); + struct ndctl_namespace *ndns; + struct ndctl_region *region; + struct ndctl_dimm *check; + + if (!ident || strcmp(ident, "all") == 0) + return dimm; + + ndctl_region_foreach(bus, region) { + ndctl_namespace_foreach(region, ndns) { + if (!util_namespace_filter(ndns, ident)) + continue; + ndctl_dimm_foreach_in_region(region, check) + if (check == dimm) + return dimm; + } + } + + return NULL; +} + +struct ndctl_region *util_region_filter_by_namespace(struct ndctl_region *region, + const char *ident) +{ + struct ndctl_namespace *ndns; + + if (!ident || strcmp(ident, "all") == 0) + return region; + + ndctl_namespace_foreach(region, ndns) + if (util_namespace_filter(ndns, ident)) + return region; + return NULL; +} + struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev, const char *ident) { diff --git a/util/filter.h b/util/filter.h index dcc537caaaf9..aa0098d2c099 100644 --- a/util/filter.h +++ b/util/filter.h @@ -20,8 +20,18 @@ struct ndctl_namespace *util_namespace_filter(struct ndctl_namespace *ndns, struct ndctl_dimm *util_dimm_filter(struct ndctl_dimm *dimm, const char *ident); struct ndctl_bus *util_bus_filter_by_dimm(struct ndctl_bus *bus, const char *ident); +struct ndctl_bus *util_bus_filter_by_region(struct ndctl_bus *bus, + const char *ident); +struct ndctl_bus *util_bus_filter_by_namespace(struct ndctl_bus *bus, + const char *ident); struct ndctl_region *util_region_filter_by_dimm(struct ndctl_region *region, const char *ident); +struct ndctl_dimm *util_dimm_filter_by_region(struct ndctl_dimm *dimm, + const char *ident); +struct ndctl_dimm *util_dimm_filter_by_namespace(struct ndctl_dimm *dimm, + const char *ident); +struct ndctl_region *util_region_filter_by_namespace(struct ndctl_region *region, + const char *ident); struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev, const char *ident); #endif