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()
208 set_bit(CF_CONNECTED, &con->flags); in tipc_conn_alloc()
209 con->server = s; in tipc_conn_alloc()
211 return con; in tipc_conn_alloc()
216 struct tipc_conn *con; in tipc_conn_lookup() local
219 con = idr_find(&s->conn_idr, conid); in tipc_conn_lookup()
220 if (!connected(con) || !kref_get_unless_zero(&con->kref)) in tipc_conn_lookup()
221 con = NULL; in tipc_conn_lookup()
223 return con; in tipc_conn_lookup()
229 static void tipc_conn_delete_sub(struct tipc_conn *con, struct tipc_subscr *s) in tipc_conn_delete_sub() argument
231 struct tipc_net *tn = tipc_net(con->server->net); in tipc_conn_delete_sub()
232 struct list_head *sub_list = &con->sub_list; in tipc_conn_delete_sub()
235 spin_lock_bh(&con->sub_lock); in tipc_conn_delete_sub()
244 spin_unlock_bh(&con->sub_lock); in tipc_conn_delete_sub()
247 static void tipc_conn_send_to_sock(struct tipc_conn *con) in tipc_conn_send_to_sock() argument
249 struct list_head *queue = &con->outqueue; in tipc_conn_send_to_sock()
250 struct tipc_topsrv *srv = con->server; in tipc_conn_send_to_sock()
258 spin_lock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
263 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
266 tipc_conn_delete_sub(con, &evt->s); in tipc_conn_send_to_sock()
274 if (con->sock) { in tipc_conn_send_to_sock()
275 ret = kernel_sendmsg(con->sock, &msg, &iov, in tipc_conn_send_to_sock()
281 return tipc_conn_close(con); in tipc_conn_send_to_sock()
292 spin_lock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
296 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
301 struct tipc_conn *con = container_of(work, struct tipc_conn, swork); in tipc_conn_send_work() local
303 if (connected(con)) in tipc_conn_send_work()
304 tipc_conn_send_to_sock(con); in tipc_conn_send_work()
306 conn_put(con); in tipc_conn_send_work()
317 struct tipc_conn *con; in tipc_topsrv_queue_evt() local
319 con = tipc_conn_lookup(srv, conid); in tipc_topsrv_queue_evt()
320 if (!con) in tipc_topsrv_queue_evt()
323 if (!connected(con)) in tipc_topsrv_queue_evt()
331 spin_lock_bh(&con->outqueue_lock); in tipc_topsrv_queue_evt()
332 list_add_tail(&e->list, &con->outqueue); in tipc_topsrv_queue_evt()
333 spin_unlock_bh(&con->outqueue_lock); in tipc_topsrv_queue_evt()
335 if (queue_work(srv->send_wq, &con->swork)) in tipc_topsrv_queue_evt()
338 conn_put(con); in tipc_topsrv_queue_evt()
347 struct tipc_conn *con; in tipc_conn_write_space() local
350 con = sk->sk_user_data; in tipc_conn_write_space()
351 if (connected(con)) { in tipc_conn_write_space()
352 conn_get(con); in tipc_conn_write_space()
353 if (!queue_work(con->server->send_wq, &con->swork)) in tipc_conn_write_space()
354 conn_put(con); in tipc_conn_write_space()
360 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()
403 ret = tipc_conn_rcv_sub(srv, con, &s); in tipc_conn_rcv_from_sock()
407 tipc_conn_close(con); in tipc_conn_rcv_from_sock()
414 struct tipc_conn *con = container_of(work, struct tipc_conn, rwork); in tipc_conn_recv_work() local
417 while (connected(con)) { in tipc_conn_recv_work()
418 if (tipc_conn_rcv_from_sock(con)) in tipc_conn_recv_work()
427 conn_put(con); in tipc_conn_recv_work()
435 struct tipc_conn *con; in tipc_conn_data_ready() local
438 con = sk->sk_user_data; in tipc_conn_data_ready()
439 if (connected(con)) { in tipc_conn_data_ready()
440 conn_get(con); in tipc_conn_data_ready()
441 if (!queue_work(con->server->rcv_wq, &con->rwork)) in tipc_conn_data_ready()
442 conn_put(con); in tipc_conn_data_ready()
452 struct tipc_conn *con; in tipc_topsrv_accept() local
460 con = tipc_conn_alloc(srv); in tipc_topsrv_accept()
461 if (IS_ERR(con)) { in tipc_topsrv_accept()
462 ret = PTR_ERR(con); in tipc_topsrv_accept()
471 newsk->sk_user_data = con; in tipc_topsrv_accept()
472 con->sock = newsock; in tipc_topsrv_accept()
560 struct tipc_conn *con; in tipc_topsrv_kern_subscr() local
570 con = tipc_conn_alloc(tipc_topsrv(net)); in tipc_topsrv_kern_subscr()
571 if (IS_ERR(con)) in tipc_topsrv_kern_subscr()
574 *conid = con->conid; in tipc_topsrv_kern_subscr()
575 con->sock = NULL; in tipc_topsrv_kern_subscr()
576 rc = tipc_conn_rcv_sub(tipc_topsrv(net), con, &sub); in tipc_topsrv_kern_subscr()
579 conn_put(con); in tipc_topsrv_kern_subscr()
585 struct tipc_conn *con; in tipc_topsrv_kern_unsubscr() local
587 con = tipc_conn_lookup(tipc_topsrv(net), conid); in tipc_topsrv_kern_unsubscr()
588 if (!con) in tipc_topsrv_kern_unsubscr()
591 test_and_clear_bit(CF_CONNECTED, &con->flags); in tipc_topsrv_kern_unsubscr()
592 tipc_conn_delete_sub(con, NULL); in tipc_topsrv_kern_unsubscr()
593 conn_put(con); in tipc_topsrv_kern_unsubscr()
594 conn_put(con); in tipc_topsrv_kern_unsubscr()
677 struct tipc_conn *con; in tipc_topsrv_stop() local
682 con = idr_find(&srv->conn_idr, id); in tipc_topsrv_stop()
683 if (con) { in tipc_topsrv_stop()
685 tipc_conn_close(con); in tipc_topsrv_stop()