From nobody Mon Feb 9 04:14:44 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=1560511734; cv=none; d=zoho.com; s=zohoarc; b=hxAIXIBFmZkkMDsMK+3ffXA0VvYQrtHUZJRIh0rfoeTSCwzW1f2j8nmTzS/pkgL1zdWyck+MnCSe8VjFaf8MsRyT61R2X1QOFPmrqxrVHZ73wGUD5mzxzFD0yvR8T/WxUsNh2iYacWsYTlUJ9BRl5F97iGg9HyYZIE8Nbjf+Xs0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560511734; 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=hFMKwKejXkl1HOJMcEEtK3jhpW32+iGHWbqwlmCb8C0=; b=mu7HJvxuMYAm6YOG34Ix1Vc9CKHjR6bM6RwX5QEtdhX1WVYxnMptUhujlBrAEATt5nQ/KW9EfOySkcIp+SDHRU9hF/kbQ7yWIg7rDC4xX5QNblIO+xuoERtIcoV/jJNcKABa+dMI+LEJ98lBA6o+/1Eix5phPG7/JSTV7eTbvOo= ARC-Authentication-Results: i=1; mx.zoho.com; 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 1560511734356801.7622294983506; Fri, 14 Jun 2019 04:28:54 -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 1hbkN8-0008SQ-0u; Fri, 14 Jun 2019 11:27:54 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hbkN6-0008Rb-HF for xen-devel@lists.xenproject.org; Fri, 14 Jun 2019 11:27:52 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 703b6cfe-8e97-11e9-a07e-5be0cf5927e5; Fri, 14 Jun 2019 11:27:49 +0000 (UTC) X-Inumbo-ID: 703b6cfe-8e97-11e9-a07e-5be0cf5927e5 Authentication-Results: esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.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=esa5.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 (esa5.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=esa5.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 4v17sPX06L0GBxB8o8zh5iKDAxoT+LV+GRHc9AD61XHVKOxA4m9E5NlPaNigXSqzmf+QBLMjJ0 HQr7lpgm8v7ZnLfRyXNthDcBCz9Za2etHpkdX55noCB8pem5ag/TNiepHcJheMZl1jv1M9Tb7a FTEsfiGqE7YY2ntTAHlhdHWoCJ+HV/gBki6lNCw9E/BZxgqZOlQQD8/K4rbV1Wvl63s/B9TrJX cL+vfYeA+yJiZks720zWchQauNS9aegAcFw6ZUhDTrVw/OsGR760SikPiax5z3ZTvMHjZ7m693 xO8= X-SBRS: 2.7 X-MesageID: 1724306 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,373,1557201600"; d="scan'208";a="1724306" From: Anthony PERARD To: Date: Fri, 14 Jun 2019 12:24:43 +0100 Message-ID: <20190614112444.29980-15-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190614112444.29980-1-anthony.perard@citrix.com> References: <20190614112444.29980-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 14/15] libxl_usb: usbctrl, make use of generic device handling functions 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" Two functions in generate `libxl_device_usbctrl' can be replaced by generic macro: - libxl_device_usbctrl_list -> LIBXL_DEFINE_DEVICE_LIST - libxl_devid_to_device_usbctrl -> LIBXL_DEFINE_DEVID_TO_DEVICE This patch only needs to define `libxl__usbctrl_devtype.from_xenstore' to makes use of them. Small change, libxl_devid_to_device_usbctrl doesn't list all usbctrl anymore before finding the right one. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_usb.c | 122 +++++++++++----------------------------- 1 file changed, 32 insertions(+), 90 deletions(-) diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c index 9851fe8468..de49f8620c 100644 --- a/tools/libxl/libxl_usb.c +++ b/tools/libxl/libxl_usb.c @@ -563,81 +563,53 @@ void libxl__initiate_device_usbctrl_remove(libxl__egc= *egc, return; } =20 -libxl_device_usbctrl * -libxl_device_usbctrl_list(libxl_ctx *ctx, uint32_t domid, int *num) +static int libxl__usbctrl_from_xenstore(libxl__gc *gc, + const char *libxl_path, + libxl_devid devid, + libxl_device_usbctrl *usbctrl_r) { - GC_INIT(ctx); - libxl_device_usbctrl *usbctrls =3D NULL; - char *libxl_vusbs_path =3D NULL; - char **entry =3D NULL; - unsigned int nentries =3D 0; - - *num =3D 0; - - libxl_vusbs_path =3D GCSPRINTF("%s/device/%s", - libxl__xs_libxl_path(gc, domid), - libxl__device_kind_to_string(LIBXL__DEVICE_KIND_VUSB)= ); - entry =3D libxl__xs_directory(gc, XBT_NULL, libxl_vusbs_path, &nentrie= s); - - if (entry && nentries) { - usbctrls =3D libxl__zalloc(NOGC, sizeof(*usbctrls) * nentries); - libxl_device_usbctrl *usbctrl; - libxl_device_usbctrl *end =3D usbctrls + nentries; - for (usbctrl =3D usbctrls; - usbctrl < end; - usbctrl++, entry++, (*num)++) { - const char *tmp, *be_path, *libxl_path; - int ret; - - libxl_device_usbctrl_init(usbctrl); - usbctrl->devid =3D atoi(*entry); + int rc; + const char *tmp; + const char *be_path; =20 #define READ_SUBPATH(path, subpath) ({ \ - ret =3D libxl__xs_read_checked(gc, XBT_NULL, \ + rc =3D libxl__xs_read_checked(gc, XBT_NULL, \ GCSPRINTF("%s/" subpath, path), \ &tmp); \ - if (ret) goto out; \ + if (rc) goto out; \ (char *)tmp; \ }) =20 #define READ_SUBPATH_INT(path, subpath) ({ \ - ret =3D libxl__xs_read_checked(gc, XBT_NULL, \ + rc =3D libxl__xs_read_checked(gc, XBT_NULL, \ GCSPRINTF("%s/" subpath, path), \ &tmp); \ - if (ret) goto out; \ + if (rc) goto out; \ tmp ? atoi(tmp) : -1; \ }) =20 - libxl_path =3D GCSPRINTF("%s/%s", libxl_vusbs_path, *entry); - libxl_usbctrl_type_from_string(READ_SUBPATH(libxl_path, "type"= ), - &usbctrl->type); - if (usbctrl->type =3D=3D LIBXL_USBCTRL_TYPE_DEVICEMODEL) { - be_path =3D libxl_path; - ret =3D libxl__get_domid(gc, &usbctrl->backend_domid); - } else { - be_path =3D READ_SUBPATH(libxl_path, "backend"); - if (!be_path) goto out; - ret =3D libxl__backendpath_parse_domid(gc, be_path, - &usbctrl->backend_dom= id); - } - if (ret) goto out; - usbctrl->version =3D READ_SUBPATH_INT(be_path, "usb-ver"); - usbctrl->ports =3D READ_SUBPATH_INT(be_path, "num-ports"); + usbctrl_r->devid =3D devid; + libxl_usbctrl_type_from_string(READ_SUBPATH(libxl_path, "type"), + &usbctrl_r->type); + if (usbctrl_r->type =3D=3D LIBXL_USBCTRL_TYPE_DEVICEMODEL) { + be_path =3D libxl_path; + rc =3D libxl__get_domid(gc, &usbctrl_r->backend_domid); + } else { + be_path =3D READ_SUBPATH(libxl_path, "backend"); + if (!be_path) goto out; + rc =3D libxl__backendpath_parse_domid(gc, be_path, + &usbctrl_r->backend_domid); + } + if (rc) goto out; + usbctrl_r->version =3D READ_SUBPATH_INT(be_path, "usb-ver"); + usbctrl_r->ports =3D READ_SUBPATH_INT(be_path, "num-ports"); =20 #undef READ_SUBPATH #undef READ_SUBPATH_INT - } - } - - GC_FREE; - return usbctrls; - out: - LOGD(ERROR, domid, "Unable to list USB Controllers"); - libxl_device_usbctrl_list_free(usbctrls, *num); - GC_FREE; - *num =3D 0; - return NULL; + if (rc) + libxl_device_usbctrl_dispose(usbctrl_r); + return rc; } =20 int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid, @@ -705,30 +677,6 @@ int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint3= 2_t domid, return rc; } =20 -int libxl_devid_to_device_usbctrl(libxl_ctx *ctx, - uint32_t domid, - int devid, - libxl_device_usbctrl *usbctrl) -{ - libxl_device_usbctrl *usbctrls; - int nb =3D 0; - int i, rc; - - usbctrls =3D libxl_device_usbctrl_list(ctx, domid, &nb); - if (!usbctrls) return ERROR_FAIL; - - rc =3D ERROR_FAIL; - for (i =3D 0; i < nb; i++) { - if (devid =3D=3D usbctrls[i].devid) { - libxl_device_usbctrl_copy(ctx, usbctrl, &usbctrls[i]); - rc =3D 0; - break; - } - } - - libxl_device_usbctrl_list_free(usbctrls, nb); - return rc; -} =20 static char *usbdev_busaddr_to_busid(libxl__gc *gc, int bus, int addr) { @@ -1945,15 +1893,6 @@ static int libxl_device_usbdev_compare(const libxl_d= evice_usbdev *d1, return COMPARE_USB(d1, d2); } =20 -void libxl_device_usbctrl_list_free(libxl_device_usbctrl *list, int nr) -{ - int i; - - for (i =3D 0; i < nr; i++) - libxl_device_usbctrl_dispose(&list[i]); - free(list); -} - void libxl_device_usbdev_list_free(libxl_device_usbdev *list, int nr) { int i; @@ -1965,7 +1904,10 @@ void libxl_device_usbdev_list_free(libxl_device_usbd= ev *list, int nr) =20 #define libxl__device_usbctrl_update_devid NULL =20 +LIBXL_DEFINE_DEVID_TO_DEVICE(usbctrl) +LIBXL_DEFINE_DEVICE_LIST(usbctrl) DEFINE_DEVICE_TYPE_STRUCT(usbctrl, VUSB, + .from_xenstore =3D (device_from_xenstore_fn_t)libxl__usbctrl_from_xens= tore, .dm_needed =3D libxl_device_usbctrl_dm_needed ); =20 --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel