From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59900) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLDjD-00022j-0r for qemu-devel@nongnu.org; Mon, 18 Jan 2016 12:36:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLDjA-0004J7-Ey for qemu-devel@nongnu.org; Mon, 18 Jan 2016 12:36:30 -0500 Received: from mx2.suse.de ([195.135.220.15]:56059) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLDj9-0004Hc-Vu for qemu-devel@nongnu.org; Mon, 18 Jan 2016 12:36:28 -0500 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 18 Jan 2016 18:36:24 +0100 Message-Id: <1453138585-22738-4-git-send-email-afaerber@suse.de> In-Reply-To: <1453138585-22738-1-git-send-email-afaerber@suse.de> References: <1453138585-22738-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL v2 3/4] qdev: Free QemuOpts when the QOM path goes away List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Paolo Bonzini Otherwise there is a race where the DEVICE_DELETED event has been sent bu= t attempts to reuse the ID will fail. Note that similar races exist for other QemuOpts, which this patch does not attempt to fix. For example, if the device is a block device, then unplugging it also deletes its backend. However, this backend's get deleted in drive_info_del(), which is only called when properties are destroyed. Just like device_finalize(), drive_info_del() is called some time after DEVICE_DELETED is sent. A separate patch series has been sent to plug this other bug. Character devices also have yet to be fixed. Reported-by: Michael S. Tsirkin Signed-off-by: Paolo Bonzini Reviewed-by: Markus Armbruster Signed-off-by: Andreas F=C3=A4rber --- hw/core/qdev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 2c7101d..44bf790 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -1206,7 +1206,6 @@ static void device_finalize(Object *obj) NamedGPIOList *ngl, *next; =20 DeviceState *dev =3D DEVICE(obj); - qemu_opts_del(dev->opts); =20 QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) { QLIST_REMOVE(ngl, node); @@ -1254,6 +1253,9 @@ static void device_unparent(Object *obj) qapi_event_send_device_deleted(!!dev->id, dev->id, path, &error_= abort); g_free(path); } + + qemu_opts_del(dev->opts); + dev->opts =3D NULL; } =20 static void device_class_init(ObjectClass *class, void *data) --=20 2.6.2