From patchwork Mon Nov 25 22:48:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bandan Das X-Patchwork-Id: 294132 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CC9622C00AA for ; Tue, 26 Nov 2013 09:51:28 +1100 (EST) Received: from localhost ([::1]:55491 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vl502-0005nK-99 for incoming@patchwork.ozlabs.org; Mon, 25 Nov 2013 17:51:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vl4yS-00044E-7s for qemu-devel@nongnu.org; Mon, 25 Nov 2013 17:49:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vl4yL-000797-Ql for qemu-devel@nongnu.org; Mon, 25 Nov 2013 17:49:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48332) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vl4yL-00078z-I9 for qemu-devel@nongnu.org; Mon, 25 Nov 2013 17:49:41 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAPMne54000817 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Nov 2013 17:49:40 -0500 Received: from nelium.bos.redhat.com ([10.18.25.173]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rAPMnTxU006408; Mon, 25 Nov 2013 17:49:39 -0500 From: Bandan Das To: qemu-devel@nongnu.org Date: Mon, 25 Nov 2013 17:48:41 -0500 Message-Id: <1385419722-22205-3-git-send-email-bsd@redhat.com> In-Reply-To: <1385419722-22205-1-git-send-email-bsd@redhat.com> References: <1385419722-22205-1-git-send-email-bsd@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [RFC PATCH 2/3] qdev: Integrate the bus realized property to get 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 This introduces three changes - first, it sets the realized property for BusState in the setter functions for DeviceState so that a call to the (device) setter will also set the value for any children buses appropriately. Second, it introduces a bool called realized_cache that tracks the most recent value of the "realized" property so that an event can be sent when the device is being removed. Third, it reorders code in device_unparent so that unrealize can be recursively called for its children Signed-off-by: Bandan Das --- hw/core/qdev.c | 57 +++++++++++++++++++++++++++++++++++++++++--------- include/hw/qdev-core.h | 1 + 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index b503cc8..a51238c 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -740,7 +740,9 @@ static void device_set_realized(Object *obj, bool value, Error **err) { DeviceState *dev = DEVICE(obj); DeviceClass *dc = DEVICE_GET_CLASS(dev); + BusState *bus; Error *local_err = NULL; + bool rcache = dev->realized_cache; if (value && !dev->realized) { if (!obj->parent && local_err == NULL) { @@ -753,8 +755,13 @@ static void device_set_realized(Object *obj, bool value, Error **err) g_free(name); } + dev->realized_cache = true; + if (dc->realize) { dc->realize(dev, &local_err); + if (local_err != NULL) { + goto error; + } } if (qdev_get_vmsd(dev) && local_err == NULL) { @@ -762,24 +769,50 @@ static void device_set_realized(Object *obj, bool value, Error **err) dev->instance_id_alias, dev->alias_required_for_version); } + + QLIST_FOREACH(bus, &dev->child_bus, sibling) { + object_property_set_bool(OBJECT(bus), true, + "realized", &local_err); + + if (local_err != NULL) { + goto error; + } + } + if (dev->hotplugged && local_err == NULL) { device_reset(dev); } + } else if (!value && dev->realized) { + + QLIST_FOREACH(bus, &dev->child_bus, sibling) { + object_property_set_bool(OBJECT(bus), false, + "realized", &local_err); + + if (local_err != NULL) { + goto error; + } + } + if (qdev_get_vmsd(dev)) { vmstate_unregister(dev, qdev_get_vmsd(dev), dev); } + if (dc->unrealize) { dc->unrealize(dev, &local_err); - } - } - if (local_err != NULL) { - error_propagate(err, local_err); - return; + if (local_err != NULL) { + goto error; + } + } } dev->realized = value; + return; + +error: + dev->realized_cache = rcache; + error_propagate(err, local_err); } static void device_initfn(Object *obj) @@ -796,6 +829,7 @@ static void device_initfn(Object *obj) dev->instance_id_alias = -1; dev->realized = false; + dev->realized_cache = false; object_property_add_bool(obj, "realized", device_get_realized, device_set_realized, NULL); @@ -854,15 +888,17 @@ static void device_unparent(Object *obj) DeviceState *dev = DEVICE(obj); BusState *bus; QObject *event_data; - bool have_realized = dev->realized; + /* Call this first so that the change can propagate */ + + if (dev->realized) { + object_property_set_bool(obj, false, "realized", NULL); + } while (dev->num_child_bus) { bus = QLIST_FIRST(&dev->child_bus); qbus_free(bus); } - if (dev->realized) { - object_property_set_bool(obj, false, "realized", NULL); - } + if (dev->parent_bus) { bus_remove_child(dev->parent_bus, dev); object_unref(OBJECT(dev->parent_bus)); @@ -870,9 +906,10 @@ static void device_unparent(Object *obj) } /* Only send event if the device had been completely realized */ - if (have_realized) { + if (!dev->realized && dev->realized_cache) { gchar *path = object_get_canonical_path(OBJECT(dev)); + dev->realized_cache = false; if (dev->id) { event_data = qobject_from_jsonf("{ 'device': %s, 'path': %s }", dev->id, path); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 405b029..82f86e7 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -142,6 +142,7 @@ struct DeviceState { int num_child_bus; int instance_id_alias; int alias_required_for_version; + bool realized_cache; }; #define TYPE_BUS "bus"