block: Mark bdrv_co_refresh_total_sectors() and callers GRAPH_RDLOCK
authorKevin Wolf <kwolf@redhat.com>
Fri, 3 Feb 2023 15:22:02 +0000 (16:22 +0100)
committerKevin Wolf <kwolf@redhat.com>
Thu, 23 Feb 2023 18:49:33 +0000 (19:49 +0100)
This adds GRAPH_RDLOCK annotations to declare that callers of
bdrv_co_refresh_total_sectors() need to hold a reader lock for the
graph.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20230203152202.49054-24-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
18 files changed:
block.c
block/blkdebug.c
block/blklogwrites.c
block/blkreplay.c
block/blkverify.c
block/copy-on-read.c
block/crypto.c
block/filter-compress.c
block/mirror.c
block/preallocate.c
block/quorum.c
block/raw-format.c
block/replication.c
block/stream.c
block/throttle.c
include/block/block-io.h
include/block/block_int-common.h
include/block/block_int-io.h

diff --git a/block.c b/block.c
index c4c67d09d457e291122033c042c2d2e513279608..0dd604d0f6a8d18ab7db0130638dbcb6ec9ffeff 100644 (file)
--- a/block.c
+++ b/block.c
@@ -1042,6 +1042,7 @@ int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs,
 {
     BlockDriver *drv = bs->drv;
     IO_CODE();
+    assert_bdrv_graph_readable();
 
     if (!drv) {
         return -ENOMEDIUM;
@@ -5843,6 +5844,7 @@ int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs)
 {
     BlockDriver *drv = bs->drv;
     IO_CODE();
+    assert_bdrv_graph_readable();
 
     if (!drv)
         return -ENOMEDIUM;
@@ -5864,6 +5866,7 @@ int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs)
 {
     int64_t ret;
     IO_CODE();
+    assert_bdrv_graph_readable();
 
     ret = bdrv_co_nb_sectors(bs);
     if (ret < 0) {
index f418a90873266f929e23fef7059ba63878a97bb0..978c8cff9e334af4862c506bb84694c3adeb10d0 100644 (file)
@@ -967,7 +967,8 @@ static bool blkdebug_debug_is_suspended(BlockDriverState *bs, const char *tag)
     return false;
 }
 
-static int64_t coroutine_fn blkdebug_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK
+blkdebug_co_getlength(BlockDriverState *bs)
 {
     return bdrv_co_getlength(bs->file->bs);
 }
index 93086c31e1c31b6fae88ce8c2a8a0265c172bb22..3ea7141cb5cfc261b46de9a9ca15182c3f7103c8 100644 (file)
@@ -267,7 +267,8 @@ static void blk_log_writes_close(BlockDriverState *bs)
     s->log_file = NULL;
 }
 
-static int64_t coroutine_fn blk_log_writes_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK
+blk_log_writes_co_getlength(BlockDriverState *bs)
 {
     return bdrv_co_getlength(bs->file->bs);
 }
index bc96bbd41e2e744500badda7609ec43e0a6773ec..04f53eea417b3d977df2baf5d9f778cc6b901343 100644 (file)
@@ -40,7 +40,8 @@ fail:
     return ret;
 }
 
-static int64_t coroutine_fn blkreplay_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK
+blkreplay_co_getlength(BlockDriverState *bs)
 {
     return bdrv_co_getlength(bs->file->bs);
 }
index 8c11c2eae45ab431b37d2c33fab1198d67c49d6c..1c16f86b2e702330375adb893ead5489cfb84406 100644 (file)
@@ -155,7 +155,8 @@ static void blkverify_close(BlockDriverState *bs)
     s->test_file = NULL;
 }
 
-static int64_t coroutine_fn blkverify_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK
+blkverify_co_getlength(BlockDriverState *bs)
 {
     BDRVBlkverifyState *s = bs->opaque;
 
index 20215cff939575b8ebfce039d2b4ddef4cdc48e9..cc0f848b0f108f0b2ca7a419bd7238bf9577b220 100644 (file)
@@ -121,7 +121,7 @@ static void cor_child_perm(BlockDriverState *bs, BdrvChild *c,
 }
 
 
-static int64_t coroutine_fn cor_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK cor_co_getlength(BlockDriverState *bs)
 {
     return bdrv_co_getlength(bs->file->bs);
 }
index e77790ac8ad47b4afb2bdade1ee1fec3af5dd678..ca67289187eedecad7fcd96204d475bd069853e6 100644 (file)
@@ -530,7 +530,8 @@ static void block_crypto_refresh_limits(BlockDriverState *bs, Error **errp)
 }
 
 
-static int64_t coroutine_fn block_crypto_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK
+block_crypto_co_getlength(BlockDriverState *bs)
 {
     BlockCrypto *crypto = bs->opaque;
     int64_t len = bdrv_co_getlength(bs->file->bs);
index c7d50a67a7209cdca1d0c954db02d19e7cb63afd..ac285f4b665776f195f6c7213a53f88bcccfce55 100644 (file)
@@ -55,7 +55,8 @@ static int compress_open(BlockDriverState *bs, QDict *options, int flags,
 }
 
 
-static int64_t coroutine_fn compress_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK
+compress_co_getlength(BlockDriverState *bs)
 {
     return bdrv_co_getlength(bs->file->bs);
 }
index ec5cd22a7cca41fe0b9d743efd6e561c5bc951c6..97c6a5777d92e72d96cb160c846af822a0376317 100644 (file)
@@ -917,7 +917,10 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
         goto immediate_exit;
     }
 
