Lines Matching refs:con

138 	struct connection *con;  member
186 struct connection *con; in __find_con() local
190 hlist_for_each_entry(con, &connection_hash[r], list) { in __find_con()
191 if (con->nodeid == nodeid) in __find_con()
192 return con; in __find_con()
203 struct connection *con = NULL; in __nodeid2con() local
206 con = __find_con(nodeid); in __nodeid2con()
207 if (con || !alloc) in __nodeid2con()
208 return con; in __nodeid2con()
210 con = kmem_cache_zalloc(con_cache, alloc); in __nodeid2con()
211 if (!con) in __nodeid2con()
215 hlist_add_head(&con->list, &connection_hash[r]); in __nodeid2con()
217 con->nodeid = nodeid; in __nodeid2con()
218 mutex_init(&con->sock_mutex); in __nodeid2con()
219 INIT_LIST_HEAD(&con->writequeue); in __nodeid2con()
220 spin_lock_init(&con->writequeue_lock); in __nodeid2con()
221 INIT_WORK(&con->swork, process_send_sockets); in __nodeid2con()
222 INIT_WORK(&con->rwork, process_recv_sockets); in __nodeid2con()
225 if (con->nodeid) { in __nodeid2con()
228 con->connect_action = zerocon->connect_action; in __nodeid2con()
229 if (!con->rx_action) in __nodeid2con()
230 con->rx_action = zerocon->rx_action; in __nodeid2con()
233 return con; in __nodeid2con()
241 struct connection *con; in foreach_conn() local
244 hlist_for_each_entry_safe(con, n, &connection_hash[i], list) in foreach_conn()
245 conn_func(con); in foreach_conn()
251 struct connection *con; in nodeid2con() local
254 con = __nodeid2con(nodeid, allocation); in nodeid2con()
257 return con; in nodeid2con()
414 struct connection *con; in lowcomms_data_ready() local
417 con = sock2con(sk); in lowcomms_data_ready()
418 if (con && !test_and_set_bit(CF_READ_PENDING, &con->flags)) in lowcomms_data_ready()
419 queue_work(recv_workqueue, &con->rwork); in lowcomms_data_ready()
425 struct connection *con; in lowcomms_write_space() local
428 con = sock2con(sk); in lowcomms_write_space()
429 if (!con) in lowcomms_write_space()
432 clear_bit(SOCK_NOSPACE, &con->sock->flags); in lowcomms_write_space()
434 if (test_and_clear_bit(CF_APP_LIMITED, &con->flags)) { in lowcomms_write_space()
435 con->sock->sk->sk_write_pending--; in lowcomms_write_space()
436 clear_bit(SOCKWQ_ASYNC_NOSPACE, &con->sock->flags); in lowcomms_write_space()
439 queue_work(send_workqueue, &con->swork); in lowcomms_write_space()
444 static inline void lowcomms_connect_sock(struct connection *con) in lowcomms_connect_sock() argument
446 if (test_bit(CF_CLOSE, &con->flags)) in lowcomms_connect_sock()
448 queue_work(send_workqueue, &con->swork); in lowcomms_connect_sock()
469 struct connection *con; in dlm_lowcomms_connect_node() local
474 con = nodeid2con(nodeid, GFP_NOFS); in dlm_lowcomms_connect_node()
475 if (!con) in dlm_lowcomms_connect_node()
477 lowcomms_connect_sock(con); in dlm_lowcomms_connect_node()
483 struct connection *con; in lowcomms_error_report() local
488 con = sock2con(sk); in lowcomms_error_report()
489 if (con == NULL) in lowcomms_error_report()
493 if (con->sock == NULL || in lowcomms_error_report()
494 kernel_getpeername(con->sock, (struct sockaddr *)&saddr) < 0) { in lowcomms_error_report()
498 con->nodeid, dlm_config.ci_tcp_port, in lowcomms_error_report()
506 con->nodeid, &sin4->sin_addr.s_addr, in lowcomms_error_report()
515 con->nodeid, sin6->sin6_addr.s6_addr32[0], in lowcomms_error_report()
553 static void add_sock(struct socket *sock, struct connection *con) in add_sock() argument
558 con->sock = sock; in add_sock()
560 sk->sk_user_data = con; in add_sock()
590 static void close_connection(struct connection *con, bool and_other, in close_connection() argument
593 bool closing = test_and_set_bit(CF_CLOSING, &con->flags); in close_connection()
595 if (tx && !closing && cancel_work_sync(&con->swork)) { in close_connection()
596 log_print("canceled swork for node %d", con->nodeid); in close_connection()
597 clear_bit(CF_WRITE_PENDING, &con->flags); in close_connection()
599 if (rx && !closing && cancel_work_sync(&con->rwork)) { in close_connection()
600 log_print("canceled rwork for node %d", con->nodeid); in close_connection()
601 clear_bit(CF_READ_PENDING, &con->flags); in close_connection()
604 mutex_lock(&con->sock_mutex); in close_connection()
605 if (con->sock) { in close_connection()
606 restore_callbacks(con->sock); in close_connection()
607 sock_release(con->sock); in close_connection()
608 con->sock = NULL; in close_connection()
610 if (con->othercon && and_other) { in close_connection()
612 close_connection(con->othercon, false, true, true); in close_connection()
614 if (con->rx_page) { in close_connection()
615 __free_page(con->rx_page); in close_connection()
616 con->rx_page = NULL; in close_connection()
619 con->retries = 0; in close_connection()
620 mutex_unlock(&con->sock_mutex); in close_connection()
621 clear_bit(CF_CLOSING, &con->flags); in close_connection()
625 static int receive_from_sock(struct connection *con) in receive_from_sock() argument
635 mutex_lock(&con->sock_mutex); in receive_from_sock()
637 if (con->sock == NULL) { in receive_from_sock()
641 if (con->nodeid == 0) { in receive_from_sock()
646 if (con->rx_page == NULL) { in receive_from_sock()
651 con->rx_page = alloc_page(GFP_ATOMIC); in receive_from_sock()
652 if (con->rx_page == NULL) in receive_from_sock()
654 cbuf_init(&con->cb, PAGE_SIZE); in receive_from_sock()
661 iov[0].iov_len = con->cb.base - cbuf_data(&con->cb); in receive_from_sock()
662 iov[0].iov_base = page_address(con->rx_page) + cbuf_data(&con->cb); in receive_from_sock()
670 if (cbuf_data(&con->cb) >= con->cb.base) { in receive_from_sock()
671 iov[0].iov_len = PAGE_SIZE - cbuf_data(&con->cb); in receive_from_sock()
672 iov[1].iov_len = con->cb.base; in receive_from_sock()
673 iov[1].iov_base = page_address(con->rx_page); in receive_from_sock()
679 r = ret = sock_recvmsg(con->sock, &msg, MSG_DONTWAIT | MSG_NOSIGNAL); in receive_from_sock()
685 cbuf_add(&con->cb, ret); in receive_from_sock()
686 ret = dlm_process_incoming_buffer(con->nodeid, in receive_from_sock()
687 page_address(con->rx_page), in receive_from_sock()
688 con->cb.base, con->cb.len, in receive_from_sock()
692 page_address(con->rx_page), con->cb.base, in receive_from_sock()
693 con->cb.len, r); in receive_from_sock()
697 cbuf_eat(&con->cb, ret); in receive_from_sock()
699 if (cbuf_empty(&con->cb) && !call_again_soon) { in receive_from_sock()
700 __free_page(con->rx_page); in receive_from_sock()
701 con->rx_page = NULL; in receive_from_sock()
706 mutex_unlock(&con->sock_mutex); in receive_from_sock()
710 if (!test_and_set_bit(CF_READ_PENDING, &con->flags)) in receive_from_sock()
711 queue_work(recv_workqueue, &con->rwork); in receive_from_sock()
712 mutex_unlock(&con->sock_mutex); in receive_from_sock()
716 mutex_unlock(&con->sock_mutex); in receive_from_sock()
718 close_connection(con, true, true, false); in receive_from_sock()
729 static int tcp_accept_from_sock(struct connection *con) in tcp_accept_from_sock() argument
746 mutex_lock_nested(&con->sock_mutex, 0); in tcp_accept_from_sock()
748 if (!con->sock) { in tcp_accept_from_sock()
749 mutex_unlock(&con->sock_mutex); in tcp_accept_from_sock()
753 result = kernel_accept(con->sock, &newsock, O_NONBLOCK); in tcp_accept_from_sock()
773 mutex_unlock(&con->sock_mutex); in tcp_accept_from_sock()
843 mutex_unlock(&con->sock_mutex); in tcp_accept_from_sock()
848 mutex_unlock(&con->sock_mutex); in tcp_accept_from_sock()
857 static int sctp_accept_from_sock(struct connection *con) in sctp_accept_from_sock() argument
875 mutex_lock_nested(&con->sock_mutex, 0); in sctp_accept_from_sock()
877 ret = kernel_accept(con->sock, &newsock, O_NONBLOCK); in sctp_accept_from_sock()
960 mutex_unlock(&con->sock_mutex); in sctp_accept_from_sock()
965 mutex_unlock(&con->sock_mutex); in sctp_accept_from_sock()
1001 static int sctp_bind_addrs(struct connection *con, uint16_t port) in sctp_bind_addrs() argument
1011 result = kernel_bind(con->sock, in sctp_bind_addrs()
1015 result = kernel_setsockopt(con->sock, SOL_SCTP, in sctp_bind_addrs()
1033 static void sctp_connect_to_sock(struct connection *con) in sctp_connect_to_sock() argument
1042 if (con->nodeid == 0) { in sctp_connect_to_sock()
1047 mutex_lock(&con->sock_mutex); in sctp_connect_to_sock()
1050 if (con->retries++ > MAX_CONNECT_RETRIES) in sctp_connect_to_sock()
1053 if (con->sock) { in sctp_connect_to_sock()
1054 log_print("node %d already connected.", con->nodeid); in sctp_connect_to_sock()
1059 result = nodeid_to_addr(con->nodeid, &daddr, NULL, true); in sctp_connect_to_sock()
1061 log_print("no address for nodeid %d", con->nodeid); in sctp_connect_to_sock()
1071 con->rx_action = receive_from_sock; in sctp_connect_to_sock()
1072 con->connect_action = sctp_connect_to_sock; in sctp_connect_to_sock()
1073 add_sock(sock, con); in sctp_connect_to_sock()
1076 if (sctp_bind_addrs(con, 0)) in sctp_connect_to_sock()
1081 log_print("connecting to %d", con->nodeid); in sctp_connect_to_sock()
1106 con->sock = NULL; in sctp_connect_to_sock()
1119 log_print("connect %d try %d error %d", con->nodeid, in sctp_connect_to_sock()
1120 con->retries, result); in sctp_connect_to_sock()
1121 mutex_unlock(&con->sock_mutex); in sctp_connect_to_sock()
1123 lowcomms_connect_sock(con); in sctp_connect_to_sock()
1128 mutex_unlock(&con->sock_mutex); in sctp_connect_to_sock()
1132 static void tcp_connect_to_sock(struct connection *con) in tcp_connect_to_sock() argument
1140 if (con->nodeid == 0) { in tcp_connect_to_sock()
1145 mutex_lock(&con->sock_mutex); in tcp_connect_to_sock()
1146 if (con->retries++ > MAX_CONNECT_RETRIES) in tcp_connect_to_sock()
1150 if (con->sock) in tcp_connect_to_sock()
1160 result = nodeid_to_addr(con->nodeid, &saddr, NULL, false); in tcp_connect_to_sock()
1162 log_print("no address for nodeid %d", con->nodeid); in tcp_connect_to_sock()
1166 con->rx_action = receive_from_sock; in tcp_connect_to_sock()
1167 con->connect_action = tcp_connect_to_sock; in tcp_connect_to_sock()
1168 add_sock(sock, con); in tcp_connect_to_sock()
1183 log_print("connecting to %d", con->nodeid); in tcp_connect_to_sock()
1197 if (con->sock) { in tcp_connect_to_sock()
1198 sock_release(con->sock); in tcp_connect_to_sock()
1199 con->sock = NULL; in tcp_connect_to_sock()
1212 log_print("connect %d try %d error %d", con->nodeid, in tcp_connect_to_sock()
1213 con->retries, result); in tcp_connect_to_sock()
1214 mutex_unlock(&con->sock_mutex); in tcp_connect_to_sock()
1216 lowcomms_connect_sock(con); in tcp_connect_to_sock()
1220 mutex_unlock(&con->sock_mutex); in tcp_connect_to_sock()
1224 static struct socket *tcp_create_listen_sock(struct connection *con, in tcp_create_listen_sock() argument
1256 sock->sk->sk_user_data = con; in tcp_create_listen_sock()
1258 con->rx_action = tcp_accept_from_sock; in tcp_create_listen_sock()
1259 con->connect_action = tcp_connect_to_sock; in tcp_create_listen_sock()
1269 con->sock = NULL; in tcp_create_listen_sock()
1313 struct connection *con = nodeid2con(0, GFP_NOFS); in sctp_listen_for_all() local
1317 if (!con) in sctp_listen_for_all()
1341 sock->sk->sk_user_data = con; in sctp_listen_for_all()
1343 con->sock = sock; in sctp_listen_for_all()
1344 con->sock->sk->sk_data_ready = lowcomms_data_ready; in sctp_listen_for_all()
1345 con->rx_action = sctp_accept_from_sock; in sctp_listen_for_all()
1346 con->connect_action = sctp_connect_to_sock; in sctp_listen_for_all()
1351 if (sctp_bind_addrs(con, dlm_config.ci_tcp_port)) in sctp_listen_for_all()
1364 con->sock = NULL; in sctp_listen_for_all()
1372 struct connection *con = nodeid2con(0, GFP_NOFS); in tcp_listen_for_all() local
1375 if (!con) in tcp_listen_for_all()
1387 sock = tcp_create_listen_sock(con, dlm_local_addr[0]); in tcp_listen_for_all()
1389 add_sock(sock, con); in tcp_listen_for_all()
1401 static struct writequeue_entry *new_writequeue_entry(struct connection *con, in new_writequeue_entry() argument
1420 entry->con = con; in new_writequeue_entry()
1427 struct connection *con; in dlm_lowcomms_get_buffer() local
1431 con = nodeid2con(nodeid, allocation); in dlm_lowcomms_get_buffer()
1432 if (!con) in dlm_lowcomms_get_buffer()
1435 spin_lock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1436 e = list_entry(con->writequeue.prev, struct writequeue_entry, list); in dlm_lowcomms_get_buffer()
1437 if ((&e->list == &con->writequeue) || in dlm_lowcomms_get_buffer()
1445 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1453 e = new_writequeue_entry(con, allocation); in dlm_lowcomms_get_buffer()
1455 spin_lock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1459 list_add_tail(&e->list, &con->writequeue); in dlm_lowcomms_get_buffer()
1460 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1469 struct connection *con = e->con; in dlm_lowcomms_commit_buffer() local
1472 spin_lock(&con->writequeue_lock); in dlm_lowcomms_commit_buffer()
1477 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_commit_buffer()
1479 queue_work(send_workqueue, &con->swork); in dlm_lowcomms_commit_buffer()
1483 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_commit_buffer()
1488 static void send_to_sock(struct connection *con) in send_to_sock() argument
1496 mutex_lock(&con->sock_mutex); in send_to_sock()
1497 if (con->sock == NULL) in send_to_sock()
1500 spin_lock(&con->writequeue_lock); in send_to_sock()
1502 e = list_entry(con->writequeue.next, struct writequeue_entry, in send_to_sock()
1504 if ((struct list_head *) e == &con->writequeue) in send_to_sock()
1510 spin_unlock(&con->writequeue_lock); in send_to_sock()
1514 ret = kernel_sendpage(con->sock, e->page, offset, len, in send_to_sock()
1518 test_bit(SOCKWQ_ASYNC_NOSPACE, &con->sock->flags) && in send_to_sock()
1519 !test_and_set_bit(CF_APP_LIMITED, &con->flags)) { in send_to_sock()
1523 set_bit(SOCK_NOSPACE, &con->sock->flags); in send_to_sock()
1524 con->sock->sk->sk_write_pending++; in send_to_sock()
1538 spin_lock(&con->writequeue_lock); in send_to_sock()
1541 spin_unlock(&con->writequeue_lock); in send_to_sock()
1543 mutex_unlock(&con->sock_mutex); in send_to_sock()
1547 mutex_unlock(&con->sock_mutex); in send_to_sock()
1548 close_connection(con, true, false, true); in send_to_sock()
1551 queue_work(send_workqueue, &con->swork); in send_to_sock()
1555 mutex_unlock(&con->sock_mutex); in send_to_sock()
1556 queue_work(send_workqueue, &con->swork); in send_to_sock()
1560 static void clean_one_writequeue(struct connection *con) in clean_one_writequeue() argument
1564 spin_lock(&con->writequeue_lock); in clean_one_writequeue()
1565 list_for_each_entry_safe(e, safe, &con->writequeue, list) { in clean_one_writequeue()
1569 spin_unlock(&con->writequeue_lock); in clean_one_writequeue()
1576 struct connection *con; in dlm_lowcomms_close() local
1580 con = nodeid2con(nodeid, 0); in dlm_lowcomms_close()
1581 if (con) { in dlm_lowcomms_close()
1582 set_bit(CF_CLOSE, &con->flags); in dlm_lowcomms_close()
1583 close_connection(con, true, true, true); in dlm_lowcomms_close()
1584 clean_one_writequeue(con); in dlm_lowcomms_close()
1603 struct connection *con = container_of(work, struct connection, rwork); in process_recv_sockets() local
1606 clear_bit(CF_READ_PENDING, &con->flags); in process_recv_sockets()
1608 err = con->rx_action(con); in process_recv_sockets()
1615 struct connection *con = container_of(work, struct connection, swork); in process_send_sockets() local
1617 clear_bit(CF_WRITE_PENDING, &con->flags); in process_send_sockets()
1618 if (con->sock == NULL) /* not mutex protected so check it inside too */ in process_send_sockets()
1619 con->connect_action(con); in process_send_sockets()
1620 if (!list_empty(&con->writequeue)) in process_send_sockets()
1621 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
1702 hlist_for_each_entry_safe(con, n, in work_flush()
1704 ok &= test_bit(CF_READ_PENDING, &con->flags); in work_flush()
1705 ok &= test_bit(CF_WRITE_PENDING, &con->flags); in work_flush()
1706 if (con->othercon) { in work_flush()
1708 &con->othercon->flags); in work_flush()
1710 &con->othercon->flags); in work_flush()
1736 struct connection *con; in dlm_lowcomms_start() local
1774 con = nodeid2con(0,0); in dlm_lowcomms_start()
1775 if (con) { in dlm_lowcomms_start()
1776 close_connection(con, false, true, true); in dlm_lowcomms_start()
1777 kmem_cache_free(con_cache, con); in dlm_lowcomms_start()