Lines Matching refs:con
136 struct connection *con; member
184 struct connection *con; in __find_con() local
188 hlist_for_each_entry(con, &connection_hash[r], list) { in __find_con()
189 if (con->nodeid == nodeid) in __find_con()
190 return con; in __find_con()
201 struct connection *con = NULL; in __nodeid2con() local
204 con = __find_con(nodeid); in __nodeid2con()
205 if (con || !alloc) in __nodeid2con()
206 return con; in __nodeid2con()
208 con = kmem_cache_zalloc(con_cache, alloc); in __nodeid2con()
209 if (!con) in __nodeid2con()
213 hlist_add_head(&con->list, &connection_hash[r]); in __nodeid2con()
215 con->nodeid = nodeid; in __nodeid2con()
216 mutex_init(&con->sock_mutex); in __nodeid2con()
217 INIT_LIST_HEAD(&con->writequeue); in __nodeid2con()
218 spin_lock_init(&con->writequeue_lock); in __nodeid2con()
219 INIT_WORK(&con->swork, process_send_sockets); in __nodeid2con()
220 INIT_WORK(&con->rwork, process_recv_sockets); in __nodeid2con()
223 if (con->nodeid) { in __nodeid2con()
226 con->connect_action = zerocon->connect_action; in __nodeid2con()
227 if (!con->rx_action) in __nodeid2con()
228 con->rx_action = zerocon->rx_action; in __nodeid2con()
231 return con; in __nodeid2con()
239 struct connection *con; in foreach_conn() local
242 hlist_for_each_entry_safe(con, n, &connection_hash[i], list) in foreach_conn()
243 conn_func(con); in foreach_conn()
249 struct connection *con; in nodeid2con() local
252 con = __nodeid2con(nodeid, allocation); in nodeid2con()
255 return con; in nodeid2con()
412 struct connection *con; in lowcomms_data_ready() local
415 con = sock2con(sk); in lowcomms_data_ready()
416 if (con && !test_and_set_bit(CF_READ_PENDING, &con->flags)) in lowcomms_data_ready()
417 queue_work(recv_workqueue, &con->rwork); in lowcomms_data_ready()
423 struct connection *con; in lowcomms_write_space() local
426 con = sock2con(sk); in lowcomms_write_space()
427 if (!con) in lowcomms_write_space()
430 clear_bit(SOCK_NOSPACE, &con->sock->flags); in lowcomms_write_space()
432 if (test_and_clear_bit(CF_APP_LIMITED, &con->flags)) { in lowcomms_write_space()
433 con->sock->sk->sk_write_pending--; in lowcomms_write_space()
434 clear_bit(SOCKWQ_ASYNC_NOSPACE, &con->sock->flags); in lowcomms_write_space()
437 queue_work(send_workqueue, &con->swork); in lowcomms_write_space()
442 static inline void lowcomms_connect_sock(struct connection *con) in lowcomms_connect_sock() argument
444 if (test_bit(CF_CLOSE, &con->flags)) in lowcomms_connect_sock()
446 queue_work(send_workqueue, &con->swork); in lowcomms_connect_sock()
467 struct connection *con; in dlm_lowcomms_connect_node() local
472 con = nodeid2con(nodeid, GFP_NOFS); in dlm_lowcomms_connect_node()
473 if (!con) in dlm_lowcomms_connect_node()
475 lowcomms_connect_sock(con); in dlm_lowcomms_connect_node()
481 struct connection *con; in lowcomms_error_report() local
486 con = sock2con(sk); in lowcomms_error_report()
487 if (con == NULL) in lowcomms_error_report()
491 if (con->sock == NULL || in lowcomms_error_report()
492 kernel_getpeername(con->sock, (struct sockaddr *)&saddr) < 0) { in lowcomms_error_report()
496 con->nodeid, dlm_config.ci_tcp_port, in lowcomms_error_report()
504 con->nodeid, &sin4->sin_addr.s_addr, in lowcomms_error_report()
513 con->nodeid, sin6->sin6_addr.s6_addr32[0], in lowcomms_error_report()
551 static void add_sock(struct socket *sock, struct connection *con) in add_sock() argument
556 con->sock = sock; in add_sock()
558 sk->sk_user_data = con; in add_sock()
588 static void close_connection(struct connection *con, bool and_other, in close_connection() argument
591 bool closing = test_and_set_bit(CF_CLOSING, &con->flags); in close_connection()
593 if (tx && !closing && cancel_work_sync(&con->swork)) { in close_connection()
594 log_print("canceled swork for node %d", con->nodeid); in close_connection()
595 clear_bit(CF_WRITE_PENDING, &con->flags); in close_connection()
597 if (rx && !closing && cancel_work_sync(&con->rwork)) { in close_connection()
598 log_print("canceled rwork for node %d", con->nodeid); in close_connection()
599 clear_bit(CF_READ_PENDING, &con->flags); in close_connection()
602 mutex_lock(&con->sock_mutex); in close_connection()
603 if (con->sock) { in close_connection()
604 restore_callbacks(con->sock); in close_connection()
605 sock_release(con->sock); in close_connection()
606 con->sock = NULL; in close_connection()
608 if (con->othercon && and_other) { in close_connection()
610 close_connection(con->othercon, false, true, true); in close_connection()
612 if (con->rx_page) { in close_connection()
613 __free_page(con->rx_page); in close_connection()
614 con->rx_page = NULL; in close_connection()
617 con->retries = 0; in close_connection()
618 mutex_unlock(&con->sock_mutex); in close_connection()
619 clear_bit(CF_CLOSING, &con->flags); in close_connection()
623 static int receive_from_sock(struct connection *con) in receive_from_sock() argument
633 mutex_lock(&con->sock_mutex); in receive_from_sock()
635 if (con->sock == NULL) { in receive_from_sock()
639 if (con->nodeid == 0) { in receive_from_sock()
644 if (con->rx_page == NULL) { in receive_from_sock()
649 con->rx_page = alloc_page(GFP_ATOMIC); in receive_from_sock()
650 if (con->rx_page == NULL) in receive_from_sock()
652 cbuf_init(&con->cb, PAGE_SIZE); in receive_from_sock()
659 iov[0].iov_len = con->cb.base - cbuf_data(&con->cb); in receive_from_sock()
660 iov[0].iov_base = page_address(con->rx_page) + cbuf_data(&con->cb); in receive_from_sock()
668 if (cbuf_data(&con->cb) >= con->cb.base) { in receive_from_sock()
669 iov[0].iov_len = PAGE_SIZE - cbuf_data(&con->cb); in receive_from_sock()
670 iov[1].iov_len = con->cb.base; in receive_from_sock()
671 iov[1].iov_base = page_address(con->rx_page); in receive_from_sock()
677 r = ret = sock_recvmsg(con->sock, &msg, MSG_DONTWAIT | MSG_NOSIGNAL); in receive_from_sock()
683 cbuf_add(&con->cb, ret); in receive_from_sock()
684 ret = dlm_process_incoming_buffer(con->nodeid, in receive_from_sock()
685 page_address(con->rx_page), in receive_from_sock()
686 con->cb.base, con->cb.len, in receive_from_sock()
690 page_address(con->rx_page), con->cb.base, in receive_from_sock()
691 con->cb.len, r); in receive_from_sock()
695 cbuf_eat(&con->cb, ret); in receive_from_sock()
697 if (cbuf_empty(&con->cb) && !call_again_soon) { in receive_from_sock()
698 __free_page(con->rx_page); in receive_from_sock()
699 con->rx_page = NULL; in receive_from_sock()
704 mutex_unlock(&con->sock_mutex); in receive_from_sock()
708 if (!test_and_set_bit(CF_READ_PENDING, &con->flags)) in receive_from_sock()
709 queue_work(recv_workqueue, &con->rwork); in receive_from_sock()
710 mutex_unlock(&con->sock_mutex); in receive_from_sock()
714 mutex_unlock(&con->sock_mutex); in receive_from_sock()
716 close_connection(con, true, true, false); in receive_from_sock()
727 static int tcp_accept_from_sock(struct connection *con) in tcp_accept_from_sock() argument
744 mutex_lock_nested(&con->sock_mutex, 0); in tcp_accept_from_sock()
746 if (!con->sock) { in tcp_accept_from_sock()
747 mutex_unlock(&con->sock_mutex); in tcp_accept_from_sock()
751 result = kernel_accept(con->sock, &newsock, O_NONBLOCK); in tcp_accept_from_sock()
771 mutex_unlock(&con->sock_mutex); in tcp_accept_from_sock()
841 mutex_unlock(&con->sock_mutex); in tcp_accept_from_sock()
846 mutex_unlock(&con->sock_mutex); in tcp_accept_from_sock()
855 static int sctp_accept_from_sock(struct connection *con) in sctp_accept_from_sock() argument
873 mutex_lock_nested(&con->sock_mutex, 0); in sctp_accept_from_sock()
875 ret = kernel_accept(con->sock, &newsock, O_NONBLOCK); in sctp_accept_from_sock()
958 mutex_unlock(&con->sock_mutex); in sctp_accept_from_sock()
963 mutex_unlock(&con->sock_mutex); in sctp_accept_from_sock()
999 static int sctp_bind_addrs(struct connection *con, uint16_t port) in sctp_bind_addrs() argument
1009 result = kernel_bind(con->sock, in sctp_bind_addrs()
1013 result = kernel_setsockopt(con->sock, SOL_SCTP, in sctp_bind_addrs()
1031 static void sctp_connect_to_sock(struct connection *con) in sctp_connect_to_sock() argument
1040 if (con->nodeid == 0) { in sctp_connect_to_sock()
1045 mutex_lock(&con->sock_mutex); in sctp_connect_to_sock()
1048 if (con->retries++ > MAX_CONNECT_RETRIES) in sctp_connect_to_sock()
1051 if (con->sock) { in sctp_connect_to_sock()
1052 log_print("node %d already connected.", con->nodeid); in sctp_connect_to_sock()
1057 result = nodeid_to_addr(con->nodeid, &daddr, NULL, true); in sctp_connect_to_sock()
1059 log_print("no address for nodeid %d", con->nodeid); in sctp_connect_to_sock()
1069 con->rx_action = receive_from_sock; in sctp_connect_to_sock()
1070 con->connect_action = sctp_connect_to_sock; in sctp_connect_to_sock()
1071 add_sock(sock, con); in sctp_connect_to_sock()
1074 if (sctp_bind_addrs(con, 0)) in sctp_connect_to_sock()
1079 log_print("connecting to %d", con->nodeid); in sctp_connect_to_sock()
1104 con->sock = NULL; in sctp_connect_to_sock()
1117 log_print("connect %d try %d error %d", con->nodeid, in sctp_connect_to_sock()
1118 con->retries, result); in sctp_connect_to_sock()
1119 mutex_unlock(&con->sock_mutex); in sctp_connect_to_sock()
1121 lowcomms_connect_sock(con); in sctp_connect_to_sock()
1126 mutex_unlock(&con->sock_mutex); in sctp_connect_to_sock()
1130 static void tcp_connect_to_sock(struct connection *con) in tcp_connect_to_sock() argument
1138 if (con->nodeid == 0) { in tcp_connect_to_sock()
1143 mutex_lock(&con->sock_mutex); in tcp_connect_to_sock()
1144 if (con->retries++ > MAX_CONNECT_RETRIES) in tcp_connect_to_sock()
1148 if (con->sock) in tcp_connect_to_sock()
1158 result = nodeid_to_addr(con->nodeid, &saddr, NULL, false); in tcp_connect_to_sock()
1160 log_print("no address for nodeid %d", con->nodeid); in tcp_connect_to_sock()
1164 con->rx_action = receive_from_sock; in tcp_connect_to_sock()
1165 con->connect_action = tcp_connect_to_sock; in tcp_connect_to_sock()
1166 add_sock(sock, con); in tcp_connect_to_sock()
1181 log_print("connecting to %d", con->nodeid); in tcp_connect_to_sock()
1195 if (con->sock) { in tcp_connect_to_sock()
1196 sock_release(con->sock); in tcp_connect_to_sock()
1197 con->sock = NULL; in tcp_connect_to_sock()
1210 log_print("connect %d try %d error %d", con->nodeid, in tcp_connect_to_sock()
1211 con->retries, result); in tcp_connect_to_sock()
1212 mutex_unlock(&con->sock_mutex); in tcp_connect_to_sock()
1214 lowcomms_connect_sock(con); in tcp_connect_to_sock()
1218 mutex_unlock(&con->sock_mutex); in tcp_connect_to_sock()
1222 static struct socket *tcp_create_listen_sock(struct connection *con, in tcp_create_listen_sock() argument
1254 sock->sk->sk_user_data = con; in tcp_create_listen_sock()
1256 con->rx_action = tcp_accept_from_sock; in tcp_create_listen_sock()
1257 con->connect_action = tcp_connect_to_sock; in tcp_create_listen_sock()
1267 con->sock = NULL; in tcp_create_listen_sock()
1311 struct connection *con = nodeid2con(0, GFP_NOFS); in sctp_listen_for_all() local
1315 if (!con) in sctp_listen_for_all()
1339 sock->sk->sk_user_data = con; in sctp_listen_for_all()
1341 con->sock = sock; in sctp_listen_for_all()
1342 con->sock->sk->sk_data_ready = lowcomms_data_ready; in sctp_listen_for_all()
1343 con->rx_action = sctp_accept_from_sock; in sctp_listen_for_all()
1344 con->connect_action = sctp_connect_to_sock; in sctp_listen_for_all()
1349 if (sctp_bind_addrs(con, dlm_config.ci_tcp_port)) in sctp_listen_for_all()
1362 con->sock = NULL; in sctp_listen_for_all()
1370 struct connection *con = nodeid2con(0, GFP_NOFS); in tcp_listen_for_all() local
1373 if (!con) in tcp_listen_for_all()
1385 sock = tcp_create_listen_sock(con, dlm_local_addr[0]); in tcp_listen_for_all()
1387 add_sock(sock, con); in tcp_listen_for_all()
1399 static struct writequeue_entry *new_writequeue_entry(struct connection *con, in new_writequeue_entry() argument
1418 entry->con = con; in new_writequeue_entry()
1425 struct connection *con; in dlm_lowcomms_get_buffer() local
1429 con = nodeid2con(nodeid, allocation); in dlm_lowcomms_get_buffer()
1430 if (!con) in dlm_lowcomms_get_buffer()
1433 spin_lock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1434 e = list_entry(con->writequeue.prev, struct writequeue_entry, list); in dlm_lowcomms_get_buffer()
1435 if ((&e->list == &con->writequeue) || in dlm_lowcomms_get_buffer()
1443 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1451 e = new_writequeue_entry(con, allocation); in dlm_lowcomms_get_buffer()
1453 spin_lock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1457 list_add_tail(&e->list, &con->writequeue); in dlm_lowcomms_get_buffer()
1458 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1467 struct connection *con = e->con; in dlm_lowcomms_commit_buffer() local
1470 spin_lock(&con->writequeue_lock); in dlm_lowcomms_commit_buffer()
1475 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_commit_buffer()
1477 queue_work(send_workqueue, &con->swork); in dlm_lowcomms_commit_buffer()
1481 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_commit_buffer()
1486 static void send_to_sock(struct connection *con) in send_to_sock() argument
1494 mutex_lock(&con->sock_mutex); in send_to_sock()
1495 if (con->sock == NULL) in send_to_sock()
1498 spin_lock(&con->writequeue_lock); in send_to_sock()
1500 e = list_entry(con->writequeue.next, struct writequeue_entry, in send_to_sock()
1502 if ((struct list_head *) e == &con->writequeue) in send_to_sock()
1508 spin_unlock(&con->writequeue_lock); in send_to_sock()
1512 ret = kernel_sendpage(con->sock, e->page, offset, len, in send_to_sock()
1516 test_bit(SOCKWQ_ASYNC_NOSPACE, &con->sock->flags) && in send_to_sock()
1517 !test_and_set_bit(CF_APP_LIMITED, &con->flags)) { in send_to_sock()
1521 set_bit(SOCK_NOSPACE, &con->sock->flags); in send_to_sock()
1522 con->sock->sk->sk_write_pending++; in send_to_sock()
1536 spin_lock(&con->writequeue_lock); in send_to_sock()
1539 spin_unlock(&con->writequeue_lock); in send_to_sock()
1541 mutex_unlock(&con->sock_mutex); in send_to_sock()
1545 mutex_unlock(&con->sock_mutex); in send_to_sock()
1546 close_connection(con, true, false, true); in send_to_sock()
1549 queue_work(send_workqueue, &con->swork); in send_to_sock()
1553 mutex_unlock(&con->sock_mutex); in send_to_sock()
1554 queue_work(send_workqueue, &con->swork); in send_to_sock()
1558 static void clean_one_writequeue(struct connection *con) in clean_one_writequeue() argument
1562 spin_lock(&con->writequeue_lock); in clean_one_writequeue()
1563 list_for_each_entry_safe(e, safe, &con->writequeue, list) { in clean_one_writequeue()
1567 spin_unlock(&con->writequeue_lock); in clean_one_writequeue()
1574 struct connection *con; in dlm_lowcomms_close() local
1578 con = nodeid2con(nodeid, 0); in dlm_lowcomms_close()
1579 if (con) { in dlm_lowcomms_close()
1580 set_bit(CF_CLOSE, &con->flags); in dlm_lowcomms_close()
1581 close_connection(con, true, true, true); in dlm_lowcomms_close()
1582 clean_one_writequeue(con); in dlm_lowcomms_close()
1601 struct connection *con = container_of(work, struct connection, rwork); in process_recv_sockets() local
1604 clear_bit(CF_READ_PENDING, &con->flags); in process_recv_sockets()
1606 err = con->rx_action(con); in process_recv_sockets()
1613 struct connection *con = container_of(work, struct connection, swork); in process_send_sockets() local
1615 clear_bit(CF_WRITE_PENDING, &con->flags); in process_send_sockets()
1616 if (con->sock == NULL) /* not mutex protected so check it inside too */ in process_send_sockets()
1617 con->connect_action(con); in process_send_sockets()
1618 if (!list_empty(&con->writequeue)) in process_send_sockets()
1619 send_to_sock(con); in process_send_sockets()
1657 static void _stop_conn(struct connection *con, bool and_other) in _stop_conn() argument
1659 mutex_lock(&con->sock_mutex); in _stop_conn()
1660 set_bit(CF_CLOSE, &con->flags); in _stop_conn()
1661 set_bit(CF_READ_PENDING, &con->flags); in _stop_conn()
1662 set_bit(CF_WRITE_PENDING, &con->flags); in _stop_conn()
1663 if (con->sock && con->sock->sk) { in _stop_conn()
1664 write_lock_bh(&con->sock->sk->sk_callback_lock); in _stop_conn()
1665 con->sock->sk->sk_user_data = NULL; in _stop_conn()
1666 write_unlock_bh(&con->sock->sk->sk_callback_lock); in _stop_conn()
1668 if (con->othercon && and_other) in _stop_conn()
1669 _stop_conn(con->othercon, false); in _stop_conn()
1670 mutex_unlock(&con->sock_mutex); in _stop_conn()
1673 static void stop_conn(struct connection *con) in stop_conn() argument
1675 _stop_conn(con, true); in stop_conn()
1678 static void free_conn(struct connection *con) in free_conn() argument
1680 close_connection(con, true, true, true); in free_conn()
1681 if (con->othercon) in free_conn()
1682 kmem_cache_free(con_cache, con->othercon); in free_conn()
1683 hlist_del(&con->list); in free_conn()
1684 kmem_cache_free(con_cache, con); in free_conn()
1692 struct connection *con; in work_flush() local
1706 hlist_for_each_entry_safe(con, n, in work_flush()
1708 ok &= test_bit(CF_READ_PENDING, &con->flags); in work_flush()
1709 ok &= test_bit(CF_WRITE_PENDING, &con->flags); in work_flush()
1710 if (con->othercon) { in work_flush()
1712 &con->othercon->flags); in work_flush()
1714 &con->othercon->flags); in work_flush()
1740 struct connection *con; in dlm_lowcomms_start() local
1778 con = nodeid2con(0,0); in dlm_lowcomms_start()
1779 if (con) { in dlm_lowcomms_start()
1780 close_connection(con, false, true, true); in dlm_lowcomms_start()
1781 kmem_cache_free(con_cache, con); in dlm_lowcomms_start()