From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 3/6] qdev: create default bus names.
Date: Wed, 15 Jul 2009 13:59:24 +0200 [thread overview]
Message-ID: <1247659167-1177-4-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1247659167-1177-1-git-send-email-kraxel@redhat.com>
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>
---
hw/qdev.c | 25 ++++++++++++++++++++++++-
hw/qdev.h | 1 +
2 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 4c27451..2b772f8 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -234,14 +234,37 @@ void scsi_bus_new(DeviceState *host, SCSIAttachFn attach)
BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)
{
BusState *bus;
+ char *buf;
+ int i,len;
bus = qemu_mallocz(info->size);
bus->info = info;
bus->parent = parent;
- bus->name = qemu_strdup(name);
+
+ if (name) {
+ /* use supplied name */
+ bus->name = qemu_strdup(name);
+ } else if (parent && parent->id) {
+ /* parent device has id -> use it for bus name */
+ len = strlen(parent->id) + 16;
+ buf = qemu_malloc(len);
+ snprintf(buf, len, "%s.%d", parent->id, parent->num_child_bus);
+ bus->name = buf;
+ } else {
+ /* no id -> use lowercase bus type for bus name */
+ len = strlen(info->name) + 16;
+ buf = qemu_malloc(len);
+ len = snprintf(buf, len, "%s.%d", info->name,
+ parent ? parent->num_child_bus : 0);
+ for (i = 0; i < len; i++)
+ buf[i] = tolower(buf[i]);
+ bus->name = buf;
+ }
+
LIST_INIT(&bus->children);
if (parent) {
LIST_INSERT_HEAD(&parent->child_bus, bus, sibling);
+ parent->num_child_bus++;
}
return bus;
}
diff --git a/hw/qdev.h b/hw/qdev.h
index a9a229e..67c4dd5 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -27,6 +27,7 @@ struct DeviceState {
int num_gpio_in;
qemu_irq *gpio_in;
LIST_HEAD(, BusState) child_bus;
+ int num_child_bus;
NICInfo *nd;
LIST_ENTRY(DeviceState) sibling;
};
--
1.6.2.5
next prev parent reply other threads:[~2009-07-15 11:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-15 11:59 [Qemu-devel] [PATCH 0/6] qdev: -device switch patches Gerd Hoffmann
2009-07-15 11:59 ` [Qemu-devel] [PATCH 1/6] qdev/prop: add pci devfn property Gerd Hoffmann
2009-07-15 11:59 ` [Qemu-devel] [PATCH 2/6] qdev/pci: use qdev_prop_pci_devfn Gerd Hoffmann
2009-07-15 11:59 ` Gerd Hoffmann [this message]
2009-07-15 11:59 ` [Qemu-devel] [PATCH 4/6] qdev: bus walker + qdev_device_add() Gerd Hoffmann
2009-07-15 11:59 ` [Qemu-devel] [PATCH 5/6] qdev: add -device command line option Gerd Hoffmann
2009-07-15 11:59 ` [Qemu-devel] [PATCH 6/6] switch balloon initialization to -device Gerd Hoffmann
2009-07-22 15:02 ` [Qemu-devel] [PATCH 0/6] qdev: -device switch patches Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1247659167-1177-4-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).