Commit 044c7768 authored by Eric Van Hensbergen's avatar Eric Van Hensbergen
Browse files

9p: eliminate callback complexity



The current trans_fd rpc mechanisms use a dynamic callback mechanism which
introduces a lot of complexity which only accomodates a single special case.
This patch removes much of that complexity in favor of a simple exception
mechanism to deal with flushes.
Signed-off-by: default avatarEric Van Hensbergen <ericvh@gmail.com>
parent 21c00368
...@@ -105,9 +105,6 @@ enum { ...@@ -105,9 +105,6 @@ enum {
Flushed, Flushed,
}; };
struct p9_req;
typedef void (*p9_conn_req_callback)(struct p9_req *req, void *a);
/** /**
* struct p9_req - fd mux encoding of an rpc transaction * struct p9_req - fd mux encoding of an rpc transaction
* @lock: protects req_list * @lock: protects req_list
...@@ -115,8 +112,6 @@ typedef void (*p9_conn_req_callback)(struct p9_req *req, void *a); ...@@ -115,8 +112,6 @@ typedef void (*p9_conn_req_callback)(struct p9_req *req, void *a);
* @tcall: request &p9_fcall structure * @tcall: request &p9_fcall structure
* @rcall: response &p9_fcall structure * @rcall: response &p9_fcall structure
* @err: error state * @err: error state
* @cb: callback for when response is received
* @cba: argument to pass to callback
* @flush: flag to indicate RPC has been flushed * @flush: flag to indicate RPC has been flushed
* @req_list: list link for higher level objects to chain requests * @req_list: list link for higher level objects to chain requests
* @m: connection this request was issued on * @m: connection this request was issued on
...@@ -130,8 +125,6 @@ struct p9_req { ...@@ -130,8 +125,6 @@ struct p9_req {
struct p9_fcall *tcall; struct p9_fcall *tcall;
struct p9_fcall *rcall; struct p9_fcall *rcall;
int err; int err;
p9_conn_req_callback cb;
void *cba;
int flush; int flush;
struct list_head req_list; struct list_head req_list;
struct p9_conn *m; struct p9_conn *m;
...@@ -231,6 +224,65 @@ static void p9_mux_poll_stop(struct p9_conn *m) ...@@ -231,6 +224,65 @@ static void p9_mux_poll_stop(struct p9_conn *m)
spin_unlock_irqrestore(&p9_poll_lock, flags); spin_unlock_irqrestore(&p9_poll_lock, flags);
} }
static void p9_mux_free_request(struct p9_conn *m, struct p9_req *req)
{
p9_mux_put_tag(m, req->tag);
kfree(req);
}
static void p9_conn_rpc_cb(struct p9_req *req);
static void p9_mux_flush_cb(struct p9_req *freq)
{
int tag;
struct p9_conn *m = freq->m;
struct p9_req *req, *rreq, *rptr;
P9_DPRINTK(P9_DEBUG_MUX, "mux %p tc %p rc %p err %d oldtag %d\n", m,
freq->tcall, freq->rcall, freq->err,
freq->tcall->params.tflush.oldtag);
spin_lock(&m->lock);
tag = freq->tcall->params.tflush.oldtag;
req = NULL;
list_for_each_entry_safe(rreq, rptr, &m->req_list, req_list) {
if (rreq->tag == tag) {
req = rreq;
list_del(&req->req_list);
break;
}
}
spin_unlock(&m->lock);
if (req) {
spin_lock(&req->lock);
req->flush = Flushed;
spin_unlock(&req->lock);
p9_conn_rpc_cb(req);
}
kfree(freq->tcall);
kfree(freq->rcall);
p9_mux_free_request(m, freq);
}
static void p9_conn_rpc_cb(struct p9_req *req)
{
P9_DPRINTK(P9_DEBUG_MUX, "req %p\n", req);
if (req->tcall->id == P9_TFLUSH) { /* flush callback */
P9_DPRINTK(P9_DEBUG_MUX, "flush req %p\n", req);
p9_mux_flush_cb(req);
} else { /* normal wakeup path */
P9_DPRINTK(P9_DEBUG_MUX, "normal req %p\n", req);
if (req->flush != None && !req->err)
req->err = -ERESTARTSYS;
wake_up(&req->wqueue);
}
}
/** /**
* p9_conn_cancel - cancel all pending requests with error * p9_conn_cancel - cancel all pending requests with error
* @m: mux data * @m: mux data
...@@ -259,10 +311,7 @@ void p9_conn_cancel(struct p9_conn *m, int err) ...@@ -259,10 +311,7 @@ void p9_conn_cancel(struct p9_conn *m, int err)
if (!req->err) if (!req->err)
req->err = err; req->err = err;
if (req->cb) p9_conn_rpc_cb(req);
(*req->cb) (req, req->cba);
else
kfree(req->rcall);
} }
} }
...@@ -472,12 +521,8 @@ static void p9_read_work(struct work_struct *work) ...@@ -472,12 +521,8 @@ static void p9_read_work(struct work_struct *work)
req->rcall = rcall; req->rcall = rcall;
process_request(m, req); process_request(m, req);
if (req->flush != Flushing) { if (req->flush != Flushing)
if (req->cb) p9_conn_rpc_cb(req);
(*req->cb) (req, req->cba);
else
kfree(req->rcall);
}
} else { } else {
if (err >= 0 && rcall->id != P9_RFLUSH) if (err >= 0 && rcall->id != P9_RFLUSH)
P9_DPRINTK(P9_DEBUG_ERROR, P9_DPRINTK(P9_DEBUG_ERROR,
...@@ -786,14 +831,10 @@ static void p9_poll_mux(struct p9_conn *m) ...@@ -786,14 +831,10 @@ static void p9_poll_mux(struct p9_conn *m)
* *
* @m: mux data * @m: mux data
* @tc: request to be sent * @tc: request to be sent
* @cb: callback function to call when response is received
* @cba: parameter to pass to the callback function
* *
*/ */
static struct p9_req *p9_send_request(struct p9_conn *m, static struct p9_req *p9_send_request(struct p9_conn *m, struct p9_fcall *tc)
struct p9_fcall *tc,
p9_conn_req_callback cb, void *cba)
{ {
int n; int n;
struct p9_req *req; struct p9_req *req;
...@@ -835,8 +876,6 @@ static struct p9_req *p9_send_request(struct p9_conn *m, ...@@ -835,8 +876,6 @@ static struct p9_req *p9_send_request(struct p9_conn *m,
req->tcall = tc; req->tcall = tc;
req->rcall = NULL; req->rcall = NULL;
req->err = 0; req->err = 0;
req->cb = cb;
req->cba = cba;
req->flush = None; req->flush = None;
spin_lock(&m->lock); spin_lock(&m->lock);
...@@ -854,51 +893,6 @@ static struct p9_req *p9_send_request(struct p9_conn *m, ...@@ -854,51 +893,6 @@ static struct p9_req *p9_send_request(struct p9_conn *m,
return req; return req;
} }
static void p9_mux_free_request(struct p9_conn *m, struct p9_req *req)
{
p9_mux_put_tag(m, req->tag);
kfree(req);
}
static void p9_mux_flush_cb(struct p9_req *freq, void *a)
{
int tag;
struct p9_conn *m;
struct p9_req *req, *rreq, *rptr;
m = a;
P9_DPRINTK(P9_DEBUG_MUX, "mux %p tc %p rc %p err %d oldtag %d\n", m,
freq->tcall, freq->rcall, freq->err,
freq->tcall->params.tflush.oldtag);
spin_lock(&m->lock);
tag = freq->tcall->params.tflush.oldtag;
req = NULL;
list_for_each_entry_safe(rreq, rptr, &m->req_list, req_list) {
if (rreq->tag == tag) {
req = rreq;
list_del(&req->req_list);
break;
}
}
spin_unlock(&m->lock);
if (req) {
spin_lock(&req->lock);
req->flush = Flushed;
spin_unlock(&req->lock);
if (req->cb)
(*req->cb) (req, req->cba);
else
kfree(req->rcall);
}
kfree(freq->tcall);
kfree(freq->rcall);
p9_mux_free_request(m, freq);
}
static int static int
p9_mux_flush_request(struct p9_conn *m, struct p9_req *req) p9_mux_flush_request(struct p9_conn *m, struct p9_req *req)
{ {
...@@ -928,8 +922,7 @@ p9_mux_flush_request(struct p9_conn *m, struct p9_req *req) ...@@ -928,8 +922,7 @@ p9_mux_flush_request(struct p9_conn *m, struct p9_req *req)
list_del(&rreq->req_list); list_del(&rreq->req_list);
req->flush = Flushed; req->flush = Flushed;
spin_unlock(&m->lock); spin_unlock(&m->lock);
if (req->cb) p9_conn_rpc_cb(req);
(*req->cb) (req, req->cba);
return 0; return 0;
} }
} }
...@@ -937,20 +930,10 @@ p9_mux_flush_request(struct p9_conn *m, struct p9_req *req) ...@@ -937,20 +930,10 @@ p9_mux_flush_request(struct p9_conn *m, struct p9_req *req)
clear_thread_flag(TIF_SIGPENDING); clear_thread_flag(TIF_SIGPENDING);
fc = p9_create_tflush(req->tag); fc = p9_create_tflush(req->tag);
p9_send_request(m, fc, p9_mux_flush_cb, m); p9_send_request(m, fc);
return 1; return 1;
} }
static void p9_conn_rpc_cb(struct p9_req *req, void *a)
{
P9_DPRINTK(P9_DEBUG_MUX, "req %p arg %p\n", req, a);
if (req->flush != None && !req->err)
req->err = -ERESTARTSYS;
wake_up(&req->wqueue);
}
/** /**
* p9_fd_rpc- sends 9P request and waits until a response is available. * p9_fd_rpc- sends 9P request and waits until a response is available.
* The function can be interrupted. * The function can be interrupted.
...@@ -978,7 +961,7 @@ p9_fd_rpc(struct p9_client *client, struct p9_fcall *tc, struct p9_fcall **rc) ...@@ -978,7 +961,7 @@ p9_fd_rpc(struct p9_client *client, struct p9_fcall *tc, struct p9_fcall **rc)
clear_thread_flag(TIF_SIGPENDING); clear_thread_flag(TIF_SIGPENDING);
} }
req = p9_send_request(m, tc, p9_conn_rpc_cb, NULL); req = p9_send_request(m, tc);
if (IS_ERR(req)) { if (IS_ERR(req)) {
err = PTR_ERR(req); err = PTR_ERR(req);
P9_DPRINTK(P9_DEBUG_MUX, "error %d\n", err); P9_DPRINTK(P9_DEBUG_MUX, "error %d\n", err);
......
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