]> git.apps.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
xfs_{db,repair}: use accessor functions for summary info words
authorDarrick J. Wong <djwong@kernel.org>
Mon, 15 Apr 2024 23:07:30 +0000 (16:07 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 17 Apr 2024 21:06:23 +0000 (14:06 -0700)
Port xfs_db and xfs_repair to use get and set functions for rtsummary
words so that we can redefine the ondisk format with a specific
endianness.  Note that this requires the definition of a distinct type
for ondisk summary info words so that the compiler can perform proper
typechecking.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bill O'Donnell <bodonnel@redhat.com>
db/check.c
libxfs/libxfs_api_defs.h
repair/globals.c
repair/globals.h
repair/phase6.c
repair/rt.c
repair/rt.h

index 6e916f335b14cee3df4bab6bc15cc294bba0362f..103ea4022c3b3bb37ad8df6263c64f3ea83c0bc9 100644 (file)
@@ -132,8 +132,8 @@ static unsigned             sbversion;
 static int             sbver_err;
 static int             serious_error;
 static int             sflag;
-static xfs_suminfo_t   *sumcompute;
-static xfs_suminfo_t   *sumfile;
+static union xfs_suminfo_raw *sumcompute;
+static union xfs_suminfo_raw *sumfile;
 static const char      *typename[] = {
        "unknown",
        "agf",
@@ -1704,12 +1704,20 @@ check_set_rdbmap(
        }
 }
 
+static inline xfs_suminfo_t
+get_suminfo(
+       struct xfs_mount        *mp,
+       union xfs_suminfo_raw   *raw)
+{
+       return raw->old;
+}
+
 static void
 check_summary(void)
 {
        xfs_rfsblock_t  bno;
-       xfs_suminfo_t   *csp;
-       xfs_suminfo_t   *fsp;
+       union xfs_suminfo_raw *csp;
+       union xfs_suminfo_raw *fsp;
        int             log;
 
        csp = sumcompute;
@@ -1718,12 +1726,14 @@ check_summary(void)
                for (bno = 0;
                     bno < mp->m_sb.sb_rbmblocks;
                     bno++, csp++, fsp++) {
-                       if (*csp != *fsp) {
+                       if (csp->old != fsp->old) {
                                if (!sflag)
                                        dbprintf(_("rt summary mismatch, size %d "
                                                 "block %llu, file: %d, "
                                                 "computed: %d\n"),
-                                               log, bno, *fsp, *csp);
+                                               log, bno,
+                                               get_suminfo(mp, fsp),
+                                               get_suminfo(mp, csp));
                                error++;
                        }
                }
@@ -1950,8 +1960,8 @@ init(
                inomap[c] = xcalloc(mp->m_sb.sb_rblocks, sizeof(**inomap));
                words = libxfs_rtsummary_wordcount(mp, mp->m_rsumlevels,
                                mp->m_sb.sb_rbmblocks);
-               sumfile = xcalloc(words, sizeof(xfs_suminfo_t));
-               sumcompute = xcalloc(words, sizeof(xfs_suminfo_t));
+               sumfile = xcalloc(words, sizeof(union xfs_suminfo_raw));
+               sumcompute = xcalloc(words, sizeof(union xfs_suminfo_raw));
        }
        nflag = sflag = tflag = verbose = optind = 0;
        while ((c = getopt(argc, argv, "b:i:npstv")) != EOF) {
@@ -3590,6 +3600,17 @@ process_quota(
        }
 }
 
+static inline void
+inc_sumcount(
+       struct xfs_mount        *mp,
+       union xfs_suminfo_raw   *info,
+       xfs_rtsumoff_t          index)
+{
+       union xfs_suminfo_raw   *p = info + index;
+
+       p->old++;
+}
+
 static void
 process_rtbitmap(
        blkmap_t        *blkmap)
@@ -3669,7 +3690,7 @@ process_rtbitmap(
                                        bitsperblock + (bit - start_bit);
                                log = XFS_RTBLOCKLOG(len);
                                offs = xfs_rtsumoffs(mp, log, start_bmbno);
-                               sumcompute[offs]++;
+                               inc_sumcount(mp, sumcompute, offs);
                                prevbit = 0;
                        }
                }
@@ -3682,7 +3703,7 @@ process_rtbitmap(
                        (bit - start_bit);
                log = XFS_RTBLOCKLOG(len);
                offs = xfs_rtsumoffs(mp, log, start_bmbno);
-               sumcompute[offs]++;
+               inc_sumcount(mp, sumcompute, offs);
        }
        free(words);
 }
@@ -3692,12 +3713,17 @@ process_rtsummary(
        blkmap_t        *blkmap)
 {
        xfs_fsblock_t   bno;
-       char            *bytes;
+       union xfs_suminfo_raw *sfile = sumfile;
        xfs_fileoff_t   sumbno;
        int             t;
 
        sumbno = NULLFILEOFF;
        while ((sumbno = blkmap_next_off(blkmap, sumbno, &t)) != NULLFILEOFF) {
+               struct xfs_rtalloc_args args = {
+                       .mp             = mp,
+               };
+               union xfs_suminfo_raw   *ondisk;
+
                bno = blkmap_get(blkmap, sumbno);
                if (bno == NULLFSBLOCK) {
                        if (!sflag)
@@ -3710,18 +3736,22 @@ process_rtsummary(
                push_cur();
                set_cur(&typtab[TYP_RTSUMMARY], XFS_FSB_TO_DADDR(mp, bno),
                        blkbb, DB_RING_IGN, NULL);
-               if ((bytes = iocur_top->data) == NULL) {
+               if (!iocur_top->bp) {
                        if (!sflag)
                                dbprintf(_("can't read block %lld for rtsummary "
                                         "inode\n"),
                                        (xfs_fileoff_t)sumbno);
                        error++;
                        pop_cur();
+                       sfile += mp->m_blockwsize;
                        continue;
                }
-               memcpy((char *)sumfile + sumbno * mp->m_sb.sb_blocksize, bytes,
-                       mp->m_sb.sb_blocksize);
+
+               args.sumbp = iocur_top->bp;
+               ondisk = xfs_rsumblock_infoptr(&args, 0);
+               memcpy(sfile, ondisk, mp->m_sb.sb_blocksize);
                pop_cur();
+               sfile += mp->m_blockwsize;
        }
 }
 
index e87195cb1ac9c72488010a83988a4ea0b3e42d3d..cee0df2479c5a54843fc592fc2a6e12852def5dc 100644 (file)
 #define xfs_rtbitmap_setword           libxfs_rtbitmap_setword
 #define xfs_rtbitmap_wordcount         libxfs_rtbitmap_wordcount
 
+#define xfs_suminfo_add                        libxfs_suminfo_add
+#define xfs_suminfo_get                        libxfs_suminfo_get
 #define xfs_rtsummary_wordcount                libxfs_rtsummary_wordcount
 
 #define xfs_rtfree_extent              libxfs_rtfree_extent
index 73ae9de075de3cec33442a92c43a4cda082d11f2..a68929bdc01203858522ce446bd87937e8d004f2 100644 (file)
@@ -87,7 +87,7 @@ int64_t               fs_max_file_offset;
 /* realtime info */
 
 union xfs_rtword_raw   *btmcompute;
-xfs_suminfo_t  *sumcompute;
+union xfs_suminfo_raw  *sumcompute;
 
 /* inode tree records have full or partial backptr fields ? */
 
index 311cf72189f3ebb0d19af7458da6fef6e642f3fc..a67e384a626e5e62d43b7c2000bb365822ea1fee 100644 (file)
@@ -128,7 +128,7 @@ extern int64_t              fs_max_file_offset;
 /* realtime info */
 
 extern union xfs_rtword_raw            *btmcompute;
-extern xfs_suminfo_t   *sumcompute;
+extern union xfs_suminfo_raw           *sumcompute;
 
 /* inode tree records have full or partial backptr fields ? */
 
index 884b7c1ac2b5dbb984d7e48f022758adffde6cd9..0818ee1a1501adcccc18ddcca823e8cbd8b32319 100644 (file)
@@ -648,7 +648,7 @@ fill_rsumino(xfs_mount_t *mp)
        struct xfs_buf  *bp;
        xfs_trans_t     *tp;
        xfs_inode_t     *ip;
-       xfs_suminfo_t   *smp;
+       union xfs_suminfo_raw *smp;
        int             nmap;
        int             error;
        xfs_fileoff_t   bno;
@@ -671,6 +671,12 @@ fill_rsumino(xfs_mount_t *mp)
        }
 
        while (bno < end_bno)  {
+               struct xfs_rtalloc_args args = {
+                       .mp             = mp,
+                       .tp             = tp,
+               };
+               union xfs_suminfo_raw   *ondisk;
+
                /*
                 * fill the file one block at a time
                 */
@@ -697,11 +703,13 @@ _("can't access block %" PRIu64 " (fsbno %" PRIu64 ") of realtime summary inode
                        return(1);
                }
 
-               memmove(bp->b_addr, smp, mp->m_sb.sb_blocksize);
+               args.sumbp = bp;
+               ondisk = xfs_rsumblock_infoptr(&args, 0);
+               memcpy(ondisk, smp, mp->m_sb.sb_blocksize);
 
                libxfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1);
 
-               smp = (xfs_suminfo_t *)((intptr_t)smp + mp->m_sb.sb_blocksize);
+               smp += mp->m_blockwsize;
                bno++;
        }
 
index 6ab709a000cb565206ac47c266d97a031f329624..9aff5a0d3d58e57545e6f7a5c6bf95efaf2db8d5 100644 (file)
@@ -36,7 +36,7 @@ rtinit(xfs_mount_t *mp)
 
        wordcnt = libxfs_rtsummary_wordcount(mp, mp->m_rsumlevels,
                        mp->m_sb.sb_rbmblocks);
-       sumcompute = calloc(wordcnt, sizeof(xfs_suminfo_t));
+       sumcompute = calloc(wordcnt, sizeof(union xfs_suminfo_raw));
        if (!sumcompute)
                do_error(
        _("couldn't allocate memory for incore realtime summary info.\n"));
@@ -51,6 +51,17 @@ set_rtword(
        word->old = value;
 }
 
+static inline void
+inc_sumcount(
+       struct xfs_mount        *mp,
+       union xfs_suminfo_raw   *info,
+       xfs_rtsumoff_t          index)
+{
+       union xfs_suminfo_raw   *p = info + index;
+
+       p->old++;
+}
+
 /*
  * generate the real-time bitmap and summary info based on the
  * incore realtime extent map.
@@ -59,7 +70,7 @@ int
 generate_rtinfo(
        struct xfs_mount        *mp,
        union xfs_rtword_raw    *words,
-       xfs_suminfo_t           *sumcompute)
+       union xfs_suminfo_raw   *sumcompute)
 {
        xfs_rtxnum_t    extno;
        xfs_rtxnum_t    start_ext;
@@ -105,7 +116,7 @@ generate_rtinfo(
                                len = (int) (extno - start_ext);
                                log = XFS_RTBLOCKLOG(len);
                                offs = xfs_rtsumoffs(mp, log, start_bmbno);
-                               sumcompute[offs]++;
+                               inc_sumcount(mp, sumcompute, offs);
                                in_extent = 0;
                        }
 
@@ -121,7 +132,7 @@ generate_rtinfo(
                len = (int) (extno - start_ext);
                log = XFS_RTBLOCKLOG(len);
                offs = xfs_rtsumoffs(mp, log, start_bmbno);
-               sumcompute[offs]++;
+               inc_sumcount(mp, sumcompute, offs);
        }
 
        if (mp->m_sb.sb_frextents != sb_frextents) {
index 3f14393006869d7842f96bff7763f4fe396ec35b..862695487bcd4c3aa97a2260edde187ef6bb2f88 100644 (file)
@@ -12,7 +12,7 @@ void
 rtinit(xfs_mount_t             *mp);
 
 int generate_rtinfo(struct xfs_mount *mp, union xfs_rtword_raw *words,
-               xfs_suminfo_t *sumcompute);
+               union xfs_suminfo_raw *sumcompute);
 
 void check_rtbitmap(struct xfs_mount *mp);
 void check_rtsummary(struct xfs_mount *mp);