[PATCH] qemu: Prevent detaching SCSI controller used by hostdev

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Consider a guest started with the following XML snippet:

    <controller type='scsi' model='virtio-scsi' index='0'/>
    <hostdev mode='subsystem' type='scsi'>
      <source>
        <adapter name='scsi_host0'/>
        <address bus='0' target='8' unit='1074151456'/>
      </source>
    </hostdev>

If we attach/create a virtio-scsi hostdev device but forget to include
a virtio-scsi controller, one is silently created for us.  (See
qemuDomainFindOrCreateSCSIDiskController for context.)

Detaching the hostdev, followed by the controller, works well and the
guest behaves appropriately.

If we detach the virtio-scsi controller device first, Libvirt silently
detaches any associated hostdevs for us too.  But all is not well,
as the guest is unable to receive new virtio-scsi devices (the attach
commands succeed, but devices never appear within the guest), nor even
be shutdown, after this point.

It appears that something is tied up in the host virtio layer.
While I investigate this, we can see if a controller is being used by
any hostdevs, and prevent the detach if it would lead us down this path.

  $ virsh detach-device guest_one_virtio_scsi scsicontroller.xml
  error: Failed to detach device from scsicontroller.xml
  error: operation failed: device cannot be detached: device is busy

  $ virsh detach-device guest_one_virtio_scsi scsidisk.xml
  Device detached successfully

  $ virsh detach-device guest_one_virtio_scsi scsicontroller.xml
  Device detached successfully

Signed-off-by: Eric Farman <farman@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Bjoern Walk <bwalk@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxxxxxxx>
---
 src/qemu/qemu_hotplug.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index b03e618..5db7abf 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4443,6 +4443,7 @@ static bool qemuDomainDiskControllerIsBusy(virDomainObjPtr vm,
 {
     size_t i;
     virDomainDiskDefPtr disk;
+    virDomainHostdevDefPtr hostdev;
 
     for (i = 0; i < vm->def->ndisks; i++) {
         disk = vm->def->disks[i];
@@ -4465,6 +4466,15 @@ static bool qemuDomainDiskControllerIsBusy(virDomainObjPtr vm,
             return true;
     }
 
+    for (i = 0; i < vm->def->nhostdevs; i++) {
+        hostdev = vm->def->hostdevs[i];
+        if (!virHostdevIsSCSIDevice(hostdev) ||
+            detach->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI)
+            continue;
+        if (hostdev->info->addr.drive.controller == detach->idx)
+            return true;
+    }
+
     return false;
 }
 
-- 
2.8.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux