[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 17/20] block-gen: assert that bdrv_co_pdiscard is always called w
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH 17/20] block-gen: assert that bdrv_co_pdiscard is always called with graph rdlock taken |
Date: |
Wed, 16 Nov 2022 08:48:47 -0500 |
This function, in addition to be called by a generated_co_wrapper,
is also called by the blk_* API.
The strategy is to always take the lock at the function called
when the coroutine is created, to avoid recursive locking.
Protecting bdrv_co_pdiscard{_snapshot}() implies that the following BlockDriver
callbacks always called with graph rdlock taken:
- bdrv_co_pdiscard
- bdrv_aio_pdiscard
- bdrv_co_pdiscard_snapshot
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block/block-backend.c | 1 +
block/io.c | 2 ++
include/block/block_int-common.h | 3 +++
3 files changed, 6 insertions(+)
diff --git a/block/block-backend.c b/block/block-backend.c
index d660772375..211a813523 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1716,6 +1716,7 @@ blk_co_do_pdiscard(BlockBackend *blk, int64_t offset,
int64_t bytes)
IO_CODE();
blk_wait_while_drained(blk);
+ GRAPH_RDLOCK_GUARD();
ret = blk_check_byte_request(blk, offset, bytes);
if (ret < 0) {
diff --git a/block/io.c b/block/io.c
index c9b451fecd..bc9f47538c 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2885,6 +2885,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child,
int64_t offset,
int head, tail, align;
BlockDriverState *bs = child->bs;
IO_CODE();
+ assert_bdrv_graph_readable();
if (!bs || !bs->drv || !bdrv_is_inserted(bs)) {
return -ENOMEDIUM;
@@ -3488,6 +3489,7 @@ bdrv_co_pdiscard_snapshot(BlockDriverState *bs, int64_t
offset, int64_t bytes)
BlockDriver *drv = bs->drv;
int ret;
IO_CODE();
+ assert_bdrv_graph_readable();
if (!drv) {
return -ENOMEDIUM;
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
index 568c2d3092..7c34a8e40f 100644
--- a/include/block/block_int-common.h
+++ b/include/block/block_int-common.h
@@ -486,6 +486,7 @@ struct BlockDriver {
BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque);
BlockAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs,
BlockCompletionFunc *cb, void *opaque);
+ /* Called with graph rdlock taken. */
BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs,
int64_t offset, int bytes,
BlockCompletionFunc *cb, void *opaque);
@@ -559,6 +560,7 @@ struct BlockDriver {
*/
int coroutine_fn (*bdrv_co_pwrite_zeroes)(BlockDriverState *bs,
int64_t offset, int64_t bytes, BdrvRequestFlags flags);
+ /* Called with graph rdlock taken. */
int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs,
int64_t offset, int64_t bytes);
@@ -647,6 +649,7 @@ struct BlockDriver {
int coroutine_fn (*bdrv_co_snapshot_block_status)(BlockDriverState *bs,
bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum,
int64_t *map, BlockDriverState **file);
+ /* Called with graph rdlock taken. */
int coroutine_fn (*bdrv_co_pdiscard_snapshot)(BlockDriverState *bs,
int64_t offset, int64_t bytes);
--
2.31.1
- [PATCH 16/20] block-gen: assert that bdrv_co_{read/write}v_vmstate are always called with graph rdlock taken, (continued)
- [PATCH 16/20] block-gen: assert that bdrv_co_{read/write}v_vmstate are always called with graph rdlock taken, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 04/20] block.c: wrlock in bdrv_replace_child_noperm, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 20/20] block-gen: assert that nbd_co_do_establish_connection is always called with graph rdlock taken, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 09/20] block-backend: introduce new generated_co_wrapper_blk annotation, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 07/20] graph-lock: implement WITH_GRAPH_RDLOCK_GUARD and GRAPH_RDLOCK_GUARD macros, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 10/20] block-gen: assert that {bdrv/blk}_co_truncate is always called with graph rdlock taken, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 03/20] async: register/unregister aiocontext in graph lock list, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 05/20] block: remove unnecessary assert_bdrv_graph_writable(), Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 14/20] block-gen: assert that bdrv_co_pread is always called with graph rdlock taken, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 15/20] block-gen: assert that {bdrv/blk}_co_flush is always called with graph rdlock taken, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 17/20] block-gen: assert that bdrv_co_pdiscard is always called with graph rdlock taken,
Emanuele Giuseppe Esposito <=
- Re: [PATCH 00/20] Protect the block layer with a rwlock: part 1, Emanuele Giuseppe Esposito, 2022/11/21