Commit 092d5d9d authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Dave Chinner

xfs: cleanup xfs_reflink_find_cow_mapping

Use xfs_iext_lookup_extent to look up the extent, drop a useless check,
drop a unneeded return value and clean up the general style a little bit.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
parent 2755fc44
...@@ -777,7 +777,7 @@ xfs_map_cow( ...@@ -777,7 +777,7 @@ xfs_map_cow(
{ {
struct xfs_inode *ip = XFS_I(inode); struct xfs_inode *ip = XFS_I(inode);
struct xfs_bmbt_irec imap; struct xfs_bmbt_irec imap;
bool is_cow = false, need_alloc = false; bool is_cow = false;
int error; int error;
/* /*
...@@ -795,7 +795,7 @@ xfs_map_cow( ...@@ -795,7 +795,7 @@ xfs_map_cow(
* Else we need to check if there is a COW mapping at this offset. * Else we need to check if there is a COW mapping at this offset.
*/ */
xfs_ilock(ip, XFS_ILOCK_SHARED); xfs_ilock(ip, XFS_ILOCK_SHARED);
is_cow = xfs_reflink_find_cow_mapping(ip, offset, &imap, &need_alloc); is_cow = xfs_reflink_find_cow_mapping(ip, offset, &imap);
xfs_iunlock(ip, XFS_ILOCK_SHARED); xfs_iunlock(ip, XFS_ILOCK_SHARED);
if (!is_cow) if (!is_cow)
...@@ -805,7 +805,7 @@ xfs_map_cow( ...@@ -805,7 +805,7 @@ xfs_map_cow(
* And if the COW mapping has a delayed extent here we need to * And if the COW mapping has a delayed extent here we need to
* allocate real space for it now. * allocate real space for it now.
*/ */
if (need_alloc) { if (isnullstartblock(imap.br_startblock)) {
error = xfs_iomap_write_allocate(ip, XFS_COW_FORK, offset, error = xfs_iomap_write_allocate(ip, XFS_COW_FORK, offset,
&imap); &imap);
if (error) if (error)
...@@ -1312,7 +1312,6 @@ __xfs_get_blocks( ...@@ -1312,7 +1312,6 @@ __xfs_get_blocks(
ssize_t size; ssize_t size;
int new = 0; int new = 0;
bool is_cow = false; bool is_cow = false;
bool need_alloc = false;
BUG_ON(create && !direct); BUG_ON(create && !direct);
...@@ -1338,9 +1337,11 @@ __xfs_get_blocks( ...@@ -1338,9 +1337,11 @@ __xfs_get_blocks(
end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + size); end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + size);
offset_fsb = XFS_B_TO_FSBT(mp, offset); offset_fsb = XFS_B_TO_FSBT(mp, offset);
if (create && direct && xfs_is_reflink_inode(ip)) if (create && direct && xfs_is_reflink_inode(ip)) {
is_cow = xfs_reflink_find_cow_mapping(ip, offset, &imap, is_cow = xfs_reflink_find_cow_mapping(ip, offset, &imap);
&need_alloc); ASSERT(!is_cow || !isnullstartblock(imap.br_startblock));
}
if (!is_cow) { if (!is_cow) {
error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb,
&imap, &nimaps, XFS_BMAPI_ENTIRE); &imap, &nimaps, XFS_BMAPI_ENTIRE);
...@@ -1357,7 +1358,6 @@ __xfs_get_blocks( ...@@ -1357,7 +1358,6 @@ __xfs_get_blocks(
xfs_reflink_trim_irec_to_next_cow(ip, offset_fsb, xfs_reflink_trim_irec_to_next_cow(ip, offset_fsb,
&imap); &imap);
} }
ASSERT(!need_alloc);
if (error) if (error)
goto out_unlock; goto out_unlock;
......
...@@ -420,44 +420,31 @@ xfs_reflink_allocate_cow_range( ...@@ -420,44 +420,31 @@ xfs_reflink_allocate_cow_range(
} }
/* /*
* Find the CoW reservation (and whether or not it needs block allocation) * Find the CoW reservation for a given byte offset of a file.
* for a given byte offset of a file.
*/ */
bool bool
xfs_reflink_find_cow_mapping( xfs_reflink_find_cow_mapping(
struct xfs_inode *ip, struct xfs_inode *ip,
xfs_off_t offset, xfs_off_t offset,
struct xfs_bmbt_irec *imap, struct xfs_bmbt_irec *imap)
bool *need_alloc)
{ {
struct xfs_bmbt_irec irec; struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
struct xfs_ifork *ifp; xfs_fileoff_t offset_fsb;
struct xfs_bmbt_rec_host *gotp; struct xfs_bmbt_irec got;
xfs_fileoff_t bno;
xfs_extnum_t idx; xfs_extnum_t idx;
ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL | XFS_ILOCK_SHARED)); ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL | XFS_ILOCK_SHARED));
ASSERT(xfs_is_reflink_inode(ip)); ASSERT(xfs_is_reflink_inode(ip));
/* Find the extent in the CoW fork. */ offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset);
ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK); if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &idx, &got))
bno = XFS_B_TO_FSBT(ip->i_mount, offset);
gotp = xfs_iext_bno_to_ext(ifp, bno, &idx);
if (!gotp)
return false; return false;
if (got.br_startoff > offset_fsb)
xfs_bmbt_get_all(gotp, &irec);
if (bno >= irec.br_startoff + irec.br_blockcount ||
bno < irec.br_startoff)
return false; return false;
trace_xfs_reflink_find_cow_mapping(ip, offset, 1, XFS_IO_OVERWRITE, trace_xfs_reflink_find_cow_mapping(ip, offset, 1, XFS_IO_OVERWRITE,
&irec); &got);
*imap = got;
/* If it's still delalloc, we must allocate later. */
*imap = irec;
*need_alloc = !!(isnullstartblock(irec.br_startblock));
return true; return true;
} }
......
...@@ -31,7 +31,7 @@ extern int xfs_reflink_reserve_cow(struct xfs_inode *ip, ...@@ -31,7 +31,7 @@ extern int xfs_reflink_reserve_cow(struct xfs_inode *ip,
extern int xfs_reflink_allocate_cow_range(struct xfs_inode *ip, extern int xfs_reflink_allocate_cow_range(struct xfs_inode *ip,
xfs_off_t offset, xfs_off_t count); xfs_off_t offset, xfs_off_t count);
extern bool xfs_reflink_find_cow_mapping(struct xfs_inode *ip, xfs_off_t offset, extern bool xfs_reflink_find_cow_mapping(struct xfs_inode *ip, xfs_off_t offset,
struct xfs_bmbt_irec *imap, bool *need_alloc); struct xfs_bmbt_irec *imap);
extern int xfs_reflink_trim_irec_to_next_cow(struct xfs_inode *ip, extern int xfs_reflink_trim_irec_to_next_cow(struct xfs_inode *ip,
xfs_fileoff_t offset_fsb, struct xfs_bmbt_irec *imap); xfs_fileoff_t offset_fsb, struct xfs_bmbt_irec *imap);
......
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