nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] device-dax: Auto-bind device after successful new_id
@ 2019-02-13  1:50 Dan Williams
  2019-02-13  8:06 ` Brice Goglin
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Williams @ 2019-02-13  1:50 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: Alexander Duyck, Dave Hansen, linux-kernel, Brice Goglin

The typical 'new_id' attribute behavior is to immediately attach a
device to its driver after a new device-id is added. Implement this
behavior for the dax bus.

Reported-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>
Reported-by: Brice Goglin <Brice.Goglin@inria.fr>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
Changes since v1:
* Fix the remove_id path since do_id_store() is shared with the new_id
  path (Brice)

Brice, this works for me. I'll push it out on libnvdimm-pending, or in
the meantime you can apply this patch after reverting commit
a9f1ffdb6a20 on the current state of the branch.

 drivers/dax/bus.c |   24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
index c620ad52d7e5..a410154d75fb 100644
--- a/drivers/dax/bus.c
+++ b/drivers/dax/bus.c
@@ -57,8 +57,13 @@ static int dax_match_id(struct dax_device_driver *dax_drv, struct device *dev)
 	return match;
 }
 
+enum id_action {
+	ID_REMOVE,
+	ID_ADD,
+};
+
 static ssize_t do_id_store(struct device_driver *drv, const char *buf,
-		size_t count, bool add)
+		size_t count, enum id_action action)
 {
 	struct dax_device_driver *dax_drv = to_dax_drv(drv);
 	unsigned int region_id, id;
@@ -77,7 +82,7 @@ static ssize_t do_id_store(struct device_driver *drv, const char *buf,
 	mutex_lock(&dax_bus_lock);
 	dax_id = __dax_match_id(dax_drv, buf);
 	if (!dax_id) {
-		if (add) {
+		if (action == ID_ADD) {
 			dax_id = kzalloc(sizeof(*dax_id), GFP_KERNEL);
 			if (dax_id) {
 				strncpy(dax_id->dev_name, buf, DAX_NAME_LEN);
@@ -86,26 +91,33 @@ static ssize_t do_id_store(struct device_driver *drv, const char *buf,
 				rc = -ENOMEM;
 		} else
 			/* nothing to remove */;
-	} else if (!add) {
+	} else if (action == ID_REMOVE) {
 		list_del(&dax_id->list);
 		kfree(dax_id);
 	} else
 		/* dax_id already added */;
 	mutex_unlock(&dax_bus_lock);
-	return rc;
+
+	if (rc < 0)
+		return rc;
+	if (action == ID_ADD)
+		rc = driver_attach(drv);
+	if (rc)
+		return rc;
+	return count;
 }
 
 static ssize_t new_id_store(struct device_driver *drv, const char *buf,
 		size_t count)
 {
-	return do_id_store(drv, buf, count, true);
+	return do_id_store(drv, buf, count, ID_ADD);
 }
 static DRIVER_ATTR_WO(new_id);
 
 static ssize_t remove_id_store(struct device_driver *drv, const char *buf,
 		size_t count)
 {
-	return do_id_store(drv, buf, count, false);
+	return do_id_store(drv, buf, count, ID_REMOVE);
 }
 static DRIVER_ATTR_WO(remove_id);
 

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] device-dax: Auto-bind device after successful new_id
  2019-02-13  1:50 [PATCH v2] device-dax: Auto-bind device after successful new_id Dan Williams
@ 2019-02-13  8:06 ` Brice Goglin
  0 siblings, 0 replies; 2+ messages in thread
From: Brice Goglin @ 2019-02-13  8:06 UTC (permalink / raw)
  To: Dan Williams, linux-nvdimm; +Cc: Alexander Duyck, Dave Hansen, linux-kernel

Thanks Dan, remove_id works now.

Brice


Le 13/02/2019 à 02:50, Dan Williams a écrit :
> The typical 'new_id' attribute behavior is to immediately attach a
> device to its driver after a new device-id is added. Implement this
> behavior for the dax bus.
>
> Reported-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>
> Reported-by: Brice Goglin <Brice.Goglin@inria.fr>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
> Changes since v1:
> * Fix the remove_id path since do_id_store() is shared with the new_id
>   path (Brice)
>
> Brice, this works for me. I'll push it out on libnvdimm-pending, or in
> the meantime you can apply this patch after reverting commit
> a9f1ffdb6a20 on the current state of the branch.
>
>  drivers/dax/bus.c |   24 ++++++++++++++++++------
>  1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
> index c620ad52d7e5..a410154d75fb 100644
> --- a/drivers/dax/bus.c
> +++ b/drivers/dax/bus.c
> @@ -57,8 +57,13 @@ static int dax_match_id(struct dax_device_driver *dax_drv, struct device *dev)
>  	return match;
>  }
>  
> +enum id_action {
> +	ID_REMOVE,
> +	ID_ADD,
> +};
> +
>  static ssize_t do_id_store(struct device_driver *drv, const char *buf,
> -		size_t count, bool add)
> +		size_t count, enum id_action action)
>  {
>  	struct dax_device_driver *dax_drv = to_dax_drv(drv);
>  	unsigned int region_id, id;
> @@ -77,7 +82,7 @@ static ssize_t do_id_store(struct device_driver *drv, const char *buf,
>  	mutex_lock(&dax_bus_lock);
>  	dax_id = __dax_match_id(dax_drv, buf);
>  	if (!dax_id) {
> -		if (add) {
> +		if (action == ID_ADD) {
>  			dax_id = kzalloc(sizeof(*dax_id), GFP_KERNEL);
>  			if (dax_id) {
>  				strncpy(dax_id->dev_name, buf, DAX_NAME_LEN);
> @@ -86,26 +91,33 @@ static ssize_t do_id_store(struct device_driver *drv, const char *buf,
>  				rc = -ENOMEM;
>  		} else
>  			/* nothing to remove */;
> -	} else if (!add) {
> +	} else if (action == ID_REMOVE) {
>  		list_del(&dax_id->list);
>  		kfree(dax_id);
>  	} else
>  		/* dax_id already added */;
>  	mutex_unlock(&dax_bus_lock);
> -	return rc;
> +
> +	if (rc < 0)
> +		return rc;
> +	if (action == ID_ADD)
> +		rc = driver_attach(drv);
> +	if (rc)
> +		return rc;
> +	return count;
>  }
>  
>  static ssize_t new_id_store(struct device_driver *drv, const char *buf,
>  		size_t count)
>  {
> -	return do_id_store(drv, buf, count, true);
> +	return do_id_store(drv, buf, count, ID_ADD);
>  }
>  static DRIVER_ATTR_WO(new_id);
>  
>  static ssize_t remove_id_store(struct device_driver *drv, const char *buf,
>  		size_t count)
>  {
> -	return do_id_store(drv, buf, count, false);
> +	return do_id_store(drv, buf, count, ID_REMOVE);
>  }
>  static DRIVER_ATTR_WO(remove_id);
>  
>
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-13  8:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-13  1:50 [PATCH v2] device-dax: Auto-bind device after successful new_id Dan Williams
2019-02-13  8:06 ` Brice Goglin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).