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)
120 return con && test_bit(CF_CONNECTED, &con->flags);
125 struct tipc_conn *con = container_of(kref, struct tipc_conn, kref);
126 struct tipc_topsrv *s = con->server;
130 idr_remove(&s->conn_idr, con->conid);
133 if (con->sock)
134 sock_release(con->sock);
136 spin_lock_bh(&con->outqueue_lock);
137 list_for_each_entry_safe(e, safe, &con->outqueue, list) {
141 spin_unlock_bh(&con->outqueue_lock);
142 kfree(con);
145 static void conn_put(struct tipc_conn *con)
147 kref_put(&con->kref, tipc_conn_kref_release);
150 static void conn_get(struct tipc_conn *con)
152 kref_get(&con->kref);
155 static void tipc_conn_close(struct tipc_conn *con)
157 struct sock *sk = con->sock->sk;
161 disconnect = test_and_clear_bit(CF_CONNECTED, &con->flags);
165 tipc_conn_delete_sub(con, NULL);
174 kernel_sock_shutdown(con->sock, SHUT_RDWR);
176 conn_put(con);
181 struct tipc_conn *con;
184 con = kzalloc(sizeof(*con), GFP_ATOMIC);
185 if (!con)
188 kref_init(&con->kref);
189 INIT_LIST_HEAD(&con->outqueue);
190 INIT_LIST_HEAD(&con->sub_list);
191 spin_lock_init(&con->outqueue_lock);
192 spin_lock_init(&con->sub_lock);
193 INIT_WORK(&con->swork, tipc_conn_send_work);
194 INIT_WORK(&con->rwork, tipc_conn_recv_work);
197 ret = idr_alloc(&s->conn_idr, con, 0, 0, GFP_ATOMIC);
199 kfree(con);
203 con->conid = ret;
206 set_bit(CF_CONNECTED, &con->flags);
207 con->server = s;
208 con->sock = sock;
209 conn_get(con);
212 return con;
217 struct tipc_conn *con;
220 con = idr_find(&s->conn_idr, conid);
221 if (!connected(con) || !kref_get_unless_zero(&con->kref))
222 con = NULL;
224 return con;
230 static void tipc_conn_delete_sub(struct tipc_conn *con, struct tipc_subscr *s)
232 struct tipc_net *tn = tipc_net(con->server->net);
233 struct list_head *sub_list = &con->sub_list;
236 spin_lock_bh(&con->sub_lock);
245 spin_unlock_bh(&con->sub_lock);
248 static void tipc_conn_send_to_sock(struct tipc_conn *con)
250 struct list_head *queue = &con->outqueue;
251 struct tipc_topsrv *srv = con->server;
259 spin_lock_bh(&con->outqueue_lock);
264 spin_unlock_bh(&con->outqueue_lock);
267 tipc_conn_delete_sub(con, &evt->s);
275 if (con->sock) {
276 ret = kernel_sendmsg(con->sock, &msg, &iov,
282 return tipc_conn_close(con);
293 spin_lock_bh(&con->outqueue_lock);
297 spin_unlock_bh(&con->outqueue_lock);
302 struct tipc_conn *con = container_of(work, struct tipc_conn, swork);
304 if (connected(con))
305 tipc_conn_send_to_sock(con);
307 conn_put(con);
318 struct tipc_conn *con;
320 con = tipc_conn_lookup(srv, conid);
321 if (!con)
324 if (!connected(con))
332 spin_lock_bh(&con->outqueue_lock);
333 list_add_tail(&e->list, &con->outqueue);
334 spin_unlock_bh(&con->outqueue_lock);
336 if (queue_work(srv->send_wq, &con->swork))
339 conn_put(con);
348 struct tipc_conn *con;
351 con = sk->sk_user_data;
352 if (connected(con)) {
353 conn_get(con);
354 if (!queue_work(con->server->send_wq, &con->swork))
355 conn_put(con);
361 struct tipc_conn *con,
370 tipc_conn_delete_sub(con, s);
377 sub = tipc_sub_subscribe(srv->net, s, con->conid);
381 spin_lock_bh(&con->sub_lock);
382 list_add(&sub->sub_list, &con->sub_list);
383 spin_unlock_bh(&con->sub_lock);
387 static int tipc_conn_rcv_from_sock(struct tipc_conn *con)
389 struct tipc_topsrv *srv = con->server;
390 struct sock *sk = con->sock->sk;
400 ret = sock_recvmsg(con->sock, &msg, MSG_DONTWAIT);
406 if (likely(connected(con)))
407 ret = tipc_conn_rcv_sub(srv, con, &s);
413 tipc_conn_close(con);
419 struct tipc_conn *con = container_of(work, struct tipc_conn, rwork);
422 while (connected(con)) {
423 if (tipc_conn_rcv_from_sock(con))
432 conn_put(con);
440 struct tipc_conn *con;
443 con = sk->sk_user_data;
444 if (connected(con)) {
445 conn_get(con);
446 if (!queue_work(con->server->rcv_wq, &con->rwork))
447 conn_put(con);
456 struct tipc_conn *con;
472 con = tipc_conn_alloc(srv, newsock);
473 if (IS_ERR(con)) {
474 ret = PTR_ERR(con);
483 newsk->sk_user_data = con;
488 conn_put(con);
572 struct tipc_conn *con;
582 con = tipc_conn_alloc(tipc_topsrv(net), NULL);
583 if (IS_ERR(con))
586 *conid = con->conid;
587 rc = tipc_conn_rcv_sub(tipc_topsrv(net), con, &sub);
589 conn_put(con);
591 conn_put(con);
597 struct tipc_conn *con;
599 con = tipc_conn_lookup(tipc_topsrv(net), conid);
600 if (!con)
603 test_and_clear_bit(CF_CONNECTED, &con->flags);
604 tipc_conn_delete_sub(con, NULL);
605 conn_put(con);
606 conn_put(con);
695 struct tipc_conn *con;
700 con = idr_find(&srv->conn_idr, id);
701 if (con) {
703 tipc_conn_close(con);