From patchwork Sun Jun 10 01:09:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 163966 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 E193BB6F13 for ; Sun, 10 Jun 2012 11:09:50 +1000 (EST) Received: from localhost ([::1]:60200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SdWf6-0003bJ-JZ for incoming@patchwork.ozlabs.org; Sat, 09 Jun 2012 21:09:48 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55432) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SdWek-0003TG-7i for qemu-devel@nongnu.org; Sat, 09 Jun 2012 21:09:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SdWeg-0001Zi-Vy for qemu-devel@nongnu.org; Sat, 09 Jun 2012 21:09:25 -0400 Received: from cantor2.suse.de ([195.135.220.15]:52226 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SdWeg-0001ZN-JW for qemu-devel@nongnu.org; Sat, 09 Jun 2012 21:09:22 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 8B7349A78E; Sun, 10 Jun 2012 03:09:21 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Sun, 10 Jun 2012 03:09:04 +0200 Message-Id: <1339290549-3789-3-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1339290549-3789-1-git-send-email-afaerber@suse.de> References: <1339290549-3789-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori Subject: [Qemu-devel] [PATCH qom-next v2 2/7] qdev: Push state up to Object 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 From: Paolo Bonzini 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 [AF: Replace state enum by realized boolean, requested by Anthony.] Signed-off-by: Andreas Färber --- hw/qdev-addr.c | 3 ++- hw/qdev-properties.c | 26 +++++++++++++------------- hw/qdev.c | 11 +++++------ hw/qdev.h | 6 ------ include/qemu/object.h | 9 +++++++++ qom/object.c | 5 +++++ 6 files changed, 34 insertions(+), 26 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 099a7aa..fcc0bed 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; } @@ -766,7 +766,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; } @@ -797,7 +797,7 @@ static void set_pci_devfn(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; } @@ -867,7 +867,7 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque, const int64_t min = 512; const int64_t max = 32768; - 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 b20b34d..5580fc1 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -155,7 +155,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) { @@ -178,7 +178,7 @@ int qdev_init(DeviceState *dev) dev->instance_id_alias, dev->alias_required_for_version); } - dev->state = DEV_STATE_INITIALIZED; + OBJECT(dev)->realized = true; if (dev->hotplugged) { device_reset(dev); } @@ -188,7 +188,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; } @@ -567,7 +567,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; } @@ -674,7 +674,6 @@ static void device_initfn(Object *obj) } dev->instance_id_alias = -1; - dev->state = DEV_STATE_CREATED; class = object_get_class(OBJECT(dev)); do { @@ -697,7 +696,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 ae1d281..a1e40c5 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -19,11 +19,6 @@ typedef struct BusState BusState; typedef struct BusClass BusClass; -enum DevState { - DEV_STATE_CREATED = 1, - DEV_STATE_INITIALIZED, -}; - enum { DEV_NVECTORS_UNSPECIFIED = -1, }; @@ -64,7 +59,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 8b17776..0a3828d 100644 --- a/include/qemu/object.h +++ b/include/qemu/object.h @@ -264,6 +264,7 @@ struct Object QTAILQ_HEAD(, ObjectProperty) properties; uint32_t ref; Object *parent; + bool realized; }; /** @@ -812,6 +813,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 00bb3b0..8d10a27 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1237,6 +1237,11 @@ static char *qdev_get_type(Object *obj, Error **errp) return g_strdup(object_get_typename(obj)); } +bool object_is_realized(Object *obj) +{ + return obj->realized; +} + static void object_instance_init(Object *obj) { object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);