Thanks to visit codestin.com
Credit goes to github.com

Skip to content

block: qcow: Fix QCOW2 thread safety for multiple virtio queues - #7661

Merged
rbradford merged 2 commits into
cloud-hypervisor:mainfrom
weltling:qcow-mq
Feb 3, 2026
Merged

rbradford merged 2 commits into
cloud-hypervisor:mainfrom
weltling:qcow-mq

Conversation

@weltling

@weltling weltling commented Feb 3, 2026

Copy link
Copy Markdown
Member

This PR fixes data corruption when using QCOW2 images with num_queues > 1.

When virtio-block is configured with multiple queues, each queue gets its own QcowSync instance that shares the underlying QcowFile through Clone. The cloned instances share mutable file position but stay out of sync with metadata, leading to cache corruption under concurrent I/O.

Issue #7560 carries plans and a discussion targeting a proper refactoring for the block crate. As an immediate fix, wrapping QcowFile in Arc<Mutex<>> to serialize all QCOW2 operations seems the simplest solution. This approach has obvious performance downsides for multiqueue configurations, however:

  • The multiqueue scenario is already broken without this fix
  • The impact on the default num_queues=1 is negligible
  • A proper refactoring would be significantly more intrusive, requiring careful separation of metadata locking from data I/O paths

While introducing serialization ahead of a proper refactoring is not ideal, the current data corruption makes this a necessary intermediate step to provide a working multiqueue QCOW2 implementation.

Multiple stress tests have been added: parallel writes, mixed read/write, backing file operations, random 4K I/O, fsync storms, and metadata operations.

Fixes #7660

Add stress tests for QCOW2 with >=8 virtio queues to verify
thread safety of multiqueue concurrent disk access:

- parallel dd writes
- 4 readers + 4 writers mixed I/O
- overlay with backing file
- random 4K writes
- parallel small writes + fsync
- mkdir/touch/rm/rename metadata operations

Signed-off-by: Anatol Belski <[email protected]>
Wrap QcowFile in Arc<Mutex<>> to ensure thread safety when multiple
virtio queues access the same QCOW2 image concurrently.

Previously, each queue received its own QcowSync instance via
new_async_io() that shared the underlying QcowFile through Clone.
However, cloned QcowFile instances share internal mutable state
(L2 cache, reference counts, file seek position) without
synchronization, leading to data corruption under concurrent I/O.

This change serializes all QCOW2 operations through a mutex, which
ensures correctness at the cost of parallelism. A more performant
solution would require separating metadata locking from actual I/O
operations, tracked in cloud-hypervisor#7560.

Related: cloud-hypervisor#7560

Signed-off-by: Anatol Belski <[email protected]>
@weltling
weltling requested a review from a team as a code owner February 3, 2026 20:55
@rbradford
rbradford added this pull request to the merge queue Feb 3, 2026
Merged via the queue into cloud-hypervisor:main with commit 9bc367a Feb 3, 2026
43 checks passed
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Done in Cloud Hypervisor Roadmap Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

QCOW2 backend corrupts data with multiple virtio-blk queues

3 participants