From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783878; cv=none; d=zoho.com; s=zohoarc; b=ThdA/MhbHwp/9fFt5XG5uUT/l/TqlvecBdpXV0/xs9W0nnznuW6hCsvwbiN7oCuG/JWY87W68xBa4XBECahnZI5H/8Dl3DA4AUfExbo0Cd2tJODZSOUuU4pIpqx2+vXybl580TKO9ZAQ4/foasJg6CmiamipiNoboL7nCKzBYm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783878; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=b3wqAyf70WZO+DQB1Pr5Vd6MBNzT52E7HPaQMI/PIfU=; b=mUtpAYQ3Nu63Pkzx6moOzXaDxfL4h+VWhz2c3yoOx/MIO4R8qjmyN1HA67tZPnHN1N7E6hZ4raZBCgS0+4eENpO0Eo00uYvu7VbcHUxQ62YRm3kNsl1Pg32EMx2ykfFDK1w0ZzEOOv/s65aGuheDEXMDUBmuJ7A7PG1aFGP/j4Q= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783878804949.1422868090044; Wed, 14 Aug 2019 04:57:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 49E13302C060; Wed, 14 Aug 2019 11:57:57 +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 07D958175D; Wed, 14 Aug 2019 11:57:57 +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 512D01806B01; Wed, 14 Aug 2019 11:57:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBvqlf015470 for ; Wed, 14 Aug 2019 07:57:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id A6FDA34912; Wed, 14 Aug 2019 11:57:52 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32C42348C3 for ; Wed, 14 Aug 2019 11:57:52 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:30 +0200 Message-Id: <27eb21f277de0981dcb6d94b8482233459cb02df.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/18] virpcimock: Move actions checking one level up 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 14 Aug 2019 11:57:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The pci_driver_bind() and pci_driver_unbind() functions are "internal implementation", meaning other parts of the code should be able to call them and get the job done. Checking for actions (PCI_ACTION_BIND and PCI_ACTION_UNBIND) should be done in handlers (pci_driver_handle_bind() and pci_driver_handle_unbind()). Surprisingly, the other two actions (PCI_ACTION_NEW_ID and PCI_ACTION_REMOVE_ID) are checked already at this level. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index beb5e1490d..6865f992dc 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -551,8 +551,8 @@ pci_driver_bind(struct pciDriver *driver, int ret =3D -1; char *devpath =3D NULL, *driverpath =3D NULL; =20 - if (dev->driver || PCI_ACTION_BIND & driver->fail) { - /* Device already bound or failing driver requested */ + if (dev->driver) { + /* Device already bound */ errno =3D ENODEV; return ret; } @@ -598,8 +598,8 @@ pci_driver_unbind(struct pciDriver *driver, int ret =3D -1; char *devpath =3D NULL, *driverpath =3D NULL; =20 - if (dev->driver !=3D driver || PCI_ACTION_UNBIND & driver->fail) { - /* Device not bound to the @driver or failing driver used */ + if (dev->driver !=3D driver) { + /* Device not bound to the @driver */ errno =3D ENODEV; return ret; } @@ -669,8 +669,8 @@ pci_driver_handle_bind(const char *path) struct pciDevice *dev =3D pci_device_find_by_content(path); struct pciDriver *driver =3D pci_driver_find_by_path(path); =20 - if (!driver || !dev) { - /* This should never happen (TM) */ + if (!driver || !dev || PCI_ACTION_BIND & driver->fail) { + /* No driver, no device or failing driver requested */ errno =3D ENODEV; goto cleanup; } @@ -686,8 +686,8 @@ pci_driver_handle_unbind(const char *path) int ret =3D -1; struct pciDevice *dev =3D pci_device_find_by_content(path); =20 - if (!dev || !dev->driver) { - /* This should never happen (TM) */ + if (!dev || !dev->driver || PCI_ACTION_UNBIND & dev->driver->fail) { + /* No device, device not binded or failing driver requested */ errno =3D ENODEV; goto cleanup; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783891; cv=none; d=zoho.com; s=zohoarc; b=eR1auyyHK4T3GgeidI8ywUIHjxZHCnW7i3unmxYD3piSuBsY7iy+InHA5YPltUFnPZ4jtd9n/7V8rM+uTqckVuuwcBX54W9SwetLNt7iGt3E3wEhi5E1d/gTuuYzQOCPxWnlryblfoqpI1LPRpAeYOiAVmNcOyD29l52WAwBK3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783891; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=DtGOODcpfoI8PKxiXpDce+pYcfiX6bTxG4IcEQzPJu0=; b=kMZ+pF43luO/B309jdpnewXIcd6ouaNX01RqTq2fJaSY0lEBGibR9/1xhY7qM8HWnAqvHNu2bR3sAOYSxBlMmntOgGmnVNeHImHcxu6DW9svjYZWCNdOG97a3qUK5HD9GQUq6POAvaqb0s2PmL8o9u/TTMsv6ZSQyFFvoRmDUQg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783891843474.69659468590555; Wed, 14 Aug 2019 04:58:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86EF3307D84B; Wed, 14 Aug 2019 11:58:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 648528069F; Wed, 14 Aug 2019 11:58:10 +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 213532551B; Wed, 14 Aug 2019 11:58:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBvrYn015478 for ; Wed, 14 Aug 2019 07:57:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 724C734912; Wed, 14 Aug 2019 11:57:53 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2787348C3 for ; Wed, 14 Aug 2019 11:57:52 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:31 +0200 Message-Id: <5b034b79744325d7d14bade9875cc546c42b5193.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/18] Revert "virpcitest: Test virPCIDeviceDetach failure" 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 14 Aug 2019 11:58:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts commit b70c093ffa00cd87c8d39d3652b798f033a81faf. In next commit the virpcimock is going to be extended and thus binding a PCI device to vfio-pci driver will finally succeed. Remove this test as it will no longer make sense. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcitest.c | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 961a7eff1a..9ecd1b7d27 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -256,36 +256,6 @@ testVirPCIDeviceDetachSingle(const void *opaque) return ret; } =20 -static int -testVirPCIDeviceDetachFail(const void *opaque) -{ - const struct testPCIDevData *data =3D opaque; - int ret =3D -1; - virPCIDevicePtr dev; - - dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, data->fun= ction); - if (!dev) - goto cleanup; - - virPCIDeviceSetStubDriver(dev, VIR_PCI_STUB_DRIVER_VFIO); - - if (virPCIDeviceDetach(dev, NULL, NULL) < 0) { - if (virTestGetVerbose() || virTestGetDebug()) - virDispatchError(NULL); - virResetLastError(); - ret =3D 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - "Attaching device %s to %s should have failed", - virPCIDeviceGetName(dev), - virPCIStubDriverTypeToString(VIR_PCI_STUB_DRIVER_VF= IO)); - } - - cleanup: - virPCIDeviceFree(dev); - return ret; -} - static int testVirPCIDeviceReattachSingle(const void *opaque) { @@ -421,8 +391,6 @@ mymain(void) DO_TEST_PCI(testVirPCIDeviceIsAssignable, 5, 0x90, 1, 0); DO_TEST_PCI(testVirPCIDeviceIsAssignable, 1, 1, 0, 0); =20 - DO_TEST_PCI(testVirPCIDeviceDetachFail, 0, 0x0a, 1, 0); - /* Reattach a device already bound to non-stub a driver */ DO_TEST_PCI_DRIVER(0, 0x0a, 1, 0, "i915"); DO_TEST_PCI(testVirPCIDeviceReattachSingle, 0, 0x0a, 1, 0); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783878; cv=none; d=zoho.com; s=zohoarc; b=c59yTSsb6C+zefqIb3pdS1Z6J8aofOvcsvwfHndWZGvQkLvifi+uvkMu4sRdXhKGXbmgu3X2zK1s3NXjHtCpfEb6ZGGREDekXBkcSWnUe9HoJjZhHkFGs3ld88H2lnsG5aBocyJ8md9rd3Gey3rvMuTbsdMyqfq4pStYCzb46J4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783878; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=2fWL4lnkJU+TIKRZ1SQG5JZsJ1K5wxT+92Okrjcr3eI=; b=Eup2l9vQtVbYakFQyBDsaIGZMwpsWLCT3sk0jZqMP48eBvuAENyYSoVFdM05LgeSMldgtm7lmo6rVvgZi8kg7vaH4n6yyUJCSMejnuGOTOTwD2Snjexn57kfRkgtp1ZJkvfPgXKaNOWx/PaNVgTgL7V1Aonm125gVD39jURhSEE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783878963245.71641561339015; Wed, 14 Aug 2019 04:57:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5057B3001467; Wed, 14 Aug 2019 11:57:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F3CC07AB72; Wed, 14 Aug 2019 11:57:56 +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 792E71C89; Wed, 14 Aug 2019 11:57:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBvsaT015485 for ; Wed, 14 Aug 2019 07:57:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3FD3B348C3; Wed, 14 Aug 2019 11:57:54 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF06D34940 for ; Wed, 14 Aug 2019 11:57:53 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:32 +0200 Message-Id: <3a54dd800f660c24922ad83a77c634b2bd4b1866.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/18] virpcimock: Create driver_override file in device dirs 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 14 Aug 2019 11:57:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Newer kernels (v3.16-rc1~29^2~6^4) have 'driver_override' file which simplifies way of binding a PCI device to desired driver. Libvirt has support for this for some time too (v2.3.0-rc1~236), but not our virpcimock. So far we did not care because our code is designed to deal with this situation. Except for one. hypothetical case: binding a device to the vfio-pci driver can be successful only via driver_override. Any attempt to bind a PCI device to vfio-pci driver using old method (new_id + unbind + bind) will fail because of b803b29c1a5. While on vanilla kernel I'm able to use the old method successfully, it's failing on RHEL kernels (not sure why). Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 52 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 6865f992dc..1c21e4e045 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -87,6 +87,11 @@ char *fakesysfspcidir; * Probe for a driver that handles the specified device. * Data in format "DDDD:BB:DD.F" (Domain:Bus:Device.Function). * + * /sys/bus/pci/devices//driver_override + * Name of a driver that overrides preferred driver can be written + * here. The device will be attached to it on drivers_probe event. + * Writing an empty string (or "\n") clears the override. + * * As a little hack, we are not mocking write to these files, but close() * instead. The advantage is we don't need any self growing array to hold = the * partial writes and construct them back. We can let all the writes finis= h, @@ -147,6 +152,7 @@ static struct pciDevice *pci_device_find_by_content(con= st char *path); static void pci_driver_new(const char *name, int fail, ...); static struct pciDriver *pci_driver_find_by_dev(struct pciDevice *dev); static struct pciDriver *pci_driver_find_by_path(const char *path); +static struct pciDriver *pci_driver_find_by_driver_override(struct pciDevi= ce *dev); static int pci_driver_bind(struct pciDriver *driver, struct pciDevice *dev= ); static int pci_driver_unbind(struct pciDriver *driver, struct pciDevice *d= ev); static int pci_driver_handle_change(int fd, const char *path); @@ -202,7 +208,8 @@ make_symlink(const char *path, static int pci_read_file(const char *path, char *buf, - size_t buf_size) + size_t buf_size, + bool truncate) { int ret =3D -1; int fd =3D -1; @@ -224,7 +231,8 @@ pci_read_file(const char *path, goto cleanup; } =20 - if (ftruncate(fd, 0) < 0) + if (truncate && + ftruncate(fd, 0) < 0) goto cleanup; =20 ret =3D 0; @@ -398,6 +406,8 @@ pci_device_new_from_stub(const struct pciDevice *data) ABORT("@tmp overflow"); make_file(devpath, "class", tmp, -1); =20 + make_file(devpath, "driver_override", NULL, -1); + if (snprintf(tmp, sizeof(tmp), "%s/../../../kernel/iommu_groups/%d", devpath, dev->iommuGroup) < 0) { @@ -441,7 +451,7 @@ pci_device_find_by_content(const char *path) { char tmp[32]; =20 - if (pci_read_file(path, tmp, sizeof(tmp)) < 0) + if (pci_read_file(path, tmp, sizeof(tmp), true) < 0) return NULL; =20 return pci_device_find_by_id(tmp); @@ -450,7 +460,10 @@ pci_device_find_by_content(const char *path) static int pci_device_autobind(struct pciDevice *dev) { - struct pciDriver *driver =3D pci_driver_find_by_dev(dev); + struct pciDriver *driver =3D pci_driver_find_by_driver_override(dev); + + if (!driver) + driver =3D pci_driver_find_by_dev(dev); =20 if (!driver) { /* No driver found. Nothing to do */ @@ -544,6 +557,31 @@ pci_driver_find_by_path(const char *path) return NULL; } =20 +static struct pciDriver * +pci_driver_find_by_driver_override(struct pciDevice *dev) +{ + VIR_AUTOFREE(char *) path =3D NULL; + char tmp[32]; + size_t i; + + if (virAsprintfQuiet(&path, + SYSFS_PCI_PREFIX "devices/%s/driver_override", + dev->id) < 0) + return NULL; + + if (pci_read_file(path, tmp, sizeof(tmp), false) < 0) + return NULL; + + for (i =3D 0; i < nPCIDrivers; i++) { + struct pciDriver *driver =3D pciDrivers[i]; + + if (STREQ(tmp, driver->name)) + return driver; + } + + return NULL; +} + static int pci_driver_bind(struct pciDriver *driver, struct pciDevice *dev) @@ -657,6 +695,8 @@ pci_driver_handle_change(int fd ATTRIBUTE_UNUSED, const= char *path) ret =3D pci_driver_handle_remove_id(path); else if (STREQ(file, "drivers_probe")) ret =3D pci_driver_handle_drivers_probe(path); + else if (STREQ(file, "driver_override")) + ret =3D 0; /* nada */ else ABORT("Not handled write to: %s", path); return ret; @@ -711,7 +751,7 @@ pci_driver_handle_new_id(const char *path) goto cleanup; } =20 - if (pci_read_file(path, buf, sizeof(buf)) < 0) + if (pci_read_file(path, buf, sizeof(buf), true) < 0) goto cleanup; =20 if (sscanf(buf, "%x %x", &vendor, &device) < 2) { @@ -766,7 +806,7 @@ pci_driver_handle_remove_id(const char *path) goto cleanup; } =20 - if (pci_read_file(path, buf, sizeof(buf)) < 0) + if (pci_read_file(path, buf, sizeof(buf), true) < 0) goto cleanup; =20 if (sscanf(buf, "%x %x", &vendor, &device) < 2) { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783895; cv=none; d=zoho.com; s=zohoarc; b=cYZBW/rss6MVLxEiYp2wKBI2iDhK10+QRmRMG2qtn5thwl/uKVvR0BnxKyNAhulUX/H+HvSi92my5Cd11B7fidRBoCxOqP7YvHbWMUuk4kD7UdK5+czZVB24mjFkzG3W+5enXhKylLTy3GEqXljYUjlivGqVznqdmTdzxq3oh5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783895; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=zPHtqhOrWRIgKaUOZNR84DWm51ZLn6KfeJo+yH9nzfQ=; b=G5X1DW7O1j3Gn+zybkxbaMEEmoZY9AVAZwP/lSSsbt/NBfTXxmho8EHrbKDOCtBFUZ3T+JQ6FeCKCdF3QtSw9Vm4rC14mPswd8NAvruvhh8hZJD0FUpFFPRkj+mOqG74CxtlVlYmSAwfNKi0o+xIE07egnli2PFCAoIYaqIfPC4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15657838950413.6707165707770173; Wed, 14 Aug 2019 04:58:15 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F037A302C073; Wed, 14 Aug 2019 11:58:13 +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 CB57E8E78D; Wed, 14 Aug 2019 11:58:13 +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 8DE56180BA9A; Wed, 14 Aug 2019 11:58:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBvtcK015490 for ; Wed, 14 Aug 2019 07:57:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0B06534912; Wed, 14 Aug 2019 11:57:55 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8AECB348C3 for ; Wed, 14 Aug 2019 11:57:54 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:33 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/18] virpcimock: Drop needless typecast 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 14 Aug 2019 11:58:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" When creating a PCI device, the pciDevice structure contains @id member which holds device address (DDDD.BB:DD.F) and is type of 'char *'. But the structure is initialized from a const char and in fact we never modify or free the @id. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 1c21e4e045..853ac588e9 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -120,7 +120,7 @@ struct pciDriver { }; =20 struct pciDevice { - char *id; + const char *id; int vendor; int device; int klass; @@ -878,7 +878,7 @@ init_env(void) =20 # define MAKE_PCI_DEVICE(Id, Vendor, Device, ...) \ do { \ - struct pciDevice dev =3D {.id =3D (char *)Id, .vendor =3D Vendor, \ + struct pciDevice dev =3D {.id =3D Id, .vendor =3D Vendor, \ .device =3D Device, __VA_ARGS__}; \ pci_device_new_from_stub(&dev); \ } while (0) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783893; cv=none; d=zoho.com; s=zohoarc; b=hN+ouT0y7gkVjGnAUZKSQsx/BAmXzV6jFAhNnPeThno2Ifb9welTXSvj8EOts1jiQbtqc4JT0MK88iPEHhX+YZhqf6KTSuSN0clMmYT3whU/STuF/xqB52uz0xTyYQjpyBOXapmB6dOY/X1UpLeklf/+v2Z5abX1G86zw0g/77o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783893; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=Zj66RxoC3SCDljI5XN09pycLYKcTf+HyysyOsLHfR5M=; b=HurD/3DnxM6LE9Yl82XP6zc6bOqoxov31RzQoxgWevThyrYzVPsiP2LOZOr5xX/Zi3lD9ZXMtnEK7sbMY9N/Hd/dmOd4887MUXIAV7xCS7VSzW4k9syPfcQfGvkWYlbBksqiWqw3Im1iO4pYMX2rDcZC12/gGxjxoGpEgLxhLLQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783893011212.84063447157894; Wed, 14 Aug 2019 04:58:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC3E5302C071; Wed, 14 Aug 2019 11:58:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7F9368D66B; Wed, 14 Aug 2019 11:58:11 +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 363B82551B; Wed, 14 Aug 2019 11:58:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBvwaq015516 for ; Wed, 14 Aug 2019 07:57:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0E73D34D3A; Wed, 14 Aug 2019 11:57:58 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DF8034940 for ; Wed, 14 Aug 2019 11:57:55 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:34 +0200 Message-Id: <370b40cbd6f92ebecc06edda5b33375682ab5ae4.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/18] virpcimock: Use VIR_AUTOFREE() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 14 Aug 2019 11:58:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" It saves us couple of lines. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 109 +++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 73 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 853ac588e9..0950f3ba00 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -172,7 +172,7 @@ make_file(const char *path, ssize_t len) { int fd =3D -1; - char *filepath =3D NULL; + VIR_AUTOFREE(char *) filepath =3D NULL; if (value && len =3D=3D -1) len =3D strlen(value); =20 @@ -186,7 +186,6 @@ make_file(const char *path, ABORT("Unable to write: %s", filepath); =20 VIR_FORCE_CLOSE(fd); - VIR_FREE(filepath); } =20 static void @@ -194,15 +193,13 @@ make_symlink(const char *path, const char *name, const char *target) { - char *filepath =3D NULL; + VIR_AUTOFREE(char *) filepath =3D NULL; =20 if (virAsprintfQuiet(&filepath, "%s/%s", path, name) < 0) ABORT_OOM(); =20 if (symlink(target, filepath) < 0) ABORT("Unable to create symlink filepath -> target"); - - VIR_FREE(filepath); } =20 static int @@ -213,7 +210,7 @@ pci_read_file(const char *path, { int ret =3D -1; int fd =3D -1; - char *newpath; + VIR_AUTOFREE(char *) newpath =3D NULL; =20 if (virAsprintfQuiet(&newpath, "%s/%s", fakesysfspcidir, @@ -237,7 +234,6 @@ pci_read_file(const char *path, =20 ret =3D 0; cleanup: - VIR_FREE(newpath); real_close(fd); return ret; } @@ -335,10 +331,10 @@ static void pci_device_new_from_stub(const struct pciDevice *data) { struct pciDevice *dev; - char *devpath; - char *id; + VIR_AUTOFREE(char *) devpath =3D NULL; + VIR_AUTOFREE(char *) id =3D NULL; char *c; - char *configSrc; + VIR_AUTOFREE(char *) configSrc =3D NULL; char tmp[256]; struct stat sb; bool configSrcExists =3D false; @@ -363,7 +359,6 @@ pci_device_new_from_stub(const struct pciDevice *data) virAsprintfQuiet(&devpath, "%s/devices/%s", fakesysfspcidir, data-= >id) < 0) ABORT_OOM(); =20 - VIR_FREE(id); memcpy(dev, data, sizeof(*dev)); =20 if (virFileMakePath(devpath) < 0) @@ -380,14 +375,13 @@ pci_device_new_from_stub(const struct pciDevice *data) * file, and parallel VPATH builds must not stomp on the * original; besides, 'make distcheck' requires the original * to be read-only */ - char *buf; + VIR_AUTOFREE(char *) buf =3D NULL; ssize_t len; =20 if ((len =3D virFileReadAll(configSrc, 4096, &buf)) < 0) ABORT("Unable to read config file '%s'", configSrc); =20 make_file(devpath, "config", buf, len); - VIR_FREE(buf); } else { /* If there's no config data in the virpcitestdata dir, create a d= ummy * config file */ @@ -427,9 +421,6 @@ pci_device_new_from_stub(const struct pciDevice *data) =20 if (VIR_APPEND_ELEMENT_QUIET(pciDevices, nPCIDevices, dev) < 0) ABORT_OOM(); - - VIR_FREE(devpath); - VIR_FREE(configSrc); } =20 static struct pciDevice * @@ -483,7 +474,7 @@ pci_driver_new(const char *name, int fail, ...) struct pciDriver *driver; va_list args; int vendor, device; - char *driverpath; + VIR_AUTOFREE(char *) driverpath =3D NULL; =20 if (VIR_ALLOC_QUIET(driver) < 0 || VIR_STRDUP_QUIET(driver->name, name) < 0 || @@ -519,8 +510,6 @@ pci_driver_new(const char *name, int fail, ...) =20 if (VIR_APPEND_ELEMENT_QUIET(pciDrivers, nPCIDrivers, driver) < 0) ABORT_OOM(); - - VIR_FREE(driverpath); } =20 static struct pciDriver * @@ -586,13 +575,13 @@ static int pci_driver_bind(struct pciDriver *driver, struct pciDevice *dev) { - int ret =3D -1; - char *devpath =3D NULL, *driverpath =3D NULL; + VIR_AUTOFREE(char *) devpath =3D NULL; + VIR_AUTOFREE(char *) driverpath =3D NULL; =20 if (dev->driver) { /* Device already bound */ errno =3D ENODEV; - return ret; + return -1; } =20 /* Make symlink under device tree */ @@ -601,11 +590,11 @@ pci_driver_bind(struct pciDriver *driver, virAsprintfQuiet(&driverpath, "%s/drivers/%s", fakesysfspcidir, driver->name) < 0) { errno =3D ENOMEM; - goto cleanup; + return -1; } =20 if (symlink(driverpath, devpath) < 0) - goto cleanup; + return -1; =20 /* Make symlink under driver tree */ VIR_FREE(devpath); @@ -615,31 +604,27 @@ pci_driver_bind(struct pciDriver *driver, virAsprintfQuiet(&driverpath, "%s/drivers/%s/%s", fakesysfspcidir, driver->name, dev->id) < 0) { errno =3D ENOMEM; - goto cleanup; + return -1; } =20 if (symlink(devpath, driverpath) < 0) - goto cleanup; + return -1; =20 dev->driver =3D driver; - ret =3D 0; - cleanup: - VIR_FREE(devpath); - VIR_FREE(driverpath); - return ret; + return 0; } =20 static int pci_driver_unbind(struct pciDriver *driver, struct pciDevice *dev) { - int ret =3D -1; - char *devpath =3D NULL, *driverpath =3D NULL; + VIR_AUTOFREE(char *) devpath =3D NULL; + VIR_AUTOFREE(char *) driverpath =3D NULL; =20 if (dev->driver !=3D driver) { /* Device not bound to the @driver */ errno =3D ENODEV; - return ret; + return -1; } =20 /* Make symlink under device tree */ @@ -648,19 +633,15 @@ pci_driver_unbind(struct pciDriver *driver, virAsprintfQuiet(&driverpath, "%s/drivers/%s/%s", fakesysfspcidir, driver->name, dev->id) < 0) { errno =3D ENOMEM; - goto cleanup; + return -1; } =20 if (unlink(devpath) < 0 || unlink(driverpath) < 0) - goto cleanup; + return -1; =20 dev->driver =3D NULL; - ret =3D 0; - cleanup: - VIR_FREE(devpath); - VIR_FREE(driverpath); - return ret; + return 0; } =20 static int @@ -909,20 +890,15 @@ init_env(void) int access(const char *path, int mode) { - int ret; + VIR_AUTOFREE(char *) newpath =3D NULL; =20 init_syms(); =20 - if (STRPREFIX(path, SYSFS_PCI_PREFIX)) { - char *newpath; - if (getrealpath(&newpath, path) < 0) - return -1; - ret =3D real_access(newpath, mode); - VIR_FREE(newpath); - } else { - ret =3D real_access(path, mode); - } - return ret; + if (STRPREFIX(path, SYSFS_PCI_PREFIX) && + getrealpath(&newpath, path) < 0) + return -1; + + return real_access(newpath ? newpath : path, mode); } =20 =20 @@ -941,7 +917,7 @@ int open(const char *path, int flags, ...) { int ret; - char *newpath =3D NULL; + VIR_AUTOFREE(char *) newpath =3D NULL; =20 init_syms(); =20 @@ -968,15 +944,13 @@ open(const char *path, int flags, ...) ret =3D -1; } =20 - VIR_FREE(newpath); return ret; } =20 DIR * opendir(const char *path) { - DIR *ret; - char *newpath =3D NULL; + VIR_AUTOFREE(char *) newpath =3D NULL; =20 init_syms(); =20 @@ -984,10 +958,7 @@ opendir(const char *path) getrealpath(&newpath, path) < 0) return NULL; =20 - ret =3D real_opendir(newpath ? newpath : path); - - VIR_FREE(newpath); - return ret; + return real_opendir(newpath ? newpath : path); } =20 int @@ -1001,23 +972,15 @@ close(int fd) char * virFileCanonicalizePath(const char *path) { - char *ret; + VIR_AUTOFREE(char *) newpath =3D NULL; =20 init_syms(); =20 - if (STRPREFIX(path, SYSFS_PCI_PREFIX)) { - char *newpath; + if (STRPREFIX(path, SYSFS_PCI_PREFIX) && + getrealpath(&newpath, path) < 0) + return NULL; =20 - if (getrealpath(&newpath, path) < 0) - return NULL; - - ret =3D real_virFileCanonicalizePath(newpath); - VIR_FREE(newpath); - } else { - ret =3D real_virFileCanonicalizePath(path); - } - - return ret; + return real_virFileCanonicalizePath(newpath ? newpath : path); } =20 # include "virmockstathelpers.c" --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783898; cv=none; d=zoho.com; s=zohoarc; b=KFTYiipC1J91ATdsMTbejldDRu01N6F21/DsQmH1WEPCOVIzPcVRs8m6Vy/p9eV/MjbCIFjkopFcdJ3G54e04V9k/YLvWlidLYYpNeVo5UNO9aKW0rpNoRKbzoTPSVyMkUX32Edb16BvP1f6MjSBmJlkAY/wTdinaWeBxaowLKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783898; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=FvBokLpsTSiXeKFLYdkUDL7raDkV42fRgbMESqjJlt4=; b=Z3jHsf1uKI/Ge1XHbZTWvrnAy78wzFDqHcLzI+wQ+7iL5ASaHpJWwg9kJ5EWOVacVVe3Y1CEEd/1Xs7UsVXcTVTxDxHwPYjYPEtJVqd+rx9l3TUIT39YzgrnXvvoyDlVUqvQT/rvQQPHmf2A24cOQ+n8hzRM/TreYCA2iEF+Kvw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783898521194.73914874716218; Wed, 14 Aug 2019 04:58:18 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 57B745FD66; Wed, 14 Aug 2019 11:58:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D9765D9CC; Wed, 14 Aug 2019 11:58:17 +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 E94FF24F68; Wed, 14 Aug 2019 11:58:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBw1d4015527 for ; Wed, 14 Aug 2019 07:58:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 282AD349D3; Wed, 14 Aug 2019 11:58:01 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id A852934D27 for ; Wed, 14 Aug 2019 11:57:58 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:35 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/18] virpcimock: Eliminate use of @fakesysfspcidir 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 14 Aug 2019 11:58:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The @fakesysfspcidir is derived from @fakerootdir. We don't need two global variables that contain nearly the same content, especially when we construct the actual path anyways. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 0950f3ba00..296da9b453 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -41,7 +41,6 @@ static char *(*real_virFileCanonicalizePath)(const char *= path); * vircgroupmock.c:462:22: error: static variable 'fakesysfsdir' is used i= n an inline function with external linkage [-Werror,-Wstatic-in-inline] */ char *fakerootdir; -char *fakesysfspcidir; =20 # define SYSFS_PCI_PREFIX "/sys/bus/pci/" =20 @@ -212,9 +211,7 @@ pci_read_file(const char *path, int fd =3D -1; VIR_AUTOFREE(char *) newpath =3D NULL; =20 - if (virAsprintfQuiet(&newpath, "%s/%s", - fakesysfspcidir, - path + strlen(SYSFS_PCI_PREFIX)) < 0) { + if (virAsprintfQuiet(&newpath, "%s/%s", fakerootdir, path) < 0) { errno =3D ENOMEM; goto cleanup; } @@ -245,8 +242,8 @@ getrealpath(char **newpath, init_env(); =20 if (STRPREFIX(path, SYSFS_PCI_PREFIX)) { - if (virAsprintfQuiet(newpath, "%s/%s", - fakesysfspcidir, + if (virAsprintfQuiet(newpath, "%s/sys/bus/pci/%s", + fakerootdir, path + strlen(SYSFS_PCI_PREFIX)) < 0) { errno =3D ENOMEM; return -1; @@ -356,7 +353,7 @@ pci_device_new_from_stub(const struct pciDevice *data) if (VIR_ALLOC_QUIET(dev) < 0 || virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config", abs_srcdir, id) < 0 || - virAsprintfQuiet(&devpath, "%s/devices/%s", fakesysfspcidir, data-= >id) < 0) + virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s", fakerootdi= r, data->id) < 0) ABORT_OOM(); =20 memcpy(dev, data, sizeof(*dev)); @@ -478,7 +475,7 @@ pci_driver_new(const char *name, int fail, ...) =20 if (VIR_ALLOC_QUIET(driver) < 0 || VIR_STRDUP_QUIET(driver->name, name) < 0 || - virAsprintfQuiet(&driverpath, "%s/drivers/%s", fakesysfspcidir, na= me) < 0) + virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s", fakeroo= tdir, name) < 0) ABORT_OOM(); =20 driver->fail =3D fail; @@ -585,10 +582,10 @@ pci_driver_bind(struct pciDriver *driver, } =20 /* Make symlink under device tree */ - if (virAsprintfQuiet(&devpath, "%s/devices/%s/driver", - fakesysfspcidir, dev->id) < 0 || - virAsprintfQuiet(&driverpath, "%s/drivers/%s", - fakesysfspcidir, driver->name) < 0) { + if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s/driver", + fakerootdir, dev->id) < 0 || + virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s", + fakerootdir, driver->name) < 0) { errno =3D ENOMEM; return -1; } @@ -599,10 +596,10 @@ pci_driver_bind(struct pciDriver *driver, /* Make symlink under driver tree */ VIR_FREE(devpath); VIR_FREE(driverpath); - if (virAsprintfQuiet(&devpath, "%s/devices/%s", - fakesysfspcidir, dev->id) < 0 || - virAsprintfQuiet(&driverpath, "%s/drivers/%s/%s", - fakesysfspcidir, driver->name, dev->id) < 0) { + if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s", + fakerootdir, dev->id) < 0 || + virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s", + fakerootdir, driver->name, dev->id) < 0) { errno =3D ENOMEM; return -1; } @@ -628,10 +625,10 @@ pci_driver_unbind(struct pciDriver *driver, } =20 /* Make symlink under device tree */ - if (virAsprintfQuiet(&devpath, "%s/devices/%s/driver", - fakesysfspcidir, dev->id) < 0 || - virAsprintfQuiet(&driverpath, "%s/drivers/%s/%s", - fakesysfspcidir, driver->name, dev->id) < 0) { + if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s/driver", + fakerootdir, dev->id) < 0 || + virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s", + fakerootdir, driver->name, dev->id) < 0) { errno =3D ENOMEM; return -1; } @@ -834,7 +831,9 @@ init_syms(void) static void init_env(void) { - if (fakerootdir && fakesysfspcidir) + VIR_AUTOFREE(char *) fakesysfspcidir =3D NULL; + + if (fakerootdir) return; =20 if (!(fakerootdir =3D getenv("LIBVIRT_FAKE_ROOT_DIR"))) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783901; cv=none; d=zoho.com; s=zohoarc; b=RhUqzSd1fWNnjzOsCslthAQaXH3eSDrBDcwajapRIYGFZev13Des5qKkY4ORkXRZ1Nk11SOKiT7bExZi7O7pdKIKGmeABUiRpjNxSjFz0E1IJixZ9/WC0avCY/1/fhUXGutqu/W19nY1zMmN4lcxB0XPhM67z9U0ANQLdXsSnrs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783901; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=Ld6xkzZYnvTHPL+y/nB9CRxeWokzJSqSBBuHLVnIZnY=; b=nnNrx0qL3DDGpW2nFXSdmWnm/Oz2C2vOBbYr89tPI9ZzkEjV0N4Min6RQg9CYn9MgjCUQF33rHIxcxA17CgxWHEizH6X/1UYDopilRwgxkGFuRzENxuAvPgj3j7Ou3jkH2gnTp425f3eStNKKK1/2ZSZDrM9tEX4IQMcQP/wF2M= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156578390178824.147100294598886; Wed, 14 Aug 2019 04:58:21 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 9779B309843C; Wed, 14 Aug 2019 11:58:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6CF55891B9; Wed, 14 Aug 2019 11:58:20 +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 298DA24F33; Wed, 14 Aug 2019 11:58:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBw3OY015537 for ; Wed, 14 Aug 2019 07:58:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8CCBE34942; Wed, 14 Aug 2019 11:58:03 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18A8C348C3 for ; Wed, 14 Aug 2019 11:58:01 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:36 +0200 Message-Id: <190ae2ea26d0a199260e6fc97cc90fc413ad589a.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/18] virpcimock: Rename @fakesysfspcidir 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 14 Aug 2019 11:58:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We will need to create more directories and instead of introducing bunch of new variables to hold their actual paths, we can have one and reuse it. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 296da9b453..e97dbd81f8 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -831,7 +831,7 @@ init_syms(void) static void init_env(void) { - VIR_AUTOFREE(char *) fakesysfspcidir =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (fakerootdir) return; @@ -839,14 +839,14 @@ init_env(void) if (!(fakerootdir =3D getenv("LIBVIRT_FAKE_ROOT_DIR"))) ABORT("Missing LIBVIRT_FAKE_ROOT_DIR env variable\n"); =20 - if (virAsprintfQuiet(&fakesysfspcidir, "%s%s", + if (virAsprintfQuiet(&tmp, "%s%s", fakerootdir, SYSFS_PCI_PREFIX) < 0) ABORT_OOM(); =20 - if (virFileMakePath(fakesysfspcidir) < 0) - ABORT("Unable to create: %s", fakesysfspcidir); + if (virFileMakePath(tmp) < 0) + ABORT("Unable to create: %s", tmp); =20 - make_file(fakesysfspcidir, "drivers_probe", NULL, -1); + make_file(tmp, "drivers_probe", NULL, -1); =20 # define MAKE_PCI_DRIVER(name, ...) \ pci_driver_new(name, 0, __VA_ARGS__, -1, -1) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783894; cv=none; d=zoho.com; s=zohoarc; b=PJohT6ciPspWOhBlU/GdyEVFYXjuU3Cxha3ztyVhttZZc542R2k09cE3yvA/JQHxqATX1yvneN1k+9sByH0/rymO8QL8R13emDBSjA1uU3fIRI1pyt34A1zkzry0Y5Xl25piXgYX6MYglqcACAeoPBke/UG4b5iWaohdzAMtALk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783894; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=uvK/aGVRuig91FynOljPr2lDqdS/JOciktmTbD94vRg=; b=SgH7uZyDeUzA5moNO03RmoslFtKr3FkGwrQwqBX0xhQAsrrNxhgb02JhrNASI56XiAAP0vA8M+baW7tgZlqJkbgIXDWtc8Futptc8S30NgB69DHCnhy6DRk3N8w0NuiHjhQchyrnXlAg22Sd5pct5pHOJZ6l0dxoD5WU53tfYSU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783894856818.8779705515467; Wed, 14 Aug 2019 04:58:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AA773001FA4; Wed, 14 Aug 2019 11:58:13 +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 764A97AB75; Wed, 14 Aug 2019 11:58:13 +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 3CABA180B536; Wed, 14 Aug 2019 11:58:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBw5pU015547 for ; Wed, 14 Aug 2019 07:58:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id D97F9348C3; Wed, 14 Aug 2019 11:58:05 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6397334940 for ; Wed, 14 Aug 2019 11:58:03 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:37 +0200 Message-Id: <7f3759f76a3ba16afa23f40de6d13cf23a0a5a4b.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/18] virpcimock: Create devices/ and drivers/ under /sys/bus/pci upfront 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 14 Aug 2019 11:58:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In near future, we will be creating devices under different location and just symlink them under devices/. Just like real kernel does. But for that we need the directories to exists. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index e97dbd81f8..213f906500 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -187,6 +187,19 @@ make_file(const char *path, VIR_FORCE_CLOSE(fd); } =20 +static void +make_dir(const char *path, + const char *name) +{ + VIR_AUTOFREE(char *) dirpath =3D NULL; + + if (virAsprintfQuiet(&dirpath, "%s/%s", path, name) < 0) + ABORT_OOM(); + + if (virFileMakePath(dirpath) < 0) + ABORT("Unable to create: %s", dirpath); +} + static void make_symlink(const char *path, const char *name, @@ -846,6 +859,8 @@ init_env(void) if (virFileMakePath(tmp) < 0) ABORT("Unable to create: %s", tmp); =20 + make_dir(tmp, "devices"); + make_dir(tmp, "drivers"); make_file(tmp, "drivers_probe", NULL, -1); =20 # define MAKE_PCI_DRIVER(name, ...) \ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783898; cv=none; d=zoho.com; s=zohoarc; b=g6y7fQt6Ada88/X6AYTtBeeBA9rteOHQjilimhr3yCVB0azwRKkas0meBHJyGA44sb1KiNjbvCZi2HPNUYvjKYuoJT0hFXrWX4h2ELeRbZuIO2szRzv8pZqQV/qTIoG/9+K0mDuVwbwfEcxb7Msee9ZUjh8DXtCqlqITasEUj3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783898; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=qK7lElIOP9OZrp6doujAcu8WfBiUnzp8jGONJpNZGS8=; b=DIE4GjtPZ5c+f6wjKEitDXaXjkEdE0vmhLtUlh6p1OAqhr6fCBb002c29c5DiXtrxe5iweEfVDDMG28BzjvgILvugQ/ned/MuMnWO7tls6r/bY58oDc18mYjEs9P5TfQ6+X8N6wFt2wt+jDs/Wj2UvmQnBxxOxBOH/PxoByC1+I= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783898681747.3818768389606; Wed, 14 Aug 2019 04:58:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD94D300BEA8; Wed, 14 Aug 2019 11:58: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 B900C34912; Wed, 14 Aug 2019 11:58: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 77094180BAA2; Wed, 14 Aug 2019 11:58:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBwARo015566 for ; Wed, 14 Aug 2019 07:58:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C60E348C3; Wed, 14 Aug 2019 11:58:10 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2864734D3D for ; Wed, 14 Aug 2019 11:58:06 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:38 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/18] virpcimock: Introduce and use pci_device_get_path() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 14 Aug 2019 11:58:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Have just one function to generate path to a PCI device so that when we change it in near future there's only few of the places we need to fix. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 213f906500..52a585d0cc 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -337,6 +337,29 @@ remove_fd(int fd) /* * PCI Device functions */ +static char * +pci_device_get_path(const struct pciDevice *dev, + const char *file, + bool faked) +{ + char *ret =3D NULL; + const char *prefix =3D ""; + + if (faked) + prefix =3D fakerootdir; + + if (file) { + ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "devices= /%s/%s", + prefix, dev->id, file)); + } else { + ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "devices= /%s", + prefix, dev->id)); + } + + return ret; +} + + static void pci_device_new_from_stub(const struct pciDevice *data) { @@ -365,12 +388,14 @@ pci_device_new_from_stub(const struct pciDevice *data) =20 if (VIR_ALLOC_QUIET(dev) < 0 || virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config", - abs_srcdir, id) < 0 || - virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s", fakerootdi= r, data->id) < 0) + abs_srcdir, id) < 0) ABORT_OOM(); =20 memcpy(dev, data, sizeof(*dev)); =20 + if (!(devpath =3D pci_device_get_path(dev, NULL, true))) + ABORT_OOM(); + if (virFileMakePath(devpath) < 0) ABORT("Unable to create: %s", devpath); =20 @@ -563,9 +588,7 @@ pci_driver_find_by_driver_override(struct pciDevice *de= v) char tmp[32]; size_t i; =20 - if (virAsprintfQuiet(&path, - SYSFS_PCI_PREFIX "devices/%s/driver_override", - dev->id) < 0) + if (!(path =3D pci_device_get_path(dev, "driver_override", false))) return NULL; =20 if (pci_read_file(path, tmp, sizeof(tmp), false) < 0) @@ -595,8 +618,7 @@ pci_driver_bind(struct pciDriver *driver, } =20 /* Make symlink under device tree */ - if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s/driver", - fakerootdir, dev->id) < 0 || + if (!(devpath =3D pci_device_get_path(dev, "driver", true)) || virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s", fakerootdir, driver->name) < 0) { errno =3D ENOMEM; @@ -609,8 +631,7 @@ pci_driver_bind(struct pciDriver *driver, /* Make symlink under driver tree */ VIR_FREE(devpath); VIR_FREE(driverpath); - if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s", - fakerootdir, dev->id) < 0 || + if (!(devpath =3D pci_device_get_path(dev, NULL, true)) || virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s", fakerootdir, driver->name, dev->id) < 0) { errno =3D ENOMEM; @@ -638,8 +659,7 @@ pci_driver_unbind(struct pciDriver *driver, } =20 /* Make symlink under device tree */ - if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s/driver", - fakerootdir, dev->id) < 0 || + if (!(devpath =3D pci_device_get_path(dev, "driver", true)) || virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s", fakerootdir, driver->name, dev->id) < 0) { errno =3D ENOMEM; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783896; cv=none; d=zoho.com; s=zohoarc; b=RjF1GTtqD+uu8R1K7GZ813YQJGqYPdjuMX9R7uux62Qv93R1/P7YppnEApehNenl1jF5NnDNAiUF5dXe9y2kgScg127vJPAHKLSZzB3ILYYxG7sjhAqJ6Ppbh/8qVBs3aGycQ1aAfAWqJAilFI3baChweyp5JZinAGr7dlAp6Jg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783896; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=3qxqgTjKZM9w6bRJ4o9YXmOJA71ElZJQ+PHxUNOUCc8=; b=VzC5/5l9WUiMa6RbEyC6Gq2GQ1ylcqFVjIUzgtMnXAJ/LeImdHQGbLu1RWcdhNU2d727OudeirBUZ/NRxP8ZFraSRMOY39ERUAaUN3/fmF1TtewpUbrM1vF+Cwb3HpVCuTiie1h7w6ZVitX1AZZHZI3iro2TyAPdoYLxtnabJKY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783896144241.28726412901824; Wed, 14 Aug 2019 04:58:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E5E430C061A; Wed, 14 Aug 2019 11:58:15 +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 E9D7234D2F; Wed, 14 Aug 2019 11:58:14 +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 B2B6D180BA9E; Wed, 14 Aug 2019 11:58:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBwCsn015579 for ; Wed, 14 Aug 2019 07:58:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id E431234912; Wed, 14 Aug 2019 11:58:12 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F762348C3 for ; Wed, 14 Aug 2019 11:58:10 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:39 +0200 Message-Id: <36a5ac10ab7ba8e9adf750f2ce6c89295859eaaf.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/18] virpcimock: Introduce and use pci_driver_get_path() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 14 Aug 2019 11:58:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Have just one function to generate path to a PCI driver so that when we change it in near future there's only few of the places we need to fix. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 52a585d0cc..de365cdb78 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -503,6 +503,29 @@ pci_device_autobind(struct pciDevice *dev) /* * PCI Driver functions */ +static char * +pci_driver_get_path(const struct pciDriver *driver, + const char *file, + bool faked) +{ + char *ret =3D NULL; + const char *prefix =3D ""; + + if (faked) + prefix =3D fakerootdir; + + if (file) { + ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "drivers= /%s/%s", + prefix, driver->name, file)); + } else { + ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "drivers= /%s", + prefix, driver->name)); + } + + return ret; +} + + static void pci_driver_new(const char *name, int fail, ...) { @@ -513,7 +536,7 @@ pci_driver_new(const char *name, int fail, ...) =20 if (VIR_ALLOC_QUIET(driver) < 0 || VIR_STRDUP_QUIET(driver->name, name) < 0 || - virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s", fakeroo= tdir, name) < 0) + !(driverpath =3D pci_driver_get_path(driver, NULL, true))) ABORT_OOM(); =20 driver->fail =3D fail; @@ -619,8 +642,7 @@ pci_driver_bind(struct pciDriver *driver, =20 /* Make symlink under device tree */ if (!(devpath =3D pci_device_get_path(dev, "driver", true)) || - virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s", - fakerootdir, driver->name) < 0) { + !(driverpath =3D pci_driver_get_path(driver, NULL, true))) { errno =3D ENOMEM; return -1; } @@ -632,8 +654,7 @@ pci_driver_bind(struct pciDriver *driver, VIR_FREE(devpath); VIR_FREE(driverpath); if (!(devpath =3D pci_device_get_path(dev, NULL, true)) || - virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s", - fakerootdir, driver->name, dev->id) < 0) { + !(driverpath =3D pci_driver_get_path(driver, dev->id, true))) { errno =3D ENOMEM; return -1; } @@ -660,8 +681,7 @@ pci_driver_unbind(struct pciDriver *driver, =20 /* Make symlink under device tree */ if (!(devpath =3D pci_device_get_path(dev, "driver", true)) || - virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s", - fakerootdir, driver->name, dev->id) < 0) { + !(driverpath =3D pci_driver_get_path(driver, dev->id, true))) { errno =3D ENOMEM; return -1; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783905; cv=none; d=zoho.com; s=zohoarc; b=Cc2+uqCKdBmnUsoK3qK6/ONO2kSRcQH8jsaUlhTEjhvirTUJsirDEUuCYbi8Uc0O+nzYbnCehkBEi7bwfFg5X1Y3jGLTCgUtxOQoYnhmjtYadcaYBW4NWLXsc+OUXljUsbLR+6hSGYwkGknG2zhbnELsPOtaPaCEFEhjRZsa0uI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783905; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=L18y2SDlBQCQ97dU9bbygiMXbaIWq8cDuIBRR+s7Yms=; b=oosHBQ7Jo/mEwevP2dwSxaGi2kOu+xWDlgwo5D3QnXo7KnkdUSVXeLBnD1NGyW10J1L5s8X9tWuGCw94Q433ch5kIVbvs6r0heGH7tMW1LH+RrnMi1bjyfUz/39pjll7Co2nzaiJdzrVfomLm0OB1sGj1vhkSArMAD2QS8CLH6A= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15657839053801010.4993739059985; Wed, 14 Aug 2019 04:58:25 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 063044C95D; Wed, 14 Aug 2019 11:58:24 +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 D4A40891B0; Wed, 14 Aug 2019 11:58:23 +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 9EBAF180BAA6; Wed, 14 Aug 2019 11:58:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBwFAn015589 for ; Wed, 14 Aug 2019 07:58:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2CBBF348C3; Wed, 14 Aug 2019 11:58:15 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD39E34940 for ; Wed, 14 Aug 2019 11:58:13 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:40 +0200 Message-Id: <8d185c23bd61b1711d084c3a54125ff3f52a1c3b.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/18] virpcimock: Store PCI address as ints not string 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 14 Aug 2019 11:58:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In upcoming patches we will need only some portions of the PCI address. To construct that easily, it's better if the PCI address of a device is stored as four integers rather than one string. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 76 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index de365cdb78..c10764dcdd 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -118,8 +118,16 @@ struct pciDriver { unsigned int fail; /* Bitwise-OR of driverActions that should fail */ }; =20 +struct pciDeviceAddress { + unsigned int domain; + unsigned int bus; + unsigned int device; + unsigned int function; +}; +# define ADDR_STR_FMT "%04x:%02x:%02x.%d" + struct pciDevice { - const char *id; + struct pciDeviceAddress addr; int vendor; int device; int klass; @@ -145,7 +153,7 @@ static void init_env(void); =20 static int pci_device_autobind(struct pciDevice *dev); static void pci_device_new_from_stub(const struct pciDevice *data); -static struct pciDevice *pci_device_find_by_id(const char *id); +static struct pciDevice *pci_device_find_by_id(struct pciDeviceAddress con= st *addr); static struct pciDevice *pci_device_find_by_content(const char *path); =20 static void pci_driver_new(const char *name, int fail, ...); @@ -337,6 +345,29 @@ remove_fd(int fd) /* * PCI Device functions */ +static char * +pci_address_format(struct pciDeviceAddress const *addr) +{ + char *ret; + + ignore_value(virAsprintfQuiet(&ret, ADDR_STR_FMT, + addr->domain, addr->bus, + addr->device, addr->function)); + return ret; +} + +static int +pci_address_parse(struct pciDeviceAddress *addr, + const char *buf) +{ + if (sscanf(buf, ADDR_STR_FMT, + &addr->domain, &addr->bus, + &addr->device, &addr->function) !=3D 4) + return -1; + return 0; +} + + static char * pci_device_get_path(const struct pciDevice *dev, const char *file, @@ -344,16 +375,20 @@ pci_device_get_path(const struct pciDevice *dev, { char *ret =3D NULL; const char *prefix =3D ""; + VIR_AUTOFREE(char *) devid =3D NULL; =20 if (faked) prefix =3D fakerootdir; =20 + if (!(devid =3D pci_address_format(&dev->addr))) + return NULL; + if (file) { ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "devices= /%s/%s", - prefix, dev->id, file)); + prefix, devid, file)); } else { ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "devices= /%s", - prefix, dev->id)); + prefix, devid)); } =20 return ret; @@ -366,13 +401,15 @@ pci_device_new_from_stub(const struct pciDevice *data) struct pciDevice *dev; VIR_AUTOFREE(char *) devpath =3D NULL; VIR_AUTOFREE(char *) id =3D NULL; + VIR_AUTOFREE(char *) devid =3D NULL; char *c; VIR_AUTOFREE(char *) configSrc =3D NULL; char tmp[256]; struct stat sb; bool configSrcExists =3D false; =20 - if (VIR_STRDUP_QUIET(id, data->id) < 0) + if (!(devid =3D pci_address_format(&data->addr)) || + VIR_STRDUP_QUIET(id, devid) < 0) ABORT_OOM(); =20 /* Replace ':' with '-' to create the config filename from the @@ -452,20 +489,20 @@ pci_device_new_from_stub(const struct pciDevice *data) make_symlink(devpath, "iommu_group", tmp); =20 if (pci_device_autobind(dev) < 0) - ABORT("Unable to bind: %s", data->id); + ABORT("Unable to bind: %s", devid); =20 if (VIR_APPEND_ELEMENT_QUIET(pciDevices, nPCIDevices, dev) < 0) ABORT_OOM(); } =20 static struct pciDevice * -pci_device_find_by_id(const char *id) +pci_device_find_by_id(struct pciDeviceAddress const *addr) { size_t i; for (i =3D 0; i < nPCIDevices; i++) { struct pciDevice *dev =3D pciDevices[i]; =20 - if (STREQ(dev->id, id)) + if (!memcmp(&dev->addr, addr, sizeof(*addr))) return dev; } =20 @@ -476,11 +513,13 @@ static struct pciDevice * pci_device_find_by_content(const char *path) { char tmp[32]; + struct pciDeviceAddress addr; =20 - if (pci_read_file(path, tmp, sizeof(tmp), true) < 0) + if (pci_read_file(path, tmp, sizeof(tmp), true) < 0 || + pci_address_parse(&addr, tmp) < 0) return NULL; =20 - return pci_device_find_by_id(tmp); + return pci_device_find_by_id(&addr); } =20 static int @@ -607,6 +646,7 @@ pci_driver_find_by_path(const char *path) static struct pciDriver * pci_driver_find_by_driver_override(struct pciDevice *dev) { + VIR_AUTOFREE(char *) devid =3D NULL; VIR_AUTOFREE(char *) path =3D NULL; char tmp[32]; size_t i; @@ -631,6 +671,7 @@ static int pci_driver_bind(struct pciDriver *driver, struct pciDevice *dev) { + VIR_AUTOFREE(char *) devid =3D NULL; VIR_AUTOFREE(char *) devpath =3D NULL; VIR_AUTOFREE(char *) driverpath =3D NULL; =20 @@ -653,8 +694,9 @@ pci_driver_bind(struct pciDriver *driver, /* Make symlink under driver tree */ VIR_FREE(devpath); VIR_FREE(driverpath); - if (!(devpath =3D pci_device_get_path(dev, NULL, true)) || - !(driverpath =3D pci_driver_get_path(driver, dev->id, true))) { + if (!(devid =3D pci_address_format(&dev->addr)) || + !(devpath =3D pci_device_get_path(dev, NULL, true)) || + !(driverpath =3D pci_driver_get_path(driver, devid, true))) { errno =3D ENOMEM; return -1; } @@ -670,6 +712,7 @@ static int pci_driver_unbind(struct pciDriver *driver, struct pciDevice *dev) { + VIR_AUTOFREE(char *) devid =3D NULL; VIR_AUTOFREE(char *) devpath =3D NULL; VIR_AUTOFREE(char *) driverpath =3D NULL; =20 @@ -680,8 +723,9 @@ pci_driver_unbind(struct pciDriver *driver, } =20 /* Make symlink under device tree */ - if (!(devpath =3D pci_device_get_path(dev, "driver", true)) || - !(driverpath =3D pci_driver_get_path(driver, dev->id, true))) { + if (!(devid =3D pci_address_format(&dev->addr)) || + !(devpath =3D pci_device_get_path(dev, "driver", true)) || + !(driverpath =3D pci_driver_get_path(driver, devid, true))) { errno =3D ENOMEM; return -1; } @@ -913,8 +957,10 @@ init_env(void) =20 # define MAKE_PCI_DEVICE(Id, Vendor, Device, ...) \ do { \ - struct pciDevice dev =3D {.id =3D Id, .vendor =3D Vendor, \ + struct pciDevice dev =3D {.vendor =3D Vendor, \ .device =3D Device, __VA_ARGS__}; \ + if (pci_address_parse(&dev.addr, Id) < 0) \ + ABORT("Unable to parse PCI address " Id); \ pci_device_new_from_stub(&dev); \ } while (0) =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783908; cv=none; d=zoho.com; s=zohoarc; b=iGCVpo99MiZA5cCNf1qeXOayHPp7XEqvg51aPf3qgkwXAScrruWGQwea52uKCw1rlmpWNcN8WYCb7Cc22MmXvPu6MtEZMjt66tNudUyXgQ43VE0YAiZG6ggE5GLQSuOcJNiVJvPNSf/csxubN18OIc174SVMVg7esqSNug5FBf8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783908; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=KnKbVLo/iIFkNIxhv87zZv5eZ8fhoG/Edu1T50XDHRI=; b=RiLB3YvciGeQiYtUIuF3/SXTTClSwZP0D0rk9sUO3XdE9WDeohPEi+zyaxWFvoFqGjpKHQttI1Jr6QfwCdyisvZzsCp05dNnRitWqR8R+PGjUwJ3vFPPoJ4u+vUx7jag4r9cPP3PtrG3CoPdyXuwkyxMk0W5KIIZEPOGL41tpLk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783908414183.65059333155727; Wed, 14 Aug 2019 04:58:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 534BE30607E1; Wed, 14 Aug 2019 11:58:27 +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 2727F81C17; Wed, 14 Aug 2019 11:58:27 +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 E1F2C1806134; Wed, 14 Aug 2019 11:58:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBwHAU015600 for ; Wed, 14 Aug 2019 07:58:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id A0901348C3; Wed, 14 Aug 2019 11:58:17 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B09134940 for ; Wed, 14 Aug 2019 11:58:15 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:41 +0200 Message-Id: <14233cd614f83451207744a1f04d244d4d2ac17d.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/18] virpcimock: Create PCI devices under /sys/devices/pci* 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 14 Aug 2019 11:58:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" So far, we are creating devices directly under /sys/bus/pci/devices/*. There is not much problem with it, but if we really want to model kernel behaviour we need to create them under /sys/devices/pciDDDD:BB and then only symlink them from the old location. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index c10764dcdd..0774bf62d9 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -383,12 +383,17 @@ pci_device_get_path(const struct pciDevice *dev, if (!(devid =3D pci_address_format(&dev->addr))) return NULL; =20 + /* PCI devices really do live under /sys/devices/pciDDDD:BB + * and then they are just symlinked to /sys/bus/pci/devices/ + */ if (file) { - ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "devices= /%s/%s", - prefix, devid, file)); + ignore_value(virAsprintfQuiet(&ret, "%s/sys/devices/pci%04x:%02x/%= s/%s", + prefix, dev->addr.domain, dev->addr.= bus, + devid, file)); } else { - ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "devices= /%s", - prefix, devid)); + ignore_value(virAsprintfQuiet(&ret, "%s/sys/devices/pci%04x:%02x/%= s", + prefix, dev->addr.domain, dev->addr.= bus, + devid)); } =20 return ret; @@ -400,6 +405,7 @@ pci_device_new_from_stub(const struct pciDevice *data) { struct pciDevice *dev; VIR_AUTOFREE(char *) devpath =3D NULL; + VIR_AUTOFREE(char *) devsympath =3D NULL; VIR_AUTOFREE(char *) id =3D NULL; VIR_AUTOFREE(char *) devid =3D NULL; char *c; @@ -488,6 +494,17 @@ pci_device_new_from_stub(const struct pciDevice *data) } make_symlink(devpath, "iommu_group", tmp); =20 + if (snprintf(tmp, sizeof(tmp), + "../../../devices/pci%04x:%02x/%s", + dev->addr.domain, dev->addr.bus, devid) < 0) { + ABORT("@tmp overflow"); + } + + if (virAsprintfQuiet(&devsympath, "%s" SYSFS_PCI_PREFIX "devices", fak= erootdir) < 0) + ABORT_OOM(); + + make_symlink(devsympath, devid, tmp); + if (pci_device_autobind(dev) < 0) ABORT("Unable to bind: %s", devid); =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783911; cv=none; d=zoho.com; s=zohoarc; b=LSfnyk9YwVu7kpnbrsBq+1pE1sbOXIOtImliEI9IVsBGiGF/nsc4neACo5IaPifbcMExSeSi95p2IbAV5Xb/2SwcUlPKc9+3l/Sf8hoEg5oimHbVG0+z/SRyuW0NHa4kbYlQAznEtRbLFZeg8wLJvmoOj0Cu89BDbmzij7gXjuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783911; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=gbabJzIjsOF7wb+kzYBEKDHz/ovv2m+bZE98lXqxESw=; b=SBcm8CY6TY+f4TqO9BeqHrng1R/OZy6q32zSswcSfJBRi8lhxoKFnyqEexagWi/2BIIq0rutlo+5Eluz4knhgEV/yXXWfOxPo9IqV4SL/DQsgrWOL7fzC+CNuG6gz7FodaVr9b/9LobOJCjjm+wF5NqEFFzVQcc3Q+dxvIf2j+g= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15657839118691020.3145563728309; Wed, 14 Aug 2019 04:58:31 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B057FC009DE1; Wed, 14 Aug 2019 11:58:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7616A5D9CC; Wed, 14 Aug 2019 11:58:30 +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 3556024F37; Wed, 14 Aug 2019 11:58:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBwIEw015605 for ; Wed, 14 Aug 2019 07:58:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6C80834D27; Wed, 14 Aug 2019 11:58:18 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC3D9349D3 for ; Wed, 14 Aug 2019 11:58:17 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:42 +0200 Message-Id: <090dcf52b29ae97d0bc77a1569a7522b69d6e736.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/18] virpcimock: Create symlink in /sys/kernel/iommu_groups/N/devices dir 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 14 Aug 2019 11:58:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" So far, we don't need to create anything under /sys/kernel/iommu_groups/N/devices directory (which is symlinked from /sys/bus/pci/devices/DDDD:BB:DD.F/iommu_group directory) because virhostdevtest still tests the old KVM assignment and thus has no notion of IOMMU groups. This will change in near future though. And in order to discover devices belonging to the same IOMMU group we need to do what kernel does - create symlinks to devices. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcimock.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 0774bf62d9..6f315217e2 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -400,6 +400,30 @@ pci_device_get_path(const struct pciDevice *dev, } =20 =20 +static void +pci_device_create_iommu(const struct pciDevice *dev, + const char *devid) +{ + VIR_AUTOFREE(char *) iommuPath =3D NULL; + char tmp[256]; + + if (virAsprintfQuiet(&iommuPath, "%s/sys/kernel/iommu_groups/%d/device= s/", + fakerootdir, dev->iommuGroup) < 0) + ABORT_OOM(); + + if (virFileMakePath(iommuPath) < 0) + ABORT("Unable to create: %s", iommuPath); + + if (snprintf(tmp, sizeof(tmp), + "../../../../devices/pci%04x:%02x/%s", + dev->addr.domain, dev->addr.bus, devid) < 0) { + ABORT("@tmp overflow"); + } + + make_symlink(iommuPath, devid, tmp); +} + + static void pci_device_new_from_stub(const struct pciDevice *data) { @@ -480,13 +504,7 @@ pci_device_new_from_stub(const struct pciDevice *data) =20 make_file(devpath, "driver_override", NULL, -1); =20 - if (snprintf(tmp, sizeof(tmp), - "%s/../../../kernel/iommu_groups/%d", - devpath, dev->iommuGroup) < 0) { - ABORT("@tmp overflow"); - } - if (virFileMakePath(tmp) < 0) - ABORT("Unable to create %s", tmp); + pci_device_create_iommu(dev, devid); =20 if (snprintf(tmp, sizeof(tmp), "../../../kernel/iommu_groups/%d", dev->iommuGroup) < 0) { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783915; cv=none; d=zoho.com; s=zohoarc; b=mSJmORqlj/Z6YX+MzJiPR7NxttlPib1Aigl7UTsdGeCUqCPcaLUk3xOD3lt4U2NbywF8a+kNugSOt1YXOkKLI654SpoEMYn2DV0ZDG1rgFMlyQfd6rKk08h4R+bhPmxeCd3UzWHuo1a8f3JTvU69lsJqo4gkO0chaMxdjtq89XQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783915; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=XyawkR6iod76s9537fCg0c8RDZ8QSj6bUXkbLdZuX7Q=; b=E8nNgTHRtRLXweBXN01L4Bs/+Zu+FmWC6MkduL0+dGN2TLc34q/D2295ym5kzsnG4/n1kfqBfokNHJ/LpV3wKhPEFZ+zDnfqBRcahuetG+fMC7jBp+USnm6jyqeEkGo9SwtSB8BFOyooLExSxxl0FIEbCebUdyEnZuWaIr6+UGo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783915301839.3871243107394; Wed, 14 Aug 2019 04:58:35 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1CEF930A5A61; Wed, 14 Aug 2019 11:58:34 +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 E8D76891AE; Wed, 14 Aug 2019 11:58:33 +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 A859E180B536; Wed, 14 Aug 2019 11:58:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBwJBs015610 for ; Wed, 14 Aug 2019 07:58:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3A5FE34913; Wed, 14 Aug 2019 11:58:19 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8B7B348C3 for ; Wed, 14 Aug 2019 11:58:18 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:43 +0200 Message-Id: <23af363b9ea0f8cd6bab0fb92927e3cc8db0068c.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/18] virhostdev: Check driver name too in virHostdevIsPCINodeDeviceUsed() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 14 Aug 2019 11:58:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" It may happen that there are two domains with the same name in two separate drivers (e.g. qemu and lxc). That is why for PCI devices we track both names of driver and domain combination which has taken the device. However, when we check if given PCI device is in use (or PCI devices from the same IOMMU group) we compare only domain name. This means that we can mistakenly claim device as free to use while in fact it isn't. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- src/util/virhostdev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 75e44b5227..cb69582c21 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -51,6 +51,7 @@ static virHostdevManagerPtr virHostdevManagerNew(void); =20 struct virHostdevIsPCINodeDeviceUsedData { virHostdevManagerPtr mgr; + const char *driverName; const char *domainName; const bool usesVFIO; }; @@ -91,8 +92,8 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddr= essPtr devAddr, void *o virPCIDeviceGetUsedBy(actual, &actual_drvname, &actual_domname); =20 if (helperData->usesVFIO && - (actual_domname && helperData->domainName) && - (STREQ(actual_domname, helperData->domainName))) + STREQ_NULLABLE(actual_drvname, helperData->driverName) && + STREQ_NULLABLE(actual_domname, helperData->domainName)) goto iommu_owner; =20 if (actual_drvname && actual_domname) @@ -706,7 +707,7 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, virPCIDevicePtr pci =3D virPCIDeviceListGet(pcidevs, i); bool strict_acs_check =3D !!(flags & VIR_HOSTDEV_STRICT_ACS_CHECK); bool usesVFIO =3D (virPCIDeviceGetStubDriver(pci) =3D=3D VIR_PCI_S= TUB_DRIVER_VFIO); - struct virHostdevIsPCINodeDeviceUsedData data =3D { mgr, dom_name,= usesVFIO }; + struct virHostdevIsPCINodeDeviceUsedData data =3D {mgr, drv_name, = dom_name, usesVFIO}; int hdrType =3D -1; =20 if (virPCIGetHeaderType(pci, &hdrType) < 0) @@ -1995,7 +1996,7 @@ int virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr, virPCIDevicePtr pci) { - struct virHostdevIsPCINodeDeviceUsedData data =3D { mgr, NULL, false }; + struct virHostdevIsPCINodeDeviceUsedData data =3D {mgr, NULL, NULL, fa= lse}; int ret =3D -1; =20 virObjectLock(mgr->activePCIHostdevs); @@ -2021,7 +2022,7 @@ int virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr mgr, virPCIDevicePtr pci) { - struct virHostdevIsPCINodeDeviceUsedData data =3D { mgr, NULL, false }; + struct virHostdevIsPCINodeDeviceUsedData data =3D {mgr, NULL, NULL, fa= lse}; int ret =3D -1; =20 virObjectLock(mgr->activePCIHostdevs); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783903; cv=none; d=zoho.com; s=zohoarc; b=IJ0tnJ0wsnwqQYHz5d/QtvBe/2iv8EkUD08MKZgk+FQeJyesyl64+C+5OOj0LBGbl3m7XfihaYpIL4zLZLxHC/1MUYs+frHNnKI8n56a9+q+zC7J0emK1zuB3em6gRXLmsaCCAsWVNF7xuKNHuUj5WNL73roENMZi0Maaq1kqHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783903; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=INqla4DOa9Lm1dB6iiibb4V+UxmlpjBI3uA1G83vS2k=; b=OspYFMERSak9tI9EUZEP73Mju50O0YXYHjT9Y3VyqUAqRui/z86yLZ2OZoJyGicpX3M62x14+pAwVPZwD4uyvf2XzAyOf1CmMPzor0OynYsjdClprW8aqNDIP53xbH9qADMUYpe+U0WZfCqTH49XFAWmGyQFz/V7K+Bf7eL2PP8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783903926293.9042551316254; Wed, 14 Aug 2019 04:58:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75D834FCD6; Wed, 14 Aug 2019 11:58:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F5A683094; Wed, 14 Aug 2019 11:58:22 +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 043EB24F35; Wed, 14 Aug 2019 11:58:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBwKx8015623 for ; Wed, 14 Aug 2019 07:58:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 057DB34D2F; Wed, 14 Aug 2019 11:58:20 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84BCA348C3 for ; Wed, 14 Aug 2019 11:58:19 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:44 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 15/18] virhostdev: Unify virHostdevPreparePCIDevices behaviour for KVM and VFIO cases 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 14 Aug 2019 11:58:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The virHostdevPreparePCIDevices() function works in several steps. In the very first one, it checks if devices we want to detach from the host are not taken already by some other domain. However, this piece of code returns different results depending on the stub driver used (which is not wrong per se, but keep on reading). If the stub driver is KVM then virHostdevIsPCINodeDeviceUsed() is called which basically checks if a PCI device from the detach list is not used by any domain (including the one we are preparing the device for). If that is the case, an error is reported ("device in use") and -1 is returned. However, that is not what happens if the stub driver is VFIO. If the stub driver is VFIO, then we iterate over all PCI devices from the same IOMMU group and check if they are taken by some other domain (because a PCI device, well IOMMU group, can't be shared between two or more qemu processes). But we fail to check, if the device we are trying to detach from the host is not already taken by a domain. That is, calling virHostdevPreparePCIDevices() over a hostdev device twice succeeds the first time and fails too late in the second run (fortunately, virHostdevResetAllPCIDevices() will throw an error, but this is already too late because the PCI device in question was moved to the list of inactive PCI devices and now it appears in both lists). Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- src/util/virhostdev.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index cb69582c21..6861b8a84e 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -53,7 +53,7 @@ struct virHostdevIsPCINodeDeviceUsedData { virHostdevManagerPtr mgr; const char *driverName; const char *domainName; - const bool usesVFIO; + bool usesVFIO; }; =20 /* This module makes heavy use of bookkeeping lists contained inside a @@ -707,7 +707,7 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, virPCIDevicePtr pci =3D virPCIDeviceListGet(pcidevs, i); bool strict_acs_check =3D !!(flags & VIR_HOSTDEV_STRICT_ACS_CHECK); bool usesVFIO =3D (virPCIDeviceGetStubDriver(pci) =3D=3D VIR_PCI_S= TUB_DRIVER_VFIO); - struct virHostdevIsPCINodeDeviceUsedData data =3D {mgr, drv_name, = dom_name, usesVFIO}; + struct virHostdevIsPCINodeDeviceUsedData data =3D {mgr, drv_name, = dom_name, false}; int hdrType =3D -1; =20 if (virPCIGetHeaderType(pci, &hdrType) < 0) @@ -728,18 +728,19 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, } =20 /* The device is in use by other active domain if - * the dev is in list activePCIHostdevs. VFIO devices - * belonging to same iommu group can't be shared - * across guests. - */ + * the dev is in list activePCIHostdevs. */ devAddr =3D virPCIDeviceGetAddress(pci); + if (virHostdevIsPCINodeDeviceUsed(devAddr, &data)) + goto cleanup; + + /* VFIO devices belonging to same IOMMU group can't be + * shared across guests. Check if that's the case. */ if (usesVFIO) { + data.usesVFIO =3D true; if (virPCIDeviceAddressIOMMUGroupIterate(devAddr, virHostdevIsPCINodeDe= viceUsed, &data) < 0) goto cleanup; - } else if (virHostdevIsPCINodeDeviceUsed(devAddr, &data)) { - goto cleanup; } } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783919; cv=none; d=zoho.com; s=zohoarc; b=L51L5uby2u81NP3wK6vUQhEVr0t8Nqbq8uKgU+evg1O0dPa4h/abN9zM7Ir00GFmwGxF2IIy5sZVMtW5Pq/7W4Zob5ArVFnXewcYf+WYNI7Ff23uB3ccRlFg161qsdx55UbWMLcZhoa5SphLPwVgOfNhgH2DoehqpMRwlOY6Zeo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783919; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=GtDpudlIYNiqXm8Rx7mQXGxrWZmpt91naLfmtwD52y8=; b=CzDBQhRa9VyZGFgbwRIyeQvKGoqxN5F8J1Ee9KRjAZXK8UKjXC784zn/pwlcu2OYi6Ub4TjctRW+Ax9RSEVF6w5/oBS0U5ObPKQH6LoCEAD87D750i6lEQ0Fa2CX6pdGnE3M1EbsDDcY1l1y3K+DWCN55T5h6nEfJIAIl6KsmNs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783919613694.2931602006948; Wed, 14 Aug 2019 04:58:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 88A12C08E284; Wed, 14 Aug 2019 11:58:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 60F3A34D3B; Wed, 14 Aug 2019 11:58:37 +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 273DF24F3A; Wed, 14 Aug 2019 11:58:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBwKjC015633 for ; Wed, 14 Aug 2019 07:58:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id C683B34940; Wed, 14 Aug 2019 11:58:20 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5153034913 for ; Wed, 14 Aug 2019 11:58:20 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:45 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 16/18] qemuxml2argvtest: Switch to modern vfio backend 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 14 Aug 2019 11:58:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The pci-assign device is so old school that no one uses it. All modern systems have adapted VFIO. Switch our xml2argv test too. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- .../hostdev-pci-address-device.args | 2 +- tests/qemuxml2argvdata/hostdev-pci-address.args | 2 +- tests/qemuxml2argvdata/net-hostdev-bootorder.args | 3 +-- .../qemuxml2argvdata/net-hostdev-multidomain.args | 2 +- tests/qemuxml2argvdata/net-hostdev.args | 2 +- tests/qemuxml2argvdata/pci-rom.args | 4 ++-- tests/qemuxml2argvtest.c | 14 +++++++------- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/qemuxml2argvdata/hostdev-pci-address-device.args b/tests= /qemuxml2argvdata/hostdev-pci-address-device.args index 5159b00ef1..79654f44bb 100644 --- a/tests/qemuxml2argvdata/hostdev-pci-address-device.args +++ b/tests/qemuxml2argvdata/hostdev-pci-address-device.args @@ -27,5 +27,5 @@ server,nowait \ -usb \ -drive file=3D/dev/HostVG/QEMUGuest2,format=3Draw,if=3Dnone,id=3Ddrive-ide= 0-0-0 \ -device ide-hd,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-0,b= ootindex=3D1 \ --device pci-assign,host=3D0000:06:12.5,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x= 3 \ +-device vfio-pci,host=3D0000:06:12.5,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x3 \ -device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x4 diff --git a/tests/qemuxml2argvdata/hostdev-pci-address.args b/tests/qemuxm= l2argvdata/hostdev-pci-address.args index fe6acaaf62..0a57a8f29e 100644 --- a/tests/qemuxml2argvdata/hostdev-pci-address.args +++ b/tests/qemuxml2argvdata/hostdev-pci-address.args @@ -27,4 +27,4 @@ server,nowait \ -usb \ -drive file=3D/dev/HostVG/QEMUGuest2,format=3Draw,if=3Dnone,id=3Ddrive-ide= 0-0-0 \ -device ide-hd,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-0,b= ootindex=3D1 \ --device pci-assign,host=3D0000:06:12.5,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x3 +-device vfio-pci,host=3D0000:06:12.5,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x3 diff --git a/tests/qemuxml2argvdata/net-hostdev-bootorder.args b/tests/qemu= xml2argvdata/net-hostdev-bootorder.args index eefc247eed..515b0c58d3 100644 --- a/tests/qemuxml2argvdata/net-hostdev-bootorder.args +++ b/tests/qemuxml2argvdata/net-hostdev-bootorder.args @@ -27,5 +27,4 @@ server,nowait \ -usb \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Draw,if=3Dnone,id=3Ddrive-ide= 0-0-0 \ -device ide-hd,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-0,b= ootindex=3D2 \ --device pci-assign,host=3D0000:03:07.1,id=3Dhostdev0,bootindex=3D1,bus=3Dp= ci.0,\ -addr=3D0x3 +-device vfio-pci,host=3D0000:03:07.1,id=3Dhostdev0,bootindex=3D1,bus=3Dpci= .0,addr=3D0x3 diff --git a/tests/qemuxml2argvdata/net-hostdev-multidomain.args b/tests/qe= muxml2argvdata/net-hostdev-multidomain.args index bf7686f49c..18c5e98188 100644 --- a/tests/qemuxml2argvdata/net-hostdev-multidomain.args +++ b/tests/qemuxml2argvdata/net-hostdev-multidomain.args @@ -27,5 +27,5 @@ server,nowait \ -usb \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Draw,if=3Dnone,id=3Ddrive-ide= 0-0-0 \ -device ide-hd,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-0,b= ootindex=3D1 \ --device pci-assign,host=3D2424:21:1c.6,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x= 3 \ +-device vfio-pci,host=3D2424:21:1c.6,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x3 \ -device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x4 diff --git a/tests/qemuxml2argvdata/net-hostdev.args b/tests/qemuxml2argvda= ta/net-hostdev.args index 94eac176f3..aa9e91db82 100644 --- a/tests/qemuxml2argvdata/net-hostdev.args +++ b/tests/qemuxml2argvdata/net-hostdev.args @@ -27,5 +27,5 @@ server,nowait \ -usb \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Draw,if=3Dnone,id=3Ddrive-ide= 0-0-0 \ -device ide-hd,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-0,b= ootindex=3D1 \ --device pci-assign,host=3D0000:03:07.1,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x= 3 \ +-device vfio-pci,host=3D0000:03:07.1,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x3 \ -device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x4 diff --git a/tests/qemuxml2argvdata/pci-rom.args b/tests/qemuxml2argvdata/p= ci-rom.args index 7235642ee8..4a5dc4161a 100644 --- a/tests/qemuxml2argvdata/pci-rom.args +++ b/tests/qemuxml2argvdata/pci-rom.args @@ -33,7 +33,7 @@ addr=3D0x3,rombar=3D1 \ -netdev user,id=3Dhostnet1 \ -device virtio-net-pci,netdev=3Dhostnet1,id=3Dnet1,mac=3D52:54:00:24:a5:9e= ,bus=3Dpci.0,\ addr=3D0x4,romfile=3D/etc/fake/bootrom.bin \ --device pci-assign,host=3D0000:06:12.5,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x= 5,rombar=3D0 \ --device pci-assign,host=3D0000:06:12.6,id=3Dhostdev1,bus=3Dpci.0,addr=3D0x= 6,rombar=3D1,\ +-device vfio-pci,host=3D0000:06:12.5,id=3Dhostdev0,bus=3Dpci.0,addr=3D0x5,= rombar=3D0 \ +-device vfio-pci,host=3D0000:06:12.6,id=3Dhostdev1,bus=3Dpci.0,addr=3D0x6,= rombar=3D1,\ romfile=3D/etc/fake/bootrom.bin \ -device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x7 diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index c166fd18d6..26b512d246 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -496,7 +496,7 @@ testCompareXMLToArgv(const void *data) if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_T= YPE_PCI && hostdev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV= _PCI_BACKEND_DEFAULT) { - hostdev->source.subsys.u.pci.backend =3D VIR_DOMAIN_HOSTDEV_PC= I_BACKEND_KVM; + hostdev->source.subsys.u.pci.backend =3D VIR_DOMAIN_HOSTDEV_PC= I_BACKEND_VFIO; } } =20 @@ -1303,9 +1303,9 @@ mymain(void) DO_TEST("net-many-models", NONE); DO_TEST("net-mcast", NONE); DO_TEST("net-udp", NONE); - DO_TEST("net-hostdev", NONE); - DO_TEST("net-hostdev-bootorder", NONE); - DO_TEST("net-hostdev-multidomain", NONE); + DO_TEST("net-hostdev", QEMU_CAPS_DEVICE_VFIO_PCI); + DO_TEST("net-hostdev-bootorder", QEMU_CAPS_DEVICE_VFIO_PCI); + DO_TEST("net-hostdev-multidomain", QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("net-hostdev-vfio", QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("net-hostdev-vfio-multidomain", @@ -1576,8 +1576,8 @@ mymain(void) DO_TEST("hostdev-usb-address", NONE); DO_TEST("hostdev-usb-address-device", NONE); DO_TEST("hostdev-usb-address-device-boot", NONE); - DO_TEST("hostdev-pci-address", NONE); - DO_TEST("hostdev-pci-address-device", NONE); + DO_TEST("hostdev-pci-address", QEMU_CAPS_DEVICE_VFIO_PCI); + DO_TEST("hostdev-pci-address-device", QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("hostdev-vfio", QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("hostdev-vfio-multidomain", @@ -1613,7 +1613,7 @@ mymain(void) QEMU_CAPS_DEVICE_ZPCI); DO_TEST_PARSE_ERROR("hostdev-vfio-zpci", QEMU_CAPS_DEVICE_VFIO_PCI); - DO_TEST("pci-rom", NONE); + DO_TEST("pci-rom", QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("pci-rom-disabled", NONE); DO_TEST("pci-rom-disabled-invalid", NONE); =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783904; cv=none; d=zoho.com; s=zohoarc; b=PVIhUQcLXG/jGZCB0UGvXUS1q/UPj79F/RSFVXUYsy79vEgxQjj60sBzWXnEl/Snw736JuNEY39vEx6X8dzNcak6uWghviAqM3DQKTBn1Sf31pGEH/V25EpcwpmR6Kb0EnqSnmgg7W8WkDsX+//vGkJnoFpWo7shGdxxV6ePSUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783904; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=5I6d7S4P7WIsZilUzrvXvtJlwY40b1mV+fRYdIIP0RE=; b=gVrd8fjPv06e5lk3+G1brDDcVHPGdTV2xcGClqbV0myEIvf1/AeHHV33BzXu1mh8gRElBgjp3Od5R94q50OxQQ3POPfpm28uqNVTeHOMUya/6LxX0d8AgAwbs8fQgB6WRo/RrXndzuXJaeEKskdI1SjTH/vV5RtPt06/N4Gc9/Y= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783904045901.9802925758493; Wed, 14 Aug 2019 04:58:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C3BB8309BDA0; Wed, 14 Aug 2019 11:58:22 +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 A1C2234D2F; Wed, 14 Aug 2019 11:58:22 +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 67FDC180BA9E; Wed, 14 Aug 2019 11:58:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBwLL3015647 for ; Wed, 14 Aug 2019 07:58:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 932A034D27; Wed, 14 Aug 2019 11:58:21 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E912349D3 for ; Wed, 14 Aug 2019 11:58:20 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:46 +0200 Message-Id: <1143790019ff65b90c815b870c12e65f6bf2fa88.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 17/18] virhostdevtest: Use modern VFIO 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 14 Aug 2019 11:58:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The pci-stub is so old school that no one uses it. All modern systems have adapted VFIO. Switch our virhostdevtest too. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virhostdevtest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 20984f3442..f860426678 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -96,7 +96,7 @@ myInit(void) subsys.u.pci.addr.bus =3D 0; subsys.u.pci.addr.slot =3D i + 1; subsys.u.pci.addr.function =3D 0; - subsys.u.pci.backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM; + subsys.u.pci.backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; hostdevs[i]->source.subsys =3D subsys; } =20 @@ -104,7 +104,7 @@ myInit(void) if (!(dev[i] =3D virPCIDeviceNew(0, 0, i + 1, 0))) goto cleanup; =20 - virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_KVM); + virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); } =20 if (VIR_ALLOC(mgr) < 0) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Feb 8 00:16:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565783906; cv=none; d=zoho.com; s=zohoarc; b=Y5qF5jf1jhjZRa9wu8tIkbRvylOZnL8AnXToCTVPpfUIr+TNat0tSWANG3qzUlsgxv2CAg2aSChnO/EuWjbsi2jP8kDl/JC6zUnQ7dyYDkKkNrOJD3DACQrbupmak9Qq7Zd0YEjy1RZccdutU8iiJmBm7Ch2VPLIV7PiuwPgoBA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565783906; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=thS8+fXPn3aozoUCBDlnpbaU675q4dVX5kxuAe1WtvM=; b=WoboOa1LO71oJwU+O7nykp3kDXr1ITOmNdhr+AoRsBmRJkjahHU+60Uxg+UaJeeLeJq/+Z5blOEON6D8Gespjjo1X/jQ2OKpTMowZdZmu6ZRHDjrMg9x5/jlYPLWhL0uFzcJtJ+QUIfRK3f5ctNvANqO11Y8/LFHn4Txn+CsjxM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565783906928120.8190806515189; Wed, 14 Aug 2019 04:58:26 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id BFA82302C06D; Wed, 14 Aug 2019 11:58:25 +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 9B608891AE; Wed, 14 Aug 2019 11:58:25 +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 5CE11180BAA9; Wed, 14 Aug 2019 11:58:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7EBwMxE015653 for ; Wed, 14 Aug 2019 07:58:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 60074349D3; Wed, 14 Aug 2019 11:58:22 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEEB534D2F for ; Wed, 14 Aug 2019 11:58:21 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 14 Aug 2019 13:57:47 +0200 Message-Id: <1ff2e37f514a28d061f9ea73a3eaf43c86c26e68.1565777704.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 18/18] virpcitest: Use modern VFIO 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 14 Aug 2019 11:58:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The pci-stub is so old school that no one uses it. All modern systems have adapted VFIO. Switch our virpcitest too. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza --- tests/virpcitest.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 9ecd1b7d27..0bd37268ef 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -106,12 +106,12 @@ testVirPCIDeviceDetach(const void *opaque ATTRIBUTE_U= NUSED) if (!(dev[i] =3D virPCIDeviceNew(0, 0, i + 1, 0))) goto cleanup; =20 - virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_KVM); + virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); =20 if (virPCIDeviceDetach(dev[i], activeDevs, inactiveDevs) < 0) goto cleanup; =20 - if (testVirPCIDeviceCheckDriver(dev[i], "pci-stub") < 0) + if (testVirPCIDeviceCheckDriver(dev[i], "vfio-pci") < 0) goto cleanup; =20 CHECK_LIST_COUNT(activeDevs, 0); @@ -147,7 +147,7 @@ testVirPCIDeviceReset(const void *opaque ATTRIBUTE_UNUS= ED) if (!(dev[i] =3D virPCIDeviceNew(0, 0, i + 1, 0))) goto cleanup; =20 - virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_KVM); + virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); =20 if (virPCIDeviceReset(dev[i], activeDevs, inactiveDevs) < 0) goto cleanup; @@ -187,7 +187,7 @@ testVirPCIDeviceReattach(const void *opaque ATTRIBUTE_U= NUSED) CHECK_LIST_COUNT(activeDevs, 0); CHECK_LIST_COUNT(inactiveDevs, i + 1); =20 - virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_KVM); + virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); } =20 CHECK_LIST_COUNT(activeDevs, 0); @@ -245,7 +245,7 @@ testVirPCIDeviceDetachSingle(const void *opaque) if (!dev) goto cleanup; =20 - virPCIDeviceSetStubDriver(dev, VIR_PCI_STUB_DRIVER_KVM); + virPCIDeviceSetStubDriver(dev, VIR_PCI_STUB_DRIVER_VFIO); =20 if (virPCIDeviceDetach(dev, NULL, NULL) < 0) goto cleanup; @@ -405,7 +405,7 @@ mymain(void) /* Detach an unbound device */ DO_TEST_PCI_DRIVER(0, 0x0a, 2, 0, NULL); DO_TEST_PCI(testVirPCIDeviceDetachSingle, 0, 0x0a, 2, 0); - DO_TEST_PCI_DRIVER(0, 0x0a, 2, 0, "pci-stub"); + DO_TEST_PCI_DRIVER(0, 0x0a, 2, 0, "vfio-pci"); =20 /* Reattach an unknown unbound device */ DO_TEST_PCI_DRIVER(0, 0x0a, 3, 0, NULL); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list