Btrfs: remove unnecessary condition in btrfs_clone() to avoid too much nesting
The bulk of the work done when cloning extents, at ioctl.c:btrfs_clone(), is done inside an if statement that checks if the found key has the type BTRFS_EXTENT_DATA_KEY. That if statement is redundant however, because btrfs_search_slot() always leaves us in a leaf slot that points to a key that is always greater then or equals to the search key, and our search key here has that type, and because we bail out before that if statement if the key at the given leaf slot is greater then BTRFS_EXTENT_DATA_KEY. Therefore just remove that if statement, not only because it is useless but mostly because it increases the nesting/indentation level in this function which is quite big and makes things a bit awkward whenever I need to fix something that requires changing btrfs_clone() (and it has been like that for many years already). Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:

committed by
David Sterba

parent
559ca6ea69
commit
b64119b5f0
@@ -3516,6 +3516,14 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
u64 next_key_min_offset = key.offset + 1;
|
u64 next_key_min_offset = key.offset + 1;
|
||||||
|
struct btrfs_file_extent_item *extent;
|
||||||
|
int type;
|
||||||
|
u32 size;
|
||||||
|
struct btrfs_key new_key;
|
||||||
|
u64 disko = 0, diskl = 0;
|
||||||
|
u64 datao = 0, datal = 0;
|
||||||
|
u8 comp;
|
||||||
|
u64 drop_start;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* note the key will change type as we walk through the
|
* note the key will change type as we walk through the
|
||||||
@@ -3556,15 +3564,7 @@ process_slot:
|
|||||||
key.objectid != btrfs_ino(BTRFS_I(src)))
|
key.objectid != btrfs_ino(BTRFS_I(src)))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (key.type == BTRFS_EXTENT_DATA_KEY) {
|
ASSERT(key.type == BTRFS_EXTENT_DATA_KEY);
|
||||||
struct btrfs_file_extent_item *extent;
|
|
||||||
int type;
|
|
||||||
u32 size;
|
|
||||||
struct btrfs_key new_key;
|
|
||||||
u64 disko = 0, diskl = 0;
|
|
||||||
u64 datao = 0, datal = 0;
|
|
||||||
u8 comp;
|
|
||||||
u64 drop_start;
|
|
||||||
|
|
||||||
extent = btrfs_item_ptr(leaf, slot,
|
extent = btrfs_item_ptr(leaf, slot,
|
||||||
struct btrfs_file_extent_item);
|
struct btrfs_file_extent_item);
|
||||||
@@ -3572,23 +3572,19 @@ process_slot:
|
|||||||
type = btrfs_file_extent_type(leaf, extent);
|
type = btrfs_file_extent_type(leaf, extent);
|
||||||
if (type == BTRFS_FILE_EXTENT_REG ||
|
if (type == BTRFS_FILE_EXTENT_REG ||
|
||||||
type == BTRFS_FILE_EXTENT_PREALLOC) {
|
type == BTRFS_FILE_EXTENT_PREALLOC) {
|
||||||
disko = btrfs_file_extent_disk_bytenr(leaf,
|
disko = btrfs_file_extent_disk_bytenr(leaf, extent);
|
||||||
extent);
|
diskl = btrfs_file_extent_disk_num_bytes(leaf, extent);
|
||||||
diskl = btrfs_file_extent_disk_num_bytes(leaf,
|
|
||||||
extent);
|
|
||||||
datao = btrfs_file_extent_offset(leaf, extent);
|
datao = btrfs_file_extent_offset(leaf, extent);
|
||||||
datal = btrfs_file_extent_num_bytes(leaf,
|
datal = btrfs_file_extent_num_bytes(leaf, extent);
|
||||||
extent);
|
|
||||||
} else if (type == BTRFS_FILE_EXTENT_INLINE) {
|
} else if (type == BTRFS_FILE_EXTENT_INLINE) {
|
||||||
/* take upper bound, may be compressed */
|
/* Take upper bound, may be compressed */
|
||||||
datal = btrfs_file_extent_ram_bytes(leaf,
|
datal = btrfs_file_extent_ram_bytes(leaf, extent);
|
||||||
extent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The first search might have left us at an extent
|
* The first search might have left us at an extent item that
|
||||||
* item that ends before our target range's start, can
|
* ends before our target range's start, can happen if we have
|
||||||
* happen if we have holes and NO_HOLES feature enabled.
|
* holes and NO_HOLES feature enabled.
|
||||||
*/
|
*/
|
||||||
if (key.offset + datal <= off) {
|
if (key.offset + datal <= off) {
|
||||||
path->slots[0]++;
|
path->slots[0]++;
|
||||||
@@ -3598,8 +3594,7 @@ process_slot:
|
|||||||
}
|
}
|
||||||
next_key_min_offset = key.offset + datal;
|
next_key_min_offset = key.offset + datal;
|
||||||
size = btrfs_item_size_nr(leaf, slot);
|
size = btrfs_item_size_nr(leaf, slot);
|
||||||
read_extent_buffer(leaf, buf,
|
read_extent_buffer(leaf, buf, btrfs_item_ptr_offset(leaf, slot),
|
||||||
btrfs_item_ptr_offset(leaf, slot),
|
|
||||||
size);
|
size);
|
||||||
|
|
||||||
btrfs_release_path(path);
|
btrfs_release_path(path);
|
||||||
@@ -3613,11 +3608,10 @@ process_slot:
|
|||||||
new_key.offset = destoff;
|
new_key.offset = destoff;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deal with a hole that doesn't have an extent item
|
* Deal with a hole that doesn't have an extent item that
|
||||||
* that represents it (NO_HOLES feature enabled).
|
* represents it (NO_HOLES feature enabled).
|
||||||
* This hole is either in the middle of the cloning
|
* This hole is either in the middle of the cloning range or at
|
||||||
* range or at the beginning (fully overlaps it or
|
* the beginning (fully overlaps it or partially overlaps it).
|
||||||
* partially overlaps it).
|
|
||||||
*/
|
*/
|
||||||
if (new_key.offset != last_dest_end)
|
if (new_key.offset != last_dest_end)
|
||||||
drop_start = last_dest_end;
|
drop_start = last_dest_end;
|
||||||
@@ -3633,11 +3627,11 @@ process_slot:
|
|||||||
* | ------------- extent ------------- |
|
* | ------------- extent ------------- |
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* subtract range b */
|
/* Subtract range b */
|
||||||
if (key.offset + datal > off + len)
|
if (key.offset + datal > off + len)
|
||||||
datal = off + len - key.offset;
|
datal = off + len - key.offset;
|
||||||
|
|
||||||
/* subtract range a */
|
/* Subtract range a */
|
||||||
if (off > key.offset) {
|
if (off > key.offset) {
|
||||||
datao += off - key.offset;
|
datao += off - key.offset;
|
||||||
datal -= off - key.offset;
|
datal -= off - key.offset;
|
||||||
@@ -3676,12 +3670,10 @@ process_slot:
|
|||||||
datal -= skip + trim;
|
datal -= skip + trim;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If our extent is inline, we know we will drop
|
* If our extent is inline, we know we will drop or
|
||||||
* or adjust at most 1 extent item in the
|
* adjust at most 1 extent item in the destination root.
|
||||||
* destination root.
|
|
||||||
*
|
*
|
||||||
* 1 - adjusting old extent (we may have to
|
* 1 - adjusting old extent (we may have to split it)
|
||||||
* split it)
|
|
||||||
* 1 - add new extent
|
* 1 - add new extent
|
||||||
* 1 - inode update
|
* 1 - inode update
|
||||||
*/
|
*/
|
||||||
@@ -3691,16 +3683,12 @@ process_slot:
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = clone_copy_inline_extent(inode,
|
ret = clone_copy_inline_extent(inode, trans, path,
|
||||||
trans, path,
|
&new_key, drop_start,
|
||||||
&new_key,
|
datal, skip, size, buf);
|
||||||
drop_start,
|
|
||||||
datal,
|
|
||||||
skip, size, buf);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (ret != -EOPNOTSUPP)
|
if (ret != -EOPNOTSUPP)
|
||||||
btrfs_abort_transaction(trans,
|
btrfs_abort_transaction(trans, ret);
|
||||||
ret);
|
|
||||||
btrfs_end_transaction(trans);
|
btrfs_end_transaction(trans);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -3710,15 +3698,13 @@ process_slot:
|
|||||||
|
|
||||||
last_dest_end = ALIGN(new_key.offset + datal,
|
last_dest_end = ALIGN(new_key.offset + datal,
|
||||||
fs_info->sectorsize);
|
fs_info->sectorsize);
|
||||||
ret = clone_finish_inode_update(trans, inode,
|
ret = clone_finish_inode_update(trans, inode, last_dest_end,
|
||||||
last_dest_end,
|
destoff, olen, no_time_update);
|
||||||
destoff, olen,
|
|
||||||
no_time_update);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
if (new_key.offset + datal >= destoff + len)
|
if (new_key.offset + datal >= destoff + len)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
btrfs_release_path(path);
|
btrfs_release_path(path);
|
||||||
key.offset = next_key_min_offset;
|
key.offset = next_key_min_offset;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user