diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index a2cb0006f757cdbf26d65fb7fc2aceac6941d80b..48df519734d86cb3738a20651a8867715dc08f48 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -465,6 +465,9 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr, size_t i; int ret = -1; + if (!nhostdevs) + return 0; + virObjectLock(hostdev_mgr->activePCIHostdevs); virObjectLock(hostdev_mgr->inactivePCIHostdevs); @@ -699,6 +702,9 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr hostdev_mgr, virPCIDeviceListPtr pcidevs; size_t i; + if (!nhostdevs) + return; + virObjectLock(hostdev_mgr->activePCIHostdevs); virObjectLock(hostdev_mgr->inactivePCIHostdevs); @@ -786,6 +792,9 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr, size_t i; int ret = -1; + if (!nhostdevs) + return 0; + virObjectLock(mgr->activePCIHostdevs); virObjectLock(mgr->inactivePCIHostdevs); @@ -846,6 +855,9 @@ virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr, size_t i; int ret = -1; + if (!nhostdevs) + return 0; + virObjectLock(mgr->activeUSBHostdevs); for (i = 0; i < nhostdevs; i++) { virUSBDevicePtr usb = NULL; @@ -893,6 +905,9 @@ virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr, virSCSIDevicePtr scsi = NULL; virSCSIDevicePtr tmp = NULL; + if (!nhostdevs) + return 0; + virObjectLock(mgr->activeSCSIHostdevs); for (i = 0; i < nhostdevs; i++) { hostdev = hostdevs[i]; @@ -1091,6 +1106,9 @@ virHostdevPrepareUSBDevices(virHostdevManagerPtr hostdev_mgr, virUSBDevicePtr tmp; bool coldBoot = !!(flags & VIR_HOSTDEV_COLD_BOOT); + if (!nhostdevs) + return 0; + /* To prevent situation where USB device is assigned to two domains * we need to keep a list of currently assigned USB devices. * This is done in several loops which cannot be joined into one big @@ -1160,6 +1178,9 @@ virHostdevPrepareSCSIDevices(virHostdevManagerPtr hostdev_mgr, virSCSIDeviceListPtr list; virSCSIDevicePtr tmp; + if (!nhostdevs) + return 0; + /* To prevent situation where SCSI device is assigned to two domains * we need to keep a list of currently assigned SCSI devices. * This is done in several loops which cannot be joined into one big @@ -1268,6 +1289,9 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr hostdev_mgr, { size_t i; + if (!nhostdevs) + return; + virObjectLock(hostdev_mgr->activeUSBHostdevs); for (i = 0; i < nhostdevs; i++) { virDomainHostdevDefPtr hostdev = hostdevs[i]; @@ -1334,6 +1358,9 @@ virHostdevReAttachSCSIDevices(virHostdevManagerPtr hostdev_mgr, { size_t i; + if (!nhostdevs) + return; + virObjectLock(hostdev_mgr->activeSCSIHostdevs); for (i = 0; i < nhostdevs; i++) { virDomainHostdevDefPtr hostdev = hostdevs[i]; diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index da1367c4c1e2acf1357702b378dd7a938a869646..ade7e2ff2f4d8fe91fb5893d204e5b14751706a0 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -61,80 +61,96 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr, const unsigned char *uuid, virDomainHostdevDefPtr *hostdevs, int nhostdevs, - unsigned int flags); + unsigned int flags) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) + ATTRIBUTE_NONNULL(4); int virHostdevPrepareUSBDevices(virHostdevManagerPtr hostdev_mgr, const char *drv_name, const char *dom_name, virDomainHostdevDefPtr *hostdevs, int nhostdevs, - unsigned int flags); + unsigned int flags) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); int virHostdevPrepareSCSIDevices(virHostdevManagerPtr hostdev_mgr, const char *drv_name, const char *dom_name, virDomainHostdevDefPtr *hostdevs, - int nhostdevs); + int nhostdevs) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); void virHostdevReAttachPCIDevices(virHostdevManagerPtr hostdev_mgr, const char *drv_name, const char *dom_name, virDomainHostdevDefPtr *hostdevs, int nhostdevs, - const char *oldStateDir); + const char *oldStateDir) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); void virHostdevReAttachUSBDevices(virHostdevManagerPtr hostdev_mgr, const char *drv_name, const char *dom_name, virDomainHostdevDefPtr *hostdevs, - int nhostdevs); + int nhostdevs) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); void virHostdevReAttachSCSIDevices(virHostdevManagerPtr hostdev_mgr, const char *drv_name, const char *dom_name, virDomainHostdevDefPtr *hostdevs, - int nhostdevs); + int nhostdevs) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); int virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr, virDomainHostdevDefPtr *hostdevs, int nhostdevs, const char *drv_name, - const char *dom_name); + const char *dom_name) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5); int virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr, virDomainHostdevDefPtr *hostdevs, int nhostdevs, const char *drv_name, - const char *dom_name); + const char *dom_name) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5); int virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr, virDomainHostdevDefPtr *hostdevs, int nhostdevs, const char *drv_name, - const char *dom_name); + const char *dom_name) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5); int virHostdevUpdateDomainActiveDevices(virHostdevManagerPtr mgr, const char *driver, virDomainDefPtr def, - unsigned int flags); + unsigned int flags) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); int virHostdevPrepareDomainDevices(virHostdevManagerPtr mgr, const char *driver, virDomainDefPtr def, - unsigned int flags); + unsigned int flags) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); void virHostdevReAttachDomainDevices(virHostdevManagerPtr mgr, const char *driver, virDomainDefPtr def, unsigned int flags, - const char *oldStateDir); + const char *oldStateDir) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5); /* functions used by NodeDevDetach/Reattach/Reset */ int virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr, - virPCIDevicePtr pci); + virPCIDevicePtr pci) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr mgr, - virPCIDevicePtr pci); + virPCIDevicePtr pci) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int virHostdevPCINodeDeviceReset(virHostdevManagerPtr mgr, - virPCIDevicePtr pci); + virPCIDevicePtr pci) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); #endif /* __VIR_HOSTDEV_H__ */