xfs: remember sick inodes that get inactivated
authorDarrick J. Wong <djwong@kernel.org>
Thu, 22 Feb 2024 20:33:03 +0000 (12:33 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 22 Feb 2024 20:33:03 +0000 (12:33 -0800)
If an unhealthy inode gets inactivated, remember this fact in the
per-fs health summary.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_fs.h
fs/xfs/libxfs/xfs_health.h
fs/xfs/libxfs/xfs_inode_buf.c
fs/xfs/scrub/health.c
fs/xfs/xfs_health.c
fs/xfs/xfs_inode.c
fs/xfs/xfs_trace.h

index 515cd27d3b3a845271e9c51a41b54b85bfa55c44..b5c8da7e6aa99ad5d8fb6cdd911f457ec3969a9c 100644 (file)
@@ -294,6 +294,7 @@ struct xfs_ag_geometry {
 #define XFS_AG_GEOM_SICK_FINOBT        (1 << 7)  /* free inode index */
 #define XFS_AG_GEOM_SICK_RMAPBT        (1 << 8)  /* reverse mappings */
 #define XFS_AG_GEOM_SICK_REFCNTBT (1 << 9)  /* reference counts */
+#define XFS_AG_GEOM_SICK_INODES        (1 << 10) /* bad inodes were seen */
 
 /*
  * Structures for XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG & XFS_IOC_FSGROWFSRT
index 032d45fcbd51f86c92af1ee59631983062660fdf..3c64b5f9bd6817af320d86e6839d2933293e7dea 100644 (file)
@@ -76,6 +76,7 @@ struct xfs_da_args;
 #define XFS_SICK_AG_FINOBT     (1 << 7)  /* free inode index */
 #define XFS_SICK_AG_RMAPBT     (1 << 8)  /* reverse mappings */
 #define XFS_SICK_AG_REFCNTBT   (1 << 9)  /* reference counts */
+#define XFS_SICK_AG_INODES     (1 << 10) /* inactivated bad inodes */
 
 /* Observable health issues for inode metadata. */
 #define XFS_SICK_INO_CORE      (1 << 0)  /* inode core */
@@ -92,6 +93,9 @@ struct xfs_da_args;
 #define XFS_SICK_INO_DIR_ZAPPED                (1 << 10) /* directory erased */
 #define XFS_SICK_INO_SYMLINK_ZAPPED    (1 << 11) /* symlink erased */
 
+/* Don't propagate sick status to ag health summary during inactivation */
+#define XFS_SICK_INO_FORGET    (1 << 12)
+
 /* Primary evidence of health problems in a given group. */
 #define XFS_SICK_FS_PRIMARY    (XFS_SICK_FS_COUNTERS | \
                                 XFS_SICK_FS_UQUOTA | \
@@ -132,12 +136,12 @@ struct xfs_da_args;
 #define XFS_SICK_FS_SECONDARY  (0)
 #define XFS_SICK_RT_SECONDARY  (0)
 #define XFS_SICK_AG_SECONDARY  (0)
-#define XFS_SICK_INO_SECONDARY (0)
+#define XFS_SICK_INO_SECONDARY (XFS_SICK_INO_FORGET)
 
 /* Evidence of health problems elsewhere. */
 #define XFS_SICK_FS_INDIRECT   (0)
 #define XFS_SICK_RT_INDIRECT   (0)
-#define XFS_SICK_AG_INDIRECT   (0)
+#define XFS_SICK_AG_INDIRECT   (XFS_SICK_AG_INODES)
 #define XFS_SICK_INO_INDIRECT  (0)
 
 /* All health masks. */
index 1280d6acd1c1bb26dd25e6ba4f6bbbae99ecbd93..d0dcce462bf4234e813bceb19448f65903c66956 100644 (file)
@@ -139,7 +139,7 @@ xfs_imap_to_bp(
                        imap->im_len, XBF_UNMAPPED, bpp, &xfs_inode_buf_ops);
        if (xfs_metadata_is_sick(error))
                xfs_agno_mark_sick(mp, xfs_daddr_to_agno(mp, imap->im_blkno),
-                               XFS_SICK_AG_INOBT);
+                               XFS_SICK_AG_INODES);
        return error;
 }
 
index c682c7093353455c84a768c6ab0f74e59402cc9a..af192b41e78cd83ec482f0c20085217b3298eb82 100644 (file)
@@ -183,9 +183,19 @@ xchk_update_health(
        case XHG_INO:
                if (!sc->ip)
                        return;
-               if (bad)
-                       xfs_inode_mark_corrupt(sc->ip, sc->sick_mask);
-               else
+               if (bad) {
+                       unsigned int    mask = sc->sick_mask;
+
+                       /*
+                        * If we're coming in for repairs then we don't want
+                        * sickness flags to propagate to the incore health
+                        * status if the inode gets inactivated before we can
+                        * fix it.
+                        */
+                       if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR)
+                               mask |= XFS_SICK_INO_FORGET;
+                       xfs_inode_mark_corrupt(sc->ip, mask);
+               } else
                        xfs_inode_mark_healthy(sc->ip, sc->sick_mask);
                break;
        case XHG_FS:
index a264547fcd9438819e3b8ee46a864944f41c058d..855221c0dd34135f1f38d74df6a745efb57f05dd 100644 (file)
@@ -431,6 +431,7 @@ static const struct ioctl_sick_map ag_map[] = {
        { XFS_SICK_AG_FINOBT,   XFS_AG_GEOM_SICK_FINOBT },
        { XFS_SICK_AG_RMAPBT,   XFS_AG_GEOM_SICK_RMAPBT },
        { XFS_SICK_AG_REFCNTBT, XFS_AG_GEOM_SICK_REFCNTBT },
+       { XFS_SICK_AG_INODES,   XFS_AG_GEOM_SICK_INODES },
        { 0, 0 },
 };
 
index 5d0ac5c733f3d2d6382cd67e4e3c49fa033fbf41..ea48774f6b76d398bf6f9731145483751a4bf506 100644 (file)
@@ -1738,6 +1738,39 @@ xfs_inode_needs_inactive(
        return xfs_can_free_eofblocks(ip, true);
 }
 
+/*
+ * Save health status somewhere, if we're dumping an inode with uncorrected
+ * errors and online repair isn't running.
+ */
+static inline void
+xfs_inactive_health(
+       struct xfs_inode        *ip)
+{
+       struct xfs_mount        *mp = ip->i_mount;
+       struct xfs_perag        *pag;
+       unsigned int            sick;
+       unsigned int            checked;
+
+       xfs_inode_measure_sickness(ip, &sick, &checked);
+       if (!sick)
+               return;
+
+       trace_xfs_inode_unfixed_corruption(ip, sick);
+
+       if (sick & XFS_SICK_INO_FORGET)
+               return;
+
+       pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino));
+       if (!pag) {
+               /* There had better still be a perag structure! */
+               ASSERT(0);
+               return;
+       }
+
+       xfs_ag_mark_sick(pag, XFS_SICK_AG_INODES);
+       xfs_perag_put(pag);
+}
+
 /*
  * xfs_inactive
  *
@@ -1766,6 +1799,8 @@ xfs_inactive(
        mp = ip->i_mount;
        ASSERT(!xfs_iflags_test(ip, XFS_IRECOVERY));
 
+       xfs_inactive_health(ip);
+
        /*
         * If this is a read-only mount, don't do this (would generate I/O)
         * unless we're in log recovery and cleaning the iunlinked list.
index 667ecae469ccb1906973a85e35470d45c21f2589..8ea6a6e712b36ec0d8e9fc995c09425723135103 100644 (file)
@@ -3985,6 +3985,7 @@ DEFINE_EVENT(xfs_inode_corrupt_class, name,       \
 DEFINE_INODE_CORRUPT_EVENT(xfs_inode_mark_sick);
 DEFINE_INODE_CORRUPT_EVENT(xfs_inode_mark_corrupt);
 DEFINE_INODE_CORRUPT_EVENT(xfs_inode_mark_healthy);
+DEFINE_INODE_CORRUPT_EVENT(xfs_inode_unfixed_corruption);
 
 TRACE_EVENT(xfs_iwalk_ag,
        TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno,