[PATCH AUTOSEL for 4.9 058/156] afs: Flush outstanding writes when an fd is closed

From: alexander . levin
Date: Thu Dec 07 2017 - 12:32:11 EST


From: David Howells <dhowells@xxxxxxxxxx>

[ Upstream commit 58fed94dfb17e89556b5705f20f90e5b2971b6a1 ]

Flush outstanding writes in afs when an fd is closed. This is what NFS and
CIFS do.

Reported-by: Marc Dionne <marc.c.dionne@xxxxxxxxx>
Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
Signed-off-by: Sasha Levin <alexander.levin@xxxxxxxxxxx>
---
fs/afs/file.c | 1 +
fs/afs/internal.h | 1 +
fs/afs/write.c | 14 ++++++++++++++
3 files changed, 16 insertions(+)

diff --git a/fs/afs/file.c b/fs/afs/file.c
index 6344aee4ac4b..72372970725b 100644
--- a/fs/afs/file.c
+++ b/fs/afs/file.c
@@ -29,6 +29,7 @@ static int afs_readpages(struct file *filp, struct address_space *mapping,

const struct file_operations afs_file_operations = {
.open = afs_open,
+ .flush = afs_flush,
.release = afs_release,
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 6961f6175529..67c63aa86b25 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -752,6 +752,7 @@ extern int afs_writepages(struct address_space *, struct writeback_control *);
extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
extern int afs_writeback_all(struct afs_vnode *);
+extern int afs_flush(struct file *, fl_owner_t);
extern int afs_fsync(struct file *, loff_t, loff_t, int);


diff --git a/fs/afs/write.c b/fs/afs/write.c
index 26d809aee78b..4ab108e6a3cd 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -736,6 +736,20 @@ out:
}

/*
+ * Flush out all outstanding writes on a file opened for writing when it is
+ * closed.
+ */
+int afs_flush(struct file *file, fl_owner_t id)
+{
+ _enter("");
+
+ if ((file->f_mode & FMODE_WRITE) == 0)
+ return 0;
+
+ return vfs_fsync(file, 0);
+}
+
+/*
* notification that a previously read-only page is about to become writable
* - if it returns an error, the caller will deliver a bus error signal
*/
--
2.11.0