Skip to content

Commit e77751a

Browse files
Miao XieChris Mason
authored andcommitted
Btrfs: fix the wrong nocow range check
The following warning message was outputed when running the 274th case of xfstests with nodatacow option: BUG: Bad page state in process kswapd0 pfn:1c66f page:ffffea0000636848 count:0 mapcount:0 mapping:(null) index:0x78000 page flags: 0x1000000000100a(error|uptodate|private_2) It is because the check of nocow range was wrong, we should compare the start and end position of the extent with the write position to verify if the write position was in the extent, but the current code just used the start postion to do the check, so we got the wrong extent and told the caller that it was a nocow write. And then when we write back the dirty pages, we found we should cow the extent, but at that time, there was no space in the fs, we had to the error flag for the page. When someone reclaimed that page, the above warning outputed. Fix it. Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Josef Bacik <jbacik@fb.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent 25e293c commit e77751a

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎fs/btrfs/inode.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6503,6 +6503,7 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
65036503
int slot;
65046504
int found_type;
65056505
bool nocow = (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW);
6506+
65066507
path = btrfs_alloc_path();
65076508
if (!path)
65086509
return -ENOMEM;
@@ -6546,6 +6547,10 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
65466547
if (!nocow && found_type == BTRFS_FILE_EXTENT_REG)
65476548
goto out;
65486549

6550+
extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi);
6551+
if (extent_end <= offset)
6552+
goto out;
6553+
65496554
disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
65506555
if (disk_bytenr == 0)
65516556
goto out;
@@ -6563,8 +6568,6 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
65636568
*ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi);
65646569
}
65656570

6566-
extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi);
6567-
65686571
if (btrfs_extent_readonly(root, disk_bytenr))
65696572
goto out;
65706573
btrfs_release_path(path);

0 commit comments

Comments
 (0)