Skip to contentSkip to conversation

hotplug: fix scsi hotplug.

PATCH In review Gerd Hoffmann 3 participants 7 messages Oct 14, 2009 – Oct 15, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hotplug: fix scsi hotplug.

Well, partly just papering over the issues. But without proper scsi bus infrastructure we hardly can do better. Changes:

* Avoid auto-attach by setting the bus number to -1.
* Ignore the unit value calculated by drive_init().
* Explicitly attach the devices to the adapter.
* Add sanity checks. Don't allow attaching scsi drives to your network device.
* Kill the bus+unit printing. The values are bogus, and we can't easily figure the correct ones. I doubt this ever worked correctly with multiple scsi adapters present in the system.

Should come more close to the expected behavior now ...

Oh, and pc-bios/bios.bin needs a update too, otherwise pci hotplug doesn't work at all.

---
 hw/pci-hotplug.c |   24 +++++++++++++++++++-----
 pc-bios/bios.bin |  Bin 131072 -> 131072 bytes
 2 files changed, 19 insertions(+), 5 deletions(-)
hw/pci-hotplug.c +19 -5
index d0f2911..8bedea2 100644
@@ -52,9 +52,10 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
 {
     int dom, pci_bus;
     unsigned slot;
-    int drive_idx, type, bus;
+    int drive_idx, type;
     int success = 0;
     PCIDevice *dev;
+    char buf[128];
 
     if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) {
         return;
@@ -74,11 +75,19 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
         return;
     }
     type = drives_table[drive_idx].type;
-    bus = drive_get_max_bus (type);
 
     switch (type) {
     case IF_SCSI:
+        if (!dev->qdev.info || strcmp(dev->qdev.info->name, "lsi53c895a") != 0) {
+            monitor_printf(mon, "Device is not a scsi adapter\n");
+            break;
+        }
         success = 1;
+        drives_table[drive_idx].bus = -1;
+        drives_table[drive_idx].unit = -1;
+        if (get_param_value(buf, sizeof(buf), "unit", opts)) {
+            drives_table[drive_idx].unit = atoi(buf);
+        }
         lsi_scsi_attach(&dev->qdev, drives_table[drive_idx].bdrv,
                         drives_table[drive_idx].unit);
         break;
@@ -87,9 +96,7 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
     }
 
     if (success)
-        monitor_printf(mon, "OK bus %d, unit %d\n",
-                       drives_table[drive_idx].bus,
-                       drives_table[drive_idx].unit);
+        monitor_printf(mon, "OK\n");
     return;
 }
 
