Skip to contentSkip to conversation

staging: usbip: misc. userspace changes

PATCH In review matt mooney 2 participants 24 messages Jun 20, 2011 – Jul 6, 2011 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: usbip: misc. userspace changes

Hi Greg,

This patch set contains only userspace changes. Next, I will take a look at attach and detach, which should soon lead to the reason why usbip is not currently working.

Thanks,
matt

matt mooney (22):
staging: usbip: userspace: update cleanup.sh
staging: usbip: userspace: usbip_common.h: cleanup log macros
staging: usbip: userspace: usbip_common.h: move enums
staging: usbip: userspace: usbip_common.h: fixup header includes
staging: usbip: userspace: libsrc: set program name for logging
staging: usbip: userspace: usbip.c: add log option
staging: usbip: userspace: libsrc: remove usbip.h
staging: usbip: userspace: libsrc: change all output messages to
debug
staging: usbip: userspace: usbip: modify command failure
staging: usbip: userspace: utils: remove libsysfs circumvention
staging: usbip: userspace: utils.c: rewrite modify_match_busid
staging: usbip: userspace: usbip_bind.c: major rewrite of the
implementation
staging: usbip: userspace: usbip_unbind.c: implement using libsysfs
staging: usbip: userspace: usbip list: edit output messages
staging: usbip: userspace: usbip list: move output header
staging: usbip: userspace: rename stub driver files
staging: usbip: userspace: usbip_host: update function and variable
names
staging: usbip: userspace: usbipd: major cleanup of daemon
staging: usbip: userspace: usbip_network.c: coding style cleanup
staging: usbip: userspace: add new prefix for usbip network code
staging: usbip: userspace: fix header installation bug
staging: usbip: userspace: configure.ac: change package data

 drivers/staging/usbip/userspace/Makefile.am        |    4 +-
 drivers/staging/usbip/userspace/cleanup.sh         |   10 +-
 drivers/staging/usbip/userspace/configure.ac       |    2 +-
 drivers/staging/usbip/userspace/libsrc/Makefile.am |    8 +-
 .../staging/usbip/userspace/libsrc/stub_driver.c   |  390 -----------
 .../staging/usbip/userspace/libsrc/stub_driver.h   |   36 -
 drivers/staging/usbip/userspace/libsrc/usbip.h     |   19 -
 .../staging/usbip/userspace/libsrc/usbip_common.c  |   19 +-
 .../staging/usbip/userspace/libsrc/usbip_common.h  |  118 ++--
 .../usbip/userspace/libsrc/usbip_host_driver.c     |  401 +++++++++++
 .../usbip/userspace/libsrc/usbip_host_driver.h     |   48 ++
 .../staging/usbip/userspace/libsrc/vhci_driver.c   |   99 ++--
 .../staging/usbip/userspace/libsrc/vhci_driver.h   |   13 +-
 drivers/staging/usbip/userspace/src/Makefile.am    |    6 +-
 drivers/staging/usbip/userspace/src/usbip.c        |   26 +-
 drivers/staging/usbip/userspace/src/usbip_attach.c |    8 +-
 drivers/staging/usbip/userspace/src/usbip_bind.c   |  303 +++++----
 drivers/staging/usbip/userspace/src/usbip_list.c   |   81 ++-
 .../staging/usbip/userspace/src/usbip_network.c    |  121 ++--
 .../staging/usbip/userspace/src/usbip_network.h    |   39 +-
 drivers/staging/usbip/userspace/src/usbip_unbind.c |  123 +++-
 drivers/staging/usbip/userspace/src/usbipd.c       |  697 ++++++++++----------
 drivers/staging/usbip/userspace/src/utils.c        |  317 ++--------
 drivers/staging/usbip/userspace/src/utils.h        |   31 +-
 24 files changed, 1417 insertions(+), 1502 deletions(-)
 delete mode 100644 drivers/staging/usbip/userspace/libsrc/stub_driver.c
 delete mode 100644 drivers/staging/usbip/userspace/libsrc/stub_driver.h
 delete mode 100644 drivers/staging/usbip/userspace/libsrc/usbip.h
 create mode 100644 drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
 create mode 100644 drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h
Signature · 1 line
1.7.5.2
#1 lore raw

PATCH 1/22 staging: usbip: userspace: update cleanup.sh

Modify $FILES to account for the new directory layout. Also, sort the list of files within the variable to make it human-readable.

---
 drivers/staging/usbip/userspace/cleanup.sh |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
drivers/staging/usbip/userspace/cleanup.sh +6 -4
index da2f89b..955c3cc 100755
@@ -1,10 +1,12 @@
-#!/bin/sh -x
-
+#!/bin/sh
 
 if [ -r Makefile ]; then
 	make distclean
 fi
 
-FILES="configure cscope.out Makefile.in depcomp compile config.guess config.sub config.h.in~ config.log config.status ltmain.sh libtool config.h.in autom4te.cache missing aclocal.m4 install-sh cmd/Makefile.in lib/Makefile.in Makefile lib/Makefile cmd/Makefile"
+FILES="aclocal.m4 autom4te.cache compile config.guess config.h.in config.log \
+       config.status config.sub configure cscope.out depcomp install-sh      \
+       libsrc/Makefile libsrc/Makefile.in libtool ltmain.sh Makefile         \
+       Makefile.in missing src/Makefile src/Makefile.in"
 
-rm -Rf $FILES
+rm -vRf $FILES
Signature · 1 line
1.7.5.2
#2 lore raw

PATCH 2/22 staging: usbip: userspace: usbip_common.h: cleanup log macros

In reply to matt mooney

Provide better abstraction for easier modification, and align the macros for readability. Remove notice() because it is not used.

---
 .../staging/usbip/userspace/libsrc/usbip_common.h  |   88 ++++++++++----------
 1 files changed, 43 insertions(+), 45 deletions(-)
drivers/staging/usbip/userspace/libsrc/usbip_common.h +43 -45
index 32b27ed..090b7c5 100644
@@ -58,51 +58,49 @@ extern int usbip_use_syslog;
 extern int usbip_use_stderr;
 extern int usbip_use_debug ;
 
