Commit 116e0024 authored by Liu Bo's avatar Liu Bo Committed by Chris Mason

Btrfs: allow compressed extents to be merged during defragment

The rule originally comes from nocow writing, but snapshot-aware
defrag is a different case, the extent has been writen and we're
not going to change the extent but add a reference on the data.

So we're able to allow such compressed extents to be merged into
one bigger extent if they're pointing to the same data.
Reviewed-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent 8b87dc17
...@@ -2212,16 +2212,18 @@ static noinline bool record_extent_backrefs(struct btrfs_path *path, ...@@ -2212,16 +2212,18 @@ static noinline bool record_extent_backrefs(struct btrfs_path *path,
static int relink_is_mergable(struct extent_buffer *leaf, static int relink_is_mergable(struct extent_buffer *leaf,
struct btrfs_file_extent_item *fi, struct btrfs_file_extent_item *fi,
u64 disk_bytenr) struct new_sa_defrag_extent *new)
{ {
if (btrfs_file_extent_disk_bytenr(leaf, fi) != disk_bytenr) if (btrfs_file_extent_disk_bytenr(leaf, fi) != new->bytenr)
return 0; return 0;
if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_REG) if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_REG)
return 0; return 0;
if (btrfs_file_extent_compression(leaf, fi) || if (btrfs_file_extent_compression(leaf, fi) != new->compress_type)
btrfs_file_extent_encryption(leaf, fi) || return 0;
if (btrfs_file_extent_encryption(leaf, fi) ||
btrfs_file_extent_other_encoding(leaf, fi)) btrfs_file_extent_other_encoding(leaf, fi))
return 0; return 0;
...@@ -2365,8 +2367,8 @@ static noinline int relink_extent_backref(struct btrfs_path *path, ...@@ -2365,8 +2367,8 @@ static noinline int relink_extent_backref(struct btrfs_path *path,
struct btrfs_file_extent_item); struct btrfs_file_extent_item);
extent_len = btrfs_file_extent_num_bytes(leaf, fi); extent_len = btrfs_file_extent_num_bytes(leaf, fi);
if (relink_is_mergable(leaf, fi, new->bytenr) && if (extent_len + found_key.offset == start &&
extent_len + found_key.offset == start) { relink_is_mergable(leaf, fi, new)) {
btrfs_set_file_extent_num_bytes(leaf, fi, btrfs_set_file_extent_num_bytes(leaf, fi,
extent_len + len); extent_len + len);
btrfs_mark_buffer_dirty(leaf); btrfs_mark_buffer_dirty(leaf);
......
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