Lines Matching +full:sub +full:- +full:module
4 * Copyright (c) 2012-2013, Wind River Systems
5 * Copyright (c) 2017-2018, Ericsson AB
45 #include <linux/module.h>
55 * struct tipc_topsrv - TIPC server structure
79 * struct tipc_conn - TIPC connection structure
120 return con && test_bit(CF_CONNECTED, &con->flags); in connected()
126 struct tipc_topsrv *s = con->server; in tipc_conn_kref_release()
129 spin_lock_bh(&s->idr_lock); in tipc_conn_kref_release()
130 idr_remove(&s->conn_idr, con->conid); in tipc_conn_kref_release()
131 s->idr_in_use--; in tipc_conn_kref_release()
132 spin_unlock_bh(&s->idr_lock); in tipc_conn_kref_release()
133 if (con->sock) in tipc_conn_kref_release()
134 sock_release(con->sock); in tipc_conn_kref_release()
136 spin_lock_bh(&con->outqueue_lock); in tipc_conn_kref_release()
137 list_for_each_entry_safe(e, safe, &con->outqueue, list) { in tipc_conn_kref_release()
138 list_del(&e->list); in tipc_conn_kref_release()
141 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_kref_release()
147 kref_put(&con->kref, tipc_conn_kref_release); in conn_put()
152 kref_get(&con->kref); in conn_get()
157 struct sock *sk = con->sock->sk; in tipc_conn_close()
160 write_lock_bh(&sk->sk_callback_lock); in tipc_conn_close()
161 disconnect = test_and_clear_bit(CF_CONNECTED, &con->flags); in tipc_conn_close()
164 sk->sk_user_data = NULL; in tipc_conn_close()
167 write_unlock_bh(&sk->sk_callback_lock); in tipc_conn_close()
173 /* Don't flush pending works, -just let them expire */ in tipc_conn_close()
174 kernel_sock_shutdown(con->sock, SHUT_RDWR); in tipc_conn_close()
186 return ERR_PTR(-ENOMEM); in tipc_conn_alloc()
188 kref_init(&con->kref); in tipc_conn_alloc()
189 INIT_LIST_HEAD(&con->outqueue); in tipc_conn_alloc()
190 INIT_LIST_HEAD(&con->sub_list); in tipc_conn_alloc()
191 spin_lock_init(&con->outqueue_lock); in tipc_conn_alloc()
192 spin_lock_init(&con->sub_lock); in tipc_conn_alloc()
193 INIT_WORK(&con->swork, tipc_conn_send_work); in tipc_conn_alloc()
194 INIT_WORK(&con->rwork, tipc_conn_recv_work); in tipc_conn_alloc()
196 spin_lock_bh(&s->idr_lock); in tipc_conn_alloc()
197 ret = idr_alloc(&s->conn_idr, con, 0, 0, GFP_ATOMIC); in tipc_conn_alloc()
200 spin_unlock_bh(&s->idr_lock); in tipc_conn_alloc()
201 return ERR_PTR(-ENOMEM); in tipc_conn_alloc()
203 con->conid = ret; in tipc_conn_alloc()
204 s->idr_in_use++; in tipc_conn_alloc()
205 spin_unlock_bh(&s->idr_lock); in tipc_conn_alloc()
207 set_bit(CF_CONNECTED, &con->flags); in tipc_conn_alloc()
208 con->server = s; in tipc_conn_alloc()
217 spin_lock_bh(&s->idr_lock); in tipc_conn_lookup()
218 con = idr_find(&s->conn_idr, conid); in tipc_conn_lookup()
219 if (!connected(con) || !kref_get_unless_zero(&con->kref)) in tipc_conn_lookup()
221 spin_unlock_bh(&s->idr_lock); in tipc_conn_lookup()
225 /* tipc_conn_delete_sub - delete a specific or all subscriptions
230 struct tipc_net *tn = tipc_net(con->server->net); in tipc_conn_delete_sub()
231 struct list_head *sub_list = &con->sub_list; in tipc_conn_delete_sub()
232 struct tipc_subscription *sub, *tmp; in tipc_conn_delete_sub() local
234 spin_lock_bh(&con->sub_lock); in tipc_conn_delete_sub()
235 list_for_each_entry_safe(sub, tmp, sub_list, sub_list) { in tipc_conn_delete_sub()
236 if (!s || !memcmp(s, &sub->evt.s, sizeof(*s))) { in tipc_conn_delete_sub()
237 tipc_sub_unsubscribe(sub); in tipc_conn_delete_sub()
238 atomic_dec(&tn->subscription_count); in tipc_conn_delete_sub()
243 spin_unlock_bh(&con->sub_lock); in tipc_conn_delete_sub()
248 struct list_head *queue = &con->outqueue; in tipc_conn_send_to_sock()
249 struct tipc_topsrv *srv = con->server; in tipc_conn_send_to_sock()
257 spin_lock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
261 evt = &e->evt; in tipc_conn_send_to_sock()
262 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
264 if (e->inactive) in tipc_conn_send_to_sock()
265 tipc_conn_delete_sub(con, &evt->s); in tipc_conn_send_to_sock()
273 if (con->sock) { in tipc_conn_send_to_sock()
274 ret = kernel_sendmsg(con->sock, &msg, &iov, in tipc_conn_send_to_sock()
276 if (ret == -EWOULDBLOCK || ret == 0) { in tipc_conn_send_to_sock()
283 tipc_topsrv_kern_evt(srv->net, evt); in tipc_conn_send_to_sock()
291 spin_lock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
292 list_del(&e->list); in tipc_conn_send_to_sock()
295 spin_unlock_bh(&con->outqueue_lock); in tipc_conn_send_to_sock()
308 /* tipc_topsrv_queue_evt() - interrupt level call from a subscription instance
309 * The queued work is launched into tipc_conn_send_work()->tipc_conn_send_to_sock()
328 e->inactive = (event == TIPC_SUBSCR_TIMEOUT); in tipc_topsrv_queue_evt()
329 memcpy(&e->evt, evt, sizeof(*evt)); in tipc_topsrv_queue_evt()
330 spin_lock_bh(&con->outqueue_lock); in tipc_topsrv_queue_evt()
331 list_add_tail(&e->list, &con->outqueue); in tipc_topsrv_queue_evt()
332 spin_unlock_bh(&con->outqueue_lock); in tipc_topsrv_queue_evt()
334 if (queue_work(srv->send_wq, &con->swork)) in tipc_topsrv_queue_evt()
340 /* tipc_conn_write_space - interrupt callback after a sendmsg EAGAIN
342 * The queued work is launched into tipc_send_work()->tipc_conn_send_to_sock()
348 read_lock_bh(&sk->sk_callback_lock); in tipc_conn_write_space()
349 con = sk->sk_user_data; in tipc_conn_write_space()
352 if (!queue_work(con->server->send_wq, &con->swork)) in tipc_conn_write_space()
355 read_unlock_bh(&sk->sk_callback_lock); in tipc_conn_write_space()
362 struct tipc_net *tn = tipc_net(srv->net); in tipc_conn_rcv_sub()
363 struct tipc_subscription *sub; in tipc_conn_rcv_sub() local
371 if (atomic_read(&tn->subscription_count) >= TIPC_MAX_SUBSCR) { in tipc_conn_rcv_sub()
373 return -1; in tipc_conn_rcv_sub()
375 sub = tipc_sub_subscribe(srv->net, s, con->conid); in tipc_conn_rcv_sub()
376 if (!sub) in tipc_conn_rcv_sub()
377 return -1; in tipc_conn_rcv_sub()
378 atomic_inc(&tn->subscription_count); 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()
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()
399 if (ret == -EWOULDBLOCK) in tipc_conn_rcv_from_sock()
400 return -EWOULDBLOCK; in tipc_conn_rcv_from_sock()
402 read_lock_bh(&sk->sk_callback_lock); in tipc_conn_rcv_from_sock()
406 read_unlock_bh(&sk->sk_callback_lock); in tipc_conn_rcv_from_sock()
433 /* tipc_conn_data_ready - interrupt callback indicating the socket has data
434 * The queued work is launched into tipc_recv_work()->tipc_conn_rcv_from_sock()
440 read_lock_bh(&sk->sk_callback_lock); in tipc_conn_data_ready()
441 con = sk->sk_user_data; in tipc_conn_data_ready()
444 if (!queue_work(con->server->rcv_wq, &con->rwork)) in tipc_conn_data_ready()
447 read_unlock_bh(&sk->sk_callback_lock); in tipc_conn_data_ready()
453 struct socket *lsock = srv->listener; in tipc_topsrv_accept()
470 newsk = newsock->sk; in tipc_topsrv_accept()
471 write_lock_bh(&newsk->sk_callback_lock); in tipc_topsrv_accept()
472 newsk->sk_data_ready = tipc_conn_data_ready; in tipc_topsrv_accept()
473 newsk->sk_write_space = tipc_conn_write_space; in tipc_topsrv_accept()
474 newsk->sk_user_data = con; in tipc_topsrv_accept()
475 con->sock = newsock; in tipc_topsrv_accept()
476 write_unlock_bh(&newsk->sk_callback_lock); in tipc_topsrv_accept()
479 newsk->sk_data_ready(newsk); in tipc_topsrv_accept()
483 /* tipc_topsrv_listener_data_ready - interrupt callback with connection request
490 read_lock_bh(&sk->sk_callback_lock); in tipc_topsrv_listener_data_ready()
491 srv = sk->sk_user_data; in tipc_topsrv_listener_data_ready()
492 if (srv->listener) in tipc_topsrv_listener_data_ready()
493 queue_work(srv->rcv_wq, &srv->awork); in tipc_topsrv_listener_data_ready()
494 read_unlock_bh(&sk->sk_callback_lock); in tipc_topsrv_listener_data_ready()
504 rc = sock_create_kern(srv->net, AF_TIPC, SOCK_SEQPACKET, 0, &lsock); in tipc_topsrv_create_listener()
508 srv->listener = lsock; in tipc_topsrv_create_listener()
509 sk = lsock->sk; in tipc_topsrv_create_listener()
510 write_lock_bh(&sk->sk_callback_lock); in tipc_topsrv_create_listener()
511 sk->sk_data_ready = tipc_topsrv_listener_data_ready; in tipc_topsrv_create_listener()
512 sk->sk_user_data = srv; in tipc_topsrv_create_listener()
513 write_unlock_bh(&sk->sk_callback_lock); in tipc_topsrv_create_listener()
535 /* As server's listening socket owner and creator is the same module, in tipc_topsrv_create_listener()
536 * we have to decrease TIPC module reference count to guarantee that in tipc_topsrv_create_listener()
538 * executing "rmmod" command is unable to make TIPC module deleted in tipc_topsrv_create_listener()
539 * after TIPC module is inserted successfully. in tipc_topsrv_create_listener()
545 * decrement the module reference count twice to ensure that it keeps in tipc_topsrv_create_listener()
547 * must bump the module reference count twice as well before the socket in tipc_topsrv_create_listener()
550 module_put(lsock->ops->owner); in tipc_topsrv_create_listener()
551 module_put(sk->sk_prot_creator->owner); in tipc_topsrv_create_listener()
556 return -EINVAL; in tipc_topsrv_create_listener()
562 struct tipc_subscr sub; in tipc_topsrv_kern_subscr() local
566 sub.seq.type = type; in tipc_topsrv_kern_subscr()
567 sub.seq.lower = lower; in tipc_topsrv_kern_subscr()
568 sub.seq.upper = upper; in tipc_topsrv_kern_subscr()
569 sub.timeout = TIPC_WAIT_FOREVER; in tipc_topsrv_kern_subscr()
570 sub.filter = filter; in tipc_topsrv_kern_subscr()
571 *(u32 *)&sub.usr_handle = port; in tipc_topsrv_kern_subscr()
577 *conid = con->conid; in tipc_topsrv_kern_subscr()
578 con->sock = NULL; in tipc_topsrv_kern_subscr()
579 rc = tipc_conn_rcv_sub(tipc_topsrv(net), con, &sub); in tipc_topsrv_kern_subscr()
594 test_and_clear_bit(CF_CONNECTED, &con->flags); in tipc_topsrv_kern_unsubscr()
602 u32 port = *(u32 *)&evt->s.usr_handle; in tipc_topsrv_kern_evt()
621 s->rcv_wq = alloc_ordered_workqueue("tipc_rcv", 0); in tipc_topsrv_work_start()
622 if (!s->rcv_wq) { in tipc_topsrv_work_start()
624 return -ENOMEM; in tipc_topsrv_work_start()
627 s->send_wq = alloc_ordered_workqueue("tipc_send", 0); in tipc_topsrv_work_start()
628 if (!s->send_wq) { in tipc_topsrv_work_start()
630 destroy_workqueue(s->rcv_wq); in tipc_topsrv_work_start()
631 return -ENOMEM; in tipc_topsrv_work_start()
639 destroy_workqueue(s->rcv_wq); in tipc_topsrv_work_stop()
640 destroy_workqueue(s->send_wq); in tipc_topsrv_work_stop()
652 return -ENOMEM; in tipc_topsrv_start()
654 srv->net = net; in tipc_topsrv_start()
655 INIT_WORK(&srv->awork, tipc_topsrv_accept); in tipc_topsrv_start()
657 strscpy(srv->name, name, sizeof(srv->name)); in tipc_topsrv_start()
658 tn->topsrv = srv; in tipc_topsrv_start()
659 atomic_set(&tn->subscription_count, 0); in tipc_topsrv_start()
661 spin_lock_init(&srv->idr_lock); in tipc_topsrv_start()
662 idr_init(&srv->conn_idr); in tipc_topsrv_start()
663 srv->idr_in_use = 0; in tipc_topsrv_start()
685 struct socket *lsock = srv->listener; in tipc_topsrv_stop()
689 spin_lock_bh(&srv->idr_lock); in tipc_topsrv_stop()
690 for (id = 0; srv->idr_in_use; id++) { in tipc_topsrv_stop()
691 con = idr_find(&srv->conn_idr, id); in tipc_topsrv_stop()
693 spin_unlock_bh(&srv->idr_lock); in tipc_topsrv_stop()
695 spin_lock_bh(&srv->idr_lock); in tipc_topsrv_stop()
698 __module_get(lsock->ops->owner); in tipc_topsrv_stop()
699 __module_get(lsock->sk->sk_prot_creator->owner); in tipc_topsrv_stop()
700 srv->listener = NULL; in tipc_topsrv_stop()
701 spin_unlock_bh(&srv->idr_lock); in tipc_topsrv_stop()
704 idr_destroy(&srv->conn_idr); in tipc_topsrv_stop()