]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Introduce qemuDomainFindSCSIControllerModel
authorJohn Ferlan <jferlan@redhat.com>
Tue, 30 Jan 2018 15:45:43 +0000 (10:45 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 31 Jan 2018 16:32:04 +0000 (11:32 -0500)
Rather than repeat multiple steps in order to find the SCSI
controller model, let's combine them into one helper that will
return either the model from the definition or the default
model based on the capabilities.

This patch adds an extra check/error that the controller
that's being found actually exists. This just clarifies that
the error was because the controller doesn't exist rather
than the more generic error that we were unable to determine
the model from qemuDomainSetSCSIControllerModel when a -1
was passed in and the capabilities were unable to find one.

src/qemu/qemu_alias.c
src/qemu/qemu_command.c
src/qemu/qemu_domain_address.c
src/qemu/qemu_domain_address.h

index ed96f9f4cb6210acd0ef77aa594ab0fb12342f47..ed3af04decc6ac3c4b7145afd6740570785fe191 100644 (file)
@@ -190,14 +190,10 @@ qemuAssignDeviceDiskAlias(virDomainDefPtr def,
 
     if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
         if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
-            virDomainControllerDefPtr cont;
-
-            cont = virDomainDeviceFindSCSIController(def, &disk->info);
-            if (cont)
-                controllerModel = cont->model;
-
-            if ((qemuDomainSetSCSIControllerModel(def, qemuCaps,
-                                                  &controllerModel)) < 0)
+            controllerModel = qemuDomainFindSCSIControllerModel(def,
+                                                                &disk->info,
+                                                                qemuCaps);
+            if (controllerModel < 0)
                 return -1;
         }
 
index 113a2919bdb43f9b71ef1af399fb4bc17c2b5f94..32ff385cf6c7de55a2f301eb3d9dcdb690b3cf69 100644 (file)
@@ -1957,7 +1957,6 @@ qemuBuildDriveDevStr(const virDomainDef *def,
                      virQEMUCapsPtr qemuCaps)
 {
     virBuffer opt = VIR_BUFFER_INITIALIZER;
-    virDomainControllerDefPtr cont;
     const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
     const char *contAlias;
     char *drivealias;
@@ -2043,11 +2042,9 @@ qemuBuildDriveDevStr(const virDomainDef *def,
             goto error;
         }
 
-        cont = virDomainDeviceFindSCSIController(def, &disk->info);
-        if (cont)
-            controllerModel = cont->model;
-        if ((qemuDomainSetSCSIControllerModel(def, qemuCaps,
-                                              &controllerModel)) < 0)
+        controllerModel = qemuDomainFindSCSIControllerModel(def, &disk->info,
+                                                            qemuCaps);
+        if (controllerModel < 0)
             goto error;
 
         if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
@@ -5143,16 +5140,12 @@ qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
                            virQEMUCapsPtr qemuCaps)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
-    virDomainControllerDefPtr cont;
     int model = -1;
     char *driveAlias;
     const char *contAlias;
 
-    cont = virDomainDeviceFindSCSIController(def, dev->info);
-    if (cont)
-        model = cont->model;
-
-    if (qemuDomainSetSCSIControllerModel(def, qemuCaps, &model) < 0)
+    model = qemuDomainFindSCSIControllerModel(def, dev->info, qemuCaps);
+    if (model < 0)
         goto error;
 
     if (model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
index 86fe7ad11b617de6b6c3e71a11cf18ac222624e4..74f7df205c865fb5c403051533a56df18117f848 100644 (file)
@@ -74,6 +74,37 @@ qemuDomainSetSCSIControllerModel(const virDomainDef *def,
 }
 
 
+/**
+ * @def: Domain definition
+ * @info: Domain device info
+ * @qemuCaps: QEMU capabilities
+ *
+ * Using the device info, find the controller related to the
+ * device by index and use that controller to return the model.
+ *
+ * Returns the model if found, -1 if not with an error message set
+ */
+int
+qemuDomainFindSCSIControllerModel(const virDomainDef *def,
+                                  virDomainDeviceInfoPtr info,
+                                  virQEMUCapsPtr qemuCaps)
+{
+    virDomainControllerDefPtr cont;
+    int model;
+
+    if (!(cont = virDomainDeviceFindSCSIController(def, info))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unable to find a SCSI controller for idx=%d"),
+                       info->addr.drive.controller);
+        return -1;
+    }
+
+    model = cont->model;
+    ignore_value(qemuDomainSetSCSIControllerModel(def, qemuCaps, &model));
+    return model;
+}
+
+
 static int
 qemuDomainAssignVirtioSerialAddresses(virDomainDefPtr def)
 {
index e951a4c884901f8fdfe7462bd56217f4fb5ded22..8a43468927f7930d311897cb5ec6ff5e890d585c 100644 (file)
@@ -32,6 +32,10 @@ int qemuDomainSetSCSIControllerModel(const virDomainDef *def,
                                      virQEMUCapsPtr qemuCaps,
                                      int *model);
 
+int qemuDomainFindSCSIControllerModel(const virDomainDef *def,
+                                      virDomainDeviceInfoPtr info,
+                                      virQEMUCapsPtr qemuCaps);
+
 int qemuDomainAssignAddresses(virDomainDefPtr def,
                               virQEMUCapsPtr qemuCaps,
                               virQEMUDriverPtr driver,