]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Btrfs: use i_size_read() in btrfs_defrag_file()
authorLi Zefan <lizf@cn.fujitsu.com>
Fri, 2 Sep 2011 07:56:39 +0000 (15:56 +0800)
committerChris Mason <chris.mason@oracle.com>
Wed, 16 Nov 2011 02:20:38 +0000 (21:20 -0500)
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>
(cherry picked from commit 151a31b25e5c941bdd9fdefed650effca223c716)

fs/btrfs/ioctl.c

index 9c21833ea2aeeb6cc6faa46134040a6bb9625de4..817487162f1b7b77d7507b4e8d1c1b2c1fd87256 100644 (file)
@@ -987,6 +987,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
        struct btrfs_super_block *disk_super;
        struct file_ra_state *ra = NULL;
        unsigned long last_index;
+       u64 isize = i_size_read(inode);
        u64 features;
        u64 last_len = 0;
        u64 skip = 0;
@@ -1012,7 +1013,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
                        compress_type = range->compress_type;
        }
 
-       if (inode->i_size == 0)
+       if (isize == 0)
                return 0;
 
        /*
@@ -1037,10 +1038,10 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 
        /* find the last page to defrag */
        if (range->start + range->len > range->start) {
-               last_index = min_t(u64, inode->i_size - 1,
+               last_index = min_t(u64, isize - 1,
                         range->start + range->len - 1) >> PAGE_CACHE_SHIFT;
        } else {
-               last_index = (inode->i_size - 1) >> PAGE_CACHE_SHIFT;
+               last_index = (isize - 1) >> PAGE_CACHE_SHIFT;
        }
 
        if (newer_than) {