Blame SOURCES/0112-cxl-memdev-Add-serial-support-for-memdev-related-com.patch

2eb93d
From c09c507e5a608718ac96af088fdc8cb441b09d0b Mon Sep 17 00:00:00 2001
2eb93d
From: Dan Williams <dan.j.williams@intel.com>
2eb93d
Date: Sun, 23 Jan 2022 16:54:06 -0800
2eb93d
Subject: [PATCH 112/217] cxl/memdev: Add serial support for memdev-related
2eb93d
 commands
2eb93d
2eb93d
Allow for a "-s, --serial" option to turn the argument list into serial
2eb93d
identifiers.
2eb93d
2eb93d
Link: https://lore.kernel.org/r/164298564631.3021641.5552442288217413180.stgit@dwillia2-desk3.amr.corp.intel.com
2eb93d
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 Documentation/cxl/memdev-option.txt |  5 ++++
2eb93d
 Documentation/cxl/meson.build       |  4 ++-
2eb93d
 cxl/memdev.c                        | 45 +++++++++++++++++++++--------
2eb93d
 3 files changed, 41 insertions(+), 13 deletions(-)
2eb93d
2eb93d
diff --git a/Documentation/cxl/memdev-option.txt b/Documentation/cxl/memdev-option.txt
2eb93d
index e778582..64348be 100644
2eb93d
--- a/Documentation/cxl/memdev-option.txt
2eb93d
+++ b/Documentation/cxl/memdev-option.txt
2eb93d
@@ -2,3 +2,8 @@
2eb93d
 A 'memX' device name, or a memdev id number. Restrict the operation to
2eb93d
 the specified memdev(s). The keyword 'all' can be specified to indicate
2eb93d
 the lack of any restriction.
2eb93d
+
2eb93d
+-S::
2eb93d
+--serial::
2eb93d
+	Rather an a memdev id number, interpret the <memdev> argument(s)
2eb93d
+	as a list of serial numbers.
2eb93d
diff --git a/Documentation/cxl/meson.build b/Documentation/cxl/meson.build
2eb93d
index 64ce13f..0a6346b 100644
2eb93d
--- a/Documentation/cxl/meson.build
2eb93d
+++ b/Documentation/cxl/meson.build
2eb93d
@@ -19,7 +19,9 @@ else
2eb93d
 endif
2eb93d
 
2eb93d
 filedeps = [
2eb93d
-        '../copyright.txt',
2eb93d
+  '../copyright.txt',
2eb93d
+  'memdev-option.txt',
2eb93d
+  'labels-options.txt',
2eb93d
 ]
2eb93d
 
2eb93d
 cxl_manpages = [
2eb93d
diff --git a/cxl/memdev.c b/cxl/memdev.c
2eb93d
index 4cca8b8..ef5343a 100644
2eb93d
--- a/cxl/memdev.c
2eb93d
+++ b/cxl/memdev.c
2eb93d
@@ -24,12 +24,14 @@ static struct parameters {
2eb93d
 	unsigned len;
2eb93d
 	unsigned offset;
2eb93d
 	bool verbose;
2eb93d
+	bool serial;
2eb93d
 } param;
2eb93d
 
2eb93d
 static struct log_ctx ml;
2eb93d
 
2eb93d
 #define BASE_OPTIONS() \
2eb93d
-OPT_BOOLEAN('v',"verbose", &param.verbose, "turn on debug")
2eb93d
+OPT_BOOLEAN('v',"verbose", &param.verbose, "turn on debug"), \
2eb93d
+OPT_BOOLEAN('S', "serial", &param.serial, "user serials numbers to id memdevs")
2eb93d
 
2eb93d
 #define READ_OPTIONS() \
2eb93d
 OPT_STRING('o', "output", &param.outfile, "output-file", \
2eb93d
@@ -172,8 +174,9 @@ out:
2eb93d
 }
2eb93d
 
2eb93d
 static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
2eb93d
-		int (*action)(struct cxl_memdev *memdev, struct action_context *actx),
2eb93d
-		const struct option *options, const char *usage)
2eb93d
+			 int (*action)(struct cxl_memdev *memdev,
2eb93d
+				       struct action_context *actx),
2eb93d
+			 const struct option *options, const char *usage)
2eb93d
 {
2eb93d
 	struct cxl_memdev *memdev, *single = NULL;
2eb93d
 	struct action_context actx = { 0 };
2eb93d
@@ -190,16 +193,25 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
2eb93d
 	if (argc == 0)
2eb93d
 		usage_with_options(u, options);
2eb93d
 	for (i = 0; i < argc; i++) {
2eb93d
-		if (strcmp(argv[i], "all") == 0) {
2eb93d
-			argc = 1;
2eb93d
-			break;
2eb93d
+		if (param.serial) {
2eb93d
+			char *end;
2eb93d
+
2eb93d
+			strtoull(argv[i], &end, 0);
2eb93d
+			if (end[0] == 0)
2eb93d
+				continue;
2eb93d
+		} else {
2eb93d
+			if (strcmp(argv[i], "all") == 0) {
2eb93d
+				argc = 1;
2eb93d
+				break;
2eb93d
+			}
2eb93d
+			if (sscanf(argv[i], "mem%lu", &id) == 1)
2eb93d
+				continue;
2eb93d
+			if (sscanf(argv[i], "%lu", &id) == 1)
2eb93d
+				continue;
2eb93d
 		}
2eb93d
-		if (sscanf(argv[i], "mem%lu", &id) == 1)
2eb93d
-			continue;
2eb93d
-		if (sscanf(argv[i], "%lu", &id) == 1)
2eb93d
-			continue;
2eb93d
 
2eb93d
-		log_err(&ml, "'%s' is not a valid memdev name\n", argv[i]);
2eb93d
+		log_err(&ml, "'%s' is not a valid memdev %s\n", argv[i],
2eb93d
+			param.serial ? "serial number" : "name");
2eb93d
 		err++;
2eb93d
 	}
2eb93d
 
2eb93d
@@ -244,7 +256,16 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
2eb93d
 
2eb93d
 	for (i = 0; i < argc; i++) {
2eb93d
 		cxl_memdev_foreach(ctx, memdev) {
2eb93d
-			if (!util_cxl_memdev_filter(memdev, argv[i], NULL))
2eb93d
+			const char *memdev_filter = NULL;
2eb93d
+			const char *serial_filter = NULL;
2eb93d
+
2eb93d
+			if (param.serial)
2eb93d
+				serial_filter = argv[i];
2eb93d
+			else
2eb93d
+				memdev_filter = argv[i];
2eb93d
+
2eb93d
+			if (!util_cxl_memdev_filter(memdev, memdev_filter,
2eb93d
+						    serial_filter))
2eb93d
 				continue;
2eb93d
 
2eb93d
 			if (action == action_write) {
2eb93d
-- 
2eb93d
2.27.0
2eb93d