@@ -64,6 +64,10 @@ OPTIONS
]
----
+-s::
+--serial=::
+ Specify CXL memory device serial number(s) to filter the listing
+
-M::
--memdevs::
Include CXL memory devices in the listing
@@ -21,15 +21,45 @@ static const char *which_sep(const char *filter)
return " ";
}
+static struct cxl_memdev *
+util_cxl_memdev_serial_filter(struct cxl_memdev *memdev, const char *__serials)
+{
+ unsigned long long serial = 0;
+ char *serials, *save, *end;
+ const char *arg;
+
+ if (!__serials)
+ return memdev;
+
+ serials = strdup(__serials);
+ if (!serials)
+ return NULL;
+
+ for (arg = strtok_r(serials, which_sep(__serials), &save); arg;
+ arg = strtok_r(NULL, which_sep(__serials), &save)) {
+ serial = strtoull(arg, &end, 0);
+ if (!arg[0] || end[0] != 0)
+ continue;
+ if (cxl_memdev_get_serial(memdev) == serial)
+ break;
+ }
+
+ free(serials);
+ if (arg)
+ return memdev;
+ return NULL;
+}
+
struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
- const char *__ident)
+ const char *__ident,
+ const char *serials)
{
char *ident, *save;
const char *name;
int memdev_id;
if (!__ident)
- return memdev;
+ return util_cxl_memdev_serial_filter(memdev, serials);
ident = strdup(__ident);
if (!ident)
@@ -51,7 +81,7 @@ struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
free(ident);
if (name)
- return memdev;
+ return util_cxl_memdev_serial_filter(memdev, serials);
return NULL;
}
@@ -82,7 +112,7 @@ int cxl_filter_walk(struct cxl_ctx *ctx, struct cxl_filter_params *p)
cxl_memdev_foreach(ctx, memdev) {
struct json_object *jdev;
- if (!util_cxl_memdev_filter(memdev, p->memdev_filter))
+ if (!util_cxl_memdev_filter(memdev, p->memdev_filter, p->serial_filter))
continue;
if (p->memdevs) {
jdev = util_cxl_memdev_to_json(memdev, flags);
@@ -8,6 +8,7 @@
struct cxl_filter_params {
const char *memdev_filter;
+ const char *serial_filter;
bool memdevs;
bool idle;
bool human;
@@ -16,6 +17,7 @@ struct cxl_filter_params {
};
struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
- const char *ident);
+ const char *__ident,
+ const char *serials);
int cxl_filter_walk(struct cxl_ctx *ctx, struct cxl_filter_params *param);
#endif /* _CXL_UTIL_FILTER_H_ */
@@ -24,6 +24,8 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
const struct option options[] = {
OPT_STRING('m', "memdev", ¶m.memdev_filter, "memory device name",
"filter by CXL memory device name"),
+ OPT_STRING('s', "serial", ¶m.serial_filter, "memory device serial",
+ "filter by CXL memory device serial number"),
OPT_BOOLEAN('M', "memdevs", ¶m.memdevs,
"include CXL memory device info"),
OPT_BOOLEAN('i', "idle", ¶m.idle, "include disabled devices"),
@@ -47,7 +49,7 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
usage_with_options(u, options);
if (num_list_flags() == 0) {
- if (param.memdev_filter)
+ if (param.memdev_filter || param.serial_filter)
param.memdevs = true;
else {
/*
@@ -248,7 +248,7 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
continue;
cxl_memdev_foreach (ctx, memdev) {
- if (!util_cxl_memdev_filter(memdev, argv[i]))
+ if (!util_cxl_memdev_filter(memdev, argv[i], NULL))
continue;
if (action == action_write) {
Given that serial numbers are intended to be unique device identifiers, enable them as a memdev filter option. Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- Documentation/cxl/cxl-list.txt | 4 ++++ cxl/filter.c | 38 ++++++++++++++++++++++++++++++++++---- cxl/filter.h | 4 +++- cxl/list.c | 4 +++- cxl/memdev.c | 2 +- 5 files changed, 45 insertions(+), 7 deletions(-)