]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: hoist the secondary sb qflags handling
authorDarrick J. Wong <djwong@kernel.org>
Thu, 21 Nov 2024 00:24:42 +0000 (16:24 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 24 Dec 2024 02:01:36 +0000 (18:01 -0800)
Hoist all the secondary superblock qflags and quota inode modification
code into a separate function so that we can disable it in the next
patch.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
repair/agheader.c

index fd279559aed9731aa5964072d6039721e4ae064e..4a530fd6b8fe96e096460f5f288c5ad8872f1bdb 100644 (file)
@@ -319,6 +319,90 @@ check_v5_feature_mismatch(
        return XR_AG_SB_SEC;
 }
 
+/*
+ * quota inodes and flags in secondary superblocks are never set by mkfs.
+ * However, they could be set in a secondary if a fs with quotas was growfs'ed
+ * since growfs copies the new primary into the secondaries.
+ *
+ * Also, the in-core inode flags now have different meaning to the on-disk
+ * flags, and so libxfs_sb_to_disk cannot directly write the
+ * sb_gquotino/sb_pquotino fields without specific sb_qflags being set.  Hence
+ * we need to zero those fields directly in the sb buffer here.
+ */
+static int
+secondary_sb_quota(
+       struct xfs_mount        *mp,
+       struct xfs_buf          *sbuf,
+       struct xfs_sb           *sb,
+       xfs_agnumber_t          i,
+       int                     do_bzero)
+{
+       struct xfs_dsb          *dsb = sbuf->b_addr;
+       int                     rval = 0;
+
+       if (sb->sb_inprogress == 1 && sb->sb_uquotino != NULLFSINO)  {
+               if (!no_modify)
+                       sb->sb_uquotino = 0;
+               if (!do_bzero)  {
+                       rval |= XR_AG_SB;
+                       do_warn(
+               _("non-null user quota inode field in superblock %d\n"),
+                               i);
+
+               } else
+                       rval |= XR_AG_SB_SEC;
+       }
+
+       if (sb->sb_inprogress == 1 && sb->sb_gquotino != NULLFSINO)  {
+               if (!no_modify) {
+                       sb->sb_gquotino = 0;
+                       dsb->sb_gquotino = 0;
+               }
+               if (!do_bzero)  {
+                       rval |= XR_AG_SB;
+                       do_warn(
+               _("non-null group quota inode field in superblock %d\n"),
+                               i);
+
+               } else
+                       rval |= XR_AG_SB_SEC;
+       }
+
+       /*
+        * Note that sb_pquotino is not considered a valid sb field for pre-v5
+        * superblocks. If it is anything other than 0 it is considered garbage
+        * data beyond the valid sb and explicitly zeroed above.
+        */
+       if (xfs_has_pquotino(mp) &&
+           sb->sb_inprogress == 1 && sb->sb_pquotino != NULLFSINO)  {
+               if (!no_modify) {
+                       sb->sb_pquotino = 0;
+                       dsb->sb_pquotino = 0;
+               }
+               if (!do_bzero)  {
+                       rval |= XR_AG_SB;
+                       do_warn(
+               _("non-null project quota inode field in superblock %d\n"),
+                               i);
+
+               } else
+                       rval |= XR_AG_SB_SEC;
+       }
+
+       if (sb->sb_inprogress == 1 && sb->sb_qflags)  {
+               if (!no_modify)
+                       sb->sb_qflags = 0;
+               if (!do_bzero)  {
+                       rval |= XR_AG_SB;
+                       do_warn(_("non-null quota flags in superblock %d\n"),
+                               i);
+               } else
+                       rval |= XR_AG_SB_SEC;
+       }
+
+       return rval;
+}
+
 /*
  * Possible fields that may have been set at mkfs time,
  * sb_inoalignmt, sb_unit, sb_width and sb_dirblklog.
@@ -340,7 +424,6 @@ secondary_sb_whack(
        struct xfs_sb   *sb,
        xfs_agnumber_t  i)
 {
-       struct xfs_dsb  *dsb = sbuf->b_addr;
        int             do_bzero = 0;
        int             size;
        char            *ip;
@@ -426,77 +509,7 @@ secondary_sb_whack(
                        rval |= XR_AG_SB_SEC;
        }
 
-       /*
-        * quota inodes and flags in secondary superblocks are never set by
-        * mkfs.  However, they could be set in a secondary if a fs with quotas
-        * was growfs'ed since growfs copies the new primary into the
-        * secondaries.
-        *
-        * Also, the in-core inode flags now have different meaning to the
-        * on-disk flags, and so libxfs_sb_to_disk cannot directly write the
-        * sb_gquotino/sb_pquotino fields without specific sb_qflags being set.
-        * Hence we need to zero those fields directly in the sb buffer here.
-        */
-
-       if (sb->sb_inprogress == 1 && sb->sb_uquotino != NULLFSINO)  {
-               if (!no_modify)
-                       sb->sb_uquotino = 0;
-               if (!do_bzero)  {
-                       rval |= XR_AG_SB;
-                       do_warn(
-               _("non-null user quota inode field in superblock %d\n"),
-                               i);
-
-               } else
-                       rval |= XR_AG_SB_SEC;
-       }
-
-       if (sb->sb_inprogress == 1 && sb->sb_gquotino != NULLFSINO)  {
-               if (!no_modify) {
-                       sb->sb_gquotino = 0;
-                       dsb->sb_gquotino = 0;
-               }
-               if (!do_bzero)  {
-                       rval |= XR_AG_SB;
-                       do_warn(
-               _("non-null group quota inode field in superblock %d\n"),
-                               i);
-
-               } else
-                       rval |= XR_AG_SB_SEC;
-       }
-
-       /*
-        * Note that sb_pquotino is not considered a valid sb field for pre-v5
-        * superblocks. If it is anything other than 0 it is considered garbage
-        * data beyond the valid sb and explicitly zeroed above.
-        */
-       if (xfs_has_pquotino(mp) &&
-           sb->sb_inprogress == 1 && sb->sb_pquotino != NULLFSINO)  {
-               if (!no_modify) {
-                       sb->sb_pquotino = 0;
-                       dsb->sb_pquotino = 0;
-               }
-               if (!do_bzero)  {
-                       rval |= XR_AG_SB;
-                       do_warn(
-               _("non-null project quota inode field in superblock %d\n"),
-                               i);
-
-               } else
-                       rval |= XR_AG_SB_SEC;
-       }
-
-       if (sb->sb_inprogress == 1 && sb->sb_qflags)  {
-               if (!no_modify)
-                       sb->sb_qflags = 0;
-               if (!do_bzero)  {
-                       rval |= XR_AG_SB;
-                       do_warn(_("non-null quota flags in superblock %d\n"),
-                               i);
-               } else
-                       rval |= XR_AG_SB_SEC;
-       }
+       rval |= secondary_sb_quota(mp, sbuf, sb, i, do_bzero);
 
        /*
         * if the secondaries agree on a stripe unit/width or inode