qdev: Keep global allocation counter per bus
PATCH 1/1 qdev: Keep global allocation counter per bus
When we have 2 separate qdev devices that both create a qbus of the same type without specifying a bus name or device name, we end up with two buses of the same name, such as ide.0 on the Mac machines:
dev: macio-ide, id ""
bus: ide.0
type IDE
dev: macio-ide, id ""
bus: ide.0
type IDEIf we now spawn a device that connects to a ide.0 the last created bus gets the device, with the first created bus inaccessible to the command line.
After some discussion on IRC we concluded that the best quick fix way forward for this is to make automated bus-class type based allocation count a global counter. That's what this patch implements. With this we instead get
dev: macio-ide, id ""
bus: ide.1
type IDE
dev: macio-ide, id ""
bus: ide.0
type IDEon the example mentioned above.
This also means that if you did -device ...,bus=ide.0 you got a device on the first bus (the last created one) before this patch and get that device on the second one (the first created one) now.
This is intended and makes the bus enumeration work as expected.
As per review request follows a list of otherwise affected boards and the reasoning for the conclusion that they are ok:
target machine bus id times ------ ------- ------ -----
aarch64 n800 i2c-bus.0 2 aarch64 n810 i2c-bus.0 2 arm n800 i2c-bus.0 2 arm n810 i2c-bus.0 2
-> Devices are created explicitly on one of the two buses, using
s->mpu->i2c[0], so no change to the guest.
aarch64 vexpress-a15 virtio-mmio-bus.0 4 aarch64 vexpress-a9 virtio-mmio-bus.0 4 aarch64 virt virtio-mmio-bus.0 32 arm vexpress-a15 virtio-mmio-bus.0 4 arm vexpress-a9 virtio-mmio-bus.0 4 arm virt virtio-mmio-bus.0 32
-> Migration drivers need to access virtio-mmio-bus.4/32 rather
than .0 on the destination from old->new. Bugfix as it allows coldplug for specific buses.
aarch64 xilinx-zynq-a9 usb-bus.0 2 arm xilinx-zynq-a9 usb-bus.0 2 mips64el fulong2e usb-bus.0 2
-> Normal USB operation not affected. Migration driver needs command
line to use the other bus.
i386 isapc ide.0 2 x86_64 isapc ide.0 2
-> Fix part of this patch.
mips mips ide.0 2 mips64 mips ide.0 2 mips64el mips ide.0 2 mipsel mips ide.0 2
-> Not affected, the bus is not stored anywhere.
ppc g3beige ide.0 2 ppc mac99 ide.0 2 ppc prep ide.0 2 ppc64 g3beige ide.0 2 ppc64 mac99 ide.0 2 ppc64 prep ide.0 2
-> Bugfix
---
v1 -> v2:
- add fix for isapc which was searching for 2 buses called "ide.0"
- explain the semantic change more in the commit message
v2 -> v3:
- add board list to commit message
--- hw/core/qdev.c | 20 +++++++++++++------- hw/i386/pc_piix.c | 8 +++++++- include/hw/qdev-core.h | 2 ++ 3 files changed, 22 insertions(+), 8 deletions(-)
hw/core/qdev.c +13 -7
@@ -430,27 +430,33 @@ DeviceState *qdev_find_recursive(BusState *bus, const char *id)static void qbus_realize (BusState *bus,DeviceState *parent,const char *name) {const char *typename =object_get_typename (OBJECT (bus)); +BusClass *bc;char *buf; -int i,len; +int i, len, bus_id; bus->parent = parent;if (name) { bus->name =g_strdup (name); }else if (bus->parent && bus->parent->id) { -/* parent device has id -> use it for bus name */ +/* parent device has id -> use it plus parent-bus-id for bus name */ + bus_id = bus->parent->num_child_bus; + len =strlen (bus->parent->id) +16 ; buf =g_malloc (len); -snprintf (buf, len,"%s.%d" , bus->parent->id, bus->parent->num_child_bus); +snprintf (buf, len,"%s.%d" , bus->parent->id, bus_id); bus->name = buf; }else { -/* no id -> use lowercase bus type for bus name */ +/* no id -> use lowercase bus type plus global bus-id for bus name */ + bc =BUS_GET_CLASS (bus); + bus_id = bc->automatic_ids++; + len =strlen (typename) +16 ; buf =g_malloc (len); - len =snprintf (buf, len,"%s.%d" , typename, - bus->parent ? bus->parent->num_child_bus :0 ); -for (i =0 ; i < len; i++) + len =snprintf (buf, len,"%s.%d" , typename, bus_id); +for (i =0 ; i < len; i++) { buf[i] =qemu_tolower (buf[i]); + } bus->name = buf; }
hw/i386/pc_piix.c +7 -1
@@ -221,10 +221,16 @@ static void pc_init1(QEMUMachineInitArgs *args, }else {for (i =0 ; i <MAX_IDE_BUS ; i++) {ISADevice *dev; +char busname[] ="ide.0" ; dev =isa_ide_init (isa_bus, ide_iobase[i], ide_iobase2[i], ide_irq[i], hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i +1 ]); - idebus[i] =qdev_get_child_bus (DEVICE (dev),"ide.0" ); +/* +* The ide bus name is ide.0 for the first bus and ide.1 for the +* second one. +*/ + busname[4 ] ='0' + i; + idebus[i] =qdev_get_child_bus (DEVICE (dev), busname); } }
include/hw/qdev-core.h +2 -0
@@ -172,6 +172,8 @@ struct BusClass {void (*reset)(BusState *bus);/* maximum devices allowed on the bus, 0: no limit. */ int max_dev; +/* number of automatically allocated bus ids (e.g. ide.0) */ +int automatic_ids; }; typedef struct BusChild {
Signature · 1 line
1.8.1.4
Actually [PATCH v3].
Quoted 27 lines · Alexander Graf
When we have 2 separate qdev devices that both create a qbus of the same type without specifying a bus name or device name, we end up with two buses of the same name, such as ide.0 on the Mac machines:
dev: macio-ide, id ""
bus: ide.0 type IDE dev: macio-ide, id "" bus: ide.0 type IDEIf we now spawn a device that connects to a ide.0 the last created bus gets the device, with the first created bus inaccessible to the command line.
After some discussion on IRC we concluded that the best quick fix way forward for this is to make automated bus-class type based allocation count a global counter. That's what this patch implements. With this we instead get
dev: macio-ide, id ""
bus: ide.1 type IDE dev: macio-ide, id "" bus: ide.0 type IDE
Quoted 5 lines
on the example mentioned above.
This also means that if you did -device ...,bus=ide.0 you got a device on the first bus (the last created one) before this patch and get that device on the second one (the first created one) now.
Please add:
This breaks migration unless you change bus=ide.0 to bus=ide.1 on the destination.
Should be mentioned in release notes. Do we have a place where we collect release notes as we go?
Quoted 8 lines
This is intended and makes the bus enumeration work as expected.
As per review request follows a list of otherwise affected boards and the reasoning for the conclusion that they are ok:
target machine bus id times ------ ------- ------ -----
Quoted 7 lines
aarch64 n800 i2c-bus.0 2 aarch64 n810 i2c-bus.0 2 arm n800 i2c-bus.0 2 arm n810 i2c-bus.0 2-> Devices are created explicitly on one of the two buses, using
s->mpu->i2c[0], so no change to the guest.
Yes. Bus ID "i2c-bus.0" isn't exposed to the user or the guest, so changing its interpretation is harmless.
Quoted 10 lines
aarch64 vexpress-a15 virtio-mmio-bus.0 4 aarch64 vexpress-a9 virtio-mmio-bus.0 4 aarch64 virt virtio-mmio-bus.0 32 arm vexpress-a15 virtio-mmio-bus.0 4 arm vexpress-a9 virtio-mmio-bus.0 4 arm virt virtio-mmio-bus.0 32-> Migration drivers need to access virtio-mmio-bus.4/32 rather
than .0 on the destination fromold->new. Bugfix as it allows coldplug for specific buses.
"from old->new"? Do you mean "for old->new"?
Suggest
-> Makes -device bus= work for all virtio-mmio buses. Breaks
migration. Workaround for migration from old to new: specify virtio-mmio-bus.4 or .32 respectively rather than .0 on the destination.
Quoted 11 lines
aarch64 xilinx-zynq-a9 usb-bus.0 2 arm xilinx-zynq-a9 usb-bus.0 2 mips64el fulong2e usb-bus.0 2-> Normal USB operation not affected. Migration driver needs command
line to use the other bus.i386 isapc ide.0 2 x86_64 isapc ide.0 2-> Fix part of this patch.
Err, what's part of this patch is adapting pc_init1() for the changed bus name, so it doesn't break. No need to mention what you're not breaking. But do mention what you're breaking: migration with bus=ide.0, exactly like in your Mac example.
Please replace by something like this:
-> Makes -device bus= work for all IDE buses. Breaks migration.
Workaround for migration from old to new: specify ide.1 rather than ide.0 on the destination.
Quoted 6 lines
mips mips ide.0 2 mips64 mips ide.0 2 mips64el mips ide.0 2 mipsel mips ide.0 2-> Not affected, the bus is not stored anywhere.
Are you sure? I believe these are affected exactly like isapc.
Quoted 8 lines
ppc g3beige ide.0 2 ppc mac99 ide.0 2 ppc prep ide.0 2 ppc64 g3beige ide.0 2 ppc64 mac99 ide.0 2 ppc64 prep ide.0 2-> Bugfix
Again, just like isapc.
Quoted 4 lines
CC Paolo Bonzini <[email protected]>CC Markus Armbruster <[email protected]>CC Anthony Liguori <[email protected]>Signed-off-by Alexander Graf <[email protected]>
Patch looks good.
Il 04/02/2014 11:33, Markus Armbruster ha scritto:
Quoted 6 lines
This breaks migration unless you change bus=ide.0 to bus=ide.1 on the destination.
Should be mentioned in release notes. Do we have a place where we collect release notes as we go?
Yes, http://wiki.qemu.org/ChangeLog/Next
Paolo
Quoted 9 lines · Paolo Bonzini
Il 04/02/2014 11:33, Markus Armbruster ha scritto:
Quoted 6 lines
This breaks migration unless you change bus=ide.0 to bus=ide.1 on the destination.
Should be mentioned in release notes. Do we have a place where we collect release notes as we go?
I can record this change there, but I don't seem to have an account.
Il 04/02/2014 13:14, Markus Armbruster ha scritto:
Quoted 7 lines
Quoted 5 lines · Paolo Bonzini
Il 04/02/2014 11:33, Markus Armbruster ha scritto:
Quoted 4 lines
This breaks migration unless you change bus=ide.0 to bus=ide.1 on the destination.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Should be mentioned in release notes. Do we have a place where we collect release notes as we go?
I can record this change there, but I don't seem to have an account.
Created one, will send account details offlist.
Paolo
Quoted 8 lines · Paolo Bonzini
Il 04/02/2014 13:14, Markus Armbruster ha scritto:
Quoted 7 lines
Quoted 5 lines · Paolo Bonzini
Il 04/02/2014 11:33, Markus Armbruster ha scritto:
Quoted 4 lines
This breaks migration unless you change bus=ide.0 to bus=ide.1 on the destination.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Should be mentioned in release notes. Do we have a place where we collect release notes as we go?
I can record this change there, but I don't seem to have an account.
Created one, will send account details offlist.
I'll update the page when the patch gets committed.
Alex, want me to repost it with the commit message amended as outlined in my review?
Quoted 15 lines · Markus Armbruster
Quoted 13 lines · Paolo Bonzini
Il 04/02/2014 13:14, Markus Armbruster ha scritto:
Quoted 12 lines
Quoted 9 lines · Paolo Bonzini
Il 04/02/2014 11:33, Markus Armbruster ha scritto:
Quoted 6 lines
This breaks migration unless you change bus=ide.0 to bus=ide.1 on the destination.
Should be mentioned in release notes. Do we have a place where we collect release notes as we go?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I can record this change there, but I don't seem to have an account.
Created one, will send account details offlist.
I'll update the page when the patch gets committed.
Alex, want me to repost it with the commit message amended as outlined in my review?
Yes, please. I'm sure if I change it you'll find some nits again.
Alex
Quoted 19 lines · Alexander Graf
Quoted 17 lines · Markus Armbruster
Quoted 15 lines · Paolo Bonzini
Il 04/02/2014 13:14, Markus Armbruster ha scritto:
Quoted 13 lines
Quoted 9 lines · Paolo Bonzini
Il 04/02/2014 11:33, Markus Armbruster ha scritto:
Quoted 6 lines
This breaks migration unless you change bus=ide.0 to bus=ide.1 on the destination.
Should be mentioned in release notes. Do we have a place where we collect release notes as we go?
I can record this change there, but I don't seem to have an account.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Created one, will send account details offlist.
I'll update the page when the patch gets committed.
Alex, want me to repost it with the commit message amended as outlined in my review?
Yes, please. I'm sure if I change it you'll find some nits again.
Believe me, I felt bad about nit-picking your commit message *again*. I would've refrained if it wasn't about breaking backwards compatibility. I'm not overly adverse to that, but I am a stickler for describing exactly what gets broken. Hope I didn't try your patience too much...
Anyway, v4 just sent.