]> git.hungrycats.org Git - linux/commitdiff
resize-missing: cover letter and TESTING.md
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 21 Oct 2026 23:16:11 +0000 (19:16 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 21 Oct 2026 23:16:11 +0000 (19:16 -0400)
The cover explains the problem (a smaller replacement can't be used for
a missing device), what the patch allows and refuses, the two bugs fixed
in Qu's 2019 version and the test results.  TESTING.md records n-rsz's
runs on both lanes (forensics/n-rsz-20261021, harness 9a2358c).  The
patch is re-exported as 1/1 now that the series has a cover.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B6wxsJn1aY7PwnhgXdz6Ec

README.md
topics/resize-missing/0000-cover-letter.patch [new file with mode: 0644]
topics/resize-missing/0001-btrfs-resize-allow-shrinking-a-missing-device.patch
topics/resize-missing/TESTING.md [new file with mode: 0644]

index 27781bca985b75e43cd5f0f6ef54c237c7f8c6c9..e833d83212e2d2a7ad3c6e8de6c68d906dfb4ffc 100644 (file)
--- a/README.md
+++ b/README.md
@@ -77,7 +77,7 @@ the integration recipe below uses.
 | `read-policies` | 9 | `18680c6045be` | Kai Krakow | new | Kai's series; his postings are authoritative |
 | `replace-fixes` | 7 | `43c8a1e60a5a` | Zygo | new | patch 7 has a btrfs-progs counterpart (`topics/replace-abort-uncorrectable`) |
 | `dev-stats` | 1 | `55ade1cf195c` | Zygo | new, 0/1 (2026-10-21) | behaviour change, offered for rejection; independent of every other series |
-| `resize-missing` | 1 | `8763f9e2126d` | Qu Wenruo, rewritten by Zygo | none yet (single patch) | Qu's 2019 patch reworked: grow checks now return, absolute sizes checked; Zygo's Signed-off-by to be added before sending |
+| `resize-missing` | 1 | `8763f9e2126d` | Qu Wenruo, rewritten by Zygo | new, 0/1 (2026-10-21) | Qu's 2019 patch reworked: grow checks now return, absolute sizes checked; Zygo's Signed-off-by to be added before sending |
 
 ## Applying one series
 
diff --git a/topics/resize-missing/0000-cover-letter.patch b/topics/resize-missing/0000-cover-letter.patch
new file mode 100644 (file)
index 0000000..563d3b1
--- /dev/null
@@ -0,0 +1,48 @@
+From 8763f9e2126d43bc4504612d63f08807aec86a7e Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Wed, 21 Oct 2026 19:15:12 -0400
+Subject: [PATCH 0/1] btrfs: resize: allow shrinking a missing device
+To: linux-btrfs@vger.kernel.org
+
+A failed device can't be replaced by one that is even slightly smaller:
+dev-replace refuses a target smaller than the source's recorded size, and
+the resize ioctl refuses a missing device because it isn't writeable.  The
+only way out has been "btrfs device remove missing", which rewrites every
+chunk that had a stripe on the missing device.  That takes a long time and,
+on a full filesystem, may not be possible at all.
+
+The patch lets resize shrink a missing device, relocating the chunks above
+the new size as for a present device.  The smaller replacement then fits.
+A missing device has no block device to measure, so it can't grow: "max",
+"+size" and an absolute size above the current one return -EINVAL.  A
+present device that isn't writeable still gets -EPERM.
+
+Qu Wenruo wrote this patch in November 2019 for a RAID10 user who hit the
+problem; it was never merged.  This version fixes two bugs in it: the
+"+size" check on a missing device only logged a message and went ahead,
+and an absolute size skipped the check entirely, so growth was refused
+only by btrfs_grow_device() returning -EACCES.  It also treats a device
+with no bdev as missing, whether or not BTRFS_DEV_STATE_MISSING is set,
+because a device can go missing at runtime while its bdev pointer is still
+set, and a rescan can clear the MISSING bit while no bdev is open.
+
+Tested with resize-missing-test.sh on raid1 and raid10, misc-next and
+6.18, with the device lost before mount and, on misc-next, at runtime
+(a null_blk member powered off under the mounted filesystem).  The grow
+attempts fail with -EINVAL, shrinking relocates everything above the new
+size, and replacing with a target of exactly the shrunk size succeeds;
+scrub, checksums and btrfs check are clean afterwards.  Without the patch,
+every resize of the missing device fails with -EPERM and the replace is
+refused.
+
+Qu Wenruo (1):
+  btrfs: resize: allow shrinking a missing device
+
+ fs/btrfs/ioctl.c | 32 ++++++++++++++++++++++++++++----
+ 1 file changed, 28 insertions(+), 4 deletions(-)
+
+
+base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
+-- 
+2.47.3
+
index 0e08e96d78934c327ee5ba0e40f8c38d79b37759..ecd0e40af2d1b4340fed32080671f590807224c1 100644 (file)
@@ -1,7 +1,7 @@
 From 8763f9e2126d43bc4504612d63f08807aec86a7e Mon Sep 17 00:00:00 2001
 From: Qu Wenruo <wqu@suse.com>
 Date: Mon, 18 Nov 2019 15:05:25 +0800
-Subject: [PATCH] btrfs: resize: allow shrinking a missing device
+Subject: [PATCH 1/1] btrfs: resize: allow shrinking a missing device
 To: linux-btrfs@vger.kernel.org
 
 One user reported a case where a device couldn't be replaced because the
@@ -93,8 +93,6 @@ index dec015e6bd29a..ceec0d43123c7 100644
                ret = -EFBIG;
                goto out_finish;
        }
