Lines Matching refs:con
124 static void tipc_conn_delete_sub(struct tipc_conn *con, struct tipc_subscr *s);
126 static bool connected(struct tipc_conn *con) in connected() argument
128 return con && test_bit(CF_CONNECTED, &con->flags); in connected()
133 struct tipc_conn *con = container_of(kref, struct tipc_conn, kref); in tipc_conn_kref_release() local
134 struct tipc_topsrv *s = con->server; in tipc_conn_kref_release()
138 idr_remove(&s->conn_idr, con->conid); in tipc_conn_kref_release()
141 if (con->sock) in tipc_conn_kref_release()
142 sock_release(con->sock); in tipc_conn_kref_release()
144 spin_lock_bh(&con->outqueue_lock); in tipc_conn_kref_release()
145 list_for_each_entry_safe(e, safe, &con->outqueue, list) { in tipc_conn_kref_release()
149 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_kref_release()
150 kfree(con); in tipc_conn_kref_release()
153 static void conn_put(struct tipc_conn *con) in conn_put() argument
155 kref_put(&con->kref, tipc_conn_kref_release); in conn_put()
158 static void conn_get(struct tipc_conn *con) in conn_get() argument
160 kref_get(&con->kref); in conn_get()
163 static void tipc_conn_close(struct tipc_conn *con) in tipc_conn_close() argument
165 struct sock *sk = con->sock->sk; in tipc_conn_close()
169 disconnect = test_and_clear_bit(CF_CONNECTED, &con->flags); in tipc_conn_close()
173 tipc_conn_delete_sub(con, NULL); in tipc_conn_close()
182 kernel_sock_shutdown(con->sock, SHUT_RDWR); in tipc_conn_close()
184 conn_put(con); in tipc_conn_close()
189 struct tipc_conn *con; in tipc_conn_alloc() local
192 con = kzalloc(sizeof(*con), GFP_ATOMIC); in tipc_conn_alloc()
193 if (!con) in tipc_conn_alloc()
196 kref_init(&con->kref); in tipc_conn_alloc()
197 INIT_LIST_HEAD(&con->outqueue); in tipc_conn_alloc()
198 INIT_LIST_HEAD(&con->sub_list); in tipc_conn_alloc()
199 spin_lock_init(&con->outqueue_lock); in tipc_conn_alloc()
200 spin_lock_init(&con->sub_lock); in tipc_conn_alloc()
201 INIT_WORK(&con->swork, tipc_conn_send_work); in tipc_conn_alloc()
202 INIT_WORK(&con->rwork, tipc_conn_recv_work); in tipc_conn_alloc()
205 ret = idr_alloc(&s->conn_idr, con, 0, 0, GFP_ATOMIC); in tipc_conn_alloc()
207 kfree(con); in tipc_conn_alloc()
211 con->conid = ret; in tipc_conn_alloc()
215 set_bit(CF_CONNECTED, &con->flags); in tipc_conn_alloc()
216 con->server = s; in tipc_conn_alloc()
218 return con; in tipc_conn_alloc()
223 struct tipc_conn *con; in tipc_conn_lookup() local
226 con = idr_find(&s->conn_idr, conid); in tipc_conn_lookup()
227 if (!connected(con) || !kref_get_unless_zero(&con->kref)) in tipc_conn_lookup()
228 con = NULL; in tipc_conn_lookup()
230 return con; in tipc_conn_lookup()
236 static void tipc_conn_delete_sub(struct tipc_conn *con, struct tipc_subscr *s) in tipc_conn_delete_sub() argument
238 struct tipc_net *tn = tipc_net(con->server->net); in tipc_conn_delete_sub()
239 struct list_head *sub_list = &con->sub_list; in tipc_conn_delete_sub()
242 spin_lock_bh(&con->sub_lock); in tipc_conn_delete_sub()
251 spin_unlock_bh(&con->sub_lock); in tipc_conn_delete_sub()
254 static void tipc_conn_send_to_sock(struct tipc_conn *con) in tipc_conn_send_to_sock() argument
256 struct list_head *queue = &con->outqueue; in tipc_conn_send_to_sock()
257 struct tipc_topsrv *srv = con->server; in tipc_conn_send_to_sock()
265 spin_lock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
270 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
273 tipc_conn_delete_sub(con, &evt->s); in tipc_conn_send_to_sock()
281 if (con->sock) { in tipc_conn_send_to_sock()
282 ret = kernel_sendmsg(con->sock, &msg, &iov, in tipc_conn_send_to_sock()
288 return tipc_conn_close(con); in tipc_conn_send_to_sock()
299 spin_lock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
303 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
308 struct tipc_conn *con = container_of(work, struct tipc_conn, swork); in tipc_conn_send_work() local
310 if (connected(con)) in tipc_conn_send_work()
311 tipc_conn_send_to_sock(con); in tipc_conn_send_work()
313 conn_put(con); in tipc_conn_send_work()
324 struct tipc_conn *con; in tipc_topsrv_queue_evt() local
326 con = tipc_conn_lookup(srv, conid); in tipc_topsrv_queue_evt()
327 if (!con) in tipc_topsrv_queue_evt()
330 if (!connected(con)) in tipc_topsrv_queue_evt()
338 spin_lock_bh(&con->outqueue_lock); in tipc_topsrv_queue_evt()
339 list_add_tail(&e->list, &con->outqueue); in tipc_topsrv_queue_evt()
340 spin_unlock_bh(&con->outqueue_lock); in tipc_topsrv_queue_evt()
342 if (queue_work(srv->send_wq, &con->swork)) in tipc_topsrv_queue_evt()
345 conn_put(con); in tipc_topsrv_queue_evt()
354 struct tipc_conn *con; in tipc_conn_write_space() local
357 con = sk->sk_user_data; in tipc_conn_write_space()
358 if (connected(con)) { in tipc_conn_write_space()
359 conn_get(con); in tipc_conn_write_space()
360 if (!queue_work(con->server->send_wq, &con->swork)) in tipc_conn_write_space()
361 conn_put(con); in tipc_conn_write_space()
367 struct tipc_conn *con, in tipc_conn_rcv_sub() argument
374 tipc_conn_delete_sub(con, s); in tipc_conn_rcv_sub()
381 sub = tipc_sub_subscribe(srv->net, s, con->conid); in tipc_conn_rcv_sub()
385 spin_lock_bh(&con->sub_lock); in tipc_conn_rcv_sub()
386 list_add(&sub->sub_list, &con->sub_list); in tipc_conn_rcv_sub()
387 spin_unlock_bh(&con->sub_lock); in tipc_conn_rcv_sub()
391 static int tipc_conn_rcv_from_sock(struct tipc_conn *con) in tipc_conn_rcv_from_sock() argument
393 struct tipc_topsrv *srv = con->server; in tipc_conn_rcv_from_sock()
394 struct sock *sk = con->sock->sk; in tipc_conn_rcv_from_sock()
404 ret = sock_recvmsg(con->sock, &msg, MSG_DONTWAIT); in tipc_conn_rcv_from_sock()
409 ret = tipc_conn_rcv_sub(srv, con, &s); in tipc_conn_rcv_from_sock()
413 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
444 con = sk->sk_user_data; in tipc_conn_data_ready()
445 if (connected(con)) { in tipc_conn_data_ready()
446 conn_get(con); in tipc_conn_data_ready()
447 if (!queue_work(con->server->rcv_wq, &con->rwork)) in tipc_conn_data_ready()
448 conn_put(con); in tipc_conn_data_ready()
458 struct tipc_conn *con; in tipc_topsrv_accept() local
466 con = tipc_conn_alloc(srv); in tipc_topsrv_accept()
467 if (IS_ERR(con)) { in tipc_topsrv_accept()
468 ret = PTR_ERR(con); in tipc_topsrv_accept()
477 newsk->sk_user_data = con; in tipc_topsrv_accept()
478 con->sock = newsock; in tipc_topsrv_accept()
566 struct tipc_conn *con; in tipc_topsrv_kern_subscr() local
576 con = tipc_conn_alloc(tipc_topsrv(net)); in tipc_topsrv_kern_subscr()
577 if (IS_ERR(con)) in tipc_topsrv_kern_subscr()
580 *conid = con->conid; in tipc_topsrv_kern_subscr()
581 con->sock = NULL; in tipc_topsrv_kern_subscr()
582 rc = tipc_conn_rcv_sub(tipc_topsrv(net), con, &sub); in tipc_topsrv_kern_subscr()
585 conn_put(con); in tipc_topsrv_kern_subscr()
591 struct tipc_conn *con; in tipc_topsrv_kern_unsubscr() local
593 con = tipc_conn_lookup(tipc_topsrv(net), conid); in tipc_topsrv_kern_unsubscr()
594 if (!con) in tipc_topsrv_kern_unsubscr()
597 test_and_clear_bit(CF_CONNECTED, &con->flags); in tipc_topsrv_kern_unsubscr()
598 tipc_conn_delete_sub(con, NULL); in tipc_topsrv_kern_unsubscr()
599 conn_put(con); in tipc_topsrv_kern_unsubscr()
600 conn_put(con); in tipc_topsrv_kern_unsubscr()
683 struct tipc_conn *con; in tipc_topsrv_stop() local
688 con = idr_find(&srv->conn_idr, id); in tipc_topsrv_stop()
689 if (con) { in tipc_topsrv_stop()
691 tipc_conn_close(con); in tipc_topsrv_stop()