Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
hw/qdev: introduce qdev_is_realized() helper
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>
  • Loading branch information
Stefan Hajnoczi authored and Kevin Wolf committed May 30, 2023
1 parent 2d19629 commit 26462a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 1 addition & 2 deletions hw/scsi/scsi-bus.c
Expand Up @@ -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;
}

Expand Down
17 changes: 14 additions & 3 deletions 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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 26462a7

Please sign in to comment.