Skip to content

Commit fa0d44e

Browse files
Christoph Hellwigdjwong
authored andcommitted
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 <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 6519f70 commit fa0d44e

File tree

1 file changed

+51
-52
lines changed

1 file changed

+51
-52
lines changed

fs/xfs/libxfs/xfs_da_btree.c

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ xfs_da_state_free(xfs_da_state_t *state)
110110
kmem_cache_free(xfs_da_state_zone, state);
111111
}
112112

113+
static inline int xfs_dabuf_nfsb(struct xfs_mount *mp, int whichfork)
114+
{
115+
if (whichfork == XFS_DATA_FORK)
116+
return mp->m_dir_geo->fsbcount;
117+
return mp->m_attr_geo->fsbcount;
118+
}
119+
113120
void
114121
xfs_da3_node_hdr_from_disk(
115122
struct xfs_mount *mp,
@@ -2539,7 +2546,7 @@ xfs_dabuf_map(
25392546
int *nmaps)
25402547
{
25412548
struct xfs_mount *mp = dp->i_mount;
2542-
int nfsb;
2549+
int nfsb = xfs_dabuf_nfsb(mp, whichfork);
25432550
int error = 0;
25442551
struct xfs_bmbt_irec irec;
25452552
struct xfs_bmbt_irec *irecs = &irec;
@@ -2548,35 +2555,13 @@ xfs_dabuf_map(
25482555
ASSERT(map && *map);
25492556
ASSERT(*nmaps == 1);
25502557

2551-
if (whichfork == XFS_DATA_FORK)
2552-
nfsb = mp->m_dir_geo->fsbcount;
2553-
else
2554-
nfsb = mp->m_attr_geo->fsbcount;
2555-
2556-
/*
2557-
* Caller doesn't have a mapping. -2 means don't complain
2558-
* if we land in a hole.
2559-
*/
2560-
if (mappedbno == -1 || mappedbno == -2) {
2561-
/*
2562-
* Optimize the one-block case.
2563-
*/
2564-
if (nfsb != 1)
2565-
irecs = kmem_zalloc(sizeof(irec) * nfsb,
2566-
KM_NOFS);
2567-
2568-
nirecs = nfsb;
2569-
error = xfs_bmapi_read(dp, (xfs_fileoff_t)bno, nfsb, irecs,
2570-
&nirecs, xfs_bmapi_aflag(whichfork));
2571-
if (error)
2572-
goto out;
2573-
} else {
2574-
irecs->br_startblock = XFS_DADDR_TO_FSB(mp, mappedbno);
2575-
irecs->br_startoff = (xfs_fileoff_t)bno;
2576-
irecs->br_blockcount = nfsb;
2577-
irecs->br_state = 0;
2578-
nirecs = 1;
2579-
}
2558+
if (nfsb != 1)
2559+
irecs = kmem_zalloc(sizeof(irec) * nfsb, KM_NOFS);
2560+
nirecs = nfsb;
2561+
error = xfs_bmapi_read(dp, (xfs_fileoff_t)bno, nfsb, irecs,
2562+
&nirecs, xfs_bmapi_aflag(whichfork));
2563+
if (error)
2564+
goto out;
25802565

25812566
if (!xfs_da_map_covers_blocks(nirecs, irecs, bno, nfsb)) {
25822567
/* Caller ok with no mapping. */
@@ -2616,37 +2601,42 @@ xfs_dabuf_map(
26162601
*/
26172602
int
26182603
xfs_da_get_buf(
2619-
struct xfs_trans *trans,
2604+
struct xfs_trans *tp,
26202605
struct xfs_inode *dp,
26212606
xfs_dablk_t bno,
26222607
xfs_daddr_t mappedbno,
26232608
struct xfs_buf **bpp,
26242609
int whichfork)
26252610
{
2611+
struct xfs_mount *mp = dp->i_mount;
26262612
struct xfs_buf *bp;
2627-
struct xfs_buf_map map;
2628-
struct xfs_buf_map *mapp;
2629-
int nmap;
2613+
struct xfs_buf_map map, *mapp = &map;
2614+
int nmap = 1;
26302615
int error;
26312616

26322617
*bpp = NULL;
2633-
mapp = &map;
2634-
nmap = 1;
2635-
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
2636-
&mapp, &nmap);
2618+
2619+
if (mappedbno >= 0) {
2620+
bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, mappedbno,
2621+
XFS_FSB_TO_BB(mp,
2622+
xfs_dabuf_nfsb(mp, whichfork)), 0);
2623+
goto done;
2624+
}
2625+
2626+
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
26372627
if (error) {
26382628
/* mapping a hole is not an error, but we don't continue */
26392629
if (error == -1)
26402630
error = 0;
26412631
goto out_free;
26422632
}
26432633

2644-
bp = xfs_trans_get_buf_map(trans, dp->i_mount->m_ddev_targp,
2645-
mapp, nmap, 0);
2634+
bp = xfs_trans_get_buf_map(tp, mp->m_ddev_targp, mapp, nmap, 0);
2635+
done:
26462636
error = bp ? bp->b_error : -EIO;
26472637
if (error) {
26482638
if (bp)
2649-
xfs_trans_brelse(trans, bp);
2639+
xfs_trans_brelse(tp, bp);
26502640
goto out_free;
26512641
}
26522642

@@ -2664,35 +2654,41 @@ xfs_da_get_buf(
26642654
*/
26652655
int
26662656
xfs_da_read_buf(
2667-
struct xfs_trans *trans,
2657+
struct xfs_trans *tp,
26682658
struct xfs_inode *dp,
26692659
xfs_dablk_t bno,
26702660
xfs_daddr_t mappedbno,
26712661
struct xfs_buf **bpp,
26722662
int whichfork,
26732663
const struct xfs_buf_ops *ops)
26742664
{
2665+
struct xfs_mount *mp = dp->i_mount;
26752666
struct xfs_buf *bp;
2676-
struct xfs_buf_map map;
2677-
struct xfs_buf_map *mapp;
2678-
int nmap;
2667+
struct xfs_buf_map map, *mapp = &map;
2668+
int nmap = 1;
26792669
int error;
26802670

26812671
*bpp = NULL;
2682-
mapp = &map;
2683-
nmap = 1;
2684-
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
2685-
&mapp, &nmap);
2672+
2673+
if (mappedbno >= 0) {
2674+
error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
2675+
mappedbno, XFS_FSB_TO_BB(mp,
2676+
xfs_dabuf_nfsb(mp, whichfork)),
2677+
0, &bp, ops);
2678+
goto done;
2679+
}
2680+
2681+
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
26862682
if (error) {
26872683
/* mapping a hole is not an error, but we don't continue */
26882684
if (error == -1)
26892685
error = 0;
26902686
goto out_free;
26912687
}
26922688

2693-
error = xfs_trans_read_buf_map(dp->i_mount, trans,
2694-
dp->i_mount->m_ddev_targp,
2695-
mapp, nmap, 0, &bp, ops);
2689+
error = xfs_trans_read_buf_map(mp, tp, mp->m_ddev_targp, mapp, nmap, 0,
2690+
&bp, ops);
2691+
done:
26962692
if (error)
26972693
goto out_free;
26982694

@@ -2724,6 +2720,9 @@ xfs_da_reada_buf(
27242720
int nmap;
27252721
int error;
27262722

2723+
if (mappedbno >= 0)
2724+
return -EINVAL;
2725+
27272726
mapp = &map;
27282727
nmap = 1;
27292728
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,

0 commit comments

Comments
 (0)