qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, afaerber@suse.de
Subject: [Qemu-devel] [PATCH 19/25] qom: push state up to Object
Date: Tue,  3 Apr 2012 13:15:47 +0200	[thread overview]
Message-ID: <1333451753-3550-20-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1333451753-3550-1-git-send-email-pbonzini@redhat.com>

qdev properties use the state member (an embryo of the "realized"
property) in order to disable setting them after a device has been
initialized.  So, in order to push qdev properties up to Object
we need to push this bit there too.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/qdev-addr.c        |    3 ++-
 hw/qdev-properties.c  |   24 ++++++++++++------------
 hw/qdev.c             |   11 +++++------
 hw/qdev.h             |    6 ------
 include/qemu/object.h |   14 ++++++++++++++
 qom/object.c          |    6 ++++++
 6 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/hw/qdev-addr.c b/hw/qdev-addr.c
index b711b6b..a3796bd 100644
--- a/hw/qdev-addr.c
+++ b/hw/qdev-addr.c
@@ -1,3 +1,4 @@
+#include "qemu/object.h"
 #include "qdev.h"
 #include "qdev-addr.h"
 #include "targphys.h"
@@ -39,7 +40,7 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     int64_t value;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index ffd601a..282cf68 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -53,7 +53,7 @@ static void set_bit(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     bool value;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -93,7 +93,7 @@ static void set_uint8(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -160,7 +160,7 @@ static void set_uint16(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -193,7 +193,7 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -218,7 +218,7 @@ static void set_int32(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     int32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -291,7 +291,7 @@ static void set_uint64(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -379,7 +379,7 @@ static void set_string(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     char *str;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -457,7 +457,7 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
     char *str;
     int ret;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -626,7 +626,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
     int64_t id;
     VLANState *vlan;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -696,7 +696,7 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
     int i, pos;
     char *str, *p;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -764,7 +764,7 @@ static void set_enum(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     int *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -795,7 +795,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     char *str = (char *)"";
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
diff --git a/hw/qdev.c b/hw/qdev.c
index 9e7a4b7..12752e9 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -124,7 +124,7 @@ int qdev_init(DeviceState *dev)
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
     int rc;
 
-    assert(dev->state == DEV_STATE_CREATED);
+    assert(!object_is_realized(OBJECT(dev)));
 
     rc = dc->init(dev);
     if (rc < 0) {
@@ -146,7 +146,7 @@ int qdev_init(DeviceState *dev)
                                        dev->instance_id_alias,
                                        dev->alias_required_for_version);
     }
-    dev->state = DEV_STATE_INITIALIZED;
+    OBJECT(dev)->state = OBJECT_STATE_REALIZED;
     if (dev->hotplugged) {
         device_reset(dev);
     }
@@ -156,7 +156,7 @@ int qdev_init(DeviceState *dev)
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
                                  int required_for_version)
 {
-    assert(dev->state == DEV_STATE_CREATED);
+    assert(!object_is_realized(OBJECT(dev)));
     dev->instance_id_alias = alias_id;
     dev->alias_required_for_version = required_for_version;
 }
@@ -515,7 +515,7 @@ static void qdev_set_legacy_property(Object *obj, Visitor *v, void *opaque,
     char *ptr = NULL;
     int ret;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -619,7 +619,6 @@ static void device_initfn(Object *obj)
     }
 
     dev->instance_id_alias = -1;
-    dev->state = DEV_STATE_CREATED;
 
     class = object_get_class(OBJECT(dev));
     do {
@@ -639,7 +638,7 @@ static void device_finalize(Object *obj)
     BusState *bus;
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (dev->state == DEV_STATE_INITIALIZED) {
+    if (object_is_realized(obj)) {
         while (dev->num_child_bus) {
             bus = QLIST_FIRST(&dev->child_bus);
             qbus_free(bus);
diff --git a/hw/qdev.h b/hw/qdev.h
index a159b94..a21633b 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -18,11 +18,6 @@ typedef struct BusState BusState;
 
 typedef struct BusInfo BusInfo;
 
-enum DevState {
-    DEV_STATE_CREATED = 1,
-    DEV_STATE_INITIALIZED,
-};
-
 enum {
     DEV_NVECTORS_UNSPECIFIED = -1,
 };
@@ -63,7 +58,6 @@ struct DeviceState {
     Object parent_obj;
 
     const char *id;
-    enum DevState state;
     QemuOpts *opts;
     int hotplugged;
     BusState *parent_bus;
diff --git a/include/qemu/object.h b/include/qemu/object.h
index 80f2bf3..a7e5fc2 100644
--- a/include/qemu/object.h
+++ b/include/qemu/object.h
@@ -241,6 +241,11 @@ struct ObjectClass
     Type type;
 };
 
+typedef enum ObjectState {
+    OBJECT_STATE_CREATED = 1,
+    OBJECT_STATE_REALIZED,
+} ObjectState;
+
 /**
  * Object:
  *
@@ -264,6 +269,7 @@ struct Object
     QTAILQ_HEAD(, ObjectProperty) properties;
     uint32_t ref;
     Object *parent;
+    ObjectState state;
 };
 
 /**
@@ -812,6 +818,14 @@ const char *object_property_get_type(Object *obj, const char *name,
 Object *object_get_root(void);
 
 /**
+ * object_is_realized:
+ * @obj: the object
+ *
+ * Returns whether @obj has been realized (i.e. completely constructed).
+ */
+bool object_is_realized(Object *obj);
+
+/**
  * object_get_canonical_path:
  *
  * Returns: The canonical path for a object.  This is the path within the
diff --git a/qom/object.c b/qom/object.c
index 488047c..65eaa84 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1220,9 +1220,15 @@ static char *qdev_get_type(Object *obj, Error **errp)
     return g_strdup(object_get_typename(obj));
 }
 
+bool object_is_realized(Object *obj)
+{
+    return obj->state == OBJECT_STATE_REALIZED;
+}
+
 static void object_instance_init(Object *obj)
 {
     object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
+    obj->state = OBJECT_STATE_CREATED;
 }
 
 static void register_types(void)
-- 
1.7.9.3

  parent reply	other threads:[~2012-04-03 11:17 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-03 11:15 [Qemu-devel] [PATCH 00/25] qdev properties final installment: push, push! Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 01/25] qom: add object_class_get_parent Paolo Bonzini
2012-04-03 20:50   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 02/25] qom: add object_child_foreach Paolo Bonzini
2012-04-03 20:51   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 03/25] qom: add class_base_init Paolo Bonzini
2012-04-03 20:51   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 04/25] qom: make Object a type Paolo Bonzini
2012-04-03 12:30   ` Andreas Färber
2012-04-03 13:06     ` Paolo Bonzini
2012-04-03 20:52   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 05/25] qom: push type up to Object Paolo Bonzini
2012-04-03 12:33   ` Andreas Färber
2012-04-03 20:55   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 06/25] qdev: fix -device foo,? Paolo Bonzini
2012-04-03 20:59   ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree Paolo Bonzini
2012-04-03 12:28   ` Jan Kiszka
2012-04-03 13:05     ` Paolo Bonzini
2012-05-11 14:10       ` Andreas Färber
2012-05-16  7:40         ` Paolo Bonzini
2012-05-16  7:43           ` Paolo Bonzini
2012-04-03 21:06   ` Anthony Liguori
2012-05-10 20:58     ` Jan Kiszka
2012-05-11 11:28       ` Paolo Bonzini
2012-05-11 11:38         ` Andreas Färber
2012-04-03 11:15 ` [Qemu-devel] [PATCH 08/25] qdev: remove qdev_prop_set_defaults Paolo Bonzini
2012-04-03 21:09   ` Anthony Liguori
2012-04-03 21:43     ` Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 09/25] qdev: move bus properties to a separate global Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 10/25] qdev: do not propagate properties to subclasses Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 11/25] qdev: pick global properties from superclasses Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 12/25] qdev: factor setting of global properties Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 13/25] qdev: replace bus properties with superclass properties Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 14/25] qapi: add Visitor interfaces for uint*_t and int*_t Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 15/25] qdev: use int32_t container for devfn property Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 16/25] qdev: switch property accessors to fixed-width visitor interfaces Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 17/25] qdev: remove PropertyInfo range checking Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 18/25] qdev: remove qdev_prop_exists Paolo Bonzini
2012-04-03 11:15 ` Paolo Bonzini [this message]
2012-04-03 11:15 ` [Qemu-devel] [PATCH 20/25] qdev: generalize properties to Objects Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 21/25] qdev: move bulk of qdev-properties.c to qom/object.c Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 22/25] qom: push static properties to Object Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 23/25] qom: add realized property Paolo Bonzini
2012-04-03 12:11   ` Andreas Färber
2012-04-03 13:03     ` Paolo Bonzini
2012-04-05 12:04       ` Andreas Färber
2012-04-05 12:36         ` Paolo Bonzini
2012-04-05 13:31           ` Andreas Färber
2012-04-05 14:16             ` Paolo Bonzini
2012-04-05 15:13               ` Anthony Liguori
2012-05-09 20:01   ` Igor Mammedov
2012-05-10  7:05     ` Paolo Bonzini
2012-05-10 10:01       ` Andreas Färber
2012-05-10 12:19         ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 24/25] qdev: implement qdev_init on top of realize Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 25/25] qdev: split part of device_finalize to device_unrealize Paolo Bonzini

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=1333451753-3550-20-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@us.ibm.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).