anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

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

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