btrfs/direct-IO: fix a bug of btrfs_dio_read
diff mbox

Message ID 4BE2257A.7030005@cn.fujitsu.com
State Not Applicable, archived
Headers show

Commit Message

liubo May 6, 2010, 2:12 a.m. UTC
None

Patch
diff mbox

diff --git a/fs/btrfs/dio.c b/fs/btrfs/dio.c
index c930ff5..7178a25 100644
--- a/fs/btrfs/dio.c
+++ b/fs/btrfs/dio.c
@@ -517,11 +517,6 @@  static void btrfs_dio_read(struct btrfs_diocb *diocb)
 	lockend = ALIGN(end, blocksize) - 1;
 
 getlock:
-	/* writeout everything we read for checksum or compressed extents */
-	filemap_write_and_wait_range(diocb->inode->i_mapping,
-				diocb->lockstart, lockend);
-	lock_extent(io_tree, diocb->lockstart, lockend, GFP_NOFS);
-
 	data_len = min_t(u64, end, i_size_read(diocb->inode));
 	if (data_len <= diocb->start) {
 		/* whatever we finished (or 0) is returned past EOF */
@@ -529,6 +524,11 @@  getlock:
 	}
 	data_len -= diocb->start;
 
+	/* writeout everything we read for checksum or compressed extents */
+	filemap_write_and_wait_range(diocb->inode->i_mapping,
+				diocb->lockstart, lockend);
+	lock_extent(io_tree, diocb->lockstart, lockend, GFP_NOFS);
+
 	safe_to_read = 0;
 	while (data_len && !diocb->error) { /* error in reaper stops submit */
 		struct extent_map *em;