]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - mkfs/xfs_mkfs.c
xfs_scrub: remove moveon from progress report helpers
[thirdparty/xfsprogs-dev.git] / mkfs / xfs_mkfs.c
index 3343aaf1e93d020e2e3d93359819c9128064f372..18338a61476913a443f1f43f025a484925ce0e49 100644 (file)
@@ -3,13 +3,13 @@
  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  * All Rights Reserved.
  */
-#include "libfrog.h"
+#include "libfrog/util.h"
 #include "libxfs.h"
 #include <ctype.h>
 #include "xfs_multidisk.h"
 #include "libxcmd.h"
-#include "fsgeom.h"
-
+#include "libfrog/fsgeom.h"
+#include "libfrog/topology.h"
 
 #define TERABYTES(count, blog) ((uint64_t)(count) << (40 - (blog)))
 #define GIGABYTES(count, blog) ((uint64_t)(count) << (30 - (blog)))
@@ -858,7 +858,7 @@ usage( void )
                            (sunit=value,swidth=value|su=num,sw=num|noalign),\n\
                            sectsize=num\n\
 /* force overwrite */  [-f]\n\
-/* inode size */       [-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,\n\
+/* inode size */       [-i perblock=n|size=num,maxpct=n,attr=0|1|2,\n\
                            projid32bit=0|1,sparse=0|1]\n\
 /* no discard */       [-K]\n\
 /* log subvol */       [-l agnum=n,internal,size=num,logdev=xxx,version=n\n\
@@ -1451,15 +1451,15 @@ data_opts_parser(
                break;
        case D_RTINHERIT:
                if (getnum(value, opts, subopt))
-                       cli->fsx.fsx_xflags |= XFS_DIFLAG_RTINHERIT;
+                       cli->fsx.fsx_xflags |= FS_XFLAG_RTINHERIT;
                break;
        case D_PROJINHERIT:
                cli->fsx.fsx_projid = getnum(value, opts, subopt);
-               cli->fsx.fsx_xflags |= XFS_DIFLAG_PROJINHERIT;
+               cli->fsx.fsx_xflags |= FS_XFLAG_PROJINHERIT;
                break;
        case D_EXTSZINHERIT:
                cli->fsx.fsx_extsize = getnum(value, opts, subopt);
-               cli->fsx.fsx_xflags |= XFS_DIFLAG_EXTSZINHERIT;
+               cli->fsx.fsx_xflags |= FS_XFLAG_EXTSZINHERIT;
                break;
        case D_COWEXTSIZE:
                cli->fsx.fsx_cowextsize = getnum(value, opts, subopt);
@@ -1973,15 +1973,15 @@ _("Directory ftype field always enabled on CRC enabled filesystems\n"));
                        usage();
                }
 
-       } else {
+       } else {        /* !crcs_enabled */
                /*
-                * The kernel doesn't currently support crc=0,finobt=1
-                * filesystems. If crcs are not enabled and the user has not
-                * explicitly turned finobt on, then silently turn it off to
-                * avoid an unnecessary warning.
+                * The kernel doesn't support crc=0,finobt=1 filesystems.
+                * If crcs are not enabled and the user has not explicitly
+                * turned finobt on, then silently turn it off to avoid an
+                * unnecessary warning.
                 * If the user explicitly tried to use crc=0,finobt=1,
                 * then issue an error.
-                * The same is also for sparse inodes.
+                * The same is also true for sparse inodes and reflink.
                 */
                if (cli->sb_feat.finobt && cli_opt_set(&mopts, M_FINOBT)) {
                        fprintf(stderr,
@@ -2004,7 +2004,7 @@ _("rmapbt not supported without CRC support\n"));
                }
                cli->sb_feat.rmapbt = false;
 
-               if (cli->sb_feat.reflink) {
+               if (cli->sb_feat.reflink && cli_opt_set(&mopts, M_REFLINK)) {
                        fprintf(stderr,
 _("reflink not supported without CRC support\n"));
                        usage();
@@ -2216,7 +2216,7 @@ validate_extsize_hint(
         * that we know that we'll be propagating a correct hint and flag to
         * new files on the data device.
         */
-       if (cli->fsx.fsx_xflags & XFS_DIFLAG_EXTSZINHERIT)
+       if (cli->fsx.fsx_xflags & FS_XFLAG_EXTSZINHERIT)
                flags |= XFS_DIFLAG_EXTSZINHERIT;
 
        fa = libxfs_inode_validate_extsize(mp, cli->fsx.fsx_extsize, S_IFDIR,
@@ -2237,7 +2237,7 @@ _("illegal extent size hint %lld, must be less than %u.\n"),
                return;
 
        flags = XFS_DIFLAG_REALTIME;
-       if (cli->fsx.fsx_xflags & XFS_DIFLAG_EXTSIZE)
+       if (cli->fsx.fsx_xflags & FS_XFLAG_EXTSZINHERIT)
                flags |= XFS_DIFLAG_EXTSIZE;
 
        fa = libxfs_inode_validate_extsize(mp, cli->fsx.fsx_extsize, S_IFREG,
@@ -3033,15 +3033,27 @@ align_internal_log(
        struct xfs_mount        *mp,
        int                     sunit)
 {
+       uint64_t                logend;
+
        /* round up log start if necessary */
        if ((cfg->logstart % sunit) != 0)
                cfg->logstart = ((cfg->logstart + (sunit - 1)) / sunit) * sunit;
 
+       /* If our log start overlaps the next AG's metadata, fail. */
+       if (XFS_FSB_TO_AGBNO(mp, cfg->logstart) <= XFS_AGFL_BLOCK(mp)) {
+                       fprintf(stderr,
+_("Due to stripe alignment, the internal log start (%lld) cannot be aligned\n"
+  "within an allocation group.\n"),
+                       (long long) cfg->logstart);
+               usage();
+       }
+
        /* round up/down the log size now */
        align_log_size(cfg, sunit);
 
-       /* check the aligned log still fits in an AG. */
-       if (cfg->logblocks > cfg->agsize - XFS_FSB_TO_AGBNO(mp, cfg->logstart)) {
+       /* check the aligned log still starts and ends in the same AG. */
+       logend = cfg->logstart + cfg->logblocks - 1;
+       if (XFS_FSB_TO_AGNO(mp, cfg->logstart) != XFS_FSB_TO_AGNO(mp, logend)) {
                fprintf(stderr,
 _("Due to stripe alignment, the internal log size (%lld) is too large.\n"
   "Must fit within an allocation group.\n"),
@@ -3270,8 +3282,17 @@ finish_superblock_setup(
        struct xfs_mount        *mp,
        struct xfs_sb           *sbp)
 {
-       if (cfg->label)
-               strncpy(sbp->sb_fname, cfg->label, sizeof(sbp->sb_fname));
+       if (cfg->label) {
+               size_t          label_len;
+
+               /*
+                * Labels are null terminated unless the string fits exactly
+                * in the label field, so assume sb_fname is zeroed and then
+                * do a memcpy because the destination isn't a normal C string.
+                */
+               label_len = min(sizeof(sbp->sb_fname), strlen(cfg->label));
+               memcpy(sbp->sb_fname, cfg->label, label_len);
+       }
 
        sbp->sb_dblocks = cfg->dblocks;
        sbp->sb_rblocks = cfg->rtblocks;
@@ -3409,349 +3430,30 @@ initialise_ag_headers(
        struct xfs_mount        *mp,
        struct xfs_sb           *sbp,
        xfs_agnumber_t          agno,
-       int                     *worst_freelist)
+       int                     *worst_freelist,
+       struct list_head        *buffer_list)
 {
+       struct aghdr_init_data  id = {
+               .agno           = agno,
+               .agsize         = cfg->agsize,
+       };
        struct xfs_perag        *pag = libxfs_perag_get(mp, agno);
-       struct xfs_agfl         *agfl;
-       struct xfs_agf          *agf;
-       struct xfs_agi          *agi;
-       struct xfs_buf          *buf;
-       struct xfs_btree_block  *block;
-       struct xfs_alloc_rec    *arec;
-       struct xfs_alloc_rec    *nrec;
-       int                     bucket;
-       uint64_t                agsize = cfg->agsize;
-       xfs_agblock_t           agblocks;
-       bool                    is_log_ag = false;
-       int                     c;
-
-       if (cfg->loginternal && agno == cfg->logagno)
-               is_log_ag = true;
+       int                     error;
 
-       /*
-        * Superblock.
-        */
-       buf = libxfs_getbuf(mp->m_ddev_targp,
-                       XFS_AG_DADDR(mp, agno, XFS_SB_DADDR),
-                       XFS_FSS_TO_BB(mp, 1));
-       buf->b_ops = &xfs_sb_buf_ops;
-       memset(buf->b_addr, 0, cfg->sectorsize);
-       libxfs_sb_to_disk(buf->b_addr, sbp);
-       libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-
-       /*
-        * AG header block: freespace
-        */
-       buf = libxfs_getbuf(mp->m_ddev_targp,
-                       XFS_AG_DADDR(mp, agno, XFS_AGF_DADDR(mp)),
-                       XFS_FSS_TO_BB(mp, 1));
-       buf->b_ops = &xfs_agf_buf_ops;
-       agf = XFS_BUF_TO_AGF(buf);
-       memset(agf, 0, cfg->sectorsize);
        if (agno == cfg->agcount - 1)
-               agsize = cfg->dblocks - (xfs_rfsblock_t)(agno * agsize);
-       agf->agf_magicnum = cpu_to_be32(XFS_AGF_MAGIC);
-       agf->agf_versionnum = cpu_to_be32(XFS_AGF_VERSION);
-       agf->agf_seqno = cpu_to_be32(agno);
-       agf->agf_length = cpu_to_be32(agsize);
-       agf->agf_roots[XFS_BTNUM_BNOi] = cpu_to_be32(XFS_BNO_BLOCK(mp));
-       agf->agf_roots[XFS_BTNUM_CNTi] = cpu_to_be32(XFS_CNT_BLOCK(mp));
-       agf->agf_levels[XFS_BTNUM_BNOi] = cpu_to_be32(1);
-       agf->agf_levels[XFS_BTNUM_CNTi] = cpu_to_be32(1);
-       pag->pagf_levels[XFS_BTNUM_BNOi] = 1;
-       pag->pagf_levels[XFS_BTNUM_CNTi] = 1;
-
-       if (xfs_sb_version_hasrmapbt(sbp)) {
-               agf->agf_roots[XFS_BTNUM_RMAPi] = cpu_to_be32(XFS_RMAP_BLOCK(mp));
-               agf->agf_levels[XFS_BTNUM_RMAPi] = cpu_to_be32(1);
-               agf->agf_rmap_blocks = cpu_to_be32(1);
-       }
+               id.agsize = cfg->dblocks - (xfs_rfsblock_t)(agno * cfg->agsize);
 
-       if (xfs_sb_version_hasreflink(sbp)) {
-               agf->agf_refcount_root = cpu_to_be32(libxfs_refc_block(mp));
-               agf->agf_refcount_level = cpu_to_be32(1);
-               agf->agf_refcount_blocks = cpu_to_be32(1);
+       INIT_LIST_HEAD(&id.buffer_list);
+       error = -libxfs_ag_init_headers(mp, &id);
+       if (error) {
+               fprintf(stderr, _("AG header init failed, error %d\n"), error);
+               exit(1);
        }
 
-       agf->agf_flfirst = 0;
-       agf->agf_fllast = cpu_to_be32(libxfs_agfl_size(mp) - 1);
-       agf->agf_flcount = 0;
-       agblocks = (xfs_agblock_t)(agsize - libxfs_prealloc_blocks(mp));
-       agf->agf_freeblks = cpu_to_be32(agblocks);
-       agf->agf_longest = cpu_to_be32(agblocks);
+       list_splice_tail_init(&id.buffer_list, buffer_list);
 
-       if (xfs_sb_version_hascrc(sbp))
-               platform_uuid_copy(&agf->agf_uuid, &sbp->sb_uuid);
-
-       if (is_log_ag) {
-               be32_add_cpu(&agf->agf_freeblks, -(int64_t)cfg->logblocks);
-               agf->agf_longest = cpu_to_be32(agsize -
-                       XFS_FSB_TO_AGBNO(mp, cfg->logstart) - cfg->logblocks);
-       }
        if (libxfs_alloc_min_freelist(mp, pag) > *worst_freelist)
                *worst_freelist = libxfs_alloc_min_freelist(mp, pag);
-       libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-
-       /*
-        * AG freelist header block
-        */
-       buf = libxfs_getbuf(mp->m_ddev_targp,
-                       XFS_AG_DADDR(mp, agno, XFS_AGFL_DADDR(mp)),
-                       XFS_FSS_TO_BB(mp, 1));
-       buf->b_ops = &xfs_agfl_buf_ops;
-       agfl = XFS_BUF_TO_AGFL(buf);
-       /* setting to 0xff results in initialisation to NULLAGBLOCK */
-       memset(agfl, 0xff, cfg->sectorsize);
-       if (xfs_sb_version_hascrc(sbp)) {
-               agfl->agfl_magicnum = cpu_to_be32(XFS_AGFL_MAGIC);
-               agfl->agfl_seqno = cpu_to_be32(agno);
-               platform_uuid_copy(&agfl->agfl_uuid, &sbp->sb_uuid);
-               for (bucket = 0; bucket < libxfs_agfl_size(mp); bucket++)
-                       agfl->agfl_bno[bucket] = cpu_to_be32(NULLAGBLOCK);
-       }
-
-       libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-
-       /*
-        * AG header block: inodes
-        */
-       buf = libxfs_getbuf(mp->m_ddev_targp,
-                       XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)),
-                       XFS_FSS_TO_BB(mp, 1));
-       agi = XFS_BUF_TO_AGI(buf);
-       buf->b_ops = &xfs_agi_buf_ops;
-       memset(agi, 0, cfg->sectorsize);
-       agi->agi_magicnum = cpu_to_be32(XFS_AGI_MAGIC);
-       agi->agi_versionnum = cpu_to_be32(XFS_AGI_VERSION);
-       agi->agi_seqno = cpu_to_be32(agno);
-       agi->agi_length = cpu_to_be32(agsize);
-       agi->agi_count = 0;
-       agi->agi_root = cpu_to_be32(XFS_IBT_BLOCK(mp));
-       agi->agi_level = cpu_to_be32(1);
-       if (xfs_sb_version_hasfinobt(sbp)) {
-               agi->agi_free_root = cpu_to_be32(XFS_FIBT_BLOCK(mp));
-               agi->agi_free_level = cpu_to_be32(1);
-       }
-       agi->agi_freecount = 0;
-       agi->agi_newino = cpu_to_be32(NULLAGINO);
-       agi->agi_dirino = cpu_to_be32(NULLAGINO);
-       if (xfs_sb_version_hascrc(sbp))
-               platform_uuid_copy(&agi->agi_uuid, &sbp->sb_uuid);
-       for (c = 0; c < XFS_AGI_UNLINKED_BUCKETS; c++)
-               agi->agi_unlinked[c] = cpu_to_be32(NULLAGINO);
-       libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-
-       /*
-        * BNO btree root block
-        */
-       buf = libxfs_getbuf(mp->m_ddev_targp,
-                       XFS_AGB_TO_DADDR(mp, agno, XFS_BNO_BLOCK(mp)),
-                       BTOBB(cfg->blocksize));
-       buf->b_ops = &xfs_allocbt_buf_ops;
-       block = XFS_BUF_TO_BLOCK(buf);
-       memset(block, 0, cfg->blocksize);
-       libxfs_btree_init_block(mp, buf, XFS_BTNUM_BNO, 0, 1, agno, 0);
-
-       arec = XFS_ALLOC_REC_ADDR(mp, block, 1);
-       arec->ar_startblock = cpu_to_be32(libxfs_prealloc_blocks(mp));
-       if (is_log_ag) {
-               xfs_agblock_t   start = XFS_FSB_TO_AGBNO(mp, cfg->logstart);
-
-               ASSERT(start >= libxfs_prealloc_blocks(mp));
-               if (start != libxfs_prealloc_blocks(mp)) {
-                       /*
-                        * Modify first record to pad stripe align of log
-                        */
-                       arec->ar_blockcount = cpu_to_be32(start -
-                                               libxfs_prealloc_blocks(mp));
-                       nrec = arec + 1;
-                       /*
-                        * Insert second record at start of internal log
-                        * which then gets trimmed.
-                        */
-                       nrec->ar_startblock = cpu_to_be32(
-                                       be32_to_cpu(arec->ar_startblock) +
-                                       be32_to_cpu(arec->ar_blockcount));
-                       arec = nrec;
-                       be16_add_cpu(&block->bb_numrecs, 1);
-               }
-               /*
-                * Change record start to after the internal log
-                */
-               be32_add_cpu(&arec->ar_startblock, cfg->logblocks);
-       }
-       /*
-        * Calculate the record block count and check for the case where
-        * the log might have consumed all available space in the AG. If
-        * so, reset the record count to 0 to avoid exposure of an invalid
-        * record start block.
-        */
-       arec->ar_blockcount = cpu_to_be32(agsize -
-                                         be32_to_cpu(arec->ar_startblock));
-       if (!arec->ar_blockcount)
-               block->bb_numrecs = 0;
-
-       libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-
-       /*
-        * CNT btree root block
-        */
-       buf = libxfs_getbuf(mp->m_ddev_targp,
-                       XFS_AGB_TO_DADDR(mp, agno, XFS_CNT_BLOCK(mp)),
-                       BTOBB(cfg->blocksize));
-       buf->b_ops = &xfs_allocbt_buf_ops;
-       block = XFS_BUF_TO_BLOCK(buf);
-       memset(block, 0, cfg->blocksize);
-       libxfs_btree_init_block(mp, buf, XFS_BTNUM_CNT, 0, 1, agno, 0);
-
-       arec = XFS_ALLOC_REC_ADDR(mp, block, 1);
-       arec->ar_startblock = cpu_to_be32(libxfs_prealloc_blocks(mp));
-       if (is_log_ag) {
-               xfs_agblock_t   start = XFS_FSB_TO_AGBNO(mp, cfg->logstart);
-
-               ASSERT(start >= libxfs_prealloc_blocks(mp));
-               if (start != libxfs_prealloc_blocks(mp)) {
-                       arec->ar_blockcount = cpu_to_be32(start -
-                                       libxfs_prealloc_blocks(mp));
-                       nrec = arec + 1;
-                       nrec->ar_startblock = cpu_to_be32(
-                                       be32_to_cpu(arec->ar_startblock) +
-                                       be32_to_cpu(arec->ar_blockcount));
-                       arec = nrec;
-                       be16_add_cpu(&block->bb_numrecs, 1);
-               }
-               be32_add_cpu(&arec->ar_startblock, cfg->logblocks);
-       }
-       /*
-        * Calculate the record block count and check for the case where
-        * the log might have consumed all available space in the AG. If
-        * so, reset the record count to 0 to avoid exposure of an invalid
-        * record start block.
-        */
-       arec->ar_blockcount = cpu_to_be32(agsize -
-                                         be32_to_cpu(arec->ar_startblock));
-       if (!arec->ar_blockcount)
-               block->bb_numrecs = 0;
-
-       libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-
-       /*
-        * refcount btree root block
-        */
-       if (xfs_sb_version_hasreflink(sbp)) {
-               buf = libxfs_getbuf(mp->m_ddev_targp,
-                       XFS_AGB_TO_DADDR(mp, agno, libxfs_refc_block(mp)),
-                       BTOBB(cfg->blocksize));
-               buf->b_ops = &xfs_refcountbt_buf_ops;
-
-               block = XFS_BUF_TO_BLOCK(buf);
-               memset(block, 0, cfg->blocksize);
-               libxfs_btree_init_block(mp, buf, XFS_BTNUM_REFC, 0, 0, agno, 0);
-               libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-       }
-
-       /*
-        * INO btree root block
-        */
-       buf = libxfs_getbuf(mp->m_ddev_targp,
-                       XFS_AGB_TO_DADDR(mp, agno, XFS_IBT_BLOCK(mp)),
-                       BTOBB(cfg->blocksize));
-       buf->b_ops = &xfs_inobt_buf_ops;
-       block = XFS_BUF_TO_BLOCK(buf);
-       memset(block, 0, cfg->blocksize);
-       libxfs_btree_init_block(mp, buf, XFS_BTNUM_INO, 0, 0, agno, 0);
-       libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-
-       /*
-        * Free INO btree root block
-        */
-       if (xfs_sb_version_hasfinobt(sbp)) {
-               buf = libxfs_getbuf(mp->m_ddev_targp,
-                               XFS_AGB_TO_DADDR(mp, agno, XFS_FIBT_BLOCK(mp)),
-                               BTOBB(cfg->blocksize));
-               buf->b_ops = &xfs_inobt_buf_ops;
-               block = XFS_BUF_TO_BLOCK(buf);
-               memset(block, 0, cfg->blocksize);
-               libxfs_btree_init_block(mp, buf, XFS_BTNUM_FINO, 0, 0, agno, 0);
-               libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-       }
-
-       /* RMAP btree root block */
-       if (xfs_sb_version_hasrmapbt(sbp)) {
-               struct xfs_rmap_rec     *rrec;
-
-               buf = libxfs_getbuf(mp->m_ddev_targp,
-                       XFS_AGB_TO_DADDR(mp, agno, XFS_RMAP_BLOCK(mp)),
-                       BTOBB(cfg->blocksize));
-               buf->b_ops = &xfs_rmapbt_buf_ops;
-               block = XFS_BUF_TO_BLOCK(buf);
-               memset(block, 0, cfg->blocksize);
-
-               libxfs_btree_init_block(mp, buf, XFS_BTNUM_RMAP, 0, 0, agno, 0);
-
-               /*
-                * mark the AG header regions as static metadata
-                * The BNO btree block is the first block after the
-                * headers, so it's location defines the size of region
-                * the static metadata consumes.
-                */
-               rrec = XFS_RMAP_REC_ADDR(block, 1);
-               rrec->rm_startblock = 0;
-               rrec->rm_blockcount = cpu_to_be32(XFS_BNO_BLOCK(mp));
-               rrec->rm_owner = cpu_to_be64(XFS_RMAP_OWN_FS);
-               rrec->rm_offset = 0;
-               be16_add_cpu(&block->bb_numrecs, 1);
-
-               /* account freespace btree root blocks */
-               rrec = XFS_RMAP_REC_ADDR(block, 2);
-               rrec->rm_startblock = cpu_to_be32(XFS_BNO_BLOCK(mp));
-               rrec->rm_blockcount = cpu_to_be32(2);
-               rrec->rm_owner = cpu_to_be64(XFS_RMAP_OWN_AG);
-               rrec->rm_offset = 0;
-               be16_add_cpu(&block->bb_numrecs, 1);
-
-               /* account inode btree root blocks */
-               rrec = XFS_RMAP_REC_ADDR(block, 3);
-               rrec->rm_startblock = cpu_to_be32(XFS_IBT_BLOCK(mp));
-               rrec->rm_blockcount = cpu_to_be32(XFS_RMAP_BLOCK(mp) -
-                                               XFS_IBT_BLOCK(mp));
-               rrec->rm_owner = cpu_to_be64(XFS_RMAP_OWN_INOBT);
-               rrec->rm_offset = 0;
-               be16_add_cpu(&block->bb_numrecs, 1);
-
-               /* account for rmap btree root */
-               rrec = XFS_RMAP_REC_ADDR(block, 4);
-               rrec->rm_startblock = cpu_to_be32(XFS_RMAP_BLOCK(mp));
-               rrec->rm_blockcount = cpu_to_be32(1);
-               rrec->rm_owner = cpu_to_be64(XFS_RMAP_OWN_AG);
-               rrec->rm_offset = 0;
-               be16_add_cpu(&block->bb_numrecs, 1);
-
-               /* account for refcount btree root */
-               if (xfs_sb_version_hasreflink(sbp)) {
-                       rrec = XFS_RMAP_REC_ADDR(block, 5);
-                       rrec->rm_startblock = cpu_to_be32(libxfs_refc_block(mp));
-                       rrec->rm_blockcount = cpu_to_be32(1);
-                       rrec->rm_owner = cpu_to_be64(XFS_RMAP_OWN_REFC);
-                       rrec->rm_offset = 0;
-                       be16_add_cpu(&block->bb_numrecs, 1);
-               }
-
-               /* account for the log space */
-               if (is_log_ag) {
-                       rrec = XFS_RMAP_REC_ADDR(block,
-                                       be16_to_cpu(block->bb_numrecs) + 1);
-                       rrec->rm_startblock = cpu_to_be32(
-                                       XFS_FSB_TO_AGBNO(mp, cfg->logstart));
-                       rrec->rm_blockcount = cpu_to_be32(cfg->logblocks);
-                       rrec->rm_owner = cpu_to_be64(XFS_RMAP_OWN_LOG);
-                       rrec->rm_offset = 0;
-                       be16_add_cpu(&block->bb_numrecs, 1);
-               }
-
-               libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
-       }
-
        libxfs_perag_put(pag);
 }
 
@@ -3779,8 +3481,11 @@ initialise_ag_freespace(
        libxfs_alloc_fix_freelist(&args, 0);
        libxfs_perag_put(args.pag);
        c = -libxfs_trans_commit(tp);
-       if (c)
-               res_failed(c);
+       if (c) {
+               errno = c;
+               perror(_("initializing AG free space list"));
+               exit(1);
+       }
 }
 
 /*
@@ -3867,13 +3572,15 @@ main(
                        .finobt = true,
                        .spinodes = true,
                        .rmapbt = false,
-                       .reflink = false,
+                       .reflink = true,
                        .parent_pointers = false,
                        .nodalign = false,
                        .nortalign = false,
                },
        };
 
+       struct list_head        buffer_list;
+
        platform_uuid_generate(&cli.uuid);
        progname = basename(argv[0]);
        setlocale(LC_ALL, "");
@@ -3986,7 +3693,6 @@ main(
        cfg.rtblocks = calc_dev_size(cli.rtsize, &cfg, &ropts, R_SIZE, "rt");
 
        validate_rtextsize(&cfg, &cli, &ft);
-       calc_stripe_factors(&cfg, &cli, &ft);
 
        /*
         * Open and validate the device configurations
@@ -3996,6 +3702,7 @@ main(
        validate_datadev(&cfg, &cli);
        validate_logdev(&cfg, &cli, &logfile);
        validate_rtdev(&cfg, &cli, &rtfile);
+       calc_stripe_factors(&cfg, &cli, &ft);
 
        /*
         * At this point when know exactly what size all the devices are,
@@ -4031,17 +3738,8 @@ main(
        /* Print the intended geometry of the fs. */
        if (!quiet || dry_run) {
                struct xfs_fsop_geom    geo;
-               int                     error;
-
-               error = -libxfs_fs_geometry(sbp, &geo,
-                               XFS_FS_GEOM_MAX_STRUCT_VER);
-               if (error) {
-                       fprintf(stderr,
-       _("%s: failed to generate filesystem geometry\n"),
-                               progname);
-                       exit(1);
-               }
 
+               libxfs_fs_geometry(sbp, &geo, XFS_FS_GEOM_MAX_STRUCT_VER);
                xfs_report_geom(&geo, dfile, logfile, rtfile);
                if (dry_run)
                        exit(0);
@@ -4074,8 +3772,26 @@ main(
        /*
         * Initialise all the static on disk metadata.
         */
-       for (agno = 0; agno < cfg.agcount; agno++)
-               initialise_ag_headers(&cfg, mp, sbp, agno, &worst_freelist);
+       INIT_LIST_HEAD(&buffer_list);
+       for (agno = 0; agno < cfg.agcount; agno++) {
+               initialise_ag_headers(&cfg, mp, sbp, agno, &worst_freelist,
+                               &buffer_list);
+
+               if (agno % 16)
+                       continue;
+
+               if (libxfs_buf_delwri_submit(&buffer_list)) {
+                       fprintf(stderr, _("%s: writing AG headers failed\n"),
+                                       progname);
+                       exit(1);
+               }
+       }
+
+       if (libxfs_buf_delwri_submit(&buffer_list)) {
+               fprintf(stderr, _("%s: writing AG headers failed\n"),
+                               progname);
+               exit(1);
+       }
 
        /*
         * Initialise the freespace freelists (i.e. AGFLs) in each AG.
@@ -4114,7 +3830,9 @@ main(
        /*
         * Mark the filesystem ok.
         */
-       buf = libxfs_getsb(mp, LIBXFS_EXIT_ON_FAILURE);
+       buf = libxfs_getsb(mp);
+       if (!buf || buf->b_error)
+               exit(1);
        (XFS_BUF_TO_SBP(buf))->sb_inprogress = 0;
        libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);