Skip to contentSkip to conversation

btrfs/direct-IO: fix a bug of btrfs_dio_read

PATCH In review liubo 2 participants 3 messages May 6, 2010 Btrfs file system

lore
Share & tools
lore

liubo

author
#0 lore raw

PATCH 1/1 btrfs/direct-IO: fix a bug of btrfs_dio_read

As I mentioned in the bug-report, when the file size is not n * BUFFERSIZE, this file cannot be read correctly and the system will crash or hang up.

After investigation, I fount that data_len should be checked before lock_extent, in order to prevent the situation that when it comes to the file end, diocb->lockstart changes to lockend+1, then lock_extent
will cause system's crash or hang.

So move the data_len's check ahead.

---
 fs/btrfs/dio.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
fs/btrfs/dio.c +5 -5
index c930ff5..7178a25 100644
@@ -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;
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 4 lines · liubo

As I mentioned in the bug-report, when the file size is not n * BUFFERSIZE, this file cannot be read correctly and the system will crash or hang up.

Quoted 8 lines

After investigation, I fount that data_len should be checked before lock_extent, in order to prevent the situation that when it comes to the file end, diocb->lockstart changes to lockend+1, then lock_extent
will cause system's crash or hang.

So move the data_len's check ahead.

Please read my previous email, DIO has been refactored, this code isn't going to be used anymore. Thanks,

Josef

author
#2 lore raw
Quoted 8 lines · Josef Bacik

Please read my previous email, DIO has been refactored, this code isn't going to be used anymore. Thanks,

Josef

All right, I'll look into new DIO. :-)

Thanks,
LiuBo