NFSv4.1/pnfs: Ensure that writes respect the O_SYNC flag when doing O_DIRECT
authorTrond Myklebust <trond.myklebust@primarydata.com>
Wed, 25 Mar 2015 22:58:53 +0000 (18:58 -0400)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Fri, 27 Mar 2015 16:39:37 +0000 (12:39 -0400)
If the caller does not specify the O_SYNC flag, then it is legitimate
to return from O_DIRECT without doing a pNFS layoutcommit operation.
However if the file is opened O_DIRECT|O_SYNC then we'd better get it
right.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
fs/nfs/direct.c
fs/nfs/file.c
fs/nfs/nfs4file.c

index 51f617e45fd1ba59119a3569c37dee3ac42ac4e2..018a06a062bd234f61a701c07beabbbfc13619e6 100644 (file)
@@ -1034,6 +1034,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter,
                        if (i_size_read(inode) < iocb->ki_pos)
                                i_size_write(inode, iocb->ki_pos);
                        spin_unlock(&inode->i_lock);
+                       generic_write_sync(file, pos, result);
                }
        }
        nfs_direct_req_release(dreq);
index 6959cb76744b78efd851aec8d6b8bf05ba1d2f01..28228f381266174562a4d93c37fe9cbbbee82ba2 100644 (file)
@@ -281,6 +281,7 @@ nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
 
        trace_nfs_fsync_enter(inode);
 
+       nfs_inode_dio_wait(inode);
        do {
                ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
                if (ret != 0)
index 8da5409e6f1a63db92713e1edd9a3ac3d196140b..befe7a2c62843f31512fa4b98130d6f7a93d0c49 100644 (file)
@@ -104,6 +104,7 @@ nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
 
        trace_nfs_fsync_enter(inode);
 
+       nfs_inode_dio_wait(inode);
        do {
                ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
                if (ret != 0)