From patchwork Fri Aug 2 15:35:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3BF9A17E0 for ; Fri, 2 Aug 2019 15:59:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C14828872 for ; Fri, 2 Aug 2019 15:59:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20FBE28876; Fri, 2 Aug 2019 15:59:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A8EAE28613 for ; Fri, 2 Aug 2019 15:59:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwf-00066F-JO; Fri, 02 Aug 2019 15:58:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwe-00064t-4H for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:16 +0000 X-Inumbo-ID: 5602e1f0-b53e-11e9-8980-bc764e045a96 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 5602e1f0-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:14 +0000 (UTC) Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: aa0TOMMODD5cqOZBZlWPgeqE5h5GW4jqGv6t9lzVLyq1ugv1C+lBSMsVz5Z7np+2qE7D7olauz yqQ+KI4Q75LvVF9XYx344tAy/5xBX31pqEOPmjB+tuDJC0bg+lVmD7vJ3LTvP7MX4QsfB9ifWd LFoLMzX3y7o7kI7SqBU547wUs8TvS1lj6aQMBchZHFox0v04njuImmTWrvddaR9uMzS311vQpq ScDGCcGkbfScedAGKS1eNF4jVNBwIZ9cBegJ8XFZqkT9wdhHOkKb7smsfgLBE9DMqGCyFdx22q +sI= X-SBRS: 2.7 X-MesageID: 3931682 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3931682" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:46 +0100 Message-ID: <20190802153606.32061-16-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 15/35] libxl: Inline do_usbdev_add into libxl__device_usbdev_add X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Having the function do_usbdev_add makes it harder to add asynchronous calls into it. Move its body back into libxl__device_usbdev_add and adjust the latter as there are no reason to have a separated function. No functional changes. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_usb.c | 121 ++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 68 deletions(-) diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index 3d69379c20..43c8ad3ee3 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -1519,72 +1519,6 @@ static int usbback_dev_assign(libxl__gc *gc, const char *busid) return rc; } -static int do_usbdev_add(libxl__gc *gc, uint32_t domid, - libxl_device_usbdev *usbdev, - bool update_json) -{ - int rc; - char *busid; - libxl_device_usbctrl usbctrl; - - libxl_device_usbctrl_init(&usbctrl); - rc = libxl_devid_to_device_usbctrl(CTX, domid, usbdev->ctrl, &usbctrl); - if (rc) goto out; - - switch (usbctrl.type) { - case LIBXL_USBCTRL_TYPE_PV: - busid = usbdev_busaddr_to_busid(gc, usbdev->u.hostdev.hostbus, - usbdev->u.hostdev.hostaddr); - if (!busid) { - rc = ERROR_FAIL; - goto out; - } - - rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, - LIBXL_USBCTRL_TYPE_PV, - update_json); - if (rc) goto out; - - rc = usbback_dev_assign(gc, busid); - if (rc) { - libxl__device_usbdev_remove_xenstore(gc, domid, usbdev, - LIBXL_USBCTRL_TYPE_PV); - goto out; - } - break; - case LIBXL_USBCTRL_TYPE_QUSB: - rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, - LIBXL_USBCTRL_TYPE_QUSB, - update_json); - if (rc) goto out; - - break; - case LIBXL_USBCTRL_TYPE_DEVICEMODEL: - rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, - LIBXL_USBCTRL_TYPE_DEVICEMODEL, - update_json); - if (rc) goto out; - - rc = libxl__device_usbdev_add_hvm(gc, domid, usbdev); - if (rc) { - libxl__device_usbdev_remove_xenstore(gc, domid, usbdev, - LIBXL_USBCTRL_TYPE_DEVICEMODEL); - goto out; - } - break; - default: - LOGD(ERROR, domid, "Unsupported usb controller type"); - rc = ERROR_FAIL; - goto out; - } - - rc = 0; - -out: - libxl_device_usbctrl_dispose(&usbctrl); - return rc; -} - /* AO operation to add a usb device. * * Generally, it does: @@ -1610,6 +1544,7 @@ static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, libxl_device_usbdev *assigned; int num_assigned; libxl_device_usbctrl usbctrl; + char *busid; libxl_device_usbctrl_init(&usbctrl); @@ -1628,6 +1563,7 @@ static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, rc = ERROR_INVAL; goto out; } + libxl_device_usbctrl_dispose(&usbctrl); } /* check usb device is assignable type */ @@ -1657,14 +1593,63 @@ static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, aodev->update_json); if (rc) goto out; + rc = libxl_devid_to_device_usbctrl(CTX, domid, usbdev->ctrl, &usbctrl); + if (rc) goto out; + /* do actual adding usb device operation */ - rc = do_usbdev_add(gc, domid, usbdev, aodev->update_json); + switch (usbctrl.type) { + case LIBXL_USBCTRL_TYPE_PV: + busid = usbdev_busaddr_to_busid(gc, usbdev->u.hostdev.hostbus, + usbdev->u.hostdev.hostaddr); + if (!busid) { + rc = ERROR_FAIL; + goto out; + } + + rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, + LIBXL_USBCTRL_TYPE_PV, + aodev->update_json); + if (rc) goto out; + + rc = usbback_dev_assign(gc, busid); + if (rc) { + libxl__device_usbdev_remove_xenstore(gc, domid, usbdev, + LIBXL_USBCTRL_TYPE_PV); + goto out; + } + break; + case LIBXL_USBCTRL_TYPE_QUSB: + rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, + LIBXL_USBCTRL_TYPE_QUSB, + aodev->update_json); + if (rc) goto out; + + break; + case LIBXL_USBCTRL_TYPE_DEVICEMODEL: + rc = libxl__device_usbdev_add_xenstore(gc, domid, usbdev, + LIBXL_USBCTRL_TYPE_DEVICEMODEL, + aodev->update_json); + if (rc) goto out; + + rc = libxl__device_usbdev_add_hvm(gc, domid, usbdev); + if (rc) { + libxl__device_usbdev_remove_xenstore(gc, domid, usbdev, + LIBXL_USBCTRL_TYPE_DEVICEMODEL); + goto out; + } + break; + default: + LOGD(ERROR, domid, "Unsupported usb controller type"); + rc = ERROR_FAIL; + goto out; + } + + rc = 0; out: libxl_device_usbctrl_dispose(&usbctrl); aodev->rc = rc; aodev->callback(egc, aodev); - return; } LIBXL_DEFINE_DEVICE_ADD(usbdev)