virhostdev.c: add virHostdevIsPCIDevice() helper

Add a helper to quickly determine if a hostdev is a PCI device,
instead of doing a tedious 'if' check with hostdev mode and
subsys type.

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Daniel Henrique Barboza 2021-01-04 09:54:38 -03:00
parent 953be56eea
commit a8017c6882
3 changed files with 12 additions and 3 deletions

View File

@ -347,12 +347,18 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev,
}
bool
virHostdevIsPCIDevice(const virDomainHostdevDef *hostdev)
{
return hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
}
static bool
virHostdevIsPCINetDevice(const virDomainHostdevDef *hostdev)
{
return hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
hostdev->parentnet != NULL;
return virHostdevIsPCIDevice(hostdev) && hostdev->parentnet != NULL;
}

View File

@ -233,3 +233,5 @@ virHostdevUpdateActiveNVMeDevices(virHostdevManagerPtr hostdev_mgr,
const char *dom_name,
virDomainDiskDefPtr *disks,
size_t ndisks);
bool virHostdevIsPCIDevice(const virDomainHostdevDef *hostdev);

View File

@ -1526,6 +1526,7 @@ virCloseCallbacksUnset;
# hypervisor/virhostdev.h
virHostdevFindUSBDevice;
virHostdevIsPCIDevice;
virHostdevManagerGetDefault;
virHostdevPCINodeDeviceDetach;
virHostdevPCINodeDeviceReAttach;