Skip to content

tests/bcachefs: add online shrink coverage#85

Draft
Komzpa wants to merge 22 commits into
koverstreet:masterfrom
Komzpa:komzpa/bcachefs-shrink-test
Draft

tests/bcachefs: add online shrink coverage#85
Komzpa wants to merge 22 commits into
koverstreet:masterfrom
Komzpa:komzpa/bcachefs-shrink-test

Conversation

@Komzpa

@Komzpa Komzpa commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add tests/fs/bcachefs/shrink.ktest covering online device shrink paths
  • preserve the useful shrink coverage commits from Jul Lang's jullanggit/ktest shrink branch instead of squashing them
  • keep this PR scoped to online shrink coverage, matching the current bcachefs-tools-side implementation artifact
  • tolerate the resize-retarget race where either the original shrink request or the foreground retarget request can observe the superseded/canceled ioctl result, while still verifying final member size and file checksums

Scope

This is the ktest companion for the shrink issue cluster:

  • koverstreet/bcachefs#781
  • koverstreet/bcachefs#1056
  • koverstreet/bcachefs-tools#268
  • koverstreet/bcachefs-tools#742
  • koverstreet/bcachefs#1073

The offline shrink cases from the source branch are preserved in history but removed again by a separate Komzpa commit because koverstreet/bcachefs-tools#742 still leaves offline shrink rejected. This PR is about online shrink proof coverage.

Validation

Current head: 0bdec5d426122b740faefbda88c5d2fcbfe1f7e5

  • git diff --check
  • bash -n tests/fs/bcachefs/shrink.ktest
  • cargo build --verbose
  • local full shrink suite using koverstreet/bcachefs-tools#742 head d432f6894649123cc1e6fde2157b967f2662094e and a local ktest kernel/root pair with host-mount support: all 15 tests passed, TEST SUCCESS

GitHub 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:

  • 40d3285 tests/bcachefs: keep shrink coverage online-only
  • 0bdec5d tests/bcachefs: tolerate retarget cancel race

jullanggit and others added 21 commits June 30, 2026 19:23
… 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.
@Komzpa Komzpa force-pushed the komzpa/bcachefs-shrink-test branch from 7659ae5 to 40d3285 Compare June 30, 2026 15:24
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