mirror of https://gitee.com/openkylin/linux.git
fuse: req state use flags
Use flags for representing the state in fuse_req. This is needed since req->list will be protected by different locks in different states, hence we'll want the state itself to be split into distinct bits, each protected with the relevant lock in that state. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
This commit is contained in:
parent
7a3b2c7547
commit
33e14b4dfd
|
@ -48,6 +48,7 @@ static void fuse_request_init(struct fuse_req *req, struct page **pages,
|
||||||
req->pages = pages;
|
req->pages = pages;
|
||||||
req->page_descs = page_descs;
|
req->page_descs = page_descs;
|
||||||
req->max_pages = npages;
|
req->max_pages = npages;
|
||||||
|
__set_bit(FR_PENDING, &req->flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct fuse_req *__fuse_request_alloc(unsigned npages, gfp_t flags)
|
static struct fuse_req *__fuse_request_alloc(unsigned npages, gfp_t flags)
|
||||||
|
@ -380,8 +381,10 @@ __releases(fc->lock)
|
||||||
req->end = NULL;
|
req->end = NULL;
|
||||||
list_del_init(&req->list);
|
list_del_init(&req->list);
|
||||||
list_del_init(&req->intr_entry);
|
list_del_init(&req->intr_entry);
|
||||||
|
WARN_ON(test_bit(FR_PENDING, &req->flags));
|
||||||
|
WARN_ON(test_bit(FR_SENT, &req->flags));
|
||||||
smp_wmb();
|
smp_wmb();
|
||||||
req->state = FUSE_REQ_FINISHED;
|
set_bit(FR_FINISHED, &req->flags);
|
||||||
if (test_bit(FR_BACKGROUND, &req->flags)) {
|
if (test_bit(FR_BACKGROUND, &req->flags)) {
|
||||||
clear_bit(FR_BACKGROUND, &req->flags);
|
clear_bit(FR_BACKGROUND, &req->flags);
|
||||||
if (fc->num_background == fc->max_background)
|
if (fc->num_background == fc->max_background)
|
||||||
|
@ -421,13 +424,13 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
|
||||||
if (!fc->no_interrupt) {
|
if (!fc->no_interrupt) {
|
||||||
/* Any signal may interrupt this */
|
/* Any signal may interrupt this */
|
||||||
err = wait_event_interruptible(req->waitq,
|
err = wait_event_interruptible(req->waitq,
|
||||||
req->state == FUSE_REQ_FINISHED);
|
test_bit(FR_FINISHED, &req->flags));
|
||||||
if (!err)
|
if (!err)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
spin_lock(&fc->lock);
|
spin_lock(&fc->lock);
|
||||||
set_bit(FR_INTERRUPTED, &req->flags);
|
set_bit(FR_INTERRUPTED, &req->flags);
|
||||||
if (req->state == FUSE_REQ_SENT)
|
if (test_bit(FR_SENT, &req->flags))
|
||||||
queue_interrupt(fc, req);
|
queue_interrupt(fc, req);
|
||||||
spin_unlock(&fc->lock);
|
spin_unlock(&fc->lock);
|
||||||
}
|
}
|
||||||
|
@ -438,7 +441,7 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
|
||||||
/* Only fatal signals may interrupt this */
|
/* Only fatal signals may interrupt this */
|
||||||
block_sigs(&oldset);
|
block_sigs(&oldset);
|
||||||
err = wait_event_interruptible(req->waitq,
|
err = wait_event_interruptible(req->waitq,
|
||||||
req->state == FUSE_REQ_FINISHED);
|
test_bit(FR_FINISHED, &req->flags));
|
||||||
restore_sigs(&oldset);
|
restore_sigs(&oldset);
|
||||||
|
|
||||||
if (!err)
|
if (!err)
|
||||||
|
@ -446,7 +449,7 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
|
||||||
|
|
||||||
spin_lock(&fc->lock);
|
spin_lock(&fc->lock);
|
||||||
/* Request is not yet in userspace, bail out */
|
/* Request is not yet in userspace, bail out */
|
||||||
if (req->state == FUSE_REQ_PENDING) {
|
if (test_bit(FR_PENDING, &req->flags)) {
|
||||||
list_del(&req->list);
|
list_del(&req->list);
|
||||||
spin_unlock(&fc->lock);
|
spin_unlock(&fc->lock);
|
||||||
__fuse_put_request(req);
|
__fuse_put_request(req);
|
||||||
|
@ -460,7 +463,7 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
|
||||||
* Either request is already in userspace, or it was forced.
|
* Either request is already in userspace, or it was forced.
|
||||||
* Wait it out.
|
* Wait it out.
|
||||||
*/
|
*/
|
||||||
wait_event(req->waitq, req->state == FUSE_REQ_FINISHED);
|
wait_event(req->waitq, test_bit(FR_FINISHED, &req->flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
|
static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
|
||||||
|
@ -1273,7 +1276,7 @@ static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
|
||||||
}
|
}
|
||||||
|
|
||||||
req = list_entry(fc->pending.next, struct fuse_req, list);
|
req = list_entry(fc->pending.next, struct fuse_req, list);
|
||||||
req->state = FUSE_REQ_IO;
|
clear_bit(FR_PENDING, &req->flags);
|
||||||
list_move(&req->list, &fc->io);
|
list_move(&req->list, &fc->io);
|
||||||
|
|
||||||
in = &req->in;
|
in = &req->in;
|
||||||
|
@ -1308,7 +1311,7 @@ static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
|
||||||
if (!test_bit(FR_ISREPLY, &req->flags)) {
|
if (!test_bit(FR_ISREPLY, &req->flags)) {
|
||||||
request_end(fc, req);
|
request_end(fc, req);
|
||||||
} else {
|
} else {
|
||||||
req->state = FUSE_REQ_SENT;
|
set_bit(FR_SENT, &req->flags);
|
||||||
list_move_tail(&req->list, &fc->processing);
|
list_move_tail(&req->list, &fc->processing);
|
||||||
if (test_bit(FR_INTERRUPTED, &req->flags))
|
if (test_bit(FR_INTERRUPTED, &req->flags))
|
||||||
queue_interrupt(fc, req);
|
queue_interrupt(fc, req);
|
||||||
|
@ -1904,7 +1907,7 @@ static ssize_t fuse_dev_do_write(struct fuse_conn *fc,
|
||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
req->state = FUSE_REQ_IO;
|
clear_bit(FR_SENT, &req->flags);
|
||||||
list_move(&req->list, &fc->io);
|
list_move(&req->list, &fc->io);
|
||||||
req->out.h = oh;
|
req->out.h = oh;
|
||||||
set_bit(FR_LOCKED, &req->flags);
|
set_bit(FR_LOCKED, &req->flags);
|
||||||
|
@ -2059,6 +2062,8 @@ __acquires(fc->lock)
|
||||||
struct fuse_req *req;
|
struct fuse_req *req;
|
||||||
req = list_entry(head->next, struct fuse_req, list);
|
req = list_entry(head->next, struct fuse_req, list);
|
||||||
req->out.h.error = -ECONNABORTED;
|
req->out.h.error = -ECONNABORTED;
|
||||||
|
clear_bit(FR_PENDING, &req->flags);
|
||||||
|
clear_bit(FR_SENT, &req->flags);
|
||||||
request_end(fc, req);
|
request_end(fc, req);
|
||||||
spin_lock(&fc->lock);
|
spin_lock(&fc->lock);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1743,7 +1743,7 @@ static bool fuse_writepage_in_flight(struct fuse_req *new_req,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (old_req->num_pages == 1 && old_req->state == FUSE_REQ_PENDING) {
|
if (old_req->num_pages == 1 && test_bit(FR_PENDING, &old_req->flags)) {
|
||||||
struct backing_dev_info *bdi = inode_to_bdi(page->mapping->host);
|
struct backing_dev_info *bdi = inode_to_bdi(page->mapping->host);
|
||||||
|
|
||||||
copy_highpage(old_req->pages[0], page);
|
copy_highpage(old_req->pages[0], page);
|
||||||
|
|
|
@ -241,14 +241,6 @@ struct fuse_args {
|
||||||
|
|
||||||
#define FUSE_ARGS(args) struct fuse_args args = {}
|
#define FUSE_ARGS(args) struct fuse_args args = {}
|
||||||
|
|
||||||
/** The request state */
|
|
||||||
enum fuse_req_state {
|
|
||||||
FUSE_REQ_PENDING = 0,
|
|
||||||
FUSE_REQ_IO,
|
|
||||||
FUSE_REQ_SENT,
|
|
||||||
FUSE_REQ_FINISHED
|
|
||||||
};
|
|
||||||
|
|
||||||
/** The request IO state (for asynchronous processing) */
|
/** The request IO state (for asynchronous processing) */
|
||||||
struct fuse_io_priv {
|
struct fuse_io_priv {
|
||||||
int async;
|
int async;
|
||||||
|
@ -274,6 +266,9 @@ struct fuse_io_priv {
|
||||||
* FR_ABORTED: the request was aborted
|
* FR_ABORTED: the request was aborted
|
||||||
* FR_INTERRUPTED: the request has been interrupted
|
* FR_INTERRUPTED: the request has been interrupted
|
||||||
* FR_LOCKED: data is being copied to/from the request
|
* FR_LOCKED: data is being copied to/from the request
|
||||||
|
* FR_PENDING: request is not yet in userspace
|
||||||
|
* FR_SENT: request is in userspace, waiting for an answer
|
||||||
|
* FR_FINISHED: request is finished
|
||||||
*/
|
*/
|
||||||
enum fuse_req_flag {
|
enum fuse_req_flag {
|
||||||
FR_ISREPLY,
|
FR_ISREPLY,
|
||||||
|
@ -283,6 +278,9 @@ enum fuse_req_flag {
|
||||||
FR_ABORTED,
|
FR_ABORTED,
|
||||||
FR_INTERRUPTED,
|
FR_INTERRUPTED,
|
||||||
FR_LOCKED,
|
FR_LOCKED,
|
||||||
|
FR_PENDING,
|
||||||
|
FR_SENT,
|
||||||
|
FR_FINISHED,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -309,9 +307,6 @@ struct fuse_req {
|
||||||
/* Request flags, updated with test/set/clear_bit() */
|
/* Request flags, updated with test/set/clear_bit() */
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
/** State of the request */
|
|
||||||
enum fuse_req_state state;
|
|
||||||
|
|
||||||
/** The request input */
|
/** The request input */
|
||||||
struct fuse_in in;
|
struct fuse_in in;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue