]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Separate calls based on controller bus type
authorEric Farman <farman@linux.vnet.ibm.com>
Thu, 21 Nov 2013 03:36:26 +0000 (22:36 -0500)
committerJán Tomko <jtomko@redhat.com>
Thu, 21 Nov 2013 09:38:53 +0000 (10:38 +0100)
For systems without a PCI bus, attaching a SCSI controller fails:

  [root@xxxxxxxx ~]# cat controller.xml
  <controller type='scsi' model='virtio-scsi' index='0' />
  [root@xxxxxxxx ~]# virsh attach-device guest01 controller.xml
  error: Failed to attach device from controller.xml
  error: XML error: No PCI buses available

A similar problem occurs with the detach of a controller:

  [root@xxxxxxxx ~]# virsh detach-device guest01 controller.xml
  error: Failed to detach device from controller.xml
  error: operation failed: controller scsi:0 not found

The qemuDomainXXtachPciControllerDevice routines made assumptions
that any caller had a PCI bus.  These routines now selectively calls
PCI functions where necessary, and assigns the device information
type to one appropriate for the bus in use.

Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_hotplug.c

index c81d0f369f1b381d649959c2499c67d053ae6bea..f11d75584426a5e48bf516d1132736803202f65a 100644 (file)
@@ -366,8 +366,23 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
     }
 
     if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
-        if (qemuDomainPCIAddressEnsureAddr(priv->pciaddrs, &controller->info) < 0)
-            goto cleanup;
+        if (controller->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+            if (STRPREFIX(vm->def->os.machine, "s390-ccw") &&
+                virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW))
+                controller->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW;
+            else if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_S390))
+                controller->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390;
+        }
+
+        if (controller->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
+            controller->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+            if (qemuDomainPCIAddressEnsureAddr(priv->pciaddrs, &controller->info) < 0)
+                goto cleanup;
+        } else if (controller->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) {
+            if (qemuDomainCCWAddressAssign(&controller->info, priv->ccwaddrs,
+                                           !controller->info.addr.ccw.assigned) < 0)
+                goto cleanup;
+        }
         releaseaddr = true;
         if (qemuAssignDeviceControllerAlias(controller) < 0)
             goto cleanup;
@@ -399,7 +414,8 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
     qemuDomainObjExitMonitor(driver, vm);
 
     if (ret == 0) {
-        controller->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+        if (controller->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
+            controller->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
         virDomainControllerInsertPreAlloced(vm->def, controller);
     }
 
@@ -3049,14 +3065,24 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver,
 
     detach = vm->def->controllers[idx];
 
-    if (!virDomainDeviceAddressIsValid(&detach->info,
-                                       VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)) {
-        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-                       _("device cannot be detached without a PCI address"));
+    if (detach->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI &&
+        detach->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW &&
+        detach->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390) {
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       _("device with '%s' address cannot be detached"),
+                       virDomainDeviceAddressTypeToString(detach->info.type));
         goto cleanup;
     }
 
-    if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) {
+    if (!virDomainDeviceAddressIsValid(&detach->info, detach->info.type)) {
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       _("device with invalid '%s' address cannot be detached"),
+                       virDomainDeviceAddressTypeToString(detach->info.type));
+        goto cleanup;
+    }
+
+    if (detach->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI &&
+        qemuIsMultiFunctionDevice(vm->def, &detach->info)) {
         virReportError(VIR_ERR_OPERATION_FAILED,
                        _("cannot hot unplug multifunction PCI device: %s"),
                        dev->data.disk->dst);