qemu/include/block
Denis V. Lunev 16f94ef4c6 block/qapi: take stats->lock when reading BlockAcctStats for query-blockstats
bdrv_query_blk_stats() reads BlockAcctStats's counters, latency
histogram, and per-interval TimedAverage stats without stats->lock,
while block_account_one_io() updates the same fields under that lock
from an iothread. timed_average_min()/max()/avg() make this worse
than a stale read: they call check_expirations(), which can reset a
window's sum/count/min/max -- a write, not just a read -- so this is
a genuine race with a concurrent writer, not merely a slower reader
like the scalar counters.

Take stats->lock for the whole call, both to close the race and to
make the returned snapshot internally consistent (previously each
field could reflect a different instant relative to concurrent
updates).

block_acct_queue_depth() used to take the lock itself on every call;
since bdrv_query_blk_stats() is its only caller and now already holds
the lock, that would self-deadlock. Make it require the caller to
hold stats->lock instead (documented and asserted).

Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Kevin Wolf <kwolf@redhat.com>
CC: Hanna Reitz <hreitz@redhat.com>
CC: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
CC: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Message-ID: <20260724111311.4086859-3-den@openvz.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2026-08-03 10:42:29 +02:00
..
accounting.h block/qapi: take stats->lock when reading BlockAcctStats for query-blockstats 2026-08-03 10:42:29 +02:00
aio_task.h block: Remove unused aio_task_pool_empty 2024-09-30 10:53:18 +03:00
block-common.h block: Add blk_co_start/end_request() and BDRV_REQ_NO_QUEUE 2026-05-19 17:25:48 +02:00
block-copy.h block: reduce files included by block/aio.h 2025-12-27 10:11:12 +01:00
block-global-state.h block: reduce files included by block/aio.h 2025-12-27 10:11:12 +01:00
block-hmp-cmds.h include/block: Untangle inclusion loops 2023-01-20 07:24:28 +01:00
block-io.h block: rename block/aio-wait.h to qemu/aio-wait.h 2025-12-27 10:11:12 +01:00
block.h include/block: Untangle inclusion loops 2023-01-20 07:24:28 +01:00
block_backup.h include/block: Untangle inclusion loops 2023-01-20 07:24:28 +01:00
block_int-common.h qcow2: Add keep_data_file command-line option 2026-03-06 17:45:15 +01:00
block_int-global-state.h mirror: Drop redundant zero_target parameter 2025-05-14 20:10:12 -05:00
block_int-io.h block: make bdrv_co_parent_cb_resize() a proper IO API function 2025-10-29 12:10:09 +01:00
block_int.h include/block: Untangle inclusion loops 2023-01-20 07:24:28 +01:00
blockjob.h blockjob: mark block_job_remove_all_bdrv() as GRAPH_UNLOCKED 2025-07-14 15:42:28 +02:00
blockjob_int.h block: Mark block_job_add_bdrv() GRAPH_WRLOCK 2023-11-07 19:14:19 +01:00
dirty-bitmap.h block: reduce files included by block/aio.h 2025-12-27 10:11:12 +01:00
export.h block/export: Add multi-threading interface 2026-03-10 12:11:57 +01:00
fuse.h fuse: Allow exporting BDSs via FUSE 2020-12-11 17:52:39 +01:00
graph-lock.h block: add bdrv_graph_wrlock_drained() convenience wrapper 2025-07-14 15:40:58 +02:00
nbd.h block: replace TABs with space 2025-11-11 22:06:09 +01:00
nvme.h hw/nvme: add migration blockers for non-supported cases 2026-07-07 00:39:42 +02:00
qapi.h qemu-img info: Optionally show block limits 2025-10-29 12:10:10 +01:00
qdict.h qapi: Move include/qapi/qmp/ to include/qobject/ 2025-02-10 15:33:16 +01:00
raw-aio.h block: rename block/aio.h to qemu/aio.h 2025-12-27 10:11:12 +01:00
replication.h replication: move include out of root directory 2021-05-26 14:49:46 +02:00
reqlist.h block/reqlist: add reqlist_wait_all() 2022-03-07 09:33:30 +01:00
snapshot.h block/snapshot: mark bdrv_all_delete_snapshot() as GRAPH_UNLOCKED 2025-07-14 15:42:02 +02:00
thread-pool.h block: rename block/aio.h to qemu/aio.h 2025-12-27 10:11:12 +01:00
throttle-groups.h block/throttle-groups: fix deadlock with iolimits and muliple iothreads 2026-03-06 17:45:15 +01:00
ufs.h hw/ufs: Populate cqe.task_tag for UFSHCI 4.1 tag decoding 2026-07-01 10:19:10 +09:00
write-threshold.h block: Clean up includes 2023-02-08 07:28:05 +01:00