Skip to content

Commit 199e9ba

Browse files
Christoph Hellwigdjwong
authored andcommitted
xfs: improve the xfs_dabuf_map calling conventions
Use a flags argument with the XFS_DABUF_MAP_HOLE_OK flag to signal that a hole is okay and not corruption, and return 0 with *nmap set to 0 to signal that case in the return value instead of a nameless -1 return code. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 45feef8 commit 199e9ba

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

fs/xfs/libxfs/xfs_da_btree.c

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,19 +2460,11 @@ xfs_da_shrink_inode(
24602460
return error;
24612461
}
24622462

2463-
/*
2464-
* Map the block we are given ready for reading. There are three possible return
2465-
* values:
2466-
* -1 - will be returned if we land in a hole and mappedbno == -2 so the
2467-
* caller knows not to execute a subsequent read.
2468-
* 0 - if we mapped the block successfully
2469-
* >0 - positive error number if there was an error.
2470-
*/
24712463
static int
24722464
xfs_dabuf_map(
24732465
struct xfs_inode *dp,
24742466
xfs_dablk_t bno,
2475-
xfs_daddr_t mappedbno,
2467+
unsigned int flags,
24762468
int whichfork,
24772469
struct xfs_buf_map **mapp,
24782470
int *nmaps)
@@ -2527,7 +2519,7 @@ xfs_dabuf_map(
25272519

25282520
invalid_mapping:
25292521
/* Caller ok with no mapping. */
2530-
if (XFS_IS_CORRUPT(mp, mappedbno != -2)) {
2522+
if (XFS_IS_CORRUPT(mp, !(flags & XFS_DABUF_MAP_HOLE_OK))) {
25312523
error = -EFSCORRUPTED;
25322524
if (xfs_error_level >= XFS_ERRLEVEL_LOW) {
25332525
xfs_alert(mp, "%s: bno %u inode %llu",
@@ -2575,13 +2567,11 @@ xfs_da_get_buf(
25752567
goto done;
25762568
}
25772569

2578-
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
2579-
if (error) {
2580-
/* mapping a hole is not an error, but we don't continue */
2581-
if (error == -1)
2582-
error = 0;
2570+
error = xfs_dabuf_map(dp, bno,
2571+
mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
2572+
whichfork, &mapp, &nmap);
2573+
if (error || nmap == 0)
25832574
goto out_free;
2584-
}
25852575

25862576
bp = xfs_trans_get_buf_map(tp, mp->m_ddev_targp, mapp, nmap, 0);
25872577
done:
@@ -2630,13 +2620,11 @@ xfs_da_read_buf(
26302620
goto done;
26312621
}
26322622

2633-
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
2634-
if (error) {
2635-
/* mapping a hole is not an error, but we don't continue */
2636-
if (error == -1)
2637-
error = 0;
2623+
error = xfs_dabuf_map(dp, bno,
2624+
mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
2625+
whichfork, &mapp, &nmap);
2626+
if (error || !nmap)
26382627
goto out_free;
2639-
}
26402628

26412629
error = xfs_trans_read_buf_map(mp, tp, mp->m_ddev_targp, mapp, nmap, 0,
26422630
&bp, ops);
@@ -2677,14 +2665,11 @@ xfs_da_reada_buf(
26772665

26782666
mapp = &map;
26792667
nmap = 1;
2680-
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
2681-
&mapp, &nmap);
2682-
if (error) {
2683-
/* mapping a hole is not an error, but we don't continue */
2684-
if (error == -1)
2685-
error = 0;
2668+
error = xfs_dabuf_map(dp, bno,
2669+
mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
2670+
whichfork, &mapp, &nmap);
2671+
if (error || !nmap)
26862672
goto out_free;
2687-
}
26882673

26892674
mappedbno = mapp[0].bm_bn;
26902675
xfs_buf_readahead_map(dp->i_mount->m_ddev_targp, mapp, nmap, ops);

fs/xfs/libxfs/xfs_da_btree.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
194194
/*
195195
* Utility routines.
196196
*/
197+
198+
#define XFS_DABUF_MAP_HOLE_OK (1 << 0)
199+
197200
int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno);
198201
int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
199202
int count);

0 commit comments

Comments
 (0)