diff options
author | Shuah Khan <shuahkh@osg.samsung.com> | 2018-03-07 15:42:26 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-03-09 12:17:09 -0500 |
commit | ad81b15d561692df1ce2a57dce391d39633209b1 (patch) | |
tree | 34801798ed490afb0b040cc1334ccc171fa5ea7f /tools/usb/usbip/src | |
parent | c207a10d2f0bddf691920c0d73b7e8a83e6e2fb6 (diff) |
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: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/usb/usbip/src')
-rw-r--r-- | tools/usb/usbip/src/usbip_attach.c | 11 | ||||
-rw-r--r-- | tools/usb/usbip/src/usbip_list.c | 6 | ||||
-rw-r--r-- | tools/usb/usbip/src/usbip_network.c | 6 | ||||
-rw-r--r-- | tools/usb/usbip/src/usbip_network.h | 2 | ||||
-rw-r--r-- | tools/usb/usbip/src/usbipd.c | 18 |
5 files changed, 24 insertions, 19 deletions
diff --git a/tools/usb/usbip/src/usbip_attach.c b/tools/usb/usbip/src/usbip_attach.c index f60738735398..ba88728483ff 100644 --- a/tools/usb/usbip/src/usbip_attach.c +++ b/tools/usb/usbip/src/usbip_attach.c | |||
@@ -135,6 +135,7 @@ static int query_import_device(int sockfd, char *busid) | |||
135 | struct op_import_request request; | 135 | struct op_import_request request; |
136 | struct op_import_reply reply; | 136 | struct op_import_reply reply; |
137 | uint16_t code = OP_REP_IMPORT; | 137 | uint16_t code = OP_REP_IMPORT; |
138 | int status; | ||
138 | 139 | ||
139 | memset(&request, 0, sizeof(request)); | 140 | memset(&request, 0, sizeof(request)); |
140 | memset(&reply, 0, sizeof(reply)); | 141 | memset(&reply, 0, sizeof(reply)); |
@@ -157,9 +158,10 @@ static int query_import_device(int sockfd, char *busid) | |||
157 | } | 158 | } |
158 | 159 | ||
159 | /* receive a reply */ | 160 | /* receive a reply */ |
160 | rc = usbip_net_recv_op_common(sockfd, &code); | 161 | rc = usbip_net_recv_op_common(sockfd, &code, &status); |
161 | if (rc < 0) { | 162 | if (rc < 0) { |
162 | err("recv op_common"); | 163 | err("Attach Request for %s failed - %s\n", |
164 | busid, usbip_op_common_status_string(status)); | ||
163 | return -1; | 165 | return -1; |
164 | } | 166 | } |
165 | 167 | ||
@@ -194,11 +196,8 @@ static int attach_device(char *host, char *busid) | |||
194 | } | 196 | } |
195 | 197 | ||
196 | rhport = query_import_device(sockfd, busid); | 198 | rhport = query_import_device(sockfd, busid); |
197 | if (rhport < 0) { | 199 | if (rhport < 0) |
198 | err("Attach request for Device %s. Is this device exported?", | ||
199 | busid); | ||
200 | return -1; | 200 | return -1; |
201 | } | ||
202 | 201 | ||
203 | close(sockfd); | 202 | close(sockfd); |
204 | 203 | ||
diff --git a/tools/usb/usbip/src/usbip_list.c b/tools/usb/usbip/src/usbip_list.c index d65a9f444174..8d4ccf4b9480 100644 --- a/tools/usb/usbip/src/usbip_list.c +++ b/tools/usb/usbip/src/usbip_list.c | |||
@@ -62,6 +62,7 @@ static int get_exported_devices(char *host, int sockfd) | |||
62 | struct usbip_usb_interface uintf; | 62 | struct usbip_usb_interface uintf; |
63 | unsigned int i; | 63 | unsigned int i; |
64 | int rc, j; | 64 | int rc, j; |
65 | int status; | ||
65 | 66 | ||
66 | rc = usbip_net_send_op_common(sockfd, OP_REQ_DEVLIST, 0); | 67 | rc = usbip_net_send_op_common(sockfd, OP_REQ_DEVLIST, 0); |
67 | if (rc < 0) { | 68 | if (rc < 0) { |
@@ -69,9 +70,10 @@ static int get_exported_devices(char *host, int sockfd) | |||
69 | return -1; | 70 | return -1; |
70 | } | 71 | } |
71 | 72 | ||
72 | rc = usbip_net_recv_op_common(sockfd, &code); | 73 | rc = usbip_net_recv_op_common(sockfd, &code, &status); |
73 | if (rc < 0) { | 74 | if (rc < 0) { |
74 | dbg("usbip_net_recv_op_common failed"); | 75 | err("Exported Device List Request failed - %s\n", |
76 | usbip_op_common_status_string(status)); | ||
75 | return -1; | 77 | return -1; |
76 | } | 78 | } |
77 | 79 | ||
diff --git a/tools/usb/usbip/src/usbip_network.c b/tools/usb/usbip/src/usbip_network.c index 90325fa8bc38..8ffcd47d9638 100644 --- a/tools/usb/usbip/src/usbip_network.c +++ b/tools/usb/usbip/src/usbip_network.c | |||
@@ -163,7 +163,7 @@ int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status) | |||
163 | return 0; | 163 | return 0; |
164 | } | 164 | } |
165 | 165 | ||
166 | int usbip_net_recv_op_common(int sockfd, uint16_t *code) | 166 | int usbip_net_recv_op_common(int sockfd, uint16_t *code, int *status) |
167 | { | 167 | { |
168 | struct op_common op_common; | 168 | struct op_common op_common; |
169 | int rc; | 169 | int rc; |
@@ -191,10 +191,14 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code) | |||
191 | if (op_common.code != *code) { | 191 | if (op_common.code != *code) { |
192 | dbg("unexpected pdu %#0x for %#0x", op_common.code, | 192 | dbg("unexpected pdu %#0x for %#0x", op_common.code, |
193 | *code); | 193 | *code); |
194 | /* return error status */ | ||
195 | *status = ST_ERROR; | ||
194 | goto err; | 196 | goto err; |
195 | } | 197 | } |
196 | } | 198 | } |
197 | 199 | ||
200 | *status = op_common.status; | ||
201 | |||
198 | if (op_common.status != ST_OK) { | 202 | if (op_common.status != ST_OK) { |
199 | dbg("request failed at peer: %d", op_common.status); | 203 | dbg("request failed at peer: %d", op_common.status); |
200 | goto err; | 204 | goto err; |
diff --git a/tools/usb/usbip/src/usbip_network.h b/tools/usb/usbip/src/usbip_network.h index b6a2f9be888c..555215eae43e 100644 --- a/tools/usb/usbip/src/usbip_network.h +++ b/tools/usb/usbip/src/usbip_network.h | |||
@@ -174,7 +174,7 @@ void usbip_net_pack_usb_interface(int pack, struct usbip_usb_interface *uinf); | |||
174 | ssize_t usbip_net_recv(int sockfd, void *buff, size_t bufflen); | 174 | ssize_t usbip_net_recv(int sockfd, void *buff, size_t bufflen); |
175 | ssize_t usbip_net_send(int sockfd, void *buff, size_t bufflen); | 175 | ssize_t usbip_net_send(int sockfd, void *buff, size_t bufflen); |
176 | int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status); | 176 | int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status); |
177 | int usbip_net_recv_op_common(int sockfd, uint16_t *code); | 177 | int usbip_net_recv_op_common(int sockfd, uint16_t *code, int *status); |
178 | int usbip_net_set_reuseaddr(int sockfd); | 178 | int usbip_net_set_reuseaddr(int sockfd); |
179 | int usbip_net_set_nodelay(int sockfd); | 179 | int usbip_net_set_nodelay(int sockfd); |
180 | int usbip_net_set_keepalive(int sockfd); | 180 | int usbip_net_set_keepalive(int sockfd); |
diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c index c6dad2a13c80..f8ff735eb100 100644 --- a/tools/usb/usbip/src/usbipd.c +++ b/tools/usb/usbip/src/usbipd.c | |||
@@ -107,7 +107,7 @@ static int recv_request_import(int sockfd) | |||
107 | struct usbip_usb_device pdu_udev; | 107 | struct usbip_usb_device pdu_udev; |
108 | struct list_head *i; | 108 | struct list_head *i; |
109 | int found = 0; | 109 | int found = 0; |
110 | int error = 0; | 110 | int status = ST_OK; |
111 | int rc; | 111 | int rc; |
112 | 112 | ||
113 | memset(&req, 0, sizeof(req)); | 113 | memset(&req, 0, sizeof(req)); |
@@ -133,22 +133,21 @@ static int recv_request_import(int sockfd) | |||
133 | usbip_net_set_nodelay(sockfd); | 133 | usbip_net_set_nodelay(sockfd); |
134 | 134 | ||
135 | /* export device needs a TCP/IP socket descriptor */ | 135 | /* export device needs a TCP/IP socket descriptor */ |
136 | rc = usbip_export_device(edev, sockfd); | 136 | status = usbip_export_device(edev, sockfd); |
137 | if (rc < 0) | 137 | if (status < 0) |
138 | error = 1; | 138 | status = ST_NA; |
139 | } else { | 139 | } else { |
140 | info("requested device not found: %s", req.busid); | 140 | info("requested device not found: %s", req.busid); |
141 | error = 1; | 141 | status = ST_NODEV; |
142 | } | 142 | } |
143 | 143 | ||
144 | rc = usbip_net_send_op_common(sockfd, OP_REP_IMPORT, | 144 | rc = usbip_net_send_op_common(sockfd, OP_REP_IMPORT, status); |
145 | (!error ? ST_OK : ST_NA)); | ||
146 | if (rc < 0) { | 145 | if (rc < 0) { |
147 | dbg("usbip_net_send_op_common failed: %#0x", OP_REP_IMPORT); | 146 | dbg("usbip_net_send_op_common failed: %#0x", OP_REP_IMPORT); |
148 | return -1; | 147 | return -1; |
149 | } | 148 | } |
150 | 149 | ||
151 | if (error) { | 150 | if (status) { |
152 | dbg("import request busid %s: failed", req.busid); | 151 | dbg("import request busid %s: failed", req.busid); |
153 | return -1; | 152 | return -1; |
154 | } | 153 | } |
@@ -251,8 +250,9 @@ static int recv_pdu(int connfd) | |||
251 | { | 250 | { |
252 | uint16_t code = OP_UNSPEC; | 251 | uint16_t code = OP_UNSPEC; |
253 | int ret; | 252 | int ret; |
253 | int status; | ||
254 | 254 | ||
255 | ret = usbip_net_recv_op_common(connfd, &code); | 255 | ret = usbip_net_recv_op_common(connfd, &code, &status); |
256 | if (ret < 0) { | 256 | if (ret < 0) { |
257 | dbg("could not receive opcode: %#0x", code); | 257 | dbg("could not receive opcode: %#0x", code); |
258 | return -1; | 258 | return -1; |