Skip to content

fix(virtio): sync disk data on virtio-blk FLUSH - #545

Merged
Lencerf merged 1 commit into
google:mainfrom
Lencerf:fix/blk-flush
Nov 11, 2026
Merged

Lencerf merged 1 commit into
google:mainfrom
Lencerf:fix/blk-flush

Conversation

@Lencerf

@Lencerf Lencerf commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Split from #544.

VirtioMio::handle_queue() previously handled BlkRequest::Flush with <&File as Write>::flush(), which is a no-op in the Rust standard library and never invokes fsync. Per VirtIO 1.4 Sec 5.2.6.2, a block device backed by persistent storage must ensure writes are committed to it before reporting completion of a VIRTIO_BLK_T_FLUSH request. Call File::sync_data() instead.

A flush only needs the written data and the metadata required to read it back (file size, block allocation), not timestamps, so the io_uring worker now also sets IORING_FSYNC_DATASYNC. Both workers use fdatasync(2) on Linux; on macOS, sync_data() issues F_FULLFSYNC like sync_all().

cargo +nightly fmt --check, cargo clippy --all-targets -D warnings on x86_64-unknown-linux-gnu/musl, aarch64-unknown-linux-gnu and aarch64-apple-darwin, and cargo test --workspace pass locally.

VirtioMio::handle_queue() previously handled BlkRequest::Flush by
calling <&File as Write>::flush(), which is a no-op in the Rust standard
library and never synchronizes data to disk.

Per VirtIO 1.4 Sec 5.2.6.2, a block device backed by persistent storage
must ensure writes are committed to it before reporting completion of a
VIRTIO_BLK_T_FLUSH request. Call File::sync_data() instead.

A flush only needs the written data and the metadata required to read
it back, such as the file size and block allocation, not timestamps.
So also set IORING_FSYNC_DATASYNC on the fsync in the io_uring worker,
which makes both workers use fdatasync(2) on Linux. On macOS,
sync_data() issues F_FULLFSYNC, the same as sync_all().

Fixes: 9a3857f ("fix(blk): flush disk file on FLUSH requests")
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 42962744932

Coverage decreased (-0.01%) to 43.821%

Details

  • Coverage decreased (-0.01%) from the base build.
  • Patch coverage: 4 uncovered changes across 1 file (0 of 4 lines covered, 0.0%).
  • 2 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
alioth/src/virtio/dev/blk.rs 4 0 0.0%

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
alioth/src/virtio/worker/io_uring.rs 2 70.37%

Coverage Stats

Coverage Status
Relevant Lines: 16443
Covered Lines: 6995
Line Coverage: 42.54%
Relevant Branches: 1756
Covered Branches: 980
Branch Coverage: 55.81%
Branches in Coverage %: Yes
Coverage Strength: 905.92 hits per line

💛 - Coveralls

@Lencerf
Lencerf added this pull request to the merge queue Nov 11, 2026
Merged via the queue into google:main with commit b641dff Nov 11, 2026
20 checks passed
@Lencerf
Lencerf deleted the fix/blk-flush branch November 11, 2026 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants