Repository navigation
virtio_blk: Use write through mode without negotiated FLUSH - #5153
Anatol Belski (weltling) wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The SQLite fallback can acknowledge writes that are not durable because sync_cache drops its transaction without committing it before switching to synchronous=NORMAL.
1 open issue
What changed in this PR
This PR updates virtio-blk to select write-through mode when the guest does not negotiate FLUSH, while preserving writeback mode when FLUSH is negotiated.
Changes:
- Select the cache policy at queue startup.
- Request Force Unit Access (FUA) when supported; otherwise flush the backend cache before completing writes.
- Add tests for policy selection, completion ordering, and write and flush error reporting.
| File | Description |
|---|---|
vm/devices/virtio/virtio_blk/src/lib.rs |
Selects and applies the negotiated cache policy to write requests. |
vm/devices/virtio/virtio_blk/src/integration_tests.rs |
Tests cache policy combinations, flush ordering, and error propagation. |
Review effort: Balanced
5531a56 to
6d915af
Compare
6d915af to
87243c4
Compare
87243c4 to
02c0366
Compare
There was a problem hiding this comment.
🟡 Changes recommended
SQLite-backed NVMe and IDE disks can acknowledge FUA writes without a WAL sync in NORMAL mode, risking loss of data reported as durable after a host power failure.
1 open issue
2 resolved since last review
Review effort: Balanced
02c0366 to
a31e203
Compare
a31e203 to
fc0aaeb
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Non-FUA writes can suffer a substantial throughput regression, and guest flushes can fail when the SQLite log cannot grow even if prior writes are already durable.
2 open issues
1 resolved since last review
Review effort: Balanced
These observation seem correct but go far out of scope of this PR which only targets virtio-blk. Thanks |
fc0aaeb to
9cd7457
Compare
9cd7457 to
20e467e
Compare
20e467e to
cecc381
Compare
cecc381 to
a576a70
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Cross-platform FUA and flush durability, including macOS SQLite behavior, requires platform-specific and power-loss validation that hook-based tests cannot provide.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
| VIRTIO_BLK_T_IN => { | ||
| let disk_sector = virtio_to_disk_sector(header.sector, sector_shift, sector_mask)?; | ||
| let (bytes, bounced) = do_io(disk, mem, work, disk_sector, true).await?; | ||
| let (bytes, bounced) = do_io(disk, mem, work, disk_sector, true, false).await?; |
There was a problem hiding this comment.
Let's avoid functions with multiple bool parameters--it's impossible to tell what's going on in the caller.
There was a problem hiding this comment.
Rewrote to keep the original do_io signature. A new shared helper uses an enum to distinquish read, write back and write through.
Thanks
|
Let's not take the sqlite changes. This is a test-only backend and I don't see a need to change the FUA or flush behavior in this PR. |
a576a70 to
b60c40c
Compare
Select the write cache policy from the negotiated FLUSH feature. Require durable writes when FLUSH is not negotiated. Use FUA when the backend supports it. Otherwise, wait for a cache flush before completing the request. Use writeback mode when FLUSH is negotiated. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
Add a queue setup helper that accepts the negotiated features. Test writes with and without negotiated FLUSH. Test backends with and without FUA support. Verify that explicit flush requests reach the backend and report success to the guest. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
Hold the backend write pending when FLUSH is not negotiated. Verify that the cache flush does not start before the write completes. Then delay the cache flush and verify that the status byte and used ring remain unchanged while the flush is pending. Test completed flushes and flush errors. Verify that a flush error is reported to the guest as an I/O error. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
Return a backend error for a FUA write when FLUSH is not negotiated. Verify that the guest receives an I/O error instead of success. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
b60c40c to
bb82856
Compare
Removed the sqlite part as suggested. Thanks |



The device currently offers FLUSH but not CONFIG_WCE. If the guest does not negotiate FLUSH, completed writes must be durable. Previously, writes could complete while their data remained in volatile cache.
Select the write cache policy at queue startup. When FLUSH is not negotiated, request FUA if the backend supports it. For other backends, wait for a cache flush before completing the write. Preserve writeback mode when FLUSH is negotiated.
Add tests for cache policy selection and completion ordering. Verify that write and flush errors are reported to the guest.