Commit 64c6d8ed authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Linus Torvalds

[PATCH] fuse: add asynchronous request support

Add possibility for requests to run asynchronously and call an 'end' callback
when finished.

With this, the special handling of the INIT and RELEASE requests can be
cleaned up too.
Signed-off-by: default avatarMiklos Szeredi <miklos@szeredi.hu>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 69a53bf2
...@@ -172,6 +172,8 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req) ...@@ -172,6 +172,8 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
fuse_putback_request() */ fuse_putback_request() */
for (i = 1; i < FUSE_MAX_OUTSTANDING; i++) for (i = 1; i < FUSE_MAX_OUTSTANDING; i++)
up(&fc->outstanding_sem); up(&fc->outstanding_sem);
fuse_put_request(fc, req);
} }
/* /*
...@@ -180,13 +182,15 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req) ...@@ -180,13 +182,15 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
* occurred during communication with userspace, or the device file * occurred during communication with userspace, or the device file
* was closed. In case of a background request the reference to the * was closed. In case of a background request the reference to the
* stored objects are released. The requester thread is woken up (if * stored objects are released. The requester thread is woken up (if
* still waiting), and finally the reference to the request is * still waiting), the 'end' callback is called if given, else the
* released * reference to the request is released
* *
* Called with fuse_lock, unlocks it * Called with fuse_lock, unlocks it
*/ */
static void request_end(struct fuse_conn *fc, struct fuse_req *req) static void request_end(struct fuse_conn *fc, struct fuse_req *req)
{ {
void (*end) (struct fuse_conn *, struct fuse_req *) = req->end;
req->end = NULL;
list_del(&req->list); list_del(&req->list);
req->state = FUSE_REQ_FINISHED; req->state = FUSE_REQ_FINISHED;
spin_unlock(&fuse_lock); spin_unlock(&fuse_lock);
...@@ -197,15 +201,9 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req) ...@@ -197,15 +201,9 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
up_read(&fc->sbput_sem); up_read(&fc->sbput_sem);
} }
wake_up(&req->waitq); wake_up(&req->waitq);
if (req->in.h.opcode == FUSE_INIT) if (end)
process_init_reply(fc, req); end(fc, req);
else if (req->in.h.opcode == FUSE_RELEASE && req->inode == NULL) { else
/* Special case for failed iget in CREATE */
u64 nodeid = req->in.h.nodeid;
fuse_reset_request(req);
fuse_send_forget(fc, req, nodeid, 1);
return;
}
fuse_put_request(fc, req); fuse_put_request(fc, req);
} }
...@@ -387,6 +385,7 @@ void fuse_send_init(struct fuse_conn *fc) ...@@ -387,6 +385,7 @@ void fuse_send_init(struct fuse_conn *fc)
req->out.argvar = 1; req->out.argvar = 1;
req->out.args[0].size = sizeof(struct fuse_init_out); req->out.args[0].size = sizeof(struct fuse_init_out);
req->out.args[0].value = &req->misc.init_out; req->out.args[0].value = &req->misc.init_out;
req->end = process_init_reply;
request_send_background(fc, req); request_send_background(fc, req);
} }
...@@ -864,17 +863,32 @@ static void end_requests(struct fuse_conn *fc, struct list_head *head) ...@@ -864,17 +863,32 @@ static void end_requests(struct fuse_conn *fc, struct list_head *head)
* The requests are set to interrupted and finished, and the request * The requests are set to interrupted and finished, and the request
* waiter is woken up. This will make request_wait_answer() wait * waiter is woken up. This will make request_wait_answer() wait
* until the request is unlocked and then return. * until the request is unlocked and then return.
*
* If the request is asynchronous, then the end function needs to be
* called after waiting for the request to be unlocked (if it was
* locked).
*/ */
static void end_io_requests(struct fuse_conn *fc) static void end_io_requests(struct fuse_conn *fc)
{ {
while (!list_empty(&fc->io)) { while (!list_empty(&fc->io)) {
struct fuse_req *req; struct fuse_req *req =
req = list_entry(fc->io.next, struct fuse_req, list); list_entry(fc->io.next, struct fuse_req, list);
void (*end) (struct fuse_conn *, struct fuse_req *) = req->end;
req->interrupted = 1; req->interrupted = 1;
req->out.h.error = -ECONNABORTED; req->out.h.error = -ECONNABORTED;
req->state = FUSE_REQ_FINISHED; req->state = FUSE_REQ_FINISHED;
list_del_init(&req->list); list_del_init(&req->list);
wake_up(&req->waitq); wake_up(&req->waitq);
if (end) {
req->end = NULL;
/* The end function will consume this reference */
__fuse_get_request(req);
spin_unlock(&fuse_lock);
wait_event(req->waitq, !req->locked);
end(fc, req);
spin_lock(&fuse_lock);
}
} }
} }
......
...@@ -113,6 +113,14 @@ int fuse_open_common(struct inode *inode, struct file *file, int isdir) ...@@ -113,6 +113,14 @@ int fuse_open_common(struct inode *inode, struct file *file, int isdir)
return err; return err;
} }
/* Special case for failed iget in CREATE */
static void fuse_release_end(struct fuse_conn *fc, struct fuse_req *req)
{
u64 nodeid = req->in.h.nodeid;
fuse_reset_request(req);
fuse_send_forget(fc, req, nodeid, 1);
}
void fuse_send_release(struct fuse_conn *fc, struct fuse_file *ff, void fuse_send_release(struct fuse_conn *fc, struct fuse_file *ff,
u64 nodeid, struct inode *inode, int flags, int isdir) u64 nodeid, struct inode *inode, int flags, int isdir)
{ {
...@@ -128,6 +136,8 @@ void fuse_send_release(struct fuse_conn *fc, struct fuse_file *ff, ...@@ -128,6 +136,8 @@ void fuse_send_release(struct fuse_conn *fc, struct fuse_file *ff,
req->in.args[0].size = sizeof(struct fuse_release_in); req->in.args[0].size = sizeof(struct fuse_release_in);
req->in.args[0].value = inarg; req->in.args[0].value = inarg;
request_send_background(fc, req); request_send_background(fc, req);
if (!inode)
req->end = fuse_release_end;
kfree(ff); kfree(ff);
} }
......
...@@ -120,6 +120,8 @@ enum fuse_req_state { ...@@ -120,6 +120,8 @@ enum fuse_req_state {
FUSE_REQ_FINISHED FUSE_REQ_FINISHED
}; };
struct fuse_conn;
/** /**
* A request to the client * A request to the client
*/ */
...@@ -186,6 +188,9 @@ struct fuse_req { ...@@ -186,6 +188,9 @@ struct fuse_req {
/** File used in the request (or NULL) */ /** File used in the request (or NULL) */
struct file *file; struct file *file;
/** Request completion callback */
void (*end)(struct fuse_conn *, struct fuse_req *);
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment