]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Try controller add when searching hostdev bus for unit
authorJohn Ferlan <jferlan@redhat.com>
Wed, 22 Jul 2015 12:09:23 +0000 (08:09 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 3 Aug 2015 20:48:45 +0000 (16:48 -0400)
If virDomainControllerSCSINextUnit failed to find a slot on the current
VIR_DOMAIN_CONTROLLER_TYPE_SCSI controller(s), try to add a new controller;
otherwise, there may be multiple unit=0 entries for the same "next"
controller.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/conf/domain_conf.c

index a903338d95a6b5268f002bb42277d86d0d3ff012..f0951209d75293162090f1ff0196d4e4b2eea19d 100644 (file)
@@ -3985,7 +3985,7 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr xmlopt,
     int next_unit = 0;
     unsigned controller = 0;
     size_t i;
-    int ret;
+    int ret = -1;
 
     for (i = 0; i < def->ncontrollers; i++) {
         if (def->controllers[i]->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI)
@@ -4004,6 +4004,17 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr xmlopt,
         }
     }
 
+    /* If failed to find any VIR_DOMAIN_CONTROLLER_TYPE_SCSI or any space
+     * on existing VIR_DOMAIN_CONTROLLER_TYPE_SCSI controller(s), then
+     * try to add a new controller resulting in placement of this entry
+     * as unit=0
+     */
+    if (ret == -1 &&
+        virDomainDefMaybeAddController((virDomainDefPtr) def,
+                                           VIR_DOMAIN_CONTROLLER_TYPE_SCSI,
+                                           controller, -1) < 0)
+        return -1;
+
     hostdev->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE;
     hostdev->info->addr.drive.controller = controller;
     hostdev->info->addr.drive.bus = 0;