[Devel,vz7,35/46] fuse: request_end(): do once

Submitted by Maxim Patlasov on March 25, 2017, 2:26 a.m.

Details

Message ID 149040877377.25341.6779827324843167108.stgit@maxim-thinkpad
State New
Series "fuse: add multi-threading support"
Headers show

Commit Message

Maxim Patlasov March 25, 2017, 2:26 a.m.
Backport from ml:

commit 365ae710df91edc97d24817e3271e01bffaaee32
Author: Miklos Szeredi <mszeredi@suse.cz>
Date:   Wed Jul 1 16:26:06 2015 +0200

    fuse: request_end(): do once

    When the connection is aborted it is possible that request_end() will be
    called twice.  Use atomic test and set to do the actual ending only once.

    test_and_set_bit() also provides the necessary barrier semantics so no
    explicit smp_wmb() is necessary.

    Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
    Reviewed-by: Ashish Samant <ashish.samant@oracle.com>

Signed-off-by: Maxim Patlasov <mpatlasov@virtuozzo.com>
---
 fs/fuse/dev.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 50812a0..4d16a1c 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -367,14 +367,18 @@  __releases(fc->lock)
 {
 	struct fuse_iqueue *fiq = &fc->iq;
 	void (*end) (struct fuse_conn *, struct fuse_req *) = req->end;
+
+	if (test_and_set_bit(FR_FINISHED, &req->flags)) {
+		spin_unlock(&fc->lock);
+		return;
+	}
+
 	req->end = NULL;
 	spin_lock(&fiq->waitq.lock);
 	list_del_init(&req->intr_entry);
 	spin_unlock(&fiq->waitq.lock);
 	WARN_ON(test_bit(FR_PENDING, &req->flags));
 	WARN_ON(test_bit(FR_SENT, &req->flags));
-	smp_wmb();
-	set_bit(FR_FINISHED, &req->flags);
 	if (test_bit(FR_BACKGROUND, &req->flags)) {
 		clear_bit(FR_BACKGROUND, &req->flags);
 		if (fc->num_background == fc->max_background)