Commit 2b8f12b7 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Alex Elder

xfs: clean up mapping size calculation in __xfs_get_blocks

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAlex Elder <aelder@sgi.com>
parent 558e6891
...@@ -1536,16 +1536,23 @@ __xfs_get_blocks( ...@@ -1536,16 +1536,23 @@ __xfs_get_blocks(
} }
} }
/*
* If this is O_DIRECT or the mpage code calling tell them how large
* the mapping is, so that we can avoid repeated get_blocks calls.
*/
if (direct || size > (1 << inode->i_blkbits)) { if (direct || size > (1 << inode->i_blkbits)) {
struct xfs_mount *mp = XFS_I(inode)->i_mount; xfs_off_t mapping_size;
xfs_off_t iomap_offset = XFS_FSB_TO_B(mp, imap.br_startoff);
xfs_off_t iomap_delta = offset - iomap_offset; mapping_size = imap.br_startoff + imap.br_blockcount - iblock;
xfs_off_t iomap_bsize = XFS_FSB_TO_B(mp, imap.br_blockcount); mapping_size <<= inode->i_blkbits;
ASSERT(iomap_bsize - iomap_delta > 0); ASSERT(mapping_size > 0);
offset = min_t(xfs_off_t, if (mapping_size > size)
iomap_bsize - iomap_delta, size); mapping_size = size;
bh_result->b_size = (ssize_t)min_t(xfs_off_t, LONG_MAX, offset); if (mapping_size > LONG_MAX)
mapping_size = LONG_MAX;
bh_result->b_size = mapping_size;
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment