|
|
2eb93d |
From 0ce0152d8e29f85325a3a59f94051228540abf6a Mon Sep 17 00:00:00 2001
|
|
|
2eb93d |
From: Dan Williams <dan.j.williams@intel.com>
|
|
|
2eb93d |
Date: Sun, 23 Jan 2022 16:52:20 -0800
|
|
|
2eb93d |
Subject: [PATCH 092/217] cxl/list: Support multiple memdev device name filter
|
|
|
2eb93d |
arguments
|
|
|
2eb93d |
|
|
|
2eb93d |
Similar to 'ndctl list', allow for a syntax like:
|
|
|
2eb93d |
|
|
|
2eb93d |
cxl list -m "$(seq -s ' ' 2 5)"
|
|
|
2eb93d |
|
|
|
2eb93d |
...to filter the output to just those 4 memdevs.
|
|
|
2eb93d |
|
|
|
2eb93d |
Link: https://lore.kernel.org/r/164298554075.3021641.17678360870961637912.stgit@dwillia2-desk3.amr.corp.intel.com
|
|
|
2eb93d |
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
|
|
|
2eb93d |
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
|
|
|
2eb93d |
---
|
|
|
2eb93d |
Documentation/cxl/cxl-list.txt | 21 ++++++++++++++++++-
|
|
|
2eb93d |
cxl/filter.c | 38 ++++++++++++++++++++++++----------
|
|
|
2eb93d |
2 files changed, 47 insertions(+), 12 deletions(-)
|
|
|
2eb93d |
|
|
|
2eb93d |
diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt
|
|
|
2eb93d |
index c8d10fb..686e0ea 100644
|
|
|
2eb93d |
--- a/Documentation/cxl/cxl-list.txt
|
|
|
2eb93d |
+++ b/Documentation/cxl/cxl-list.txt
|
|
|
2eb93d |
@@ -30,7 +30,7 @@ OPTIONS
|
|
|
2eb93d |
-------
|
|
|
2eb93d |
-m::
|
|
|
2eb93d |
--memdev=::
|
|
|
2eb93d |
- Specify a cxl memory device name to filter the listing. For example:
|
|
|
2eb93d |
+ Specify CXL memory device name(s), or device id(s), to filter the listing. For example:
|
|
|
2eb93d |
----
|
|
|
2eb93d |
# cxl list --memdev=mem0
|
|
|
2eb93d |
{
|
|
|
2eb93d |
@@ -38,6 +38,25 @@ OPTIONS
|
|
|
2eb93d |
"pmem_size":268435456,
|
|
|
2eb93d |
"ram_size":0,
|
|
|
2eb93d |
}
|
|
|
2eb93d |
+
|
|
|
2eb93d |
+# cxl list -m "0 mem1 2"
|
|
|
2eb93d |
+[
|
|
|
2eb93d |
+ {
|
|
|
2eb93d |
+ "memdev":"mem0",
|
|
|
2eb93d |
+ "pmem_size":268435456,
|
|
|
2eb93d |
+ "ram_size":0
|
|
|
2eb93d |
+ },
|
|
|
2eb93d |
+ {
|
|
|
2eb93d |
+ "memdev":"mem2",
|
|
|
2eb93d |
+ "pmem_size":268435456,
|
|
|
2eb93d |
+ "ram_size":268435456
|
|
|
2eb93d |
+ },
|
|
|
2eb93d |
+ {
|
|
|
2eb93d |
+ "memdev":"mem1",
|
|
|
2eb93d |
+ "pmem_size":268435456,
|
|
|
2eb93d |
+ "ram_size":268435456
|
|
|
2eb93d |
+ }
|
|
|
2eb93d |
+]
|
|
|
2eb93d |
----
|
|
|
2eb93d |
|
|
|
2eb93d |
-M::
|
|
|
2eb93d |
diff --git a/cxl/filter.c b/cxl/filter.c
|
|
|
2eb93d |
index 21322ed..efafaf5 100644
|
|
|
2eb93d |
--- a/cxl/filter.c
|
|
|
2eb93d |
+++ b/cxl/filter.c
|
|
|
2eb93d |
@@ -2,24 +2,40 @@
|
|
|
2eb93d |
// Copyright (C) 2015-2020 Intel Corporation. All rights reserved.
|
|
|
2eb93d |
#include <stdio.h>
|
|
|
2eb93d |
#include <string.h>
|
|
|
2eb93d |
+#include <stdlib.h>
|
|
|
2eb93d |
#include <cxl/libcxl.h>
|
|
|
2eb93d |
#include "filter.h"
|
|
|
2eb93d |
|
|
|
2eb93d |
struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
|
|
|
2eb93d |
- const char *ident)
|
|
|
2eb93d |
+ const char *__ident)
|
|
|
2eb93d |
{
|
|
|
2eb93d |
- int memdev_id;
|
|
|
2eb93d |
+ char *ident, *save;
|
|
|
2eb93d |
+ const char *name;
|
|
|
2eb93d |
+ int memdev_id;
|
|
|
2eb93d |
|
|
|
2eb93d |
- if (!ident || strcmp(ident, "all") == 0)
|
|
|
2eb93d |
- return memdev;
|
|
|
2eb93d |
+ if (!__ident)
|
|
|
2eb93d |
+ return memdev;
|
|
|
2eb93d |
|
|
|
2eb93d |
- if (strcmp(ident, cxl_memdev_get_devname(memdev)) == 0)
|
|
|
2eb93d |
- return memdev;
|
|
|
2eb93d |
+ ident = strdup(__ident);
|
|
|
2eb93d |
+ if (!ident)
|
|
|
2eb93d |
+ return NULL;
|
|
|
2eb93d |
|
|
|
2eb93d |
- if ((sscanf(ident, "%d", &memdev_id) == 1
|
|
|
2eb93d |
- || sscanf(ident, "mem%d", &memdev_id) == 1)
|
|
|
2eb93d |
- && cxl_memdev_get_id(memdev) == memdev_id)
|
|
|
2eb93d |
- return memdev;
|
|
|
2eb93d |
+ for (name = strtok_r(ident, " ", &save); name;
|
|
|
2eb93d |
+ name = strtok_r(NULL, " ", &save)) {
|
|
|
2eb93d |
+ if (strcmp(name, "all") == 0)
|
|
|
2eb93d |
+ break;
|
|
|
2eb93d |
|
|
|
2eb93d |
- return NULL;
|
|
|
2eb93d |
+ if ((sscanf(name, "%d", &memdev_id) == 1 ||
|
|
|
2eb93d |
+ sscanf(name, "mem%d", &memdev_id) == 1) &&
|
|
|
2eb93d |
+ cxl_memdev_get_id(memdev) == memdev_id)
|
|
|
2eb93d |
+ break;
|
|
|
2eb93d |
+
|
|
|
2eb93d |
+ if (strcmp(name, cxl_memdev_get_devname(memdev)) == 0)
|
|
|
2eb93d |
+ break;
|
|
|
2eb93d |
+ }
|
|
|
2eb93d |
+
|
|
|
2eb93d |
+ free(ident);
|
|
|
2eb93d |
+ if (name)
|
|
|
2eb93d |
+ return memdev;
|
|
|
2eb93d |
+ return NULL;
|
|
|
2eb93d |
}
|
|
|
2eb93d |
--
|
|
|
2eb93d |
2.27.0
|
|
|
2eb93d |
|