]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: report dir/attr block corruption errors to the health system
authorDarrick J. Wong <djwong@kernel.org>
Mon, 22 Apr 2024 17:00:55 +0000 (10:00 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 3 Jun 2024 18:37:36 +0000 (11:37 -0700)
Source kernel commit: ca14c0968c1f693ab4bcb5368c800c33e7a2ad7e

Whenever we encounter corrupt directory or extended attribute blocks, we
should report that to the health monitoring system for later reporting.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
libxfs/util.c
libxfs/xfs_attr_leaf.c
libxfs/xfs_attr_remote.c
libxfs/xfs_da_btree.c
libxfs/xfs_dir2.c
libxfs/xfs_dir2_block.c
libxfs/xfs_dir2_data.c
libxfs/xfs_dir2_leaf.c
libxfs/xfs_dir2_node.c
libxfs/xfs_health.h

index b45d670653cf54604c878a2388f2e56e8db430d7..6c326e84aab623dc9ca19293c3120f2b4f3fae3e 100644 (file)
@@ -734,3 +734,5 @@ void xfs_agno_mark_sick(struct xfs_mount *mp, xfs_agnumber_t agno,
 void xfs_ag_mark_sick(struct xfs_perag *pag, unsigned int mask) { }
 void xfs_bmap_mark_sick(struct xfs_inode *ip, int whichfork) { }
 void xfs_btree_mark_sick(struct xfs_btree_cur *cur) { }
+void xfs_dirattr_mark_sick(struct xfs_inode *ip, int whichfork) { }
+void xfs_da_mark_sick(struct xfs_da_args *args) { }
index fdc53451ce9c2082191cf90e9b47e1a8cdcebf53..a44312cdc67595f64e5b648b4608b95dcea5b511 100644 (file)
@@ -26,6 +26,7 @@
 #include "xfs_dir2.h"
 #include "xfs_ag.h"
 #include "xfs_errortag.h"
+#include "xfs_health.h"
 
 
 /*
@@ -2340,6 +2341,7 @@ xfs_attr3_leaf_lookup_int(
        entries = xfs_attr3_leaf_entryp(leaf);
        if (ichdr.count >= args->geo->blksize / 8) {
                xfs_buf_mark_corrupt(bp);
+               xfs_da_mark_sick(args);
                return -EFSCORRUPTED;
        }
 
@@ -2359,10 +2361,12 @@ xfs_attr3_leaf_lookup_int(
        }
        if (!(probe >= 0 && (!ichdr.count || probe < ichdr.count))) {
                xfs_buf_mark_corrupt(bp);
+               xfs_da_mark_sick(args);
                return -EFSCORRUPTED;
        }
        if (!(span <= 4 || be32_to_cpu(entry->hashval) == hashval)) {
                xfs_buf_mark_corrupt(bp);
+               xfs_da_mark_sick(args);
                return -EFSCORRUPTED;
        }
 
index 12d1ba9c3a341ec4301a4012a9eb3ff4db7b124c..a400a22d34a40151fe4e3407c966988321745474 100644 (file)
@@ -21,6 +21,7 @@
 #include "xfs_attr.h"
 #include "xfs_attr_remote.h"
 #include "xfs_trace.h"
+#include "xfs_health.h"
 
 #define ATTR_RMTVALUE_MAPSIZE  1       /* # of map entries at once */
 
@@ -275,17 +276,18 @@ xfs_attr3_rmt_hdr_set(
  */
 STATIC int
 xfs_attr_rmtval_copyout(
-       struct xfs_mount *mp,
-       struct xfs_buf  *bp,
-       xfs_ino_t       ino,
-       int             *offset,
-       int             *valuelen,
-       uint8_t         **dst)
+       struct xfs_mount        *mp,
+       struct xfs_buf          *bp,
+       struct xfs_inode        *dp,
+       int                     *offset,
+       int                     *valuelen,
+       uint8_t                 **dst)
 {
-       char            *src = bp->b_addr;
-       xfs_daddr_t     bno = xfs_buf_daddr(bp);
-       int             len = BBTOB(bp->b_length);
-       int             blksize = mp->m_attr_geo->blksize;
+       char                    *src = bp->b_addr;
+       xfs_ino_t               ino = dp->i_ino;
+       xfs_daddr_t             bno = xfs_buf_daddr(bp);
+       int                     len = BBTOB(bp->b_length);
+       int                     blksize = mp->m_attr_geo->blksize;
 
        ASSERT(len >= blksize);
 
@@ -301,6 +303,7 @@ xfs_attr_rmtval_copyout(
                                xfs_alert(mp,
 "remote attribute header mismatch bno/off/len/owner (0x%llx/0x%x/Ox%x/0x%llx)",
                                        bno, *offset, byte_cnt, ino);
+                               xfs_dirattr_mark_sick(dp, XFS_ATTR_FORK);
                                return -EFSCORRUPTED;
                        }
                        hdr_size = sizeof(struct xfs_attr3_rmt_hdr);
@@ -417,10 +420,12 @@ xfs_attr_rmtval_get(
                        dblkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
                        error = xfs_buf_read(mp->m_ddev_targp, dblkno, dblkcnt,
                                        0, &bp, &xfs_attr3_rmt_buf_ops);
+                       if (xfs_metadata_is_sick(error))
+                               xfs_dirattr_mark_sick(args->dp, XFS_ATTR_FORK);
                        if (error)
                                return error;
 
-                       error = xfs_attr_rmtval_copyout(mp, bp, args->dp->i_ino,
+                       error = xfs_attr_rmtval_copyout(mp, bp, args->dp,
                                                        &offset, &valuelen,
                                                        &dst);
                        xfs_buf_relse(bp);
index 0fea72f3323d37567ceabb2dbae39b6f1df3915c..8ace7622abce2b8b4e21047f028dc14afc87e1e0 100644 (file)
@@ -19,6 +19,7 @@
 #include "xfs_bmap.h"
 #include "xfs_attr_leaf.h"
 #include "xfs_trace.h"
+#include "xfs_health.h"
 
 /*
  * xfs_da_btree.c
@@ -349,6 +350,8 @@ const struct xfs_buf_ops xfs_da3_node_buf_ops = {
 static int
 xfs_da3_node_set_type(
        struct xfs_trans        *tp,
+       struct xfs_inode        *dp,
+       int                     whichfork,
        struct xfs_buf          *bp)
 {
        struct xfs_da_blkinfo   *info = bp->b_addr;
@@ -370,6 +373,7 @@ xfs_da3_node_set_type(
                XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, tp->t_mountp,
                                info, sizeof(*info));
                xfs_trans_brelse(tp, bp);
+               xfs_dirattr_mark_sick(dp, whichfork);
                return -EFSCORRUPTED;
        }
 }
@@ -388,7 +392,7 @@ xfs_da3_node_read(
                        &xfs_da3_node_buf_ops);
        if (error || !*bpp || !tp)
                return error;
-       return xfs_da3_node_set_type(tp, *bpp);
+       return xfs_da3_node_set_type(tp, dp, whichfork, *bpp);
 }
 
 int
@@ -405,6 +409,8 @@ xfs_da3_node_read_mapped(
        error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, mappedbno,
                        XFS_FSB_TO_BB(mp, xfs_dabuf_nfsb(mp, whichfork)), 0,
                        bpp, &xfs_da3_node_buf_ops);
+       if (xfs_metadata_is_sick(error))
+               xfs_dirattr_mark_sick(dp, whichfork);
        if (error || !*bpp)
                return error;
 
@@ -415,7 +421,7 @@ xfs_da3_node_read_mapped(
 
        if (!tp)
                return 0;
-       return xfs_da3_node_set_type(tp, *bpp);
+       return xfs_da3_node_set_type(tp, dp, whichfork, *bpp);
 }
 
 /*
@@ -628,6 +634,7 @@ xfs_da3_split(
        if (node->hdr.info.forw) {
                if (be32_to_cpu(node->hdr.info.forw) != addblk->blkno) {
                        xfs_buf_mark_corrupt(oldblk->bp);
+                       xfs_da_mark_sick(state->args);
                        error = -EFSCORRUPTED;
                        goto out;
                }
@@ -641,6 +648,7 @@ xfs_da3_split(
        if (node->hdr.info.back) {
                if (be32_to_cpu(node->hdr.info.back) != addblk->blkno) {
                        xfs_buf_mark_corrupt(oldblk->bp);
+                       xfs_da_mark_sick(state->args);
                        error = -EFSCORRUPTED;
                        goto out;
                }
@@ -1632,6 +1640,7 @@ xfs_da3_node_lookup_int(
 
                if (magic != XFS_DA_NODE_MAGIC && magic != XFS_DA3_NODE_MAGIC) {
                        xfs_buf_mark_corrupt(blk->bp);
+                       xfs_da_mark_sick(args);
                        return -EFSCORRUPTED;
                }
 
@@ -1647,6 +1656,7 @@ xfs_da3_node_lookup_int(
                /* Tree taller than we can handle; bail out! */
                if (nodehdr.level >= XFS_DA_NODE_MAXDEPTH) {
                        xfs_buf_mark_corrupt(blk->bp);
+                       xfs_da_mark_sick(args);
                        return -EFSCORRUPTED;
                }
 
@@ -1655,6 +1665,7 @@ xfs_da3_node_lookup_int(
                        expected_level = nodehdr.level - 1;
                else if (expected_level != nodehdr.level) {
                        xfs_buf_mark_corrupt(blk->bp);
+                       xfs_da_mark_sick(args);
                        return -EFSCORRUPTED;
                } else
                        expected_level--;
@@ -1706,12 +1717,16 @@ xfs_da3_node_lookup_int(
                }
 
                /* We can't point back to the root. */
-               if (XFS_IS_CORRUPT(dp->i_mount, blkno == args->geo->leafblk))
+               if (XFS_IS_CORRUPT(dp->i_mount, blkno == args->geo->leafblk)) {
+                       xfs_da_mark_sick(args);
                        return -EFSCORRUPTED;
+               }
        }
 
-       if (XFS_IS_CORRUPT(dp->i_mount, expected_level != 0))
+       if (XFS_IS_CORRUPT(dp->i_mount, expected_level != 0)) {
+               xfs_da_mark_sick(args);
                return -EFSCORRUPTED;
+       }
 
        /*
         * A leaf block that ends in the hashval that we are interested in
@@ -1729,6 +1744,7 @@ xfs_da3_node_lookup_int(
                        args->blkno = blk->blkno;
                } else {
                        ASSERT(0);
+                       xfs_da_mark_sick(args);
                        return -EFSCORRUPTED;
                }
                if (((retval == -ENOENT) || (retval == -ENOATTR)) &&
@@ -2295,8 +2311,10 @@ xfs_da3_swap_lastblock(
        error = xfs_bmap_last_before(tp, dp, &lastoff, w);
        if (error)
                return error;
-       if (XFS_IS_CORRUPT(mp, lastoff == 0))
+       if (XFS_IS_CORRUPT(mp, lastoff == 0)) {
+               xfs_da_mark_sick(args);
                return -EFSCORRUPTED;
+       }
        /*
         * Read the last block in the btree space.
         */
@@ -2346,6 +2364,7 @@ xfs_da3_swap_lastblock(
                if (XFS_IS_CORRUPT(mp,
                                   be32_to_cpu(sib_info->forw) != last_blkno ||
                                   sib_info->magic != dead_info->magic)) {
+                       xfs_da_mark_sick(args);
                        error = -EFSCORRUPTED;
                        goto done;
                }
@@ -2366,6 +2385,7 @@ xfs_da3_swap_lastblock(
                if (XFS_IS_CORRUPT(mp,
                                   be32_to_cpu(sib_info->back) != last_blkno ||
                                   sib_info->magic != dead_info->magic)) {
+                       xfs_da_mark_sick(args);
                        error = -EFSCORRUPTED;
                        goto done;
                }
@@ -2388,6 +2408,7 @@ xfs_da3_swap_lastblock(
                xfs_da3_node_hdr_from_disk(dp->i_mount, &par_hdr, par_node);
                if (XFS_IS_CORRUPT(mp,
                                   level >= 0 && level != par_hdr.level + 1)) {
+                       xfs_da_mark_sick(args);
                        error = -EFSCORRUPTED;
                        goto done;
                }
@@ -2399,6 +2420,7 @@ xfs_da3_swap_lastblock(
                     entno++)
                        continue;
                if (XFS_IS_CORRUPT(mp, entno == par_hdr.count)) {
+                       xfs_da_mark_sick(args);
                        error = -EFSCORRUPTED;
                        goto done;
                }
@@ -2424,6 +2446,7 @@ xfs_da3_swap_lastblock(
                xfs_trans_brelse(tp, par_buf);
                par_buf = NULL;
                if (XFS_IS_CORRUPT(mp, par_blkno == 0)) {
+                       xfs_da_mark_sick(args);
                        error = -EFSCORRUPTED;
                        goto done;
                }
@@ -2433,6 +2456,7 @@ xfs_da3_swap_lastblock(
                par_node = par_buf->b_addr;
                xfs_da3_node_hdr_from_disk(dp->i_mount, &par_hdr, par_node);
                if (XFS_IS_CORRUPT(mp, par_hdr.level != level)) {
+                       xfs_da_mark_sick(args);
                        error = -EFSCORRUPTED;
                        goto done;
                }
@@ -2563,6 +2587,7 @@ out_free_irecs:
 invalid_mapping:
        /* Caller ok with no mapping. */
        if (XFS_IS_CORRUPT(mp, !(flags & XFS_DABUF_MAP_HOLE_OK))) {
+               xfs_dirattr_mark_sick(dp, whichfork);
                error = -EFSCORRUPTED;
                if (xfs_error_level >= XFS_ERRLEVEL_LOW) {
                        xfs_alert(mp, "%s: bno %u inode %llu",
@@ -2644,6 +2669,8 @@ xfs_da_read_buf(
 
        error = xfs_trans_read_buf_map(mp, tp, mp->m_ddev_targp, mapp, nmap, 0,
                        &bp, ops);
+       if (xfs_metadata_is_sick(error))
+               xfs_dirattr_mark_sick(dp, whichfork);
        if (error)
                goto out_free;
 
index ac372bf2aa32b62d1c9661c0075e15505680e4c1..530c3e22a169e2f143e4c8f92d865718a97f6ae0 100644 (file)
@@ -17,6 +17,7 @@
 #include "xfs_dir2_priv.h"
 #include "xfs_errortag.h"
 #include "xfs_trace.h"
+#include "xfs_health.h"
 
 const struct xfs_name xfs_name_dotdot = {
        .name   = (const unsigned char *)"..",
@@ -625,8 +626,10 @@ xfs_dir2_isblock(
                return 0;
 
        *isblock = true;
-       if (XFS_IS_CORRUPT(mp, args->dp->i_disk_size != args->geo->blksize))
+       if (XFS_IS_CORRUPT(mp, args->dp->i_disk_size != args->geo->blksize)) {
+               xfs_da_mark_sick(args);
                return -EFSCORRUPTED;
+       }
        return 0;
 }
 
index aed3c14a86b964f306cdcc2e9674ddef401de229..9d87735e7807681f96f3486e8e668e63b9bd11c7 100644 (file)
@@ -17,6 +17,7 @@
 #include "xfs_dir2.h"
 #include "xfs_dir2_priv.h"
 #include "xfs_trace.h"
+#include "xfs_health.h"
 
 /*
  * Local function prototypes.
@@ -149,6 +150,7 @@ xfs_dir3_block_read(
                __xfs_buf_mark_corrupt(*bpp, fa);
                xfs_trans_brelse(tp, *bpp);
                *bpp = NULL;
+               xfs_dirattr_mark_sick(dp, XFS_DATA_FORK);
                return -EFSCORRUPTED;
        }
 
index 4e207986bc926c6794f5bb9b5fb42c6999afb585..aaf3f62af91e6d0ca529eb0e1af3605c8a185da1 100644 (file)
@@ -15,6 +15,7 @@
 #include "xfs_dir2.h"
 #include "xfs_dir2_priv.h"
 #include "xfs_trans.h"
+#include "xfs_health.h"
 
 static xfs_failaddr_t xfs_dir2_data_freefind_verify(
                struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_free *bf,
@@ -430,6 +431,7 @@ xfs_dir3_data_read(
                __xfs_buf_mark_corrupt(*bpp, fa);
                xfs_trans_brelse(tp, *bpp);
                *bpp = NULL;
+               xfs_dirattr_mark_sick(dp, XFS_DATA_FORK);
                return -EFSCORRUPTED;
        }
 
@@ -1195,6 +1197,7 @@ xfs_dir2_data_use_free(
 corrupt:
        xfs_corruption_error(__func__, XFS_ERRLEVEL_LOW, args->dp->i_mount,
                        hdr, sizeof(*hdr), __FILE__, __LINE__, fa);
+       xfs_da_mark_sick(args);
        return -EFSCORRUPTED;
 }
 
index 5da66006cb5bde37fc59052832a58fe058a6e5fd..80cea8a275d885ccae7865e62f516dcda06ac986 100644 (file)
@@ -17,6 +17,7 @@
 #include "xfs_dir2_priv.h"
 #include "xfs_trace.h"
 #include "xfs_trans.h"
+#include "xfs_health.h"
 
 /*
  * Local function declarations.
@@ -1391,8 +1392,10 @@ xfs_dir2_leaf_removename(
        bestsp = xfs_dir2_leaf_bests_p(ltp);
        if (be16_to_cpu(bestsp[db]) != oldbest) {
                xfs_buf_mark_corrupt(lbp);
+               xfs_da_mark_sick(args);
                return -EFSCORRUPTED;
        }
+
        /*
         * Mark the former data entry unused.
         */
index c0eb335c3002f30a5e5f576e171c00fd29a16820..44c8f3f2b07ea236845fd436cc74141c0729acdf 100644 (file)
@@ -17,6 +17,7 @@
 #include "xfs_dir2_priv.h"
 #include "xfs_trace.h"
 #include "xfs_trans.h"
+#include "xfs_health.h"
 
 /*
  * Function declarations.
@@ -228,6 +229,7 @@ __xfs_dir3_free_read(
                __xfs_buf_mark_corrupt(*bpp, fa);
                xfs_trans_brelse(tp, *bpp);
                *bpp = NULL;
+               xfs_dirattr_mark_sick(dp, XFS_DATA_FORK);
                return -EFSCORRUPTED;
        }
 
@@ -440,6 +442,7 @@ xfs_dir2_leaf_to_node(
        if (be32_to_cpu(ltp->bestcount) >
                                (uint)dp->i_disk_size / args->geo->blksize) {
                xfs_buf_mark_corrupt(lbp);
+               xfs_da_mark_sick(args);
                return -EFSCORRUPTED;
        }
 
@@ -514,6 +517,7 @@ xfs_dir2_leafn_add(
         */
        if (index < 0) {
                xfs_buf_mark_corrupt(bp);
+               xfs_da_mark_sick(args);
                return -EFSCORRUPTED;
        }
 
@@ -733,6 +737,7 @@ xfs_dir2_leafn_lookup_for_addname(
                                           cpu_to_be16(NULLDATAOFF))) {
                                if (curfdb != newfdb)
                                        xfs_trans_brelse(tp, curbp);
+                               xfs_da_mark_sick(args);
                                return -EFSCORRUPTED;
                        }
                        curfdb = newfdb;
@@ -801,6 +806,7 @@ xfs_dir2_leafn_lookup_for_entry(
        xfs_dir3_leaf_check(dp, bp);
        if (leafhdr.count <= 0) {
                xfs_buf_mark_corrupt(bp);
+               xfs_da_mark_sick(args);
                return -EFSCORRUPTED;
        }
 
@@ -1736,6 +1742,7 @@ xfs_dir2_node_add_datablk(
                        } else {
                                xfs_alert(mp, " ... fblk is NULL");
                        }
+                       xfs_da_mark_sick(args);
                        return -EFSCORRUPTED;
                }
 
index 8f566a78737fed838845665522583f48a00264d7..ff98c03212b8c4c94ff01e5937a6ca0517ea2e02 100644 (file)
@@ -38,6 +38,7 @@ struct xfs_perag;
 struct xfs_inode;
 struct xfs_fsop_geom;
 struct xfs_btree_cur;
+struct xfs_da_args;
 
 /* Observable health issues for metadata spanning the entire filesystem. */
 #define XFS_SICK_FS_COUNTERS   (1 << 0)  /* summary counters */
@@ -162,6 +163,8 @@ void xfs_inode_measure_sickness(struct xfs_inode *ip, unsigned int *sick,
 void xfs_health_unmount(struct xfs_mount *mp);
 void xfs_bmap_mark_sick(struct xfs_inode *ip, int whichfork);
 void xfs_btree_mark_sick(struct xfs_btree_cur *cur);
+void xfs_dirattr_mark_sick(struct xfs_inode *ip, int whichfork);
+void xfs_da_mark_sick(struct xfs_da_args *args);
 
 /* Now some helpers. */