Lines Matching +full:0 +full:m
157 static void p9_mux_poll_stop(struct p9_conn *m) in p9_mux_poll_stop() argument
162 for (i = 0; i < ARRAY_SIZE(m->poll_wait); i++) { in p9_mux_poll_stop()
163 struct p9_poll_wait *pwait = &m->poll_wait[i]; in p9_mux_poll_stop()
172 list_del_init(&m->poll_pending_link); in p9_mux_poll_stop()
180 * @m: mux data
185 static void p9_conn_cancel(struct p9_conn *m, int err) in p9_conn_cancel() argument
190 p9_debug(P9_DEBUG_ERROR, "mux %p err %d\n", m, err); in p9_conn_cancel()
192 spin_lock(&m->req_lock); in p9_conn_cancel()
194 if (m->err) { in p9_conn_cancel()
195 spin_unlock(&m->req_lock); in p9_conn_cancel()
199 m->err = err; in p9_conn_cancel()
201 list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) { in p9_conn_cancel()
205 list_for_each_entry_safe(req, rtmp, &m->unsent_req_list, req_list) { in p9_conn_cancel()
210 spin_unlock(&m->req_lock); in p9_conn_cancel()
217 p9_client_cb(m->client, req, REQ_STATUS_ERROR); in p9_conn_cancel()
267 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN) in p9_fd_read()
282 struct p9_conn *m; in p9_read_work() local
284 m = container_of(work, struct p9_conn, rq); in p9_read_work()
286 if (m->err < 0) in p9_read_work()
289 p9_debug(P9_DEBUG_TRANS, "start mux %p pos %zd\n", m, m->rc.offset); in p9_read_work()
291 if (!m->rc.sdata) { in p9_read_work()
292 m->rc.sdata = m->tmp_buf; in p9_read_work()
293 m->rc.offset = 0; in p9_read_work()
294 m->rc.capacity = P9_HDRSZ; /* start by reading header */ in p9_read_work()
297 clear_bit(Rpending, &m->wsched); in p9_read_work()
299 m, m->rc.offset, m->rc.capacity, in p9_read_work()
300 m->rc.capacity - m->rc.offset); in p9_read_work()
301 err = p9_fd_read(m->client, m->rc.sdata + m->rc.offset, in p9_read_work()
302 m->rc.capacity - m->rc.offset); in p9_read_work()
303 p9_debug(P9_DEBUG_TRANS, "mux %p got %d bytes\n", m, err); in p9_read_work()
307 if (err <= 0) in p9_read_work()
310 m->rc.offset += err; in p9_read_work()
313 if ((!m->rreq) && (m->rc.offset == m->rc.capacity)) { in p9_read_work()
317 m->rc.size = P9_HDRSZ; in p9_read_work()
318 err = p9_parse_header(&m->rc, &m->rc.size, NULL, NULL, 0); in p9_read_work()
327 m, m->rc.size, m->rc.tag); in p9_read_work()
329 m->rreq = p9_tag_lookup(m->client, m->rc.tag); in p9_read_work()
330 if (!m->rreq || (m->rreq->status != REQ_STATUS_SENT)) { in p9_read_work()
332 m->rc.tag); in p9_read_work()
337 if (m->rc.size > m->rreq->rc.capacity) { in p9_read_work()
340 m->rc.size, m->rc.tag, m->rreq->rc.capacity); in p9_read_work()
345 if (!m->rreq->rc.sdata) { in p9_read_work()
348 m->rc.tag, m->rreq); in p9_read_work()
349 p9_req_put(m->client, m->rreq); in p9_read_work()
350 m->rreq = NULL; in p9_read_work()
354 m->rc.sdata = m->rreq->rc.sdata; in p9_read_work()
355 memcpy(m->rc.sdata, m->tmp_buf, m->rc.capacity); in p9_read_work()
356 m->rc.capacity = m->rc.size; in p9_read_work()
362 if ((m->rreq) && (m->rc.offset == m->rc.capacity)) { in p9_read_work()
364 m->rreq->rc.size = m->rc.offset; in p9_read_work()
365 spin_lock(&m->req_lock); in p9_read_work()
366 if (m->rreq->status == REQ_STATUS_SENT) { in p9_read_work()
367 list_del(&m->rreq->req_list); in p9_read_work()
368 p9_client_cb(m->client, m->rreq, REQ_STATUS_RCVD); in p9_read_work()
369 } else if (m->rreq->status == REQ_STATUS_FLSHD) { in p9_read_work()
374 spin_unlock(&m->req_lock); in p9_read_work()
377 m->rc.tag); in p9_read_work()
381 spin_unlock(&m->req_lock); in p9_read_work()
382 m->rc.sdata = NULL; in p9_read_work()
383 m->rc.offset = 0; in p9_read_work()
384 m->rc.capacity = 0; in p9_read_work()
385 p9_req_put(m->client, m->rreq); in p9_read_work()
386 m->rreq = NULL; in p9_read_work()
390 clear_bit(Rworksched, &m->wsched); in p9_read_work()
392 if (!list_empty(&m->req_list)) { in p9_read_work()
393 if (test_and_clear_bit(Rpending, &m->wsched)) in p9_read_work()
396 n = p9_fd_poll(m->client, NULL, NULL); in p9_read_work()
398 if ((n & EPOLLIN) && !test_and_set_bit(Rworksched, &m->wsched)) { in p9_read_work()
399 p9_debug(P9_DEBUG_TRANS, "sched read work %p\n", m); in p9_read_work()
400 schedule_work(&m->rq); in p9_read_work()
406 p9_conn_cancel(m, err); in p9_read_work()
407 clear_bit(Rworksched, &m->wsched); in p9_read_work()
433 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN) in p9_fd_write()
448 struct p9_conn *m; in p9_write_work() local
451 m = container_of(work, struct p9_conn, wq); in p9_write_work()
453 if (m->err < 0) { in p9_write_work()
454 clear_bit(Wworksched, &m->wsched); in p9_write_work()
458 if (!m->wsize) { in p9_write_work()
459 spin_lock(&m->req_lock); in p9_write_work()
460 if (list_empty(&m->unsent_req_list)) { in p9_write_work()
461 clear_bit(Wworksched, &m->wsched); in p9_write_work()
462 spin_unlock(&m->req_lock); in p9_write_work()
466 req = list_entry(m->unsent_req_list.next, struct p9_req_t, in p9_write_work()
470 list_move_tail(&req->req_list, &m->req_list); in p9_write_work()
472 m->wbuf = req->tc.sdata; in p9_write_work()
473 m->wsize = req->tc.size; in p9_write_work()
474 m->wpos = 0; in p9_write_work()
476 m->wreq = req; in p9_write_work()
477 spin_unlock(&m->req_lock); in p9_write_work()
481 m, m->wpos, m->wsize); in p9_write_work()
482 clear_bit(Wpending, &m->wsched); in p9_write_work()
483 err = p9_fd_write(m->client, m->wbuf + m->wpos, m->wsize - m->wpos); in p9_write_work()
484 p9_debug(P9_DEBUG_TRANS, "mux %p sent %d bytes\n", m, err); in p9_write_work()
489 if (err < 0) in p9_write_work()
491 else if (err == 0) { in p9_write_work()
496 m->wpos += err; in p9_write_work()
497 if (m->wpos == m->wsize) { in p9_write_work()
498 m->wpos = m->wsize = 0; in p9_write_work()
499 p9_req_put(m->client, m->wreq); in p9_write_work()
500 m->wreq = NULL; in p9_write_work()
504 clear_bit(Wworksched, &m->wsched); in p9_write_work()
506 if (m->wsize || !list_empty(&m->unsent_req_list)) { in p9_write_work()
507 if (test_and_clear_bit(Wpending, &m->wsched)) in p9_write_work()
510 n = p9_fd_poll(m->client, NULL, NULL); in p9_write_work()
513 !test_and_set_bit(Wworksched, &m->wsched)) { in p9_write_work()
514 p9_debug(P9_DEBUG_TRANS, "sched write work %p\n", m); in p9_write_work()
515 schedule_work(&m->wq); in p9_write_work()
522 p9_conn_cancel(m, err); in p9_write_work()
523 clear_bit(Wworksched, &m->wsched); in p9_write_work()
530 struct p9_conn *m = pwait->conn; in p9_pollwake() local
534 if (list_empty(&m->poll_pending_link)) in p9_pollwake()
535 list_add_tail(&m->poll_pending_link, &p9_poll_pending_list); in p9_pollwake()
554 struct p9_conn *m = container_of(p, struct p9_conn, pt); in p9_pollwait() local
558 for (i = 0; i < ARRAY_SIZE(m->poll_wait); i++) { in p9_pollwait()
559 if (m->poll_wait[i].wait_addr == NULL) { in p9_pollwait()
560 pwait = &m->poll_wait[i]; in p9_pollwait()
570 pwait->conn = m; in p9_pollwait()
587 struct p9_conn *m = &ts->conn; in p9_conn_create() local
591 INIT_LIST_HEAD(&m->mux_list); in p9_conn_create()
592 m->client = client; in p9_conn_create()
594 spin_lock_init(&m->req_lock); in p9_conn_create()
595 INIT_LIST_HEAD(&m->req_list); in p9_conn_create()
596 INIT_LIST_HEAD(&m->unsent_req_list); in p9_conn_create()
597 INIT_WORK(&m->rq, p9_read_work); in p9_conn_create()
598 INIT_WORK(&m->wq, p9_write_work); in p9_conn_create()
599 INIT_LIST_HEAD(&m->poll_pending_link); in p9_conn_create()
600 init_poll_funcptr(&m->pt, p9_pollwait); in p9_conn_create()
602 n = p9_fd_poll(client, &m->pt, NULL); in p9_conn_create()
604 p9_debug(P9_DEBUG_TRANS, "mux %p can read\n", m); in p9_conn_create()
605 set_bit(Rpending, &m->wsched); in p9_conn_create()
609 p9_debug(P9_DEBUG_TRANS, "mux %p can write\n", m); in p9_conn_create()
610 set_bit(Wpending, &m->wsched); in p9_conn_create()
616 * @m: connection to poll
620 static void p9_poll_mux(struct p9_conn *m) in p9_poll_mux() argument
625 if (m->err < 0) in p9_poll_mux()
628 n = p9_fd_poll(m->client, NULL, &err); in p9_poll_mux()
630 p9_debug(P9_DEBUG_TRANS, "error mux %p err %d\n", m, n); in p9_poll_mux()
631 p9_conn_cancel(m, err); in p9_poll_mux()
635 set_bit(Rpending, &m->wsched); in p9_poll_mux()
636 p9_debug(P9_DEBUG_TRANS, "mux %p can read\n", m); in p9_poll_mux()
637 if (!test_and_set_bit(Rworksched, &m->wsched)) { in p9_poll_mux()
638 p9_debug(P9_DEBUG_TRANS, "sched read work %p\n", m); in p9_poll_mux()
639 schedule_work(&m->rq); in p9_poll_mux()
644 set_bit(Wpending, &m->wsched); in p9_poll_mux()
645 p9_debug(P9_DEBUG_TRANS, "mux %p can write\n", m); in p9_poll_mux()
646 if ((m->wsize || !list_empty(&m->unsent_req_list)) && in p9_poll_mux()
647 !test_and_set_bit(Wworksched, &m->wsched)) { in p9_poll_mux()
648 p9_debug(P9_DEBUG_TRANS, "sched write work %p\n", m); in p9_poll_mux()
649 schedule_work(&m->wq); in p9_poll_mux()
669 struct p9_conn *m = &ts->conn; in p9_fd_request() local
672 m, current, &req->tc, req->tc.id); in p9_fd_request()
674 spin_lock(&m->req_lock); in p9_fd_request()
676 if (m->err < 0) { in p9_fd_request()
677 spin_unlock(&m->req_lock); in p9_fd_request()
678 return m->err; in p9_fd_request()
682 list_add_tail(&req->req_list, &m->unsent_req_list); in p9_fd_request()
683 spin_unlock(&m->req_lock); in p9_fd_request()
685 if (test_and_clear_bit(Wpending, &m->wsched)) in p9_fd_request()
688 n = p9_fd_poll(m->client, NULL, NULL); in p9_fd_request()
690 if (n & EPOLLOUT && !test_and_set_bit(Wworksched, &m->wsched)) in p9_fd_request()
691 schedule_work(&m->wq); in p9_fd_request()
693 return 0; in p9_fd_request()
699 struct p9_conn *m = &ts->conn; in p9_fd_cancel() local
704 spin_lock(&m->req_lock); in p9_fd_cancel()
710 ret = 0; in p9_fd_cancel()
712 spin_unlock(&m->req_lock); in p9_fd_cancel()
720 struct p9_conn *m = &ts->conn; in p9_fd_cancelled() local
724 spin_lock(&m->req_lock); in p9_fd_cancelled()
729 spin_unlock(&m->req_lock); in p9_fd_cancelled()
730 return 0; in p9_fd_cancelled()
738 spin_unlock(&m->req_lock); in p9_fd_cancelled()
742 return 0; in p9_fd_cancelled()
745 static int p9_fd_show_options(struct seq_file *m, struct p9_client *clnt) in p9_fd_show_options() argument
749 seq_printf(m, ",port=%u", clnt->trans_opts.tcp.port); in p9_fd_show_options()
751 if (clnt->trans_opts.fd.rfd != ~0) in p9_fd_show_options()
752 seq_printf(m, ",rfd=%u", clnt->trans_opts.fd.rfd); in p9_fd_show_options()
753 if (clnt->trans_opts.fd.wfd != ~0) in p9_fd_show_options()
754 seq_printf(m, ",wfd=%u", clnt->trans_opts.fd.wfd); in p9_fd_show_options()
756 return 0; in p9_fd_show_options()
764 * Returns 0 upon success, -ERRNO upon failure
775 opts->rfd = ~0; in parse_opts()
776 opts->wfd = ~0; in parse_opts()
780 return 0; in parse_opts()
797 r = match_int(&args[0], &option); in parse_opts()
798 if (r < 0) { in parse_opts()
823 return 0; in parse_opts()
857 return 0; in p9_fd_open()
881 file = sock_alloc_file(csocket, 0, NULL); in p9_socket_open()
897 return 0; in p9_socket_open()
902 * @m: mux to destroy
906 static void p9_conn_destroy(struct p9_conn *m) in p9_conn_destroy() argument
909 m, m->mux_list.prev, m->mux_list.next); in p9_conn_destroy()
911 p9_mux_poll_stop(m); in p9_conn_destroy()
912 cancel_work_sync(&m->rq); in p9_conn_destroy()
913 if (m->rreq) { in p9_conn_destroy()
914 p9_req_put(m->client, m->rreq); in p9_conn_destroy()
915 m->rreq = NULL; in p9_conn_destroy()
917 cancel_work_sync(&m->wq); in p9_conn_destroy()
918 if (m->wreq) { in p9_conn_destroy()
919 p9_req_put(m->client, m->wreq); in p9_conn_destroy()
920 m->wreq = NULL; in p9_conn_destroy()
923 p9_conn_cancel(m, -ECONNRESET); in p9_conn_destroy()
925 m->client = NULL; in p9_conn_destroy()
964 rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]); in valid_ipaddr4()
967 for (count = 0; count < 4; count++) { in valid_ipaddr4()
971 return 0; in valid_ipaddr4()
979 memset(&cl, 0, sizeof(cl)); in p9_bind_privport()
1001 if (err < 0) in p9_fd_create_tcp()
1004 if (addr == NULL || valid_ipaddr4(addr) < 0) in p9_fd_create_tcp()
1024 if (err < 0) { in p9_fd_create_tcp()
1034 sizeof(struct sockaddr_in), 0); in p9_fd_create_tcp()
1035 if (err < 0) { in p9_fd_create_tcp()
1066 SOCK_STREAM, 0, &csocket, 1); in p9_fd_create_unix()
1067 if (err < 0) { in p9_fd_create_unix()
1074 sizeof(struct sockaddr_un) - 1, 0); in p9_fd_create_unix()
1075 if (err < 0) { in p9_fd_create_unix()
1092 if (err < 0) in p9_fd_create()
1097 if (opts.rfd == ~0 || opts.wfd == ~0) { in p9_fd_create()
1103 if (err < 0) in p9_fd_create()
1108 return 0; in p9_fd_create()
1115 .def = 0,
1129 .def = 0,
1143 .def = 0,
1192 return 0; in p9_trans_fd_init()