linux-cxl.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: linux-cxl@vger.kernel.org
Cc: vishal.l.verma@intel.com
Subject: [ndctl PATCH 26/37] cxl/memdev: Add serial support for memdev-related commands
Date: Sun, 23 Jan 2022 16:54:06 -0800	[thread overview]
Message-ID: <164298564631.3021641.5552442288217413180.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <164298550885.3021641.11210386002804544864.stgit@dwillia2-desk3.amr.corp.intel.com>

Allow for a "-s, --serial" option to turn the argument list into serial
identifiers.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 Documentation/cxl/memdev-option.txt |    5 ++++
 Documentation/cxl/meson.build       |    4 ++-
 cxl/memdev.c                        |   45 ++++++++++++++++++++++++++---------
 3 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/Documentation/cxl/memdev-option.txt b/Documentation/cxl/memdev-option.txt
index e7785827ab4c..64348bed1791 100644
--- a/Documentation/cxl/memdev-option.txt
+++ b/Documentation/cxl/memdev-option.txt
@@ -2,3 +2,8 @@
 A 'memX' device name, or a memdev id number. Restrict the operation to
 the specified memdev(s). The keyword 'all' can be specified to indicate
 the lack of any restriction.
+
+-S::
+--serial::
+	Rather an a memdev id number, interpret the <memdev> argument(s)
+	as a list of serial numbers.
diff --git a/Documentation/cxl/meson.build b/Documentation/cxl/meson.build
index 64ce13f59012..0a6346bc47ca 100644
--- a/Documentation/cxl/meson.build
+++ b/Documentation/cxl/meson.build
@@ -19,7 +19,9 @@ else
 endif
 
 filedeps = [
-        '../copyright.txt',
+  '../copyright.txt',
+  'memdev-option.txt',
+  'labels-options.txt',
 ]
 
 cxl_manpages = [
diff --git a/cxl/memdev.c b/cxl/memdev.c
index 4cca8b8c10be..ef5343ad892b 100644
--- a/cxl/memdev.c
+++ b/cxl/memdev.c
@@ -24,12 +24,14 @@ static struct parameters {
 	unsigned len;
 	unsigned offset;
 	bool verbose;
+	bool serial;
 } param;
 
 static struct log_ctx ml;
 
 #define BASE_OPTIONS() \
-OPT_BOOLEAN('v',"verbose", &param.verbose, "turn on debug")
+OPT_BOOLEAN('v',"verbose", &param.verbose, "turn on debug"), \
+OPT_BOOLEAN('S', "serial", &param.serial, "user serials numbers to id memdevs")
 
 #define READ_OPTIONS() \
 OPT_STRING('o', "output", &param.outfile, "output-file", \
@@ -172,8 +174,9 @@ out:
 }
 
 static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
-		int (*action)(struct cxl_memdev *memdev, struct action_context *actx),
-		const struct option *options, const char *usage)
+			 int (*action)(struct cxl_memdev *memdev,
+				       struct action_context *actx),
+			 const struct option *options, const char *usage)
 {
 	struct cxl_memdev *memdev, *single = NULL;
 	struct action_context actx = { 0 };
@@ -190,16 +193,25 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
 	if (argc == 0)
 		usage_with_options(u, options);
 	for (i = 0; i < argc; i++) {
-		if (strcmp(argv[i], "all") == 0) {
-			argc = 1;
-			break;
+		if (param.serial) {
+			char *end;
+
+			strtoull(argv[i], &end, 0);
+			if (end[0] == 0)
+				continue;
+		} else {
+			if (strcmp(argv[i], "all") == 0) {
+				argc = 1;
+				break;
+			}
+			if (sscanf(argv[i], "mem%lu", &id) == 1)
+				continue;
+			if (sscanf(argv[i], "%lu", &id) == 1)
+				continue;
 		}
-		if (sscanf(argv[i], "mem%lu", &id) == 1)
-			continue;
-		if (sscanf(argv[i], "%lu", &id) == 1)
-			continue;
 
-		log_err(&ml, "'%s' is not a valid memdev name\n", argv[i]);
+		log_err(&ml, "'%s' is not a valid memdev %s\n", argv[i],
+			param.serial ? "serial number" : "name");
 		err++;
 	}
 
@@ -244,7 +256,16 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
 
 	for (i = 0; i < argc; i++) {
 		cxl_memdev_foreach(ctx, memdev) {
-			if (!util_cxl_memdev_filter(memdev, argv[i], NULL))
+			const char *memdev_filter = NULL;
+			const char *serial_filter = NULL;
+
+			if (param.serial)
+				serial_filter = argv[i];
+			else
+				memdev_filter = argv[i];
+
+			if (!util_cxl_memdev_filter(memdev, memdev_filter,
+						    serial_filter))
 				continue;
 
 			if (action == action_write) {


  parent reply	other threads:[~2022-01-24  0:54 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24  0:51 [ndctl PATCH 00/37] cxl: Full topology enumeration Dan Williams
2022-01-24  0:51 ` [ndctl PATCH 01/37] test: Add 'suite' identifiers to tests Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 02/37] ndctl: Rename util_filter to ndctl_filter Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 03/37] build: Add tags Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 04/37] json: Add support for json_object_new_uint64() Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 05/37] cxl/json: Cleanup object leak false positive Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 06/37] cxl/list: Support multiple memdev device name filter arguments Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 07/37] cxl/list: Support comma separated lists Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 08/37] cxl/list: Introduce cxl_filter_walk() Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 09/37] cxl/list: Emit device serial numbers Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 10/37] cxl/list: Add filter by serial support Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 11/37] cxl/lib: Rename nvdimm bridge to pmem Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 12/37] cxl/list: Cleanup options definitions Dan Williams
2022-01-24  0:52 ` [ndctl PATCH 13/37] Documentation: Enhance libcxl memdev API documentation Dan Williams
2022-01-24  0:53 ` [ndctl PATCH 14/37] cxl/list: Add bus objects Dan Williams
2022-01-24  0:53 ` [ndctl PATCH 15/37] util/json: Warn on stderr about empty list results Dan Williams
2022-01-24  0:53 ` [ndctl PATCH 16/37] util/sysfs: Uplevel modalias lookup helper to util/ Dan Williams
2022-01-24  0:53 ` [ndctl PATCH 17/37] cxl/list: Add port enumeration Dan Williams
2022-01-24  0:53 ` [ndctl PATCH 18/37] cxl/list: Add --debug option Dan Williams
2022-01-24  0:53 ` [ndctl PATCH 19/37] cxl/list: Add endpoints Dan Williams
2022-01-24  0:53 ` [ndctl PATCH 20/37] cxl/list: Add 'host' entries for port-like objects Dan Williams
2022-01-24  0:53 ` [ndctl PATCH 21/37] cxl/list: Add 'host' entries for memdevs Dan Williams
2022-01-24  0:53 ` [ndctl PATCH 22/37] cxl/list: Move enabled memdevs underneath their endpoint Dan Williams
2022-01-24  0:53 ` [ndctl PATCH 23/37] cxl/list: Filter memdev by ancestry Dan Williams
2022-01-24  0:53 ` [ndctl PATCH 24/37] cxl/memdev: Use a local logger for debug Dan Williams
2022-01-24  0:54 ` [ndctl PATCH 25/37] cxl/memdev: Cleanup memdev filter Dan Williams
2022-01-24  0:54 ` Dan Williams [this message]
2022-02-10  1:10   ` [ndctl PATCH 26/37] cxl/memdev: Add serial support for memdev-related commands Alison Schofield
2022-02-10  1:55     ` Dan Williams
2022-01-24  0:54 ` [ndctl PATCH 27/37] cxl/list: Add 'numa_node' to memdev listings Dan Williams
2022-01-24  0:54 ` [ndctl PATCH 28/37] util: Implement common bind/unbind helpers Dan Williams
2022-01-24  0:54 ` [ndctl PATCH 29/37] cxl/memdev: Enable / disable support Dan Williams
2022-01-24  0:54 ` [ndctl PATCH 30/37] cxl/list: Add decoder support Dan Williams
2022-01-24  0:54 ` [ndctl PATCH 31/37] cxl/list: Extend decoder objects with target information Dan Williams
2022-01-24  0:54 ` [ndctl PATCH 32/37] cxl/list: Use 'physical_node' for root port attachment detection Dan Williams
2022-01-24  0:54 ` [ndctl PATCH 33/37] cxl/list: Reuse the --target option for ports Dan Williams
2022-01-24  0:54 ` [ndctl PATCH 34/37] cxl/list: Support filtering memdevs by decoders Dan Williams
2022-01-24  0:54 ` [ndctl PATCH 35/37] cxl/list: Support filtering memdevs by ports Dan Williams
2022-01-24  0:55 ` [ndctl PATCH 36/37] cxl/port: Add {disable,enable}-port command Dan Williams
2022-01-24  0:55 ` [ndctl PATCH 37/37] cxl/list: Filter dports and targets by memdevs Dan Williams

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=164298564631.3021641.5552442288217413180.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-cxl@vger.kernel.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).