Lines Matching refs:con
116 static void tipc_conn_delete_sub(struct tipc_conn *con, struct tipc_subscr *s);
118 static bool connected(struct tipc_conn *con) in connected() argument
120 return con && test_bit(CF_CONNECTED, &con->flags); in connected()
125 struct tipc_conn *con = container_of(kref, struct tipc_conn, kref); in tipc_conn_kref_release() local
126 struct tipc_topsrv *s = con->server; in tipc_conn_kref_release()
130 idr_remove(&s->conn_idr, con->conid); in tipc_conn_kref_release()
133 if (con->sock) in tipc_conn_kref_release()
134 sock_release(con->sock); in tipc_conn_kref_release()
136 spin_lock_bh(&con->outqueue_lock); in tipc_conn_kref_release()
137 list_for_each_entry_safe(e, safe, &con->outqueue, list) { in tipc_conn_kref_release()
141 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_kref_release()
142 kfree(con); in tipc_conn_kref_release()
145 static void conn_put(struct tipc_conn *con) in conn_put() argument
147 kref_put(&con->kref, tipc_conn_kref_release); in conn_put()
150 static void conn_get(struct tipc_conn *con) in conn_get() argument
152 kref_get(&con->kref); in conn_get()
155 static void tipc_conn_close(struct tipc_conn *con) in tipc_conn_close() argument
157 struct sock *sk = con->sock->sk; in tipc_conn_close()
161 disconnect = test_and_clear_bit(CF_CONNECTED, &con->flags); in tipc_conn_close()
165 tipc_conn_delete_sub(con, NULL); in tipc_conn_close()
174 kernel_sock_shutdown(con->sock, SHUT_RDWR); in tipc_conn_close()
176 conn_put(con); in tipc_conn_close()
181 struct tipc_conn *con; in tipc_conn_alloc() local
184 con = kzalloc(sizeof(*con), GFP_ATOMIC); in tipc_conn_alloc()
185 if (!con) in tipc_conn_alloc()
188 kref_init(&con->kref); in tipc_conn_alloc()
189 INIT_LIST_HEAD(&con->outqueue); in tipc_conn_alloc()
190 INIT_LIST_HEAD(&con->sub_list); in tipc_conn_alloc()
191 spin_lock_init(&con->outqueue_lock); in tipc_conn_alloc()
192 spin_lock_init(&con->sub_lock); in tipc_conn_alloc()
193 INIT_WORK(&con->swork, tipc_conn_send_work); in tipc_conn_alloc()
194 INIT_WORK(&con->rwork, tipc_conn_recv_work); in tipc_conn_alloc()
197 ret = idr_alloc(&s->conn_idr, con, 0, 0, GFP_ATOMIC); in tipc_conn_alloc()
199 kfree(con); in tipc_conn_alloc()
203 con->conid = ret; in tipc_conn_alloc()
207 set_bit(CF_CONNECTED, &con->flags); in tipc_conn_alloc()
208 con->server = s; in tipc_conn_alloc()
210 return con; in tipc_conn_alloc()
215 struct tipc_conn *con; in tipc_conn_lookup() local
218 con = idr_find(&s->conn_idr, conid); in tipc_conn_lookup()
219 if (!connected(con) || !kref_get_unless_zero(&con->kref)) in tipc_conn_lookup()
220 con = NULL; in tipc_conn_lookup()
222 return con; in tipc_conn_lookup()
228 static void tipc_conn_delete_sub(struct tipc_conn *con, struct tipc_subscr *s) in tipc_conn_delete_sub() argument
230 struct tipc_net *tn = tipc_net(con->server->net); in tipc_conn_delete_sub()
231 struct list_head *sub_list = &con->sub_list; in tipc_conn_delete_sub()
234 spin_lock_bh(&con->sub_lock); in tipc_conn_delete_sub()
243 spin_unlock_bh(&con->sub_lock); in tipc_conn_delete_sub()
246 static void tipc_conn_send_to_sock(struct tipc_conn *con) in tipc_conn_send_to_sock() argument
248 struct list_head *queue = &con->outqueue; in tipc_conn_send_to_sock()
249 struct tipc_topsrv *srv = con->server; in tipc_conn_send_to_sock()
257 spin_lock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
262 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
265 tipc_conn_delete_sub(con, &evt->s); in tipc_conn_send_to_sock()
273 if (con->sock) { in tipc_conn_send_to_sock()
274 ret = kernel_sendmsg(con->sock, &msg, &iov, in tipc_conn_send_to_sock()
280 return tipc_conn_close(con); in tipc_conn_send_to_sock()
291 spin_lock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
295 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
300 struct tipc_conn *con = container_of(work, struct tipc_conn, swork); in tipc_conn_send_work() local
302 if (connected(con)) in tipc_conn_send_work()
303 tipc_conn_send_to_sock(con); in tipc_conn_send_work()
305 conn_put(con); in tipc_conn_send_work()
316 struct tipc_conn *con; in tipc_topsrv_queue_evt() local
318 con = tipc_conn_lookup(srv, conid); in tipc_topsrv_queue_evt()
319 if (!con) in tipc_topsrv_queue_evt()
322 if (!connected(con)) in tipc_topsrv_queue_evt()
330 spin_lock_bh(&con->outqueue_lock); in tipc_topsrv_queue_evt()
331 list_add_tail(&e->list, &con->outqueue); in tipc_topsrv_queue_evt()
332 spin_unlock_bh(&con->outqueue_lock); in tipc_topsrv_queue_evt()
334 if (queue_work(srv->send_wq, &con->swork)) in tipc_topsrv_queue_evt()
337 conn_put(con); in tipc_topsrv_queue_evt()
346 struct tipc_conn *con; in tipc_conn_write_space() local
349 con = sk->sk_user_data; in tipc_conn_write_space()
350 if (connected(con)) { in tipc_conn_write_space()
351 conn_get(con); in tipc_conn_write_space()
352 if (!queue_work(con->server->send_wq, &con->swork)) in tipc_conn_write_space()
353 conn_put(con); in tipc_conn_write_space()
359 struct tipc_conn *con, in tipc_conn_rcv_sub() argument
368 tipc_conn_delete_sub(con, s); in tipc_conn_rcv_sub()
375 sub = tipc_sub_subscribe(srv->net, s, con->conid); in tipc_conn_rcv_sub()
379 spin_lock_bh(&con->sub_lock); in tipc_conn_rcv_sub()
380 list_add(&sub->sub_list, &con->sub_list); in tipc_conn_rcv_sub()
381 spin_unlock_bh(&con->sub_lock); in tipc_conn_rcv_sub()
385 static int tipc_conn_rcv_from_sock(struct tipc_conn *con) in tipc_conn_rcv_from_sock() argument
387 struct tipc_topsrv *srv = con->server; in tipc_conn_rcv_from_sock()
388 struct sock *sk = con->sock->sk; in tipc_conn_rcv_from_sock()
398 ret = sock_recvmsg(con->sock, &msg, MSG_DONTWAIT); in tipc_conn_rcv_from_sock()
404 if (likely(connected(con))) in tipc_conn_rcv_from_sock()
405 ret = tipc_conn_rcv_sub(srv, con, &s); in tipc_conn_rcv_from_sock()
411 tipc_conn_close(con); in tipc_conn_rcv_from_sock()
417 struct tipc_conn *con = container_of(work, struct tipc_conn, rwork); in tipc_conn_recv_work() local
420 while (connected(con)) { in tipc_conn_recv_work()
421 if (tipc_conn_rcv_from_sock(con)) in tipc_conn_recv_work()
430 conn_put(con); in tipc_conn_recv_work()
438 struct tipc_conn *con; in tipc_conn_data_ready() local
441 con = sk->sk_user_data; in tipc_conn_data_ready()
442 if (connected(con)) { in tipc_conn_data_ready()
443 conn_get(con); in tipc_conn_data_ready()
444 if (!queue_work(con->server->rcv_wq, &con->rwork)) in tipc_conn_data_ready()
445 conn_put(con); in tipc_conn_data_ready()
455 struct tipc_conn *con; in tipc_topsrv_accept() local
463 con = tipc_conn_alloc(srv); in tipc_topsrv_accept()
464 if (IS_ERR(con)) { in tipc_topsrv_accept()
465 ret = PTR_ERR(con); in tipc_topsrv_accept()
474 newsk->sk_user_data = con; in tipc_topsrv_accept()
475 con->sock = newsock; in tipc_topsrv_accept()
563 struct tipc_conn *con; in tipc_topsrv_kern_subscr() local
573 con = tipc_conn_alloc(tipc_topsrv(net)); in tipc_topsrv_kern_subscr()
574 if (IS_ERR(con)) in tipc_topsrv_kern_subscr()
577 *conid = con->conid; in tipc_topsrv_kern_subscr()
578 con->sock = NULL; in tipc_topsrv_kern_subscr()
579 rc = tipc_conn_rcv_sub(tipc_topsrv(net), con, &sub); in tipc_topsrv_kern_subscr()
582 conn_put(con); in tipc_topsrv_kern_subscr()
588 struct tipc_conn *con; in tipc_topsrv_kern_unsubscr() local
590 con = tipc_conn_lookup(tipc_topsrv(net), conid); in tipc_topsrv_kern_unsubscr()
591 if (!con) in tipc_topsrv_kern_unsubscr()
594 test_and_clear_bit(CF_CONNECTED, &con->flags); in tipc_topsrv_kern_unsubscr()
595 tipc_conn_delete_sub(con, NULL); in tipc_topsrv_kern_unsubscr()
596 conn_put(con); in tipc_topsrv_kern_unsubscr()
597 conn_put(con); in tipc_topsrv_kern_unsubscr()
686 struct tipc_conn *con; in tipc_topsrv_stop() local
691 con = idr_find(&srv->conn_idr, id); in tipc_topsrv_stop()
692 if (con) { in tipc_topsrv_stop()
694 tipc_conn_close(con); in tipc_topsrv_stop()