Commit d271de9f1bd7c4671af8cc8edca4ac677371cfff
Committed by
Anthony Liguori
1 parent
a6307b08
qdev: create default bus names.
Create a default bus name if none is passed to qbus_create(). If the parent device has DeviceState->id set it will be used to create the bus name,. i.e. -device lsi,id=foo will give you a scsi bus named "foo.0". If there is no id BusInfo->name (lowercased) will be used instead, i.e. -device lsi will give you a scsi bus named "scsi.0". A scsi adapter with two scsi busses would have "scsi.0" and "scsi.1" or "$id.0" and "$id.1" busses. The numbers of the child busses are per device, i.e. when adding two lsi adapters both will have a "*.0" child bus. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
2 changed files
with
25 additions
and
1 deletions
hw/qdev.c
... | ... | @@ -232,14 +232,37 @@ void scsi_bus_new(DeviceState *host, SCSIAttachFn attach) |
232 | 232 | BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name) |
233 | 233 | { |
234 | 234 | BusState *bus; |
235 | + char *buf; | |
236 | + int i,len; | |
235 | 237 | |
236 | 238 | bus = qemu_mallocz(info->size); |
237 | 239 | bus->info = info; |
238 | 240 | bus->parent = parent; |
239 | - bus->name = qemu_strdup(name); | |
241 | + | |
242 | + if (name) { | |
243 | + /* use supplied name */ | |
244 | + bus->name = qemu_strdup(name); | |
245 | + } else if (parent && parent->id) { | |
246 | + /* parent device has id -> use it for bus name */ | |
247 | + len = strlen(parent->id) + 16; | |
248 | + buf = qemu_malloc(len); | |
249 | + snprintf(buf, len, "%s.%d", parent->id, parent->num_child_bus); | |
250 | + bus->name = buf; | |
251 | + } else { | |
252 | + /* no id -> use lowercase bus type for bus name */ | |
253 | + len = strlen(info->name) + 16; | |
254 | + buf = qemu_malloc(len); | |
255 | + len = snprintf(buf, len, "%s.%d", info->name, | |
256 | + parent ? parent->num_child_bus : 0); | |
257 | + for (i = 0; i < len; i++) | |
258 | + buf[i] = tolower(buf[i]); | |
259 | + bus->name = buf; | |
260 | + } | |
261 | + | |
240 | 262 | LIST_INIT(&bus->children); |
241 | 263 | if (parent) { |
242 | 264 | LIST_INSERT_HEAD(&parent->child_bus, bus, sibling); |
265 | + parent->num_child_bus++; | |
243 | 266 | } |
244 | 267 | return bus; |
245 | 268 | } | ... | ... |