-#define err(fmt, args...)	do { \
-	if (usbip_use_syslog) { \
-		syslog(LOG_ERR, "usbip err: %13s:%4d (%-12s) " fmt "\n", \
-			__FILE__, __LINE__, __FUNCTION__,  ##args); \
-	} \
-	if (usbip_use_stderr) { \
-		fprintf(stderr, "usbip err: %13s:%4d (%-12s) " fmt "\n", \
-			__FILE__, __LINE__, __FUNCTION__,  ##args); \
-	} \
-} while (0)
-
-#define notice(fmt, args...)	do { \
-	if (usbip_use_syslog) { \
-		syslog(LOG_DEBUG, "usbip: " fmt, ##args); \
-	} \
-	if (usbip_use_stderr) { \
-		fprintf(stderr, "usbip: " fmt "\n",  ##args); \
-	} \
-} while (0)
-
-#define info(fmt, args...)	do { \
-	if (usbip_use_syslog) { \
-		syslog(LOG_DEBUG, fmt, ##args); \
-	} \
-	if (usbip_use_stderr) { \
-		fprintf(stderr, fmt "\n",  ##args); \
-	} \
-} while (0)
-
-#define dbg(fmt, args...)	do { \
-	if (usbip_use_debug) { \
-		if (usbip_use_syslog) { \
-			syslog(LOG_DEBUG, "usbip dbg: %13s:%4d (%-12s) " fmt, \
-				__FILE__, __LINE__, __FUNCTION__,  ##args); \
-		} \
-		if (usbip_use_stderr) { \
-			fprintf(stderr, "usbip dbg: %13s:%4d (%-12s) " fmt "\n", \
-				__FILE__, __LINE__, __FUNCTION__,  ##args); \
-		} \
-	} \
-} while (0)
-
-
-#define BUG()	do { err("sorry, it's a bug"); abort(); } while (0)
-
+#define PROGNAME "usbip"
+
+#define pr_fmt(fmt)	"%s: %s: " fmt "\n", PROGNAME
+#define dbg_fmt(fmt)	pr_fmt("%s:%d:[%s] " fmt), "debug",	\
+		        __FILE__, __LINE__, __FUNCTION__
+
+#define err(fmt, args...)						\
+	do {								\
+		if (usbip_use_syslog) {					\
+			syslog(LOG_ERR, pr_fmt(fmt), "error", ##args);	\
+		}							\
+		if (usbip_use_stderr) {					\
+			fprintf(stderr, pr_fmt(fmt), "error", ##args);	\
+		}							\
+	} while (0)
+
+#define info(fmt, args...)						\
+	do {								\
+		if (usbip_use_syslog) {					\
+			syslog(LOG_INFO, pr_fmt(fmt), "info", ##args);	\
+		}							\
+		if (usbip_use_stderr) {					\
+			fprintf(stderr, pr_fmt(fmt), "info", ##args);	\
+		}							\
+	} while (0)
+
+#define dbg(fmt, args...)						\
+	do {								\
+	if (usbip_use_debug) {						\
+		if (usbip_use_syslog) {					\
+			syslog(LOG_DEBUG, dbg_fmt(fmt), ##args);	\
+		}							\
+		if (usbip_use_stderr) {					\
+			fprintf(stderr, dbg_fmt(fmt), ##args);		\
+		}							\
+	}								\
+	} while (0)
+
+#define BUG()						\
+	do {						\
+		err("sorry, it's a bug!");		\
+		abort();				\
+	} while (0)
 
 struct usbip_usb_interface {
 	uint8_t bInterfaceClass;
Signature · 1 line
1.7.5.2
#3 lore raw

PATCH 3/22 staging: usbip: userspace: usbip_common.h: move enums

In reply to matt mooney

Relocate enums to follow logging macros.

---
 .../staging/usbip/userspace/libsrc/usbip_common.h  |   50 +++++++++----------
 1 files changed, 24 insertions(+), 26 deletions(-)
drivers/staging/usbip/userspace/libsrc/usbip_common.h +24 -26
index 090b7c5..7dadb21 100644
@@ -30,30 +30,6 @@
 #define USBIP_HOST_DRV_NAME	"usbip-host"
 #define USBIP_VHCI_DRV_NAME	"vhci_hcd"
 
-enum usb_device_speed {
-	USB_SPEED_UNKNOWN = 0,                  /* enumerating */
-	USB_SPEED_LOW, USB_SPEED_FULL,          /* usb 1.1 */
-	USB_SPEED_HIGH,                         /* usb 2.0 */
-	USB_SPEED_VARIABLE                      /* wireless (usb 2.5) */
-};
-
-/* FIXME: how to sync with drivers/usbip_common.h ? */
-enum usbip_device_status{
-	/* sdev is available. */
-	SDEV_ST_AVAILABLE = 0x01,
-	/* sdev is now used. */
-	SDEV_ST_USED,
-	/* sdev is unusable because of a fatal error. */
-	SDEV_ST_ERROR,
-
-	/* vdev does not connect a remote device. */
-	VDEV_ST_NULL,
-	/* vdev is used, but the USB address is not assigned yet */
-	VDEV_ST_NOTASSIGNED,
-	VDEV_ST_USED,
-	VDEV_ST_ERROR
-};
-
 extern int usbip_use_syslog;
 extern int usbip_use_stderr;
 extern int usbip_use_debug ;
@@ -102,6 +78,30 @@ extern int usbip_use_debug ;
 		abort();				\
 	} while (0)
 
+enum usb_device_speed {
+	USB_SPEED_UNKNOWN = 0,                  /* enumerating */
+	USB_SPEED_LOW, USB_SPEED_FULL,          /* usb 1.1 */
+	USB_SPEED_HIGH,                         /* usb 2.0 */
+	USB_SPEED_VARIABLE                      /* wireless (usb 2.5) */
+};
+
+/* FIXME: how to sync with drivers/usbip_common.h ? */
+enum usbip_device_status{
+	/* sdev is available. */
+	SDEV_ST_AVAILABLE = 0x01,
+	/* sdev is now used. */
+	SDEV_ST_USED,
+	/* sdev is unusable because of a fatal error. */
+	SDEV_ST_ERROR,
+
+	/* vdev does not connect a remote device. */
+	VDEV_ST_NULL,
+	/* vdev is used, but the USB address is not assigned yet */
+	VDEV_ST_NOTASSIGNED,
+	VDEV_ST_USED,
+	VDEV_ST_ERROR
+};
+
 struct usbip_usb_interface {
 	uint8_t bInterfaceClass;
 	uint8_t bInterfaceSubClass;
@@ -109,8 +109,6 @@ struct usbip_usb_interface {
 	uint8_t padding;	/* alignment */
 } __attribute__((packed));
 
-
-
 struct usbip_usb_device {
 	char path[SYSFS_PATH_MAX];
 	char busid[SYSFS_BUS_ID_SIZE];
Signature · 1 line
1.7.5.2
#4 lore raw

PATCH 4/22 staging: usbip: userspace: usbip_common.h: fixup header includes

In reply to matt mooney

Remove unnecessary headers from the file, and add the now missing headers into the files that actually need them.

---
 .../staging/usbip/userspace/libsrc/stub_driver.c   |    2 ++
 .../staging/usbip/userspace/libsrc/usbip_common.h  |   18 ++++++++----------
 drivers/staging/usbip/userspace/src/utils.c        |    1 +
 3 files changed, 11 insertions(+), 10 deletions(-)
drivers/staging/usbip/userspace/libsrc/stub_driver.c +2 -0
index 4d4d171..6a1272d 100644
@@ -4,6 +4,8 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+
+#include <errno.h>
 #include <unistd.h>
 
 #include "usbip.h"
drivers/staging/usbip/userspace/libsrc/usbip_common.h +8 -10
index 7dadb21..eedefbd 100644
@@ -2,20 +2,18 @@
  * Copyright (C) 2005-2007 Takahiro Hirofuchi
  */
 
-#ifndef _USBIP_COMMON_H
-#define _USBIP_COMMON_H
+#ifndef __USBIP_COMMON_H
+#define __USBIP_COMMON_H
+
+#include <sysfs/libsysfs.h>
 
-#include <unistd.h>
 #include <stdint.h>
-#include <syslog.h>
-#include <errno.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
+#include <string.h>
 
-#include <sysfs/libsysfs.h>
-#include <netdb.h>
-#include <sys/socket.h>
+#include <syslog.h>
+#include <unistd.h>
 
 #ifndef USBIDS_FILE
 #define USBIDS_FILE "/usr/share/hwdata/usb.ids"
@@ -146,4 +144,4 @@ void usbip_names_free(void);
 void usbip_names_get_product(char *buff, size_t size, uint16_t vendor, uint16_t product);
 void usbip_names_get_class(char *buff, size_t size, uint8_t class, uint8_t subclass, uint8_t protocol);
 
-#endif
+#endif /* __USBIP_COMMON_H */
drivers/staging/usbip/userspace/src/utils.c +1 -0
index 1da1109..2a25cec 100644
@@ -6,6 +6,7 @@
 #include <sysfs/libsysfs.h>
 
 #include <limits.h>
+#include <errno.h>
 #include <stdio.h>
 #include <string.h>
 
Signature · 1 line
1.7.5.2
#5 lore raw

PATCH 5/22 staging: usbip: userspace: libsrc: set program name for logging

In reply to matt mooney

Set the program name to "libusbip" to identify that the message is from the library code.

---
 .../staging/usbip/userspace/libsrc/stub_driver.c   |    3 +++
 .../staging/usbip/userspace/libsrc/usbip_common.c  |    3 +++
 .../staging/usbip/userspace/libsrc/vhci_driver.c   |    3 +++
 3 files changed, 9 insertions(+), 0 deletions(-)
drivers/staging/usbip/userspace/libsrc/stub_driver.c +3 -0
index 6a1272d..b62f6b2 100644
@@ -10,6 +10,9 @@
 
 #include "usbip.h"
 
+#undef  PROGNAME
+#define PROGNAME "libusbip"
+
 struct usbip_stub_driver *stub_driver;
 
 static struct sysfs_driver *open_sysfs_stub_driver(void)
drivers/staging/usbip/userspace/libsrc/usbip_common.c +3 -0
index e9d0614..6ac4361 100644
@@ -5,6 +5,9 @@
 #include "usbip.h"
 #include "names.h"
 
+#undef  PROGNAME
+#define PROGNAME "libusbip"
+
 int usbip_use_syslog = 0;
 int usbip_use_stderr = 0;
 int usbip_use_debug  = 0;
drivers/staging/usbip/userspace/libsrc/vhci_driver.c +3 -0
index 386f63b..f10121c 100644
@@ -5,6 +5,9 @@
 
 #include "usbip.h"
 
+#undef  PROGNAME
+#define PROGNAME "libusbip"
+
 struct usbip_vhci_driver *vhci_driver;
 
 static struct usbip_imported_device *imported_device_init(struct usbip_imported_device *idev, char *busid)
Signature · 1 line
1.7.5.2
#6 lore raw

PATCH 6/22 staging: usbip: userspace: usbip.c: add log option

In reply to matt mooney

Add option for logging with syslog, and default to use stderr for error and info messages.

---
 drivers/staging/usbip/userspace/src/usbip.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
drivers/staging/usbip/userspace/src/usbip.c +10 -3
index 8940cd0..cdfe4c2 100644
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 
 #include <getopt.h>
+#include <syslog.h>
 
 #include "usbip_common.h"
 #include "usbip.h"
@@ -33,7 +34,7 @@ static int usbip_version(int argc, char *argv[]);
 static const char usbip_version_string[] = PACKAGE_STRING;
 
 static const char usbip_usage_string[] =
-	"usbip [--debug] [version]\n"
+	"usbip [--debug] [--log] [version]\n"
 	"             [help] <command> <args>\n";
 
 static void usbip_usage(void)
@@ -138,12 +139,15 @@ int main(int argc, char *argv[])
 {
 	static const struct option opts[] = {
 		{ "debug", no_argument, NULL, 'd' },
-		{ NULL, 0, NULL, 0 }
+		{ "log",   no_argument, NULL, 'l' },
+		{ NULL,    0,           NULL,  0  }
 	};
+
 	char *cmd;
 	int opt;
 	int i, rc = -1;
 
+	usbip_use_stderr = 1;
 	opterr = 0;
 	for (;;) {
 		opt = getopt_long(argc, argv, "+d", opts, NULL);
@@ -154,7 +158,10 @@ int main(int argc, char *argv[])
 		switch (opt) {
 		case 'd':
 			usbip_use_debug = 1;
-			usbip_use_stderr = 1;
+			break;
+		case 'l':
+			usbip_use_syslog = 1;
+			openlog("", LOG_PID, LOG_USER);
 			break;
 		default:
 			goto err_out;
Signature · 1 line
1.7.5.2
#7 lore raw

PATCH 7/22 staging: usbip: userspace: libsrc: remove usbip.h

In reply to matt mooney

Remove the library version of usbip.h because its sole purpose was to include other headers, which is bad practice. Also modify include guards for consistency.

---
 drivers/staging/usbip/userspace/Makefile.am        |    2 +-
 drivers/staging/usbip/userspace/libsrc/Makefile.am |    2 +-
 .../staging/usbip/userspace/libsrc/stub_driver.c   |    3 ++-
 .../staging/usbip/userspace/libsrc/stub_driver.h   |   11 ++++++-----
 drivers/staging/usbip/userspace/libsrc/usbip.h     |   19 -------------------
 .../staging/usbip/userspace/libsrc/usbip_common.c  |    2 +-
 .../staging/usbip/userspace/libsrc/vhci_driver.c   |    4 ++--
 .../staging/usbip/userspace/libsrc/vhci_driver.h   |   13 ++++++++-----
 8 files changed, 21 insertions(+), 35 deletions(-)
 delete mode 100644 drivers/staging/usbip/userspace/libsrc/usbip.h
drivers/staging/usbip/userspace/Makefile.am +1 -1
index 4b66cbe..d557fe9 100644
@@ -1,6 +1,6 @@
 SUBDIRS := libsrc src
 includedir := @includedir@/usbip
 include_HEADERS := $(addprefix libsrc/, \
-		     usbip.h usbip_common.h vhci_driver.h stub_driver.h)
+		     usbip_common.h vhci_driver.h stub_driver.h)
 
 dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8 usbip_bind_driver.8)
drivers/staging/usbip/userspace/libsrc/Makefile.am +1 -1
index 77ecf6b..6696aa7 100644
@@ -3,5 +3,5 @@ libusbip_la_CFLAGS   := @EXTRA_CFLAGS@
 libusbip_la_LDFLAGS  := -version-info @LIBUSBIP_VERSION@
 
 lib_LTLIBRARIES := libusbip.la
-libusbip_la_SOURCES := names.c names.h stub_driver.c stub_driver.h usbip.h \
+libusbip_la_SOURCES := names.c names.h stub_driver.c stub_driver.h \
 		       usbip_common.c usbip_common.h vhci_driver.c vhci_driver.h
drivers/staging/usbip/userspace/libsrc/stub_driver.c +2 -1
index b62f6b2..0f9593b 100644
@@ -8,7 +8,8 @@
 #include <errno.h>
 #include <unistd.h>
 
-#include "usbip.h"
+#include "usbip_common.h"
+#include "stub_driver.h"
 
 #undef  PROGNAME
 #define PROGNAME "libusbip"
drivers/staging/usbip/userspace/libsrc/stub_driver.h +6 -5
index 332ebc5..9eaf92c 100644
@@ -2,11 +2,11 @@
  * Copyright (C) 2005-2007 Takahiro Hirofuchi
  */
 
-#ifndef _USBIP_STUB_DRIVER_H
-#define _USBIP_STUB_DRIVER_H
-
-#include "usbip.h"
+#ifndef __USBIP_STUB_DRIVER_H
+#define __USBIP_STUB_DRIVER_H
 
+#include <stdint.h>
+#include "usbip_common.h"
 
 struct usbip_stub_driver {
 	int ndevs;
@@ -33,4 +33,5 @@ int usbip_stub_refresh_device_list(void);
 int usbip_stub_export_device(struct usbip_exported_device *edev, int sockfd);
 
 struct usbip_exported_device *usbip_stub_get_device(int num);
-#endif
+
+#endif /* __USBIP_STUB_DRIVER_H */
drivers/staging/usbip/userspace/libsrc/usbip.h deleted +0 -19
deleted file mode 100644
index 7cb8e6f..0000000
@@ -1,19 +0,0 @@
-/*
- * Copyright (C) 2005-2007 Takahiro Hirofuchi
- */
-
-#ifndef _USBIP_H
-#define _USBIP_H
-
-#ifdef HAVE_CONFIG_H
-#include "../config.h"
-#endif
-
-#include "usbip_common.h"
-#include "stub_driver.h"
-#include "vhci_driver.h"
-#ifdef DMALLOC
-#include <dmalloc.h>
-#endif
-
-#endif
drivers/staging/usbip/userspace/libsrc/usbip_common.c +1 -1
index 6ac4361..e0ec23f 100644
@@ -2,7 +2,7 @@
  * Copyright (C) 2005-2007 Takahiro Hirofuchi
  */
 
-#include "usbip.h"
+#include "usbip_common.h"
 #include "names.h"
 
 #undef  PROGNAME
drivers/staging/usbip/userspace/libsrc/vhci_driver.c +2 -2
index f10121c..e663fab 100644
@@ -2,8 +2,8 @@
  * Copyright (C) 2005-2007 Takahiro Hirofuchi
  */
 
-
-#include "usbip.h"
+#include "usbip_common.h"
+#include "vhci_driver.h"
 
 #undef  PROGNAME
 #define PROGNAME "libusbip"
drivers/staging/usbip/userspace/libsrc/vhci_driver.h +8 -5
index a2f7db1..89949aa 100644
@@ -2,13 +2,15 @@
  * Copyright (C) 2005-2007 Takahiro Hirofuchi
  */
 
-#ifndef _VHCI_DRIVER_H
-#define _VHCI_DRIVER_H
+#ifndef __VHCI_DRIVER_H
+#define __VHCI_DRIVER_H
 
-#include "usbip.h"
+#include <sysfs/libsysfs.h>
+#include <stdint.h>
 
-#define USBIP_VHCI_BUS_TYPE "platform"
+#include "usbip_common.h"
 
+#define USBIP_VHCI_BUS_TYPE "platform"
 #define MAXNPORT 128
 
 struct usbip_class_device {
@@ -61,4 +63,5 @@ int usbip_vhci_attach_device(uint8_t port, int sockfd, uint8_t busnum,
 		uint8_t devnum, uint32_t speed);
 
 int usbip_vhci_detach_device(uint8_t port);
-#endif
+
+#endif /* __VHCI_DRIVER_H */
Signature · 1 line
1.7.5.2
#8 lore raw

PATCH 8/22 staging: usbip: userspace: libsrc: change all output messages to debug

In reply to matt mooney

The library should not be displaying random messages intermixed with those from the programs that use them. So, instead, change all of the output from the library to debug only, and allow the programs to decide what to tell the user. This also changes the messages to use the same form, which makes understanding them easier.

---
 .../staging/usbip/userspace/libsrc/stub_driver.c   |   55 ++++++------
 .../staging/usbip/userspace/libsrc/usbip_common.c  |   14 ++--
 .../staging/usbip/userspace/libsrc/vhci_driver.c   |   94 ++++++++++----------
 3 files changed, 80 insertions(+), 83 deletions(-)
drivers/staging/usbip/userspace/libsrc/stub_driver.c +27 -28
index 0f9593b..604aed1 100644
@@ -27,7 +27,7 @@ static struct sysfs_driver *open_sysfs_stub_driver(void)
 
 	ret = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
 	if (ret < 0) {
-		err("sysfs must be mounted");
+		dbg("sysfs_get_mnt_path failed");
 		return NULL;
 	}
 
@@ -37,8 +37,7 @@ static struct sysfs_driver *open_sysfs_stub_driver(void)
 
 	stub_driver = sysfs_open_driver_path(stub_driver_path);
 	if (!stub_driver) {
-		err(USBIP_CORE_MOD_NAME ".ko and " USBIP_HOST_DRV_NAME
-		    ".ko must be loaded");
+		dbg("sysfs_open_driver_path failed");
 		return NULL;
 	}
 
@@ -82,7 +81,7 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev)
 			break;
 
 		if (errno != ENOENT) {
-			err("error stat'ing %s", attrpath);
+			dbg("stat failed: %s", attrpath);
 			return -1;
 		}
 
@@ -91,21 +90,21 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev)
 	}
 
 	if (retries == 0)
-		err("usbip_status not ready after %d retries",
-			SYSFS_OPEN_RETRIES);
+		dbg("usbip_status not ready after %d retries",
+		    SYSFS_OPEN_RETRIES);
 	else if (retries < SYSFS_OPEN_RETRIES)
-		info("warning: usbip_status ready after %d retries",
-			 SYSFS_OPEN_RETRIES - retries);
+		dbg("warning: usbip_status ready after %d retries",
+		    SYSFS_OPEN_RETRIES - retries);
 
 	attr = sysfs_open_attribute(attrpath);
 	if (!attr) {
-		err("open %s", attrpath);
+		dbg("sysfs_open_attribute failed: %s", attrpath);
 		return -1;
 	}
 
 	ret = sysfs_read_attribute(attr);
 	if (ret) {
-		err("read %s", attrpath);
+		dbg("sysfs_read_attribute failed: %s", attrpath);
 		sysfs_close_attribute(attr);
 		return -1;
 	}
@@ -134,13 +133,13 @@ static struct usbip_exported_device *usbip_exported_device_new(char *sdevpath)
 
 	edev = (struct usbip_exported_device *) calloc(1, sizeof(*edev));
 	if (!edev) {
-		err("alloc device");
+		dbg("calloc failed");
 		return NULL;
 	}
 
 	edev->sudev = sysfs_open_device_path(sdevpath);
 	if (!edev->sudev) {
-		err("open %s", sdevpath);
+		dbg("sysfs_open_device_path failed: %s", sdevpath);
 		goto err;
 	}
 
@@ -155,7 +154,7 @@ static struct usbip_exported_device *usbip_exported_device_new(char *sdevpath)
 		sizeof(struct usbip_usb_interface);
 	edev = (struct usbip_exported_device *) realloc(edev, size);
 	if (!edev) {
-		err("alloc device");
+		dbg("realloc failed");
 		goto err;
 	}
 
@@ -204,8 +203,8 @@ static int refresh_exported_devices(void)
 
 	suinf_list = sysfs_get_driver_devices(stub_driver->sysfs_driver);
 	if (!suinf_list) {
-		info("bind " USBIP_HOST_DRV_NAME ".ko to a usb device to be "
-		     "exportable!\n");
+		dbg("bind " USBIP_HOST_DRV_NAME ".ko to a usb device to be "
+		    "exportable!\n");
 		goto bye;
 	}
 
@@ -215,7 +214,7 @@ static int refresh_exported_devices(void)
 		/* get usb device of this usb interface */
 		sudev = sysfs_get_device_parent(suinf);
 		if (!sudev) {
-			err("get parent dev of %s", suinf->name);
+			dbg("sysfs_get_device_parent failed: %s", suinf->name);
 			continue;
 		}
 
@@ -229,7 +228,7 @@ static int refresh_exported_devices(void)
 
 		edev = usbip_exported_device_new(sudev->path);
 		if (!edev) {
-			err("usbip_exported_device new");
+			dbg("usbip_exported_device_new failed");
 			continue;
 		}
 
@@ -257,7 +256,7 @@ int usbip_stub_refresh_device_list(void)
 	stub_driver->edev_list = dlist_new_with_delete(sizeof(struct usbip_exported_device),
 			usbip_exported_device_delete);
 	if (!stub_driver->edev_list) {
-		err("alloc dlist");
+		dbg("dlist_new_with_delete failed");
 		return -1;
 	}
 
@@ -275,7 +274,7 @@ int usbip_stub_driver_open(void)
 
 	stub_driver = (struct usbip_stub_driver *) calloc(1, sizeof(*stub_driver));
 	if (!stub_driver) {
-		err("alloc stub_driver");
+		dbg("calloc failed");
 		return -1;
 	}
 
@@ -284,7 +283,7 @@ int usbip_stub_driver_open(void)
 	stub_driver->edev_list = dlist_new_with_delete(sizeof(struct usbip_exported_device),
 			usbip_exported_device_delete);
 	if (!stub_driver->edev_list) {
-		err("alloc dlist");
+		dbg("dlist_new_with_delete failed");
 		goto err;
 	}
 
@@ -334,16 +333,16 @@ int usbip_stub_export_device(struct usbip_exported_device *edev, int sockfd)
 
 
 	if (edev->status != SDEV_ST_AVAILABLE) {
-		info("device not available, %s", edev->udev.busid);
+		dbg("device not available: %s", edev->udev.busid);
 		switch( edev->status ) {
 			case SDEV_ST_ERROR:
-				info("     status SDEV_ST_ERROR");
+				dbg("status SDEV_ST_ERROR");
 				break;
 			case SDEV_ST_USED:
-				info("     status SDEV_ST_USED");
+				dbg("status SDEV_ST_USED");
 				break;
 			default:
-				info("     status unknown: 0x%x", edev->status);
+				dbg("status unknown: 0x%x", edev->status);
 		}
 		return -1;
 	}
@@ -357,21 +356,21 @@ int usbip_stub_export_device(struct usbip_exported_device *edev, int sockfd)
 
 	attr = sysfs_open_attribute(attrpath);
 	if (!attr) {
-		err("open %s", attrpath);
+		dbg("sysfs_open_attribute failed: %s", attrpath);
 		return -1;
 	}
 
 	snprintf(sockfd_buff, sizeof(sockfd_buff), "%d\n", sockfd);
 
 	dbg("write: %s", sockfd_buff);
-
 	ret = sysfs_write_attribute(attr, sockfd_buff, strlen(sockfd_buff));
 	if (ret < 0) {
-		err("write sockfd %s to %s", sockfd_buff, attrpath);
+		dbg("sysfs_write_attribute failed:  sockfd %s to %s",
+		    sockfd_buff, attrpath);
 		goto err_write_sockfd;
 	}
 
-	info("connect %s", edev->udev.busid);
+	dbg("connect: %s", edev->udev.busid);
 
 err_write_sockfd:
 	sysfs_close_attribute(attr);
drivers/staging/usbip/userspace/libsrc/usbip_common.c +7 -7
index e0ec23f..154b4b1 100644
@@ -120,19 +120,19 @@ int read_attr_value(struct sysfs_device *dev, const char *name, const char *form
 
 	attr = sysfs_open_attribute(attrpath);
 	if (!attr) {
-		err("open attr %s", attrpath);
+		dbg("sysfs_open_attribute failed: %s", attrpath);
 		return 0;
 	}
 
 	ret = sysfs_read_attribute(attr);
 	if (ret < 0) {
-		err("read attr");
+		dbg("sysfs_read_attribute failed");
 		goto err;
 	}
 
 	ret = sscanf(attr->value, format, &num);
 	if (ret < 1) {
-		err("sscanf");
+		dbg("sscanf failed");
 		goto err;
 	}
 
@@ -154,19 +154,19 @@ int read_attr_speed(struct sysfs_device *dev)
 
 	attr = sysfs_open_attribute(attrpath);
 	if (!attr) {
-		err("open attr");
+		dbg("sysfs_open_attribute failed: %s", attrpath);
 		return 0;
 	}
 
 	ret = sysfs_read_attribute(attr);
 	if (ret < 0) {
-		err("read attr");
+		dbg("sysfs_read_attribute failed");
 		goto err;
 	}
 
 	ret = sscanf(attr->value, "%s\n", speed);
 	if (ret < 1) {
-		err("sscanf");
+		dbg("sscanf failed");
 		goto err;
 	}
 err:
@@ -222,7 +222,7 @@ int read_usb_interface(struct usbip_usb_device *udev, int i,
 
 	sif = sysfs_open_device("usb", busid);
 	if (!sif) {
-		err("open sif of %s", busid);
+		dbg("sysfs_open_device(\"usb\", \"%s\") failed", busid);
 		return -1;
 	}
 
drivers/staging/usbip/userspace/libsrc/vhci_driver.c +46 -48

259 lines not on this page · raw message

Signature · 1 line
1.7.5.2
#9 lore raw

PATCH 9/22 staging: usbip: userspace: usbip: modify command failure

In reply to matt mooney

When a bad option is given, display a message stating such and output usage. When a bad command is given, output command help.

---
 drivers/staging/usbip/userspace/src/usbip.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
drivers/staging/usbip/userspace/src/usbip.c +8 -5
index cdfe4c2..583b179 100644
@@ -125,13 +125,13 @@ static int usbip_version(int argc, char *argv[])
 	(void) argc;
 	(void) argv;
 
-	printf("%s\n", usbip_version_string);
+	printf(PROGNAME " (%s)\n", usbip_version_string);
 	return 0;
 }
 
 static int run_command(const struct command *cmd, int argc, char *argv[])
 {
-	dbg("running command: `%s'\n", cmd->name);
+	dbg("running command: `%s'", cmd->name);
 	return cmd->fn(argc, argv);
 }
 
@@ -163,8 +163,11 @@ int main(int argc, char *argv[])
 			usbip_use_syslog = 1;
 			openlog("", LOG_PID, LOG_USER);
 			break;
+		case '?':
+			printf("usbip: invalid option\n");
 		default:
-			goto err_out;
+			usbip_usage();
+			goto out;
 		}
 	}
 
@@ -180,8 +183,8 @@ int main(int argc, char *argv[])
 			}
 	}
 
-err_out:
-	usbip_usage();
+	/* invalid command */
+	usbip_help(0, NULL);
 out:
 	return (rc > -1 ? EXIT_SUCCESS : EXIT_FAILURE);
 }
Signature · 1 line
1.7.5.2
#10 lore raw

PATCH 10/22 staging: usbip: userspace: utils: remove libsysfs circumvention

In reply to matt mooney

Removes all of the helper functions that used a lot of hard-coded values intead of libsysfs. Most of these functions were unused anyway.

---
 drivers/staging/usbip/userspace/src/utils.c |  250 ---------------------------
 drivers/staging/usbip/userspace/src/utils.h |   31 ++--
 2 files changed, 18 insertions(+), 263 deletions(-)
drivers/staging/usbip/userspace/src/utils.c +0 -250
index 2a25cec..9b31c78 100644
@@ -62,253 +62,3 @@ int modify_match_busid(char *busid, int add)
 
 	return 0;
 }
-
-int read_integer(char *path)
-{
-	char buff[100];
-	int fd;
-	int ret = 0;
-
-	memset(buff, 0, sizeof(buff));
-
-	fd = open(path, O_RDONLY);
-	if (fd < 0)
-		return -1;
-
-	ret = read(fd, buff, sizeof(buff));
-	if (ret < 0) {
-		close(fd);
-		return -1;
-	}
-
-	sscanf(buff, "%d", &ret);
-
-	close(fd);
-
-	return ret;
-}
-
-int read_string(char *path, char *string, size_t len)
-{
-	int fd;
-	int ret = 0;
-	char  *p;
-
-	memset(string, 0, len);
-
-	fd = open(path, O_RDONLY);
-	if (fd < 0) {
-		string = NULL;
-		return -1;
-	}
-
-	ret = read(fd, string, len-1);
-	if (ret < 0) {
-		string = NULL;
-		close(fd);
-		return -1;
-	}
-
-	p = strchr(string, '\n');
-	*p = '\0';
-
-	close(fd);
-
-	return 0;
-}
-
-int write_integer(char *path, int value)
-{
-	int fd;
-	int ret;
-	char buff[100];
-
-	snprintf(buff, sizeof(buff), "%d", value);
-
-	fd = open(path, O_WRONLY);
-	if (fd < 0)
-		return -1;
-
-	ret = write(fd, buff, strlen(buff));
-	if (ret < 0) {
-		close(fd);
-		return -1;
-	}
-
-	close(fd);
-
-	return 0;
-}
-
-int read_bConfigurationValue(char *busid)
-{
-	char path[PATH_MAX];
-
-	snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/bConfigurationValue", busid);
-
-	return read_integer(path);
-}
-
-int write_bConfigurationValue(char *busid, int config)
-{
-	char path[PATH_MAX];
-
-	snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/bConfigurationValue", busid);
-
-	return write_integer(path, config);
-}
-
-int read_bNumInterfaces(char *busid)
-{
-	char path[PATH_MAX];
-
-	snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/bNumInterfaces", busid);
-
-	return read_integer(path);
-}
-
-int read_bDeviceClass(char *busid)
-{
-	char path[PATH_MAX];
-
-	snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/bDeviceClass", busid);
-
-	return read_integer(path);
-}
-
-int getdriver(char *busid, int conf, int infnum, char *driver, size_t len)
-{
-	char path[PATH_MAX];
-	char linkto[PATH_MAX];
-	const char none[] = "none";
-	int ret;
-
-	snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s:%d.%d/driver", busid, conf, infnum);
-
-	/* readlink does not add NULL */
-	memset(linkto, 0, sizeof(linkto));
-	ret = readlink(path, linkto, sizeof(linkto)-1);
-	if (ret < 0) {
-		strncpy(driver, none, len);
-		return -1;
-	} else {
-		strncpy(driver, basename(linkto), len);
-		return 0;
-	}
-}
-
-int getdevicename(char *busid, char *name, size_t len)
-{
-	char path[PATH_MAX];
-	char idProduct[10], idVendor[10];
-
-	snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/idVendor", busid);
-	read_string(path, idVendor, sizeof(idVendor));
-
-	snprintf(path, PATH_MAX, "/sys/bus/usb/devices/%s/idProduct", busid);
-	read_string(path, idProduct, sizeof(idProduct));
-
-	if (!idVendor[0] || !idProduct[0])
-		return -1;
-
-	snprintf(name, len, "%s:%s", idVendor, idProduct);
-
-	return 0;
-}
-
-#define MAXLINE 100
-
-/* if this cannot read a whole line, return -1 */
-int readline(int sockfd, char *buff, int bufflen)
-{
-	int ret;
-	char c;
-	int index = 0;
-
-
-	while (index < bufflen) {
-		ret = read(sockfd, &c, sizeof(c));
-		if (ret < 0 && errno == EINTR)
-			continue;
-		if (ret <= 0) {
-			return -1;
-		}
-
-		buff[index] = c;
-
-		if ( index > 0 && buff[index-1] == '\r'  && buff[index] == '\n') {
-			/* end of line */
-			buff[index-1] = '\0';	/* get rid of delimitor */
-			return index;
-		} else
-			index++;
-	}
-
-	return -1;
-}
-
-#if 0
-int writeline(int sockfd, char *str, int strlen)
-{
-	int ret;
-	int index = 0;
-	int len;
-	char buff[MAXLINE];
-
-	if (strlen + 3 > MAXLINE)
-		return -1;
-
-	strncpy(buff, str, strlen);
-	buff[strlen+1] = '\r';
-	buff[strlen+2] = '\n';
-	buff[strlen+3] = '\0';
-
-	len = strlen + 3;
-
-	while (len > 0) {
-		ret = write(sockfd, buff+index, len);
-		if (ret <= 0) {
-			return -1;
-		}
-
-		len -= ret;
-		index += ret;
-	}
-
-	return index;
-}
-#endif
-
-int writeline(int sockfd, char *str, int strlen)
-{
-	int ret;
-	int index = 0;
-	int len;
-	char buff[MAXLINE];
-
-	len = strnlen(str, strlen);
-
-	if (strlen + 2 > MAXLINE)
-		return -1;
-
-	memcpy(buff, str, strlen);
-	buff[strlen] = '\r';
-	buff[strlen+1] = '\n';		/* strlen+1 <= MAXLINE-1 */
-
-	len = strlen + 2;
-
-	while (len > 0) {
-		ret = write(sockfd, buff+index, len);
-		if (ret < 0 && errno == EINTR)
-			continue;
-		if (ret <= 0) {
-			return -1;
-		}
-
-		len -= ret;
-		index += ret;
-	}
-
-	return index;
-}
-
drivers/staging/usbip/userspace/src/utils.h +18 -13
index b50e95a..fdcb14d 100644
@@ -1,19 +1,24 @@
+/*
+ * Copyright (C) 2011 matt mooney <[email protected]>
+ *               2005-2007 Takahiro Hirofuchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef __UTILS_H
 #define __UTILS_H
 
-#include <stdlib.h>
-
 int modify_match_busid(char *busid, int add);
-int read_string(char *path, char *, size_t len);
-int read_integer(char *path);
-int getdevicename(char *busid, char *name, size_t len);
-int getdriver(char *busid, int conf, int infnum, char *driver, size_t len);
-int read_bNumInterfaces(char *busid);
-int read_bConfigurationValue(char *busid);
-int write_integer(char *path, int value);
-int write_bConfigurationValue(char *busid, int config);
-int read_bDeviceClass(char *busid);
-int readline(int sockfd, char *str, int strlen);
-int writeline(int sockfd, char *buff, int bufflen);
 
 #endif /* __UTILS_H */
Signature · 1 line
1.7.5.2
#11 lore raw

PATCH 11/22 staging: usbip: userspace: utils.c: rewrite modify_match_busid

In reply to matt mooney

Rewrite the function to use libsysfs.

---
 drivers/staging/usbip/userspace/src/utils.c |   68 ++++++++++++++++-----------
 1 files changed, 40 insertions(+), 28 deletions(-)
drivers/staging/usbip/userspace/src/utils.c +40 -28
index 9b31c78..2d4966e 100644
@@ -1,64 +1,76 @@
 /*
+ * Copyright (C) 2011 matt mooney <[email protected]>
+ *               2005-2007 Takahiro Hirofuchi
  *
- * Copyright (C) 2005-2007 Takahiro Hirofuchi
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <sysfs/libsysfs.h>
 
-#include <limits.h>
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
 
-#include <fcntl.h>
-#include <libgen.h>
-#include <unistd.h>
-
 #include "usbip_common.h"
 #include "utils.h"
 
 int modify_match_busid(char *busid, int add)
 {
-	int fd;
-	int ret;
+	char bus_type[] = "usb";
+	char attr_name[] = "match_busid";
 	char buff[SYSFS_BUS_ID_SIZE + 4];
 	char sysfs_mntpath[SYSFS_PATH_MAX];
-	char match_busid_path[SYSFS_PATH_MAX];
+	char match_busid_attr_path[SYSFS_PATH_MAX];
+	struct sysfs_attribute *match_busid_attr;
+	int rc, ret = 0;
 
-	ret = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
-	if (ret < 0) {
-		err("sysfs must be mounted");
+	if (strnlen(busid, SYSFS_BUS_ID_SIZE) > SYSFS_BUS_ID_SIZE - 1) {
+		dbg("busid is too long");
 		return -1;
 	}
 
-	snprintf(match_busid_path, sizeof(match_busid_path),
-		 "%s/%s/usb/%s/%s/match_busid", sysfs_mntpath, SYSFS_BUS_NAME,
-		 SYSFS_DRIVERS_NAME, USBIP_HOST_DRV_NAME);
-
-	/* BUS_IS_SIZE includes NULL termination? */
-	if (strnlen(busid, SYSFS_BUS_ID_SIZE) > SYSFS_BUS_ID_SIZE - 1) {
-		dbg("busid is too long");
+	rc = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
+	if (rc < 0) {
+		err("sysfs must be mounted: %s", strerror(errno));
 		return -1;
 	}
 
-	fd = open(match_busid_path, O_WRONLY);
-	if (fd < 0)
+	snprintf(match_busid_attr_path, sizeof(match_busid_attr_path),
+		 "%s/%s/%s/%s/%s/%s", sysfs_mntpath, SYSFS_BUS_NAME, bus_type,
+		 SYSFS_DRIVERS_NAME, USBIP_HOST_DRV_NAME, attr_name);
+
+	match_busid_attr = sysfs_open_attribute(match_busid_attr_path);
+	if (!match_busid_attr) {
+		dbg("problem getting match_busid attribute: %s",
+		    strerror(errno));
 		return -1;
+	}
 
 	if (add)
 		snprintf(buff, SYSFS_BUS_ID_SIZE + 4, "add %s", busid);
 	else
 		snprintf(buff, SYSFS_BUS_ID_SIZE + 4, "del %s", busid);
 
-	dbg("write \"%s\" to %s", buff, match_busid_path);
+	dbg("write \"%s\" to %s", buff, match_busid_attr->path);
 
-	ret = write(fd, buff, sizeof(buff));
-	if (ret < 0) {
-		close(fd);
-		return -1;
+	rc = sysfs_write_attribute(match_busid_attr, buff, sizeof(buff));
+	if (rc < 0) {
+		dbg("failed to write match_busid: %s", strerror(errno));
+		ret = -1;
 	}
 
-	close(fd);
+	sysfs_close_attribute(match_busid_attr);
 
-	return 0;
+	return ret;
 }
Signature · 1 line
1.7.5.2
#12 lore raw

PATCH 12/22 staging: usbip: userspace: usbip_bind.c: major rewrite of the implementation

In reply to matt mooney

Rewrite functions in terms of libsysfs, which eliminates a lot of helper functions simplifying the file layout. Now, the two processes taking place here, an unbind of the old driver and a bind of usbip-host, are single functions and have been renamed along with the controlling function. A check to see if the device is already bound to usbip-host is now included.

---
 drivers/staging/usbip/userspace/src/usbip_bind.c |  303 +++++++++++-----------
 1 files changed, 158 insertions(+), 145 deletions(-)
drivers/staging/usbip/userspace/src/usbip_bind.c +158 -145
index 978b7aa..9ecaf6e 100644
@@ -18,18 +18,23 @@
 
 #include <sysfs/libsysfs.h>
 
-#include <limits.h>
+#include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
-#include <fcntl.h>
 #include <getopt.h>
-#include <unistd.h>
 
 #include "usbip_common.h"
 #include "utils.h"
 #include "usbip.h"
 
+enum unbind_status {
+	UNBIND_ST_OK,
+	UNBIND_ST_USBIP_HOST,
+	UNBIND_ST_FAILED
+};
+
 static const char usbip_bind_usage_string[] =
 	"usbip bind <args>\n"
 	"    -b, --busid=<busid>    Bind " USBIP_HOST_DRV_NAME ".ko to device "
@@ -40,195 +45,202 @@ void usbip_bind_usage(void)
 	printf("usage: %s", usbip_bind_usage_string);
 }
 
-static const char unbind_path_format[] = "/sys/bus/usb/devices/%s/driver/unbind";
-
-/* buggy driver may cause dead lock */
-static int unbind_interface_busid(char *busid)
+/* call at unbound state */
+static int bind_usbip(char *busid)
 {
-	char unbind_path[SYSFS_PATH_MAX];
-	int fd;
-	int ret;
-
-	snprintf(unbind_path, sizeof(unbind_path), unbind_path_format, busid);
-
-	fd = open(unbind_path, O_WRONLY);
-	if (fd < 0) {
-		dbg("opening unbind_path failed: %d", fd);
+	char bus_type[] = "usb";
+	char attr_name[] = "bind";
+	char sysfs_mntpath[SYSFS_PATH_MAX];
+	char bind_attr_path[SYSFS_PATH_MAX];
+	char intf_busid[SYSFS_BUS_ID_SIZE];
+	struct sysfs_device *busid_dev;
+	struct sysfs_attribute *bind_attr;
+	struct sysfs_attribute *bConfValue;
+	struct sysfs_attribute *bNumIntfs;
+	int i, failed = 0;
+	int rc, ret = -1;
+
+	rc = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
+	if (rc < 0) {
+		err("sysfs must be mounted: %s", strerror(errno));
 		return -1;
 	}
 
-	ret = write(fd, busid, strnlen(busid, SYSFS_BUS_ID_SIZE));
-	if (ret < 0) {
-		dbg("write to unbind_path failed: %d", ret);
-		close(fd);
-		return -1;
-	}
-
-	close(fd);
-
-	return 0;
-}
-
-static int unbind_interface(char *busid, int configvalue, int interface)
-{
-	char inf_busid[SYSFS_BUS_ID_SIZE];
-	dbg("unbinding interface");
-
-	snprintf(inf_busid, SYSFS_BUS_ID_SIZE, "%s:%d.%d", busid, configvalue,
-		 interface);
+	snprintf(bind_attr_path, sizeof(bind_attr_path), "%s/%s/%s/%s/%s/%s",
+		 sysfs_mntpath, SYSFS_BUS_NAME, bus_type, SYSFS_DRIVERS_NAME,
+		 USBIP_HOST_DRV_NAME, attr_name);
 
-	return unbind_interface_busid(inf_busid);
-}
-
-static int unbind(char *busid)
-{
-	int configvalue = 0;
-	int ninterface = 0;
-	int devclass = 0;
-	int i;
-	int failed = 0;
-
-	configvalue = read_bConfigurationValue(busid);
-	ninterface  = read_bNumInterfaces(busid);
-	devclass  = read_bDeviceClass(busid);
-
-	if (configvalue < 0 || ninterface < 0 || devclass < 0) {
-		dbg("read config and ninf value, removed?");
+	bind_attr = sysfs_open_attribute(bind_attr_path);
+	if (!bind_attr) {
+		dbg("problem getting bind attribute: %s", strerror(errno));
 		return -1;
 	}
 
-	if (devclass == 0x09) {
-		dbg("skip unbinding of hub");
-		return -1;
+	busid_dev = sysfs_open_device(bus_type, busid);
+	if (!busid_dev) {
+		dbg("sysfs_open_device %s failed: %s", busid, strerror(errno));
+		goto err_close_bind_attr;
 	}
 
-	for (i = 0; i < ninterface; i++) {
-		char driver[PATH_MAX];
-		int ret;
-
-		memset(&driver, 0, sizeof(driver));
-
-		getdriver(busid, configvalue, i, driver, PATH_MAX-1);
+	bConfValue = sysfs_get_device_attr(busid_dev, "bConfigurationValue");
+	bNumIntfs  = sysfs_get_device_attr(busid_dev, "bNumInterfaces");
 
-		dbg(" %s:%d.%d	-> %s ", busid, configvalue, i, driver);
-
-		if (!strncmp("none", driver, PATH_MAX))
-			continue; /* unbound interface */
+	if (!bConfValue || !bNumIntfs) {
+		dbg("problem getting device attributes: %s",
+		    strerror(errno));
+		goto err_close_busid_dev;
+	}
 
-#if 0
-		if (!strncmp("usbip", driver, PATH_MAX))
-			continue; /* already bound to usbip */
-#endif
+	for (i = 0; i < atoi(bNumIntfs->value); i++) {
+		snprintf(intf_busid, SYSFS_BUS_ID_SIZE, "%s:%.1s.%d", busid,
+			 bConfValue->value, i);
 
-		/* unbinding */
-		ret = unbind_interface(busid, configvalue, i);
-		if (ret < 0) {
-			dbg("unbind driver at %s:%d.%d failed",
-			    busid, configvalue, i);
+		rc = sysfs_write_attribute(bind_attr, intf_busid,
+					   SYSFS_BUS_ID_SIZE);
+		if (rc < 0) {
+			dbg("bind driver at %s failed", intf_busid);
 			failed = 1;
 		}
 	}
 
-	if (failed)
-		return -1;
-	else
-		return 0;
-}
-
-static const char bind_path_format[] = "/sys/bus/usb/drivers/%s/bind";
+	if (!failed)
+		ret = 0;
 
-static int bind_interface_busid(char *busid, char *driver)
-{
-	char bind_path[PATH_MAX];
-	int fd;
-	int ret;
+err_close_busid_dev:
+	sysfs_close_device(busid_dev);
+err_close_bind_attr:
+	sysfs_close_attribute(bind_attr);
 
-	snprintf(bind_path, sizeof(bind_path), bind_path_format, driver);
+	return ret;
+}
 
-	fd = open(bind_path, O_WRONLY);
-	if (fd < 0)
+/* buggy driver may cause dead lock */
+static int unbind_other(char *busid)
+{
+	char bus_type[] = "usb";
+	char intf_busid[SYSFS_BUS_ID_SIZE];
+	struct sysfs_device *busid_dev;
+	struct sysfs_device *intf_dev;
+	struct sysfs_driver *intf_drv;
+	struct sysfs_attribute *unbind_attr;
+	struct sysfs_attribute *bConfValue;
+	struct sysfs_attribute *bDevClass;
+	struct sysfs_attribute *bNumIntfs;
+	int i, rc;
+	enum unbind_status status = UNBIND_ST_OK;
+
+	busid_dev = sysfs_open_device(bus_type, busid);
+	if (!busid_dev) {
+		dbg("sysfs_open_device %s failed: %s", busid, strerror(errno));
 		return -1;
+	}
 
-	ret = write(fd, busid, strnlen(busid, SYSFS_BUS_ID_SIZE));
-	if (ret < 0) {
-		close(fd);
-		return -1;
+	bConfValue = sysfs_get_device_attr(busid_dev, "bConfigurationValue");
+	bDevClass  = sysfs_get_device_attr(busid_dev, "bDeviceClass");
+	bNumIntfs  = sysfs_get_device_attr(busid_dev, "bNumInterfaces");
+	if (!bConfValue || !bDevClass || !bNumIntfs) {
+		dbg("problem getting device attributes: %s",
+		    strerror(errno));
+		goto err_close_busid_dev;
 	}
 
-	close(fd);
+	if (!strncmp(bDevClass->value, "09", bDevClass->len)) {
+		dbg("skip unbinding of hub");
+		goto err_close_busid_dev;
+	}
 
-	return 0;
-}
+	for (i = 0; i < atoi(bNumIntfs->value); i++) {
+		snprintf(intf_busid, SYSFS_BUS_ID_SIZE, "%s:%.1s.%d", busid,
+			 bConfValue->value, i);
+		intf_dev = sysfs_open_device(bus_type, intf_busid);
+		if (!intf_dev) {
+			dbg("could not open interface device: %s",
+			    strerror(errno));
+			goto err_close_busid_dev;
+		}
 
-static int bind_interface(char *busid, int configvalue, int interface, char *driver)
-{
-	char inf_busid[SYSFS_BUS_ID_SIZE];
+		dbg("%s -> %s", intf_dev->name,  intf_dev->driver_name);
 
-	snprintf(inf_busid, SYSFS_BUS_ID_SIZE, "%s:%d.%d", busid, configvalue,
-		 interface);
+		if (!strncmp("unknown", intf_dev->driver_name, SYSFS_NAME_LEN))
+			/* unbound interface */
+			continue;
 
-	return bind_interface_busid(inf_busid, driver);
-}
+		if (!strncmp(USBIP_HOST_DRV_NAME, intf_dev->driver_name,
+			     SYSFS_NAME_LEN)) {
+			/* already bound to usbip-host */
+			status = UNBIND_ST_USBIP_HOST;
+			continue;
+		}
 
-/* call at unbound state */
-static int bind_to_usbip(char *busid)
-{
-	int configvalue = 0;
-	int ninterface = 0;
-	int i;
-	int failed = 0;
+		/* unbinding */
+		intf_drv = sysfs_open_driver(bus_type, intf_dev->driver_name);
+		if (!intf_drv) {
+			dbg("could not open interface driver on %s: %s",
+			    intf_dev->name, strerror(errno));
+			goto err_close_intf_dev;
+		}
 
-	configvalue = read_bConfigurationValue(busid);
-	ninterface  = read_bNumInterfaces(busid);
+		unbind_attr = sysfs_get_driver_attr(intf_drv, "unbind");
+		if (!unbind_attr) {
+			dbg("problem getting interface driver attribute: %s",
+			    strerror(errno));
+			goto err_close_intf_drv;
+		}
 
-	if (configvalue < 0 || ninterface < 0) {
-		dbg("read config and ninf value, removed?");
-		return -1;
+		rc = sysfs_write_attribute(unbind_attr, intf_dev->bus_id,
+					   SYSFS_BUS_ID_SIZE);
+		if (rc < 0) {
+			/* NOTE: why keep unbinding other interfaces? */
+			dbg("unbind driver at %s failed", intf_dev->bus_id);
+			status = UNBIND_ST_FAILED;
+		}
+
+		sysfs_close_driver(intf_drv);
+		sysfs_close_device(intf_dev);
 	}
 
-	for (i = 0; i < ninterface; i++) {
-		int ret;
+	goto out;
 
-		ret = bind_interface(busid, configvalue, i,
-				     USBIP_HOST_DRV_NAME);
-		if (ret < 0) {
-			dbg("bind usbip at %s:%d.%d, failed",
-			    busid, configvalue, i);
-			failed = 1;
-			/* need to contine binding at other interfaces */
-		}
-	}
+err_close_intf_drv:
+	sysfs_close_driver(intf_drv);
+err_close_intf_dev:
+	sysfs_close_device(intf_dev);
+err_close_busid_dev:
+	status = UNBIND_ST_FAILED;
+out:
+	sysfs_close_device(busid_dev);
 
-	if (failed)
-		return -1;
-	else
-		return 0;
+	return status;
 }
 
-static int use_device_by_usbip(char *busid)
+static int bind_device(char *busid)
 {
-	int ret;
+	int rc;
 
-	ret = unbind(busid);
-	if (ret < 0) {
-		dbg("unbind drivers of %s, failed", busid);
+	rc = unbind_other(busid);
+	if (rc == UNBIND_ST_FAILED) {
+		err("could not unbind driver from device on busid %s", busid);
+		return -1;
+	} else if (rc == UNBIND_ST_USBIP_HOST) {
+		err("device on busid %s is already bound to %s", busid,
+		    USBIP_HOST_DRV_NAME);
 		return -1;
 	}
 
-	ret = modify_match_busid(busid, 1);
-	if (ret < 0) {
-		dbg("add %s to match_busid, failed", busid);
+	rc = modify_match_busid(busid, 1);
+	if (rc < 0) {
+		err("unable to bind device on %s", busid);
 		return -1;
 	}
 
-	ret = bind_to_usbip(busid);
-	if (ret < 0) {
-		dbg("bind usbip to %s, failed", busid);
+	rc = bind_usbip(busid);
+	if (rc < 0) {
+		err("could not bind device to %s", USBIP_HOST_DRV_NAME);
 		modify_match_busid(busid, 0);
 		return -1;
 	}
 
-	dbg("bind %s complete!", busid);
+	printf("bind device on busid %s: complete\n", busid);
 
 	return 0;
 }
@@ -237,8 +249,9 @@ int usbip_bind(int argc, char *argv[])
 {
 	static const struct option opts[] = {
 		{ "busid", required_argument, NULL, 'b' },
-		{ NULL, 0, NULL, 0 }
+		{ NULL,    0,                 NULL,  0  }
 	};
+
 	int opt;
 	int ret = -1;
 
@@ -250,7 +263,7 @@ int usbip_bind(int argc, char *argv[])
 
 		switch (opt) {
 		case 'b':
-			ret = use_device_by_usbip(optarg);
+			ret = bind_device(optarg);
 			goto out;
 		default:
 			goto err_out;
Signature · 1 line
1.7.5.2
#13 lore raw

PATCH 13/22 staging: usbip: userspace: usbip_unbind.c: implement using libsysfs

In reply to matt mooney

Modify unbind to use libsysfs, and include a check to verify that the device is actually using usbip-host before proceeding. The output messages have been changed to be consistent with `usbip bind'.

---
 drivers/staging/usbip/userspace/src/usbip_unbind.c |  123 +++++++++++++++++---
 1 files changed, 107 insertions(+), 16 deletions(-)
drivers/staging/usbip/userspace/src/usbip_unbind.c +107 -16
index 9978d38..d5a9ab6 100644
@@ -16,10 +16,13 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <sysfs/libsysfs.h>
+
+#include <errno.h>
 #include <stdio.h>
+#include <string.h>
 
 #include <getopt.h>
-#include <unistd.h>
 
 #include "usbip_common.h"
 #include "utils.h"
@@ -35,41 +38,129 @@ void usbip_unbind_usage(void)
 	printf("usage: %s", usbip_unbind_usage_string);
 }
 
-static int use_device_by_other(char *busid)
+static int unbind_device(char *busid)
 {
-	int rc;
-	int config;
+	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[] = "bConfigurationValue";
+	char sysfs_mntpath[SYSFS_PATH_MAX];
+	char busid_attr_path[SYSFS_PATH_MAX];
+	struct sysfs_attribute *busid_attr;
+	char *val = NULL;
+	int len;
+
+	/* 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;
+	}
+
+	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;
+		}
+	}
+
+	if (!verified) {
+		err("device on busid %s is not using %s", busid,
+		    USBIP_HOST_DRV_NAME);
+		goto err_close_usbip_host_drv;
+	}
+
+	/*
+	 * 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;
+	}
 
-	/* read and write the same config value to kick probing */
-	config = read_bConfigurationValue(busid);
-	if (config < 0) {
-		dbg("read bConfigurationValue of %s, failed", busid);
+	snprintf(busid_attr_path, sizeof(busid_attr_path), "%s/%s/%s/%s/%s/%s",
+		 sysfs_mntpath, SYSFS_BUS_NAME, bus_type, SYSFS_DEVICES_NAME,
+		 busid, attr_name);
+
+	/* read a device attribute */
+	busid_attr = sysfs_open_attribute(busid_attr_path);
+	if (!busid_attr) {
+		err("could not open %s/%s: %s", busid, attr_name,
+		    strerror(errno));
 		return -1;
 	}
 
+	if (sysfs_read_attribute(busid_attr) < 0) {
+		err("problem reading attribute: %s", strerror(errno));
+		goto err_out;
+	}
+
+	len = busid_attr->len;
+	val = malloc(len);
+	*val = *busid_attr->value;
+	sysfs_close_attribute(busid_attr);
+
+	/* notify driver of unbind */
 	rc = modify_match_busid(busid, 0);
 	if (rc < 0) {
-		dbg("del %s to match_busid, failed", busid);
+		err("unable to unbind device on %s", busid);
+		goto err_out;
+	}
+
+	/* write the device attribute */
+	busid_attr = sysfs_open_attribute(busid_attr_path);
+	if (!busid_attr) {
+		err("could not open %s/%s: %s", busid, attr_name,
+		    strerror(errno));
 		return -1;
 	}
 
-	rc = write_bConfigurationValue(busid, config);
+	rc = sysfs_write_attribute(busid_attr, val, len);
 	if (rc < 0) {
-		dbg("read bConfigurationValue of %s, failed", busid);
-		return -1;
+		err("problem writing attribute: %s", strerror(errno));
+		goto err_out;
 	}
+	sysfs_close_attribute(busid_attr);
+
+	ret = 0;
+	printf("unbind device on busid %s: complete\n", busid);
 
-	info("bind %s to other drivers than usbip, complete!", busid);
+err_out:
+	free(val);
+err_close_usbip_host_drv:
+	sysfs_close_driver(usbip_host_drv);
 
-	return 0;
+	return ret;
 }
 
 int usbip_unbind(int argc, char *argv[])
 {
 	static const struct option opts[] = {
 		{ "busid", required_argument, NULL, 'b' },
-		{ NULL, 0, NULL, 0 }
+		{ NULL,    0,                 NULL,  0  }
 	};
+
 	int opt;
 	int ret = -1;
 
@@ -81,7 +172,7 @@ int usbip_unbind(int argc, char *argv[])
 
 		switch (opt) {
 		case 'b':
-			ret = use_device_by_other(optarg);
+			ret = unbind_device(optarg);
 			goto out;
 		default:
 			goto err_out;
Signature · 1 line
1.7.5.2
#14 lore raw

PATCH 14/22 staging: usbip: userspace: usbip list: edit output messages

In reply to matt mooney

Edit dbg and normal output messages for consistency and better feedback.

---
 drivers/staging/usbip/userspace/src/usbip_list.c |   58 +++++++++++++---------
 1 files changed, 34 insertions(+), 24 deletions(-)
drivers/staging/usbip/userspace/src/usbip_list.c +34 -24
index 03f6210..afff469 100644
@@ -49,7 +49,7 @@ static int get_exported_devices(int sockfd)
 {
 	char product_name[100];
 	char class_name[100];
-	struct op_devlist_reply rep;
+	struct op_devlist_reply reply;
 	uint16_t code = OP_REP_DEVLIST;
 	struct usbip_usb_device udev;
 	struct usbip_usb_interface uintf;
@@ -58,30 +58,30 @@ static int get_exported_devices(int sockfd)
 
 	rc = usbip_send_op_common(sockfd, OP_REQ_DEVLIST, 0);
 	if (rc < 0) {
-		dbg("usbip_send_op_common");
+		dbg("usbip_send_op_common failed");
 		return -1;
 	}
 
 	rc = usbip_recv_op_common(sockfd, &code);
 	if (rc < 0) {
-		dbg("usbip_recv_op_common");
+		dbg("usbip_recv_op_common failed");
 		return -1;
 	}
 
-	memset(&rep, 0, sizeof(rep));
-	rc = usbip_recv(sockfd, &rep, sizeof(rep));
+	memset(&reply, 0, sizeof(reply));
+	rc = usbip_recv(sockfd, &reply, sizeof(reply));
 	if (rc < 0) {
-		dbg("usbip_recv_op_devlist");
+		dbg("usbip_recv_op_devlist failed");
 		return -1;
 	}
-	PACK_OP_DEVLIST_REPLY(0, &rep);
-	dbg("exportable devices: %d", rep.ndev);
+	PACK_OP_DEVLIST_REPLY(0, &reply);
+	dbg("exportable devices: %d\n", reply.ndev);
 
-	for (i = 0; i < rep.ndev; i++) {
+	for (i = 0; i < reply.ndev; i++) {
 		memset(&udev, 0, sizeof(udev));
 		rc = usbip_recv(sockfd, &udev, sizeof(udev));
 		if (rc < 0) {
-			dbg("usbip_recv: usbip_usb_device[%d]", i);
+			dbg("usbip_recv failed: usbip_usb_device[%d]", i);
 			return -1;
 		}
 		pack_usb_device(0, &udev);
@@ -98,7 +98,7 @@ static int get_exported_devices(int sockfd)
 		for (j = 0; j < udev.bNumInterfaces; j++) {
 			rc = usbip_recv(sockfd, &uintf, sizeof(uintf));
 			if (rc < 0) {
-				dbg("usbip_recv: usbip_usb_interface[%d]", j);
+				dbg("usbip_recv failed: usbip_usb_intf[%d]", j);
 				return -1;
 			}
 			pack_usb_interface(0, &uintf);
@@ -108,7 +108,6 @@ static int get_exported_devices(int sockfd)
 					      uintf.bInterfaceSubClass,
 					      uintf.bInterfaceProtocol);
 			printf("%8s: %2d - %s\n", "", j, class_name);
-
 		}
 		printf("\n");
 	}
@@ -123,16 +122,19 @@ static int list_exported_devices(char *host)
 
 	sockfd = usbip_net_tcp_connect(host, USBIP_PORT_STRING);
 	if (sockfd < 0) {
-		err("unable to connect to %s port %s: %s\n", host,
+		err("could not connect to %s:%s: %s", host,
 		    USBIP_PORT_STRING, gai_strerror(sockfd));
 		return -1;
 	}
-	dbg("connected to %s port %s\n", host, USBIP_PORT_STRING);
-	printf("- %s\n", host);
+	dbg("connected to %s:%s", host, USBIP_PORT_STRING);
+
+	printf("Exportable USB devices\n");
+	printf("======================\n");
+	printf(" - %s\n", host);
 
 	rc = get_exported_devices(sockfd);
 	if (rc < 0) {
-		dbg("get_exported_devices failed");
+		err("failed to get device list from %s", host);
 		return -1;
 	}
 
@@ -193,13 +195,14 @@ static int list_devices(bool parsable)
 
 	ubus = sysfs_open_bus(bus_type);
 	if (!ubus) {
-		err("sysfs_open_bus: %s", strerror(errno));
+		err("could not open %s bus: %s", bus_type, strerror(errno));
 		return -1;
 	}
 
 	devlist = sysfs_get_bus_devices(ubus);
 	if (!devlist) {
-		err("sysfs_get_bus_devices: %s", strerror(errno));
+		err("could not get %s bus devices: %s", bus_type,
+		    strerror(errno));
 		goto err_out;
 	}
 
@@ -215,8 +218,11 @@ static int list_devices(bool parsable)
 		idProduct  = sysfs_get_device_attr(dev, "idProduct");
 		bConfValue = sysfs_get_device_attr(dev, "bConfigurationValue");
 		bNumIntfs  = sysfs_get_device_attr(dev, "bNumInterfaces");
-		if (!idVendor || !idProduct || !bConfValue || !bNumIntfs)
+		if (!idVendor || !idProduct || !bConfValue || !bNumIntfs) {
+			err("problem getting device attributes: %s",
+			    strerror(errno));
 			goto err_out;
+		}
 
 		print_device(dev->bus_id, idVendor->value, idProduct->value,
 			     parsable);
@@ -225,8 +231,11 @@ static int list_devices(bool parsable)
 			snprintf(busid, sizeof(busid), "%s:%.1s.%d",
 				 dev->bus_id, bConfValue->value, i);
 			intf = sysfs_open_device(bus_type, busid);
-			if (!intf)
+			if (!intf) {
+				err("could not open device interface: %s",
+				    strerror(errno));
 				goto err_out;
+			}
 			print_interface(busid, intf->driver_name, parsable);
 			sysfs_close_device(intf);
 		}
@@ -244,11 +253,12 @@ err_out:
 int usbip_list(int argc, char *argv[])
 {
 	static const struct option opts[] = {
-		{ "parsable", no_argument, NULL, 'p' },
-		{ "remote", required_argument, NULL, 'r' },
-		{ "local", no_argument, NULL, 'l' },
-		{ NULL, 0, NULL, 0 }
+		{ "parsable", no_argument,       NULL, 'p' },
+		{ "remote",   required_argument, NULL, 'r' },
+		{ "local",    no_argument,       NULL, 'l' },
+		{ NULL,       0,                 NULL,  0  }
 	};
+
 	bool parsable = false;
 	int opt;
 	int ret = -1;
Signature · 1 line
1.7.5.2
#15 lore raw

PATCH 15/22 staging: usbip: userspace: usbip list: move output header

In reply to matt mooney

Delay the printing of the output header until the list is received from the remote host. This allows notification that the host does not have any exportable devices.

---
 drivers/staging/usbip/userspace/src/usbip_list.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
drivers/staging/usbip/userspace/src/usbip_list.c +11 -6
index afff469..973bf8c 100644
@@ -45,7 +45,7 @@ void usbip_list_usage(void)
 	printf("usage: %s", usbip_list_usage_string);
 }
 
-static int get_exported_devices(int sockfd)
+static int get_exported_devices(char *host, int sockfd)
 {
 	char product_name[100];
 	char class_name[100];
@@ -77,6 +77,15 @@ static int get_exported_devices(int sockfd)
 	PACK_OP_DEVLIST_REPLY(0, &reply);
 	dbg("exportable devices: %d\n", reply.ndev);
 
+	if (reply.ndev == 0) {
+		info("no exportable devices found on %s", host);
+		return 0;
+	}
+
+	printf("Exportable USB devices\n");
+	printf("======================\n");
+	printf(" - %s\n", host);
+
 	for (i = 0; i < reply.ndev; i++) {
 		memset(&udev, 0, sizeof(udev));
 		rc = usbip_recv(sockfd, &udev, sizeof(udev));
@@ -128,11 +137,7 @@ static int list_exported_devices(char *host)
 	}
 	dbg("connected to %s:%s", host, USBIP_PORT_STRING);
 
-	printf("Exportable USB devices\n");
-	printf("======================\n");
-	printf(" - %s\n", host);
-
-	rc = get_exported_devices(sockfd);
+	rc = get_exported_devices(host, sockfd);
 	if (rc < 0) {
 		err("failed to get device list from %s", host);
 		return -1;
Signature · 1 line
1.7.5.2
#16 lore raw

PATCH 16/22 staging: usbip: userspace: rename stub driver files

In reply to matt mooney

Rename stub_driver.? to usbip_host_driver.?

---
 drivers/staging/usbip/userspace/Makefile.am        |    2 +-
 drivers/staging/usbip/userspace/libsrc/Makefile.am |    2 +-
 .../staging/usbip/userspace/libsrc/stub_driver.c   |  395 --------------------
 .../staging/usbip/userspace/libsrc/stub_driver.h   |   37 --
 .../usbip/userspace/libsrc/usbip_host_driver.c     |  395 ++++++++++++++++++++
 .../usbip/userspace/libsrc/usbip_host_driver.h     |   37 ++
 6 files changed, 434 insertions(+), 434 deletions(-)
 delete mode 100644 drivers/staging/usbip/userspace/libsrc/stub_driver.c
 delete mode 100644 drivers/staging/usbip/userspace/libsrc/stub_driver.h
 create mode 100644 drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
 create mode 100644 drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h
drivers/staging/usbip/userspace/Makefile.am +1 -1
index d557fe9..fbdeef3 100644
@@ -1,6 +1,6 @@
 SUBDIRS := libsrc src
 includedir := @includedir@/usbip
 include_HEADERS := $(addprefix libsrc/, \
-		     usbip_common.h vhci_driver.h stub_driver.h)
+		     usbip_common.h vhci_driver.h usbip_host_driver.h)
 
 dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8 usbip_bind_driver.8)
drivers/staging/usbip/userspace/libsrc/Makefile.am +1 -1
index 6696aa7..9b663a4 100644
@@ -3,5 +3,5 @@ libusbip_la_CFLAGS   := @EXTRA_CFLAGS@
 libusbip_la_LDFLAGS  := -version-info @LIBUSBIP_VERSION@
 
 lib_LTLIBRARIES := libusbip.la
-libusbip_la_SOURCES := names.c names.h stub_driver.c stub_driver.h \
+libusbip_la_SOURCES := names.c names.h usbip_host_driver.c usbip_host_driver.h \
 		       usbip_common.c usbip_common.h vhci_driver.c vhci_driver.h
drivers/staging/usbip/userspace/libsrc/stub_driver.c deleted +0 -395

395 lines not on this page · raw message

drivers/staging/usbip/userspace/libsrc/stub_driver.h deleted +0 -37
deleted file mode 100644
index 9eaf92c..0000000
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2005-2007 Takahiro Hirofuchi
- */
-
-#ifndef __USBIP_STUB_DRIVER_H
-#define __USBIP_STUB_DRIVER_H
-
-#include <stdint.h>
-#include "usbip_common.h"
-
-struct usbip_stub_driver {
-	int ndevs;
-	struct sysfs_driver *sysfs_driver;
-
-	struct dlist *edev_list;	/* list of exported device */
-};
-
-struct usbip_exported_device {
-	struct sysfs_device *sudev;
-
-	int32_t status;
-	struct usbip_usb_device    udev;
-	struct usbip_usb_interface uinf[];
-};
-
-
-extern struct usbip_stub_driver *stub_driver;
-
-int usbip_stub_driver_open(void);
-void usbip_stub_driver_close(void);
-
-int usbip_stub_refresh_device_list(void);
-int usbip_stub_export_device(struct usbip_exported_device *edev, int sockfd);
-
-struct usbip_exported_device *usbip_stub_get_device(int num);
-
-#endif /* __USBIP_STUB_DRIVER_H */
drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c new file +395 -0

395 lines not on this page · raw message

drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h new file +37 -0
new file mode 100644
index 0000000..9eaf92c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2005-2007 Takahiro Hirofuchi
+ */
+
+#ifndef __USBIP_STUB_DRIVER_H
+#define __USBIP_STUB_DRIVER_H
+
+#include <stdint.h>
+#include "usbip_common.h"
+
+struct usbip_stub_driver {
+	int ndevs;
+	struct sysfs_driver *sysfs_driver;
+
+	struct dlist *edev_list;	/* list of exported device */
+};
+
+struct usbip_exported_device {
+	struct sysfs_device *sudev;
+
+	int32_t status;
+	struct usbip_usb_device    udev;
+	struct usbip_usb_interface uinf[];
+};
+
+
+extern struct usbip_stub_driver *stub_driver;
+
+int usbip_stub_driver_open(void);
+void usbip_stub_driver_close(void);
+
+int usbip_stub_refresh_device_list(void);
+int usbip_stub_export_device(struct usbip_exported_device *edev, int sockfd);
+
+struct usbip_exported_device *usbip_stub_get_device(int num);
+
+#endif /* __USBIP_STUB_DRIVER_H */
Signature · 1 line
1.7.5.2
#17 lore raw

PATCH 17/22 staging: usbip: userspace: usbip_host: update function and variable names

In reply to matt mooney

Officially change stub_driver to usbip_host_driver. And, reorganize usbip_host_driver.c while also cleaning up coding style.

---
 .../usbip/userspace/libsrc/usbip_host_driver.c     |  316 ++++++++++----------
 .../usbip/userspace/libsrc/usbip_host_driver.h     |   45 ++-
 2 files changed, 189 insertions(+), 172 deletions(-)
drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c +161 -155
index 604aed1..71a449c 100644
@@ -1,5 +1,19 @@
 /*
- * Copyright (C) 2005-2007 Takahiro Hirofuchi
+ * Copyright (C) 2011 matt mooney <[email protected]>
+ *               2005-2007 Takahiro Hirofuchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <sys/types.h>
@@ -9,41 +23,12 @@
 #include <unistd.h>
 
 #include "usbip_common.h"
-#include "stub_driver.h"
+#include "usbip_host_driver.h"
 
 #undef  PROGNAME
 #define PROGNAME "libusbip"
 
-struct usbip_stub_driver *stub_driver;
-
-static struct sysfs_driver *open_sysfs_stub_driver(void)
-{
-	int ret;
-
-	char sysfs_mntpath[SYSFS_PATH_MAX];
-	char stub_driver_path[SYSFS_PATH_MAX];
-	struct sysfs_driver *stub_driver;
-
-
-	ret = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
-	if (ret < 0) {
-		dbg("sysfs_get_mnt_path failed");
-		return NULL;
-	}
-
-	snprintf(stub_driver_path, SYSFS_PATH_MAX, "%s/%s/usb/%s/%s",
-			sysfs_mntpath, SYSFS_BUS_NAME, SYSFS_DRIVERS_NAME,
-			USBIP_HOST_DRV_NAME);
-
-	stub_driver = sysfs_open_driver_path(stub_driver_path);
-	if (!stub_driver) {
-		dbg("sysfs_open_driver_path failed");
-		return NULL;
-	}
-
-	return stub_driver;
-}
-
+struct usbip_host_driver *host_driver;
 
 #define SYSFS_OPEN_RETRIES 100
 
@@ -53,7 +38,7 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev)
 	char attrpath[SYSFS_PATH_MAX];
 	struct sysfs_attribute *attr;
 	int value = 0;
-	int  ret;
+	int rc;
 	struct stat s;
 	int retries = SYSFS_OPEN_RETRIES;
 
@@ -72,9 +57,7 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev)
 	 */
 
 	snprintf(attrpath, SYSFS_PATH_MAX, "%s/%s:%d.%d/usbip_status",
-			udev->path, udev->busid,
-			udev->bConfigurationValue,
-			0);
+		 udev->path, udev->busid, udev->bConfigurationValue, 0);
 
 	while (retries > 0) {
 		if (stat(attrpath, &s) == 0)
@@ -102,8 +85,8 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev)
 		return -1;
 	}
 
-	ret = sysfs_read_attribute(attr);
-	if (ret) {
+	rc = sysfs_read_attribute(attr);
+	if (rc) {
 		dbg("sysfs_read_attribute failed: %s", attrpath);
 		sysfs_close_attribute(attr);
 		return -1;
@@ -116,22 +99,13 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev)
 	return value;
 }
 
-
-static void usbip_exported_device_delete(void *dev)
-{
-	struct usbip_exported_device *edev =
-		(struct usbip_exported_device *) dev;
-
-	sysfs_close_device(edev->sudev);
-	free(dev);
-}
-
-
 static struct usbip_exported_device *usbip_exported_device_new(char *sdevpath)
 {
 	struct usbip_exported_device *edev = NULL;
+	size_t size;
+	int i;
 
-	edev = (struct usbip_exported_device *) calloc(1, sizeof(*edev));
+	edev = calloc(1, sizeof(*edev));
 	if (!edev) {
 		dbg("calloc failed");
 		return NULL;
@@ -150,223 +124,255 @@ static struct usbip_exported_device *usbip_exported_device_new(char *sdevpath)
 		goto err;
 
 	/* reallocate buffer to include usb interface data */
-	size_t size = sizeof(*edev) + edev->udev.bNumInterfaces *
+	size = sizeof(*edev) + edev->udev.bNumInterfaces *
 		sizeof(struct usbip_usb_interface);
-	edev = (struct usbip_exported_device *) realloc(edev, size);
+
+	edev = realloc(edev, size);
 	if (!edev) {
 		dbg("realloc failed");
 		goto err;
 	}
 
-	for (int i=0; i < edev->udev.bNumInterfaces; i++)
+	for (i = 0; i < edev->udev.bNumInterfaces; i++)
 		read_usb_interface(&edev->udev, i, &edev->uinf[i]);
 
 	return edev;
-
 err:
 	if (edev && edev->sudev)
 		sysfs_close_device(edev->sudev);
 	if (edev)
 		free(edev);
+
 	return NULL;
 }
 
-
 static int check_new(struct dlist *dlist, struct sysfs_device *target)
 {
 	struct sysfs_device *dev;
 
 	dlist_for_each_data(dlist, dev, struct sysfs_device) {
 		if (!strncmp(dev->bus_id, target->bus_id, SYSFS_BUS_ID_SIZE))
-			/* found. not new */
+			/* device found and is not new */
 			return 0;
 	}
-
 	return 1;
 }
 
-static void delete_nothing(void *dev __attribute__((unused)))
+static void delete_nothing(void *unused_data)
 {
-	/* do not delete anything. but, its container will be deleted. */
+	/*
+	 * NOTE: Do not delete anything, but the container will be deleted.
+	 */
+	(void) unused_data;
 }
 
 static int refresh_exported_devices(void)
 {
-	struct sysfs_device	*suinf;  /* sysfs_device of usb_interface */
-	struct dlist		*suinf_list;
-
-	struct sysfs_device	*sudev;  /* sysfs_device of usb_device */
+	/* sysfs_device of usb_interface */
+	struct sysfs_device	*suintf;
+	struct dlist		*suintf_list;
+	/* sysfs_device of usb_device */
+	struct sysfs_device	*sudev;
 	struct dlist		*sudev_list;
+	struct usbip_exported_device *edev;
 
+	sudev_list = dlist_new_with_delete(sizeof(struct sysfs_device),
+					   delete_nothing);
 
-	sudev_list = dlist_new_with_delete(sizeof(struct sysfs_device), delete_nothing);
-
-	suinf_list = sysfs_get_driver_devices(stub_driver->sysfs_driver);
-	if (!suinf_list) {
+	suintf_list = sysfs_get_driver_devices(host_driver->sysfs_driver);
+	if (!suintf_list) {
+		/*
+		 * Not an error condition. There are simply no devices bound to
+		 * the driver yet.
+		 */
 		dbg("bind " USBIP_HOST_DRV_NAME ".ko to a usb device to be "
-		    "exportable!\n");
-		goto bye;
+		    "exportable!");
+		return 0;
 	}
 
 	/* collect unique USB devices (not interfaces) */
-	dlist_for_each_data(suinf_list, suinf, struct sysfs_device) {
-
+	dlist_for_each_data(suintf_list, suintf, struct sysfs_device) {
 		/* get usb device of this usb interface */
-		sudev = sysfs_get_device_parent(suinf);
+		sudev = sysfs_get_device_parent(suintf);
 		if (!sudev) {
-			dbg("sysfs_get_device_parent failed: %s", suinf->name);
+			dbg("sysfs_get_device_parent failed: %s", suintf->name);
 			continue;
 		}
 
 		if (check_new(sudev_list, sudev)) {
+			/* insert item at head of list */
 			dlist_unshift(sudev_list, sudev);
 		}
 	}
 
 	dlist_for_each_data(sudev_list, sudev, struct sysfs_device) {
-		struct usbip_exported_device *edev;
-
 		edev = usbip_exported_device_new(sudev->path);
 		if (!edev) {
 			dbg("usbip_exported_device_new failed");
 			continue;
 		}
 
-		dlist_unshift(stub_driver->edev_list, (void *) edev);
-		stub_driver->ndevs++;
+		dlist_unshift(host_driver->edev_list, edev);
+		host_driver->ndevs++;
 	}
 
-
 	dlist_destroy(sudev_list);
 
-bye:
-
 	return 0;
 }
 
-int usbip_stub_refresh_device_list(void)
+static struct sysfs_driver *open_sysfs_host_driver(void)
 {
-	int ret;
+	char bus_type[] = "usb";
+	char sysfs_mntpath[SYSFS_PATH_MAX];
+	char host_drv_path[SYSFS_PATH_MAX];
+	struct sysfs_driver *host_drv;
+	int rc;
 
-	if (stub_driver->edev_list)
-		dlist_destroy(stub_driver->edev_list);
+	rc = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
+	if (rc < 0) {
+		dbg("sysfs_get_mnt_path failed");
+		return NULL;
+	}
 
-	stub_driver->ndevs = 0;
+	snprintf(host_drv_path, SYSFS_PATH_MAX, "%s/%s/%s/%s/%s",
+		 sysfs_mntpath, SYSFS_BUS_NAME, bus_type, SYSFS_DRIVERS_NAME,
+		 USBIP_HOST_DRV_NAME);
 
-	stub_driver->edev_list = dlist_new_with_delete(sizeof(struct usbip_exported_device),
-			usbip_exported_device_delete);
-	if (!stub_driver->edev_list) {
-		dbg("dlist_new_with_delete failed");
-		return -1;
+	host_drv = sysfs_open_driver_path(host_drv_path);
+	if (!host_drv) {
+		dbg("sysfs_open_driver_path failed");
+		return NULL;
 	}
 
-	ret = refresh_exported_devices();
-	if (ret < 0)
-		return ret;
-
-	return 0;
+	return host_drv;
 }
 
-int usbip_stub_driver_open(void)
+static void usbip_exported_device_delete(void *dev)
 {
-	int ret;
+	struct usbip_exported_device *edev = dev;
+	sysfs_close_device(edev->sudev);
+	free(dev);
+}
 
+int usbip_host_driver_open(void)
+{
+	int rc;
 
-	stub_driver = (struct usbip_stub_driver *) calloc(1, sizeof(*stub_driver));
-	if (!stub_driver) {
+	host_driver = calloc(1, sizeof(*host_driver));
+	if (!host_driver) {
 		dbg("calloc failed");
 		return -1;
 	}
 
-	stub_driver->ndevs = 0;
-
-	stub_driver->edev_list = dlist_new_with_delete(sizeof(struct usbip_exported_device),
-			usbip_exported_device_delete);
-	if (!stub_driver->edev_list) {
+	host_driver->ndevs = 0;
+	host_driver->edev_list =
+		dlist_new_with_delete(sizeof(struct usbip_exported_device),
+				      usbip_exported_device_delete);
+	if (!host_driver->edev_list) {
 		dbg("dlist_new_with_delete failed");
-		goto err;
+		goto err_free_host_driver;
 	}
 
-	stub_driver->sysfs_driver = open_sysfs_stub_driver();
-	if (!stub_driver->sysfs_driver)
-		goto err;
+	host_driver->sysfs_driver = open_sysfs_host_driver();
+	if (!host_driver->sysfs_driver)
+		goto err_destroy_edev_list;
 
-	ret = refresh_exported_devices();
-	if (ret < 0)
-		goto err;
+	rc = refresh_exported_devices();
+	if (rc < 0)
+		goto err_close_sysfs_driver;
 
 	return 0;
 
+err_close_sysfs_driver:
+	sysfs_close_driver(host_driver->sysfs_driver);
+err_destroy_edev_list:
+	dlist_destroy(host_driver->edev_list);
+err_free_host_driver:
+	free(host_driver);
+	host_driver = NULL;
 
-err:
-	if (stub_driver->sysfs_driver)
-		sysfs_close_driver(stub_driver->sysfs_driver);
-	if (stub_driver->edev_list)
-		dlist_destroy(stub_driver->edev_list);
-	free(stub_driver);
-
-	stub_driver = NULL;
 	return -1;
 }
 
-
-void usbip_stub_driver_close(void)
+void usbip_host_driver_close(void)
 {
-	if (!stub_driver)
+	if (!host_driver)
 		return;
 
-	if (stub_driver->edev_list)
-		dlist_destroy(stub_driver->edev_list);
-	if (stub_driver->sysfs_driver)
-		sysfs_close_driver(stub_driver->sysfs_driver);
-	free(stub_driver);
+	if (host_driver->edev_list)
+		dlist_destroy(host_driver->edev_list);
+	if (host_driver->sysfs_driver)
+		sysfs_close_driver(host_driver->sysfs_driver);
 
-	stub_driver = NULL;
+	free(host_driver);
+	host_driver = NULL;
 }
 
-int usbip_stub_export_device(struct usbip_exported_device *edev, int sockfd)
+int usbip_host_refresh_device_list(void)
 {
-	char attrpath[SYSFS_PATH_MAX];
+	int rc;
+
+	if (host_driver->edev_list)
+		dlist_destroy(host_driver->edev_list);
+
+	host_driver->ndevs = 0;
+	host_driver->edev_list =
+		dlist_new_with_delete(sizeof(struct usbip_exported_device),
+				      usbip_exported_device_delete);
+	if (!host_driver->edev_list) {
+		dbg("dlist_new_with_delete failed");
+		return -1;
+	}
+
+	rc = refresh_exported_devices();
+	if (rc < 0)
+		return -1;
+
+	return 0;
+}
+
+int usbip_host_export_device(struct usbip_exported_device *edev, int sockfd)
+{
+	char attr_name[] = "usbip_sockfd";
+	char attr_path[SYSFS_PATH_MAX];
 	struct sysfs_attribute *attr;
 	char sockfd_buff[30];
 	int ret;
 
-
 	if (edev->status != SDEV_ST_AVAILABLE) {
 		dbg("device not available: %s", edev->udev.busid);
-		switch( edev->status ) {
-			case SDEV_ST_ERROR:
-				dbg("status SDEV_ST_ERROR");
-				break;
-			case SDEV_ST_USED:
-				dbg("status SDEV_ST_USED");
-				break;
-			default:
-				dbg("status unknown: 0x%x", edev->status);
+		switch (edev->status) {
+		case SDEV_ST_ERROR:
+			dbg("status SDEV_ST_ERROR");
+			break;
+		case SDEV_ST_USED:
+			dbg("status SDEV_ST_USED");
+			break;
+		default:
+			dbg("status unknown: 0x%x", edev->status);
 		}
 		return -1;
 	}
 
 	/* only the first interface is true */
-	snprintf(attrpath, sizeof(attrpath), "%s/%s:%d.%d/%s",
-			edev->udev.path,
-			edev->udev.busid,
-			edev->udev.bConfigurationValue, 0,
-			"usbip_sockfd");
+	snprintf(attr_path, sizeof(attr_path), "%s/%s:%d.%d/%s",
+		 edev->udev.path, edev->udev.busid,
+		 edev->udev.bConfigurationValue, 0, attr_name);
 
-	attr = sysfs_open_attribute(attrpath);
+	attr = sysfs_open_attribute(attr_path);
 	if (!attr) {
-		dbg("sysfs_open_attribute failed: %s", attrpath);
+		dbg("sysfs_open_attribute failed: %s", attr_path);
 		return -1;
 	}
 
 	snprintf(sockfd_buff, sizeof(sockfd_buff), "%d\n", sockfd);
-
 	dbg("write: %s", sockfd_buff);
+
 	ret = sysfs_write_attribute(attr, sockfd_buff, strlen(sockfd_buff));
 	if (ret < 0) {
-		dbg("sysfs_write_attribute failed:  sockfd %s to %s",
-		    sockfd_buff, attrpath);
+		dbg("sysfs_write_attribute failed: sockfd %s to %s",
+		    sockfd_buff, attr_path);
 		goto err_write_sockfd;
 	}
 
@@ -378,17 +384,17 @@ err_write_sockfd:
 	return ret;
 }
 
-struct usbip_exported_device *usbip_stub_get_device(int num)
+struct usbip_exported_device *usbip_host_get_device(int num)
 {
 	struct usbip_exported_device *edev;
-	struct dlist		*dlist = stub_driver->edev_list;
-	int count = 0;
+	struct dlist *dlist = host_driver->edev_list;
+	int cnt = 0;
 
 	dlist_for_each_data(dlist, edev, struct usbip_exported_device) {
-		if (num == count)
+		if (num == cnt)
 			return edev;
 		else
-			count++ ;
+			cnt++;
 	}
 
 	return NULL;
drivers/staging/usbip/userspace/libsrc/usbip_host_driver.h +28 -17

65 lines not on this page · raw message

Signature · 1 line
1.7.5.2
#18 lore raw

PATCH 18/22 staging: usbip: userspace: usbipd: major cleanup of daemon

In reply to matt mooney

Reorganize, rename [for clarity and to remove stub_driver references], modify output messages, and cleanup coding style; nevertheless, the actual implementation is pretty much untouched.

---
 drivers/staging/usbip/userspace/src/usbipd.c |  693 +++++++++++++-------------
 1 files changed, 345 insertions(+), 348 deletions(-)
drivers/staging/usbip/userspace/src/usbipd.c +345 -348
index 332f9e6..aa92623 100644
@@ -1,6 +1,19 @@
 /*
+ * Copyright (C) 2011 matt mooney <[email protected]>
+ *               2005-2007 Takahiro Hirofuchi
  *
- * Copyright (C) 2005-2007 Takahiro Hirofuchi
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -27,66 +40,157 @@
 #include <glib.h>
 #include <signal.h>
 
-#include "stub_driver.h"
+#include "usbip_host_driver.h"
 #include "usbip_common.h"
 #include "usbip_network.h"
 
-static const char version[] = PACKAGE_STRING;
+#undef  PROGNAME
+#define PROGNAME "usbipd"
+#define MAXSOCKFD 20
+
+GMainLoop *main_loop;
 
-static int send_reply_devlist(int sockfd)
+static const char usbip_version_string[] = PACKAGE_STRING;
+
+static const char usbipd_help_string[] =
+	"usage: usbipd [options]			\n"
+	"	-D, --daemon				\n"
+	"		Run as a daemon process.	\n"
+	"						\n"
+	"	-d, --debug				\n"
+	"		Print debugging information.	\n"
+	"						\n"
+	"	-h, --help 				\n"
+	"		Print this help.		\n"
+	"						\n"
+	"	-v, --version				\n"
+	"		Show version.			\n";
+
+static void usbipd_help(void)
 {
-	int ret;
+	printf("%s\n", usbipd_help_string);
+}
+
+static int recv_request_import(int sockfd)
+{
+	struct op_import_request req;
+	struct op_common reply;
 	struct usbip_exported_device *edev;
-	struct op_devlist_reply reply;
+	struct usbip_usb_device pdu_udev;
+	int found = 0;
+	int error = 0;
+	int rc;
 
+	memset(&req, 0, sizeof(req));
+	memset(&reply, 0, sizeof(reply));
 
-	reply.ndev = 0;
+	rc = usbip_recv(sockfd, &req, sizeof(req));
+	if (rc < 0) {
+		dbg("usbip_recv failed: import request");
+		return -1;
+	}
+	PACK_OP_IMPORT_REQUEST(0, &req);
 
-	/* how many devices are exported ? */
-	dlist_for_each_data(stub_driver->edev_list, edev, struct usbip_exported_device) {
-		reply.ndev += 1;
+	dlist_for_each_data(host_driver->edev_list, edev,
+			    struct usbip_exported_device) {
+		if (!strncmp(req.busid, edev->udev.busid, SYSFS_BUS_ID_SIZE)) {
+			info("found requested device: %s", req.busid);
+			found = 1;
+			break;
+		}
 	}
 
-	dbg("%d devices are exported", reply.ndev);
+	if (found) {
+		/* should set TCP_NODELAY for usbip */
+		usbip_set_nodelay(sockfd);
 
-	ret = usbip_send_op_common(sockfd, OP_REP_DEVLIST,  ST_OK);
-	if (ret < 0) {
-		err("send op_common");
-		return ret;
+		/* export device needs a TCP/IP socket descriptor */
+		rc = usbip_host_export_device(edev, sockfd);
+		if (rc < 0)
+			error = 1;
+	} else {
+		info("requested device not found: %s", req.busid);
+		error = 1;
 	}
 
-	PACK_OP_DEVLIST_REPLY(1, &reply);
 
-	ret = usbip_send(sockfd, (void *) &reply, sizeof(reply));
-	if (ret < 0) {
-		err("send op_devlist_reply");
-		return ret;
+	rc = usbip_send_op_common(sockfd, OP_REP_IMPORT,
+				  (!error ? ST_OK : ST_NA));
+	if (rc < 0) {
+		dbg("usbip_send_op_common failed: %#0x", OP_REP_IMPORT);
+		return -1;
+	}
+
+	if (error) {
+		dbg("import request busid %s: failed", req.busid);
+		return -1;
+	}
+
+	memcpy(&pdu_udev, &edev->udev, sizeof(pdu_udev));
+	pack_usb_device(1, &pdu_udev);
+
+	rc = usbip_send(sockfd, &pdu_udev, sizeof(pdu_udev));
+	if (rc < 0) {
+		dbg("usbip_send failed: devinfo");
+		return -1;
 	}
 
-	dlist_for_each_data(stub_driver->edev_list, edev, struct usbip_exported_device) {
-		struct usbip_usb_device pdu_udev;
+	dbg("import request busid %s: complete", req.busid);
+
+	return 0;
+}
 
+static int send_reply_devlist(int connfd)
+{
+	struct usbip_exported_device *edev;
+	struct usbip_usb_device pdu_udev;
+	struct usbip_usb_interface pdu_uinf;
+	struct op_devlist_reply reply;
+	int i;
+	int rc;
+
+	reply.ndev = 0;
+	/* number of exported devices */
+	dlist_for_each_data(host_driver->edev_list, edev,
+			    struct usbip_exported_device) {
+		reply.ndev += 1;
+	}
+	info("exportable devices: %d", reply.ndev);
+
+	rc = usbip_send_op_common(connfd, OP_REP_DEVLIST, ST_OK);
+	if (rc < 0) {
+		dbg("usbip_send_op_common failed: %#0x", OP_REP_DEVLIST);
+		return -1;
+	}
+	PACK_OP_DEVLIST_REPLY(1, &reply);
+
+	rc = usbip_send(connfd, &reply, sizeof(reply));
+	if (rc < 0) {
+		dbg("usbip_send failed: %#0x", OP_REP_DEVLIST);
+		return -1;
+	}
+
+	dlist_for_each_data(host_driver->edev_list, edev,
+			    struct usbip_exported_device) {
 		dump_usb_device(&edev->udev);
 		memcpy(&pdu_udev, &edev->udev, sizeof(pdu_udev));
 		pack_usb_device(1, &pdu_udev);
 
-		ret = usbip_send(sockfd, (void *) &pdu_udev, sizeof(pdu_udev));
-		if (ret < 0) {
-			err("send pdu_udev");
-			return ret;
+		rc = usbip_send(connfd, &pdu_udev, sizeof(pdu_udev));
+		if (rc < 0) {
+			dbg("usbip_send failed: pdu_udev");
+			return -1;
 		}
 
-		for (int i=0; i < edev->udev.bNumInterfaces; i++) {
-			struct usbip_usb_interface pdu_uinf;
-
+		for (i = 0; i < edev->udev.bNumInterfaces; i++) {
 			dump_usb_interface(&edev->uinf[i]);
 			memcpy(&pdu_uinf, &edev->uinf[i], sizeof(pdu_uinf));
 			pack_usb_interface(1, &pdu_uinf);
 
-			ret = usbip_send(sockfd, (void *) &pdu_uinf, sizeof(pdu_uinf));
-			if (ret < 0) {
-				err("send pdu_uinf");
-				return ret;
+			rc = usbip_send(connfd, &pdu_uinf, sizeof(pdu_uinf));
+			if (rc < 0) {
+				dbg("usbip_send failed: pdu_uinf");
+				return -1;
 			}
 		}
 	}
@@ -94,283 +198,227 @@ static int send_reply_devlist(int sockfd)
 	return 0;
 }
 
-
-static int recv_request_devlist(int sockfd)
+static int recv_request_devlist(int connfd)
 {
-	int ret;
 	struct op_devlist_request req;
+	int rc;
 
 	memset(&req, 0, sizeof(req));
 
-	ret = usbip_recv(sockfd, (void *) &req, sizeof(req));
-	if (ret < 0) {
-		err("recv devlist request");
+	rc = usbip_recv(connfd, &req, sizeof(req));
+	if (rc < 0) {
+		dbg("usbip_recv failed: devlist request");
 		return -1;
 	}
 
-	ret = send_reply_devlist(sockfd);
-	if (ret < 0) {
-		err("send devlist reply");
+	rc = send_reply_devlist(connfd);
+	if (rc < 0) {
+		dbg("send_reply_devlist failed");
 		return -1;
 	}
 
 	return 0;
 }
 
-
-static int recv_request_import(int sockfd)
+static int recv_pdu(int connfd)
 {
+	uint16_t code = OP_UNSPEC;
 	int ret;
-	struct op_import_request req;
-	struct op_common reply;
-	struct usbip_exported_device *edev;
-	int found = 0;
-	int error = 0;
-
-	memset(&req, 0, sizeof(req));
-	memset(&reply, 0, sizeof(reply));
 
-	ret = usbip_recv(sockfd, (void *) &req, sizeof(req));
+	ret = usbip_recv_op_common(connfd, &code);
 	if (ret < 0) {
-		err("recv import request");
+		dbg("could not receive opcode: %#0x", code);
 		return -1;
 	}
 
-	PACK_OP_IMPORT_REQUEST(0, &req);
-
-	dlist_for_each_data(stub_driver->edev_list, edev, struct usbip_exported_device) {
-		if (!strncmp(req.busid, edev->udev.busid, SYSFS_BUS_ID_SIZE)) {
-			dbg("found requested device %s", req.busid);
-			found = 1;
-			break;
-		}
+	ret = usbip_host_refresh_device_list();
+	if (ret < 0) {
+		dbg("could not refresh device list: %d", ret);
+		return -1;
 	}
 
-	if (found) {
-		/* should set TCP_NODELAY for usbip */
-		usbip_set_nodelay(sockfd);
-
-		/* export_device needs a TCP/IP socket descriptor */
-		ret = usbip_stub_export_device(edev, sockfd);
-		if (ret < 0)
-			error = 1;
-	} else {
-		info("not found requested device %s", req.busid);
-		error = 1;
+	info("received request: %#0x(%d)", code, connfd);
+	switch (code) {
+	case OP_REQ_DEVLIST:
+		ret = recv_request_devlist(connfd);
+		break;
+	case OP_REQ_IMPORT:
+		ret = recv_request_import(connfd);
+		break;
+	case OP_REQ_DEVINFO:
+	case OP_REQ_CRYPKEY:
+	default:
+		err("received an unknown opcode: %#0x", code);
+		ret = -1;
 	}
 
+	if (ret == 0)
+		info("request %#0x(%d): complete", code, connfd);
+	else
+		info("request %#0x(%d): failed", code, connfd);
 
-	ret = usbip_send_op_common(sockfd, OP_REP_IMPORT, (!error ? ST_OK : ST_NA));
-	if (ret < 0) {
-		err("send import reply");
-		return -1;
-	}
-
-	if (!error) {
-		struct usbip_usb_device pdu_udev;
+	return ret;
+}
 
-		memcpy(&pdu_udev, &edev->udev, sizeof(pdu_udev));
-		pack_usb_device(1, &pdu_udev);
+#ifdef HAVE_LIBWRAP
+static int tcpd_auth(int connfd)
+{
+	struct request_info request;
+	int rc;
 
-		ret = usbip_send(sockfd, (void *) &pdu_udev, sizeof(pdu_udev));
-		if (ret < 0) {
-			err("send devinfo");
-			return -1;
-		}
-	}
+	request_init(&request, RQ_DAEMON, PROGNAME, RQ_FILE, connfd, 0);
+	fromhost(&request);
+	rc = hosts_access(&request);
+	if (rc == 0)
+		return -1;
 
 	return 0;
 }
+#endif
 
-
-
-static int recv_pdu(int sockfd)
+static int do_accept(int listenfd)
 {
-	int ret;
-	uint16_t code = OP_UNSPEC;
+	int connfd;
+	struct sockaddr_storage ss;
+	socklen_t len = sizeof(ss);
+	char host[NI_MAXHOST], port[NI_MAXSERV];
+	int rc;
 
+	memset(&ss, 0, sizeof(ss));
 
-	ret = usbip_recv_op_common(sockfd, &code);
-	if (ret < 0) {
-		err("recv op_common, %d", ret);
-		return ret;
+	connfd = accept(listenfd, (struct sockaddr *) &ss, &len);
+	if (connfd < 0) {
+		err("failed to accept connection");
+		return -1;
 	}
 
+	rc = getnameinfo((struct sockaddr *) &ss, len, host, sizeof(host),
+			 port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV);
+	if (rc)
+		err("getnameinfo: %s", gai_strerror(rc));
 
-	ret = usbip_stub_refresh_device_list();
-	if (ret < 0)
+#ifdef HAVE_LIBWRAP
+	rc = tcpd_auth(connfd);
+	if (rc < 0) {
+		info("denied access from %s", host);
+		close(connfd);
 		return -1;
+	}
+#endif
+	info("connection from %s:%s", host, port);
 
-	switch(code) {
-		case OP_REQ_DEVLIST:
-			ret = recv_request_devlist(sockfd);
-			break;
+	return connfd;
+}
 
-		case OP_REQ_IMPORT:
-			ret = recv_request_import(sockfd);
-			break;
+gboolean process_request(GIOChannel *gio, GIOCondition condition,
+			 gpointer unused_data)
+{
+	int listenfd;
+	int connfd;
 
-		case OP_REQ_DEVINFO:
-		case OP_REQ_CRYPKEY:
+	(void) unused_data;
 
-		default:
-			err("unknown op_code, %d", code);
-			ret = -1;
+	if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
+		err("unknown condition");
+		BUG();
 	}
 
+	if (condition & G_IO_IN) {
+		listenfd = g_io_channel_unix_get_fd(gio);
+		connfd = do_accept(listenfd);
+		if (connfd < 0)
+			return TRUE;
 
-	return ret;
-}
-
-
+		recv_pdu(connfd);
+		close(connfd);
+	}
 
+	return TRUE;
+}
 
 static void log_addrinfo(struct addrinfo *ai)
 {
-	int ret;
 	char hbuf[NI_MAXHOST];
 	char sbuf[NI_MAXSERV];
+	int rc;
 
-	ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, hbuf, sizeof(hbuf),
-			sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
-	if (ret)
-		err("getnameinfo, %s", gai_strerror(ret));
+	rc = getnameinfo(ai->ai_addr, ai->ai_addrlen, hbuf, sizeof(hbuf),
+			 sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
+	if (rc)
+		err("getnameinfo: %s", gai_strerror(rc));
 
-	info("listen at [%s]:%s", hbuf, sbuf);
-}
-
-static struct addrinfo *my_getaddrinfo(char *host, int ai_family)
-{
-	int ret;
-	struct addrinfo hints, *ai_head;
-
-	memset(&hints, 0, sizeof(hints));
-
-	hints.ai_family   = ai_family;
-	hints.ai_socktype = SOCK_STREAM;
-	hints.ai_flags    = AI_PASSIVE;
-
-	ret = getaddrinfo(host, USBIP_PORT_STRING, &hints, &ai_head);
-	if (ret) {
-		err("%s: %s", USBIP_PORT_STRING, gai_strerror(ret));
-		return NULL;
-	}
-
-	return ai_head;
+	info("listening on %s:%s", hbuf, sbuf);
 }
 
-#define MAXSOCK 20
-static int listen_all_addrinfo(struct addrinfo *ai_head, int lsock[])
+static int listen_all_addrinfo(struct addrinfo *ai_head, int sockfdlist[])
 {
 	struct addrinfo *ai;
-	int n = 0;		/* number of sockets */
+	int ret, nsockfd = 0;
 
-	for (ai = ai_head; ai && n < MAXSOCK; ai = ai->ai_next) {
-		int ret;
-
-		lsock[n] = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
-		if (lsock[n] < 0)
+	for (ai = ai_head; ai && nsockfd < MAXSOCKFD; ai = ai->ai_next) {
+		sockfdlist[nsockfd] = socket(ai->ai_family, ai->ai_socktype,
+					     ai->ai_protocol);
+		if (sockfdlist[nsockfd] < 0)
 			continue;
 
-		usbip_set_reuseaddr(lsock[n]);
-		usbip_set_nodelay(lsock[n]);
+		usbip_set_reuseaddr(sockfdlist[nsockfd]);
+		usbip_set_nodelay(sockfdlist[nsockfd]);
 
-		if (lsock[n] >= FD_SETSIZE) {
-			close(lsock[n]);
-			lsock[n] = -1;
+		if (sockfdlist[nsockfd] >= FD_SETSIZE) {
+			close(sockfdlist[nsockfd]);
+			sockfdlist[nsockfd] = -1;
 			continue;
 		}
 
-		ret = bind(lsock[n], ai->ai_addr, ai->ai_addrlen);
+		ret = bind(sockfdlist[nsockfd], ai->ai_addr, ai->ai_addrlen);
 		if (ret < 0) {
-			close(lsock[n]);
-			lsock[n] = -1;
+			close(sockfdlist[nsockfd]);
+			sockfdlist[nsockfd] = -1;
 			continue;
 		}
 
-		ret = listen(lsock[n], SOMAXCONN);
+		ret = listen(sockfdlist[nsockfd], SOMAXCONN);
 		if (ret < 0) {
-			close(lsock[n]);
-			lsock[n] = -1;
+			close(sockfdlist[nsockfd]);
+			sockfdlist[nsockfd] = -1;
 			continue;
 		}
 
 		log_addrinfo(ai);
-
-		/* next if succeed */
-		n++;
+		nsockfd++;
 	}
 
-	if (n == 0) {
-		err("no socket to listen to");
+	if (nsockfd == 0)
 		return -1;
-	}
 
-	dbg("listen %d address%s", n, (n==1)?"":"es");
+	dbg("listening on %d address%s", nsockfd, (nsockfd == 1) ? "" : "es");
 
-	return n;
+	return nsockfd;
 }
 
-#ifdef HAVE_LIBWRAP
-static int tcpd_auth(int csock)
+static struct addrinfo *do_getaddrinfo(char *host, int ai_family)
 {
-	int ret;
-	struct request_info request;
-
-	request_init(&request, RQ_DAEMON, "usbipd", RQ_FILE, csock, 0);
-
-	fromhost(&request);
-
-	ret = hosts_access(&request);
-	if (!ret)
-		return -1;
-
-	return 0;
-}
-#endif
-
-static int my_accept(int lsock)
-{
-	int csock;
-	struct sockaddr_storage ss;
-	socklen_t len = sizeof(ss);
-	char host[NI_MAXHOST], port[NI_MAXSERV];
-	int ret;
-
-	memset(&ss, 0, sizeof(ss));
-
-	csock = accept(lsock, (struct sockaddr *) &ss, &len);
-	if (csock < 0) {
-		err("accept");
-		return -1;
-	}
+	struct addrinfo hints, *ai_head;
+	int rc;
 
-	ret = getnameinfo((struct sockaddr *) &ss, len,
-			host, sizeof(host), port, sizeof(port),
-			(NI_NUMERICHOST | NI_NUMERICSERV));
-	if (ret)
-		err("getnameinfo, %s", gai_strerror(ret));
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family   = ai_family;
+	hints.ai_socktype = SOCK_STREAM;
+	hints.ai_flags    = AI_PASSIVE;
 
-#ifdef HAVE_LIBWRAP
-	ret = tcpd_auth(csock);
-	if (ret < 0) {
-		info("deny access from %s", host);
-		close(csock);
-		return -1;
+	rc = getaddrinfo(host, USBIP_PORT_STRING, &hints, &ai_head);
+	if (rc) {
+		err("failed to get a network address %s: %s", USBIP_PORT_STRING,
+		    gai_strerror(rc));
+		return NULL;
 	}
-#endif
-
-	info("connected from %s:%s", host, port);
 
-	return csock;
+	return ai_head;
 }
 
-
-GMainLoop *main_loop;
-
 static void signal_handler(int i)
 {
-	dbg("signal catched, code %d", i);
+	dbg("received signal: code %d", i);
 
 	if (main_loop)
 		g_main_loop_quit(main_loop);
@@ -387,184 +435,133 @@ static void set_signal(void)
 	sigaction(SIGINT, &act, NULL);
 }
 
-
-gboolean process_comming_request(GIOChannel *gio, GIOCondition condition,
-				 gpointer data __attribute__((unused)))
+static int do_standalone_mode(gboolean daemonize)
 {
-	int ret;
-
-	if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
-		g_error("unknown condition");
-
-
-	if (condition & G_IO_IN) {
-		int lsock;
-		int csock;
-
-		lsock = g_io_channel_unix_get_fd(gio);
-
-		csock = my_accept(lsock);
-		if (csock < 0)
-			return TRUE;
-
-		ret = recv_pdu(csock);
-		if (ret < 0)
-			err("process recieved pdu");
-
-		close(csock);
-	}
-
-	return TRUE;
-}
-
-
-static void do_standalone_mode(gboolean daemonize)
-{
-	int ret;
-	int lsock[MAXSOCK];
 	struct addrinfo *ai_head;
-	int n;
-
-
+	int sockfdlist[MAXSOCKFD];
+	int nsockfd;
+	int i;
 
-	ret = usbip_names_init(USBIDS_FILE);
-	if (ret)
-		err("open usb.ids");
+	if (usbip_names_init(USBIDS_FILE))
+		err("failed to open %s", USBIDS_FILE);
 
-	ret = usbip_stub_driver_open();
-	if (ret < 0)
-		g_error("driver open failed");
+	if (usbip_host_driver_open()) {
+		err("please load " USBIP_CORE_MOD_NAME ".ko and "
+		    USBIP_HOST_DRV_NAME ".ko!");
+		return -1;
+	}
 
 	if (daemonize) {
-		if (daemon(0,0) < 0)
-			g_error("daemonizing failed: %s", g_strerror(errno));
+		if (daemon(0,0) < 0) {
+			err("daemonizing failed: %s", strerror(errno));
+			return -1;
+		}
 
 		usbip_use_syslog = 1;
 	}
-
 	set_signal();
 
-	ai_head = my_getaddrinfo(NULL, PF_UNSPEC);
+	ai_head = do_getaddrinfo(NULL, PF_UNSPEC);
 	if (!ai_head)
-		return;
+		return -1;
 
-	n = listen_all_addrinfo(ai_head, lsock);
-	if (n <= 0)
-		g_error("no socket to listen to");
+	info("starting " PROGNAME " (%s)", usbip_version_string);
+
+	nsockfd = listen_all_addrinfo(ai_head, sockfdlist);
+	if (nsockfd <= 0) {
+		err("failed to open a listening socket");
+		return -1;
+	}
 
-	for (int i = 0; i < n; i++) {
+	for (i = 0; i < nsockfd; i++) {
 		GIOChannel *gio;
 
-		gio = g_io_channel_unix_new(lsock[i]);
+		gio = g_io_channel_unix_new(sockfdlist[i]);
 		g_io_add_watch(gio, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL),
-				process_comming_request, NULL);
+			       process_request, NULL);
 	}
 
-
-	info("usbipd start (%s)", version);
-
-
 	main_loop = g_main_loop_new(FALSE, FALSE);
 	g_main_loop_run(main_loop);
 
-	info("shutdown");
+	info("shutting down " PROGNAME);
 
 	freeaddrinfo(ai_head);
+	usbip_host_driver_close();
 	usbip_names_free();
-	usbip_stub_driver_close();
 
-	return;
-}
-
-
-static const char help_message[] = "\
-Usage: usbipd [options]				\n\
-	-D, --daemon				\n\
-		Run as a daemon process.	\n\
-						\n\
-	-d, --debug				\n\
-		Print debugging information.	\n\
-						\n\
-	-v, --version				\n\
-		Show version.			\n\
-						\n\
-	-h, --help 				\n\
-		Print this help.		\n";
-
-static void show_help(void)
-{
-	printf("%s", help_message);
+	return 0;
 }
 
-static const struct option longopts[] = {
-	{"daemon",	no_argument,	NULL, 'D'},
-	{"debug",	no_argument,	NULL, 'd'},
-	{"version",	no_argument,	NULL, 'v'},
-	{"help",	no_argument,	NULL, 'h'},
-	{NULL,		0,		NULL,  0}
-};
-
 int main(int argc, char *argv[])
 {
-	gboolean daemonize = FALSE;
+	static const struct option longopts[] = {
+		{ "daemon",  no_argument, NULL, 'D' },
+		{ "debug",   no_argument, NULL, 'd' },
+		{ "help",    no_argument, NULL, 'h' },
+		{ "version", no_argument, NULL, 'v' },
+		{ NULL,	     0,           NULL,  0  }
+	};
 
 	enum {
 		cmd_standalone_mode = 1,
 		cmd_help,
 		cmd_version
-	} cmd = cmd_standalone_mode;
+	} cmd;
 
+	gboolean daemonize = FALSE;
+	int opt, rc = -1;
 
 	usbip_use_stderr = 1;
 	usbip_use_syslog = 0;
 
 	if (geteuid() != 0)
-		g_warning("running non-root?");
+		err("not running as root?");
 
+	cmd = cmd_standalone_mode;
 	for (;;) {
-		int c;
-		int index = 0;
+		opt = getopt_long(argc, argv, "Ddhv", longopts, NULL);
 
-		c = getopt_long(argc, argv, "vhdD", longopts, &index);
-
-		if (c == -1)
+		if (opt == -1)
 			break;
 
-		switch (c) {
-			case 'd':
-				usbip_use_debug = 1;
-				continue;
-			case 'v':
-				cmd = cmd_version;
-				break;
-			case 'h':
-				cmd = cmd_help;
-				break;
-			case 'D':
-				daemonize = TRUE;
-				break;
-			case '?':
-				show_help();
-				exit(EXIT_FAILURE);
-			default:
-				err("getopt");
-		}
-	}
-
-	switch (cmd) {
-		case cmd_standalone_mode:
-			do_standalone_mode(daemonize);
+		switch (opt) {
+		case 'D':
+			daemonize = TRUE;
+			break;
+		case 'd':
+			usbip_use_debug = 1;
 			break;
-		case cmd_version:
-			printf("%s\n", version);
+		case 'h':
+			cmd = cmd_help;
 			break;
-		case cmd_help:
-			show_help();
+		case 'v':
+			cmd = cmd_version;
 			break;
+		case '?':
+			usbipd_help();
 		default:
-			info("unknown cmd");
-			show_help();
+			goto err_out;
+		}
 	}
 
-	return 0;
+	switch (cmd) {
+	case cmd_standalone_mode:
+		rc = do_standalone_mode(daemonize);
+		break;
+	case cmd_version:
+		printf(PROGNAME " (%s)\n", usbip_version_string);
+		rc = 0;
+		break;
+	case cmd_help:
+		usbipd_help();
+		rc = 0;
+		break;
+	default:
+		usbipd_help();
+		goto err_out;
+	}
+
+err_out:
+	return (rc > -1 ? EXIT_SUCCESS : EXIT_FAILURE);
 }
Signature · 1 line
1.7.5.2
#19 lore raw

PATCH 19/22 staging: usbip: userspace: usbip_network.c: coding style cleanup

In reply to matt mooney

Change messges to debug, and fix a few coding style issues.

---
 .../staging/usbip/userspace/src/usbip_network.c    |   73 +++++++++++--------
 1 files changed, 42 insertions(+), 31 deletions(-)
drivers/staging/usbip/userspace/src/usbip_network.c +42 -31
index 26e95bd..a3833ff 100644
@@ -1,6 +1,19 @@
 /*
+ * Copyright (C) 2011 matt mooney <[email protected]>
+ *               2005-2007 Takahiro Hirofuchi
  *
- * Copyright (C) 2005-2007 Takahiro Hirofuchi
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <sys/socket.h>
@@ -56,17 +69,15 @@ void pack_usb_interface(int pack __attribute__((unused)),
 	/* uint8_t members need nothing */
 }
 
-
 static ssize_t usbip_xmit(int sockfd, void *buff, size_t bufflen, int sending)
 {
+	ssize_t nbytes;
 	ssize_t total = 0;
 
 	if (!bufflen)
 		return 0;
 
 	do {
-		ssize_t nbytes;
-
 		if (sending)
 			nbytes = send(sockfd, buff, bufflen, 0);
 		else
@@ -75,13 +86,12 @@ static ssize_t usbip_xmit(int sockfd, void *buff, size_t bufflen, int sending)
 		if (nbytes <= 0)
 			return -1;
 
-		buff	= (void *) ((intptr_t) buff + nbytes);
+		buff	 = (void *)((intptr_t) buff + nbytes);
 		bufflen	-= nbytes;
 		total	+= nbytes;
 
 	} while (bufflen > 0);
 
-
 	return total;
 }
 
@@ -97,8 +107,8 @@ ssize_t usbip_send(int sockfd, void *buff, size_t bufflen)
 
 int usbip_send_op_common(int sockfd, uint32_t code, uint32_t status)
 {
-	int ret;
 	struct op_common op_common;
+	int rc;
 
 	memset(&op_common, 0, sizeof(op_common));
 
@@ -108,9 +118,9 @@ int usbip_send_op_common(int sockfd, uint32_t code, uint32_t status)
 
 	PACK_OP_COMMON(1, &op_common);
 
-	ret = usbip_send(sockfd, (void *) &op_common, sizeof(op_common));
-	if (ret < 0) {
-		err("usbip_send has failed");
+	rc = usbip_send(sockfd, &op_common, sizeof(op_common));
+	if (rc < 0) {
+		dbg("usbip_send failed: %d", rc);
 		return -1;
 	}
 
@@ -119,36 +129,38 @@ int usbip_send_op_common(int sockfd, uint32_t code, uint32_t status)
 
 int usbip_recv_op_common(int sockfd, uint16_t *code)
 {
-	int ret;
 	struct op_common op_common;
+	int rc;
 
 	memset(&op_common, 0, sizeof(op_common));
 
-	ret = usbip_recv(sockfd, (void *) &op_common, sizeof(op_common));
-	if (ret < 0) {
-		err("usbip_recv has failed ret=%d", ret);
+	rc = usbip_recv(sockfd, &op_common, sizeof(op_common));
+	if (rc < 0) {
+		dbg("usbip_recv failed: %d", rc);
 		goto err;
 	}
 
 	PACK_OP_COMMON(0, &op_common);
 
 	if (op_common.version != USBIP_VERSION) {
-		err("version mismatch, %d %d", op_common.version, USBIP_VERSION);
+		dbg("version mismatch: %d %d", op_common.version,
+		    USBIP_VERSION);
 		goto err;
 	}
 
-	switch(*code) {
-		case OP_UNSPEC:
-			break;
-		default:
-			if (op_common.code != *code) {
-				info("unexpected pdu %d for %d", op_common.code, *code);
-				goto err;
-			}
+	switch (*code) {
+	case OP_UNSPEC:
+		break;
+	default:
+		if (op_common.code != *code) {
+			dbg("unexpected pdu %#0x for %#0x", op_common.code,
+			    *code);
+			goto err;
+		}
 	}
 
 	if (op_common.status != ST_OK) {
-		info("request failed at peer, %d", op_common.status);
+		dbg("request failed at peer: %d", op_common.status);
 		goto err;
 	}
 
@@ -159,7 +171,6 @@ err:
 	return -1;
 }
 
-
 int usbip_set_reuseaddr(int sockfd)
 {
 	const int val = 1;
@@ -167,7 +178,7 @@ int usbip_set_reuseaddr(int sockfd)
 
 	ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
 	if (ret < 0)
-		err("setsockopt SO_REUSEADDR");
+		dbg("setsockopt: SO_REUSEADDR");
 
 	return ret;
 }
@@ -179,7 +190,7 @@ int usbip_set_nodelay(int sockfd)
 
 	ret = setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
 	if (ret < 0)
-		err("setsockopt TCP_NODELAY");
+		dbg("setsockopt: TCP_NODELAY");
 
 	return ret;
 }
@@ -191,7 +202,7 @@ int usbip_set_keepalive(int sockfd)
 
 	ret = setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val));
 	if (ret < 0)
-		err("setsockopt SO_KEEPALIVE");
+		dbg("setsockopt: SO_KEEPALIVE");
 
 	return ret;
 }
@@ -199,7 +210,7 @@ int usbip_set_keepalive(int sockfd)
 /*
  * IPv6 Ready
  */
-int usbip_net_tcp_connect(char *hostname, char *port)
+int usbip_net_tcp_connect(char *hostname, char *service)
 {
 	struct addrinfo hints, *res, *rp;
 	int sockfd;
@@ -210,9 +221,9 @@ int usbip_net_tcp_connect(char *hostname, char *port)
 	hints.ai_socktype = SOCK_STREAM;
 
 	/* get all possible addresses */
-	ret = getaddrinfo(hostname, port, &hints, &res);
+	ret = getaddrinfo(hostname, service, &hints, &res);
 	if (ret < 0) {
-		dbg("getaddrinfo: %s port %s: %s", hostname, port,
+		dbg("getaddrinfo: %s service %s: %s", hostname, service,
 		    gai_strerror(ret));
 		return ret;
 	}
Signature · 1 line
1.7.5.2
#20 lore raw

PATCH 20/22 staging: usbip: userspace: add new prefix for usbip network code

In reply to matt mooney

Change and add new usbip_net_ prefix to every function in the network code for easier identification.

---
 drivers/staging/usbip/userspace/src/usbip_attach.c |    8 ++--
 drivers/staging/usbip/userspace/src/usbip_list.c   |   26 +++++----
 .../staging/usbip/userspace/src/usbip_network.c    |   56 ++++++++++---------
 .../staging/usbip/userspace/src/usbip_network.h    |   39 +++++++-------
 drivers/staging/usbip/userspace/src/usbipd.c       |   50 +++++++++---------
 5 files changed, 91 insertions(+), 88 deletions(-)
drivers/staging/usbip/userspace/src/usbip_attach.c +4 -4
index 189238b..b7885a2 100644
@@ -115,7 +115,7 @@ static int query_import_device(int sockfd, char *busid)
 	memset(&reply, 0, sizeof(reply));
 
 	/* send a request */
-	rc = usbip_send_op_common(sockfd, OP_REQ_IMPORT, 0);
+	rc = usbip_net_send_op_common(sockfd, OP_REQ_IMPORT, 0);
 	if (rc < 0) {
 		err("send op_common");
 		return -1;
@@ -125,20 +125,20 @@ static int query_import_device(int sockfd, char *busid)
 
 	PACK_OP_IMPORT_REQUEST(0, &request);
 
-	rc = usbip_send(sockfd, (void *) &request, sizeof(request));
+	rc = usbip_net_send(sockfd, (void *) &request, sizeof(request));
 	if (rc < 0) {
 		err("send op_import_request");
 		return -1;
 	}
 
 	/* recieve a reply */
-	rc = usbip_recv_op_common(sockfd, &code);
+	rc = usbip_net_recv_op_common(sockfd, &code);
 	if (rc < 0) {
 		err("recv op_common");
 		return -1;
 	}
 
-	rc = usbip_recv(sockfd, (void *) &reply, sizeof(reply));
+	rc = usbip_net_recv(sockfd, (void *) &reply, sizeof(reply));
 	if (rc < 0) {
 		err("recv op_import_reply");
 		return -1;
drivers/staging/usbip/userspace/src/usbip_list.c +14 -12
index 973bf8c..3edf5d1 100644
@@ -56,22 +56,22 @@ static int get_exported_devices(char *host, int sockfd)
 	unsigned int i;
 	int j, rc;
 
-	rc = usbip_send_op_common(sockfd, OP_REQ_DEVLIST, 0);
+	rc = usbip_net_send_op_common(sockfd, OP_REQ_DEVLIST, 0);
 	if (rc < 0) {
-		dbg("usbip_send_op_common failed");
+		dbg("usbip_net_send_op_common failed");
 		return -1;
 	}
 
-	rc = usbip_recv_op_common(sockfd, &code);
+	rc = usbip_net_recv_op_common(sockfd, &code);
 	if (rc < 0) {
-		dbg("usbip_recv_op_common failed");
+		dbg("usbip_net_recv_op_common failed");
 		return -1;
 	}
 
 	memset(&reply, 0, sizeof(reply));
-	rc = usbip_recv(sockfd, &reply, sizeof(reply));
+	rc = usbip_net_recv(sockfd, &reply, sizeof(reply));
 	if (rc < 0) {
-		dbg("usbip_recv_op_devlist failed");
+		dbg("usbip_net_recv_op_devlist failed");
 		return -1;
 	}
 	PACK_OP_DEVLIST_REPLY(0, &reply);
@@ -88,12 +88,12 @@ static int get_exported_devices(char *host, int sockfd)
 
 	for (i = 0; i < reply.ndev; i++) {
 		memset(&udev, 0, sizeof(udev));
-		rc = usbip_recv(sockfd, &udev, sizeof(udev));
+		rc = usbip_net_recv(sockfd, &udev, sizeof(udev));
 		if (rc < 0) {
-			dbg("usbip_recv failed: usbip_usb_device[%d]", i);
+			dbg("usbip_net_recv failed: usbip_usb_device[%d]", i);
 			return -1;
 		}
-		pack_usb_device(0, &udev);
+		usbip_net_pack_usb_device(0, &udev);
 
 		usbip_names_get_product(product_name, sizeof(product_name),
 					udev.idVendor, udev.idProduct);
@@ -105,12 +105,14 @@ static int get_exported_devices(char *host, int sockfd)
 		printf("%8s: %s\n", "", class_name);
 
 		for (j = 0; j < udev.bNumInterfaces; j++) {
-			rc = usbip_recv(sockfd, &uintf, sizeof(uintf));
+			rc = usbip_net_recv(sockfd, &uintf, sizeof(uintf));
 			if (rc < 0) {
-				dbg("usbip_recv failed: usbip_usb_intf[%d]", j);
+				dbg("usbip_net_recv failed: usbip_usb_intf[%d]",
+				    j);
+
 				return -1;
 			}
-			pack_usb_interface(0, &uintf);
+			usbip_net_pack_usb_interface(0, &uintf);
 
 			usbip_names_get_class(class_name, sizeof(class_name),
 					      uintf.bInterfaceClass,
drivers/staging/usbip/userspace/src/usbip_network.c +29 -27

139 lines not on this page · raw message

drivers/staging/usbip/userspace/src/usbip_network.h +19 -20
index 07274df..2d1e070 100644
@@ -34,9 +34,9 @@ struct op_common {
 } __attribute__((packed));
 
 #define PACK_OP_COMMON(pack, op_common)  do {\
-	pack_uint16_t(pack, &(op_common)->version);\
-	pack_uint16_t(pack, &(op_common)->code   );\
-	pack_uint32_t(pack, &(op_common)->status );\
+	usbip_net_pack_uint16_t(pack, &(op_common)->version);\
+	usbip_net_pack_uint16_t(pack, &(op_common)->code   );\
+	usbip_net_pack_uint32_t(pack, &(op_common)->status );\
 } while (0)
 
 /* ---------------------------------------------------------------------- */
@@ -79,7 +79,7 @@ struct op_import_reply {
 } while (0)
 
 #define PACK_OP_IMPORT_REPLY(pack, reply)  do {\
-	pack_usb_device(pack, &(reply)->udev);\
+	usbip_net_pack_usb_device(pack, &(reply)->udev);\
 } while (0)
 
 /* ---------------------------------------------------------------------- */
@@ -98,7 +98,7 @@ struct op_export_reply {
 
 
 #define PACK_OP_EXPORT_REQUEST(pack, request)  do {\
-	pack_usb_device(pack, &(request)->udev);\
+	usbip_net_pack_usb_device(pack, &(request)->udev);\
 } while (0)
 
 #define PACK_OP_EXPORT_REPLY(pack, reply)  do {\
@@ -119,7 +119,7 @@ struct op_unexport_reply {
 } __attribute__((packed));
 
 #define PACK_OP_UNEXPORT_REQUEST(pack, request)  do {\
-	pack_usb_device(pack, &(request)->udev);\
+	usbip_net_pack_usb_device(pack, &(request)->udev);\
 } while (0)
 
 #define PACK_OP_UNEXPORT_REPLY(pack, reply)  do {\
@@ -164,22 +164,21 @@ struct op_devlist_reply_extra {
 } while (0)
 
 #define PACK_OP_DEVLIST_REPLY(pack, reply)  do {\
-	pack_uint32_t(pack, &(reply)->ndev);\
+	usbip_net_pack_uint32_t(pack, &(reply)->ndev);\
 } while (0)
 
-void pack_uint32_t(int pack, uint32_t *num);
-void pack_uint16_t(int pack, uint16_t *num);
-void pack_usb_device(int pack, struct usbip_usb_device *udev);
-void pack_usb_interface(int pack, struct usbip_usb_interface *uinf);
-
-ssize_t usbip_recv(int sockfd, void *buff, size_t bufflen);
-ssize_t usbip_send(int sockfd, void *buff, size_t bufflen);
-int usbip_send_op_common(int sockfd, uint32_t code, uint32_t status);
-int usbip_recv_op_common(int sockfd, uint16_t *code);
-int usbip_set_reuseaddr(int sockfd);
-int usbip_set_nodelay(int sockfd);
-int usbip_set_keepalive(int sockfd);
-
+void usbip_net_pack_uint32_t(int pack, uint32_t *num);
+void usbip_net_pack_uint16_t(int pack, uint16_t *num);
+void usbip_net_pack_usb_device(int pack, struct usbip_usb_device *udev);
+void usbip_net_pack_usb_interface(int pack, struct usbip_usb_interface *uinf);
+
+ssize_t usbip_net_recv(int sockfd, void *buff, size_t bufflen);
+ssize_t usbip_net_send(int sockfd, void *buff, size_t bufflen);
+int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status);
+int usbip_net_recv_op_common(int sockfd, uint16_t *code);
+int usbip_net_set_reuseaddr(int sockfd);
+int usbip_net_set_nodelay(int sockfd);
+int usbip_net_set_keepalive(int sockfd);
 int usbip_net_tcp_connect(char *hostname, char *port);
 
 #endif /* __USBIP_NETWORK_H */
drivers/staging/usbip/userspace/src/usbipd.c +25 -25

125 lines not on this page · raw message

Signature · 1 line
1.7.5.2
#21 lore raw

PATCH 21/22 staging: usbip: userspace: fix header installation bug

In reply to matt mooney

A bug that I created due to using simply expanding variables in the makefiles. Although only unexpanded paths are at issue here, I decided to use recursively expanding variables on all of the parameterized values.

---
 drivers/staging/usbip/userspace/Makefile.am        |    2 +-
 drivers/staging/usbip/userspace/libsrc/Makefile.am |    6 +++---
 drivers/staging/usbip/userspace/src/Makefile.am    |    6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/staging/usbip/userspace/Makefile.am +1 -1
index fbdeef3..9ab1949 100644
@@ -1,5 +1,5 @@
 SUBDIRS := libsrc src
-includedir := @includedir@/usbip
+includedir = @includedir@/usbip
 include_HEADERS := $(addprefix libsrc/, \
 		     usbip_common.h vhci_driver.h usbip_host_driver.h)
 
drivers/staging/usbip/userspace/libsrc/Makefile.am +3 -3
index 9b663a4..4921189 100644
@@ -1,6 +1,6 @@
-libusbip_la_CPPFLAGS := -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
-libusbip_la_CFLAGS   := @EXTRA_CFLAGS@
-libusbip_la_LDFLAGS  := -version-info @LIBUSBIP_VERSION@
+libusbip_la_CPPFLAGS = -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
+libusbip_la_CFLAGS   = @EXTRA_CFLAGS@
+libusbip_la_LDFLAGS  = -version-info @LIBUSBIP_VERSION@
 
 lib_LTLIBRARIES := libusbip.la
 libusbip_la_SOURCES := names.c names.h usbip_host_driver.c usbip_host_driver.h \
drivers/staging/usbip/userspace/src/Makefile.am +3 -3
index 52741c8..3f09f6a 100644
@@ -1,6 +1,6 @@
-AM_CPPFLAGS := -I$(top_srcdir)/libsrc -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
-AM_CFLAGS   := @EXTRA_CFLAGS@ @PACKAGE_CFLAGS@
-LDADD       := $(top_srcdir)/libsrc/libusbip.la @PACKAGE_LIBS@
+AM_CPPFLAGS = -I$(top_srcdir)/libsrc -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
+AM_CFLAGS   = @EXTRA_CFLAGS@ @PACKAGE_CFLAGS@
+LDADD       = $(top_builddir)/libsrc/libusbip.la @PACKAGE_LIBS@
 
 sbin_PROGRAMS := usbip usbipd
 
Signature · 1 line
1.7.5.2
#22 lore raw

PATCH 22/22 staging: usbip: userspace: configure.ac: change package data

In reply to matt mooney

Change package name to usbip-utils, email address to linux-usb, and bump minor version number.

---
 drivers/staging/usbip/userspace/configure.ac |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/usbip/userspace/configure.ac +1 -1
index 39e4a47..89fefd5 100644
@@ -1,7 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([usbip], [1.0.0], [[email protected]])
+AC_INIT([usbip-utils], [1.1.0], [[email protected]])
 AC_DEFINE([USBIP_VERSION], [0x00000100], [binary-coded decimal version number])
 
 CURRENT=0
Signature · 1 line
1.7.5.2
#23 lore raw
In reply to matt mooney
Quoted 5 lines · matt mooney

Hi Greg,

This patch set contains only userspace changes. Next, I will take a look at attach and detach, which should soon lead to the reason why usbip is not currently working.

Not all of these applied, care to resend the ones that didn't after rebasing on the current staging-next tree?

thanks,

greg k-h