Received: by 10.223.185.116 with SMTP id b49csp5493400wrg; Wed, 7 Mar 2018 12:44:52 -0800 (PST) X-Google-Smtp-Source: AG47ELvEucO2Hj2Wfsp8b8HFSqTZB8Iuq/Mmz5u5F0c6lZwoPNIDZdUP1/Wy7z6vkMm5rsNLDCgV X-Received: by 2002:a17:902:70c5:: with SMTP id l5-v6mr1584564plt.13.1520455492361; Wed, 07 Mar 2018 12:44:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520455492; cv=none; d=google.com; s=arc-20160816; b=00+LTdj0/TrRfpGYLShPRiMgGKMg9nn6vcGmH6zF8rtEGpLaN8Q0VZAUDPhGggd123 aH9T9R6W2dnP3tMwWSMorcGXH/CLDQgEKYjMoXxP98TdL/p6u07JvrUpplF0tqXA7g7j RtecQGzpBSI4Y+7Es5qs/NIZStg1GHC1tZ9za+UxkJNHkpXmSr4C//o7D49YYj6IafS0 r83q5C//3LoNqR+9Cpa74Zb7iw0AYYPjdZqN7CPuiyRR4TvGVwZJ6KzCMBhWuPLWwt88 XDo9tsano0xPdKanOhLf7hqhVj7dKVYYybO2Dnj713jLnwBwGA3ngIlqZlPQj/AprMjS EoYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=3HC3j35A+FWLJvL6yqr4xI27wmBtAyT1zrXWPpKV8r0=; b=gDb0tXEpg8h/Q7+ZGegkPEbPLdjKgDXVVkpzDROB9w7HbS5CRHGdjDX0gPehoDKYFR 2pN4hX+HrhKBPGJYjZU+J2F02E5GEqlSSxyu8viQSJNX9tSfy9uHCnihqQE/wn+eKEJJ n7v00yHQzsh8k/c7ou85vXfkadRYh5Jg1RapES8uOlb5mybd5G0Xjky7RCxIiPPUKjOq Ze7DwMU1qKSNUxfwb4FOPV5ywJjKAv8Ie0BPnth3CrGlrZC8WoTo2F0k8Q5UpGDLRCRz B8tN5/ok5vvROWzMBVXF+HuCfptKpEmuziT5WpbHo06MBqFBGOw39tjPQtI2xV2vmywb nPqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u1si11782754pgp.498.2018.03.07.12.44.38; Wed, 07 Mar 2018 12:44:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935166AbeCGUm5 (ORCPT + 99 others); Wed, 7 Mar 2018 15:42:57 -0500 Received: from osg.samsung.com ([64.30.133.232]:40207 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934750AbeCGUmv (ORCPT ); Wed, 7 Mar 2018 15:42:51 -0500 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id A5BCB3FBCE; Wed, 7 Mar 2018 12:42:51 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id I_GeWnawc8Jn; Wed, 7 Mar 2018 12:42:50 -0800 (PST) Received: from localhost.localdomain (c-24-9-64-241.hsd1.co.comcast.net [24.9.64.241]) by osg.samsung.com (Postfix) with ESMTPSA id C0B5C3FBB8; Wed, 7 Mar 2018 12:42:49 -0800 (PST) From: Shuah Khan To: valentina.manea.m@gmail.com, shuah@kernel.org, gregkh@linuxfoundation.org Cc: Shuah Khan , yuyang.du@intel.com, k.opasiak@samsung.com, nobuo.iwata@fujixerox.co.jp, julien.boibessot@armadeus.com, jdieter@lesbg.com, peter.senna@gmail.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] usbip: tools: change to use new error codes in server reply messages Date: Wed, 7 Mar 2018 13:42:26 -0700 Message-Id: <0c71a0f246feec53ef79b8ea827767a5c0f76097.1520455011.git.shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- tools/usb/usbip/src/usbip_attach.c | 11 +++++------ tools/usb/usbip/src/usbip_list.c | 6 ++++-- tools/usb/usbip/src/usbip_network.c | 6 +++++- tools/usb/usbip/src/usbip_network.h | 2 +- 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) 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); 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) 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; } 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) 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; 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); 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); 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) 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; -- 2.14.1