From patchwork Thu Apr 26 18:17:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10366619 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 AA8D4601BE for ; Thu, 26 Apr 2018 18:17:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A4AC291B4 for ; Thu, 26 Apr 2018 18:17:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F136291BA; Thu, 26 Apr 2018 18:17:10 +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 29A03291B4 for ; Thu, 26 Apr 2018 18:17:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0F574203B9000; Thu, 26 Apr 2018 11:17:10 -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=192.55.52.88; helo=mga01.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 E3807203B8FF3 for ; Thu, 26 Apr 2018 11:17:08 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2018 11:17:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,331,1520924400"; d="scan'208";a="44855597" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by FMSMGA003.fm.intel.com with ESMTP; 26 Apr 2018 11:17:08 -0700 Subject: [PATCH v3 1/4] ndctl: convert namespace actions to use util_filter_params From: Dave Jiang To: vishal.l.verma@intel.com, dan.j.williams@intel.com Date: Thu, 26 Apr 2018 11:17:08 -0700 Message-ID: <152476662812.70161.4900273108048073021.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <152476632250.70161.9698682147434730585.stgit@djiang5-desk3.ch.intel.com> References: <152476632250.70161.9698682147434730585.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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: , Cc: linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP In preparation of moving to using util_filter_walk, moving parts of namespace params to util_filter_params. Signed-off-by: Dave Jiang --- ndctl/namespace.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index fe86d826..e61f500c 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -40,14 +40,11 @@ static struct parameters { bool mode_default; bool align_default; bool autolabel; - const char *bus; const char *map; - const char *type; const char *uuid; const char *name; const char *size; const char *mode; - const char *region; const char *reconfig; const char *sector_size; const char *align; @@ -55,6 +52,8 @@ static struct parameters { .autolabel = true, }; +struct util_filter_params uf_param; + void builtin_xaction_namespace_reset(void) { /* @@ -87,9 +86,9 @@ struct parsed_parameters { }}) #define BASE_OPTIONS() \ -OPT_STRING('b', "bus", ¶m.bus, "bus-id", \ +OPT_STRING('b', "bus", &uf_param.bus, "bus-id", \ "limit namespace to a bus with an id or provider of "), \ -OPT_STRING('r', "region", ¶m.region, "region-id", \ +OPT_STRING('r', "region", &uf_param.region, "region-id", \ "limit namespace to a region with an id or name of "), \ OPT_BOOLEAN('v', "verbose", &verbose, "emit extra debug messages to stderr") @@ -108,7 +107,7 @@ OPT_STRING('M', "map", ¶m.map, "memmap-location", \ "specify 'mem' or 'dev' for the location of the memmap"), \ OPT_STRING('l', "sector-size", ¶m.sector_size, "lba-size", \ "specify the logical sector size in bytes"), \ -OPT_STRING('t', "type", ¶m.type, "type", \ +OPT_STRING('t', "type", &uf_param.type, "type", \ "specify the type of namespace to create 'pmem' or 'blk'"), \ OPT_STRING('a', "align", ¶m.align, "align", \ "specify the namespace alignment in bytes (default: 2M)"), \ @@ -148,18 +147,18 @@ static int set_defaults(enum device_action mode) { int rc = 0; - if (param.type) { - if (strcmp(param.type, "pmem") == 0) + if (uf_param.type) { + if (strcmp(uf_param.type, "pmem") == 0) /* pass */; - else if (strcmp(param.type, "blk") == 0) + else if (strcmp(uf_param.type, "blk") == 0) /* pass */; else { error("invalid type '%s', must be either 'pmem' or 'blk'\n", - param.type); + uf_param.type); rc = -EINVAL; } } else if (!param.reconfig && mode == ACTION_CREATE) - param.type = "pmem"; + uf_param.type = "pmem"; if (param.mode) { if (strcmp(param.mode, "safe") == 0) @@ -180,8 +179,8 @@ static int set_defaults(enum device_action mode) error("invalid mode '%s'\n", param.mode); rc = -EINVAL; } - } else if (!param.reconfig && param.type) { - if (strcmp(param.type, "pmem") == 0) + } else if (!param.reconfig && uf_param.type) { + if (strcmp(uf_param.type, "pmem") == 0) param.mode = "memory"; else param.mode = "safe"; @@ -208,7 +207,7 @@ static int set_defaults(enum device_action mode) param.map = "dev"; /* check for incompatible mode and type combinations */ - if (param.type && param.mode && strcmp(param.type, "blk") == 0 + if (uf_param.type && param.mode && strcmp(uf_param.type, "blk") == 0 && (strcmp(param.mode, "memory") == 0 || strcmp(param.mode, "dax") == 0)) { error("only 'pmem' namespaces support dax operation\n"); @@ -244,7 +243,7 @@ static int set_defaults(enum device_action mode) error("invalid sector size: %s\n", param.sector_size); rc = -EINVAL; } - } else if (((param.type && strcmp(param.type, "blk") == 0) + } else if (((uf_param.type && strcmp(uf_param.type, "blk") == 0) || (param.mode && strcmp(param.mode, "safe") == 0))) { /* default sector size for blk-type or safe-mode */ param.sector_size = "4096"; @@ -1000,19 +999,19 @@ static int do_xaction_namespace(const char *namespace, ndctl_set_log_priority(ctx, LOG_DEBUG); ndctl_bus_foreach(ctx, bus) { - if (!util_bus_filter(bus, param.bus)) + if (!util_bus_filter(bus, uf_param.bus)) continue; ndctl_region_foreach(bus, region) { - if (!util_region_filter(region, param.region)) + if (!util_region_filter(region, uf_param.region)) continue; - if (param.type) { - if (strcmp(param.type, "pmem") == 0 + if (uf_param.type) { + if (strcmp(uf_param.type, "pmem") == 0 && ndctl_region_get_type(region) == ND_DEVICE_REGION_PMEM) /* pass */; - else if (strcmp(param.type, "blk") == 0 + else if (strcmp(uf_param.type, "blk") == 0 && ndctl_region_get_type(region) == ND_DEVICE_REGION_BLK) /* pass */; @@ -1125,7 +1124,7 @@ int cmd_create_namespace(int argc, const char **argv, void *ctx) * fallback to blk before giving up. */ memset(¶m, 0, sizeof(param)); - param.type = "blk"; + uf_param.type = "blk"; set_defaults(ACTION_CREATE); created = do_xaction_namespace(NULL, ACTION_CREATE, ctx); }