From patchwork Fri Aug 2 15:35:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073829 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 698331395 for ; Fri, 2 Aug 2019 15:59:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58EC828613 for ; Fri, 2 Aug 2019 15:59:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D05C28872; Fri, 2 Aug 2019 15:59:49 +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 C914B28613 for ; Fri, 2 Aug 2019 15:59:48 +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 1htZx0-0006hk-4M; Fri, 02 Aug 2019 15:58:38 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwy-0006es-MJ for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:36 +0000 X-Inumbo-ID: 62692693-b53e-11e9-8980-bc764e045a96 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 62692693-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:35 +0000 (UTC) Authentication-Results: esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.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=esa1.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 (esa1.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=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 34CbmWvo6apQGjTt0e89UZHXb4fHJDmovNUWyVIpigV+s4NAf7W1cx50ftz35zft4yIGgH7t+f OEzVbP5DiQ6zsf7gD3exgARxluxb9Jsk8L2CGbRcJODqeKnW3mxWm7SshdDDfrDMCxLlerVxkp OhQqb2QtpcfrgHTU04gDskmkw8NCCsqQHypDOGhfMPSIqiUmnRd+I8o9FEsMp64OroHk/+FbCk v5AU7U1MrqcUFKqFHkDiTa0eBcpvGjKMUPHO20C0VC3YnTeTmpkuwG9nJ9YzPCvZLc9O/052q2 AS4= X-SBRS: 2.7 X-MesageID: 3826803 X-Ironport-Server: esa1.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="3826803" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:53 +0100 Message-ID: <20190802153606.32061-23-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 22/35] libxl: Use aodev for libxl__device_usbdev_remove 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 This also mean libxl__initiate_device_usbctrl_remove, which uses libxl__device_usbdev_remove synchronously, needs to be updated to use it with multidev. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_usb.c | 79 +++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 18 deletions(-) diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index 6b3e388a18..8e3a419805 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -556,9 +556,11 @@ static int libxl__device_usbdev_list_for_usbctrl(libxl__gc *gc, uint32_t domid, libxl_device_usbdev **usbdevs, int *num); -static int libxl__device_usbdev_remove(libxl__gc *gc, uint32_t domid, - libxl_device_usbdev *usbdev); +static void libxl__device_usbdev_remove(libxl__egc *egc, + uint32_t domid, libxl_device_usbdev *usbdev, libxl__ao_device *aodev); +static void device_usbctrl_usbdevs_removed(libxl__egc *, + libxl__multidev *, int rc); static void device_usbctrl_remove_timeout(libxl__egc *egc, libxl__ev_time *ev, const struct timeval *requested_abs, int rc); static void device_usbctrl_remove_qmp_cb(libxl__egc *egc, @@ -566,6 +568,11 @@ static void device_usbctrl_remove_qmp_cb(libxl__egc *egc, static void device_usbctrl_remove_done(libxl__egc *egc, libxl__ao_device *, int rc); +typedef struct { + libxl__multidev multidev; + libxl__ao_device *aodev; +} usbctrl_remove_state; + /* AO function to remove a usb controller. * * Generally, it does: @@ -586,6 +593,12 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc *egc, uint32_t domid = aodev->dev->domid; int usbctrl_devid = aodev->dev->devid; libxl_device_usbctrl *usbctrl; + usbctrl_remove_state *ucrs; + + GCNEW(ucrs); + ucrs->aodev = aodev; + ucrs->multidev.callback = device_usbctrl_usbdevs_removed; + libxl__multidev_begin(ao, &ucrs->multidev); GCNEW(usbctrl); libxl_device_usbctrl_init(usbctrl); @@ -603,14 +616,29 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc *egc, if (rc) goto out; for (i = 0; i < num_usbdev; i++) { - rc = libxl__device_usbdev_remove(gc, domid, &usbdevs[i]); - if (rc) { - LOGD(ERROR, domid, "libxl__device_usbdev_remove failed: controller %d, " - "port %d", usbdevs[i].ctrl, usbdevs[i].port); - goto out; - } + libxl__ao_device *usbdev_aodev = + libxl__multidev_prepare(&ucrs->multidev); + usbdev_aodev->action = LIBXL__DEVICE_ACTION_REMOVE; + libxl__device_usbdev_remove(egc, domid, &usbdevs[i], usbdev_aodev); } +out: + libxl__multidev_prepared(egc, &ucrs->multidev, rc); /* must be last */ +} + +static void device_usbctrl_usbdevs_removed(libxl__egc *egc, + libxl__multidev *multidev, + int rc) +{ + usbctrl_remove_state *ucrs = + CONTAINER_OF(multidev, *ucrs, multidev); + libxl__ao_device *aodev = ucrs->aodev; + STATE_AO_GC(aodev->ao); + libxl_device_usbctrl *const usbctrl = aodev->device_config; + + if (rc) goto out; + + /* Remove usbctrl */ if (usbctrl->type == LIBXL_USBCTRL_TYPE_DEVICEMODEL) { libxl__ev_qmp *const qmp = &aodev->qmp; @@ -620,10 +648,10 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc *egc, if (rc) goto out; qmp->ao = ao; - qmp->domid = domid; + qmp->domid = aodev->dev->domid; qmp->callback = device_usbctrl_remove_qmp_cb; qmp->payload_fd = -1; - rc = libxl__device_usbctrl_del_hvm(gc, qmp, usbctrl_devid); + rc = libxl__device_usbctrl_del_hvm(gc, qmp, aodev->dev->devid); if (rc) goto out; return; } @@ -1847,20 +1875,31 @@ static LIBXL_DEFINE_DEVICES_ADD(usbdev) * 2) remove the usb device from xenstore controller/port. * 3) unbind usb device from usbback and rebind to its original driver. * If usb device has many interfaces, do it to each interface. + * + * Before calling this function, aodev should be properly filled: + * aodev->ao, aodev->callback, ... */ -static int libxl__device_usbdev_remove(libxl__gc *gc, uint32_t domid, - libxl_device_usbdev *usbdev) +static void libxl__device_usbdev_remove(libxl__egc *egc, uint32_t domid, + libxl_device_usbdev *usbdev, + libxl__ao_device *aodev) { + STATE_AO_GC(aodev->ao); int rc; char *busid; libxl_device_usbctrl usbctrl; + /* Store *usbdev to be used by callbacks */ + aodev->device_config = usbdev; + aodev->device_type = &libxl__usbdev_devtype; + + libxl_device_usbctrl_init(&usbctrl); + if (usbdev->ctrl < 0 || usbdev->port < 1) { LOGD(ERROR, domid, "Invalid USB device"); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } - libxl_device_usbctrl_init(&usbctrl); rc = libxl_devid_to_device_usbctrl(CTX, domid, usbdev->ctrl, &usbctrl); if (rc) goto out; @@ -1946,7 +1985,8 @@ static int libxl__device_usbdev_remove(libxl__gc *gc, uint32_t domid, out: libxl_device_usbctrl_dispose(&usbctrl); - return rc; + aodev->rc = rc; + aodev->callback(egc, aodev); } int libxl_device_usbdev_remove(libxl_ctx *ctx, uint32_t domid, @@ -1955,11 +1995,14 @@ int libxl_device_usbdev_remove(libxl_ctx *ctx, uint32_t domid, { AO_CREATE(ctx, domid, ao_how); - int rc; + libxl__ao_device *aodev; - rc = libxl__device_usbdev_remove(gc, domid, usbdev); + GCNEW(aodev); + libxl__prepare_ao_device(ao, aodev); + aodev->action = LIBXL__DEVICE_ACTION_REMOVE; + aodev->callback = device_addrm_aocomplete; + libxl__device_usbdev_remove(egc, domid, usbdev, aodev); - libxl__ao_complete(egc, ao, rc); return AO_INPROGRESS; }