block: add single-check guard in throttle_group_restart_queue to address race with schedule_next_request
PATCH 1/1 block: add single-check guard in throttle_group_restart_queue to address race with schedule_next_request
A race condition exists between throttle_group_restart_queue() and schedule_next_request(): when multiple ThrottleGroupMembers in the same throttle group are assigned to different IOThreads, concurrent execution can cause schedule_next_request() to re-arm a throttle timer while throttle_group_restart_queue() is being called (e.g., from a timer callback or external restart). This violates the assumption that no timer is pending upon entry to throttle_group_restart_queue(), triggering an assertion failure and causing QEMU to abort.
This patch replaces the assert with a single early-return check:
if the timer for the given direction is already pending, the function returns immediately. This prevents duplicate coroutine scheduling and avoids crashes under race conditions, without altering the core (non-thread-safe) throttle group logic.
For details, see: https://gitlab.com/qemu-project/qemu/-/issues/3194
--- block/throttle-groups.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
block/throttle-groups.c +3 -4
@@ -430,15 +430,14 @@ static void throttle_group_restart_queue(ThrottleGroupMember *tgm, ThrottleDirection direction) {Coroutine *co; +if (timer_pending (tgm->throttle_timers.timers[direction])) { +return ; + }RestartData *rd =g_new0 (RestartData,1 ); rd->tgm = tgm; rd->direction = direction; -/* This function is called when a timer is fired or when -* throttle_group_restart_tgm() is called. Either way, there can -* be no timer pending on this tgm at this point */ -assert (!timer_pending (tgm->throttle_timers.timers[direction]));qatomic_inc (&tgm->restart_pending);
Signature · 1 line
2.31.1
PATCH 1/1 mirror: Optimize mirroring for zero blocks in mirror_read_complete
When mirroring data blocks, detect if the read data consists entirely of zeros. If so, use blk_co_pwrite_zeroes() instead of regular write to improve performance.
--- block/mirror.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
block/mirror.c +27 -0
@@ -269,6 +269,33 @@ static void coroutine_fn mirror_read_complete(MirrorOp *op, int ret)return ; } +/* Check if the read data is all zeros */ +bool is_zero = true; +for (int i =0 ; i < op->qiov.niov; i++) { +if (!buffer_is_zero (op->qiov.iov[i].iov_base, + op->qiov.iov[i].iov_len)) { + is_zero = false; +break ; + } + } + +/* Write to target - optimized path for zero blocks */ +if (is_zero) { +/* +* Use zero-writing interface which may: +* 1. Avoid actual data transfer +* 2. Enable storage-level optimizations +* 3. Potentially unmap blocks (if supported) +*/ + ret =blk_co_pwrite_zeroes (s->target, op->offset, + op->qiov.size, +BDRV_REQ_MAY_UNMAP ); + }else { +/* Normal data write path */ + ret =blk_co_pwritev (s->target, op->offset, + op->qiov.size, &op->qiov,0 ); + } + ret =blk_co_pwritev (s->target, op->offset, op->qiov.size, &op->qiov,0 );mirror_write_complete (op, ret); }
Signature · 1 line
2.45.1.windows.1