diff options
author | Andreas Färber <afaerber@suse.de> | 2013-01-09 03:58:10 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2013-01-15 18:26:30 -0600 |
commit | 7983c8a335dd09fec49f99a44d4404aa87828c0a (patch) | |
tree | c69919e4bfc2de020b0d9b12df47bfd8527aa50d | |
parent | 2c9ee0291f8ca7e18f8e96a34e8f4be7867219d2 (diff) |
qdev: Fold state enum into bool realized
Whether the device was initialized or not is QOM-level information and
currently unused. Drop it from device. This leaves the boolean state of
whether or not DeviceClass::init was called or not, a.k.a. "realized".
Suggested-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r-- | hw/qdev-addr.c | 2 | ||||
-rw-r--r-- | hw/qdev-core.h | 18 | ||||
-rw-r--r-- | hw/qdev-properties-system.c | 4 | ||||
-rw-r--r-- | hw/qdev-properties.c | 24 | ||||
-rw-r--r-- | hw/qdev.c | 12 |
5 files changed, 31 insertions, 29 deletions
diff --git a/hw/qdev-addr.c b/hw/qdev-addr.c index 3bfe101d79..b4388f6a66 100644 --- a/hw/qdev-addr.c +++ b/hw/qdev-addr.c @@ -40,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 (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } diff --git a/hw/qdev-core.h b/hw/qdev-core.h index 853bd08a1f..cb6b30b82d 100644 --- a/hw/qdev-core.h +++ b/hw/qdev-core.h @@ -8,11 +8,6 @@ #include "hw/irq.h" #include "qapi/error.h" -enum DevState { - DEV_STATE_CREATED = 1, - DEV_STATE_INITIALIZED, -}; - enum { DEV_NVECTORS_UNSPECIFIED = -1, }; @@ -49,13 +44,20 @@ typedef struct DeviceClass { const char *bus_type; } DeviceClass; -/* This structure should not be accessed directly. We declare it here - so that it can be embedded in individual device state structures. */ +/** + * DeviceState: + * @realized: Indicates whether the device has been fully constructed. + * + * This structure should not be accessed directly. We declare it here + * so that it can be embedded in individual device state structures. + */ struct DeviceState { + /*< private >*/ Object parent_obj; + /*< public >*/ const char *id; - enum DevState state; + bool realized; QemuOpts *opts; int hotplugged; BusState *parent_bus; diff --git a/hw/qdev-properties-system.c b/hw/qdev-properties-system.c index c73c713080..ce0f7933e6 100644 --- a/hw/qdev-properties-system.c +++ b/hw/qdev-properties-system.c @@ -42,7 +42,7 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop, char *str; int ret; - if (dev->state != DEV_STATE_CREATED) { + if (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -254,7 +254,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque, int32_t id; NetClientState *hubport; - if (dev->state != DEV_STATE_CREATED) { + if (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index f724357ccb..a8a31f56e4 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -32,7 +32,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 (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -85,7 +85,7 @@ static void set_bit(Object *obj, Visitor *v, void *opaque, Error *local_err = NULL; bool value; - if (dev->state != DEV_STATE_CREATED) { + if (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -125,7 +125,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 (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -192,7 +192,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 (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -225,7 +225,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 (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -250,7 +250,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 (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -323,7 +323,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 (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -413,7 +413,7 @@ static void set_string(Object *obj, Visitor *v, void *opaque, Error *local_err = NULL; char *str; - if (dev->state != DEV_STATE_CREATED) { + if (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -477,7 +477,7 @@ static void set_mac(Object *obj, Visitor *v, void *opaque, int i, pos; char *str, *p; - if (dev->state != DEV_STATE_CREATED) { + if (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -569,7 +569,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 (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -640,7 +640,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 (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -708,7 +708,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque, unsigned long dom = 0, bus = 0; unsigned int slot = 0, func = 0; - if (dev->state != DEV_STATE_CREATED) { + if (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -151,7 +151,7 @@ int qdev_init(DeviceState *dev) DeviceClass *dc = DEVICE_GET_CLASS(dev); int rc; - assert(dev->state == DEV_STATE_CREATED); + assert(!dev->realized); rc = dc->init(dev); if (rc < 0) { @@ -174,7 +174,7 @@ int qdev_init(DeviceState *dev) dev->instance_id_alias, dev->alias_required_for_version); } - dev->state = DEV_STATE_INITIALIZED; + dev->realized = true; if (dev->hotplugged) { device_reset(dev); } @@ -184,7 +184,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(!dev->realized); dev->instance_id_alias = alias_id; dev->alias_required_for_version = required_for_version; } @@ -546,7 +546,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 (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } @@ -653,7 +653,7 @@ static void device_initfn(Object *obj) } dev->instance_id_alias = -1; - dev->state = DEV_STATE_CREATED; + dev->realized = false; class = object_get_class(OBJECT(dev)); do { @@ -676,7 +676,7 @@ static void device_finalize(Object *obj) BusState *bus; DeviceClass *dc = DEVICE_GET_CLASS(dev); - if (dev->state == DEV_STATE_INITIALIZED) { + if (dev->realized) { while (dev->num_child_bus) { bus = QLIST_FIRST(&dev->child_bus); qbus_free(bus); |