Skip to content

Commit c834dc0

Browse files
esposemkevmw
authored andcommitted
block: Convert bdrv_debug_event() to co_wrapper_mixed
bdrv_debug_event() is categorized as an I/O function, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since it traverses the block nodes graph, which however is only possible in a coroutine. Therefore turn it into a co_wrapper_mixed to move the actual function into a coroutine where the lock can be taken. Signed-off-by: Emanuele Giuseppe Esposito <[email protected]> Signed-off-by: Kevin Wolf <[email protected]> Message-Id: <[email protected]> Reviewed-by: Emanuele Giuseppe Esposito <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 2c75261 commit c834dc0

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

block.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6351,14 +6351,14 @@ BlockStatsSpecific *bdrv_get_specific_stats(BlockDriverState *bs)
63516351
return drv->bdrv_get_specific_stats(bs);
63526352
}
63536353

6354-
void bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent event)
6354+
void coroutine_fn bdrv_co_debug_event(BlockDriverState *bs, BlkdebugEvent event)
63556355
{
63566356
IO_CODE();
6357-
if (!bs || !bs->drv || !bs->drv->bdrv_debug_event) {
6357+
if (!bs || !bs->drv || !bs->drv->bdrv_co_debug_event) {
63586358
return;
63596359
}
63606360

6361-
bs->drv->bdrv_debug_event(bs, event);
6361+
bs->drv->bdrv_co_debug_event(bs, event);
63626362
}
63636363

63646364
static BlockDriverState *bdrv_find_debug_node(BlockDriverState *bs)

block/blkdebug.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,8 @@ static void process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,
836836
}
837837
}
838838

839-
static void blkdebug_debug_event(BlockDriverState *bs, BlkdebugEvent event)
839+
static void coroutine_fn
840+
blkdebug_co_debug_event(BlockDriverState *bs, BlkdebugEvent event)
840841
{
841842
BDRVBlkdebugState *s = bs->opaque;
842843
struct BlkdebugRule *rule, *next;
@@ -1086,7 +1087,7 @@ static BlockDriver bdrv_blkdebug = {
10861087
.bdrv_co_pdiscard = blkdebug_co_pdiscard,
10871088
.bdrv_co_block_status = blkdebug_co_block_status,
10881089

1089-
.bdrv_debug_event = blkdebug_debug_event,
1090+
.bdrv_co_debug_event = blkdebug_co_debug_event,
10901091
.bdrv_debug_breakpoint = blkdebug_debug_breakpoint,
10911092
.bdrv_debug_remove_breakpoint
10921093
= blkdebug_debug_remove_breakpoint,

block/io.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
12511251
goto err;
12521252
}
12531253

1254-
bdrv_debug_event(bs, BLKDBG_COR_WRITE);
1254+
bdrv_co_debug_event(bs, BLKDBG_COR_WRITE);
12551255
if (drv->bdrv_co_pwrite_zeroes &&
12561256
buffer_is_zero(bounce_buffer, pnum)) {
12571257
/* FIXME: Should we (perhaps conditionally) be setting
@@ -1496,21 +1496,21 @@ static coroutine_fn int bdrv_padding_rmw_read(BdrvChild *child,
14961496
qemu_iovec_init_buf(&local_qiov, pad->buf, bytes);
14971497

14981498
if (pad->head) {
1499-
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_HEAD);
1499+
bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_HEAD);
15001500
}
15011501
if (pad->merge_reads && pad->tail) {
1502-
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL);
1502+
bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL);
15031503
}
15041504
ret = bdrv_aligned_preadv(child, req, req->overlap_offset, bytes,
15051505
align, &local_qiov, 0, 0);
15061506
if (ret < 0) {
15071507
return ret;
15081508
}
15091509
if (pad->head) {
1510-
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_HEAD);
1510+
bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_HEAD);
15111511
}
15121512
if (pad->merge_reads && pad->tail) {
1513-
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL);
1513+
bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL);
15141514
}
15151515

15161516
if (pad->merge_reads) {
@@ -1521,15 +1521,15 @@ static coroutine_fn int bdrv_padding_rmw_read(BdrvChild *child,
15211521
if (pad->tail) {
15221522
qemu_iovec_init_buf(&local_qiov, pad->tail_buf, align);
15231523

1524-
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL);
1524+
bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL);
15251525
ret = bdrv_aligned_preadv(
15261526
child, req,
15271527
req->overlap_offset + req->overlap_bytes - align,
15281528
align, align, &local_qiov, 0, 0);
15291529
if (ret < 0) {
15301530
return ret;
15311531
}
1532-
bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL);
1532+
bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL);
15331533
}
15341534

15351535
zero_mem:
@@ -1931,16 +1931,16 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child,
19311931
if (ret < 0) {
19321932
/* Do nothing, write notifier decided to fail this request */
19331933
} else if (flags & BDRV_REQ_ZERO_WRITE) {
1934-
bdrv_debug_event(bs, BLKDBG_PWRITEV_ZERO);
1934+
bdrv_co_debug_event(bs, BLKDBG_PWRITEV_ZERO);
19351935
ret = bdrv_co_do_pwrite_zeroes(bs, offset, bytes, flags);
19361936
} else if (flags & BDRV_REQ_WRITE_COMPRESSED) {
19371937
ret = bdrv_driver_pwritev_compressed(bs, offset, bytes,
19381938
qiov, qiov_offset);
19391939
} else if (bytes <= max_transfer) {
1940-
bdrv_debug_event(bs, BLKDBG_PWRITEV);
1940+
bdrv_co_debug_event(bs, BLKDBG_PWRITEV);
19411941
ret = bdrv_driver_pwritev(bs, offset, bytes, qiov, qiov_offset, flags);
19421942
} else {
1943-
bdrv_debug_event(bs, BLKDBG_PWRITEV);
1943+
bdrv_co_debug_event(bs, BLKDBG_PWRITEV);
19441944
while (bytes_remaining) {
19451945
int num = MIN(bytes_remaining, max_transfer);
19461946
int local_flags = flags;
@@ -1963,7 +1963,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child,
19631963
bytes_remaining -= num;
19641964
}
19651965
}
1966-
bdrv_debug_event(bs, BLKDBG_PWRITEV_DONE);
1966+
bdrv_co_debug_event(bs, BLKDBG_PWRITEV_DONE);
19671967

19681968
if (ret >= 0) {
19691969
ret = 0;

include/block/block-io.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ void *qemu_try_blockalign0(BlockDriverState *bs, size_t size);
191191
void bdrv_enable_copy_on_read(BlockDriverState *bs);
192192
void bdrv_disable_copy_on_read(BlockDriverState *bs);
193193

194-
void bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent event);
194+
void coroutine_fn bdrv_co_debug_event(BlockDriverState *bs,
195+
BlkdebugEvent event);
196+
void co_wrapper_mixed bdrv_debug_event(BlockDriverState *bs,
197+
BlkdebugEvent event);
195198

196199
#define BLKDBG_EVENT(child, evt) \
197200
do { \

include/block/block_int-common.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,8 @@ struct BlockDriver {
725725
int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_check)(
726726
BlockDriverState *bs, BdrvCheckResult *result, BdrvCheckMode fix);
727727

728-
void (*bdrv_debug_event)(BlockDriverState *bs, BlkdebugEvent event);
728+
void coroutine_fn (*bdrv_co_debug_event)(BlockDriverState *bs,
729+
BlkdebugEvent event);
729730

730731
/* io queue for linux-aio */
731732
void coroutine_fn (*bdrv_co_io_plug)(BlockDriverState *bs);

0 commit comments

Comments
 (0)