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>
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] NFS: report and clear ENOSPC/EFBIG/EDQUOT writeback error on close() file
Date: Tue, 14 Jun 2022 23:28:17 +0800	[thread overview]
Message-ID: <20220614152817.271507-1-chenxiaosong2@huawei.com> (raw)

Currently, we report and clear ENOSPC/EFBIG/EDQUOT writeback error on write(),
write() file will report unexpected error if previous writeback error have not
been cleared.

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
                              |
                              | # Just write 512B and report unexpected error
                              | dd if=/dev/zero of=/mnt/file count=1 ibs=10K

Fix this by clearing ENOSPC/EFBIG/EDQUOT writeback error on close file,
it will not clear other errors that are not supposed to be reported by close().

Signed-off-by: ChenXiaoSong <chenxiaosong2@huawei.com>
---
 fs/nfs/file.c     | 16 ++++++++--------
 fs/nfs/internal.h | 10 ++++++++++
 fs/nfs/nfs4file.c |  9 +++++++--
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 2d72b1b7ed74..275d1fdc7f9a 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -138,7 +138,7 @@ static int
 nfs_file_flush(struct file *file, fl_owner_t id)
 {
 	struct inode	*inode = file_inode(file);
-	errseq_t since;
+	errseq_t since, error;
 
 	dprintk("NFS: flush(%pD2)\n", file);
 
@@ -149,7 +149,12 @@ nfs_file_flush(struct file *file, fl_owner_t id)
 	/* Flush writes to the server and return any errors */
 	since = filemap_sample_wb_err(file->f_mapping);
 	nfs_wb_all(inode);
-	return filemap_check_wb_err(file->f_mapping, since);
+	error = filemap_check_wb_err(file->f_mapping, since);
+
+	if (nfs_should_clear_wb_err(error))
+		file_check_and_advance_wb_err(file);
+
+	return error;
 }
 
 ssize_t
@@ -673,12 +678,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
 out:
 	/* Return error values */
 	error = filemap_check_wb_err(file->f_mapping, since);
-	switch (error) {
-	default:
-		break;
-	case -EDQUOT:
-	case -EFBIG:
-	case -ENOSPC:
+	if (nfs_should_clear_wb_err(error)) {
 		nfs_wb_all(inode);
 		error = file_check_and_advance_wb_err(file);
 		if (error < 0)
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 8f8cd6e2d4db..e49aad8f7d09 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -859,3 +859,13 @@ static inline void nfs_set_port(struct sockaddr *sap, int *port,
 
 	rpc_set_port(sap, *port);
 }
+
+static inline bool nfs_should_clear_wb_err(int error) {
+	switch (error) {
+	case -EDQUOT:
+	case -EFBIG:
+	case -ENOSPC:
+		return true;
+	}
+	return false;
+}
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index 03d3a270eff4..ddf3f0abd55a 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -113,7 +113,7 @@ static int
 nfs4_file_flush(struct file *file, fl_owner_t id)
 {
 	struct inode	*inode = file_inode(file);
-	errseq_t since;
+	errseq_t since, error;
 
 	dprintk("NFS: flush(%pD2)\n", file);
 
@@ -131,7 +131,12 @@ nfs4_file_flush(struct file *file, fl_owner_t id)
 	/* Flush writes to the server and return any errors */
 	since = filemap_sample_wb_err(file->f_mapping);
 	nfs_wb_all(inode);
-	return filemap_check_wb_err(file->f_mapping, since);
+	error = filemap_check_wb_err(file->f_mapping, since);
+
+	if (nfs_should_clear_wb_err(error))
+		file_check_and_advance_wb_err(file);
+
+	return error;
 }
 
 #ifdef CONFIG_NFS_V4_2
-- 
2.31.1


             reply	other threads:[~2022-06-14 15:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14 15:28 ChenXiaoSong [this message]
2022-06-14 19:48 ` Trond Myklebust
2022-06-15  1:34   ` chenxiaosong (A)
2022-06-15 11:55     ` Trond Myklebust
2022-06-15  0:33 ` kernel test robot
2022-06-15  1:14 ` kernel test robot

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=20220614152817.271507-1-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=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®