qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] qdev-monitor.c: Add device id generation
@ 2015-08-27 23:14 Programmingkid
  2015-08-28  8:58 ` Daniel P. Berrange
  0 siblings, 1 reply; 2+ messages in thread
From: Programmingkid @ 2015-08-27 23:14 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Kevin Wolf, Peter Maydell, John Snow, Jeff Cody,
	qemu-devel qemu-devel, Paolo Bonzini, Andreas Färber

Add device ID generation to each device if an ID isn't given.

An auto-generated ID will begin with an underscore character. This will
distinguish it from user-made ID's. 

An user-made ID cannot begin with an underscore, so there is no
problem of collisions with auto-generated ID's. 

A management program like libvirt should have no problems with this
patch since the names for ID's it gives do not start with an underscore. 

Signed-off-by: John Arbuckle <programmingkidx@gmail.com>

---
 qdev-monitor.c |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index f9e2d62..a9beb6d 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -574,18 +574,17 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
     id = qemu_opts_id(opts);
     if (id) {
         dev->id = id;
+    } else { /* create an ID for a device if none is provided */
+        static uint64_t deviceIDCount;
+        char *deviceIDString;
+
+        /* Add an underscore to show this ID is auto-generated */
+        deviceIDString = g_strdup_printf("_%" PRIu64, deviceIDCount++);
+        dev->id = (const char *) deviceIDString;
     }
 
-    if (dev->id) {
-        object_property_add_child(qdev_get_peripheral(), dev->id,
-                                  OBJECT(dev), NULL);
-    } else {
-        static int anon_count;
-        gchar *name = g_strdup_printf("device[%d]", anon_count++);
-        object_property_add_child(qdev_get_peripheral_anon(), name,
+    object_property_add_child(qdev_get_peripheral(), dev->id,
                                   OBJECT(dev), NULL);
-        g_free(name);
-    }
 
     /* set properties */
     if (qemu_opt_foreach(opts, set_property, dev, &err)) {
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-08-28  8:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-27 23:14 [Qemu-devel] [PATCH v2] qdev-monitor.c: Add device id generation Programmingkid
2015-08-28  8:58 ` Daniel P. Berrange

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).