From: Shuah Khan <shuah.kh@samsung.com>
To: Valentina Manea <valentina.manea.m@gmail.com>,
gregkh@linuxfoundation.org
Cc: tobias.polzer@fau.de, dominik.paulus@fau.de,
ly80toro@cip.cs.fau.de, ihadzic@research.bell-labs.com,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
devel@driverdev.osuosl.org, firefly@lists.rosedu.org,
Shuah Khan <shuah.kh@samsung.com>
Subject: Re: [PATCH 10/12] staging: usbip: userspace: migrate vhci_driver to libudev
Date: Thu, 06 Mar 2014 15:07:10 -0700 [thread overview]
Message-ID: <5318F18E.7000204@samsung.com> (raw)
In-Reply-To: <1393960252-21247-11-git-send-email-valentina.manea.m@gmail.com>
On 03/04/2014 12:10 PM, Valentina Manea wrote:
> This patch migrates vhci_driver to libudev.
>
> Signed-off-by: Valentina Manea <valentina.manea.m@gmail.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 9c11060..c4a72c3 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 73a163aa..e7839a0 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);
> + dbg("udev_device_get_sysattr_value failed");
I am afraid you are going to be tired of me saying this :) err() please.
I have had to run usbip userspace tools with strace a few times to
figure out where it failed. Hence this insistence on err() where it is
makes sense.
> 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);
> + dbg("udev_device_get_sysattr_value failed");
Same here err()
> 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) {
> dbg("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");
> + dbg("udev_device_new_from_subsystem_sysname");
Same comment about error
> 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 e72baa0..8a84fdf 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"
> @@ -32,10 +32,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];
>
You have my Reviewed-by after making the recommended changes.
Reviewed-by: Shuah Khan <shuah.kh@samsung.com>
-- Shuah
--
Shuah Khan
Senior Linux Kernel Developer - Open Source Group
Samsung Research America(Silicon Valley)
shuah.kh@samsung.com | (970) 672-0658
next prev parent reply other threads:[~2014-03-06 22:07 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-04 19:10 [PATCH 00/12] Migrate usbip-utils " Valentina Manea
2014-03-04 19:10 ` [PATCH 01/12] staging: usbip: userspace: migrate usbip_bind " Valentina Manea
2014-03-05 9:42 ` Dan Carpenter
2014-03-05 10:15 ` Dan Carpenter
2014-03-06 6:17 ` Valentina Manea
2014-03-05 9:56 ` Dan Carpenter
2014-03-06 16:15 ` Shuah Khan
2014-03-06 18:19 ` Dan Carpenter
2014-03-04 19:10 ` [PATCH 02/12] staging: usbip: userspace: remove useless libsysfs includes Valentina Manea
2014-03-04 19:10 ` [PATCH 03/12] staging: usbip: userspace: migrate usbip_unbind to libudev Valentina Manea
2014-03-06 16:31 ` Shuah Khan
2014-03-04 19:10 ` [PATCH 04/12] staging: usbip: userspace: migrate usbip_list " Valentina Manea
2014-03-06 20:57 ` Shuah Khan
2014-03-04 19:10 ` [PATCH 05/12] staging: usbip: userspace: re-add interface information listing Valentina Manea
2014-03-06 21:11 ` Shuah Khan
2014-03-04 19:10 ` [PATCH 06/12] staging: usbip: userspace: add new list API Valentina Manea
2014-03-05 6:35 ` Greg KH
2014-03-05 10:16 ` Dan Carpenter
[not found] ` <CAByK=5bzS4R0sGj5w5x8gc8DcKXvnr58WskoShuq6G30YTsOgQ@mail.gmail.com>
2014-03-06 19:55 ` [firefly] " Greg KH
2014-03-04 19:10 ` [PATCH 07/12] staging: usbip: userspace: move sysfs_utils to libsrc Valentina Manea
2014-03-04 19:10 ` [PATCH 08/12] staging: usbip: userspace: migrate usbip_host_driver to libudev Valentina Manea
2014-03-06 21:43 ` Shuah Khan
2014-03-04 19:10 ` [PATCH 09/12] staging: usbip: userspace: remove class device infrastructure in vhci_driver Valentina Manea
2014-03-06 21:59 ` Shuah Khan
2014-03-04 19:10 ` [PATCH 10/12] staging: usbip: userspace: migrate vhci_driver to libudev Valentina Manea
2014-03-06 22:07 ` Shuah Khan [this message]
2014-03-04 19:10 ` [PATCH 11/12] staging: usbip: userspace: remove libsysfs flag and autoconf check Valentina Manea
2014-03-04 19:10 ` [PATCH 12/12] staging: usbip: userspace: update dependencies in README Valentina Manea
2014-03-05 6:37 ` [PATCH 00/12] Migrate usbip-utils to libudev 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=5318F18E.7000204@samsung.com \
--to=shuah.kh@samsung.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=tobias.polzer@fau.de \
--cc=valentina.manea.m@gmail.com \
/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
Powered by JetHome