diff options
Diffstat (limited to 'net/9p/trans_fd.c')
-rw-r--r-- | net/9p/trans_fd.c | 104 |
1 files changed, 36 insertions, 68 deletions
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index cdf137af7adc..d652baf5ff91 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c | |||
@@ -151,7 +151,6 @@ struct p9_mux_poll_task { | |||
151 | * @trans: reference to transport instance for this connection | 151 | * @trans: reference to transport instance for this connection |
152 | * @tagpool: id accounting for transactions | 152 | * @tagpool: id accounting for transactions |
153 | * @err: error state | 153 | * @err: error state |
154 | * @equeue: event wait_q (?) | ||
155 | * @req_list: accounting for requests which have been sent | 154 | * @req_list: accounting for requests which have been sent |
156 | * @unsent_req_list: accounting for requests that haven't been sent | 155 | * @unsent_req_list: accounting for requests that haven't been sent |
157 | * @rcall: current response &p9_fcall structure | 156 | * @rcall: current response &p9_fcall structure |
@@ -178,7 +177,6 @@ struct p9_conn { | |||
178 | struct p9_trans *trans; | 177 | struct p9_trans *trans; |
179 | struct p9_idpool *tagpool; | 178 | struct p9_idpool *tagpool; |
180 | int err; | 179 | int err; |
181 | wait_queue_head_t equeue; | ||
182 | struct list_head req_list; | 180 | struct list_head req_list; |
183 | struct list_head unsent_req_list; | 181 | struct list_head unsent_req_list; |
184 | struct p9_fcall *rcall; | 182 | struct p9_fcall *rcall; |
@@ -240,22 +238,6 @@ static int p9_conn_rpcnb(struct p9_conn *m, struct p9_fcall *tc, | |||
240 | 238 | ||
241 | static void p9_conn_cancel(struct p9_conn *m, int err); | 239 | static void p9_conn_cancel(struct p9_conn *m, int err); |
242 | 240 | ||
243 | static int p9_mux_global_init(void) | ||
244 | { | ||
245 | int i; | ||
246 | |||
247 | for (i = 0; i < ARRAY_SIZE(p9_mux_poll_tasks); i++) | ||
248 | p9_mux_poll_tasks[i].task = NULL; | ||
249 | |||
250 | p9_mux_wq = create_workqueue("v9fs"); | ||
251 | if (!p9_mux_wq) { | ||
252 | printk(KERN_WARNING "v9fs: mux: creating workqueue failed\n"); | ||
253 | return -ENOMEM; | ||
254 | } | ||
255 | |||
256 | return 0; | ||
257 | } | ||
258 | |||
259 | static u16 p9_mux_get_tag(struct p9_conn *m) | 241 | static u16 p9_mux_get_tag(struct p9_conn *m) |
260 | { | 242 | { |
261 | int tag; | 243 | int tag; |
@@ -409,11 +391,11 @@ static void p9_mux_poll_stop(struct p9_conn *m) | |||
409 | static struct p9_conn *p9_conn_create(struct p9_trans *trans) | 391 | static struct p9_conn *p9_conn_create(struct p9_trans *trans) |
410 | { | 392 | { |
411 | int i, n; | 393 | int i, n; |
412 | struct p9_conn *m, *mtmp; | 394 | struct p9_conn *m; |
413 | 395 | ||
414 | P9_DPRINTK(P9_DEBUG_MUX, "transport %p msize %d\n", trans, | 396 | P9_DPRINTK(P9_DEBUG_MUX, "transport %p msize %d\n", trans, |
415 | trans->msize); | 397 | trans->msize); |
416 | m = kmalloc(sizeof(struct p9_conn), GFP_KERNEL); | 398 | m = kzalloc(sizeof(struct p9_conn), GFP_KERNEL); |
417 | if (!m) | 399 | if (!m) |
418 | return ERR_PTR(-ENOMEM); | 400 | return ERR_PTR(-ENOMEM); |
419 | 401 | ||
@@ -424,25 +406,14 @@ static struct p9_conn *p9_conn_create(struct p9_trans *trans) | |||
424 | m->trans = trans; | 406 | m->trans = trans; |
425 | m->tagpool = p9_idpool_create(); | 407 | m->tagpool = p9_idpool_create(); |
426 | if (IS_ERR(m->tagpool)) { | 408 | if (IS_ERR(m->tagpool)) { |
427 | mtmp = ERR_PTR(-ENOMEM); | ||
428 | kfree(m); | 409 | kfree(m); |
429 | return mtmp; | 410 | return ERR_PTR(-ENOMEM); |
430 | } | 411 | } |
431 | 412 | ||
432 | m->err = 0; | ||
433 | init_waitqueue_head(&m->equeue); | ||
434 | INIT_LIST_HEAD(&m->req_list); | 413 | INIT_LIST_HEAD(&m->req_list); |
435 | INIT_LIST_HEAD(&m->unsent_req_list); | 414 | INIT_LIST_HEAD(&m->unsent_req_list); |
436 | m->rcall = NULL; | ||
437 | m->rpos = 0; | ||
438 | m->rbuf = NULL; | ||
439 | m->wpos = m->wsize = 0; | ||
440 | m->wbuf = NULL; | ||
441 | INIT_WORK(&m->rq, p9_read_work); | 415 | INIT_WORK(&m->rq, p9_read_work); |
442 | INIT_WORK(&m->wq, p9_write_work); | 416 | INIT_WORK(&m->wq, p9_write_work); |
443 | m->wsched = 0; | ||
444 | memset(&m->poll_waddr, 0, sizeof(m->poll_waddr)); | ||
445 | m->poll_task = NULL; | ||
446 | n = p9_mux_poll_start(m); | 417 | n = p9_mux_poll_start(m); |
447 | if (n) { | 418 | if (n) { |
448 | kfree(m); | 419 | kfree(m); |
@@ -463,10 +434,8 @@ static struct p9_conn *p9_conn_create(struct p9_trans *trans) | |||
463 | for (i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) { | 434 | for (i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) { |
464 | if (IS_ERR(m->poll_waddr[i])) { | 435 | if (IS_ERR(m->poll_waddr[i])) { |
465 | p9_mux_poll_stop(m); | 436 | p9_mux_poll_stop(m); |
466 | mtmp = (void *)m->poll_waddr; /* the error code */ | ||
467 | kfree(m); | 437 | kfree(m); |
468 | m = mtmp; | 438 | return (void *)m->poll_waddr; /* the error code */ |
469 | break; | ||
470 | } | 439 | } |
471 | } | 440 | } |
472 | 441 | ||
@@ -483,18 +452,13 @@ static void p9_conn_destroy(struct p9_conn *m) | |||
483 | { | 452 | { |
484 | P9_DPRINTK(P9_DEBUG_MUX, "mux %p prev %p next %p\n", m, | 453 | P9_DPRINTK(P9_DEBUG_MUX, "mux %p prev %p next %p\n", m, |
485 | m->mux_list.prev, m->mux_list.next); | 454 | m->mux_list.prev, m->mux_list.next); |
486 | p9_conn_cancel(m, -ECONNRESET); | ||
487 | |||
488 | if (!list_empty(&m->req_list)) { | ||
489 | /* wait until all processes waiting on this session exit */ | ||
490 | P9_DPRINTK(P9_DEBUG_MUX, | ||
491 | "mux %p waiting for empty request queue\n", m); | ||
492 | wait_event_timeout(m->equeue, (list_empty(&m->req_list)), 5000); | ||
493 | P9_DPRINTK(P9_DEBUG_MUX, "mux %p request queue empty: %d\n", m, | ||
494 | list_empty(&m->req_list)); | ||
495 | } | ||
496 | 455 | ||
497 | p9_mux_poll_stop(m); | 456 | p9_mux_poll_stop(m); |
457 | cancel_work_sync(&m->rq); | ||
458 | cancel_work_sync(&m->wq); | ||
459 | |||
460 | p9_conn_cancel(m, -ECONNRESET); | ||
461 | |||
498 | m->trans = NULL; | 462 | m->trans = NULL; |
499 | p9_idpool_destroy(m->tagpool); | 463 | p9_idpool_destroy(m->tagpool); |
500 | kfree(m); | 464 | kfree(m); |
@@ -840,8 +804,6 @@ static void p9_read_work(struct work_struct *work) | |||
840 | (*req->cb) (req, req->cba); | 804 | (*req->cb) (req, req->cba); |
841 | else | 805 | else |
842 | kfree(req->rcall); | 806 | kfree(req->rcall); |
843 | |||
844 | wake_up(&m->equeue); | ||
845 | } | 807 | } |
846 | } else { | 808 | } else { |
847 | if (err >= 0 && rcall->id != P9_RFLUSH) | 809 | if (err >= 0 && rcall->id != P9_RFLUSH) |
@@ -908,8 +870,10 @@ static struct p9_req *p9_send_request(struct p9_conn *m, | |||
908 | else | 870 | else |
909 | n = p9_mux_get_tag(m); | 871 | n = p9_mux_get_tag(m); |
910 | 872 | ||
911 | if (n < 0) | 873 | if (n < 0) { |
874 | kfree(req); | ||
912 | return ERR_PTR(-ENOMEM); | 875 | return ERR_PTR(-ENOMEM); |
876 | } | ||
913 | 877 | ||
914 | p9_set_tag(tc, n); | 878 | p9_set_tag(tc, n); |
915 | 879 | ||
@@ -984,8 +948,6 @@ static void p9_mux_flush_cb(struct p9_req *freq, void *a) | |||
984 | (*req->cb) (req, req->cba); | 948 | (*req->cb) (req, req->cba); |
985 | else | 949 | else |
986 | kfree(req->rcall); | 950 | kfree(req->rcall); |
987 | |||
988 | wake_up(&m->equeue); | ||
989 | } | 951 | } |
990 | 952 | ||
991 | kfree(freq->tcall); | 953 | kfree(freq->tcall); |
@@ -1191,8 +1153,6 @@ void p9_conn_cancel(struct p9_conn *m, int err) | |||
1191 | else | 1153 | else |
1192 | kfree(req->rcall); | 1154 | kfree(req->rcall); |
1193 | } | 1155 | } |
1194 | |||
1195 | wake_up(&m->equeue); | ||
1196 | } | 1156 | } |
1197 | 1157 | ||
1198 | /** | 1158 | /** |
@@ -1370,7 +1330,6 @@ p9_fd_poll(struct p9_trans *trans, struct poll_table_struct *pt) | |||
1370 | { | 1330 | { |
1371 | int ret, n; | 1331 | int ret, n; |
1372 | struct p9_trans_fd *ts = NULL; | 1332 | struct p9_trans_fd *ts = NULL; |
1373 | mm_segment_t oldfs; | ||
1374 | 1333 | ||
1375 | if (trans && trans->status == Connected) | 1334 | if (trans && trans->status == Connected) |
1376 | ts = trans->priv; | 1335 | ts = trans->priv; |
@@ -1384,24 +1343,17 @@ p9_fd_poll(struct p9_trans *trans, struct poll_table_struct *pt) | |||
1384 | if (!ts->wr->f_op || !ts->wr->f_op->poll) | 1343 | if (!ts->wr->f_op || !ts->wr->f_op->poll) |
1385 | return -EIO; | 1344 | return -EIO; |
1386 | 1345 | ||
1387 | oldfs = get_fs(); | ||
1388 | set_fs(get_ds()); | ||
1389 | |||
1390 | ret = ts->rd->f_op->poll(ts->rd, pt); | 1346 | ret = ts->rd->f_op->poll(ts->rd, pt); |
1391 | if (ret < 0) | 1347 | if (ret < 0) |
1392 | goto end; | 1348 | return ret; |
1393 | 1349 | ||
1394 | if (ts->rd != ts->wr) { | 1350 | if (ts->rd != ts->wr) { |
1395 | n = ts->wr->f_op->poll(ts->wr, pt); | 1351 | n = ts->wr->f_op->poll(ts->wr, pt); |
1396 | if (n < 0) { | 1352 | if (n < 0) |
1397 | ret = n; | 1353 | return n; |
1398 | goto end; | ||
1399 | } | ||
1400 | ret = (ret & ~POLLOUT) | (n & ~POLLIN); | 1354 | ret = (ret & ~POLLOUT) | (n & ~POLLIN); |
1401 | } | 1355 | } |
1402 | 1356 | ||
1403 | end: | ||
1404 | set_fs(oldfs); | ||
1405 | return ret; | 1357 | return ret; |
1406 | } | 1358 | } |
1407 | 1359 | ||
@@ -1629,6 +1581,7 @@ static struct p9_trans_module p9_tcp_trans = { | |||
1629 | .maxsize = MAX_SOCK_BUF, | 1581 | .maxsize = MAX_SOCK_BUF, |
1630 | .def = 1, | 1582 | .def = 1, |
1631 | .create = p9_trans_create_tcp, | 1583 | .create = p9_trans_create_tcp, |
1584 | .owner = THIS_MODULE, | ||
1632 | }; | 1585 | }; |
1633 | 1586 | ||
1634 | static struct p9_trans_module p9_unix_trans = { | 1587 | static struct p9_trans_module p9_unix_trans = { |
@@ -1636,6 +1589,7 @@ static struct p9_trans_module p9_unix_trans = { | |||
1636 | .maxsize = MAX_SOCK_BUF, | 1589 | .maxsize = MAX_SOCK_BUF, |
1637 | .def = 0, | 1590 | .def = 0, |
1638 | .create = p9_trans_create_unix, | 1591 | .create = p9_trans_create_unix, |
1592 | .owner = THIS_MODULE, | ||
1639 | }; | 1593 | }; |
1640 | 1594 | ||
1641 | static struct p9_trans_module p9_fd_trans = { | 1595 | static struct p9_trans_module p9_fd_trans = { |
@@ -1643,14 +1597,20 @@ static struct p9_trans_module p9_fd_trans = { | |||
1643 | .maxsize = MAX_SOCK_BUF, | 1597 | .maxsize = MAX_SOCK_BUF, |
1644 | .def = 0, | 1598 | .def = 0, |
1645 | .create = p9_trans_create_fd, | 1599 | .create = p9_trans_create_fd, |
1600 | .owner = THIS_MODULE, | ||
1646 | }; | 1601 | }; |
1647 | 1602 | ||
1648 | int p9_trans_fd_init(void) | 1603 | int p9_trans_fd_init(void) |
1649 | { | 1604 | { |
1650 | int ret = p9_mux_global_init(); | 1605 | int i; |
1651 | if (ret) { | 1606 | |
1652 | printk(KERN_WARNING "9p: starting mux failed\n"); | 1607 | for (i = 0; i < ARRAY_SIZE(p9_mux_poll_tasks); i++) |
1653 | return ret; | 1608 | p9_mux_poll_tasks[i].task = NULL; |
1609 | |||
1610 | p9_mux_wq = create_workqueue("v9fs"); | ||
1611 | if (!p9_mux_wq) { | ||
1612 | printk(KERN_WARNING "v9fs: mux: creating workqueue failed\n"); | ||
1613 | return -ENOMEM; | ||
1654 | } | 1614 | } |
1655 | 1615 | ||
1656 | v9fs_register_trans(&p9_tcp_trans); | 1616 | v9fs_register_trans(&p9_tcp_trans); |
@@ -1659,4 +1619,12 @@ int p9_trans_fd_init(void) | |||
1659 | 1619 | ||
1660 | return 0; | 1620 | return 0; |
1661 | } | 1621 | } |
1662 | EXPORT_SYMBOL(p9_trans_fd_init); | 1622 | |
1623 | void p9_trans_fd_exit(void) | ||
1624 | { | ||
1625 | v9fs_unregister_trans(&p9_tcp_trans); | ||
1626 | v9fs_unregister_trans(&p9_unix_trans); | ||
1627 | v9fs_unregister_trans(&p9_fd_trans); | ||
1628 | |||
1629 | destroy_workqueue(p9_mux_wq); | ||
1630 | } | ||