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