Skip to content

Commit d456c25

Browse files
josefbacikkdave
authored andcommitted
btrfs: push lock_extent down in cow_file_range()
Now that we've got the extent lock pushed into cow_file_range() we can push it further down into the allocation loop. This allows us to only hold the extent lock during the dropping of the extent map range and inserting the ordered extent. This makes the error case a little trickier as we'll now have to lock the range before clearing any of the other extent bits for the range, but this is the error path so is less performance critical. Reviewed-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent cd241a8 commit d456c25

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

fs/btrfs/inode.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,8 +1371,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
13711371
}
13721372
}
13731373

1374-
lock_extent(&inode->io_tree, start, end, NULL);
1375-
13761374
alloc_hint = get_extent_allocation_hint(inode, start, num_bytes);
13771375

13781376
/*
@@ -1429,6 +1427,9 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
14291427
extent_reserved = true;
14301428

14311429
ram_size = ins.offset;
1430+
1431+
lock_extent(&inode->io_tree, start, start + ram_size - 1, NULL);
1432+
14321433
em = create_io_em(inode, start, ins.offset, /* len */
14331434
start, /* orig_start */
14341435
ins.objectid, /* block_start */
@@ -1438,6 +1439,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
14381439
BTRFS_COMPRESS_NONE, /* compress_type */
14391440
BTRFS_ORDERED_REGULAR /* type */);
14401441
if (IS_ERR(em)) {
1442+
unlock_extent(&inode->io_tree, start,
1443+
start + ram_size - 1, NULL);
14411444
ret = PTR_ERR(em);
14421445
goto out_reserve;
14431446
}
@@ -1448,6 +1451,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
14481451
0, 1 << BTRFS_ORDERED_REGULAR,
14491452
BTRFS_COMPRESS_NONE);
14501453
if (IS_ERR(ordered)) {
1454+
unlock_extent(&inode->io_tree, start,
1455+
start + ram_size - 1, NULL);
14511456
ret = PTR_ERR(ordered);
14521457
goto out_drop_extent_cache;
14531458
}
@@ -1549,6 +1554,13 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
15491554
locked_page, 0, page_ops);
15501555
}
15511556

1557+
/*
1558+
* At this point we're unlocked, we want to make sure we're only
1559+
* clearing these flags under the extent lock, so lock the rest of the
1560+
* range and clear everything up.
1561+
*/
1562+
lock_extent(&inode->io_tree, start, end, NULL);
1563+
15521564
/*
15531565
* For the range (2). If we reserved an extent for our delalloc range
15541566
* (or a subrange) and failed to create the respective ordered extent,

0 commit comments

Comments
 (0)