Repository navigation
vhdx: fix concurrent allocation and metadata publication - #5063
Draft
John Starks (jstarks) wants to merge 3 commits into
Draft
John Starks (jstarks) wants to merge 3 commits into
John Starks (jstarks) wants to merge 3 commits into
Conversation
Recheck partially present mappings under the allocation lock so queued writes reuse their payload and preserve parent inheritance. Delay publication until zero-filled payloads are initialized, clear each partial block's bitmap through the WAL, and establish safe recycled payload contents before logging their allocation. Preserve reclaimed space ownership on rollback and make allocation, completion, and cache acquisition cancellation-safe. Add deterministic transition and selective-persistence regressions plus a seeded sector model to exercise concurrency, recovery, and first-touch flush costs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3027827-8feb-43a4-830a-e4bb487c1328
Create differencing fixtures with the current parent API. Run each seeded model configuration as its own test so all sixteen schedules remain covered without exceeding the runner's per-test timeout. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3027827-8feb-43a4-830a-e4bb487c1328
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Cancelling zero-fill can release a region while its initialization write is still running, allowing another writer to reuse it before the outstanding write erases the new data.
1 open issue
What changed in this PR
This PR fixes concurrent VHDX allocation so queued partial writes reuse existing payloads without losing earlier writes or parent inheritance. It also hardens metadata publication and rollback in the storage backend.
Changes:
- Order payload initialization and sector-bitmap logging before publication.
- Track allocation ownership during rollback and add cancellation cleanup for writes and cache acquisition.
- Add deterministic concurrency, selective-persistence, flush-count, and seeded recovery tests.
| File | Description |
|---|---|
vm/devices/storage/vhdx/src/trim.rs |
Clarifies bitmap initialization responsibility in comments. |
vm/devices/storage/vhdx/src/tests/transition_tests.rs |
Adds cancellation, persistence, and sector-model regressions. |
vm/devices/storage/vhdx/src/tests/support.rs |
Adds controlled I/O pauses, failures, and persistence scheduling. |
vm/devices/storage/vhdx/src/tests/mod.rs |
Registers transition tests. |
vm/devices/storage/vhdx/src/tests/io_tests.rs |
Tests concurrent allocation, rollback ownership, and bitmap preservation. |
vm/devices/storage/vhdx/src/tests/crash_tests.rs |
Updates comments describing publication and flush dependencies. |
vm/devices/storage/vhdx/src/space.rs |
Prevents reclaiming transitioning soft anchors and adds coverage. |
vm/devices/storage/vhdx/src/sector_bitmap.rs |
Ensures bitmap initialization zeros are logged. |
vm/devices/storage/vhdx/src/io.rs |
Fixes allocation rechecks and revises publication and rollback handling. |
vm/devices/storage/vhdx/src/cache.rs |
Adds cancellation cleanup and pins pending page loads. |
Review effort: Balanced
Comment on lines
+618
to
+620
| self.file | ||
| .zero_range(new_offset, self.block_size as u64) | ||
| .await |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Concurrent partial writes can both observe an unallocated differencing block. The allocation-lock recheck misses the transition to PartiallyPresent, so a queued writer replaces the payload and loses earlier writes and parent inheritance. Handle that state explicitly and reuse the existing allocation.
Harden the related publication and rollback paths: keep zero-fill initialization ahead of payload publication, initialize each partial block’s bitmap range through the WAL, and establish safe recycled payload contents before logging the allocation. Preserve deferred-release and soft-anchor ownership on abort, and make allocation, completion, and cache acquisition cancellation-safe. Safe partial payloads avoid recurring data-flush barriers when additional sectors become present.
Add deterministic concurrency and selective-persistence regressions, first-touch flush-count checks, and a bounded sector model covering writes, trim, abort, flush, and recovery with both logical sector sizes. Each seeded configuration runs independently to stay within the test runner’s per-test timeout.
Validated on Linux after rebasing onto current main: compilation checks for vhdx and disklayer_vhdx, all-target Clippy and documentation for vhdx, 483 passing tests across both packages with the agent nextest profile, and cargo xtask fmt --fix. Native Windows cross-validation was not run.