xfs: simplify mappedbno handling in xfs_da_{get,read}_buf
Shortcut the creation of xfs_bmbt_irec and xfs_buf_map for the case where the callers passed an already mapped xfs_daddr_t. This is in preparation for splitting these cases out entirely later. Also reject the mappedbno case for xfs_da_reada_buf as no callers currently uses it and it will be removed soon. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
This commit is contained in:
parent
6519f708cc
commit
fa0d44ec7f
|
@ -110,6 +110,13 @@ xfs_da_state_free(xfs_da_state_t *state)
|
||||||
kmem_cache_free(xfs_da_state_zone, state);
|
kmem_cache_free(xfs_da_state_zone, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int xfs_dabuf_nfsb(struct xfs_mount *mp, int whichfork)
|
||||||
|
{
|
||||||
|
if (whichfork == XFS_DATA_FORK)
|
||||||
|
return mp->m_dir_geo->fsbcount;
|
||||||
|
return mp->m_attr_geo->fsbcount;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xfs_da3_node_hdr_from_disk(
|
xfs_da3_node_hdr_from_disk(
|
||||||
struct xfs_mount *mp,
|
struct xfs_mount *mp,
|
||||||
|
@ -2539,7 +2546,7 @@ xfs_dabuf_map(
|
||||||
int *nmaps)
|
int *nmaps)
|
||||||
{
|
{
|
||||||
struct xfs_mount *mp = dp->i_mount;
|
struct xfs_mount *mp = dp->i_mount;
|
||||||
int nfsb;
|
int nfsb = xfs_dabuf_nfsb(mp, whichfork);
|
||||||
int error = 0;
|
int error = 0;
|
||||||
struct xfs_bmbt_irec irec;
|
struct xfs_bmbt_irec irec;
|
||||||
struct xfs_bmbt_irec *irecs = &irec;
|
struct xfs_bmbt_irec *irecs = &irec;
|
||||||
|
@ -2548,35 +2555,13 @@ xfs_dabuf_map(
|
||||||
ASSERT(map && *map);
|
ASSERT(map && *map);
|
||||||
ASSERT(*nmaps == 1);
|
ASSERT(*nmaps == 1);
|
||||||
|
|
||||||
if (whichfork == XFS_DATA_FORK)
|
if (nfsb != 1)
|
||||||
nfsb = mp->m_dir_geo->fsbcount;
|
irecs = kmem_zalloc(sizeof(irec) * nfsb, KM_NOFS);
|
||||||
else
|
nirecs = nfsb;
|
||||||
nfsb = mp->m_attr_geo->fsbcount;
|
error = xfs_bmapi_read(dp, (xfs_fileoff_t)bno, nfsb, irecs,
|
||||||
|
&nirecs, xfs_bmapi_aflag(whichfork));
|
||||||
/*
|
if (error)
|
||||||
* Caller doesn't have a mapping. -2 means don't complain
|
goto out;
|
||||||
* if we land in a hole.
|
|
||||||
*/
|
|
||||||
if (mappedbno == -1 || mappedbno == -2) {
|
|
||||||
/*
|
|
||||||
* Optimize the one-block case.
|
|
||||||
*/
|
|
||||||
if (nfsb != 1)
|
|
||||||
irecs = kmem_zalloc(sizeof(irec) * nfsb,
|
|
||||||
KM_NOFS);
|
|
||||||
|
|
||||||
nirecs = nfsb;
|
|
||||||
error = xfs_bmapi_read(dp, (xfs_fileoff_t)bno, nfsb, irecs,
|
|
||||||
&nirecs, xfs_bmapi_aflag(whichfork));
|
|
||||||
if (error)
|
|
||||||
goto out;
|
|
||||||
} else {
|
|
||||||
irecs->br_startblock = XFS_DADDR_TO_FSB(mp, mappedbno);
|
|
||||||
irecs->br_startoff = (xfs_fileoff_t)bno;
|
|
||||||
irecs->br_blockcount = nfsb;
|
|
||||||
irecs->br_state = 0;
|
|
||||||
nirecs = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!xfs_da_map_covers_blocks(nirecs, irecs, bno, nfsb)) {
|
if (!xfs_da_map_covers_blocks(nirecs, irecs, bno, nfsb)) {
|
||||||
/* Caller ok with no mapping. */
|
/* Caller ok with no mapping. */
|
||||||
|
@ -2616,24 +2601,29 @@ out:
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xfs_da_get_buf(
|
xfs_da_get_buf(
|
||||||
struct xfs_trans *trans,
|
struct xfs_trans *tp,
|
||||||
struct xfs_inode *dp,
|
struct xfs_inode *dp,
|
||||||
xfs_dablk_t bno,
|
xfs_dablk_t bno,
|
||||||
xfs_daddr_t mappedbno,
|
xfs_daddr_t mappedbno,
|
||||||
struct xfs_buf **bpp,
|
struct xfs_buf **bpp,
|
||||||
int whichfork)
|
int whichfork)
|
||||||
{
|
{
|
||||||
|
struct xfs_mount *mp = dp->i_mount;
|
||||||
struct xfs_buf *bp;
|
struct xfs_buf *bp;
|
||||||
struct xfs_buf_map map;
|
struct xfs_buf_map map, *mapp = ↦
|
||||||
struct xfs_buf_map *mapp;
|
int nmap = 1;
|
||||||
int nmap;
|
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
*bpp = NULL;
|
*bpp = NULL;
|
||||||
mapp = ↦
|
|
||||||
nmap = 1;
|
if (mappedbno >= 0) {
|
||||||
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
|
bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, mappedbno,
|
||||||
&mapp, &nmap);
|
XFS_FSB_TO_BB(mp,
|
||||||
|
xfs_dabuf_nfsb(mp, whichfork)), 0);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
|
||||||
if (error) {
|
if (error) {
|
||||||
/* mapping a hole is not an error, but we don't continue */
|
/* mapping a hole is not an error, but we don't continue */
|
||||||
if (error == -1)
|
if (error == -1)
|
||||||
|
@ -2641,12 +2631,12 @@ xfs_da_get_buf(
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
bp = xfs_trans_get_buf_map(trans, dp->i_mount->m_ddev_targp,
|
bp = xfs_trans_get_buf_map(tp, mp->m_ddev_targp, mapp, nmap, 0);
|
||||||
mapp, nmap, 0);
|
done:
|
||||||
error = bp ? bp->b_error : -EIO;
|
error = bp ? bp->b_error : -EIO;
|
||||||
if (error) {
|
if (error) {
|
||||||
if (bp)
|
if (bp)
|
||||||
xfs_trans_brelse(trans, bp);
|
xfs_trans_brelse(tp, bp);
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2664,7 +2654,7 @@ out_free:
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xfs_da_read_buf(
|
xfs_da_read_buf(
|
||||||
struct xfs_trans *trans,
|
struct xfs_trans *tp,
|
||||||
struct xfs_inode *dp,
|
struct xfs_inode *dp,
|
||||||
xfs_dablk_t bno,
|
xfs_dablk_t bno,
|
||||||
xfs_daddr_t mappedbno,
|
xfs_daddr_t mappedbno,
|
||||||
|
@ -2672,17 +2662,23 @@ xfs_da_read_buf(
|
||||||
int whichfork,
|
int whichfork,
|
||||||
const struct xfs_buf_ops *ops)
|
const struct xfs_buf_ops *ops)
|
||||||
{
|
{
|
||||||
|
struct xfs_mount *mp = dp->i_mount;
|
||||||
struct xfs_buf *bp;
|
struct xfs_buf *bp;
|
||||||
struct xfs_buf_map map;
|
struct xfs_buf_map map, *mapp = ↦
|
||||||
struct xfs_buf_map *mapp;
|
int nmap = 1;
|
||||||
int nmap;
|
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
*bpp = NULL;
|
*bpp = NULL;
|
||||||
mapp = ↦
|
|
||||||
nmap = 1;
|
if (mappedbno >= 0) {
|
||||||
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
|
error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
|
||||||
&mapp, &nmap);
|
mappedbno, XFS_FSB_TO_BB(mp,
|
||||||
|
xfs_dabuf_nfsb(mp, whichfork)),
|
||||||
|
0, &bp, ops);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
|
||||||
if (error) {
|
if (error) {
|
||||||
/* mapping a hole is not an error, but we don't continue */
|
/* mapping a hole is not an error, but we don't continue */
|
||||||
if (error == -1)
|
if (error == -1)
|
||||||
|
@ -2690,9 +2686,9 @@ xfs_da_read_buf(
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = xfs_trans_read_buf_map(dp->i_mount, trans,
|
error = xfs_trans_read_buf_map(mp, tp, mp->m_ddev_targp, mapp, nmap, 0,
|
||||||
dp->i_mount->m_ddev_targp,
|
&bp, ops);
|
||||||
mapp, nmap, 0, &bp, ops);
|
done:
|
||||||
if (error)
|
if (error)
|
||||||
goto out_free;
|
goto out_free;
|
||||||
|
|
||||||
|
@ -2724,6 +2720,9 @@ xfs_da_reada_buf(
|
||||||
int nmap;
|
int nmap;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
if (mappedbno >= 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
mapp = ↦
|
mapp = ↦
|
||||||
nmap = 1;
|
nmap = 1;
|
||||||
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
|
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
|
||||||
|
|
Loading…
Reference in New Issue