@@ -130,7 +137,14 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
 
     switch (type) {
     case IF_SCSI:
+        drives_table[drive_idx].bus = -1;
+        drives_table[drive_idx].unit = -1;
+        if (get_param_value(buf, sizeof(buf), "unit", opts)) {
+            drives_table[drive_idx].unit = atoi(buf);
+        }
         dev = pci_create("lsi53c895a", devaddr);
+        lsi_scsi_attach(&dev->qdev, drives_table[drive_idx].bdrv,
+                        drives_table[drive_idx].unit);
         break;
     case IF_VIRTIO:
         dev = pci_create("virtio-blk-pci", devaddr);
pc-bios/bios.bin binary +0 -0
index e4323c0504f8f4faf72d56e288c0d457b37bf442..542beddc6fa9c267893283c919158be28f61cb05 100644
GIT binary patch
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 12 lines · Gerd Hoffmann

Well, partly just papering over the issues. But without proper scsi bus infrastructure we hardly can do better. Changes:

* Avoid auto-attach by setting the bus number to -1.
* Ignore the unit value calculated by drive_init().
* Explicitly attach the devices to the adapter.
* Add sanity checks. Don't allow attaching scsi drives to your network device.
* Kill the bus+unit printing. The values are bogus, and we can't easily figure the correct ones. I doubt this ever worked correctly with multiple scsi adapters present in the system.

Quoted 5 lines

Should come more close to the expected behavior now ...

Oh, and pc-bios/bios.bin needs a update too, otherwise pci hotplug doesn't work at all.

What's it being updated to?

Regards,

Anthony Liguori

#2 lore raw
Quoted 4 lines · Anthony Liguori
Quoted 2 lines

Oh, and pc-bios/bios.bin needs a update too, otherwise pci hotplug doesn't work at all.

What's it being updated to?

pcbios da5ff65dc9473e3f069736d38b9a189ea14a67eb (same as master).

cheers,
Gerd

#3 lore raw
In reply to Gerd Hoffmann
Quoted 2 lines · Gerd Hoffmann

Oh, and pc-bios/bios.bin needs a update too, otherwise pci hotplug doesn't work at all.

Hi Gerd-

I'm having trouble applying the pc-bios/bios.bin binary patch. Can you explain how to apply this diff?

:-Dustin

#4 lore raw
Quoted 8 lines · Dustin Kirkland
Quoted 2 lines · Gerd Hoffmann

Oh, and pc-bios/bios.bin needs a update too, otherwise pci hotplug doesn't work at all.

Hi Gerd-

I'm having trouble applying the pc-bios/bios.bin binary patch. Can you explain how to apply this diff?

"git am" should work. You can also simply ignore the patch and copy bios.bin over from the master branch.

HTH,
Gerd

Tested-by on v1 1/1
#5 lore raw
In reply to Gerd Hoffmann
Quoted 78 lines · Gerd Hoffmann

Well, partly just papering over the issues.  But without proper scsi bus infrastructure we hardly can do better.  Changes:

 * Avoid auto-attach by setting the bus number to -1.
 * Ignore the unit value calculated by drive_init().
 * Explicitly attach the devices to the adapter.
 * Add sanity checks.  Don't allow attaching scsi drives to your network device.
 * Kill the bus+unit printing.  The values are bogus, and we can't easily figure the correct ones.  I doubt this ever worked correctly with multiple scsi adapters present in the system.

Should come more close to the expected behavior now ...

Oh, and pc-bios/bios.bin needs a update too, otherwise pci hotplug doesn't work at all.

---
 hw/pci-hotplug.c |   24 +++++++++++++++++++-----
 pc-bios/bios.bin |  Bin 131072 -> 131072 bytes

 2 files changed, 19 insertions(+), 5 deletions(-)
hw/pci-hotplug.c +2 -2
index d0f2911..8bedea2 100644
@@ -52,9 +52,10 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
  {
     int dom, pci_bus;
     unsigned slot;
-    int drive_idx, type, bus;
+    int drive_idx, type;
     int success = 0;
     PCIDevice *dev;
+    char buf[128];
 
     if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) {
         return;
@@ -74,11 +75,19 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
         return;
     }
     type = drives_table[drive_idx].type;
-    bus = drive_get_max_bus (type);
 
     switch (type) {

    case IF_SCSI:
+        if (!dev->qdev.info || strcmp(dev->qdev.info->name, "lsi53c895a") != 0) {
+            monitor_printf(mon, "Device is not a scsi adapter\n");
+            break;
+        }
        success = 1;
+        drives_table[drive_idx].bus = -1;
+        drives_table[drive_idx].unit = -1;
+        if (get_param_value(buf, sizeof(buf), "unit", opts)) {
+            drives_table[drive_idx].unit = atoi(buf);
+        }
        lsi_scsi_attach(&dev->qdev, drives_table[drive_idx].bdrv, drives_table[drive_idx].unit);
        break;

hw/pci-hotplug.c +1 -3
@@ -87,9 +96,7 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
     }
 
     if (success)
-        monitor_printf(mon, "OK bus %d, unit %d\n",
-                       drives_table[drive_idx].bus,
-                       drives_table[drive_idx].unit);
+        monitor_printf(mon, "OK\n");
     return;
  }
 
@@ -130,7 +137,14 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
 
     switch (type) {

    case IF_SCSI:
+        drives_table[drive_idx].bus = -1;
+        drives_table[drive_idx].unit = -1;
+        if (get_param_value(buf, sizeof(buf), "unit", opts)) {

Quoted 8 lines

+            drives_table[drive_idx].unit = atoi(buf);
+        }
        dev = pci_create("lsi53c895a", devaddr);
+        lsi_scsi_attach(&dev->qdev, drives_table[drive_idx].bdrv,
+                        drives_table[drive_idx].unit); break;
    case IF_VIRTIO:
        dev = pci_create("virtio-blk-pci", devaddr);

Thanks, Gerd.

I applied this patch against qemu-kvm-0.11.0 stable, built, and tested it. I can verify that it fixes the scsi hot-add issues I was seeing. I am now able to add/remove/add/remove/add/remove a scsi disk to a running instance without segfaulting qemu.

Note that on remove, I do get a stack track in the guest's kernel (2.6.31), though the remove does succeed, and the disk disappears.

Also note that I did not replace the bios.bin, as it appears to me that the qemu-kvm-0.11 bios.bin is working properly.

#6 lore raw
Quoted 2 lines · Dustin Kirkland

Also note that I did not replace the bios.bin, as it appears to me that the qemu-kvm-0.11 bios.bin is working properly.

Yes, kvm has its own bios, only for vanilla upstream the bios must be replaced.

cheers,
Gerd