Replace the bool DeviceState::realized field with the enum-valued
DeviceState::phase field to express finer phases in following changes.
The QOM realized property is an internal lifecycle property, not for
end users. Replace it with the enum-valued phase property.
Signed-off-by: Akihiko Odaki <[email protected]>
---
qapi/common.json | 14 ++++++++++++++
include/hw/core/qdev.h | 7 ++++---
hw/core/qdev-clock.c | 4 ++--
hw/core/qdev-properties.c | 4 ++--
hw/core/qdev.c | 45 ++++++++++++++++++++++
+----------------------
hw/scsi/scsi-bus.c | 4 ++--
qom/qom-qmp-cmds.c | 2 +-
system/qdev-monitor.c | 5 +++--
8 files changed, 51 insertions(+), 34 deletions(-)
diff --git a/qapi/common.json b/qapi/common.json
index af7e3d618a7c..415a2722fc1a 100644
--- a/qapi/common.json
+++ b/qapi/common.json
@@ -7,6 +7,20 @@
# *****************
##
+##
+# @DevicePhase:
+#
+# An enumeration of the device phases
+#
+# @unrealized: the initial phase
+#
+# @realized: the phase after realization
+#
+# Since: 11.2
+##
+{ 'enum': 'DevicePhase',
+ 'data': [ 'unrealized', 'realized' ] }
+
##
# @IoOperationType:
#
diff --git a/include/hw/core/qdev.h b/include/hw/core/qdev.h
index b1c5f4780a90..ff367b2a5f98 100644
--- a/include/hw/core/qdev.h
+++ b/include/hw/core/qdev.h
@@ -1,6 +1,7 @@
#ifndef QDEV_CORE_H
#define QDEV_CORE_H
+#include "qapi/qapi-types-common.h"
#include "qemu/atomic.h"
#include "qemu/queue.h"
#include "qemu/bitmap.h"
@@ -232,9 +233,9 @@ struct DeviceState {
*/
char *canonical_path;
/**
- * @realized: has device been realized?
+ * @phase: the current phase
*/
- bool realized;
+ DevicePhase phase;
/**
* @pending_deleted_event: track pending deletion events during
unplug
*/
@@ -440,7 +441,7 @@ DeviceState *qdev_try_new(const char *name);
*/
static inline bool qdev_is_realized(const DeviceState *dev)
{
- return qatomic_load_acquire(&dev->realized);
+ return qatomic_load_acquire(&dev->phase) == DEVICE_PHASE_REALIZED;
}
/**
diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c
index 861f78f94c64..efb33a3a27e7 100644
--- a/hw/core/qdev-clock.c
+++ b/hw/core/qdev-clock.c
@@ -30,7 +30,7 @@ static NamedClockList
*qdev_init_clocklist(DeviceState *dev, const char *name,
* Clock must be added before realize() so that we can compute the
* clock's canonical path during device_realize().
*/
- assert(!dev->realized);
+ assert(dev->phase != DEVICE_PHASE_REALIZED);
/*
* The ncl structure is freed by qdev_finalize_clocklist() which
will
@@ -186,6 +186,6 @@ Clock *qdev_alias_clock(DeviceState *dev, const
char *name,
void qdev_connect_clock_in(DeviceState *dev, const char *name, Clock
*source)
{
- assert(!dev->realized);
+ assert(dev->phase != DEVICE_PHASE_REALIZED);
clock_set_source(qdev_get_clock_in(dev, name), source);
}
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 34d7b26a7303..66cff4b9338c 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -33,7 +33,7 @@ static bool qdev_prop_allow_set(Object *obj, const
char *name,
{
DeviceState *dev = DEVICE(obj);
- if (dev->realized && !info->realized_set_allowed) {
+ if (dev->phase == DEVICE_PHASE_REALIZED && !info-
>realized_set_allowed) {
qdev_prop_set_after_realize(dev, name, errp);
return false;
}