Btrfs: Properly clear dirty and delalloc extent bits while preparing the file for write
Yan Zheng noticed that we don't clear the extent state tree dirty and delalloc
bits when we clear the dirty bits on the page during file write.
This leads to csum errors later on.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index b0352b5..1a47251 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -762,6 +762,13 @@
set_page_extent_mapped(pages[i]);
WARN_ON(!PageLocked(pages[i]));
}
+ if (start_pos < inode->i_size) {
+ u64 last_pos;
+ last_pos = (index + num_pages) << PAGE_CACHE_SHIFT;
+ clear_extent_bits(&BTRFS_I(inode)->io_tree, start_pos,
+ last_pos - 1, EXTENT_DIRTY | EXTENT_DELALLOC,
+ GFP_NOFS);
+ }
return 0;
}