Skip to contentSkip to conversation

more buffer cache cleanups

PATCH In review Christoph Hellwig 2 participants 11 messages Mar 17, 2025 – Mar 18, 2025 XFS filesystem

lore
Share & tools
lore
#0 lore raw

Hi all,

this series started by just removing the unused flags argument to the uncached buf_get/read interfaces but then escalated a bit. It is still entirely superfluous cosmetic cleanups, though.

Diffstat:

 b/fs/xfs/libxfs/xfs_ag.c |    2 
 b/fs/xfs/xfs_buf.c       |  165 +++++++++++++++++++++--------------------------
 b/fs/xfs/xfs_buf.h       |    2 
 b/fs/xfs/xfs_fsops.c     |    2 
 b/fs/xfs/xfs_mount.c     |    6 -
 b/fs/xfs/xfs_rtalloc.c   |    4 -
 fs/xfs/xfs_buf.c         |   54 +++------------
 fs/xfs/xfs_buf.h         |    2 
 fs/xfs/xfs_rtalloc.c     |    2 
 9 files changed, 96 insertions(+), 143 deletions(-)
#1 lore raw

PATCH 1/5 xfs: call xfs_buf_alloc_backing_mem from _xfs_buf_alloc

We never allocate a buffer without backing memory. Simplify the call chain by calling xfs_buf_alloc_backing_mem from _xfs_buf_alloc. To avoid a forward declaration, move _xfs_buf_alloc down a bit in the file.

Also drop the pointless _-prefix from _xfs_buf_alloc.

---
 fs/xfs/xfs_buf.c | 165 +++++++++++++++++++++--------------------------
 1 file changed, 75 insertions(+), 90 deletions(-)
fs/xfs/xfs_buf.c +75 -90
index 106ee81fa56f..f42f6e47f783 100644
@@ -118,71 +118,6 @@ xfs_buf_free_maps(
 	}
 }
 
-static int
-_xfs_buf_alloc(
-	struct xfs_buftarg	*target,
-	struct xfs_buf_map	*map,
-	int			nmaps,
-	xfs_buf_flags_t		flags,
-	struct xfs_buf		**bpp)
-{
-	struct xfs_buf		*bp;
-	int			error;
-	int			i;
-
-	*bpp = NULL;
-	bp = kmem_cache_zalloc(xfs_buf_cache,
-			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
-
-	/*
-	 * We don't want certain flags to appear in b_flags unless they are
-	 * specifically set by later operations on the buffer.
-	 */
-	flags &= ~(XBF_TRYLOCK | XBF_ASYNC | XBF_READ_AHEAD);
-
-	/*
-	 * A new buffer is held and locked by the owner.  This ensures that the
-	 * buffer is owned by the caller and racing RCU lookups right after
-	 * inserting into the hash table are safe (and will have to wait for
-	 * the unlock to do anything non-trivial).
-	 */
-	bp->b_hold = 1;
-	sema_init(&bp->b_sema, 0); /* held, no waiters */
-
-	spin_lock_init(&bp->b_lock);
-	atomic_set(&bp->b_lru_ref, 1);
-	init_completion(&bp->b_iowait);
-	INIT_LIST_HEAD(&bp->b_lru);
-	INIT_LIST_HEAD(&bp->b_list);
-	INIT_LIST_HEAD(&bp->b_li_list);
-	bp->b_target = target;
-	bp->b_mount = target->bt_mount;
-	bp->b_flags = flags;
-
-	error = xfs_buf_get_maps(bp, nmaps);
-	if (error)  {
-		kmem_cache_free(xfs_buf_cache, bp);
-		return error;
-	}
-
-	bp->b_rhash_key = map[0].bm_bn;
-	bp->b_length = 0;
-	for (i = 0; i < nmaps; i++) {
-		bp->b_maps[i].bm_bn = map[i].bm_bn;
-		bp->b_maps[i].bm_len = map[i].bm_len;
-		bp->b_length += map[i].bm_len;
-	}
-
-	atomic_set(&bp->b_pin_count, 0);
-	init_waitqueue_head(&bp->b_waiters);
-
-	XFS_STATS_INC(bp->b_mount, xb_create);
-	trace_xfs_buf_init(bp, _RET_IP_);
-
-	*bpp = bp;
-	return 0;
-}
-
 static void
 xfs_buf_free_callback(
 	struct callback_head	*cb)
@@ -342,6 +277,77 @@ xfs_buf_alloc_backing_mem(
 	return 0;
 }
 
+static int
+xfs_buf_alloc(
+	struct xfs_buftarg	*target,
+	struct xfs_buf_map	*map,
+	int			nmaps,
+	xfs_buf_flags_t		flags,
+	struct xfs_buf		**bpp)
+{
+	struct xfs_buf		*bp;
+	int			error;
+	int			i;
+
+	*bpp = NULL;
+	bp = kmem_cache_zalloc(xfs_buf_cache,
+			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
+
+	/*
+	 * We don't want certain flags to appear in b_flags unless they are
+	 * specifically set by later operations on the buffer.
+	 */
+	flags &= ~(XBF_TRYLOCK | XBF_ASYNC | XBF_READ_AHEAD);
+
+	/*
+	 * A new buffer is held and locked by the owner.  This ensures that the
+	 * buffer is owned by the caller and racing RCU lookups right after
+	 * inserting into the hash table are safe (and will have to wait for
+	 * the unlock to do anything non-trivial).
+	 */
+	bp->b_hold = 1;
+	sema_init(&bp->b_sema, 0); /* held, no waiters */
+
+	spin_lock_init(&bp->b_lock);
+	atomic_set(&bp->b_lru_ref, 1);
+	init_completion(&bp->b_iowait);
+	INIT_LIST_HEAD(&bp->b_lru);
+	INIT_LIST_HEAD(&bp->b_list);
+	INIT_LIST_HEAD(&bp->b_li_list);
+	bp->b_target = target;
+	bp->b_mount = target->bt_mount;
+	bp->b_flags = flags;
+
+	error = xfs_buf_get_maps(bp, nmaps);
+	if (error)  {
+		kmem_cache_free(xfs_buf_cache, bp);
+		return error;
+	}
+
+	bp->b_rhash_key = map[0].bm_bn;
+	bp->b_length = 0;
+	for (i = 0; i < nmaps; i++) {
+		bp->b_maps[i].bm_bn = map[i].bm_bn;
+		bp->b_maps[i].bm_len = map[i].bm_len;
+		bp->b_length += map[i].bm_len;
+	}
+
+	atomic_set(&bp->b_pin_count, 0);
+	init_waitqueue_head(&bp->b_waiters);
+
+	XFS_STATS_INC(bp->b_mount, xb_create);
+	trace_xfs_buf_init(bp, _RET_IP_);
+
+	error = xfs_buf_alloc_backing_mem(bp, flags);
+	if (error) {
+		xfs_buf_free(bp);
+		return error;
+	}
+
+	*bpp = bp;
+	return 0;
+}
+
 /*
  *	Finding and Reading Buffers
  */
@@ -525,14 +531,10 @@ xfs_buf_find_insert(
 	struct xfs_buf		*bp;
 	int			error;
 
-	error = _xfs_buf_alloc(btp, map, nmaps, flags, &new_bp);
+	error = xfs_buf_alloc(btp, map, nmaps, flags, &new_bp);
 	if (error)
 		goto out_drop_pag;
 
-	error = xfs_buf_alloc_backing_mem(new_bp, flags);
-	if (error)
-		goto out_free_buf;
-
 	/* The new buffer keeps the perag reference until it is freed. */
 	new_bp->b_pag = pag;
 
@@ -869,28 +871,11 @@ xfs_buf_get_uncached(
 	struct xfs_buf		**bpp)
 {
 	int			error;
-	struct xfs_buf		*bp;
 	DEFINE_SINGLE_BUF_MAP(map, XFS_BUF_DADDR_NULL, numblks);
 
-	/* there are currently no valid flags for xfs_buf_get_uncached */
-	ASSERT(flags == 0);
-
-	*bpp = NULL;
-
-	error = _xfs_buf_alloc(target, &map, 1, flags, &bp);
-	if (error)
-		return error;
-
-	error = xfs_buf_alloc_backing_mem(bp, flags);
-	if (error)
-		goto fail_free_buf;
-
-	trace_xfs_buf_get_uncached(bp, _RET_IP_);
-	*bpp = bp;
-	return 0;
-
-fail_free_buf:
-	xfs_buf_free(bp);
+	error = xfs_buf_alloc(target, &map, 1, flags, bpp);
+	if (!error)
+		trace_xfs_buf_get_uncached(*bpp, _RET_IP_);
 	return error;
 }
 
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] xfs: call xfs_buf_alloc_backing_mem from _xfs_buf_alloc

Quoted 8 lines · Christoph Hellwig

We never allocate a buffer without backing memory. Simplify the call chain by calling xfs_buf_alloc_backing_mem from _xfs_buf_alloc. To avoid a forward declaration, move _xfs_buf_alloc down a bit in the file.

Also drop the pointless _-prefix from _xfs_buf_alloc.

Looks good.

Quoted 210 lines
---
 fs/xfs/xfs_buf.c | 165 +++++++++++++++++++++--------------------------
 1 file changed, 75 insertions(+), 90 deletions(-)
fs/xfs/xfs_buf.c +75 -91
index 106ee81fa56f..f42f6e47f783 100644
@@ -118,71 +118,6 @@ xfs_buf_free_maps(
 	}
 }
 
-static int
-_xfs_buf_alloc(
-	struct xfs_buftarg	*target,
-	struct xfs_buf_map	*map,
-	int			nmaps,
-	xfs_buf_flags_t		flags,
-	struct xfs_buf		**bpp)
-{
-	struct xfs_buf		*bp;
-	int			error;
-	int			i;
-
-	*bpp = NULL;
-	bp = kmem_cache_zalloc(xfs_buf_cache,
-			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
-
-	/*
-	 * We don't want certain flags to appear in b_flags unless they are
-	 * specifically set by later operations on the buffer.
-	 */
-	flags &= ~(XBF_TRYLOCK | XBF_ASYNC | XBF_READ_AHEAD);
-
-	/*
-	 * A new buffer is held and locked by the owner.  This ensures that the
-	 * buffer is owned by the caller and racing RCU lookups right after
-	 * inserting into the hash table are safe (and will have to wait for
-	 * the unlock to do anything non-trivial).
-	 */
-	bp->b_hold = 1;
-	sema_init(&bp->b_sema, 0); /* held, no waiters */
-
-	spin_lock_init(&bp->b_lock);
-	atomic_set(&bp->b_lru_ref, 1);
-	init_completion(&bp->b_iowait);
-	INIT_LIST_HEAD(&bp->b_lru);
-	INIT_LIST_HEAD(&bp->b_list);
-	INIT_LIST_HEAD(&bp->b_li_list);
-	bp->b_target = target;
-	bp->b_mount = target->bt_mount;
-	bp->b_flags = flags;
-
-	error = xfs_buf_get_maps(bp, nmaps);
-	if (error)  {
-		kmem_cache_free(xfs_buf_cache, bp);
-		return error;
-	}
-
-	bp->b_rhash_key = map[0].bm_bn;
-	bp->b_length = 0;
-	for (i = 0; i < nmaps; i++) {
-		bp->b_maps[i].bm_bn = map[i].bm_bn;
-		bp->b_maps[i].bm_len = map[i].bm_len;
-		bp->b_length += map[i].bm_len;
-	}
-
-	atomic_set(&bp->b_pin_count, 0);
-	init_waitqueue_head(&bp->b_waiters);
-
-	XFS_STATS_INC(bp->b_mount, xb_create);
-	trace_xfs_buf_init(bp, _RET_IP_);
-
-	*bpp = bp;
-	return 0;
-}
-
 static void
 xfs_buf_free_callback(
 	struct callback_head	*cb)
@@ -342,6 +277,77 @@ xfs_buf_alloc_backing_mem(
 	return 0;
 }
 
+static int
+xfs_buf_alloc(
+	struct xfs_buftarg	*target,
+	struct xfs_buf_map	*map,
+	int			nmaps,
+	xfs_buf_flags_t		flags,
+	struct xfs_buf		**bpp)
+{
+	struct xfs_buf		*bp;
+	int			error;
+	int			i;
+
+	*bpp = NULL;
+	bp = kmem_cache_zalloc(xfs_buf_cache,
+			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
+
+	/*
+	 * We don't want certain flags to appear in b_flags unless they are
+	 * specifically set by later operations on the buffer.
+	 */
+	flags &= ~(XBF_TRYLOCK | XBF_ASYNC | XBF_READ_AHEAD);
+
+	/*
+	 * A new buffer is held and locked by the owner.  This ensures that the
+	 * buffer is owned by the caller and racing RCU lookups right after
+	 * inserting into the hash table are safe (and will have to wait for
+	 * the unlock to do anything non-trivial).
+	 */
+	bp->b_hold = 1;
+	sema_init(&bp->b_sema, 0); /* held, no waiters */
+
+	spin_lock_init(&bp->b_lock);
+	atomic_set(&bp->b_lru_ref, 1);
+	init_completion(&bp->b_iowait);
+	INIT_LIST_HEAD(&bp->b_lru);
+	INIT_LIST_HEAD(&bp->b_list);
+	INIT_LIST_HEAD(&bp->b_li_list);
+	bp->b_target = target;
+	bp->b_mount = target->bt_mount;
+	bp->b_flags = flags;
+
+	error = xfs_buf_get_maps(bp, nmaps);
+	if (error)  {
+		kmem_cache_free(xfs_buf_cache, bp);
+		return error;
+	}
+
+	bp->b_rhash_key = map[0].bm_bn;
+	bp->b_length = 0;
+	for (i = 0; i < nmaps; i++) {
+		bp->b_maps[i].bm_bn = map[i].bm_bn;
+		bp->b_maps[i].bm_len = map[i].bm_len;
+		bp->b_length += map[i].bm_len;
+	}
+
+	atomic_set(&bp->b_pin_count, 0);
+	init_waitqueue_head(&bp->b_waiters);
+
+	XFS_STATS_INC(bp->b_mount, xb_create);
+	trace_xfs_buf_init(bp, _RET_IP_);
+
+	error = xfs_buf_alloc_backing_mem(bp, flags);
+	if (error) {
+		xfs_buf_free(bp);
+		return error;
+	}
+
+	*bpp = bp;
+	return 0;
+}
+
 /*
  *	Finding and Reading Buffers
  */
@@ -525,14 +531,10 @@ xfs_buf_find_insert(
 	struct xfs_buf		*bp;
 	int			error;
 
-	error = _xfs_buf_alloc(btp, map, nmaps, flags, &new_bp);
+	error = xfs_buf_alloc(btp, map, nmaps, flags, &new_bp);
 	if (error)
 		goto out_drop_pag;
 
-	error = xfs_buf_alloc_backing_mem(new_bp, flags);
-	if (error)
-		goto out_free_buf;
-
 	/* The new buffer keeps the perag reference until it is freed. */
 	new_bp->b_pag = pag;
 
@@ -869,28 +871,11 @@ xfs_buf_get_uncached(
 	struct xfs_buf		**bpp)
 {
 	int			error;
-	struct xfs_buf		*bp;
 	DEFINE_SINGLE_BUF_MAP(map, XFS_BUF_DADDR_NULL, numblks);
 
-	/* there are currently no valid flags for xfs_buf_get_uncached */
-	ASSERT(flags == 0);
-
-	*bpp = NULL;
-
-	error = _xfs_buf_alloc(target, &map, 1, flags, &bp);
-	if (error)
-		return error;
-
-	error = xfs_buf_alloc_backing_mem(bp, flags);
-	if (error)
-		goto fail_free_buf;
-
-	trace_xfs_buf_get_uncached(bp, _RET_IP_);
-	*bpp = bp;
-	return 0;
-
-fail_free_buf:
-	xfs_buf_free(bp);
+	error = xfs_buf_alloc(target, &map, 1, flags, bpp);
+	if (!error)
+		trace_xfs_buf_get_uncached(*bpp, _RET_IP_);
 	return error;
 }
 
--

2.45.2

#3 lore raw

PATCH 2/5 xfs: remove xfs_buf_get_maps

In reply to Christoph Hellwig

xfs_buf_get_maps has a single caller, and can just be open coded there. When doing that, stop handling the allocation failure as we always pass __GFP_NOFAIL to the slab allocator, and use the proper kcalloc helper for array allocations.

---
 fs/xfs/xfs_buf.c | 33 ++++++---------------------------
 1 file changed, 6 insertions(+), 27 deletions(-)
fs/xfs/xfs_buf.c +6 -27
index f42f6e47f783..878dc0f108d1 100644
@@ -88,26 +88,6 @@ xfs_buf_stale(
 	spin_unlock(&bp->b_lock);
 }
 
-static int
-xfs_buf_get_maps(
-	struct xfs_buf		*bp,
-	int			map_count)
-{
-	ASSERT(bp->b_maps == NULL);
-	bp->b_map_count = map_count;
-
-	if (map_count == 1) {
-		bp->b_maps = &bp->__b_map;
-		return 0;
-	}
-
-	bp->b_maps = kzalloc(map_count * sizeof(struct xfs_buf_map),
-			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
-	if (!bp->b_maps)
-		return -ENOMEM;
-	return 0;
-}
-
 static void
 xfs_buf_free_maps(
 	struct xfs_buf	*bp)
@@ -317,15 +297,14 @@ xfs_buf_alloc(
 	bp->b_target = target;
 	bp->b_mount = target->bt_mount;
 	bp->b_flags = flags;
-
-	error = xfs_buf_get_maps(bp, nmaps);
-	if (error)  {
-		kmem_cache_free(xfs_buf_cache, bp);
-		return error;
-	}
-
 	bp->b_rhash_key = map[0].bm_bn;
 	bp->b_length = 0;
+	bp->b_map_count = nmaps;
+	if (nmaps == 1)
+		bp->b_maps = &bp->__b_map;
+	else
+		bp->b_maps = kcalloc(nmaps, sizeof(struct xfs_buf_map),
+				GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
 	for (i = 0; i < nmaps; i++) {
 		bp->b_maps[i].bm_bn = map[i].bm_bn;
 		bp->b_maps[i].bm_len = map[i].bm_len;
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] xfs: remove xfs_buf_get_maps

Quoted 10 lines · Christoph Hellwig

xfs_buf_get_maps has a single caller, and can just be open coded there. When doing that, stop handling the allocation failure as we always pass __GFP_NOFAIL to the slab allocator, and use the proper kcalloc helper for array allocations.

---
 fs/xfs/xfs_buf.c | 33 ++++++---------------------------
 1 file changed, 6 insertions(+), 27 deletions(-)

Looks good.

Quoted 56 lines
fs/xfs/xfs_buf.c +6 -28
index f42f6e47f783..878dc0f108d1 100644
@@ -88,26 +88,6 @@ xfs_buf_stale(
 	spin_unlock(&bp->b_lock);
 }
 
-static int
-xfs_buf_get_maps(
-	struct xfs_buf		*bp,
-	int			map_count)
-{
-	ASSERT(bp->b_maps == NULL);
-	bp->b_map_count = map_count;
-
-	if (map_count == 1) {
-		bp->b_maps = &bp->__b_map;
-		return 0;
-	}
-
-	bp->b_maps = kzalloc(map_count * sizeof(struct xfs_buf_map),
-			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
-	if (!bp->b_maps)
-		return -ENOMEM;
-	return 0;
-}
-
 static void
 xfs_buf_free_maps(
 	struct xfs_buf	*bp)
@@ -317,15 +297,14 @@ xfs_buf_alloc(
 	bp->b_target = target;
 	bp->b_mount = target->bt_mount;
 	bp->b_flags = flags;
-
-	error = xfs_buf_get_maps(bp, nmaps);
-	if (error)  {
-		kmem_cache_free(xfs_buf_cache, bp);
-		return error;
-	}
-
 	bp->b_rhash_key = map[0].bm_bn;
 	bp->b_length = 0;
+	bp->b_map_count = nmaps;
+	if (nmaps == 1)
+		bp->b_maps = &bp->__b_map;
+	else
+		bp->b_maps = kcalloc(nmaps, sizeof(struct xfs_buf_map),
+				GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
 	for (i = 0; i < nmaps; i++) {
 		bp->b_maps[i].bm_bn = map[i].bm_bn;
 		bp->b_maps[i].bm_len = map[i].bm_len;
--

2.45.2

#5 lore raw

PATCH 3/5 xfs: remove xfs_buf_free_maps

In reply to Christoph Hellwig

xfs_buf_free_maps only has a single caller, so open code it there. Stop zeroing the b_maps pointer as the buffer is freed in the next line.

---
 fs/xfs/xfs_buf.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
fs/xfs/xfs_buf.c +2 -11
index 878dc0f108d1..bf75964bbfe8 100644
@@ -88,23 +88,14 @@ xfs_buf_stale(
 	spin_unlock(&bp->b_lock);
 }
 
-static void
-xfs_buf_free_maps(
-	struct xfs_buf	*bp)
-{
-	if (bp->b_maps != &bp->__b_map) {
-		kfree(bp->b_maps);
-		bp->b_maps = NULL;
-	}
-}
-
 static void
 xfs_buf_free_callback(
 	struct callback_head	*cb)
 {
 	struct xfs_buf		*bp = container_of(cb, struct xfs_buf, b_rcu);
 
-	xfs_buf_free_maps(bp);
+	if (bp->b_maps != &bp->__b_map)
+		kfree(bp->b_maps);
 	kmem_cache_free(xfs_buf_cache, bp);
 }
 
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 3/5
#6 lore raw

Re: [PATCH 3/5] xfs: remove xfs_buf_free_maps

Quoted 4 lines · Christoph Hellwig

xfs_buf_free_maps only has a single caller, so open code it there. Stop zeroing the b_maps pointer as the buffer is freed in the next line.

Sounds good.

Quoted 37 lines
---
 fs/xfs/xfs_buf.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
fs/xfs/xfs_buf.c +2 -12
index 878dc0f108d1..bf75964bbfe8 100644
@@ -88,23 +88,14 @@ xfs_buf_stale(
 	spin_unlock(&bp->b_lock);
 }
 
-static void
-xfs_buf_free_maps(
-	struct xfs_buf	*bp)
-{
-	if (bp->b_maps != &bp->__b_map) {
-		kfree(bp->b_maps);
-		bp->b_maps = NULL;
-	}
-}
-
 static void
 xfs_buf_free_callback(
 	struct callback_head	*cb)
 {
 	struct xfs_buf		*bp = container_of(cb, struct xfs_buf, b_rcu);
 
-	xfs_buf_free_maps(bp);
+	if (bp->b_maps != &bp->__b_map)
+		kfree(bp->b_maps);
 	kmem_cache_free(xfs_buf_cache, bp);
 }
 
--

2.45.2

#7 lore raw

PATCH 4/5 xfs: remove the flags argument to xfs_buf_read_uncached

In reply to Christoph Hellwig

No callers passes flags to xfs_buf_read_uncached, which makes sense given that the flags apply to behavior not used for uncached buffers.

---
 fs/xfs/xfs_buf.c     | 3 +--
 fs/xfs/xfs_buf.h     | 2 +-
 fs/xfs/xfs_fsops.c   | 2 +-
 fs/xfs/xfs_mount.c   | 6 +++---
 fs/xfs/xfs_rtalloc.c | 4 ++--
 5 files changed, 8 insertions(+), 9 deletions(-)
fs/xfs/xfs_buf.c +1 -2
index bf75964bbfe8..6469a69b18fe 100644
@@ -802,7 +802,6 @@ xfs_buf_read_uncached(
 	struct xfs_buftarg	*target,
 	xfs_daddr_t		daddr,
 	size_t			numblks,
-	xfs_buf_flags_t		flags,
 	struct xfs_buf		**bpp,
 	const struct xfs_buf_ops *ops)
 {
@@ -811,7 +810,7 @@ xfs_buf_read_uncached(
 
 	*bpp = NULL;
 
-	error = xfs_buf_get_uncached(target, numblks, flags, &bp);
+	error = xfs_buf_get_uncached(target, numblks, 0, &bp);
 	if (error)
 		return error;
 
fs/xfs/xfs_buf.h +1 -1
index db43bdc17f55..6a426a8d6197 100644
@@ -275,7 +275,7 @@ xfs_buf_readahead(
 int xfs_buf_get_uncached(struct xfs_buftarg *target, size_t numblks,
 		xfs_buf_flags_t flags, struct xfs_buf **bpp);
 int xfs_buf_read_uncached(struct xfs_buftarg *target, xfs_daddr_t daddr,
-		size_t numblks, xfs_buf_flags_t flags, struct xfs_buf **bpp,
+		size_t numblks, struct xfs_buf **bpp,
 		const struct xfs_buf_ops *ops);
 int _xfs_buf_read(struct xfs_buf *bp);
 void xfs_buf_hold(struct xfs_buf *bp);
fs/xfs/xfs_fsops.c +1 -1
index b6f3d7abdae5..0ada73569394 100644
@@ -111,7 +111,7 @@ xfs_growfs_data_private(
 	if (nb > mp->m_sb.sb_dblocks) {
 		error = xfs_buf_read_uncached(mp->m_ddev_targp,
 				XFS_FSB_TO_BB(mp, nb) - XFS_FSS_TO_BB(mp, 1),
-				XFS_FSS_TO_BB(mp, 1), 0, &bp, NULL);
+				XFS_FSS_TO_BB(mp, 1), &bp, NULL);
 		if (error)
 			return error;
 		xfs_buf_relse(bp);
fs/xfs/xfs_mount.c +3 -3
index e65a659901d5..00b53f479ece 100644
@@ -186,7 +186,7 @@ xfs_readsb(
 	 */
 reread:
 	error = xfs_buf_read_uncached(mp->m_ddev_targp, XFS_SB_DADDR,
-				      BTOBB(sector_size), 0, &bp, buf_ops);
+				      BTOBB(sector_size), &bp, buf_ops);
 	if (error) {
 		if (loud)
 			xfs_warn(mp, "SB validate failed with error %d.", error);
@@ -414,7 +414,7 @@ xfs_check_sizes(
 	}
 	error = xfs_buf_read_uncached(mp->m_ddev_targp,
 					d - XFS_FSS_TO_BB(mp, 1),
-					XFS_FSS_TO_BB(mp, 1), 0, &bp, NULL);
+					XFS_FSS_TO_BB(mp, 1), &bp, NULL);
 	if (error) {
 		xfs_warn(mp, "last sector read failed");
 		return error;
@@ -431,7 +431,7 @@ xfs_check_sizes(
 	}
 	error = xfs_buf_read_uncached(mp->m_logdev_targp,
 					d - XFS_FSB_TO_BB(mp, 1),
-					XFS_FSB_TO_BB(mp, 1), 0, &bp, NULL);
+					XFS_FSB_TO_BB(mp, 1), &bp, NULL);
 	if (error) {
 		xfs_warn(mp, "log device read failed");
 		return error;
fs/xfs/xfs_rtalloc.c +2 -2
index 3aa222ea9500..e35c728f222e 100644
@@ -1350,7 +1350,7 @@ xfs_rt_check_size(
 
 	error = xfs_buf_read_uncached(mp->m_rtdev_targp,
 			XFS_FSB_TO_BB(mp, mp->m_sb.sb_rtstart) + daddr,
-			XFS_FSB_TO_BB(mp, 1), 0, &bp, NULL);
+			XFS_FSB_TO_BB(mp, 1), &bp, NULL);
 	if (error)
 		xfs_warn(mp, "cannot read last RT device sector (%lld)",
 				last_block);
@@ -1511,7 +1511,7 @@ xfs_rtmount_readsb(
 
 	/* m_blkbb_log is not set up yet */
 	error = xfs_buf_read_uncached(mp->m_rtdev_targp, XFS_RTSB_DADDR,
-			mp->m_sb.sb_blocksize >> BBSHIFT, 0, &bp,
+			mp->m_sb.sb_blocksize >> BBSHIFT, &bp,
 			&xfs_rtsb_buf_ops);
 	if (error) {
 		xfs_warn(mp, "rt sb validate failed with error %d.", error);
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 4/5
#8 lore raw

Re: [PATCH 4/5] xfs: remove the flags argument to xfs_buf_read_uncached

Quoted 4 lines · Christoph Hellwig

No callers passes flags to xfs_buf_read_uncached, which makes sense given that the flags apply to behavior not used for uncached buffers.

Quoted 111 lines
---
 fs/xfs/xfs_buf.c     | 3 +--
 fs/xfs/xfs_buf.h     | 2 +-
 fs/xfs/xfs_fsops.c   | 2 +-
 fs/xfs/xfs_mount.c   | 6 +++---
 fs/xfs/xfs_rtalloc.c | 4 ++--
 5 files changed, 8 insertions(+), 9 deletions(-)
fs/xfs/xfs_buf.c +1 -2
index bf75964bbfe8..6469a69b18fe 100644
@@ -802,7 +802,6 @@ xfs_buf_read_uncached(
 	struct xfs_buftarg	*target,
 	xfs_daddr_t		daddr,
 	size_t			numblks,
-	xfs_buf_flags_t		flags,
 	struct xfs_buf		**bpp,
 	const struct xfs_buf_ops *ops)
 {
@@ -811,7 +810,7 @@ xfs_buf_read_uncached(
 
 	*bpp = NULL;
 
-	error = xfs_buf_get_uncached(target, numblks, flags, &bp);
+	error = xfs_buf_get_uncached(target, numblks, 0, &bp);
 	if (error)
 		return error;
 
fs/xfs/xfs_buf.h +1 -1
index db43bdc17f55..6a426a8d6197 100644
@@ -275,7 +275,7 @@ xfs_buf_readahead(
 int xfs_buf_get_uncached(struct xfs_buftarg *target, size_t numblks,
 		xfs_buf_flags_t flags, struct xfs_buf **bpp);
 int xfs_buf_read_uncached(struct xfs_buftarg *target, xfs_daddr_t daddr,
-		size_t numblks, xfs_buf_flags_t flags, struct xfs_buf **bpp,
+		size_t numblks, struct xfs_buf **bpp,
 		const struct xfs_buf_ops *ops);
 int _xfs_buf_read(struct xfs_buf *bp);
 void xfs_buf_hold(struct xfs_buf *bp);
fs/xfs/xfs_fsops.c +1 -1
index b6f3d7abdae5..0ada73569394 100644
@@ -111,7 +111,7 @@ xfs_growfs_data_private(
 	if (nb > mp->m_sb.sb_dblocks) {
 		error = xfs_buf_read_uncached(mp->m_ddev_targp,
 				XFS_FSB_TO_BB(mp, nb) - XFS_FSS_TO_BB(mp, 1),
-				XFS_FSS_TO_BB(mp, 1), 0, &bp, NULL);
+				XFS_FSS_TO_BB(mp, 1), &bp, NULL);
 		if (error)
 			return error;
 		xfs_buf_relse(bp);
fs/xfs/xfs_mount.c +3 -3
index e65a659901d5..00b53f479ece 100644
@@ -186,7 +186,7 @@ xfs_readsb(
 	 */
 reread:
 	error = xfs_buf_read_uncached(mp->m_ddev_targp, XFS_SB_DADDR,
-				      BTOBB(sector_size), 0, &bp, buf_ops);
+				      BTOBB(sector_size), &bp, buf_ops);
 	if (error) {
 		if (loud)
 			xfs_warn(mp, "SB validate failed with error %d.", error);
@@ -414,7 +414,7 @@ xfs_check_sizes(
 	}
 	error = xfs_buf_read_uncached(mp->m_ddev_targp,
 					d - XFS_FSS_TO_BB(mp, 1),
-					XFS_FSS_TO_BB(mp, 1), 0, &bp, NULL);
+					XFS_FSS_TO_BB(mp, 1), &bp, NULL);
 	if (error) {
 		xfs_warn(mp, "last sector read failed");
 		return error;
@@ -431,7 +431,7 @@ xfs_check_sizes(
 	}
 	error = xfs_buf_read_uncached(mp->m_logdev_targp,
 					d - XFS_FSB_TO_BB(mp, 1),
-					XFS_FSB_TO_BB(mp, 1), 0, &bp, NULL);
+					XFS_FSB_TO_BB(mp, 1), &bp, NULL);
 	if (error) {
 		xfs_warn(mp, "log device read failed");
 		return error;
fs/xfs/xfs_rtalloc.c +2 -3
index 3aa222ea9500..e35c728f222e 100644
@@ -1350,7 +1350,7 @@ xfs_rt_check_size(
 
 	error = xfs_buf_read_uncached(mp->m_rtdev_targp,
 			XFS_FSB_TO_BB(mp, mp->m_sb.sb_rtstart) + daddr,
-			XFS_FSB_TO_BB(mp, 1), 0, &bp, NULL);
+			XFS_FSB_TO_BB(mp, 1), &bp, NULL);
 	if (error)
 		xfs_warn(mp, "cannot read last RT device sector (%lld)",
 				last_block);
@@ -1511,7 +1511,7 @@ xfs_rtmount_readsb(
 
 	/* m_blkbb_log is not set up yet */
 	error = xfs_buf_read_uncached(mp->m_rtdev_targp, XFS_RTSB_DADDR,
-			mp->m_sb.sb_blocksize >> BBSHIFT, 0, &bp,
+			mp->m_sb.sb_blocksize >> BBSHIFT, &bp,
 			&xfs_rtsb_buf_ops);
 	if (error) {
 		xfs_warn(mp, "rt sb validate failed with error %d.", error);
--

2.45.2

#9 lore raw

PATCH 5/5 xfs: remove the flags argument to xfs_buf_get_uncached

In reply to Christoph Hellwig

No callers passes flags to xfs_buf_get_uncached, which makes sense given that the flags apply to behavior not used for uncached buffers.

---
 fs/xfs/libxfs/xfs_ag.c | 2 +-
 fs/xfs/xfs_buf.c       | 5 ++---
 fs/xfs/xfs_buf.h       | 2 +-
 fs/xfs/xfs_rtalloc.c   | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_ag.c +1 -1
index b59cb461e096..e6ba914f6d06 100644
@@ -301,7 +301,7 @@ xfs_get_aghdr_buf(
 	struct xfs_buf		*bp;
 	int			error;
 
-	error = xfs_buf_get_uncached(mp->m_ddev_targp, numblks, 0, &bp);
+	error = xfs_buf_get_uncached(mp->m_ddev_targp, numblks, &bp);
 	if (error)
 		return error;
 
fs/xfs/xfs_buf.c +2 -3
index 6469a69b18fe..8e7f1b324b3b 100644
@@ -810,7 +810,7 @@ xfs_buf_read_uncached(
 
 	*bpp = NULL;
 
-	error = xfs_buf_get_uncached(target, numblks, 0, &bp);
+	error = xfs_buf_get_uncached(target, numblks, &bp);
 	if (error)
 		return error;
 
@@ -836,13 +836,12 @@ int
 xfs_buf_get_uncached(
 	struct xfs_buftarg	*target,
 	size_t			numblks,
-	xfs_buf_flags_t		flags,
 	struct xfs_buf		**bpp)
 {
 	int			error;
 	DEFINE_SINGLE_BUF_MAP(map, XFS_BUF_DADDR_NULL, numblks);
 
-	error = xfs_buf_alloc(target, &map, 1, flags, bpp);
+	error = xfs_buf_alloc(target, &map, 1, 0, bpp);
 	if (!error)
 		trace_xfs_buf_get_uncached(*bpp, _RET_IP_);
 	return error;
fs/xfs/xfs_buf.h +1 -1
index 6a426a8d6197..d0b065a9a9f0 100644
@@ -273,7 +273,7 @@ xfs_buf_readahead(
 }
 
 int xfs_buf_get_uncached(struct xfs_buftarg *target, size_t numblks,
-		xfs_buf_flags_t flags, struct xfs_buf **bpp);
+		struct xfs_buf **bpp);
 int xfs_buf_read_uncached(struct xfs_buftarg *target, xfs_daddr_t daddr,
 		size_t numblks, struct xfs_buf **bpp,
 		const struct xfs_buf_ops *ops);
fs/xfs/xfs_rtalloc.c +1 -1
index e35c728f222e..6484c596ecea 100644
@@ -839,7 +839,7 @@ xfs_growfs_rt_init_rtsb(
 		return 0;
 
 	error = xfs_buf_get_uncached(mp->m_rtdev_targp, XFS_FSB_TO_BB(mp, 1),
-			0, &rtsb_bp);
+			&rtsb_bp);
 	if (error)
 		return error;
 
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 5/5
#10 lore raw

Re: [PATCH 5/5] xfs: remove the flags argument to xfs_buf_get_uncached

Quoted 4 lines · Christoph Hellwig

No callers passes flags to xfs_buf_get_uncached, which makes sense given that the flags apply to behavior not used for uncached buffers.

Quoted 78 lines
---
 fs/xfs/libxfs/xfs_ag.c | 2 +-
 fs/xfs/xfs_buf.c       | 5 ++---
 fs/xfs/xfs_buf.h       | 2 +-
 fs/xfs/xfs_rtalloc.c   | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_ag.c +1 -1
index b59cb461e096..e6ba914f6d06 100644
@@ -301,7 +301,7 @@ xfs_get_aghdr_buf(
 	struct xfs_buf		*bp;
 	int			error;
 
-	error = xfs_buf_get_uncached(mp->m_ddev_targp, numblks, 0, &bp);
+	error = xfs_buf_get_uncached(mp->m_ddev_targp, numblks, &bp);
 	if (error)
 		return error;
 
fs/xfs/xfs_buf.c +2 -3
index 6469a69b18fe..8e7f1b324b3b 100644
@@ -810,7 +810,7 @@ xfs_buf_read_uncached(
 
 	*bpp = NULL;
 
-	error = xfs_buf_get_uncached(target, numblks, 0, &bp);
+	error = xfs_buf_get_uncached(target, numblks, &bp);
 	if (error)
 		return error;
 
@@ -836,13 +836,12 @@ int
 xfs_buf_get_uncached(
 	struct xfs_buftarg	*target,
 	size_t			numblks,
-	xfs_buf_flags_t		flags,
 	struct xfs_buf		**bpp)
 {
 	int			error;
 	DEFINE_SINGLE_BUF_MAP(map, XFS_BUF_DADDR_NULL, numblks);
 
-	error = xfs_buf_alloc(target, &map, 1, flags, bpp);
+	error = xfs_buf_alloc(target, &map, 1, 0, bpp);
 	if (!error)
 		trace_xfs_buf_get_uncached(*bpp, _RET_IP_);
 	return error;
fs/xfs/xfs_buf.h +1 -1
index 6a426a8d6197..d0b065a9a9f0 100644
@@ -273,7 +273,7 @@ xfs_buf_readahead(
 }
 
 int xfs_buf_get_uncached(struct xfs_buftarg *target, size_t numblks,
-		xfs_buf_flags_t flags, struct xfs_buf **bpp);
+		struct xfs_buf **bpp);
 int xfs_buf_read_uncached(struct xfs_buftarg *target, xfs_daddr_t daddr,
 		size_t numblks, struct xfs_buf **bpp,
 		const struct xfs_buf_ops *ops);
fs/xfs/xfs_rtalloc.c +1 -2
index e35c728f222e..6484c596ecea 100644
@@ -839,7 +839,7 @@ xfs_growfs_rt_init_rtsb(
 		return 0;
 
 	error = xfs_buf_get_uncached(mp->m_rtdev_targp, XFS_FSB_TO_BB(mp, 1),
-			0, &rtsb_bp);
+			&rtsb_bp);
 	if (error)
 		return error;
 
--

2.45.2