qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Bandan Das <bsd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [RFC PATCH 2/3] qdev: Integrate the bus realized property to get
Date: Mon, 25 Nov 2013 17:48:41 -0500	[thread overview]
Message-ID: <1385419722-22205-3-git-send-email-bsd@redhat.com> (raw)
In-Reply-To: <1385419722-22205-1-git-send-email-bsd@redhat.com>

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 <bsd@redhat.com>
---
 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"
-- 
1.8.3.1

  parent reply	other threads:[~2013-11-25 22:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-25 22:48 [Qemu-devel] [RFC PATCH 0/3] Add realize unrealize interfaces for BusState Bandan Das
2013-11-25 22:48 ` [Qemu-devel] [RFC PATCH 1/3] qdev: add realize/unrealize " Bandan Das
2013-11-25 22:48 ` Bandan Das [this message]
2013-11-25 22:48 ` [Qemu-devel] [RFC PATCH 3/3] pci: move vmstate_pcibus registration/unregistration to realize and unrealize interfaces Bandan Das
2014-03-12 20:29   ` Michael S. Tsirkin
2013-12-11 15:27 ` [Qemu-devel] [RFC PATCH 0/3] Add realize unrealize interfaces for BusState Bandan Das
2014-03-12 20:38   ` Andreas Färber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1385419722-22205-3-git-send-email-bsd@redhat.com \
    --to=bsd@redhat.com \
    --cc=afaerber@suse.de \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).