Skip to content

Commit 1829065

Browse files
committed
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: Trond Myklebust <[email protected]>
1 parent 89698b2 commit 1829065

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

fs/nfs/file.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
623623
struct inode *inode = file_inode(file);
624624
unsigned long written = 0;
625625
ssize_t result;
626-
size_t count = iov_iter_count(from);
627626

628627
result = nfs_key_timeout_notify(file, inode);
629628
if (result)
@@ -633,9 +632,8 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
633632
return nfs_file_direct_write(iocb, from);
634633

635634
dprintk("NFS: write(%pD2, %zu@%Ld)\n",
636-
file, count, (long long) iocb->ki_pos);
635+
file, iov_iter_count(from), (long long) iocb->ki_pos);
637636

638-
result = -EBUSY;
639637
if (IS_SWAPFILE(inode))
640638
goto out_swapfile;
641639
/*
@@ -647,28 +645,33 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
647645
goto out;
648646
}
649647

650-
result = count;
651-
if (!count)
648+
inode_lock(inode);
649+
result = generic_write_checks(iocb, from);
650+
if (result > 0) {
651+
current->backing_dev_info = inode_to_bdi(inode);
652+
result = generic_perform_write(file, from, iocb->ki_pos);
653+
current->backing_dev_info = NULL;
654+
}
655+
inode_unlock(inode);
656+
if (result <= 0)
652657
goto out;
653658

654-
result = generic_file_write_iter(iocb, from);
655-
if (result > 0)
656-
written = result;
659+
written = generic_write_sync(iocb, result);
660+
iocb->ki_pos += written;
657661

658662
/* Return error values */
659-
if (result >= 0 && nfs_need_check_write(file, inode)) {
663+
if (nfs_need_check_write(file, inode)) {
660664
int err = vfs_fsync(file, 0);
661665
if (err < 0)
662666
result = err;
663667
}
664-
if (result > 0)
665-
nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written);
668+
nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written);
666669
out:
667670
return result;
668671

669672
out_swapfile:
670673
printk(KERN_INFO "NFS: attempt to write to active swap file!\n");
671-
goto out;
674+
return -EBUSY;
672675
}
673676
EXPORT_SYMBOL_GPL(nfs_file_write);
674677

0 commit comments

Comments
 (0)