From patchwork Thu Apr 26 00:56:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 10364521 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 2B398602DC for ; Thu, 26 Apr 2018 00:59:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AF9828D91 for ; Thu, 26 Apr 2018 00:59:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D23228E02; Thu, 26 Apr 2018 00:59:33 +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 7806628D91 for ; Thu, 26 Apr 2018 00:59:31 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D0AC9202E5EF9; Wed, 25 Apr 2018 17:59:31 -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=202.219.69.169; helo=mgwkm02.jp.fujitsu.com; envelope-from=qi.fuli@jp.fujitsu.com; receiver=linux-nvdimm@lists.01.org Received: from mgwkm02.jp.fujitsu.com (mgwkm02.jp.fujitsu.com [202.219.69.169]) (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 8C9DF202E5EF5 for ; Wed, 25 Apr 2018 17:59:30 -0700 (PDT) Received: from kw-mxoi2.gw.nic.fujitsu.com (unknown [192.168.231.133]) by mgwkm02.jp.fujitsu.com with smtp id 4ac4_7bde_bfd48b75_f4d4_4dee_9599_22467bfb7b39; Thu, 26 Apr 2018 09:59:23 +0900 Received: from m3050.s.css.fujitsu.com (msm.b.css.fujitsu.com [10.134.21.208]) by kw-mxoi2.gw.nic.fujitsu.com (Postfix) with ESMTP id 53C9CAC00EA for ; Thu, 26 Apr 2018 09:59:23 +0900 (JST) Received: from qi-fedora.fujitsu.com (unknown [10.124.196.110]) by m3050.s.css.fujitsu.com (Postfix) with ESMTP id 36916519; Thu, 26 Apr 2018 09:59:23 +0900 (JST) From: QI Fuli To: linux-nvdimm@lists.01.org Subject: [PATCH v2] ndctl, filter: fix "keyword 'all' is ignored" in util__filter() Date: Thu, 26 Apr 2018 09:56:48 +0900 Message-Id: <20180426005648.13028-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 is a follow up patch for commit c70adc3cf6bf ("ndctl, filter: refactor util__filter() to support multiple space-seperated arguments") refactored util__filter() to support multiple space-seperated arguments. But, when the keyword "all" is included in space-seperated arguments, it will be treaded as 's name. This patch fixes it. Signed-off-by: QI Fuli Change log since v1: - Removing the strcmp(__ident, "all") == 0 at the top of util__filter() - Changing the strcmp(ident, "all") == 0 to strcmp(name, "all") == 0 Reviewed-by: Dan Williams --- util/filter.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/util/filter.c b/util/filter.c index 0d3cc02..1734bce 100644 --- a/util/filter.c +++ b/util/filter.c @@ -31,7 +31,7 @@ struct ndctl_bus *util_bus_filter(struct ndctl_bus *bus, const char *__ident) unsigned long bus_id, id; const char *provider, *devname, *name; - if (!__ident || strcmp(__ident, "all") == 0) + if (!__ident) return bus; ident = strdup(__ident); @@ -40,6 +40,9 @@ struct ndctl_bus *util_bus_filter(struct ndctl_bus *bus, const char *__ident) for (name = strtok_r(ident, " ", &save); name; name = strtok_r(NULL, " ", &save)) { + if (strcmp(name, "all") == 0) + break; + bus_id = strtoul(ident, &end, 0); if (end == ident || end[0]) bus_id = ULONG_MAX; @@ -69,7 +72,7 @@ struct ndctl_region *util_region_filter(struct ndctl_region *region, const char *name, *region_name; unsigned long region_id, id; - if (!__ident || strcmp(__ident, "all") == 0) + if (!__ident) return region; ident = strdup(__ident); @@ -78,6 +81,9 @@ struct ndctl_region *util_region_filter(struct ndctl_region *region, for (name = strtok_r(ident, " ", &save); name; name = strtok_r(NULL, " ", &save)) { + if (strcmp(name, "all") == 0) + break; + region_id = strtoul(ident, &end, 0); if (end == ident || end[0]) region_id = ULONG_MAX; @@ -106,7 +112,7 @@ struct ndctl_namespace *util_namespace_filter(struct ndctl_namespace *ndns, const char *name; char *ident, *save; - if (!__ident || strcmp(__ident, "all") == 0) + if (!__ident) return ndns; ident = strdup(__ident); @@ -115,6 +121,9 @@ struct ndctl_namespace *util_namespace_filter(struct ndctl_namespace *ndns, for (name = strtok_r(ident, " ", &save); name; name = strtok_r(NULL, " ", &save)) { + if (strcmp(name, "all") == 0) + break; + if (strcmp(name, ndctl_namespace_get_devname(ndns)) == 0) break; @@ -137,7 +146,7 @@ struct ndctl_dimm *util_dimm_filter(struct ndctl_dimm *dimm, const char *name, *dimm_name; unsigned long dimm_id, id; - if (!__ident || strcmp(__ident, "all") == 0) + if (!__ident) return dimm; ident = strdup(__ident); @@ -146,6 +155,9 @@ struct ndctl_dimm *util_dimm_filter(struct ndctl_dimm *dimm, for (name = strtok_r(ident, " ", &save); name; name = strtok_r(NULL, " ", &save)) { + if (strcmp(name, "all") == 0) + break; + dimm_id = strtoul(ident, &end, 0); if (end == ident || end[0]) dimm_id = ULONG_MAX;