-
-base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
 -- 
 2.47.3
 
diff --git a/topics/resize-missing/TESTING.md b/topics/resize-missing/TESTING.md
new file mode 100644 (file)
index 0000000..ca6326f
--- /dev/null
@@ -0,0 +1,97 @@
+# Testing: resize-missing
+
+The one patch lets the resize ioctl shrink a missing device, so that a
+replacement smaller than the missing device's recorded size can be used
+with `btrfs replace`.  A missing device is one with
+`BTRFS_DEV_STATE_MISSING` set or no bdev.  It cannot grow: `max`, `+size`
+and an absolute size above the current one return -EINVAL.  A present,
+non-writeable device still gets -EPERM.
+
+Without the patch, every resize of a missing device fails with -EPERM
+("resizer unable to apply on readonly device"), and `btrfs replace`
+refuses a target smaller than the source ("target device smaller than
+source device").
+
+This is a rewrite of Qu Wenruo's 2019 patch (874977e114cc0 as ported to
+7.0).  The original had two bugs, which a test must rule out:
+- `+size` on a missing device logged a message and carried on, with no
+  error returned;
+- an absolute size skipped the missing-device check, so only
+  `btrfs_grow_device()`'s -EACCES stopped the growth.
+
+To verify, a test must show:
+- every way of growing a missing device (`max`, `+size`, absolute larger)
+  is refused, and the recorded size is unchanged;
+- shrinking a missing device works and relocates every chunk that had a
+  stripe above the new size;
+- a replace with a target of exactly the shrunk size then succeeds, and
+  the data is intact (scrub, checksums, `btrfs check`, non-degraded
+  remount);
+- resizing a present device still works;
+- the same holds for a device that goes missing at runtime (misc-next has
+  `btrfs_remove_bdev()`, which sets MISSING while the bdev is still set).
+
+Added to both lanes 2026-10-21: misc-next topic 8763f9e2126d (testing
+723245adb5c1, zb64 2550544f9c6e), 6.18 topic 42d60c710e72 (testing
+ba7d11a7b7ac, zb64 7626a4a10198).  The tested kernels were built from
+`refs/cand/resize-missing/{mn,618}/zb64`: the previous lane heads plus
+this patch, with the same fs/btrfs trees as the new zb64 heads.
+
+## Existing tests
+
+None.  No harness test resized a missing device.
+
+## New tests
+
+| test | verifies | patch(es) | duration | last result | date | kernel | harness | evidence |
+|---|---|---|---|---|---|---|---|---|
+| `resize-missing-test.sh` raid1 (3 devs), raid10 (4 devs), device lost before mount | grow refused (`max`, `+1G`, absolute cur+1G: EINVAL, size unchanged); absolute cur is a no-op; `-512M` and a shrink below the highest extent relocate; present device `-1G` / `max` work; replace with a target of exactly the shrunk size, then scrub, checksums, `btrfs check`, non-degraded remount | 1 | ~3-5 min per profile | PASS on both profiles, no WARN/BUG/KASAN/lockdep/hung task | 2026-10-21 | misc-next cand zb64 86426366cf7a (7.3.0-rc7+ #1, ahive) | 9a2358c | forensics/n-rsz-20261021/ahive/candidate-static/ |
+| same | as above | 1 | ~3-5 min per profile | PASS on both profiles, kernel log clean | 2026-10-21 | 6.18 cand zb64 55546d681ccf (6.18.57+ #1, ehive) | 9a2358c | forensics/n-rsz-20261021/ehive/candidate-static/ |
+| same, runtime loss (raid1; a null_blk member powered off under the mounted fs) | the device counts as missing after `btrfs_remove_bdev()`; same resize, replace and verification steps | 1 | ~5 min | PASS, no oops | 2026-10-21 | misc-next cand zb64 86426366cf7a (#1, with `CONFIG_BLK_DEV_NULL_BLK=y`) | 9a2358c | forensics/n-rsz-20261021/ahive/candidate-runtime/ |
+| same, negative control (`RM_EXPECT=base`) | without the patch every resize of the missing device is EPERM and the smaller replace is refused; a full-size replace (control) works | - | ~3-5 min per profile | as expected on both profiles and both lanes | 2026-10-21 | misc-next zb64 568c45b64012 (#5, ahive); 6.18 zb64 39e1125533c7 (6.18.57+ #2, ehive: the candidate minus the patch) | 9a2358c | forensics/n-rsz-20261021/{ahive,ehive}/base-raid{1,10}/ |
+| W=1 `make fs/btrfs/`, then a full bzImage | no new warnings; the kernel links | 1 | - | no new warning in ioctl.c on either lane; the known ones (stripe_whole_bytes unused, frame-size warnings in free-space-cache.c and tree-log.c) are identical with and without the patch; bzImage rc 0 on all three kernels | 2026-10-21 | mn 86426366cf7a, 618 55546d681ccf and 39e1125533c7 | 9a2358c | forensics/n-rsz-20261021/{ahive,ehive}/w1-*.txt |
+
+**resize-missing-test.sh.**
+
+Fixture:
+- 3 GiB loop images, every member including the replace target prefilled
+  with labelled poison.  mkfs -K, mount -o nodiscard, `replace -K`.
+- reclaim-regimen stopped for the run.
+- About 1 GiB of files with recorded sha256.  The script keeps writing
+  until the victim device has an extent in its top 512 MiB (checked with
+  `dump-tree -t dev` after `blockdev --flushbufs`).  It then deletes the
+  earliest files down to 1 GiB and runs `balance -dusage=50`, so the
+  degraded filesystem has room for the replace.  Without that release, the
+  replace hit ENOSPC on the base kernels too: a fixture problem, not the
+  patch.
+- The victim is lost with `losetup -d` before a `-o degraded` mount, or, in
+  the runtime arm, by powering off its null_blk device under the mounted
+  filesystem.
+
+Coverage of the top 512 MiB: raid1 reached it on every run (highest victim
+extent 2581-3072 MiB).  raid10 reached it only on the misc-next candidate
+(2876 MiB); on the other raid10 runs the highest extent was at 2252 MiB.
+There, the second shrink, to below the highest extent, is the step that
+relocates.  Every run ends with no victim extent above the new size.
+
+The replace target size is the victim's committed `total_bytes` after the
+shrink, read from the dev item in the chunk tree.  `btrfs fi show` and
+`dev usage` print size 0 for a missing device.
+
+Messages seen on the candidates:
+- `resizer unable to apply 'max' on missing device N`;
+- `resizer unable to grow missing device N`, shared by `+size` and an
+  absolute grow;
+- `resize device <missing disk> (devid N) from A to B`.
+
+## Open
+
+- In the runtime arm, the dead null_blk device kept receiving writes after
+  "has gone missing, continue as degraded" (`errs: wr 1..164`, then
+  `rd 1..5` and "scrub: fixed up error" during the replace).  This looks
+  like existing runtime-missing behaviour and does not involve the resize
+  path, but it was not compared against a kernel without the patch.
+- Not covered: a missing device that is the source of a suspended
+  dev-replace (the exclusive operation normally prevents a concurrent
+  resize, but a replace suspended at mount is a separate state), and
+  zoned devices.