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

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