During namespace creation skip presence of region label if present. Also preserve region label into labels list if present.
Signed-off-by: Neeraj Kumar <[email protected]> --- drivers/nvdimm/namespace_devs.c | 50 +++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index e5c2f78ca7dd..8edd26407939 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -1985,6 +1985,10 @@ static struct device **scan_labels(struct nd_region *nd_region) if (!lsa_label) continue; + /* skip region labels if present */ + if (is_region_label(ndd, lsa_label)) + continue; + nd_label = &lsa_label->ns_label; /* skip labels that describe extents outside of the region */ @@ -2025,9 +2029,30 @@ static struct device **scan_labels(struct nd_region *nd_region) if (count == 0) { struct nd_namespace_pmem *nspm; + for (i = 0; i < nd_region->ndr_mappings; i++) { + struct nd_label_ent *le, *e; + LIST_HEAD(list); - /* Publish a zero-sized namespace for userspace to configure. */ - nd_mapping_free_labels(nd_mapping); + nd_mapping = &nd_region->mapping[i]; + if (list_empty(&nd_mapping->labels)) + continue; + + list_for_each_entry_safe(le, e, &nd_mapping->labels, + list) { + struct nd_lsa_label *nd_label = le->label; + + /* preserve region labels if present */ + if (is_region_label(ndd, nd_label)) + list_move_tail(&le->list, &list); + } + + /* + * Publish a zero-sized namespace for userspace + * to configure. + */ + nd_mapping_free_labels(nd_mapping); + list_splice_init(&list, &nd_mapping->labels); + } nspm = kzalloc(sizeof(*nspm), GFP_KERNEL); if (!nspm) goto err; @@ -2039,7 +2064,7 @@ static struct device **scan_labels(struct nd_region *nd_region) } else if (is_memory(&nd_region->dev)) { /* clean unselected labels */ for (i = 0; i < nd_region->ndr_mappings; i++) { - struct list_head *l, *e; + struct nd_label_ent *le, *e; LIST_HEAD(list); int j; @@ -2050,10 +2075,25 @@ static struct device **scan_labels(struct nd_region *nd_region) } j = count; - list_for_each_safe(l, e, &nd_mapping->labels) { + list_for_each_entry_safe(le, e, &nd_mapping->labels, + list) { + struct nd_lsa_label *nd_label = le->label; + + /* preserve region labels */ + if (is_region_label(ndd, nd_label)) { + list_move_tail(&le->list, &list); + continue; + } + + /* + * Once preserving selected ns label done + * break out of loop + */ if (!j--) break; - list_move_tail(l, &list); + + /* preserve selected ns label */ + list_move_tail(&le->list, &list); } nd_mapping_free_labels(nd_mapping); list_splice_init(&list, &nd_mapping->labels); -- 2.34.1

