Merge branch 'for-4.2/writeback' of git://git.kernel.dk/linux-block
[cascardo/linux.git] / fs / ocfs2 / file.c
index 913fc25..719f7f4 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/falloc.h>
 #include <linux/quotaops.h>
 #include <linux/blkdev.h>
+#include <linux/backing-dev.h>
 
 #include <cluster/masklog.h>
 
@@ -1126,7 +1127,7 @@ out:
 int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
 {
        int status = 0, size_change;
-       struct inode *inode = dentry->d_inode;
+       struct inode *inode = d_inode(dentry);
        struct super_block *sb = inode->i_sb;
        struct ocfs2_super *osb = OCFS2_SB(sb);
        struct buffer_head *bh = NULL;
@@ -1275,8 +1276,8 @@ int ocfs2_getattr(struct vfsmount *mnt,
                  struct dentry *dentry,
                  struct kstat *stat)
 {
-       struct inode *inode = dentry->d_inode;
-       struct super_block *sb = dentry->d_inode->i_sb;
+       struct inode *inode = d_inode(dentry);
+       struct super_block *sb = d_inode(dentry)->i_sb;
        struct ocfs2_super *osb = sb->s_fs_info;
        int err;
 
@@ -2114,7 +2115,7 @@ static int ocfs2_prepare_inode_for_write(struct file *file,
 {
        int ret = 0, meta_level = 0;
        struct dentry *dentry = file->f_path.dentry;
-       struct inode *inode = dentry->d_inode;
+       struct inode *inode = d_inode(dentry);
        loff_t end;
        struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
        int full_coherency = !(osb->s_mount_opt &
@@ -2250,7 +2251,7 @@ out:
 static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
                                    struct iov_iter *from)
 {
-       int direct_io, appending, rw_level, have_alloc_sem  = 0;
+       int direct_io, appending, rw_level;
        int can_do_direct, has_refcount = 0;
        ssize_t written = 0;
        ssize_t ret;
@@ -2279,16 +2280,7 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
 
        mutex_lock(&inode->i_mutex);
 
-       ocfs2_iocb_clear_sem_locked(iocb);
-
 relock:
-       /* to match setattr's i_mutex -> rw_lock ordering */
-       if (direct_io) {
-               have_alloc_sem = 1;
-               /* communicate with ocfs2_dio_end_io */
-               ocfs2_iocb_set_sem_locked(iocb);
-       }
-
        /*
         * Concurrent O_DIRECT writes are allowed with
         * mount_option "coherency=buffered".
@@ -2298,7 +2290,7 @@ relock:
        ret = ocfs2_rw_lock(inode, rw_level);
        if (ret < 0) {
                mlog_errno(ret);
-               goto out_sems;
+               goto out_mutex;
        }
 
        /*
@@ -2347,7 +2339,6 @@ relock:
        if (direct_io && !can_do_direct) {
                ocfs2_rw_unlock(inode, rw_level);
 
-               have_alloc_sem = 0;
                rw_level = -1;
 
                direct_io = 0;
@@ -2416,7 +2407,6 @@ no_sync:
         */
        if ((ret == -EIOCBQUEUED) || (!ocfs2_iocb_is_rw_locked(iocb))) {
                rw_level = -1;
-               have_alloc_sem = 0;
                unaligned_dio = 0;
        }
 
@@ -2429,10 +2419,7 @@ out:
        if (rw_level != -1)
                ocfs2_rw_unlock(inode, rw_level);
 
-out_sems:
-       if (have_alloc_sem)
-               ocfs2_iocb_clear_sem_locked(iocb);
-
+out_mutex:
        mutex_unlock(&inode->i_mutex);
 
        if (written)
@@ -2473,7 +2460,7 @@ bail:
 static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,
                                   struct iov_iter *to)
 {
-       int ret = 0, rw_level = -1, have_alloc_sem = 0, lock_level = 0;
+       int ret = 0, rw_level = -1, lock_level = 0;
        struct file *filp = iocb->ki_filp;
        struct inode *inode = file_inode(filp);
 
@@ -2490,16 +2477,11 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,
                goto bail;
        }
 
-       ocfs2_iocb_clear_sem_locked(iocb);
-
        /*
         * buffered reads protect themselves in ->readpage().  O_DIRECT reads
         * need locks to protect pending reads from racing with truncate.
         */
        if (iocb->ki_flags & IOCB_DIRECT) {
-               have_alloc_sem = 1;
-               ocfs2_iocb_set_sem_locked(iocb);
-
                ret = ocfs2_rw_lock(inode, 0);
                if (ret < 0) {
                        mlog_errno(ret);
@@ -2535,13 +2517,9 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,
        /* see ocfs2_file_write_iter */
        if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) {
                rw_level = -1;
-               have_alloc_sem = 0;
        }
 
 bail:
-       if (have_alloc_sem)
-               ocfs2_iocb_clear_sem_locked(iocb);
-
        if (rw_level != -1)
                ocfs2_rw_unlock(inode, rw_level);