Lines Matching refs:con
139 struct connection *con; member
180 struct connection *con; in __find_con() local
184 hlist_for_each_entry(con, &connection_hash[r], list) { in __find_con()
185 if (con->nodeid == nodeid) in __find_con()
186 return con; in __find_con()
197 struct connection *con = NULL; in __nodeid2con() local
200 con = __find_con(nodeid); in __nodeid2con()
201 if (con || !alloc) in __nodeid2con()
202 return con; in __nodeid2con()
204 con = kmem_cache_zalloc(con_cache, alloc); in __nodeid2con()
205 if (!con) in __nodeid2con()
209 hlist_add_head(&con->list, &connection_hash[r]); in __nodeid2con()
211 con->nodeid = nodeid; in __nodeid2con()
212 mutex_init(&con->sock_mutex); in __nodeid2con()
213 INIT_LIST_HEAD(&con->writequeue); in __nodeid2con()
214 spin_lock_init(&con->writequeue_lock); in __nodeid2con()
215 INIT_WORK(&con->swork, process_send_sockets); in __nodeid2con()
216 INIT_WORK(&con->rwork, process_recv_sockets); in __nodeid2con()
219 if (con->nodeid) { in __nodeid2con()
222 con->connect_action = zerocon->connect_action; in __nodeid2con()
223 if (!con->rx_action) in __nodeid2con()
224 con->rx_action = zerocon->rx_action; in __nodeid2con()
227 return con; in __nodeid2con()
235 struct connection *con; in foreach_conn() local
238 hlist_for_each_entry_safe(con, n, &connection_hash[i], list) in foreach_conn()
239 conn_func(con); in foreach_conn()
245 struct connection *con; in nodeid2con() local
248 con = __nodeid2con(nodeid, allocation); in nodeid2con()
251 return con; in nodeid2con()
408 struct connection *con = sock2con(sk); in lowcomms_data_ready() local
409 if (con && !test_and_set_bit(CF_READ_PENDING, &con->flags)) in lowcomms_data_ready()
410 queue_work(recv_workqueue, &con->rwork); in lowcomms_data_ready()
415 struct connection *con = sock2con(sk); in lowcomms_write_space() local
417 if (!con) in lowcomms_write_space()
420 clear_bit(SOCK_NOSPACE, &con->sock->flags); in lowcomms_write_space()
422 if (test_and_clear_bit(CF_APP_LIMITED, &con->flags)) { in lowcomms_write_space()
423 con->sock->sk->sk_write_pending--; in lowcomms_write_space()
424 clear_bit(SOCKWQ_ASYNC_NOSPACE, &con->sock->flags); in lowcomms_write_space()
427 if (!test_and_set_bit(CF_WRITE_PENDING, &con->flags)) in lowcomms_write_space()
428 queue_work(send_workqueue, &con->swork); in lowcomms_write_space()
431 static inline void lowcomms_connect_sock(struct connection *con) in lowcomms_connect_sock() argument
433 if (test_bit(CF_CLOSE, &con->flags)) in lowcomms_connect_sock()
435 if (!test_and_set_bit(CF_CONNECT_PENDING, &con->flags)) in lowcomms_connect_sock()
436 queue_work(send_workqueue, &con->swork); in lowcomms_connect_sock()
456 struct connection *con; in dlm_lowcomms_connect_node() local
461 con = nodeid2con(nodeid, GFP_NOFS); in dlm_lowcomms_connect_node()
462 if (!con) in dlm_lowcomms_connect_node()
464 lowcomms_connect_sock(con); in dlm_lowcomms_connect_node()
470 struct connection *con = sock2con(sk); in lowcomms_error_report() local
473 if (nodeid_to_addr(con->nodeid, &saddr, NULL, false)) { in lowcomms_error_report()
477 con->nodeid, dlm_config.ci_tcp_port, in lowcomms_error_report()
486 con->nodeid, &sin4->sin_addr.s_addr, in lowcomms_error_report()
495 con->nodeid, sin6->sin6_addr.s6_addr32[0], in lowcomms_error_report()
502 con->orig_error_report(sk); in lowcomms_error_report()
506 static void add_sock(struct socket *sock, struct connection *con) in add_sock() argument
508 con->sock = sock; in add_sock()
511 con->sock->sk->sk_data_ready = lowcomms_data_ready; in add_sock()
512 con->sock->sk->sk_write_space = lowcomms_write_space; in add_sock()
513 con->sock->sk->sk_state_change = lowcomms_state_change; in add_sock()
514 con->sock->sk->sk_user_data = con; in add_sock()
515 con->sock->sk->sk_allocation = GFP_NOFS; in add_sock()
516 con->orig_error_report = con->sock->sk->sk_error_report; in add_sock()
517 con->sock->sk->sk_error_report = lowcomms_error_report; in add_sock()
540 static void close_connection(struct connection *con, bool and_other, in close_connection() argument
543 clear_bit(CF_CONNECT_PENDING, &con->flags); in close_connection()
544 clear_bit(CF_WRITE_PENDING, &con->flags); in close_connection()
545 if (tx && cancel_work_sync(&con->swork)) in close_connection()
546 log_print("canceled swork for node %d", con->nodeid); in close_connection()
547 if (rx && cancel_work_sync(&con->rwork)) in close_connection()
548 log_print("canceled rwork for node %d", con->nodeid); in close_connection()
550 mutex_lock(&con->sock_mutex); in close_connection()
551 if (con->sock) { in close_connection()
552 sock_release(con->sock); in close_connection()
553 con->sock = NULL; in close_connection()
555 if (con->othercon && and_other) { in close_connection()
557 close_connection(con->othercon, false, true, true); in close_connection()
559 if (con->rx_page) { in close_connection()
560 __free_page(con->rx_page); in close_connection()
561 con->rx_page = NULL; in close_connection()
564 con->retries = 0; in close_connection()
565 mutex_unlock(&con->sock_mutex); in close_connection()
569 static int receive_from_sock(struct connection *con) in receive_from_sock() argument
579 mutex_lock(&con->sock_mutex); in receive_from_sock()
581 if (con->sock == NULL) { in receive_from_sock()
585 if (con->nodeid == 0) { in receive_from_sock()
590 if (con->rx_page == NULL) { in receive_from_sock()
595 con->rx_page = alloc_page(GFP_ATOMIC); in receive_from_sock()
596 if (con->rx_page == NULL) in receive_from_sock()
598 cbuf_init(&con->cb, PAGE_CACHE_SIZE); in receive_from_sock()
605 iov[0].iov_len = con->cb.base - cbuf_data(&con->cb); in receive_from_sock()
606 iov[0].iov_base = page_address(con->rx_page) + cbuf_data(&con->cb); in receive_from_sock()
614 if (cbuf_data(&con->cb) >= con->cb.base) { in receive_from_sock()
615 iov[0].iov_len = PAGE_CACHE_SIZE - cbuf_data(&con->cb); in receive_from_sock()
616 iov[1].iov_len = con->cb.base; in receive_from_sock()
617 iov[1].iov_base = page_address(con->rx_page); in receive_from_sock()
622 r = ret = kernel_recvmsg(con->sock, &msg, iov, nvec, len, in receive_from_sock()
629 cbuf_add(&con->cb, ret); in receive_from_sock()
630 ret = dlm_process_incoming_buffer(con->nodeid, in receive_from_sock()
631 page_address(con->rx_page), in receive_from_sock()
632 con->cb.base, con->cb.len, in receive_from_sock()
636 page_address(con->rx_page), con->cb.base, in receive_from_sock()
637 con->cb.len, r); in receive_from_sock()
641 cbuf_eat(&con->cb, ret); in receive_from_sock()
643 if (cbuf_empty(&con->cb) && !call_again_soon) { in receive_from_sock()
644 __free_page(con->rx_page); in receive_from_sock()
645 con->rx_page = NULL; in receive_from_sock()
650 mutex_unlock(&con->sock_mutex); in receive_from_sock()
654 if (!test_and_set_bit(CF_READ_PENDING, &con->flags)) in receive_from_sock()
655 queue_work(recv_workqueue, &con->rwork); in receive_from_sock()
656 mutex_unlock(&con->sock_mutex); in receive_from_sock()
660 mutex_unlock(&con->sock_mutex); in receive_from_sock()
662 close_connection(con, false, true, false); in receive_from_sock()
673 static int tcp_accept_from_sock(struct connection *con) in tcp_accept_from_sock() argument
696 mutex_lock_nested(&con->sock_mutex, 0); in tcp_accept_from_sock()
699 if (con->sock == NULL) in tcp_accept_from_sock()
702 newsock->type = con->sock->type; in tcp_accept_from_sock()
703 newsock->ops = con->sock->ops; in tcp_accept_from_sock()
705 result = con->sock->ops->accept(con->sock, newsock, O_NONBLOCK); in tcp_accept_from_sock()
725 mutex_unlock(&con->sock_mutex); in tcp_accept_from_sock()
790 mutex_unlock(&con->sock_mutex); in tcp_accept_from_sock()
795 mutex_unlock(&con->sock_mutex); in tcp_accept_from_sock()
803 static int sctp_accept_from_sock(struct connection *con) in sctp_accept_from_sock() argument
821 mutex_lock_nested(&con->sock_mutex, 0); in sctp_accept_from_sock()
823 ret = kernel_accept(con->sock, &newsock, O_NONBLOCK); in sctp_accept_from_sock()
903 mutex_unlock(&con->sock_mutex); in sctp_accept_from_sock()
908 mutex_unlock(&con->sock_mutex); in sctp_accept_from_sock()
944 static int sctp_bind_addrs(struct connection *con, uint16_t port) in sctp_bind_addrs() argument
954 result = kernel_bind(con->sock, in sctp_bind_addrs()
958 result = kernel_setsockopt(con->sock, SOL_SCTP, in sctp_bind_addrs()
976 static void sctp_connect_to_sock(struct connection *con) in sctp_connect_to_sock() argument
984 if (con->nodeid == 0) { in sctp_connect_to_sock()
989 mutex_lock(&con->sock_mutex); in sctp_connect_to_sock()
992 if (con->retries++ > MAX_CONNECT_RETRIES) in sctp_connect_to_sock()
995 if (con->sock) { in sctp_connect_to_sock()
996 log_print("node %d already connected.", con->nodeid); in sctp_connect_to_sock()
1001 result = nodeid_to_addr(con->nodeid, &daddr, NULL, true); in sctp_connect_to_sock()
1003 log_print("no address for nodeid %d", con->nodeid); in sctp_connect_to_sock()
1013 sock->sk->sk_user_data = con; in sctp_connect_to_sock()
1014 con->rx_action = receive_from_sock; in sctp_connect_to_sock()
1015 con->connect_action = sctp_connect_to_sock; in sctp_connect_to_sock()
1016 add_sock(sock, con); in sctp_connect_to_sock()
1019 if (sctp_bind_addrs(con, 0)) in sctp_connect_to_sock()
1024 log_print("connecting to %d", con->nodeid); in sctp_connect_to_sock()
1039 con->sock = NULL; in sctp_connect_to_sock()
1052 log_print("connect %d try %d error %d", con->nodeid, in sctp_connect_to_sock()
1053 con->retries, result); in sctp_connect_to_sock()
1054 mutex_unlock(&con->sock_mutex); in sctp_connect_to_sock()
1056 clear_bit(CF_CONNECT_PENDING, &con->flags); in sctp_connect_to_sock()
1057 lowcomms_connect_sock(con); in sctp_connect_to_sock()
1062 mutex_unlock(&con->sock_mutex); in sctp_connect_to_sock()
1063 set_bit(CF_WRITE_PENDING, &con->flags); in sctp_connect_to_sock()
1067 static void tcp_connect_to_sock(struct connection *con) in tcp_connect_to_sock() argument
1075 if (con->nodeid == 0) { in tcp_connect_to_sock()
1080 mutex_lock(&con->sock_mutex); in tcp_connect_to_sock()
1081 if (con->retries++ > MAX_CONNECT_RETRIES) in tcp_connect_to_sock()
1085 if (con->sock) in tcp_connect_to_sock()
1095 result = nodeid_to_addr(con->nodeid, &saddr, NULL, false); in tcp_connect_to_sock()
1097 log_print("no address for nodeid %d", con->nodeid); in tcp_connect_to_sock()
1101 sock->sk->sk_user_data = con; in tcp_connect_to_sock()
1102 con->rx_action = receive_from_sock; in tcp_connect_to_sock()
1103 con->connect_action = tcp_connect_to_sock; in tcp_connect_to_sock()
1104 add_sock(sock, con); in tcp_connect_to_sock()
1119 log_print("connecting to %d", con->nodeid); in tcp_connect_to_sock()
1133 if (con->sock) { in tcp_connect_to_sock()
1134 sock_release(con->sock); in tcp_connect_to_sock()
1135 con->sock = NULL; in tcp_connect_to_sock()
1148 log_print("connect %d try %d error %d", con->nodeid, in tcp_connect_to_sock()
1149 con->retries, result); in tcp_connect_to_sock()
1150 mutex_unlock(&con->sock_mutex); in tcp_connect_to_sock()
1152 clear_bit(CF_CONNECT_PENDING, &con->flags); in tcp_connect_to_sock()
1153 lowcomms_connect_sock(con); in tcp_connect_to_sock()
1157 mutex_unlock(&con->sock_mutex); in tcp_connect_to_sock()
1158 set_bit(CF_WRITE_PENDING, &con->flags); in tcp_connect_to_sock()
1162 static struct socket *tcp_create_listen_sock(struct connection *con, in tcp_create_listen_sock() argument
1193 con->rx_action = tcp_accept_from_sock; in tcp_create_listen_sock()
1194 con->connect_action = tcp_connect_to_sock; in tcp_create_listen_sock()
1203 con->sock = NULL; in tcp_create_listen_sock()
1248 struct connection *con = nodeid2con(0, GFP_NOFS); in sctp_listen_for_all() local
1252 if (!con) in sctp_listen_for_all()
1275 sock->sk->sk_user_data = con; in sctp_listen_for_all()
1276 con->sock = sock; in sctp_listen_for_all()
1277 con->sock->sk->sk_data_ready = lowcomms_data_ready; in sctp_listen_for_all()
1278 con->rx_action = sctp_accept_from_sock; in sctp_listen_for_all()
1279 con->connect_action = sctp_connect_to_sock; in sctp_listen_for_all()
1282 if (sctp_bind_addrs(con, dlm_config.ci_tcp_port)) in sctp_listen_for_all()
1295 con->sock = NULL; in sctp_listen_for_all()
1303 struct connection *con = nodeid2con(0, GFP_NOFS); in tcp_listen_for_all() local
1306 if (!con) in tcp_listen_for_all()
1318 sock = tcp_create_listen_sock(con, dlm_local_addr[0]); in tcp_listen_for_all()
1320 add_sock(sock, con); in tcp_listen_for_all()
1332 static struct writequeue_entry *new_writequeue_entry(struct connection *con, in new_writequeue_entry() argument
1351 entry->con = con; in new_writequeue_entry()
1358 struct connection *con; in dlm_lowcomms_get_buffer() local
1362 con = nodeid2con(nodeid, allocation); in dlm_lowcomms_get_buffer()
1363 if (!con) in dlm_lowcomms_get_buffer()
1366 spin_lock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1367 e = list_entry(con->writequeue.prev, struct writequeue_entry, list); in dlm_lowcomms_get_buffer()
1368 if ((&e->list == &con->writequeue) || in dlm_lowcomms_get_buffer()
1376 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1384 e = new_writequeue_entry(con, allocation); in dlm_lowcomms_get_buffer()
1386 spin_lock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1390 list_add_tail(&e->list, &con->writequeue); in dlm_lowcomms_get_buffer()
1391 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_get_buffer()
1400 struct connection *con = e->con; in dlm_lowcomms_commit_buffer() local
1403 spin_lock(&con->writequeue_lock); in dlm_lowcomms_commit_buffer()
1408 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_commit_buffer()
1410 if (!test_and_set_bit(CF_WRITE_PENDING, &con->flags)) { in dlm_lowcomms_commit_buffer()
1411 queue_work(send_workqueue, &con->swork); in dlm_lowcomms_commit_buffer()
1416 spin_unlock(&con->writequeue_lock); in dlm_lowcomms_commit_buffer()
1421 static void send_to_sock(struct connection *con) in send_to_sock() argument
1429 mutex_lock(&con->sock_mutex); in send_to_sock()
1430 if (con->sock == NULL) in send_to_sock()
1433 spin_lock(&con->writequeue_lock); in send_to_sock()
1435 e = list_entry(con->writequeue.next, struct writequeue_entry, in send_to_sock()
1437 if ((struct list_head *) e == &con->writequeue) in send_to_sock()
1443 spin_unlock(&con->writequeue_lock); in send_to_sock()
1447 ret = kernel_sendpage(con->sock, e->page, offset, len, in send_to_sock()
1451 test_bit(SOCKWQ_ASYNC_NOSPACE, &con->sock->flags) && in send_to_sock()
1452 !test_and_set_bit(CF_APP_LIMITED, &con->flags)) { in send_to_sock()
1456 set_bit(SOCK_NOSPACE, &con->sock->flags); in send_to_sock()
1457 con->sock->sk->sk_write_pending++; in send_to_sock()
1471 spin_lock(&con->writequeue_lock); in send_to_sock()
1474 spin_unlock(&con->writequeue_lock); in send_to_sock()
1476 mutex_unlock(&con->sock_mutex); in send_to_sock()
1480 mutex_unlock(&con->sock_mutex); in send_to_sock()
1481 close_connection(con, false, false, true); in send_to_sock()
1482 lowcomms_connect_sock(con); in send_to_sock()
1486 mutex_unlock(&con->sock_mutex); in send_to_sock()
1487 lowcomms_connect_sock(con); in send_to_sock()
1490 static void clean_one_writequeue(struct connection *con) in clean_one_writequeue() argument
1494 spin_lock(&con->writequeue_lock); in clean_one_writequeue()
1495 list_for_each_entry_safe(e, safe, &con->writequeue, list) { in clean_one_writequeue()
1499 spin_unlock(&con->writequeue_lock); in clean_one_writequeue()
1506 struct connection *con; in dlm_lowcomms_close() local
1510 con = nodeid2con(nodeid, 0); in dlm_lowcomms_close()
1511 if (con) { in dlm_lowcomms_close()
1512 set_bit(CF_CLOSE, &con->flags); in dlm_lowcomms_close()
1513 close_connection(con, true, true, true); in dlm_lowcomms_close()
1514 clean_one_writequeue(con); in dlm_lowcomms_close()
1533 struct connection *con = container_of(work, struct connection, rwork); in process_recv_sockets() local
1536 clear_bit(CF_READ_PENDING, &con->flags); in process_recv_sockets()
1538 err = con->rx_action(con); in process_recv_sockets()
1545 struct connection *con = container_of(work, struct connection, swork); in process_send_sockets() local
1547 if (test_and_clear_bit(CF_CONNECT_PENDING, &con->flags)) in process_send_sockets()
1548 con->connect_action(con); in process_send_sockets()
1549 if (test_and_clear_bit(CF_WRITE_PENDING, &con->flags)) in process_send_sockets()
1550 send_to_sock(con); in process_send_sockets()
1586 static void stop_conn(struct connection *con) in stop_conn() argument
1588 con->flags |= 0x0F; in stop_conn()
1589 if (con->sock && con->sock->sk) in stop_conn()
1590 con->sock->sk->sk_user_data = NULL; in stop_conn()
1593 static void free_conn(struct connection *con) in free_conn() argument
1595 close_connection(con, true, true, true); in free_conn()
1596 if (con->othercon) in free_conn()
1597 kmem_cache_free(con_cache, con->othercon); in free_conn()
1598 hlist_del(&con->list); in free_conn()
1599 kmem_cache_free(con_cache, con); in free_conn()
1626 struct connection *con; in dlm_lowcomms_start() local
1664 con = nodeid2con(0,0); in dlm_lowcomms_start()
1665 if (con) { in dlm_lowcomms_start()
1666 close_connection(con, false, true, true); in dlm_lowcomms_start()
1667 kmem_cache_free(con_cache, con); in dlm_lowcomms_start()