From nobody Mon Feb 9 08:56:54 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1568914933; cv=none; d=zoho.com; s=zohoarc; b=DuEp66LgpTI5+0RW1exzZ092BvCKWiBdK9cg1VQPYnFYqVJY2LjVBYyN2dTZUAv3hzk/R97NtRSFJRA+Jv0kbqVPK98XXz8vdmSPwFUY8xlzlCeUUfkc5lzatiFtGBKVS1XausgduUpQBAaQbtXhI9KwR+C2y/uL9ZKMG3/ywEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568914933; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=TsXQQjfuaic8aTyDuBHiP0q8gjidn+TFubVJ+ssk0NI=; b=I0oB2Y/lup8LZAH6arhDRvRMH1UJfIR4v12DuhK+66c8ZSAxcEsBSTOk5eqn4WM6abkOvstupxybJH2rSqx/EoilM79WK24aICH9ZJxpmyTvVMFUGYcQnJpFgU90oahel41TVqkcAxStoscWOIaUQ82HODMNRbPjG/bFoQj0qmg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1568914933391943.1141887012257; Thu, 19 Sep 2019 10:42:13 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0Qc-0004Vx-Ur; Thu, 19 Sep 2019 17:41:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iB0Qb-0004U3-56 for xen-devel@lists.xenproject.org; Thu, 19 Sep 2019 17:41:13 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id aaa2a52e-db04-11e9-b299-bc764e2007e4; Thu, 19 Sep 2019 17:41:10 +0000 (UTC) X-Inumbo-ID: aaa2a52e-db04-11e9-b299-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568914871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yOckcj6yovcmhN9pDR0SHR6o36KGwIV4SVH3LqweW0E=; b=c89ntU5dDY3LqaUqGT7uXdZTdGX8og9umnuyk3o7QiX+ZZVAZFTN8ZnW bd/gr4UnEWZEaXjN9lq/O8QAAyyVeWJGm9Zdpr1zF6KTzKNFoJxa2KEtU FYdSS70WziYPbH/H5zhKl45y3UT6SGkQ/Q/+2+WswTlpMTD4CJll6/tkQ A=; Authentication-Results: esa3.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 (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.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=esa3.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 (esa3.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=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: uPbAmj7f21ACptnSssdrDc5G3wfrd5EkIGDzemgyTiXUjrjDjPvu8+DKz7hd4PKE+GtT7ypr9U 57583BLeNGD824lAYLHTCRNjC0P2C0S2CKxkBNnxcKnbFNtFLTSKWgiGN/MX+ZVQOfWS74v6/r ZaoqW20/3bPmnaZmbwMC+sISLSOyULGUufOGGbSgXCOTEUdUjWdaSp3mkq0L5BfTKT6UVCJex7 etixPR9NiLRmmB7IQRZhjyvTvcjC2bYXZZs9J0xwcKeV463aho3aYJNqgTNvcAEnpRgpSOOUUv FNs= X-SBRS: 2.7 X-MesageID: 5806214 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,524,1559534400"; d="scan'208";a="5806214" From: Anthony PERARD To: Date: Thu, 19 Sep 2019 18:16:42 +0100 Message-ID: <20190919171656.899649-23-anthony.perard@citrix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919171656.899649-1-anthony.perard@citrix.com> References: <20190919171656.899649-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 b9a31f96ebe3..3b432231ea85 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -554,9 +554,11 @@ static int libxl__device_usbdev_list_for_usbctrl(libxl= __gc *gc, uint32_t domid, libxl_device_usbdev **usb= devs, int *num); =20 -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); =20 +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, @@ -564,6 +566,11 @@ static void device_usbctrl_remove_qmp_cb(libxl__egc *e= gc, static void device_usbctrl_remove_done(libxl__egc *egc, libxl__ao_device *, int rc); =20 +typedef struct { + libxl__multidev multidev; + libxl__ao_device *aodev; +} usbctrl_remove_state; + /* AO function to remove a usb controller. * * Generally, it does: @@ -584,6 +591,12 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc = *egc, uint32_t domid =3D aodev->dev->domid; int usbctrl_devid =3D aodev->dev->devid; libxl_device_usbctrl *usbctrl; + usbctrl_remove_state *ucrs; + + GCNEW(ucrs); + ucrs->aodev =3D aodev; + ucrs->multidev.callback =3D device_usbctrl_usbdevs_removed; + libxl__multidev_begin(ao, &ucrs->multidev); =20 GCNEW(usbctrl); libxl_device_usbctrl_init(usbctrl); @@ -601,14 +614,29 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc= *egc, if (rc) goto out; =20 for (i =3D 0; i < num_usbdev; i++) { - rc =3D libxl__device_usbdev_remove(gc, domid, &usbdevs[i]); - if (rc) { - LOGD(ERROR, domid, "libxl__device_usbdev_remove failed: contro= ller %d, " - "port %d", usbdevs[i].ctrl, usbdevs[i].port); - goto out; - } + libxl__ao_device *usbdev_aodev =3D + libxl__multidev_prepare(&ucrs->multidev); + usbdev_aodev->action =3D LIBXL__DEVICE_ACTION_REMOVE; + libxl__device_usbdev_remove(egc, domid, &usbdevs[i], usbdev_aodev); } =20 +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 =3D + CONTAINER_OF(multidev, *ucrs, multidev); + libxl__ao_device *aodev =3D ucrs->aodev; + STATE_AO_GC(aodev->ao); + libxl_device_usbctrl *const usbctrl =3D aodev->device_config; + + if (rc) goto out; + + /* Remove usbctrl */ if (usbctrl->type =3D=3D LIBXL_USBCTRL_TYPE_DEVICEMODEL) { libxl__ev_qmp *const qmp =3D &aodev->qmp; =20 @@ -618,10 +646,10 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc= *egc, if (rc) goto out; =20 qmp->ao =3D ao; - qmp->domid =3D domid; + qmp->domid =3D aodev->dev->domid; qmp->callback =3D device_usbctrl_remove_qmp_cb; qmp->payload_fd =3D -1; - rc =3D libxl__device_usbctrl_del_hvm(gc, qmp, usbctrl_devid); + rc =3D libxl__device_usbctrl_del_hvm(gc, qmp, aodev->dev->devid); if (rc) goto out; return; } @@ -1845,20 +1873,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; =20 + /* Store *usbdev to be used by callbacks */ + aodev->device_config =3D usbdev; + aodev->device_type =3D &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 =3D ERROR_FAIL; + goto out; } =20 - libxl_device_usbctrl_init(&usbctrl); rc =3D libxl_devid_to_device_usbctrl(CTX, domid, usbdev->ctrl, &usbctr= l); if (rc) goto out; =20 @@ -1944,7 +1983,8 @@ static int libxl__device_usbdev_remove(libxl__gc *gc,= uint32_t domid, =20 out: libxl_device_usbctrl_dispose(&usbctrl); - return rc; + aodev->rc =3D rc; + aodev->callback(egc, aodev); } =20 int libxl_device_usbdev_remove(libxl_ctx *ctx, uint32_t domid, @@ -1953,11 +1993,14 @@ int libxl_device_usbdev_remove(libxl_ctx *ctx, uint= 32_t domid, =20 { AO_CREATE(ctx, domid, ao_how); - int rc; + libxl__ao_device *aodev; =20 - rc =3D libxl__device_usbdev_remove(gc, domid, usbdev); + GCNEW(aodev); + libxl__prepare_ao_device(ao, aodev); + aodev->action =3D LIBXL__DEVICE_ACTION_REMOVE; + aodev->callback =3D device_addrm_aocomplete; + libxl__device_usbdev_remove(egc, domid, usbdev, aodev); =20 - libxl__ao_complete(egc, ao, rc); return AO_INPROGRESS; } =20 --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel