From patchwork Wed Oct 19 16:47:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9384883 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 56466607D0 for ; Wed, 19 Oct 2016 16:51:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4777728901 for ; Wed, 19 Oct 2016 16:51:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C62928C35; Wed, 19 Oct 2016 16:51:04 +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 35F6F28901 for ; Wed, 19 Oct 2016 16:51:03 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2BCCC1A1E6E; Wed, 19 Oct 2016 09:51:03 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B9E941A1E6E for ; Wed, 19 Oct 2016 09:51:01 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP; 19 Oct 2016 09:51:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,367,1473145200"; d="scan'208"; a="1072735625" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.14]) by fmsmga002.fm.intel.com with ESMTP; 19 Oct 2016 09:51:01 -0700 Subject: [ndctl PATCH 2/8] ndctl: consolidate label commands into a single file From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 19 Oct 2016 09:47:59 -0700 Message-ID: <147689567927.11015.16338248621049060172.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <147689566876.11015.13898062253087685236.stgit@dwillia2-desk3.amr.corp.intel.com> References: <147689566876.11015.13898062253087685236.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.21 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 Merge ndctl/builtin-zero-labels.c and ndctl/builtin-read-labels.c into a single file, but no functional change. Signed-off-by: Dan Williams --- ndctl/Makefile.am | 3 - ndctl/builtin-labels.c | 84 +++++++++++++++++++++++++++++++++++++++ ndctl/builtin-zero-labels.c | 92 ------------------------------------------- 3 files changed, 84 insertions(+), 95 deletions(-) rename ndctl/{builtin-read-labels.c => builtin-labels.c} (83%) delete mode 100644 ndctl/builtin-zero-labels.c diff --git a/ndctl/Makefile.am b/ndctl/Makefile.am index 29237b76713a..dc990988ed43 100644 --- a/ndctl/Makefile.am +++ b/ndctl/Makefile.am @@ -10,8 +10,7 @@ ndctl_SOURCES = ndctl.c \ builtin-list.c \ builtin-test.c \ builtin-help.c \ - builtin-zero-labels.c \ - builtin-read-labels.c \ + builtin-labels.c \ util/json.c if ENABLE_SMART diff --git a/ndctl/builtin-read-labels.c b/ndctl/builtin-labels.c similarity index 83% rename from ndctl/builtin-read-labels.c rename to ndctl/builtin-labels.c index 207d44ce7f68..c85069d97655 100644 --- a/ndctl/builtin-read-labels.c +++ b/ndctl/builtin-labels.c @@ -1,4 +1,3 @@ - /* * Copyright (c) 2016, Intel Corporation. * @@ -64,6 +63,89 @@ struct namespace_label { le32 unused; }; +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); + int i, rc, log; + + for (i = 0; i < argc; i++) + if (util_dimm_filter(dimm, argv[i])) + break; + if (i >= argc) + return -ENODEV; + + log = ndctl_get_log_priority(ctx); + if (verbose) + ndctl_set_log_priority(ctx, LOG_DEBUG); + rc = ndctl_dimm_zero_labels(dimm); + ndctl_set_log_priority(ctx, log); + + return rc; +} + +int cmd_zero_labels(int argc, const char **argv, struct ndctl_ctx *ctx) +{ + const char *nmem_bus = NULL; + bool verbose = false; + const struct option nmem_options[] = { + OPT_STRING('b', "bus", &nmem_bus, "bus-id", + " must be on a bus with an id/provider of "), + OPT_BOOLEAN('v',"verbose", &verbose, "turn on debug"), + OPT_END(), + }; + const char * const u[] = { + "ndctl zero-labels [..] []", + NULL + }; + struct ndctl_dimm *dimm; + struct ndctl_bus *bus; + int i, rc, count, err = 0; + + argc = parse_options(argc, argv, nmem_options, u, 0); + + 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", &id) != 1) { + fprintf(stderr, "unknown extra parameter \"%s\"\n", + argv[i]); + usage_with_options(u, nmem_options); + } + } + + count = 0; + ndctl_bus_foreach(ctx, bus) { + if (!util_bus_filter(bus, nmem_bus)) + continue; + + ndctl_dimm_foreach(bus, dimm) { + rc = do_zero_dimm(dimm, argv, argc, verbose); + if (rc == 0) + count++; + else if (rc && !err) + err = rc; + } + } + rc = err; + + fprintf(stderr, "zeroed %d nmem%s\n", count, count > 1 ? "s" : ""); + + /* + * 0 if all dimms zeroed, count if at least 1 dimm zeroed, < 0 + * if all errors + */ + if (rc == 0) + return 0; + if (count) + return count; + return rc; +} + static struct json_object *dump_label_json(struct ndctl_cmd *cmd_read, ssize_t size) { struct json_object *jarray = json_object_new_array(); diff --git a/ndctl/builtin-zero-labels.c b/ndctl/builtin-zero-labels.c deleted file mode 100644 index 2fe466e6ba34..000000000000 --- a/ndctl/builtin-zero-labels.c +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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); - int i, rc, log; - - for (i = 0; i < argc; i++) - if (util_dimm_filter(dimm, argv[i])) - break; - if (i >= argc) - return -ENODEV; - - log = ndctl_get_log_priority(ctx); - if (verbose) - ndctl_set_log_priority(ctx, LOG_DEBUG); - rc = ndctl_dimm_zero_labels(dimm); - ndctl_set_log_priority(ctx, log); - - return rc; -} - -int cmd_zero_labels(int argc, const char **argv, struct ndctl_ctx *ctx) -{ - const char *nmem_bus = NULL; - bool verbose = false; - const struct option nmem_options[] = { - OPT_STRING('b', "bus", &nmem_bus, "bus-id", - " must be on a bus with an id/provider of "), - OPT_BOOLEAN('v',"verbose", &verbose, "turn on debug"), - OPT_END(), - }; - const char * const u[] = { - "ndctl zero-labels [..] []", - NULL - }; - struct ndctl_dimm *dimm; - struct ndctl_bus *bus; - int i, rc, count, err = 0; - - argc = parse_options(argc, argv, nmem_options, u, 0); - - 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", &id) != 1) { - fprintf(stderr, "unknown extra parameter \"%s\"\n", - argv[i]); - usage_with_options(u, nmem_options); - } - } - - count = 0; - ndctl_bus_foreach(ctx, bus) { - if (!util_bus_filter(bus, nmem_bus)) - continue; - - ndctl_dimm_foreach(bus, dimm) { - rc = do_zero_dimm(dimm, argv, argc, verbose); - if (rc == 0) - count++; - else if (rc && !err) - err = rc; - } - } - rc = err; - - fprintf(stderr, "zeroed %d nmem%s\n", count, count > 1 ? "s" : ""); - - /* - * 0 if all dimms zeroed, count if at least 1 dimm zeroed, < 0 - * if all errors - */ - if (rc == 0) - return 0; - if (count) - return count; - return rc; -}