linux/fs/xfs/scrub
Darrick J. Wong 6be73cecb5 xfs: fix broken logic when detecting mergeable bmap records
Commit 6bc6c99a944c was a well-intentioned effort to initiate
consolidation of adjacent bmbt mapping records by setting the PREEN
flag.  Consolidation can only happen if the length of the combined
record doesn't overflow the 21-bit blockcount field of the bmbt
recordset.  Unfortunately, the length test is inverted, leading to it
triggering on data forks like these:

 EXT: FILE-OFFSET           BLOCK-RANGE        AG AG-OFFSET               TOTAL
   0: [0..16777207]:        76110848..92888055  0 (76110848..92888055) 16777208
   1: [16777208..20639743]: 92888056..96750591  0 (92888056..96750591)  3862536

Note that record 0 has a length of 16777208 512b blocks.  This
corresponds to 2097151 4k fsblocks, which is the maximum.  Hence the two
records cannot be merged.

However, the logic is still wrong even if we change the in-loop
comparison, because the scope of our examination isn't broad enough
inside the loop to detect mappings like this:

   0: [0..9]:               76110838..76110847  0 (76110838..76110847)       10
   1: [10..16777217]:       76110848..92888055  0 (76110848..92888055) 16777208
   2: [16777218..20639753]: 92888056..96750591  0 (92888056..96750591)  3862536

These three records could be merged into two, but one cannot determine
this purely from looking at records 0-1 or 1-2 in isolation.

Hoist the mergability detection outside the loop, and base its decision
making on whether or not a merged mapping could be expressed in fewer
bmbt records.  While we're at it, fix the incorrect return type of the
iter function.

Fixes: 336642f792 ("xfs: alert the user about data/attr fork mappings that could be merged")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2023-06-05 14:48:12 +10:00
..
agheader_repair.c xfs: convert xbitmap to interval tree 2023-04-11 19:00:36 -07:00
agheader.c xfs: teach scrub to check for sole ownership of metadata objects 2023-04-11 19:00:15 -07:00
alloc.c xfs: flag free space btree records that could be merged 2023-04-11 19:00:26 -07:00
attr.c xfs: don't load local xattr values during scrub 2023-04-11 19:00:35 -07:00
attr.h xfs: check used space of shortform xattr structures 2023-04-11 19:00:33 -07:00
bitmap.c xfs: cross-reference rmap records with free space btrees 2023-04-11 19:00:38 -07:00
bitmap.h xfs: cross-reference rmap records with free space btrees 2023-04-11 19:00:38 -07:00
bmap.c xfs: fix broken logic when detecting mergeable bmap records 2023-06-05 14:48:12 +10:00
btree.c xfs: teach scrub to check for sole ownership of metadata objects 2023-04-11 19:00:15 -07:00
btree.h xfs: always scrub record/key order of interior records 2023-04-11 19:00:09 -07:00
common.c xfs: disable reaping in fscounters scrub 2023-05-02 09:16:14 +10:00
common.h xfs: disable reaping in fscounters scrub 2023-05-02 09:16:14 +10:00
dabtree.c xfs: scrub should use ECHRNG to signal that the drain is needed 2023-04-11 19:00:00 -07:00
dabtree.h xfs: update copyright years for scrub/ files 2023-04-11 18:59:57 -07:00
dir.c xfs: manage inode DONTCACHE status at irele time 2023-04-11 19:00:20 -07:00
fscounters.c xfs: disable reaping in fscounters scrub 2023-05-02 09:16:14 +10:00
health.c xfs: allow queued AG intents to drain before scrubbing 2023-04-11 18:59:58 -07:00
health.h xfs: update copyright years for scrub/ files 2023-04-11 18:59:57 -07:00
ialloc.c xfs: teach scrub to check for sole ownership of metadata objects 2023-04-11 19:00:15 -07:00
inode.c xfs: don't take the MMAPLOCK when scrubbing file metadata 2023-04-11 19:00:22 -07:00
parent.c xfs: manage inode DONTCACHE status at irele time 2023-04-11 19:00:20 -07:00
quota.c xfs: minimize overhead of drain wakeups by using jump labels 2023-04-11 18:59:59 -07:00
readdir.c xfs: streamline the directory iteration code for scrub 2023-04-11 19:00:17 -07:00
readdir.h xfs: streamline the directory iteration code for scrub 2023-04-11 19:00:17 -07:00
refcount.c xfs: fix duplicate includes 2023-04-20 08:18:34 +10:00
repair.c xfs: remove the for_each_xbitmap_ helpers 2023-04-11 19:00:35 -07:00
repair.h xfs: introduce bitmap type for AG blocks 2023-04-11 19:00:37 -07:00
rmap.c xfs: cross-reference rmap records with refcount btrees 2023-04-11 19:00:39 -07:00
rtbitmap.c xfs: update copyright years for scrub/ files 2023-04-11 18:59:57 -07:00
scrub.c xfs: disable reaping in fscounters scrub 2023-05-02 09:16:14 +10:00
scrub.h xfs: Fix undefined behavior of shift into sign bit 2023-06-05 04:09:27 +10:00
symlink.c xfs: update copyright years for scrub/ files 2023-04-11 18:59:57 -07:00
trace.c xfs: update copyright years for scrub/ files 2023-04-11 18:59:57 -07:00
trace.h xfs: disable reaping in fscounters scrub 2023-05-02 09:16:14 +10:00
xfs_scrub.h xfs: update copyright years for scrub/ files 2023-04-11 18:59:57 -07:00