fuse: pqueue locking
Add a fpq->lock for protecting members of struct fuse_pqueue and FR_LOCKED request flag. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Reviewed-by: Ashish Samant <ashish.samant@oracle.com>
This commit is contained in:
parent
24b4d33d46
commit
45a91cb1a4
|
@ -1291,7 +1291,9 @@ static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
|
||||||
request_end(fc, req);
|
request_end(fc, req);
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
|
spin_lock(&fpq->lock);
|
||||||
list_add(&req->list, &fpq->io);
|
list_add(&req->list, &fpq->io);
|
||||||
|
spin_unlock(&fpq->lock);
|
||||||
spin_unlock(&fc->lock);
|
spin_unlock(&fc->lock);
|
||||||
cs->req = req;
|
cs->req = req;
|
||||||
err = fuse_copy_one(cs, &in->h, sizeof(in->h));
|
err = fuse_copy_one(cs, &in->h, sizeof(in->h));
|
||||||
|
@ -1300,6 +1302,7 @@ static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
|
||||||
(struct fuse_arg *) in->args, 0);
|
(struct fuse_arg *) in->args, 0);
|
||||||
fuse_copy_finish(cs);
|
fuse_copy_finish(cs);
|
||||||
spin_lock(&fc->lock);
|
spin_lock(&fc->lock);
|
||||||
|
spin_lock(&fpq->lock);
|
||||||
clear_bit(FR_LOCKED, &req->flags);
|
clear_bit(FR_LOCKED, &req->flags);
|
||||||
if (!fpq->connected) {
|
if (!fpq->connected) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
|
@ -1314,6 +1317,7 @@ static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
|
||||||
goto out_end;
|
goto out_end;
|
||||||
}
|
}
|
||||||
list_move_tail(&req->list, &fpq->processing);
|
list_move_tail(&req->list, &fpq->processing);
|
||||||
|
spin_unlock(&fpq->lock);
|
||||||
set_bit(FR_SENT, &req->flags);
|
set_bit(FR_SENT, &req->flags);
|
||||||
/* matches barrier in request_wait_answer() */
|
/* matches barrier in request_wait_answer() */
|
||||||
smp_mb__after_atomic();
|
smp_mb__after_atomic();
|
||||||
|
@ -1325,6 +1329,7 @@ static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
|
||||||
|
|
||||||
out_end:
|
out_end:
|
||||||
list_del_init(&req->list);
|
list_del_init(&req->list);
|
||||||
|
spin_unlock(&fpq->lock);
|
||||||
request_end(fc, req);
|
request_end(fc, req);
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -1893,16 +1898,19 @@ static ssize_t fuse_dev_do_write(struct fuse_conn *fc,
|
||||||
goto err_finish;
|
goto err_finish;
|
||||||
|
|
||||||
spin_lock(&fc->lock);
|
spin_lock(&fc->lock);
|
||||||
|
spin_lock(&fpq->lock);
|
||||||
err = -ENOENT;
|
err = -ENOENT;
|
||||||
if (!fpq->connected)
|
if (!fpq->connected)
|
||||||
goto err_unlock;
|
goto err_unlock_pq;
|
||||||
|
|
||||||
req = request_find(fpq, oh.unique);
|
req = request_find(fpq, oh.unique);
|
||||||
if (!req)
|
if (!req)
|
||||||
goto err_unlock;
|
goto err_unlock_pq;
|
||||||
|
|
||||||
/* Is it an interrupt reply? */
|
/* Is it an interrupt reply? */
|
||||||
if (req->intr_unique == oh.unique) {
|
if (req->intr_unique == oh.unique) {
|
||||||
|
spin_unlock(&fpq->lock);
|
||||||
|
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
if (nbytes != sizeof(struct fuse_out_header))
|
if (nbytes != sizeof(struct fuse_out_header))
|
||||||
goto err_unlock;
|
goto err_unlock;
|
||||||
|
@ -1921,6 +1929,7 @@ static ssize_t fuse_dev_do_write(struct fuse_conn *fc,
|
||||||
list_move(&req->list, &fpq->io);
|
list_move(&req->list, &fpq->io);
|
||||||
req->out.h = oh;
|
req->out.h = oh;
|
||||||
set_bit(FR_LOCKED, &req->flags);
|
set_bit(FR_LOCKED, &req->flags);
|
||||||
|
spin_unlock(&fpq->lock);
|
||||||
cs->req = req;
|
cs->req = req;
|
||||||
if (!req->out.page_replace)
|
if (!req->out.page_replace)
|
||||||
cs->move_pages = 0;
|
cs->move_pages = 0;
|
||||||
|
@ -1930,16 +1939,20 @@ static ssize_t fuse_dev_do_write(struct fuse_conn *fc,
|
||||||
fuse_copy_finish(cs);
|
fuse_copy_finish(cs);
|
||||||
|
|
||||||
spin_lock(&fc->lock);
|
spin_lock(&fc->lock);
|
||||||
|
spin_lock(&fpq->lock);
|
||||||
clear_bit(FR_LOCKED, &req->flags);
|
clear_bit(FR_LOCKED, &req->flags);
|
||||||
if (!fpq->connected)
|
if (!fpq->connected)
|
||||||
err = -ENOENT;
|
err = -ENOENT;
|
||||||
else if (err)
|
else if (err)
|
||||||
req->out.h.error = -EIO;
|
req->out.h.error = -EIO;
|
||||||
list_del_init(&req->list);
|
list_del_init(&req->list);
|
||||||
|
spin_unlock(&fpq->lock);
|
||||||
request_end(fc, req);
|
request_end(fc, req);
|
||||||
|
|
||||||
return err ? err : nbytes;
|
return err ? err : nbytes;
|
||||||
|
|
||||||
|
err_unlock_pq:
|
||||||
|
spin_unlock(&fpq->lock);
|
||||||
err_unlock:
|
err_unlock:
|
||||||
spin_unlock(&fc->lock);
|
spin_unlock(&fc->lock);
|
||||||
err_finish:
|
err_finish:
|
||||||
|
@ -2130,6 +2143,7 @@ void fuse_abort_conn(struct fuse_conn *fc)
|
||||||
fc->connected = 0;
|
fc->connected = 0;
|
||||||
fc->blocked = 0;
|
fc->blocked = 0;
|
||||||
fuse_set_initialized(fc);
|
fuse_set_initialized(fc);
|
||||||
|
spin_lock(&fpq->lock);
|
||||||
fpq->connected = 0;
|
fpq->connected = 0;
|
||||||
list_for_each_entry_safe(req, next, &fpq->io, list) {
|
list_for_each_entry_safe(req, next, &fpq->io, list) {
|
||||||
req->out.h.error = -ECONNABORTED;
|
req->out.h.error = -ECONNABORTED;
|
||||||
|
@ -2140,6 +2154,7 @@ void fuse_abort_conn(struct fuse_conn *fc)
|
||||||
spin_unlock(&req->waitq.lock);
|
spin_unlock(&req->waitq.lock);
|
||||||
}
|
}
|
||||||
list_splice_init(&fpq->processing, &to_end2);
|
list_splice_init(&fpq->processing, &to_end2);
|
||||||
|
spin_unlock(&fpq->lock);
|
||||||
fc->max_background = UINT_MAX;
|
fc->max_background = UINT_MAX;
|
||||||
flush_bg_queue(fc);
|
flush_bg_queue(fc);
|
||||||
|
|
||||||
|
|
|
@ -405,6 +405,9 @@ struct fuse_pqueue {
|
||||||
/** Connection established */
|
/** Connection established */
|
||||||
unsigned connected;
|
unsigned connected;
|
||||||
|
|
||||||
|
/** Lock protecting accessess to members of this structure */
|
||||||
|
spinlock_t lock;
|
||||||
|
|
||||||
/** The list of requests being processed */
|
/** The list of requests being processed */
|
||||||
struct list_head processing;
|
struct list_head processing;
|
||||||
|
|
||||||
|
|
|
@ -580,6 +580,7 @@ static void fuse_iqueue_init(struct fuse_iqueue *fiq)
|
||||||
static void fuse_pqueue_init(struct fuse_pqueue *fpq)
|
static void fuse_pqueue_init(struct fuse_pqueue *fpq)
|
||||||
{
|
{
|
||||||
memset(fpq, 0, sizeof(struct fuse_pqueue));
|
memset(fpq, 0, sizeof(struct fuse_pqueue));
|
||||||
|
spin_lock_init(&fpq->lock);
|
||||||
INIT_LIST_HEAD(&fpq->processing);
|
INIT_LIST_HEAD(&fpq->processing);
|
||||||
INIT_LIST_HEAD(&fpq->io);
|
INIT_LIST_HEAD(&fpq->io);
|
||||||
fpq->connected = 1;
|
fpq->connected = 1;
|
||||||
|
|
Loading…
Reference in New Issue