[PATCH V4 06/17] nvdimm/label: Preserve region label during namespace creation

Neeraj Kumar posted 17 patches 1 week, 5 days ago
[PATCH V4 06/17] nvdimm/label: Preserve region label during namespace creation
Posted by Neeraj Kumar 1 week, 5 days ago
During namespace creation we scan labels present in LSA using
scan_labels(). Currently scan_labels() is only preserving
namespace labels into label_ent list.

In this patch we also preserve region label into label_ent list

Signed-off-by: Neeraj Kumar <s.neeraj@samsung.com>
---
 drivers/nvdimm/namespace_devs.c | 47 +++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index b1abbe602a5e..9450200b4470 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -1999,9 +1999,32 @@ 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 cxl_region_label *region_label;
+			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) {
+				region_label = le->region_label;
+				if (!region_label)
+					continue;
+
+				/* Preserve region labels if present */
+				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;
@@ -2013,7 +2036,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;
 
@@ -2024,10 +2047,24 @@ 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) {
+				/* Preserve region labels */
+				if (uuid_equal(&le->label_uuid,
+					       &cxl_region_uuid)) {
+					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 V4 06/17] nvdimm/label: Preserve region label during namespace creation
Posted by Dave Jiang 1 week, 5 days ago

On 11/19/25 12:52 AM, Neeraj Kumar wrote:
> During namespace creation we scan labels present in LSA using
> scan_labels(). Currently scan_labels() is only preserving
> namespace labels into label_ent list.
> 
> In this patch we also preserve region label into label_ent list
> 
> Signed-off-by: Neeraj Kumar <s.neeraj@samsung.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
>  drivers/nvdimm/namespace_devs.c | 47 +++++++++++++++++++++++++++++----
>  1 file changed, 42 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
> index b1abbe602a5e..9450200b4470 100644
> --- a/drivers/nvdimm/namespace_devs.c
> +++ b/drivers/nvdimm/namespace_devs.c
> @@ -1999,9 +1999,32 @@ 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 cxl_region_label *region_label;
> +			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) {
> +				region_label = le->region_label;
> +				if (!region_label)
> +					continue;
> +
> +				/* Preserve region labels if present */
> +				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;
> @@ -2013,7 +2036,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;
>  
> @@ -2024,10 +2047,24 @@ 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) {
> +				/* Preserve region labels */
> +				if (uuid_equal(&le->label_uuid,
> +					       &cxl_region_uuid)) {
> +					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);