ocfs2: fix several issues of append dio
authorJoseph Qi <joseph.qi@huawei.com>
Fri, 4 Sep 2015 22:43:40 +0000 (15:43 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 4 Sep 2015 23:54:41 +0000 (16:54 -0700)
1) Take rw EX lock in case of append dio.
2) Explicitly treat the error code -EIOCBQUEUED as normal.
3) Set di_bh to NULL after brelse if it may be used again later.

Signed-off-by: Joseph Qi <joseph.qi@huawei.com>
Cc: Yiwen Jiang <jiangyiwen@huawei.com>
Cc: Weiwei Wang <wangww631@huawei.com>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ocfs2/aops.c
fs/ocfs2/file.c

index 1e88ff4837020d4cdf43a87f94b4f97b827182f7..b36dcad3a14058320b9112f13d3bbe3b93882405 100644 (file)
@@ -860,7 +860,8 @@ static ssize_t ocfs2_direct_IO_write(struct kiocb *iocb,
        written = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter,
                                       offset, ocfs2_direct_IO_get_blocks,
                                       ocfs2_dio_end_io, NULL, 0);
-       if (unlikely(written < 0)) {
+       /* overwrite aio may return -EIOCBQUEUED, and it is not an error */
+       if ((written < 0) && (written != -EIOCBQUEUED)) {
                loff_t i_size = i_size_read(inode);
 
                if (offset + count > i_size) {
@@ -879,12 +880,14 @@ static ssize_t ocfs2_direct_IO_write(struct kiocb *iocb,
 
                                        ocfs2_inode_unlock(inode, 1);
                                        brelse(di_bh);
+                                       di_bh = NULL;
                                        goto clean_orphan;
                                }
                        }
 
                        ocfs2_inode_unlock(inode, 1);
                        brelse(di_bh);
+                       di_bh = NULL;
 
                        ret = jbd2_journal_force_commit(journal);
                        if (ret < 0)
@@ -939,10 +942,12 @@ clean_orphan:
                if (tmp_ret < 0) {
                        ret = tmp_ret;
                        mlog_errno(ret);
+                       brelse(di_bh);
                        goto out;
                }
 
                ocfs2_inode_unlock(inode, 1);
+               brelse(di_bh);
 
                tmp_ret = jbd2_journal_force_commit(journal);
                if (tmp_ret < 0) {
index 5d384a6cd696e938a051aab9de76ead2568ea255..38fc339228327bc6ede74a3a283f961165aeb2f7 100644 (file)
@@ -2271,6 +2271,8 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
                               OCFS2_MOUNT_COHERENCY_BUFFERED);
        int unaligned_dio = 0;
        int dropped_dio = 0;
+       int append_write = ((iocb->ki_pos + count) >=
+                       i_size_read(inode) ? 1 : 0);
 
        trace_ocfs2_file_aio_write(inode, file, file->f_path.dentry,
                (unsigned long long)OCFS2_I(inode)->ip_blkno,
@@ -2290,8 +2292,9 @@ relock:
        /*
         * Concurrent O_DIRECT writes are allowed with
         * mount_option "coherency=buffered".
+        * For append write, we must take rw EX.
         */
-       rw_level = (!direct_io || full_coherency);
+       rw_level = (!direct_io || full_coherency || append_write);
 
        ret = ocfs2_rw_lock(inode, rw_level);
        if (ret < 0) {