linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Trond Myklebust <trondmy@gmail.com>
To: Anna Schumaker <Anna.Schumaker@netapp.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 04/15] NFS: Fix up fsync() when the server rebooted
Date: Mon,  6 Jan 2020 15:25:03 -0500	[thread overview]
Message-ID: <20200106202514.785483-5-trond.myklebust@hammerspace.com> (raw)
In-Reply-To: <20200106202514.785483-4-trond.myklebust@hammerspace.com>

Don't clear the NFS_CONTEXT_RESEND_WRITES flag until after calling
nfs_commit_inode(). Otherwise, if nfs_commit_inode() returns an
error, we end up with dirty pages in the page cache, but no tag
to tell us that those pages need resending.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/file.c | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 8eb731d9be3e..95a3445c8926 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -204,44 +204,39 @@ EXPORT_SYMBOL_GPL(nfs_file_mmap);
 static int
 nfs_file_fsync_commit(struct file *file, int datasync)
 {
-	struct nfs_open_context *ctx = nfs_file_open_context(file);
 	struct inode *inode = file_inode(file);
-	int do_resend, status;
-	int ret = 0;
+	int ret;
 
 	dprintk("NFS: fsync file(%pD2) datasync %d\n", file, datasync);
 
 	nfs_inc_stats(inode, NFSIOS_VFSFSYNC);
-	do_resend = test_and_clear_bit(NFS_CONTEXT_RESEND_WRITES, &ctx->flags);
-	status = nfs_commit_inode(inode, FLUSH_SYNC);
-	if (status == 0)
-		status = file_check_and_advance_wb_err(file);
-	if (status < 0) {
-		ret = status;
-		goto out;
-	}
-	do_resend |= test_bit(NFS_CONTEXT_RESEND_WRITES, &ctx->flags);
-	if (do_resend)
-		ret = -EAGAIN;
-out:
-	return ret;
+	ret = nfs_commit_inode(inode, FLUSH_SYNC);
+	if (ret < 0)
+		return ret;
+	return file_check_and_advance_wb_err(file);
 }
 
 int
 nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
 {
-	int ret;
+	struct nfs_open_context *ctx = nfs_file_open_context(file);
 	struct inode *inode = file_inode(file);
+	int ret;
 
 	trace_nfs_fsync_enter(inode);
 
-	do {
+	for (;;) {
 		ret = file_write_and_wait_range(file, start, end);
 		if (ret != 0)
 			break;
 		ret = nfs_file_fsync_commit(file, datasync);
-		if (!ret)
-			ret = pnfs_sync_inode(inode, !!datasync);
+		if (ret != 0)
+			break;
+		ret = pnfs_sync_inode(inode, !!datasync);
+		if (ret != 0)
+			break;
+		if (!test_and_clear_bit(NFS_CONTEXT_RESEND_WRITES, &ctx->flags))
+			break;
 		/*
 		 * If nfs_file_fsync_commit detected a server reboot, then
 		 * resend all dirty pages that might have been covered by
@@ -249,7 +244,7 @@ nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
 		 */
 		start = 0;
 		end = LLONG_MAX;
-	} while (ret == -EAGAIN);
+	}
 
 	trace_nfs_fsync_exit(inode, ret);
 	return ret;
-- 
2.24.1


  reply	other threads:[~2020-01-06 20:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-06 20:24 [PATCH 00/15] Various writeback related fixes Trond Myklebust
2020-01-06 20:25 ` [PATCH 01/15] NFS: Revalidate the file size on a fatal write error Trond Myklebust
2020-01-06 20:25   ` [PATCH 02/15] NFS: Revalidate the file mapping on all fatal writeback errors Trond Myklebust
2020-01-06 20:25     ` [PATCH 03/15] SUNRPC: Remove broken gss_mech_list_pseudoflavors() Trond Myklebust
2020-01-06 20:25       ` Trond Myklebust [this message]
2020-01-06 20:25         ` [PATCH 05/15] NFS/pnfs: Fix pnfs_generic_prepare_to_resend_writes() Trond Myklebust
2020-01-06 20:25           ` [PATCH 06/15] NFSv4: Improve read/write/commit tracing Trond Myklebust
2020-01-06 20:25             ` [PATCH 07/15] NFS: Fix fix of show_nfs_errors Trond Myklebust
2020-01-06 20:25               ` [PATCH 08/15] pNFS/flexfiles: Record resend attempts on I/O failure Trond Myklebust
2020-01-06 20:25                 ` [PATCH 09/15] NFS: Clean up generic file read tracepoints Trond Myklebust
2020-01-06 20:25                   ` [PATCH 10/15] NFS: Clean up generic writeback tracepoints Trond Myklebust
2020-01-06 20:25                     ` [PATCH 11/15] NFS: Clean up generic file commit tracepoint Trond Myklebust
2020-01-06 20:25                       ` [PATCH 12/15] pNFS/flexfiles: Add tracing for layout errors Trond Myklebust
2020-01-06 20:25                         ` [PATCH 13/15] NFS: Improve tracing of permission calls Trond Myklebust
2020-01-06 20:25                           ` [PATCH 14/15] NFS: When resending after a short write, reset the reply count to zero Trond Myklebust
2020-01-06 20:25                             ` [PATCH 15/15] NFS: Fix nfs_direct_write_reschedule_io() Trond Myklebust

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=20200106202514.785483-5-trond.myklebust@hammerspace.com \
    --to=trondmy@gmail.com \
    --cc=Anna.Schumaker@netapp.com \
    --cc=linux-nfs@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).