|
|
26ccd9 |
From d7854adcd1e517d2372ec51f4a1ede2d549975e8 Mon Sep 17 00:00:00 2001
|
|
|
26ccd9 |
From: Dan Williams <dan.j.williams@intel.com>
|
|
|
26ccd9 |
Date: Sun, 23 Jan 2022 16:52:41 -0800
|
|
|
26ccd9 |
Subject: [PATCH 096/217] cxl/list: Add filter by serial support
|
|
|
26ccd9 |
|
|
|
26ccd9 |
Given that serial numbers are intended to be unique device identifiers,
|
|
|
26ccd9 |
enable them as a memdev filter option.
|
|
|
26ccd9 |
|
|
|
26ccd9 |
Link: https://lore.kernel.org/r/164298556167.3021641.5470955268978068465.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/cxl-list.txt | 4 ++++
|
|
|
26ccd9 |
cxl/filter.c | 38 ++++++++++++++++++++++++++++++----
|
|
|
26ccd9 |
cxl/filter.h | 4 +++-
|
|
|
26ccd9 |
cxl/list.c | 4 +++-
|
|
|
26ccd9 |
cxl/memdev.c | 2 +-
|
|
|
26ccd9 |
5 files changed, 45 insertions(+), 7 deletions(-)
|
|
|
26ccd9 |
|
|
|
26ccd9 |
diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt
|
|
|
26ccd9 |
index bd0207e..224c972 100644
|
|
|
26ccd9 |
--- a/Documentation/cxl/cxl-list.txt
|
|
|
26ccd9 |
+++ b/Documentation/cxl/cxl-list.txt
|
|
|
26ccd9 |
@@ -64,6 +64,10 @@ OPTIONS
|
|
|
26ccd9 |
]
|
|
|
26ccd9 |
----
|
|
|
26ccd9 |
|
|
|
26ccd9 |
+-s::
|
|
|
26ccd9 |
+--serial=::
|
|
|
26ccd9 |
+ Specify CXL memory device serial number(s) to filter the listing
|
|
|
26ccd9 |
+
|
|
|
26ccd9 |
-M::
|
|
|
26ccd9 |
--memdevs::
|
|
|
26ccd9 |
Include CXL memory devices in the listing
|
|
|
26ccd9 |
diff --git a/cxl/filter.c b/cxl/filter.c
|
|
|
26ccd9 |
index d1ff4b6..26efc65 100644
|
|
|
26ccd9 |
--- a/cxl/filter.c
|
|
|
26ccd9 |
+++ b/cxl/filter.c
|
|
|
26ccd9 |
@@ -21,15 +21,45 @@ static const char *which_sep(const char *filter)
|
|
|
26ccd9 |
return " ";
|
|
|
26ccd9 |
}
|
|
|
26ccd9 |
|
|
|
26ccd9 |
+static struct cxl_memdev *
|
|
|
26ccd9 |
+util_cxl_memdev_serial_filter(struct cxl_memdev *memdev, const char *__serials)
|
|
|
26ccd9 |
+{
|
|
|
26ccd9 |
+ unsigned long long serial = 0;
|
|
|
26ccd9 |
+ char *serials, *save, *end;
|
|
|
26ccd9 |
+ const char *arg;
|
|
|
26ccd9 |
+
|
|
|
26ccd9 |
+ if (!__serials)
|
|
|
26ccd9 |
+ return memdev;
|
|
|
26ccd9 |
+
|
|
|
26ccd9 |
+ serials = strdup(__serials);
|
|
|
26ccd9 |
+ if (!serials)
|
|
|
26ccd9 |
+ return NULL;
|
|
|
26ccd9 |
+
|
|
|
26ccd9 |
+ for (arg = strtok_r(serials, which_sep(__serials), &save); arg;
|
|
|
26ccd9 |
+ arg = strtok_r(NULL, which_sep(__serials), &save)) {
|
|
|
26ccd9 |
+ serial = strtoull(arg, &end, 0);
|
|
|
26ccd9 |
+ if (!arg[0] || end[0] != 0)
|
|
|
26ccd9 |
+ continue;
|
|
|
26ccd9 |
+ if (cxl_memdev_get_serial(memdev) == serial)
|
|
|
26ccd9 |
+ break;
|
|
|
26ccd9 |
+ }
|
|
|
26ccd9 |
+
|
|
|
26ccd9 |
+ free(serials);
|
|
|
26ccd9 |
+ if (arg)
|
|
|
26ccd9 |
+ return memdev;
|
|
|
26ccd9 |
+ return NULL;
|
|
|
26ccd9 |
+}
|
|
|
26ccd9 |
+
|
|
|
26ccd9 |
struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
|
|
|
26ccd9 |
- const char *__ident)
|
|
|
26ccd9 |
+ const char *__ident,
|
|
|
26ccd9 |
+ const char *serials)
|
|
|
26ccd9 |
{
|
|
|
26ccd9 |
char *ident, *save;
|
|
|
26ccd9 |
const char *name;
|
|
|
26ccd9 |
int memdev_id;
|
|
|
26ccd9 |
|
|
|
26ccd9 |
if (!__ident)
|
|
|
26ccd9 |
- return memdev;
|
|
|
26ccd9 |
+ return util_cxl_memdev_serial_filter(memdev, serials);
|
|
|
26ccd9 |
|
|
|
26ccd9 |
ident = strdup(__ident);
|
|
|
26ccd9 |
if (!ident)
|
|
|
26ccd9 |
@@ -51,7 +81,7 @@ struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
|
|
|
26ccd9 |
|
|
|
26ccd9 |
free(ident);
|
|
|
26ccd9 |
if (name)
|
|
|
26ccd9 |
- return memdev;
|
|
|
26ccd9 |
+ return util_cxl_memdev_serial_filter(memdev, serials);
|
|
|
26ccd9 |
return NULL;
|
|
|
26ccd9 |
}
|
|
|
26ccd9 |
|
|
|
26ccd9 |
@@ -82,7 +112,7 @@ int cxl_filter_walk(struct cxl_ctx *ctx, struct cxl_filter_params *p)
|
|
|
26ccd9 |
cxl_memdev_foreach(ctx, memdev) {
|
|
|
26ccd9 |
struct json_object *jdev;
|
|
|
26ccd9 |
|
|
|
26ccd9 |
- if (!util_cxl_memdev_filter(memdev, p->memdev_filter))
|
|
|
26ccd9 |
+ if (!util_cxl_memdev_filter(memdev, p->memdev_filter, p->serial_filter))
|
|
|
26ccd9 |
continue;
|
|
|
26ccd9 |
if (p->memdevs) {
|
|
|
26ccd9 |
jdev = util_cxl_memdev_to_json(memdev, flags);
|
|
|
26ccd9 |
diff --git a/cxl/filter.h b/cxl/filter.h
|
|
|
26ccd9 |
index 664b74b..12d9344 100644
|
|
|
26ccd9 |
--- a/cxl/filter.h
|
|
|
26ccd9 |
+++ b/cxl/filter.h
|
|
|
26ccd9 |
@@ -8,6 +8,7 @@
|
|
|
26ccd9 |
|
|
|
26ccd9 |
struct cxl_filter_params {
|
|
|
26ccd9 |
const char *memdev_filter;
|
|
|
26ccd9 |
+ const char *serial_filter;
|
|
|
26ccd9 |
bool memdevs;
|
|
|
26ccd9 |
bool idle;
|
|
|
26ccd9 |
bool human;
|
|
|
26ccd9 |
@@ -16,6 +17,7 @@ struct cxl_filter_params {
|
|
|
26ccd9 |
};
|
|
|
26ccd9 |
|
|
|
26ccd9 |
struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
|
|
|
26ccd9 |
- const char *ident);
|
|
|
26ccd9 |
+ const char *__ident,
|
|
|
26ccd9 |
+ const char *serials);
|
|
|
26ccd9 |
int cxl_filter_walk(struct cxl_ctx *ctx, struct cxl_filter_params *param);
|
|
|
26ccd9 |
#endif /* _CXL_UTIL_FILTER_H_ */
|
|
|
26ccd9 |
diff --git a/cxl/list.c b/cxl/list.c
|
|
|
26ccd9 |
index 1730307..6bc48df 100644
|
|
|
26ccd9 |
--- a/cxl/list.c
|
|
|
26ccd9 |
+++ b/cxl/list.c
|
|
|
26ccd9 |
@@ -24,6 +24,8 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
|
|
|
26ccd9 |
const struct option options[] = {
|
|
|
26ccd9 |
OPT_STRING('m', "memdev", ¶m.memdev_filter, "memory device name",
|
|
|
26ccd9 |
"filter by CXL memory device name"),
|
|
|
26ccd9 |
+ OPT_STRING('s', "serial", ¶m.serial_filter, "memory device serial",
|
|
|
26ccd9 |
+ "filter by CXL memory device serial number"),
|
|
|
26ccd9 |
OPT_BOOLEAN('M', "memdevs", ¶m.memdevs,
|
|
|
26ccd9 |
"include CXL memory device info"),
|
|
|
26ccd9 |
OPT_BOOLEAN('i', "idle", ¶m.idle, "include disabled devices"),
|
|
|
26ccd9 |
@@ -47,7 +49,7 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
|
|
|
26ccd9 |
usage_with_options(u, options);
|
|
|
26ccd9 |
|
|
|
26ccd9 |
if (num_list_flags() == 0) {
|
|
|
26ccd9 |
- if (param.memdev_filter)
|
|
|
26ccd9 |
+ if (param.memdev_filter || param.serial_filter)
|
|
|
26ccd9 |
param.memdevs = true;
|
|
|
26ccd9 |
else {
|
|
|
26ccd9 |
/*
|
|
|
26ccd9 |
diff --git a/cxl/memdev.c b/cxl/memdev.c
|
|
|
26ccd9 |
index d063d51..b9141be 100644
|
|
|
26ccd9 |
--- a/cxl/memdev.c
|
|
|
26ccd9 |
+++ b/cxl/memdev.c
|
|
|
26ccd9 |
@@ -248,7 +248,7 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
|
|
|
26ccd9 |
continue;
|
|
|
26ccd9 |
|
|
|
26ccd9 |
cxl_memdev_foreach (ctx, memdev) {
|
|
|
26ccd9 |
- if (!util_cxl_memdev_filter(memdev, argv[i]))
|
|
|
26ccd9 |
+ if (!util_cxl_memdev_filter(memdev, argv[i], NULL))
|
|
|
26ccd9 |
continue;
|
|
|
26ccd9 |
|
|
|
26ccd9 |
if (action == action_write) {
|
|
|
26ccd9 |
--
|
|
|
26ccd9 |
2.27.0
|
|
|
26ccd9 |
|