Skip to content

Commit 4577b01

Browse files
Josef BacikChris Mason
authored andcommitted
Btrfs: relocate csums properly with prealloc extents
A user reported a problem where they were getting csum errors when running a balance and running systemd's journal. This is because systemd is awesome and fallocate()'s its log space and writes into it. Unfortunately we assume that when we read in all the csums for an extent that they are sequential starting at the bytenr we care about. This obviously isn't the case for prealloc extents, where we could have written to the middle of the prealloc extent only, which means the csum would be for the bytenr in the middle of our range and not the front of our range. Fix this by offsetting the new bytenr we are logging to based on the original bytenr the csum was for. With this patch I no longer see the csum errors I was seeing. Thanks, Cc: stable@vger.kernel.org Reported-by: Chris Murphy <lists@colorremedies.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
1 parent e84cc14 commit 4577b01

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎fs/btrfs/relocation.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4472,6 +4472,7 @@ int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len)
44724472
struct btrfs_root *root = BTRFS_I(inode)->root;
44734473
int ret;
44744474
u64 disk_bytenr;
4475+
u64 new_bytenr;
44754476
LIST_HEAD(list);
44764477

44774478
ordered = btrfs_lookup_ordered_extent(inode, file_pos);
@@ -4483,13 +4484,24 @@ int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len)
44834484
if (ret)
44844485
goto out;
44854486

4486-
disk_bytenr = ordered->start;
44874487
while (!list_empty(&list)) {
44884488
sums = list_entry(list.next, struct btrfs_ordered_sum, list);
44894489
list_del_init(&sums->list);
44904490

4491-
sums->bytenr = disk_bytenr;
4492-
disk_bytenr += sums->len;
4491+
/*
4492+
* We need to offset the new_bytenr based on where the csum is.
4493+
* We need to do this because we will read in entire prealloc
4494+
* extents but we may have written to say the middle of the
4495+
* prealloc extent, so we need to make sure the csum goes with
4496+
* the right disk offset.
4497+
*
4498+
* We can do this because the data reloc inode refers strictly
4499+
* to the on disk bytes, so we don't have to worry about
4500+
* disk_len vs real len like with real inodes since it's all
4501+
* disk length.
4502+
*/
4503+
new_bytenr = ordered->start + (sums->bytenr - disk_bytenr);
4504+
sums->bytenr = new_bytenr;
44934505

44944506
btrfs_add_ordered_sum(inode, ordered, sums);
44954507
}

0 commit comments

Comments
 (0)