Currently, writeback error in address_space flags will not be set in nfs_mapping_set_error(), return value of nfs_wb_all() is always 0 even if there is new writeback error. And error from filemap_check_wb_err() is just used to check, will not be reported to userspace. Furthermore, filemap_sample_wb_err() always return 0 if old writeback error have not been consumed. filemap_check_wb_err() will return the old error even if there is no new writeback error between filemap_sample_wb_err() and filemap_check_wb_err(). So we still need record writeback error in address_space flags. The writeback error in address_space flags is not used to be reported to userspace, it is just used to detect if there is new error while writeback. generic_perform_write() detect wb error by calling filemap_check_errors(): generic_perform_write nfs_write_end nfs_wb_all filemap_write_and_wait filemap_write_and_wait_range filemap_check_errors filemap_fdatawait_range() detect wb error by calling filemap_check_errors(): filemap_fdatawait_range __filemap_fdatawait_range filemap_check_errors As filemap_check_errors() only report -EIO or -ENOSPC, we must use the more nuanced writeback error for -EIO by returning -(file->f_mapping->wb_err & MAX_ERRNO). Fixes: 6c984083ec24 ("NFS: Use of mapping_set_error() results in spurious errors") Signed-off-by: ChenXiaoSong <chenxiaosong2@xxxxxxxxxx> --- fs/nfs/file.c | 3 +++ fs/nfs/write.c | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index b0ca244c50d0..5513ab63c108 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -683,6 +683,9 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) } nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written); out: + /* Use the more nuanced writeback error for -EIO */ + if (result == -EIO) + result = filemap_check_wb_err(file->f_mapping, 0); return result; out_swapfile: diff --git a/fs/nfs/write.c b/fs/nfs/write.c index f00d45cf80ef..eec15efb41ab 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -312,10 +312,7 @@ static void nfs_mapping_set_error(struct page *page, int error) struct address_space *mapping = page_file_mapping(page); SetPageError(page); - filemap_set_wb_err(mapping, error); - if (mapping->host) - errseq_set(&mapping->host->i_sb->s_wb_err, - error == -ENOSPC ? -ENOSPC : -EIO); + mapping_set_error(mapping, error); nfs_set_pageerror(mapping); } -- 2.31.1