Skip to content

Commit

Permalink
NFS: Sync the correct byte range during synchronous writes
Browse files Browse the repository at this point in the history
Since commit 1829065 ("NFS: Move buffered I/O locking into
nfs_file_write()") nfs_file_write() has not flushed the correct byte
range during synchronous writes.  generic_write_sync() expects that
iocb->ki_pos points to the right edge of the range rather than the
left edge.

To replicate the problem, open a file with O_DSYNC, have the client
write at increasing offsets, and then print the successful offsets.
Block port 2049 partway through that sequence, and observe that the
client application indicates successful writes in advance of what the
server received.

Fixes: 1829065 ("NFS: Move buffered I/O locking into nfs_file_write()")
Signed-off-by: Jacob Strauss <jsstraus@amazon.com>
Signed-off-by: Tarang Gupta <tarangg@amazon.com>
Tested-by: Tarang Gupta <tarangg@amazon.com>
Cc: stable@vger.kernel.org # v4.8+
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
  • Loading branch information
tarangg@amazon.com authored and trondmypd committed Sep 7, 2017
1 parent 58a6989 commit e973b1a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/nfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,11 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
if (result <= 0)
goto out;

result = generic_write_sync(iocb, result);
if (result < 0)
goto out;
written = result;
iocb->ki_pos += written;
result = generic_write_sync(iocb, written);
if (result < 0)
goto out;

/* Return error values */
if (nfs_need_check_write(file, inode)) {
Expand Down

0 comments on commit e973b1a

Please sign in to comment.