From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Cc: vishal.l.verma@intel.com
Subject: [ndctl PATCH 20/36] ndctl/namespace: Introduce mode-to-name and name-to-mode helpers
Date: Sat, 29 Feb 2020 12:21:50 -0800 [thread overview]
Message-ID: <158300771041.2141307.11811224712955268465.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <158300760415.2141307.14060353322051900501.stgit@dwillia2-desk3.amr.corp.intel.com>
Before open coding yet another translation between modes and their text
name, introduce a util_nsmode() and util_nsmode_name() helpers.
Consolidate the existing mode_to_type() helper into the new common /
public util.
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
ndctl/namespace.c | 39 +++++++--------------------------------
util/filter.c | 42 +++++++++++++++++++++++++++---------------
util/filter.h | 3 +++
3 files changed, 37 insertions(+), 47 deletions(-)
diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 770caa5ebab0..1747a061d5b7 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -214,21 +214,7 @@ static int set_defaults(enum device_action mode)
param.type = "pmem";
if (param.mode) {
- if (strcmp(param.mode, "safe") == 0)
- /* pass */;
- else if (strcmp(param.mode, "sector") == 0)
- param.mode = "safe"; /* pass */
- else if (strcmp(param.mode, "memory") == 0)
- /* pass */;
- else if (strcmp(param.mode, "fsdax") == 0)
- param.mode = "memory"; /* pass */
- else if (strcmp(param.mode, "raw") == 0)
- /* pass */;
- else if (strcmp(param.mode, "dax") == 0)
- /* pass */;
- else if (strcmp(param.mode, "devdax") == 0)
- param.mode = "dax"; /* pass */
- else {
+ if (util_nsmode(param.mode) == NDCTL_NS_MODE_UNKNOWN) {
error("invalid mode '%s'\n", param.mode);
rc = -EINVAL;
}
@@ -294,7 +280,7 @@ static int set_defaults(enum device_action mode)
rc = -EINVAL;
}
} else if (((param.type && strcmp(param.type, "blk") == 0)
- || (param.mode && strcmp(param.mode, "safe") == 0))) {
+ || util_nsmode(param.mode) == NDCTL_NS_MODE_SECTOR)) {
/* default sector size for blk-type or safe-mode */
param.sector_size = "4096";
}
@@ -585,23 +571,12 @@ static int validate_namespace_options(struct ndctl_region *region,
}
if (param.mode) {
- if (strcmp(param.mode, "memory") == 0)
- p->mode = NDCTL_NS_MODE_FSDAX;
- else if (strcmp(param.mode, "sector") == 0)
- p->mode = NDCTL_NS_MODE_SECTOR;
- else if (strcmp(param.mode, "safe") == 0)
- p->mode = NDCTL_NS_MODE_SECTOR;
- else if (strcmp(param.mode, "dax") == 0)
- p->mode = NDCTL_NS_MODE_DEVDAX;
- else
- p->mode = NDCTL_NS_MODE_RAW;
-
+ p->mode = util_nsmode(param.mode);
if (ndctl_region_get_type(region) != ND_DEVICE_REGION_PMEM
&& (p->mode == NDCTL_NS_MODE_FSDAX
|| p->mode == NDCTL_NS_MODE_DEVDAX)) {
err("blk %s does not support %s mode\n", region_name,
- p->mode == NDCTL_NS_MODE_FSDAX
- ? "fsdax" : "devdax");
+ util_nsmode_name(p->mode));
return -EAGAIN;
}
} else if (ndns)
@@ -619,7 +594,8 @@ static int validate_namespace_options(struct ndctl_region *region,
} else if (p->mode == NDCTL_NS_MODE_DEVDAX) {
dax = ndctl_region_get_dax_seed(region);
if (!dax) {
- error("Kernel does not support devdax mode\n");
+ error("Kernel does not support %s mode\n",
+ util_nsmode_name(p->mode));
return -ENODEV;
}
}
@@ -643,8 +619,7 @@ static int validate_namespace_options(struct ndctl_region *region,
default:
error("%s mode does not support setting an alignment\n",
- p->mode == NDCTL_NS_MODE_SECTOR
- ? "sector" : "raw");
+ util_nsmode_name(p->mode));
return -ENXIO;
}
diff --git a/util/filter.c b/util/filter.c
index 9f6b65a70117..af72793929e2 100644
--- a/util/filter.c
+++ b/util/filter.c
@@ -351,29 +351,41 @@ struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region,
return NULL;
}
-static enum ndctl_namespace_mode mode_to_type(const char *mode)
+enum ndctl_namespace_mode util_nsmode(const char *mode)
{
if (!mode)
- return -ENXIO;
-
+ return NDCTL_NS_MODE_UNKNOWN;
if (strcasecmp(mode, "memory") == 0)
- return NDCTL_NS_MODE_MEMORY;
- else if (strcasecmp(mode, "fsdax") == 0)
- return NDCTL_NS_MODE_MEMORY;
- else if (strcasecmp(mode, "sector") == 0)
+ return NDCTL_NS_MODE_FSDAX;
+ if (strcasecmp(mode, "fsdax") == 0)
+ return NDCTL_NS_MODE_FSDAX;
+ if (strcasecmp(mode, "sector") == 0)
return NDCTL_NS_MODE_SECTOR;
- else if (strcasecmp(mode, "safe") == 0)
+ if (strcasecmp(mode, "safe") == 0)
return NDCTL_NS_MODE_SECTOR;
- else if (strcasecmp(mode, "dax") == 0)
- return NDCTL_NS_MODE_DAX;
- else if (strcasecmp(mode, "devdax") == 0)
- return NDCTL_NS_MODE_DAX;
- else if (strcasecmp(mode, "raw") == 0)
+ if (strcasecmp(mode, "dax") == 0)
+ return NDCTL_NS_MODE_DEVDAX;
+ if (strcasecmp(mode, "devdax") == 0)
+ return NDCTL_NS_MODE_DEVDAX;
+ if (strcasecmp(mode, "raw") == 0)
return NDCTL_NS_MODE_RAW;
return NDCTL_NS_MODE_UNKNOWN;
}
+const char *util_nsmode_name(enum ndctl_namespace_mode mode)
+{
+ static const char * const modes[] = {
+ [NDCTL_NS_MODE_FSDAX] = "fsdax",
+ [NDCTL_NS_MODE_DEVDAX] = "devdax",
+ [NDCTL_NS_MODE_RAW] = "raw",
+ [NDCTL_NS_MODE_SECTOR] = "sector",
+ [NDCTL_NS_MODE_UNKNOWN] = "unknown",
+ };
+
+ return modes[mode];
+}
+
int util_filter_walk(struct ndctl_ctx *ctx, struct util_filter_ctx *fctx,
struct util_filter_params *param)
{
@@ -396,7 +408,7 @@ int util_filter_walk(struct ndctl_ctx *ctx, struct util_filter_ctx *fctx,
type = ND_DEVICE_REGION_BLK;
}
- if (mode_to_type(param->mode) == NDCTL_NS_MODE_UNKNOWN) {
+ if (param->mode && util_nsmode(param->mode) == NDCTL_NS_MODE_UNKNOWN) {
error("invalid mode: '%s'\n", param->mode);
return -EINVAL;
}
@@ -474,7 +486,7 @@ int util_filter_walk(struct ndctl_ctx *ctx, struct util_filter_ctx *fctx,
continue;
mode = ndctl_namespace_get_mode(ndns);
- if (param->mode && mode_to_type(param->mode) != mode)
+ if (param->mode && util_nsmode(param->mode) != mode)
continue;
fctx->filter_namespace(ndns, fctx);
diff --git a/util/filter.h b/util/filter.h
index 0c12b94218d6..ad3441cc3a16 100644
--- a/util/filter.h
+++ b/util/filter.h
@@ -40,6 +40,9 @@ struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev,
struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region,
const char *ident);
+enum ndctl_namespace_mode util_nsmode(const char *mode);
+const char *util_nsmode_name(enum ndctl_namespace_mode mode);
+
struct json_object;
/* json object hierarchy for the util_filter_walk() performed by cmd_list() */
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
next prev parent reply other threads:[~2020-02-29 20:37 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-29 20:20 [ndctl PATCH 00/36] Multiple topics / backlog for v68 Dan Williams
2020-02-29 20:20 ` [ndctl PATCH 01/36] ndctl/list: Add 'target_node' to region and namespace verbose listings Dan Williams
2020-02-29 20:20 ` [ndctl PATCH 02/36] ndctl/docs: Fix mailing list sign-up link Dan Williams
2020-02-29 20:20 ` [ndctl PATCH 03/36] ndctl/list: Drop named list objects from verbose listing Dan Williams
2020-02-29 20:20 ` [ndctl PATCH 04/36] daxctl/list: Avoid memory operations without resource data Dan Williams
2020-02-29 20:20 ` [ndctl PATCH 05/36] ndctl/build: Fix distcheck Dan Williams
2020-02-29 20:20 ` [ndctl PATCH 06/36] ndctl/namespace: Fix destroy-namespace accounting relative to seed devices Dan Williams
2020-02-29 20:20 ` [ndctl PATCH 07/36] ndctl/region: Support ndctl_region_{get, set}_align() Dan Williams
2020-02-29 20:20 ` [ndctl PATCH 08/36] ndctl/namespace: Emit better errors on failure Dan Williams
2020-02-29 20:20 ` [ndctl PATCH 09/36] ndctl/namespace: Check for region alignment violations Dan Williams
2020-02-29 20:20 ` [ndctl PATCH 10/36] ndctl/util: Up-level is_power_of_2() and introduce IS_ALIGNED Dan Williams
2020-02-29 20:21 ` [ndctl PATCH 11/36] ndctl/namespace: Validate resource alignment for dax-mode namespaces Dan Williams
2020-02-29 20:21 ` [ndctl PATCH 12/36] ndctl/namespace: Add read-infoblock command Dan Williams
2020-02-29 20:21 ` [ndctl PATCH 13/36] ndctl/test: Update dax-dev to handle multiple e820 ranges Dan Williams
2020-02-29 20:21 ` [ndctl PATCH 14/36] ndctl/namespace: Always zero info-blocks Dan Williams
2020-02-29 20:21 ` [ndctl PATCH 15/36] ndctl/namespace: Disable autorecovery of create-namespace failures Dan Williams
2020-02-29 20:21 ` [ndctl PATCH 16/36] ndctl/build: Fix EXTRA_DIST already defined errors Dan Williams
2020-02-29 20:21 ` [ndctl PATCH 17/36] ndctl/test: Checkout device-mapper + dax operation Dan Williams
2020-02-29 20:21 ` [ndctl PATCH 18/36] ndctl/test: Exercise sub-section sized namespace creation/deletion Dan Williams
2020-02-29 20:21 ` [ndctl PATCH 19/36] ndctl/namespace: Kill off the legacy mode names Dan Williams
2020-02-29 20:21 ` Dan Williams [this message]
2020-02-29 20:21 ` [ndctl PATCH 21/36] ndctl/namespace: Validate namespace size within validate_namespace_options() Dan Williams
2020-02-29 20:22 ` [ndctl PATCH 22/36] ndctl/namespace: Clarify 16M minimum size requirement Dan Williams
2020-02-29 20:22 ` [ndctl PATCH 23/36] ndctl/test: Regression test 'failed to track' Dan Williams
2020-02-29 20:22 ` [ndctl PATCH 24/36] ndctl/dimm: Rework dimm command status reporting Dan Williams
2020-02-29 20:22 ` [ndctl PATCH 25/36] ndctl/dimm: Rework iteration to drop unaligned pointers Dan Williams
2020-02-29 20:22 ` [ndctl PATCH 26/36] ndctl/test: Fix typos / loss of tpm.handle in security test Dan Williams
2020-02-29 20:22 ` [ndctl PATCH 27/36] ndctl/test: Relax dax_pmem_compat requirement Dan Williams
2020-03-03 13:28 ` Jan Kara
2020-03-03 21:05 ` Dan Williams
2020-03-03 22:58 ` [ndctl PATCH v2 1/2] ndctl/test: Cleanup test-vs-production nvdimm module detection Dan Williams
2020-03-04 12:44 ` Jan Kara
2020-03-03 22:58 ` [ndctl PATCH v2 2/2] ndctl/test: Relax dax_pmem_compat requirement Dan Williams
2020-03-04 12:44 ` Jan Kara
2020-02-29 20:22 ` [ndctl PATCH 28/36] ndctl/namespace: Fix namespace-action vs namespace-mode confusion Dan Williams
2020-02-29 20:22 ` [ndctl PATCH 29/36] ndctl/namespace: Update 'pfn' infoblock definition Dan Williams
2020-02-29 20:22 ` [ndctl PATCH 30/36] ndctl/util: Return 0 for NULL arguments to parse_size64() Dan Williams
2020-02-29 20:22 ` [ndctl PATCH 31/36] ndctl/namespace: Fix read-info-block vs read-infoblock Dan Williams
2020-02-29 20:22 ` [ndctl PATCH 32/36] ndctl/namespace: Parse infoblocks from stdin Dan Williams
2020-02-29 20:23 ` [ndctl PATCH 33/36] ndctl/namespace: Add write-infoblock command Dan Williams
2020-02-29 20:23 ` [ndctl PATCH 34/36] ndctl/list: Add option to list configured + disabled namespaces Dan Williams
2020-02-29 20:23 ` [ndctl PATCH 35/36] ndctl/lib/namespace: Fix resource retrieval after size change Dan Williams
2020-02-29 20:23 ` [ndctl PATCH 36/36] ndctl/test: Regression test misaligned namespaces Dan Williams
2020-03-19 4:13 ` [ndctl PATCH 00/36] Multiple topics / backlog for v68 Verma, Vishal L
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=158300771041.2141307.11811224712955268465.stgit@dwillia2-desk3.amr.corp.intel.com \
--to=dan.j.williams@intel.com \
--cc=linux-nvdimm@lists.01.org \
--cc=vishal.l.verma@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).