]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Use existing SCSI hostdev model to create new
authorJohn Ferlan <jferlan@redhat.com>
Mon, 4 Dec 2017 20:52:57 +0000 (15:52 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 4 Jan 2018 15:30:43 +0000 (10:30 -0500)
In virDomainDefMaybeAddHostdevSCSIcontroller when we add a new
controller because someone neglected to add one or we're adding
one because the existing one is full, we should copy over the
model number from the existing controller since whatever we
create should at least have the same characteristics as the one
we cannot use because it's full.

NB: This affects the existing hostdev-scsi-autogen-address test
which would add a default ('lsi') SCSI controller for the various
scsi_host's that would create a controller for the hostdev.

src/conf/domain_conf.c
tests/qemuxml2xmloutdata/hostdev-scsi-autogen-address.xml

index 9a62bc472c68ac88969d3c42dfcd458839460fb7..3f28ac62408eb566cf32793d6ae39d93bddaf633 100644 (file)
@@ -17727,12 +17727,23 @@ virDomainDefMaybeAddHostdevSCSIcontroller(virDomainDefPtr def)
     size_t i;
     int maxController = -1;
     virDomainHostdevDefPtr hostdev;
+    int newModel = -1;
 
     for (i = 0; i < def->nhostdevs; i++) {
         hostdev = def->hostdevs[i];
         if (virHostdevIsSCSIDevice(hostdev) &&
             (int)hostdev->info->addr.drive.controller > maxController) {
+            int model = -1;
+
             maxController = hostdev->info->addr.drive.controller;
+            /* We may be creating a new controller because this one is full.
+             * So let's grab the model from it and update the model we're
+             * going to add as long as this one isn't undefined. The premise
+             * being keeping the same controller model for all SCSI hostdevs. */
+            model = virDomainDeviceFindControllerModel(def, hostdev->info,
+                                                       VIR_DOMAIN_CONTROLLER_TYPE_SCSI);
+            if (model != -1)
+                newModel = model;
         }
     }
 
@@ -17740,7 +17751,8 @@ virDomainDefMaybeAddHostdevSCSIcontroller(virDomainDefPtr def)
         return 0;
 
     for (i = 0; i <= maxController; i++) {
-        if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_SCSI, i, -1) < 0)
+        if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_SCSI,
+                                           i, newModel) < 0)
             return -1;
     }
 
index 8e93056eedc66063bf94d8b4559443c89e7b9c74..cea212b64d4bd0f44be1ab93f71f75701cf03ddb 100644 (file)
@@ -29,7 +29,7 @@
       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
     </controller>
     <controller type='pci' index='0' model='pci-root'/>
-    <controller type='scsi' index='1'>
+    <controller type='scsi' index='1' model='virtio-scsi'>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
     </controller>
     <input type='mouse' bus='ps2'/>