mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Valentina Manea <valentina.manea.m@gmail.com>
To: gregkh@linuxfoundation.org
Cc: tobias.polzer@fau.de, dominik.paulus@fau.de,
	ly80toro@cip.cs.fau.de, shuah.kh@samsung.com,
	ihadzic@research.bell-labs.com, linux-kernel@vger.kernel.org,
	linux-usb@vger.kernel.org, devel@driverdev.osuosl.org,
	firefly@lists.rosedu.org, andy.grover@gmail.com,
	Valentina Manea <valentina.manea.m@gmail.com>
Subject: [PATCH 15/18] staging: usbip: trigger driver probing after unbinding from usbip-host
Date: Sat,  8 Mar 2014 14:53:33 +0200	[thread overview]
Message-ID: <1394283216-1277-16-git-send-email-valentina.manea.m@gmail.com> (raw)
In-Reply-To: <1394283216-1277-1-git-send-email-valentina.manea.m@gmail.com>

A sysfs attribute is used to announce kernel space that a
new driver probing session should be triggered for the just
unbinded device.

In order to have the address of struct device associated to this
USB device, a new member has been added to struct bus_id_priv.

Signed-off-by: Valentina Manea <valentina.manea.m@gmail.com>
---
 drivers/staging/usbip/stub.h                       |  1 +
 drivers/staging/usbip/stub_dev.c                   |  1 +
 drivers/staging/usbip/stub_main.c                  | 39 ++++++++++++++++++++++
 drivers/staging/usbip/userspace/src/usbip_unbind.c | 17 ++++++++--
 4 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/usbip/stub.h b/drivers/staging/usbip/stub.h
index 82e539a..266e2b0 100644
--- a/drivers/staging/usbip/stub.h
+++ b/drivers/staging/usbip/stub.h
@@ -86,6 +86,7 @@ struct bus_id_priv {
 	char status;
 	int interf_count;
 	struct stub_device *sdev;
+	struct usb_device *udev;
 	char shutdown_busid;
 };
 
diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c
index 1bd13cf..ee899f0 100644
--- a/drivers/staging/usbip/stub_dev.c
+++ b/drivers/staging/usbip/stub_dev.c
@@ -386,6 +386,7 @@ static int stub_probe(struct usb_device *udev)
 	/* set private data to usb_device */
 	dev_set_drvdata(&udev->dev, sdev);
 	busid_priv->sdev = sdev;
