aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLi Zefan <lizf@cn.fujitsu.com>2011-09-02 03:56:39 -0400
committerDavid Sterba <dsterba@suse.cz>2011-10-20 12:10:35 -0400
commit151a31b25e5c941bdd9fdefed650effca223c716 (patch)
tree60c0888c247601fad2b550885c5b430f1fbf02e0
parentcbcc83265d929ac71553c1b5dafdb830171af947 (diff)
Btrfs: use i_size_read() in btrfs_defrag_file()
Don't use inode->i_size directly, since we're not holding i_mutex. This also fixes another bug, that i_size can change after it's checked against 0 and then (i_size - 1) can be negative. Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
-rw-r--r--fs/btrfs/ioctl.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index b39f7bf92704..323d77f09258 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -978,6 +978,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
978 struct btrfs_super_block *disk_super; 978 struct btrfs_super_block *disk_super;
979 struct file_ra_state *ra = NULL; 979 struct file_ra_state *ra = NULL;
980 unsigned long last_index; 980 unsigned long last_index;
981 u64 isize = i_size_read(inode);
981 u64 features; 982 u64 features;
982 u64 last_len = 0; 983 u64 last_len = 0;
983 u64 skip = 0; 984 u64 skip = 0;
@@ -1003,7 +1004,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
1003 compress_type = range->compress_type; 1004 compress_type = range->compress_type;
1004 } 1005 }
1005 1006
1006 if (inode->i_size == 0) 1007 if (isize == 0)
1007 return 0; 1008 return 0;
1008 1009
1009 /* 1010 /*
@@ -1028,10 +1029,10 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
1028 1029
1029 /* find the last page to defrag */ 1030 /* find the last page to defrag */
1030 if (range->start + range->len > range->start) { 1031 if (range->start + range->len > range->start) {
1031 last_index = min_t(u64, inode->i_size - 1, 1032 last_index = min_t(u64, isize - 1,
1032 range->start + range->len - 1) >> PAGE_CACHE_SHIFT; 1033 range->start + range->len - 1) >> PAGE_CACHE_SHIFT;
1033 } else { 1034 } else {
1034 last_index = (inode->i_size - 1) >> PAGE_CACHE_SHIFT; 1035 last_index = (isize - 1) >> PAGE_CACHE_SHIFT;
1035 } 1036 }
1036 1037
1037 if (newer_than) { 1038 if (newer_than) {