Skip to content

Commit

Permalink
Handle flush on working requests (issue 49).
Browse files Browse the repository at this point in the history
  • Loading branch information
garlick committed Jun 8, 2011
1 parent c28c6b9 commit c94ee3f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
12 changes: 1 addition & 11 deletions libnpfs/conn.c
Expand Up @@ -353,18 +353,8 @@ np_conn_respond(Npreq *req)
}

done:
if (req->tcall) {
free(req->tcall);
req->tcall = NULL;
}
if (req->rcall) {
free(req->rcall);
req->rcall = NULL;
}
if (conn->resetting) {
if (conn->resetting)
xpthread_cond_broadcast(&conn->resetcond);
}

if (destroy_trans) /* np_conn_read_proc will take care of resetting */
np_trans_destroy(destroy_trans);
}
Expand Down
11 changes: 10 additions & 1 deletion libnpfs/fcall.c
Expand Up @@ -257,10 +257,19 @@ np_flush(Npreq *req, Npfcall *tc)
np_conn_respond(creq);
xpthread_mutex_unlock(&creq->lock);
np_req_unref(creq);
break;
goto done;
}
}
for(creq = tp->workreqs; creq != NULL; creq = creq->next) {
if (creq->conn==req->conn && creq->tag==oldtag) {
xpthread_mutex_lock(&creq->lock);
creq->flushed = 1;
xpthread_mutex_unlock(&creq->lock);
goto done;
}
}
}
done:
xpthread_mutex_unlock(&req->conn->srv->lock);
if (!(ret = np_create_rflush ()))
np_uerror (ENOMEM);
Expand Down
1 change: 1 addition & 0 deletions libnpfs/npfs.h
Expand Up @@ -171,6 +171,7 @@ struct Npreq {
int refcount;
Npconn* conn;
u16 tag;
int flushed;
Npfcall* tcall;
Npfcall* rcall;
Npfid* fid;
Expand Down
28 changes: 19 additions & 9 deletions libnpfs/srv.c
Expand Up @@ -661,12 +661,12 @@ np_wthread_proc(void *a)
}
np_srv_remove_req(tp, req);
np_srv_add_workreq(tp, req);
req->wthread = wt;
xpthread_mutex_unlock(&tp->srv->lock);

req->wthread = wt;
rc = np_process_request(req, tp);
if (rc)
np_respond(tp, req, rc);
np_respond(tp, req, rc);

xpthread_mutex_lock(&tp->srv->lock);
}
xpthread_mutex_unlock (&tp->srv->lock);
Expand All @@ -682,17 +682,17 @@ np_respond(Nptpool *tp, Npreq *req, Npfcall *rc)
xpthread_mutex_unlock(&tp->srv->lock);

xpthread_mutex_lock(&req->lock);
if (req->fid != NULL) {
np_fid_decref(req->fid);
req->fid = NULL;
}
req->rcall = rc;
if (req->rcall) {
if (req->rcall && !req->flushed) {
np_set_tag(req->rcall, req->tag);
if (req->fid != NULL) {
np_fid_decref(req->fid);
req->fid = NULL;
}
np_conn_respond(req);
}

xpthread_mutex_unlock(&req->lock);

np_req_unref(req);
}

Expand All @@ -719,6 +719,7 @@ Npreq *np_req_alloc(Npconn *conn, Npfcall *tc) {
req->refcount = 1;
req->conn = conn;
req->tag = tc->tag;
req->flushed = 0;
req->tcall = tc;
req->rcall = NULL;
req->next = NULL;
Expand Down Expand Up @@ -754,6 +755,15 @@ np_req_unref(Npreq *req)

if (req->conn)
np_conn_decref(req->conn);
if (req->tcall) {
free (req->tcall);
req->tcall = NULL;
}
if (req->rcall) {
free (req->rcall);
req->rcall = NULL;
}
pthread_mutex_destroy (&req->lock);

xpthread_mutex_lock(&reqpool.lock);
if (reqpool.reqnum < 64) {
Expand Down

0 comments on commit c94ee3f

Please sign in to comment.