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 03/18] staging: usbip: userspace: migrate usbip_unbind to libudev
Date: Sat, 8 Mar 2014 14:53:21 +0200 [thread overview]
Message-ID: <1394283216-1277-4-git-send-email-valentina.manea.m@gmail.com> (raw)
In-Reply-To: <1394283216-1277-1-git-send-email-valentina.manea.m@gmail.com>
This patch modifies usbip_unbind to use libudev.
Signed-off-by: Valentina Manea <valentina.manea.m@gmail.com>
Reviewed-by: Shuah Khan <shuah.kh@samsung.com>
---
drivers/staging/usbip/userspace/src/usbip_unbind.c | 93 +++++++---------------
1 file changed, 29 insertions(+), 64 deletions(-)
diff --git a/drivers/staging/usbip/userspace/src/usbip_unbind.c b/drivers/staging/usbip/userspace/src/usbip_unbind.c
index cace878..7180dbe 100644
--- a/drivers/staging/usbip/userspace/src/usbip_unbind.c
+++ b/drivers/staging/usbip/userspace/src/usbip_unbind.c
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <sysfs/libsysfs.h>
+#include <libudev.h>
#include <errno.h>
#include <stdio.h>
@@ -27,6 +27,7 @@
#include "usbip_common.h"
#include "utils.h"
#include "usbip.h"
+#include "sysfs_utils.h"
static const char usbip_unbind_usage_string[] =
"usbip unbind <args>\n"
@@ -41,92 +42,56 @@ void usbip_unbind_usage(void)
static int unbind_device(char *busid)
{
char bus_type[] = "usb";
- struct sysfs_driver *usbip_host_drv;
- struct sysfs_device *dev;
- struct dlist *devlist;
- int verified = 0;
int rc, ret = -1;
char attr_name[] = "unbind";
- char sysfs_mntpath[SYSFS_PATH_MAX];
char unbind_attr_path[SYSFS_PATH_MAX];
- struct sysfs_attribute *unbind_attr;
-
- /* verify the busid device is using usbip-host */
- usbip_host_drv = sysfs_open_driver(bus_type, USBIP_HOST_DRV_NAME);
- if (!usbip_host_drv) {
- err("could not open %s driver: %s", USBIP_HOST_DRV_NAME,
- strerror(errno));
- return -1;
- }
- devlist = sysfs_get_driver_devices(usbip_host_drv);
- if (!devlist) {
- err("%s is not in use by any devices", USBIP_HOST_DRV_NAME);
- goto err_close_usbip_host_drv;
- }
+ struct udev *udev;
+ struct udev_device *dev;
+ const char *driver;
- dlist_for_each_data(devlist, dev, struct sysfs_device) {
- if (!strncmp(busid, dev->name, strlen(busid)) &&
- !strncmp(dev->driver_name, USBIP_HOST_DRV_NAME,
- strlen(USBIP_HOST_DRV_NAME))) {
- verified = 1;
- break;
- }
- }
+ /* Create libudev context. */
+ udev = udev_new();
- if (!verified) {
- err("device on busid %s is not using %s", busid,
- USBIP_HOST_DRV_NAME);
- goto err_close_usbip_host_drv;
+ /* Check whether the device with this bus ID exists. */
+ dev = udev_device_new_from_subsystem_sysname(udev, "usb", busid);
+ if (!dev) {
+ err("device with the specified bus ID does not exist");
+ goto err_close_udev;
}
- /*
- * NOTE: A read and write of an attribute value of the device busid
- * refers to must be done to start probing. That way a rebind of the
- * default driver for the device occurs.
- *
- * This seems very hackish and adds a lot of pointless code. I think it
- * should be done in the kernel by the driver after del_match_busid is
- * finished!
- */
-
- rc = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
- if (rc < 0) {
- err("sysfs must be mounted: %s", strerror(errno));
- return -1;
+ /* Check whether the device is using usbip-host driver. */
+ driver = udev_device_get_driver(dev);
+ if (!driver || strcmp(driver, "usbip-host")) {
+ err("device is not bound to usbip-host driver");
+ goto err_close_udev;
}
+ /* Unbind device from driver. */
snprintf(unbind_attr_path, sizeof(unbind_attr_path), "%s/%s/%s/%s/%s/%s",
- sysfs_mntpath, SYSFS_BUS_NAME, bus_type, SYSFS_DRIVERS_NAME,
+ SYSFS_MNT_PATH, SYSFS_BUS_NAME, bus_type, SYSFS_DRIVERS_NAME,
USBIP_HOST_DRV_NAME, attr_name);
- /* read a device attribute */
- unbind_attr = sysfs_open_attribute(unbind_attr_path);
- if (!unbind_attr) {
- err("could not open %s/%s: %s", busid, attr_name,
- strerror(errno));
- return -1;
+ rc = write_sysfs_attribute(unbind_attr_path, busid, strlen(busid));
+ if (rc < 0) {
+ err("error unbinding device %s from driver", busid);
+ goto err_close_udev;
}
- /* notify driver of unbind */
+ /* Notify driver of unbind. */
rc = modify_match_busid(busid, 0);
if (rc < 0) {
err("unable to unbind device on %s", busid);
+ goto err_close_udev;
}
- rc = sysfs_write_attribute(unbind_attr, busid,
- SYSFS_BUS_ID_SIZE);
- if (rc < 0) {
- dbg("bind driver at %s failed", busid);
- }
- sysfs_close_attribute(unbind_attr);
-
ret = 0;
- printf("unbind device on busid %s: complete\n", busid);
+ info("unbind device on busid %s: complete", busid);
-err_close_usbip_host_drv:
- sysfs_close_driver(usbip_host_drv);
+err_close_udev:
+ udev_device_unref(dev);
+ udev_unref(udev);
return ret;
}
--
1.8.1.2
next prev 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 ` Valentina Manea [this message]
2014-03-08 12:53 ` [PATCH 04/18] staging: usbip: userspace: migrate usbip_list to libudev 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 ` [PATCH 15/18] staging: usbip: trigger driver probing after unbinding from usbip-host Valentina Manea
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-4-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®