All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: vishal.l.verma@intel.com
Cc: Quanquan Cao <caoqq@fujitsu.com>,
	linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev,
	caoqq@fujitsu.com
Subject: [NDCTL PATCH] cxl/region: Move cxl destroy_region() to new disable_region() helper
Date: Mon, 27 Nov 2023 16:53:31 -0700	[thread overview]
Message-ID: <170112921107.2687457.2741231995154639197.stgit@djiang5-mobl3> (raw)

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) {



             reply	other threads:[~2023-11-27 23:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-27 23:53 Dave Jiang [this message]
2023-11-28  2:19 ` [NDCTL PATCH] cxl/region: Move cxl destroy_region() to new disable_region() helper Cao, Quanquan/曹 全全

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=170112921107.2687457.2741231995154639197.stgit@djiang5-mobl3 \
    --to=dave.jiang@intel.com \
    --cc=caoqq@fujitsu.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.