@@ -38,6 +38,7 @@ static bool verbose;
static bool force;
static struct parameters {
bool do_scan;
+ bool mode_default;
const char *bus;
const char *map;
const char *type;
@@ -153,6 +154,7 @@ static int set_defaults(enum namespace_action mode)
param.mode = "memory";
else
param.mode = "safe";
+ param.mode_default = true;
}
if (param.map) {
@@ -428,6 +430,22 @@ static int validate_namespace_options(struct ndctl_namespace *ndns,
} else if (p->mode == NDCTL_NS_MODE_MEMORY)
p->loc = NDCTL_PFN_LOC_PMEM;
+ /* check if we need, and whether the kernel supports, pfn devices */
+ if (do_setup_pfn(ndns, p)) {
+ struct ndctl_region *region;
+ struct ndctl_pfn *pfn;
+
+ region = ndctl_namespace_get_region(ndns);
+ pfn = ndctl_region_get_pfn_seed(region);
+ if (!pfn && param.mode_default) {
+ debug("memory mode not available\n");
+ p->mode = NDCTL_NS_MODE_RAW;
+ } else if (!pfn) {
+ error("operation failed, memory mode not available\n");
+ return -EINVAL;
+ }
+ }
+
return 0;
}
When a kernel does not support ZONE_DEVICE it is unable to support pfn-device configurations. Use the absence of a pfn-seed as the indicator of this configuration to fail the operation with an error rather than crashing. Reported-by: Linda Knippers <linda.knippers@hpe.com> Reported-by: Vishal Verma <vishal.l.verma@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- builtin-xaction-namespace.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)