Lines Matching refs:sk

71 void bt_sock_reclassify_lock(struct sock *sk, int proto)  in bt_sock_reclassify_lock()  argument
73 BUG_ON(!sk); in bt_sock_reclassify_lock()
74 BUG_ON(!sock_allow_reclassification(sk)); in bt_sock_reclassify_lock()
76 sock_lock_init_class_and_name(sk, in bt_sock_reclassify_lock()
134 bt_sock_reclassify_lock(sock->sk, proto); in bt_sock_create()
146 struct sock *sk; in bt_sock_alloc() local
148 sk = sk_alloc(net, PF_BLUETOOTH, prio, prot, kern); in bt_sock_alloc()
149 if (!sk) in bt_sock_alloc()
152 sock_init_data(sock, sk); in bt_sock_alloc()
153 INIT_LIST_HEAD(&bt_sk(sk)->accept_q); in bt_sock_alloc()
155 sock_reset_flag(sk, SOCK_ZAPPED); in bt_sock_alloc()
157 sk->sk_protocol = proto; in bt_sock_alloc()
158 sk->sk_state = BT_OPEN; in bt_sock_alloc()
162 spin_lock(&sk->sk_peer_lock); in bt_sock_alloc()
163 sk->sk_peer_pid = get_pid(task_tgid(current)); in bt_sock_alloc()
164 sk->sk_peer_cred = get_current_cred(); in bt_sock_alloc()
165 spin_unlock(&sk->sk_peer_lock); in bt_sock_alloc()
168 return sk; in bt_sock_alloc()
172 void bt_sock_link(struct bt_sock_list *l, struct sock *sk) in bt_sock_link() argument
175 sk_add_node(sk, &l->head); in bt_sock_link()
180 void bt_sock_unlink(struct bt_sock_list *l, struct sock *sk) in bt_sock_unlink() argument
183 sk_del_node_init(sk); in bt_sock_unlink()
190 struct sock *sk; in bt_sock_linked() local
197 sk_for_each(sk, &l->head) { in bt_sock_linked()
198 if (s == sk) { in bt_sock_linked()
210 void bt_accept_enqueue(struct sock *parent, struct sock *sk, bool bh) in bt_accept_enqueue() argument
215 BT_DBG("parent %p, sk %p", parent, sk); in bt_accept_enqueue()
217 sock_hold(sk); in bt_accept_enqueue()
220 bh_lock_sock_nested(sk); in bt_accept_enqueue()
222 lock_sock_nested(sk, SINGLE_DEPTH_NESTING); in bt_accept_enqueue()
224 list_add_tail(&bt_sk(sk)->accept_q, &bt_sk(parent)->accept_q); in bt_accept_enqueue()
225 bt_sk(sk)->parent = parent; in bt_accept_enqueue()
230 spin_lock(&sk->sk_peer_lock); in bt_accept_enqueue()
231 old_pid = sk->sk_peer_pid; in bt_accept_enqueue()
232 old_cred = sk->sk_peer_cred; in bt_accept_enqueue()
233 sk->sk_peer_pid = get_pid(parent->sk_peer_pid); in bt_accept_enqueue()
234 sk->sk_peer_cred = get_cred(parent->sk_peer_cred); in bt_accept_enqueue()
235 spin_unlock(&sk->sk_peer_lock); in bt_accept_enqueue()
241 bh_unlock_sock(sk); in bt_accept_enqueue()
243 release_sock(sk); in bt_accept_enqueue()
252 void bt_accept_unlink(struct sock *sk) in bt_accept_unlink() argument
254 BT_DBG("sk %p state %d", sk, sk->sk_state); in bt_accept_unlink()
256 list_del_init(&bt_sk(sk)->accept_q); in bt_accept_unlink()
257 sk_acceptq_removed(bt_sk(sk)->parent); in bt_accept_unlink()
258 bt_sk(sk)->parent = NULL; in bt_accept_unlink()
259 sock_put(sk); in bt_accept_unlink()
266 struct sock *sk; in bt_accept_dequeue() local
272 sk = (struct sock *)s; in bt_accept_dequeue()
275 sock_hold(sk); in bt_accept_dequeue()
276 lock_sock(sk); in bt_accept_dequeue()
281 if (!bt_sk(sk)->parent) { in bt_accept_dequeue()
282 BT_DBG("sk %p, already unlinked", sk); in bt_accept_dequeue()
283 release_sock(sk); in bt_accept_dequeue()
284 sock_put(sk); in bt_accept_dequeue()
294 sock_put(sk); in bt_accept_dequeue()
297 if (sk->sk_state == BT_CLOSED) { in bt_accept_dequeue()
298 bt_accept_unlink(sk); in bt_accept_dequeue()
299 release_sock(sk); in bt_accept_dequeue()
303 if (sk->sk_state == BT_CONNECTED || !newsock || in bt_accept_dequeue()
305 bt_accept_unlink(sk); in bt_accept_dequeue()
307 sock_graft(sk, newsock); in bt_accept_dequeue()
309 release_sock(sk); in bt_accept_dequeue()
310 return sk; in bt_accept_dequeue()
313 release_sock(sk); in bt_accept_dequeue()
323 struct sock *sk = sock->sk; in bt_sock_recvmsg() local
329 BT_DBG("sock %p sk %p len %zu", sock, sk, len); in bt_sock_recvmsg()
334 skb = skb_recv_datagram(sk, flags, &err); in bt_sock_recvmsg()
336 if (sk->sk_shutdown & RCV_SHUTDOWN) in bt_sock_recvmsg()
352 sock_recv_cmsgs(msg, sk, skb); in bt_sock_recvmsg()
354 if (msg->msg_name && bt_sk(sk)->skb_msg_name) in bt_sock_recvmsg()
355 bt_sk(sk)->skb_msg_name(skb, msg->msg_name, in bt_sock_recvmsg()
358 if (test_bit(BT_SK_PKT_STATUS, &bt_sk(sk)->flags)) { in bt_sock_recvmsg()
366 skb_free_datagram(sk, skb); in bt_sock_recvmsg()
375 static long bt_sock_data_wait(struct sock *sk, long timeo) in bt_sock_data_wait() argument
379 add_wait_queue(sk_sleep(sk), &wait); in bt_sock_data_wait()
383 if (!skb_queue_empty(&sk->sk_receive_queue)) in bt_sock_data_wait()
386 if (sk->sk_err || (sk->sk_shutdown & RCV_SHUTDOWN)) in bt_sock_data_wait()
392 sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk); in bt_sock_data_wait()
393 release_sock(sk); in bt_sock_data_wait()
395 lock_sock(sk); in bt_sock_data_wait()
396 sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk); in bt_sock_data_wait()
400 remove_wait_queue(sk_sleep(sk), &wait); in bt_sock_data_wait()
407 struct sock *sk = sock->sk; in bt_sock_stream_recvmsg() local
415 BT_DBG("sk %p size %zu", sk, size); in bt_sock_stream_recvmsg()
417 lock_sock(sk); in bt_sock_stream_recvmsg()
419 target = sock_rcvlowat(sk, flags & MSG_WAITALL, size); in bt_sock_stream_recvmsg()
420 timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); in bt_sock_stream_recvmsg()
426 skb = skb_dequeue(&sk->sk_receive_queue); in bt_sock_stream_recvmsg()
431 err = sock_error(sk); in bt_sock_stream_recvmsg()
434 if (sk->sk_shutdown & RCV_SHUTDOWN) in bt_sock_stream_recvmsg()
441 timeo = bt_sock_data_wait(sk, timeo); in bt_sock_stream_recvmsg()
452 skb_queue_head(&sk->sk_receive_queue, skb); in bt_sock_stream_recvmsg()
460 sock_recv_cmsgs(msg, sk, skb); in bt_sock_stream_recvmsg()
491 skb_queue_head(&sk->sk_receive_queue, skb); in bt_sock_stream_recvmsg()
498 skb_queue_head(&sk->sk_receive_queue, skb); in bt_sock_stream_recvmsg()
504 release_sock(sk); in bt_sock_stream_recvmsg()
512 struct sock *sk; in bt_accept_poll() local
515 sk = (struct sock *)s; in bt_accept_poll()
516 if (sk->sk_state == BT_CONNECTED || in bt_accept_poll()
518 sk->sk_state == BT_CONNECT2)) in bt_accept_poll()
528 struct sock *sk = sock->sk; in bt_sock_poll() local
531 poll_wait(file, sk_sleep(sk), wait); in bt_sock_poll()
533 if (sk->sk_state == BT_LISTEN) in bt_sock_poll()
534 return bt_accept_poll(sk); in bt_sock_poll()
536 if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue)) in bt_sock_poll()
538 (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0); in bt_sock_poll()
540 if (sk->sk_shutdown & RCV_SHUTDOWN) in bt_sock_poll()
543 if (sk->sk_shutdown == SHUTDOWN_MASK) in bt_sock_poll()
546 if (!skb_queue_empty_lockless(&sk->sk_receive_queue)) in bt_sock_poll()
549 if (sk->sk_state == BT_CLOSED) in bt_sock_poll()
552 if (sk->sk_state == BT_CONNECT || in bt_sock_poll()
553 sk->sk_state == BT_CONNECT2 || in bt_sock_poll()
554 sk->sk_state == BT_CONFIG) in bt_sock_poll()
557 if (!test_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags) && sock_writeable(sk)) in bt_sock_poll()
560 sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); in bt_sock_poll()
568 struct sock *sk = sock->sk; in bt_sock_ioctl() local
573 BT_DBG("sk %p cmd %x arg %lx", sk, cmd, arg); in bt_sock_ioctl()
577 if (sk->sk_state == BT_LISTEN) in bt_sock_ioctl()
580 amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk); in bt_sock_ioctl()
587 if (sk->sk_state == BT_LISTEN) in bt_sock_ioctl()
590 spin_lock(&sk->sk_receive_queue.lock); in bt_sock_ioctl()
591 skb = skb_peek(&sk->sk_receive_queue); in bt_sock_ioctl()
593 spin_unlock(&sk->sk_receive_queue.lock); in bt_sock_ioctl()
608 int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo) in bt_sock_wait_state() argument
613 BT_DBG("sk %p", sk); in bt_sock_wait_state()
615 add_wait_queue(sk_sleep(sk), &wait); in bt_sock_wait_state()
617 while (sk->sk_state != state) { in bt_sock_wait_state()
628 release_sock(sk); in bt_sock_wait_state()
630 lock_sock(sk); in bt_sock_wait_state()
633 err = sock_error(sk); in bt_sock_wait_state()
638 remove_wait_queue(sk_sleep(sk), &wait); in bt_sock_wait_state()
644 int bt_sock_wait_ready(struct sock *sk, unsigned int msg_flags) in bt_sock_wait_ready() argument
650 BT_DBG("sk %p", sk); in bt_sock_wait_ready()
652 timeo = sock_sndtimeo(sk, !!(msg_flags & MSG_DONTWAIT)); in bt_sock_wait_ready()
654 add_wait_queue(sk_sleep(sk), &wait); in bt_sock_wait_ready()
656 while (test_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags)) { in bt_sock_wait_ready()
667 release_sock(sk); in bt_sock_wait_ready()
669 lock_sock(sk); in bt_sock_wait_ready()
672 err = sock_error(sk); in bt_sock_wait_ready()
677 remove_wait_queue(sk_sleep(sk), &wait); in bt_sock_wait_ready()
722 struct sock *sk = sk_entry(v); in bt_seq_show() local
723 struct bt_sock *bt = bt_sk(sk); in bt_seq_show()
727 sk, in bt_seq_show()
728 refcount_read(&sk->sk_refcnt), in bt_seq_show()
729 sk_rmem_alloc_get(sk), in bt_seq_show()
730 sk_wmem_alloc_get(sk), in bt_seq_show()
731 from_kuid(seq_user_ns(seq), sock_i_uid(sk)), in bt_seq_show()
732 sock_i_ino(sk), in bt_seq_show()