]> www.infradead.org Git - users/hch/misc.git/commitdiff
xfs: add block headers to realtime summary blocks
authorDarrick J. Wong <djwong@kernel.org>
Wed, 29 May 2024 04:11:20 +0000 (21:11 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 24 Jul 2024 05:33:38 +0000 (22:33 -0700)
Upgrade rtsummary blocks to have self describing metadata like most
every other thing in XFS.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
fs/xfs/libxfs/xfs_format.h
fs/xfs/libxfs/xfs_rtbitmap.c
fs/xfs/libxfs/xfs_rtbitmap.h
fs/xfs/libxfs/xfs_shared.h
fs/xfs/scrub/rtsummary_repair.c
fs/xfs/xfs_buf_item_recover.c
fs/xfs/xfs_rtalloc.c

index fcc3a524fc51ed41b9a6efd0cb31fb6574e76974..e7fb96277c245e02112702c004a20c829f8ec711 100644 (file)
@@ -1259,6 +1259,7 @@ static inline bool xfs_dinode_has_large_extent_counts(
  * RT bit manipulation macros.
  */
 #define XFS_RTBITMAP_MAGIC     0x424D505A      /* BMPZ */
+#define XFS_RTSUMMARY_MAGIC    0x53554D59      /* SUMY */
 
 struct xfs_rtbuf_blkinfo {
        __be32          rt_magic;       /* validity check on block */
index 6b0d1187a760717eef18d87db17546b726c8a95e..86ed4ad6957dee37d6ff9266b8e07ae02476dd39 100644 (file)
@@ -54,7 +54,7 @@ xfs_rtbuf_verify_read(
        struct xfs_rtbuf_blkinfo        *hdr = bp->b_addr;
        xfs_failaddr_t                  fa;
 
-       if (!xfs_has_rtgroups(mp) || bp->b_ops != &xfs_rtbitmap_buf_ops)
+       if (!xfs_has_rtgroups(mp))
                return;
 
        if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr->rt_lsn))) {
@@ -85,7 +85,7 @@ xfs_rtbuf_verify_write(
        struct xfs_buf_log_item         *bip = bp->b_log_item;
        xfs_failaddr_t                  fa;
 
-       if (!xfs_has_rtgroups(mp) || bp->b_ops != &xfs_rtbitmap_buf_ops)
+       if (!xfs_has_rtgroups(mp))
                return;
 
        fa = xfs_rtbuf_verify(bp);
@@ -113,6 +113,14 @@ const struct xfs_buf_ops xfs_rtbitmap_buf_ops = {
        .verify_struct  = xfs_rtbuf_verify,
 };
 
+const struct xfs_buf_ops xfs_rtsummary_buf_ops = {
+       .name           = "xfs_rtsummary",
+       .magic          = { 0, cpu_to_be32(XFS_RTSUMMARY_MAGIC) },
+       .verify_read    = xfs_rtbuf_verify_read,
+       .verify_write   = xfs_rtbuf_verify_write,
+       .verify_struct  = xfs_rtbuf_verify,
+};
+
 /* Release cached rt bitmap and summary buffers. */
 void
 xfs_rtbuf_cache_relse(
@@ -198,7 +206,7 @@ xfs_rtbuf_get(
        if (error)
                return error;
 
-       if (xfs_has_rtgroups(mp) && !issum) {
+       if (xfs_has_rtgroups(mp)) {
                struct xfs_rtbuf_blkinfo        *hdr = bp->b_addr;
 
                if (hdr->rt_owner != cpu_to_be64(ip->i_ino)) {
@@ -1235,6 +1243,10 @@ xfs_rtsummary_blockcount(
        unsigned long long      rsumwords;
 
        rsumwords = (unsigned long long)rsumlevels * rbmblocks;
+
+       if (xfs_has_rtgroups(mp))
+               return howmany_64(rsumwords, mp->m_blockwsize);
+
        return XFS_B_TO_FSB(mp, rsumwords << XFS_WORDLOG);
 }
 
index c1942321fd149a8b0bbaae8b93da782696fe0a51..aa3206c22ad6f4ffe4f1c6295db798998647157e 100644 (file)
@@ -232,6 +232,9 @@ xfs_rtsumoffs_to_block(
        struct xfs_mount        *mp,
        xfs_rtsumoff_t          rsumoff)
 {
+       if (xfs_has_rtgroups(mp))
+               return rsumoff / mp->m_blockwsize;
+
        return XFS_B_TO_FSBT(mp, rsumoff * sizeof(xfs_suminfo_t));
 }
 
@@ -246,6 +249,9 @@ xfs_rtsumoffs_to_infoword(
 {
        unsigned int            mask = mp->m_blockmask >> XFS_SUMINFOLOG;
 
+       if (xfs_has_rtgroups(mp))
+               return rsumoff % mp->m_blockwsize;
+
        return rsumoff & mask;
 }
 
@@ -255,7 +261,13 @@ xfs_rsumblock_infoptr(
        struct xfs_rtalloc_args *args,
        unsigned int            index)
 {
-       union xfs_suminfo_raw   *info = args->sumbp->b_addr;
+       union xfs_suminfo_raw   *info;
+       struct xfs_rtbuf_blkinfo *hdr = args->sumbp->b_addr;
+
+       if (xfs_has_rtgroups(args->mp))
+               info = (union xfs_suminfo_raw *)(hdr + 1);
+       else
+               info = args->sumbp->b_addr;
 
        return info + index;
 }
@@ -289,8 +301,11 @@ xfs_rtblock_ops(
        struct xfs_mount        *mp,
        bool                    issum)
 {
-       if (xfs_has_rtgroups(mp) && !issum)
+       if (xfs_has_rtgroups(mp)) {
+               if (issum)
+                       return &xfs_rtsummary_buf_ops;
                return &xfs_rtbitmap_buf_ops;
+       }
        return &xfs_rtbuf_ops;
 }
 
index 9acf8d401acea20184b31022407d9b408c61aee2..b6e56daa6a1477ad9a40f70c4f94435e52f7ece7 100644 (file)
@@ -39,6 +39,7 @@ extern const struct xfs_buf_ops xfs_inode_buf_ra_ops;
 extern const struct xfs_buf_ops xfs_refcountbt_buf_ops;
 extern const struct xfs_buf_ops xfs_rmapbt_buf_ops;
 extern const struct xfs_buf_ops xfs_rtbitmap_buf_ops;
+extern const struct xfs_buf_ops xfs_rtsummary_buf_ops;
 extern const struct xfs_buf_ops xfs_rtbuf_ops;
 extern const struct xfs_buf_ops xfs_rtsb_buf_ops;
 extern const struct xfs_buf_ops xfs_sb_buf_ops;
index d9e971c4c79fb267129002644de5310e94eb825a..7cf00bdf63350e78d191ded3f0125a269504ee20 100644 (file)
@@ -82,12 +82,23 @@ xrep_rtsummary_prep_buf(
        ondisk = xfs_rsumblock_infoptr(&rts->args, 0);
        rts->args.sumbp = NULL;
 
-       bp->b_ops = &xfs_rtbuf_ops;
-
        error = xfsum_copyout(sc, rts->prep_wordoff, ondisk, mp->m_blockwsize);
        if (error)
                return error;
 
+       if (xfs_has_rtgroups(sc->mp)) {
+               struct xfs_rtbuf_blkinfo        *hdr = bp->b_addr;
+
+               hdr->rt_magic = cpu_to_be32(XFS_RTSUMMARY_MAGIC);
+               hdr->rt_owner = cpu_to_be64(sc->ip->i_ino);
+               hdr->rt_blkno = cpu_to_be64(xfs_buf_daddr(bp));
+               hdr->rt_lsn = 0;
+               uuid_copy(&hdr->rt_uuid, &sc->mp->m_sb.sb_meta_uuid);
+               bp->b_ops = &xfs_rtsummary_buf_ops;
+       } else {
+               bp->b_ops = &xfs_rtbuf_ops;
+       }
+
        rts->prep_wordoff += mp->m_blockwsize;
        xfs_trans_buf_set_type(sc->tp, bp, XFS_BLFT_RTSUMMARY_BUF);
        return 0;
index 403e30554f0a685f74fb60b5935e3a7d4d3b496a..43ef40ff13819ef839f9a0e4853c5b29f1a84f2a 100644 (file)
@@ -399,7 +399,10 @@ xlog_recover_validate_buf_type(
                bp->b_ops = xfs_rtblock_ops(mp, false);
                break;
        case XFS_BLFT_RTSUMMARY_BUF:
-               /* no magic numbers for verification of RT buffers */
+               if (xfs_has_rtgroups(mp) && magic32 != XFS_RTSUMMARY_MAGIC) {
+                       warnmsg = "Bad rtsummary magic!";
+                       break;
+               }
                bp->b_ops = xfs_rtblock_ops(mp, true);
                break;
 #endif /* CONFIG_XFS_RT */
@@ -735,13 +738,13 @@ xlog_recover_get_buf_lsn(
         * UUIDs, so we must recover them immediately.
         */
        blft = xfs_blft_from_flags(buf_f);
-       if (!xfs_has_rtgroups(mp) && blft == XFS_BLFT_RTBITMAP_BUF)
-               goto recover_immediately;
-       if (blft == XFS_BLFT_RTSUMMARY_BUF)
+       if (!xfs_has_rtgroups(mp) && (blft == XFS_BLFT_RTBITMAP_BUF ||
+                                     blft == XFS_BLFT_RTSUMMARY_BUF))
                goto recover_immediately;
 
        magic32 = be32_to_cpu(*(__be32 *)blk);
        switch (magic32) {
+       case XFS_RTSUMMARY_MAGIC:
        case XFS_RTBITMAP_MAGIC: {
                struct xfs_rtbuf_blkinfo        *hdr = blk;
 
index 1c6affe049697913531f789dc8d385b4f84202ad..6a331cae6a2e6ef394f6905ed5c4d3e173af0ce5 100644 (file)
@@ -748,10 +748,13 @@ xfs_growfs_init_rtbuf(
        bp->b_ops = xfs_rtblock_ops(mp, buf_type == XFS_BLFT_RTSUMMARY_BUF);
        memset(bp->b_addr, 0, mp->m_sb.sb_blocksize);
 
-       if (xfs_has_rtgroups(mp) && buf_type == XFS_BLFT_RTBITMAP_BUF) {
+       if (xfs_has_rtgroups(mp)) {
                struct xfs_rtbuf_blkinfo        *hdr = bp->b_addr;
 
-               hdr->rt_magic = cpu_to_be32(XFS_RTBITMAP_MAGIC);
+               if (buf_type == XFS_BLFT_RTBITMAP_BUF)
+                       hdr->rt_magic = cpu_to_be32(XFS_RTBITMAP_MAGIC);
+               else
+                       hdr->rt_magic = cpu_to_be32(XFS_RTSUMMARY_MAGIC);
                hdr->rt_owner = cpu_to_be64(ip->i_ino);
                hdr->rt_blkno = cpu_to_be64(d);
                uuid_copy(&hdr->rt_uuid, &mp->m_sb.sb_meta_uuid);