Commit 05b7c8ab authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: move some code around inside xfs_bmap_shift_extents

For the first right move we need to look up next_fsb.  That means
our last fsb that contains next_fsb must also be the current extent,
so take advantage of that by moving the code around a bit.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent f2285c14
...@@ -6127,7 +6127,6 @@ xfs_bmap_shift_extents( ...@@ -6127,7 +6127,6 @@ xfs_bmap_shift_extents(
ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
ASSERT(direction == SHIFT_LEFT || direction == SHIFT_RIGHT); ASSERT(direction == SHIFT_LEFT || direction == SHIFT_RIGHT);
ASSERT(*next_fsb != NULLFSBLOCK || direction == SHIFT_RIGHT);
ifp = XFS_IFORK_PTR(ip, whichfork); ifp = XFS_IFORK_PTR(ip, whichfork);
if (!(ifp->if_flags & XFS_IFEXTENTS)) { if (!(ifp->if_flags & XFS_IFEXTENTS)) {
...@@ -6159,23 +6158,17 @@ xfs_bmap_shift_extents( ...@@ -6159,23 +6158,17 @@ xfs_bmap_shift_extents(
* In case of first right shift, we need to initialize next_fsb * In case of first right shift, we need to initialize next_fsb
*/ */
if (*next_fsb == NULLFSBLOCK) { if (*next_fsb == NULLFSBLOCK) {
gotp = xfs_iext_get_ext(ifp, total_extents - 1); ASSERT(direction == SHIFT_RIGHT);
current_ext = total_extents - 1;
gotp = xfs_iext_get_ext(ifp, current_ext);
xfs_bmbt_get_all(gotp, &got); xfs_bmbt_get_all(gotp, &got);
*next_fsb = got.br_startoff; *next_fsb = got.br_startoff;
if (stop_fsb > *next_fsb) { if (stop_fsb > *next_fsb) {
*done = 1; *done = 1;
goto del_cursor; goto del_cursor;
} }
} } else {
/* Lookup the extent index at which we have to stop */
if (direction == SHIFT_RIGHT) {
gotp = xfs_iext_bno_to_ext(ifp, stop_fsb, &stop_extent);
/* Make stop_extent exclusive of shift range */
stop_extent--;
} else
stop_extent = total_extents;
/* /*
* Look up the extent index for the fsb where we start shifting. We can * Look up the extent index for the fsb where we start shifting. We can
* henceforth iterate with current_ext as extent list changes are locked * henceforth iterate with current_ext as extent list changes are locked
...@@ -6190,13 +6183,24 @@ xfs_bmap_shift_extents( ...@@ -6190,13 +6183,24 @@ xfs_bmap_shift_extents(
*done = 1; *done = 1;
goto del_cursor; goto del_cursor;
} }
}
/* some sanity checking before we finally start shifting extents */ /* Lookup the extent index at which we have to stop */
if ((direction == SHIFT_LEFT && current_ext >= stop_extent) || if (direction == SHIFT_RIGHT) {
(direction == SHIFT_RIGHT && current_ext <= stop_extent)) { xfs_iext_bno_to_ext(ifp, stop_fsb, &stop_extent);
/* Make stop_extent exclusive of shift range */
stop_extent--;
if (current_ext <= stop_extent) {
error = -EIO; error = -EIO;
goto del_cursor; goto del_cursor;
} }
} else {
stop_extent = total_extents;
if (current_ext >= stop_extent) {
error = -EIO;
goto del_cursor;
}
}
while (nexts++ < num_exts) { while (nexts++ < num_exts) {
error = xfs_bmse_shift_one(ip, whichfork, offset_shift_fsb, error = xfs_bmse_shift_one(ip, whichfork, offset_shift_fsb,
......
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