diff mbox series

[ndctl,1/2] daxctl/device.c: Handle special case of destroying daxX.0

Message ID 20240412-vv-daxctl-fixes-v1-1-6e808174e24f@intel.com (mailing list archive)
State New
Delegated to: Patchwork Bot
Headers show
Series daxctl: Fix error handling and propagation in daxctl/device.c | expand

Commit Message

Verma, Vishal L April 12, 2024, 9:05 p.m. UTC
The kernel has special handling for destroying the 0th dax device under
any given DAX region (daxX.0). It ensures the size is set to 0, but
doesn't actually remove the device, instead it returns an EBUSY,
indicating that this device cannot be removed.

Add an expectation in daxctl's dev_destroy() helper to handle this case
instead of returning the error - as far as the user is concerned, the
size has been set to zero, and the destroy operation has been completed,
even if the kernel indicated an EBUSY.

Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Alison Schofield <alison.schofield@intel.com>
Reported-by: Ira Weiny <ira.weiny@intel.com>
Reported-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 daxctl/device.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Dan Williams April 12, 2024, 9:09 p.m. UTC | #1
Vishal Verma wrote:
> The kernel has special handling for destroying the 0th dax device under
> any given DAX region (daxX.0). It ensures the size is set to 0, but
> doesn't actually remove the device, instead it returns an EBUSY,
> indicating that this device cannot be removed.
> 
> Add an expectation in daxctl's dev_destroy() helper to handle this case
> instead of returning the error - as far as the user is concerned, the
> size has been set to zero, and the destroy operation has been completed,
> even if the kernel indicated an EBUSY.
> 
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Alison Schofield <alison.schofield@intel.com>
> Reported-by: Ira Weiny <ira.weiny@intel.com>
> Reported-by: Dave Jiang <dave.jiang@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>

Looks good,

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Dave Jiang April 15, 2024, 4:17 p.m. UTC | #2
On 4/12/24 2:05 PM, Vishal Verma wrote:
> The kernel has special handling for destroying the 0th dax device under
> any given DAX region (daxX.0). It ensures the size is set to 0, but
> doesn't actually remove the device, instead it returns an EBUSY,
> indicating that this device cannot be removed.
> 
> Add an expectation in daxctl's dev_destroy() helper to handle this case
> instead of returning the error - as far as the user is concerned, the
> size has been set to zero, and the destroy operation has been completed,
> even if the kernel indicated an EBUSY.
> 
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Alison Schofield <alison.schofield@intel.com>
> Reported-by: Ira Weiny <ira.weiny@intel.com>
> Reported-by: Dave Jiang <dave.jiang@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  daxctl/device.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/daxctl/device.c b/daxctl/device.c
> index 83913430..83c61389 100644
> --- a/daxctl/device.c
> +++ b/daxctl/device.c
> @@ -675,6 +675,13 @@ static int dev_destroy(struct daxctl_dev *dev)
>  		return rc;
>  
>  	rc = daxctl_region_destroy_dev(daxctl_dev_get_region(dev), dev);
> +	/*
> +	 * The kernel treats daxX.0 specially. It can't be deleted to ensure
> +	 * there is always a /sys/bus/dax/ present. If this happens, an
> +	 * EBUSY is returned. Expect it and don't treat it as an error.
> +	 */
> +	if (daxctl_dev_get_id(dev) == 0 && rc == -EBUSY)
> +		return 0;
>  	if (rc < 0)
>  		return rc;
>  
>
diff mbox series

Patch

diff --git a/daxctl/device.c b/daxctl/device.c
index 83913430..83c61389 100644
--- a/daxctl/device.c
+++ b/daxctl/device.c
@@ -675,6 +675,13 @@  static int dev_destroy(struct daxctl_dev *dev)
 		return rc;
 
 	rc = daxctl_region_destroy_dev(daxctl_dev_get_region(dev), dev);
+	/*
+	 * The kernel treats daxX.0 specially. It can't be deleted to ensure
+	 * there is always a /sys/bus/dax/ present. If this happens, an
+	 * EBUSY is returned. Expect it and don't treat it as an error.
+	 */
+	if (daxctl_dev_get_id(dev) == 0 && rc == -EBUSY)
+		return 0;
 	if (rc < 0)
 		return rc;