Commit 830b4abf authored by Chandan Babu R's avatar Chandan Babu R

Merge tag 'refactor-rtbitmap-accessors-6.7_2023-10-19' of...

Merge tag 'refactor-rtbitmap-accessors-6.7_2023-10-19' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.7-mergeA

xfs: refactor rtbitmap/summary accessors [v1.2]

Since the rtbitmap and rtsummary accessor functions have proven more
controversial than the rest of the macro refactoring, split the patchset
into two to make review easier.

v1.1: various cleanups suggested by hch
v1.2: rework the accessor functions to reduce the amount of cursor
      tracking required, and create explicit bitmap/summary logging
      functions

With a bit of luck, this should all go splendidly.
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarChandan Babu R <chandanbabu@kernel.org>

* tag 'refactor-rtbitmap-accessors-6.7_2023-10-19' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: use accessor functions for summary info words
  xfs: create helpers for rtsummary block/wordcount computations
  xfs: use accessor functions for bitmap words
  xfs: create a helper to handle logging parts of rt bitmap/summary blocks
parents 035e32f7 663b8db7
...@@ -690,6 +690,22 @@ struct xfs_agfl { ...@@ -690,6 +690,22 @@ struct xfs_agfl {
ASSERT(xfs_daddr_to_agno(mp, d) == \ ASSERT(xfs_daddr_to_agno(mp, d) == \
xfs_daddr_to_agno(mp, (d) + (len) - 1))) xfs_daddr_to_agno(mp, (d) + (len) - 1)))
/*
* Realtime bitmap information is accessed by the word, which is currently
* stored in host-endian format.
*/
union xfs_rtword_raw {
__u32 old;
};
/*
* Realtime summary counts are accessed by the word, which is currently
* stored in host-endian format.
*/
union xfs_suminfo_raw {
__u32 old;
};
/* /*
* XFS Timestamps * XFS Timestamps
* ============== * ==============
......
This diff is collapsed.
...@@ -159,16 +159,39 @@ xfs_rbmblock_to_rtx( ...@@ -159,16 +159,39 @@ xfs_rbmblock_to_rtx(
} }
/* Return a pointer to a bitmap word within a rt bitmap block. */ /* Return a pointer to a bitmap word within a rt bitmap block. */
static inline xfs_rtword_t * static inline union xfs_rtword_raw *
xfs_rbmblock_wordptr( xfs_rbmblock_wordptr(
struct xfs_buf *bp, struct xfs_buf *bp,
unsigned int index) unsigned int index)
{ {
xfs_rtword_t *words = bp->b_addr; union xfs_rtword_raw *words = bp->b_addr;
return words + index; return words + index;
} }
/* Convert an ondisk bitmap word to its incore representation. */
static inline xfs_rtword_t
xfs_rtbitmap_getword(
struct xfs_buf *bp,
unsigned int index)
{
union xfs_rtword_raw *word = xfs_rbmblock_wordptr(bp, index);
return word->old;
}
/* Set an ondisk bitmap word from an incore representation. */
static inline void
xfs_rtbitmap_setword(
struct xfs_buf *bp,
unsigned int index,
xfs_rtword_t value)
{
union xfs_rtword_raw *word = xfs_rbmblock_wordptr(bp, index);
word->old = value;
}
/* /*
* Convert a rt extent length and rt bitmap block number to a xfs_suminfo_t * Convert a rt extent length and rt bitmap block number to a xfs_suminfo_t
* offset within the rt summary file. * offset within the rt summary file.
...@@ -209,16 +232,40 @@ xfs_rtsumoffs_to_infoword( ...@@ -209,16 +232,40 @@ xfs_rtsumoffs_to_infoword(
} }
/* Return a pointer to a summary info word within a rt summary block. */ /* Return a pointer to a summary info word within a rt summary block. */
static inline xfs_suminfo_t * static inline union xfs_suminfo_raw *
xfs_rsumblock_infoptr( xfs_rsumblock_infoptr(
struct xfs_buf *bp, struct xfs_buf *bp,
unsigned int index) unsigned int index)
{ {
xfs_suminfo_t *info = bp->b_addr; union xfs_suminfo_raw *info = bp->b_addr;
return info + index; return info + index;
} }
/* Get the current value of a summary counter. */
static inline xfs_suminfo_t
xfs_suminfo_get(
struct xfs_buf *bp,
unsigned int index)
{
union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(bp, index);
return info->old;
}
/* Add to the current value of a summary counter and return the new value. */
static inline xfs_suminfo_t
xfs_suminfo_add(
struct xfs_buf *bp,
unsigned int index,
int delta)
{
union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(bp, index);
info->old += delta;
return info->old;
}
/* /*
* Functions for walking free space rtextents in the realtime bitmap. * Functions for walking free space rtextents in the realtime bitmap.
*/ */
...@@ -285,6 +332,11 @@ xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t ...@@ -285,6 +332,11 @@ xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t
rtextents); rtextents);
unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp, unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp,
xfs_rtbxlen_t rtextents); xfs_rtbxlen_t rtextents);
xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp,
unsigned int rsumlevels, xfs_extlen_t rbmblocks);
unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp,
unsigned int rsumlevels, xfs_extlen_t rbmblocks);
#else /* CONFIG_XFS_RT */ #else /* CONFIG_XFS_RT */
# define xfs_rtfree_extent(t,b,l) (-ENOSYS) # define xfs_rtfree_extent(t,b,l) (-ENOSYS)
# define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS) # define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS)
...@@ -299,6 +351,8 @@ xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents) ...@@ -299,6 +351,8 @@ xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
return 0; return 0;
} }
# define xfs_rtbitmap_wordcount(mp, r) (0) # define xfs_rtbitmap_wordcount(mp, r) (0)
# define xfs_rtsummary_blockcount(mp, l, b) (0)
# define xfs_rtsummary_wordcount(mp, l, b) (0)
#endif /* CONFIG_XFS_RT */ #endif /* CONFIG_XFS_RT */
#endif /* __XFS_RTBITMAP_H__ */ #endif /* __XFS_RTBITMAP_H__ */
...@@ -82,9 +82,10 @@ static inline int ...@@ -82,9 +82,10 @@ static inline int
xfsum_load( xfsum_load(
struct xfs_scrub *sc, struct xfs_scrub *sc,
xfs_rtsumoff_t sumoff, xfs_rtsumoff_t sumoff,
xfs_suminfo_t *info) union xfs_suminfo_raw *rawinfo)
{ {
return xfile_obj_load(sc->xfile, info, sizeof(xfs_suminfo_t), return xfile_obj_load(sc->xfile, rawinfo,
sizeof(union xfs_suminfo_raw),
sumoff << XFS_WORDLOG); sumoff << XFS_WORDLOG);
} }
...@@ -92,9 +93,10 @@ static inline int ...@@ -92,9 +93,10 @@ static inline int
xfsum_store( xfsum_store(
struct xfs_scrub *sc, struct xfs_scrub *sc,
xfs_rtsumoff_t sumoff, xfs_rtsumoff_t sumoff,
const xfs_suminfo_t info) const union xfs_suminfo_raw rawinfo)
{ {
return xfile_obj_store(sc->xfile, &info, sizeof(xfs_suminfo_t), return xfile_obj_store(sc->xfile, &rawinfo,
sizeof(union xfs_suminfo_raw),
sumoff << XFS_WORDLOG); sumoff << XFS_WORDLOG);
} }
...@@ -102,13 +104,22 @@ static inline int ...@@ -102,13 +104,22 @@ static inline int
xfsum_copyout( xfsum_copyout(
struct xfs_scrub *sc, struct xfs_scrub *sc,
xfs_rtsumoff_t sumoff, xfs_rtsumoff_t sumoff,
xfs_suminfo_t *info, union xfs_suminfo_raw *rawinfo,
unsigned int nr_words) unsigned int nr_words)
{ {
return xfile_obj_load(sc->xfile, info, nr_words << XFS_WORDLOG, return xfile_obj_load(sc->xfile, rawinfo, nr_words << XFS_WORDLOG,
sumoff << XFS_WORDLOG); sumoff << XFS_WORDLOG);
} }
static inline xfs_suminfo_t
xchk_rtsum_inc(
struct xfs_mount *mp,
union xfs_suminfo_raw *v)
{
v->old += 1;
return v->old;
}
/* Update the summary file to reflect the free extent that we've accumulated. */ /* Update the summary file to reflect the free extent that we've accumulated. */
STATIC int STATIC int
xchk_rtsum_record_free( xchk_rtsum_record_free(
...@@ -123,7 +134,8 @@ xchk_rtsum_record_free( ...@@ -123,7 +134,8 @@ xchk_rtsum_record_free(
xfs_filblks_t rtlen; xfs_filblks_t rtlen;
xfs_rtsumoff_t offs; xfs_rtsumoff_t offs;
unsigned int lenlog; unsigned int lenlog;
xfs_suminfo_t v = 0; union xfs_suminfo_raw v;
xfs_suminfo_t value;
int error = 0; int error = 0;
if (xchk_should_terminate(sc, &error)) if (xchk_should_terminate(sc, &error))
...@@ -147,9 +159,9 @@ xchk_rtsum_record_free( ...@@ -147,9 +159,9 @@ xchk_rtsum_record_free(
if (error) if (error)
return error; return error;
v++; value = xchk_rtsum_inc(sc->mp, &v);
trace_xchk_rtsum_record_free(mp, rec->ar_startext, rec->ar_extcount, trace_xchk_rtsum_record_free(mp, rec->ar_startext, rec->ar_extcount,
lenlog, offs, v); lenlog, offs, value);
return xfsum_store(sc, offs, v); return xfsum_store(sc, offs, v);
} }
...@@ -184,7 +196,7 @@ xchk_rtsum_compare( ...@@ -184,7 +196,7 @@ xchk_rtsum_compare(
int nmap; int nmap;
for (off = 0; off < XFS_B_TO_FSB(mp, mp->m_rsumsize); off++) { for (off = 0; off < XFS_B_TO_FSB(mp, mp->m_rsumsize); off++) {
xfs_suminfo_t *ondisk_info; union xfs_suminfo_raw *ondisk_info;
int error = 0; int error = 0;
if (xchk_should_terminate(sc, &error)) if (xchk_should_terminate(sc, &error))
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "xfs_inode.h" #include "xfs_inode.h"
#include "xfs_btree.h" #include "xfs_btree.h"
#include "xfs_ag.h" #include "xfs_ag.h"
#include "xfs_rtbitmap.h"
#include "scrub/scrub.h" #include "scrub/scrub.h"
#include "scrub/xfile.h" #include "scrub/xfile.h"
#include "scrub/xfarray.h" #include "scrub/xfarray.h"
......
...@@ -1038,8 +1038,8 @@ TRACE_EVENT(xfarray_sort_stats, ...@@ -1038,8 +1038,8 @@ TRACE_EVENT(xfarray_sort_stats,
TRACE_EVENT(xchk_rtsum_record_free, TRACE_EVENT(xchk_rtsum_record_free,
TP_PROTO(struct xfs_mount *mp, xfs_rtxnum_t start, TP_PROTO(struct xfs_mount *mp, xfs_rtxnum_t start,
xfs_rtbxlen_t len, unsigned int log, loff_t pos, xfs_rtbxlen_t len, unsigned int log, loff_t pos,
xfs_suminfo_t v), xfs_suminfo_t value),
TP_ARGS(mp, start, len, log, pos, v), TP_ARGS(mp, start, len, log, pos, value),
TP_STRUCT__entry( TP_STRUCT__entry(
__field(dev_t, dev) __field(dev_t, dev)
__field(dev_t, rtdev) __field(dev_t, rtdev)
...@@ -1047,7 +1047,7 @@ TRACE_EVENT(xchk_rtsum_record_free, ...@@ -1047,7 +1047,7 @@ TRACE_EVENT(xchk_rtsum_record_free,
__field(unsigned long long, len) __field(unsigned long long, len)
__field(unsigned int, log) __field(unsigned int, log)
__field(loff_t, pos) __field(loff_t, pos)
__field(xfs_suminfo_t, v) __field(xfs_suminfo_t, value)
), ),
TP_fast_assign( TP_fast_assign(
__entry->dev = mp->m_super->s_dev; __entry->dev = mp->m_super->s_dev;
...@@ -1056,7 +1056,7 @@ TRACE_EVENT(xchk_rtsum_record_free, ...@@ -1056,7 +1056,7 @@ TRACE_EVENT(xchk_rtsum_record_free,
__entry->len = len; __entry->len = len;
__entry->log = log; __entry->log = log;
__entry->pos = pos; __entry->pos = pos;
__entry->v = v; __entry->value = value;
), ),
TP_printk("dev %d:%d rtdev %d:%d rtx 0x%llx rtxcount 0x%llx log %u rsumpos 0x%llx sumcount %u", TP_printk("dev %d:%d rtdev %d:%d rtx 0x%llx rtxcount 0x%llx log %u rsumpos 0x%llx sumcount %u",
MAJOR(__entry->dev), MINOR(__entry->dev), MAJOR(__entry->dev), MINOR(__entry->dev),
...@@ -1065,7 +1065,7 @@ TRACE_EVENT(xchk_rtsum_record_free, ...@@ -1065,7 +1065,7 @@ TRACE_EVENT(xchk_rtsum_record_free,
__entry->len, __entry->len,
__entry->log, __entry->log,
__entry->pos, __entry->pos,
__entry->v) __entry->value)
); );
#endif /* CONFIG_XFS_RT */ #endif /* CONFIG_XFS_RT */
......
...@@ -72,6 +72,10 @@ xfs_check_ondisk_structs(void) ...@@ -72,6 +72,10 @@ xfs_check_ondisk_structs(void)
XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_map_t, 4); XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_map_t, 4);
XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_name_local_t, 4); XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_name_local_t, 4);
/* realtime structures */
XFS_CHECK_STRUCT_SIZE(union xfs_rtword_raw, 4);
XFS_CHECK_STRUCT_SIZE(union xfs_suminfo_raw, 4);
/* /*
* m68k has problems with xfs_attr_leaf_name_remote_t, but we pad it to * m68k has problems with xfs_attr_leaf_name_remote_t, but we pad it to
* 4 bytes anyway so it's not obviously a problem. Hence for the moment * 4 bytes anyway so it's not obviously a problem. Hence for the moment
......
...@@ -1001,8 +1001,7 @@ xfs_growfs_rt( ...@@ -1001,8 +1001,7 @@ xfs_growfs_rt(
nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents); nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents);
nrextslog = xfs_highbit32(nrextents); nrextslog = xfs_highbit32(nrextents);
nrsumlevels = nrextslog + 1; nrsumlevels = nrextslog + 1;
nrsumsize = (uint)sizeof(xfs_suminfo_t) * nrsumlevels * nrbmblocks; nrsumblocks = xfs_rtsummary_blockcount(mp, nrsumlevels, nrbmblocks);
nrsumblocks = XFS_B_TO_FSB(mp, nrsumsize);
nrsumsize = XFS_FSB_TO_B(mp, nrsumblocks); nrsumsize = XFS_FSB_TO_B(mp, nrsumblocks);
/* /*
* New summary size can't be more than half the size of * New summary size can't be more than half the size of
...@@ -1063,10 +1062,8 @@ xfs_growfs_rt( ...@@ -1063,10 +1062,8 @@ xfs_growfs_rt(
ASSERT(nsbp->sb_rextents != 0); ASSERT(nsbp->sb_rextents != 0);
nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents); nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents);
nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1; nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1;
nrsumsize = nrsumblocks = xfs_rtsummary_blockcount(mp, nrsumlevels,
(uint)sizeof(xfs_suminfo_t) * nrsumlevels * nsbp->sb_rbmblocks);
nsbp->sb_rbmblocks;
nrsumblocks = XFS_B_TO_FSB(mp, nrsumsize);
nmp->m_rsumsize = nrsumsize = XFS_FSB_TO_B(mp, nrsumblocks); nmp->m_rsumsize = nrsumsize = XFS_FSB_TO_B(mp, nrsumblocks);
/* /*
* Start a transaction, get the log reservation. * Start a transaction, get the log reservation.
...@@ -1272,6 +1269,7 @@ xfs_rtmount_init( ...@@ -1272,6 +1269,7 @@ xfs_rtmount_init(
struct xfs_buf *bp; /* buffer for last block of subvolume */ struct xfs_buf *bp; /* buffer for last block of subvolume */
struct xfs_sb *sbp; /* filesystem superblock copy in mount */ struct xfs_sb *sbp; /* filesystem superblock copy in mount */
xfs_daddr_t d; /* address of last block of subvolume */ xfs_daddr_t d; /* address of last block of subvolume */
unsigned int rsumblocks;
int error; int error;
sbp = &mp->m_sb; sbp = &mp->m_sb;
...@@ -1283,10 +1281,9 @@ xfs_rtmount_init( ...@@ -1283,10 +1281,9 @@ xfs_rtmount_init(
return -ENODEV; return -ENODEV;
} }
mp->m_rsumlevels = sbp->sb_rextslog + 1; mp->m_rsumlevels = sbp->sb_rextslog + 1;
mp->m_rsumsize = rsumblocks = xfs_rtsummary_blockcount(mp, mp->m_rsumlevels,
(uint)sizeof(xfs_suminfo_t) * mp->m_rsumlevels * mp->m_sb.sb_rbmblocks);
sbp->sb_rbmblocks; mp->m_rsumsize = XFS_FSB_TO_B(mp, rsumblocks);
mp->m_rsumsize = roundup(mp->m_rsumsize, sbp->sb_blocksize);
mp->m_rbmip = mp->m_rsumip = NULL; mp->m_rbmip = mp->m_rsumip = NULL;
/* /*
* Check that the realtime section is an ok size. * Check that the realtime section is an ok size.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment