From: cem@kernel.org
To: linux-xfs@vger.kernel.org
Subject: [PATCH 20/35] xfs: convert rt summary macros to helpers
Date: Thu, 15 Feb 2024 13:08:32 +0100 [thread overview]
Message-ID: <20240215120907.1542854-21-cem@kernel.org> (raw)
In-Reply-To: <20240215120907.1542854-1-cem@kernel.org>
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 097b4b7b64ef67a4703b89fd4064480b61557fd5
Convert the realtime summary file macros to helper functions so that we
can improve type checking.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
db/check.c | 5 ++--
include/libxfs.h | 1 +
libxfs/xfs_format.h | 9 +-------
libxfs/xfs_rtbitmap.c | 10 ++++----
libxfs/xfs_rtbitmap.h | 53 +++++++++++++++++++++++++++++++++++++++++++
libxfs/xfs_types.h | 2 ++
repair/rt.c | 5 ++--
7 files changed, 69 insertions(+), 16 deletions(-)
diff --git a/db/check.c b/db/check.c
index fdf1f6a1e..9d5576c33 100644
--- a/db/check.c
+++ b/db/check.c
@@ -20,6 +20,7 @@
#include "init.h"
#include "malloc.h"
#include "dir2.h"
+#include "xfs_rtbitmap.h"
typedef enum {
IS_USER_QUOTA, IS_PROJECT_QUOTA, IS_GROUP_QUOTA,
@@ -3648,7 +3649,7 @@ process_rtbitmap(
len = ((int)bmbno - start_bmbno) *
bitsperblock + (bit - start_bit);
log = XFS_RTBLOCKLOG(len);
- offs = XFS_SUMOFFS(mp, log, start_bmbno);
+ offs = xfs_rtsumoffs(mp, log, start_bmbno);
sumcompute[offs]++;
prevbit = 0;
}
@@ -3661,7 +3662,7 @@ process_rtbitmap(
len = ((int)bmbno - start_bmbno) * bitsperblock +
(bit - start_bit);
log = XFS_RTBLOCKLOG(len);
- offs = XFS_SUMOFFS(mp, log, start_bmbno);
+ offs = xfs_rtsumoffs(mp, log, start_bmbno);
sumcompute[offs]++;
}
}
diff --git a/include/libxfs.h b/include/libxfs.h
index 486566391..9cec394ca 100644
--- a/include/libxfs.h
+++ b/include/libxfs.h
@@ -44,6 +44,7 @@ struct iomap;
#define __round_mask(x, y) ((__typeof__(x))((y)-1))
#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
#define unlikely(x) (x)
+#define likely(x) (x)
/*
* This mirrors the kernel include for xfs_buf.h - it's implicitly included in
diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h
index ac6dd1023..d48e3a395 100644
--- a/libxfs/xfs_format.h
+++ b/libxfs/xfs_format.h
@@ -1144,15 +1144,8 @@ static inline bool xfs_dinode_has_large_extent_counts(
#define XFS_BLOCKMASK(mp) ((mp)->m_blockmask)
/*
- * RT Summary and bit manipulation macros.
+ * RT bit manipulation macros.
*/
-#define XFS_SUMOFFS(mp,ls,bb) ((int)((ls) * (mp)->m_sb.sb_rbmblocks + (bb)))
-#define XFS_SUMOFFSTOBLOCK(mp,s) \
- (((s) * (uint)sizeof(xfs_suminfo_t)) >> (mp)->m_sb.sb_blocklog)
-#define XFS_SUMPTR(mp,bp,so) \
- ((xfs_suminfo_t *)((bp)->b_addr + \
- (((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
-
#define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b))
#define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b))
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index fce88c759..c635e8c2e 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -453,17 +453,18 @@ xfs_rtmodify_summary_int(
struct xfs_buf *bp; /* buffer for the summary block */
int error; /* error value */
xfs_fileoff_t sb; /* summary fsblock */
- int so; /* index into the summary file */
+ xfs_rtsumoff_t so; /* index into the summary file */
xfs_suminfo_t *sp; /* pointer to returned data */
+ unsigned int infoword;
/*
* Compute entry number in the summary file.
*/
- so = XFS_SUMOFFS(mp, log, bbno);
+ so = xfs_rtsumoffs(mp, log, bbno);
/*
* Compute the block number in the summary file.
*/
- sb = XFS_SUMOFFSTOBLOCK(mp, so);
+ sb = xfs_rtsumoffs_to_block(mp, so);
/*
* If we have an old buffer, and the block number matches, use that.
*/
@@ -491,7 +492,8 @@ xfs_rtmodify_summary_int(
/*
* Point to the summary information, modify/log it, and/or copy it out.
*/
- sp = XFS_SUMPTR(mp, bp, so);
+ infoword = xfs_rtsumoffs_to_infoword(mp, so);
+ sp = xfs_rsumblock_infoptr(bp, infoword);
if (delta) {
uint first = (uint)((char *)sp - (char *)bp->b_addr);
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 3252ed217..167ea6a08 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -6,6 +6,9 @@
#ifndef __XFS_RTBITMAP_H__
#define __XFS_RTBITMAP_H__
+/* For userspace XFS_RT is always defined */
+#define CONFIG_XFS_RT
+
static inline xfs_rtblock_t
xfs_rtx_to_rtb(
struct xfs_mount *mp,
@@ -169,6 +172,56 @@ xfs_rbmblock_wordptr(
return words + index;
}
+/*
+ * Convert a rt extent length and rt bitmap block number to a xfs_suminfo_t
+ * offset within the rt summary file.
+ */
+static inline xfs_rtsumoff_t
+xfs_rtsumoffs(
+ struct xfs_mount *mp,
+ int log2_len,
+ xfs_fileoff_t rbmoff)
+{
+ return log2_len * mp->m_sb.sb_rbmblocks + rbmoff;
+}
+
+/*
+ * Convert an xfs_suminfo_t offset to a file block offset within the rt summary
+ * file.
+ */
+static inline xfs_fileoff_t
+xfs_rtsumoffs_to_block(
+ struct xfs_mount *mp,
+ xfs_rtsumoff_t rsumoff)
+{
+ return XFS_B_TO_FSBT(mp, rsumoff * sizeof(xfs_suminfo_t));
+}
+
+/*
+ * Convert an xfs_suminfo_t offset to an info word offset within an rt summary
+ * block.
+ */
+static inline unsigned int
+xfs_rtsumoffs_to_infoword(
+ struct xfs_mount *mp,
+ xfs_rtsumoff_t rsumoff)
+{
+ unsigned int mask = mp->m_blockmask >> XFS_SUMINFOLOG;
+
+ return rsumoff & mask;
+}
+
+/* Return a pointer to a summary info word within a rt summary block. */
+static inline xfs_suminfo_t *
+xfs_rsumblock_infoptr(
+ struct xfs_buf *bp,
+ unsigned int index)
+{
+ xfs_suminfo_t *info = bp->b_addr;
+
+ return info + index;
+}
+
/*
* Functions for walking free space rtextents in the realtime bitmap.
*/
diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h
index c78237852..533200c4c 100644
--- a/libxfs/xfs_types.h
+++ b/libxfs/xfs_types.h
@@ -19,6 +19,7 @@ typedef int64_t xfs_fsize_t; /* bytes in a file */
typedef uint64_t xfs_ufsize_t; /* unsigned bytes in a file */
typedef int32_t xfs_suminfo_t; /* type of bitmap summary info */
+typedef uint32_t xfs_rtsumoff_t; /* offset of an rtsummary info word */
typedef uint32_t xfs_rtword_t; /* word type for bitmap manipulations */
typedef int64_t xfs_lsn_t; /* log sequence number */
@@ -149,6 +150,7 @@ typedef uint32_t xfs_dqid_t;
*/
#define XFS_NBBYLOG 3 /* log2(NBBY) */
#define XFS_WORDLOG 2 /* log2(sizeof(xfs_rtword_t)) */
+#define XFS_SUMINFOLOG 2 /* log2(sizeof(xfs_suminfo_t)) */
#define XFS_NBWORDLOG (XFS_NBBYLOG + XFS_WORDLOG)
#define XFS_NBWORD (1 << XFS_NBWORDLOG)
#define XFS_WORDMASK ((1 << XFS_WORDLOG) - 1)
diff --git a/repair/rt.c b/repair/rt.c
index a4cca7aa2..abe58b569 100644
--- a/repair/rt.c
+++ b/repair/rt.c
@@ -13,6 +13,7 @@
#include "protos.h"
#include "err_protos.h"
#include "rt.h"
+#include "xfs_rtbitmap.h"
#define xfs_highbit64 libxfs_highbit64 /* for XFS_RTBLOCKLOG macro */
@@ -91,7 +92,7 @@ generate_rtinfo(xfs_mount_t *mp,
} else if (in_extent == 1) {
len = (int) (extno - start_ext);
log = XFS_RTBLOCKLOG(len);
- offs = XFS_SUMOFFS(mp, log, start_bmbno);
+ offs = xfs_rtsumoffs(mp, log, start_bmbno);
sumcompute[offs]++;
in_extent = 0;
}
@@ -107,7 +108,7 @@ generate_rtinfo(xfs_mount_t *mp,
if (in_extent == 1) {
len = (int) (extno - start_ext);
log = XFS_RTBLOCKLOG(len);
- offs = XFS_SUMOFFS(mp, log, start_bmbno);
+ offs = xfs_rtsumoffs(mp, log, start_bmbno);
sumcompute[offs]++;
}
--
2.43.0
next prev parent reply other threads:[~2024-02-15 12:09 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
2024-02-15 12:08 ` [PATCH 01/35] xfs: bump max fsgeom struct version cem
2024-02-15 12:08 ` [PATCH 02/35] xfs: hoist freeing of rt data fork extent mappings cem
2024-02-15 12:08 ` [PATCH 03/35] xfs: fix units conversion error in xfs_bmap_del_extent_delay cem
2024-02-15 12:08 ` [PATCH 04/35] xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h cem
2024-02-15 12:08 ` [PATCH 05/35] xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator cem
2024-02-15 12:08 ` [PATCH 06/35] xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t cem
2024-02-15 12:08 ` [PATCH 07/35] xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t cem
2024-02-15 12:08 ` [PATCH 08/35] xfs: rename xfs_verify_rtext to xfs_verify_rtbext cem
2024-02-15 12:08 ` [PATCH 09/35] xfs: convert rt extent numbers to xfs_rtxnum_t cem
2024-02-15 12:08 ` [PATCH 10/35] xfs: create a helper to convert rtextents to rtblocks cem
2024-02-15 12:08 ` [PATCH 11/35] xfs: create a helper to compute leftovers of realtime extents cem
2024-02-15 12:08 ` [PATCH 12/35] xfs: create a helper to convert extlen to rtextlen cem
2024-02-15 12:08 ` [PATCH 13/35] xfs: create helpers to convert rt block numbers to rt extent numbers cem
2024-02-15 12:08 ` [PATCH 14/35] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls cem
2024-02-15 12:08 ` [PATCH 15/35] xfs: create rt extent rounding helpers for realtime extent blocks cem
2024-02-15 12:08 ` [PATCH 16/35] xfs: use shifting and masking when converting rt extents, if possible cem
2024-02-15 12:08 ` [PATCH 17/35] xfs: convert the rtbitmap block and bit macros to static inline functions cem
2024-02-15 12:08 ` [PATCH 18/35] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros cem
2024-02-15 12:08 ` [PATCH 19/35] xfs: convert open-coded xfs_rtword_t pointer accesses to helper cem
2024-02-15 12:08 ` cem [this message]
2024-02-15 12:08 ` [PATCH 21/35] xfs: convert to new timestamp accessors cem
2024-02-15 12:08 ` [PATCH 22/35] xfs: create helpers for rtbitmap block/wordcount computations cem
2024-02-15 12:08 ` [PATCH 23/35] xfs: create a helper to handle logging parts of rt bitmap/summary blocks cem
2024-02-15 12:08 ` [PATCH 24/35] xfs: use accessor functions for bitmap words cem
2024-02-15 12:08 ` [PATCH 25/35] xfs: create helpers for rtsummary block/wordcount computations cem
2024-02-15 12:08 ` [PATCH 26/35] xfs: use accessor functions for summary info words cem
2024-02-15 12:08 ` [PATCH 27/35] xfs: consolidate realtime allocation arguments cem
2024-02-15 12:08 ` [PATCH 28/35] xfs: cache last bitmap block in realtime allocator cem
2024-02-15 12:08 ` [PATCH 29/35] xfs: simplify xfs_rtbuf_get calling conventions cem
2024-02-15 12:08 ` [PATCH 30/35] xfs: simplify rt bitmap/summary block accessor functions cem
2024-02-15 12:08 ` [PATCH 31/35] xfs: invert the realtime summary cache cem
2024-02-15 12:08 ` [PATCH 32/35] xfs: factor out xfs_defer_pending_abort cem
2024-02-15 12:08 ` [PATCH 33/35] xfs: abort intent items when recovery intents fail cem
2024-02-15 12:08 ` [PATCH 34/35] xfs: fix internal error from AGFL exhaustion cem
2024-02-15 12:08 ` [PATCH 35/35] xfs: inode recovery does not validate the recovered inode cem
2024-02-16 7:11 ` [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240215120907.1542854-21-cem@kernel.org \
--to=cem@kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox