Skip to content

Commit

Permalink
Btrfs: fix stop searching test in replace_one_extent
Browse files Browse the repository at this point in the history
replace_one_extent searches tree leaves for references to a given extent. It
stops searching if it goes beyond the last possible position.

The last possible position is computed by adding the starting offset of a found
file extent to the full size of the extent. The code uses physical size of the
extent as the full size. This is incorrect when compression is used.

The fix is get the full size from ram_bytes field of file extent item.

Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
  • Loading branch information
Yan Zheng authored and Chris Mason committed Jan 21, 2009
1 parent 95029d7 commit 86288a1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -4440,15 +4440,14 @@ static noinline int replace_one_extent(struct btrfs_trans_handle *trans,
u64 lock_end = 0;
u64 num_bytes;
u64 ext_offset;
u64 first_pos;
u64 search_end = (u64)-1;
u32 nritems;
int nr_scaned = 0;
int extent_locked = 0;
int extent_type;
int ret;

memcpy(&key, leaf_key, sizeof(key));
first_pos = INT_LIMIT(loff_t) - extent_key->offset;
if (ref_path->owner_objectid != BTRFS_MULTIPLE_OBJECTIDS) {
if (key.objectid < ref_path->owner_objectid ||
(key.objectid == ref_path->owner_objectid &&
Expand Down Expand Up @@ -4497,7 +4496,7 @@ static noinline int replace_one_extent(struct btrfs_trans_handle *trans,
if ((key.objectid > ref_path->owner_objectid) ||
(key.objectid == ref_path->owner_objectid &&
key.type > BTRFS_EXTENT_DATA_KEY) ||
(key.offset >= first_pos + extent_key->offset))
key.offset >= search_end)
break;
}

Expand Down Expand Up @@ -4530,8 +4529,10 @@ static noinline int replace_one_extent(struct btrfs_trans_handle *trans,
num_bytes = btrfs_file_extent_num_bytes(leaf, fi);
ext_offset = btrfs_file_extent_offset(leaf, fi);

if (first_pos > key.offset - ext_offset)
first_pos = key.offset - ext_offset;
if (search_end == (u64)-1) {
search_end = key.offset - ext_offset +
btrfs_file_extent_ram_bytes(leaf, fi);
}

if (!extent_locked) {
lock_start = key.offset;
Expand Down Expand Up @@ -4720,7 +4721,7 @@ static noinline int replace_one_extent(struct btrfs_trans_handle *trans,
}
skip:
if (ref_path->owner_objectid != BTRFS_MULTIPLE_OBJECTIDS &&
key.offset >= first_pos + extent_key->offset)
key.offset >= search_end)
break;

cond_resched();
Expand Down

0 comments on commit 86288a1

Please sign in to comment.