1250081 Commits

Author SHA1 Message Date
Chandan Babu R
a7ade7e13d xfs: btree readahead cleanups [v29.3 10/18]
Minor cleanups for the btree block readahead code.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZdlBYQAKCRBKO3ySh0YR
 pmF2AQCvxmU219Wjaa25Bkor40UGpcgy4T5xbFdSFT8umdPxXAD+IdVsIUm6pPmk
 gr4+OPqIwJbGUaz3GJHg5qO6Wh+orQY=
 =rxd3
 -----END PGP SIGNATURE-----

Merge tag 'btree-readahead-cleanups-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: btree readahead cleanups

Minor cleanups for the btree block readahead code.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'btree-readahead-cleanups-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: split xfs_buf_rele for cached vs uncached buffers
  xfs: move and rename xfs_btree_read_bufl
  xfs: remove xfs_btree_reada_bufs
  xfs: remove xfs_btree_reada_bufl
2024-02-24 10:11:25 +05:30
Chandan Babu R
169c030a95 xfs: btree check cleanups [v29.3 09/18]
Minor cleanups for the btree block pointer checking code.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZdlBYQAKCRBKO3ySh0YR
 psBVAP4ik1Cj5KPP75mJws4duDycYjy9Wm0ZucNjUD19iQbo9wEAqXwFZuUm/wuJ
 TbCPVZ9EWtqg7pInrOSK+GmoOjUciQM=
 =FpUY
 -----END PGP SIGNATURE-----

Merge tag 'btree-check-cleanups-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: btree check cleanups

Minor cleanups for the btree block pointer checking code.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'btree-check-cleanups-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: factor out a __xfs_btree_check_lblock_hdr helper
  xfs: rename btree helpers that depends on the block number representation
  xfs: consolidate btree block verification
  xfs: tighten up validation of root block in inode forks
  xfs: remove the crc variable in __xfs_btree_check_lblock
  xfs: misc cleanups for __xfs_btree_check_sblock
  xfs: consolidate btree ptr checking
  xfs: open code xfs_btree_check_lptr in xfs_bmap_btree_to_extents
  xfs: simplify xfs_btree_check_lblock_siblings
  xfs: simplify xfs_btree_check_sblock_siblings
2024-02-24 10:08:27 +05:30
Chandan Babu R
ee138217c3 xfs: remove bc_btnum from btree cursors [v29.3 08/18]
From Christoph Hellwig,
 
 This series continues the migration of btree geometry information out of
 the cursor structure and into the ops structure.  This time around, we
 replace the btree type enumeration (btnum) with an explicit name string
 in the btree ops structure.  This enables easy creation of /any/ new
 btree type without having to mess with libxfs.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZdlBYQAKCRBKO3ySh0YR
 ppPOAP9QUT/PSvFdaSSKr64DAIy/fNE5qusmDfmBeQY/uMqOAQEAr75VaDV77JA3
 KYIXiQVu6siZrRzVOC7T6oANii7+Ugk=
 =1Tbm
 -----END PGP SIGNATURE-----

Merge tag 'btree-remove-btnum-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: remove bc_btnum from btree cursors

From Christoph Hellwig,

This series continues the migration of btree geometry information out of
the cursor structure and into the ops structure.  This time around, we
replace the btree type enumeration (btnum) with an explicit name string
in the btree ops structure.  This enables easy creation of /any/ new
btree type without having to mess with libxfs.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'btree-remove-btnum-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: remove xfs_btnum_t
  xfs: pass a 'bool is_finobt' to xfs_inobt_insert
  xfs: split xfs_inobt_init_cursor
  xfs: split xfs_inobt_insert_sprec
  xfs: remove the which variable in xchk_iallocbt
  xfs: remove the btnum argument to xfs_inobt_count_blocks
  xfs: remove xfs_inobt_cur
  xfs: split xfs_allocbt_init_cursor
  xfs: refactor the btree cursor allocation logic in xchk_ag_btcur_init
  xfs: add a sick_mask to struct xfs_btree_ops
  xfs: add a name field to struct xfs_btree_ops
  xfs: split the agf_roots and agf_levels arrays
  xfs: remove xfs_bmbt_stage_cursor
  xfs: fold xfs_bmbt_init_common into xfs_bmbt_init_cursor
  xfs: make staging file forks explicit
  xfs: make full use of xfs_btree_stage_ifakeroot in xfs_bmbt_stage_cursor
  xfs: remove xfs_rmapbt_stage_cursor
  xfs: fold xfs_rmapbt_init_common into xfs_rmapbt_init_cursor
  xfs: remove xfs_refcountbt_stage_cursor
  xfs: fold xfs_refcountbt_init_common into xfs_refcountbt_init_cursor
  xfs: remove xfs_inobt_stage_cursor
  xfs: fold xfs_inobt_init_common into xfs_inobt_init_cursor
  xfs: remove xfs_allocbt_stage_cursor
  xfs: fold xfs_allocbt_init_common into xfs_allocbt_init_cursor
  xfs: don't override bc_ops for staging btrees
  xfs: add a xfs_btree_init_ptr_from_cur
  xfs: move comment about two 2 keys per pointer in the rmap btree
2024-02-24 10:04:39 +05:30
Chandan Babu R
681cb87b6a xfs: move btree geometry to ops struct [v29.3 07/18]
This patchset prepares the generic btree code to allow for the creation
 of new btree types outside of libxfs.  The end goal here is for online
 fsck to be able to create its own in-memory btrees that will be used to
 improve the performance (and reduce the memory requirements of) the
 refcount btree.
 
 To enable this, I decided that the btree ops structure is the ideal
 place to encode all of the geometry information about a btree. The btree
 ops struture already contains the buffer ops (and hence the btree block
 magic numbers) as well as the key and record sizes, so it doesn't seem
 all that farfetched to encode the XFS_BTREE_ flags that determine the
 geometry (ROOT_IN_INODE, LONG_PTRS, etc).
 
 The rest of the patchset cleans up the btree functions that initialize
 btree blocks and btree buffers.  The bulk of this work is to replace
 btree geometry related function call arguments with a single pointer to
 the ops structure, and then clean up everything else around that.  As a
 side effect, we rename the functions.
 
 Later, Christoph Hellwig and I merged together a bunch more cleanups
 that he wanted to do for a while.  All the btree geometry information is
 now in the btree ops structure, we've created an explicit btree type
 (ag, inode, mem) and moved the per-btree type information to a separate
 union.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZdlBYQAKCRBKO3ySh0YR
 puvdAQDMAehLo8djvsi4dipw1+v7kgD11/H1sD4qsHQTc2UuGAEA3me2bHB36o1k
 bDL7Vmsin6BazStkoqCGhc18x8MW3w4=
 =0Fis
 -----END PGP SIGNATURE-----

Merge tag 'btree-geometry-in-ops-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: move btree geometry to ops struct

This patchset prepares the generic btree code to allow for the creation
of new btree types outside of libxfs.  The end goal here is for online
fsck to be able to create its own in-memory btrees that will be used to
improve the performance (and reduce the memory requirements of) the
refcount btree.

To enable this, I decided that the btree ops structure is the ideal
place to encode all of the geometry information about a btree. The btree
ops struture already contains the buffer ops (and hence the btree block
magic numbers) as well as the key and record sizes, so it doesn't seem
all that farfetched to encode the XFS_BTREE_ flags that determine the
geometry (ROOT_IN_INODE, LONG_PTRS, etc).

The rest of the patchset cleans up the btree functions that initialize
btree blocks and btree buffers.  The bulk of this work is to replace
btree geometry related function call arguments with a single pointer to
the ops structure, and then clean up everything else around that.  As a
side effect, we rename the functions.

Later, Christoph Hellwig and I merged together a bunch more cleanups
that he wanted to do for a while.  All the btree geometry information is
now in the btree ops structure, we've created an explicit btree type
(ag, inode, mem) and moved the per-btree type information to a separate
union.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'btree-geometry-in-ops-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: create predicate to determine if cursor is at inode root level
  xfs: split the per-btree union in struct xfs_btree_cur
  xfs: split out a btree type from the btree ops geometry flags
  xfs: store the btree pointer length in struct xfs_btree_ops
  xfs: factor out a btree block owner check
  xfs: factor out a xfs_btree_owner helper
  xfs: move the btree stats offset into struct btree_ops
  xfs: move lru refs to the btree ops structure
  xfs: set btree block buffer ops in _init_buf
  xfs: remove the unnecessary daddr paramter to _init_block
  xfs: btree convert xfs_btree_init_block to xfs_btree_init_buf calls
  xfs: rename btree block/buffer init functions
  xfs: initialize btree blocks using btree_ops structure
  xfs: extern some btree ops structures
  xfs: turn the allocbt cursor active field into a btree flag
  xfs: consolidate the xfs_alloc_lookup_* helpers
  xfs: remove bc_ino.flags
  xfs: encode the btree geometry flags in the btree ops structure
  xfs: fix imprecise logic in xchk_btree_check_block_owner
  xfs: drop XFS_BTREE_CRC_BLOCKS
  xfs: set the btree cursor bc_ops in xfs_btree_alloc_cursor
  xfs: consolidate btree block allocation tracepoints
  xfs: consolidate btree block freeing tracepoints
2024-02-24 10:01:16 +05:30
Chandan Babu R
5d1bd19d83 xfs: online repair for fs summary counters [v29.3 06/18]
A longstanding deficiency in the online fs summary counter scrubbing
 code is that it hasn't any means to quiesce the incore percpu counters
 while it's running.  There is no way to coordinate with other threads
 are reserving or freeing free space simultaneously, which leads to false
 error reports.  Right now, if the discrepancy is large, we just sort of
 shrug and bail out with an incomplete flag, but this is lame.
 
 For repair activity, we actually /do/ need to stabilize the counters to
 get an accurate reading and install it in the percpu counter.  To
 improve the former and enable the latter, allow the fscounters online
 fsck code to perform an exclusive mini-freeze on the filesystem.  The
 exclusivity prevents userspace from thawing while we're running, and the
 mini-freeze means that we don't wait for the log to quiesce, which will
 make both speedier.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZdlBYQAKCRBKO3ySh0YR
 pjYgAQCHdKKwkD0bAZyKT6By30Vxiahey5HUrlLvg1QeGIzXlAD/e4oLwdfxYrcr
 1wL7GTDix9eVJSMe7ZSgmxX4W9KVMAE=
 =CqKZ
 -----END PGP SIGNATURE-----

Merge tag 'repair-fscounters-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: online repair for fs summary counters

A longstanding deficiency in the online fs summary counter scrubbing
code is that it hasn't any means to quiesce the incore percpu counters
while it's running.  There is no way to coordinate with other threads
are reserving or freeing free space simultaneously, which leads to false
error reports.  Right now, if the discrepancy is large, we just sort of
shrug and bail out with an incomplete flag, but this is lame.

For repair activity, we actually /do/ need to stabilize the counters to
get an accurate reading and install it in the percpu counter.  To
improve the former and enable the latter, allow the fscounters online
fsck code to perform an exclusive mini-freeze on the filesystem.  The
exclusivity prevents userspace from thawing while we're running, and the
mini-freeze means that we don't wait for the log to quiesce, which will
make both speedier.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'repair-fscounters-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: repair summary counters
2024-02-24 09:58:28 +05:30
Chandan Babu R
f107757953 xfs: indirect health reporting [v29.3 05/18]
This series enables the XFS health reporting infrastructure to remember
 indirect health concerns when resources are scarce.  For example, if a
 scrub notices that there's something wrong with an inode's metadata but
 memory reclaim needs to free the incore inode, we want to record in the
 perag data the fact that there was some inode somewhere with an error.
 The perag structures never go away.
 
 The first two patches in this series set that up, and the third one
 provides a means for xfs_scrub to tell the kernel that it can forget the
 indirect problem report.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZdlBYAAKCRBKO3ySh0YR
 pvzvAQD1oxlTpXYLjT5xnhQHpg/nYoXUQdOqFLrMTH5i8mm9VQD+JmiLvIUCD5Au
 K4qtmq9MSO4XzTKDbx9B4l/rn0H4uQ0=
 =H6az
 -----END PGP SIGNATURE-----

