Skip to content

Commit

Permalink
qdev: Push state up to Object
Browse files Browse the repository at this point in the history
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>
[AF: Replace state enum by realized boolean, requested by Anthony.]
Signed-off-by: Andreas Färber <afaerber@suse.de>
  • Loading branch information
bonzini authored and afaerber committed Jun 19, 2012
1 parent 496fec4 commit 09be505
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
3 changes: 2 additions & 1 deletion hw/qdev-addr.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "qemu/object.h"
#include "qdev.h"
#include "qdev-addr.h"
#include "targphys.h"
Expand Down Expand Up @@ -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;
}
Expand Down
26 changes: 13 additions & 13 deletions hw/qdev-properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 5 additions & 6 deletions hw/qdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions hw/qdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -64,7 +59,6 @@ struct DeviceState {
Object parent_obj;

const char *id;
enum DevState state;
QemuOpts *opts;
int hotplugged;
BusState *parent_bus;
Expand Down
9 changes: 9 additions & 0 deletions include/qemu/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ struct Object
QTAILQ_HEAD(, ObjectProperty) properties;
uint32_t ref;
Object *parent;
bool realized;
};

/**
Expand Down Expand Up @@ -811,6 +812,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:
*
Expand Down
5 changes: 5 additions & 0 deletions qom/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 09be505

Please sign in to comment.