2017-09-07 13:30:24

by tarangg

[permalink] [raw]
Subject: [PATCH 1/1] NFS: Sync the correct byte range during synchronous writes

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 <[email protected]>
Signed-off-by: Tarang Gupta <[email protected]>
Tested-by: Tarang Gupta <[email protected]>
---
fs/nfs/file.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

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)) {
--
2.11.0 (Apple Git-81)



2017-09-07 15:12:10

by Trond Myklebust

[permalink] [raw]
Subject: Re: [PATCH 1/1] NFS: Sync the correct byte range during synchronous writes

T24gVGh1LCAyMDE3LTA5LTA3IGF0IDA5OjI5IC0wNDAwLCB0YXJhbmdnQGFtYXpvbi5jb20gd3Jv
dGU6DQo+IFNpbmNlIGNvbW1pdCAxODI5MDY1MGIxYzggKCJORlM6IE1vdmUgYnVmZmVyZWQgSS9P
IGxvY2tpbmcgaW50bw0KPiBuZnNfZmlsZV93cml0ZSgpIikgbmZzX2ZpbGVfd3JpdGUoKSBoYXMg
bm90IGZsdXNoZWQgdGhlIGNvcnJlY3QgYnl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