direct-io: only inc/dec inode->i_dio_count for file systems
[cascardo/linux.git] / fs / ext4 / inode.c
index 85404f1..bccec41 100644 (file)
@@ -37,7 +37,6 @@
 #include <linux/printk.h>
 #include <linux/slab.h>
 #include <linux/ratelimit.h>
-#include <linux/aio.h>
 #include <linux/bitops.h>
 
 #include "ext4_jbd2.h"
@@ -1024,6 +1023,7 @@ static int ext4_write_end(struct file *file,
 {
        handle_t *handle = ext4_journal_current_handle();
        struct inode *inode = mapping->host;
+       loff_t old_size = inode->i_size;
        int ret = 0, ret2;
        int i_size_changed = 0;
 
@@ -1054,6 +1054,8 @@ static int ext4_write_end(struct file *file,
        unlock_page(page);
        page_cache_release(page);
 
+       if (old_size < pos)
+               pagecache_isize_extended(inode, old_size, pos);
        /*
         * Don't mark the inode dirty under page lock. First, it unnecessarily
         * makes the holding time of page lock longer. Second, it forces lock
@@ -1095,6 +1097,7 @@ static int ext4_journalled_write_end(struct file *file,
 {
        handle_t *handle = ext4_journal_current_handle();
        struct inode *inode = mapping->host;
+       loff_t old_size = inode->i_size;
        int ret = 0, ret2;
        int partial = 0;
        unsigned from, to;
@@ -1127,6 +1130,9 @@ static int ext4_journalled_write_end(struct file *file,
        unlock_page(page);
        page_cache_release(page);
 
+       if (old_size < pos)
+               pagecache_isize_extended(inode, old_size, pos);
+
        if (size_changed) {
                ret2 = ext4_mark_inode_dirty(handle, inode);
                if (!ret)
@@ -2946,8 +2952,8 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
  * if the machine crashes during the write.
  *
  */
-static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
-                             struct iov_iter *iter, loff_t offset)
+static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
+                                 loff_t offset)
 {
        struct file *file = iocb->ki_filp;
        struct inode *inode = file->f_mapping->host;
@@ -2960,8 +2966,8 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
        ext4_io_end_t *io_end = NULL;
 
        /* Use the old path for reads and writes beyond i_size. */
-       if (rw != WRITE || final_size > inode->i_size)
-               return ext4_ind_direct_IO(rw, iocb, iter, offset);
+       if (iov_iter_rw(iter) != WRITE || final_size > inode->i_size)
+               return ext4_ind_direct_IO(iocb, iter, offset);
 
        BUG_ON(iocb->private == NULL);
 
@@ -2970,8 +2976,8 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
         * conversion. This also disallows race between truncate() and
         * overwrite DIO as i_dio_count needs to be incremented under i_mutex.
         */
-       if (rw == WRITE)
-               atomic_inc(&inode->i_dio_count);
+       if (iov_iter_rw(iter) == WRITE)
+               inode_dio_begin(inode);
 
        /* If we do a overwrite dio, i_mutex locking can be released */
        overwrite = *((int *)iocb->private);
@@ -3028,10 +3034,10 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
                dio_flags = DIO_LOCKING;
        }
        if (IS_DAX(inode))
-               ret = dax_do_io(rw, iocb, inode, iter, offset, get_block_func,
+               ret = dax_do_io(iocb, inode, iter, offset, get_block_func,
                                ext4_end_io_dio, dio_flags);
        else
-               ret = __blockdev_direct_IO(rw, iocb, inode,
+               ret = __blockdev_direct_IO(iocb, inode,
                                           inode->i_sb->s_bdev, iter, offset,
                                           get_block_func,
                                           ext4_end_io_dio, NULL, dio_flags);
@@ -3072,8 +3078,8 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
        }
 
 retake_lock:
-       if (rw == WRITE)
-               inode_dio_done(inode);
+       if (iov_iter_rw(iter) == WRITE)
+               inode_dio_end(inode);
        /* take i_mutex locking again if we do a ovewrite dio */
        if (overwrite) {
                up_read(&EXT4_I(inode)->i_data_sem);
@@ -3083,8 +3089,8 @@ retake_lock:
        return ret;
 }
 
-static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb,
-                             struct iov_iter *iter, loff_t offset)
+static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
+                             loff_t offset)
 {
        struct file *file = iocb->ki_filp;
        struct inode *inode = file->f_mapping->host;
@@ -3101,12 +3107,12 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb,
        if (ext4_has_inline_data(inode))
                return 0;
 
-       trace_ext4_direct_IO_enter(inode, offset, count, rw);
+       trace_ext4_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));
        if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
-               ret = ext4_ext_direct_IO(rw, iocb, iter, offset);
+               ret = ext4_ext_direct_IO(iocb, iter, offset);
        else
-               ret = ext4_ind_direct_IO(rw, iocb, iter, offset);
-       trace_ext4_direct_IO_exit(inode, offset, count, rw, ret);
+               ret = ext4_ind_direct_IO(iocb, iter, offset);
+       trace_ext4_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), ret);
        return ret;
 }
 
@@ -4518,7 +4524,7 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)
  */
 int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 {
-       struct inode *inode = dentry->d_inode;
+       struct inode *inode = d_inode(dentry);
        int error, rc = 0;
        int orphan = 0;
        const unsigned int ia_valid = attr->ia_valid;
@@ -4666,7 +4672,7 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
        struct inode *inode;
        unsigned long long delalloc_blocks;
 
-       inode = dentry->d_inode;
+       inode = d_inode(dentry);
        generic_fillattr(inode, stat);
 
        /*