Hi Zygo, Thanks for the detailed review. It changed the design, not just the patch.
I agree with the core point: physical bad-sector handling belongs below the filesystem. A drive with spare sectors already does the useful part in firmware: the filesystem sees EIO or a checksum mismatch, retries another copy, and rewrites the good data to the failed LBA. That rewrite is what makes the drive move the sector to a spare. We only need a block-layer replacement when the drive can no longer remap, because the spares are exhausted or the firmware refuses. I also accept the consequences you spelled out: the remap unit has to be the lower device's logical block size; reserve allocations must never move; and the table has to be crash-consistent with the data, with FLUSH/FUA committing table changes and two copies protecting the metadata. btrfs should not intercept physical I/O for this. Verified defects ---------------- I checked each point against 6.12 and I am not disputing any of them: - the write redirect used the chunk/map length, not the bio length; - repair writes went through the redirect as well; - fast-fail after a split dropped the remainder; - fast-fail inflated read_io_errs without doing I/O; - device replace reused the old devid, so persisted ranges followed it; - the incompat bit was cleared when one device's list emptied, not when the filesystem had no ranges left; - the mirror-collapse test could pass from the page cache; - dmq renumbered reserve offsets on every rebuild; - dmq reloaded the table and only then installed the ranges, leaving a window with no remaps. The last two are already fixed in the userspace side. The map schema now stores a per-range reserve_start and the allocator cursor; reconciliation keeps existing offsets and only allocates new gaps. Live updates diff the target's range list and send incremental add_bad/remove_bad messages, so a range-only change does not reload the table at all. Geometry changes are refused while the mapped device is mounted. The userspace suite covers add-below, remove-middle, idempotent re-apply, split boundaries, poison-to-redirect, and reserve exhaustion. Status of the btrfs patch ------------------------- The btrfs patch is withdrawn from upstream consideration and kept as an experiment in the branch. I will not resend it and I am not preparing a btrfs v2. Scrub reporting and targeted relocation may still be useful, but as filesystem features that feed the block layer, not as I/O interception. Proposed dm-first staging ------------------------- I am not claiming crash-safe redirect yet. For a first submission I would like the target to do detection, keep a pending list, and poison confirmed ranges (return EIO, never stale or zero data). The volatile table would be restored by userspace before mount, but nothing would move data to a reserve, so no acknowledged write can outlive a lost mapping. Redirect would arrive with the persistent log: a small self-checksummed area at the end of the device, two copies, a generation number, and the mapping committed before the remapped write is reported durable. Does that split make sense as a first submission, or would you rather see redirect and the persistent table in one series? Two smaller decisions: - Geometry. I plan to require the lower device to be a partition by default. Whole-disk ownership, including LBA 0, becomes an explicit mode with a documented recovery path (initramfs or rescue media), because the target has to own the partition table and the boot loader's sectors too. Is the partition requirement reasonable, or is whole-disk the more useful default? - Reserve. User-specified size with a documented default, not a hardcoded constant; new defects take the next free block and existing mappings never move. Any preference on the default or on whether the pool may grow? I am rejecting zoned-device support for v1. I will post the dm design and the on-disk format as a separate RFC once the format and crash-ordering rules are written down. If you are willing to look at the format before there is code, that is the review that would save the most time. Thanks again, Alexey
