Commit ad81b15d authored by Shuah Khan's avatar Shuah Khan Committed by Greg Kroah-Hartman

usbip: tools: change to use new error codes in server reply messages

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: default avatarShuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c207a10d
...@@ -135,6 +135,7 @@ static int query_import_device(int sockfd, char *busid) ...@@ -135,6 +135,7 @@ static int query_import_device(int sockfd, char *busid)
struct op_import_request request; struct op_import_request request;
struct op_import_reply reply; struct op_import_reply reply;
uint16_t code = OP_REP_IMPORT; uint16_t code = OP_REP_IMPORT;
int status;
memset(&request, 0, sizeof(request)); memset(&request, 0, sizeof(request));
memset(&reply, 0, sizeof(reply)); memset(&reply, 0, sizeof(reply));
...@@ -157,9 +158,10 @@ static int query_import_device(int sockfd, char *busid) ...@@ -157,9 +158,10 @@ static int query_import_device(int sockfd, char *busid)
} }
/* receive a reply */ /* receive a reply */
rc = usbip_net_recv_op_common(sockfd, &code); rc = usbip_net_recv_op_common(sockfd, &code, &status);
if (rc < 0) { if (rc < 0) {
err("recv op_common"); err("Attach Request for %s failed - %s\n",
busid, usbip_op_common_status_string(status));
return -1; return -1;
} }
...@@ -194,11 +196,8 @@ static int attach_device(char *host, char *busid) ...@@ -194,11 +196,8 @@ static int attach_device(char *host, char *busid)
} }
rhport = query_import_device(sockfd, busid); rhport = query_import_device(sockfd, busid);
if (rhport < 0) { if (rhport < 0)
err("Attach request for Device %s. Is this device exported?",
busid);
return -1; return -1;
}
close(sockfd); close(sockfd);
......
...@@ -62,6 +62,7 @@ static int get_exported_devices(char *host, int sockfd) ...@@ -62,6 +62,7 @@ static int get_exported_devices(char *host, int sockfd)
struct usbip_usb_interface uintf; struct usbip_usb_interface uintf;
unsigned int i; unsigned int i;
int rc, j; int rc, j;
int status;
rc = usbip_net_send_op_common(sockfd, OP_REQ_DEVLIST, 0); rc = usbip_net_send_op_common(sockfd, OP_REQ_DEVLIST, 0);
if (rc < 0) { if (rc < 0) {
...@@ -69,9 +70,10 @@ static int get_exported_devices(char *host, int sockfd) ...@@ -69,9 +70,10 @@ static int get_exported_devices(char *host, int sockfd)
return -1; return -1;
} }
rc = usbip_net_recv_op_common(sockfd, &code); rc = usbip_net_recv_op_common(sockfd, &code, &status);
if (rc < 0) { 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; return -1;
} }
......
...@@ -163,7 +163,7 @@ int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status) ...@@ -163,7 +163,7 @@ int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status)
return 0; 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; struct op_common op_common;
int rc; int rc;
...@@ -191,10 +191,14 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code) ...@@ -191,10 +191,14 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code)
if (op_common.code != *code) { if (op_common.code != *code) {
dbg("unexpected pdu %#0x for %#0x", op_common.code, dbg("unexpected pdu %#0x for %#0x", op_common.code,
*code); *code);
/* return error status */
*status = ST_ERROR;
goto err; goto err;
} }
} }
*status = op_common.status;
if (op_common.status != ST_OK) { if (op_common.status != ST_OK) {
dbg("request failed at peer: %d", op_common.status); dbg("request failed at peer: %d", op_common.status);
goto err; goto err;
......
...@@ -174,7 +174,7 @@ void usbip_net_pack_usb_interface(int pack, struct usbip_usb_interface *uinf); ...@@ -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_recv(int sockfd, void *buff, size_t bufflen);
ssize_t usbip_net_send(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_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_reuseaddr(int sockfd);
int usbip_net_set_nodelay(int sockfd); int usbip_net_set_nodelay(int sockfd);
int usbip_net_set_keepalive(int sockfd); int usbip_net_set_keepalive(int sockfd);
......
...@@ -107,7 +107,7 @@ static int recv_request_import(int sockfd) ...@@ -107,7 +107,7 @@ static int recv_request_import(int sockfd)
struct usbip_usb_device pdu_udev; struct usbip_usb_device pdu_udev;
struct list_head *i; struct list_head *i;
int found = 0; int found = 0;
int error = 0; int status = ST_OK;
int rc; int rc;
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
...@@ -133,22 +133,21 @@ static int recv_request_import(int sockfd) ...@@ -133,22 +133,21 @@ static int recv_request_import(int sockfd)
usbip_net_set_nodelay(sockfd); usbip_net_set_nodelay(sockfd);
/* export device needs a TCP/IP socket descriptor */ /* export device needs a TCP/IP socket descriptor */
rc = usbip_export_device(edev, sockfd); status = usbip_export_device(edev, sockfd);
if (rc < 0) if (status < 0)
error = 1; status = ST_NA;
} else { } else {
info("requested device not found: %s", req.busid); info("requested device not found: %s", req.busid);
error = 1; status = ST_NODEV;
} }
rc = usbip_net_send_op_common(sockfd, OP_REP_IMPORT, rc = usbip_net_send_op_common(sockfd, OP_REP_IMPORT, status);
(!error ? ST_OK : ST_NA));
if (rc < 0) { if (rc < 0) {
dbg("usbip_net_send_op_common failed: %#0x", OP_REP_IMPORT); dbg("usbip_net_send_op_common failed: %#0x", OP_REP_IMPORT);
return -1; return -1;
} }
if (error) { if (status) {
dbg("import request busid %s: failed", req.busid); dbg("import request busid %s: failed", req.busid);
return -1; return -1;
} }
...@@ -251,8 +250,9 @@ static int recv_pdu(int connfd) ...@@ -251,8 +250,9 @@ static int recv_pdu(int connfd)
{ {
uint16_t code = OP_UNSPEC; uint16_t code = OP_UNSPEC;
int ret; int ret;
int status;
ret = usbip_net_recv_op_common(connfd, &code); ret = usbip_net_recv_op_common(connfd, &code, &status);
if (ret < 0) { if (ret < 0) {
dbg("could not receive opcode: %#0x", code); dbg("could not receive opcode: %#0x", code);
return -1; return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment