tests/bcachefs: add online shrink coverage#85
Draft
Komzpa wants to merge 22 commits into
Draft
Conversation
This was referenced Jun 30, 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.
7659ae5 to
40d3285
Compare
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.
Summary
tests/fs/bcachefs/shrink.ktestcovering online device shrink pathsjullanggit/ktestshrink branch instead of squashing themScope
This is the ktest companion for the shrink issue cluster:
koverstreet/bcachefs#781koverstreet/bcachefs#1056koverstreet/bcachefs-tools#268koverstreet/bcachefs-tools#742koverstreet/bcachefs#1073The offline shrink cases from the source branch are preserved in history but removed again by a separate Komzpa commit because
koverstreet/bcachefs-tools#742still leaves offline shrink rejected. This PR is about online shrink proof coverage.Validation
Current head:
0bdec5d426122b740faefbda88c5d2fcbfe1f7e5git diff --checkbash -n tests/fs/bcachefs/shrink.ktestcargo build --verbosekoverstreet/bcachefs-tools#742headd432f6894649123cc1e6fde2157b967f2662094eand a local ktest kernel/root pair with host-mount support: all 15 tests passed,TEST SUCCESSGitHub CI for the current head is green.
Provenance
Based on
https://github.com/jullanggit/ktest/tree/shrink.Credit for the original shrink test work belongs to Jul Lang. The branch keeps the imported commit authors/messages where practical; the online-only scope adjustment and retarget-race fix are separate Komzpa commits at the tail of the branch.
Recent tail commits on this PR:
40d3285tests/bcachefs: keep shrink coverage online-only0bdec5dtests/bcachefs: tolerate retarget cancel race