From nobody Sat Feb 7 11:05:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1609764925; cv=none; d=zohomail.com; s=zohoarc; b=QGQyjg19VtnJN53yBTilwxlARZuOqify51JVpViWWsw5XzBL3goebL1ODNMarwPj4tfsAviL3BpbEfiospyNH+E6jAQEPulswV0J1V/cH8rrfvZ976R0T4pr59NcsH3TGwJgoUNMH/IlLgqGPfHAUaQ6RL7SxbngwD5UPcbO1jM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764925; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ziq0Za+qadaftSnfpUpWkjvjhYJ2axTj819/xWxfE2w=; b=d8zEEwIlRACXi1xkTvWvsRtpzl7ljd5nQhREoXWjK5MzZUgDeH6DabVywajqZ1osUU+Ye8XdUubIwzVL5zUHejaV9vc7jeYzxQNVSVJ/laUeD5QRUZHllnZEoJkTJDq3dOlhgzzn9m2YnUc/+jrUkgzkejQ2eVr+N6KZESPth2A= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609764925115872.0164107763323; Mon, 4 Jan 2021 04:55:25 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-418-fm6Lv2YEOiOm4jGyUJlrgw-1; Mon, 04 Jan 2021 07:55:21 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 746D4104FB62; Mon, 4 Jan 2021 12:55:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5111A5D9D3; Mon, 4 Jan 2021 12:55:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DAC9D1809CA2; Mon, 4 Jan 2021 12:55:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104Ct9g7014157 for ; Mon, 4 Jan 2021 07:55:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id AA1B82026D48; Mon, 4 Jan 2021 12:55:09 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A4D622026D47 for ; Mon, 4 Jan 2021 12:55:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07A69101A561 for ; Mon, 4 Jan 2021 12:55:07 +0000 (UTC) Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-295-rwAu4rlTMjaJI_0TlIkZbg-1; Mon, 04 Jan 2021 07:55:05 -0500 Received: by mail-qt1-f178.google.com with SMTP id a6so18337970qtw.6 for ; Mon, 04 Jan 2021 04:55:04 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:03 -0800 (PST) X-MC-Unique: fm6Lv2YEOiOm4jGyUJlrgw-1 X-MC-Unique: rwAu4rlTMjaJI_0TlIkZbg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ziq0Za+qadaftSnfpUpWkjvjhYJ2axTj819/xWxfE2w=; b=F8KkbXUjGex083Y301TT7rCrgNbaU0uz9QD56rlvK5TTQsAfEiKFl3FpLuONwkRInd Uqhyk0aEARFTn54HKLvFUSpC1VSr1BGFiq0gvwJoQCMUGnaYDQ9vX2F7IpVAVNhw4U9W PybFT0oxdCi1DkuTNbXqiSlqJB3cE5Z+B+eGvWgzwtRHmkFHbfDbtglTGfqparI4C8P6 jes9NsPeMadCvAWtrql5b0ZiPxUt0wxVd3hw32tzlAxnx4r6yynyggdhlRHh8xoH/S3y aaAQVrITC9g/4m+Db2G9bg7plhq32cmHfZ33Zqt874vHlHaqMJmn3Z3SarSZLwIonnLg +v4Q== X-Gm-Message-State: AOAM530ilvc0b0SDCnXBKKO71UBOpa+Z6qX0muD6JbsQOsYPOHTz5M2j FHosXzjDN9WBH52mxxPZfCLcjJW7BiHdtw== X-Google-Smtp-Source: ABdhPJyQeSdlO6t5dGQM1rRrkEneprmxY/kRgJii04oBljcltuZr7OMIsnQU6odYIbwQoV75IZN5EA== X-Received: by 2002:ac8:5741:: with SMTP id 1mr70072733qtx.294.1609764904153; Mon, 04 Jan 2021 04:55:04 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 04/20] virpci.c: simplify virPCIDeviceNew() signature Date: Mon, 4 Jan 2021 09:54:28 -0300 Message-Id: <20210104125444.200536-5-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The current virPCIDeviceNew() signature, receiving 4 uints in sequence (domain, bus, slot, function), is not neat. We already have a way to represent a PCI address in virPCIDeviceAddress that is used in the code. Aside from the test files, most of virPCIDeviceNew() callers have access to a virPCIDeviceAddress reference, but then we need to retrieve the 4 required uints (addr.domain, addr.bus, addr.slot, addr.function) to satisfy virPCIDeviceNew(). The result is that we have extra verbosity/boilerplate to retrieve an information that is already available in virPCIDeviceAddress. A better way is presented by virNVMEDeviceNew(), where the caller just supplies a virPCIDeviceAddress pointer and the function handles the details internally. This patch changes virPCIDeviceNew() to receive a virPCIDeviceAddress pointer instead of 4 uints. Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/virhostdev.c | 3 +-- src/libxl/libxl_driver.c | 6 ++--- src/node_device/node_device_udev.c | 11 +++++--- src/qemu/qemu_domain_address.c | 5 +--- src/qemu/qemu_driver.c | 6 ++--- src/security/security_apparmor.c | 3 +-- src/security/security_dac.c | 6 ++--- src/security/security_selinux.c | 6 ++--- src/security/virt-aa-helper.c | 6 +---- src/util/virnetdev.c | 3 +-- src/util/virnvme.c | 5 +--- src/util/virpci.c | 40 +++++++++--------------------- src/util/virpci.h | 5 +--- tests/virhostdevtest.c | 3 ++- tests/virpcitest.c | 35 +++++++++++++++++++------- 15 files changed, 64 insertions(+), 79 deletions(-) diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 120187b07a..7338ac0700 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -235,8 +235,7 @@ virHostdevGetPCIHostDevice(const virDomainHostdevDef *h= ostdev, hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PC= I) return 0; =20 - actual =3D virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + actual =3D virPCIDeviceNew(&pcisrc->addr); =20 if (!actual) return -1; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 691cecb1e9..9b93fd77d2 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5824,7 +5824,7 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 @@ -5895,7 +5895,7 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev) if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 @@ -5953,7 +5953,7 @@ libxlNodeDeviceReset(virNodeDevicePtr dev) if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 55a2731681..fceb135aa5 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -367,6 +367,7 @@ udevProcessPCI(struct udev_device *device, virNodeDevCapPCIDevPtr pci_dev =3D &def->caps->data.pci_dev; virPCIEDeviceInfoPtr pci_express =3D NULL; virPCIDevicePtr pciDev =3D NULL; + virPCIDeviceAddress devAddr; int ret =3D -1; char *p; bool privileged; @@ -416,10 +417,12 @@ udevProcessPCI(struct udev_device *device, if (virNodeDeviceGetPCIDynamicCaps(def->sysfs_path, pci_dev) < 0) goto cleanup; =20 - if (!(pciDev =3D virPCIDeviceNew(pci_dev->domain, - pci_dev->bus, - pci_dev->slot, - pci_dev->function))) + devAddr.domain =3D pci_dev->domain; + devAddr.bus =3D pci_dev->bus; + devAddr.slot =3D pci_dev->slot; + devAddr.function =3D pci_dev->function; + + if (!(pciDev =3D virPCIDeviceNew(&devAddr))) goto cleanup; =20 /* We need to be root to read PCI device configs */ diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index f0ba318cc8..ae4ad6677c 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -857,10 +857,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevi= ceDefPtr dev, return 0; } =20 - if (!(pciDev =3D virPCIDeviceNew(hostAddr->domain, - hostAddr->bus, - hostAddr->slot, - hostAddr->function))) { + if (!(pciDev =3D virPCIDeviceNew(hostAddr))) { /* libvirt should be able to perform all the * operations in virPCIDeviceNew() even if it's * running unprivileged, so if this fails, the device diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8c59a5e589..c450501c4d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11996,7 +11996,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 @@ -12077,7 +12077,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 @@ -12131,7 +12131,7 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) goto cleanup; =20 - pci =3D virPCIDeviceNew(devAddr.domain, devAddr.bus, devAddr.slot, dev= Addr.function); + pci =3D virPCIDeviceNew(&devAddr); if (!pci) goto cleanup; =20 diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index 1b035cce2f..b564866678 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -876,8 +876,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr m= gr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { virPCIDevicePtr pci =3D - virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) goto done; diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 4f4a0a069e..b5e56feaa8 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1268,8 +1268,7 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr m= gr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { virPCIDevicePtr pci =3D - virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; @@ -1437,8 +1436,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerP= tr mgr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { virPCIDevicePtr pci =3D - virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index e9cd95916e..c43d326314 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2104,8 +2104,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityMa= nagerPtr mgr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { virPCIDevicePtr pci =3D - virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; @@ -2344,8 +2343,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecuri= tyManagerPtr mgr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { virPCIDevicePtr pci =3D - virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus, - pcisrc->addr.slot, pcisrc->addr.function); + virPCIDeviceNew(&pcisrc->addr); =20 if (!pci) return -1; diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 5a6f4a5f7d..5efdb61e59 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1104,11 +1104,7 @@ get_files(vahControl * ctl) } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - virPCIDevicePtr pci =3D virPCIDeviceNew( - dev->source.subsys.u.pci.addr.domain, - dev->source.subsys.u.pci.addr.bus, - dev->source.subsys.u.pci.addr.slot, - dev->source.subsys.u.pci.addr.function); + virPCIDevicePtr pci =3D virPCIDeviceNew(&dev->source.subsy= s.u.pci.addr); =20 virDomainHostdevSubsysPCIBackendType backend =3D dev->sour= ce.subsys.u.pci.backend; if (backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO || diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index a73e5f72f1..acb3ec960c 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1141,8 +1141,7 @@ virNetDevGetPCIDevice(const char *devName) if (!vfPCIAddr) return NULL; =20 - return virPCIDeviceNew(vfPCIAddr->domain, vfPCIAddr->bus, - vfPCIAddr->slot, vfPCIAddr->function); + return virPCIDeviceNew(vfPCIAddr); } # endif =20 diff --git a/src/util/virnvme.c b/src/util/virnvme.c index b8179aa431..66b73cd1d1 100644 --- a/src/util/virnvme.c +++ b/src/util/virnvme.c @@ -290,10 +290,7 @@ virNVMeDeviceCreatePCIDevice(const virNVMeDevice *nvme) { g_autoptr(virPCIDevice) pci =3D NULL; =20 - if (!(pci =3D virPCIDeviceNew(nvme->address.domain, - nvme->address.bus, - nvme->address.slot, - nvme->address.function))) + if (!(pci =3D virPCIDeviceNew(&nvme->address))) return NULL; =20 /* NVMe devices must be bound to vfio */ diff --git a/src/util/virpci.c b/src/util/virpci.c index 3d9d583622..545b2650a0 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -475,24 +475,24 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate pre= dicate, return -1; =20 while ((ret =3D virDirRead(dir, &entry, PCI_SYSFS "devices")) > 0) { - unsigned int domain, bus, slot, function; g_autoptr(virPCIDevice) check =3D NULL; + virPCIDeviceAddress devAddr; char *tmp; =20 /* expected format: ::. */ if (/* domain */ - virStrToLong_ui(entry->d_name, &tmp, 16, &domain) < 0 || *tmp = !=3D ':' || + virStrToLong_ui(entry->d_name, &tmp, 16, &devAddr.domain) < 0 = || *tmp !=3D ':' || /* bus */ - virStrToLong_ui(tmp + 1, &tmp, 16, &bus) < 0 || *tmp !=3D ':' = || + virStrToLong_ui(tmp + 1, &tmp, 16, &devAddr.bus) < 0 || *tmp != =3D ':' || /* slot */ - virStrToLong_ui(tmp + 1, &tmp, 16, &slot) < 0 || *tmp !=3D '.'= || + virStrToLong_ui(tmp + 1, &tmp, 16, &devAddr.slot) < 0 || *tmp = !=3D '.' || /* function */ - virStrToLong_ui(tmp + 1, NULL, 16, &function) < 0) { + virStrToLong_ui(tmp + 1, NULL, 16, &devAddr.function) < 0) { VIR_WARN("Unusual entry in " PCI_SYSFS "devices: %s", entry->d= _name); continue; } =20 - check =3D virPCIDeviceNew(domain, bus, slot, function); + check =3D virPCIDeviceNew(&devAddr); if (!check) { ret =3D -1; break; @@ -767,10 +767,7 @@ virPCIDeviceIsParent(virPCIDevicePtr dev, virPCIDevice= Ptr check, void *data) */ if (dev->address.bus > secondary && dev->address.bus <=3D subordinate)= { if (*best =3D=3D NULL) { - *best =3D virPCIDeviceNew(check->address.domain, - check->address.bus, - check->address.slot, - check->address.function); + *best =3D virPCIDeviceNew(&check->address); if (*best =3D=3D NULL) { ret =3D -1; goto cleanup; @@ -790,10 +787,7 @@ virPCIDeviceIsParent(virPCIDevicePtr dev, virPCIDevice= Ptr check, void *data) =20 if (secondary > best_secondary) { virPCIDeviceFree(*best); - *best =3D virPCIDeviceNew(check->address.domain, - check->address.bus, - check->address.slot, - check->address.function); + *best =3D virPCIDeviceNew(&check->address); if (*best =3D=3D NULL) { ret =3D -1; goto cleanup; @@ -1455,10 +1449,7 @@ virPCIDeviceAddressAsString(const virPCIDeviceAddres= s *addr) } =20 virPCIDevicePtr -virPCIDeviceNew(unsigned int domain, - unsigned int bus, - unsigned int slot, - unsigned int function) +virPCIDeviceNew(const virPCIDeviceAddress *address) { g_autoptr(virPCIDevice) dev =3D NULL; g_autofree char *vendor =3D NULL; @@ -1466,10 +1457,7 @@ virPCIDeviceNew(unsigned int domain, =20 dev =3D g_new0(virPCIDevice, 1); =20 - dev->address.domain =3D domain; - dev->address.bus =3D bus; - dev->address.slot =3D slot; - dev->address.function =3D function; + virPCIDeviceAddressCopy(&dev->address, address); =20 dev->name =3D virPCIDeviceAddressAsString(&dev->address); =20 @@ -1896,8 +1884,7 @@ virPCIDeviceGetIOMMUGroupAddOne(virPCIDeviceAddressPt= r newDevAddr, void *opaque) virPCIDeviceListPtr groupList =3D opaque; g_autoptr(virPCIDevice) newDev =3D NULL; =20 - if (!(newDev =3D virPCIDeviceNew(newDevAddr->domain, newDevAddr->bus, - newDevAddr->slot, newDevAddr->function)= )) + if (!(newDev =3D virPCIDeviceNew(newDevAddr))) return -1; =20 if (virPCIDeviceListAdd(groupList, newDev) < 0) @@ -2028,10 +2015,7 @@ virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDevi= ceAddress *devAddr) { g_autoptr(virPCIDevice) pci =3D NULL; =20 - if (!(pci =3D virPCIDeviceNew(devAddr->domain, - devAddr->bus, - devAddr->slot, - devAddr->function))) + if (!(pci =3D virPCIDeviceNew(devAddr))) return NULL; =20 return virPCIDeviceGetIOMMUGroupDev(pci); diff --git a/src/util/virpci.h b/src/util/virpci.h index 43828b0a8a..d4451848c1 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -113,10 +113,7 @@ struct _virPCIEDeviceInfo { virPCIELink *link_sta; /* Actually negotiated capabilities */ }; =20 -virPCIDevicePtr virPCIDeviceNew(unsigned int domain, - unsigned int bus, - unsigned int slot, - unsigned int function); +virPCIDevicePtr virPCIDeviceNew(const virPCIDeviceAddress *address); virPCIDevicePtr virPCIDeviceCopy(virPCIDevicePtr dev); void virPCIDeviceFree(virPCIDevicePtr dev); const char *virPCIDeviceGetName(virPCIDevicePtr dev); diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 385db0849a..40c14a5281 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -138,7 +138,8 @@ myInit(void) } =20 for (i =3D 0; i < nhostdevs; i++) { - if (!(dev[i] =3D virPCIDeviceNew(0, 0, i + 1, 0))) + virDomainHostdevSubsys subsys =3D hostdevs[i]->source.subsys; + if (!(dev[i] =3D virPCIDeviceNew(&subsys.u.pci.addr))) goto cleanup; =20 virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 6f064a3f85..6a4bd5518d 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -60,8 +60,9 @@ testVirPCIDeviceNew(const void *opaque G_GNUC_UNUSED) int ret =3D -1; virPCIDevicePtr dev; const char *devName; + virPCIDeviceAddress devAddr =3D {.domain =3D 0, .bus =3D 0, .slot =3D = 0, .function =3D 0}; =20 - if (!(dev =3D virPCIDeviceNew(0, 0, 0, 0))) + if (!(dev =3D virPCIDeviceNew(&devAddr))) goto cleanup; =20 devName =3D virPCIDeviceGetName(dev); @@ -103,7 +104,9 @@ testVirPCIDeviceDetach(const void *opaque G_GNUC_UNUSED) CHECK_LIST_COUNT(inactiveDevs, 0); =20 for (i =3D 0; i < nDev; i++) { - if (!(dev[i] =3D virPCIDeviceNew(0, 0, i + 1, 0))) + virPCIDeviceAddress devAddr =3D {.domain =3D 0, .bus =3D 0, + .slot =3D i + 1, .function =3D 0}; + if (!(dev[i] =3D virPCIDeviceNew(&devAddr))) goto cleanup; =20 virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); @@ -144,7 +147,9 @@ testVirPCIDeviceReset(const void *opaque G_GNUC_UNUSED) CHECK_LIST_COUNT(inactiveDevs, 0); =20 for (i =3D 0; i < nDev; i++) { - if (!(dev[i] =3D virPCIDeviceNew(0, 0, i + 1, 0))) + virPCIDeviceAddress devAddr =3D {.domain =3D 0, .bus =3D 0, + .slot =3D i + 1, .function =3D 0}; + if (!(dev[i] =3D virPCIDeviceNew(&devAddr))) goto cleanup; =20 virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); @@ -176,7 +181,9 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUS= ED) goto cleanup; =20 for (i =3D 0; i < nDev; i++) { - if (!(dev[i] =3D virPCIDeviceNew(0, 0, i + 1, 0))) + virPCIDeviceAddress devAddr =3D {.domain =3D 0, .bus =3D 0, + .slot =3D i + 1, .function =3D 0}; + if (!(dev[i] =3D virPCIDeviceNew(&devAddr))) goto cleanup; =20 if (virPCIDeviceListAdd(inactiveDevs, dev[i]) < 0) { @@ -222,8 +229,10 @@ testVirPCIDeviceIsAssignable(const void *opaque) const struct testPCIDevData *data =3D opaque; int ret =3D -1; virPCIDevicePtr dev; + virPCIDeviceAddress devAddr =3D {.domain =3D data->domain, .bus =3D da= ta->bus, + .slot =3D data->slot, .function =3D dat= a->function}; =20 - if (!(dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, dat= a->function))) + if (!(dev =3D virPCIDeviceNew(&devAddr))) return -1; =20 if (virPCIDeviceIsAssignable(dev, true)) @@ -239,8 +248,10 @@ testVirPCIDeviceDetachSingle(const void *opaque) const struct testPCIDevData *data =3D opaque; int ret =3D -1; virPCIDevicePtr dev; + virPCIDeviceAddress devAddr =3D {.domain =3D data->domain, .bus =3D da= ta->bus, + .slot =3D data->slot, .function =3D dat= a->function}; =20 - dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, data->fun= ction); + dev =3D virPCIDeviceNew(&devAddr); if (!dev) goto cleanup; =20 @@ -261,8 +272,10 @@ testVirPCIDeviceReattachSingle(const void *opaque) const struct testPCIDevData *data =3D opaque; int ret =3D -1; virPCIDevicePtr dev; + virPCIDeviceAddress devAddr =3D {.domain =3D data->domain, .bus =3D da= ta->bus, + .slot =3D data->slot, .function =3D dat= a->function}; =20 - dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, data->fun= ction); + dev =3D virPCIDeviceNew(&devAddr); if (!dev) goto cleanup; =20 @@ -285,8 +298,10 @@ testVirPCIDeviceCheckDriverTest(const void *opaque) const struct testPCIDevData *data =3D opaque; int ret =3D -1; virPCIDevicePtr dev; + virPCIDeviceAddress devAddr =3D {.domain =3D data->domain, .bus =3D da= ta->bus, + .slot =3D data->slot, .function =3D dat= a->function}; =20 - dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, data->fun= ction); + dev =3D virPCIDeviceNew(&devAddr); if (!dev) goto cleanup; =20 @@ -305,8 +320,10 @@ testVirPCIDeviceUnbind(const void *opaque) const struct testPCIDevData *data =3D opaque; int ret =3D -1; virPCIDevicePtr dev; + virPCIDeviceAddress devAddr =3D {.domain =3D data->domain, .bus =3D da= ta->bus, + .slot =3D data->slot, .function =3D dat= a->function}; =20 - dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, data->fun= ction); + dev =3D virPCIDeviceNew(&devAddr); if (!dev) goto cleanup; =20 --=20 2.26.2