All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cifs: cifs_flush should wait for writeback to complete before proceeding
@ 2010-09-24 12:59 Jeff Layton
       [not found] ` <1285333153-9113-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 17+ messages in thread
From: Jeff Layton @ 2010-09-24 12:59 UTC (permalink / raw)
  To: smfrench-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA

It's possible that the kernel will call cifs_close on a filp while there
is still dirty data attached to the inode. If it's the last writeable
filp for an inode, then we may have no way to flush this data to the
server.

Thus, simply doing a filemap_fdatawrite in the .flush operation isn't
sufficient. The client needs to wait for it to complete before
returning. OTOH, there's no real need to perform a flush on a
filehandle that's read-only.

What currently saves us on this is the fact that cifs_writepages is
basically synchronous. If and when we ever switch to an async writeback
model, this will need to be fixed, so we might as well go ahead and
fix it now.

When flushing a writable filp, wait for the writeback to complete before
returning to ensure that the filehandle stays around until the writeback
is complete.

Signed-off-by: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 fs/cifs/file.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 80856f1..8084a8d 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -1737,16 +1737,13 @@ int cifs_flush(struct file *file, fl_owner_t id)
 	struct inode *inode = file->f_path.dentry->d_inode;
 	int rc = 0;
 
-	/* Rather than do the steps manually:
-	   lock the inode for writing
-	   loop through pages looking for write behind data (dirty pages)
-	   coalesce into contiguous 16K (or smaller) chunks to write to server
-	   send to server (prefer in parallel)
-	   deal with writebehind errors
-	   unlock inode for writing
-	   filemapfdatawrite appears easier for the time being */
-
-	rc = filemap_fdatawrite(inode->i_mapping);
+	/*
+	 * if the file is writable, then flush any dirty data to ensure that
+	 * the filehandle isn't closed out before writeback completes.
+	 */
+	if (file->f_mode & FMODE_WRITE)
+		rc = filemap_write_and_wait(inode->i_mapping);
+
 	/* reset wb rc if we were able to write out dirty pages */
 	if (!rc) {
 		rc = CIFS_I(inode)->write_behind_rc;
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2010-10-04 17:22 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-24 12:59 [PATCH] cifs: cifs_flush should wait for writeback to complete before proceeding Jeff Layton
     [not found] ` <1285333153-9113-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-09-24 17:58   ` Steve French
     [not found]     ` <AANLkTimdoOPyAmhWw0kTtnZan6+gudJZn=vgqTNpEL+A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-09-24 18:11       ` Jeff Layton
     [not found]         ` <20100924141137.4cb03197-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2010-09-24 18:43           ` Steve French
     [not found]             ` <AANLkTinunozFdg9S+pBrNLpcgZKoAzVg2a4QXBOBi--u-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-09-24 19:08               ` Jeff Layton
     [not found]                 ` <20100924150826.1819f930-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2010-09-24 19:24                   ` Steve French
     [not found]                     ` <AANLkTikX=cLcVK3FOFyiBeaYBQOSARHE1bnaKQcvXhX+-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-09-24 19:32                       ` Jeff Layton
     [not found]                         ` <20100924153206.48c202f4-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2010-09-24 19:36                           ` Steve French
     [not found]                             ` <AANLkTinECWNE9B56fYhp7iahp3QN8S_f0BHV9XS4SBhX-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-09-24 19:45                               ` Jeff Layton
2010-09-25  4:23           ` Christoph Hellwig
     [not found]             ` <20100925042330.GA11930-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2010-09-25  5:31               ` Steve French
2010-09-25 11:33               ` Jeff Layton
2010-09-25 12:16               ` Jeff Layton
     [not found]                 ` <20100925081644.777952fe-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2010-09-29 11:48                   ` Jeff Layton
2010-10-04 17:05                   ` Christoph Hellwig
     [not found]                     ` <20101004170534.GA25799-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2010-10-04 17:20                       ` Jeff Layton
     [not found]                         ` <20101004132057.5f76b550-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2010-10-04 17:22                           ` Jeff Layton

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.