From nobody Sat Feb 7 11:05:20 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1609764929; cv=none; d=zohomail.com; s=zohoarc; b=g1GsVWBm95IY6idJdEBihDFace1A2OCb8P3OGeF49jKPj7CNMUrbdYwE8G1ZkRXvq2mGHapWEM6WmeKkKzRGcFESedDEGZzbTHaGZPJf/PNBBtXEx66s6iOBoQv0pPGHF6GrTMZjbneVMbZjMzWi+bMbDYuF/4yEMDHPTSdVkJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764929; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/WM1lQBxI4H1SkZ3Qj2kNpQhU+WgytRtjBNVNmO1zaI=; b=WqL+J28LL3cB2n5kI1GNK5MpdGs4tIO7Ndju0Gy4wlHLJSlRPzyN7SjlOYTbyJCPhtMDbe6rFLv5bx0xhmWycOxf8VUSLz2oPWoX9OEzQh4DgnfvyjskYtbUnWBSTxb1T81iez+ECavhAeH0J4SrEpn0AlnH0tBWJgDQ1HWm03s= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764929187351.18853157599926; Mon, 4 Jan 2021 04:55:29 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-429-bUlW7ecLNq2GAS5K7YHvgA-1; Mon, 04 Jan 2021 07:55:24 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 271CD85C73B; Mon, 4 Jan 2021 12:55:19 +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 051A55D761; Mon, 4 Jan 2021 12:55:19 +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 C3D3A1809CA6; Mon, 4 Jan 2021 12:55:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtBM4014175 for ; Mon, 4 Jan 2021 07:55:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 702FE2166B2B; Mon, 4 Jan 2021 12:55:11 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6AC4C2166B2A for ; Mon, 4 Jan 2021 12:55:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 83A29101A560 for ; Mon, 4 Jan 2021 12:55:08 +0000 (UTC) Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-199-VL9LTp9xMx6lu9UQUCzaJA-1; Mon, 04 Jan 2021 07:55:06 -0500 Received: by mail-qk1-f182.google.com with SMTP id z11so23219280qkj.7 for ; Mon, 04 Jan 2021 04:55:06 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:05 -0800 (PST) X-MC-Unique: bUlW7ecLNq2GAS5K7YHvgA-1 X-MC-Unique: VL9LTp9xMx6lu9UQUCzaJA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/WM1lQBxI4H1SkZ3Qj2kNpQhU+WgytRtjBNVNmO1zaI=; b=b8rJ5ev435Gb1pWzfrxYlgVUHVejdY09ONoifp2Cc5A0EzP7AXUttu9CIEIlpNqgoI Ai9gSN2qIMnwzj1NDI4Gs4vJzSBtxJGRW+NFPr/AuWCDYIjyO8WVD2xL/PFcrE0hKnMd ENE1Z5U2BhicCIi+sCPUC3wf37LaP1DqxFJ5iQ44ftLxWHQlZvuP5AEFd4h5jH1xVuMR yJpeIjGAEJrlT6HbJwOsw9YgJl+tGXwFSPMcuVOkr9NgYeWSVxowR2eD51hFh5arO1od L6UnyS+U2kwbBNevOELsumfLWTMhI56ynjPhKWjqDv5XOYYNR2wEVH9wG/JjbeLykAt7 qfgg== X-Gm-Message-State: AOAM531MLOuWlxkNEP/2j7EEVVcddqggQFcRUab1+FangApRyU41gjR5 /H38k4W/hmz/lRXIX5ik4ECN3tZLL2wDNA== X-Google-Smtp-Source: ABdhPJwCMarq3niIEhvWgUpUzkENJuH/b6XYm4FjSUaJSx0pV0zdeKMB/UKNkZluhPGenVvbREFIMw== X-Received: by 2002:a37:4e50:: with SMTP id c77mr70089099qkb.252.1609764905845; Mon, 04 Jan 2021 04:55:05 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 05/20] virpci: introduce virPCIDeviceExists() Date: Mon, 4 Jan 2021 09:54:29 -0300 Message-Id: <20210104125444.200536-6-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We're going to add logic to handle the case where a previously existing PCI device does not longer exist in the host. The logic was copied from virPCIDeviceNew(), which verifies if a PCI device exists in the host, returning NULL and throwing an error if it doesn't. The NULL is used for other errors as well (product/vendor id read errors, dev id overflow), meaning that we can't re-use virPCIDeviceNew() for the purpose of detecting if the device exists. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/util/virpci.c | 10 ++++++++++ src/util/virpci.h | 1 + 3 files changed, 12 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fe4ee25f3a..81ce142635 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2817,6 +2817,7 @@ virPCIDeviceAddressIsValid; virPCIDeviceAddressParse; virPCIDeviceCopy; virPCIDeviceDetach; +virPCIDeviceExists; virPCIDeviceFileIterate; virPCIDeviceFree; virPCIDeviceGetAddress; diff --git a/src/util/virpci.c b/src/util/virpci.c index 545b2650a0..1a542b18b6 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1448,6 +1448,16 @@ virPCIDeviceAddressAsString(const virPCIDeviceAddres= s *addr) return str; } =20 +bool +virPCIDeviceExists(const virPCIDeviceAddress *addr) +{ + g_autofree char *devName =3D virPCIDeviceAddressAsString(addr); + g_autofree char *devPath =3D g_strdup_printf(PCI_SYSFS "devices/%s/con= fig", + devName); + + return virFileExists(devPath); +} + virPCIDevicePtr virPCIDeviceNew(const virPCIDeviceAddress *address) { diff --git a/src/util/virpci.h b/src/util/virpci.h index d4451848c1..a9c597a428 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -201,6 +201,7 @@ int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDev= iceAddressPtr devAddr, size_t *nIommuGroupDevices); int virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr); char *virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDeviceAddress *devAd= dr); +bool virPCIDeviceExists(const virPCIDeviceAddress *addr); char *virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev); =20 int virPCIDeviceIsAssignable(virPCIDevicePtr dev, --=20 2.26.2