diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f31a58f0c0ba0b4f4f5ea3ada4a27ae8931e4dc1..d061f2c607838469812d9c8631af1725b4b308aa 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1303,6 +1303,7 @@ virHostdevPreparePCIDevices; virHostdevPrepareSCSIDevices; virHostdevPrepareUSBDevices; virHostdevReAttachPCIDevices; +virHostdevReAttachScsiHostdevs; virHostdevReAttachUsbHostdevs; virHostdevUpdateActivePciHostdevs; virHostdevUpdateActiveScsiHostdevs; diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index b4ab1bda4789071f207d34deed3b337501337bcc..c83b95de09cbc11151067b7fe6ae9e7895239e0d 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -328,68 +328,6 @@ qemuDomainReAttachHostUsbDevices(virQEMUDriverPtr driver, name, hostdevs, nhostdevs); } -static void -virHostdevReAttachScsiHostdevs(virHostdevManagerPtr hostdev_mgr, - const char *drv_name, - const char *name, - virDomainHostdevDefPtr *hostdevs, - int nhostdevs) -{ - size_t i; - - virObjectLock(hostdev_mgr->activeScsiHostdevs); - for (i = 0; i < nhostdevs; i++) { - virDomainHostdevDefPtr hostdev = hostdevs[i]; - virSCSIDevicePtr scsi; - virSCSIDevicePtr tmp; - - if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || - hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) - continue; - - if (!(scsi = virSCSIDeviceNew(NULL, - hostdev->source.subsys.u.scsi.adapter, - hostdev->source.subsys.u.scsi.bus, - hostdev->source.subsys.u.scsi.target, - hostdev->source.subsys.u.scsi.unit, - hostdev->readonly, - hostdev->shareable))) { - VIR_WARN("Unable to reattach SCSI device %s:%d:%d:%d on domain %s", - hostdev->source.subsys.u.scsi.adapter, - hostdev->source.subsys.u.scsi.bus, - hostdev->source.subsys.u.scsi.target, - hostdev->source.subsys.u.scsi.unit, - name); - continue; - } - - /* Only delete the devices which are marked as being used by @name, - * because qemuProcessStart could fail on the half way. */ - - if (!(tmp = virSCSIDeviceListFind(hostdev_mgr->activeScsiHostdevs, scsi))) { - VIR_WARN("Unable to find device %s:%d:%d:%d " - "in list of active SCSI devices", - hostdev->source.subsys.u.scsi.adapter, - hostdev->source.subsys.u.scsi.bus, - hostdev->source.subsys.u.scsi.target, - hostdev->source.subsys.u.scsi.unit); - virSCSIDeviceFree(scsi); - continue; - } - - VIR_DEBUG("Removing %s:%d:%d:%d dom=%s from activeScsiHostdevs", - hostdev->source.subsys.u.scsi.adapter, - hostdev->source.subsys.u.scsi.bus, - hostdev->source.subsys.u.scsi.target, - hostdev->source.subsys.u.scsi.unit, - name); - - virSCSIDeviceListDel(hostdev_mgr->activeScsiHostdevs, tmp, drv_name, name); - virSCSIDeviceFree(scsi); - } - virObjectUnlock(hostdev_mgr->activeScsiHostdevs); -} - void qemuDomainReAttachHostScsiDevices(virQEMUDriverPtr driver, const char *name, diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index d8d6c903ae6425f4d1f5288543b95bb6239d825a..cc1ce07dd39f6b0caedd797016215199c10516b5 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1317,3 +1317,65 @@ virHostdevReAttachUsbHostdevs(virHostdevManagerPtr hostdev_mgr, } virObjectUnlock(hostdev_mgr->activeUsbHostdevs); } + +void +virHostdevReAttachScsiHostdevs(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs) +{ + size_t i; + + virObjectLock(hostdev_mgr->activeScsiHostdevs); + for (i = 0; i < nhostdevs; i++) { + virDomainHostdevDefPtr hostdev = hostdevs[i]; + virSCSIDevicePtr scsi; + virSCSIDevicePtr tmp; + + if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || + hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) + continue; + + if (!(scsi = virSCSIDeviceNew(NULL, + hostdev->source.subsys.u.scsi.adapter, + hostdev->source.subsys.u.scsi.bus, + hostdev->source.subsys.u.scsi.target, + hostdev->source.subsys.u.scsi.unit, + hostdev->readonly, + hostdev->shareable))) { + VIR_WARN("Unable to reattach SCSI device %s:%d:%d:%d on domain %s", + hostdev->source.subsys.u.scsi.adapter, + hostdev->source.subsys.u.scsi.bus, + hostdev->source.subsys.u.scsi.target, + hostdev->source.subsys.u.scsi.unit, + name); + continue; + } + + /* Only delete the devices which are marked as being used by @name, + * because qemuProcessStart could fail on the half way. */ + + if (!(tmp = virSCSIDeviceListFind(hostdev_mgr->activeScsiHostdevs, scsi))) { + VIR_WARN("Unable to find device %s:%d:%d:%d " + "in list of active SCSI devices", + hostdev->source.subsys.u.scsi.adapter, + hostdev->source.subsys.u.scsi.bus, + hostdev->source.subsys.u.scsi.target, + hostdev->source.subsys.u.scsi.unit); + virSCSIDeviceFree(scsi); + continue; + } + + VIR_DEBUG("Removing %s:%d:%d:%d dom=%s from activeScsiHostdevs", + hostdev->source.subsys.u.scsi.adapter, + hostdev->source.subsys.u.scsi.bus, + hostdev->source.subsys.u.scsi.target, + hostdev->source.subsys.u.scsi.unit, + name); + + virSCSIDeviceListDel(hostdev_mgr->activeScsiHostdevs, tmp, drv_name, name); + virSCSIDeviceFree(scsi); + } + virObjectUnlock(hostdev_mgr->activeScsiHostdevs); +} diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 7bd5da1478ad8d4efa73f0f19ea1354cc70f2216..809996c228df1d260de038f08d4cd2d5e6615cab 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -84,6 +84,12 @@ virHostdevReAttachUsbHostdevs(virHostdevManagerPtr hostdev_mgr, const char *name, virDomainHostdevDefPtr *hostdevs, int nhostdevs); +void +virHostdevReAttachScsiHostdevs(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs); int virHostdevUpdateActivePciHostdevs(virHostdevManagerPtr mgr, const char *drv_name,