hotplug: fix scsi hotplug.
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
@@ -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
Signature · 1 line
1.6.2.5
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 bydrive_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
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
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
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
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 bydrive_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.
Signed-off-by Gerd Hoffmann <[email protected]>---
hw/pci-hotplug.c | 24 +++++++++++++++++++-----
pc-bios/bios.bin | Bin 131072 -> 131072 bytes2 files changed, 19 insertions(+), 5 deletions(-)hw/pci-hotplug.c +2
-2@@ -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;
caseIF_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.
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