]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
mkfs: enable reflink on the realtime device
authorDarrick J. Wong <djwong@kernel.org>
Tue, 15 Oct 2024 19:44:49 +0000 (12:44 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 1 Nov 2024 20:45:01 +0000 (13:45 -0700)
Allow the creation of filesystems with both reflink and realtime volumes
enabled.  For now we don't support a realtime extent size > 1.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/init.c
libxfs/libxfs_api_defs.h
mkfs/xfs_mkfs.c

index 956cdb33c379164bd03bb15b35131e89a1d9164a..573828f1a9248b83a9d7c5491b0906c50c98522a 100644 (file)
@@ -305,9 +305,9 @@ rtmount_init(
        if (mp->m_sb.sb_rblocks == 0)
                return 0;
 
-       if (xfs_has_reflink(mp)) {
+       if (xfs_has_reflink(mp) && mp->m_sb.sb_rextsize > 1) {
                fprintf(stderr,
-       _("%s: Reflink not compatible with realtime device. Please try a newer xfsprogs.\n"),
+       _("%s: Reflink not compatible with realtime extent size > 1. Please try a newer xfsprogs.\n"),
                                progname);
                return -1;
        }
index de8d58e52048437ae0d6ff742e9c204a800110ae..030367d874ebbe89f61f51aa8fbbfd25e5f19999 100644 (file)
 
 #define xfs_rtrefcountbt_absolute_maxlevels    libxfs_rtrefcountbt_absolute_maxlevels
 #define xfs_rtrefcountbt_calc_size             libxfs_rtrefcountbt_calc_size
+#define xfs_rtrefcountbt_calc_reserves libxfs_rtrefcountbt_calc_reserves
 #define xfs_rtrefcountbt_commit_staged_btree   libxfs_rtrefcountbt_commit_staged_btree
 #define xfs_rtrefcountbt_create                libxfs_rtrefcountbt_create
 #define xfs_rtrefcountbt_droot_maxrecs libxfs_rtrefcountbt_droot_maxrecs
index f176e677330a184adce02c929f00ca15107f4cdc..2ea3ee75ea632ab2b9932ef9021ea425c8aee488 100644 (file)
@@ -2617,12 +2617,36 @@ _("inode btree counters not supported without finobt support\n"));
        }
 
        if (cli->xi->rt.name) {
-               if (cli->sb_feat.reflink && cli_opt_set(&mopts, M_REFLINK)) {
-                       fprintf(stderr,
-_("reflink not supported with realtime devices\n"));
-                       usage();
+               if (cli->rtextsize && cli->sb_feat.reflink) {
+                       if (cli_opt_set(&mopts, M_REFLINK)) {
+                               fprintf(stderr,
+_("reflink not supported on realtime devices with rt extent size specified\n"));
+                               usage();
+                       }
+                       cli->sb_feat.reflink = false;
+               }
+               if (cfg->blocksize < XFS_MIN_RTEXTSIZE && cli->sb_feat.reflink) {
+                       if (cli_opt_set(&mopts, M_REFLINK)) {
+                               fprintf(stderr,
+_("reflink not supported on realtime devices with blocksize %d < %d\n"),
+                                               cli->blocksize,
+                                               XFS_MIN_RTEXTSIZE);
+                               usage();
+                       }
+                       cli->sb_feat.reflink = false;
+               }
+               if (!cli->sb_feat.metadir && cli->sb_feat.reflink) {
+                       if (cli_opt_set(&mopts, M_REFLINK) &&
+                           cli_opt_set(&mopts, M_METADIR)) {
+                               fprintf(stderr,
+_("reflink not supported on realtime devices without metadir feature\n"));
+                               usage();
+                       } else if (cli_opt_set(&mopts, M_REFLINK)) {
+                               cli->sb_feat.metadir = true;
+                       } else {
+                               cli->sb_feat.reflink = false;
+                       }
                }
-               cli->sb_feat.reflink = false;
 
                if (!cli->sb_feat.metadir && cli->sb_feat.rmapbt) {
                        if (cli_opt_set(&mopts, M_RMAPBT) &&
@@ -2820,6 +2844,19 @@ validate_rtextsize(
                        usage();
                }
                cfg->rtextblocks = (xfs_extlen_t)(rtextbytes >> cfg->blocklog);
+       } else if (cli->sb_feat.reflink && cli->xi->rt.name) {
+               /*
+                * reflink doesn't support rt extent size > 1FSB yet, so set
+                * an extent size of 1FSB.  Make sure we still satisfy the
+                * minimum rt extent size.
+                */
+               if (cfg->blocksize < XFS_MIN_RTEXTSIZE) {
+                       fprintf(stderr,
+               _("reflink not supported on rt volume with blocksize %d\n"),
+                               cfg->blocksize);
+                       usage();
+               }
+               cfg->rtextblocks = 1;
        } else {
                /*
                 * If realtime extsize has not been specified by the user,
@@ -2851,6 +2888,12 @@ validate_rtextsize(
                }
        }
        ASSERT(cfg->rtextblocks);
+
+       if (cli->sb_feat.reflink && cfg->rtblocks > 0 && cfg->rtextblocks > 1) {
+               fprintf(stderr,
+_("reflink not supported on realtime with extent sizes > 1\n"));
+               usage();
+       }
 }
 
 /* Validate the incoming extsize hint. */
@@ -4940,11 +4983,19 @@ check_rt_meta_prealloc(
                                rtg->rtg_inodes[XFS_RTGI_RMAP], ask);
                if (error)
                        prealloc_fail(mp, error, ask, _("realtime rmap btree"));
+
+               ask = libxfs_rtrefcountbt_calc_reserves(mp);
+               error = -libxfs_metafile_resv_init(
+                               rtg->rtg_inodes[XFS_RTGI_REFCOUNT], ask);
+               if (error)
+                       prealloc_fail(mp, error, ask, _("realtime refcount btree"));
        }
 
        /* Unreserve the realtime metadata reservations. */
-       while ((rtg = xfs_rtgroup_next(mp, rtg)))
+       while ((rtg = xfs_rtgroup_next(mp, rtg))) {
                libxfs_metafile_resv_free(rtg->rtg_inodes[XFS_RTGI_RMAP]);
+               libxfs_metafile_resv_free(rtg->rtg_inodes[XFS_RTGI_REFCOUNT]);
+       }
 
        /* Unreserve the per-AG reservations. */
        while ((pag = xfs_perag_next(mp, pag)))