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>
This commit is contained in:
Dave Chinner 2022-07-07 22:05:18 +10:00 committed by Dave Chinner
parent 7561cea5db
commit 85c73bf726
5 changed files with 41 additions and 37 deletions

View File

@ -543,6 +543,7 @@ xfs_attr_rmtval_stale(
{ {
struct xfs_mount *mp = ip->i_mount; struct xfs_mount *mp = ip->i_mount;
struct xfs_buf *bp; struct xfs_buf *bp;
int error;
ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
@ -550,14 +551,18 @@ xfs_attr_rmtval_stale(
XFS_IS_CORRUPT(mp, map->br_startblock == HOLESTARTBLOCK)) XFS_IS_CORRUPT(mp, map->br_startblock == HOLESTARTBLOCK))
return -EFSCORRUPTED; return -EFSCORRUPTED;
bp = xfs_buf_incore(mp->m_ddev_targp, error = xfs_buf_incore(mp->m_ddev_targp,
XFS_FSB_TO_DADDR(mp, map->br_startblock), XFS_FSB_TO_DADDR(mp, map->br_startblock),
XFS_FSB_TO_BB(mp, map->br_blockcount), incore_flags); XFS_FSB_TO_BB(mp, map->br_blockcount),
if (bp) { incore_flags, &bp);
xfs_buf_stale(bp); if (error) {
xfs_buf_relse(bp); if (error == -ENOENT)
return 0;
return error;
} }
xfs_buf_stale(bp);
xfs_buf_relse(bp);
return 0; return 0;
} }

View File

@ -457,17 +457,20 @@ xrep_invalidate_blocks(
* assume it's owned by someone else. * assume it's owned by someone else.
*/ */
for_each_xbitmap_block(fsbno, bmr, n, bitmap) { for_each_xbitmap_block(fsbno, bmr, n, bitmap) {
int error;
/* Skip AG headers and post-EOFS blocks */ /* Skip AG headers and post-EOFS blocks */
if (!xfs_verify_fsbno(sc->mp, fsbno)) if (!xfs_verify_fsbno(sc->mp, fsbno))
continue; continue;
bp = xfs_buf_incore(sc->mp->m_ddev_targp, error = xfs_buf_incore(sc->mp->m_ddev_targp,
XFS_FSB_TO_DADDR(sc->mp, fsbno), XFS_FSB_TO_DADDR(sc->mp, fsbno),
XFS_FSB_TO_BB(sc->mp, 1), XBF_TRYLOCK); XFS_FSB_TO_BB(sc->mp, 1), XBF_TRYLOCK, &bp);
if (bp) { if (error)
continue;
xfs_trans_bjoin(sc->tp, bp); xfs_trans_bjoin(sc->tp, bp);
xfs_trans_binval(sc->tp, bp); xfs_trans_binval(sc->tp, bp);
} }
}
return 0; return 0;
} }

View File

@ -616,23 +616,6 @@ found:
return 0; return 0;
} }
struct xfs_buf *
xfs_buf_incore(
struct xfs_buftarg *target,
xfs_daddr_t blkno,
size_t numblks,
xfs_buf_flags_t flags)
{
struct xfs_buf *bp;
int error;
DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
error = xfs_buf_find(target, &map, 1, flags, NULL, &bp);
if (error)
return NULL;
return bp;
}
/* /*
* Assembles a buffer covering the specified range. The code is optimised for * Assembles a buffer covering the specified range. The code is optimised for
* cache hits, as metadata intensive workloads will see 3 orders of magnitude * cache hits, as metadata intensive workloads will see 3 orders of magnitude
@ -656,6 +639,8 @@ xfs_buf_get_map(
goto found; goto found;
if (error != -ENOENT) if (error != -ENOENT)
return error; return error;
if (flags & XBF_INCORE)
return -ENOENT;
error = _xfs_buf_alloc(target, map, nmaps, flags, &new_bp); error = _xfs_buf_alloc(target, map, nmaps, flags, &new_bp);
if (error) if (error)

View File

@ -42,9 +42,11 @@ struct xfs_buf;
#define _XBF_DELWRI_Q (1u << 22)/* buffer on a delwri queue */ #define _XBF_DELWRI_Q (1u << 22)/* buffer on a delwri queue */
/* flags used only as arguments to access routines */ /* flags used only as arguments to access routines */
#define XBF_INCORE (1u << 29)/* lookup only, return if found in cache */
#define XBF_TRYLOCK (1u << 30)/* lock requested, but do not wait */ #define XBF_TRYLOCK (1u << 30)/* lock requested, but do not wait */
#define XBF_UNMAPPED (1u << 31)/* do not map the buffer */ #define XBF_UNMAPPED (1u << 31)/* do not map the buffer */
typedef unsigned int xfs_buf_flags_t; typedef unsigned int xfs_buf_flags_t;
#define XFS_BUF_FLAGS \ #define XFS_BUF_FLAGS \
@ -63,6 +65,7 @@ typedef unsigned int xfs_buf_flags_t;
{ _XBF_KMEM, "KMEM" }, \ { _XBF_KMEM, "KMEM" }, \
{ _XBF_DELWRI_Q, "DELWRI_Q" }, \ { _XBF_DELWRI_Q, "DELWRI_Q" }, \
/* The following interface flags should never be set */ \ /* The following interface flags should never be set */ \
{ XBF_INCORE, "INCORE" }, \
{ XBF_TRYLOCK, "TRYLOCK" }, \ { XBF_TRYLOCK, "TRYLOCK" }, \
{ XBF_UNMAPPED, "UNMAPPED" } { XBF_UNMAPPED, "UNMAPPED" }
@ -196,10 +199,6 @@ struct xfs_buf {
}; };
/* Finding and Reading Buffers */ /* Finding and Reading Buffers */
struct xfs_buf *xfs_buf_incore(struct xfs_buftarg *target,
xfs_daddr_t blkno, size_t numblks,
xfs_buf_flags_t flags);
int xfs_buf_get_map(struct xfs_buftarg *target, struct xfs_buf_map *map, int xfs_buf_get_map(struct xfs_buftarg *target, struct xfs_buf_map *map,
int nmaps, xfs_buf_flags_t flags, struct xfs_buf **bpp); int nmaps, xfs_buf_flags_t flags, struct xfs_buf **bpp);
int xfs_buf_read_map(struct xfs_buftarg *target, struct xfs_buf_map *map, 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,
struct xfs_buf_map *map, int nmaps, struct xfs_buf_map *map, int nmaps,
const struct xfs_buf_ops *ops); const struct xfs_buf_ops *ops);
static inline int
xfs_buf_incore(
struct xfs_buftarg *target,
xfs_daddr_t blkno,
size_t numblks,
xfs_buf_flags_t flags,
struct xfs_buf **bpp)
{
DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
return xfs_buf_get_map(target, &map, 1, XBF_INCORE | flags, bpp);
}
static inline int static inline int
xfs_buf_get( xfs_buf_get(
struct xfs_buftarg *target, struct xfs_buftarg *target,

View File

@ -1229,12 +1229,11 @@ xfs_qm_flush_one(
*/ */
if (!xfs_dqflock_nowait(dqp)) { if (!xfs_dqflock_nowait(dqp)) {
/* buf is pinned in-core by delwri list */ /* buf is pinned in-core by delwri list */
bp = xfs_buf_incore(mp->m_ddev_targp, dqp->q_blkno, error = xfs_buf_incore(mp->m_ddev_targp, dqp->q_blkno,
mp->m_quotainfo->qi_dqchunklen, 0); mp->m_quotainfo->qi_dqchunklen, 0, &bp);
if (!bp) { if (error)
error = -EINVAL;
goto out_unlock; goto out_unlock;
}
xfs_buf_unlock(bp); xfs_buf_unlock(bp);
xfs_buf_delwri_pushbuf(bp, buffer_list); xfs_buf_delwri_pushbuf(bp, buffer_list);