]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_repair: validate CoW extent size hint on rtinherit directories
authorDarrick J. Wong <djwong@kernel.org>
Mon, 12 Aug 2024 21:19:25 +0000 (14:19 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 14 Aug 2024 03:08:24 +0000 (20:08 -0700)
XFS allows a sysadmin to change the rt extent size when adding a rt
section to a filesystem after formatting.  If there are any directories
with both a cowextsize hint and rtinherit set, the hint could become
misaligned with the new rextsize.  Offer to fix the problem if we're in
modify mode and the verifier didn't trip.  If we're in dry run mode,
we let the kernel fix it.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
repair/dinode.c

index 970ec259bcd2d1ef2510365b1699f6339faf71e3..918989ca6290a6c6e5a2c36405876ee8c942e33f 100644 (file)
@@ -2916,6 +2916,47 @@ should_have_metadir_iflag(
        return false;
 }
 
+static void
+validate_cowextsize(
+       struct xfs_mount        *mp,
+       struct xfs_dinode       *dino,
+       xfs_ino_t               lino,
+       int                     *dirty)
+{
+       uint16_t                flags = be16_to_cpu(dino->di_flags);
+       uint64_t                flags2 = be64_to_cpu(dino->di_flags2);
+       unsigned int            value = be32_to_cpu(dino->di_cowextsize);
+       bool                    misaligned = false;
+       bool                    bad;
+
+       /*
+        * XFS allows a sysadmin to change the rt extent size when adding a
+        * rt section to a filesystem after formatting.  If there are any
+        * directories with both a cowextsize hint and rtinherit set, the
+        * hint could become misaligned with the new rextsize.
+        */
+       if ((flags2 & XFS_DIFLAG2_COWEXTSIZE) &&
+           (flags & XFS_DIFLAG_RTINHERIT) &&
+           value % mp->m_sb.sb_rextsize > 0)
+               misaligned = true;
+
+       /* Complain if the verifier fails. */
+       bad = libxfs_inode_validate_cowextsize(mp, value,
+                       be16_to_cpu(dino->di_mode), flags, flags2) != NULL;
+       if (bad || misaligned) {
+               do_warn(
+_("Bad CoW extent size hint %u on inode %" PRIu64 ", "),
+                               be32_to_cpu(dino->di_cowextsize), lino);
+               if (!no_modify) {
+                       do_warn(_("resetting to zero\n"));
+                       dino->di_flags2 &= ~cpu_to_be64(XFS_DIFLAG2_COWEXTSIZE);
+                       dino->di_cowextsize = 0;
+                       *dirty = 1;
+               } else
+                       do_warn(_("would reset to zero\n"));
+       }
+}
+
 /*
  * returns 0 if the inode is ok, 1 if the inode is corrupt
  * check_dups can be set to 1 *only* when called by the
@@ -3502,27 +3543,8 @@ _("bad (negative) size %" PRId64 " on inode %" PRIu64 "\n"),
 
        validate_extsize(mp, dino, lino, dirty);
 
-       /*
-        * Only (regular files and directories) with COWEXTSIZE flags
-        * set can have extsize set.
-        */
-       if (dino->di_version >= 3 &&
-           libxfs_inode_validate_cowextsize(mp,
-                       be32_to_cpu(dino->di_cowextsize),
-                       be16_to_cpu(dino->di_mode),
-                       be16_to_cpu(dino->di_flags),
-                       be64_to_cpu(dino->di_flags2)) != NULL) {
-               do_warn(
-_("Bad CoW extent size %u on inode %" PRIu64 ", "),
-                               be32_to_cpu(dino->di_cowextsize), lino);
-               if (!no_modify)  {
-                       do_warn(_("resetting to zero\n"));
-                       dino->di_flags2 &= ~cpu_to_be64(XFS_DIFLAG2_COWEXTSIZE);
-                       dino->di_cowextsize = 0;
-                       *dirty = 1;
-               } else
-                       do_warn(_("would reset to zero\n"));
-       }
+       if (dino->di_version >= 3)
+               validate_cowextsize(mp, dino, lino, dirty);
 
        /* nsec fields cannot be larger than 1 billion */
        check_nsec("atime", lino, dino, &dino->di_atime, dirty);