From patchwork Wed Apr 18 06:32:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 10347411 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 C810A6031B for ; Wed, 18 Apr 2018 06:34:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC8FC1FF13 for ; Wed, 18 Apr 2018 06:34:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B09242858E; Wed, 18 Apr 2018 06:34:25 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 318F51FF13 for ; Wed, 18 Apr 2018 06:34:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B48FA2263DD75; Tue, 17 Apr 2018 23:34:24 -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=211.128.242.42; helo=mgwym03.jp.fujitsu.com; envelope-from=qi.fuli@jp.fujitsu.com; receiver=linux-nvdimm@lists.01.org Received: from mgwym03.jp.fujitsu.com (mgwym03.jp.fujitsu.com [211.128.242.42]) (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 5E716220E8CB6 for ; Tue, 17 Apr 2018 23:34:22 -0700 (PDT) Received: from yt-mxauth.gw.nic.fujitsu.com (unknown [192.168.229.68]) by mgwym03.jp.fujitsu.com with smtp id 7137_411e_f6ae0d8f_dafd_46ec_80b4_3d18d20122d2; Wed, 18 Apr 2018 15:34:13 +0900 Received: from m3050.s.css.fujitsu.com (msm.b.css.fujitsu.com [10.134.21.208]) by yt-mxauth.gw.nic.fujitsu.com (Postfix) with ESMTP id 41421AC02D2 for ; Wed, 18 Apr 2018 15:34:11 +0900 (JST) Received: from qi-fedora.fujitsu.com (unknown [10.124.196.110]) by m3050.s.css.fujitsu.com (Postfix) with ESMTP id 23E863F9; Wed, 18 Apr 2018 15:34:11 +0900 (JST) From: QI Fuli To: linux-nvdimm@lists.01.org Subject: [PATCH v2] ndctl, filter: refacor util__filter() to support multiple space-seperated arguments Date: Wed, 18 Apr 2018 15:32:42 +0900 Message-Id: <20180418063242.9221-1-qi.fuli@jp.fujitsu.com> X-Mailer: git-send-email 2.17.0.140.g0b0cc9f86 X-TM-AS-MML: disable X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP This patch refactors util__filter to support multiple space-seperated arguments. Currently, only one can be filtered by 's name in util__filter(). As a result, when users want to moniotr multiple dimms, they have to run multiple monitor processes. This feature teachs the util_dimm_filter() that the "ident" argument maybe a space-seperatd string which includes multiple dimm_names. Therefore the monitor can filter multiple dimms in one process. Signed-off-by: QI Fuli Signed-off-by: Dan Williams Change log since v1: - Removing OPT_STRING_LIST from parse-option Reviewed-by: Dan Williams Reviewed-by: Dan Williams Signed-off-by: QI Fuli --- util/filter.c | 141 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 92 insertions(+), 49 deletions(-) diff --git a/util/filter.c b/util/filter.c index 6ab391a..0d3cc02 100644 --- a/util/filter.c +++ b/util/filter.c @@ -25,101 +25,144 @@ #define NUMA_NO_NODE (-1) -struct ndctl_bus *util_bus_filter(struct ndctl_bus *bus, const char *ident) +struct ndctl_bus *util_bus_filter(struct ndctl_bus *bus, const char *__ident) { - char *end = NULL; + char *end = NULL, *ident, *save; unsigned long bus_id, id; - const char *provider, *devname; + const char *provider, *devname, *name; - if (!ident || strcmp(ident, "all") == 0) + if (!__ident || strcmp(__ident, "all") == 0) return bus; - bus_id = strtoul(ident, &end, 0); - if (end == ident || end[0]) - bus_id = ULONG_MAX; + ident = strdup(__ident); + if (!ident) + return NULL; - provider = ndctl_bus_get_provider(bus); - devname = ndctl_bus_get_devname(bus); - id = ndctl_bus_get_id(bus); + for (name = strtok_r(ident, " ", &save); name; + name = strtok_r(NULL, " ", &save)) { + bus_id = strtoul(ident, &end, 0); + if (end == ident || end[0]) + bus_id = ULONG_MAX; - if (bus_id < ULONG_MAX && bus_id == id) - return bus; + provider = ndctl_bus_get_provider(bus); + devname = ndctl_bus_get_devname(bus); + id = ndctl_bus_get_id(bus); - if (bus_id == ULONG_MAX && (strcmp(ident, provider) == 0 - || strcmp(ident, devname) == 0)) - return bus; + if (bus_id < ULONG_MAX && bus_id == id) + break; + if (bus_id == ULONG_MAX && (strcmp(provider, name) == 0 + || strcmp(devname, name) == 0)) + break; + } + free(ident); + + if (name) + return bus; return NULL; } struct ndctl_region *util_region_filter(struct ndctl_region *region, - const char *ident) + const char *__ident) { - char *end = NULL; - const char *name; + char *end = NULL, *ident, *save; + const char *name, *region_name; unsigned long region_id, id; - if (!ident || strcmp(ident, "all") == 0) + if (!__ident || strcmp(__ident, "all") == 0) return region; - region_id = strtoul(ident, &end, 0); - if (end == ident || end[0]) - region_id = ULONG_MAX; + ident = strdup(__ident); + if (!ident) + return NULL; - name = ndctl_region_get_devname(region); - id = ndctl_region_get_id(region); + for (name = strtok_r(ident, " ", &save); name; + name = strtok_r(NULL, " ", &save)) { + region_id = strtoul(ident, &end, 0); + if (end == ident || end[0]) + region_id = ULONG_MAX; - if (region_id < ULONG_MAX && region_id == id) - return region; + region_name = ndctl_region_get_devname(region); + id = ndctl_region_get_id(region); - if (region_id == ULONG_MAX && strcmp(ident, name) == 0) - return region; + if (region_id < ULONG_MAX && region_id == id) + break; + + if (region_id == ULONG_MAX && strcmp(region_name, name) == 0) + break; + } + free(ident); + if (name) + return region; return NULL; } struct ndctl_namespace *util_namespace_filter(struct ndctl_namespace *ndns, - const char *ident) + const char *__ident) { struct ndctl_region *region = ndctl_namespace_get_region(ndns); unsigned long region_id, ndns_id; + const char *name; + char *ident, *save; - if (!ident || strcmp(ident, "all") == 0) + if (!__ident || strcmp(__ident, "all") == 0) return ndns; - if (strcmp(ident, ndctl_namespace_get_devname(ndns)) == 0) - return ndns; + ident = strdup(__ident); + if (!ident) + return NULL; - if (sscanf(ident, "%ld.%ld", ®ion_id, &ndns_id) == 2 - && ndctl_region_get_id(region) == region_id - && ndctl_namespace_get_id(ndns) == ndns_id) - return ndns; + for (name = strtok_r(ident, " ", &save); name; + name = strtok_r(NULL, " ", &save)) { + if (strcmp(name, ndctl_namespace_get_devname(ndns)) == 0) + break; + + if (sscanf(name, "%ld.%ld", ®ion_id, &ndns_id) == 2 + && ndctl_region_get_id(region) == region_id + && ndctl_namespace_get_id(ndns) == ndns_id) + break; + } + free(ident); + if (name) + return ndns; return NULL; } -struct ndctl_dimm *util_dimm_filter(struct ndctl_dimm *dimm, const char *ident) +struct ndctl_dimm *util_dimm_filter(struct ndctl_dimm *dimm, + const char *__ident) { - char *end = NULL; - const char *name; + char *end = NULL, *ident, *save; + const char *name, *dimm_name; unsigned long dimm_id, id; - if (!ident || strcmp(ident, "all") == 0) + if (!__ident || strcmp(__ident, "all") == 0) return dimm; - dimm_id = strtoul(ident, &end, 0); - if (end == ident || end[0]) - dimm_id = ULONG_MAX; + ident = strdup(__ident); + if (!ident) + return NULL; - name = ndctl_dimm_get_devname(dimm); - id = ndctl_dimm_get_id(dimm); + for (name = strtok_r(ident, " ", &save); name; + name = strtok_r(NULL, " ", &save)) { + dimm_id = strtoul(ident, &end, 0); + if (end == ident || end[0]) + dimm_id = ULONG_MAX; - if (dimm_id < ULONG_MAX && dimm_id == id) - return dimm; + dimm_name = ndctl_dimm_get_devname(dimm); + id = ndctl_dimm_get_id(dimm); - if (dimm_id == ULONG_MAX && strcmp(ident, name) == 0) - return dimm; + if (dimm_id < ULONG_MAX && dimm_id == id) + break; + + if (dimm_id == ULONG_MAX && strcmp(dimm_name, name) == 0) + break; + } + free(ident); + if (name) + return dimm; return NULL; }