usbip: tools: change to use new error codes in server reply messages
authorShuah Khan <shuahkh@osg.samsung.com>
Wed, 7 Mar 2018 20:42:26 +0000 (13:42 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 9 Mar 2018 17:17:09 +0000 (09:17 -0800)
Changed usbip_network, usbip_attach, usbip_list, and usbipd to use
and propagate the new error codes in server reply messages.

usbip_net_recv_op_common() is changed to take a pointer to status
return the status returned in the op_common.status to callers.

usbip_attach and usbip_list use the common interface to print error
messages to indicate why the request failed.

With this change the messages say why a request failed:

- when a client requests a device that is already exported:

usbip attach -r server_name -b 3-10.2
usbip: error: Attach Request for 3-10.2 failed - Device busy (exported)

- when a client requests a device that isn't exportable,

usbip attach -r server_name -b 3-10.4
usbip: error: Attach Request for 3-10.4 failed - Device not found

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/usb/usbip/src/usbip_attach.c
tools/usb/usbip/src/usbip_list.c
tools/usb/usbip/src/usbip_network.c
tools/usb/usbip/src/usbip_network.h
tools/usb/usbip/src/usbipd.c

index f60738735398c1a363410e8681575a7f71cfba6c..ba88728483ff9212d972d6bfc7c02e3a70f3ef3b 100644 (file)
@@ -135,6 +135,7 @@ static int query_import_device(int sockfd, char *busid)
        struct op_import_request request;
        struct op_import_reply   reply;
        uint16_t code = OP_REP_IMPORT;
+       int status;
 
        memset(&request, 0, sizeof(request));
        memset(&reply, 0, sizeof(reply));
@@ -157,9 +158,10 @@ static int query_import_device(int sockfd, char *busid)
        }
 
        /* receive a reply */
-       rc = usbip_net_recv_op_common(sockfd, &code);
+       rc = usbip_net_recv_op_common(sockfd, &code, &status);
        if (rc < 0) {
-               err("recv op_common");
+               err("Attach Request for %s failed - %s\n",
+                   busid, usbip_op_common_status_string(status));
                return -1;
        }
 
@@ -194,11 +196,8 @@ static int attach_device(char *host, char *busid)
        }
 
        rhport = query_import_device(sockfd, busid);
-       if (rhport < 0) {
-               err("Attach request for Device %s. Is this device exported?",
-                   busid);
+       if (rhport < 0)
                return -1;
-       }
 
        close(sockfd);
 
index d65a9f444174495029e96bc5d81c0fbfd81e52b5..8d4ccf4b948010305bff3c000a16d17eee6ad123 100644 (file)
@@ -62,6 +62,7 @@ static int get_exported_devices(char *host, int sockfd)
        struct usbip_usb_interface uintf;
        unsigned int i;
        int rc, j;
+       int status;
 
        rc = usbip_net_send_op_common(sockfd, OP_REQ_DEVLIST, 0);
        if (rc < 0) {
@@ -69,9 +70,10 @@ static int get_exported_devices(char *host, int sockfd)
                return -1;
        }
 
-       rc = usbip_net_recv_op_common(sockfd, &code);
+       rc = usbip_net_recv_op_common(sockfd, &code, &status);
        if (rc < 0) {
-               dbg("usbip_net_recv_op_common failed");
+               err("Exported Device List Request failed - %s\n",
+                   usbip_op_common_status_string(status));
                return -1;
        }
 
index 90325fa8bc3815e38f9aba416d92ae7797d213fe..8ffcd47d96385edc404dbfaca9fe50b11e6de1a3 100644 (file)
@@ -163,7 +163,7 @@ int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status)
        return 0;
 }
 
-int usbip_net_recv_op_common(int sockfd, uint16_t *code)
+int usbip_net_recv_op_common(int sockfd, uint16_t *code, int *status)
 {
        struct op_common op_common;
        int rc;
@@ -191,10 +191,14 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code)
                if (op_common.code != *code) {
                        dbg("unexpected pdu %#0x for %#0x", op_common.code,
                            *code);
+                       /* return error status */
+                       *status = ST_ERROR;
                        goto err;
                }
        }
 
+       *status = op_common.status;
+
        if (op_common.status != ST_OK) {
                dbg("request failed at peer: %d", op_common.status);
                goto err;
index b6a2f9be888c65aedad87cd8f7306ced35307b71..555215eae43e9ee9fd75d789cdb2250d9b62086a 100644 (file)
@@ -174,7 +174,7 @@ 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_recv_op_common(int sockfd, uint16_t *code, int *status);
 int usbip_net_set_reuseaddr(int sockfd);
 int usbip_net_set_nodelay(int sockfd);
 int usbip_net_set_keepalive(int sockfd);
index c6dad2a13c801693e5f99ae445ed2b7a247978f8..f8ff735eb1001d30eef869347419134a733fae22 100644 (file)
@@ -107,7 +107,7 @@ static int recv_request_import(int sockfd)
        struct usbip_usb_device pdu_udev;
        struct list_head *i;
        int found = 0;
-       int error = 0;
+       int status = ST_OK;
        int rc;
 
        memset(&req, 0, sizeof(req));
@@ -133,22 +133,21 @@ static int recv_request_import(int sockfd)
                usbip_net_set_nodelay(sockfd);
 
                /* export device needs a TCP/IP socket descriptor */
-               rc = usbip_export_device(edev, sockfd);
-               if (rc < 0)
-                       error = 1;
+               status = usbip_export_device(edev, sockfd);
+               if (status < 0)
+                       status = ST_NA;
        } else {
                info("requested device not found: %s", req.busid);
-               error = 1;
+               status = ST_NODEV;
        }
 
-       rc = usbip_net_send_op_common(sockfd, OP_REP_IMPORT,
-                                     (!error ? ST_OK : ST_NA));
+       rc = usbip_net_send_op_common(sockfd, OP_REP_IMPORT, status);
        if (rc < 0) {
                dbg("usbip_net_send_op_common failed: %#0x", OP_REP_IMPORT);
                return -1;
        }
 
-       if (error) {
+       if (status) {
                dbg("import request busid %s: failed", req.busid);
                return -1;
        }
@@ -251,8 +250,9 @@ static int recv_pdu(int connfd)
 {
        uint16_t code = OP_UNSPEC;
        int ret;
+       int status;
 
-       ret = usbip_net_recv_op_common(connfd, &code);
+       ret = usbip_net_recv_op_common(connfd, &code, &status);
        if (ret < 0) {
                dbg("could not receive opcode: %#0x", code);
                return -1;