From nobody Mon Sep 8 17:07:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=maximilian_martin@gmx.de; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1755528566; cv=none; d=zohomail.com; s=zohoarc; b=CeOfqL0dUdN+BK/pRb04+97qSgQBr3lSFoV3prG1zyhpKy0kRtYb8DmVqLzjIsRvTGSHMc3/yBd1r38EIqzNJkY2VyGOJXTw5YOwGvjktdBzyJW29cobB2gHx46RBF7+UEI4N8SzasQG55v0hVfjevQunpou08jKuR3S182v8NQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755528566; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=ClAbh02p/6jD1/1KKM2h9IFPnxesblMTD4rSYwemYAU=; b=LBbZynuYWLRU2uI4vewMlcoP08FHyg9FNV91cM6vNgZjfLk+yS2Wdj7vXKlRHKx42qVi0O4yZqGUXzYbDHleO/K4VRfpwLSLNRh8imLkDcsdsNcI0uLOLnSZkojNERxXlvEskrS7G9ZeXvAHokWcCX8++UF1vRcZHGWcoQA15Vg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=maximilian_martin@gmx.de; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1755528566508854.5592475880126; Mon, 18 Aug 2025 07:49:26 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A90D2E02; Mon, 18 Aug 2025 10:49:25 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 02EDBD65; Mon, 18 Aug 2025 10:39:45 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 64792A99; Mon, 18 Aug 2025 10:39:37 -0400 (EDT) Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 36C80A64 for ; Mon, 18 Aug 2025 10:39:33 -0400 (EDT) Received: from cu-host.fritz.box ([185.17.205.244]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N95iH-1uSRwZ27C3-0142s6; Mon, 18 Aug 2025 16:34:20 +0200 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1755527971; x=1756132771; i=maximilian_martin@gmx.de; bh=ClAbh02p/6jD1/1KKM2h9IFPnxesblMTD4rSYwemYAU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=YIx55fXlvSC4ikpw1XhRw2IvASocgqIrA6DMUzMhi1LfUIhrHYEFo7+RkXY6kKS7 qVi0X3jr4aSvNkTIDLi4s2iibRAC+YEhsJHjLgVq1YdwXxlSSzvvAvtTV53kGs7Sy Q/BDJentHTRzeBZbJDX4qE6UTzaw7azhk2v/wucwtjGOcn4RGpC9a5zrWhYpyDXSh 74k1rTOvCON77lZx+uoCljYRqG7iYDNomKuBfyesJXmzGr6vS/Alsw3eLlFkJKLpM ma0eHgPHXCHxKAUTNUt29VgurehAbKWIVo+LAxXQCB8lo0Td3V8XIGo7yBny/FoHJ /cTwGWbOWdZUWKXVWA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a To: devel@lists.libvirt.org Subject: [PATCH v3 3/7] domain_conf, virhostdev, virusb, virusb test: add bus/port matching Date: Mon, 18 Aug 2025 16:34:13 +0200 Message-Id: <20250818143417.765-4-maximilian_martin@gmx.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250818143417.765-1-maximilian_martin@gmx.de> References: <20250818143417.765-1-maximilian_martin@gmx.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:Ic4IM+b3J8m5DZgc+to6MTwwFQ4XVzRbnCXxkH1WWiwo9JkgP2T iMI6Iu6T/aFpPhrFSIJTjeXEFbWW4VBTJi0+rC6zXrC+9hyO4Cl49R+YiVxAyDAbL0CcHWY WeP+XxPDqXRv+LJTR5Uf1jrV5g9JEytEhBfpgfAHyvwLDVqWrRVbe+WTAF8OvE3C1VVo9cx kld23g9c33SddcJjfNzww== UI-OutboundReport: notjunk:1;M01:P0:WZz1grYex1Y=;9OtijlTi+oCIVN5BbdVwW0JYX// 0uzxaQQzGeojEhC1dBf9Aa8vjZx2BhGUGz04xtgFO3fTDriaRWhM95MatT5L06P6ye93VOgqZ 9VAS95lahqs65TN6LtMNF19PDRV+stukA2qBRvxZSF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p4roP6p1nlxtAzR8OhgJWxRS5AN0+ZMhmI9NVm5HMn+OyZ9 Fxjk5DQC8E+IPM4qwL/OAQDQ0pfmdP+r6iiI6FGlTfyQW7fNHWWEhtAjjXoJObVNeybT+DjE0 3+JXAJ8lEDW/d1bkrB1jgkHnjknAXTYWwOTkAGK1eK2/FR9aHc0K2yzsdaN49kpXCGrceIsYQ P5hZX1Of4NXCvvEZupBgqGADb4JYlBjonnZ71jcFg0KYZkpDJM89v0312u1a8QB34XqrPYXNp Wi05BWR5r+LKVNI2IN8Np3Hkxypvjost0U4KkL/O/V3yeLoLq1CW+NMWL9XjCxiMCoMshCm8u qkpOjAAaPCgMjy9qBfwwuL8Pj+az Message-ID-Hash: AW54G4BPEH2UHW55O37MOYIAQ37NHMJQ X-Message-ID-Hash: AW54G4BPEH2UHW55O37MOYIAQ37NHMJQ X-MailFrom: maximilian_martin@gmx.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Maximilian Martin X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Maximilian Martin via Devel Reply-To: Maximilian Martin X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1755528569360124100 Content-Type: text/plain; charset="utf-8" From: Maximilian Martin This patch implements USB bus/port matching. In addition to vendor/product and bus/device matching, bus/port matching is implemented. This involves additions and refactorings in the domain configuration, host device handling, and USB helpers. Also, test methods are refactored and extended. Signed-off-by: Maximilian Martin --- src/conf/domain_conf.c | 58 +++++++++++-- src/conf/domain_conf.h | 1 + src/hypervisor/virhostdev.c | 131 +++++++++++++++++------------ src/libvirt_private.syms | 2 - src/util/virusb.c | 160 ++++++++++++------------------------ src/util/virusb.h | 22 ++--- tests/virusbtest.c | 149 +++++++++++++++++++++++---------- 7 files changed, 298 insertions(+), 225 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7766e302ec..63f3032892 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2680,6 +2680,15 @@ virDomainHostdevSubsysSCSIClear(virDomainHostdevSubs= ysSCSI *scsisrc) } } =20 +static void +virDomainHostdevSubsysUSBClear(virDomainHostdevSubsysUSB *usbsrc) +{ + if (!usbsrc) + return; + + VIR_FREE(usbsrc->port); +} + =20 static void virDomainHostdevDefClear(virDomainHostdevDef *def) @@ -2723,6 +2732,8 @@ virDomainHostdevDefClear(virDomainHostdevDef *def) g_clear_pointer(&def->source.subsys.u.pci.origstates, virBitma= pFree); break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: + virDomainHostdevSubsysUSBClear(&def->source.subsys.u.usb); + break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: break; @@ -5961,13 +5972,38 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr nod= e, } =20 if ((addressNode =3D virXPathNode("./address", ctxt))) { + bool foundDevice =3D false; + bool foundPort =3D false; + g_autofree char *port =3D NULL; + int rc =3D -1; + if (virXMLPropUInt(addressNode, "bus", 0, - VIR_XML_PROP_REQUIRED, &usbsrc->bus) < 0) + VIR_XML_PROP_REQUIRED, &usbsrc->bus) < 0) { return -1; + } =20 - if (virXMLPropUInt(addressNode, "device", 0, - VIR_XML_PROP_REQUIRED, &usbsrc->device) < 0) + rc =3D virXMLPropUInt(addressNode, "device", 0, + VIR_XML_PROP_NONE, &usbsrc->device); + if (rc < 0) return -1; + else if (rc > 0) + foundDevice =3D true; + + port =3D virXMLPropString(addressNode, "port"); + if (port && *port) { + usbsrc->port =3D g_steal_pointer(&port); + foundPort =3D true; + } + + if (!foundDevice && !foundPort) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("usb address needs either device id or port")); + return -1; + } else if (foundDevice && foundPort) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("found both device id and port in usb address (amb= iguous setting)")); + return -1; + } } =20 return 0; @@ -14851,8 +14887,13 @@ virDomainHostdevMatchSubsysUSB(virDomainHostdevDef= *first, virDomainHostdevSubsysUSB *first_usbsrc =3D &first->source.subsys.u.us= b; virDomainHostdevSubsysUSB *second_usbsrc =3D &second->source.subsys.u.= usb; =20 - if (first_usbsrc->bus && first_usbsrc->device) { - /* specified by bus location on host */ + if (first_usbsrc->bus && first_usbsrc->port) { + /* specified by bus and port on host */ + if (first_usbsrc->bus =3D=3D second_usbsrc->bus && + STREQ_NULLABLE(first_usbsrc->port, second_usbsrc->port)) + return 1; + } else if (first_usbsrc->bus && first_usbsrc->device) { + /* specified by bus and device id on host */ if (first_usbsrc->bus =3D=3D second_usbsrc->bus && first_usbsrc->device =3D=3D second_usbsrc->device) return 1; @@ -24511,10 +24552,15 @@ virDomainHostdevDefFormatSubsysUSB(virBuffer *buf, virBufferAsprintf(&sourceChildBuf, "\n", u= sbsrc->product); } =20 - if (usbsrc->bus || usbsrc->device) + if (usbsrc->bus && usbsrc->port) { + virBufferAsprintf(&sourceChildBuf, "
\n", + includeTypeInAddr ? "type=3D'usb' " : "", + usbsrc->bus, usbsrc->port); + } else if (usbsrc->bus || usbsrc->device) { virBufferAsprintf(&sourceChildBuf, "
\n", includeTypeInAddr ? "type=3D'usb' " : "", usbsrc->bus, usbsrc->device); + } =20 virXMLFormatElement(buf, "source", &sourceAttrBuf, &sourceChildBuf); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index eca820892e..a655dc57a8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -228,6 +228,7 @@ struct _virDomainHostdevSubsysUSB { on vendor/product */ unsigned bus; unsigned device; + char *port; =20 unsigned vendor; unsigned product; diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 7d7df4418d..19907c76ba 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -1359,6 +1359,41 @@ virHostdevMarkUSBDevices(virHostdevManager *mgr, return -1; } =20 +static int +virHostdevFindUSBDeviceWithFlags(virDomainHostdevDef *hostdev, + bool mandatory, + unsigned int flags, + virUSBDevice **usb) +{ + virDomainHostdevSubsysUSB *usbsrc =3D &hostdev->source.subsys.u.usb; + unsigned vendor =3D usbsrc->vendor; + unsigned product =3D usbsrc->product; + unsigned bus =3D usbsrc->bus; + const char *port =3D usbsrc->port; + unsigned device =3D usbsrc->device; + g_autoptr(virUSBDeviceList) devs =3D NULL; + int rc; + + rc =3D virUSBDeviceFind(vendor, product, bus, device, port, NULL, + mandatory, flags, &devs); + if (rc < 0) + return -1; + + if (rc =3D=3D 1) { + *usb =3D virUSBDeviceListGet(devs, 0); + virUSBDeviceListSteal(devs, *usb); + } + + if (rc > 1) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("Multiple USB devices for %1$x:%2$x, use to specify one"), + vendor, product); + return -1; + } + + return rc; +} + =20 int virHostdevFindUSBDevice(virDomainHostdevDef *hostdev, @@ -1367,77 +1402,65 @@ virHostdevFindUSBDevice(virDomainHostdevDef *hostde= v, { virDomainHostdevSubsysUSB *usbsrc =3D &hostdev->source.subsys.u.usb; unsigned vendor =3D usbsrc->vendor; - unsigned product =3D usbsrc->product; unsigned bus =3D usbsrc->bus; unsigned device =3D usbsrc->device; + const char *port =3D usbsrc->port; bool autoAddress =3D usbsrc->autoAddress; + unsigned int flags =3D 0; int rc; =20 *usb =3D NULL; =20 - if (vendor && bus) { - rc =3D virUSBDeviceFind(vendor, product, bus, device, - NULL, - autoAddress ? false : mandatory, - usb); - if (rc < 0) { - return -1; - } else if (!autoAddress) { - goto out; - } else { - VIR_INFO("USB device %x:%x could not be found at previous" - " address (bus:%u device:%u)", - vendor, product, bus, device); - } + if (vendor) + flags |=3D USB_DEVICE_FIND_BY_VENDOR; + if (device) + flags |=3D USB_DEVICE_FIND_BY_DEVICE; + if (port) + flags |=3D USB_DEVICE_FIND_BY_PORT; + + /* Rule out invalid cases. */ + if (vendor && device && port) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("Cannot match USB device on vendor/product, bus/d= evice, and bus/port at once.")); + } else if (device && port) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("Cannot match USB device on bus/device and bus/po= rt at once.")); + } else if (!vendor && !device && !port) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("No matching fields for USB device found. Vendor/= product, bus/device, or bus/port required.")); + return -1; } =20 - /* When vendor is specified, its USB address is either unspecified or = the - * device could not be found at the USB device where it had been - * automatically found before. - */ - if (vendor) { - g_autoptr(virUSBDeviceList) devs =3D NULL; + /* First attempt, matching on all valid fields. */ + rc =3D virHostdevFindUSBDeviceWithFlags(hostdev, + autoAddress ? false : mandatory, + flags, usb); + if (rc < 0) + return -1; =20 - rc =3D virUSBDeviceFindByVendor(vendor, product, NULL, mandatory, = &devs); - if (rc < 0) { - return -1; - } else if (rc =3D=3D 0) { - goto out; - } else if (rc > 1) { - if (autoAddress) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("Multiple USB devices for %1$x:%2$x were = found, but none of them is at bus:%3$u device:%4$u"), - vendor, product, bus, device); - } else { - virReportError(VIR_ERR_OPERATION_FAILED, - _("Multiple USB devices for %1$x:%2$x, use =
to specify one"), - vendor, product); - } + if (rc !=3D 1 && autoAddress && device) { + VIR_INFO("USB device could not be found at previous address " + "(bus:%u device:%u)", bus, device); + + /* Second attempt, for when the device number has changed. */ + flags &=3D ~USB_DEVICE_FIND_BY_DEVICE; + usbsrc->device =3D 0; + + rc =3D virHostdevFindUSBDeviceWithFlags(hostdev, mandatory, + flags, usb); + if (rc < 0) return -1; - } =20 - *usb =3D virUSBDeviceListGet(devs, 0); - virUSBDeviceListSteal(devs, *usb); + usbsrc->autoAddress =3D true; + } =20 + if (!*usb) { + hostdev->missing =3D true; + } else if (!usbsrc->bus || !usbsrc->device) { usbsrc->bus =3D virUSBDeviceGetBus(*usb); usbsrc->device =3D virUSBDeviceGetDevno(*usb); - usbsrc->autoAddress =3D true; - - if (autoAddress) { - VIR_INFO("USB device %x:%x found at bus:%u device:%u (moved" - " from bus:%u device:%u)", - vendor, product, - usbsrc->bus, usbsrc->device, - bus, device); - } - } else if (bus) { - if (virUSBDeviceFindByBus(bus, device, NULL, mandatory, usb) < 0) - return -1; } =20 - out: - if (!*usb) - hostdev->missing =3D true; return 0; } =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b846011f0f..bc01f25d4c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3680,8 +3680,6 @@ virURIResolveAlias; # util/virusb.h virUSBDeviceFileIterate; virUSBDeviceFind; -virUSBDeviceFindByBus; -virUSBDeviceFindByVendor; virUSBDeviceFree; virUSBDeviceGetBus; virUSBDeviceGetDevno; diff --git a/src/util/virusb.c b/src/util/virusb.c index cf3461f80a..85ad3d58ce 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -61,12 +61,6 @@ struct _virUSBDeviceList { virUSBDevice **devs; }; =20 -typedef enum { - USB_DEVICE_ALL =3D 0, - USB_DEVICE_FIND_BY_VENDOR =3D 1 << 0, - USB_DEVICE_FIND_BY_BUS =3D 1 << 1, -} virUSBDeviceFindFlags; - static virClass *virUSBDeviceListClass; =20 static void virUSBDeviceListDispose(void *obj); @@ -102,11 +96,29 @@ static int virUSBSysReadFile(const char *f_name, const= char *d_name, return 0; } =20 +static int +virUSBSysReadFileStr(const char *f_name, + const char *d_name, + char **value) +{ + char *buf =3D NULL; + g_autofree char *filename =3D NULL; + + filename =3D g_strdup_printf(USB_SYSFS "/devices/%s/%s", d_name, f_nam= e); + + if (virFileReadAll(filename, 1024, &buf) < 0) + return -1; + + *value =3D buf; + return 0; +} + static virUSBDeviceList * virUSBDeviceSearch(unsigned int vendor, unsigned int product, unsigned int bus, unsigned int devno, + const char *port, const char *vroot, unsigned int flags) { @@ -127,6 +139,8 @@ virUSBDeviceSearch(unsigned int vendor, =20 while ((direrr =3D virDirRead(dir, &de, USB_SYSFS "/devices")) > 0) { unsigned int found_prod, found_vend, found_bus, found_devno; + g_autofree char *found_port =3D NULL; + bool port_matches; char *tmpstr =3D de->d_name; =20 if (strchr(de->d_name, ':')) @@ -154,16 +168,31 @@ virUSBDeviceSearch(unsigned int vendor, 10, &found_devno) < 0) goto cleanup; =20 - if ((flags & USB_DEVICE_FIND_BY_VENDOR) && - (found_prod !=3D product || found_vend !=3D vendor)) - continue; + if (virUSBSysReadFileStr("devpath", de->d_name, + &found_port) < 0) { + goto cleanup; + } else { + virStringTrimOptionalNewline(found_port); + port_matches =3D STREQ_NULLABLE(found_port, port); + } =20 - if (flags & USB_DEVICE_FIND_BY_BUS) { + if (flags & USB_DEVICE_FIND_BY_VENDOR) { + if (found_prod !=3D product || found_vend !=3D vendor) + continue; + } + + if (flags & USB_DEVICE_FIND_BY_DEVICE) { if (found_bus !=3D bus || found_devno !=3D devno) continue; found =3D true; } =20 + if (flags & USB_DEVICE_FIND_BY_PORT) { + if (found_bus !=3D bus || !port_matches) + continue; + found =3D true; + } + usb =3D virUSBDeviceNew(found_bus, found_devno, vroot); =20 if (!usb) @@ -185,123 +214,42 @@ virUSBDeviceSearch(unsigned int vendor, return ret; } =20 -int -virUSBDeviceFindByVendor(unsigned int vendor, - unsigned int product, - const char *vroot, - bool mandatory, - virUSBDeviceList **devices) -{ - virUSBDeviceList *list; - int count; - - if (!(list =3D virUSBDeviceSearch(vendor, product, 0, 0, - vroot, - USB_DEVICE_FIND_BY_VENDOR))) - return -1; - - if (list->count =3D=3D 0) { - virObjectUnref(list); - if (!mandatory) { - VIR_DEBUG("Did not find USB device %04x:%04x", - vendor, product); - if (devices) - *devices =3D NULL; - return 0; - } - - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Did not find USB device %1$04x:%2$04x"), vendor,= product); - return -1; - } - - count =3D list->count; - if (devices) - *devices =3D list; - else - virObjectUnref(list); - - return count; -} - -int -virUSBDeviceFindByBus(unsigned int bus, - unsigned int devno, - const char *vroot, - bool mandatory, - virUSBDevice **usb) -{ - virUSBDeviceList *list; - - if (!(list =3D virUSBDeviceSearch(0, 0, bus, devno, - vroot, - USB_DEVICE_FIND_BY_BUS))) - return -1; - - if (list->count =3D=3D 0) { - virObjectUnref(list); - if (!mandatory) { - VIR_DEBUG("Did not find USB device bus:%u device:%u", - bus, devno); - if (usb) - *usb =3D NULL; - return 0; - } - - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Did not find USB device bus:%1$u device:%2$u"), - bus, devno); - return -1; - } - - if (usb) { - *usb =3D virUSBDeviceListGet(list, 0); - virUSBDeviceListSteal(list, *usb); - } - virObjectUnref(list); - - return 0; -} - int virUSBDeviceFind(unsigned int vendor, unsigned int product, unsigned int bus, unsigned int devno, + const char *port, const char *vroot, bool mandatory, - virUSBDevice **usb) + unsigned int flags, + virUSBDeviceList **devices) { - virUSBDeviceList *list; + g_autoptr(virUSBDeviceList) list =3D NULL; + int count; =20 - unsigned int flags =3D USB_DEVICE_FIND_BY_VENDOR|USB_DEVICE_FIND_BY_BU= S; - if (!(list =3D virUSBDeviceSearch(vendor, product, bus, devno, + if (!(list =3D virUSBDeviceSearch(vendor, product, bus, devno, port, vroot, flags))) return -1; =20 - if (list->count =3D=3D 0) { - virObjectUnref(list); + count =3D list->count; + if (count =3D=3D 0) { if (!mandatory) { - VIR_DEBUG("Did not find USB device %04x:%04x bus:%u device:%u", - vendor, product, bus, devno); - if (usb) - *usb =3D NULL; + if (devices) + *devices =3D NULL; return 0; } =20 virReportError(VIR_ERR_INTERNAL_ERROR, - _("Did not find USB device %1$04x:%2$04x bus:%3$u d= evice:%4$u"), - vendor, product, bus, devno); + _("Did not find matching USB device: vid:%1$04x, pi= d:%2$04x, bus:%3$u, device:%4$u, port:%5$s"), + vendor, product, bus, devno, port ? port : ""); return -1; } =20 - if (usb) { - *usb =3D virUSBDeviceListGet(list, 0); - virUSBDeviceListSteal(list, *usb); - } - virObjectUnref(list); + if (devices) + *devices =3D g_steal_pointer(&list); =20 - return 0; + return count; } =20 virUSBDevice * diff --git a/src/util/virusb.h b/src/util/virusb.h index d2b3f69942..86cc0a9d3d 100644 --- a/src/util/virusb.h +++ b/src/util/virusb.h @@ -30,30 +30,26 @@ typedef struct _virUSBDeviceList virUSBDeviceList; =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virUSBDeviceList, virObjectUnref); =20 +typedef enum { + USB_DEVICE_ALL =3D 0, + USB_DEVICE_FIND_BY_VENDOR =3D 1 << 0, + USB_DEVICE_FIND_BY_DEVICE =3D 1 << 1, + USB_DEVICE_FIND_BY_PORT =3D 1 << 2, +} virUSBDeviceFindFlags; =20 virUSBDevice *virUSBDeviceNew(unsigned int bus, unsigned int devno, const char *vroot); =20 -int virUSBDeviceFindByBus(unsigned int bus, - unsigned int devno, - const char *vroot, - bool mandatory, - virUSBDevice **usb); - -int virUSBDeviceFindByVendor(unsigned int vendor, - unsigned int product, - const char *vroot, - bool mandatory, - virUSBDeviceList **devices); - int virUSBDeviceFind(unsigned int vendor, unsigned int product, unsigned int bus, unsigned int devno, + const char *port, const char *vroot, bool mandatory, - virUSBDevice **usb); + unsigned int flags, + virUSBDeviceList **devices); =20 void virUSBDeviceFree(virUSBDevice *dev); int virUSBDeviceSetUsedBy(virUSBDevice *dev, diff --git a/tests/virusbtest.c b/tests/virusbtest.c index 870e136321..12ac338df9 100644 --- a/tests/virusbtest.c +++ b/tests/virusbtest.c @@ -26,9 +26,11 @@ #define VIR_FROM_THIS VIR_FROM_NONE =20 typedef enum { - FIND_BY_ALL, FIND_BY_VENDOR, - FIND_BY_BUS + FIND_BY_DEVICE, + FIND_BY_PORT, + FIND_BY_VENDOR_AND_DEVICE, + FIND_BY_VENDOR_AND_PORT } testUSBFindFlags; =20 struct findTestInfo { @@ -37,6 +39,7 @@ struct findTestInfo { unsigned int product; unsigned int bus; unsigned int devno; + const char *port; const char *vroot; bool mandatory; int how; @@ -70,25 +73,34 @@ static int testDeviceFind(const void *opaque) g_autoptr(virUSBDeviceList) devs =3D NULL; int rv =3D 0; size_t i, ndevs =3D 0; + unsigned int flags =3D 0; =20 switch (info->how) { - case FIND_BY_ALL: - rv =3D virUSBDeviceFind(info->vendor, info->product, - info->bus, info->devno, - info->vroot, info->mandatory, &dev); - break; case FIND_BY_VENDOR: - rv =3D virUSBDeviceFindByVendor(info->vendor, info->product, - info->vroot, info->mandatory, &devs); + flags =3D USB_DEVICE_FIND_BY_VENDOR; + break; + case FIND_BY_DEVICE: + flags =3D USB_DEVICE_FIND_BY_DEVICE; + break; + case FIND_BY_PORT: + flags =3D USB_DEVICE_FIND_BY_PORT; break; - case FIND_BY_BUS: - rv =3D virUSBDeviceFindByBus(info->bus, info->devno, - info->vroot, info->mandatory, &dev); + case FIND_BY_VENDOR_AND_DEVICE: + flags =3D USB_DEVICE_FIND_BY_VENDOR | + USB_DEVICE_FIND_BY_DEVICE; + break; + case FIND_BY_VENDOR_AND_PORT: + flags =3D USB_DEVICE_FIND_BY_VENDOR | + USB_DEVICE_FIND_BY_PORT; break; } =20 + rv =3D virUSBDeviceFind(info->vendor, info->product, + info->bus, info->devno, info->port, + info->vroot, info->mandatory, flags, &devs); + if (info->expectFailure) { - if (rv =3D=3D 0) { + if (rv >=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "unexpected success"); } else { @@ -99,9 +111,20 @@ static int testDeviceFind(const void *opaque) goto cleanup; } =20 + if (info->how !=3D FIND_BY_VENDOR) { + if (rv =3D=3D 1) { + dev =3D virUSBDeviceListGet(devs, 0); + virUSBDeviceListSteal(devs, dev); + } else { + goto cleanup; + } + } + switch (info->how) { - case FIND_BY_ALL: - case FIND_BY_BUS: + case FIND_BY_DEVICE: + case FIND_BY_PORT: + case FIND_BY_VENDOR_AND_DEVICE: + case FIND_BY_VENDOR_AND_PORT: if (virUSBDeviceFileIterate(dev, testDeviceFileActor, NULL) < 0) goto cleanup; break; @@ -146,14 +169,17 @@ testUSBList(const void *opaque G_GNUC_UNUSED) virUSBDeviceList *list =3D NULL; virUSBDeviceList *devlist =3D NULL; virUSBDevice *dev =3D NULL; + virUSBDeviceList *devs =3D NULL; int ret =3D -1; + int rv; size_t i, ndevs; =20 if (!(list =3D virUSBDeviceListNew())) goto cleanup; =20 #define EXPECTED_NDEVS_ONE 3 - if (virUSBDeviceFindByVendor(0x1d6b, 0x0002, NULL, true, &devlist) < 0) + if (virUSBDeviceFind(0x1d6b, 0x0002, 0, 0, NULL, NULL, true, + USB_DEVICE_FIND_BY_VENDOR, &devlist) < 0) goto cleanup; =20 ndevs =3D virUSBDeviceListCount(devlist); @@ -176,7 +202,8 @@ testUSBList(const void *opaque G_GNUC_UNUSED) goto cleanup; =20 #define EXPECTED_NDEVS_TWO 3 - if (virUSBDeviceFindByVendor(0x18d1, 0x4e22, NULL, true, &devlist) < 0) + if (virUSBDeviceFind(0x18d1, 0x4e22, 0, 0, NULL, NULL, true, + USB_DEVICE_FIND_BY_VENDOR, &devlist) < 0) goto cleanup; =20 ndevs =3D virUSBDeviceListCount(devlist); @@ -196,8 +223,16 @@ testUSBList(const void *opaque G_GNUC_UNUSED) EXPECTED_NDEVS_ONE + EXPECTED_NDEVS_TWO) < 0) goto cleanup; =20 - if (virUSBDeviceFind(0x18d1, 0x4e22, 1, 20, NULL, true, &dev) < 0) + rv =3D virUSBDeviceFind(0x18d1, 0x4e22, 1, 20, NULL, NULL, true, + USB_DEVICE_FIND_BY_VENDOR | + USB_DEVICE_FIND_BY_DEVICE, &devs); + if (rv !=3D 1) { goto cleanup; + } else { + dev =3D virUSBDeviceListGet(devs, 0); + virUSBDeviceListSteal(devs, dev); + } + virObjectUnref(devs); =20 if (!virUSBDeviceListFind(list, dev)) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -229,49 +264,75 @@ mymain(void) { int rv =3D 0; =20 -#define DO_TEST_FIND_FULL(name, vend, prod, bus, devno, vroot, mand, how, = fail) \ +#define DO_TEST_FIND_FULL(name, vend, prod, bus, devno, \ + port, vroot, mand, how, fail) \ do { \ struct findTestInfo data =3D { name, vend, prod, bus, \ - devno, vroot, mand, how, fail \ + devno, port, vroot, mand, how, fail \ }; \ if (virTestRun("USBDeviceFind " name, testDeviceFind, &data) < 0) \ rv =3D -1; \ } while (0) =20 -#define DO_TEST_FIND(name, vend, prod, bus, devno) \ - DO_TEST_FIND_FULL(name, vend, prod, bus, devno, NULL, true, \ - FIND_BY_ALL, false) -#define DO_TEST_FIND_FAIL(name, vend, prod, bus, devno) \ - DO_TEST_FIND_FULL(name, vend, prod, bus, devno, NULL, true, \ - FIND_BY_ALL, true) - -#define DO_TEST_FIND_BY_BUS(name, bus, devno) \ - DO_TEST_FIND_FULL(name, 101, 202, bus, devno, NULL, true, \ - FIND_BY_BUS, false) -#define DO_TEST_FIND_BY_BUS_FAIL(name, bus, devno) \ - DO_TEST_FIND_FULL(name, 101, 202, bus, devno, NULL, true, \ - FIND_BY_BUS, true) - #define DO_TEST_FIND_BY_VENDOR(name, vend, prod) \ - DO_TEST_FIND_FULL(name, vend, prod, 123, 456, NULL, true, \ + DO_TEST_FIND_FULL(name, vend, prod, 123, 456, NULL, NULL, true, \ FIND_BY_VENDOR, false) #define DO_TEST_FIND_BY_VENDOR_FAIL(name, vend, prod) \ - DO_TEST_FIND_FULL(name, vend, prod, 123, 456, NULL, true, \ + DO_TEST_FIND_FULL(name, vend, prod, 123, 456, NULL, NULL, true, \ FIND_BY_VENDOR, true) =20 - DO_TEST_FIND("Nexus", 0x18d1, 0x4e22, 1, 20); - DO_TEST_FIND_FAIL("Nexus wrong devnum", 0x18d1, 0x4e22, 1, 25); - DO_TEST_FIND_FAIL("Bogus", 0xf00d, 0xbeef, 1024, 768); - - DO_TEST_FIND_BY_BUS("integrated camera", 1, 5); - DO_TEST_FIND_BY_BUS_FAIL("wrong bus/devno combination", 2, 20); - DO_TEST_FIND_BY_BUS_FAIL("missing bus", 5, 20); - DO_TEST_FIND_BY_BUS_FAIL("missing devnum", 1, 158); +#define DO_TEST_FIND_BY_DEVICE(name, bus, devno) \ + DO_TEST_FIND_FULL(name, 0x1010, 0x2020, bus, devno, NULL, NULL, true, \ + FIND_BY_DEVICE, false) +#define DO_TEST_FIND_BY_DEVICE_FAIL(name, bus, devno) \ + DO_TEST_FIND_FULL(name, 0x1010, 0x2020, bus, devno, NULL, NULL, true, \ + FIND_BY_DEVICE, true) + +#define DO_TEST_FIND_BY_PORT(name, bus, port) \ + DO_TEST_FIND_FULL(name, 0x1010, 0x2020, bus, 456, port, NULL, true, \ + FIND_BY_PORT, false) +#define DO_TEST_FIND_BY_PORT_FAIL(name, bus, port) \ + DO_TEST_FIND_FULL(name, 0x1010, 0x2020, bus, 456, port, NULL, true, \ + FIND_BY_PORT, true) + +#define DO_TEST_FIND_BY_VENDOR_AND_DEVICE(name, vend, prod, bus, devno) \ + DO_TEST_FIND_FULL(name, vend, prod, bus, devno, NULL, NULL, true, \ + FIND_BY_VENDOR_AND_DEVICE, false) +#define DO_TEST_FIND_BY_VENDOR_AND_DEVICE_FAIL(name, vend, prod, bus, devn= o) \ + DO_TEST_FIND_FULL(name, vend, prod, bus, devno, NULL, NULL, true, \ + FIND_BY_VENDOR_AND_DEVICE, true) + +#define DO_TEST_FIND_BY_VENDOR_AND_PORT(name, vend, prod, bus, port) \ + DO_TEST_FIND_FULL(name, vend, prod, bus, 456, port, NULL, true, \ + FIND_BY_VENDOR_AND_PORT, false) +#define DO_TEST_FIND_BY_VENDOR_AND_PORT_FAIL(name, vend, prod, bus, port) \ + DO_TEST_FIND_FULL(name, vend, prod, bus, 456, port, NULL, true, \ + FIND_BY_VENDOR_AND_PORT, true) + + DO_TEST_FIND_BY_DEVICE("integrated camera", 1, 5); + DO_TEST_FIND_BY_DEVICE_FAIL("wrong bus/devno combination", 2, 20); + DO_TEST_FIND_BY_DEVICE_FAIL("missing bus", 5, 20); + DO_TEST_FIND_BY_DEVICE_FAIL("missing devnum", 1, 158); =20 DO_TEST_FIND_BY_VENDOR("Nexus (multiple results)", 0x18d1, 0x4e22); DO_TEST_FIND_BY_VENDOR_FAIL("Bogus vendor and product", 0xf00d, 0xbeef= ); DO_TEST_FIND_BY_VENDOR_FAIL("Valid vendor", 0x1d6b, 0xbeef); =20 + DO_TEST_FIND_BY_PORT("Logitech mouse", 1, "1.5.3.3"); + DO_TEST_FIND_BY_PORT_FAIL("wrong bus/port combination", 2, "1.5.3.3"); + DO_TEST_FIND_BY_PORT_FAIL("missing bus", 5, "1.5.3.3"); + DO_TEST_FIND_BY_PORT_FAIL("missing port", 1, "8.2.5"); + + DO_TEST_FIND_BY_VENDOR_AND_DEVICE("Nexus", 0x18d1, 0x4e22, 1, 20); + DO_TEST_FIND_BY_VENDOR_AND_DEVICE_FAIL("Bogus vendor and product", 0xf= 00d, 0xbeef, 1, 25); + DO_TEST_FIND_BY_VENDOR_AND_DEVICE_FAIL("Nexus wrong devnum", 0x18d1, 0= x4e22, 1, 25); + DO_TEST_FIND_BY_VENDOR_AND_DEVICE_FAIL("Bogus", 0xf00d, 0xbeef, 1024, = 768); + + DO_TEST_FIND_BY_VENDOR_AND_PORT("Nexus", 0x046d, 0xc069, 1, "1.5.3.3"); + DO_TEST_FIND_BY_VENDOR_AND_PORT_FAIL("Bogus vendor and product", 0xf00= d, 0xbeef, 1, "1.5.3.3"); + DO_TEST_FIND_BY_VENDOR_AND_PORT_FAIL("Nexus wrong port", 0x18d1, 0x4e2= 2, 1, "8.2.5"); + DO_TEST_FIND_BY_VENDOR_AND_PORT_FAIL("Bogus", 0xf00d, 0xbeef, 1024, "1= .1.1.1"); + if (virTestRun("USB List test", testUSBList, NULL) < 0) rv =3D -1; =20 --=20 2.39.5