* [PATCH 00/35] xfsprogs: libxfs-sync for 6.7
@ 2024-02-15 12:08 cem
2024-02-15 12:08 ` [PATCH 01/35] xfs: bump max fsgeom struct version cem
` (35 more replies)
0 siblings, 36 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: Carlos Maiolino <cem@kernel.org>
Hello folks,
this is the libxfs-sync for 6.7. I know we don't use to publish the results on
the list, but this release's sync was a bit more complicated, so, if you can
spare a few minutes, I'd appreciate an extra pair of eyes on top of it.
Also I thinkg it's a good idea to publish the patches here before pushing them
to for-next.
You can also pull the patches directly from my repository:
git@gitolite.kernel.org:pub/scm/linux/kernel/git/cem/xfsprogs-dev.git libxfs-sync-6.7
The sync is under testing now, so far nothing has been found, but it's still
going.
Darrick J. Wong (27):
xfs: bump max fsgeom struct version
xfs: hoist freeing of rt data fork extent mappings
xfs: fix units conversion error in xfs_bmap_del_extent_delay
xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h
xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator
xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t
xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t
xfs: rename xfs_verify_rtext to xfs_verify_rtbext
xfs: convert rt extent numbers to xfs_rtxnum_t
xfs: create a helper to convert rtextents to rtblocks
xfs: create a helper to compute leftovers of realtime extents
xfs: create a helper to convert extlen to rtextlen
xfs: create helpers to convert rt block numbers to rt extent numbers
xfs: convert do_div calls to xfs_rtb_to_rtx helper calls
xfs: create rt extent rounding helpers for realtime extent blocks
xfs: use shifting and masking when converting rt extents, if possible
xfs: convert the rtbitmap block and bit macros to static inline
functions
xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros
xfs: convert open-coded xfs_rtword_t pointer accesses to helper
xfs: convert rt summary macros to helpers
xfs: create helpers for rtbitmap block/wordcount computations
xfs: create a helper to handle logging parts of rt bitmap/summary
blocks
xfs: use accessor functions for bitmap words
xfs: create helpers for rtsummary block/wordcount computations
xfs: use accessor functions for summary info words
xfs: simplify xfs_rtbuf_get calling conventions
xfs: simplify rt bitmap/summary block accessor functions
Dave Chinner (2):
xfs: consolidate realtime allocation arguments
xfs: inode recovery does not validate the recovered inode
Jeff Layton (1):
xfs: convert to new timestamp accessors
Long Li (2):
xfs: factor out xfs_defer_pending_abort
xfs: abort intent items when recovery intents fail
Omar Sandoval (3):
xfs: cache last bitmap block in realtime allocator
xfs: invert the realtime summary cache
xfs: fix internal error from AGFL exhaustion
db/check.c | 5 +-
include/libxfs.h | 1 +
include/xfs_inode.h | 74 +++-
include/xfs_mount.h | 2 +
libxfs/libxfs_api_defs.h | 1 +
libxfs/libxfs_priv.h | 79 ++--
libxfs/util.c | 2 +-
libxfs/xfs_alloc.c | 27 +-
libxfs/xfs_bmap.c | 44 +--
libxfs/xfs_defer.c | 28 +-
libxfs/xfs_defer.h | 2 +-
libxfs/xfs_format.h | 34 +-
libxfs/xfs_inode_buf.c | 13 +-
libxfs/xfs_rtbitmap.c | 809 +++++++++++++++++++++------------------
libxfs/xfs_rtbitmap.h | 386 +++++++++++++++++++
libxfs/xfs_sb.c | 2 +
libxfs/xfs_sb.h | 2 +-
libxfs/xfs_trans_inode.c | 2 +-
libxfs/xfs_trans_resv.c | 10 +-
libxfs/xfs_types.c | 4 +-
libxfs/xfs_types.h | 10 +-
mkfs/proto.c | 2 +-
repair/rt.c | 5 +-
23 files changed, 1043 insertions(+), 501 deletions(-)
create mode 100644 libxfs/xfs_rtbitmap.h
Carlos
--
2.43.0
^ permalink raw reply [flat|nested] 37+ messages in thread
* [PATCH 01/35] xfs: bump max fsgeom struct version
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 02/35] xfs: hoist freeing of rt data fork extent mappings cem
` (34 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 9488062805943c2d63350d3ef9e4dc093799789a
The latest version of the fs geometry structure is v5. Bump this
constant so that xfs_db and mkfs calls to libxfs_fs_geometry will fill
out all the fields.
IOWs, this commit is a no-op for the kernel, but will be useful for
userspace reporting in later changes.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_sb.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libxfs/xfs_sb.h b/libxfs/xfs_sb.h
index a5e14740e..19134b23c 100644
--- a/libxfs/xfs_sb.h
+++ b/libxfs/xfs_sb.h
@@ -25,7 +25,7 @@ extern uint64_t xfs_sb_version_to_features(struct xfs_sb *sbp);
extern int xfs_update_secondary_sbs(struct xfs_mount *mp);
-#define XFS_FS_GEOM_MAX_STRUCT_VER (4)
+#define XFS_FS_GEOM_MAX_STRUCT_VER (5)
extern void xfs_fs_geometry(struct xfs_mount *mp, struct xfs_fsop_geom *geo,
int struct_version);
extern int xfs_sb_read_secondary(struct xfs_mount *mp,
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 02/35] xfs: hoist freeing of rt data fork extent mappings
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 ` cem
2024-02-15 12:08 ` [PATCH 03/35] xfs: fix units conversion error in xfs_bmap_del_extent_delay cem
` (33 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 6c664484337b37fa0cf6e958f4019623e30d40f7
Currently, xfs_bmap_del_extent_real contains a bunch of code to convert
the physical extent of a data fork mapping for a realtime file into rt
extents and pass that to the rt extent freeing function. Since the
details of this aren't needed when CONFIG_XFS_REALTIME=n, move it to
xfs_rtbitmap.c to reduce code size when realtime isn't enabled.
This will (one day) enable realtime EFIs to reuse the same
unit-converting call with less code duplication.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/libxfs_api_defs.h | 1 +
libxfs/libxfs_priv.h | 1 +
libxfs/xfs_bmap.c | 19 +++----------------
libxfs/xfs_rtbitmap.c | 33 +++++++++++++++++++++++++++++++++
4 files changed, 38 insertions(+), 16 deletions(-)
diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
index 04277c009..a16efa007 100644
--- a/libxfs/libxfs_api_defs.h
+++ b/libxfs/libxfs_api_defs.h
@@ -176,6 +176,7 @@
#define xfs_rmap_query_range libxfs_rmap_query_range
#define xfs_rtfree_extent libxfs_rtfree_extent
+#define xfs_rtfree_blocks libxfs_rtfree_blocks
#define xfs_sb_from_disk libxfs_sb_from_disk
#define xfs_sb_quota_from_disk libxfs_sb_quota_from_disk
#define xfs_sb_read_secondary libxfs_sb_read_secondary
diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index 5a7decf97..21d772cf4 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -497,6 +497,7 @@ xfs_buf_corruption_error(struct xfs_buf *bp, xfs_failaddr_t fa);
/* XXX: this is clearly a bug - a shared header needs to export this */
/* xfs_rtalloc.c */
int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
+int libxfs_rtfree_blocks(struct xfs_trans *, xfs_fsblock_t, xfs_filblks_t);
bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
struct xfs_rtalloc_rec {
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index 2bd23d40e..5744b882b 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -5050,33 +5050,20 @@ xfs_bmap_del_extent_real(
flags = XFS_ILOG_CORE;
if (whichfork == XFS_DATA_FORK && XFS_IS_REALTIME_INODE(ip)) {
- xfs_filblks_t len;
- xfs_extlen_t mod;
-
- len = div_u64_rem(del->br_blockcount, mp->m_sb.sb_rextsize,
- &mod);
- ASSERT(mod == 0);
-
if (!(bflags & XFS_BMAPI_REMAP)) {
- xfs_fsblock_t bno;
-
- bno = div_u64_rem(del->br_startblock,
- mp->m_sb.sb_rextsize, &mod);
- ASSERT(mod == 0);
-
- error = xfs_rtfree_extent(tp, bno, (xfs_extlen_t)len);
+ error = xfs_rtfree_blocks(tp, del->br_startblock,
+ del->br_blockcount);
if (error)
goto done;
}
do_fx = 0;
- nblks = len * mp->m_sb.sb_rextsize;
qfield = XFS_TRANS_DQ_RTBCOUNT;
} else {
do_fx = 1;
- nblks = del->br_blockcount;
qfield = XFS_TRANS_DQ_BCOUNT;
}
+ nblks = del->br_blockcount;
del_endblock = del->br_startblock + del->br_blockcount;
if (cur) {
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index bc8312caf..2c20c6538 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -1003,6 +1003,39 @@ xfs_rtfree_extent(
return 0;
}
+/*
+ * Free some blocks in the realtime subvolume. rtbno and rtlen are in units of
+ * rt blocks, not rt extents; must be aligned to the rt extent size; and rtlen
+ * cannot exceed XFS_MAX_BMBT_EXTLEN.
+ */
+int
+xfs_rtfree_blocks(
+ struct xfs_trans *tp,
+ xfs_fsblock_t rtbno,
+ xfs_filblks_t rtlen)
+{
+ struct xfs_mount *mp = tp->t_mountp;
+ xfs_rtblock_t bno;
+ xfs_filblks_t len;
+ xfs_extlen_t mod;
+
+ ASSERT(rtlen <= XFS_MAX_BMBT_EXTLEN);
+
+ len = div_u64_rem(rtlen, mp->m_sb.sb_rextsize, &mod);
+ if (mod) {
+ ASSERT(mod == 0);
+ return -EIO;
+ }
+
+ bno = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod);
+ if (mod) {
+ ASSERT(mod == 0);
+ return -EIO;
+ }
+
+ return xfs_rtfree_extent(tp, bno, len);
+}
+
/* Find all the free records within a given range. */
int
xfs_rtalloc_query_range(
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 03/35] xfs: fix units conversion error in xfs_bmap_del_extent_delay
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 ` cem
2024-02-15 12:08 ` [PATCH 04/35] xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h cem
` (32 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: ddd98076d5c075c8a6c49d9e6e8ee12844137f23
The unit conversions in this function do not make sense. First we
convert a block count to bytes, then divide that bytes value by
rextsize, which is in blocks, to get an rt extent count. You can't
divide bytes by blocks to get a (possibly multiblock) extent value.
Fortunately nobody uses delalloc on the rt volume so this hasn't
mattered.
Fixes: fa5c836ca8eb5 ("xfs: refactor xfs_bunmapi_cow")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_bmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index 5744b882b..6fbfcb25a 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -4820,7 +4820,7 @@ xfs_bmap_del_extent_delay(
ASSERT(got_endoff >= del_endoff);
if (isrt) {
- uint64_t rtexts = XFS_FSB_TO_B(mp, del->br_blockcount);
+ uint64_t rtexts = del->br_blockcount;
do_div(rtexts, mp->m_sb.sb_rextsize);
xfs_mod_frextents(mp, rtexts);
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 04/35] xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (2 preceding siblings ...)
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 ` cem
2024-02-15 12:08 ` [PATCH 05/35] xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator cem
` (31 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 13928113fc5b5e79c91796290a99ed991ac0efe2
Move all the declarations for functionality in xfs_rtbitmap.c into a
separate xfs_rtbitmap.h header file.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/libxfs_priv.h | 56 ++---------------------------
libxfs/xfs_bmap.c | 1 +
libxfs/xfs_rtbitmap.c | 1 +
libxfs/xfs_rtbitmap.h | 82 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 86 insertions(+), 54 deletions(-)
create mode 100644 libxfs/xfs_rtbitmap.h
diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index 21d772cf4..ed437e38e 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -37,6 +37,8 @@
#ifndef __LIBXFS_INTERNAL_XFS_H__
#define __LIBXFS_INTERNAL_XFS_H__
+#define CONFIG_XFS_RT
+
#include "libxfs_api_defs.h"
#include "platform_defs.h"
#include "xfs.h"
@@ -494,23 +496,6 @@ void xfs_inode_verifier_error(struct xfs_inode *ip, int error,
void
xfs_buf_corruption_error(struct xfs_buf *bp, xfs_failaddr_t fa);
-/* XXX: this is clearly a bug - a shared header needs to export this */
-/* xfs_rtalloc.c */
-int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
-int libxfs_rtfree_blocks(struct xfs_trans *, xfs_fsblock_t, xfs_filblks_t);
-bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
-
-struct xfs_rtalloc_rec {
- xfs_rtblock_t ar_startext;
- xfs_rtblock_t ar_extcount;
-};
-
-typedef int (*xfs_rtalloc_query_range_fn)(
- struct xfs_mount *mp,
- struct xfs_trans *tp,
- const struct xfs_rtalloc_rec *rec,
- void *priv);
-
int libxfs_zero_extent(struct xfs_inode *ip, xfs_fsblock_t start_fsb,
xfs_off_t count_fsb);
@@ -547,43 +532,6 @@ xfs_agnumber_t xfs_set_inode_alloc(struct xfs_mount *mp,
xfs_agnumber_t agcount);
/* Keep static checkers quiet about nonstatic functions by exporting */
-int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
-int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_extlen_t len, int val,
- xfs_rtblock_t *new, int *stat);
-int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_rtblock_t limit,
- xfs_rtblock_t *rtblock);
-int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_rtblock_t limit,
- xfs_rtblock_t *rtblock);
-int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_extlen_t len, int val);
-int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
- int log, xfs_rtblock_t bbno, int delta,
- struct xfs_buf **rbpp, xfs_fsblock_t *rsb,
- xfs_suminfo_t *sum);
-int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
- xfs_rtblock_t bbno, int delta, struct xfs_buf **rbpp,
- xfs_fsblock_t *rsb);
-int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_extlen_t len,
- struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
-int xfs_rtalloc_query_range(struct xfs_mount *mp,
- struct xfs_trans *tp,
- const struct xfs_rtalloc_rec *low_rec,
- const struct xfs_rtalloc_rec *high_rec,
- xfs_rtalloc_query_range_fn fn,
- void *priv);
-int xfs_rtalloc_query_all(struct xfs_mount *mp,
- struct xfs_trans *tp,
- xfs_rtalloc_query_range_fn fn,
- void *priv);
-bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
-int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_extlen_t len,
- bool *is_free);
/* xfs_bmap_util.h */
struct xfs_bmalloca;
int xfs_bmap_extsize_align(struct xfs_mount *mp, struct xfs_bmbt_irec *gotp,
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index 6fbfcb25a..bc82b71f3 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -29,6 +29,7 @@
#include "xfs_ag.h"
#include "xfs_ag_resv.h"
#include "xfs_refcount.h"
+#include "xfs_rtbitmap.h"
struct kmem_cache *xfs_bmap_intent_cache;
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 2c20c6538..bd0925c9a 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -14,6 +14,7 @@
#include "xfs_inode.h"
#include "xfs_bmap.h"
#include "xfs_trans.h"
+#include "xfs_rtbitmap.h"
/*
* Realtime allocator bitmap functions shared with userspace.
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
new file mode 100644
index 000000000..546dea34b
--- /dev/null
+++ b/libxfs/xfs_rtbitmap.h
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ */
+#ifndef __XFS_RTBITMAP_H__
+#define __XFS_RTBITMAP_H__
+
+/*
+ * XXX: Most of the realtime allocation functions deal in units of realtime
+ * extents, not realtime blocks. This looks funny when paired with the type
+ * name and screams for a larger cleanup.
+ */
+struct xfs_rtalloc_rec {
+ xfs_rtblock_t ar_startext;
+ xfs_rtblock_t ar_extcount;
+};
+
+typedef int (*xfs_rtalloc_query_range_fn)(
+ struct xfs_mount *mp,
+ struct xfs_trans *tp,
+ const struct xfs_rtalloc_rec *rec,
+ void *priv);
+
+#ifdef CONFIG_XFS_RT
+int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
+ xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
+int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
+ xfs_rtblock_t start, xfs_extlen_t len, int val,
+ xfs_rtblock_t *new, int *stat);
+int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
+ xfs_rtblock_t start, xfs_rtblock_t limit,
+ xfs_rtblock_t *rtblock);
+int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
+ xfs_rtblock_t start, xfs_rtblock_t limit,
+ xfs_rtblock_t *rtblock);
+int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
+ xfs_rtblock_t start, xfs_extlen_t len, int val);
+int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
+ int log, xfs_rtblock_t bbno, int delta,
+ struct xfs_buf **rbpp, xfs_fsblock_t *rsb,
+ xfs_suminfo_t *sum);
+int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
+ xfs_rtblock_t bbno, int delta, struct xfs_buf **rbpp,
+ xfs_fsblock_t *rsb);
+int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
+ xfs_rtblock_t start, xfs_extlen_t len,
+ struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
+int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
+ const struct xfs_rtalloc_rec *low_rec,
+ const struct xfs_rtalloc_rec *high_rec,
+ xfs_rtalloc_query_range_fn fn, void *priv);
+int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,
+ xfs_rtalloc_query_range_fn fn,
+ void *priv);
+bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
+int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
+ xfs_rtblock_t start, xfs_extlen_t len,
+ bool *is_free);
+/*
+ * Free an extent in the realtime subvolume. Length is expressed in
+ * realtime extents, as is the block number.
+ */
+int /* error */
+xfs_rtfree_extent(
+ struct xfs_trans *tp, /* transaction pointer */
+ xfs_rtblock_t bno, /* starting block number to free */
+ xfs_extlen_t len); /* length of extent freed */
+
+/* Same as above, but in units of rt blocks. */
+int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
+ xfs_filblks_t rtlen);
+#else /* CONFIG_XFS_RT */
+# define xfs_rtfree_extent(t,b,l) (-ENOSYS)
+# define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS)
+# define xfs_rtalloc_query_range(m,t,l,h,f,p) (-ENOSYS)
+# define xfs_rtalloc_query_all(m,t,f,p) (-ENOSYS)
+# define xfs_rtbuf_get(m,t,b,i,p) (-ENOSYS)
+# define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS)
+#endif /* CONFIG_XFS_RT */
+
+#endif /* __XFS_RTBITMAP_H__ */
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 05/35] xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (3 preceding siblings ...)
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 ` cem
2024-02-15 12:08 ` [PATCH 06/35] xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t cem
` (30 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: a684c538bc14410565e8939393089670fa1e19dd
In most of the filesystem, we use xfs_extlen_t to store the length of a
file (or AG) space mapping in units of fs blocks. Unfortunately, the
realtime allocator also uses it to store the length of a rt space
mapping in units of rt extents. This is confusing, since one rt extent
can consist of many fs blocks.
Separate the two by introducing a new type (xfs_rtxlen_t) to store the
length of a space mapping (in units of realtime extents) that would be
found in a file.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 12 ++++++------
libxfs/xfs_rtbitmap.h | 11 +++++------
libxfs/xfs_types.h | 1 +
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index bd0925c9a..976b1aca6 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -532,7 +532,7 @@ xfs_rtmodify_range(
xfs_mount_t *mp, /* file system mount point */
xfs_trans_t *tp, /* transaction pointer */
xfs_rtblock_t start, /* starting block to modify */
- xfs_extlen_t len, /* length of extent to modify */
+ xfs_rtxlen_t len, /* length of extent to modify */
int val) /* 1 for free, 0 for allocated */
{
xfs_rtword_t *b; /* current word in buffer */
@@ -688,7 +688,7 @@ xfs_rtfree_range(
xfs_mount_t *mp, /* file system mount point */
xfs_trans_t *tp, /* transaction pointer */
xfs_rtblock_t start, /* starting block to free */
- xfs_extlen_t len, /* length to free */
+ xfs_rtxlen_t len, /* length to free */
struct xfs_buf **rbpp, /* in/out: summary block buffer */
xfs_fsblock_t *rsb) /* in/out: summary block number */
{
@@ -764,7 +764,7 @@ xfs_rtcheck_range(
xfs_mount_t *mp, /* file system mount point */
xfs_trans_t *tp, /* transaction pointer */
xfs_rtblock_t start, /* starting block number of extent */
- xfs_extlen_t len, /* length of extent */
+ xfs_rtxlen_t len, /* length of extent */
int val, /* 1 for free, 0 for allocated */
xfs_rtblock_t *new, /* out: first block not matching */
int *stat) /* out: 1 for matches, 0 for not */
@@ -940,7 +940,7 @@ xfs_rtcheck_alloc_range(
xfs_mount_t *mp, /* file system mount point */
xfs_trans_t *tp, /* transaction pointer */
xfs_rtblock_t bno, /* starting block number of extent */
- xfs_extlen_t len) /* length of extent */
+ xfs_rtxlen_t len) /* length of extent */
{
xfs_rtblock_t new; /* dummy for xfs_rtcheck_range */
int stat;
@@ -963,7 +963,7 @@ int /* error */
xfs_rtfree_extent(
xfs_trans_t *tp, /* transaction pointer */
xfs_rtblock_t bno, /* starting block number to free */
- xfs_extlen_t len) /* length of extent freed */
+ xfs_rtxlen_t len) /* length of extent freed */
{
int error; /* error value */
xfs_mount_t *mp; /* file system mount structure */
@@ -1114,7 +1114,7 @@ xfs_rtalloc_extent_is_free(
struct xfs_mount *mp,
struct xfs_trans *tp,
xfs_rtblock_t start,
- xfs_extlen_t len,
+ xfs_rtxlen_t len,
bool *is_free)
{
xfs_rtblock_t end;
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 546dea34b..d44496101 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -26,7 +26,7 @@ typedef int (*xfs_rtalloc_query_range_fn)(
int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_extlen_t len, int val,
+ xfs_rtblock_t start, xfs_rtxlen_t len, int val,
xfs_rtblock_t *new, int *stat);
int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_rtblock_t start, xfs_rtblock_t limit,
@@ -35,7 +35,7 @@ int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_rtblock_t start, xfs_rtblock_t limit,
xfs_rtblock_t *rtblock);
int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_extlen_t len, int val);
+ xfs_rtblock_t start, xfs_rtxlen_t len, int val);
int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
int log, xfs_rtblock_t bbno, int delta,
struct xfs_buf **rbpp, xfs_fsblock_t *rsb,
@@ -44,7 +44,7 @@ int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
xfs_rtblock_t bbno, int delta, struct xfs_buf **rbpp,
xfs_fsblock_t *rsb);
int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_extlen_t len,
+ xfs_rtblock_t start, xfs_rtxlen_t len,
struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
const struct xfs_rtalloc_rec *low_rec,
@@ -53,9 +53,8 @@ int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_rtalloc_query_range_fn fn,
void *priv);
-bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_extlen_t len,
+ xfs_rtblock_t start, xfs_rtxlen_t len,
bool *is_free);
/*
* Free an extent in the realtime subvolume. Length is expressed in
@@ -65,7 +64,7 @@ int /* error */
xfs_rtfree_extent(
struct xfs_trans *tp, /* transaction pointer */
xfs_rtblock_t bno, /* starting block number to free */
- xfs_extlen_t len); /* length of extent freed */
+ xfs_rtxlen_t len); /* length of extent freed */
/* Same as above, but in units of rt blocks. */
int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h
index 851220021..713cb7031 100644
--- a/libxfs/xfs_types.h
+++ b/libxfs/xfs_types.h
@@ -11,6 +11,7 @@ typedef uint32_t prid_t; /* project ID */
typedef uint32_t xfs_agblock_t; /* blockno in alloc. group */
typedef uint32_t xfs_agino_t; /* inode # within allocation grp */
typedef uint32_t xfs_extlen_t; /* extent length in blocks */
+typedef uint32_t xfs_rtxlen_t; /* file extent length in rtextents */
typedef uint32_t xfs_agnumber_t; /* allocation group number */
typedef uint64_t xfs_extnum_t; /* # of extents in a file */
typedef uint32_t xfs_aextnum_t; /* # extents in an attribute fork */
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 06/35] xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (4 preceding siblings ...)
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 ` cem
2024-02-15 12:08 ` [PATCH 07/35] xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t cem
` (29 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 03f4de332e2e79db36ed2156fb2350480f142bec
We should use xfs_fileoff_t to store the file block offset of any
location within the realtime bitmap or summary files.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 22 +++++++++++-----------
libxfs/xfs_rtbitmap.h | 12 ++++++------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 976b1aca6..9a9097edd 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -53,7 +53,7 @@ int
xfs_rtbuf_get(
xfs_mount_t *mp, /* file system mount structure */
xfs_trans_t *tp, /* transaction pointer */
- xfs_rtblock_t block, /* block number in bitmap or summary */
+ xfs_fileoff_t block, /* block number in bitmap or summary */
int issum, /* is summary not bitmap */
struct xfs_buf **bpp) /* output: buffer for the block */
{
@@ -99,7 +99,7 @@ xfs_rtfind_back(
{
xfs_rtword_t *b; /* current word in buffer */
int bit; /* bit number in the word */
- xfs_rtblock_t block; /* bitmap block number */
+ xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */
@@ -274,7 +274,7 @@ xfs_rtfind_forw(
{
xfs_rtword_t *b; /* current word in buffer */
int bit; /* bit number in the word */
- xfs_rtblock_t block; /* bitmap block number */
+ xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */
@@ -444,15 +444,15 @@ xfs_rtmodify_summary_int(
xfs_mount_t *mp, /* file system mount structure */
xfs_trans_t *tp, /* transaction pointer */
int log, /* log2 of extent size */
- xfs_rtblock_t bbno, /* bitmap block number */
+ xfs_fileoff_t bbno, /* bitmap block number */
int delta, /* change to make to summary info */
struct xfs_buf **rbpp, /* in/out: summary block buffer */
- xfs_fsblock_t *rsb, /* in/out: summary block number */
+ xfs_fileoff_t *rsb, /* in/out: summary block number */
xfs_suminfo_t *sum) /* out: summary info for this block */
{
struct xfs_buf *bp; /* buffer for the summary block */
int error; /* error value */
- xfs_fsblock_t sb; /* summary fsblock */
+ xfs_fileoff_t sb; /* summary fsblock */
int so; /* index into the summary file */
xfs_suminfo_t *sp; /* pointer to returned data */
@@ -514,10 +514,10 @@ xfs_rtmodify_summary(
xfs_mount_t *mp, /* file system mount structure */
xfs_trans_t *tp, /* transaction pointer */
int log, /* log2 of extent size */
- xfs_rtblock_t bbno, /* bitmap block number */
+ xfs_fileoff_t bbno, /* bitmap block number */
int delta, /* change to make to summary info */
struct xfs_buf **rbpp, /* in/out: summary block buffer */
- xfs_fsblock_t *rsb) /* in/out: summary block number */
+ xfs_fileoff_t *rsb) /* in/out: summary block number */
{
return xfs_rtmodify_summary_int(mp, tp, log, bbno,
delta, rbpp, rsb, NULL);
@@ -537,7 +537,7 @@ xfs_rtmodify_range(
{
xfs_rtword_t *b; /* current word in buffer */
int bit; /* bit number in the word */
- xfs_rtblock_t block; /* bitmap block number */
+ xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */
@@ -690,7 +690,7 @@ xfs_rtfree_range(
xfs_rtblock_t start, /* starting block to free */
xfs_rtxlen_t len, /* length to free */
struct xfs_buf **rbpp, /* in/out: summary block buffer */
- xfs_fsblock_t *rsb) /* in/out: summary block number */
+ xfs_fileoff_t *rsb) /* in/out: summary block number */
{
xfs_rtblock_t end; /* end of the freed extent */
int error; /* error value */
@@ -771,7 +771,7 @@ xfs_rtcheck_range(
{
xfs_rtword_t *b; /* current word in buffer */
int bit; /* bit number in the word */
- xfs_rtblock_t block; /* bitmap block number */
+ xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index d44496101..e2ea6d31c 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -24,7 +24,7 @@ typedef int (*xfs_rtalloc_query_range_fn)(
#ifdef CONFIG_XFS_RT
int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
+ xfs_fileoff_t block, int issum, struct xfs_buf **bpp);
int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_rtblock_t start, xfs_rtxlen_t len, int val,
xfs_rtblock_t *new, int *stat);
@@ -37,15 +37,15 @@ int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_rtblock_t start, xfs_rtxlen_t len, int val);
int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
- int log, xfs_rtblock_t bbno, int delta,
- struct xfs_buf **rbpp, xfs_fsblock_t *rsb,
+ int log, xfs_fileoff_t bbno, int delta,
+ struct xfs_buf **rbpp, xfs_fileoff_t *rsb,
xfs_suminfo_t *sum);
int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
- xfs_rtblock_t bbno, int delta, struct xfs_buf **rbpp,
- xfs_fsblock_t *rsb);
+ xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
+ xfs_fileoff_t *rsb);
int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_rtblock_t start, xfs_rtxlen_t len,
- struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
+ struct xfs_buf **rbpp, xfs_fileoff_t *rsb);
int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
const struct xfs_rtalloc_rec *low_rec,
const struct xfs_rtalloc_rec *high_rec,
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 07/35] xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (5 preceding siblings ...)
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 ` cem
2024-02-15 12:08 ` [PATCH 08/35] xfs: rename xfs_verify_rtext to xfs_verify_rtbext cem
` (28 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: f29c3e745dc253bf9d9d06ddc36af1a534ba1dd0
XFS uses xfs_rtblock_t for many different uses, which makes it much more
difficult to perform a unit analysis on the codebase. One of these
(ab)uses is when we need to store the length of a free space extent as
stored in the realtime bitmap. Because there can be up to 2^64 realtime
extents in a filesystem, we need a new type that is larger than
xfs_rtxlen_t for callers that are querying the bitmap directly. This
means scrub and growfs.
Create this type as "xfs_rtbxlen_t" and use it to store 64-bit rtx
lengths. 'b' stands for 'bitmap' or 'big'; reader's choice.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_format.h | 2 +-
libxfs/xfs_rtbitmap.h | 2 +-
libxfs/xfs_types.h | 1 +
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h
index 371dc0723..20acb8573 100644
--- a/libxfs/xfs_format.h
+++ b/libxfs/xfs_format.h
@@ -98,7 +98,7 @@ typedef struct xfs_sb {
uint32_t sb_blocksize; /* logical block size, bytes */
xfs_rfsblock_t sb_dblocks; /* number of data blocks */
xfs_rfsblock_t sb_rblocks; /* number of realtime blocks */
- xfs_rtblock_t sb_rextents; /* number of realtime extents */
+ xfs_rtbxlen_t sb_rextents; /* number of realtime extents */
uuid_t sb_uuid; /* user-visible file system unique id */
xfs_fsblock_t sb_logstart; /* starting block of log if internal */
xfs_ino_t sb_rootino; /* root inode number */
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index e2ea6d31c..b0a81fb8d 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -13,7 +13,7 @@
*/
struct xfs_rtalloc_rec {
xfs_rtblock_t ar_startext;
- xfs_rtblock_t ar_extcount;
+ xfs_rtbxlen_t ar_extcount;
};
typedef int (*xfs_rtalloc_query_range_fn)(
diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h
index 713cb7031..9af98a975 100644
--- a/libxfs/xfs_types.h
+++ b/libxfs/xfs_types.h
@@ -32,6 +32,7 @@ typedef uint64_t xfs_rfsblock_t; /* blockno in filesystem (raw) */
typedef uint64_t xfs_rtblock_t; /* extent (block) in realtime area */
typedef uint64_t xfs_fileoff_t; /* block number in a file */
typedef uint64_t xfs_filblks_t; /* number of blocks in a file */
+typedef uint64_t xfs_rtbxlen_t; /* rtbitmap extent length in rtextents */
typedef int64_t xfs_srtblock_t; /* signed version of xfs_rtblock_t */
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 08/35] xfs: rename xfs_verify_rtext to xfs_verify_rtbext
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (6 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 07/35] xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 09/35] xfs: convert rt extent numbers to xfs_rtxnum_t cem
` (27 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 3d2b6d034f0feb7741b313f978a2fe45e917e1be
This helper function validates that a range of *blocks* in the
realtime section is completely contained within the realtime section.
It does /not/ validate ranges of *rtextents*. Rename the function to
avoid suggesting that it does, and change the type of the @len parameter
since xfs_rtblock_t is a position unit, not a length unit.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_bmap.c | 4 ++--
libxfs/xfs_types.c | 4 ++--
libxfs/xfs_types.h | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index bc82b71f3..69549a94a 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -6190,8 +6190,8 @@ xfs_bmap_validate_extent(
return __this_address;
if (XFS_IS_REALTIME_INODE(ip) && whichfork == XFS_DATA_FORK) {
- if (!xfs_verify_rtext(mp, irec->br_startblock,
- irec->br_blockcount))
+ if (!xfs_verify_rtbext(mp, irec->br_startblock,
+ irec->br_blockcount))
return __this_address;
} else {
if (!xfs_verify_fsbext(mp, irec->br_startblock,
diff --git a/libxfs/xfs_types.c b/libxfs/xfs_types.c
index 87abc8244..74ab1965a 100644
--- a/libxfs/xfs_types.c
+++ b/libxfs/xfs_types.c
@@ -148,10 +148,10 @@ xfs_verify_rtbno(
/* Verify that a realtime device extent is fully contained inside the volume. */
bool
-xfs_verify_rtext(
+xfs_verify_rtbext(
struct xfs_mount *mp,
xfs_rtblock_t rtbno,
- xfs_rtblock_t len)
+ xfs_filblks_t len)
{
if (rtbno + len <= rtbno)
return false;
diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h
index 9af98a975..9e45f13f6 100644
--- a/libxfs/xfs_types.h
+++ b/libxfs/xfs_types.h
@@ -231,8 +231,8 @@ bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);
bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino);
bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino);
bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
-bool xfs_verify_rtext(struct xfs_mount *mp, xfs_rtblock_t rtbno,
- xfs_rtblock_t len);
+bool xfs_verify_rtbext(struct xfs_mount *mp, xfs_rtblock_t rtbno,
+ xfs_filblks_t len);
bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
bool xfs_verify_dablk(struct xfs_mount *mp, xfs_fileoff_t off);
void xfs_icount_range(struct xfs_mount *mp, unsigned long long *min,
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 09/35] xfs: convert rt extent numbers to xfs_rtxnum_t
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (7 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 08/35] xfs: rename xfs_verify_rtext to xfs_verify_rtbext cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 10/35] xfs: create a helper to convert rtextents to rtblocks cem
` (26 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 2d5f216b77e33f9b503bd42998271da35d4b7055
Further disambiguate the xfs_rtblock_t uses by creating a new type,
xfs_rtxnum_t, to store the position of an extent within the realtime
section, in units of rtextents.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 86 +++++++++++++++++++++----------------------
libxfs/xfs_rtbitmap.h | 26 ++++++-------
libxfs/xfs_types.h | 2 +
3 files changed, 57 insertions(+), 57 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 9a9097edd..4085f29b6 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -93,9 +93,9 @@ int
xfs_rtfind_back(
xfs_mount_t *mp, /* file system mount point */
xfs_trans_t *tp, /* transaction pointer */
- xfs_rtblock_t start, /* starting block to look at */
- xfs_rtblock_t limit, /* last block to look at */
- xfs_rtblock_t *rtblock) /* out: start block found */
+ xfs_rtxnum_t start, /* starting rtext to look at */
+ xfs_rtxnum_t limit, /* last rtext to look at */
+ xfs_rtxnum_t *rtx) /* out: start rtext found */
{
xfs_rtword_t *b; /* current word in buffer */
int bit; /* bit number in the word */
@@ -103,9 +103,9 @@ xfs_rtfind_back(
struct xfs_buf *bp; /* buf for the block */
xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */
- xfs_rtblock_t firstbit; /* first useful bit in the word */
- xfs_rtblock_t i; /* current bit number rel. to start */
- xfs_rtblock_t len; /* length of inspected area */
+ xfs_rtxnum_t firstbit; /* first useful bit in the word */
+ xfs_rtxnum_t i; /* current bit number rel. to start */
+ xfs_rtxnum_t len; /* length of inspected area */
xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t want; /* mask for "good" values */
xfs_rtword_t wdiff; /* difference from wanted value */
@@ -154,7 +154,7 @@ xfs_rtfind_back(
*/
xfs_trans_brelse(tp, bp);
i = bit - XFS_RTHIBIT(wdiff);
- *rtblock = start - i + 1;
+ *rtx = start - i + 1;
return 0;
}
i = bit - firstbit + 1;
@@ -200,7 +200,7 @@ xfs_rtfind_back(
*/
xfs_trans_brelse(tp, bp);
i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
- *rtblock = start - i + 1;
+ *rtx = start - i + 1;
return 0;
}
i += XFS_NBWORD;
@@ -247,7 +247,7 @@ xfs_rtfind_back(
*/
xfs_trans_brelse(tp, bp);
i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
- *rtblock = start - i + 1;
+ *rtx = start - i + 1;
return 0;
} else
i = len;
@@ -256,7 +256,7 @@ xfs_rtfind_back(
* No match, return that we scanned the whole area.
*/
xfs_trans_brelse(tp, bp);
- *rtblock = start - i + 1;
+ *rtx = start - i + 1;
return 0;
}
@@ -268,9 +268,9 @@ int
xfs_rtfind_forw(
xfs_mount_t *mp, /* file system mount point */
xfs_trans_t *tp, /* transaction pointer */
- xfs_rtblock_t start, /* starting block to look at */
- xfs_rtblock_t limit, /* last block to look at */
- xfs_rtblock_t *rtblock) /* out: start block found */
+ xfs_rtxnum_t start, /* starting rtext to look at */
+ xfs_rtxnum_t limit, /* last rtext to look at */
+ xfs_rtxnum_t *rtx) /* out: start rtext found */
{
xfs_rtword_t *b; /* current word in buffer */
int bit; /* bit number in the word */
@@ -278,9 +278,9 @@ xfs_rtfind_forw(
struct xfs_buf *bp; /* buf for the block */
xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */
- xfs_rtblock_t i; /* current bit number rel. to start */
- xfs_rtblock_t lastbit; /* last useful bit in the word */
- xfs_rtblock_t len; /* length of inspected area */
+ xfs_rtxnum_t i; /* current bit number rel. to start */
+ xfs_rtxnum_t lastbit; /* last useful bit in the word */
+ xfs_rtxnum_t len; /* length of inspected area */
xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t want; /* mask for "good" values */
xfs_rtword_t wdiff; /* difference from wanted value */
@@ -328,7 +328,7 @@ xfs_rtfind_forw(
*/
xfs_trans_brelse(tp, bp);
i = XFS_RTLOBIT(wdiff) - bit;
- *rtblock = start + i - 1;
+ *rtx = start + i - 1;
return 0;
}
i = lastbit - bit;
@@ -373,7 +373,7 @@ xfs_rtfind_forw(
*/
xfs_trans_brelse(tp, bp);
i += XFS_RTLOBIT(wdiff);
- *rtblock = start + i - 1;
+ *rtx = start + i - 1;
return 0;
}
i += XFS_NBWORD;
@@ -417,7 +417,7 @@ xfs_rtfind_forw(
*/
xfs_trans_brelse(tp, bp);
i += XFS_RTLOBIT(wdiff);
- *rtblock = start + i - 1;
+ *rtx = start + i - 1;
return 0;
} else
i = len;
@@ -426,7 +426,7 @@ xfs_rtfind_forw(
* No match, return that we scanned the whole area.
*/
xfs_trans_brelse(tp, bp);
- *rtblock = start + i - 1;
+ *rtx = start + i - 1;
return 0;
}
@@ -531,7 +531,7 @@ int
xfs_rtmodify_range(
xfs_mount_t *mp, /* file system mount point */
xfs_trans_t *tp, /* transaction pointer */
- xfs_rtblock_t start, /* starting block to modify */
+ xfs_rtxnum_t start, /* starting rtext to modify */
xfs_rtxlen_t len, /* length of extent to modify */
int val) /* 1 for free, 0 for allocated */
{
@@ -687,15 +687,15 @@ int
xfs_rtfree_range(
xfs_mount_t *mp, /* file system mount point */
xfs_trans_t *tp, /* transaction pointer */
- xfs_rtblock_t start, /* starting block to free */
+ xfs_rtxnum_t start, /* starting rtext to free */
xfs_rtxlen_t len, /* length to free */
struct xfs_buf **rbpp, /* in/out: summary block buffer */
xfs_fileoff_t *rsb) /* in/out: summary block number */
{
- xfs_rtblock_t end; /* end of the freed extent */
+ xfs_rtxnum_t end; /* end of the freed extent */
int error; /* error value */
- xfs_rtblock_t postblock; /* first block freed > end */
- xfs_rtblock_t preblock; /* first block freed < start */
+ xfs_rtxnum_t postblock; /* first rtext freed > end */
+ xfs_rtxnum_t preblock; /* first rtext freed < start */
end = start + len - 1;
/*
@@ -763,10 +763,10 @@ int
xfs_rtcheck_range(
xfs_mount_t *mp, /* file system mount point */
xfs_trans_t *tp, /* transaction pointer */
- xfs_rtblock_t start, /* starting block number of extent */
+ xfs_rtxnum_t start, /* starting rtext number of extent */
xfs_rtxlen_t len, /* length of extent */
int val, /* 1 for free, 0 for allocated */
- xfs_rtblock_t *new, /* out: first block not matching */
+ xfs_rtxnum_t *new, /* out: first rtext not matching */
int *stat) /* out: 1 for matches, 0 for not */
{
xfs_rtword_t *b; /* current word in buffer */
@@ -775,8 +775,8 @@ xfs_rtcheck_range(
struct xfs_buf *bp; /* buf for the block */
xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */
- xfs_rtblock_t i; /* current bit number rel. to start */
- xfs_rtblock_t lastbit; /* last useful bit in word */
+ xfs_rtxnum_t i; /* current bit number rel. to start */
+ xfs_rtxnum_t lastbit; /* last useful bit in word */
xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t wdiff; /* difference from wanted value */
int word; /* word number in the buffer */
@@ -939,14 +939,14 @@ STATIC int /* error */
xfs_rtcheck_alloc_range(
xfs_mount_t *mp, /* file system mount point */
xfs_trans_t *tp, /* transaction pointer */
- xfs_rtblock_t bno, /* starting block number of extent */
+ xfs_rtxnum_t start, /* starting rtext number of extent */
xfs_rtxlen_t len) /* length of extent */
{
- xfs_rtblock_t new; /* dummy for xfs_rtcheck_range */
+ xfs_rtxnum_t new; /* dummy for xfs_rtcheck_range */
int stat;
int error;
- error = xfs_rtcheck_range(mp, tp, bno, len, 0, &new, &stat);
+ error = xfs_rtcheck_range(mp, tp, start, len, 0, &new, &stat);
if (error)
return error;
ASSERT(stat);
@@ -962,7 +962,7 @@ xfs_rtcheck_alloc_range(
int /* error */
xfs_rtfree_extent(
xfs_trans_t *tp, /* transaction pointer */
- xfs_rtblock_t bno, /* starting block number to free */
+ xfs_rtxnum_t start, /* starting rtext number to free */
xfs_rtxlen_t len) /* length of extent freed */
{
int error; /* error value */
@@ -975,14 +975,14 @@ xfs_rtfree_extent(
ASSERT(mp->m_rbmip->i_itemp != NULL);
ASSERT(xfs_isilocked(mp->m_rbmip, XFS_ILOCK_EXCL));
- error = xfs_rtcheck_alloc_range(mp, tp, bno, len);
+ error = xfs_rtcheck_alloc_range(mp, tp, start, len);
if (error)
return error;
/*
* Free the range of realtime blocks.
*/
- error = xfs_rtfree_range(mp, tp, bno, len, &sumbp, &sb);
+ error = xfs_rtfree_range(mp, tp, start, len, &sumbp, &sb);
if (error) {
return error;
}
@@ -1016,7 +1016,7 @@ xfs_rtfree_blocks(
xfs_filblks_t rtlen)
{
struct xfs_mount *mp = tp->t_mountp;
- xfs_rtblock_t bno;
+ xfs_rtxnum_t start;
xfs_filblks_t len;
xfs_extlen_t mod;
@@ -1028,13 +1028,13 @@ xfs_rtfree_blocks(
return -EIO;
}
- bno = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod);
+ start = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod);
if (mod) {
ASSERT(mod == 0);
return -EIO;
}
- return xfs_rtfree_extent(tp, bno, len);
+ return xfs_rtfree_extent(tp, start, len);
}
/* Find all the free records within a given range. */
@@ -1048,9 +1048,9 @@ xfs_rtalloc_query_range(
void *priv)
{
struct xfs_rtalloc_rec rec;
- xfs_rtblock_t rtstart;
- xfs_rtblock_t rtend;
- xfs_rtblock_t high_key;
+ xfs_rtxnum_t rtstart;
+ xfs_rtxnum_t rtend;
+ xfs_rtxnum_t high_key;
int is_free;
int error = 0;
@@ -1113,11 +1113,11 @@ int
xfs_rtalloc_extent_is_free(
struct xfs_mount *mp,
struct xfs_trans *tp,
- xfs_rtblock_t start,
+ xfs_rtxnum_t start,
xfs_rtxlen_t len,
bool *is_free)
{
- xfs_rtblock_t end;
+ xfs_rtxnum_t end;
int matches;
int error;
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index b0a81fb8d..5e2afb7fe 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -7,12 +7,10 @@
#define __XFS_RTBITMAP_H__
/*
- * XXX: Most of the realtime allocation functions deal in units of realtime
- * extents, not realtime blocks. This looks funny when paired with the type
- * name and screams for a larger cleanup.
+ * Functions for walking free space rtextents in the realtime bitmap.
*/
struct xfs_rtalloc_rec {
- xfs_rtblock_t ar_startext;
+ xfs_rtxnum_t ar_startext;
xfs_rtbxlen_t ar_extcount;
};
@@ -26,16 +24,16 @@ typedef int (*xfs_rtalloc_query_range_fn)(
int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_fileoff_t block, int issum, struct xfs_buf **bpp);
int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_rtxlen_t len, int val,
- xfs_rtblock_t *new, int *stat);
+ xfs_rtxnum_t start, xfs_rtxlen_t len, int val,
+ xfs_rtxnum_t *new, int *stat);
int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_rtblock_t limit,
- xfs_rtblock_t *rtblock);
+ xfs_rtxnum_t start, xfs_rtxnum_t limit,
+ xfs_rtxnum_t *rtblock);
int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_rtblock_t limit,
- xfs_rtblock_t *rtblock);
+ xfs_rtxnum_t start, xfs_rtxnum_t limit,
+ xfs_rtxnum_t *rtblock);
int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_rtxlen_t len, int val);
+ xfs_rtxnum_t start, xfs_rtxlen_t len, int val);
int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
int log, xfs_fileoff_t bbno, int delta,
struct xfs_buf **rbpp, xfs_fileoff_t *rsb,
@@ -44,7 +42,7 @@ int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
xfs_fileoff_t *rsb);
int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_rtxlen_t len,
+ xfs_rtxnum_t start, xfs_rtxlen_t len,
struct xfs_buf **rbpp, xfs_fileoff_t *rsb);
int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
const struct xfs_rtalloc_rec *low_rec,
@@ -54,7 +52,7 @@ int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_rtalloc_query_range_fn fn,
void *priv);
int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtblock_t start, xfs_rtxlen_t len,
+ xfs_rtxnum_t start, xfs_rtxlen_t len,
bool *is_free);
/*
* Free an extent in the realtime subvolume. Length is expressed in
@@ -63,7 +61,7 @@ int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
int /* error */
xfs_rtfree_extent(
struct xfs_trans *tp, /* transaction pointer */
- xfs_rtblock_t bno, /* starting block number to free */
+ xfs_rtxnum_t start, /* starting rtext number to free */
xfs_rtxlen_t len); /* length of extent freed */
/* Same as above, but in units of rt blocks. */
diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h
index 9e45f13f6..c78237852 100644
--- a/libxfs/xfs_types.h
+++ b/libxfs/xfs_types.h
@@ -32,6 +32,7 @@ typedef uint64_t xfs_rfsblock_t; /* blockno in filesystem (raw) */
typedef uint64_t xfs_rtblock_t; /* extent (block) in realtime area */
typedef uint64_t xfs_fileoff_t; /* block number in a file */
typedef uint64_t xfs_filblks_t; /* number of blocks in a file */
+typedef uint64_t xfs_rtxnum_t; /* rtextent number */
typedef uint64_t xfs_rtbxlen_t; /* rtbitmap extent length in rtextents */
typedef int64_t xfs_srtblock_t; /* signed version of xfs_rtblock_t */
@@ -49,6 +50,7 @@ typedef void * xfs_failaddr_t;
#define NULLRFSBLOCK ((xfs_rfsblock_t)-1)
#define NULLRTBLOCK ((xfs_rtblock_t)-1)
#define NULLFILEOFF ((xfs_fileoff_t)-1)
+#define NULLRTEXTNO ((xfs_rtxnum_t)-1)
#define NULLAGBLOCK ((xfs_agblock_t)-1)
#define NULLAGNUMBER ((xfs_agnumber_t)-1)
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 10/35] xfs: create a helper to convert rtextents to rtblocks
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (8 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 09/35] xfs: convert rt extent numbers to xfs_rtxnum_t cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 11/35] xfs: create a helper to compute leftovers of realtime extents cem
` (25 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: fa5a387230861116c2434c20d29fc4b3fd077d24
Create a helper to convert a realtime extent to a realtime block. Later
on we'll change the helper to use bit shifts when possible.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 5e2afb7fe..099ea8902 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -6,6 +6,22 @@
#ifndef __XFS_RTBITMAP_H__
#define __XFS_RTBITMAP_H__
+static inline xfs_rtblock_t
+xfs_rtx_to_rtb(
+ struct xfs_mount *mp,
+ xfs_rtxnum_t rtx)
+{
+ return rtx * mp->m_sb.sb_rextsize;
+}
+
+static inline xfs_extlen_t
+xfs_rtxlen_to_extlen(
+ struct xfs_mount *mp,
+ xfs_rtxlen_t rtxlen)
+{
+ return rtxlen * mp->m_sb.sb_rextsize;
+}
+
/*
* Functions for walking free space rtextents in the realtime bitmap.
*/
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 11/35] xfs: create a helper to compute leftovers of realtime extents
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (9 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 10/35] xfs: create a helper to convert rtextents to rtblocks cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 12/35] xfs: create a helper to convert extlen to rtextlen cem
` (24 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 68db60bf01c131c09bbe35adf43bd957a4c124bc
Create a helper to compute the misalignment between a file extent
(xfs_extlen_t) and a realtime extent.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_bmap.c | 4 ++--
libxfs/xfs_rtbitmap.h | 9 +++++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index 69549a94a..6e863c8a4 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -2983,7 +2983,7 @@ xfs_bmap_extsize_align(
* If realtime, and the result isn't a multiple of the realtime
* extent size we need to remove blocks until it is.
*/
- if (rt && (temp = (align_alen % mp->m_sb.sb_rextsize))) {
+ if (rt && (temp = xfs_extlen_to_rtxmod(mp, align_alen))) {
/*
* We're not covering the original request, or
* we won't be able to once we fix the length.
@@ -3010,7 +3010,7 @@ xfs_bmap_extsize_align(
else {
align_alen -= orig_off - align_off;
align_off = orig_off;
- align_alen -= align_alen % mp->m_sb.sb_rextsize;
+ align_alen -= xfs_extlen_to_rtxmod(mp, align_alen);
}
/*
* Result doesn't cover the request, fail it.
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 099ea8902..b6a4c46bd 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -22,6 +22,15 @@ xfs_rtxlen_to_extlen(
return rtxlen * mp->m_sb.sb_rextsize;
}
+/* Compute the misalignment between an extent length and a realtime extent .*/
+static inline unsigned int
+xfs_extlen_to_rtxmod(
+ struct xfs_mount *mp,
+ xfs_extlen_t len)
+{
+ return len % mp->m_sb.sb_rextsize;
+}
+
/*
* Functions for walking free space rtextents in the realtime bitmap.
*/
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 12/35] xfs: create a helper to convert extlen to rtextlen
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (10 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 11/35] xfs: create a helper to compute leftovers of realtime extents cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 13/35] xfs: create helpers to convert rt block numbers to rt extent numbers cem
` (23 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 2c2b981b737a519907429f62148bbd9e40e01132
Create a helper to compute the realtime extent (xfs_rtxlen_t) from an
extent length (xfs_extlen_t) value.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.h | 8 ++++++++
libxfs/xfs_trans_resv.c | 3 ++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index b6a4c46bd..e2a36fc15 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -31,6 +31,14 @@ xfs_extlen_to_rtxmod(
return len % mp->m_sb.sb_rextsize;
}
+static inline xfs_rtxlen_t
+xfs_extlen_to_rtxlen(
+ struct xfs_mount *mp,
+ xfs_extlen_t len)
+{
+ return len / mp->m_sb.sb_rextsize;
+}
+
/*
* Functions for walking free space rtextents in the realtime bitmap.
*/
diff --git a/libxfs/xfs_trans_resv.c b/libxfs/xfs_trans_resv.c
index 04c444806..53c190b72 100644
--- a/libxfs/xfs_trans_resv.c
+++ b/libxfs/xfs_trans_resv.c
@@ -18,6 +18,7 @@
#include "xfs_trans.h"
#include "xfs_trans_space.h"
#include "xfs_quota_defs.h"
+#include "xfs_rtbitmap.h"
#define _ALLOC true
#define _FREE false
@@ -219,7 +220,7 @@ xfs_rtalloc_block_count(
unsigned int blksz = XFS_FSB_TO_B(mp, 1);
unsigned int rtbmp_bytes;
- rtbmp_bytes = (XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize) / NBBY;
+ rtbmp_bytes = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN) / NBBY;
return (howmany(rtbmp_bytes, blksz) + 1) * num_ops;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 13/35] xfs: create helpers to convert rt block numbers to rt extent numbers
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (11 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 12/35] xfs: create a helper to convert extlen to rtextlen cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 14/35] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls cem
` (22 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 5dc3a80d46a450481df7f7e9fe673ba3eb4514c3
Create helpers to do unit conversions of rt block numbers to rt extent
numbers. There are three variations -- one to compute the rt extent
number from an rt block number; one to compute the offset of an rt block
within an rt extent; and one to extract both.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_bmap.c | 8 ++++----
libxfs/xfs_rtbitmap.c | 4 ++--
libxfs/xfs_rtbitmap.h | 31 +++++++++++++++++++++++++++++++
3 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index 6e863c8a4..6d7fa88f9 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -5270,7 +5270,6 @@ __xfs_bunmapi(
int tmp_logflags; /* partial logging flags */
int wasdel; /* was a delayed alloc extent */
int whichfork; /* data or attribute fork */
- xfs_fsblock_t sum;
xfs_filblks_t len = *rlen; /* length to unmap in file */
xfs_fileoff_t end;
struct xfs_iext_cursor icur;
@@ -5365,8 +5364,8 @@ __xfs_bunmapi(
if (!isrt)
goto delete;
- sum = del.br_startblock + del.br_blockcount;
- div_u64_rem(sum, mp->m_sb.sb_rextsize, &mod);
+ mod = xfs_rtb_to_rtxoff(mp,
+ del.br_startblock + del.br_blockcount);
if (mod) {
/*
* Realtime extent not lined up at the end.
@@ -5413,7 +5412,8 @@ __xfs_bunmapi(
goto error0;
goto nodelete;
}
- div_u64_rem(del.br_startblock, mp->m_sb.sb_rextsize, &mod);
+
+ mod = xfs_rtb_to_rtxoff(mp, del.br_startblock);
if (mod) {
xfs_extlen_t off = mp->m_sb.sb_rextsize - mod;
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 4085f29b6..48e709a28 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -1022,13 +1022,13 @@ xfs_rtfree_blocks(
ASSERT(rtlen <= XFS_MAX_BMBT_EXTLEN);
- len = div_u64_rem(rtlen, mp->m_sb.sb_rextsize, &mod);
+ len = xfs_rtb_to_rtxrem(mp, rtlen, &mod);
if (mod) {
ASSERT(mod == 0);
return -EIO;
}
- start = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod);
+ start = xfs_rtb_to_rtxrem(mp, rtbno, &mod);
if (mod) {
ASSERT(mod == 0);
return -EIO;
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index e2a36fc15..9df583083 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -39,6 +39,37 @@ xfs_extlen_to_rtxlen(
return len / mp->m_sb.sb_rextsize;
}
+/* Convert an rt block number into an rt extent number. */
+static inline xfs_rtxnum_t
+xfs_rtb_to_rtx(
+ struct xfs_mount *mp,
+ xfs_rtblock_t rtbno)
+{
+ return div_u64(rtbno, mp->m_sb.sb_rextsize);
+}
+
+/* Return the offset of an rt block number within an rt extent. */
+static inline xfs_extlen_t
+xfs_rtb_to_rtxoff(
+ struct xfs_mount *mp,
+ xfs_rtblock_t rtbno)
+{
+ return do_div(rtbno, mp->m_sb.sb_rextsize);
+}
+
+/*
+ * Crack an rt block number into an rt extent number and an offset within that
+ * rt extent. Returns the rt extent number directly and the offset in @off.
+ */
+static inline xfs_rtxnum_t
+xfs_rtb_to_rtxrem(
+ struct xfs_mount *mp,
+ xfs_rtblock_t rtbno,
+ xfs_extlen_t *off)
+{
+ return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off);
+}
+
/*
* Functions for walking free space rtextents in the realtime bitmap.
*/
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 14/35] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (12 preceding siblings ...)
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 ` cem
2024-02-15 12:08 ` [PATCH 15/35] xfs: create rt extent rounding helpers for realtime extent blocks cem
` (21 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 055641248f649b52620a5fe8774bea253690e057
Convert these calls to use the helpers, and clean up all these places
where the same variable can have different units depending on where it
is in the function.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_bmap.c | 8 ++------
libxfs/xfs_rtbitmap.h | 14 ++++++++++++++
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index 6d7fa88f9..8fde0dc25 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -4820,12 +4820,8 @@ xfs_bmap_del_extent_delay(
ASSERT(got->br_startoff <= del->br_startoff);
ASSERT(got_endoff >= del_endoff);
- if (isrt) {
- uint64_t rtexts = del->br_blockcount;
-
- do_div(rtexts, mp->m_sb.sb_rextsize);
- xfs_mod_frextents(mp, rtexts);
- }
+ if (isrt)
+ xfs_mod_frextents(mp, xfs_rtb_to_rtx(mp, del->br_blockcount));
/*
* Update the inode delalloc counter now and wait to update the
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 9df583083..ff901bf3d 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -70,6 +70,20 @@ xfs_rtb_to_rtxrem(
return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off);
}
+/*
+ * Convert an rt block number into an rt extent number, rounding up to the next
+ * rt extent if the rt block is not aligned to an rt extent boundary.
+ */
+static inline xfs_rtxnum_t
+xfs_rtb_to_rtxup(
+ struct xfs_mount *mp,
+ xfs_rtblock_t rtbno)
+{
+ if (do_div(rtbno, mp->m_sb.sb_rextsize))
+ rtbno++;
+ return rtbno;
+}
+
/*
* Functions for walking free space rtextents in the realtime bitmap.
*/
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 15/35] xfs: create rt extent rounding helpers for realtime extent blocks
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (13 preceding siblings ...)
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 ` cem
2024-02-15 12:08 ` [PATCH 16/35] xfs: use shifting and masking when converting rt extents, if possible cem
` (20 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 5f57f7309d9ab9d24d50c5707472b1ed8af4eabc
Create a pair of functions to round rtblock numbers up or down to the
nearest rt extent.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index ff901bf3d..ecf5645dd 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -84,6 +84,24 @@ xfs_rtb_to_rtxup(
return rtbno;
}
+/* Round this rtblock up to the nearest rt extent size. */
+static inline xfs_rtblock_t
+xfs_rtb_roundup_rtx(
+ struct xfs_mount *mp,
+ xfs_rtblock_t rtbno)
+{
+ return roundup_64(rtbno, mp->m_sb.sb_rextsize);
+}
+
+/* Round this rtblock down to the nearest rt extent size. */
+static inline xfs_rtblock_t
+xfs_rtb_rounddown_rtx(
+ struct xfs_mount *mp,
+ xfs_rtblock_t rtbno)
+{
+ return rounddown_64(rtbno, mp->m_sb.sb_rextsize);
+}
+
/*
* Functions for walking free space rtextents in the realtime bitmap.
*/
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 16/35] xfs: use shifting and masking when converting rt extents, if possible
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (14 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 15/35] xfs: create rt extent rounding helpers for realtime extent blocks cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 17/35] xfs: convert the rtbitmap block and bit macros to static inline functions cem
` (19 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: ef5a83b7e597038d1c734ddb4bc00638082c2bf1
Avoid the costs of integer division (32-bit and 64-bit) if the realtime
extent size is a power of two.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
include/xfs_mount.h | 2 ++
libxfs/libxfs_priv.h | 24 ++++++++++++++++++++++++
libxfs/xfs_rtbitmap.h | 29 +++++++++++++++++++++++++++++
libxfs/xfs_sb.c | 2 ++
4 files changed, 57 insertions(+)
diff --git a/include/xfs_mount.h b/include/xfs_mount.h
index 9adc1f898..98d5b199d 100644
--- a/include/xfs_mount.h
+++ b/include/xfs_mount.h
@@ -71,6 +71,7 @@ typedef struct xfs_mount {
uint8_t m_blkbb_log; /* blocklog - BBSHIFT */
uint8_t m_sectbb_log; /* sectorlog - BBSHIFT */
uint8_t m_agno_log; /* log #ag's */
+ int8_t m_rtxblklog; /* log2 of rextsize, if possible */
uint m_blockmask; /* sb_blocksize-1 */
uint m_blockwsize; /* sb_blocksize in words */
uint m_blockwmask; /* blockwsize-1 */
@@ -93,6 +94,7 @@ typedef struct xfs_mount {
struct radix_tree_root m_perag_tree;
uint64_t m_features; /* active filesystem features */
uint64_t m_low_space[XFS_LOWSP_MAX];
+ uint64_t m_rtxblkmask; /* rt extent block mask */
unsigned long m_opstate; /* dynamic state flags */
bool m_finobt_nores; /* no per-AG finobt resv. */
uint m_qflags; /* quota status flags */
diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index ed437e38e..30ff8dba9 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -323,6 +323,30 @@ roundup_pow_of_two(uint v)
return 0;
}
+/* If @b is a power of 2, return log2(b). Else return -1. */
+static inline int8_t log2_if_power2(unsigned long b)
+{
+ unsigned long mask = 1;
+ unsigned int i;
+ unsigned int ret = 1;
+
+ if (!is_power_of_2(b))
+ return -1;
+
+ for (i = 0; i < NBBY * sizeof(unsigned long); i++, mask <<= 1) {
+ if (b & mask)
+ ret = i;
+ }
+
+ return ret;
+}
+
+/* If @b is a power of 2, return a mask of the lower bits, else return zero. */
+static inline unsigned long long mask64_if_power2(unsigned long b)
+{
+ return is_power_of_2(b) ? b - 1 : 0;
+}
+
/* buffer management */
#define XBF_TRYLOCK 0
#define XBF_UNMAPPED 0
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index ecf5645dd..3686a53e0 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -11,6 +11,9 @@ xfs_rtx_to_rtb(
struct xfs_mount *mp,
xfs_rtxnum_t rtx)
{
+ if (mp->m_rtxblklog >= 0)
+ return rtx << mp->m_rtxblklog;
+
return rtx * mp->m_sb.sb_rextsize;
}
@@ -19,6 +22,9 @@ xfs_rtxlen_to_extlen(
struct xfs_mount *mp,
xfs_rtxlen_t rtxlen)
{
+ if (mp->m_rtxblklog >= 0)
+ return rtxlen << mp->m_rtxblklog;
+
return rtxlen * mp->m_sb.sb_rextsize;
}
@@ -28,6 +34,9 @@ xfs_extlen_to_rtxmod(
struct xfs_mount *mp,
xfs_extlen_t len)
{
+ if (mp->m_rtxblklog >= 0)
+ return len & mp->m_rtxblkmask;
+
return len % mp->m_sb.sb_rextsize;
}
@@ -36,6 +45,9 @@ xfs_extlen_to_rtxlen(
struct xfs_mount *mp,
xfs_extlen_t len)
{
+ if (mp->m_rtxblklog >= 0)
+ return len >> mp->m_rtxblklog;
+
return len / mp->m_sb.sb_rextsize;
}
@@ -45,6 +57,9 @@ xfs_rtb_to_rtx(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
+ if (likely(mp->m_rtxblklog >= 0))
+ return rtbno >> mp->m_rtxblklog;
+
return div_u64(rtbno, mp->m_sb.sb_rextsize);
}
@@ -54,6 +69,9 @@ xfs_rtb_to_rtxoff(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
+ if (likely(mp->m_rtxblklog >= 0))
+ return rtbno & mp->m_rtxblkmask;
+
return do_div(rtbno, mp->m_sb.sb_rextsize);
}
@@ -67,6 +85,11 @@ xfs_rtb_to_rtxrem(
xfs_rtblock_t rtbno,
xfs_extlen_t *off)
{
+ if (likely(mp->m_rtxblklog >= 0)) {
+ *off = rtbno & mp->m_rtxblkmask;
+ return rtbno >> mp->m_rtxblklog;
+ }
+
return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off);
}
@@ -79,6 +102,12 @@ xfs_rtb_to_rtxup(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
+ if (likely(mp->m_rtxblklog >= 0)) {
+ if (rtbno & mp->m_rtxblkmask)
+ return (rtbno >> mp->m_rtxblklog) + 1;
+ return rtbno >> mp->m_rtxblklog;
+ }
+
if (do_div(rtbno, mp->m_sb.sb_rextsize))
rtbno++;
return rtbno;
diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c
index 01935017c..1ebdb7ec4 100644
--- a/libxfs/xfs_sb.c
+++ b/libxfs/xfs_sb.c
@@ -973,6 +973,8 @@ xfs_sb_mount_common(
mp->m_blockmask = sbp->sb_blocksize - 1;
mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG;
mp->m_blockwmask = mp->m_blockwsize - 1;
+ mp->m_rtxblklog = log2_if_power2(sbp->sb_rextsize);
+ mp->m_rtxblkmask = mask64_if_power2(sbp->sb_rextsize);
mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1);
mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0);
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 17/35] xfs: convert the rtbitmap block and bit macros to static inline functions
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (15 preceding siblings ...)
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 ` cem
2024-02-15 12:08 ` [PATCH 18/35] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros cem
` (18 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 90d98a6ada1da0f8797ff3f5adafd175dd8c0a81
Replace these macros with typechecked helper functions. Eventually
we're going to add more logic to the helpers and it'll be easier if we
don't have to macro it up.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_format.h | 5 -----
libxfs/xfs_rtbitmap.c | 30 +++++++++++++++---------------
libxfs/xfs_rtbitmap.h | 27 +++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h
index 20acb8573..0e2ee8202 100644
--- a/libxfs/xfs_format.h
+++ b/libxfs/xfs_format.h
@@ -1155,11 +1155,6 @@ static inline bool xfs_dinode_has_large_extent_counts(
((xfs_suminfo_t *)((bp)->b_addr + \
(((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
-#define XFS_BITTOBLOCK(mp,bi) ((bi) >> (mp)->m_blkbit_log)
-#define XFS_BLOCKTOBIT(mp,bb) ((bb) << (mp)->m_blkbit_log)
-#define XFS_BITTOWORD(mp,bi) \
- ((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(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 48e709a28..540cb1481 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -109,12 +109,12 @@ xfs_rtfind_back(
xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t want; /* mask for "good" values */
xfs_rtword_t wdiff; /* difference from wanted value */
- int word; /* word number in the buffer */
+ unsigned int word; /* word number in the buffer */
/*
* Compute and read in starting bitmap block for starting block.
*/
- block = XFS_BITTOBLOCK(mp, start);
+ block = xfs_rtx_to_rbmblock(mp, start);
error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
if (error) {
return error;
@@ -123,7 +123,7 @@ xfs_rtfind_back(
/*
* Get the first word's index & point to it.
*/
- word = XFS_BITTOWORD(mp, start);
+ word = xfs_rtx_to_rbmword(mp, start);
b = &bufp[word];
bit = (int)(start & (XFS_NBWORD - 1));
len = start - limit + 1;
@@ -284,12 +284,12 @@ xfs_rtfind_forw(
xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t want; /* mask for "good" values */
xfs_rtword_t wdiff; /* difference from wanted value */
- int word; /* word number in the buffer */
+ unsigned int word; /* word number in the buffer */
/*
* Compute and read in starting bitmap block for starting block.
*/
- block = XFS_BITTOBLOCK(mp, start);
+ block = xfs_rtx_to_rbmblock(mp, start);
error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
if (error) {
return error;
@@ -298,7 +298,7 @@ xfs_rtfind_forw(
/*
* Get the first word's index & point to it.
*/
- word = XFS_BITTOWORD(mp, start);
+ word = xfs_rtx_to_rbmword(mp, start);
b = &bufp[word];
bit = (int)(start & (XFS_NBWORD - 1));
len = limit - start + 1;
@@ -545,12 +545,12 @@ xfs_rtmodify_range(
int i; /* current bit number rel. to start */
int lastbit; /* last useful bit in word */
xfs_rtword_t mask; /* mask o frelevant bits for value */
- int word; /* word number in the buffer */
+ unsigned int word; /* word number in the buffer */
/*
* Compute starting bitmap block number.
*/
- block = XFS_BITTOBLOCK(mp, start);
+ block = xfs_rtx_to_rbmblock(mp, start);
/*
* Read the bitmap block, and point to its data.
*/
@@ -562,7 +562,7 @@ xfs_rtmodify_range(
/*
* Compute the starting word's address, and starting bit.
*/
- word = XFS_BITTOWORD(mp, start);
+ word = xfs_rtx_to_rbmword(mp, start);
first = b = &bufp[word];
bit = (int)(start & (XFS_NBWORD - 1));
/*
@@ -728,7 +728,7 @@ xfs_rtfree_range(
if (preblock < start) {
error = xfs_rtmodify_summary(mp, tp,
XFS_RTBLOCKLOG(start - preblock),
- XFS_BITTOBLOCK(mp, preblock), -1, rbpp, rsb);
+ xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb);
if (error) {
return error;
}
@@ -740,7 +740,7 @@ xfs_rtfree_range(
if (postblock > end) {
error = xfs_rtmodify_summary(mp, tp,
XFS_RTBLOCKLOG(postblock - end),
- XFS_BITTOBLOCK(mp, end + 1), -1, rbpp, rsb);
+ xfs_rtx_to_rbmblock(mp, end + 1), -1, rbpp, rsb);
if (error) {
return error;
}
@@ -751,7 +751,7 @@ xfs_rtfree_range(
*/
error = xfs_rtmodify_summary(mp, tp,
XFS_RTBLOCKLOG(postblock + 1 - preblock),
- XFS_BITTOBLOCK(mp, preblock), 1, rbpp, rsb);
+ xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb);
return error;
}
@@ -779,12 +779,12 @@ xfs_rtcheck_range(
xfs_rtxnum_t lastbit; /* last useful bit in word */
xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t wdiff; /* difference from wanted value */
- int word; /* word number in the buffer */
+ unsigned int word; /* word number in the buffer */
/*
* Compute starting bitmap block number
*/
- block = XFS_BITTOBLOCK(mp, start);
+ block = xfs_rtx_to_rbmblock(mp, start);
/*
* Read the bitmap block.
*/
@@ -796,7 +796,7 @@ xfs_rtcheck_range(
/*
* Compute the starting word's address, and starting bit.
*/
- word = XFS_BITTOWORD(mp, start);
+ word = xfs_rtx_to_rbmword(mp, start);
b = &bufp[word];
bit = (int)(start & (XFS_NBWORD - 1));
/*
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 3686a53e0..5c4325702 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -131,6 +131,33 @@ xfs_rtb_rounddown_rtx(
return rounddown_64(rtbno, mp->m_sb.sb_rextsize);
}
+/* Convert an rt extent number to a file block offset in the rt bitmap file. */
+static inline xfs_fileoff_t
+xfs_rtx_to_rbmblock(
+ struct xfs_mount *mp,
+ xfs_rtxnum_t rtx)
+{
+ return rtx >> mp->m_blkbit_log;
+}
+
+/* Convert an rt extent number to a word offset within an rt bitmap block. */
+static inline unsigned int
+xfs_rtx_to_rbmword(
+ struct xfs_mount *mp,
+ xfs_rtxnum_t rtx)
+{
+ return (rtx >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp);
+}
+
+/* Convert a file block offset in the rt bitmap file to an rt extent number. */
+static inline xfs_rtxnum_t
+xfs_rbmblock_to_rtx(
+ struct xfs_mount *mp,
+ xfs_fileoff_t rbmoff)
+{
+ return rbmoff << mp->m_blkbit_log;
+}
+
/*
* Functions for walking free space rtextents in the realtime bitmap.
*/
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 18/35] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (16 preceding siblings ...)
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 ` cem
2024-02-15 12:08 ` [PATCH 19/35] xfs: convert open-coded xfs_rtword_t pointer accesses to helper cem
` (17 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: add3cddaea509071d01bf1d34df0d05db1a93a07
Remove these trivial macros since they're not even part of the ondisk
format.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_format.h | 2 --
libxfs/xfs_rtbitmap.c | 16 ++++++++--------
libxfs/xfs_rtbitmap.h | 2 +-
3 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h
index 0e2ee8202..ac6dd1023 100644
--- a/libxfs/xfs_format.h
+++ b/libxfs/xfs_format.h
@@ -1142,8 +1142,6 @@ static inline bool xfs_dinode_has_large_extent_counts(
#define XFS_BLOCKSIZE(mp) ((mp)->m_sb.sb_blocksize)
#define XFS_BLOCKMASK(mp) ((mp)->m_blockmask)
-#define XFS_BLOCKWSIZE(mp) ((mp)->m_blockwsize)
-#define XFS_BLOCKWMASK(mp) ((mp)->m_blockwmask)
/*
* RT Summary and bit manipulation macros.
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 540cb1481..6776e45c1 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -172,7 +172,7 @@ xfs_rtfind_back(
return error;
}
bufp = bp->b_addr;
- word = XFS_BLOCKWMASK(mp);
+ word = mp->m_blockwsize - 1;
b = &bufp[word];
} else {
/*
@@ -218,7 +218,7 @@ xfs_rtfind_back(
return error;
}
bufp = bp->b_addr;
- word = XFS_BLOCKWMASK(mp);
+ word = mp->m_blockwsize - 1;
b = &bufp[word];
} else {
/*
@@ -336,7 +336,7 @@ xfs_rtfind_forw(
* Go on to next block if that's where the next word is
* and we need the next word.
*/
- if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+ if (++word == mp->m_blockwsize && i < len) {
/*
* If done with this block, get the previous one.
*/
@@ -381,7 +381,7 @@ xfs_rtfind_forw(
* Go on to next block if that's where the next word is
* and we need the next word.
*/
- if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+ if (++word == mp->m_blockwsize && i < len) {
/*
* If done with this block, get the next one.
*/
@@ -591,7 +591,7 @@ xfs_rtmodify_range(
* Go on to the next block if that's where the next word is
* and we need the next word.
*/
- if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+ if (++word == mp->m_blockwsize && i < len) {
/*
* Log the changed part of this block.
* Get the next one.
@@ -631,7 +631,7 @@ xfs_rtmodify_range(
* Go on to the next block if that's where the next word is
* and we need the next word.
*/
- if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+ if (++word == mp->m_blockwsize && i < len) {
/*
* Log the changed part of this block.
* Get the next one.
@@ -834,7 +834,7 @@ xfs_rtcheck_range(
* Go on to next block if that's where the next word is
* and we need the next word.
*/
- if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+ if (++word == mp->m_blockwsize && i < len) {
/*
* If done with this block, get the next one.
*/
@@ -880,7 +880,7 @@ xfs_rtcheck_range(
* Go on to next block if that's where the next word is
* and we need the next word.
*/
- if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
+ if (++word == mp->m_blockwsize && i < len) {
/*
* If done with this block, get the next one.
*/
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 5c4325702..a382b38c6 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -146,7 +146,7 @@ xfs_rtx_to_rbmword(
struct xfs_mount *mp,
xfs_rtxnum_t rtx)
{
- return (rtx >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp);
+ return (rtx >> XFS_NBWORDLOG) & (mp->m_blockwsize - 1);
}
/* Convert a file block offset in the rt bitmap file to an rt extent number. */
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 19/35] xfs: convert open-coded xfs_rtword_t pointer accesses to helper
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (17 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 18/35] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 20/35] xfs: convert rt summary macros to helpers cem
` (16 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: a9948626849c2c65dfd201b5e9d855e62937de61
There are a bunch of places where we use open-coded logic to find a
pointer to an xfs_rtword_t within a rt bitmap buffer. Convert all that
to helper functions for better type safety.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 59 +++++++++++++++++++++++--------------------
libxfs/xfs_rtbitmap.h | 11 ++++++++
2 files changed, 42 insertions(+), 28 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 6776e45c1..fce88c759 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -101,7 +101,6 @@ xfs_rtfind_back(
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
- xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */
xfs_rtxnum_t firstbit; /* first useful bit in the word */
xfs_rtxnum_t i; /* current bit number rel. to start */
@@ -119,12 +118,12 @@ xfs_rtfind_back(
if (error) {
return error;
}
- bufp = bp->b_addr;
+
/*
* Get the first word's index & point to it.
*/
word = xfs_rtx_to_rbmword(mp, start);
- b = &bufp[word];
+ b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1));
len = start - limit + 1;
/*
@@ -171,9 +170,9 @@ xfs_rtfind_back(
if (error) {
return error;
}
- bufp = bp->b_addr;
+
word = mp->m_blockwsize - 1;
- b = &bufp[word];
+ b = xfs_rbmblock_wordptr(bp, word);
} else {
/*
* Go on to the previous word in the buffer.
@@ -217,9 +216,9 @@ xfs_rtfind_back(
if (error) {
return error;
}
- bufp = bp->b_addr;
+
word = mp->m_blockwsize - 1;
- b = &bufp[word];
+ b = xfs_rbmblock_wordptr(bp, word);
} else {
/*
* Go on to the previous word in the buffer.
@@ -276,7 +275,6 @@ xfs_rtfind_forw(
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
- xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */
xfs_rtxnum_t i; /* current bit number rel. to start */
xfs_rtxnum_t lastbit; /* last useful bit in the word */
@@ -294,12 +292,12 @@ xfs_rtfind_forw(
if (error) {
return error;
}
- bufp = bp->b_addr;
+
/*
* Get the first word's index & point to it.
*/
word = xfs_rtx_to_rbmword(mp, start);
- b = &bufp[word];
+ b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1));
len = limit - start + 1;
/*
@@ -345,8 +343,9 @@ xfs_rtfind_forw(
if (error) {
return error;
}
- b = bufp = bp->b_addr;
+
word = 0;
+ b = xfs_rbmblock_wordptr(bp, word);
} else {
/*
* Go on to the previous word in the buffer.
@@ -390,8 +389,9 @@ xfs_rtfind_forw(
if (error) {
return error;
}
- b = bufp = bp->b_addr;
+
word = 0;
+ b = xfs_rbmblock_wordptr(bp, word);
} else {
/*
* Go on to the next word in the buffer.
@@ -539,7 +539,6 @@ xfs_rtmodify_range(
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
- xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */
xfs_rtword_t *first; /* first used word in the buffer */
int i; /* current bit number rel. to start */
@@ -558,12 +557,12 @@ xfs_rtmodify_range(
if (error) {
return error;
}
- bufp = bp->b_addr;
+
/*
* Compute the starting word's address, and starting bit.
*/
word = xfs_rtx_to_rbmword(mp, start);
- first = b = &bufp[word];
+ first = b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1));
/*
* 0 (allocated) => all zeroes; 1 (free) => all ones.
@@ -597,14 +596,15 @@ xfs_rtmodify_range(
* Get the next one.
*/
xfs_trans_log_buf(tp, bp,
- (uint)((char *)first - (char *)bufp),
- (uint)((char *)b - (char *)bufp));
+ (uint)((char *)first - (char *)bp->b_addr),
+ (uint)((char *)b - (char *)bp->b_addr));
error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
if (error) {
return error;
}
- first = b = bufp = bp->b_addr;
+
word = 0;
+ first = b = xfs_rbmblock_wordptr(bp, word);
} else {
/*
* Go on to the next word in the buffer
@@ -637,14 +637,15 @@ xfs_rtmodify_range(
* Get the next one.
*/
xfs_trans_log_buf(tp, bp,
- (uint)((char *)first - (char *)bufp),
- (uint)((char *)b - (char *)bufp));
+ (uint)((char *)first - (char *)bp->b_addr),
+ (uint)((char *)b - (char *)bp->b_addr));
error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
if (error) {
return error;
}
- first = b = bufp = bp->b_addr;
+
word = 0;
+ first = b = xfs_rbmblock_wordptr(bp, word);
} else {
/*
* Go on to the next word in the buffer
@@ -674,8 +675,9 @@ xfs_rtmodify_range(
* Log any remaining changed bytes.
*/
if (b > first)
- xfs_trans_log_buf(tp, bp, (uint)((char *)first - (char *)bufp),
- (uint)((char *)b - (char *)bufp - 1));
+ xfs_trans_log_buf(tp, bp,
+ (uint)((char *)first - (char *)bp->b_addr),
+ (uint)((char *)b - (char *)bp->b_addr - 1));
return 0;
}
@@ -773,7 +775,6 @@ xfs_rtcheck_range(
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
- xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */
xfs_rtxnum_t i; /* current bit number rel. to start */
xfs_rtxnum_t lastbit; /* last useful bit in word */
@@ -792,12 +793,12 @@ xfs_rtcheck_range(
if (error) {
return error;
}
- bufp = bp->b_addr;
+
/*
* Compute the starting word's address, and starting bit.
*/
word = xfs_rtx_to_rbmword(mp, start);
- b = &bufp[word];
+ b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1));
/*
* 0 (allocated) => all zero's; 1 (free) => all one's.
@@ -843,8 +844,9 @@ xfs_rtcheck_range(
if (error) {
return error;
}
- b = bufp = bp->b_addr;
+
word = 0;
+ b = xfs_rbmblock_wordptr(bp, word);
} else {
/*
* Go on to the next word in the buffer.
@@ -889,8 +891,9 @@ xfs_rtcheck_range(
if (error) {
return error;
}
- b = bufp = bp->b_addr;
+
word = 0;
+ b = xfs_rbmblock_wordptr(bp, word);
} else {
/*
* Go on to the next word in the buffer.
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index a382b38c6..3252ed217 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -158,6 +158,17 @@ xfs_rbmblock_to_rtx(
return rbmoff << mp->m_blkbit_log;
}
+/* Return a pointer to a bitmap word within a rt bitmap block. */
+static inline xfs_rtword_t *
+xfs_rbmblock_wordptr(
+ struct xfs_buf *bp,
+ unsigned int index)
+{
+ xfs_rtword_t *words = bp->b_addr;
+
+ return words + index;
+}
+
/*
* Functions for walking free space rtextents in the realtime bitmap.
*/
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 20/35] xfs: convert rt summary macros to helpers
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (18 preceding siblings ...)
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
2024-02-15 12:08 ` [PATCH 21/35] xfs: convert to new timestamp accessors cem
` (15 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
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
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 21/35] xfs: convert to new timestamp accessors
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (19 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 20/35] xfs: convert rt summary macros to helpers cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 22/35] xfs: create helpers for rtbitmap block/wordcount computations cem
` (14 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: Jeff Layton <jlayton@kernel.org>
Source kernel commit: 75d1e312bbbd175fa27ffdd4c4fe9e8cc7d047ec
Convert to using the new inode timestamp accessor functions.
[Carlos: Also partially port 077c212f0344ae and 12cd4402365166]
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Link: https://lore.kernel.org/r/20231004185347.80880-75-jlayton@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
include/xfs_inode.h | 74 ++++++++++++++++++++++++++++++++++++++--
libxfs/util.c | 2 +-
libxfs/xfs_inode_buf.c | 10 +++---
libxfs/xfs_rtbitmap.c | 6 +++-
libxfs/xfs_trans_inode.c | 2 +-
mkfs/proto.c | 2 +-
6 files changed, 86 insertions(+), 10 deletions(-)
diff --git a/include/xfs_inode.h b/include/xfs_inode.h
index 986815e5c..a351bb0d9 100644
--- a/include/xfs_inode.h
+++ b/include/xfs_inode.h
@@ -41,8 +41,8 @@ struct inode {
unsigned long i_state; /* Not actually used in userspace */
uint32_t i_generation;
uint64_t i_version;
- struct timespec64 i_atime;
- struct timespec64 i_mtime;
+ struct timespec64 __i_atime;
+ struct timespec64 __i_mtime;
struct timespec64 __i_ctime; /* use inode_*_ctime accessors! */
spinlock_t i_lock;
};
@@ -69,6 +69,76 @@ static inline void ihold(struct inode *inode)
inode->i_count++;
}
+static inline time64_t inode_get_atime_sec(const struct inode *inode)
+{
+ return inode->__i_atime.tv_sec;
+}
+
+static inline long inode_get_atime_nsec(const struct inode *inode)
+{
+ return inode->__i_atime.tv_nsec;
+}
+
+static inline struct timespec64 inode_get_atime(const struct inode *inode)
+{
+ return inode->__i_atime;
+}
+
+static inline struct timespec64 inode_set_atime_to_ts(struct inode *inode,
+ struct timespec64 ts)
+{
+ inode->__i_atime = ts;
+ return ts;
+}
+
+static inline struct timespec64 inode_set_atime(struct inode *inode,
+ time64_t sec, long nsec)
+{
+ struct timespec64 ts = { .tv_sec = sec,
+ .tv_nsec = nsec };
+ return inode_set_atime_to_ts(inode, ts);
+}
+
+static inline time64_t inode_get_mtime_sec(const struct inode *inode)
+{
+ return inode->__i_mtime.tv_sec;
+}
+
+static inline long inode_get_mtime_nsec(const struct inode *inode)
+{
+ return inode->__i_mtime.tv_nsec;
+}
+
+static inline struct timespec64 inode_get_mtime(const struct inode *inode)
+{
+ return inode->__i_mtime;
+}
+
+static inline struct timespec64 inode_set_mtime_to_ts(struct inode *inode,
+ struct timespec64 ts)
+{
+ inode->__i_mtime = ts;
+ return ts;
+}
+
+static inline struct timespec64 inode_set_mtime(struct inode *inode,
+ time64_t sec, long nsec)
+{
+ struct timespec64 ts = { .tv_sec = sec,
+ .tv_nsec = nsec };
+ return inode_set_mtime_to_ts(inode, ts);
+}
+
+static inline time64_t inode_get_ctime_sec(const struct inode *inode)
+{
+ return inode->__i_ctime.tv_sec;
+}
+
+static inline long inode_get_ctime_nsec(const struct inode *inode)
+{
+ return inode->__i_ctime.tv_nsec;
+}
+
static inline struct timespec64 inode_get_ctime(const struct inode *inode)
{
return inode->__i_ctime;
diff --git a/libxfs/util.c b/libxfs/util.c
index 8f79b0cd1..8517bfb64 100644
--- a/libxfs/util.c
+++ b/libxfs/util.c
@@ -291,7 +291,7 @@ libxfs_init_new_inode(
if (!pip)
ip->i_diflags2 = xfs_flags2diflags2(ip,
fsx->fsx_xflags);
- ip->i_crtime = VFS_I(ip)->i_mtime; /* struct copy */
+ ip->i_crtime = inode_get_mtime(VFS_I(ip)); /* struct copy */
ip->i_cowextsize = pip ? 0 : fsx->fsx_cowextsize;
}
diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c
index fccab4193..74a1bd227 100644
--- a/libxfs/xfs_inode_buf.c
+++ b/libxfs/xfs_inode_buf.c
@@ -217,8 +217,10 @@ xfs_inode_from_disk(
* a time before epoch is converted to a time long after epoch
* on 64 bit systems.
*/
- inode->i_atime = xfs_inode_from_disk_ts(from, from->di_atime);
- inode->i_mtime = xfs_inode_from_disk_ts(from, from->di_mtime);
+ inode_set_atime_to_ts(inode,
+ xfs_inode_from_disk_ts(from, from->di_atime));
+ inode_set_mtime_to_ts(inode,
+ xfs_inode_from_disk_ts(from, from->di_mtime));
inode_set_ctime_to_ts(inode,
xfs_inode_from_disk_ts(from, from->di_ctime));
@@ -312,8 +314,8 @@ xfs_inode_to_disk(
to->di_projid_lo = cpu_to_be16(ip->i_projid & 0xffff);
to->di_projid_hi = cpu_to_be16(ip->i_projid >> 16);
- to->di_atime = xfs_inode_to_disk_ts(ip, inode->i_atime);
- to->di_mtime = xfs_inode_to_disk_ts(ip, inode->i_mtime);
+ to->di_atime = xfs_inode_to_disk_ts(ip, inode_get_atime(inode));
+ to->di_mtime = xfs_inode_to_disk_ts(ip, inode_get_mtime(inode));
to->di_ctime = xfs_inode_to_disk_ts(ip, inode_get_ctime(inode));
to->di_nlink = cpu_to_be32(inode->i_nlink);
to->di_gen = cpu_to_be32(inode->i_generation);
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index c635e8c2e..9a8bd93b7 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -974,6 +974,7 @@ xfs_rtfree_extent(
xfs_mount_t *mp; /* file system mount structure */
xfs_fsblock_t sb; /* summary file block number */
struct xfs_buf *sumbp = NULL; /* summary file block buffer */
+ struct timespec64 atime;
mp = tp->t_mountp;
@@ -1003,7 +1004,10 @@ xfs_rtfree_extent(
mp->m_sb.sb_rextents) {
if (!(mp->m_rbmip->i_diflags & XFS_DIFLAG_NEWRTBM))
mp->m_rbmip->i_diflags |= XFS_DIFLAG_NEWRTBM;
- *(uint64_t *)&VFS_I(mp->m_rbmip)->i_atime = 0;
+
+ atime = inode_get_atime(VFS_I(mp->m_rbmip));
+ atime.tv_sec = 0;
+ inode_set_atime_to_ts(VFS_I(mp->m_rbmip), atime);
xfs_trans_log_inode(tp, mp->m_rbmip, XFS_ILOG_CORE);
}
return 0;
diff --git a/libxfs/xfs_trans_inode.c b/libxfs/xfs_trans_inode.c
index ca8e82376..c171a525c 100644
--- a/libxfs/xfs_trans_inode.c
+++ b/libxfs/xfs_trans_inode.c
@@ -62,7 +62,7 @@ xfs_trans_ichgtime(
tv = current_time(inode);
if (flags & XFS_ICHGTIME_MOD)
- inode->i_mtime = tv;
+ inode_set_mtime_to_ts(inode, tv);
if (flags & XFS_ICHGTIME_CHG)
inode_set_ctime_to_ts(inode, tv);
if (flags & XFS_ICHGTIME_CREATE)
diff --git a/mkfs/proto.c b/mkfs/proto.c
index ea31cfe5c..e9c633ed3 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -688,7 +688,7 @@ rtinit(
mp->m_sb.sb_rbmino = rbmip->i_ino;
rbmip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize;
rbmip->i_diflags = XFS_DIFLAG_NEWRTBM;
- *(uint64_t *)&VFS_I(rbmip)->i_atime = 0;
+ inode_set_atime(VFS_I(rbmip), 0, 0);
libxfs_trans_log_inode(tp, rbmip, XFS_ILOG_CORE);
libxfs_log_sb(tp);
mp->m_rbmip = rbmip;
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 22/35] xfs: create helpers for rtbitmap block/wordcount computations
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (20 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 21/35] xfs: convert to new timestamp accessors cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 23/35] xfs: create a helper to handle logging parts of rt bitmap/summary blocks cem
` (13 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: d0448fe76ac1a9ccbce574577a4c82246d17eec4
Create helper functions that compute the number of blocks or words
necessary to store the rt bitmap.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 27 +++++++++++++++++++++++++++
libxfs/xfs_rtbitmap.h | 12 ++++++++++++
libxfs/xfs_trans_resv.c | 9 +++++----
3 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 9a8bd93b7..92473d4a5 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -1137,3 +1137,30 @@ xfs_rtalloc_extent_is_free(
*is_free = matches;
return 0;
}
+
+/*
+ * Compute the number of rtbitmap blocks needed to track the given number of rt
+ * extents.
+ */
+xfs_filblks_t
+xfs_rtbitmap_blockcount(
+ struct xfs_mount *mp,
+ xfs_rtbxlen_t rtextents)
+{
+ return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize);
+}
+
+/*
+ * Compute the number of rtbitmap words needed to populate every block of a
+ * bitmap that is large enough to track the given number of rt extents.
+ */
+unsigned long long
+xfs_rtbitmap_wordcount(
+ struct xfs_mount *mp,
+ xfs_rtbxlen_t rtextents)
+{
+ xfs_filblks_t blocks;
+
+ blocks = xfs_rtbitmap_blockcount(mp, rtextents);
+ return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
+}
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 167ea6a08..618c96468 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -283,6 +283,11 @@ xfs_rtfree_extent(
/* Same as above, but in units of rt blocks. */
int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
xfs_filblks_t rtlen);
+
+xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t
+ rtextents);
+unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp,
+ xfs_rtbxlen_t rtextents);
#else /* CONFIG_XFS_RT */
# define xfs_rtfree_extent(t,b,l) (-ENOSYS)
# define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS)
@@ -290,6 +295,13 @@ int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
# define xfs_rtalloc_query_all(m,t,f,p) (-ENOSYS)
# define xfs_rtbuf_get(m,t,b,i,p) (-ENOSYS)
# define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS)
+static inline xfs_filblks_t
+xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
+{
+ /* shut up gcc */
+ return 0;
+}
+# define xfs_rtbitmap_wordcount(mp, r) (0)
#endif /* CONFIG_XFS_RT */
#endif /* __XFS_RTBITMAP_H__ */
diff --git a/libxfs/xfs_trans_resv.c b/libxfs/xfs_trans_resv.c
index 53c190b72..82b3d1522 100644
--- a/libxfs/xfs_trans_resv.c
+++ b/libxfs/xfs_trans_resv.c
@@ -217,11 +217,12 @@ xfs_rtalloc_block_count(
struct xfs_mount *mp,
unsigned int num_ops)
{
- unsigned int blksz = XFS_FSB_TO_B(mp, 1);
- unsigned int rtbmp_bytes;
+ unsigned int rtbmp_blocks;
+ xfs_rtxlen_t rtxlen;
- rtbmp_bytes = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN) / NBBY;
- return (howmany(rtbmp_bytes, blksz) + 1) * num_ops;
+ rtxlen = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN);
+ rtbmp_blocks = xfs_rtbitmap_blockcount(mp, rtxlen);
+ return (rtbmp_blocks + 1) * num_ops;
}
/*
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 23/35] xfs: create a helper to handle logging parts of rt bitmap/summary blocks
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (21 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 22/35] xfs: create helpers for rtbitmap block/wordcount computations cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 24/35] xfs: use accessor functions for bitmap words cem
` (12 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 312d61021b8947446aa9ec80b78b9230e8cb3691
Create an explicit helper function to log parts of rt bitmap and summary
blocks. While we're at it, fix an off-by-one error in two of the
rtbitmap logging calls that led to unnecessarily large log items but was
otherwise benign.
Note that the upcoming rtgroups patchset will add block headers to the
rtbitmap and rtsummary files. The helpers in this and the next few
patches take a less than direct route through xfs_rbmblock_wordptr and
xfs_rsumblock_infoptr to avoid helper churn in that patchset.
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 55 +++++++++++++++++++++++++++++++------------
1 file changed, 40 insertions(+), 15 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 92473d4a5..562b40a1a 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -430,6 +430,21 @@ xfs_rtfind_forw(
return 0;
}
+/* Log rtsummary counter at @infoword. */
+static inline void
+xfs_trans_log_rtsummary(
+ struct xfs_trans *tp,
+ struct xfs_buf *bp,
+ unsigned int infoword)
+{
+ size_t first, last;
+
+ first = (void *)xfs_rsumblock_infoptr(bp, infoword) - bp->b_addr;
+ last = first + sizeof(xfs_suminfo_t) - 1;
+
+ xfs_trans_log_buf(tp, bp, first, last);
+}
+
/*
* Read and/or modify the summary information for a given extent size,
* bitmap block combination.
@@ -495,8 +510,6 @@ xfs_rtmodify_summary_int(
infoword = xfs_rtsumoffs_to_infoword(mp, so);
sp = xfs_rsumblock_infoptr(bp, infoword);
if (delta) {
- uint first = (uint)((char *)sp - (char *)bp->b_addr);
-
*sp += delta;
if (mp->m_rsum_cache) {
if (*sp == 0 && log == mp->m_rsum_cache[bbno])
@@ -504,7 +517,7 @@ xfs_rtmodify_summary_int(
if (*sp != 0 && log < mp->m_rsum_cache[bbno])
mp->m_rsum_cache[bbno] = log;
}
- xfs_trans_log_buf(tp, bp, first, first + sizeof(*sp) - 1);
+ xfs_trans_log_rtsummary(tp, bp, infoword);
}
if (sum)
*sum = *sp;
@@ -525,6 +538,22 @@ xfs_rtmodify_summary(
delta, rbpp, rsb, NULL);
}
+/* Log rtbitmap block from the word @from to the byte before @next. */
+static inline void
+xfs_trans_log_rtbitmap(
+ struct xfs_trans *tp,
+ struct xfs_buf *bp,
+ unsigned int from,
+ unsigned int next)
+{
+ size_t first, last;
+
+ first = (void *)xfs_rbmblock_wordptr(bp, from) - bp->b_addr;
+ last = ((void *)xfs_rbmblock_wordptr(bp, next) - 1) - bp->b_addr;
+
+ xfs_trans_log_buf(tp, bp, first, last);
+}
+
/*
* Set the given range of bitmap bits to the given value.
* Do whatever I/O and logging is required.
@@ -546,6 +575,7 @@ xfs_rtmodify_range(
int i; /* current bit number rel. to start */
int lastbit; /* last useful bit in word */
xfs_rtword_t mask; /* mask o frelevant bits for value */
+ unsigned int firstword; /* first word used in the buffer */
unsigned int word; /* word number in the buffer */
/*
@@ -563,7 +593,7 @@ xfs_rtmodify_range(
/*
* Compute the starting word's address, and starting bit.
*/
- word = xfs_rtx_to_rbmword(mp, start);
+ firstword = word = xfs_rtx_to_rbmword(mp, start);
first = b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1));
/*
@@ -597,15 +627,13 @@ xfs_rtmodify_range(
* Log the changed part of this block.
* Get the next one.
*/
- xfs_trans_log_buf(tp, bp,
- (uint)((char *)first - (char *)bp->b_addr),
- (uint)((char *)b - (char *)bp->b_addr));
+ xfs_trans_log_rtbitmap(tp, bp, firstword, word);
error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
if (error) {
return error;
}
- word = 0;
+ firstword = word = 0;
first = b = xfs_rbmblock_wordptr(bp, word);
} else {
/*
@@ -638,15 +666,13 @@ xfs_rtmodify_range(
* Log the changed part of this block.
* Get the next one.
*/
- xfs_trans_log_buf(tp, bp,
- (uint)((char *)first - (char *)bp->b_addr),
- (uint)((char *)b - (char *)bp->b_addr));
+ xfs_trans_log_rtbitmap(tp, bp, firstword, word);
error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
if (error) {
return error;
}
- word = 0;
+ firstword = word = 0;
first = b = xfs_rbmblock_wordptr(bp, word);
} else {
/*
@@ -671,15 +697,14 @@ xfs_rtmodify_range(
*b |= mask;
else
*b &= ~mask;
+ word++;
b++;
}
/*
* Log any remaining changed bytes.
*/
if (b > first)
- xfs_trans_log_buf(tp, bp,
- (uint)((char *)first - (char *)bp->b_addr),
- (uint)((char *)b - (char *)bp->b_addr - 1));
+ xfs_trans_log_rtbitmap(tp, bp, firstword, word);
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 24/35] xfs: use accessor functions for bitmap words
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (22 preceding siblings ...)
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 ` cem
2024-02-15 12:08 ` [PATCH 25/35] xfs: create helpers for rtsummary block/wordcount computations cem
` (11 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 97e993830a1cdd86ad7d207308b9f55a00660edd
Create 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>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_format.h | 8 ++++
libxfs/xfs_rtbitmap.c | 109 +++++++++++++-----------------------------
libxfs/xfs_rtbitmap.h | 27 ++++++++++-
3 files changed, 67 insertions(+), 77 deletions(-)
diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h
index d48e3a395..2af891d5d 100644
--- a/libxfs/xfs_format.h
+++ b/libxfs/xfs_format.h
@@ -690,6 +690,14 @@ struct xfs_agfl {
ASSERT(xfs_daddr_to_agno(mp, d) == \
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;
+};
+
/*
* XFS Timestamps
* ==============
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 562b40a1a..f7be9ea5f 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -97,7 +97,6 @@ xfs_rtfind_back(
xfs_rtxnum_t limit, /* last rtext to look at */
xfs_rtxnum_t *rtx) /* out: start rtext found */
{
- xfs_rtword_t *b; /* current word in buffer */
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
@@ -108,6 +107,7 @@ xfs_rtfind_back(
xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t want; /* mask for "good" values */
xfs_rtword_t wdiff; /* difference from wanted value */
+ xfs_rtword_t incore;
unsigned int word; /* word number in the buffer */
/*
@@ -123,14 +123,14 @@ xfs_rtfind_back(
* Get the first word's index & point to it.
*/
word = xfs_rtx_to_rbmword(mp, start);
- b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1));
len = start - limit + 1;
/*
* Compute match value, based on the bit at start: if 1 (free)
* then all-ones, else all-zeroes.
*/
- want = (*b & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
+ incore = xfs_rtbitmap_getword(bp, word);
+ want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
/*
* If the starting position is not word-aligned, deal with the
* partial word.
@@ -147,7 +147,7 @@ xfs_rtfind_back(
* Calculate the difference between the value there
* and what we're looking for.
*/
- if ((wdiff = (*b ^ want) & mask)) {
+ if ((wdiff = (incore ^ want) & mask)) {
/*
* Different. Mark where we are and return.
*/
@@ -172,12 +172,6 @@ xfs_rtfind_back(
}
word = mp->m_blockwsize - 1;
- b = xfs_rbmblock_wordptr(bp, word);
- } else {
- /*
- * Go on to the previous word in the buffer.
- */
- b--;
}
} else {
/*
@@ -193,7 +187,8 @@ xfs_rtfind_back(
/*
* Compute difference between actual and desired value.
*/
- if ((wdiff = *b ^ want)) {
+ incore = xfs_rtbitmap_getword(bp, word);
+ if ((wdiff = incore ^ want)) {
/*
* Different, mark where we are and return.
*/
@@ -218,12 +213,6 @@ xfs_rtfind_back(
}
word = mp->m_blockwsize - 1;
- b = xfs_rbmblock_wordptr(bp, word);
- } else {
- /*
- * Go on to the previous word in the buffer.
- */
- b--;
}
}
/*
@@ -240,7 +229,8 @@ xfs_rtfind_back(
/*
* Compute difference between actual and desired value.
*/
- if ((wdiff = (*b ^ want) & mask)) {
+ incore = xfs_rtbitmap_getword(bp, word);
+ if ((wdiff = (incore ^ want) & mask)) {
/*
* Different, mark where we are and return.
*/
@@ -271,7 +261,6 @@ xfs_rtfind_forw(
xfs_rtxnum_t limit, /* last rtext to look at */
xfs_rtxnum_t *rtx) /* out: start rtext found */
{
- xfs_rtword_t *b; /* current word in buffer */
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
@@ -282,6 +271,7 @@ xfs_rtfind_forw(
xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t want; /* mask for "good" values */
xfs_rtword_t wdiff; /* difference from wanted value */
+ xfs_rtword_t incore;
unsigned int word; /* word number in the buffer */
/*
@@ -297,14 +287,14 @@ xfs_rtfind_forw(
* Get the first word's index & point to it.
*/
word = xfs_rtx_to_rbmword(mp, start);
- b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1));
len = limit - start + 1;
/*
* Compute match value, based on the bit at start: if 1 (free)
* then all-ones, else all-zeroes.
*/
- want = (*b & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
+ incore = xfs_rtbitmap_getword(bp, word);
+ want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
/*
* If the starting position is not word-aligned, deal with the
* partial word.
@@ -320,7 +310,7 @@ xfs_rtfind_forw(
* Calculate the difference between the value there
* and what we're looking for.
*/
- if ((wdiff = (*b ^ want) & mask)) {
+ if ((wdiff = (incore ^ want) & mask)) {
/*
* Different. Mark where we are and return.
*/
@@ -345,12 +335,6 @@ xfs_rtfind_forw(
}
word = 0;
- b = xfs_rbmblock_wordptr(bp, word);
- } else {
- /*
- * Go on to the previous word in the buffer.
- */
- b++;
}
} else {
/*
@@ -366,7 +350,8 @@ xfs_rtfind_forw(
/*
* Compute difference between actual and desired value.
*/
- if ((wdiff = *b ^ want)) {
+ incore = xfs_rtbitmap_getword(bp, word);
+ if ((wdiff = incore ^ want)) {
/*
* Different, mark where we are and return.
*/
@@ -391,12 +376,6 @@ xfs_rtfind_forw(
}
word = 0;
- b = xfs_rbmblock_wordptr(bp, word);
- } else {
- /*
- * Go on to the next word in the buffer.
- */
- b++;
}
}
/*
@@ -411,7 +390,8 @@ xfs_rtfind_forw(
/*
* Compute difference between actual and desired value.
*/
- if ((wdiff = (*b ^ want) & mask)) {
+ incore = xfs_rtbitmap_getword(bp, word);
+ if ((wdiff = (incore ^ want) & mask)) {
/*
* Different, mark where we are and return.
*/
@@ -566,15 +546,14 @@ xfs_rtmodify_range(
xfs_rtxlen_t len, /* length of extent to modify */
int val) /* 1 for free, 0 for allocated */
{
- xfs_rtword_t *b; /* current word in buffer */
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
int error; /* error value */
- xfs_rtword_t *first; /* first used word in the buffer */
int i; /* current bit number rel. to start */
int lastbit; /* last useful bit in word */
xfs_rtword_t mask; /* mask o frelevant bits for value */
+ xfs_rtword_t incore;
unsigned int firstword; /* first word used in the buffer */
unsigned int word; /* word number in the buffer */
@@ -594,7 +573,6 @@ xfs_rtmodify_range(
* Compute the starting word's address, and starting bit.
*/
firstword = word = xfs_rtx_to_rbmword(mp, start);
- first = b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1));
/*
* 0 (allocated) => all zeroes; 1 (free) => all ones.
@@ -613,10 +591,12 @@ xfs_rtmodify_range(
/*
* Set/clear the active bits.
*/
+ incore = xfs_rtbitmap_getword(bp, word);
if (val)
- *b |= mask;
+ incore |= mask;
else
- *b &= ~mask;
+ incore &= ~mask;
+ xfs_rtbitmap_setword(bp, word, incore);
i = lastbit - bit;
/*
* Go on to the next block if that's where the next word is
@@ -634,12 +614,6 @@ xfs_rtmodify_range(
}
firstword = word = 0;
- first = b = xfs_rbmblock_wordptr(bp, word);
- } else {
- /*
- * Go on to the next word in the buffer
- */
- b++;
}
} else {
/*
@@ -655,7 +629,7 @@ xfs_rtmodify_range(
/*
* Set the word value correctly.
*/
- *b = val;
+ xfs_rtbitmap_setword(bp, word, val);
i += XFS_NBWORD;
/*
* Go on to the next block if that's where the next word is
@@ -673,12 +647,6 @@ xfs_rtmodify_range(
}
firstword = word = 0;
- first = b = xfs_rbmblock_wordptr(bp, word);
- } else {
- /*
- * Go on to the next word in the buffer
- */
- b++;
}
}
/*
@@ -693,17 +661,18 @@ xfs_rtmodify_range(
/*
* Set/clear the active bits.
*/
+ incore = xfs_rtbitmap_getword(bp, word);
if (val)
- *b |= mask;
+ incore |= mask;
else
- *b &= ~mask;
+ incore &= ~mask;
+ xfs_rtbitmap_setword(bp, word, incore);
word++;
- b++;
}
/*
* Log any remaining changed bytes.
*/
- if (b > first)
+ if (word > firstword)
xfs_trans_log_rtbitmap(tp, bp, firstword, word);
return 0;
}
@@ -798,7 +767,6 @@ xfs_rtcheck_range(
xfs_rtxnum_t *new, /* out: first rtext not matching */
int *stat) /* out: 1 for matches, 0 for not */
{
- xfs_rtword_t *b; /* current word in buffer */
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */
@@ -807,6 +775,7 @@ xfs_rtcheck_range(
xfs_rtxnum_t lastbit; /* last useful bit in word */
xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t wdiff; /* difference from wanted value */
+ xfs_rtword_t incore;
unsigned int word; /* word number in the buffer */
/*
@@ -825,7 +794,6 @@ xfs_rtcheck_range(
* Compute the starting word's address, and starting bit.
*/
word = xfs_rtx_to_rbmword(mp, start);
- b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1));
/*
* 0 (allocated) => all zero's; 1 (free) => all one's.
@@ -847,7 +815,8 @@ xfs_rtcheck_range(
/*
* Compute difference between actual and desired value.
*/
- if ((wdiff = (*b ^ val) & mask)) {
+ incore = xfs_rtbitmap_getword(bp, word);
+ if ((wdiff = (incore ^ val) & mask)) {
/*
* Different, compute first wrong bit and return.
*/
@@ -873,12 +842,6 @@ xfs_rtcheck_range(
}
word = 0;
- b = xfs_rbmblock_wordptr(bp, word);
- } else {
- /*
- * Go on to the next word in the buffer.
- */
- b++;
}
} else {
/*
@@ -894,7 +857,8 @@ xfs_rtcheck_range(
/*
* Compute difference between actual and desired value.
*/
- if ((wdiff = *b ^ val)) {
+ incore = xfs_rtbitmap_getword(bp, word);
+ if ((wdiff = incore ^ val)) {
/*
* Different, compute first wrong bit and return.
*/
@@ -920,12 +884,6 @@ xfs_rtcheck_range(
}
word = 0;
- b = xfs_rbmblock_wordptr(bp, word);
- } else {
- /*
- * Go on to the next word in the buffer.
- */
- b++;
}
}
/*
@@ -940,7 +898,8 @@ xfs_rtcheck_range(
/*
* Compute difference between actual and desired value.
*/
- if ((wdiff = (*b ^ val) & mask)) {
+ incore = xfs_rtbitmap_getword(bp, word);
+ if ((wdiff = (incore ^ val) & mask)) {
/*
* Different, compute first wrong bit and return.
*/
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 618c96468..02ee57f87 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -162,16 +162,39 @@ xfs_rbmblock_to_rtx(
}
/* 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(
struct xfs_buf *bp,
unsigned int index)
{
- xfs_rtword_t *words = bp->b_addr;
+ union xfs_rtword_raw *words = bp->b_addr;
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
* offset within the rt summary file.
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 25/35] xfs: create helpers for rtsummary block/wordcount computations
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (23 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 24/35] xfs: use accessor functions for bitmap words cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 26/35] xfs: use accessor functions for summary info words cem
` (10 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: bd85af280de66a946022775a876edf0c553e3f35
Create helper functions that compute the number of blocks or words
necessary to store the rt summary file.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 29 +++++++++++++++++++++++++++++
libxfs/xfs_rtbitmap.h | 7 +++++++
2 files changed, 36 insertions(+)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index f7be9ea5f..44064b6b3 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -1148,3 +1148,32 @@ xfs_rtbitmap_wordcount(
blocks = xfs_rtbitmap_blockcount(mp, rtextents);
return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
}
+
+/* Compute the number of rtsummary blocks needed to track the given rt space. */
+xfs_filblks_t
+xfs_rtsummary_blockcount(
+ struct xfs_mount *mp,
+ unsigned int rsumlevels,
+ xfs_extlen_t rbmblocks)
+{
+ unsigned long long rsumwords;
+
+ rsumwords = (unsigned long long)rsumlevels * rbmblocks;
+ return XFS_B_TO_FSB(mp, rsumwords << XFS_WORDLOG);
+}
+
+/*
+ * Compute the number of rtsummary info words needed to populate every block of
+ * a summary file that is large enough to track the given rt space.
+ */
+unsigned long long
+xfs_rtsummary_wordcount(
+ struct xfs_mount *mp,
+ unsigned int rsumlevels,
+ xfs_extlen_t rbmblocks)
+{
+ xfs_filblks_t blocks;
+
+ blocks = xfs_rtsummary_blockcount(mp, rsumlevels, rbmblocks);
+ return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
+}
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 02ee57f87..62138df6d 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -311,6 +311,11 @@ xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t
rtextents);
unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp,
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 */
# define xfs_rtfree_extent(t,b,l) (-ENOSYS)
# define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS)
@@ -325,6 +330,8 @@ xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
return 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 /* __XFS_RTBITMAP_H__ */
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 26/35] xfs: use accessor functions for summary info words
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (24 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 25/35] xfs: create helpers for rtsummary block/wordcount computations cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 27/35] xfs: consolidate realtime allocation arguments cem
` (9 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 663b8db7b0256b81152b2f786e45ecf12bdf265f
Create 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>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_format.h | 8 ++++++++
libxfs/xfs_rtbitmap.c | 15 ++++++++-------
libxfs/xfs_rtbitmap.h | 28 ++++++++++++++++++++++++++--
3 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h
index 2af891d5d..9a88aba15 100644
--- a/libxfs/xfs_format.h
+++ b/libxfs/xfs_format.h
@@ -698,6 +698,14 @@ 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
* ==============
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 44064b6b3..869d26e79 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -449,7 +449,6 @@ xfs_rtmodify_summary_int(
int error; /* error value */
xfs_fileoff_t sb; /* summary fsblock */
xfs_rtsumoff_t so; /* index into the summary file */
- xfs_suminfo_t *sp; /* pointer to returned data */
unsigned int infoword;
/*
@@ -488,19 +487,21 @@ xfs_rtmodify_summary_int(
* Point to the summary information, modify/log it, and/or copy it out.
*/
infoword = xfs_rtsumoffs_to_infoword(mp, so);
- sp = xfs_rsumblock_infoptr(bp, infoword);
if (delta) {
- *sp += delta;
+ xfs_suminfo_t val = xfs_suminfo_add(bp, infoword, delta);
+
if (mp->m_rsum_cache) {
- if (*sp == 0 && log == mp->m_rsum_cache[bbno])
+ if (val == 0 && log == mp->m_rsum_cache[bbno])
mp->m_rsum_cache[bbno]++;
- if (*sp != 0 && log < mp->m_rsum_cache[bbno])
+ if (val != 0 && log < mp->m_rsum_cache[bbno])
mp->m_rsum_cache[bbno] = log;
}
xfs_trans_log_rtsummary(tp, bp, infoword);
+ if (sum)
+ *sum = val;
+ } else if (sum) {
+ *sum = xfs_suminfo_get(bp, infoword);
}
- if (sum)
- *sum = *sp;
return 0;
}
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 62138df6d..e4268faa6 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -235,16 +235,40 @@ xfs_rtsumoffs_to_infoword(
}
/* 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(
struct xfs_buf *bp,
unsigned int index)
{
- xfs_suminfo_t *info = bp->b_addr;
+ union xfs_suminfo_raw *info = bp->b_addr;
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.
*/
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 27/35] xfs: consolidate realtime allocation arguments
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (25 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 26/35] xfs: use accessor functions for summary info words cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 28/35] xfs: cache last bitmap block in realtime allocator cem
` (8 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: Dave Chinner <dchinner@redhat.com>
Source kernel commit: 41f33d82cfd310e344fc9183f02cc9e0d2d27663
Consolidate the arguments passed around the rt allocator into a
struct xfs_rtalloc_arg similar to how the btree allocator arguments
are consolidated in a struct xfs_alloc_arg....
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 368 +++++++++++++++++++++---------------------
libxfs/xfs_rtbitmap.h | 46 +++---
2 files changed, 211 insertions(+), 203 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 869d26e79..53e2c1c89 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -51,17 +51,17 @@ const struct xfs_buf_ops xfs_rtbuf_ops = {
*/
int
xfs_rtbuf_get(
- xfs_mount_t *mp, /* file system mount structure */
- xfs_trans_t *tp, /* transaction pointer */
- xfs_fileoff_t block, /* block number in bitmap or summary */
- int issum, /* is summary not bitmap */
- struct xfs_buf **bpp) /* output: buffer for the block */
+ struct xfs_rtalloc_args *args,
+ xfs_fileoff_t block, /* block number in bitmap or summary */
+ int issum, /* is summary not bitmap */
+ struct xfs_buf **bpp) /* output: buffer for the block */
{
- struct xfs_buf *bp; /* block buffer, result */
- xfs_inode_t *ip; /* bitmap or summary inode */
- xfs_bmbt_irec_t map;
- int nmap = 1;
- int error; /* error value */
+ struct xfs_mount *mp = args->mp;
+ struct xfs_buf *bp; /* block buffer, result */
+ struct xfs_inode *ip; /* bitmap or summary inode */
+ struct xfs_bmbt_irec map;
+ int nmap = 1;
+ int error;
ip = issum ? mp->m_rsumip : mp->m_rbmip;
@@ -73,13 +73,13 @@ xfs_rtbuf_get(
return -EFSCORRUPTED;
ASSERT(map.br_startblock != NULLFSBLOCK);
- error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
+ error = xfs_trans_read_buf(mp, args->tp, mp->m_ddev_targp,
XFS_FSB_TO_DADDR(mp, map.br_startblock),
mp->m_bsize, 0, &bp, &xfs_rtbuf_ops);
if (error)
return error;
- xfs_trans_buf_set_type(tp, bp, issum ? XFS_BLFT_RTSUMMARY_BUF
+ xfs_trans_buf_set_type(args->tp, bp, issum ? XFS_BLFT_RTSUMMARY_BUF
: XFS_BLFT_RTBITMAP_BUF);
*bpp = bp;
return 0;
@@ -91,30 +91,30 @@ xfs_rtbuf_get(
*/
int
xfs_rtfind_back(
- xfs_mount_t *mp, /* file system mount point */
- xfs_trans_t *tp, /* transaction pointer */
- xfs_rtxnum_t start, /* starting rtext to look at */
- xfs_rtxnum_t limit, /* last rtext to look at */
- xfs_rtxnum_t *rtx) /* out: start rtext found */
+ struct xfs_rtalloc_args *args,
+ xfs_rtxnum_t start, /* starting rtext to look at */
+ xfs_rtxnum_t limit, /* last rtext to look at */
+ xfs_rtxnum_t *rtx) /* out: start rtext found */
{
- int bit; /* bit number in the word */
- xfs_fileoff_t block; /* bitmap block number */
- struct xfs_buf *bp; /* buf for the block */
- int error; /* error value */
- xfs_rtxnum_t firstbit; /* first useful bit in the word */
- xfs_rtxnum_t i; /* current bit number rel. to start */
- xfs_rtxnum_t len; /* length of inspected area */
- xfs_rtword_t mask; /* mask of relevant bits for value */
- xfs_rtword_t want; /* mask for "good" values */
- xfs_rtword_t wdiff; /* difference from wanted value */
- xfs_rtword_t incore;
- unsigned int word; /* word number in the buffer */
+ struct xfs_mount *mp = args->mp;
+ int bit; /* bit number in the word */
+ xfs_fileoff_t block; /* bitmap block number */
+ struct xfs_buf *bp; /* buf for the block */
+ int error; /* error value */
+ xfs_rtxnum_t firstbit; /* first useful bit in the word */
+ xfs_rtxnum_t i; /* current bit number rel. to start */
+ xfs_rtxnum_t len; /* length of inspected area */
+ xfs_rtword_t mask; /* mask of relevant bits for value */
+ xfs_rtword_t want; /* mask for "good" values */
+ xfs_rtword_t wdiff; /* difference from wanted value */
+ xfs_rtword_t incore;
+ unsigned int word; /* word number in the buffer */
/*
* Compute and read in starting bitmap block for starting block.
*/
block = xfs_rtx_to_rbmblock(mp, start);
- error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
+ error = xfs_rtbuf_get(args, block, 0, &bp);
if (error) {
return error;
}
@@ -151,7 +151,7 @@ xfs_rtfind_back(
/*
* Different. Mark where we are and return.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
i = bit - XFS_RTHIBIT(wdiff);
*rtx = start - i + 1;
return 0;
@@ -165,8 +165,8 @@ xfs_rtfind_back(
/*
* If done with this block, get the previous one.
*/
- xfs_trans_brelse(tp, bp);
- error = xfs_rtbuf_get(mp, tp, --block, 0, &bp);
+ xfs_trans_brelse(args->tp, bp);
+ error = xfs_rtbuf_get(args, --block, 0, &bp);
if (error) {
return error;
}
@@ -192,7 +192,7 @@ xfs_rtfind_back(
/*
* Different, mark where we are and return.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
*rtx = start - i + 1;
return 0;
@@ -206,8 +206,8 @@ xfs_rtfind_back(
/*
* If done with this block, get the previous one.
*/
- xfs_trans_brelse(tp, bp);
- error = xfs_rtbuf_get(mp, tp, --block, 0, &bp);
+ xfs_trans_brelse(args->tp, bp);
+ error = xfs_rtbuf_get(args, --block, 0, &bp);
if (error) {
return error;
}
@@ -234,7 +234,7 @@ xfs_rtfind_back(
/*
* Different, mark where we are and return.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
*rtx = start - i + 1;
return 0;
@@ -244,7 +244,7 @@ xfs_rtfind_back(
/*
* No match, return that we scanned the whole area.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
*rtx = start - i + 1;
return 0;
}
@@ -255,30 +255,30 @@ xfs_rtfind_back(
*/
int
xfs_rtfind_forw(
- xfs_mount_t *mp, /* file system mount point */
- xfs_trans_t *tp, /* transaction pointer */
- xfs_rtxnum_t start, /* starting rtext to look at */
- xfs_rtxnum_t limit, /* last rtext to look at */
- xfs_rtxnum_t *rtx) /* out: start rtext found */
+ struct xfs_rtalloc_args *args,
+ xfs_rtxnum_t start, /* starting rtext to look at */
+ xfs_rtxnum_t limit, /* last rtext to look at */
+ xfs_rtxnum_t *rtx) /* out: start rtext found */
{
- int bit; /* bit number in the word */
- xfs_fileoff_t block; /* bitmap block number */
- struct xfs_buf *bp; /* buf for the block */
- int error; /* error value */
- xfs_rtxnum_t i; /* current bit number rel. to start */
- xfs_rtxnum_t lastbit; /* last useful bit in the word */
- xfs_rtxnum_t len; /* length of inspected area */
- xfs_rtword_t mask; /* mask of relevant bits for value */
- xfs_rtword_t want; /* mask for "good" values */
- xfs_rtword_t wdiff; /* difference from wanted value */
- xfs_rtword_t incore;
- unsigned int word; /* word number in the buffer */
+ struct xfs_mount *mp = args->mp;
+ int bit; /* bit number in the word */
+ xfs_fileoff_t block; /* bitmap block number */
+ struct xfs_buf *bp; /* buf for the block */
+ int error;
+ xfs_rtxnum_t i; /* current bit number rel. to start */
+ xfs_rtxnum_t lastbit;/* last useful bit in the word */
+ xfs_rtxnum_t len; /* length of inspected area */
+ xfs_rtword_t mask; /* mask of relevant bits for value */
+ xfs_rtword_t want; /* mask for "good" values */
+ xfs_rtword_t wdiff; /* difference from wanted value */
+ xfs_rtword_t incore;
+ unsigned int word; /* word number in the buffer */
/*
* Compute and read in starting bitmap block for starting block.
*/
block = xfs_rtx_to_rbmblock(mp, start);
- error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
+ error = xfs_rtbuf_get(args, block, 0, &bp);
if (error) {
return error;
}
@@ -314,7 +314,7 @@ xfs_rtfind_forw(
/*
* Different. Mark where we are and return.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
i = XFS_RTLOBIT(wdiff) - bit;
*rtx = start + i - 1;
return 0;
@@ -328,8 +328,8 @@ xfs_rtfind_forw(
/*
* If done with this block, get the previous one.
*/
- xfs_trans_brelse(tp, bp);
- error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
+ xfs_trans_brelse(args->tp, bp);
+ error = xfs_rtbuf_get(args, ++block, 0, &bp);
if (error) {
return error;
}
@@ -355,7 +355,7 @@ xfs_rtfind_forw(
/*
* Different, mark where we are and return.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
i += XFS_RTLOBIT(wdiff);
*rtx = start + i - 1;
return 0;
@@ -369,8 +369,8 @@ xfs_rtfind_forw(
/*
* If done with this block, get the next one.
*/
- xfs_trans_brelse(tp, bp);
- error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
+ xfs_trans_brelse(args->tp, bp);
+ error = xfs_rtbuf_get(args, ++block, 0, &bp);
if (error) {
return error;
}
@@ -395,7 +395,7 @@ xfs_rtfind_forw(
/*
* Different, mark where we are and return.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
i += XFS_RTLOBIT(wdiff);
*rtx = start + i - 1;
return 0;
@@ -405,7 +405,7 @@ xfs_rtfind_forw(
/*
* No match, return that we scanned the whole area.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
*rtx = start + i - 1;
return 0;
}
@@ -436,20 +436,20 @@ xfs_trans_log_rtsummary(
*/
int
xfs_rtmodify_summary_int(
- xfs_mount_t *mp, /* file system mount structure */
- xfs_trans_t *tp, /* transaction pointer */
- int log, /* log2 of extent size */
- xfs_fileoff_t bbno, /* bitmap block number */
- int delta, /* change to make to summary info */
- struct xfs_buf **rbpp, /* in/out: summary block buffer */
- xfs_fileoff_t *rsb, /* in/out: summary block number */
- xfs_suminfo_t *sum) /* out: summary info for this block */
+ struct xfs_rtalloc_args *args,
+ int log, /* log2 of extent size */
+ xfs_fileoff_t bbno, /* bitmap block number */
+ int delta, /* change to make to summary info */
+ struct xfs_buf **rbpp, /* in/out: summary block buffer */
+ xfs_fileoff_t *rsb, /* in/out: summary block number */
+ xfs_suminfo_t *sum) /* out: summary info for this block */
{
- struct xfs_buf *bp; /* buffer for the summary block */
- int error; /* error value */
- xfs_fileoff_t sb; /* summary fsblock */
- xfs_rtsumoff_t so; /* index into the summary file */
- unsigned int infoword;
+ struct xfs_mount *mp = args->mp;
+ struct xfs_buf *bp; /* buffer for the summary block */
+ int error;
+ xfs_fileoff_t sb; /* summary fsblock */
+ xfs_rtsumoff_t so; /* index into the summary file */
+ unsigned int infoword;
/*
* Compute entry number in the summary file.
@@ -472,8 +472,8 @@ xfs_rtmodify_summary_int(
* If there was an old one, get rid of it first.
*/
if (*rbpp)
- xfs_trans_brelse(tp, *rbpp);
- error = xfs_rtbuf_get(mp, tp, sb, 1, &bp);
+ xfs_trans_brelse(args->tp, *rbpp);
+ error = xfs_rtbuf_get(args, sb, 1, &bp);
if (error) {
return error;
}
@@ -496,7 +496,7 @@ xfs_rtmodify_summary_int(
if (val != 0 && log < mp->m_rsum_cache[bbno])
mp->m_rsum_cache[bbno] = log;
}
- xfs_trans_log_rtsummary(tp, bp, infoword);
+ xfs_trans_log_rtsummary(args->tp, bp, infoword);
if (sum)
*sum = val;
} else if (sum) {
@@ -507,16 +507,14 @@ xfs_rtmodify_summary_int(
int
xfs_rtmodify_summary(
- xfs_mount_t *mp, /* file system mount structure */
- xfs_trans_t *tp, /* transaction pointer */
- int log, /* log2 of extent size */
- xfs_fileoff_t bbno, /* bitmap block number */
- int delta, /* change to make to summary info */
- struct xfs_buf **rbpp, /* in/out: summary block buffer */
- xfs_fileoff_t *rsb) /* in/out: summary block number */
+ struct xfs_rtalloc_args *args,
+ int log, /* log2 of extent size */
+ xfs_fileoff_t bbno, /* bitmap block number */
+ int delta, /* change to make to summary info */
+ struct xfs_buf **rbpp, /* in/out: summary block buffer */
+ xfs_fileoff_t *rsb) /* in/out: summary block number */
{
- return xfs_rtmodify_summary_int(mp, tp, log, bbno,
- delta, rbpp, rsb, NULL);
+ return xfs_rtmodify_summary_int(args, log, bbno, delta, rbpp, rsb, NULL);
}
/* Log rtbitmap block from the word @from to the byte before @next. */
@@ -541,22 +539,22 @@ xfs_trans_log_rtbitmap(
*/
int
xfs_rtmodify_range(
- xfs_mount_t *mp, /* file system mount point */
- xfs_trans_t *tp, /* transaction pointer */
- xfs_rtxnum_t start, /* starting rtext to modify */
- xfs_rtxlen_t len, /* length of extent to modify */
- int val) /* 1 for free, 0 for allocated */
+ struct xfs_rtalloc_args *args,
+ xfs_rtxnum_t start, /* starting rtext to modify */
+ xfs_rtxlen_t len, /* length of extent to modify */
+ int val) /* 1 for free, 0 for allocated */
{
- int bit; /* bit number in the word */
- xfs_fileoff_t block; /* bitmap block number */
- struct xfs_buf *bp; /* buf for the block */
- int error; /* error value */
- int i; /* current bit number rel. to start */
- int lastbit; /* last useful bit in word */
- xfs_rtword_t mask; /* mask o frelevant bits for value */
- xfs_rtword_t incore;
- unsigned int firstword; /* first word used in the buffer */
- unsigned int word; /* word number in the buffer */
+ struct xfs_mount *mp = args->mp;
+ int bit; /* bit number in the word */
+ xfs_fileoff_t block; /* bitmap block number */
+ struct xfs_buf *bp; /* buf for the block */
+ int error;
+ int i; /* current bit number rel. to start */
+ int lastbit; /* last useful bit in word */
+ xfs_rtword_t mask; /* mask of relevant bits for value */
+ xfs_rtword_t incore;
+ unsigned int firstword; /* first word used in the buffer */
+ unsigned int word; /* word number in the buffer */
/*
* Compute starting bitmap block number.
@@ -565,7 +563,7 @@ xfs_rtmodify_range(
/*
* Read the bitmap block, and point to its data.
*/
- error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
+ error = xfs_rtbuf_get(args, block, 0, &bp);
if (error) {
return error;
}
@@ -608,8 +606,9 @@ xfs_rtmodify_range(
* Log the changed part of this block.
* Get the next one.
*/
- xfs_trans_log_rtbitmap(tp, bp, firstword, word);
- error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
+ xfs_trans_log_rtbitmap(args->tp, bp, firstword,
+ word);
+ error = xfs_rtbuf_get(args, ++block, 0, &bp);
if (error) {
return error;
}
@@ -641,11 +640,11 @@ xfs_rtmodify_range(
* Log the changed part of this block.
* Get the next one.
*/
- xfs_trans_log_rtbitmap(tp, bp, firstword, word);
- error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
- if (error) {
+ xfs_trans_log_rtbitmap(args->tp, bp, firstword,
+ word);
+ error = xfs_rtbuf_get(args, ++block, 0, &bp);
+ if (error)
return error;
- }
firstword = word = 0;
}
@@ -674,7 +673,7 @@ xfs_rtmodify_range(
* Log any remaining changed bytes.
*/
if (word > firstword)
- xfs_trans_log_rtbitmap(tp, bp, firstword, word);
+ xfs_trans_log_rtbitmap(args->tp, bp, firstword, word);
return 0;
}
@@ -684,23 +683,23 @@ xfs_rtmodify_range(
*/
int
xfs_rtfree_range(
- xfs_mount_t *mp, /* file system mount point */
- xfs_trans_t *tp, /* transaction pointer */
- xfs_rtxnum_t start, /* starting rtext to free */
- xfs_rtxlen_t len, /* length to free */
- struct xfs_buf **rbpp, /* in/out: summary block buffer */
- xfs_fileoff_t *rsb) /* in/out: summary block number */
+ struct xfs_rtalloc_args *args,
+ xfs_rtxnum_t start, /* starting rtext to free */
+ xfs_rtxlen_t len, /* length to free */
+ struct xfs_buf **rbpp, /* in/out: summary block buffer */
+ xfs_fileoff_t *rsb) /* in/out: summary block number */
{
- xfs_rtxnum_t end; /* end of the freed extent */
- int error; /* error value */
- xfs_rtxnum_t postblock; /* first rtext freed > end */
- xfs_rtxnum_t preblock; /* first rtext freed < start */
+ struct xfs_mount *mp = args->mp;
+ xfs_rtxnum_t end; /* end of the freed extent */
+ int error; /* error value */
+ xfs_rtxnum_t postblock; /* first rtext freed > end */
+ xfs_rtxnum_t preblock; /* first rtext freed < start */
end = start + len - 1;
/*
* Modify the bitmap to mark this extent freed.
*/
- error = xfs_rtmodify_range(mp, tp, start, len, 1);
+ error = xfs_rtmodify_range(args, start, len, 1);
if (error) {
return error;
}
@@ -709,14 +708,14 @@ xfs_rtfree_range(
* We need to find the beginning and end of the extent so we can
* properly update the summary.
*/
- error = xfs_rtfind_back(mp, tp, start, 0, &preblock);
+ error = xfs_rtfind_back(args, start, 0, &preblock);
if (error) {
return error;
}
/*
* Find the next allocated block (end of allocated extent).
*/
- error = xfs_rtfind_forw(mp, tp, end, mp->m_sb.sb_rextents - 1,
+ error = xfs_rtfind_forw(args, end, mp->m_sb.sb_rextents - 1,
&postblock);
if (error)
return error;
@@ -725,7 +724,7 @@ xfs_rtfree_range(
* old extent, add summary data for them to be allocated.
*/
if (preblock < start) {
- error = xfs_rtmodify_summary(mp, tp,
+ error = xfs_rtmodify_summary(args,
XFS_RTBLOCKLOG(start - preblock),
xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb);
if (error) {
@@ -737,7 +736,7 @@ xfs_rtfree_range(
* old extent, add summary data for them to be allocated.
*/
if (postblock > end) {
- error = xfs_rtmodify_summary(mp, tp,
+ error = xfs_rtmodify_summary(args,
XFS_RTBLOCKLOG(postblock - end),
xfs_rtx_to_rbmblock(mp, end + 1), -1, rbpp, rsb);
if (error) {
@@ -748,7 +747,7 @@ xfs_rtfree_range(
* Increment the summary information corresponding to the entire
* (new) free extent.
*/
- error = xfs_rtmodify_summary(mp, tp,
+ error = xfs_rtmodify_summary(args,
XFS_RTBLOCKLOG(postblock + 1 - preblock),
xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb);
return error;
@@ -760,24 +759,24 @@ xfs_rtfree_range(
*/
int
xfs_rtcheck_range(
- xfs_mount_t *mp, /* file system mount point */
- xfs_trans_t *tp, /* transaction pointer */
- xfs_rtxnum_t start, /* starting rtext number of extent */
- xfs_rtxlen_t len, /* length of extent */
- int val, /* 1 for free, 0 for allocated */
- xfs_rtxnum_t *new, /* out: first rtext not matching */
- int *stat) /* out: 1 for matches, 0 for not */
+ struct xfs_rtalloc_args *args,
+ xfs_rtxnum_t start, /* starting rtext number of extent */
+ xfs_rtxlen_t len, /* length of extent */
+ int val, /* 1 for free, 0 for allocated */
+ xfs_rtxnum_t *new, /* out: first rtext not matching */
+ int *stat) /* out: 1 for matches, 0 for not */
{
- int bit; /* bit number in the word */
- xfs_fileoff_t block; /* bitmap block number */
- struct xfs_buf *bp; /* buf for the block */
- int error; /* error value */
- xfs_rtxnum_t i; /* current bit number rel. to start */
- xfs_rtxnum_t lastbit; /* last useful bit in word */
- xfs_rtword_t mask; /* mask of relevant bits for value */
- xfs_rtword_t wdiff; /* difference from wanted value */
- xfs_rtword_t incore;
- unsigned int word; /* word number in the buffer */
+ struct xfs_mount *mp = args->mp;
+ int bit; /* bit number in the word */
+ xfs_fileoff_t block; /* bitmap block number */
+ struct xfs_buf *bp; /* buf for the block */
+ int error;
+ xfs_rtxnum_t i; /* current bit number rel. to start */
+ xfs_rtxnum_t lastbit; /* last useful bit in word */
+ xfs_rtword_t mask; /* mask of relevant bits for value */
+ xfs_rtword_t wdiff; /* difference from wanted value */
+ xfs_rtword_t incore;
+ unsigned int word; /* word number in the buffer */
/*
* Compute starting bitmap block number
@@ -786,7 +785,7 @@ xfs_rtcheck_range(
/*
* Read the bitmap block.
*/
- error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
+ error = xfs_rtbuf_get(args, block, 0, &bp);
if (error) {
return error;
}
@@ -821,7 +820,7 @@ xfs_rtcheck_range(
/*
* Different, compute first wrong bit and return.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
i = XFS_RTLOBIT(wdiff) - bit;
*new = start + i;
*stat = 0;
@@ -836,8 +835,8 @@ xfs_rtcheck_range(
/*
* If done with this block, get the next one.
*/
- xfs_trans_brelse(tp, bp);
- error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
+ xfs_trans_brelse(args->tp, bp);
+ error = xfs_rtbuf_get(args, ++block, 0, &bp);
if (error) {
return error;
}
@@ -863,7 +862,7 @@ xfs_rtcheck_range(
/*
* Different, compute first wrong bit and return.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
i += XFS_RTLOBIT(wdiff);
*new = start + i;
*stat = 0;
@@ -878,8 +877,8 @@ xfs_rtcheck_range(
/*
* If done with this block, get the next one.
*/
- xfs_trans_brelse(tp, bp);
- error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
+ xfs_trans_brelse(args->tp, bp);
+ error = xfs_rtbuf_get(args, ++block, 0, &bp);
if (error) {
return error;
}
@@ -904,7 +903,7 @@ xfs_rtcheck_range(
/*
* Different, compute first wrong bit and return.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
i += XFS_RTLOBIT(wdiff);
*new = start + i;
*stat = 0;
@@ -915,7 +914,7 @@ xfs_rtcheck_range(
/*
* Successful, return.
*/
- xfs_trans_brelse(tp, bp);
+ xfs_trans_brelse(args->tp, bp);
*new = start + i;
*stat = 1;
return 0;
@@ -925,55 +924,56 @@ xfs_rtcheck_range(
/*
* Check that the given extent (block range) is allocated already.
*/
-STATIC int /* error */
+STATIC int
xfs_rtcheck_alloc_range(
- xfs_mount_t *mp, /* file system mount point */
- xfs_trans_t *tp, /* transaction pointer */
- xfs_rtxnum_t start, /* starting rtext number of extent */
- xfs_rtxlen_t len) /* length of extent */
+ struct xfs_rtalloc_args *args,
+ xfs_rtxnum_t start, /* starting rtext number of extent */
+ xfs_rtxlen_t len) /* length of extent */
{
- xfs_rtxnum_t new; /* dummy for xfs_rtcheck_range */
- int stat;
- int error;
+ xfs_rtxnum_t new; /* dummy for xfs_rtcheck_range */
+ int stat;
+ int error;
- error = xfs_rtcheck_range(mp, tp, start, len, 0, &new, &stat);
+ error = xfs_rtcheck_range(args, start, len, 0, &new, &stat);
if (error)
return error;
ASSERT(stat);
return 0;
}
#else
-#define xfs_rtcheck_alloc_range(m,t,b,l) (0)
+#define xfs_rtcheck_alloc_range(a,b,l) (0)
#endif
/*
* Free an extent in the realtime subvolume. Length is expressed in
* realtime extents, as is the block number.
*/
-int /* error */
+int
xfs_rtfree_extent(
- xfs_trans_t *tp, /* transaction pointer */
- xfs_rtxnum_t start, /* starting rtext number to free */
- xfs_rtxlen_t len) /* length of extent freed */
+ xfs_trans_t *tp, /* transaction pointer */
+ xfs_rtxnum_t start, /* starting rtext number to free */
+ xfs_rtxlen_t len) /* length of extent freed */
{
- int error; /* error value */
- xfs_mount_t *mp; /* file system mount structure */
- xfs_fsblock_t sb; /* summary file block number */
- struct xfs_buf *sumbp = NULL; /* summary file block buffer */
- struct timespec64 atime;
-
- mp = tp->t_mountp;
+ struct xfs_mount *mp = tp->t_mountp;
+ struct xfs_rtalloc_args args = {
+ .mp = mp,
+ .tp = tp,
+ };
+ int error;
+ xfs_fsblock_t sb; /* summary file block number */
+ struct xfs_buf *sumbp = NULL; /* summary file block buffer */
+ struct timespec64 atime;
ASSERT(mp->m_rbmip->i_itemp != NULL);
ASSERT(xfs_isilocked(mp->m_rbmip, XFS_ILOCK_EXCL));
- error = xfs_rtcheck_alloc_range(mp, tp, start, len);
+ error = xfs_rtcheck_alloc_range(&args, start, len);
if (error)
return error;
/*
* Free the range of realtime blocks.
*/
- error = xfs_rtfree_range(mp, tp, start, len, &sumbp, &sb);
+ error = xfs_rtfree_range(&args, start, len, &sumbp, &sb);
if (error) {
return error;
}
@@ -1041,6 +1041,10 @@ xfs_rtalloc_query_range(
xfs_rtalloc_query_range_fn fn,
void *priv)
{
+ struct xfs_rtalloc_args args = {
+ .mp = mp,
+ .tp = tp,
+ };
struct xfs_rtalloc_rec rec;
xfs_rtxnum_t rtstart;
xfs_rtxnum_t rtend;
@@ -1060,13 +1064,13 @@ xfs_rtalloc_query_range(
rtstart = low_rec->ar_startext;
while (rtstart <= high_key) {
/* Is the first block free? */
- error = xfs_rtcheck_range(mp, tp, rtstart, 1, 1, &rtend,
+ error = xfs_rtcheck_range(&args, rtstart, 1, 1, &rtend,
&is_free);
if (error)
break;
/* How long does the extent go for? */
- error = xfs_rtfind_forw(mp, tp, rtstart, high_key, &rtend);
+ error = xfs_rtfind_forw(&args, rtstart, high_key, &rtend);
if (error)
break;
@@ -1111,11 +1115,15 @@ xfs_rtalloc_extent_is_free(
xfs_rtxlen_t len,
bool *is_free)
{
+ struct xfs_rtalloc_args args = {
+ .mp = mp,
+ .tp = tp,
+ };
xfs_rtxnum_t end;
int matches;
int error;
- error = xfs_rtcheck_range(mp, tp, start, len, 1, &end, &matches);
+ error = xfs_rtcheck_range(&args, start, len, 1, &end, &matches);
if (error)
return error;
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index e4268faa6..025a7efc2 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -9,6 +9,11 @@
/* For userspace XFS_RT is always defined */
#define CONFIG_XFS_RT
+struct xfs_rtalloc_args {
+ struct xfs_mount *mp;
+ struct xfs_trans *tp;
+};
+
static inline xfs_rtblock_t
xfs_rtx_to_rtb(
struct xfs_mount *mp,
@@ -284,29 +289,24 @@ typedef int (*xfs_rtalloc_query_range_fn)(
void *priv);
#ifdef CONFIG_XFS_RT
-int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_fileoff_t block, int issum, struct xfs_buf **bpp);
-int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtxnum_t start, xfs_rtxlen_t len, int val,
- xfs_rtxnum_t *new, int *stat);
-int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtxnum_t start, xfs_rtxnum_t limit,
- xfs_rtxnum_t *rtblock);
-int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtxnum_t start, xfs_rtxnum_t limit,
- xfs_rtxnum_t *rtblock);
-int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtxnum_t start, xfs_rtxlen_t len, int val);
-int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
- int log, xfs_fileoff_t bbno, int delta,
- struct xfs_buf **rbpp, xfs_fileoff_t *rsb,
- xfs_suminfo_t *sum);
-int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
- xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
- xfs_fileoff_t *rsb);
-int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
- xfs_rtxnum_t start, xfs_rtxlen_t len,
- struct xfs_buf **rbpp, xfs_fileoff_t *rsb);
+int xfs_rtbuf_get(struct xfs_rtalloc_args *args, xfs_fileoff_t block,
+ int issum, struct xfs_buf **bpp);
+int xfs_rtcheck_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
+ xfs_rtxlen_t len, int val, xfs_rtxnum_t *new, int *stat);
+int xfs_rtfind_back(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
+ xfs_rtxnum_t limit, xfs_rtxnum_t *rtblock);
+int xfs_rtfind_forw(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
+ xfs_rtxnum_t limit, xfs_rtxnum_t *rtblock);
+int xfs_rtmodify_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
+ xfs_rtxlen_t len, int val);
+int xfs_rtmodify_summary_int(struct xfs_rtalloc_args *args, int log,
+ xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
+ xfs_fileoff_t *rsb, xfs_suminfo_t *sum);
+int xfs_rtmodify_summary(struct xfs_rtalloc_args *args, int log,
+ xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
+ xfs_fileoff_t *rsb);
+int xfs_rtfree_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
+ xfs_rtxlen_t len, struct xfs_buf **rbpp, xfs_fileoff_t *rsb);
int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
const struct xfs_rtalloc_rec *low_rec,
const struct xfs_rtalloc_rec *high_rec,
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 28/35] xfs: cache last bitmap block in realtime allocator
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (26 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 27/35] xfs: consolidate realtime allocation arguments cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 29/35] xfs: simplify xfs_rtbuf_get calling conventions cem
` (7 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: Omar Sandoval <osandov@fb.com>
Source kernel commit: e94b53ff699c2674a9ec083342a5254866210ade
Profiling a workload on a highly fragmented realtime device showed a ton
of CPU cycles being spent in xfs_trans_read_buf() called by
xfs_rtbuf_get(). Further tracing showed that much of that was repeated
calls to xfs_rtbuf_get() for the same block of the realtime bitmap.
These come from xfs_rtallocate_extent_block(): as it walks through
ranges of free bits in the bitmap, each call to xfs_rtcheck_range() and
xfs_rtfind_{forw,back}() gets the same bitmap block. If the bitmap block
is very fragmented, then this is _a lot_ of buffer lookups.
The realtime allocator already passes around a cache of the last used
realtime summary block to avoid repeated reads (the parameters rbpp and
rsb). We can do the same for the realtime bitmap.
This replaces rbpp and rsb with a struct xfs_rtbuf_cache, which caches
the most recently used block for both the realtime bitmap and summary.
xfs_rtbuf_get() now handles the caching instead of the callers, which
requires plumbing xfs_rtbuf_cache to more functions but also makes sure
we don't miss anything.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 147 ++++++++++++++++++++++--------------------
libxfs/xfs_rtbitmap.h | 17 +++--
2 files changed, 88 insertions(+), 76 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index 53e2c1c89..e9c70ff88 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -45,6 +45,23 @@ const struct xfs_buf_ops xfs_rtbuf_ops = {
.verify_write = xfs_rtbuf_verify_write,
};
+/* Release cached rt bitmap and summary buffers. */
+void
+xfs_rtbuf_cache_relse(
+ struct xfs_rtalloc_args *args)
+{
+ if (args->rbmbp) {
+ xfs_trans_brelse(args->tp, args->rbmbp);
+ args->rbmbp = NULL;
+ args->rbmoff = NULLFILEOFF;
+ }
+ if (args->sumbp) {
+ xfs_trans_brelse(args->tp, args->sumbp);
+ args->sumbp = NULL;
+ args->sumoff = NULLFILEOFF;
+ }
+}
+
/*
* Get a buffer for the bitmap or summary file block specified.
* The buffer is returned read and locked.
@@ -57,13 +74,42 @@ xfs_rtbuf_get(
struct xfs_buf **bpp) /* output: buffer for the block */
{
struct xfs_mount *mp = args->mp;
+ struct xfs_buf **cbpp; /* cached block buffer */
+ xfs_fileoff_t *coffp; /* cached block number */
struct xfs_buf *bp; /* block buffer, result */
struct xfs_inode *ip; /* bitmap or summary inode */
struct xfs_bmbt_irec map;
+ enum xfs_blft type;
int nmap = 1;
int error;
- ip = issum ? mp->m_rsumip : mp->m_rbmip;
+ if (issum) {
+ cbpp = &args->sumbp;
+ coffp = &args->sumoff;
+ ip = mp->m_rsumip;
+ type = XFS_BLFT_RTSUMMARY_BUF;
+ } else {
+ cbpp = &args->rbmbp;
+ coffp = &args->rbmoff;
+ ip = mp->m_rbmip;
+ type = XFS_BLFT_RTBITMAP_BUF;
+ }
+
+ /*
+ * If we have a cached buffer, and the block number matches, use that.
+ */
+ if (*cbpp && *coffp == block) {
+ *bpp = *cbpp;
+ return 0;
+ }
+ /*
+ * Otherwise we have to have to get the buffer. If there was an old
+ * one, get rid of it first.
+ */
+ if (*cbpp) {
+ xfs_trans_brelse(args->tp, *cbpp);
+ *cbpp = NULL;
+ }
error = xfs_bmapi_read(ip, block, 1, &map, &nmap, 0);
if (error)
@@ -79,9 +125,9 @@ xfs_rtbuf_get(
if (error)
return error;
- xfs_trans_buf_set_type(args->tp, bp, issum ? XFS_BLFT_RTSUMMARY_BUF
- : XFS_BLFT_RTBITMAP_BUF);
- *bpp = bp;
+ xfs_trans_buf_set_type(args->tp, bp, type);
+ *cbpp = *bpp = bp;
+ *coffp = block;
return 0;
}
@@ -151,7 +197,6 @@ xfs_rtfind_back(
/*
* Different. Mark where we are and return.
*/
- xfs_trans_brelse(args->tp, bp);
i = bit - XFS_RTHIBIT(wdiff);
*rtx = start - i + 1;
return 0;
@@ -165,7 +210,6 @@ xfs_rtfind_back(
/*
* If done with this block, get the previous one.
*/
- xfs_trans_brelse(args->tp, bp);
error = xfs_rtbuf_get(args, --block, 0, &bp);
if (error) {
return error;
@@ -192,7 +236,6 @@ xfs_rtfind_back(
/*
* Different, mark where we are and return.
*/
- xfs_trans_brelse(args->tp, bp);
i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
*rtx = start - i + 1;
return 0;
@@ -206,7 +249,6 @@ xfs_rtfind_back(
/*
* If done with this block, get the previous one.
*/
- xfs_trans_brelse(args->tp, bp);
error = xfs_rtbuf_get(args, --block, 0, &bp);
if (error) {
return error;
@@ -234,7 +276,6 @@ xfs_rtfind_back(
/*
* Different, mark where we are and return.
*/
- xfs_trans_brelse(args->tp, bp);
i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
*rtx = start - i + 1;
return 0;
@@ -244,7 +285,6 @@ xfs_rtfind_back(
/*
* No match, return that we scanned the whole area.
*/
- xfs_trans_brelse(args->tp, bp);
*rtx = start - i + 1;
return 0;
}
@@ -314,7 +354,6 @@ xfs_rtfind_forw(
/*
* Different. Mark where we are and return.
*/
- xfs_trans_brelse(args->tp, bp);
i = XFS_RTLOBIT(wdiff) - bit;
*rtx = start + i - 1;
return 0;
@@ -328,7 +367,6 @@ xfs_rtfind_forw(
/*
* If done with this block, get the previous one.
*/
- xfs_trans_brelse(args->tp, bp);
error = xfs_rtbuf_get(args, ++block, 0, &bp);
if (error) {
return error;
@@ -355,7 +393,6 @@ xfs_rtfind_forw(
/*
* Different, mark where we are and return.
*/
- xfs_trans_brelse(args->tp, bp);
i += XFS_RTLOBIT(wdiff);
*rtx = start + i - 1;
return 0;
@@ -369,7 +406,6 @@ xfs_rtfind_forw(
/*
* If done with this block, get the next one.
*/
- xfs_trans_brelse(args->tp, bp);
error = xfs_rtbuf_get(args, ++block, 0, &bp);
if (error) {
return error;
@@ -395,7 +431,6 @@ xfs_rtfind_forw(
/*
* Different, mark where we are and return.
*/
- xfs_trans_brelse(args->tp, bp);
i += XFS_RTLOBIT(wdiff);
*rtx = start + i - 1;
return 0;
@@ -405,7 +440,6 @@ xfs_rtfind_forw(
/*
* No match, return that we scanned the whole area.
*/
- xfs_trans_brelse(args->tp, bp);
*rtx = start + i - 1;
return 0;
}
@@ -440,8 +474,6 @@ xfs_rtmodify_summary_int(
int log, /* log2 of extent size */
xfs_fileoff_t bbno, /* bitmap block number */
int delta, /* change to make to summary info */
- struct xfs_buf **rbpp, /* in/out: summary block buffer */
- xfs_fileoff_t *rsb, /* in/out: summary block number */
xfs_suminfo_t *sum) /* out: summary info for this block */
{
struct xfs_mount *mp = args->mp;
@@ -459,30 +491,11 @@ xfs_rtmodify_summary_int(
* Compute the block number in the summary file.
*/
sb = xfs_rtsumoffs_to_block(mp, so);
- /*
- * If we have an old buffer, and the block number matches, use that.
- */
- if (*rbpp && *rsb == sb)
- bp = *rbpp;
- /*
- * Otherwise we have to get the buffer.
- */
- else {
- /*
- * If there was an old one, get rid of it first.
- */
- if (*rbpp)
- xfs_trans_brelse(args->tp, *rbpp);
- error = xfs_rtbuf_get(args, sb, 1, &bp);
- if (error) {
- return error;
- }
- /*
- * Remember this buffer and block for the next call.
- */
- *rbpp = bp;
- *rsb = sb;
- }
+
+ error = xfs_rtbuf_get(args, sb, 1, &bp);
+ if (error)
+ return error;
+
/*
* Point to the summary information, modify/log it, and/or copy it out.
*/
@@ -510,11 +523,9 @@ xfs_rtmodify_summary(
struct xfs_rtalloc_args *args,
int log, /* log2 of extent size */
xfs_fileoff_t bbno, /* bitmap block number */
- int delta, /* change to make to summary info */
- struct xfs_buf **rbpp, /* in/out: summary block buffer */
- xfs_fileoff_t *rsb) /* in/out: summary block number */
+ int delta) /* in/out: summary block number */
{
- return xfs_rtmodify_summary_int(args, log, bbno, delta, rbpp, rsb, NULL);
+ return xfs_rtmodify_summary_int(args, log, bbno, delta, NULL);
}
/* Log rtbitmap block from the word @from to the byte before @next. */
@@ -685,9 +696,7 @@ int
xfs_rtfree_range(
struct xfs_rtalloc_args *args,
xfs_rtxnum_t start, /* starting rtext to free */
- xfs_rtxlen_t len, /* length to free */
- struct xfs_buf **rbpp, /* in/out: summary block buffer */
- xfs_fileoff_t *rsb) /* in/out: summary block number */
+ xfs_rtxlen_t len) /* in/out: summary block number */
{
struct xfs_mount *mp = args->mp;
xfs_rtxnum_t end; /* end of the freed extent */
@@ -716,7 +725,7 @@ xfs_rtfree_range(
* Find the next allocated block (end of allocated extent).
*/
error = xfs_rtfind_forw(args, end, mp->m_sb.sb_rextents - 1,
- &postblock);
+ &postblock);
if (error)
return error;
/*
@@ -725,8 +734,8 @@ xfs_rtfree_range(
*/
if (preblock < start) {
error = xfs_rtmodify_summary(args,
- XFS_RTBLOCKLOG(start - preblock),
- xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb);
+ XFS_RTBLOCKLOG(start - preblock),
+ xfs_rtx_to_rbmblock(mp, preblock), -1);
if (error) {
return error;
}
@@ -737,8 +746,8 @@ xfs_rtfree_range(
*/
if (postblock > end) {
error = xfs_rtmodify_summary(args,
- XFS_RTBLOCKLOG(postblock - end),
- xfs_rtx_to_rbmblock(mp, end + 1), -1, rbpp, rsb);
+ XFS_RTBLOCKLOG(postblock - end),
+ xfs_rtx_to_rbmblock(mp, end + 1), -1);
if (error) {
return error;
}
@@ -747,10 +756,9 @@ xfs_rtfree_range(
* Increment the summary information corresponding to the entire
* (new) free extent.
*/
- error = xfs_rtmodify_summary(args,
- XFS_RTBLOCKLOG(postblock + 1 - preblock),
- xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb);
- return error;
+ return xfs_rtmodify_summary(args,
+ XFS_RTBLOCKLOG(postblock + 1 - preblock),
+ xfs_rtx_to_rbmblock(mp, preblock), 1);
}
/*
@@ -820,7 +828,6 @@ xfs_rtcheck_range(
/*
* Different, compute first wrong bit and return.
*/
- xfs_trans_brelse(args->tp, bp);
i = XFS_RTLOBIT(wdiff) - bit;
*new = start + i;
*stat = 0;
@@ -835,7 +842,6 @@ xfs_rtcheck_range(
/*
* If done with this block, get the next one.
*/
- xfs_trans_brelse(args->tp, bp);
error = xfs_rtbuf_get(args, ++block, 0, &bp);
if (error) {
return error;
@@ -862,7 +868,6 @@ xfs_rtcheck_range(
/*
* Different, compute first wrong bit and return.
*/
- xfs_trans_brelse(args->tp, bp);
i += XFS_RTLOBIT(wdiff);
*new = start + i;
*stat = 0;
@@ -877,7 +882,6 @@ xfs_rtcheck_range(
/*
* If done with this block, get the next one.
*/
- xfs_trans_brelse(args->tp, bp);
error = xfs_rtbuf_get(args, ++block, 0, &bp);
if (error) {
return error;
@@ -903,7 +907,6 @@ xfs_rtcheck_range(
/*
* Different, compute first wrong bit and return.
*/
- xfs_trans_brelse(args->tp, bp);
i += XFS_RTLOBIT(wdiff);
*new = start + i;
*stat = 0;
@@ -914,7 +917,6 @@ xfs_rtcheck_range(
/*
* Successful, return.
*/
- xfs_trans_brelse(args->tp, bp);
*new = start + i;
*stat = 1;
return 0;
@@ -959,8 +961,6 @@ xfs_rtfree_extent(
.tp = tp,
};
int error;
- xfs_fsblock_t sb; /* summary file block number */
- struct xfs_buf *sumbp = NULL; /* summary file block buffer */
struct timespec64 atime;
ASSERT(mp->m_rbmip->i_itemp != NULL);
@@ -973,10 +973,10 @@ xfs_rtfree_extent(
/*
* Free the range of realtime blocks.
*/
- error = xfs_rtfree_range(&args, start, len, &sumbp, &sb);
- if (error) {
- return error;
- }
+ error = xfs_rtfree_range(&args, start, len);
+ if (error)
+ goto out;
+
/*
* Mark more blocks free in the superblock.
*/
@@ -995,7 +995,10 @@ xfs_rtfree_extent(
inode_set_atime_to_ts(VFS_I(mp->m_rbmip), atime);
xfs_trans_log_inode(tp, mp->m_rbmip, XFS_ILOG_CORE);
}
- return 0;
+ error = 0;
+out:
+ xfs_rtbuf_cache_relse(&args);
+ return error;
}
/*
@@ -1086,6 +1089,7 @@ xfs_rtalloc_query_range(
rtstart = rtend + 1;
}
+ xfs_rtbuf_cache_relse(&args);
return error;
}
@@ -1124,6 +1128,7 @@ xfs_rtalloc_extent_is_free(
int error;
error = xfs_rtcheck_range(&args, start, len, 1, &end, &matches);
+ xfs_rtbuf_cache_relse(&args);
if (error)
return error;
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index 025a7efc2..ac8cd1412 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -12,6 +12,12 @@
struct xfs_rtalloc_args {
struct xfs_mount *mp;
struct xfs_trans *tp;
+
+ struct xfs_buf *rbmbp; /* bitmap block buffer */
+ struct xfs_buf *sumbp; /* summary block buffer */
+
+ xfs_fileoff_t rbmoff; /* bitmap block number */
+ xfs_fileoff_t sumoff; /* summary block number */
};
static inline xfs_rtblock_t
@@ -289,6 +295,8 @@ typedef int (*xfs_rtalloc_query_range_fn)(
void *priv);
#ifdef CONFIG_XFS_RT
+void xfs_rtbuf_cache_relse(struct xfs_rtalloc_args *args);
+
int xfs_rtbuf_get(struct xfs_rtalloc_args *args, xfs_fileoff_t block,
int issum, struct xfs_buf **bpp);
int xfs_rtcheck_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
@@ -300,13 +308,11 @@ int xfs_rtfind_forw(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
int xfs_rtmodify_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
xfs_rtxlen_t len, int val);
int xfs_rtmodify_summary_int(struct xfs_rtalloc_args *args, int log,
- xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
- xfs_fileoff_t *rsb, xfs_suminfo_t *sum);
+ xfs_fileoff_t bbno, int delta, xfs_suminfo_t *sum);
int xfs_rtmodify_summary(struct xfs_rtalloc_args *args, int log,
- xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp,
- xfs_fileoff_t *rsb);
+ xfs_fileoff_t bbno, int delta);
int xfs_rtfree_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
- xfs_rtxlen_t len, struct xfs_buf **rbpp, xfs_fileoff_t *rsb);
+ xfs_rtxlen_t len);
int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,
const struct xfs_rtalloc_rec *low_rec,
const struct xfs_rtalloc_rec *high_rec,
@@ -346,6 +352,7 @@ unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp,
# define xfs_rtalloc_query_range(m,t,l,h,f,p) (-ENOSYS)
# define xfs_rtalloc_query_all(m,t,f,p) (-ENOSYS)
# define xfs_rtbuf_get(m,t,b,i,p) (-ENOSYS)
+# define xfs_rtbuf_cache_relse(a) (0)
# define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS)
static inline xfs_filblks_t
xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 29/35] xfs: simplify xfs_rtbuf_get calling conventions
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (27 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 28/35] xfs: cache last bitmap block in realtime allocator cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 30/35] xfs: simplify rt bitmap/summary block accessor functions cem
` (6 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: 5b1d0ae9753f0654ab56c1e06155b3abf2919d71
Now that xfs_rtalloc_args holds references to the last-read bitmap and
summary blocks, we don't need to pass the buffer pointer out of
xfs_rtbuf_get.
Callers no longer have to xfs_trans_brelse on their own, though they are
required to call xfs_rtbuf_cache_relse before the xfs_rtalloc_args goes
out of scope.
While we're at it, create some trivial helpers so that we don't have to
remember if "0" means "bitmap" and "1" means "summary".
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 115 ++++++++++++++++++------------------------
libxfs/xfs_rtbitmap.h | 22 +++++++-
2 files changed, 69 insertions(+), 68 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index e9c70ff88..bc3ce7bce 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -70,8 +70,7 @@ int
xfs_rtbuf_get(
struct xfs_rtalloc_args *args,
xfs_fileoff_t block, /* block number in bitmap or summary */
- int issum, /* is summary not bitmap */
- struct xfs_buf **bpp) /* output: buffer for the block */
+ int issum) /* is summary not bitmap */
{
struct xfs_mount *mp = args->mp;
struct xfs_buf **cbpp; /* cached block buffer */
@@ -98,10 +97,9 @@ xfs_rtbuf_get(
/*
* If we have a cached buffer, and the block number matches, use that.
*/
- if (*cbpp && *coffp == block) {
- *bpp = *cbpp;
+ if (*cbpp && *coffp == block)
return 0;
- }
+
/*
* Otherwise we have to have to get the buffer. If there was an old
* one, get rid of it first.
@@ -126,7 +124,7 @@ xfs_rtbuf_get(
return error;
xfs_trans_buf_set_type(args->tp, bp, type);
- *cbpp = *bpp = bp;
+ *cbpp = bp;
*coffp = block;
return 0;
}
@@ -145,7 +143,6 @@ xfs_rtfind_back(
struct xfs_mount *mp = args->mp;
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
- struct xfs_buf *bp; /* buf for the block */
int error; /* error value */
xfs_rtxnum_t firstbit; /* first useful bit in the word */
xfs_rtxnum_t i; /* current bit number rel. to start */
@@ -160,10 +157,9 @@ xfs_rtfind_back(
* Compute and read in starting bitmap block for starting block.
*/
block = xfs_rtx_to_rbmblock(mp, start);
- error = xfs_rtbuf_get(args, block, 0, &bp);
- if (error) {
+ error = xfs_rtbitmap_read_buf(args, block);
+ if (error)
return error;
- }
/*
* Get the first word's index & point to it.
@@ -175,7 +171,7 @@ xfs_rtfind_back(
* Compute match value, based on the bit at start: if 1 (free)
* then all-ones, else all-zeroes.
*/
- incore = xfs_rtbitmap_getword(bp, word);
+ incore = xfs_rtbitmap_getword(args->rbmbp, word);
want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
/*
* If the starting position is not word-aligned, deal with the
@@ -210,10 +206,9 @@ xfs_rtfind_back(
/*
* If done with this block, get the previous one.
*/
- error = xfs_rtbuf_get(args, --block, 0, &bp);
- if (error) {
+ error = xfs_rtbitmap_read_buf(args, --block);
+ if (error)
return error;
- }
word = mp->m_blockwsize - 1;
}
@@ -231,7 +226,7 @@ xfs_rtfind_back(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(bp, word);
+ incore = xfs_rtbitmap_getword(args->rbmbp, word);
if ((wdiff = incore ^ want)) {
/*
* Different, mark where we are and return.
@@ -249,10 +244,9 @@ xfs_rtfind_back(
/*
* If done with this block, get the previous one.
*/
- error = xfs_rtbuf_get(args, --block, 0, &bp);
- if (error) {
+ error = xfs_rtbitmap_read_buf(args, --block);
+ if (error)
return error;
- }
word = mp->m_blockwsize - 1;
}
@@ -271,7 +265,7 @@ xfs_rtfind_back(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(bp, word);
+ incore = xfs_rtbitmap_getword(args->rbmbp, word);
if ((wdiff = (incore ^ want) & mask)) {
/*
* Different, mark where we are and return.
@@ -303,7 +297,6 @@ xfs_rtfind_forw(
struct xfs_mount *mp = args->mp;
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
- struct xfs_buf *bp; /* buf for the block */
int error;
xfs_rtxnum_t i; /* current bit number rel. to start */
xfs_rtxnum_t lastbit;/* last useful bit in the word */
@@ -318,10 +311,9 @@ xfs_rtfind_forw(
* Compute and read in starting bitmap block for starting block.
*/
block = xfs_rtx_to_rbmblock(mp, start);
- error = xfs_rtbuf_get(args, block, 0, &bp);
- if (error) {
+ error = xfs_rtbitmap_read_buf(args, block);
+ if (error)
return error;
- }
/*
* Get the first word's index & point to it.
@@ -333,7 +325,7 @@ xfs_rtfind_forw(
* Compute match value, based on the bit at start: if 1 (free)
* then all-ones, else all-zeroes.
*/
- incore = xfs_rtbitmap_getword(bp, word);
+ incore = xfs_rtbitmap_getword(args->rbmbp, word);
want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
/*
* If the starting position is not word-aligned, deal with the
@@ -367,10 +359,9 @@ xfs_rtfind_forw(
/*
* If done with this block, get the previous one.
*/
- error = xfs_rtbuf_get(args, ++block, 0, &bp);
- if (error) {
+ error = xfs_rtbitmap_read_buf(args, ++block);
+ if (error)
return error;
- }
word = 0;
}
@@ -388,7 +379,7 @@ xfs_rtfind_forw(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(bp, word);
+ incore = xfs_rtbitmap_getword(args->rbmbp, word);
if ((wdiff = incore ^ want)) {
/*
* Different, mark where we are and return.
@@ -406,10 +397,9 @@ xfs_rtfind_forw(
/*
* If done with this block, get the next one.
*/
- error = xfs_rtbuf_get(args, ++block, 0, &bp);
- if (error) {
+ error = xfs_rtbitmap_read_buf(args, ++block);
+ if (error)
return error;
- }
word = 0;
}
@@ -426,7 +416,7 @@ xfs_rtfind_forw(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(bp, word);
+ incore = xfs_rtbitmap_getword(args->rbmbp, word);
if ((wdiff = (incore ^ want) & mask)) {
/*
* Different, mark where we are and return.
@@ -477,7 +467,6 @@ xfs_rtmodify_summary_int(
xfs_suminfo_t *sum) /* out: summary info for this block */
{
struct xfs_mount *mp = args->mp;
- struct xfs_buf *bp; /* buffer for the summary block */
int error;
xfs_fileoff_t sb; /* summary fsblock */
xfs_rtsumoff_t so; /* index into the summary file */
@@ -492,7 +481,7 @@ xfs_rtmodify_summary_int(
*/
sb = xfs_rtsumoffs_to_block(mp, so);
- error = xfs_rtbuf_get(args, sb, 1, &bp);
+ error = xfs_rtsummary_read_buf(args, sb);
if (error)
return error;
@@ -501,7 +490,8 @@ xfs_rtmodify_summary_int(
*/
infoword = xfs_rtsumoffs_to_infoword(mp, so);
if (delta) {
- xfs_suminfo_t val = xfs_suminfo_add(bp, infoword, delta);
+ xfs_suminfo_t val = xfs_suminfo_add(args->sumbp, infoword,
+ delta);
if (mp->m_rsum_cache) {
if (val == 0 && log == mp->m_rsum_cache[bbno])
@@ -509,11 +499,11 @@ xfs_rtmodify_summary_int(
if (val != 0 && log < mp->m_rsum_cache[bbno])
mp->m_rsum_cache[bbno] = log;
}
- xfs_trans_log_rtsummary(args->tp, bp, infoword);
+ xfs_trans_log_rtsummary(args->tp, args->sumbp, infoword);
if (sum)
*sum = val;
} else if (sum) {
- *sum = xfs_suminfo_get(bp, infoword);
+ *sum = xfs_suminfo_get(args->sumbp, infoword);
}
return 0;
}
@@ -558,7 +548,6 @@ xfs_rtmodify_range(
struct xfs_mount *mp = args->mp;
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
- struct xfs_buf *bp; /* buf for the block */
int error;
int i; /* current bit number rel. to start */
int lastbit; /* last useful bit in word */
@@ -574,10 +563,9 @@ xfs_rtmodify_range(
/*
* Read the bitmap block, and point to its data.
*/
- error = xfs_rtbuf_get(args, block, 0, &bp);
- if (error) {
+ error = xfs_rtbitmap_read_buf(args, block);
+ if (error)
return error;
- }
/*
* Compute the starting word's address, and starting bit.
@@ -601,12 +589,12 @@ xfs_rtmodify_range(
/*
* Set/clear the active bits.
*/
- incore = xfs_rtbitmap_getword(bp, word);
+ incore = xfs_rtbitmap_getword(args->rbmbp, word);
if (val)
incore |= mask;
else
incore &= ~mask;
- xfs_rtbitmap_setword(bp, word, incore);
+ xfs_rtbitmap_setword(args->rbmbp, word, incore);
i = lastbit - bit;
/*
* Go on to the next block if that's where the next word is
@@ -617,12 +605,11 @@ xfs_rtmodify_range(
* Log the changed part of this block.
* Get the next one.
*/
- xfs_trans_log_rtbitmap(args->tp, bp, firstword,
+ xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword,
word);
- error = xfs_rtbuf_get(args, ++block, 0, &bp);
- if (error) {
+ error = xfs_rtbitmap_read_buf(args, ++block);
+ if (error)
return error;
- }
firstword = word = 0;
}
@@ -640,7 +627,7 @@ xfs_rtmodify_range(
/*
* Set the word value correctly.
*/
- xfs_rtbitmap_setword(bp, word, val);
+ xfs_rtbitmap_setword(args->rbmbp, word, val);
i += XFS_NBWORD;
/*
* Go on to the next block if that's where the next word is
@@ -651,9 +638,9 @@ xfs_rtmodify_range(
* Log the changed part of this block.
* Get the next one.
*/
- xfs_trans_log_rtbitmap(args->tp, bp, firstword,
+ xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword,
word);
- error = xfs_rtbuf_get(args, ++block, 0, &bp);
+ error = xfs_rtbitmap_read_buf(args, ++block);
if (error)
return error;
@@ -672,19 +659,19 @@ xfs_rtmodify_range(
/*
* Set/clear the active bits.
*/
- incore = xfs_rtbitmap_getword(bp, word);
+ incore = xfs_rtbitmap_getword(args->rbmbp, word);
if (val)
incore |= mask;
else
incore &= ~mask;
- xfs_rtbitmap_setword(bp, word, incore);
+ xfs_rtbitmap_setword(args->rbmbp, word, incore);
word++;
}
/*
* Log any remaining changed bytes.
*/
if (word > firstword)
- xfs_trans_log_rtbitmap(args->tp, bp, firstword, word);
+ xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword, word);
return 0;
}
@@ -777,7 +764,6 @@ xfs_rtcheck_range(
struct xfs_mount *mp = args->mp;
int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */
- struct xfs_buf *bp; /* buf for the block */
int error;
xfs_rtxnum_t i; /* current bit number rel. to start */
xfs_rtxnum_t lastbit; /* last useful bit in word */
@@ -793,10 +779,9 @@ xfs_rtcheck_range(
/*
* Read the bitmap block.
*/
- error = xfs_rtbuf_get(args, block, 0, &bp);
- if (error) {
+ error = xfs_rtbitmap_read_buf(args, block);
+ if (error)
return error;
- }
/*
* Compute the starting word's address, and starting bit.
@@ -823,7 +808,7 @@ xfs_rtcheck_range(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(bp, word);
+ incore = xfs_rtbitmap_getword(args->rbmbp, word);
if ((wdiff = (incore ^ val) & mask)) {
/*
* Different, compute first wrong bit and return.
@@ -842,10 +827,9 @@ xfs_rtcheck_range(
/*
* If done with this block, get the next one.
*/
- error = xfs_rtbuf_get(args, ++block, 0, &bp);
- if (error) {
+ error = xfs_rtbitmap_read_buf(args, ++block);
+ if (error)
return error;
- }
word = 0;
}
@@ -863,7 +847,7 @@ xfs_rtcheck_range(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(bp, word);
+ incore = xfs_rtbitmap_getword(args->rbmbp, word);
if ((wdiff = incore ^ val)) {
/*
* Different, compute first wrong bit and return.
@@ -882,10 +866,9 @@ xfs_rtcheck_range(
/*
* If done with this block, get the next one.
*/
- error = xfs_rtbuf_get(args, ++block, 0, &bp);
- if (error) {
+ error = xfs_rtbitmap_read_buf(args, ++block);
+ if (error)
return error;
- }
word = 0;
}
@@ -902,7 +885,7 @@ xfs_rtcheck_range(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(bp, word);
+ incore = xfs_rtbitmap_getword(args->rbmbp, word);
if ((wdiff = (incore ^ val) & mask)) {
/*
* Different, compute first wrong bit and return.
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index ac8cd1412..b5505da7a 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -298,7 +298,24 @@ typedef int (*xfs_rtalloc_query_range_fn)(
void xfs_rtbuf_cache_relse(struct xfs_rtalloc_args *args);
int xfs_rtbuf_get(struct xfs_rtalloc_args *args, xfs_fileoff_t block,
- int issum, struct xfs_buf **bpp);
+ int issum);
+
+static inline int
+xfs_rtbitmap_read_buf(
+ struct xfs_rtalloc_args *args,
+ xfs_fileoff_t block)
+{
+ return xfs_rtbuf_get(args, block, 0);
+}
+
+static inline int
+xfs_rtsummary_read_buf(
+ struct xfs_rtalloc_args *args,
+ xfs_fileoff_t block)
+{
+ return xfs_rtbuf_get(args, block, 1);
+}
+
int xfs_rtcheck_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
xfs_rtxlen_t len, int val, xfs_rtxnum_t *new, int *stat);
int xfs_rtfind_back(struct xfs_rtalloc_args *args, xfs_rtxnum_t start,
@@ -351,7 +368,8 @@ unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp,
# define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS)
# define xfs_rtalloc_query_range(m,t,l,h,f,p) (-ENOSYS)
# define xfs_rtalloc_query_all(m,t,f,p) (-ENOSYS)
-# define xfs_rtbuf_get(m,t,b,i,p) (-ENOSYS)
+# define xfs_rtbitmap_read_buf(a,b) (-ENOSYS)
+# define xfs_rtsummary_read_buf(a,b) (-ENOSYS)
# define xfs_rtbuf_cache_relse(a) (0)
# define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS)
static inline xfs_filblks_t
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 30/35] xfs: simplify rt bitmap/summary block accessor functions
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (28 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 29/35] xfs: simplify xfs_rtbuf_get calling conventions cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 31/35] xfs: invert the realtime summary cache cem
` (5 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: e2cf427c91494ea0d1173a911090c39665c5fdef
Simplify the calling convention of these functions since the
xfs_rtalloc_args structure contains the parameters we need.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 61 ++++++++++++++++++++-----------------------
libxfs/xfs_rtbitmap.h | 24 ++++++++---------
2 files changed, 41 insertions(+), 44 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index bc3ce7bce..f5d7e14ab 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -171,7 +171,7 @@ xfs_rtfind_back(
* Compute match value, based on the bit at start: if 1 (free)
* then all-ones, else all-zeroes.
*/
- incore = xfs_rtbitmap_getword(args->rbmbp, word);
+ incore = xfs_rtbitmap_getword(args, word);
want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
/*
* If the starting position is not word-aligned, deal with the
@@ -226,7 +226,7 @@ xfs_rtfind_back(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(args->rbmbp, word);
+ incore = xfs_rtbitmap_getword(args, word);
if ((wdiff = incore ^ want)) {
/*
* Different, mark where we are and return.
@@ -265,7 +265,7 @@ xfs_rtfind_back(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(args->rbmbp, word);
+ incore = xfs_rtbitmap_getword(args, word);
if ((wdiff = (incore ^ want) & mask)) {
/*
* Different, mark where we are and return.
@@ -325,7 +325,7 @@ xfs_rtfind_forw(
* Compute match value, based on the bit at start: if 1 (free)
* then all-ones, else all-zeroes.
*/
- incore = xfs_rtbitmap_getword(args->rbmbp, word);
+ incore = xfs_rtbitmap_getword(args, word);
want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
/*
* If the starting position is not word-aligned, deal with the
@@ -379,7 +379,7 @@ xfs_rtfind_forw(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(args->rbmbp, word);
+ incore = xfs_rtbitmap_getword(args, word);
if ((wdiff = incore ^ want)) {
/*
* Different, mark where we are and return.
@@ -416,7 +416,7 @@ xfs_rtfind_forw(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(args->rbmbp, word);
+ incore = xfs_rtbitmap_getword(args, word);
if ((wdiff = (incore ^ want) & mask)) {
/*
* Different, mark where we are and return.
@@ -437,16 +437,16 @@ xfs_rtfind_forw(
/* Log rtsummary counter at @infoword. */
static inline void
xfs_trans_log_rtsummary(
- struct xfs_trans *tp,
- struct xfs_buf *bp,
+ struct xfs_rtalloc_args *args,
unsigned int infoword)
{
+ struct xfs_buf *bp = args->sumbp;
size_t first, last;
- first = (void *)xfs_rsumblock_infoptr(bp, infoword) - bp->b_addr;
+ first = (void *)xfs_rsumblock_infoptr(args, infoword) - bp->b_addr;
last = first + sizeof(xfs_suminfo_t) - 1;
- xfs_trans_log_buf(tp, bp, first, last);
+ xfs_trans_log_buf(args->tp, bp, first, last);
}
/*
@@ -490,8 +490,7 @@ xfs_rtmodify_summary_int(
*/
infoword = xfs_rtsumoffs_to_infoword(mp, so);
if (delta) {
- xfs_suminfo_t val = xfs_suminfo_add(args->sumbp, infoword,
- delta);
+ xfs_suminfo_t val = xfs_suminfo_add(args, infoword, delta);
if (mp->m_rsum_cache) {
if (val == 0 && log == mp->m_rsum_cache[bbno])
@@ -499,11 +498,11 @@ xfs_rtmodify_summary_int(
if (val != 0 && log < mp->m_rsum_cache[bbno])
mp->m_rsum_cache[bbno] = log;
}
- xfs_trans_log_rtsummary(args->tp, args->sumbp, infoword);
+ xfs_trans_log_rtsummary(args, infoword);
if (sum)
*sum = val;
} else if (sum) {
- *sum = xfs_suminfo_get(args->sumbp, infoword);
+ *sum = xfs_suminfo_get(args, infoword);
}
return 0;
}
@@ -521,17 +520,17 @@ xfs_rtmodify_summary(
/* Log rtbitmap block from the word @from to the byte before @next. */
static inline void
xfs_trans_log_rtbitmap(
- struct xfs_trans *tp,
- struct xfs_buf *bp,
+ struct xfs_rtalloc_args *args,
unsigned int from,
unsigned int next)
{
+ struct xfs_buf *bp = args->rbmbp;
size_t first, last;
- first = (void *)xfs_rbmblock_wordptr(bp, from) - bp->b_addr;
- last = ((void *)xfs_rbmblock_wordptr(bp, next) - 1) - bp->b_addr;
+ first = (void *)xfs_rbmblock_wordptr(args, from) - bp->b_addr;
+ last = ((void *)xfs_rbmblock_wordptr(args, next) - 1) - bp->b_addr;
- xfs_trans_log_buf(tp, bp, first, last);
+ xfs_trans_log_buf(args->tp, bp, first, last);
}
/*
@@ -589,12 +588,12 @@ xfs_rtmodify_range(
/*
* Set/clear the active bits.
*/
- incore = xfs_rtbitmap_getword(args->rbmbp, word);
+ incore = xfs_rtbitmap_getword(args, word);
if (val)
incore |= mask;
else
incore &= ~mask;
- xfs_rtbitmap_setword(args->rbmbp, word, incore);
+ xfs_rtbitmap_setword(args, word, incore);
i = lastbit - bit;
/*
* Go on to the next block if that's where the next word is
@@ -605,8 +604,7 @@ xfs_rtmodify_range(
* Log the changed part of this block.
* Get the next one.
*/
- xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword,
- word);
+ xfs_trans_log_rtbitmap(args, firstword, word);
error = xfs_rtbitmap_read_buf(args, ++block);
if (error)
return error;
@@ -627,7 +625,7 @@ xfs_rtmodify_range(
/*
* Set the word value correctly.
*/
- xfs_rtbitmap_setword(args->rbmbp, word, val);
+ xfs_rtbitmap_setword(args, word, val);
i += XFS_NBWORD;
/*
* Go on to the next block if that's where the next word is
@@ -638,8 +636,7 @@ xfs_rtmodify_range(
* Log the changed part of this block.
* Get the next one.
*/
- xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword,
- word);
+ xfs_trans_log_rtbitmap(args, firstword, word);
error = xfs_rtbitmap_read_buf(args, ++block);
if (error)
return error;
@@ -659,19 +656,19 @@ xfs_rtmodify_range(
/*
* Set/clear the active bits.
*/
- incore = xfs_rtbitmap_getword(args->rbmbp, word);
+ incore = xfs_rtbitmap_getword(args, word);
if (val)
incore |= mask;
else
incore &= ~mask;
- xfs_rtbitmap_setword(args->rbmbp, word, incore);
+ xfs_rtbitmap_setword(args, word, incore);
word++;
}
/*
* Log any remaining changed bytes.
*/
if (word > firstword)
- xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword, word);
+ xfs_trans_log_rtbitmap(args, firstword, word);
return 0;
}
@@ -808,7 +805,7 @@ xfs_rtcheck_range(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(args->rbmbp, word);
+ incore = xfs_rtbitmap_getword(args, word);
if ((wdiff = (incore ^ val) & mask)) {
/*
* Different, compute first wrong bit and return.
@@ -847,7 +844,7 @@ xfs_rtcheck_range(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(args->rbmbp, word);
+ incore = xfs_rtbitmap_getword(args, word);
if ((wdiff = incore ^ val)) {
/*
* Different, compute first wrong bit and return.
@@ -885,7 +882,7 @@ xfs_rtcheck_range(
/*
* Compute difference between actual and desired value.
*/
- incore = xfs_rtbitmap_getword(args->rbmbp, word);
+ incore = xfs_rtbitmap_getword(args, word);
if ((wdiff = (incore ^ val) & mask)) {
/*
* Different, compute first wrong bit and return.
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index b5505da7a..db2f8c924 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -175,10 +175,10 @@ xfs_rbmblock_to_rtx(
/* Return a pointer to a bitmap word within a rt bitmap block. */
static inline union xfs_rtword_raw *
xfs_rbmblock_wordptr(
- struct xfs_buf *bp,
+ struct xfs_rtalloc_args *args,
unsigned int index)
{
- union xfs_rtword_raw *words = bp->b_addr;
+ union xfs_rtword_raw *words = args->rbmbp->b_addr;
return words + index;
}
@@ -186,10 +186,10 @@ xfs_rbmblock_wordptr(
/* Convert an ondisk bitmap word to its incore representation. */
static inline xfs_rtword_t
xfs_rtbitmap_getword(
- struct xfs_buf *bp,
+ struct xfs_rtalloc_args *args,
unsigned int index)
{
- union xfs_rtword_raw *word = xfs_rbmblock_wordptr(bp, index);
+ union xfs_rtword_raw *word = xfs_rbmblock_wordptr(args, index);
return word->old;
}
@@ -197,11 +197,11 @@ xfs_rtbitmap_getword(
/* Set an ondisk bitmap word from an incore representation. */
static inline void
xfs_rtbitmap_setword(
- struct xfs_buf *bp,
+ struct xfs_rtalloc_args *args,
unsigned int index,
xfs_rtword_t value)
{
- union xfs_rtword_raw *word = xfs_rbmblock_wordptr(bp, index);
+ union xfs_rtword_raw *word = xfs_rbmblock_wordptr(args, index);
word->old = value;
}
@@ -248,10 +248,10 @@ xfs_rtsumoffs_to_infoword(
/* Return a pointer to a summary info word within a rt summary block. */
static inline union xfs_suminfo_raw *
xfs_rsumblock_infoptr(
- struct xfs_buf *bp,
+ struct xfs_rtalloc_args *args,
unsigned int index)
{
- union xfs_suminfo_raw *info = bp->b_addr;
+ union xfs_suminfo_raw *info = args->sumbp->b_addr;
return info + index;
}
@@ -259,10 +259,10 @@ xfs_rsumblock_infoptr(
/* Get the current value of a summary counter. */
static inline xfs_suminfo_t
xfs_suminfo_get(
- struct xfs_buf *bp,
+ struct xfs_rtalloc_args *args,
unsigned int index)
{
- union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(bp, index);
+ union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(args, index);
return info->old;
}
@@ -270,11 +270,11 @@ xfs_suminfo_get(
/* 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,
+ struct xfs_rtalloc_args *args,
unsigned int index,
int delta)
{
- union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(bp, index);
+ union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(args, index);
info->old += delta;
return info->old;
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 31/35] xfs: invert the realtime summary cache
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (29 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 30/35] xfs: simplify rt bitmap/summary block accessor functions cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 32/35] xfs: factor out xfs_defer_pending_abort cem
` (4 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: Omar Sandoval <osandov@fb.com>
Source kernel commit: e23aaf450de733044a74bc95528f728478b61c2a
In commit 355e3532132b ("xfs: cache minimum realtime summary level"), I
added a cache of the minimum level of the realtime summary that has any
free extents. However, it turns out that the _maximum_ level is more
useful for upcoming optimizations, and basically equivalent for the
existing usage. So, let's change the meaning of the cache to be the
maximum level + 1, or 0 if there are no free extents.
For example, if the cache contains:
{0, 4}
then there are no free extents starting in realtime bitmap block 0, and
there are no free extents larger than or equal to 2^4 blocks starting in
realtime bitmap block 1. The cache is a loose upper bound, so there may
or may not be free extents smaller than 2^4 blocks in realtime bitmap
block 1.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_rtbitmap.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
index f5d7e14ab..8f313339e 100644
--- a/libxfs/xfs_rtbitmap.c
+++ b/libxfs/xfs_rtbitmap.c
@@ -493,10 +493,10 @@ xfs_rtmodify_summary_int(
xfs_suminfo_t val = xfs_suminfo_add(args, infoword, delta);
if (mp->m_rsum_cache) {
- if (val == 0 && log == mp->m_rsum_cache[bbno])
- mp->m_rsum_cache[bbno]++;
- if (val != 0 && log < mp->m_rsum_cache[bbno])
+ if (val == 0 && log + 1 == mp->m_rsum_cache[bbno])
mp->m_rsum_cache[bbno] = log;
+ if (val != 0 && log >= mp->m_rsum_cache[bbno])
+ mp->m_rsum_cache[bbno] = log + 1;
}
xfs_trans_log_rtsummary(args, infoword);
if (sum)
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 32/35] xfs: factor out xfs_defer_pending_abort
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (30 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 31/35] xfs: invert the realtime summary cache cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 33/35] xfs: abort intent items when recovery intents fail cem
` (3 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: Long Li <leo.lilong@huawei.com>
Source kernel commit: 2a5db859c6825b5d50377dda9c3cc729c20cad43
Factor out xfs_defer_pending_abort() from xfs_defer_trans_abort(), which
not use transaction parameter, so it can be used after the transaction
life cycle.
Signed-off-by: Long Li <leo.lilong@huawei.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_defer.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c
index 77a94f58f..16060ef88 100644
--- a/libxfs/xfs_defer.c
+++ b/libxfs/xfs_defer.c
@@ -240,21 +240,18 @@ xfs_defer_create_intents(
return ret;
}
-/* Abort all the intents that were committed. */
STATIC void
-xfs_defer_trans_abort(
- struct xfs_trans *tp,
- struct list_head *dop_pending)
+xfs_defer_pending_abort(
+ struct xfs_mount *mp,
+ struct list_head *dop_list)
{
struct xfs_defer_pending *dfp;
const struct xfs_defer_op_type *ops;
- trace_xfs_defer_trans_abort(tp, _RET_IP_);
-
/* Abort intent items that don't have a done item. */
- list_for_each_entry(dfp, dop_pending, dfp_list) {
+ list_for_each_entry(dfp, dop_list, dfp_list) {
ops = defer_op_types[dfp->dfp_type];
- trace_xfs_defer_pending_abort(tp->t_mountp, dfp);
+ trace_xfs_defer_pending_abort(mp, dfp);
if (dfp->dfp_intent && !dfp->dfp_done) {
ops->abort_intent(dfp->dfp_intent);
dfp->dfp_intent = NULL;
@@ -262,6 +259,16 @@ xfs_defer_trans_abort(
}
}
+/* Abort all the intents that were committed. */
+STATIC void
+xfs_defer_trans_abort(
+ struct xfs_trans *tp,
+ struct list_head *dop_pending)
+{
+ trace_xfs_defer_trans_abort(tp, _RET_IP_);
+ xfs_defer_pending_abort(tp->t_mountp, dop_pending);
+}
+
/*
* Capture resources that the caller said not to release ("held") when the
* transaction commits. Caller is responsible for zero-initializing @dres.
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 33/35] xfs: abort intent items when recovery intents fail
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (31 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 32/35] xfs: factor out xfs_defer_pending_abort cem
@ 2024-02-15 12:08 ` cem
2024-02-15 12:08 ` [PATCH 34/35] xfs: fix internal error from AGFL exhaustion cem
` (2 subsequent siblings)
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: Long Li <leo.lilong@huawei.com>
Source kernel commit: f8f9d952e42dd49ae534f61f2fa7ca0876cb9848
When recovering intents, we capture newly created intent items as part of
point, we forget to remove those newly created intent items from the AIL
and hang:
[root@localhost ~]# cat /proc/539/stack
[<0>] xfs_ail_push_all_sync+0x174/0x230
[<0>] xfs_unmount_flush_inodes+0x8d/0xd0
[<0>] xfs_mountfs+0x15f7/0x1e70
[<0>] xfs_fs_fill_super+0x10ec/0x1b20
[<0>] get_tree_bdev+0x3c8/0x730
[<0>] vfs_get_tree+0x89/0x2c0
[<0>] path_mount+0xecf/0x1800
[<0>] do_mount+0xf3/0x110
[<0>] __x64_sys_mount+0x154/0x1f0
[<0>] do_syscall_64+0x39/0x80
[<0>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
When newly created intent items fail to commit via transaction, intent
recovery hasn't created done items for these newly created intent items,
so the capture structure is the sole owner of the captured intent items.
We must release them explicitly or else they leak:
unreferenced object 0xffff888016719108 (size 432):
comm "mount", pid 529, jiffies 4294706839 (age 144.463s)
hex dump (first 32 bytes):
08 91 71 16 80 88 ff ff 08 91 71 16 80 88 ff ff ..q.......q.....
18 91 71 16 80 88 ff ff 18 91 71 16 80 88 ff ff ..q.......q.....
backtrace:
[<ffffffff8230c68f>] xfs_efi_init+0x18f/0x1d0
[<ffffffff8230c720>] xfs_extent_free_create_intent+0x50/0x150
[<ffffffff821b671a>] xfs_defer_create_intents+0x16a/0x340
[<ffffffff821bac3e>] xfs_defer_ops_capture_and_commit+0x8e/0xad0
[<ffffffff82322bb9>] xfs_cui_item_recover+0x819/0x980
[<ffffffff823289b6>] xlog_recover_process_intents+0x246/0xb70
[<ffffffff8233249a>] xlog_recover_finish+0x8a/0x9a0
[<ffffffff822eeafb>] xfs_log_mount_finish+0x2bb/0x4a0
[<ffffffff822c0f4f>] xfs_mountfs+0x14bf/0x1e70
[<ffffffff822d1f80>] xfs_fs_fill_super+0x10d0/0x1b20
[<ffffffff81a21fa2>] get_tree_bdev+0x3d2/0x6d0
[<ffffffff81a1ee09>] vfs_get_tree+0x89/0x2c0
[<ffffffff81a9f35f>] path_mount+0xecf/0x1800
[<ffffffff81a9fd83>] do_mount+0xf3/0x110
[<ffffffff81aa00e4>] __x64_sys_mount+0x154/0x1f0
[<ffffffff83968739>] do_syscall_64+0x39/0x80
Fix the problem above by abort intent items that don't have a done item
when recovery intents fail.
Fixes: e6fff81e4870 ("xfs: proper replay of deferred ops queued during log recovery")
Signed-off-by: Long Li <leo.lilong@huawei.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_defer.c | 5 +++--
libxfs/xfs_defer.h | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c
index 16060ef88..7ff125c5f 100644
--- a/libxfs/xfs_defer.c
+++ b/libxfs/xfs_defer.c
@@ -758,12 +758,13 @@ xfs_defer_ops_capture(
/* Release all resources that we used to capture deferred ops. */
void
-xfs_defer_ops_capture_free(
+xfs_defer_ops_capture_abort(
struct xfs_mount *mp,
struct xfs_defer_capture *dfc)
{
unsigned short i;
+ xfs_defer_pending_abort(mp, &dfc->dfc_dfops);
xfs_defer_cancel_list(mp, &dfc->dfc_dfops);
for (i = 0; i < dfc->dfc_held.dr_bufs; i++)
@@ -804,7 +805,7 @@ xfs_defer_ops_capture_and_commit(
/* Commit the transaction and add the capture structure to the list. */
error = xfs_trans_commit(tp);
if (error) {
- xfs_defer_ops_capture_free(mp, dfc);
+ xfs_defer_ops_capture_abort(mp, dfc);
return error;
}
diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h
index 114a3a493..8788ad5f6 100644
--- a/libxfs/xfs_defer.h
+++ b/libxfs/xfs_defer.h
@@ -121,7 +121,7 @@ int xfs_defer_ops_capture_and_commit(struct xfs_trans *tp,
struct list_head *capture_list);
void xfs_defer_ops_continue(struct xfs_defer_capture *d, struct xfs_trans *tp,
struct xfs_defer_resources *dres);
-void xfs_defer_ops_capture_free(struct xfs_mount *mp,
+void xfs_defer_ops_capture_abort(struct xfs_mount *mp,
struct xfs_defer_capture *d);
void xfs_defer_resources_rele(struct xfs_defer_resources *dres);
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 34/35] xfs: fix internal error from AGFL exhaustion
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (32 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 33/35] xfs: abort intent items when recovery intents fail cem
@ 2024-02-15 12:08 ` 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
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: Omar Sandoval <osandov@fb.com>
Source kernel commit: f63a5b3769ad7659da4c0420751d78958ab97675
We've been seeing XFS errors like the following:
XFS: Internal error i != 1 at line 3526 of file fs/xfs/libxfs/xfs_btree.c. Caller xfs_btree_insert+0x1ec/0x280
...
Call Trace:
xfs_corruption_error+0x94/0xa0
xfs_btree_insert+0x221/0x280
xfs_alloc_fixup_trees+0x104/0x3e0
xfs_alloc_ag_vextent_size+0x667/0x820
xfs_alloc_fix_freelist+0x5d9/0x750
xfs_free_extent_fix_freelist+0x65/0xa0
__xfs_free_extent+0x57/0x180
...
This is the XFS_IS_CORRUPT() check in xfs_btree_insert() when
xfs_btree_insrec() fails.
After converting this into a panic and dissecting the core dump, I found
that xfs_btree_insrec() is failing because it's trying to split a leaf
node in the cntbt when the AG free list is empty. In particular, it's
failing to get a block from the AGFL _while trying to refill the AGFL_.
If a single operation splits every level of the bnobt and the cntbt (and
the rmapbt if it is enabled) at once, the free list will be empty. Then,
when the next operation tries to refill the free list, it allocates
space. If the allocation does not use a full extent, it will need to
insert records for the remaining space in the bnobt and cntbt. And if
those new records go in full leaves, the leaves (and potentially more
nodes up to the old root) need to be split.
Fix it by accounting for the additional splits that may be required to
refill the free list in the calculation for the minimum free list size.
P.S. As far as I can tell, this bug has existed for a long time -- maybe
back to xfs-history commit afdf80ae7405 ("Add XFS_AG_MAXLEVELS macros
...") in April 1994! It requires a very unlucky sequence of events, and
in fact we didn't hit it until a particular sparse mmap workload updated
from 5.12 to 5.19. But this bug existed in 5.12, so it must've been
exposed by some other change in allocation or writeback patterns. It's
also much less likely to be hit with the rmapbt enabled, since that
increases the minimum free list size and is unlikely to split at the
same time as the bnobt and cntbt.
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_alloc.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c
index 4519a0555..7ac7c2f6c 100644
--- a/libxfs/xfs_alloc.c
+++ b/libxfs/xfs_alloc.c
@@ -2271,16 +2271,37 @@ xfs_alloc_min_freelist(
ASSERT(mp->m_alloc_maxlevels > 0);
+ /*
+ * For a btree shorter than the maximum height, the worst case is that
+ * every level gets split and a new level is added, then while inserting
+ * another entry to refill the AGFL, every level under the old root gets
+ * split again. This is:
+ *
+ * (full height split reservation) + (AGFL refill split height)
+ * = (current height + 1) + (current height - 1)
+ * = (new height) + (new height - 2)
+ * = 2 * new height - 2
+ *
+ * For a btree of maximum height, the worst case is that every level
+ * under the root gets split, then while inserting another entry to
+ * refill the AGFL, every level under the root gets split again. This is
+ * also:
+ *
+ * 2 * (current height - 1)
+ * = 2 * (new height - 1)
+ * = 2 * new height - 2
+ */
+
/* space needed by-bno freespace btree */
min_free = min_t(unsigned int, levels[XFS_BTNUM_BNOi] + 1,
- mp->m_alloc_maxlevels);
+ mp->m_alloc_maxlevels) * 2 - 2;
/* space needed by-size freespace btree */
min_free += min_t(unsigned int, levels[XFS_BTNUM_CNTi] + 1,
- mp->m_alloc_maxlevels);
+ mp->m_alloc_maxlevels) * 2 - 2;
/* space needed reverse mapping used space btree */
if (xfs_has_rmapbt(mp))
min_free += min_t(unsigned int, levels[XFS_BTNUM_RMAPi] + 1,
- mp->m_rmap_maxlevels);
+ mp->m_rmap_maxlevels) * 2 - 2;
return min_free;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* [PATCH 35/35] xfs: inode recovery does not validate the recovered inode
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (33 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 34/35] xfs: fix internal error from AGFL exhaustion cem
@ 2024-02-15 12:08 ` cem
2024-02-16 7:11 ` [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 Christoph Hellwig
35 siblings, 0 replies; 37+ messages in thread
From: cem @ 2024-02-15 12:08 UTC (permalink / raw)
To: linux-xfs
From: Dave Chinner <dchinner@redhat.com>
Source kernel commit: 038ca189c0d2c1570b4d922f25b524007c85cf94
Discovered when trying to track down a weird recovery corruption
issue that wasn't detected at recovery time.
The specific corruption was a zero extent count field when big
extent counts are in use, and it turns out the dinode verifier
doesn't detect that specific corruption case, either. So fix it too.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
libxfs/xfs_inode_buf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c
index 74a1bd227..fd351c252 100644
--- a/libxfs/xfs_inode_buf.c
+++ b/libxfs/xfs_inode_buf.c
@@ -507,6 +507,9 @@ xfs_dinode_verify(
if (mode && nextents + naextents > nblocks)
return __this_address;
+ if (nextents + naextents == 0 && nblocks != 0)
+ return __this_address;
+
if (S_ISDIR(mode) && nextents > mp->m_dir_geo->max_extents)
return __this_address;
--
2.43.0
^ permalink raw reply related [flat|nested] 37+ messages in thread
* Re: [PATCH 00/35] xfsprogs: libxfs-sync for 6.7
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
` (34 preceding siblings ...)
2024-02-15 12:08 ` [PATCH 35/35] xfs: inode recovery does not validate the recovered inode cem
@ 2024-02-16 7:11 ` Christoph Hellwig
35 siblings, 0 replies; 37+ messages in thread
From: Christoph Hellwig @ 2024-02-16 7:11 UTC (permalink / raw)
To: cem; +Cc: linux-xfs
On Thu, Feb 15, 2024 at 01:08:12PM +0100, cem@kernel.org wrote:
> From: Carlos Maiolino <cem@kernel.org>
>
> Hello folks,
>
> this is the libxfs-sync for 6.7. I know we don't use to publish the results on
> the list, but this release's sync was a bit more complicated, so, if you can
> spare a few minutes, I'd appreciate an extra pair of eyes on top of it.
> Also I thinkg it's a good idea to publish the patches here before pushing them
> to for-next.
I've looked over them and done some testing and the changes looks good
to me:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 37+ messages in thread
end of thread, other threads:[~2024-02-16 7:11 UTC | newest]
Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 20/35] xfs: convert rt summary macros to helpers cem
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox