Skip to content

Commit efc5f7a

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: decouple buffer readahead from the normal buffer read path
xfs_buf_readahead_map is the only caller of xfs_buf_read_map and thus _xfs_buf_read that is not synchronous. Split it from xfs_buf_read_map so that the asynchronous path is self-contained and the now purely synchronous xfs_buf_read_map / _xfs_buf_read implementation can be simplified. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 4b90de5 commit efc5f7a

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

fs/xfs/xfs_buf.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -794,18 +794,13 @@ xfs_buf_get_map(
794794

795795
int
796796
_xfs_buf_read(
797-
struct xfs_buf *bp,
798-
xfs_buf_flags_t flags)
797+
struct xfs_buf *bp)
799798
{
800-
ASSERT(!(flags & XBF_WRITE));
801799
ASSERT(bp->b_maps[0].bm_bn != XFS_BUF_DADDR_NULL);
802800

803801
bp->b_flags &= ~(XBF_WRITE | XBF_ASYNC | XBF_READ_AHEAD | XBF_DONE);
804-
bp->b_flags |= flags & (XBF_READ | XBF_ASYNC | XBF_READ_AHEAD);
805-
802+
bp->b_flags |= XBF_READ;
806803
xfs_buf_submit(bp);
807-
if (flags & XBF_ASYNC)
808-
return 0;
809804
return xfs_buf_iowait(bp);
810805
}
811806

@@ -857,6 +852,8 @@ xfs_buf_read_map(
857852
struct xfs_buf *bp;
858853
int error;
859854

855+
ASSERT(!(flags & (XBF_WRITE | XBF_ASYNC | XBF_READ_AHEAD)));
856+
860857
flags |= XBF_READ;
861858
*bpp = NULL;
862859

@@ -870,21 +867,11 @@ xfs_buf_read_map(
870867
/* Initiate the buffer read and wait. */
871868
XFS_STATS_INC(target->bt_mount, xb_get_read);
872869
bp->b_ops = ops;
873-
error = _xfs_buf_read(bp, flags);
874-
875-
/* Readahead iodone already dropped the buffer, so exit. */
876-
if (flags & XBF_ASYNC)
877-
return 0;
870+
error = _xfs_buf_read(bp);
878871
} else {
879872
/* Buffer already read; all we need to do is check it. */
880873
error = xfs_buf_reverify(bp, ops);
881874

882-
/* Readahead already finished; drop the buffer and exit. */
883-
if (flags & XBF_ASYNC) {
884-
xfs_buf_relse(bp);
885-
return 0;
886-
}
887-
888875
/* We do not want read in the flags */
889876
bp->b_flags &= ~XBF_READ;
890877
ASSERT(bp->b_ops != NULL || ops == NULL);
@@ -936,6 +923,7 @@ xfs_buf_readahead_map(
936923
int nmaps,
937924
const struct xfs_buf_ops *ops)
938925
{
926+
const xfs_buf_flags_t flags = XBF_READ | XBF_ASYNC | XBF_READ_AHEAD;
939927
struct xfs_buf *bp;
940928

941929
/*
@@ -945,9 +933,20 @@ xfs_buf_readahead_map(
945933
if (xfs_buftarg_is_mem(target))
946934
return;
947935

948-
xfs_buf_read_map(target, map, nmaps,
949-
XBF_TRYLOCK | XBF_ASYNC | XBF_READ_AHEAD, &bp, ops,
950-
__this_address);
936+
if (xfs_buf_get_map(target, map, nmaps, flags | XBF_TRYLOCK, &bp))
937+
return;
938+
trace_xfs_buf_readahead(bp, 0, _RET_IP_);
939+
940+
if (bp->b_flags & XBF_DONE) {
941+
xfs_buf_reverify(bp, ops);
942+
xfs_buf_relse(bp);
943+
return;
944+
}
945+
XFS_STATS_INC(target->bt_mount, xb_get_read);
946+
bp->b_ops = ops;
947+
bp->b_flags &= ~(XBF_WRITE | XBF_DONE);
948+
bp->b_flags |= flags;
949+
xfs_buf_submit(bp);
951950
}
952951

953952
/*

fs/xfs/xfs_buf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ int xfs_buf_get_uncached(struct xfs_buftarg *target, size_t numblks,
291291
int xfs_buf_read_uncached(struct xfs_buftarg *target, xfs_daddr_t daddr,
292292
size_t numblks, xfs_buf_flags_t flags, struct xfs_buf **bpp,
293293
const struct xfs_buf_ops *ops);
294-
int _xfs_buf_read(struct xfs_buf *bp, xfs_buf_flags_t flags);
294+
int _xfs_buf_read(struct xfs_buf *bp);
295295
void xfs_buf_hold(struct xfs_buf *bp);
296296

297297
/* Releasing Buffers */

fs/xfs/xfs_log_recover.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3380,7 +3380,7 @@ xlog_do_recover(
33803380
*/
33813381
xfs_buf_lock(bp);
33823382
xfs_buf_hold(bp);
3383-
error = _xfs_buf_read(bp, XBF_READ);
3383+
error = _xfs_buf_read(bp);
33843384
if (error) {
33853385
if (!xlog_is_shutdown(log)) {
33863386
xfs_buf_ioerror_alert(bp, __this_address);

fs/xfs/xfs_trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ DEFINE_EVENT(xfs_buf_flags_class, name, \
593593
DEFINE_BUF_FLAGS_EVENT(xfs_buf_find);
594594
DEFINE_BUF_FLAGS_EVENT(xfs_buf_get);
595595
DEFINE_BUF_FLAGS_EVENT(xfs_buf_read);
596+
DEFINE_BUF_FLAGS_EVENT(xfs_buf_readahead);
596597

597598
TRACE_EVENT(xfs_buf_ioerror,
598599
TP_PROTO(struct xfs_buf *bp, int error, xfs_failaddr_t caller_ip),

0 commit comments

Comments
 (0)