From patchwork Sun Aug 26 15:51:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 180100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 72E852C00D4 for ; Mon, 27 Aug 2012 09:17:56 +1000 (EST) Received: from localhost ([::1]:42378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T5m5a-0004tN-E5 for incoming@patchwork.ozlabs.org; Sun, 26 Aug 2012 19:17:54 -0400 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 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu2) with ESMTP id q7QFpox8005206; Sun, 26 Aug 2012 10:51:50 -0500 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q7QFpnUp005205; Sun, 26 Aug 2012 10:51:49 -0500 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Sun, 26 Aug 2012 10:51:35 -0500 Message-Id: <1345996298-4892-7-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1345996298-4892-1-git-send-email-aliguori@us.ibm.com> References: <1345996298-4892-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.123.140.180 Cc: Paolo Bonzini , Anthony Liguori , Liu Ping Fan , Andreas Faerber Subject: [Qemu-devel] [PATCH 6/9] qdev: make devices created with device_add nullable so they can be deleted X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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;