From patchwork Sat Apr 9 19:39:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 8788601 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1898A9F3D1 for ; Sat, 9 Apr 2016 19:40:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4AAD220222 for ; Sat, 9 Apr 2016 19:40:34 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 3B01920221 for ; Sat, 9 Apr 2016 19:40:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 30EC31A1E8F; Sat, 9 Apr 2016 12:40:33 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ml01.01.org (Postfix) with ESMTP id 10AEF1A1E8F for ; Sat, 9 Apr 2016 12:40:32 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 09 Apr 2016 12:40:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,460,1455004800"; d="scan'208";a="941815940" Received: from dwillia2-desk3.jf.intel.com ([10.54.39.14]) by fmsmga001.fm.intel.com with ESMTP; 09 Apr 2016 12:40:31 -0700 Subject: [ndctl PATCH 2/4] ndctl: use filter utility routines zero-labels From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 09 Apr 2016 12:39:41 -0700 Message-ID: <20160409193941.2002.26602.stgit@dwillia2-desk3.jf.intel.com> In-Reply-To: <20160409193930.2002.71855.stgit@dwillia2-desk3.jf.intel.com> References: <20160409193930.2002.71855.stgit@dwillia2-desk3.jf.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.20 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-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the common routines for filtering a bus or a dimm by name/id. Signed-off-by: Dan Williams --- builtin-zero-labels.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/builtin-zero-labels.c b/builtin-zero-labels.c index ae2bb3a8fdb0..649bd9eb9c08 100644 --- a/builtin-zero-labels.c +++ b/builtin-zero-labels.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -11,11 +12,10 @@ static int do_zero_dimm(struct ndctl_dimm *dimm, const char **argv, int argc, bool verbose) { struct ndctl_ctx *ctx = ndctl_dimm_get_ctx(dimm); - const char *name = ndctl_dimm_get_devname(dimm); int i, rc, log; for (i = 0; i < argc; i++) - if (strcmp(argv[i], "all") == 0 || strcmp(argv[i], name) == 0) + if (util_dimm_filter(dimm, argv[i])) break; if (i >= argc) return -ENODEV; @@ -31,7 +31,7 @@ static int do_zero_dimm(struct ndctl_dimm *dimm, const char **argv, int argc, int cmd_zero_labels(int argc, const char **argv) { - const char *nmem_bus = NULL, *provider; + const char *nmem_bus = NULL; bool verbose = false; const struct option nmem_options[] = { OPT_STRING('b', "bus", &nmem_bus, "bus-id", @@ -39,7 +39,6 @@ int cmd_zero_labels(int argc, const char **argv) OPT_BOOLEAN('v',"verbose", &verbose, "turn on debug"), OPT_END(), }; - unsigned long bus_id = ULONG_MAX, dimm_id; const char * const u[] = { "ndctl zero-labels [..] []", NULL @@ -54,9 +53,11 @@ int cmd_zero_labels(int argc, const char **argv) if (argc == 0) usage_with_options(u, nmem_options); for (i = 0; i < argc; i++) { + unsigned long id; + if (strcmp(argv[i], "all") == 0) continue; - if (sscanf(argv[i], "nmem%lu", &dimm_id) != 1) { + if (sscanf(argv[i], "nmem%lu", &id) != 1) { fprintf(stderr, "unknown extra parameter \"%s\"\n", argv[i]); usage_with_options(u, nmem_options); @@ -67,23 +68,9 @@ int cmd_zero_labels(int argc, const char **argv) if (rc < 0) return rc; - if (nmem_bus) { - char *end = NULL; - - bus_id = strtoul(nmem_bus, &end, 0); - if (end) - bus_id = ULONG_MAX; - } - count = 0; ndctl_bus_foreach(ctx, bus) { - unsigned int id = ndctl_bus_get_id(bus); - - provider = ndctl_bus_get_provider(bus); - if (bus_id < ULONG_MAX && bus_id != id) - continue; - else if (bus_id == ULONG_MAX && nmem_bus - && strcmp(nmem_bus, provider) != 0) + if (!util_bus_filter(bus, nmem_bus)) continue; ndctl_dimm_foreach(bus, dimm) {