Received: from eggs.gnu.org ([208.118.235.92]:38583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T5m5F-0004h6-Kn for qemu-devel@nongnu.org; Sun, 26 Aug 2012 19:17:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T5m5E-0003dE-S6 for qemu-devel@nongnu.org; Sun, 26 Aug 2012 19:17:33 -0400 Received: from cpe-70-123-140-180.austin.res.rr.com ([70.123.140.180]:50521 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T5m5E-0003cZ-Kw for qemu-devel@nongnu.org; Sun, 26 Aug 2012 19:17:32 -0400 From: Anthony Liguori Date: Sun, 26 Aug 2012 10:51:35 -0500 Message-Id: <1345996298-4892-7-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1345996298-4892-1-git-send-email-aliguori@us.ibm.com> References: <1345996298-4892-1-git-send-email-aliguori@us.ibm.com> Subject: [Qemu-devel] [PATCH 6/9] qdev: make devices created with device_add nullable so they can be deleted List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Anthony Liguori , Liu Ping Fan , Andreas Faerber A management tool can destroy these devices by writing an empty string into the child link property. Signed-off-by: Anthony Liguori --- hw/qdev-monitor.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c index 018b386..3f08575 100644 --- a/hw/qdev-monitor.c +++ b/hw/qdev-monitor.c @@ -469,15 +469,20 @@ DeviceState *qdev_device_add(QemuOpts *opts) return NULL; } if (qdev->id) { - object_property_add_child(qdev_get_peripheral(), qdev->id, - OBJECT(qdev), NULL); + object_property_add_nullable_child(qdev_get_peripheral(), qdev->id, + OBJECT(qdev), 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(qdev), NULL); + object_property_add_nullable_child(qdev_get_peripheral_anon(), name, + OBJECT(qdev), NULL); g_free(name); - } + } + + /* Drop the allocation reference -- the container link will ensure the + object stays alive. */ + object_unref(OBJECT(qdev)); + if (qdev_init(qdev) < 0) { qerror_report(QERR_DEVICE_INIT_FAILED, driver); return NULL; -- 1.7.5.4