Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx> --- src/libvirt_private.syms | 1 + src/qemu/qemu_hostdev.c | 62 ---------------------------------------------- src/util/virhostdev.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ src/util/virhostdev.h | 6 ++++ 4 files changed, 69 insertions(+), 62 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7da32a0..d657982 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1297,6 +1297,7 @@ virHostdevPreparePCIDevices; virHostdevPrepareSCSIDevices; virHostdevPrepareUSBDevices; virHostdevReAttachPCIDevices; +virHostdevReAttachScsiHostdevs; virHostdevReAttachUsbHostdevs; virHostdevUpdateActivePciHostdevs; virHostdevUpdateActiveScsiHostdevs; diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 7ef9b1b..b8d914a 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -358,68 +358,6 @@ qemuDomainReAttachHostUsbDevices(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, 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 03962d3..83d9916 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1295,3 +1295,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 a07ba27..0a60ec3 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, -- 1.6.0.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list