From: Anthony Liguori <aliguori@us.ibm.com>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 6/6] qdev: Generate IDs for anonymous devices
Date: Mon, 29 Aug 2011 14:23:33 -0500 [thread overview]
Message-ID: <4E5BE735.3090706@us.ibm.com> (raw)
In-Reply-To: <cd5c71b9a911b3208add7d63a4fb254797d2ea61.1314370059.git.jan.kiszka@siemens.com>
On 08/26/2011 09:48 AM, Jan Kiszka wrote:
> In order to address devices for that the user forgot or is even unable
> (no_user) to provide an ID, assign an automatically generated one. Such
> IDs have the format #<number>, thus are outside the name space availing
> to users. Don't use them for bus naming to avoid any other user-visible
> change.
I don't think this is a very nice approach. Why not eliminate anonymous
devices entirely and use a parent derived name for devices that are not
created by the user?
Regards,
Anthony Liguori
>
> CC: Markus Armbruster<armbru@redhat.com>
> Signed-off-by: Jan Kiszka<jan.kiszka@siemens.com>
> ---
> hw/qdev-properties.c | 2 +-
> hw/qdev.c | 25 +++++++++++++------------
> hw/qdev.h | 1 +
> 3 files changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index 0c0c292..4e39cef 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -682,7 +682,7 @@ int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *va
> if (res< 0) {
> error_report("Can't attach drive %s to %s.%s: %s",
> bdrv_get_device_name(value),
> - dev->id ? dev->id : dev->info->name,
> + dev->id != dev->auto_id ? dev->id : dev->info->name,
> name, strerror(-res));
> return -1;
> }
> diff --git a/hw/qdev.c b/hw/qdev.c
> index 3b0e1af..807902b 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -85,6 +85,7 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
>
> static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
> {
> + static unsigned int auto_id;
> DeviceState *dev;
>
> assert(bus->info == info->bus_info);
> @@ -94,6 +95,8 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
> qdev_prop_set_defaults(dev, dev->info->props);
> qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
> qdev_prop_set_globals(dev);
> + snprintf(dev->auto_id, sizeof(dev->auto_id), "#%u", ++auto_id);
> + dev->id = dev->auto_id;
> QLIST_INSERT_HEAD(&bus->children, dev, sibling);
> if (qdev_hotplug) {
> assert(bus->allow_hotplug);
> @@ -574,8 +577,9 @@ DeviceState *qdev_find_recursive(BusState *bus, const char *id)
> BusState *child;
>
> QLIST_FOREACH(dev,&bus->children, sibling) {
> - if (dev->id&& strcmp(dev->id, id) == 0)
> + if (strcmp(dev->id, id) == 0) {
> return dev;
> + }
> QLIST_FOREACH(child,&dev->child_bus, sibling) {
> ret = qdev_find_recursive(child, id);
> if (ret) {
> @@ -591,8 +595,8 @@ static void qbus_list_bus(DeviceState *dev)
> BusState *child;
> const char *sep = " ";
>
> - error_printf("child busses at \"%s\":",
> - dev->id ? dev->id : dev->info->name);
> + error_printf("child busses at \"%s\"/\"%s\":",
> + dev->info->name, dev->id);
> QLIST_FOREACH(child,&dev->child_bus, sibling) {
> error_printf("%s\"%s\"", sep, child->name);
> sep = ", ";
> @@ -607,9 +611,7 @@ static void qbus_list_dev(BusState *bus)
>
> error_printf("devices at \"%s\":", bus->name);
> QLIST_FOREACH(dev,&bus->children, sibling) {
> - error_printf("%s\"%s\"", sep, dev->info->name);
> - if (dev->id)
> - error_printf("/\"%s\"", dev->id);
> + error_printf("%s\"%s\"/\"%s\"", sep, dev->info->name, dev->id);
> sep = ", ";
> }
> error_printf("\n");
> @@ -638,7 +640,7 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem)
> * (3) driver alias, if present
> */
> QLIST_FOREACH(dev,&bus->children, sibling) {
> - if (dev->id&& strcmp(dev->id, elem) == 0) {
> + if (strcmp(dev->id, elem) == 0) {
> return dev;
> }
> }
> @@ -754,8 +756,8 @@ void qbus_create_inplace(BusState *bus, BusInfo *info,
> if (name) {
> /* use supplied name */
> bus->name = g_strdup(name);
> - } else if (parent&& parent->id) {
> - /* parent device has id -> use it for bus name */
> + } else if (parent&& parent->id != parent->auto_id) {
> + /* parent device has user-assigned id -> use it for bus name */
> len = strlen(parent->id) + 16;
> buf = g_malloc(len);
> snprintf(buf, len, "%s.%d", parent->id, parent->num_child_bus);
> @@ -850,8 +852,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
> static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
> {
> BusState *child;
> - qdev_printf("dev: %s, id \"%s\"\n", dev->info->name,
> - dev->id ? dev->id : "");
> + qdev_printf("dev: %s, id \"%s\"\n", dev->info->name, dev->id);
> indent += 2;
> if (dev->num_gpio_in) {
> qdev_printf("gpio-in %d\n", dev->num_gpio_in);
> @@ -1196,7 +1197,7 @@ int do_device_show(Monitor *mon, const QDict *qdict, QObject **ret_data)
> name = g_malloc(name_len);
> snprintf(name, name_len, "%s", dev->info->name);
> *ret_data = qobject_from_jsonf("{ 'device': %s, 'id': %s, 'version': %d }",
> - name, dev->id ? : "", vmsd->version_id);
> + name, dev->id, vmsd->version_id);
> g_free(name);
> qlist = qlist_new();
> parse_vmstate(vmsd, dev, qlist, qdict_get_try_bool(qdict, "full", false));
> diff --git a/hw/qdev.h b/hw/qdev.h
> index 912fc45..d028409 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -31,6 +31,7 @@ enum {
> so that it can be embedded in individual device state structures. */
> struct DeviceState {
> const char *id;
> + char auto_id[16];
> enum DevState state;
> QemuOpts *opts;
> int hotplugged;
next prev parent reply other threads:[~2011-08-29 19:23 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-26 14:48 [Qemu-devel] [PATCH 0/6] Device state visualization reloaded Jan Kiszka
2011-08-26 14:48 ` [Qemu-devel] [PATCH 1/6] monitor: return length of printed string via monitor_[v]printf Jan Kiszka
2011-08-26 14:48 ` [Qemu-devel] [PATCH 2/6] Add base64 encoder/decoder Jan Kiszka
2011-08-26 15:21 ` Peter Maydell
2011-08-26 15:23 ` Jan Kiszka
2011-08-26 15:47 ` Jan Kiszka
2011-08-26 18:02 ` Jan Kiszka
2011-09-02 17:22 ` Luiz Capitulino
2011-09-05 13:55 ` [Qemu-devel] required glib version? " Gerd Hoffmann
2011-08-26 14:48 ` [Qemu-devel] [PATCH 3/6] QMP: Reserve namespace for complex object classes Jan Kiszka
2011-09-02 17:23 ` Luiz Capitulino
2011-09-02 17:47 ` Jan Kiszka
2011-09-02 18:02 ` Anthony Liguori
2011-08-26 14:48 ` [Qemu-devel] [PATCH 4/6] QMP: Add QBuffer Jan Kiszka
2011-08-26 18:23 ` [Qemu-devel] [PATCH v2 " Jan Kiszka
2011-08-26 14:48 ` [Qemu-devel] [PATCH 5/6] monitor: Add basic device state visualization Jan Kiszka
2011-08-26 14:48 ` [Qemu-devel] [PATCH 6/6] qdev: Generate IDs for anonymous devices Jan Kiszka
2011-08-29 19:23 ` Anthony Liguori [this message]
2011-08-29 20:56 ` Jan Kiszka
2011-08-29 21:19 ` Anthony Liguori
2011-08-31 18:31 ` Jan Kiszka
2011-09-07 9:50 ` Gleb Natapov
2011-09-07 10:27 ` Jan Kiszka
2011-09-07 10:34 ` Gleb Natapov
2011-09-07 10:58 ` Jan Kiszka
2011-08-29 19:22 ` [Qemu-devel] [PATCH 0/6] Device state visualization reloaded Anthony Liguori
2011-08-29 20:54 ` Jan Kiszka
2011-09-02 17:27 ` Luiz Capitulino
2011-09-06 14:48 ` Michael S. Tsirkin
2011-09-06 15:45 ` Jan Kiszka
2011-09-06 15:51 ` Anthony Liguori
2011-09-06 16:05 ` Jan Kiszka
2011-09-06 16:08 ` Anthony Liguori
2011-09-06 16:33 ` Jan Kiszka
2011-09-06 16:09 ` Michael S. Tsirkin
2011-09-06 16:28 ` Anthony Liguori
2011-09-06 17:05 ` Michael S. Tsirkin
2011-09-07 9:37 ` Kevin Wolf
2011-09-07 13:06 ` Michael S. Tsirkin
2011-09-07 13:13 ` Jan Kiszka
2011-09-07 13:17 ` Michael S. Tsirkin
2011-09-07 13:23 ` Anthony Liguori
2011-09-07 13:29 ` Jan Kiszka
2011-09-07 13:33 ` Michael S. Tsirkin
2011-09-06 16:29 ` Jan Kiszka
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=4E5BE735.3090706@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=jan.kiszka@siemens.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.