[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 01/16] hw/qdev: introduce qdev_is_realized() helper
From: |
Stefan Hajnoczi |
Subject: |
[PATCH v2 01/16] hw/qdev: introduce qdev_is_realized() helper |
Date: |
Wed, 19 Apr 2023 13:28:02 -0400 |
Add a helper function to check whether the device is realized without
requiring the Big QEMU Lock. The next patch adds a second caller. The
goal is to avoid spreading DeviceState field accesses throughout the
code.
Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/hw/qdev-core.h | 17 ++++++++++++++---
hw/scsi/scsi-bus.c | 3 +--
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index bd50ad5ee1..4d734cf35e 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -1,6 +1,7 @@
#ifndef QDEV_CORE_H
#define QDEV_CORE_H
+#include "qemu/atomic.h"
#include "qemu/queue.h"
#include "qemu/bitmap.h"
#include "qemu/rcu.h"
@@ -164,9 +165,6 @@ struct NamedClockList {
/**
* DeviceState:
- * @realized: Indicates whether the device has been fully constructed.
- * When accessed outside big qemu lock, must be accessed with
- * qatomic_load_acquire()
* @reset: ResettableState for the device; handled by Resettable interface.
*
* This structure should not be accessed directly. We declare it here
@@ -332,6 +330,19 @@ DeviceState *qdev_new(const char *name);
*/
DeviceState *qdev_try_new(const char *name);
+/**
+ * qdev_is_realized:
+ * @dev: The device to check.
+ *
+ * May be called outside big qemu lock.
+ *
+ * Returns: %true% if the device has been fully constructed, %false% otherwise.
+ */
+static inline bool qdev_is_realized(DeviceState *dev)
+{
+ return qatomic_load_acquire(&dev->realized);
+}
+
/**
* qdev_realize: Realize @dev.
* @dev: device to realize
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index c97176110c..07275fb631 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -60,8 +60,7 @@ static SCSIDevice *do_scsi_device_find(SCSIBus *bus,
* the user access the device.
*/
- if (retval && !include_unrealized &&
- !qatomic_load_acquire(&retval->qdev.realized)) {
+ if (retval && !include_unrealized && !qdev_is_realized(&retval->qdev)) {
retval = NULL;
}
--
2.39.2
- [PATCH v2 00/16] block: remove aio_disable_external() API, Stefan Hajnoczi, 2023/04/19
- [PATCH v2 01/16] hw/qdev: introduce qdev_is_realized() helper,
Stefan Hajnoczi <=
- [PATCH v2 02/16] virtio-scsi: avoid race between unplug and transport event, Stefan Hajnoczi, 2023/04/19
- [PATCH v2 03/16] virtio-scsi: stop using aio_disable_external() during unplug, Stefan Hajnoczi, 2023/04/19
- [PATCH v2 04/16] block/export: only acquire AioContext once for vhost_user_server_stop(), Stefan Hajnoczi, 2023/04/19
- [PATCH v2 05/16] util/vhost-user-server: rename refcount to in_flight counter, Stefan Hajnoczi, 2023/04/19
- [PATCH v2 06/16] block/export: wait for vhost-user-blk requests when draining, Stefan Hajnoczi, 2023/04/19
- [PATCH v2 07/16] block/export: stop using is_external in vhost-user-blk server, Stefan Hajnoczi, 2023/04/19
- [PATCH v2 09/16] block: add blk_in_drain() API, Stefan Hajnoczi, 2023/04/19
- [PATCH v2 08/16] hw/xen: do not use aio_set_fd_handler(is_external=true) in xen_xenstore, Stefan Hajnoczi, 2023/04/19