fuse: use common sync release infrastructure for fuseblk

Make fuseblk use the "synch release from flush" instead of doing a
synchronous release from fput().

This simplifies code, as well as fixing the rare corner cases when RELEASE
would be blocking in inappropriate places.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 6c16656..162ea5b 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -95,7 +95,7 @@
 	iput(req->misc.release.inode);
 }
 
-static void fuse_file_put(struct fuse_file *ff, bool sync)
+static void fuse_file_put(struct fuse_file *ff)
 {
 	if (atomic_dec_and_test(&ff->count)) {
 		struct fuse_req *req = ff->reserved_req;
@@ -108,11 +108,6 @@
 			req->background = 0;
 			iput(req->misc.release.inode);
 			fuse_put_request(ff->fc, req);
-		} else if (sync) {
-			req->background = 0;
-			fuse_request_send(ff->fc, req);
-			iput(req->misc.release.inode);
-			fuse_put_request(ff->fc, req);
 		} else {
 			req->end = fuse_release_end;
 			req->background = 1;
@@ -204,6 +199,9 @@
 	}
 	if ((file->f_mode & FMODE_WRITE) && fc->writeback_cache)
 		fuse_link_write_file(file);
+	/* fuseblk gets sync release by default */
+	if (fc->destroy_req)
+		ff->open_flags |= FOPEN_SYNC_RELEASE;
 }
 
 int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
@@ -283,12 +281,8 @@
 	 * Normally this will send the RELEASE request, however if
 	 * some asynchronous READ or WRITE requests are outstanding,
 	 * the sending will be delayed.
-	 *
-	 * Make the release synchronous if this is a fuseblk mount,
-	 * synchronous RELEASE is allowed (and desirable) in this case
-	 * because the server can be trusted not to screw up.
 	 */
-	fuse_file_put(ff, ff->fc->destroy_req != NULL);
+	fuse_file_put(ff);
 }
 
 static int fuse_open(struct inode *inode, struct file *file)
@@ -845,7 +839,7 @@
 		page_cache_release(page);
 	}
 	if (req->ff)
-		fuse_file_put(req->ff, false);
+		fuse_file_put(req->ff);
 }
 
 static void fuse_send_readpages(struct fuse_req *req, struct file *file)
@@ -1523,7 +1517,7 @@
 		__free_page(req->pages[i]);
 
 	if (req->ff)
-		fuse_file_put(req->ff, false);
+		fuse_file_put(req->ff);
 }
 
 static void fuse_writepage_finish(struct fuse_conn *fc, struct fuse_req *req)
@@ -1680,7 +1674,7 @@
 	ff = __fuse_write_file_get(fc, fi);
 	err = fuse_flush_times(inode, ff);
 	if (ff)
-		fuse_file_put(ff, 0);
+		fuse_file_put(ff);
 
 	return err;
 }
@@ -1993,7 +1987,7 @@
 		err = 0;
 	}
 	if (data.ff)
-		fuse_file_put(data.ff, false);
+		fuse_file_put(data.ff);
 
 	kfree(data.orig_pages);
 out: