diff mbox series

[NDCTL] cxl/region: Move cxl destroy_region() to new disable_region() helper

Message ID 170112921107.2687457.2741231995154639197.stgit@djiang5-mobl3
State Accepted
Commit 9c0703f1d321e844ef50a4702e14b30e027ebaaf
Headers show
Series [NDCTL] cxl/region: Move cxl destroy_region() to new disable_region() helper | expand

Commit Message

Dave Jiang Nov. 27, 2023, 11:53 p.m. UTC
To keep the behavior consistent with the disable region operation, change
the calling of cxl_region_disable() directly in destroy_region() to the
new disable_region() helper in order to check whether the region is still
online.

Suggested-by: Quanquan Cao <caoqq@fujitsu.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 cxl/region.c |  100 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 50 insertions(+), 50 deletions(-)

Comments

Cao, Quanquan/曹 全全 Nov. 28, 2023, 2:19 a.m. UTC | #1
> To keep the behavior consistent with the disable region operation, change
> the calling of cxl_region_disable() directly in destroy_region() to the
> new disable_region() helper in order to check whether the region is still
> online.
> 
> Suggested-by: Quanquan Cao <caoqq@fujitsu.com>
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
>   cxl/region.c |  100 +++++++++++++++++++++++++++++-----------------------------
>   1 file changed, 50 insertions(+), 50 deletions(-)
> 
> diff --git a/cxl/region.c b/cxl/region.c
> index 5cbbf2749e2d..4091ee8d2713 100644
> --- a/cxl/region.c
> +++ b/cxl/region.c
> @@ -728,6 +728,55 @@ out:
>   	return rc;
>   }
>   
> +static int disable_region(struct cxl_region *region)
> +{
> +	const char *devname = cxl_region_get_devname(region);
> +	struct daxctl_region *dax_region;
> +	struct daxctl_memory *mem;
> +	struct daxctl_dev *dev;
> +	int failed = 0, rc;
> +
> +	dax_region = cxl_region_get_daxctl_region(region);
> +	if (!dax_region)
> +		goto out;
> +
> +	daxctl_dev_foreach(dax_region, dev) {
> +		mem = daxctl_dev_get_memory(dev);
> +		if (!mem)
> +			return -ENXIO;
> +
> +		/*
> +		 * If memory is still online and user wants to force it, attempt
> +		 * to offline it.
> +		 */
> +		if (daxctl_memory_is_online(mem)) {
> +			rc = daxctl_memory_offline(mem);
> +			if (rc < 0) {
> +				log_err(&rl, "%s: unable to offline %s: %s\n",
> +					devname,
> +					daxctl_dev_get_devname(dev),
> +					strerror(abs(rc)));
> +				if (!param.force)
> +					return rc;
> +
> +				failed++;
> +			}
> +		}
> +	}
> +
> +	if (failed) {
> +		log_err(&rl, "%s: Forcing region disable without successful offline.\n",
> +			devname);
> +		log_err(&rl, "%s: Physical address space has now been permanently leaked.\n",
> +			devname);
> +		log_err(&rl, "%s: Leaked address cannot be recovered until a reboot.\n",
> +			devname);
> +	}
> +
> +out:
> +	return cxl_region_disable(region);
> +}
> +
>   static int destroy_region(struct cxl_region *region)
>   {
>   	const char *devname = cxl_region_get_devname(region);
> @@ -737,7 +786,7 @@ static int destroy_region(struct cxl_region *region)
>   	/* First, unbind/disable the region if needed */
>   	if (cxl_region_is_enabled(region)) {
>   		if (param.force) {
> -			rc = cxl_region_disable(region);
> +			rc = disable_region(region);
>   			if (rc) {
>   				log_err(&rl, "%s: error disabling region: %s\n",
>   					devname, strerror(-rc));
> @@ -792,55 +841,6 @@ static int destroy_region(struct cxl_region *region)
>   	return cxl_region_delete(region);
>   }
>   
> -static int disable_region(struct cxl_region *region)
> -{
> -	const char *devname = cxl_region_get_devname(region);
> -	struct daxctl_region *dax_region;
> -	struct daxctl_memory *mem;
> -	struct daxctl_dev *dev;
> -	int failed = 0, rc;
> -
> -	dax_region = cxl_region_get_daxctl_region(region);
> -	if (!dax_region)
> -		goto out;
> -
> -	daxctl_dev_foreach(dax_region, dev) {
> -		mem = daxctl_dev_get_memory(dev);
> -		if (!mem)
> -			return -ENXIO;
> -
> -		/*
> -		 * If memory is still online and user wants to force it, attempt
> -		 * to offline it.
> -		 */
> -		if (daxctl_memory_is_online(mem)) {
> -			rc = daxctl_memory_offline(mem);
> -			if (rc < 0) {
> -				log_err(&rl, "%s: unable to offline %s: %s\n",
> -					devname,
> -					daxctl_dev_get_devname(dev),
> -					strerror(abs(rc)));
> -				if (!param.force)
> -					return rc;
> -
> -				failed++;
> -			}
> -		}
> -	}
> -
> -	if (failed) {
> -		log_err(&rl, "%s: Forcing region disable without successful offline.\n",
> -			devname);
> -		log_err(&rl, "%s: Physical address space has now been permanently leaked.\n",
> -			devname);
> -		log_err(&rl, "%s: Leaked address cannot be recovered until a reboot.\n",
> -			devname);
> -	}
> -
> -out:
> -	return cxl_region_disable(region);
> -}
> -
>   static int do_region_xable(struct cxl_region *region, enum region_actions action)
>   {
>   	switch (action) {
> 

Thank you very much for your patch.

Reviewed-by: Quanquan Cao <caoqq@fujitsu.com>
diff mbox series

Patch

diff --git a/cxl/region.c b/cxl/region.c
index 5cbbf2749e2d..4091ee8d2713 100644
--- a/cxl/region.c
+++ b/cxl/region.c
@@ -728,6 +728,55 @@  out:
 	return rc;
 }
 
+static int disable_region(struct cxl_region *region)
+{
+	const char *devname = cxl_region_get_devname(region);
+	struct daxctl_region *dax_region;
+	struct daxctl_memory *mem;
+	struct daxctl_dev *dev;
+	int failed = 0, rc;
+
+	dax_region = cxl_region_get_daxctl_region(region);
+	if (!dax_region)
+		goto out;
+
+	daxctl_dev_foreach(dax_region, dev) {
+		mem = daxctl_dev_get_memory(dev);
+		if (!mem)
+			return -ENXIO;
+
+		/*
+		 * If memory is still online and user wants to force it, attempt
+		 * to offline it.
+		 */
+		if (daxctl_memory_is_online(mem)) {
+			rc = daxctl_memory_offline(mem);
+			if (rc < 0) {
+				log_err(&rl, "%s: unable to offline %s: %s\n",
+					devname,
+					daxctl_dev_get_devname(dev),
+					strerror(abs(rc)));
+				if (!param.force)
+					return rc;
+
+				failed++;
+			}
+		}
+	}
+
+	if (failed) {
+		log_err(&rl, "%s: Forcing region disable without successful offline.\n",
+			devname);
+		log_err(&rl, "%s: Physical address space has now been permanently leaked.\n",
+			devname);
+		log_err(&rl, "%s: Leaked address cannot be recovered until a reboot.\n",
+			devname);
+	}
+
+out:
+	return cxl_region_disable(region);
+}
+
 static int destroy_region(struct cxl_region *region)
 {
 	const char *devname = cxl_region_get_devname(region);
@@ -737,7 +786,7 @@  static int destroy_region(struct cxl_region *region)
 	/* First, unbind/disable the region if needed */
 	if (cxl_region_is_enabled(region)) {
 		if (param.force) {
-			rc = cxl_region_disable(region);
+			rc = disable_region(region);
 			if (rc) {
 				log_err(&rl, "%s: error disabling region: %s\n",
 					devname, strerror(-rc));
@@ -792,55 +841,6 @@  static int destroy_region(struct cxl_region *region)
 	return cxl_region_delete(region);
 }
 
-static int disable_region(struct cxl_region *region)
-{
-	const char *devname = cxl_region_get_devname(region);
-	struct daxctl_region *dax_region;
-	struct daxctl_memory *mem;
-	struct daxctl_dev *dev;
-	int failed = 0, rc;
-
-	dax_region = cxl_region_get_daxctl_region(region);
-	if (!dax_region)
-		goto out;
-
-	daxctl_dev_foreach(dax_region, dev) {
-		mem = daxctl_dev_get_memory(dev);
-		if (!mem)
-			return -ENXIO;
-
-		/*
-		 * If memory is still online and user wants to force it, attempt
-		 * to offline it.
-		 */
-		if (daxctl_memory_is_online(mem)) {
-			rc = daxctl_memory_offline(mem);
-			if (rc < 0) {
-				log_err(&rl, "%s: unable to offline %s: %s\n",
-					devname,
-					daxctl_dev_get_devname(dev),
-					strerror(abs(rc)));
-				if (!param.force)
-					return rc;
-
-				failed++;
-			}
-		}
-	}
-
-	if (failed) {
-		log_err(&rl, "%s: Forcing region disable without successful offline.\n",
-			devname);
-		log_err(&rl, "%s: Physical address space has now been permanently leaked.\n",
-			devname);
-		log_err(&rl, "%s: Leaked address cannot be recovered until a reboot.\n",
-			devname);
-	}
-
-out:
-	return cxl_region_disable(region);
-}
-
 static int do_region_xable(struct cxl_region *region, enum region_actions action)
 {
 	switch (action) {