]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_repair: upgrade an existing filesystem to have parent pointers
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:21:45 +0000 (14:21 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:13:16 +0000 (17:13 -0700)
Upgrade an existing filesystem to have parent pointers.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
man/man8/xfs_admin.8
repair/globals.c
repair/globals.h
repair/phase2.c
repair/pptr.c
repair/xfs_repair.c

index 74a400dcfeb557dcd7449cb2f9f6e9a80ef16f44..a25e599e5f8e2ce9f2aa143f12dc9b4de3178953 100644 (file)
@@ -184,6 +184,14 @@ and online repairs to space usage metadata.
 The filesystem cannot be downgraded after this feature is enabled.
 This upgrade can fail if any AG has less than 5% free space remaining.
 This feature was added to Linux 4.8.
+.TP 0.4i
+.B parent
+Store in each child file a mirror a pointing back to the parent directory.
+This enables much stronger cross-referencing and online repairs of the
+directory tree.
+The filesystem cannot be downgraded after this feature is enabled.
+This upgrade can fail if the filesystem has less than 25% free space remaining.
+This feature is not upstream yet.
 .RE
 .TP
 .BI \-U " uuid"
index fda523a944e81ed596f7f44e91456e9c2e50eb6f..b3546488b162da9ed453bfc2efc849a78eaaf432 100644 (file)
@@ -56,6 +56,7 @@ bool  add_exchrange;          /* add file content exchange support */
 bool   add_finobt;             /* add free inode btrees */
 bool   add_reflink;            /* add reference count btrees */
 bool   add_rmapbt;             /* add reverse mapping btrees */
+bool   add_parent;             /* add parent pointers */
 
 /* misc status variables */
 
index 01b843549575d6f0d8697e16f31d7fe386926ca2..a96ea8f97622d04332789da6c1a6d997650ab996 100644 (file)
@@ -97,6 +97,7 @@ extern bool   add_exchrange;          /* add file content exchange support */
 extern bool    add_finobt;             /* add free inode btrees */
 extern bool    add_reflink;            /* add reference count btrees */
 extern bool    add_rmapbt;             /* add reverse mapping btrees */
+extern bool    add_parent;             /* add parent pointers */
 
 /* misc status variables */
 
index c7dace83e476dfe25fbb0a570daf56770f3677f3..7e454341a6d94a4ab472ef1f757c603d2d182720 100644 (file)
@@ -293,6 +293,28 @@ set_rmapbt(
        return true;
 }
 
+static bool
+set_parent(
+       struct xfs_mount        *mp,
+       struct xfs_sb           *new_sb)
+{
+       if (xfs_has_parent(mp)) {
+               printf(_("Filesystem already supports parent pointers.\n"));
+               exit(0);
+       }
+
+       if (!xfs_has_crc(mp)) {
+               printf(
+       _("Parent pointer feature only supported on V5 filesystems.\n"));
+               exit(0);
+       }
+
+       printf(_("Adding parent pointers to filesystem.\n"));
+       new_sb->sb_features_incompat |= XFS_SB_FEAT_INCOMPAT_PARENT;
+       new_sb->sb_features_incompat |= XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR;
+       return true;
+}
+
 struct check_state {
        struct xfs_sb           sb;
        uint64_t                features;
@@ -434,6 +456,19 @@ check_fs_free_space(
                libxfs_trans_cancel(tp);
        }
 
+       /*
+        * If we're adding parent pointers, we need at least 25% free since
+        * scanning the entire filesystem to guesstimate the overhead is
+        * prohibitively expensive.
+        */
+       if (xfs_has_parent(mp) && !(old->features & XFS_FEAT_PARENT)) {
+               if (mp->m_sb.sb_fdblocks < mp->m_sb.sb_dblocks / 4) {
+                       printf(
+ _("Filesystem does not have enough space to add parent pointers.\n"));
+                       exit(1);
+               }
+       }
+
        /*
         * Would the post-upgrade filesystem have enough free space on the data
         * device after making per-AG reservations?
@@ -466,6 +501,8 @@ need_check_fs_free_space(
                return true;
        if (xfs_has_rmapbt(mp) && !(old->features & XFS_FEAT_RMAPBT))
                return true;
+       if (xfs_has_parent(mp) && !(old->features & XFS_FEAT_PARENT))
+               return true;
        return false;
 }
 
@@ -549,6 +586,8 @@ upgrade_filesystem(
                dirty |= set_reflink(mp, &new_sb);
        if (add_rmapbt)
                dirty |= set_rmapbt(mp, &new_sb);
+       if (add_parent)
+               dirty |= set_parent(mp, &new_sb);
        if (!dirty)
                return;
 
index ee29e47a87bd0730f76e9117e2aadd8c0c08109d..ec641f9d6ffc3958dc8fa0c30a1ff944245da20f 100644 (file)
@@ -793,7 +793,7 @@ add_missing_parent_ptr(
                                ag_pptr->namelen,
                                name);
                return;
-       } else {
+       } else if (!add_parent) {
                do_warn(
  _("adding missing ino %llu parent pointer (ino %llu gen 0x%x name '%.*s')\n"),
                                (unsigned long long)ip->i_ino,
@@ -801,6 +801,19 @@ add_missing_parent_ptr(
                                ag_pptr->parent_gen,
                                ag_pptr->namelen,
                                name);
+       } else {
+               static bool             warned = false;
+               static pthread_mutex_t  lock = PTHREAD_MUTEX_INITIALIZER;
+
+               if (!warned) {
+                       pthread_mutex_lock(&lock);
+                       if (!warned) {
+                               do_warn(
+ _("setting parent pointers to upgrade filesystem\n"));
+                               warned = true;
+                       }
+                       pthread_mutex_unlock(&lock);
+               }
        }
 
        error = add_file_pptr(ip, ag_pptr, name);
index 2993f96b828a8f1a1bd4f4557f9802d78b47daa8..27ae298b6eabbd292b486ed39d1e91058744e663 100644 (file)
@@ -73,6 +73,7 @@ enum c_opt_nums {
        CONVERT_FINOBT,
        CONVERT_REFLINK,
        CONVERT_RMAPBT,
+       CONVERT_PARENT,
        C_MAX_OPTS,
 };
 
@@ -85,6 +86,7 @@ static char *c_opts[] = {
        [CONVERT_FINOBT]        = "finobt",
        [CONVERT_REFLINK]       = "reflink",
        [CONVERT_RMAPBT]        = "rmapbt",
+       [CONVERT_PARENT]        = "parent",
        [C_MAX_OPTS]            = NULL,
 };
 
@@ -404,6 +406,15 @@ process_args(int argc, char **argv)
                _("-c rmapbt only supports upgrades\n"));
                                        add_rmapbt = true;
                                        break;
+                               case CONVERT_PARENT:
+                                       if (!val)
+                                               do_abort(
+               _("-c parent requires a parameter\n"));
+                                       if (strtol(val, NULL, 0) != 1)
+                                               do_abort(
+               _("-c parent only supports upgrades\n"));
+                                       add_parent = true;
+                                       break;
                                default:
                                        unknown('c', val);
                                        break;