qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org
Cc: chrisw@redhat.com, kvm@vger.kernel.org, paul@codesourcery.com,
	alex.williamson@redhat.com, kraxel@redhat.com, avi@redhat.com
Subject: [Qemu-devel] [RFC PATCH 1/5] qdev: Create qdev_get_dev_path()
Date: Sun, 13 Jun 2010 23:51:19 -0600	[thread overview]
Message-ID: <20100614055119.879.92321.stgit@localhost.localdomain> (raw)
In-Reply-To: <20100614054923.879.33717.stgit@localhost.localdomain>

qdev_get_dev_path() is intended to be the canonical utility for creating
a string representing the qdev hierarchy of a device.  The path consists
of bus and device names as well as identified properties of the immediate
parent bus and device.  This results in strings like:

"/main-system-bus/pci.0,addr=00.0/i440FX"
"/main-system-bus/pci.0,addr=01.0/PIIX3"
"/main-system-bus/pci.0,addr=02.0/cirrus-vga"
"/main-system-bus/pci.0/isa.0/mc146818rtc"
"/main-system-bus/pci.0/isa.0/isa-serial"
"/main-system-bus/pci.0/isa.0/i8042"
"/main-system-bus/pci.0/isa.0/isa-fdc"
"/main-system-bus/pci.0,addr=03.0/i82551,mac=52:54:00:12:34:56"
"/main-system-bus/pci.0,addr=04.0/virtio-net-pci,mac=52:54:00:12:34:57"
"/main-system-bus/pci.0,addr=05.0/e1000,mac=52:54:00:12:34:58"
"/main-system-bus/pci.0,addr=06.0/rtl8139,mac=52:54:00:12:34:59"
"/main-system-bus/pci.0,addr=07.0/pcnet,mac=52:54:00:12:34:5a"
"/main-system-bus/pci.0,addr=01.1/piix3-ide"
"/main-system-bus/pci.0,addr=01.3/PIIX4_PM"
"/main-system-bus/pci.0,addr=08.0/lsi53c895a"
"/main-system-bus/pci.0,addr=09.0/virtio-blk-pci"

There are two primary targets for these strings.  The first is vmsave, where
we currently use a device provided string plus instance number to track
SaveStateEntries.  This fails when we introduce device hotplug, particularly
in a case were we have gaps in the instance numbers that cannot easily be
reproduced on a migration target.  The second is for naming RAMBlocks.  For
these, we would like a string that matches the vmstate string.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 hw/qdev-properties.c |    2 ++
 hw/qdev.c            |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h            |    5 ++++
 3 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 9ffdba7..e30df88 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -453,6 +453,7 @@ PropertyInfo qdev_prop_macaddr = {
     .name  = "macaddr",
     .type  = PROP_TYPE_MACADDR,
     .size  = sizeof(MACAddr),
+    .flags = PROP_FLAG_PATH,
     .parse = parse_mac,
     .print = print_mac,
 };
@@ -496,6 +497,7 @@ PropertyInfo qdev_prop_pci_devfn = {
     .name  = "pci-devfn",
     .type  = PROP_TYPE_UINT32,
     .size  = sizeof(uint32_t),
+    .flags = PROP_FLAG_PATH,
     .parse = parse_pci_devfn,
     .print = print_pci_devfn,
 };
diff --git a/hw/qdev.c b/hw/qdev.c
index 36f29ea..dea44fe 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -120,6 +120,63 @@ DeviceState *qdev_create(BusState *bus, const char *name)
     return qdev_create_from_info(bus, info);
 }
 
