]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_repair: find and mark the rtrefcountbt inode
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:22:34 +0000 (14:22 -0700)
committerChristoph Hellwig <hch@lst.de>
Mon, 12 Aug 2024 11:53:51 +0000 (13:53 +0200)
Make sure that we find the realtime refcountbt inode and mark it
appropriately, just in case we find a rogue inode claiming to
be an rtrefcount, or just plain garbage in the superblock field.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
repair/dino_chunks.c
repair/dinode.c
repair/dir2.c
repair/incore.h
repair/rmap.c
repair/rmap.h
repair/rt.h
repair/scan.c

index 4d6d9cb3eab67d60130ba9cb030dfb4a48ad33d0..24ca210a6bb446945014cf8a587971d9050275ec 100644 (file)
@@ -1017,6 +1017,17 @@ next_readbuf:
        _("would clear realtime rmap inode %" PRIu64 "\n"),
                                                ino);
                                }
+                       } else if (is_rtrefcount_inode(ino)) {
+                               refcount_avoid_check(mp);
+                               if (!no_modify)  {
+                                       do_warn(
+       _("cleared realtime refcount inode %" PRIu64 "\n"),
+                                               ino);
+                               } else  {
+                                       do_warn(
+       _("would clear realtime refcount inode %" PRIu64 "\n"),
+                                               ino);
+                               }
                        } else if (!no_modify)  {
                                do_warn(_("cleared inode %" PRIu64 "\n"),
                                        ino);
index 524de598220055d3cdea205d52c56f67bcf7543a..3e41b2566ec0f3dcfdb209e8326c4cbd4e516670 100644 (file)
@@ -157,6 +157,9 @@ clear_dinode(xfs_mount_t *mp, struct xfs_dinode *dino, xfs_ino_t ino_num)
        if (is_rtrmap_inode(ino_num))
                rmap_avoid_check(mp);
 
+       if (is_rtrefcount_inode(ino_num))
+               refcount_avoid_check(mp);
+
        /* and clear the forks */
        memset(XFS_DFORK_DPTR(dino), 0, XFS_LITINO(mp));
        return;
@@ -1113,6 +1116,12 @@ _("rtrefcount inode %" PRIu64 " not flagged as metadata\n"),
                        lino);
                return 1;
        }
+       if (type != XR_INO_RTREFC) {
+               do_warn(
+_("rtrefcount inode %" PRIu64 " was not found in the metadata directory tree\n"),
+                       lino);
+               return 1;
+       }
 
        priv.rgno = rtgroup_for_rtrefcount_inode(mp, lino);
        if (priv.rgno == NULLRGNUMBER) {
@@ -1153,7 +1162,7 @@ _("computed size of rtrefcountbt root (%zu bytes) is greater than space in "
                error = process_rtrefc_reclist(mp, rp, numrecs,
                                &priv, "rtrefcountbt root");
                if (error) {
-                       refcount_avoid_check();
+                       refcount_avoid_check(mp);
                        return 1;
                }
                return 0;
@@ -2111,6 +2120,9 @@ process_check_metadata_inodes(
        if (is_rtrmap_inode(lino))
                return process_check_rt_inode(mp, dinoc, lino, type, dirty,
                                XR_INO_RTRMAP, _("realtime rmap btree"));
+       if (is_rtrefcount_inode(lino))
+               return process_check_rt_inode(mp, dinoc, lino, type, dirty,
+                               XR_INO_RTREFC, _("realtime refcount btree"));
        return 0;
 }
 
@@ -2221,6 +2233,18 @@ _("found inode %" PRIu64 " claiming to be a rtrmapbt file, but rmapbt is disable
                }
                break;
 
+       case XR_INO_RTREFC:
+               /*
+                * if we have no refcountbt, any inode claiming
+                * to be a real-time file is bogus
+                */
+               if (!xfs_has_reflink(mp)) {
+                       do_warn(
+_("found inode %" PRIu64 " claiming to be a rtrefcountbt file, but reflink is disabled\n"), lino);
+                       return 1;
+               }
+               break;
+
        default:
                break;
        }
@@ -2250,6 +2274,7 @@ _("bad attr fork offset %d in dev inode %" PRIu64 ", should be %d\n"),
                }
                break;
        case XFS_DINODE_FMT_RMAP:
+       case XFS_DINODE_FMT_REFCOUNT:
                if (!(xfs_has_metadir(mp) && xfs_has_parent(mp))) {
                        do_warn(
 _("metadata inode %" PRIu64 " type %d cannot have attr fork\n"),
@@ -3397,6 +3422,8 @@ _("bad (negative) size %" PRId64 " on inode %" PRIu64 "\n"),
                        type = XR_INO_PQUOTA;
                else if (is_rtrmap_inode(lino))
                        type = XR_INO_RTRMAP;
+               else if (is_rtrefcount_inode(lino))
+                       type = XR_INO_RTREFC;
                else
                        type = XR_INO_DATA;
                break;
@@ -3504,6 +3531,7 @@ _("Bad CoW extent size %u on inode %" PRIu64 ", "),
                case XR_INO_GQUOTA:
                case XR_INO_PQUOTA:
                case XR_INO_RTRMAP:
+               case XR_INO_RTREFC:
                        /*
                         * This inode was recognized as being filesystem
                         * metadata, so preserve the inode and its contents for
index affb556e6eb5ecd1718533adf5bfdfd988040b86..d489a742aa5788497c7101784fc72015d8d613d1 100644 (file)
@@ -282,6 +282,9 @@ process_sf_dir2(
                } else if (is_rtrmap_inode(lino)) {
                        junkit = 1;
                        junkreason = _("realtime rmap");
+               } else if (is_rtrefcount_inode(lino)) {
+                       junkit = 1;
+                       junkreason = _("realtime refcount");
                } else if ((irec_p = find_inode_rec(mp,
                                        XFS_INO_TO_AGNO(mp, lino),
                                        XFS_INO_TO_AGINO(mp, lino))) != NULL) {
@@ -761,6 +764,8 @@ process_dir2_data(
                        clearreason = _("metadata directory root");
                } else if (is_rtrmap_inode(ent_ino)) {
                        clearreason = _("realtime rmap");
+               } else if (is_rtrefcount_inode(ent_ino)) {
+                       clearreason = _("realtime refcount");
                } else {
                        irec_p = find_inode_rec(mp,
                                                XFS_INO_TO_AGNO(mp, ent_ino),
index 28777bac7920dafaf57fca726a4725b6f66c7edb..70be9fa25ab6392a7b6afbe2d5a57986d4d2f058 100644 (file)
@@ -222,6 +222,7 @@ int         count_bcnt_extents(xfs_agnumber_t);
 #define XR_INO_GQUOTA  13              /* group quota inode */
 #define XR_INO_PQUOTA  14              /* project quota inode */
 #define XR_INO_RTRMAP  15              /* realtime rmap */
+#define XR_INO_RTREFC  16              /* realtime refcount */
 
 /* inode allocation tree */
 
index 115cd6fee3cd7756fc01615f7bb4da21693ac47e..74a874724ef57939917c6886cf0c3ca312fc884f 100644 (file)
@@ -1691,8 +1691,11 @@ init_refcount_cursor(
  * Disable the refcount btree check.
  */
 void
-refcount_avoid_check(void)
+refcount_avoid_check(
+       struct xfs_mount        *mp)
 {
+       if (xfs_has_rtgroups(mp))
+               rtginode_avoid_check(mp, XFS_RTG_REFCOUNT);
        refcbt_suspect = true;
 }
 
index 23859bf6c2ad42a6e89ba1092993900dd2c2c03b..c0984d97322861b613c8501a5498aaea151907bb 100644 (file)
@@ -41,7 +41,7 @@ extern void rmap_high_key_from_rec(struct xfs_rmap_irec *rec,
 extern int compute_refcounts(struct xfs_mount *, xfs_agnumber_t);
 uint64_t refcount_record_count(struct xfs_mount *mp, xfs_agnumber_t agno);
 extern int init_refcount_cursor(xfs_agnumber_t, struct xfs_slab_cursor **);
-extern void refcount_avoid_check(void);
+extern void refcount_avoid_check(struct xfs_mount *mp);
 void check_refcounts(struct xfs_mount *mp, xfs_agnumber_t agno);
 
 extern void record_inode_reflink_flag(struct xfs_mount *, struct xfs_dinode *,
index 3d3b08904842cf998ea6516622e46ff9023e5ddf..b54fbad11dcbf68330aa9ab77bb00a3d77ee6b75 100644 (file)
@@ -60,6 +60,11 @@ static inline bool is_rtrmap_inode(xfs_ino_t ino)
        return is_rtgroup_inode(ino, XFS_RTG_RMAP);
 }
 
+static inline bool is_rtrefcount_inode(xfs_ino_t ino)
+{
+       return is_rtgroup_inode(ino, XFS_RTG_REFCOUNT);
+}
+
 void rtginode_avoid_check(struct xfs_mount *mp, enum xfs_rtg_inodes type);
 
 #endif /* _XFS_REPAIR_RT_H_ */
index 110bbf23c3b56651ea6667317807b60f30cb0b2c..55f4c6f5ece43c709eb88988594a19fceee132d9 100644 (file)
@@ -1976,7 +1976,7 @@ _("extent (%u/%u) len %u claimed, state is %d\n"),
        libxfs_perag_put(pag);
 out:
        if (suspect)
-               refcount_avoid_check();
+               refcount_avoid_check(mp);
        return;
 }
 
@@ -2269,7 +2269,7 @@ _("%s btree block claimed (state %d), agno %d, agbno %d, suspect %d\n"),
        }
 out:
        if (suspect) {
-               refcount_avoid_check();
+               refcount_avoid_check(mp);
                return 1;
        }
 
@@ -3132,7 +3132,7 @@ validate_agf(
                if (levels == 0 || levels > mp->m_refc_maxlevels) {
                        do_warn(_("bad levels %u for refcountbt root, agno %d\n"),
                                levels, agno);
-                       refcount_avoid_check();
+                       refcount_avoid_check(mp);
                }
 
                bno = be32_to_cpu(agf->agf_refcount_root);
@@ -3150,7 +3150,7 @@ validate_agf(
                } else {
                        do_warn(_("bad agbno %u for refcntbt root, agno %d\n"),
                                bno, agno);
-                       refcount_avoid_check();
+                       refcount_avoid_check(mp);
                }
        }