xfs: add a per-leaf block callback to xchk_xattr_walk
authorDarrick J. Wong <djwong@kernel.org>
Mon, 22 Apr 2024 16:48:15 +0000 (09:48 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 23 Apr 2024 23:55:15 +0000 (16:55 -0700)
Add a second callback function to xchk_xattr_walk so that we can do
something in between attr leaf blocks.  This will be used by the next
patch to see if we should flush cached parent pointer updates to
constrain memory usage.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/scrub/attr.c
fs/xfs/scrub/dir_repair.c
fs/xfs/scrub/listxattr.c
fs/xfs/scrub/listxattr.h
fs/xfs/scrub/nlinks.c
fs/xfs/scrub/parent.c

index b550f3e34ffc73cc7900f8f8f036702f8a3edd8a..708334f9b2bd13747da3804cca3124863eaa57f7 100644 (file)
@@ -675,7 +675,7 @@ xchk_xattr(
         * iteration, which doesn't really follow the usual buffer
         * locking order.
         */
-       error = xchk_xattr_walk(sc, sc->ip, xchk_xattr_actor, NULL);
+       error = xchk_xattr_walk(sc, sc->ip, xchk_xattr_actor, NULL, NULL);
        if (!xchk_fblock_process_error(sc, XFS_ATTR_FORK, 0, &error))
                return error;
 
index 60e31da4451e8a023811e13788cfd2c559cf7c45..e968150fe0f063e2d0431c40c4201df2189a4b4e 100644 (file)
@@ -1288,7 +1288,7 @@ xrep_dir_scan_file(
                goto scan_done;
        }
 
-       error = xchk_xattr_walk(rd->sc, ip, xrep_dir_scan_pptr, rd);
+       error = xchk_xattr_walk(rd->sc, ip, xrep_dir_scan_pptr, NULL, rd);
        if (error)
                goto scan_done;
 
index cbe5911ecbbcf4ee3a7f0c7ae569086b5d3b8f78..256ff7700c9425481107a05e2b5792aafe42956f 100644 (file)
@@ -221,6 +221,7 @@ xchk_xattr_walk_node(
        struct xfs_scrub                *sc,
        struct xfs_inode                *ip,
        xchk_xattr_fn                   attr_fn,
+       xchk_xattrleaf_fn               leaf_fn,
        void                            *priv)
 {
        struct xfs_attr3_icleaf_hdr     leafhdr;
@@ -252,6 +253,12 @@ xchk_xattr_walk_node(
 
                xfs_trans_brelse(sc->tp, leaf_bp);
 
+               if (leaf_fn) {
+                       error = leaf_fn(sc, priv);
+                       if (error)
+                               goto out_bitmap;
+               }
+
                /* Make sure we haven't seen this new leaf already. */
                len = 1;
                if (xdab_bitmap_test(&seen_dablks, leafhdr.forw, &len)) {
@@ -288,6 +295,7 @@ xchk_xattr_walk(
        struct xfs_scrub        *sc,
        struct xfs_inode        *ip,
        xchk_xattr_fn           attr_fn,
+       xchk_xattrleaf_fn       leaf_fn,
        void                    *priv)
 {
        int                     error;
@@ -308,5 +316,5 @@ xchk_xattr_walk(
        if (xfs_attr_is_leaf(ip))
                return xchk_xattr_walk_leaf(sc, ip, attr_fn, priv);
 
-       return xchk_xattr_walk_node(sc, ip, attr_fn, priv);
+       return xchk_xattr_walk_node(sc, ip, attr_fn, leaf_fn, priv);
 }
index 48fe89d05946b23337292f8d8944af4638257b55..703cfb7b14cfd33151f374a5b8dcaf9d2c039c50 100644 (file)
@@ -11,7 +11,9 @@ typedef int (*xchk_xattr_fn)(struct xfs_scrub *sc, struct xfs_inode *ip,
                unsigned int namelen, const void *value, unsigned int valuelen,
                void *priv);
 
+typedef int (*xchk_xattrleaf_fn)(struct xfs_scrub *sc, void *priv);
+
 int xchk_xattr_walk(struct xfs_scrub *sc, struct xfs_inode *ip,
-               xchk_xattr_fn attr_fn, void *priv);
+               xchk_xattr_fn attr_fn, xchk_xattrleaf_fn leaf_fn, void *priv);
 
 #endif /* __XFS_SCRUB_LISTXATTR_H__ */
index d27b32e6f33db7147dfed503664566d9d214d6db..80aee30886c456257f501d478eda84faef82d136 100644 (file)
@@ -434,7 +434,8 @@ xchk_nlinks_collect_dir(
                        goto out_unlock;
                }
 
-               error = xchk_xattr_walk(sc, dp, xchk_nlinks_collect_pptr, xnc);
+               error = xchk_xattr_walk(sc, dp, xchk_nlinks_collect_pptr, NULL,
+                               xnc);
                if (error == -ECANCELED) {
                        error = 0;
                        goto out_unlock;
index 068691434be1718724b68d8e278bb8ae312c4452..733c410a22797a91c3d2395677332667dc9496e3 100644 (file)
@@ -317,7 +317,7 @@ xchk_parent_pptr_and_dotdot(
                return 0;
 
        /* Otherwise, walk the pptrs again, and check. */
-       error = xchk_xattr_walk(sc, sc->ip, xchk_parent_scan_dotdot, pp);
+       error = xchk_xattr_walk(sc, sc->ip, xchk_parent_scan_dotdot, NULL, pp);
        if (error == -ECANCELED) {
                /* Found a parent pointer that matches dotdot. */
                return 0;
@@ -699,7 +699,8 @@ xchk_parent_count_pptrs(
         */
        if (pp->need_revalidate) {
                pp->pptrs_found = 0;
-               error = xchk_xattr_walk(sc, sc->ip, xchk_parent_count_pptr, pp);
+               error = xchk_xattr_walk(sc, sc->ip, xchk_parent_count_pptr,
+                               NULL, pp);
                if (error == -EFSCORRUPTED) {
                        /* Found a bad parent pointer */
                        xchk_fblock_set_corrupt(sc, XFS_ATTR_FORK, 0);
@@ -758,7 +759,7 @@ xchk_parent_pptr(
        if (error)
                goto out_entries;
 
-       error = xchk_xattr_walk(sc, sc->ip, xchk_parent_scan_attr, pp);
+       error = xchk_xattr_walk(sc, sc->ip, xchk_parent_scan_attr, NULL, pp);
        if (error == -ECANCELED) {
                error = 0;
                goto out_names;