Add shrink tests - #97
Open
jullanggit wants to merge 32 commits into
Open
Conversation
This was referenced Jul 15, 2026
…as_required options
… seem to work TODO: revisit this with the new erasure code changes
Refactor the shrink ktest around shared helpers so every shrink scenario now shows post-resize usage, runs fsck, and remounts the full device set before finishing. Add new online shrink coverage for encrypted+compressed randrw workloads and for replicated snapshot/reflink state with extra metadata churn. Keep a mixed-bucket shrink reproducer disabled for now, with an in-code note, because it still trips no_buckets_found during device reconcile and is useful to keep around for future shrink fixes.
Add shrink helpers for recording and checking data checksums after remount, then use them to cover two more online shrink cases. One stresses xattrs, hardlinks, reflinks, symlinks, and directory churn while evacuating data off the shrinking device. The other exercises shrink with target-restricted placement by mixing fast and bulk directories and adding a second fast device before the resize. These cases extend shrink coverage into metadata preservation and allocator targeting without making the ktest significantly heavier.
Factor the metadata-tree setup into helpers, then add an online shrink case that combines replicated metadata-heavy state with concurrent file churn while a third device absorbs evacuated data. The test verifies checksums, hardlinks, symlinks, and xattrs after fsck and remount so it exercises both relocation and reopen paths under ongoing writes.
Add a shrink ktest that interrupts `bcachefs device resize` after the pending target has been recorded, remounts the filesystem, and verifies that mount-time recovery finishes the shrink before userspace regains control. The test keeps enough data on the shrinking device to make the interruption deterministic, then reissues the same shrink command after remount to confirm the restart path completed rather than leaving the device stuck in `target_nbuckets` state.
Add restart-resume coverage for an interrupted shrink and three retarget cases that change the requested device size while shrink is already in flight: retarget to a less aggressive shrink, retarget back to the current size, and retarget to grow. The new helpers verify that the first resize ioctl is superseded, that the final on-disk member size matches the latest request, and that the filesystem still passes remount, fsck, and checksum verification after each transition.
Add a shrink ktest that formats a two-device replicas=2 filesystem, writes enough data to require both members, and then verifies that shrinking one device to 256M fails. The test also checks that the resize target is cleared so remount does not keep retrying a known-impossible shrink.
shrink.ktest:
Add _do_empty_shrink, _do_two_device_data_shrink, and _do_impossible_shrink
as shared scenario functions parameterized by mode ("online" / "offline").
The online/offline branch differs only in how the resize is invoked:
online: bcachefs device resize while kernel has the FS mounted
offline: umount, call offline_device_resize() via tools lib, remount
Rewrite the three existing online tests and the three new offline tests as
thin wrappers that supply the mode, making both variants of each scenario
exercise identical setup/data/teardown.
Add offline_device_resize helper that combines the resize call with
superblock assertions (buckets, target_nbuckets inactive), documenting
the offline resize pattern.
Add three new offline tests:
test_offline_empty_shrink
test_offline_two_device_data_shrink
test_offline_impossible_shrink
single_device.ktest:
Add test_offline_grow_to_size (offline grow to explicit 2G target),
adjacent to the existing offline grow tests.
Add two new online shrink tests for the new 'bcachefs device resize cancel'
…o 0 buckets as no action
we actually need at least four devices if we want to shrink away most of one of the devices
TODO: revert this once accounting is properly handled
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.
Add tests for shrinking. These need to be executed with both a compatible bcachefs-tools and kernel.