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 <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:

committed by
Darrick J. Wong

parent
45feef8f50
commit
199e9ba4e4
@@ -2460,19 +2460,11 @@ xfs_da_shrink_inode(
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Map the block we are given ready for reading. There are three possible return
|
|
||||||
* values:
|
|
||||||
* -1 - will be returned if we land in a hole and mappedbno == -2 so the
|
|
||||||
* caller knows not to execute a subsequent read.
|
|
||||||
* 0 - if we mapped the block successfully
|
|
||||||
* >0 - positive error number if there was an error.
|
|
||||||
*/
|
|
||||||
static int
|
static int
|
||||||
xfs_dabuf_map(
|
xfs_dabuf_map(
|
||||||
struct xfs_inode *dp,
|
struct xfs_inode *dp,
|
||||||
xfs_dablk_t bno,
|
xfs_dablk_t bno,
|
||||||
xfs_daddr_t mappedbno,
|
unsigned int flags,
|
||||||
int whichfork,
|
int whichfork,
|
||||||
struct xfs_buf_map **mapp,
|
struct xfs_buf_map **mapp,
|
||||||
int *nmaps)
|
int *nmaps)
|
||||||
@@ -2527,7 +2519,7 @@ out_free_irecs:
|
|||||||
|
|
||||||
invalid_mapping:
|
invalid_mapping:
|
||||||
/* Caller ok with no mapping. */
|
/* Caller ok with no mapping. */
|
||||||
if (XFS_IS_CORRUPT(mp, mappedbno != -2)) {
|
if (XFS_IS_CORRUPT(mp, !(flags & XFS_DABUF_MAP_HOLE_OK))) {
|
||||||
error = -EFSCORRUPTED;
|
error = -EFSCORRUPTED;
|
||||||
if (xfs_error_level >= XFS_ERRLEVEL_LOW) {
|
if (xfs_error_level >= XFS_ERRLEVEL_LOW) {
|
||||||
xfs_alert(mp, "%s: bno %u inode %llu",
|
xfs_alert(mp, "%s: bno %u inode %llu",
|
||||||
@@ -2575,13 +2567,11 @@ xfs_da_get_buf(
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
|
error = xfs_dabuf_map(dp, bno,
|
||||||
if (error) {
|
mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
|
||||||
/* mapping a hole is not an error, but we don't continue */
|
whichfork, &mapp, &nmap);
|
||||||
if (error == -1)
|
if (error || nmap == 0)
|
||||||
error = 0;
|
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
|
||||||
|
|
||||||
bp = xfs_trans_get_buf_map(tp, mp->m_ddev_targp, mapp, nmap, 0);
|
bp = xfs_trans_get_buf_map(tp, mp->m_ddev_targp, mapp, nmap, 0);
|
||||||
done:
|
done:
|
||||||
@@ -2630,13 +2620,11 @@ xfs_da_read_buf(
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork, &mapp, &nmap);
|
error = xfs_dabuf_map(dp, bno,
|
||||||
if (error) {
|
mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
|
||||||
/* mapping a hole is not an error, but we don't continue */
|
whichfork, &mapp, &nmap);
|
||||||
if (error == -1)
|
if (error || !nmap)
|
||||||
error = 0;
|
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
|
||||||
|
|
||||||
error = xfs_trans_read_buf_map(mp, tp, mp->m_ddev_targp, mapp, nmap, 0,
|
error = xfs_trans_read_buf_map(mp, tp, mp->m_ddev_targp, mapp, nmap, 0,
|
||||||
&bp, ops);
|
&bp, ops);
|
||||||
@@ -2677,14 +2665,11 @@ xfs_da_reada_buf(
|
|||||||
|
|
||||||
mapp = ↦
|
mapp = ↦
|
||||||
nmap = 1;
|
nmap = 1;
|
||||||
error = xfs_dabuf_map(dp, bno, mappedbno, whichfork,
|
error = xfs_dabuf_map(dp, bno,
|
||||||
&mapp, &nmap);
|
mappedbno == -1 ? XFS_DABUF_MAP_HOLE_OK : 0,
|
||||||
if (error) {
|
whichfork, &mapp, &nmap);
|
||||||
/* mapping a hole is not an error, but we don't continue */
|
if (error || !nmap)
|
||||||
if (error == -1)
|
|
||||||
error = 0;
|
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
|
||||||
|
|
||||||
mappedbno = mapp[0].bm_bn;
|
mappedbno = mapp[0].bm_bn;
|
||||||
xfs_buf_readahead_map(dp->i_mount->m_ddev_targp, mapp, nmap, ops);
|
xfs_buf_readahead_map(dp->i_mount->m_ddev_targp, mapp, nmap, ops);
|
||||||
|
@@ -194,6 +194,9 @@ int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
|
|||||||
/*
|
/*
|
||||||
* Utility routines.
|
* Utility routines.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define XFS_DABUF_MAP_HOLE_OK (1 << 0)
|
||||||
|
|
||||||
int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno);
|
int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno);
|
||||||
int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
|
int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
|
||||||
int count);
|
int count);
|
||||||
|
Reference in New Issue
Block a user