anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

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

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