Merge tag 'indirect-health-reporting-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: indirect health reporting

This series enables the XFS health reporting infrastructure to remember
indirect health concerns when resources are scarce.  For example, if a
scrub notices that there's something wrong with an inode's metadata but
memory reclaim needs to free the incore inode, we want to record in the
perag data the fact that there was some inode somewhere with an error.
The perag structures never go away.

The first two patches in this series set that up, and the third one
provides a means for xfs_scrub to tell the kernel that it can forget the
indirect problem report.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'indirect-health-reporting-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: update health status if we get a clean bill of health
  xfs: remember sick inodes that get inactivated
  xfs: add secondary and indirect classes to the health tracking system
2024-02-24 09:55:02 +05:30
Chandan Babu R
6fe1910e85 xfs: report corruption to the health trackers [v29.3 04/18]
Any time that the runtime code thinks it has found corrupt metadata, it
 should tell the health tracking subsystem that the corresponding part of
 the filesystem is sick.  These reports come primarily from two places --
 code that is reading a buffer that fails validation, and higher level
 pieces that observe a conflict involving multiple buffers.  This
 patchset uses automated scanning to update all such callsites with a
 mark_sick call.
 
 Doing this enables the health system to record problem observed at
 runtime, which (for now) can prompt the sysadmin to run xfs_scrub, and
 (later) may enable more targetted fixing of the filesystem.
 
 Note: Earlier reviewers of this patchset suggested that the verifier
 functions themselves should be responsible for calling _mark_sick.  In a
 higher level language this would be easily accomplished with lambda
 functions and closures.  For the kernel, however, we'd have to create
 the necessary closures by hand, pass them to the buf_read calls, and
 then implement necessary state tracking to detach the xfs_buf from the
 closure at the necessary time.  This is far too much work and complexity
 and will not be pursued further.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZdlBYAAKCRBKO3ySh0YR
 pi9LAQCgKJHvlmaM5JUNPoa06YCqxvsrDHRWQ0j7cZ/xm9AGSAEAmhDay+1oCDef
 PIPxJr//SvxXByCzttjjOA+TAouGFA0=
 =2Xjd
 -----END PGP SIGNATURE-----

Merge tag 'corruption-health-reports-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: report corruption to the health trackers

Any time that the runtime code thinks it has found corrupt metadata, it
should tell the health tracking subsystem that the corresponding part of
the filesystem is sick.  These reports come primarily from two places --
code that is reading a buffer that fails validation, and higher level
pieces that observe a conflict involving multiple buffers.  This
patchset uses automated scanning to update all such callsites with a
mark_sick call.

Doing this enables the health system to record problem observed at
runtime, which (for now) can prompt the sysadmin to run xfs_scrub, and
(later) may enable more targetted fixing of the filesystem.

Note: Earlier reviewers of this patchset suggested that the verifier
functions themselves should be responsible for calling _mark_sick.  In a
higher level language this would be easily accomplished with lambda
functions and closures.  For the kernel, however, we'd have to create
the necessary closures by hand, pass them to the buf_read calls, and
then implement necessary state tracking to detach the xfs_buf from the
closure at the necessary time.  This is far too much work and complexity
and will not be pursued further.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'corruption-health-reports-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: report XFS_IS_CORRUPT errors to the health system
  xfs: report realtime metadata corruption errors to the health system
  xfs: report quota block corruption errors to the health system
  xfs: report inode corruption errors to the health system
  xfs: report symlink block corruption errors to the health system
  xfs: report dir/attr block corruption errors to the health system
  xfs: report btree block corruption errors to the health system
  xfs: report block map corruption errors to the health tracking system
  xfs: report ag header corruption errors to the health tracking system
  xfs: report fs corruption errors to the health tracking system
  xfs: separate the marking of sick and checked metadata