+    bdrv_graph_co_rdlock();
     s->bdev_length = bdrv_co_getlength(bs);
+    bdrv_graph_co_rdunlock();
+
     if (s->bdev_length < 0) {
         ret = s->bdev_length;
         goto immediate_exit;
index 63a296882dae7c586b287ac2bd170f4ddb6b9b24..71c360180945b57f44cd8392d61daee570098a7a 100644 (file)
@@ -443,7 +443,8 @@ static int coroutine_fn GRAPH_RDLOCK preallocate_co_flush(BlockDriverState *bs)
     return bdrv_co_flush(bs->file->bs);
 }
 
-static int64_t coroutine_fn preallocate_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK
+preallocate_co_getlength(BlockDriverState *bs)
 {
     int64_t ret;
     BDRVPreallocateState *s = bs->opaque;
index d58f86d3a5101387329c5364bbf2a69c3ea14434..ff5a0a2da3e1ad593b34042d122d90a05d679589 100644 (file)
@@ -764,7 +764,8 @@ quorum_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes,
                              flags | BDRV_REQ_ZERO_WRITE);
 }
 
-static int64_t coroutine_fn quorum_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK
+quorum_co_getlength(BlockDriverState *bs)
 {
     BDRVQuorumState *s = bs->opaque;
     int64_t result;
index f4203d4806ae1aca37ed8d1ec6b59a5698a7e4d5..66783ed8e77bbc93079f88e18307020ae7c45216 100644 (file)
@@ -317,7 +317,8 @@ raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes)
     return bdrv_co_pdiscard(bs->file, offset, bytes);
 }
 
-static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK
+raw_co_getlength(BlockDriverState *bs)
 {
     int64_t len;
     BDRVRawState *s = bs->opaque;
index f9f899bfc87d34e01e427d5138c74a4be1d8bcfd..de01f9618467158130d6db712e1cbff3f49b0d3a 100644 (file)
@@ -179,7 +179,8 @@ static void replication_child_perm(BlockDriverState *bs, BdrvChild *c,
     return;
 }
 
-static int64_t coroutine_fn replication_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK
+replication_co_getlength(BlockDriverState *bs)
 {
     return bdrv_co_getlength(bs->file->bs);
 }
index 22368ce186960c0e9cc738a755323725945afa07..68018699dec0eab53eba894f4455c679d4e86fed 100644 (file)
@@ -141,9 +141,11 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
         return 0;
     }
 
-    len = bdrv_getlength(s->target_bs);
-    if (len < 0) {
-        return len;
+    WITH_GRAPH_RDLOCK_GUARD() {
+        len = bdrv_co_getlength(s->target_bs);
+        if (len < 0) {
+            return len;
+        }
     }
     job_progress_set_remaining(&s->common.job, len);
 
index 5cfea3d5f8523adcc989aa6ef4715583a1168edf..3aaef18d4ed4212ef7ee5c67fa14df78706ab263 100644 (file)
@@ -106,7 +106,8 @@ static void throttle_close(BlockDriverState *bs)
 }
 
 
-static int64_t coroutine_fn throttle_co_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn GRAPH_RDLOCK
+throttle_co_getlength(BlockDriverState *bs)
 {
     return bdrv_co_getlength(bs->file->bs);
 }
index 95bcc79b7534ac6f5cc3fe7819139c7d605e1642..5da99d4d60ff6368d355395f01ce98b05fe6e2ba 100644 (file)
@@ -78,11 +78,11 @@ int coroutine_fn GRAPH_RDLOCK
 bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
                  PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
 
-int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs);
-int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState *bs);
+int64_t coroutine_fn GRAPH_RDLOCK bdrv_co_nb_sectors(BlockDriverState *bs);
+int64_t co_wrapper_mixed_bdrv_rdlock bdrv_nb_sectors(BlockDriverState *bs);
 
-int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs);
-int64_t co_wrapper_mixed bdrv_getlength(BlockDriverState *bs);
+int64_t coroutine_fn GRAPH_RDLOCK bdrv_co_getlength(BlockDriverState *bs);
+int64_t co_wrapper_mixed_bdrv_rdlock bdrv_getlength(BlockDriverState *bs);
 
 int64_t coroutine_fn bdrv_co_get_allocated_file_size(BlockDriverState *bs);
 int64_t co_wrapper bdrv_get_allocated_file_size(BlockDriverState *bs);
index d72e31aba349f6916cb68c9b8e48e98324843499..d4190173284fa37b4053b814893bb9c2c8c06981 100644 (file)
@@ -684,7 +684,9 @@ struct BlockDriver {
         BlockDriverState *bs, int64_t offset, bool exact,
         PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
 
-    int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs);
+    int64_t coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_getlength)(
+        BlockDriverState *bs);
+
     int64_t coroutine_fn (*bdrv_co_get_allocated_file_size)(
         BlockDriverState *bs);
 
index 612e5ddf9923c2204b8fd0feb6377f82a86c6894..eb0da7232ef8def942c82977a4c492a83c76baa9 100644 (file)
@@ -124,9 +124,10 @@ bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset,
                       int64_t bytes, BdrvRequestFlags read_flags,
                       BdrvRequestFlags write_flags);
 
-int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs,
-                                               int64_t hint);
-int co_wrapper_mixed
+int coroutine_fn GRAPH_RDLOCK
+bdrv_co_refresh_total_sectors(BlockDriverState *bs, int64_t hint);
+
+int co_wrapper_mixed_bdrv_rdlock
 bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint);
 
 BdrvChild *bdrv_cow_child(BlockDriverState *bs);