Skip to content

Commit 2197e9b

Browse files
trondmyamschuma-ntap
authored andcommitted
NFS: Fix up fsync() when the server rebooted
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 <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent b32d285 commit 2197e9b

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

fs/nfs/file.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -204,52 +204,47 @@ EXPORT_SYMBOL_GPL(nfs_file_mmap);
204204
static int
205205
nfs_file_fsync_commit(struct file *file, int datasync)
206206
{
207-
struct nfs_open_context *ctx = nfs_file_open_context(file);
208207
struct inode *inode = file_inode(file);
209-
int do_resend, status;
210-
int ret = 0;
208+
int ret;
211209

212210
dprintk("NFS: fsync file(%pD2) datasync %d\n", file, datasync);
213211

214212
nfs_inc_stats(inode, NFSIOS_VFSFSYNC);
215-
do_resend = test_and_clear_bit(NFS_CONTEXT_RESEND_WRITES, &ctx->flags);
216-
status = nfs_commit_inode(inode, FLUSH_SYNC);
217-
if (status == 0)
218-
status = file_check_and_advance_wb_err(file);
219-
if (status < 0) {
220-
ret = status;
221-
goto out;
222-
}
223-
do_resend |= test_bit(NFS_CONTEXT_RESEND_WRITES, &ctx->flags);
224-
if (do_resend)
225-
ret = -EAGAIN;
226-
out:
227-
return ret;
213+
ret = nfs_commit_inode(inode, FLUSH_SYNC);
214+
if (ret < 0)
215+
return ret;
216+
return file_check_and_advance_wb_err(file);
228217
}
229218

230219
int
231220
nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
232221
{
233-
int ret;
222+
struct nfs_open_context *ctx = nfs_file_open_context(file);
234223
struct inode *inode = file_inode(file);
224+
int ret;
235225

236226
trace_nfs_fsync_enter(inode);
237227

238-
do {
228+
for (;;) {
239229
ret = file_write_and_wait_range(file, start, end);
240230
if (ret != 0)
241231
break;
242232
ret = nfs_file_fsync_commit(file, datasync);
243-
if (!ret)
244-
ret = pnfs_sync_inode(inode, !!datasync);
233+
if (ret != 0)
234+
break;
235+
ret = pnfs_sync_inode(inode, !!datasync);
236+
if (ret != 0)
237+
break;
238+
if (!test_and_clear_bit(NFS_CONTEXT_RESEND_WRITES, &ctx->flags))
239+
break;
245240
/*
246241
* If nfs_file_fsync_commit detected a server reboot, then
247242
* resend all dirty pages that might have been covered by
248243
* the NFS_CONTEXT_RESEND_WRITES flag
249244
*/
250245
start = 0;
251246
end = LLONG_MAX;
252-
} while (ret == -EAGAIN);
247+
}
253248

254249
trace_nfs_fsync_exit(inode, ret);
255250
return ret;

0 commit comments

Comments
 (0)