diff mbox series

[05/23] block: Mark bdrv_co_ioctl() and callers GRAPH_RDLOCK

Message ID 20230203152202.49054-6-kwolf@redhat.com (mailing list archive)
State New, archived
Headers show
Series block: Lock the graph, part 2 (BlockDriver callbacks) | expand

Commit Message

Kevin Wolf Feb. 3, 2023, 3:21 p.m. UTC
This adds GRAPH_RDLOCK annotations to declare that callers of
bdrv_co_ioctl() need to hold a reader lock for the graph.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 include/block/block-io.h         | 3 ++-
 include/block/block_int-common.h | 9 +++++----
 block/block-backend.c            | 1 +
 block/io.c                       | 1 +
 block/raw-format.c               | 4 ++--
 5 files changed, 11 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/include/block/block-io.h b/include/block/block-io.h
index 6303501b0f..3f42c76f23 100644
--- a/include/block/block-io.h
+++ b/include/block/block-io.h
@@ -97,7 +97,8 @@  void bdrv_aio_cancel(BlockAIOCB *acb);
 void bdrv_aio_cancel_async(BlockAIOCB *acb);
 
 /* sg packet commands */
-int coroutine_fn bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);
+int coroutine_fn GRAPH_RDLOCK
+bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);
 
 /* Ensure contents are flushed to disk.  */
 int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
index 5f0104a1af..64700daf38 100644
--- a/include/block/block_int-common.h
+++ b/include/block/block_int-common.h
@@ -714,11 +714,12 @@  struct BlockDriver {
     void coroutine_fn (*bdrv_co_lock_medium)(BlockDriverState *bs, bool locked);
 
     /* to control generic scsi devices */
-    BlockAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs,
-        unsigned long int req, void *buf,
+    BlockAIOCB *coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_aio_ioctl)(
+        BlockDriverState *bs, unsigned long int req, void *buf,
         BlockCompletionFunc *cb, void *opaque);
-    int coroutine_fn (*bdrv_co_ioctl)(BlockDriverState *bs,
-                                      unsigned long int req, void *buf);
+
+    int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_ioctl)(
+        BlockDriverState *bs, unsigned long int req, void *buf);
 
     /*
      * Returns 0 for completed check, -errno for internal errors.
diff --git a/block/block-backend.c b/block/block-backend.c
index f5d9e3e269..5c731a1c6c 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1672,6 +1672,7 @@  blk_co_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf)
     IO_CODE();
 
     blk_wait_while_drained(blk);
+    GRAPH_RDLOCK_GUARD();
 
     if (!blk_is_available(blk)) {
         return -ENOMEDIUM;
diff --git a/block/io.c b/block/io.c
index 68eaa985f5..27a2824c87 100644
--- a/block/io.c
+++ b/block/io.c
@@ -3080,6 +3080,7 @@  int coroutine_fn bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf)
     };
     BlockAIOCB *acb;
     IO_CODE();
+    assert_bdrv_graph_readable();
 
     bdrv_inc_in_flight(bs);
     if (!drv || (!drv->bdrv_aio_ioctl && !drv->bdrv_co_ioctl)) {
diff --git a/block/raw-format.c b/block/raw-format.c
index f39e1f502b..202acb1232 100644
--- a/block/raw-format.c
+++ b/block/raw-format.c
@@ -415,8 +415,8 @@  static void coroutine_fn raw_co_lock_medium(BlockDriverState *bs, bool locked)
     bdrv_co_lock_medium(bs->file->bs, locked);
 }
 
-static int coroutine_fn raw_co_ioctl(BlockDriverState *bs,
-                                     unsigned long int req, void *buf)
+static int coroutine_fn GRAPH_RDLOCK
+raw_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
 {
     BDRVRawState *s = bs->opaque;
     if (s->offset || s->has_size) {