Skip to contentSkip to conversation

Skip region filtering if numa_node attribute is not present

PATCH In review Santosh Sivaraj 2 participants 2 messages Apr 16, 2020 – Apr 17, 2020 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Skip region filtering if numa_node attribute is not present

For kernel versions older than 5.4, the numa_node attribute is not present for regions; due to which ndctl list -U 1 fails to list namespaces.

---
 ndctl/lib/libndctl.c   | 13 ++++++++++---
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h       |  4 ++++
 util/filter.c          | 21 +++++++++++++++++++--
 4 files changed, 34 insertions(+), 5 deletions(-)
ndctl/lib/libndctl.c +10 -3
index ee737cb..fef9a43 100644
@@ -2136,7 +2136,7 @@ static void *add_region(void *parent, int id, const char *region_base)
 	struct ndctl_bus *bus = parent;
 	struct ndctl_ctx *ctx = bus->ctx;
 	char *path = calloc(1, strlen(region_base) + 100);
-	int perm;
+	int perm, rc;
 
 	if (!path)
 		return NULL;
@@ -2186,10 +2186,12 @@ static void *add_region(void *parent, int id, const char *region_base)
 	region->module = to_module(ctx, buf);
 
 	sprintf(path, "%s/numa_node", region_base);
-	if (sysfs_read_attr(ctx, path, buf) == 0)
+	if ((rc = sysfs_read_attr(ctx, path, buf)) == 0)
 		region->numa_node = strtol(buf, NULL, 0);
+	else if (rc == -ENOENT)
+		region->numa_node = NUMA_NO_ATTR;
 	else
-		region->numa_node = -1;
+		region->numa_node = NUMA_NO_NODE;
 
 	sprintf(path, "%s/target_node", region_base);
 	if (sysfs_read_attr(ctx, path, buf) == 0)
@@ -2471,6 +2473,11 @@ NDCTL_EXPORT struct ndctl_dimm *ndctl_region_get_next_dimm(struct ndctl_region *
 	return NULL;
 }
 
+NDCTL_EXPORT int ndctl_region_has_numa(struct ndctl_region *region)
+{
+	return (region->numa_node != NUMA_NO_ATTR);
+}
+
 NDCTL_EXPORT int ndctl_region_get_numa_node(struct ndctl_region *region)
 {
 	return region->numa_node;
ndctl/lib/libndctl.sym +1 -0
index ac575a2..a9cba8c 100644
@@ -430,4 +430,5 @@ LIBNDCTL_23 {
 	ndctl_region_get_target_node;
 	ndctl_region_get_align;
 	ndctl_region_set_align;
+	ndctl_region_has_numa;
 } LIBNDCTL_22;
ndctl/libndctl.h +4 -0
index 2580f43..5809ff3 100644
@@ -385,6 +385,7 @@ struct ndctl_dimm *ndctl_region_get_first_dimm(struct ndctl_region *region);
 struct ndctl_dimm *ndctl_region_get_next_dimm(struct ndctl_region *region,
 		struct ndctl_dimm *dimm);
 int ndctl_region_get_numa_node(struct ndctl_region *region);
+int ndctl_region_has_numa(struct ndctl_region *region);
 int ndctl_region_get_target_node(struct ndctl_region *region);
 struct ndctl_region *ndctl_bus_get_region_by_physical_address(struct ndctl_bus *bus,
 		unsigned long long address);
@@ -734,6 +735,9 @@ int ndctl_dimm_master_secure_erase(struct ndctl_dimm *dimm, long key);
 #define ND_KEY_DESC_SIZE	128
 #define ND_KEY_CMD_SIZE		128
 
+#define NUMA_NO_NODE    (-1)
+#define NUMA_NO_ATTR    (-2)
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
util/filter.c +19 -2
index af72793..41765b7 100644
@@ -23,8 +23,6 @@
 #include <ndctl/libndctl.h>
 #include <daxctl/libdaxctl.h>
 
-#define NUMA_NO_NODE    (-1)
-
 struct ndctl_bus *util_bus_filter(struct ndctl_bus *bus, const char *__ident)
 {
 	char *end = NULL, *ident, *save;
@@ -467,7 +465,22 @@ int util_filter_walk(struct ndctl_ctx *ctx, struct util_filter_ctx *fctx,
 						param->namespace))
 				continue;
 
+			/*
+			 * if numa_node attribute is not available for regions
+			 * (which is true for pre 5.4 kernels), don't skip the
+			 * region if namespace is also requested, let the
+			 * namespace filter handle the NUMA node filtering.
+			 */
 			if (numa_node != NUMA_NO_NODE &&
+			    !ndctl_region_has_numa(region) &&
+			    !fctx->filter_namespace) {
+				fprintf(stderr,
+					"This kernel does not provide NUMA node information per-region\n");
+				continue;
+			}
+
+			if (ndctl_region_has_numa(region) &&
+			    numa_node != NUMA_NO_NODE &&
 			    ndctl_region_get_numa_node(region) != numa_node)
 				continue;
 
@@ -489,6 +502,10 @@ int util_filter_walk(struct ndctl_ctx *ctx, struct util_filter_ctx *fctx,
 				if (param->mode && util_nsmode(param->mode) != mode)
 					continue;
 
+				if (numa_node != NUMA_NO_NODE &&
+				    ndctl_namespace_get_numa_node(ndns) != numa_node)
+					continue;
+
 				fctx->filter_namespace(ndns, fctx);
 			}
 		}
Signature · 4 lines
2.25.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Santosh Sivaraj

For kernel versions older than 5.4, the numa_node attribute is not present for regions; due to which ndctl list -U 1 fails to list namespaces.

Looks good to me.

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]