anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone
Jeff Moyer 2c91dc
From a36b8b815d2e8bfd8438b44d4775bdf3ffc3a6d8 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:52:26 -0800
Jeff Moyer 2c91dc
Subject: [PATCH 093/217] cxl/list: Support comma separated lists
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
In addition to supporting a syntax like:
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
   cxl list -m "0 1 2"
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
...support:
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
   cxl list -m 0,1,2
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
Link: https://lore.kernel.org/r/164298554612.3021641.3315920699556984273.stgit@dwillia2-desk3.amr.corp.intel.com
Jeff Moyer 2c91dc
Reported-by: Vishal Verma <vishal.l.verma@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
 cxl/filter.c | 13 +++++++++++--
Jeff Moyer 2c91dc
 1 file changed, 11 insertions(+), 2 deletions(-)
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
diff --git a/cxl/filter.c b/cxl/filter.c
Jeff Moyer 2c91dc
index efafaf5..405b653 100644
Jeff Moyer 2c91dc
--- a/cxl/filter.c
Jeff Moyer 2c91dc
+++ b/cxl/filter.c
Jeff Moyer 2c91dc
@@ -6,6 +6,15 @@
Jeff Moyer 2c91dc
 #include <cxl/libcxl.h>
Jeff Moyer 2c91dc
 #include "filter.h"
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
+static const char *which_sep(const char *filter)
Jeff Moyer 2c91dc
+{
Jeff Moyer 2c91dc
+	if (strchr(filter, ' '))
Jeff Moyer 2c91dc
+		return " ";
Jeff Moyer 2c91dc
+	if (strchr(filter, ','))
Jeff Moyer 2c91dc
+		return ",";
Jeff Moyer 2c91dc
+	return " ";
Jeff Moyer 2c91dc
+}
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
 struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
Jeff Moyer 2c91dc
 					  const char *__ident)
Jeff Moyer 2c91dc
 {
Jeff Moyer 2c91dc
@@ -20,8 +29,8 @@ struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
Jeff Moyer 2c91dc
 	if (!ident)
Jeff Moyer 2c91dc
 		return NULL;
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
-	for (name = strtok_r(ident, " ", &save); name;
Jeff Moyer 2c91dc
-	     name = strtok_r(NULL, " ", &save)) {
Jeff Moyer 2c91dc
+	for (name = strtok_r(ident, which_sep(__ident), &save); name;
Jeff Moyer 2c91dc
+	     name = strtok_r(NULL, which_sep(__ident), &save)) {
Jeff Moyer 2c91dc
 		if (strcmp(name, "all") == 0)
Jeff Moyer 2c91dc
 			break;
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
-- 
Jeff Moyer 2c91dc
2.27.0
Jeff Moyer 2c91dc