Lines Matching refs:con

72 	int (*rx_action) (struct tipc_conn *con);
88 static void tipc_clean_outqueues(struct tipc_conn *con);
92 struct tipc_conn *con = container_of(kref, struct tipc_conn, kref); in tipc_conn_kref_release() local
93 struct sockaddr_tipc *saddr = con->server->saddr; in tipc_conn_kref_release()
94 struct socket *sock = con->sock; in tipc_conn_kref_release()
99 if (test_bit(CF_SERVER, &con->flags)) { in tipc_conn_kref_release()
106 con->sock = NULL; in tipc_conn_kref_release()
109 tipc_clean_outqueues(con); in tipc_conn_kref_release()
110 kfree(con); in tipc_conn_kref_release()
113 static void conn_put(struct tipc_conn *con) in conn_put() argument
115 kref_put(&con->kref, tipc_conn_kref_release); in conn_put()
118 static void conn_get(struct tipc_conn *con) in conn_get() argument
120 kref_get(&con->kref); in conn_get()
125 struct tipc_conn *con; in tipc_conn_lookup() local
128 con = idr_find(&s->conn_idr, conid); in tipc_conn_lookup()
129 if (con) in tipc_conn_lookup()
130 conn_get(con); in tipc_conn_lookup()
132 return con; in tipc_conn_lookup()
137 struct tipc_conn *con; in sock_data_ready() local
140 con = sock2con(sk); in sock_data_ready()
141 if (con && test_bit(CF_CONNECTED, &con->flags)) { in sock_data_ready()
142 conn_get(con); in sock_data_ready()
143 if (!queue_work(con->server->rcv_wq, &con->rwork)) in sock_data_ready()
144 conn_put(con); in sock_data_ready()
151 struct tipc_conn *con; in sock_write_space() local
154 con = sock2con(sk); in sock_write_space()
155 if (con && test_bit(CF_CONNECTED, &con->flags)) { in sock_write_space()
156 conn_get(con); in sock_write_space()
157 if (!queue_work(con->server->send_wq, &con->swork)) in sock_write_space()
158 conn_put(con); in sock_write_space()
163 static void tipc_register_callbacks(struct socket *sock, struct tipc_conn *con) in tipc_register_callbacks() argument
171 sk->sk_user_data = con; in tipc_register_callbacks()
173 con->sock = sock; in tipc_register_callbacks()
178 static void tipc_unregister_callbacks(struct tipc_conn *con) in tipc_unregister_callbacks() argument
180 struct sock *sk = con->sock->sk; in tipc_unregister_callbacks()
187 static void tipc_close_conn(struct tipc_conn *con) in tipc_close_conn() argument
189 struct tipc_server *s = con->server; in tipc_close_conn()
191 if (test_and_clear_bit(CF_CONNECTED, &con->flags)) { in tipc_close_conn()
192 if (con->conid) in tipc_close_conn()
193 s->tipc_conn_shutdown(con->conid, con->usr_data); in tipc_close_conn()
196 idr_remove(&s->conn_idr, con->conid); in tipc_close_conn()
200 tipc_unregister_callbacks(con); in tipc_close_conn()
208 kernel_sock_shutdown(con->sock, SHUT_RDWR); in tipc_close_conn()
210 conn_put(con); in tipc_close_conn()
216 struct tipc_conn *con; in tipc_alloc_conn() local
219 con = kzalloc(sizeof(struct tipc_conn), GFP_ATOMIC); in tipc_alloc_conn()
220 if (!con) in tipc_alloc_conn()
223 kref_init(&con->kref); in tipc_alloc_conn()
224 INIT_LIST_HEAD(&con->outqueue); in tipc_alloc_conn()
225 spin_lock_init(&con->outqueue_lock); in tipc_alloc_conn()
226 INIT_WORK(&con->swork, tipc_send_work); in tipc_alloc_conn()
227 INIT_WORK(&con->rwork, tipc_recv_work); in tipc_alloc_conn()
230 ret = idr_alloc(&s->conn_idr, con, 0, 0, GFP_ATOMIC); in tipc_alloc_conn()
232 kfree(con); in tipc_alloc_conn()
236 con->conid = ret; in tipc_alloc_conn()
240 set_bit(CF_CONNECTED, &con->flags); in tipc_alloc_conn()
241 con->server = s; in tipc_alloc_conn()
243 return con; in tipc_alloc_conn()
246 static int tipc_receive_from_sock(struct tipc_conn *con) in tipc_receive_from_sock() argument
249 struct tipc_server *s = con->server; in tipc_receive_from_sock()
264 ret = kernel_recvmsg(con->sock, &msg, &iov, 1, iov.iov_len, in tipc_receive_from_sock()
271 s->tipc_conn_recvmsg(sock_net(con->sock->sk), con->conid, &addr, in tipc_receive_from_sock()
272 con->usr_data, buf, ret); in tipc_receive_from_sock()
280 tipc_close_conn(con); in tipc_receive_from_sock()
288 static int tipc_accept_from_sock(struct tipc_conn *con) in tipc_accept_from_sock() argument
290 struct tipc_server *s = con->server; in tipc_accept_from_sock()
291 struct socket *sock = con->sock; in tipc_accept_from_sock()
300 newcon = tipc_alloc_conn(con->server); in tipc_accept_from_sock()
322 static struct socket *tipc_create_listen_sock(struct tipc_conn *con) in tipc_create_listen_sock() argument
324 struct tipc_server *s = con->server; in tipc_create_listen_sock()
342 con->rx_action = tipc_accept_from_sock; in tipc_create_listen_sock()
350 con->rx_action = tipc_receive_from_sock; in tipc_create_listen_sock()
374 set_bit(CF_SERVER, &con->flags); in tipc_create_listen_sock()
387 struct tipc_conn *con; in tipc_open_listening_sock() local
389 con = tipc_alloc_conn(s); in tipc_open_listening_sock()
390 if (IS_ERR(con)) in tipc_open_listening_sock()
391 return PTR_ERR(con); in tipc_open_listening_sock()
393 sock = tipc_create_listen_sock(con); in tipc_open_listening_sock()
395 idr_remove(&s->conn_idr, con->conid); in tipc_open_listening_sock()
397 kfree(con); in tipc_open_listening_sock()
401 tipc_register_callbacks(sock, con); in tipc_open_listening_sock()
433 static void tipc_clean_outqueues(struct tipc_conn *con) in tipc_clean_outqueues() argument
437 spin_lock_bh(&con->outqueue_lock); in tipc_clean_outqueues()
438 list_for_each_entry_safe(e, safe, &con->outqueue, list) { in tipc_clean_outqueues()
442 spin_unlock_bh(&con->outqueue_lock); in tipc_clean_outqueues()
449 struct tipc_conn *con; in tipc_conn_sendmsg() local
451 con = tipc_conn_lookup(s, conid); in tipc_conn_sendmsg()
452 if (!con) in tipc_conn_sendmsg()
457 conn_put(con); in tipc_conn_sendmsg()
464 spin_lock_bh(&con->outqueue_lock); in tipc_conn_sendmsg()
465 list_add_tail(&e->list, &con->outqueue); in tipc_conn_sendmsg()
466 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_sendmsg()
468 if (test_bit(CF_CONNECTED, &con->flags)) { in tipc_conn_sendmsg()
469 if (!queue_work(s->send_wq, &con->swork)) in tipc_conn_sendmsg()
470 conn_put(con); in tipc_conn_sendmsg()
472 conn_put(con); in tipc_conn_sendmsg()
479 struct tipc_conn *con; in tipc_conn_terminate() local
481 con = tipc_conn_lookup(s, conid); in tipc_conn_terminate()
482 if (con) { in tipc_conn_terminate()
483 tipc_close_conn(con); in tipc_conn_terminate()
484 conn_put(con); in tipc_conn_terminate()
488 static void tipc_send_to_sock(struct tipc_conn *con) in tipc_send_to_sock() argument
491 struct tipc_server *s = con->server; in tipc_send_to_sock()
496 spin_lock_bh(&con->outqueue_lock); in tipc_send_to_sock()
498 e = list_entry(con->outqueue.next, struct outqueue_entry, in tipc_send_to_sock()
500 if ((struct list_head *) e == &con->outqueue) in tipc_send_to_sock()
502 spin_unlock_bh(&con->outqueue_lock); in tipc_send_to_sock()
511 ret = kernel_sendmsg(con->sock, &msg, &e->iov, 1, in tipc_send_to_sock()
526 spin_lock_bh(&con->outqueue_lock); in tipc_send_to_sock()
530 spin_unlock_bh(&con->outqueue_lock); in tipc_send_to_sock()
535 tipc_close_conn(con); in tipc_send_to_sock()
540 struct tipc_conn *con = container_of(work, struct tipc_conn, rwork); in tipc_recv_work() local
543 while (test_bit(CF_CONNECTED, &con->flags)) { in tipc_recv_work()
544 if (con->rx_action(con)) in tipc_recv_work()
553 conn_put(con); in tipc_recv_work()
558 struct tipc_conn *con = container_of(work, struct tipc_conn, swork); in tipc_send_work() local
560 if (test_bit(CF_CONNECTED, &con->flags)) in tipc_send_work()
561 tipc_send_to_sock(con); in tipc_send_work()
563 conn_put(con); in tipc_send_work()
619 struct tipc_conn *con; in tipc_server_stop() local
625 con = idr_find(&s->conn_idr, id); in tipc_server_stop()
626 if (con) { in tipc_server_stop()
629 tipc_close_conn(con); in tipc_server_stop()