Lines Matching refs:con

117 static void tipc_conn_delete_sub(struct tipc_conn *con, struct tipc_subscr *s);
119 static bool connected(struct tipc_conn *con) in connected() argument
121 return con && test_bit(CF_CONNECTED, &con->flags); in connected()
126 struct tipc_conn *con = container_of(kref, struct tipc_conn, kref); in tipc_conn_kref_release() local
127 struct tipc_topsrv *s = con->server; in tipc_conn_kref_release()
131 idr_remove(&s->conn_idr, con->conid); in tipc_conn_kref_release()
134 if (con->sock) in tipc_conn_kref_release()
135 sock_release(con->sock); in tipc_conn_kref_release()
137 spin_lock_bh(&con->outqueue_lock); in tipc_conn_kref_release()
138 list_for_each_entry_safe(e, safe, &con->outqueue, list) { in tipc_conn_kref_release()
142 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_kref_release()
143 kfree(con); in tipc_conn_kref_release()
146 static void conn_put(struct tipc_conn *con) in conn_put() argument
148 kref_put(&con->kref, tipc_conn_kref_release); in conn_put()
151 static void conn_get(struct tipc_conn *con) in conn_get() argument
153 kref_get(&con->kref); in conn_get()
156 static void tipc_conn_close(struct tipc_conn *con) in tipc_conn_close() argument
158 struct sock *sk = con->sock->sk; in tipc_conn_close()
162 disconnect = test_and_clear_bit(CF_CONNECTED, &con->flags); in tipc_conn_close()
166 tipc_conn_delete_sub(con, NULL); in tipc_conn_close()
175 kernel_sock_shutdown(con->sock, SHUT_RDWR); in tipc_conn_close()
177 conn_put(con); in tipc_conn_close()
182 struct tipc_conn *con; in tipc_conn_alloc() local
185 con = kzalloc(sizeof(*con), GFP_ATOMIC); in tipc_conn_alloc()
186 if (!con) in tipc_conn_alloc()
189 kref_init(&con->kref); in tipc_conn_alloc()
190 INIT_LIST_HEAD(&con->outqueue); in tipc_conn_alloc()
191 INIT_LIST_HEAD(&con->sub_list); in tipc_conn_alloc()
192 spin_lock_init(&con->outqueue_lock); in tipc_conn_alloc()
193 spin_lock_init(&con->sub_lock); in tipc_conn_alloc()
194 INIT_WORK(&con->swork, tipc_conn_send_work); in tipc_conn_alloc()
195 INIT_WORK(&con->rwork, tipc_conn_recv_work); in tipc_conn_alloc()
198 ret = idr_alloc(&s->conn_idr, con, 0, 0, GFP_ATOMIC); in tipc_conn_alloc()
200 kfree(con); in tipc_conn_alloc()
204 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()
209 con->sock = sock; in tipc_conn_alloc()
210 conn_get(con); in tipc_conn_alloc()
213 return con; in tipc_conn_alloc()
218 struct tipc_conn *con; in tipc_conn_lookup() local
221 con = idr_find(&s->conn_idr, conid); in tipc_conn_lookup()
222 if (!connected(con) || !kref_get_unless_zero(&con->kref)) in tipc_conn_lookup()
223 con = NULL; in tipc_conn_lookup()
225 return con; in tipc_conn_lookup()
231 static void tipc_conn_delete_sub(struct tipc_conn *con, struct tipc_subscr *s) in tipc_conn_delete_sub() argument
233 struct tipc_net *tn = tipc_net(con->server->net); in tipc_conn_delete_sub()
234 struct list_head *sub_list = &con->sub_list; in tipc_conn_delete_sub()
237 spin_lock_bh(&con->sub_lock); in tipc_conn_delete_sub()
246 spin_unlock_bh(&con->sub_lock); in tipc_conn_delete_sub()
249 static void tipc_conn_send_to_sock(struct tipc_conn *con) in tipc_conn_send_to_sock() argument
251 struct list_head *queue = &con->outqueue; in tipc_conn_send_to_sock()
252 struct tipc_topsrv *srv = con->server; in tipc_conn_send_to_sock()
260 spin_lock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
265 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
268 tipc_conn_delete_sub(con, &evt->s); in tipc_conn_send_to_sock()
276 if (con->sock) { in tipc_conn_send_to_sock()
277 ret = kernel_sendmsg(con->sock, &msg, &iov, in tipc_conn_send_to_sock()
283 return tipc_conn_close(con); in tipc_conn_send_to_sock()
294 spin_lock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
298 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
303 struct tipc_conn *con = container_of(work, struct tipc_conn, swork); in tipc_conn_send_work() local
305 if (connected(con)) in tipc_conn_send_work()
306 tipc_conn_send_to_sock(con); in tipc_conn_send_work()
308 conn_put(con); in tipc_conn_send_work()
319 struct tipc_conn *con; in tipc_topsrv_queue_evt() local
321 con = tipc_conn_lookup(srv, conid); in tipc_topsrv_queue_evt()
322 if (!con) in tipc_topsrv_queue_evt()
325 if (!connected(con)) in tipc_topsrv_queue_evt()
333 spin_lock_bh(&con->outqueue_lock); in tipc_topsrv_queue_evt()
334 list_add_tail(&e->list, &con->outqueue); in tipc_topsrv_queue_evt()
335 spin_unlock_bh(&con->outqueue_lock); in tipc_topsrv_queue_evt()
337 if (queue_work(srv->send_wq, &con->swork)) in tipc_topsrv_queue_evt()
340 conn_put(con); in tipc_topsrv_queue_evt()
349 struct tipc_conn *con; in tipc_conn_write_space() local
352 con = sk->sk_user_data; in tipc_conn_write_space()
353 if (connected(con)) { in tipc_conn_write_space()
354 conn_get(con); in tipc_conn_write_space()
355 if (!queue_work(con->server->send_wq, &con->swork)) in tipc_conn_write_space()
356 conn_put(con); in tipc_conn_write_space()
362 struct tipc_conn *con, in tipc_conn_rcv_sub() argument
371 tipc_conn_delete_sub(con, s); in tipc_conn_rcv_sub()
378 sub = tipc_sub_subscribe(srv->net, s, con->conid); in tipc_conn_rcv_sub()
382 spin_lock_bh(&con->sub_lock); in tipc_conn_rcv_sub()
383 list_add(&sub->sub_list, &con->sub_list); in tipc_conn_rcv_sub()
384 spin_unlock_bh(&con->sub_lock); in tipc_conn_rcv_sub()
388 static int tipc_conn_rcv_from_sock(struct tipc_conn *con) in tipc_conn_rcv_from_sock() argument
390 struct tipc_topsrv *srv = con->server; in tipc_conn_rcv_from_sock()
391 struct sock *sk = con->sock->sk; in tipc_conn_rcv_from_sock()
401 ret = sock_recvmsg(con->sock, &msg, MSG_DONTWAIT); in tipc_conn_rcv_from_sock()
407 if (likely(connected(con))) in tipc_conn_rcv_from_sock()
408 ret = tipc_conn_rcv_sub(srv, con, &s); in tipc_conn_rcv_from_sock()
414 tipc_conn_close(con); in tipc_conn_rcv_from_sock()
420 struct tipc_conn *con = container_of(work, struct tipc_conn, rwork); in tipc_conn_recv_work() local
423 while (connected(con)) { in tipc_conn_recv_work()
424 if (tipc_conn_rcv_from_sock(con)) in tipc_conn_recv_work()
433 conn_put(con); in tipc_conn_recv_work()
441 struct tipc_conn *con; in tipc_conn_data_ready() local
446 con = sk->sk_user_data; in tipc_conn_data_ready()
447 if (connected(con)) { in tipc_conn_data_ready()
448 conn_get(con); in tipc_conn_data_ready()
449 if (!queue_work(con->server->rcv_wq, &con->rwork)) in tipc_conn_data_ready()
450 conn_put(con); in tipc_conn_data_ready()
459 struct tipc_conn *con; in tipc_topsrv_accept() local
475 con = tipc_conn_alloc(srv, newsock); in tipc_topsrv_accept()
476 if (IS_ERR(con)) { in tipc_topsrv_accept()
477 ret = PTR_ERR(con); in tipc_topsrv_accept()
486 newsk->sk_user_data = con; in tipc_topsrv_accept()
491 conn_put(con); in tipc_topsrv_accept()
577 struct tipc_conn *con; in tipc_topsrv_kern_subscr() local
587 con = tipc_conn_alloc(tipc_topsrv(net), NULL); in tipc_topsrv_kern_subscr()
588 if (IS_ERR(con)) in tipc_topsrv_kern_subscr()
591 *conid = con->conid; in tipc_topsrv_kern_subscr()
592 rc = tipc_conn_rcv_sub(tipc_topsrv(net), con, &sub); in tipc_topsrv_kern_subscr()
594 conn_put(con); in tipc_topsrv_kern_subscr()
596 conn_put(con); in tipc_topsrv_kern_subscr()
602 struct tipc_conn *con; in tipc_topsrv_kern_unsubscr() local
604 con = tipc_conn_lookup(tipc_topsrv(net), conid); in tipc_topsrv_kern_unsubscr()
605 if (!con) in tipc_topsrv_kern_unsubscr()
608 test_and_clear_bit(CF_CONNECTED, &con->flags); in tipc_topsrv_kern_unsubscr()
609 tipc_conn_delete_sub(con, NULL); in tipc_topsrv_kern_unsubscr()
610 conn_put(con); in tipc_topsrv_kern_unsubscr()
611 conn_put(con); in tipc_topsrv_kern_unsubscr()
700 struct tipc_conn *con; in tipc_topsrv_stop() local
705 con = idr_find(&srv->conn_idr, id); in tipc_topsrv_stop()
706 if (con) { in tipc_topsrv_stop()
708 tipc_conn_close(con); in tipc_topsrv_stop()