Received: from eggs.gnu.org ([2001:4830:134:3::10]:44502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZV6NO-000659-Li for qemu-devel@nongnu.org; Thu, 27 Aug 2015 19:14:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZV6NK-0006Lu-MJ for qemu-devel@nongnu.org; Thu, 27 Aug 2015 19:14:34 -0400 Received: from mail-qk0-x234.google.com ([2607:f8b0:400d:c09::234]:36283) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZV6NK-0006Lk-Ij for qemu-devel@nongnu.org; Thu, 27 Aug 2015 19:14:30 -0400 Received: by qkda128 with SMTP id a128so19614446qkd.3 for ; Thu, 27 Aug 2015 16:14:30 -0700 (PDT) From: Programmingkid Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Thu, 27 Aug 2015 19:14:28 -0400 Message-Id: Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH v2] qdev-monitor.c: Add device id generation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Kevin Wolf , Peter Maydell , John Snow , Jeff Cody , qemu-devel qemu-devel , Paolo Bonzini , =?iso-8859-1?Q?Andreas_F=E4rber?= 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.=20 An user-made ID cannot begin with an underscore, so there is no problem of collisions with auto-generated ID's.=20 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.=20= Signed-off-by: John Arbuckle --- 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 =3D qemu_opts_id(opts); if (id) { dev->id =3D 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 =3D g_strdup_printf("_%" PRIu64, = deviceIDCount++); + dev->id =3D (const char *) deviceIDString; } =20 - if (dev->id) { - object_property_add_child(qdev_get_peripheral(), dev->id, - OBJECT(dev), NULL); - } else { - static int anon_count; - gchar *name =3D 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); - } =20 /* set properties */ if (qemu_opt_foreach(opts, set_property, dev, &err)) { --=20 1.7.5.4