[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 14/32] hw/qdev: introduce qdev_is_realized() helper
From: |
Kevin Wolf |
Subject: |
[PULL 14/32] hw/qdev: introduce qdev_is_realized() helper |
Date: |
Tue, 30 May 2023 18:32:21 +0200 |
From: Stefan Hajnoczi <stefanha@redhat.com>
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>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20230516190238.8401-3-stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@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 7623703943..f1070d6dc7 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"
@@ -168,9 +169,6 @@ typedef struct {
/**
* 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
@@ -339,6 +337,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 3c20b47ad0..8857ff41f6 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.40.1
- [PULL 15/32] virtio-scsi: avoid race between unplug and transport event, (continued)
- [PULL 15/32] virtio-scsi: avoid race between unplug and transport event, Kevin Wolf, 2023/05/30
- [PULL 17/32] util/vhost-user-server: rename refcount to in_flight counter, Kevin Wolf, 2023/05/30
- [PULL 18/32] block/export: wait for vhost-user-blk requests when draining, Kevin Wolf, 2023/05/30
- [PULL 24/32] hw/xen: do not set is_external=true on evtchn fds, Kevin Wolf, 2023/05/30
- [PULL 26/32] block/export: don't require AioContext lock around blk_exp_ref/unref(), Kevin Wolf, 2023/05/30
- [PULL 22/32] block: drain from main loop thread in bdrv_co_yield_to_drain(), Kevin Wolf, 2023/05/30
- [PULL 30/32] virtio-scsi: implement BlockDevOps->drained_begin(), Kevin Wolf, 2023/05/30
- [PULL 07/32] raw-format: Fix open with 'file' in iothread, Kevin Wolf, 2023/05/30
- [PULL 11/32] iotests: Make verify_virtio_scsi_pci_or_ccw() public, Kevin Wolf, 2023/05/30
- [PULL 09/32] block: Take AioContext lock in bdrv_open_driver(), Kevin Wolf, 2023/05/30
- [PULL 14/32] hw/qdev: introduce qdev_is_realized() helper,
Kevin Wolf <=
- [PULL 12/32] iotests: Test blockdev-create in iothread, Kevin Wolf, 2023/05/30
- [PULL 10/32] block: Fix AioContext locking in bdrv_insert_node(), Kevin Wolf, 2023/05/30
- [PULL 23/32] xen-block: implement BlockDevOps->drained_begin(), Kevin Wolf, 2023/05/30
- [PULL 21/32] block: add blk_in_drain() API, Kevin Wolf, 2023/05/30
- [PULL 13/32] block-backend: split blk_do_set_aio_context(), Kevin Wolf, 2023/05/30
- [PULL 20/32] hw/xen: do not use aio_set_fd_handler(is_external=true) in xen_xenstore, Kevin Wolf, 2023/05/30
- [PULL 25/32] block/export: rewrite vduse-blk drain code, Kevin Wolf, 2023/05/30
- [PULL 27/32] block/fuse: do not set is_external=true on FUSE fd, Kevin Wolf, 2023/05/30
- [PULL 28/32] virtio: make it possible to detach host notifier from any thread, Kevin Wolf, 2023/05/30
- [PULL 31/32] virtio: do not set is_external=true on host notifiers, Kevin Wolf, 2023/05/30