+static int qdev_strprint_parent_path(DeviceState *dev, char *buf, size_t len)
+{
+    int offset = 0;
+
+    if (dev->parent_bus && dev->parent_bus->parent)
+        offset = qdev_strprint_parent_path(dev->parent_bus->parent, buf, len);
+
+    offset += snprintf(buf + offset, len - offset,
+                        "/%s", dev->parent_bus->name);
+    return offset;
+}
+
+static int qdev_strprint_path_props(DeviceState *dev, Property *props,
+                                    char *buf, size_t len)
+{
+    int offset = 0;
+    char pbuf[64];
+
+    if (!props)
+        return 0;
+
+    while (props->name) {
+        if (props->info->flags & PROP_FLAG_PATH) {
+            if (props->info->print) {
+                props->info->print(dev, props, pbuf, sizeof(pbuf));
+                offset += snprintf(buf + offset, len - offset, ",%s=%s",
+                                   props->name, pbuf);
+            }
+        }
+        props++;
+    }
+    return offset;
+}
+
+char *qdev_get_dev_path(DeviceState *dev)
+{
+    char buf[256] = "";
+    int offset;
+
+    if (!dev)
+        return NULL;
+
+    offset = qdev_strprint_parent_path(dev, buf, sizeof(buf));
+
+    offset += qdev_strprint_path_props(dev, dev->parent_bus->info->props,
+                                       buf + offset, sizeof(buf) - offset);
+
+    offset += snprintf(buf + offset, sizeof(buf) - offset, "/%s",
+                       dev->info->name);
+    if (dev->id)
+        offset += snprintf(buf + offset, sizeof(buf) - offset, "-%s", dev->id);
+
+    offset += qdev_strprint_path_props(dev, dev->info->props,
+                                       buf + offset, sizeof(buf) - offset);
+    return qemu_strdup(buf);
+}
+
 static void qdev_print_devinfo(DeviceInfo *info)
 {
     error_printf("name \"%s\", bus %s",
diff --git a/hw/qdev.h b/hw/qdev.h
index a44060e..2702384 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -96,6 +96,7 @@ struct PropertyInfo {
     const char *name;
     size_t size;
     enum PropertyType type;
+    int flags;
     int (*parse)(DeviceState *dev, Property *prop, const char *str);
     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
 };
@@ -201,6 +202,8 @@ extern PropertyInfo qdev_prop_netdev;
 extern PropertyInfo qdev_prop_vlan;
 extern PropertyInfo qdev_prop_pci_devfn;
 
+#define PROP_FLAG_PATH        (1<<0)
+
 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
         .name      = (_name),                                    \
         .info      = &(_prop),                                   \
@@ -280,6 +283,8 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props);
 void qdev_prop_register_global_list(GlobalProperty *props);
 void qdev_prop_set_globals(DeviceState *dev);
 
+char *qdev_get_dev_path(DeviceState *dev);
+
 /* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
 extern struct BusInfo system_bus_info;
 

  reply	other threads:[~2010-06-14  5:51 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-14  5:51 [Qemu-devel] [RFC PATCH 0/5] Introduce canonical device hierarchy string Alex Williamson
2010-06-14  5:51 ` Alex Williamson [this message]
2010-06-14  6:39   ` [Qemu-devel] [RFC PATCH 1/5] qdev: Create qdev_get_dev_path() Markus Armbruster
2010-06-14 12:52     ` Alex Williamson
2010-06-14 13:00       ` Jan Kiszka
2010-06-14 13:09       ` Paul Brook
2010-06-14 15:29         ` Alex Williamson
2010-06-14 15:42           ` Paul Brook
2010-06-14 16:00           ` Jan Kiszka
2010-06-14 16:38             ` Alex Williamson
2010-06-14 16:49               ` Jan Kiszka
2010-06-14 18:35                 ` Alex Williamson
2010-06-14 21:43                   ` Paul Brook
2010-06-14 22:11                     ` Alex Williamson
2010-06-14 22:46                       ` Paul Brook
2010-06-15  1:14                         ` Alex Williamson
2010-06-15 11:24                           ` Paul Brook
2010-06-15  8:47         ` Markus Armbruster
2010-06-15  9:34           ` Jan Kiszka
2010-06-15 11:28             ` Paul Brook
2010-06-15 11:45               ` Jan Kiszka
2010-06-15 12:04                 ` Paul Brook
2010-06-15 12:16                   ` Jan Kiszka
2010-06-15 12:39                     ` Paul Brook
2010-06-15 13:00                       ` Jan Kiszka
2010-06-15 13:14                         ` Paul Brook
2010-06-15 13:16                 ` Markus Armbruster
2010-06-15 13:32                   ` Jan Kiszka
2010-06-15 20:53               ` Alex Williamson
2010-06-15 21:55                 ` Paul Brook
2010-06-15 22:33                   ` Alex Williamson
2010-06-15 23:01                     ` Paul Brook
2010-06-15 23:10                       ` Alex Williamson
2010-06-16  0:25                       ` Chris Wright
2010-06-16  0:30                         ` Paul Brook
2010-06-16  0:35                           ` Chris Wright
2010-06-16  1:30                             ` Paul Brook
2010-06-16  2:55                               ` Alex Williamson
2010-06-16  8:23                 ` Markus Armbruster
2010-06-17 22:25                   ` Alex Williamson
2010-06-18  9:16                     ` Jan Kiszka
2010-06-18 15:01                       ` Alex Williamson
2010-06-18 15:22                         ` Jan Kiszka
2010-06-18 14:03                     ` Markus Armbruster
2010-06-18 14:14                       ` Jan Kiszka
2010-06-18 15:21                       ` Alex Williamson
2010-06-15 11:42             ` Markus Armbruster
2010-06-15 11:59               ` Jan Kiszka
2010-06-15 13:07                 ` Markus Armbruster
2010-06-15 13:19                   ` Paul Brook
2010-06-15 13:32                     ` Paul Brook
2010-06-15 15:08                   ` Jan Kiszka
2010-06-16 13:02                     ` Markus Armbruster
2010-06-14  5:51 ` [Qemu-devel] [RFC PATCH 2/5] savevm: Add DeviceState param Alex Williamson
2010-06-14  5:51 ` [Qemu-devel] [RFC PATCH 3/5] savevm: Make use of the new " Alex Williamson
2010-06-14  5:51 ` [Qemu-devel] [RFC PATCH 4/5] eepro100: Add a dev field to eeprom new/free functions Alex Williamson
2010-06-14  5:51 ` [Qemu-devel] [RFC PATCH 5/5] virtio-net: Incorporate a DeviceState pointer and let savevm track instances Alex Williamson
2010-06-14  7:02 ` [Qemu-devel] Re: [RFC PATCH 0/5] Introduce canonical device hierarchy string Gerd Hoffmann
2010-06-14 19:56   ` Alex Williamson
2010-06-15  8:53     ` Markus Armbruster
2010-06-15 18:01       ` Alex Williamson
2010-06-16  8:34         ` Markus Armbruster
2010-06-16  8:36           ` Markus Armbruster
2010-06-15  9:12     ` Gerd Hoffmann
2010-06-15 18:03       ` Alex Williamson
2010-06-16  9:46 ` RFC qdev path semantics (was: [Qemu-devel] [RFC PATCH 0/5] Introduce canonical device hierarchy string) Markus Armbruster
2010-06-16 10:40   ` Paul Brook
2010-06-16 11:37   ` [Qemu-devel] Re: RFC qdev path semantics Jan Kiszka
2010-06-16 11:45     ` Paul Brook
2010-06-16 12:01       ` Jan Kiszka
2010-06-16 12:21         ` Paul Brook
2010-06-16 13:50           ` Jan Kiszka
2010-06-16 13:05   ` Markus Armbruster
2010-06-16 13:23     ` Paul Brook
2010-06-16 14:31       ` Markus Armbruster
2010-06-17 21:43   ` Alex Williamson
2010-06-17 22:01     ` Paul Brook
2010-06-17 22:34       ` Alex Williamson
2010-06-18  7:52     ` Gerd Hoffmann
2010-06-18 14:58   ` Markus Armbruster
2010-06-22 14:27   ` Anthony Liguori

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=20100614055119.879.92321.stgit@localhost.localdomain \
    --to=alex.williamson@redhat.com \
    --cc=avi@redhat.com \
    --cc=chrisw@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=paul@codesourcery.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).