[1/1] NFS: Sync the correct byte range during synchronous writes
diff mbox

Message ID 20170907132923.49969-1-tarangg@amazon.com
State New
Headers show

Commit Message

tarangg@amazon.com Sept. 7, 2017, 1:29 p.m. UTC
Since commit 18290650b1c8 ("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: 18290650b1c8 ("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>
---
 fs/nfs/file.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Trond Myklebust Sept. 7, 2017, 3:12 p.m. UTC | #1
On Thu, 2017-09-07 at 09:29 -0400, tarangg@amazon.com wrote:
> Since commit 18290650b1c8 ("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: 18290650b1c8 ("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>


Thanks! Nice catch!

Patch is applied and will be queued for stable 4.8+...

-- 
Trond Myklebust
Linux NFS client maintainer, PrimaryData
trond.myklebust@primarydata.com

Patch
diff mbox

diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index af330c31f627..a85d1cf9b4a8 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -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)) {