]> git.apps.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
xfs_{db,repair}: use accessor functions for bitmap 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 rtbitmap
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 rtbitmap words so that the compiler can perform proper
typechecking as we go back and forth.

In the upcoming rtgroups feature, we're going to fix the problem that
rtwords are written in host endian order, which means we'll need the
distinct rtword/rtword_raw types.

Suggested-by: Christoph Hellwig <hch@lst.de>
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 a8f6310fcd25823bc7155fb5e67109e7bbc4fc01..3b3f90e5e0c9219eee545b587596b779b9165db4 100644 (file)
@@ -3606,12 +3606,20 @@ process_rtbitmap(
        xfs_rtword_t    *words;
 
        bitsperblock = mp->m_sb.sb_blocksize * NBBY;
+       words = malloc(mp->m_blockwsize << XFS_WORDLOG);
+       if (!words) {
+               dbprintf(_("could not allocate rtwords buffer\n"));
+               error++;
+               return;
+       }
        bit = extno = prevbit = start_bmbno = start_bit = 0;
        bmbno = NULLFILEOFF;
        while ((bmbno = blkmap_next_off(blkmap, bmbno, &t)) != NULLFILEOFF) {
                struct xfs_rtalloc_args args = {
                        .mp             = mp,
                };
+               xfs_rtword_t    *incore = words;
+               unsigned int    i;
 
                bno = blkmap_get(blkmap, bmbno);
                if (bno == NULLFSBLOCK) {
@@ -3636,7 +3644,9 @@ process_rtbitmap(
                }
 
                args.rbmbp = iocur_top->bp;
-               words = (xfs_rtword_t *)xfs_rbmblock_wordptr(&args, 0);
+               for (i = 0; i < mp->m_blockwsize; i++, incore++)
+                       *incore = libxfs_rtbitmap_getword(&args, i);
+
                for (bit = 0;
                     bit < bitsperblock && extno < mp->m_sb.sb_rextents;
                     bit++, extno++) {
@@ -3670,6 +3680,7 @@ process_rtbitmap(
                offs = xfs_rtsumoffs(mp, log, start_bmbno);
                sumcompute[offs]++;
        }
+       free(words);
 }
 
 static void
index 5180da2fcea6ef43b21287b718216835d45e280c..feecc05c4ecc20901402b9b053034dd76856d092 100644 (file)
 #define xfs_rmap_lookup_le_range       libxfs_rmap_lookup_le_range
 #define xfs_rmap_query_range           libxfs_rmap_query_range
 
+#define xfs_rtbitmap_getword           libxfs_rtbitmap_getword
+#define xfs_rtbitmap_setword           libxfs_rtbitmap_setword
 #define xfs_rtbitmap_wordcount         libxfs_rtbitmap_wordcount
 
 #define xfs_rtfree_extent              libxfs_rtfree_extent
index c40849853b8f1d20d4e9151b4ea568167c35134e..73ae9de075de3cec33442a92c43a4cda082d11f2 100644 (file)
@@ -86,7 +86,7 @@ int64_t               fs_max_file_offset;
 
 /* realtime info */
 
-xfs_rtword_t   *btmcompute;
+union xfs_rtword_raw   *btmcompute;
 xfs_suminfo_t  *sumcompute;
 
 /* inode tree records have full or partial backptr fields ? */
index 89f1b0e078f30356337e262f76bc0d4e7b9b1da1..311cf72189f3ebb0d19af7458da6fef6e642f3fc 100644 (file)
@@ -127,7 +127,7 @@ extern int64_t              fs_max_file_offset;
 
 /* realtime info */
 
-extern xfs_rtword_t    *btmcompute;
+extern union xfs_rtword_raw            *btmcompute;
 extern xfs_suminfo_t   *sumcompute;
 
 /* inode tree records have full or partial backptr fields ? */
index 7b2044fd1dbbe0b703e22f31a1b74423b96b9e51..884b7c1ac2b5dbb984d7e48f022758adffde6cd9 100644 (file)
@@ -572,7 +572,7 @@ fill_rbmino(xfs_mount_t *mp)
        struct xfs_buf  *bp;
        xfs_trans_t     *tp;
        xfs_inode_t     *ip;
-       xfs_rtword_t    *bmp;
+       union xfs_rtword_raw    *bmp;
        int             nmap;
        int             error;
        xfs_fileoff_t   bno;
index 244b59f04ce5b8e518d7b9afd25be2a15bb47f41..213f0812250e2203e3b3bb37cc1aeb10c95285cc 100644 (file)
@@ -29,7 +29,7 @@ rtinit(xfs_mount_t *mp)
         * handled by incore_init()
         */
        wordcnt = libxfs_rtbitmap_wordcount(mp, mp->m_sb.sb_rextents);
-       btmcompute = calloc(wordcnt, sizeof(xfs_rtword_t));
+       btmcompute = calloc(wordcnt, sizeof(union xfs_rtword_raw));
        if (!btmcompute)
                do_error(
        _("couldn't allocate memory for incore realtime bitmap.\n"));
@@ -39,14 +39,24 @@ rtinit(xfs_mount_t *mp)
        _("couldn't allocate memory for incore realtime summary info.\n"));
 }
 
+static inline void
+set_rtword(
+       struct xfs_mount        *mp,
+       union xfs_rtword_raw    *word,
+       xfs_rtword_t            value)
+{
+       word->old = value;
+}
+
 /*
  * generate the real-time bitmap and summary info based on the
  * incore realtime extent map.
  */
 int
-generate_rtinfo(xfs_mount_t    *mp,
-               xfs_rtword_t    *words,
-               xfs_suminfo_t   *sumcompute)
+generate_rtinfo(
+       struct xfs_mount        *mp,
+       union xfs_rtword_raw    *words,
+       xfs_suminfo_t           *sumcompute)
 {
        xfs_rtxnum_t    extno;
        xfs_rtxnum_t    start_ext;
@@ -75,7 +85,7 @@ generate_rtinfo(xfs_mount_t   *mp,
         */
        while (extno < mp->m_sb.sb_rextents)  {
                freebit = 1;
-               *words = 0;
+               set_rtword(mp, words, 0);
                bits = 0;
                for (i = 0; i < sizeof(xfs_rtword_t) * NBBY &&
                                extno < mp->m_sb.sb_rextents; i++, extno++)  {
@@ -98,7 +108,7 @@ generate_rtinfo(xfs_mount_t  *mp,
 
                        freebit <<= 1;
                }
-               *words = bits;
+               set_rtword(mp, words, bits);
                words++;
 
                if (extno % bitsperblock == 0)
index be24e91c95ecd3262db9860e04bd9bf808214adf..3f14393006869d7842f96bff7763f4fe396ec35b 100644 (file)
@@ -11,10 +11,8 @@ struct blkmap;
 void
 rtinit(xfs_mount_t             *mp);
 
-int
-generate_rtinfo(xfs_mount_t    *mp,
-               xfs_rtword_t    *words,
-               xfs_suminfo_t   *sumcompute);
+int generate_rtinfo(struct xfs_mount *mp, union xfs_rtword_raw *words,
+               xfs_suminfo_t *sumcompute);
 
 void check_rtbitmap(struct xfs_mount *mp);
 void check_rtsummary(struct xfs_mount *mp);