From db6f9251e509107755c7014e7358469409a0d5fe Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 1 Jun 2016 16:29:43 +0800 Subject: [PATCH] btrfs-progs: convert: Insert needed holes for superblock migration New convert doesn't insert holes for superblock migration range. Unlike the old design, which only relocates 4K (superblock size) to other places. In the new design, to make sure convert can handle different page sizes and align chunks bytenr, we relocate the whole 64K range. And if there is only a 4K used block inside 64K superblock migration range, it will make converted the fs have discontiguous file extents. This patch will fix it by inserting needed holes to avoid such discontinuous error. Reported-by: Tsutomu Itoh Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- btrfs-convert.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/btrfs-convert.c b/btrfs-convert.c index 7cac304b..beec5d7d 100644 --- a/btrfs-convert.c +++ b/btrfs-convert.c @@ -1384,6 +1384,8 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans, { u64 cur_off = start; u64 cur_len = len; + u64 hole_start = start; + u64 hole_len; struct cache_extent *cache; struct btrfs_key key; struct extent_buffer *eb; @@ -1435,9 +1437,23 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans, ret = csum_disk_extent(trans, root, key.objectid, key.offset); + /* Don't forget to insert hole */ + hole_len = cur_off - hole_start; + if (hole_len) { + ret = btrfs_record_file_extent(trans, root, ino, inode, + hole_start, 0, hole_len); + if (ret < 0) + break; + } + cur_off += key.offset; + hole_start = cur_off; cur_len = start + len - cur_off; } + /* Last hole */ + if (start + len - hole_start > 0) + ret = btrfs_record_file_extent(trans, root, ino, inode, + hole_start, 0, start + len - hole_start); return ret; }