Lines Matching +full:timeout +full:- +full:secs
1 // SPDX-License-Identifier: GPL-2.0-or-later
45 #define KSMBD_TRANS(t) (&(t)->transport)
51 tcp_sock_set_nodelay(sock->sk); in ksmbd_tcp_nodelay()
56 sock_set_reuseaddr(sock->sk); in ksmbd_tcp_reuseaddr()
59 static inline void ksmbd_tcp_rcv_timeout(struct socket *sock, s64 secs) in ksmbd_tcp_rcv_timeout() argument
61 lock_sock(sock->sk); in ksmbd_tcp_rcv_timeout()
62 if (secs && secs < MAX_SCHEDULE_TIMEOUT / HZ - 1) in ksmbd_tcp_rcv_timeout()
63 sock->sk->sk_rcvtimeo = secs * HZ; in ksmbd_tcp_rcv_timeout()
65 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; in ksmbd_tcp_rcv_timeout()
66 release_sock(sock->sk); in ksmbd_tcp_rcv_timeout()
69 static inline void ksmbd_tcp_snd_timeout(struct socket *sock, s64 secs) in ksmbd_tcp_snd_timeout() argument
71 sock_set_sndtimeo(sock->sk, secs); in ksmbd_tcp_snd_timeout()
82 t->sock = client_sk; in alloc_transport()
90 conn->transport = KSMBD_TRANS(t); in alloc_transport()
91 KSMBD_TRANS(t)->conn = conn; in alloc_transport()
92 KSMBD_TRANS(t)->ops = &ksmbd_tcp_transport_ops; in alloc_transport()
98 kernel_sock_shutdown(t->sock, SHUT_RDWR); in free_transport()
99 sock_release(t->sock); in free_transport()
100 t->sock = NULL; in free_transport()
102 ksmbd_conn_free(KSMBD_TRANS(t)->conn); in free_transport()
103 kfree(t->iov); in free_transport()
108 * kvec_array_init() - initialize a IO vector segment
121 while (bytes || !iov->iov_len) { in kvec_array_init()
122 int copy = min(bytes, iov->iov_len); in kvec_array_init()
124 bytes -= copy; in kvec_array_init()
126 if (iov->iov_len == base) { in kvec_array_init()
128 nr_segs--; in kvec_array_init()
134 new->iov_base += base; in kvec_array_init()
135 new->iov_len -= base; in kvec_array_init()
140 * get_conn_iovec() - get connection iovec for reading from socket
150 if (t->iov && nr_segs <= t->nr_iov) in get_conn_iovec()
151 return t->iov; in get_conn_iovec()
153 /* not big enough -- allocate a new one and release the old */ in get_conn_iovec()
156 kfree(t->iov); in get_conn_iovec()
157 t->iov = new_iov; in get_conn_iovec()
158 t->nr_iov = nr_segs; in get_conn_iovec()
165 switch (sa->sa_family) { in ksmbd_tcp_get_port()
167 return ntohs(((struct sockaddr_in *)sa)->sin_port); in ksmbd_tcp_get_port()
169 return ntohs(((struct sockaddr_in6 *)sa)->sin6_port); in ksmbd_tcp_get_port()
175 * ksmbd_tcp_new_connection() - create a new tcp session on mount
193 return -ENOMEM; in ksmbd_tcp_new_connection()
196 csin = KSMBD_TCP_PEER_SOCKADDR(KSMBD_TRANS(t)->conn); in ksmbd_tcp_new_connection()
199 rc = -EINVAL; in ksmbd_tcp_new_connection()
204 KSMBD_TRANS(t)->conn, in ksmbd_tcp_new_connection()
220 * ksmbd_kthread_fn() - listen to new SMB connections and callback server
232 mutex_lock(&iface->sock_release_lock); in ksmbd_kthread_fn()
233 if (!iface->ksmbd_socket) { in ksmbd_kthread_fn()
234 mutex_unlock(&iface->sock_release_lock); in ksmbd_kthread_fn()
237 ret = kernel_accept(iface->ksmbd_socket, &client_sk, in ksmbd_kthread_fn()
239 mutex_unlock(&iface->sock_release_lock); in ksmbd_kthread_fn()
241 if (ret == -EAGAIN) in ksmbd_kthread_fn()
257 client_sk->sk->sk_rcvtimeo = KSMBD_TCP_RECV_TIMEOUT; in ksmbd_kthread_fn()
258 client_sk->sk->sk_sndtimeo = KSMBD_TCP_SEND_TIMEOUT; in ksmbd_kthread_fn()
268 * ksmbd_tcp_run_kthread() - start forker thread
282 kthread = kthread_run(ksmbd_kthread_fn, (void *)iface, "ksmbd-%s", in ksmbd_tcp_run_kthread()
283 iface->name); in ksmbd_tcp_run_kthread()
288 iface->ksmbd_kthread = kthread; in ksmbd_tcp_run_kthread()
294 * ksmbd_tcp_readv() - read data from socket in given iovec
313 struct ksmbd_conn *conn = KSMBD_TRANS(t)->conn; in ksmbd_tcp_readv()
317 return -ENOMEM; in ksmbd_tcp_readv()
322 for (total_read = 0; to_read; total_read += length, to_read -= length) { in ksmbd_tcp_readv()
326 total_read = -ESHUTDOWN; in ksmbd_tcp_readv()
331 length = kernel_recvmsg(t->sock, &ksmbd_msg, in ksmbd_tcp_readv()
334 if (length == -EINTR) { in ksmbd_tcp_readv()
335 total_read = -ESHUTDOWN; in ksmbd_tcp_readv()
338 total_read = -EAGAIN; in ksmbd_tcp_readv()
340 } else if (length == -ERESTARTSYS || length == -EAGAIN) { in ksmbd_tcp_readv()
349 max_retries--; in ksmbd_tcp_readv()
364 * ksmbd_tcp_read() - read data from socket in given buffer
391 return kernel_sendmsg(TCP_TRANS(t)->sock, &smb_msg, iov, nvecs, size); in ksmbd_tcp_writev()
408 /* set zero to timeout */ in tcp_destroy_socket()
419 * create_socket - create socket for ksmbd/0
434 if (ret != -EAFNOSUPPORT) in create_socket()
452 lock_sock(ksmbd_socket->sk); in create_socket()
453 ksmbd_socket->sk->sk_ipv6only = false; in create_socket()
454 release_sock(ksmbd_socket->sk); in create_socket()
463 KERNEL_SOCKPTR(iface->name), in create_socket()
464 strlen(iface->name)); in create_socket()
465 if (ret != -ENODEV && ret < 0) { in create_socket()
481 ksmbd_socket->sk->sk_rcvtimeo = KSMBD_TCP_RECV_TIMEOUT; in create_socket()
482 ksmbd_socket->sk->sk_sndtimeo = KSMBD_TCP_SEND_TIMEOUT; in create_socket()
490 iface->ksmbd_socket = ksmbd_socket; in create_socket()
496 iface->state = IFACE_STATE_CONFIGURED; in create_socket()
503 iface->ksmbd_socket = NULL; in create_socket()
520 if (!strcmp(iface->name, netdev->name)) { in ksmbd_netdev_event()
522 if (iface->state != IFACE_STATE_DOWN) in ksmbd_netdev_event()
524 ksmbd_debug(CONN, "netdev-up event: netdev(%s) is going up\n", in ksmbd_netdev_event()
525 iface->name); in ksmbd_netdev_event()
533 iface = alloc_iface(kstrdup(netdev->name, KSMBD_DEFAULT_GFP)); in ksmbd_netdev_event()
536 ksmbd_debug(CONN, "netdev-up event: netdev(%s) is going up\n", in ksmbd_netdev_event()
537 iface->name); in ksmbd_netdev_event()
545 if (!strcmp(iface->name, netdev->name) && in ksmbd_netdev_event()
546 iface->state == IFACE_STATE_CONFIGURED) { in ksmbd_netdev_event()
547 ksmbd_debug(CONN, "netdev-down event: netdev(%s) is going down\n", in ksmbd_netdev_event()
548 iface->name); in ksmbd_netdev_event()
549 tcp_stop_kthread(iface->ksmbd_kthread); in ksmbd_netdev_event()
550 iface->ksmbd_kthread = NULL; in ksmbd_netdev_event()
551 mutex_lock(&iface->sock_release_lock); in ksmbd_netdev_event()
552 tcp_destroy_socket(iface->ksmbd_socket); in ksmbd_netdev_event()
553 iface->ksmbd_socket = NULL; in ksmbd_netdev_event()
554 mutex_unlock(&iface->sock_release_lock); in ksmbd_netdev_event()
556 iface->state = IFACE_STATE_DOWN; in ksmbd_netdev_event()
596 list_del(&iface->entry); in ksmbd_tcp_destroy()
597 kfree(iface->name); in ksmbd_tcp_destroy()
615 iface->name = ifname; in alloc_iface()
616 iface->state = IFACE_STATE_DOWN; in alloc_iface()
617 list_add(&iface->entry, &iface_list); in alloc_iface()
618 mutex_init(&iface->sock_release_lock); in alloc_iface()
633 if (!alloc_iface(kstrdup(netdev->name, KSMBD_DEFAULT_GFP))) { in ksmbd_tcp_set_interfaces()
635 return -ENOMEM; in ksmbd_tcp_set_interfaces()
645 return -ENOMEM; in ksmbd_tcp_set_interfaces()
652 ifc_list_sz -= (sz + 1); in ksmbd_tcp_set_interfaces()