aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fuse
diff options
context:
space:
mode:
authorKirill Tkhai <ktkhai@virtuozzo.com>2018-08-27 11:29:56 -0400
committerMiklos Szeredi <mszeredi@redhat.com>2018-09-28 10:43:23 -0400
commit63825b4e1da5a3cba79d835a5925e5daf7db3a77 (patch)
tree55581224599445dbb52801e50273cb3071f700a8 /fs/fuse
parentae2dffa39485c6fd4f22321814c7287c274b473a (diff)
fuse: do not take fc->lock in fuse_request_send_background()
Currently, we take fc->lock there only to check for fc->connected. But this flag is changed only on connection abort, which is very rare operation. So allow checking fc->connected under just fc->bg_lock and use this lock (as well as fc->lock) when resetting fc->connected. Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/fuse')
-rw-r--r--fs/fuse/dev.c48
-rw-r--r--fs/fuse/file.c4
-rw-r--r--fs/fuse/fuse_i.h4
3 files changed, 28 insertions, 28 deletions
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index d4b9ffc6544d..071feb8cb265 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -581,42 +581,38 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args)
581 return ret; 581 return ret;
582} 582}
583 583
584/* 584bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req)
585 * Called under fc->lock
586 *
587 * fc->connected must have been checked previously
588 */
589void fuse_request_send_background_nocheck(struct fuse_conn *fc,
590 struct fuse_req *req)
591{ 585{
592 BUG_ON(!test_bit(FR_BACKGROUND, &req->flags)); 586 bool queued = false;
587
588 WARN_ON(!test_bit(FR_BACKGROUND, &req->flags));
593 if (!test_bit(FR_WAITING, &req->flags)) { 589 if (!test_bit(FR_WAITING, &req->flags)) {
594 __set_bit(FR_WAITING, &req->flags); 590 __set_bit(FR_WAITING, &req->flags);
595 atomic_inc(&fc->num_waiting); 591 atomic_inc(&fc->num_waiting);
596 } 592 }
597 __set_bit(FR_ISREPLY, &req->flags); 593 __set_bit(FR_ISREPLY, &req->flags);
598 spin_lock(&fc->bg_lock); 594 spin_lock(&fc->bg_lock);
599 fc->num_background++; 595 if (likely(fc->connected)) {
600 if (fc->num_background == fc->max_background) 596 fc->num_background++;
601 fc->blocked = 1; 597 if (fc->num_background == fc->max_background)
602 if (fc->num_background == fc->congestion_threshold && fc->sb) { 598 fc->blocked = 1;
603 set_bdi_congested(fc->sb->s_bdi, BLK_RW_SYNC); 599 if (fc->num_background == fc->congestion_threshold && fc->sb) {
604 set_bdi_congested(fc->sb->s_bdi, BLK_RW_ASYNC); 600 set_bdi_congested(fc->sb->s_bdi, BLK_RW_SYNC);
605 } 601 set_bdi_congested(fc->sb->s_bdi, BLK_RW_ASYNC);
606 list_add_tail(&req->list, &fc->bg_queue); 602 }
607 flush_bg_queue(fc); 603 list_add_tail(&req->list, &fc->bg_queue);
604 flush_bg_queue(fc);
605 queued = true;
606 }
608 spin_unlock(&fc->bg_lock); 607 spin_unlock(&fc->bg_lock);
608
609 return queued;
609} 610}
610 611
611void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req) 612void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req)
612{ 613{
613 BUG_ON(!req->end); 614 WARN_ON(!req->end);
614 spin_lock(&fc->lock); 615 if (!fuse_request_queue_background(fc, req)) {
615 if (fc->connected) {
616 fuse_request_send_background_nocheck(fc, req);
617 spin_unlock(&fc->lock);
618 } else {
619 spin_unlock(&fc->lock);
620 req->out.h.error = -ENOTCONN; 616 req->out.h.error = -ENOTCONN;
621 req->end(fc, req); 617 req->end(fc, req);
622 fuse_put_request(fc, req); 618 fuse_put_request(fc, req);
@@ -2119,7 +2115,11 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
2119 struct fuse_req *req, *next; 2115 struct fuse_req *req, *next;
2120 LIST_HEAD(to_end); 2116 LIST_HEAD(to_end);
2121 2117
2118 /* Background queuing checks fc->connected under bg_lock */
2119 spin_lock(&fc->bg_lock);
2122 fc->connected = 0; 2120 fc->connected = 0;
2121 spin_unlock(&fc->bg_lock);
2122
2123 fc->aborted = is_abort; 2123 fc->aborted = is_abort;
2124 fuse_set_initialized(fc); 2124 fuse_set_initialized(fc);
2125 list_for_each_entry(fud, &fc->devices, entry) { 2125 list_for_each_entry(fud, &fc->devices, entry) {
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 65351d43c2b6..d15c14912e72 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1487,6 +1487,7 @@ __acquires(fc->lock)
1487 struct fuse_inode *fi = get_fuse_inode(req->inode); 1487 struct fuse_inode *fi = get_fuse_inode(req->inode);
1488 struct fuse_write_in *inarg = &req->misc.write.in; 1488 struct fuse_write_in *inarg = &req->misc.write.in;
1489 __u64 data_size = req->num_pages * PAGE_SIZE; 1489 __u64 data_size = req->num_pages * PAGE_SIZE;
1490 bool queued;
1490 1491
1491 if (!fc->connected) 1492 if (!fc->connected)
1492 goto out_free; 1493 goto out_free;
@@ -1502,7 +1503,8 @@ __acquires(fc->lock)
1502 1503
1503 req->in.args[1].size = inarg->size; 1504 req->in.args[1].size = inarg->size;
1504 fi->writectr++; 1505 fi->writectr++;
1505 fuse_request_send_background_nocheck(fc, req); 1506 queued = fuse_request_queue_background(fc, req);
1507 WARN_ON(!queued);
1506 return; 1508 return;
1507 1509
1508 out_free: 1510 out_free:
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index d6d55641a5a6..6e6eab8127a4 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -863,9 +863,7 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
863 * Send a request in the background 863 * Send a request in the background
864 */ 864 */
865void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); 865void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
866 866bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req);
867void fuse_request_send_background_nocheck(struct fuse_conn *fc,
868 struct fuse_req *req);
869 867
870/* Abort all requests */ 868/* Abort all requests */
871void fuse_abort_conn(struct fuse_conn *fc, bool is_abort); 869void fuse_abort_conn(struct fuse_conn *fc, bool is_abort);