Commit 18290650 authored by Trond Myklebust's avatar Trond Myklebust

NFS: Move buffered I/O locking into nfs_file_write()

Preparation for the patch that de-serialises O_DIRECT reads and
writes.
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
parent 89698b24
...@@ -623,7 +623,6 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) ...@@ -623,7 +623,6 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
unsigned long written = 0; unsigned long written = 0;
ssize_t result; ssize_t result;
size_t count = iov_iter_count(from);
result = nfs_key_timeout_notify(file, inode); result = nfs_key_timeout_notify(file, inode);
if (result) if (result)
...@@ -633,9 +632,8 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) ...@@ -633,9 +632,8 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
return nfs_file_direct_write(iocb, from); return nfs_file_direct_write(iocb, from);
dprintk("NFS: write(%pD2, %zu@%Ld)\n", dprintk("NFS: write(%pD2, %zu@%Ld)\n",
file, count, (long long) iocb->ki_pos); file, iov_iter_count(from), (long long) iocb->ki_pos);
result = -EBUSY;
if (IS_SWAPFILE(inode)) if (IS_SWAPFILE(inode))
goto out_swapfile; goto out_swapfile;
/* /*
...@@ -647,28 +645,33 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) ...@@ -647,28 +645,33 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
goto out; goto out;
} }
result = count; inode_lock(inode);
if (!count) result = generic_write_checks(iocb, from);
if (result > 0) {
current->backing_dev_info = inode_to_bdi(inode);
result = generic_perform_write(file, from, iocb->ki_pos);
current->backing_dev_info = NULL;
}
inode_unlock(inode);
if (result <= 0)
goto out; goto out;
result = generic_file_write_iter(iocb, from); written = generic_write_sync(iocb, result);
if (result > 0) iocb->ki_pos += written;
written = result;
/* Return error values */ /* Return error values */
if (result >= 0 && nfs_need_check_write(file, inode)) { if (nfs_need_check_write(file, inode)) {
int err = vfs_fsync(file, 0); int err = vfs_fsync(file, 0);
if (err < 0) if (err < 0)
result = err; result = err;
} }
if (result > 0)
nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written); nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written);
out: out:
return result; return result;
out_swapfile: out_swapfile:
printk(KERN_INFO "NFS: attempt to write to active swap file!\n"); printk(KERN_INFO "NFS: attempt to write to active swap file!\n");
goto out; return -EBUSY;
} }
EXPORT_SYMBOL_GPL(nfs_file_write); EXPORT_SYMBOL_GPL(nfs_file_write);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment