Depending on initialization order the first seed device in a region may
not point to the first namespace. Always check if the first namespace is
available before falling back to the current seed.
Signed-off-by: Dan Williams <dan.j.williams(a)intel.com>
---
ndctl/builtin-xaction-namespace.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/ndctl/builtin-xaction-namespace.c b/ndctl/builtin-xaction-namespace.c
index 5743eeeb5bfb..46d651e86153 100644
--- a/ndctl/builtin-xaction-namespace.c
+++ b/ndctl/builtin-xaction-namespace.c
@@ -632,6 +632,18 @@ static int validate_namespace_options(struct ndctl_region *region,
return 0;
}
+static struct ndctl_namespace *region_get_namespace(struct ndctl_region *region)
+{
+ struct ndctl_namespace *ndns;
+
+ /* prefer the 0th namespace if it is idle */
+ ndctl_namespace_foreach(region, ndns)
+ if (ndctl_namespace_get_id(ndns) == 0
+ && !is_namespace_active(ndns))
+ return ndns;
+ return ndctl_region_get_namespace_seed(region);
+}
+
static int namespace_create(struct ndctl_region *region)
{
const char *devname = ndctl_region_get_devname(region);
@@ -660,7 +672,7 @@ static int namespace_create(struct ndctl_region *region)
if (p.size == 0)
p.size = available;
- ndns = ndctl_region_get_namespace_seed(region);
+ ndns = region_get_namespace(region);
if (!ndns || is_namespace_active(ndns)) {
debug("%s: no %s namespace seed\n", devname,
ndns ? "idle" : "available");
@@ -794,7 +806,7 @@ static int namespace_reconfig(struct ndctl_region *region,
if (rc)
return rc;
- ndns = ndctl_region_get_namespace_seed(region);
+ ndns = region_get_namespace(region);
if (!ndns || is_namespace_active(ndns)) {
debug("%s: no %s namespace seed\n",
ndctl_region_get_devname(region),
Show replies by date