*/
#include "fuse_i.h"
+#include "fuse_dev_i.h"
#include <linux/init.h>
#include <linux/module.h>
if (!fc)
return 0;
- val = READ_ONCE(fc->max_background);
+ val = READ_ONCE(fc->chan->max_background);
fuse_conn_put(fc);
return fuse_conn_limit_read(file, buf, len, ppos, val);
if (ret > 0) {
struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
if (fc) {
- spin_lock(&fc->bg_lock);
- fc->max_background = val;
- fc->blocked = fc->num_background >= fc->max_background;
+ spin_lock(&fc->chan->bg_lock);
+ fc->chan->max_background = val;
+ fc->blocked = fc->chan->num_background >= fc->chan->max_background;
if (!fc->blocked)
wake_up(&fc->blocked_waitq);
- spin_unlock(&fc->bg_lock);
+ spin_unlock(&fc->chan->bg_lock);
fuse_conn_put(fc);
}
}
* We get here in the unlikely case that a background
* request was allocated but not sent
*/
- spin_lock(&fc->bg_lock);
+ spin_lock(&fc->chan->bg_lock);
if (!fc->blocked)
wake_up(&fc->blocked_waitq);
- spin_unlock(&fc->bg_lock);
+ spin_unlock(&fc->chan->bg_lock);
}
if (test_bit(FR_WAITING, &req->flags)) {
return NULL;
INIT_LIST_HEAD(&fch->devices);
+ spin_lock_init(&fch->bg_lock);
+ INIT_LIST_HEAD(&fch->bg_queue);
+ fch->max_background = FUSE_DEFAULT_MAX_BACKGROUND;
return fch;
}
{
struct fuse_iqueue *fiq = &fc->chan->iq;
- while (fc->active_background < fc->max_background &&
- !list_empty(&fc->bg_queue)) {
+ while (fc->chan->active_background < fc->chan->max_background &&
+ !list_empty(&fc->chan->bg_queue)) {
struct fuse_req *req;
- req = list_first_entry(&fc->bg_queue, struct fuse_req, list);
+ req = list_first_entry(&fc->chan->bg_queue, struct fuse_req, list);
list_del(&req->list);
- fc->active_background++;
+ fc->chan->active_background++;
fuse_send_one(fiq, req);
}
}
void fuse_request_bg_finish(struct fuse_conn *fc, struct fuse_req *req)
{
- lockdep_assert_held(&fc->bg_lock);
+ lockdep_assert_held(&fc->chan->bg_lock);
clear_bit(FR_BACKGROUND, &req->flags);
- if (fc->num_background == fc->max_background) {
+ if (fc->chan->num_background == fc->chan->max_background) {
fc->blocked = 0;
wake_up(&fc->blocked_waitq);
} else if (!fc->blocked) {
wake_up(&fc->blocked_waitq);
}
- fc->num_background--;
- fc->active_background--;
+ fc->chan->num_background--;
+ fc->chan->active_background--;
}
/*
WARN_ON(test_bit(FR_PENDING, &req->flags));
WARN_ON(test_bit(FR_SENT, &req->flags));
if (test_bit(FR_BACKGROUND, &req->flags)) {
- spin_lock(&fc->bg_lock);
+ spin_lock(&fc->chan->bg_lock);
fuse_request_bg_finish(fc, req);
flush_bg_queue(fc);
- spin_unlock(&fc->bg_lock);
+ spin_unlock(&fc->chan->bg_lock);
} else {
/* Wake up waiter sleeping in request_wait_answer() */
wake_up(&req->waitq);
return fuse_request_queue_background_uring(fc, req);
#endif
- spin_lock(&fc->bg_lock);
+ spin_lock(&fc->chan->bg_lock);
if (likely(fc->connected)) {
- fc->num_background++;
- if (fc->num_background == fc->max_background)
+ fc->chan->num_background++;
+ if (fc->chan->num_background == fc->chan->max_background)
fc->blocked = 1;
- list_add_tail(&req->list, &fc->bg_queue);
+ list_add_tail(&req->list, &fc->chan->bg_queue);
flush_bg_queue(fc);
queued = true;
}
- spin_unlock(&fc->bg_lock);
+ spin_unlock(&fc->chan->bg_lock);
return queued;
}
cancel_delayed_work(&fc->timeout.work);
/* Background queuing checks fc->connected under bg_lock */
- spin_lock(&fc->bg_lock);
+ spin_lock(&fc->chan->bg_lock);
fc->connected = 0;
- spin_unlock(&fc->bg_lock);
+ spin_unlock(&fc->chan->bg_lock);
fuse_set_initialized(fc);
list_for_each_entry(fud, &fc->chan->devices, entry) {
&to_end);
spin_unlock(&fpq->lock);
}
- spin_lock(&fc->bg_lock);
+ spin_lock(&fc->chan->bg_lock);
fc->blocked = 0;
- fc->max_background = UINT_MAX;
+ fc->chan->max_background = UINT_MAX;
flush_bg_queue(fc);
- spin_unlock(&fc->bg_lock);
+ spin_unlock(&fc->chan->bg_lock);
spin_lock(&fiq->lock);
fiq->connected = 0;
#include <linux/cleanup.h>
+/** Maximum number of outstanding background requests */
+#define FUSE_DEFAULT_MAX_BACKGROUND 12
+
struct fuse_conn;
struct fuse_chan;
struct fuse_dev;
struct fuse_conn *fc = ring->fc;
lockdep_assert_held(&queue->lock);
- lockdep_assert_held(&fc->bg_lock);
+ lockdep_assert_held(&fc->chan->bg_lock);
/*
* Allow one bg request per queue, ignoring global fc limits.
* eliminates the need for remote queue wake-ups when global
* limits are met but this queue has no more waiting requests.
*/
- while ((fc->active_background < fc->max_background ||
+ while ((fc->chan->active_background < fc->chan->max_background ||
!queue->active_background) &&
(!list_empty(&queue->fuse_req_bg_queue))) {
struct fuse_req *req;
req = list_first_entry(&queue->fuse_req_bg_queue,
struct fuse_req, list);
- fc->active_background++;
+ fc->chan->active_background++;
queue->active_background++;
list_move_tail(&req->list, &queue->fuse_req_queue);
list_del_init(&req->list);
if (test_bit(FR_BACKGROUND, &req->flags)) {
queue->active_background--;
- spin_lock(&fc->bg_lock);
+ spin_lock(&fc->chan->bg_lock);
fuse_request_bg_finish(fc, req);
fuse_uring_flush_bg(queue);
- spin_unlock(&fc->bg_lock);
+ spin_unlock(&fc->chan->bg_lock);
}
spin_unlock(&queue->lock);
if (!queue)
continue;
- WARN_ON_ONCE(ring->fc->max_background != UINT_MAX);
+ WARN_ON_ONCE(ring->fc->chan->max_background != UINT_MAX);
spin_lock(&queue->lock);
queue->stopped = true;
- spin_lock(&fc->bg_lock);
+ spin_lock(&fc->chan->bg_lock);
fuse_uring_flush_bg(queue);
- spin_unlock(&fc->bg_lock);
+ spin_unlock(&fc->chan->bg_lock);
spin_unlock(&queue->lock);
fuse_uring_abort_end_queue_requests(queue);
}
ent = list_first_entry_or_null(&queue->ent_avail_queue,
struct fuse_ring_ent, list);
- spin_lock(&fc->bg_lock);
- fc->num_background++;
- if (fc->num_background == fc->max_background)
+ spin_lock(&fc->chan->bg_lock);
+ fc->chan->num_background++;
+ if (fc->chan->num_background == fc->chan->max_background)
fc->blocked = 1;
fuse_uring_flush_bg(queue);
- spin_unlock(&fc->bg_lock);
+ spin_unlock(&fc->chan->bg_lock);
/*
* Due to bg_queue flush limits there might be other bg requests
*/
#include "fuse_i.h"
+#include "fuse_dev_i.h"
#include <linux/pagemap.h>
#include <linux/slab.h>
ia = NULL;
}
if (!ia) {
- if (fc->num_background >= fc->congestion_threshold &&
+ if (fc->chan->num_background >= fc->congestion_threshold &&
rac->ra->async_size >= readahead_count(rac))
/*
* Congested and only async pages left, so skip the
return -EIO;
if (wbc->sync_mode == WB_SYNC_NONE &&
- fc->num_background >= fc->congestion_threshold)
+ fc->chan->num_background >= fc->congestion_threshold)
return 0;
return iomap_writepages(&wpc);
/** List of device instances belonging to this connection */
struct list_head devices;
+
+ /** Maximum number of outstanding background requests */
+ unsigned max_background;
+
+ /** Number of requests currently in the background */
+ unsigned num_background;
+
+ /** Number of background requests currently queued for userspace */
+ unsigned active_background;
+
+ /** The list of background requests set aside for later queuing */
+ struct list_head bg_queue;
+
+ /** Protects: max_background, num_background, active_background, bg_queue, blocked */
+ spinlock_t bg_lock;
};
#define FUSE_PQ_HASH_BITS 8
/** rbtree of fuse_files waiting for poll events indexed by ph */
struct rb_root polled_files;
- /** Maximum number of outstanding background requests */
- unsigned max_background;
-
/** Number of background requests at which congestion starts */
unsigned congestion_threshold;
- /** Number of requests currently in the background */
- unsigned num_background;
-
- /** Number of background requests currently queued for userspace */
- unsigned active_background;
-
- /** The list of background requests set aside for later queuing */
- struct list_head bg_queue;
-
- /** Protects: max_background, congestion_threshold, num_background,
- * active_background, bg_queue, blocked */
- spinlock_t bg_lock;
-
/** Flag indicating that INIT reply has been received. Allocating
* any fuse request will be suspended until the flag is set */
int initialized;
#define FUSE_DEFAULT_BLKSIZE 512
-/** Maximum number of outstanding background requests */
-#define FUSE_DEFAULT_MAX_BACKGROUND 12
-
/** Congestion starts at 75% of maximum */
#define FUSE_DEFAULT_CONGESTION_THRESHOLD (FUSE_DEFAULT_MAX_BACKGROUND * 3 / 4)
{
memset(fc, 0, sizeof(*fc));
spin_lock_init(&fc->lock);
- spin_lock_init(&fc->bg_lock);
init_rwsem(&fc->killsb);
refcount_set(&fc->count, 1);
atomic_set(&fc->epoch, 1);
INIT_WORK(&fc->epoch_work, fuse_epoch_work);
init_waitqueue_head(&fc->blocked_waitq);
- INIT_LIST_HEAD(&fc->bg_queue);
INIT_LIST_HEAD(&fc->entry);
atomic_set(&fc->num_waiting, 0);
- fc->max_background = FUSE_DEFAULT_MAX_BACKGROUND;
fc->congestion_threshold = FUSE_DEFAULT_CONGESTION_THRESHOLD;
atomic64_set(&fc->khctr, 0);
fc->polled_files = RB_ROOT;
sanitize_global_limit(&max_user_bgreq);
sanitize_global_limit(&max_user_congthresh);
- spin_lock(&fc->bg_lock);
+ spin_lock(&fc->chan->bg_lock);
if (arg->max_background) {
- fc->max_background = arg->max_background;
+ fc->chan->max_background = arg->max_background;
- if (!cap_sys_admin && fc->max_background > max_user_bgreq)
- fc->max_background = max_user_bgreq;
+ if (!cap_sys_admin && fc->chan->max_background > max_user_bgreq)
+ fc->chan->max_background = max_user_bgreq;
}
if (arg->congestion_threshold) {
fc->congestion_threshold = arg->congestion_threshold;
fc->congestion_threshold > max_user_congthresh)
fc->congestion_threshold = max_user_congthresh;
}
- spin_unlock(&fc->bg_lock);
+ spin_unlock(&fc->chan->bg_lock);
}
struct fuse_init_args {
if (expired)
goto abort_conn;
- spin_lock(&fc->bg_lock);
- expired = fuse_request_expired(fc, &fc->bg_queue);
- spin_unlock(&fc->bg_lock);
+ spin_lock(&fc->chan->bg_lock);
+ expired = fuse_request_expired(fc, &fc->chan->bg_queue);
+ spin_unlock(&fc->chan->bg_lock);
if (expired)
goto abort_conn;
if (ret == -ENOSPC) {
/*
* Virtqueue full. Retry submission from worker
- * context as we might be holding fc->bg_lock.
+ * context as we might be holding fc->chan->bg_lock.
*/
spin_lock(&fsvq->lock);
list_add_tail(&req->list, &fsvq->queued_reqs);