diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6b7261b987..93afd79e34 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2924,6 +2924,7 @@ virPCIDeviceAddressIsValid; virPCIDeviceAddressParse; virPCIDeviceCopy; virPCIDeviceDetach; +virPCIDeviceExists; virPCIDeviceFileIterate; virPCIDeviceFree; virPCIDeviceGetAddress; diff --git a/src/util/virpci.c b/src/util/virpci.c index 8147ce11e9..fd2c6525ab 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1448,6 +1448,16 @@ virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr) return str; } +bool +virPCIDeviceExists(const virPCIDeviceAddress *addr) +{ + g_autofree char *devName = virPCIDeviceAddressAsString(addr); + g_autofree char *devPath = g_strdup_printf(PCI_SYSFS "devices/%s/config", + devName); + + return virFileExists(devPath); +} + virPCIDevicePtr virPCIDeviceNew(const virPCIDeviceAddress *address) { diff --git a/src/util/virpci.h b/src/util/virpci.h index 3f609212c7..bb8bd9b561 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -206,6 +206,7 @@ int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDeviceAddressPtr devAddr, size_t *nIommuGroupDevices); int virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr); char *virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDeviceAddress *devAddr); +bool virPCIDeviceExists(const virPCIDeviceAddress *addr); char *virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev); int virPCIDeviceIsAssignable(virPCIDevicePtr dev,