[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 50/51] block: use co_wrapper_mixed_bdrv_rdlock in functions taking
From: |
Kevin Wolf |
Subject: |
[PULL 50/51] block: use co_wrapper_mixed_bdrv_rdlock in functions taking the rdlock |
Date: |
Wed, 14 Dec 2022 14:44:52 +0100 |
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Take the rdlock already, before we add the assertions.
All these functions either read the graph recursively, or call
BlockDriver callbacks that will eventually need to be protected by the
graph rdlock.
Do it now to all functions together, because many of these recursively
call each other.
For example, bdrv_co_truncate calls BlockDriver->bdrv_co_truncate, and
some driver callbacks implement their own .bdrv_co_truncate by calling
bdrv_flush inside. So if bdrv_flush asserts but bdrv_truncate does not
take the rdlock yet, the assertion will always fail.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-18-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/coroutines.h | 2 +-
include/block/block-io.h | 53 +++++++++++++++++++++++-----------------
2 files changed, 32 insertions(+), 23 deletions(-)
diff --git a/block/coroutines.h b/block/coroutines.h
index 17da4db963..48e9081aa1 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -71,7 +71,7 @@ nbd_co_do_establish_connection(BlockDriverState *bs, bool
blocking,
* the "I/O or GS" API.
*/
-int co_wrapper_mixed
+int co_wrapper_mixed_bdrv_rdlock
bdrv_common_block_status_above(BlockDriverState *bs,
BlockDriverState *base,
bool include_base,
diff --git a/include/block/block-io.h b/include/block/block-io.h
index 52869ea08e..2ed6214909 100644
--- a/include/block/block-io.h
+++ b/include/block/block-io.h
@@ -39,19 +39,24 @@
* to catch when they are accidentally called by the wrong API.
*/
-int co_wrapper_mixed bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
- int64_t bytes,
- BdrvRequestFlags flags);
+int co_wrapper_mixed_bdrv_rdlock
+bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int64_t bytes,
+ BdrvRequestFlags flags);
+
int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags);
-int co_wrapper_mixed bdrv_pread(BdrvChild *child, int64_t offset,
- int64_t bytes, void *buf,
- BdrvRequestFlags flags);
-int co_wrapper_mixed bdrv_pwrite(BdrvChild *child, int64_t offset,
- int64_t bytes, const void *buf,
- BdrvRequestFlags flags);
-int co_wrapper_mixed bdrv_pwrite_sync(BdrvChild *child, int64_t offset,
- int64_t bytes, const void *buf,
- BdrvRequestFlags flags);
+
+int co_wrapper_mixed_bdrv_rdlock
+bdrv_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf,
+ BdrvRequestFlags flags);
+
+int co_wrapper_mixed_bdrv_rdlock
+bdrv_pwrite(BdrvChild *child, int64_t offset,int64_t bytes,
+ const void *buf, BdrvRequestFlags flags);
+
+int co_wrapper_mixed_bdrv_rdlock
+bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes,
+ const void *buf, BdrvRequestFlags flags);
+
int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset,
int64_t bytes, const void *buf,
BdrvRequestFlags flags);
@@ -287,22 +292,26 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src,
int64_t src_offset,
void bdrv_drain(BlockDriverState *bs);
-int co_wrapper_mixed
+int co_wrapper_mixed_bdrv_rdlock
bdrv_truncate(BdrvChild *child, int64_t offset, bool exact,
PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
-int co_wrapper_mixed bdrv_check(BlockDriverState *bs, BdrvCheckResult *res,
- BdrvCheckMode fix);
+int co_wrapper_mixed_bdrv_rdlock
+bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
/* Invalidate any cached metadata used by image formats */
-int co_wrapper_mixed bdrv_invalidate_cache(BlockDriverState *bs,
- Error **errp);
-int co_wrapper_mixed bdrv_flush(BlockDriverState *bs);
-int co_wrapper_mixed bdrv_pdiscard(BdrvChild *child, int64_t offset,
- int64_t bytes);
-int co_wrapper_mixed
+int co_wrapper_mixed_bdrv_rdlock
+bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
+
+int co_wrapper_mixed_bdrv_rdlock bdrv_flush(BlockDriverState *bs);
+
+int co_wrapper_mixed_bdrv_rdlock
+bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes);
+
+int co_wrapper_mixed_bdrv_rdlock
bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
-int co_wrapper_mixed
+
+int co_wrapper_mixed_bdrv_rdlock
bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
/**
--
2.38.1
- [PULL 48/51] Mark assert_bdrv_graph_readable/writable() GRAPH_RD/WRLOCK, (continued)
- [PULL 48/51] Mark assert_bdrv_graph_readable/writable() GRAPH_RD/WRLOCK, Kevin Wolf, 2022/12/14
- [PULL 24/51] block/vmdk: add coroutine_fn annotations, Kevin Wolf, 2022/12/14
- [PULL 28/51] block: rename generated_co_wrapper in co_wrapper_mixed, Kevin Wolf, 2022/12/14
- [PULL 39/51] clang-tsa: Add TSA_ASSERT() macro, Kevin Wolf, 2022/12/14
- [PULL 35/51] graph-lock: Introduce a lock to protect block graph operations, Kevin Wolf, 2022/12/14
- [PULL 43/51] block: Fix locking in external_snapshot_prepare(), Kevin Wolf, 2022/12/14
- [PULL 47/51] graph-lock: TSA annotations for lock/unlock functions, Kevin Wolf, 2022/12/14
- [PULL 33/51] block/dirty-bitmap: convert coroutine-only functions to co_wrapper, Kevin Wolf, 2022/12/14
- [PULL 42/51] test-bdrv-drain: Fix incorrrect drain assumptions, Kevin Wolf, 2022/12/14
- [PULL 46/51] block: assert that graph read and writes are performed correctly, Kevin Wolf, 2022/12/14
- [PULL 50/51] block: use co_wrapper_mixed_bdrv_rdlock in functions taking the rdlock,
Kevin Wolf <=
- [PULL 51/51] block: GRAPH_RDLOCK for functions only called by co_wrappers, Kevin Wolf, 2022/12/14
- Re: [PULL 00/51] Block layer patches, Peter Maydell, 2022/12/14