diff mbox series

[2/2] NFS: Don't report write errors twice

Message ID 20220409200108.94208-2-trondmy@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/2] NFS: Do not report EINTR/ERESTARTSYS as mapping errors | expand

Commit Message

Trond Myklebust April 9, 2022, 8:01 p.m. UTC
From: Trond Myklebust <trond.myklebust@hammerspace.com>

Any errors reported by the write() system call need to be cleared from
the file descriptor's error tracking. The current call to nfs_wb_all()
causes the error to be reported, but since it doesn't call
file_check_and_advance_wb_err(), we can end up reporting the same error
a second time when the application calls fsync().

Reported-by: ChenXiaoSong <chenxiaosong2@huawei.com>
Fixes: ce368536dd61 ("nfs: nfs_file_write() should check for writeback errors")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/file.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

ChenXiaoSong April 11, 2022, 2:03 p.m. UTC | #1
在 2022/4/10 4:01, trondmy@kernel.org 写道:
> From: Trond Myklebust <trond.myklebust@hammerspace.com>
> 
> Any errors reported by the write() system call need to be cleared from
> the file descriptor's error tracking. The current call to nfs_wb_all()
> causes the error to be reported, but since it doesn't call
> file_check_and_advance_wb_err(), we can end up reporting the same error
> a second time when the application calls fsync().
> 
> Reported-by: ChenXiaoSong <chenxiaosong2@huawei.com>
> Fixes: ce368536dd61 ("nfs: nfs_file_write() should check for writeback errors")
> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> ---
>   fs/nfs/file.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/nfs/file.c b/fs/nfs/file.c
> index 81c80548a5c6..54dc6f176f5c 100644
> --- a/fs/nfs/file.c
> +++ b/fs/nfs/file.c
> @@ -677,9 +677,10 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
>   	/* Return error values */
>   	error = filemap_check_wb_err(file->f_mapping, since);
>   	if (nfs_need_check_write(file, inode, error)) {
> -		int err = nfs_wb_all(inode);
> -		if (err < 0)
> -			result = err;
> +		nfs_wb_all(inode);
> +		error = file_check_and_advance_wb_err(file);
> +		if (error < 0)
> +			result = error;
>   	}
>   	nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written);
>   out:
> 

After merging this patchset, second `dd` of the following reproducer 
will still report unexpected error: No space left on device.

Reproducer:
         nfs server            |       nfs client
 
-----------------------------|---------------------------------------------
  # No space left on server    |
  fallocate -l 100G /svr/nospc |
                               | mount -t nfs $nfs_server_ip:/ /mnt
                               |
                               | # Expected error: No space left on device
                               | dd if=/dev/zero of=/mnt/file count=1 
ibs=10K
                               |
                               | # Release space on mountpoint
                               | rm /mnt/nospc
                               |
                               | # Unexpected error: No space left on device
                               | dd if=/dev/zero of=/mnt/file count=1 
ibs=10K
diff mbox series

Patch

diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 81c80548a5c6..54dc6f176f5c 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -677,9 +677,10 @@  ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
 	/* Return error values */
 	error = filemap_check_wb_err(file->f_mapping, since);
 	if (nfs_need_check_write(file, inode, error)) {
-		int err = nfs_wb_all(inode);
-		if (err < 0)
-			result = err;
+		nfs_wb_all(inode);
+		error = file_check_and_advance_wb_err(file);
+		if (error < 0)
+			result = error;
 	}
 	nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written);
 out: