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 10/18] staging: usbip: userspace: migrate vhci_driver to libudev
Date: Sat,  8 Mar 2014 14:53:28 +0200	[thread overview]
Message-ID: <1394283216-1277-11-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 migrates vhci_driver to libudev.

Signed-off-by: Valentina Manea <valentina.manea.m@gmail.com>
Reviewed-by: Shuah Khan <shuah.kh@samsung.com>
---
 .../staging/usbip/userspace/libsrc/usbip_common.h  |   1 -
 .../staging/usbip/userspace/libsrc/vhci_driver.c   | 154 ++++++---------------
 .../staging/usbip/userspace/libsrc/vhci_driver.h   |   5 +-
 3 files changed, 44 insertions(+), 116 deletions(-)

diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_common.h b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
index ed9b43b..23be848 100644
--- a/drivers/staging/usbip/userspace/libsrc/usbip_common.h
+++ b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
@@ -5,7 +5,6 @@
 #ifndef __USBIP_COMMON_H
 #define __USBIP_COMMON_H
 
-#include <sysfs/libsysfs.h>
 #include <libudev.h>
 
 #include <stdint.h>
diff --git a/drivers/staging/usbip/userspace/libsrc/vhci_driver.c b/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
index fa68bed..8901fcb 100644
--- a/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
+++ b/drivers/staging/usbip/userspace/libsrc/vhci_driver.c
@@ -7,6 +7,7 @@
 #include <limits.h>
 #include <netdb.h>
 #include <libudev.h>
+#include "sysfs_utils.h"
 
 #undef  PROGNAME
 #define PROGNAME "libusbip"
@@ -36,7 +37,7 @@ err:
 
 
 
-static int parse_status(char *value)
+static int parse_status(const char *value)
 {
 	int ret = 0;
 	char *c;
@@ -108,42 +109,33 @@ static int parse_status(char *value)
 
 static int refresh_imported_device_list(void)
 {
-	struct sysfs_attribute *attr_status;
+	const char *attr_status;
 
-
-	attr_status = sysfs_get_device_attr(vhci_driver->hc_device, "status");
+	attr_status = udev_device_get_sysattr_value(vhci_driver->hc_device,
+					       "status");
 	if (!attr_status) {
-		dbg("sysfs_get_device_attr(\"status\") failed: %s",
-		    vhci_driver->hc_device->name);
+		err("udev_device_get_sysattr_value failed");
 		return -1;
 	}
 
-	dbg("name: %s  path: %s  len: %d  method: %d  value: %s",
-	    attr_status->name, attr_status->path, attr_status->len,
-	    attr_status->method, attr_status->value);
-
-	return parse_status(attr_status->value);
+	return parse_status(attr_status);
 }
 
 static int get_nports(void)
 {
 	char *c;
 	int nports = 0;
-	struct sysfs_attribute *attr_status;
+	const char *attr_status;
 
-	attr_status = sysfs_get_device_attr(vhci_driver->hc_device, "status");
+	attr_status = udev_device_get_sysattr_value(vhci_driver->hc_device,
+					       "status");
 	if (!attr_status) {
-		dbg("sysfs_get_device_attr(\"status\") failed: %s",
-		    vhci_driver->hc_device->name);
+		err("udev_device_get_sysattr_value failed");
 		return -1;
 	}
 
-	dbg("name: %s  path: %s  len: %d  method: %d  value: %s",
-	    attr_status->name, attr_status->path, attr_status->len,
-	    attr_status->method, attr_status->value);
-
 	/* skip a header line */
-	c = strchr(attr_status->value, '\n');
+	c = strchr(attr_status, '\n');
 	if (!c)
 		return 0;
 	c++;
@@ -160,50 +152,6 @@ static int get_nports(void)
 	return nports;
 }
 
-static int get_hc_busid(char *sysfs_mntpath, char *hc_busid)
-{
-	struct sysfs_driver *sdriver;
-	char sdriver_path[SYSFS_PATH_MAX];
-
-	struct sysfs_device *hc_dev;
-	struct dlist *hc_devs;
-
-	int found = 0;
-
-	snprintf(sdriver_path, SYSFS_PATH_MAX, "%s/%s/%s/%s/%s", sysfs_mntpath,
-	SYSFS_BUS_NAME, USBIP_VHCI_BUS_TYPE, SYSFS_DRIVERS_NAME,
-	USBIP_VHCI_DRV_NAME);
-
-	sdriver = sysfs_open_driver_path(sdriver_path);
-	if (!sdriver) {
-		dbg("sysfs_open_driver_path failed: %s", sdriver_path);
-		dbg("make sure " USBIP_CORE_MOD_NAME ".ko and "
-		    USBIP_VHCI_DRV_NAME ".ko are loaded!");
-		return -1;
-	}
-
-	hc_devs = sysfs_get_driver_devices(sdriver);
-	if (!hc_devs) {
-		dbg("sysfs_get_driver failed");
-		goto err;
-	}
-
-	/* assume only one vhci_hcd */
-	dlist_for_each_data(hc_devs, hc_dev, struct sysfs_device) {
-		strncpy(hc_busid, hc_dev->bus_id, SYSFS_BUS_ID_SIZE);
-		found = 1;
-	}
-
-err:
-	sysfs_close_driver(sdriver);
-
-	if (found)
-		return 0;
-
-	dbg("%s not found", hc_busid);
-	return -1;
-}
-
 /*
  * Read the given port's record.
  *
@@ -215,7 +163,6 @@ err:
  */
 static int read_record(int rhport, char *host, unsigned long host_len,
 		char *port, unsigned long port_len, char *busid)
-
 {
 	int part;
 	FILE *file;
@@ -272,36 +219,21 @@ static int read_record(int rhport, char *host, unsigned long host_len,
 
 int usbip_vhci_driver_open(void)
 {
-	int ret;
-	char hc_busid[SYSFS_BUS_ID_SIZE];
-
 	udev_context = udev_new();
 	if (!udev_context) {
 		err("udev_new failed");
 		return -1;
 	}
 
-	vhci_driver = (struct usbip_vhci_driver *) calloc(1, sizeof(*vhci_driver));
-	if (!vhci_driver) {
-		dbg("calloc failed");
-		return -1;
-	}
-
-	ret = sysfs_get_mnt_path(vhci_driver->sysfs_mntpath, SYSFS_PATH_MAX);
-	if (ret < 0) {
-		dbg("sysfs_get_mnt_path failed");
-		goto err;
-	}
-
-	ret = get_hc_busid(vhci_driver->sysfs_mntpath, hc_busid);
-	if (ret < 0)
-		goto err;
+	vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver));
 
 	/* will be freed in usbip_driver_close() */
-	vhci_driver->hc_device = sysfs_open_device(USBIP_VHCI_BUS_TYPE,
-						   hc_busid);
+	vhci_driver->hc_device =
+		udev_device_new_from_subsystem_sysname(udev_context,
+						       USBIP_VHCI_BUS_TYPE,
+						       USBIP_VHCI_DRV_NAME);
 	if (!vhci_driver->hc_device) {
-		dbg("sysfs_open_device failed");
+		err("udev_device_new_from_subsystem_sysname failed");
 		goto err;
 	}
 
@@ -312,13 +244,11 @@ int usbip_vhci_driver_open(void)
 	if (refresh_imported_device_list())
 		goto err;
 
-
 	return 0;
 
-
 err:
-	if (vhci_driver->hc_device)
-		sysfs_close_device(vhci_driver->hc_device);
+	udev_device_unref(vhci_driver->hc_device);
+
 	if (vhci_driver)
 		free(vhci_driver);
 
@@ -335,8 +265,8 @@ void usbip_vhci_driver_close()
 	if (!vhci_driver)
 		return;
 
-	if (vhci_driver->hc_device)
-		sysfs_close_device(vhci_driver->hc_device);
+	udev_device_unref(vhci_driver->hc_device);
+
 	free(vhci_driver);
 
 	vhci_driver = NULL;
@@ -370,24 +300,24 @@ int usbip_vhci_get_free_port(void)
 
 int usbip_vhci_attach_device2(uint8_t port, int sockfd, uint32_t devid,
 		uint32_t speed) {
-	struct sysfs_attribute *attr_attach;
 	char buff[200]; /* what size should be ? */
+	char attach_attr_path[SYSFS_PATH_MAX];
+	char attr_attach[] = "attach";
+	const char *path;
 	int ret;
 
-	attr_attach = sysfs_get_device_attr(vhci_driver->hc_device, "attach");
-	if (!attr_attach) {
-		dbg("sysfs_get_device_attr(\"attach\") failed: %s",
-		    vhci_driver->hc_device->name);
-		return -1;
-	}
-
 	snprintf(buff, sizeof(buff), "%u %d %u %u",
 			port, sockfd, devid, speed);
 	dbg("writing: %s", buff);
 
-	ret = sysfs_write_attribute(attr_attach, buff, strlen(buff));
+	path = udev_device_get_syspath(vhci_driver->hc_device);
+	snprintf(attach_attr_path, sizeof(attach_attr_path), "%s/%s",
+		 path, attr_attach);
+	dbg("attach attribute path: %s", attach_attr_path);
+
+	ret = write_sysfs_attribute(attach_attr_path, buff, strlen(buff));
 	if (ret < 0) {
-		dbg("sysfs_write_attribute failed");
+		dbg("write_sysfs_attribute failed");
 		return -1;
 	}
 
@@ -412,23 +342,23 @@ int usbip_vhci_attach_device(uint8_t port, int sockfd, uint8_t busnum,
 
 int usbip_vhci_detach_device(uint8_t port)
 {
-	struct sysfs_attribute  *attr_detach;
+	char detach_attr_path[SYSFS_PATH_MAX];
+	char attr_detach[] = "detach";
 	char buff[200]; /* what size should be ? */
+	const char *path;
 	int ret;
 
-	attr_detach = sysfs_get_device_attr(vhci_driver->hc_device, "detach");
-	if (!attr_detach) {
-		dbg("sysfs_get_device_attr(\"detach\") failed: %s",
-		    vhci_driver->hc_device->name);
-		return -1;
-	}
-
 	snprintf(buff, sizeof(buff), "%u", port);
 	dbg("writing: %s", buff);
 
-	ret = sysfs_write_attribute(attr_detach, buff, strlen(buff));
+	path = udev_device_get_syspath(vhci_driver->hc_device);
+	snprintf(detach_attr_path, sizeof(detach_attr_path), "%s/%s",
+		 path, attr_detach);
+	dbg("detach attribute path: %s", detach_attr_path);
+
+	ret = write_sysfs_attribute(detach_attr_path, buff, strlen(buff));
 	if (ret < 0) {
-		dbg("sysfs_write_attribute failed");
+		dbg("write_sysfs_attribute failed");
 		return -1;
 	}
 
diff --git a/drivers/staging/usbip/userspace/libsrc/vhci_driver.h b/drivers/staging/usbip/userspace/libsrc/vhci_driver.h
index 4d87a2a..fa2316c 100644
--- a/drivers/staging/usbip/userspace/libsrc/vhci_driver.h
+++ b/drivers/staging/usbip/userspace/libsrc/vhci_driver.h
@@ -5,7 +5,7 @@
 #ifndef __VHCI_DRIVER_H
 #define __VHCI_DRIVER_H
 
-#include <sysfs/libsysfs.h>
+#include <libudev.h>
 #include <stdint.h>
 
 #include "usbip_common.h"
@@ -27,10 +27,9 @@ struct usbip_imported_device {
 };
 
 struct usbip_vhci_driver {
-	char sysfs_mntpath[SYSFS_PATH_MAX];
 
 	/* /sys/devices/platform/vhci_hcd */
-	struct sysfs_device *hc_device;
+	struct udev_device *hc_device;
 
 	int nports;
 	struct usbip_imported_device idev[MAXNPORT];
-- 
1.8.1.2


  parent reply	other threads:[~2014-03-08 12:56 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 ` Valentina Manea [this message]
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-11-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®