]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_repair: allow sysadmins to add reflink
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)
Allow the sysadmin to use xfs_repair to upgrade an existing filesystem
to support the reference count btree, and therefore reflink.

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

index e07fc3ddb3fb82b7bf2ccfb6980015a26e165a39..3a9175c9f018e52d657956157f79dd8124e53c9b 100644 (file)
@@ -170,6 +170,12 @@ allocation on old filesystems.
 This upgrade can fail if any AG has less than 1% free space remaining.
 The filesystem cannot be downgraded after this feature is enabled.
 This feature was added to Linux 3.16.
+.TP 0.4i
+.B reflink
+Enable sharing of file data blocks.
+This upgrade can fail if any AG has less than 2% free space remaining.
+The filesystem cannot be downgraded after this feature is enabled.
+This feature was added to Linux 4.9.
 .RE
 .TP
 .BI \-U " uuid"
index 3ea5fd881eefb95d0e168b1d1412ac3e6476eb17..07a15ddfc50bb1c8a59b11bfbc058556aa744acf 100644 (file)
@@ -54,6 +54,7 @@ bool  add_bigtime;            /* add support for timestamps up to 2486 */
 bool   add_nrext64;
 bool   add_exchrange;          /* add file content exchange support */
 bool   add_finobt;             /* add free inode btrees */
+bool   add_reflink;            /* add reference count btrees */
 
 /* misc status variables */
 
index 9f9ecb261add7f255e5d7a0bbd2925e29d8e52d9..c5114b54bee97c3134f6b72715714ba672c46709 100644 (file)
@@ -95,6 +95,7 @@ extern bool   add_bigtime;            /* add support for timestamps up to 2486 */
 extern bool    add_nrext64;
 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 */
 
 /* misc status variables */
 
index 9dc10db78149724c5d9bdc706da1ad66ea20be49..ccd737a6d2a9307d53e9eb6573924a43c0d71f33 100644 (file)
@@ -198,7 +198,7 @@ set_exchrange(
                exit(0);
        }
 
-       if (!xfs_has_reflink(mp)) {
+       if (!xfs_has_reflink(mp) && !add_reflink) {
                printf(
        _("File exchange-range feature cannot be added without reflink.\n"));
                exit(0);
@@ -232,6 +232,33 @@ set_finobt(
        return true;
 }
 
+static bool
+set_reflink(
+       struct xfs_mount        *mp,
+       struct xfs_sb           *new_sb)
+{
+       if (xfs_has_reflink(mp)) {
+               printf(_("Filesystem already supports reflink.\n"));
+               exit(0);
+       }
+
+       if (!xfs_has_crc(mp)) {
+               printf(
+       _("Reflink feature only supported on V5 filesystems.\n"));
+               exit(0);
+       }
+
+       if (xfs_has_realtime(mp)) {
+               printf(_("Reflink feature not supported with realtime.\n"));
+               exit(0);
+       }
+
+       printf(_("Adding reflink support to filesystem.\n"));
+       new_sb->sb_features_ro_compat |= XFS_SB_FEAT_RO_COMPAT_REFLINK;
+       new_sb->sb_features_incompat |= XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR;
+       return true;
+}
+
 struct check_state {
        struct xfs_sb           sb;
        uint64_t                features;
@@ -401,6 +428,8 @@ need_check_fs_free_space(
 {
        if (xfs_has_finobt(mp) && !(old->features & XFS_FEAT_FINOBT))
                return true;
+       if (xfs_has_reflink(mp) && !(old->features & XFS_FEAT_REFLINK))
+               return true;
        return false;
 }
 
@@ -480,6 +509,8 @@ upgrade_filesystem(
                dirty |= set_exchrange(mp, &new_sb);
        if (add_finobt)
                dirty |= set_finobt(mp, &new_sb);
+       if (add_reflink)
+               dirty |= set_reflink(mp, &new_sb);
        if (!dirty)
                return;
 
index 553c7a6c3658a0a5e46ef1adf26e914f218a389a..97591e1b17de838608e951dc32513ecb98f5885d 100644 (file)
@@ -58,7 +58,7 @@ bool
 rmap_needs_work(
        struct xfs_mount        *mp)
 {
-       return xfs_has_reflink(mp) ||
+       return xfs_has_reflink(mp) || add_reflink ||
               xfs_has_rmapbt(mp);
 }
 
@@ -1515,7 +1515,7 @@ check_refcounts(
        int                             i;
        int                             error;
 
-       if (!xfs_has_reflink(mp))
+       if (!xfs_has_reflink(mp) || add_reflink)
                return;
        if (refcbt_suspect) {
                if (no_modify && agno == 0)
index 3755e3e7f4d2fa24afb1c3884d7939691dd9b300..22142674e0c51e78a0e27d07dd7ef26ce9041e15 100644 (file)
@@ -71,6 +71,7 @@ enum c_opt_nums {
        CONVERT_NREXT64,
        CONVERT_EXCHRANGE,
        CONVERT_FINOBT,
+       CONVERT_REFLINK,
        C_MAX_OPTS,
 };
 
@@ -81,6 +82,7 @@ static char *c_opts[] = {
        [CONVERT_NREXT64]       = "nrext64",
        [CONVERT_EXCHRANGE]     = "exchange",
        [CONVERT_FINOBT]        = "finobt",
+       [CONVERT_REFLINK]       = "reflink",
        [C_MAX_OPTS]            = NULL,
 };
 
@@ -382,6 +384,15 @@ process_args(int argc, char **argv)
                _("-c finobt only supports upgrades\n"));
                                        add_finobt = true;
                                        break;
+                               case CONVERT_REFLINK:
+                                       if (!val)
+                                               do_abort(
+               _("-c reflink requires a parameter\n"));
+                                       if (strtol(val, NULL, 0) != 1)
+                                               do_abort(
+               _("-c reflink only supports upgrades\n"));
+                                       add_reflink = true;
+                                       break;
                                default:
                                        unknown('c', val);
                                        break;