+	busid_priv->udev = udev;
 
 	err = stub_add_files(&udev->dev);
 	if (err) {
diff --git a/drivers/staging/usbip/stub_main.c b/drivers/staging/usbip/stub_main.c
index bd7b83a..9c5832a 100644
--- a/drivers/staging/usbip/stub_main.c
+++ b/drivers/staging/usbip/stub_main.c
@@ -19,6 +19,7 @@
 
 #include <linux/string.h>
 #include <linux/module.h>
+#include <linux/device.h>
 
 #include "usbip_common.h"
 #include "stub.h"
@@ -187,6 +188,34 @@ static ssize_t store_match_busid(struct device_driver *dev, const char *buf,
 static DRIVER_ATTR(match_busid, S_IRUSR | S_IWUSR, show_match_busid,
 		   store_match_busid);
 
+static ssize_t rebind_store(struct device_driver *dev, const char *buf,
+				 size_t count)
+{
+	int ret;
+	int len;
+	struct bus_id_priv *bid;
+
+	/* buf length should be less that BUSID_SIZE */
+	len = strnlen(buf, BUSID_SIZE);
+
+	if (!(len < BUSID_SIZE))
+		return -EINVAL;
+
+	bid = get_busid_priv(buf);
+	if (!bid)
+		return -ENODEV;
+
+	ret = device_attach(&bid->udev->dev);
+	if (ret < 0) {
+		dev_err(&bid->udev->dev, "rebind failed\n");
+		return ret;
+	}
+
+	return count;
+}
+
+static DRIVER_ATTR_WO(rebind);
+
 static struct stub_priv *stub_priv_pop_from_listhead(struct list_head *listhead)
 {
 	struct stub_priv *priv, *tmp;
@@ -267,6 +296,13 @@ static int __init usbip_host_init(void)
 		goto err_create_file;
 	}
 
+	ret = driver_create_file(&stub_driver.drvwrap.driver,
+				 &driver_attr_rebind);
+	if (ret) {
+		pr_err("driver_create_file failed\n");
+		goto err_create_file;
+	}
+
 	pr_info(DRIVER_DESC " v" USBIP_VERSION "\n");
 	return ret;
 
@@ -282,6 +318,9 @@ static void __exit usbip_host_exit(void)
 	driver_remove_file(&stub_driver.drvwrap.driver,
 			   &driver_attr_match_busid);
 
+	driver_remove_file(&stub_driver.drvwrap.driver,
+			   &driver_attr_rebind);
+
 	/*
 	 * deregister() calls stub_disconnect() for all devices. Device
 	 * specific data is cleared in stub_disconnect().
diff --git a/drivers/staging/usbip/userspace/src/usbip_unbind.c b/drivers/staging/usbip/userspace/src/usbip_unbind.c
index 7180dbe..a4a496c 100644
--- a/drivers/staging/usbip/userspace/src/usbip_unbind.c
+++ b/drivers/staging/usbip/userspace/src/usbip_unbind.c
@@ -44,8 +44,10 @@ static int unbind_device(char *busid)
 	char bus_type[] = "usb";
 	int rc, ret = -1;
 
-	char attr_name[] = "unbind";
+	char unbind_attr_name[] = "unbind";
 	char unbind_attr_path[SYSFS_PATH_MAX];
+	char rebind_attr_name[] = "rebind";
+	char rebind_attr_path[SYSFS_PATH_MAX];
 
 	struct udev *udev;
 	struct udev_device *dev;
@@ -71,7 +73,7 @@ static int unbind_device(char *busid)
 	/* Unbind device from driver. */
 	snprintf(unbind_attr_path, sizeof(unbind_attr_path), "%s/%s/%s/%s/%s/%s",
 		 SYSFS_MNT_PATH, SYSFS_BUS_NAME, bus_type, SYSFS_DRIVERS_NAME,
-		 USBIP_HOST_DRV_NAME, attr_name);
+		 USBIP_HOST_DRV_NAME, unbind_attr_name);
 
 	rc = write_sysfs_attribute(unbind_attr_path, busid, strlen(busid));
 	if (rc < 0) {
@@ -86,6 +88,17 @@ static int unbind_device(char *busid)
 		goto err_close_udev;
 	}
 
+	/* Trigger new probing. */
+	snprintf(rebind_attr_path, sizeof(unbind_attr_path), "%s/%s/%s/%s/%s/%s",
+			SYSFS_MNT_PATH, SYSFS_BUS_NAME, bus_type, SYSFS_DRIVERS_NAME,
+			USBIP_HOST_DRV_NAME, rebind_attr_name);
+
+	rc = write_sysfs_attribute(rebind_attr_path, busid, strlen(busid));
+	if (rc < 0) {
+		err("error rebinding");
+		goto err_close_udev;
+	}
+
 	ret = 0;
 	info("unbind device on busid %s: complete", busid);
 
-- 
1.8.1.2


  parent reply	other threads:[~2014-03-08 12:54 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-08 12:53 [PATCH 00/18] Resend of usbip-utils migration patches and various other fixes Valentina Manea
2014-03-08 12:53 ` [PATCH 01/18] staging: usbip: userspace: migrate usbip_bind to libudev Valentina Manea
2014-03-08 12:53 ` [PATCH 02/18] staging: usbip: userspace: remove useless libsysfs includes Valentina Manea
2014-03-08 12:53 ` [PATCH 03/18] staging: usbip: userspace: migrate usbip_unbind to libudev Valentina Manea
2014-03-08 12:53 ` [PATCH 04/18] staging: usbip: userspace: migrate usbip_list " Valentina Manea
2014-03-08 12:53 ` [PATCH 05/18] staging: usbip: userspace: re-add interface information listing Valentina Manea
2014-03-08 12:53 ` [PATCH 06/18] staging: usbip: userspace: add new list API Valentina Manea
2014-03-08 12:53 ` [PATCH 07/18] staging: usbip: userspace: move sysfs_utils to libsrc Valentina Manea
2014-03-08 12:53 ` [PATCH 08/18] staging: usbip: userspace: migrate usbip_host_driver to libudev Valentina Manea
2014-03-08 12:53 ` [PATCH 09/18] staging: usbip: userspace: remove class device infrastructure in vhci_driver Valentina Manea
2014-03-08 12:53 ` [PATCH 10/18] staging: usbip: userspace: migrate vhci_driver to libudev Valentina Manea
2014-03-08 12:53 ` [PATCH 11/18] staging: usbip: userspace: remove libsysfs flag and autoconf check Valentina Manea
2014-03-08 12:53 ` [PATCH 12/18] staging: usbip: userspace: update dependencies in README Valentina Manea
2014-03-08 12:53 ` [PATCH 13/18] staging: usbip: userspace: increase version to 2.0 Valentina Manea
2014-03-08 12:53 ` [PATCH 14/18] staging: usbip: let client choose device configuration Valentina Manea
2014-03-08 12:53 ` Valentina Manea [this message]
2014-03-08 12:53 ` [PATCH 16/18] staging: usbip: claim ports used by shared devices Valentina Manea
2014-03-08 12:53 ` [PATCH 17/18] staging: usbip: userspace: don't throw error when trying to read configuration specific attributes Valentina Manea
2014-03-08 12:53 ` [PATCH 18/18] staging: usbip: userspace: add hwdata as optional dependency in README Valentina Manea
2014-03-09  6:50 ` [PATCH 00/18] Resend of usbip-utils migration patches and various other fixes Greg KH
2014-03-09 15:53   ` Valentina Manea
2014-03-09 16:58     ` Greg KH

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=1394283216-1277-16-git-send-email-valentina.manea.m@gmail.com \
    --to=valentina.manea.m@gmail.com \
    --cc=andy.grover@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=dominik.paulus@fau.de \
    --cc=firefly@lists.rosedu.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ihadzic@research.bell-labs.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=ly80toro@cip.cs.fau.de \
    --cc=shuah.kh@samsung.com \
    --cc=tobias.polzer@fau.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®