Skip to content

Commit 77fe20d

Browse files
Mark FashehChris Mason
authored andcommitted
btrfs: abtract out range locking in clone ioctl()
The range locking in btrfs_ioctl_clone is trivially broken out into it's own function. This reduces the complexity of btrfs_ioctl_clone() by a small bit and makes that locking code available to future functions in fs/btrfs/ioctl.c Signed-off-by: Mark Fasheh <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent a4fdb61 commit 77fe20d

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

fs/btrfs/ioctl.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,26 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
24702470
return ret;
24712471
}
24722472

2473+
static inline void lock_extent_range(struct inode *inode, u64 off, u64 len)
2474+
{
2475+
/* do any pending delalloc/csum calc on src, one way or
2476+
another, and lock file content */
2477+
while (1) {
2478+
struct btrfs_ordered_extent *ordered;
2479+
lock_extent(&BTRFS_I(inode)->io_tree, off, off + len - 1);
2480+
ordered = btrfs_lookup_first_ordered_extent(inode,
2481+
off + len - 1);
2482+
if (!ordered &&
2483+
!test_range_bit(&BTRFS_I(inode)->io_tree, off,
2484+
off + len - 1, EXTENT_DELALLOC, 0, NULL))
2485+
break;
2486+
unlock_extent(&BTRFS_I(inode)->io_tree, off, off + len - 1);
2487+
if (ordered)
2488+
btrfs_put_ordered_extent(ordered);
2489+
btrfs_wait_ordered_range(inode, off, len);
2490+
}
2491+
}
2492+
24732493
static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
24742494
u64 off, u64 olen, u64 destoff)
24752495
{
@@ -2598,21 +2618,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
25982618
truncate_inode_pages_range(&inode->i_data, destoff,
25992619
PAGE_CACHE_ALIGN(destoff + len) - 1);
26002620

2601-
/* do any pending delalloc/csum calc on src, one way or
2602-
another, and lock file content */
2603-
while (1) {
2604-
struct btrfs_ordered_extent *ordered;
2605-
lock_extent(&BTRFS_I(src)->io_tree, off, off + len - 1);
2606-
ordered = btrfs_lookup_first_ordered_extent(src, off + len - 1);
2607-
if (!ordered &&
2608-
!test_range_bit(&BTRFS_I(src)->io_tree, off, off + len - 1,
2609-
EXTENT_DELALLOC, 0, NULL))
2610-
break;
2611-
unlock_extent(&BTRFS_I(src)->io_tree, off, off + len - 1);
2612-
if (ordered)
2613-
btrfs_put_ordered_extent(ordered);
2614-
btrfs_wait_ordered_range(src, off, len);
2615-
}
2621+
lock_extent_range(src, off, len);
26162622

26172623
/* clone data */
26182624
key.objectid = btrfs_ino(src);

0 commit comments

Comments
 (0)