2024-02-24 09:51:32 +05:30
Chandan Babu R
128d0fd1ab xfs: online repair of file link counts [v29.3 03/18]
Now that we've created the infrastructure to perform live scans of every
 file in the filesystem and the necessary hook infrastructure to observe
 live updates, use it to scan directories to compute the correct link
 counts for files in the filesystem, and reset those link counts.
 
 This patchset creates a tailored readdir implementation for scrub
 because the regular version has to cycle ILOCKs to copy information to
 userspace.  We can't cycle the ILOCK during the nlink scan and we don't
 need all the other VFS support code (maintaining a readdir cursor and
 translating XFS structures to VFS structures and back) so it was easier
 to duplicate the code.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZdlBYAAKCRBKO3ySh0YR
 pjJwAP49J6UgZUDQMX4rQ5q2TbyHLnyvUzeiQ/Cc8IqXau5VxwD/U3QNPii5uUMw
 jNid2AMba4AkXkskU6fr4do8UwmPSQ4=
 =Dva/
 -----END PGP SIGNATURE-----

Merge tag 'scrub-nlinks-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: online repair of file link counts

Now that we've created the infrastructure to perform live scans of every
file in the filesystem and the necessary hook infrastructure to observe
live updates, use it to scan directories to compute the correct link
counts for files in the filesystem, and reset those link counts.

This patchset creates a tailored readdir implementation for scrub
because the regular version has to cycle ILOCKs to copy information to
userspace.  We can't cycle the ILOCK during the nlink scan and we don't
need all the other VFS support code (maintaining a readdir cursor and
translating XFS structures to VFS structures and back) so it was easier
to duplicate the code.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'scrub-nlinks-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: teach repair to fix file nlinks
  xfs: track directory entry updates during live nlinks fsck
  xfs: teach scrub to check file nlinks
  xfs: report health of inode link counts
2024-02-24 09:47:39 +05:30
Chandan Babu R
aa03f524a2 xfs: online repair of quota counters [v29.3 02/18]
This series uses the inode scanner and live update hook functionality
 introduced in the last patchset to implement quotacheck on a live
 filesystem.  The quotacheck scrubber builds an incore copy of the
 dquot resource usage counters and compares it to the live dquots to
 report discrepancies.
 
 If the user chooses to repair the quota counters, the repair function
 visits each incore dquot to update the counts from the live information.
 The live update hooks are key to keeping the incore copy up to date.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZdlBYAAKCRBKO3ySh0YR
 pl+VAQDUflOVAEIKqwm+EaFFkbW7esxF4UYTn5N9Vj0hiLhogAD/SBOf/3fF58AI
 kwRwHDBtbDesuwZbTnaCo7Vj7Hq33wM=
 =2VuF
 -----END PGP SIGNATURE-----

Merge tag 'repair-quotacheck-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: online repair of quota counters

This series uses the inode scanner and live update hook functionality
introduced in the last patchset to implement quotacheck on a live
filesystem.  The quotacheck scrubber builds an incore copy of the
dquot resource usage counters and compares it to the live dquots to
report discrepancies.

If the user chooses to repair the quota counters, the repair function
visits each incore dquot to update the counts from the live information.
The live update hooks are key to keeping the incore copy up to date.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'repair-quotacheck-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: repair dquots based on live quotacheck results
  xfs: repair cannot update the summary counters when logging quota flags
  xfs: track quota updates during live quotacheck
  xfs: implement live quotacheck inode scan
  xfs: create a sparse load xfarray function
  xfs: create a helper to count per-device inode block usage
  xfs: create a xchk_trans_alloc_empty helper for scrub
  xfs: report the health of quota counts
2024-02-24 09:44:28 +05:30
Chandan Babu R
8e3ef44f9b xfs: repair inode mode by scanning dirs [v29.3 01/18]
One missing piece of functionality in the inode record repair code is
 figuring out what to do with a file whose mode is so corrupt that we
 cannot tell us the type of the file.  Originally this was done by
 guessing the mode from the ondisk inode contents, but Christoph didn't
 like that because it read from data fork block 0, which could be user
 controlled data.
 
 Therefore, I've replaced all that with a directory scanner that looks
 for any dirents that point to the file with the garbage mode.  If so,
 the ftype in the dirent will tell us exactly what mode to set on the
 file.  Since users cannot directly write to the ftype field of a dirent,
 this should be safe.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZdlBYAAKCRBKO3ySh0YR
 pvYaAQCdHMP4V94sw+jI46FHgqBAEEuqZUjq8cHwZPrtDzZc5QEA4fsbzR8yXJsw
 imsHjftkRhSEav0LVXhPCbaFfphbUQ0=
 =O1cc
 -----END PGP SIGNATURE-----

Merge tag 'repair-inode-mode-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC

xfs: repair inode mode by scanning dirs

One missing piece of functionality in the inode record repair code is
figuring out what to do with a file whose mode is so corrupt that we
cannot tell us the type of the file.  Originally this was done by
guessing the mode from the ondisk inode contents, but Christoph didn't
like that because it read from data fork block 0, which could be user
controlled data.

Therefore, I've replaced all that with a directory scanner that looks
for any dirents that point to the file with the garbage mode.  If so,
the ftype in the dirent will tell us exactly what mode to set on the
file.  Since users cannot directly write to the ftype field of a dirent,
this should be safe.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'repair-inode-mode-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: repair file modes by scanning for a dirent pointing to us
  xfs: create a macro for decoding ftypes in tracepoints
  xfs: create a predicate to determine if two xfs_names are the same
  xfs: create a static name for the dot entry too
  xfs: iscan batching should handle unallocated inodes too
  xfs: cache a bunch of inodes for repair scans
  xfs: stagger the starting AG of scrub iscans to reduce contention
  xfs: allow scrub to hook metadata updates in other writers
  xfs: implement live inode scan for scrub
  xfs: speed up xfs_iwalk_adjust_start a little bit
2024-02-24 09:40:39 +05:30
Christoph Hellwig
24f755e485 xfs: split xfs_buf_rele for cached vs uncached buffers
xfs_buf_rele is a bit confusing because it mixes up handling of normal
cached and the special uncached buffers without much explanation.
Split the handling into two different helpers, and use a clearly named
helper that checks the hash key to distinguish the two cases instead
of checking the pag pointer.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:41:02 -08:00
Christoph Hellwig
6a701eb8fb xfs: move and rename xfs_btree_read_bufl
Despite its name, xfs_btree_read_bufl doesn't contain any btree-related
functionaliy and isn't used by the btree code.  Move it to xfs_bmap.c,
hard code the refval and ops arguments and rename it to
xfs_bmap_read_buf.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:41:01 -08:00
Christoph Hellwig
6324b00c9e xfs: remove xfs_btree_reada_bufs
xfs_btree_reada_bufl just wraps xfs_btree_readahead and a agblock
to daddr conversion.  Just open code it's three callsites in the
two callers (One of which isn't even btree related).

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:41:01 -08:00
Christoph Hellwig
5eec8fa30d xfs: remove xfs_btree_reada_bufl
xfs_btree_reada_bufl just wraps xfs_btree_readahead and a fsblock
to daddr conversion.  Just open code it's two callsites in the only
caller.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:41:00 -08:00
Christoph Hellwig
79e72304dc xfs: factor out a __xfs_btree_check_lblock_hdr helper
This will allow sharing code with the in-memory block checking helper.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:59 -08:00
Christoph Hellwig
5ef819c34f xfs: rename btree helpers that depends on the block number representation
All these helpers hardcode fsblocks or agblocks and not just the pointer
size.  Rename them so that the names are still fitting when we add the
long format in-memory blocks and adjust the checks when calling them to
check the btree types and not just pointer length.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:58 -08:00
Christoph Hellwig
4ce0c711d9 xfs: consolidate btree block verification
Add a __xfs_btree_check_block helper that can be called by the scrub code
to validate a btree block of any form, and move the duplicate error
handling code from xfs_btree_check_sblock and xfs_btree_check_lblock into
xfs_btree_check_block and thus remove these two helpers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:57 -08:00
Christoph Hellwig
d477f1749f xfs: tighten up validation of root block in inode forks
Check that root blocks that sit in the inode fork and thus have a NULL
bp don't have siblings.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:57 -08:00
Christoph Hellwig
bd45019d9a xfs: remove the crc variable in __xfs_btree_check_lblock
crc is only used once, just use the xfs_has_crc check directly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:56 -08:00
Christoph Hellwig
43be09192c xfs: misc cleanups for __xfs_btree_check_sblock
Remove the local crc variable that is only used once and remove the bp
NULL checking as it can't ever be NULL for short form blocks.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:55 -08:00
Christoph Hellwig
57982d6c83 xfs: consolidate btree ptr checking
Merge xfs_btree_check_sptr and xfs_btree_check_lptr into a single
__xfs_btree_check_ptr that can be shared between xfs_btree_check_ptr
and the scrub code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:54 -08:00
Christoph Hellwig
fb0793f206 xfs: open code xfs_btree_check_lptr in xfs_bmap_btree_to_extents
xfs_bmap_btree_to_extents always passes a level of 1 to
xfs_btree_check_lptr, thus making the level check redundant.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:53 -08:00
Christoph Hellwig
8b8ada973c xfs: simplify xfs_btree_check_lblock_siblings
Stop using xfs_btree_check_lptr in xfs_btree_check_lblock_siblings,
as it only duplicates the xfs_verify_fsbno call in the other leg of
if / else besides adding a tautological level check.

With this the cur and level arguments can be removed as they are
now unused.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:53 -08:00
Christoph Hellwig
4bc94bf640 xfs: simplify xfs_btree_check_sblock_siblings
Stop using xfs_btree_check_sptr in xfs_btree_check_sblock_siblings,
as it only duplicates the xfs_verify_agbno call in the other leg of
if / else besides adding a tautological level check.

With this the cur and level arguments can be removed as they are
now unused.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:52 -08:00
Christoph Hellwig
ec793e690f xfs: remove xfs_btnum_t
The last checks for bc_btnum can be replaced with helpers that check
the btree ops.  This allows adding new btrees to XFS without having
to update a global enum.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
[djwong: complete the ops predicates]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:51 -08:00
Christoph Hellwig
fbeef4e061 xfs: pass a 'bool is_finobt' to xfs_inobt_insert
This is one of the last users of xfs_btnum_t and can only designate
either the inobt or finobt.  Replace it with a simple bool.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:50 -08:00
Christoph Hellwig
14dd46cf31 xfs: split xfs_inobt_init_cursor
Split xfs_inobt_init_cursor into separate routines for the inobt and
finobt to prepare for the removal of the xfs_btnum global enumeration
of btree types.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:49 -08:00
Christoph Hellwig
8541a7d9da xfs: split xfs_inobt_insert_sprec
Split the finobt version that never merges and uses a different cursor
out of xfs_inobt_insert_sprec to prepare for removing xfs_btnum_t.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:48 -08:00
Christoph Hellwig
c81a01a74a xfs: remove the which variable in xchk_iallocbt
The which variable that holds a btree number is passed to two functions
that ignore it and used in a single check that can check the sm_type
as well.  Remove it to unclutter the code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:48 -08:00
Christoph Hellwig
4bfb028a4c xfs: remove the btnum argument to xfs_inobt_count_blocks
xfs_inobt_count_blocks is only used for the finobt.  Hardcode the btnum
argument and rename the function to match that.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:47 -08:00
Christoph Hellwig
3038fd8129 xfs: remove xfs_inobt_cur
This helper provides no real advantage over just open code the two
calls in it in the callers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:46 -08:00
Christoph Hellwig
1c8b9fd278 xfs: split xfs_allocbt_init_cursor
Split xfs_allocbt_init_cursor into separate routines for the by-bno
and by-cnt btrees to prepare for the removal of the xfs_btnum global
enumeration of btree types.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:40:12 -08:00
Christoph Hellwig
4803992619 xfs: refactor the btree cursor allocation logic in xchk_ag_btcur_init
Change xchk_ag_btcur_init to allocate all cursors first and only then
check if we should delete them again because the btree is to damaged.

This allows reusing the sick_mask in struct xfs_btree_ops and simplifies
the code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:48 -08:00
Christoph Hellwig
7f47734ad6 xfs: add a sick_mask to struct xfs_btree_ops
Clean up xfs_btree_mark_sick by adding a sick_mask to the btree-ops
for all AG-root btrees.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:47 -08:00
Christoph Hellwig
77953b97bb xfs: add a name field to struct xfs_btree_ops
The btnum in struct xfs_btree_ops is often used for printing a symbolic
name for the btree.  Add a name field to the ops structure and use that
directly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:47 -08:00
Christoph Hellwig
e45ea36451 xfs: split the agf_roots and agf_levels arrays
Using arrays of largely unrelated fields that use the btree number
as index is not very robust.  Split the arrays into three separate
fields instead.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:46 -08:00
Christoph Hellwig
02f7ebf5f9 xfs: remove xfs_bmbt_stage_cursor
Just open code the two calls in the callers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:45 -08:00
Christoph Hellwig
802f91f7b1 xfs: fold xfs_bmbt_init_common into xfs_bmbt_init_cursor
Make the levels initialization in xfs_bmbt_init_cursor conditional
and merge the two helpers.

This requires the fakeroot case to now pass a -1 whichfork directly
into xfs_bmbt_init_cursor, and some special casing for that, but
at least this scheme to deal with the fake btree root is handled and
documented in once place now.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
[djwong: tidy up a multline ternary]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:44 -08:00
Darrick J. Wong
42e357c806 xfs: make staging file forks explicit
Don't open-code "-1" for whichfork when we're creating a staging btree
for a repair; let's define an actual symbol to make grepping and
understanding easier.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
2024-02-22 12:39:43 -08:00
Christoph Hellwig
579d7022d1 xfs: make full use of xfs_btree_stage_ifakeroot in xfs_bmbt_stage_cursor
Remove the duplicate cur->bc_nlevels assignment in xfs_bmbt_stage_cursor,
and move the cur->bc_ino.forksize assignment into
xfs_btree_stage_ifakeroot as it is part of setting up the fake btree
root.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:43 -08:00
Christoph Hellwig
1317813290 xfs: remove xfs_rmapbt_stage_cursor
xfs_rmapbt_stage_cursor is currently unused, but future callers can
trivially open code the two calls.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:42 -08:00
Christoph Hellwig
c49a4b2f0e xfs: fold xfs_rmapbt_init_common into xfs_rmapbt_init_cursor
Make the levels initialization in xfs_rmapbt_init_cursor conditional
and merge the two helpers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:41 -08:00
Christoph Hellwig
a5c2194406 xfs: remove xfs_refcountbt_stage_cursor
Just open code the two calls in the callers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:40 -08:00
Christoph Hellwig
4f2dc69e4b xfs: fold xfs_refcountbt_init_common into xfs_refcountbt_init_cursor
Make the levels initialization in xfs_refcountbt_init_cursor conditional
and merge the two helpers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:39 -08:00
Christoph Hellwig
6234dee7e6 xfs: remove xfs_inobt_stage_cursor
Just open code the two calls in the callers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:39 -08:00
Christoph Hellwig
f6c98d921a xfs: fold xfs_inobt_init_common into xfs_inobt_init_cursor
Make the levels initialization in xfs_inobt_init_cursor conditional
and merge the two helpers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:38 -08:00
Christoph Hellwig
91796b2eef xfs: remove xfs_allocbt_stage_cursor
Just open code the two calls in the callers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:37 -08:00
Christoph Hellwig
fb518f8eeb xfs: fold xfs_allocbt_init_common into xfs_allocbt_init_cursor
Make the levels initialization in xfs_allocbt_init_cursor conditional
and merge the two helpers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:39:36 -08:00
Christoph Hellwig
2b9e7f2668 xfs: don't override bc_ops for staging btrees
Add a few conditionals for staging btrees to the core btree code instead
of overloading the bc_ops vector.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:37:35 -08:00
Christoph Hellwig
f9c18129e5 xfs: add a xfs_btree_init_ptr_from_cur
Inode-rooted btrees don't need to initialize the root pointer in the
->init_ptr_from_cur method as the root is found by the
xfs_btree_get_iroot method later.  Make ->init_ptr_from_cur option
for inode rooted btrees by providing a helper that does the right
thing for the given btree type and also documents the semantics.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
2024-02-22 12:37:26 -08:00