[PATCH V2 12/20] nvdimm/namespace_label: Skip region label during namespace creation

Neeraj Kumar posted 20 patches 2 months, 1 week ago
There is a newer version of this series
[PATCH V2 12/20] nvdimm/namespace_label: Skip region label during namespace creation
Posted by Neeraj Kumar 2 months, 1 week ago
During namespace creation skip presence of region label if present.
Also preserve region label into labels list if present.

Signed-off-by: Neeraj Kumar <s.neeraj@samsung.com>
---
 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
Re: [PATCH V2 12/20] nvdimm/namespace_label: Skip region label during namespace creation
Posted by Jonathan Cameron 1 month, 3 weeks ago
On Wed, 30 Jul 2025 17:42:01 +0530
Neeraj Kumar <s.neeraj@samsung.com> wrote:

> During namespace creation skip presence of region label if present.

Confusing description.  What does skipping presence mean?
Reword.

During namespace creation, skip any region labels found.


> Also preserve region label into labels list if present.
> 
> Signed-off-by: Neeraj Kumar <s.neeraj@samsung.com>
> ---
>  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 */

This is kind of obvious comment. I'd drop it.

> +		if (is_region_label(ndd, lsa_label))
> +			continue;
> +
>  		nd_label = &lsa_label->ns_label;
>
Re: [PATCH V2 12/20] nvdimm/namespace_label: Skip region label during namespace creation
Posted by Neeraj Kumar 1 month ago
On 13/08/25 04:55PM, Jonathan Cameron wrote:
>On Wed, 30 Jul 2025 17:42:01 +0530
>Neeraj Kumar <s.neeraj@samsung.com> wrote:
>
>> During namespace creation skip presence of region label if present.
>
>Confusing description.  What does skipping presence mean?
>Reword.
>
>During namespace creation, skip any region labels found.

Thanks Jonathan, I will fix it in next patch-set

>
>
>> Also preserve region label into labels list if present.
>>
>> Signed-off-by: Neeraj Kumar <s.neeraj@samsung.com>
>> ---
>>  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 */
>
>This is kind of obvious comment. I'd drop it.

Sure, I will drop it in next patch-set


Regards,
Neeraj