aboutsummaryrefslogtreecommitdiffstats
path: root/net/9p/trans_fd.c
diff options
context:
space:
mode:
authorEric Van Hensbergen <ericvh@gmail.com>2008-10-16 09:30:07 -0400
committerEric Van Hensbergen <ericvh@gmail.com>2008-10-17 12:04:45 -0400
commit51a87c552dfd428e304c865e24ecbe091556f226 (patch)
tree6e9012962e6601b559dcf15ae3228647a8581a31 /net/9p/trans_fd.c
parentcb198131b0e7aba755ac164744536d461e86ab82 (diff)
9p: rework client code to use new protocol support functions
Now that the new protocol functions are in place, this patch switches the client code to using the new support code. Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
Diffstat (limited to 'net/9p/trans_fd.c')
-rw-r--r--net/9p/trans_fd.c62
1 files changed, 28 insertions, 34 deletions
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
index e147ec539585..e8ebe2cb7e8b 100644
--- a/net/9p/trans_fd.c
+++ b/net/9p/trans_fd.c
@@ -181,7 +181,7 @@ static void p9_mux_poll_stop(struct p9_conn *m)
181 * 181 *
182 */ 182 */
183 183
184void p9_conn_cancel(struct p9_conn *m, int err) 184static void p9_conn_cancel(struct p9_conn *m, int err)
185{ 185{
186 struct p9_req_t *req, *rtmp; 186 struct p9_req_t *req, *rtmp;
187 unsigned long flags; 187 unsigned long flags;
@@ -287,7 +287,7 @@ static void p9_read_work(struct work_struct *work)
287 if (m->err < 0) 287 if (m->err < 0)
288 return; 288 return;
289 289
290 P9_DPRINTK(P9_DEBUG_MUX, "start mux %p pos %d\n", m, m->rpos); 290 P9_DPRINTK(P9_DEBUG_TRANS, "start mux %p pos %d\n", m, m->rpos);
291 291
292 if (!m->rbuf) { 292 if (!m->rbuf) {
293 m->rbuf = m->tmp_buf; 293 m->rbuf = m->tmp_buf;
@@ -296,11 +296,11 @@ static void p9_read_work(struct work_struct *work)
296 } 296 }
297 297
298 clear_bit(Rpending, &m->wsched); 298 clear_bit(Rpending, &m->wsched);
299 P9_DPRINTK(P9_DEBUG_MUX, "read mux %p pos %d size: %d = %d\n", m, 299 P9_DPRINTK(P9_DEBUG_TRANS, "read mux %p pos %d size: %d = %d\n", m,
300 m->rpos, m->rsize, m->rsize-m->rpos); 300 m->rpos, m->rsize, m->rsize-m->rpos);
301 err = p9_fd_read(m->client, m->rbuf + m->rpos, 301 err = p9_fd_read(m->client, m->rbuf + m->rpos,
302 m->rsize - m->rpos); 302 m->rsize - m->rpos);
303 P9_DPRINTK(P9_DEBUG_MUX, "mux %p got %d bytes\n", m, err); 303 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p got %d bytes\n", m, err);
304 if (err == -EAGAIN) { 304 if (err == -EAGAIN) {
305 clear_bit(Rworksched, &m->wsched); 305 clear_bit(Rworksched, &m->wsched);
306 return; 306 return;
@@ -313,7 +313,7 @@ static void p9_read_work(struct work_struct *work)
313 313
314 if ((!m->req) && (m->rpos == m->rsize)) { /* header read in */ 314 if ((!m->req) && (m->rpos == m->rsize)) { /* header read in */
315 u16 tag; 315 u16 tag;
316 P9_DPRINTK(P9_DEBUG_MUX, "got new header\n"); 316 P9_DPRINTK(P9_DEBUG_TRANS, "got new header\n");
317 317
318 n = le32_to_cpu(*(__le32 *) m->rbuf); /* read packet size */ 318 n = le32_to_cpu(*(__le32 *) m->rbuf); /* read packet size */
319 if (n >= m->client->msize) { 319 if (n >= m->client->msize) {
@@ -324,8 +324,8 @@ static void p9_read_work(struct work_struct *work)
324 } 324 }
325 325
326 tag = le16_to_cpu(*(__le16 *) (m->rbuf+5)); /* read tag */ 326 tag = le16_to_cpu(*(__le16 *) (m->rbuf+5)); /* read tag */
327 P9_DPRINTK(P9_DEBUG_MUX, "mux %p pkt: size: %d bytes tag: %d\n", 327 P9_DPRINTK(P9_DEBUG_TRANS,
328 m, n, tag); 328 "mux %p pkt: size: %d bytes tag: %d\n", m, n, tag);
329 329
330 m->req = p9_tag_lookup(m->client, tag); 330 m->req = p9_tag_lookup(m->client, tag);
331 if (!m->req) { 331 if (!m->req) {
@@ -351,7 +351,7 @@ static void p9_read_work(struct work_struct *work)
351 351
352 /* not an else because some packets (like clunk) have no payload */ 352 /* not an else because some packets (like clunk) have no payload */
353 if ((m->req) && (m->rpos == m->rsize)) { /* packet is read in */ 353 if ((m->req) && (m->rpos == m->rsize)) { /* packet is read in */
354 P9_DPRINTK(P9_DEBUG_MUX, "got new packet\n"); 354 P9_DPRINTK(P9_DEBUG_TRANS, "got new packet\n");
355 355
356 list_del(&m->req->req_list); 356 list_del(&m->req->req_list);
357 p9_client_cb(m->client, m->req); 357 p9_client_cb(m->client, m->req);
@@ -369,7 +369,7 @@ static void p9_read_work(struct work_struct *work)
369 n = p9_fd_poll(m->client, NULL); 369 n = p9_fd_poll(m->client, NULL);
370 370
371 if (n & POLLIN) { 371 if (n & POLLIN) {
372 P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m); 372 P9_DPRINTK(P9_DEBUG_TRANS, "sched read work %p\n", m);
373 queue_work(p9_mux_wq, &m->rq); 373 queue_work(p9_mux_wq, &m->rq);
374 } else 374 } else
375 clear_bit(Rworksched, &m->wsched); 375 clear_bit(Rworksched, &m->wsched);
@@ -453,11 +453,11 @@ static void p9_write_work(struct work_struct *work)
453 spin_unlock(&m->client->lock); 453 spin_unlock(&m->client->lock);
454 } 454 }
455 455
456 P9_DPRINTK(P9_DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos, 456 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p pos %d size %d\n", m, m->wpos,
457 m->wsize); 457 m->wsize);
458 clear_bit(Wpending, &m->wsched); 458 clear_bit(Wpending, &m->wsched);
459 err = p9_fd_write(m->client, m->wbuf + m->wpos, m->wsize - m->wpos); 459 err = p9_fd_write(m->client, m->wbuf + m->wpos, m->wsize - m->wpos);
460 P9_DPRINTK(P9_DEBUG_MUX, "mux %p sent %d bytes\n", m, err); 460 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p sent %d bytes\n", m, err);
461 if (err == -EAGAIN) { 461 if (err == -EAGAIN) {
462 clear_bit(Wworksched, &m->wsched); 462 clear_bit(Wworksched, &m->wsched);
463 return; 463 return;
@@ -481,7 +481,7 @@ static void p9_write_work(struct work_struct *work)
481 n = p9_fd_poll(m->client, NULL); 481 n = p9_fd_poll(m->client, NULL);
482 482
483 if (n & POLLOUT) { 483 if (n & POLLOUT) {
484 P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m); 484 P9_DPRINTK(P9_DEBUG_TRANS, "sched write work %p\n", m);
485 queue_work(p9_mux_wq, &m->wq); 485 queue_work(p9_mux_wq, &m->wq);
486 } else 486 } else
487 clear_bit(Wworksched, &m->wsched); 487 clear_bit(Wworksched, &m->wsched);
@@ -558,7 +558,8 @@ static struct p9_conn *p9_conn_create(struct p9_client *client)
558 int n; 558 int n;
559 struct p9_conn *m; 559 struct p9_conn *m;
560 560
561 P9_DPRINTK(P9_DEBUG_MUX, "client %p msize %d\n", client, client->msize); 561 P9_DPRINTK(P9_DEBUG_TRANS, "client %p msize %d\n", client,
562 client->msize);
562 m = kzalloc(sizeof(struct p9_conn), GFP_KERNEL); 563 m = kzalloc(sizeof(struct p9_conn), GFP_KERNEL);
563 if (!m) 564 if (!m)
564 return ERR_PTR(-ENOMEM); 565 return ERR_PTR(-ENOMEM);
@@ -575,12 +576,12 @@ static struct p9_conn *p9_conn_create(struct p9_client *client)
575 576
576 n = p9_fd_poll(client, &m->pt); 577 n = p9_fd_poll(client, &m->pt);
577 if (n & POLLIN) { 578 if (n & POLLIN) {
578 P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m); 579 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p can read\n", m);
579 set_bit(Rpending, &m->wsched); 580 set_bit(Rpending, &m->wsched);
580 } 581 }
581 582
582 if (n & POLLOUT) { 583 if (n & POLLOUT) {
583 P9_DPRINTK(P9_DEBUG_MUX, "mux %p can write\n", m); 584 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p can write\n", m);
584 set_bit(Wpending, &m->wsched); 585 set_bit(Wpending, &m->wsched);
585 } 586 }
586 587
@@ -602,7 +603,7 @@ static void p9_poll_mux(struct p9_conn *m)
602 603
603 n = p9_fd_poll(m->client, NULL); 604 n = p9_fd_poll(m->client, NULL);
604 if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) { 605 if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) {
605 P9_DPRINTK(P9_DEBUG_MUX, "error mux %p err %d\n", m, n); 606 P9_DPRINTK(P9_DEBUG_TRANS, "error mux %p err %d\n", m, n);
606 if (n >= 0) 607 if (n >= 0)
607 n = -ECONNRESET; 608 n = -ECONNRESET;
608 p9_conn_cancel(m, n); 609 p9_conn_cancel(m, n);
@@ -610,19 +611,19 @@ static void p9_poll_mux(struct p9_conn *m)
610 611
611 if (n & POLLIN) { 612 if (n & POLLIN) {
612 set_bit(Rpending, &m->wsched); 613 set_bit(Rpending, &m->wsched);
613 P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m); 614 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p can read\n", m);
614 if (!test_and_set_bit(Rworksched, &m->wsched)) { 615 if (!test_and_set_bit(Rworksched, &m->wsched)) {
615 P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m); 616 P9_DPRINTK(P9_DEBUG_TRANS, "sched read work %p\n", m);
616 queue_work(p9_mux_wq, &m->rq); 617 queue_work(p9_mux_wq, &m->rq);
617 } 618 }
618 } 619 }
619 620
620 if (n & POLLOUT) { 621 if (n & POLLOUT) {
621 set_bit(Wpending, &m->wsched); 622 set_bit(Wpending, &m->wsched);
622 P9_DPRINTK(P9_DEBUG_MUX, "mux %p can write\n", m); 623 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p can write\n", m);
623 if ((m->wsize || !list_empty(&m->unsent_req_list)) 624 if ((m->wsize || !list_empty(&m->unsent_req_list))
624 && !test_and_set_bit(Wworksched, &m->wsched)) { 625 && !test_and_set_bit(Wworksched, &m->wsched)) {
625 P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m); 626 P9_DPRINTK(P9_DEBUG_TRANS, "sched write work %p\n", m);
626 queue_work(p9_mux_wq, &m->wq); 627 queue_work(p9_mux_wq, &m->wq);
627 } 628 }
628 } 629 }
@@ -645,8 +646,8 @@ static int p9_fd_request(struct p9_client *client, struct p9_req_t *req)
645 struct p9_trans_fd *ts = client->trans; 646 struct p9_trans_fd *ts = client->trans;
646 struct p9_conn *m = ts->conn; 647 struct p9_conn *m = ts->conn;
647 648
648 P9_DPRINTK(P9_DEBUG_MUX, "mux %p task %p tcall %p id %d\n", m, current, 649 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p task %p tcall %p id %d\n", m,
649 req->tc, req->tc->id); 650 current, req->tc, req->tc->id);
650 if (m->err < 0) 651 if (m->err < 0)
651 return m->err; 652 return m->err;
652 653
@@ -672,19 +673,12 @@ static int p9_fd_cancel(struct p9_client *client, struct p9_req_t *req)
672 struct p9_trans_fd *ts = client->trans; 673 struct p9_trans_fd *ts = client->trans;
673 struct p9_conn *m = ts->conn; 674 struct p9_conn *m = ts->conn;
674 675
675 P9_DPRINTK(P9_DEBUG_MUX, "mux %p req %p\n", m, req); 676 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p req %p\n", m, req);
676 677
677 spin_lock(&client->lock); 678 spin_lock(&client->lock);
678 list_del(&req->req_list); 679 list_del(&req->req_list);
679 spin_unlock(&client->lock); 680 spin_unlock(&client->lock);
680 681
681 /* if a response was received for a request, do nothing */
682 if (req->rc || req->t_err) {
683 P9_DPRINTK(P9_DEBUG_MUX,
684 "mux %p req %p response already received\n", m, req);
685 return 0;
686 }
687
688 if (req->status == REQ_STATUS_UNSENT) { 682 if (req->status == REQ_STATUS_UNSENT) {
689 req->status = REQ_STATUS_FLSHD; 683 req->status = REQ_STATUS_FLSHD;
690 return 0; 684 return 0;
@@ -809,7 +803,7 @@ static int p9_socket_open(struct p9_client *client, struct socket *csocket)
809 803
810static void p9_conn_destroy(struct p9_conn *m) 804static void p9_conn_destroy(struct p9_conn *m)
811{ 805{
812 P9_DPRINTK(P9_DEBUG_MUX, "mux %p prev %p next %p\n", m, 806 P9_DPRINTK(P9_DEBUG_TRANS, "mux %p prev %p next %p\n", m,
813 m->mux_list.prev, m->mux_list.next); 807 m->mux_list.prev, m->mux_list.next);
814 808
815 p9_mux_poll_stop(m); 809 p9_mux_poll_stop(m);
@@ -1060,7 +1054,7 @@ static int p9_poll_proc(void *a)
1060{ 1054{
1061 unsigned long flags; 1055 unsigned long flags;
1062 1056
1063 P9_DPRINTK(P9_DEBUG_MUX, "start %p\n", current); 1057 P9_DPRINTK(P9_DEBUG_TRANS, "start %p\n", current);
1064 repeat: 1058 repeat:
1065 spin_lock_irqsave(&p9_poll_lock, flags); 1059 spin_lock_irqsave(&p9_poll_lock, flags);
1066 while (!list_empty(&p9_poll_pending_list)) { 1060 while (!list_empty(&p9_poll_pending_list)) {
@@ -1078,7 +1072,7 @@ static int p9_poll_proc(void *a)
1078 1072
1079 set_current_state(TASK_INTERRUPTIBLE); 1073 set_current_state(TASK_INTERRUPTIBLE);
1080 if (list_empty(&p9_poll_pending_list)) { 1074 if (list_empty(&p9_poll_pending_list)) {
1081 P9_DPRINTK(P9_DEBUG_MUX, "sleeping...\n"); 1075 P9_DPRINTK(P9_DEBUG_TRANS, "sleeping...\n");
1082 schedule(); 1076 schedule();
1083 } 1077 }
1084 __set_current_state(TASK_RUNNING); 1078 __set_current_state(TASK_RUNNING);
@@ -1086,7 +1080,7 @@ static int p9_poll_proc(void *a)
1086 if (!kthread_should_stop()) 1080 if (!kthread_should_stop())
1087 goto repeat; 1081 goto repeat;
1088 1082
1089 P9_DPRINTK(P9_DEBUG_MUX, "finish\n"); 1083 P9_DPRINTK(P9_DEBUG_TRANS, "finish\n");
1090 return 0; 1084 return 0;
1091} 1085}
1092 1086