mbox series

[GIT,PULL,8/22] xfs: fix rmap btree key flag handling

Message ID 168127094461.417736.1444539165048108895.stg-ugh@frogsfrogsfrogs (mailing list archive)
State Deferred, archived
Headers show
Series [GIT,PULL,1/22] xfs: design documentation for online fsck | expand

Pull-request

git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git tags/rmap-btree-fix-key-handling-6.4_2023-04-11

Message

Darrick J. Wong April 12, 2023, 3:46 a.m. UTC
Hi Dave,

Please pull this branch with changes for xfs.

As usual, I did a test-merge with the main upstream branch as of a few
minutes ago, and didn't see any conflicts.  Please let me know if you
encounter any problems.

--D

The following changes since commit de1a9ce225e93b22d189f8ffbce20074bc803121:

xfs: hoist inode record alignment checks from scrub (2023-04-11 19:00:06 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git tags/rmap-btree-fix-key-handling-6.4_2023-04-11

for you to fetch changes up to 38384569a2a8a721623d80c5ae3bcf80614ab792:

xfs: detect unwritten bit set in rmapbt node block keys (2023-04-11 19:00:07 -0700)

----------------------------------------------------------------
xfs: fix rmap btree key flag handling [v24.5]

This series fixes numerous flag handling bugs in the rmapbt key code.
The most serious transgression is that key comparisons completely strip
out all flag bits from rm_offset, including the ones that participate in
record lookups.  The second problem is that for years we've been letting
the unwritten flag (which is an attribute of a specific record and not
part of the record key) escape from leaf records into key records.

The solution to the second problem is to filter attribute flags when
creating keys from records, and the solution to the first problem is to
preserve *only* the flags used for key lookups.  The ATTR and BMBT flags
are a part of the lookup key, and the UNWRITTEN flag is a record
attribute.

This has worked for years without generating user complaints because
ATTR and BMBT extents cannot be shared, so key comparisons succeed
solely on rm_startblock.  Only file data fork extents can be shared, and
those records never set any of the three flag bits, so comparisons that
dig into rm_owner and rm_offset work just fine.

A filesystem written with an unpatched kernel and mounted on a patched
kernel will work correctly because the ATTR/BMBT flags have been
conveyed into keys correctly all along, and we still ignore the
UNWRITTEN flag in any key record.  This was what doomed my previous
attempt to correct this problem in 2019.

A filesystem written with a patched kernel and mounted on an unpatched
kernel will also work correctly because unpatched kernels ignore all
flags.

With this patchset applied, the scrub code gains the ability to detect
rmap btrees with incorrectly set attr and bmbt flags in the key records.
After three years of testing, I haven't encountered any problems.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>

----------------------------------------------------------------
Darrick J. Wong (2):
xfs: fix rm_offset flag handling in rmap keys
xfs: detect unwritten bit set in rmapbt node block keys

fs/xfs/libxfs/xfs_rmap_btree.c | 40 +++++++++++++++++++++++--------
fs/xfs/scrub/btree.c           | 10 ++++++++
fs/xfs/scrub/btree.h           |  2 ++
fs/xfs/scrub/rmap.c            | 53 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 95 insertions(+), 10 deletions(-)