All of lore.kernel.org
 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 2/3] NFS: nfs{,4}_file_flush() return correct writeback errors
Date: Fri, 1 Apr 2022 11:44:08 +0800	[thread overview]
Message-ID: <20220401034409.256770-3-chenxiaosong2@huawei.com> (raw)
In-Reply-To: <20220401034409.256770-1-chenxiaosong2@huawei.com>

filemap_sample_wb_err() will return 0 if old wb error have not been consumed,
then filemap_check_wb_err() will return the unchanged old wb error.

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

Fix this by detecting writeback error from return value of nfs_wb_all(),
and return the more nuanced error -(file->f_mapping->wb_err & MAX_ERRNO) if
there is new wb error while nfs_wb_all().

Fixes: 67dd23f9e6fb ("nfs: ensure correct writeback errors are returned on close()")
Signed-off-by: ChenXiaoSong <chenxiaosong2@huawei.com>
---
 fs/nfs/file.c     | 8 ++++----
 fs/nfs/nfs4file.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 5513ab63c108..353f1f832519 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -136,7 +136,7 @@ static int
 nfs_file_flush(struct file *file, fl_owner_t id)
 {
 	struct inode	*inode = file_inode(file);
-	errseq_t since;
+	errseq_t error = 0;
 
 	dprintk("NFS: flush(%pD2)\n", file);
 
@@ -145,9 +145,9 @@ nfs_file_flush(struct file *file, fl_owner_t id)
 		return 0;
 
 	/* 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);
+	if (nfs_wb_all(inode))
+		error = filemap_check_wb_err(file->f_mapping, 0);
+	return error;
 }
 
 ssize_t
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index d258933cf8c8..cbbe66b54417 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -111,7 +111,7 @@ static int
 nfs4_file_flush(struct file *file, fl_owner_t id)
 {
 	struct inode	*inode = file_inode(file);
-	errseq_t since;
+	errseq_t error = 0;
 
 	dprintk("NFS: flush(%pD2)\n", file);
 
@@ -127,9 +127,9 @@ nfs4_file_flush(struct file *file, fl_owner_t id)
 		return filemap_fdatawrite(file->f_mapping);
 
 	/* 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);
+	if (nfs_wb_all(inode))
+		error = filemap_check_wb_err(file->f_mapping, 0);
+	return error;
 }
 
 #ifdef CONFIG_NFS_V4_2
-- 
2.31.1


  parent 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 ` [PATCH -next,v2 1/3] NFS: return more nuanced writeback errors in nfs_file_write() ChenXiaoSong
2022-04-01  3:44 ` ChenXiaoSong [this message]
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-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.