Skip to content

Commit 85c73bf

Browse files
dgchinnerdchinner
authored andcommitted
xfs: rework xfs_buf_incore() API
Make it consistent with the other buffer APIs to return a error and the buffer is placed in a parameter. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
1 parent 7561cea commit 85c73bf

5 files changed

Lines changed: 41 additions & 37 deletions

File tree

fs/xfs/libxfs/xfs_attr_remote.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,21 +543,26 @@ xfs_attr_rmtval_stale(
543543
{
544544
struct xfs_mount *mp = ip->i_mount;
545545
struct xfs_buf *bp;
546+
int error;
546547

547548
ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
548549

549550
if (XFS_IS_CORRUPT(mp, map->br_startblock == DELAYSTARTBLOCK) ||
550551
XFS_IS_CORRUPT(mp, map->br_startblock == HOLESTARTBLOCK))
551552
return -EFSCORRUPTED;
552553

553-
bp = xfs_buf_incore(mp->m_ddev_targp,
554+
error = xfs_buf_incore(mp->m_ddev_targp,
554555
XFS_FSB_TO_DADDR(mp, map->br_startblock),
555-
XFS_FSB_TO_BB(mp, map->br_blockcount), incore_flags);
556-
if (bp) {
557-
xfs_buf_stale(bp);
558-
xfs_buf_relse(bp);
556+
XFS_FSB_TO_BB(mp, map->br_blockcount),
557+
incore_flags, &bp);
558+
if (error) {
559+
if (error == -ENOENT)
560+
return 0;
561+
return error;
559562
}
560563

564+
xfs_buf_stale(bp);
565+
xfs_buf_relse(bp);
561566
return 0;
562567
}
563568

fs/xfs/scrub/repair.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,16 +457,19 @@ xrep_invalidate_blocks(
457457
* assume it's owned by someone else.
458458
*/
459459
for_each_xbitmap_block(fsbno, bmr, n, bitmap) {
460+
int error;
461+
460462
/* Skip AG headers and post-EOFS blocks */
461463
if (!xfs_verify_fsbno(sc->mp, fsbno))
462464
continue;
463-
bp = xfs_buf_incore(sc->mp->m_ddev_targp,
465+
error = xfs_buf_incore(sc->mp->m_ddev_targp,
464466
XFS_FSB_TO_DADDR(sc->mp, fsbno),
465-
XFS_FSB_TO_BB(sc->mp, 1), XBF_TRYLOCK);
466-
if (bp) {
467-
xfs_trans_bjoin(sc->tp, bp);
468-
xfs_trans_binval(sc->tp, bp);
469-
}
467+
XFS_FSB_TO_BB(sc->mp, 1), XBF_TRYLOCK, &bp);
468+
if (error)
469+
continue;
470+
471+
xfs_trans_bjoin(sc->tp, bp);
472+
xfs_trans_binval(sc->tp, bp);
470473
}
471474

472475
return 0;

fs/xfs/xfs_buf.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -616,23 +616,6 @@ xfs_buf_find(
616616
return 0;
617617
}
618618

619-
struct xfs_buf *
620-
xfs_buf_incore(
621-
struct xfs_buftarg *target,
622-
xfs_daddr_t blkno,
623-
size_t numblks,
624-
xfs_buf_flags_t flags)
625-
{
626-
struct xfs_buf *bp;
627-
int error;
628-
DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
629-
630-
error = xfs_buf_find(target, &map, 1, flags, NULL, &bp);
631-
if (error)
632-
return NULL;
633-
return bp;
634-
}
635-
636619
/*
637620
* Assembles a buffer covering the specified range. The code is optimised for
638621
* cache hits, as metadata intensive workloads will see 3 orders of magnitude
@@ -656,6 +639,8 @@ xfs_buf_get_map(
656639
goto found;
657640
if (error != -ENOENT)
658641
return error;
642+
if (flags & XBF_INCORE)
643+
return -ENOENT;
659644

660645
error = _xfs_buf_alloc(target, map, nmaps, flags, &new_bp);
661646
if (error)

fs/xfs/xfs_buf.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ struct xfs_buf;
4242
#define _XBF_DELWRI_Q (1u << 22)/* buffer on a delwri queue */
4343

4444
/* flags used only as arguments to access routines */
45+
#define XBF_INCORE (1u << 29)/* lookup only, return if found in cache */
4546
#define XBF_TRYLOCK (1u << 30)/* lock requested, but do not wait */
4647
#define XBF_UNMAPPED (1u << 31)/* do not map the buffer */
4748

49+
4850
typedef unsigned int xfs_buf_flags_t;
4951

5052
#define XFS_BUF_FLAGS \
@@ -63,6 +65,7 @@ typedef unsigned int xfs_buf_flags_t;
6365
{ _XBF_KMEM, "KMEM" }, \
6466
{ _XBF_DELWRI_Q, "DELWRI_Q" }, \
6567
/* The following interface flags should never be set */ \
68+
{ XBF_INCORE, "INCORE" }, \
6669
{ XBF_TRYLOCK, "TRYLOCK" }, \
6770
{ XBF_UNMAPPED, "UNMAPPED" }
6871

@@ -196,10 +199,6 @@ struct xfs_buf {
196199
};
197200

198201
/* Finding and Reading Buffers */
199-
struct xfs_buf *xfs_buf_incore(struct xfs_buftarg *target,
200-
xfs_daddr_t blkno, size_t numblks,
201-
xfs_buf_flags_t flags);
202-
203202
int xfs_buf_get_map(struct xfs_buftarg *target, struct xfs_buf_map *map,
204203
int nmaps, xfs_buf_flags_t flags, struct xfs_buf **bpp);
205204
int xfs_buf_read_map(struct xfs_buftarg *target, struct xfs_buf_map *map,
@@ -209,6 +208,19 @@ void xfs_buf_readahead_map(struct xfs_buftarg *target,
209208
struct xfs_buf_map *map, int nmaps,
210209
const struct xfs_buf_ops *ops);
211210

211+
static inline int
212+
xfs_buf_incore(
213+
struct xfs_buftarg *target,
214+
xfs_daddr_t blkno,
215+
size_t numblks,
216+
xfs_buf_flags_t flags,
217+
struct xfs_buf **bpp)
218+
{
219+
DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
220+
221+
return xfs_buf_get_map(target, &map, 1, XBF_INCORE | flags, bpp);
222+
}
223+
212224
static inline int
213225
xfs_buf_get(
214226
struct xfs_buftarg *target,

fs/xfs/xfs_qm.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,12 +1229,11 @@ xfs_qm_flush_one(
12291229
*/
12301230
if (!xfs_dqflock_nowait(dqp)) {
12311231
/* buf is pinned in-core by delwri list */
1232-
bp = xfs_buf_incore(mp->m_ddev_targp, dqp->q_blkno,
1233-
mp->m_quotainfo->qi_dqchunklen, 0);
1234-
if (!bp) {
1235-
error = -EINVAL;
1232+
error = xfs_buf_incore(mp->m_ddev_targp, dqp->q_blkno,
1233+
mp->m_quotainfo->qi_dqchunklen, 0, &bp);
1234+
if (error)
12361235
goto out_unlock;
1237-
}
1236+
12381237
xfs_buf_unlock(bp);
12391238

12401239
xfs_buf_delwri_pushbuf(bp, buffer_list);

0 commit comments

Comments
 (0)