]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: factor secondary superblock updates
authorDave Chinner <dchinner@redhat.com>
Wed, 6 Dec 2017 23:14:27 +0000 (17:14 -0600)
committerEric Sandeen <sandeen@redhat.com>
Wed, 6 Dec 2017 23:14:27 +0000 (17:14 -0600)
Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
mkfs/xfs_mkfs.c

index 4ba11b6c205d5d39b9e5b020d467f272672341a8..1b23ada2b5085bd80a077cb2827f7e58106990fe 100644 (file)
@@ -2489,6 +2489,39 @@ initialise_ag_freespace(
        libxfs_trans_commit(tp);
 }
 
+/*
+ * rewrite several secondary superblocks with the root inode number filled out.
+ * This can help repair recovery from a trashed primary superblock without
+ * losing the root inode.
+ */
+static void
+rewrite_secondary_superblocks(
+       struct xfs_mount        *mp)
+{
+       struct xfs_buf          *buf;
+
+       /* rewrite the last superblock */
+       buf = libxfs_readbuf(mp->m_dev,
+                       XFS_AGB_TO_DADDR(mp, mp->m_sb.sb_agcount - 1,
+                               XFS_SB_DADDR),
+                       XFS_FSS_TO_BB(mp, 1),
+                       LIBXFS_EXIT_ON_FAILURE, &xfs_sb_buf_ops);
+       XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
+       libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
+
+       /* and one in the middle for luck if there's enough AGs for that */
+       if (mp->m_sb.sb_agcount <= 2)
+               return;
+
+       buf = libxfs_readbuf(mp->m_dev,
+                       XFS_AGB_TO_DADDR(mp, (mp->m_sb.sb_agcount - 1) / 2,
+                               XFS_SB_DADDR),
+                       XFS_FSS_TO_BB(mp, 1),
+                       LIBXFS_EXIT_ON_FAILURE, &xfs_sb_buf_ops);
+       XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
+       libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
+}
+
 int
 main(
        int                     argc,
@@ -3716,34 +3749,10 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
        }
 
        /*
-        * Write out multiple secondary superblocks with rootinode field set
+        * Re-write multiple secondary superblocks with rootinode field set
         */
-       if (mp->m_sb.sb_agcount > 1) {
-               /*
-                * the last superblock
-                */
-               buf = libxfs_readbuf(mp->m_dev,
-                               XFS_AGB_TO_DADDR(mp, mp->m_sb.sb_agcount-1,
-                                       XFS_SB_DADDR),
-                               XFS_FSS_TO_BB(mp, 1),
-                               LIBXFS_EXIT_ON_FAILURE, &xfs_sb_buf_ops);
-               XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(
-                                                       mp->m_sb.sb_rootino);
-               libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-               /*
-                * and one in the middle for luck
-                */
-               if (mp->m_sb.sb_agcount > 2) {
-                       buf = libxfs_readbuf(mp->m_dev,
-                               XFS_AGB_TO_DADDR(mp, (mp->m_sb.sb_agcount-1)/2,
-                                       XFS_SB_DADDR),
-                               XFS_FSS_TO_BB(mp, 1),
-                               LIBXFS_EXIT_ON_FAILURE, &xfs_sb_buf_ops);
-                       XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(
-                                                       mp->m_sb.sb_rootino);
-                       libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-               }
-       }
+       if (mp->m_sb.sb_agcount > 1)
+               rewrite_secondary_superblocks(mp);
 
        /*
         * Dump all inodes and buffers before marking us all done.