File 0028-btrfs-progs-convert-Fix-a-bug-which-fails-to-insert-.patch of Package btrfsprogs.11414
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
Date: Thu, 2 Jun 2016 15:22:49 +0800
Subject: btrfs-progs: convert: Fix a bug which fails to insert hole file extent
Git-commit: 9aae31f1248f68c2f6e19b8616f043e539723b9f
Patch-mainline: v4.6
References: bsc#1042369
When copying inode, if there is a file referring part of a hole range,
convert will fail.
The problem is, when calculating real extent bytenr, it doesn't check if
the original extent is a hole.
In case the orinal extent is a hole, we still calculate bytenr using
file_pos - found_extent_file_pos, causing non-zero value, and later
btrfs_record_file_extent() detects that we are pointing to non-exist
extent and aborts convert.
Fix it by checking the disk_bytenr before calculating real disk bytenr.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
---
btrfs-convert.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/btrfs-convert.c b/btrfs-convert.c
index 20b001c..36690e6 100644
--- a/btrfs-convert.c
+++ b/btrfs-convert.c
@@ -572,7 +572,11 @@ static int record_file_blocks(struct blk_iterate_data *data,
BUG_ON(cur_off - key.offset >= extent_num_bytes);
btrfs_release_path(path);
- real_disk_bytenr = cur_off - key.offset + extent_disk_bytenr;
+ if (extent_disk_bytenr)
+ real_disk_bytenr = cur_off - key.offset +
+ extent_disk_bytenr;
+ else
+ real_disk_bytenr = 0;
cur_len = min(key.offset + extent_num_bytes,
old_disk_bytenr + num_bytes) - cur_off;
ret = btrfs_record_file_extent(data->trans, data->root,
--
2.12.3