mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: ChenXiaoSong <chenxiaosong2@huawei.com>
To: <trond.myklebust@hammerspace.com>, <anna@kernel.org>,
	<smayhew@redhat.com>
Cc: <linux-nfs@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<chenxiaosong2@huawei.com>, <liuyongqiang13@huawei.com>,
	<yi.zhang@huawei.com>, <zhangxiaoxu5@huawei.com>
Subject: [PATCH -next,v2 1/3] NFS: return more nuanced writeback errors in nfs_file_write()
Date: Fri, 1 Apr 2022 11:44:07 +0800	[thread overview]
Message-ID: <20220401034409.256770-2-chenxiaosong2@huawei.com> (raw)
In-Reply-To: <20220401034409.256770-1-chenxiaosong2@huawei.com>

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@huawei.com>
---
 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


  reply	other threads:[~2022-04-01  3:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-01  3:44 [PATCH -next,v2 0/3] nfs: handle writeback errors correctly ChenXiaoSong
2022-04-01  3:44 ` ChenXiaoSong [this message]
2022-04-01  3:44 ` [PATCH -next,v2 2/3] NFS: nfs{,4}_file_flush() return correct writeback errors ChenXiaoSong
2022-04-01  3:44 ` [PATCH -next,v2 3/3] Revert "nfs: nfs_file_write() should check for writeback errors" ChenXiaoSong
2022-04-01  7:03 ` [PATCH -next,v2 0/3] nfs: handle writeback errors correctly chenxiaosong (A)
2022-04-11 14:15   ` chenxiaosong (A)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220401034409.256770-2-chenxiaosong2@huawei.com \
    --to=chenxiaosong2@huawei.com \
    --cc=anna@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=liuyongqiang13@huawei.com \
    --cc=smayhew@redhat.com \
    --cc=trond.myklebust@hammerspace.com \
    --cc=yi.zhang@huawei.com \
    --cc=zhangxiaoxu5@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®