Lines Matching +full:tcon +full:- +full:channel
1 // SPDX-License-Identifier: LGPL-2.1
31 #include <keys/user-type.h>
71 * This should be called with server->srv_mutex held.
80 if (!server->hostname) in reconn_set_ipaddr_from_hostname()
81 return -EINVAL; in reconn_set_ipaddr_from_hostname()
84 if (server->hostname[0] == '\0') in reconn_set_ipaddr_from_hostname()
87 len = strlen(server->hostname) + 3; in reconn_set_ipaddr_from_hostname()
92 return -ENOMEM; in reconn_set_ipaddr_from_hostname()
94 scnprintf(unc, len, "\\\\%s", server->hostname); in reconn_set_ipaddr_from_hostname()
96 spin_lock(&server->srv_lock); in reconn_set_ipaddr_from_hostname()
97 ss = server->dstaddr; in reconn_set_ipaddr_from_hostname()
98 spin_unlock(&server->srv_lock); in reconn_set_ipaddr_from_hostname()
105 __func__, server->hostname, rc); in reconn_set_ipaddr_from_hostname()
107 spin_lock(&server->srv_lock); in reconn_set_ipaddr_from_hostname()
108 memcpy(&server->dstaddr, &ss, sizeof(server->dstaddr)); in reconn_set_ipaddr_from_hostname()
109 spin_unlock(&server->srv_lock); in reconn_set_ipaddr_from_hostname()
120 struct cifs_tcon *tcon = container_of(work, in smb2_query_server_interfaces() local
123 struct TCP_Server_Info *server = tcon->ses->server; in smb2_query_server_interfaces()
128 if (!server->ops->query_server_interfaces) in smb2_query_server_interfaces()
132 rc = server->ops->query_server_interfaces(xid, tcon, false); in smb2_query_server_interfaces()
136 if (rc == -EOPNOTSUPP) in smb2_query_server_interfaces()
143 queue_delayed_work(cifsiod_wq, &tcon->query_interfaces, in smb2_query_server_interfaces()
164 /* If server is a channel, select the primary channel */ in cifs_signal_cifsd_for_reconnect()
165 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in cifs_signal_cifsd_for_reconnect()
167 /* if we need to signal just this channel */ in cifs_signal_cifsd_for_reconnect()
169 spin_lock(&server->srv_lock); in cifs_signal_cifsd_for_reconnect()
170 if (server->tcpStatus != CifsExiting) in cifs_signal_cifsd_for_reconnect()
171 server->tcpStatus = CifsNeedReconnect; in cifs_signal_cifsd_for_reconnect()
172 spin_unlock(&server->srv_lock); in cifs_signal_cifsd_for_reconnect()
177 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) { in cifs_signal_cifsd_for_reconnect()
180 spin_lock(&ses->chan_lock); in cifs_signal_cifsd_for_reconnect()
181 for (i = 0; i < ses->chan_count; i++) { in cifs_signal_cifsd_for_reconnect()
182 if (!ses->chans[i].server) in cifs_signal_cifsd_for_reconnect()
185 spin_lock(&ses->chans[i].server->srv_lock); in cifs_signal_cifsd_for_reconnect()
186 if (ses->chans[i].server->tcpStatus != CifsExiting) in cifs_signal_cifsd_for_reconnect()
187 ses->chans[i].server->tcpStatus = CifsNeedReconnect; in cifs_signal_cifsd_for_reconnect()
188 spin_unlock(&ses->chans[i].server->srv_lock); in cifs_signal_cifsd_for_reconnect()
190 spin_unlock(&ses->chan_lock); in cifs_signal_cifsd_for_reconnect()
211 struct cifs_tcon *tcon; in cifs_mark_tcp_ses_conns_for_reconnect() local
219 /* If server is a channel, select the primary channel */ in cifs_mark_tcp_ses_conns_for_reconnect()
220 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in cifs_mark_tcp_ses_conns_for_reconnect()
230 if (server->terminate) { in cifs_mark_tcp_ses_conns_for_reconnect()
236 list_for_each_entry_safe(ses, nses, &pserver->smb_ses_list, smb_ses_list) { in cifs_mark_tcp_ses_conns_for_reconnect()
237 spin_lock(&ses->ses_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
238 if (ses->ses_status == SES_EXITING) { in cifs_mark_tcp_ses_conns_for_reconnect()
239 spin_unlock(&ses->ses_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
242 spin_unlock(&ses->ses_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
244 spin_lock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
247 spin_unlock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
252 spin_unlock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
254 spin_lock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
258 spin_unlock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
267 cifs_dbg(FYI, "%s: channel connect bitmap: 0x%lx\n", in cifs_mark_tcp_ses_conns_for_reconnect()
268 __func__, ses->chans_need_reconnect); in cifs_mark_tcp_ses_conns_for_reconnect()
270 /* If all channels need reconnect, then tcon needs reconnect */ in cifs_mark_tcp_ses_conns_for_reconnect()
272 spin_unlock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
275 spin_unlock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
277 spin_lock(&ses->ses_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
278 ses->ses_status = SES_NEED_RECON; in cifs_mark_tcp_ses_conns_for_reconnect()
279 spin_unlock(&ses->ses_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
281 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { in cifs_mark_tcp_ses_conns_for_reconnect()
282 tcon->need_reconnect = true; in cifs_mark_tcp_ses_conns_for_reconnect()
283 spin_lock(&tcon->tc_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
284 tcon->status = TID_NEED_RECON; in cifs_mark_tcp_ses_conns_for_reconnect()
285 spin_unlock(&tcon->tc_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
287 cancel_delayed_work(&tcon->query_interfaces); in cifs_mark_tcp_ses_conns_for_reconnect()
289 if (ses->tcon_ipc) { in cifs_mark_tcp_ses_conns_for_reconnect()
290 ses->tcon_ipc->need_reconnect = true; in cifs_mark_tcp_ses_conns_for_reconnect()
291 spin_lock(&ses->tcon_ipc->tc_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
292 ses->tcon_ipc->status = TID_NEED_RECON; in cifs_mark_tcp_ses_conns_for_reconnect()
293 spin_unlock(&ses->tcon_ipc->tc_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
305 server->maxBuf = 0; in cifs_abort_connection()
306 server->max_read = 0; in cifs_abort_connection()
311 if (server->ssocket) { in cifs_abort_connection()
312 cifs_dbg(FYI, "State: 0x%x Flags: 0x%lx\n", server->ssocket->state, in cifs_abort_connection()
313 server->ssocket->flags); in cifs_abort_connection()
314 kernel_sock_shutdown(server->ssocket, SHUT_WR); in cifs_abort_connection()
315 cifs_dbg(FYI, "Post shutdown state: 0x%x Flags: 0x%lx\n", server->ssocket->state, in cifs_abort_connection()
316 server->ssocket->flags); in cifs_abort_connection()
317 sock_release(server->ssocket); in cifs_abort_connection()
318 server->ssocket = NULL; in cifs_abort_connection()
320 server->sequence_number = 0; in cifs_abort_connection()
321 server->session_estab = false; in cifs_abort_connection()
322 kfree_sensitive(server->session_key.response); in cifs_abort_connection()
323 server->session_key.response = NULL; in cifs_abort_connection()
324 server->session_key.len = 0; in cifs_abort_connection()
325 server->lstrp = jiffies; in cifs_abort_connection()
330 spin_lock(&server->mid_lock); in cifs_abort_connection()
331 list_for_each_entry_safe(mid, nmid, &server->pending_mid_q, qhead) { in cifs_abort_connection()
332 kref_get(&mid->refcount); in cifs_abort_connection()
333 if (mid->mid_state == MID_REQUEST_SUBMITTED) in cifs_abort_connection()
334 mid->mid_state = MID_RETRY_NEEDED; in cifs_abort_connection()
335 list_move(&mid->qhead, &retry_list); in cifs_abort_connection()
336 mid->mid_flags |= MID_DELETED; in cifs_abort_connection()
338 spin_unlock(&server->mid_lock); in cifs_abort_connection()
343 list_del_init(&mid->qhead); in cifs_abort_connection()
344 mid->callback(mid); in cifs_abort_connection()
357 spin_lock(&server->srv_lock); in cifs_tcp_ses_needs_reconnect()
358 server->nr_targets = num_targets; in cifs_tcp_ses_needs_reconnect()
359 if (server->tcpStatus == CifsExiting) { in cifs_tcp_ses_needs_reconnect()
361 spin_unlock(&server->srv_lock); in cifs_tcp_ses_needs_reconnect()
362 wake_up(&server->response_q); in cifs_tcp_ses_needs_reconnect()
367 trace_smb3_reconnect(server->CurrentMid, server->conn_id, in cifs_tcp_ses_needs_reconnect()
368 server->hostname); in cifs_tcp_ses_needs_reconnect()
369 server->tcpStatus = CifsNeedReconnect; in cifs_tcp_ses_needs_reconnect()
371 spin_unlock(&server->srv_lock); in cifs_tcp_ses_needs_reconnect()
381 * wake up waiters on reconnection? - (not needed currently)
384 * the smb session (and tcon) for reconnect as well. This value
385 * doesn't really matter for non-multichannel scenario.
405 /* resolve the hostname again to make sure that IP address is up-to-date */ in __cifs_reconnect()
421 spin_lock(&server->srv_lock); in __cifs_reconnect()
422 if (server->tcpStatus != CifsExiting) in __cifs_reconnect()
423 server->tcpStatus = CifsNeedNegotiate; in __cifs_reconnect()
424 spin_unlock(&server->srv_lock); in __cifs_reconnect()
427 mod_delayed_work(cifsiod_wq, &server->reconnect, 0); in __cifs_reconnect()
429 } while (server->tcpStatus == CifsNeedReconnect); in __cifs_reconnect()
431 spin_lock(&server->srv_lock); in __cifs_reconnect()
432 if (server->tcpStatus == CifsNeedNegotiate) in __cifs_reconnect()
433 mod_delayed_work(cifsiod_wq, &server->echo, 0); in __cifs_reconnect()
434 spin_unlock(&server->srv_lock); in __cifs_reconnect()
436 wake_up(&server->response_q); in __cifs_reconnect()
447 if (server->hostname != target) { in __reconnect_target_unlocked()
450 spin_lock(&server->srv_lock); in __reconnect_target_unlocked()
451 kfree(server->hostname); in __reconnect_target_unlocked()
452 server->hostname = hostname; in __reconnect_target_unlocked()
453 spin_unlock(&server->srv_lock); in __reconnect_target_unlocked()
458 server->hostname); in __reconnect_target_unlocked()
461 /* resolve the hostname again to make sure that IP address is up-to-date. */ in __reconnect_target_unlocked()
485 return __reconnect_target_unlocked(server, server->hostname); in reconnect_target_unlocked()
510 * targets (server->nr_targets). It's also possible that the cached referral was cleared in reconnect_dfs_server()
514 mutex_lock(&server->refpath_lock); in reconnect_dfs_server()
515 if (!dfs_cache_noreq_find(server->leaf_fullpath + 1, NULL, &tl)) in reconnect_dfs_server()
517 mutex_unlock(&server->refpath_lock); in reconnect_dfs_server()
547 * process waiting for reconnect will know it needs to re-establish session and tcon in reconnect_dfs_server()
552 spin_lock(&server->srv_lock); in reconnect_dfs_server()
553 if (server->tcpStatus != CifsExiting) in reconnect_dfs_server()
554 server->tcpStatus = CifsNeedNegotiate; in reconnect_dfs_server()
555 spin_unlock(&server->srv_lock); in reconnect_dfs_server()
558 mod_delayed_work(cifsiod_wq, &server->reconnect, 0); in reconnect_dfs_server()
559 } while (server->tcpStatus == CifsNeedReconnect); in reconnect_dfs_server()
561 mutex_lock(&server->refpath_lock); in reconnect_dfs_server()
562 dfs_cache_noreq_update_tgthint(server->leaf_fullpath + 1, target_hint); in reconnect_dfs_server()
563 mutex_unlock(&server->refpath_lock); in reconnect_dfs_server()
567 spin_lock(&server->srv_lock); in reconnect_dfs_server()
568 if (server->tcpStatus == CifsNeedNegotiate) in reconnect_dfs_server()
569 mod_delayed_work(cifsiod_wq, &server->echo, 0); in reconnect_dfs_server()
570 spin_unlock(&server->srv_lock); in reconnect_dfs_server()
572 wake_up(&server->response_q); in reconnect_dfs_server()
578 mutex_lock(&server->refpath_lock); in cifs_reconnect()
579 if (!server->leaf_fullpath) { in cifs_reconnect()
580 mutex_unlock(&server->refpath_lock); in cifs_reconnect()
583 mutex_unlock(&server->refpath_lock); in cifs_reconnect()
606 if (server->tcpStatus == CifsNeedReconnect || in cifs_echo_request()
607 server->tcpStatus == CifsExiting || in cifs_echo_request()
608 server->tcpStatus == CifsNew || in cifs_echo_request()
609 (server->ops->can_echo && !server->ops->can_echo(server)) || in cifs_echo_request()
610 time_before(jiffies, server->lstrp + server->echo_interval - HZ)) in cifs_echo_request()
613 rc = server->ops->echo ? server->ops->echo(server) : -ENOSYS; in cifs_echo_request()
620 queue_delayed_work(cifsiod_wq, &server->echo, server->echo_interval); in cifs_echo_request()
626 if (!server->bigbuf) { in allocate_buffers()
627 server->bigbuf = (char *)cifs_buf_get(); in allocate_buffers()
628 if (!server->bigbuf) { in allocate_buffers()
634 } else if (server->large_buf) { in allocate_buffers()
636 memset(server->bigbuf, 0, HEADER_SIZE(server)); in allocate_buffers()
639 if (!server->smallbuf) { in allocate_buffers()
640 server->smallbuf = (char *)cifs_small_buf_get(); in allocate_buffers()
641 if (!server->smallbuf) { in allocate_buffers()
650 memset(server->smallbuf, 0, HEADER_SIZE(server)); in allocate_buffers()
665 spin_lock(&server->srv_lock); in server_unresponsive()
666 if (server->tcpStatus == CifsInNegotiate && in server_unresponsive()
667 time_after(jiffies, server->lstrp + 20 * HZ)) { in server_unresponsive()
668 spin_unlock(&server->srv_lock); in server_unresponsive()
683 if ((server->tcpStatus == CifsGood || in server_unresponsive()
684 server->tcpStatus == CifsNeedNegotiate) && in server_unresponsive()
685 (!server->ops->can_echo || server->ops->can_echo(server)) && in server_unresponsive()
686 time_after(jiffies, server->lstrp + 3 * server->echo_interval)) { in server_unresponsive()
687 spin_unlock(&server->srv_lock); in server_unresponsive()
689 (3 * server->echo_interval) / HZ); in server_unresponsive()
693 spin_unlock(&server->srv_lock); in server_unresponsive()
703 spin_lock(&server->req_lock); in zero_credits()
704 val = server->credits + server->echo_credits + server->oplock_credits; in zero_credits()
705 if (server->in_flight == 0 && val == 0) { in zero_credits()
706 spin_unlock(&server->req_lock); in zero_credits()
709 spin_unlock(&server->req_lock); in zero_credits()
725 return -ECONNABORTED; in cifs_readv_from_socket()
729 return -ECONNABORTED; in cifs_readv_from_socket()
730 if (cifs_rdma_enabled(server) && server->smbd_conn) in cifs_readv_from_socket()
731 length = smbd_recv(server->smbd_conn, smb_msg); in cifs_readv_from_socket()
733 length = sock_recvmsg(server->ssocket, smb_msg, 0); in cifs_readv_from_socket()
735 spin_lock(&server->srv_lock); in cifs_readv_from_socket()
736 if (server->tcpStatus == CifsExiting) { in cifs_readv_from_socket()
737 spin_unlock(&server->srv_lock); in cifs_readv_from_socket()
738 return -ESHUTDOWN; in cifs_readv_from_socket()
741 if (server->tcpStatus == CifsNeedReconnect) { in cifs_readv_from_socket()
742 spin_unlock(&server->srv_lock); in cifs_readv_from_socket()
744 return -ECONNABORTED; in cifs_readv_from_socket()
746 spin_unlock(&server->srv_lock); in cifs_readv_from_socket()
748 if (length == -ERESTARTSYS || in cifs_readv_from_socket()
749 length == -EAGAIN || in cifs_readv_from_socket()
750 length == -EINTR) { in cifs_readv_from_socket()
764 return -ECONNABORTED; in cifs_readv_from_socket()
839 cifs_set_port((struct sockaddr *)&server->dstaddr, CIFS_PORT); in is_smb_response()
854 mid->when_received = jiffies; in dequeue_mid()
856 spin_lock(&mid->server->mid_lock); in dequeue_mid()
858 mid->mid_state = MID_RESPONSE_RECEIVED; in dequeue_mid()
860 mid->mid_state = MID_RESPONSE_MALFORMED; in dequeue_mid()
865 if (mid->mid_flags & MID_DELETED) { in dequeue_mid()
866 spin_unlock(&mid->server->mid_lock); in dequeue_mid()
869 list_del_init(&mid->qhead); in dequeue_mid()
870 mid->mid_flags |= MID_DELETED; in dequeue_mid()
871 spin_unlock(&mid->server->mid_lock); in dequeue_mid()
886 return le16_to_cpu(shdr->CreditRequest); in smb2_get_credits_from_hdr()
893 if (server->ops->check_trans2 && in handle_mid()
894 server->ops->check_trans2(mid, server, buf, malformed)) in handle_mid()
896 mid->credits_received = smb2_get_credits_from_hdr(buf, server); in handle_mid()
897 mid->resp_buf = buf; in handle_mid()
898 mid->large_buf = server->large_buf; in handle_mid()
899 /* Was previous buf put in mpx struct for multi-rsp? */ in handle_mid()
900 if (!mid->multiRsp) { in handle_mid()
902 if (server->large_buf) in handle_mid()
903 server->bigbuf = NULL; in handle_mid()
905 server->smallbuf = NULL; in handle_mid()
913 bool srv_sign_required = server->sec_mode & server->vals->signing_required; in cifs_enable_signing()
914 bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled; in cifs_enable_signing()
936 return -EOPNOTSUPP; in cifs_enable_signing()
938 server->sign = true; in cifs_enable_signing()
945 return -EOPNOTSUPP; in cifs_enable_signing()
947 server->sign = true; in cifs_enable_signing()
950 if (cifs_rdma_enabled(server) && server->sign) in cifs_enable_signing()
962 spin_lock(&server->srv_lock); in clean_demultiplex_info()
963 list_del_init(&server->tcp_ses_list); in clean_demultiplex_info()
964 spin_unlock(&server->srv_lock); in clean_demultiplex_info()
966 cancel_delayed_work_sync(&server->echo); in clean_demultiplex_info()
968 spin_lock(&server->srv_lock); in clean_demultiplex_info()
969 server->tcpStatus = CifsExiting; in clean_demultiplex_info()
970 spin_unlock(&server->srv_lock); in clean_demultiplex_info()
971 wake_up_all(&server->response_q); in clean_demultiplex_info()
974 spin_lock(&server->req_lock); in clean_demultiplex_info()
975 if (server->credits <= 0) in clean_demultiplex_info()
976 server->credits = 1; in clean_demultiplex_info()
977 spin_unlock(&server->req_lock); in clean_demultiplex_info()
982 * same server - they now will see the session is in exit state and get in clean_demultiplex_info()
985 wake_up_all(&server->request_q); in clean_demultiplex_info()
990 if (server->ssocket) { in clean_demultiplex_info()
991 sock_release(server->ssocket); in clean_demultiplex_info()
992 server->ssocket = NULL; in clean_demultiplex_info()
995 if (!list_empty(&server->pending_mid_q)) { in clean_demultiplex_info()
1000 spin_lock(&server->mid_lock); in clean_demultiplex_info()
1001 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { in clean_demultiplex_info()
1003 cifs_dbg(FYI, "Clearing mid %llu\n", mid_entry->mid); in clean_demultiplex_info()
1004 kref_get(&mid_entry->refcount); in clean_demultiplex_info()
1005 mid_entry->mid_state = MID_SHUTDOWN; in clean_demultiplex_info()
1006 list_move(&mid_entry->qhead, &dispose_list); in clean_demultiplex_info()
1007 mid_entry->mid_flags |= MID_DELETED; in clean_demultiplex_info()
1009 spin_unlock(&server->mid_lock); in clean_demultiplex_info()
1014 cifs_dbg(FYI, "Callback mid %llu\n", mid_entry->mid); in clean_demultiplex_info()
1015 list_del_init(&mid_entry->qhead); in clean_demultiplex_info()
1016 mid_entry->callback(mid_entry); in clean_demultiplex_info()
1023 if (!list_empty(&server->pending_mid_q)) { in clean_demultiplex_info()
1041 kfree(server->leaf_fullpath); in clean_demultiplex_info()
1053 char *buf = server->smallbuf; in standard_receive3()
1054 unsigned int pdu_length = server->pdu_size; in standard_receive3()
1057 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server) - in standard_receive3()
1061 return -ECONNABORTED; in standard_receive3()
1065 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) { in standard_receive3()
1066 server->large_buf = true; in standard_receive3()
1067 memcpy(server->bigbuf, buf, server->total_read); in standard_receive3()
1068 buf = server->bigbuf; in standard_receive3()
1072 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, in standard_receive3()
1073 pdu_length - MID_HEADER_SIZE(server)); in standard_receive3()
1077 server->total_read += length; in standard_receive3()
1079 dump_smb(buf, server->total_read); in standard_receive3()
1087 char *buf = server->large_buf ? server->bigbuf : server->smallbuf; in cifs_handle_standard()
1098 rc = server->ops->check_message(buf, server->total_read, server); in cifs_handle_standard()
1101 min_t(unsigned int, server->total_read, 48)); in cifs_handle_standard()
1103 if (server->ops->is_session_expired && in cifs_handle_standard()
1104 server->ops->is_session_expired(buf)) { in cifs_handle_standard()
1106 return -1; in cifs_handle_standard()
1109 if (server->ops->is_status_pending && in cifs_handle_standard()
1110 server->ops->is_status_pending(buf, server)) in cifs_handle_standard()
1111 return -1; in cifs_handle_standard()
1132 if (shdr->CreditRequest) { in smb2_add_credits_from_hdr()
1133 spin_lock(&server->req_lock); in smb2_add_credits_from_hdr()
1134 server->credits += le16_to_cpu(shdr->CreditRequest); in smb2_add_credits_from_hdr()
1135 scredits = server->credits; in smb2_add_credits_from_hdr()
1136 in_flight = server->in_flight; in smb2_add_credits_from_hdr()
1137 spin_unlock(&server->req_lock); in smb2_add_credits_from_hdr()
1138 wake_up(&server->request_q); in smb2_add_credits_from_hdr()
1140 trace_smb3_hdr_credits(server->CurrentMid, in smb2_add_credits_from_hdr()
1141 server->conn_id, server->hostname, scredits, in smb2_add_credits_from_hdr()
1142 le16_to_cpu(shdr->CreditRequest), in_flight); in smb2_add_credits_from_hdr()
1144 __func__, le16_to_cpu(shdr->CreditRequest), in smb2_add_credits_from_hdr()
1173 while (server->tcpStatus != CifsExiting) { in cifs_demultiplex_thread()
1180 server->large_buf = false; in cifs_demultiplex_thread()
1181 buf = server->smallbuf; in cifs_demultiplex_thread()
1189 server->total_read = length; in cifs_demultiplex_thread()
1191 server->total_read = 0; in cifs_demultiplex_thread()
1194 * The right amount was read from socket - 4 bytes, in cifs_demultiplex_thread()
1205 server->pdu_size = pdu_length; in cifs_demultiplex_thread()
1208 if (server->pdu_size < MID_HEADER_SIZE(server)) { in cifs_demultiplex_thread()
1210 server->pdu_size); in cifs_demultiplex_thread()
1221 server->total_read += length; in cifs_demultiplex_thread()
1223 if (server->ops->next_header) { in cifs_demultiplex_thread()
1224 if (server->ops->next_header(server, buf, &next_offset)) { in cifs_demultiplex_thread()
1231 server->pdu_size = next_offset; in cifs_demultiplex_thread()
1238 if (server->ops->is_transform_hdr && in cifs_demultiplex_thread()
1239 server->ops->receive_transform && in cifs_demultiplex_thread()
1240 server->ops->is_transform_hdr(buf)) { in cifs_demultiplex_thread()
1241 length = server->ops->receive_transform(server, in cifs_demultiplex_thread()
1246 mids[0] = server->ops->find_mid(server, buf); in cifs_demultiplex_thread()
1250 if (!mids[0] || !mids[0]->receive) in cifs_demultiplex_thread()
1253 length = mids[0]->receive(server, mids[0]); in cifs_demultiplex_thread()
1263 if (server->ops->is_status_io_timeout && in cifs_demultiplex_thread()
1264 server->ops->is_status_io_timeout(buf)) { in cifs_demultiplex_thread()
1276 server->lstrp = jiffies; in cifs_demultiplex_thread()
1280 mids[i]->resp_buf_size = server->pdu_size; in cifs_demultiplex_thread()
1283 if (server->ops->is_network_name_deleted && in cifs_demultiplex_thread()
1284 server->ops->is_network_name_deleted(bufs[i], in cifs_demultiplex_thread()
1291 if (!mids[i]->multiRsp || mids[i]->multiEnd) in cifs_demultiplex_thread()
1292 mids[i]->callback(mids[i]); in cifs_demultiplex_thread()
1295 } else if (server->ops->is_oplock_break && in cifs_demultiplex_thread()
1296 server->ops->is_oplock_break(bufs[i], in cifs_demultiplex_thread()
1307 if (server->ops->dump_detail) in cifs_demultiplex_thread()
1308 server->ops->dump_detail(bufs[i], in cifs_demultiplex_thread()
1315 if (pdu_length > server->pdu_size) { in cifs_demultiplex_thread()
1318 pdu_length -= server->pdu_size; in cifs_demultiplex_thread()
1319 server->total_read = 0; in cifs_demultiplex_thread()
1320 server->large_buf = false; in cifs_demultiplex_thread()
1321 buf = server->smallbuf; in cifs_demultiplex_thread()
1331 /* buffer usually freed in free_mid - need to free it here on exit */ in cifs_demultiplex_thread()
1332 cifs_buf_release(server->bigbuf); in cifs_demultiplex_thread()
1333 if (server->smallbuf) /* no sense logging a debug message if NULL */ in cifs_demultiplex_thread()
1334 cifs_small_buf_release(server->smallbuf); in cifs_demultiplex_thread()
1336 task_to_wake = xchg(&server->tsk, NULL); in cifs_demultiplex_thread()
1339 /* if server->tsk was NULL then wait for a signal before exiting */ in cifs_demultiplex_thread()
1361 switch (srcaddr->sa_family) { in cifs_ipaddr_cmp()
1363 switch (rhs->sa_family) { in cifs_ipaddr_cmp()
1370 return -1; in cifs_ipaddr_cmp()
1373 switch (rhs->sa_family) { in cifs_ipaddr_cmp()
1375 return -1; in cifs_ipaddr_cmp()
1382 return -1; in cifs_ipaddr_cmp()
1386 switch (rhs->sa_family) { in cifs_ipaddr_cmp()
1389 return -1; in cifs_ipaddr_cmp()
1395 return -1; in cifs_ipaddr_cmp()
1399 return -1; /* don't expect to be here */ in cifs_ipaddr_cmp()
1410 switch (srcaddr->sa_family) { in cifs_match_ipaddr()
1412 return (rhs->sa_family == AF_UNSPEC); in cifs_match_ipaddr()
1417 return (saddr4->sin_addr.s_addr == vaddr4->sin_addr.s_addr); in cifs_match_ipaddr()
1423 return (ipv6_addr_equal(&saddr6->sin6_addr, &vaddr6->sin6_addr) in cifs_match_ipaddr()
1424 && saddr6->sin6_scope_id == vaddr6->sin6_scope_id); in cifs_match_ipaddr()
1434 * and if it fails - with 139 ports. It should be called only if address
1443 if (server->rdma) in match_port()
1446 switch (addr->sa_family) { in match_port()
1448 sport = &((struct sockaddr_in *) &server->dstaddr)->sin_port; in match_port()
1449 port = ((struct sockaddr_in *) addr)->sin_port; in match_port()
1452 sport = &((struct sockaddr_in6 *) &server->dstaddr)->sin6_port; in match_port()
1453 port = ((struct sockaddr_in6 *) addr)->sin6_port; in match_port()
1473 if (!cifs_match_ipaddr(addr, (struct sockaddr *)&server->dstaddr)) in match_server_address()
1483 * The select_sectype function should either return the ctx->sectype in match_security()
1487 if (server->ops->select_sectype(server, ctx->sectype) in match_security()
1494 * the server->sign had better be too. in match_security()
1496 if (ctx->sign && !server->sign) in match_security()
1507 struct sockaddr *addr = (struct sockaddr *)&ctx->dstaddr; in match_server()
1509 lockdep_assert_held(&server->srv_lock); in match_server()
1511 if (ctx->nosharesock) in match_server()
1515 if (server->nosharesock) in match_server()
1518 if (!match_super && (ctx->dfs_conn || server->dfs_conn)) in match_server()
1522 if (strcmp(ctx->vals->version_string, SMB3ANY_VERSION_STRING) == 0) { in match_server()
1523 if (server->vals->protocol_id < SMB30_PROT_ID) in match_server()
1525 } else if (strcmp(ctx->vals->version_string, in match_server()
1527 if (server->vals->protocol_id < SMB21_PROT_ID) in match_server()
1529 } else if ((server->vals != ctx->vals) || (server->ops != ctx->ops)) in match_server()
1532 if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns)) in match_server()
1535 if (!cifs_match_ipaddr((struct sockaddr *)&ctx->srcaddr, in match_server()
1536 (struct sockaddr *)&server->srcaddr)) in match_server()
1540 * really match either @server->leaf_fullpath or @server->dstaddr in match_server()
1542 * server -- in case of domain-based DFS referrals or DFS links -- as in match_server()
1545 * Otherwise, match the DFS referral in @server->leaf_fullpath or the in match_server()
1546 * destination address in @server->dstaddr. in match_server()
1552 if (!ctx->nodfs) { in match_server()
1553 if (server->leaf_fullpath) { in match_server()
1554 if (!ctx->leaf_fullpath || in match_server()
1555 strcasecmp(server->leaf_fullpath, in match_server()
1556 ctx->leaf_fullpath)) in match_server()
1558 } else if (ctx->leaf_fullpath) { in match_server()
1561 } else if (server->leaf_fullpath) { in match_server()
1570 if (!server->leaf_fullpath && in match_server()
1571 (strcasecmp(server->hostname, ctx->server_hostname) || in match_server()
1579 if (server->echo_interval != ctx->echo_interval * HZ) in match_server()
1582 if (server->rdma != ctx->rdma) in match_server()
1585 if (server->ignore_signature != ctx->ignore_signature) in match_server()
1588 if (server->min_offload != ctx->min_offload) in match_server()
1591 if (server->retrans != ctx->retrans) in match_server()
1604 spin_lock(&server->srv_lock); in cifs_find_tcp_session()
1611 spin_unlock(&server->srv_lock); in cifs_find_tcp_session()
1614 spin_unlock(&server->srv_lock); in cifs_find_tcp_session()
1616 ++server->srv_count; in cifs_find_tcp_session()
1631 if (--server->srv_count > 0) { in cifs_put_tcp_session()
1637 WARN_ON(server->srv_count < 0); in cifs_put_tcp_session()
1639 list_del_init(&server->tcp_ses_list); in cifs_put_tcp_session()
1642 cancel_delayed_work_sync(&server->echo); in cifs_put_tcp_session()
1651 cancel_delayed_work(&server->reconnect); in cifs_put_tcp_session()
1653 cancel_delayed_work_sync(&server->reconnect); in cifs_put_tcp_session()
1655 /* For secondary channels, we pick up ref-count on the primary server */ in cifs_put_tcp_session()
1657 cifs_put_tcp_session(server->primary_server, from_reconnect); in cifs_put_tcp_session()
1659 spin_lock(&server->srv_lock); in cifs_put_tcp_session()
1660 server->tcpStatus = CifsExiting; in cifs_put_tcp_session()
1661 spin_unlock(&server->srv_lock); in cifs_put_tcp_session()
1665 kfree_sensitive(server->session_key.response); in cifs_put_tcp_session()
1666 server->session_key.response = NULL; in cifs_put_tcp_session()
1667 server->session_key.len = 0; in cifs_put_tcp_session()
1668 kfree(server->hostname); in cifs_put_tcp_session()
1669 server->hostname = NULL; in cifs_put_tcp_session()
1671 task = xchg(&server->tsk, NULL); in cifs_put_tcp_session()
1683 cifs_dbg(FYI, "UNC: %s\n", ctx->UNC); in cifs_get_tcp_session()
1692 rc = -ENOMEM; in cifs_get_tcp_session()
1696 tcp_ses->hostname = kstrdup(ctx->server_hostname, GFP_KERNEL); in cifs_get_tcp_session()
1697 if (!tcp_ses->hostname) { in cifs_get_tcp_session()
1698 rc = -ENOMEM; in cifs_get_tcp_session()
1702 if (ctx->leaf_fullpath) { in cifs_get_tcp_session()
1703 tcp_ses->leaf_fullpath = kstrdup(ctx->leaf_fullpath, GFP_KERNEL); in cifs_get_tcp_session()
1704 if (!tcp_ses->leaf_fullpath) { in cifs_get_tcp_session()
1705 rc = -ENOMEM; in cifs_get_tcp_session()
1710 if (ctx->nosharesock) in cifs_get_tcp_session()
1711 tcp_ses->nosharesock = true; in cifs_get_tcp_session()
1712 tcp_ses->dfs_conn = ctx->dfs_conn; in cifs_get_tcp_session()
1714 tcp_ses->ops = ctx->ops; in cifs_get_tcp_session()
1715 tcp_ses->vals = ctx->vals; in cifs_get_tcp_session()
1716 cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns)); in cifs_get_tcp_session()
1718 tcp_ses->conn_id = atomic_inc_return(&tcpSesNextId); in cifs_get_tcp_session()
1719 tcp_ses->noblockcnt = ctx->rootfs; in cifs_get_tcp_session()
1720 tcp_ses->noblocksnd = ctx->noblocksnd || ctx->rootfs; in cifs_get_tcp_session()
1721 tcp_ses->noautotune = ctx->noautotune; in cifs_get_tcp_session()
1722 tcp_ses->tcp_nodelay = ctx->sockopt_tcp_nodelay; in cifs_get_tcp_session()
1723 tcp_ses->rdma = ctx->rdma; in cifs_get_tcp_session()
1724 tcp_ses->in_flight = 0; in cifs_get_tcp_session()
1725 tcp_ses->max_in_flight = 0; in cifs_get_tcp_session()
1726 tcp_ses->credits = 1; in cifs_get_tcp_session()
1729 ++primary_server->srv_count; in cifs_get_tcp_session()
1731 tcp_ses->primary_server = primary_server; in cifs_get_tcp_session()
1733 init_waitqueue_head(&tcp_ses->response_q); in cifs_get_tcp_session()
1734 init_waitqueue_head(&tcp_ses->request_q); in cifs_get_tcp_session()
1735 INIT_LIST_HEAD(&tcp_ses->pending_mid_q); in cifs_get_tcp_session()
1736 mutex_init(&tcp_ses->_srv_mutex); in cifs_get_tcp_session()
1737 memcpy(tcp_ses->workstation_RFC1001_name, in cifs_get_tcp_session()
1738 ctx->source_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL); in cifs_get_tcp_session()
1739 memcpy(tcp_ses->server_RFC1001_name, in cifs_get_tcp_session()
1740 ctx->target_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL); in cifs_get_tcp_session()
1741 tcp_ses->session_estab = false; in cifs_get_tcp_session()
1742 tcp_ses->sequence_number = 0; in cifs_get_tcp_session()
1743 tcp_ses->channel_sequence_num = 0; /* only tracked for primary channel */ in cifs_get_tcp_session()
1744 tcp_ses->reconnect_instance = 1; in cifs_get_tcp_session()
1745 tcp_ses->lstrp = jiffies; in cifs_get_tcp_session()
1746 tcp_ses->compression.requested = ctx->compress; in cifs_get_tcp_session()
1747 spin_lock_init(&tcp_ses->req_lock); in cifs_get_tcp_session()
1748 spin_lock_init(&tcp_ses->srv_lock); in cifs_get_tcp_session()
1749 spin_lock_init(&tcp_ses->mid_lock); in cifs_get_tcp_session()
1750 INIT_LIST_HEAD(&tcp_ses->tcp_ses_list); in cifs_get_tcp_session()
1751 INIT_LIST_HEAD(&tcp_ses->smb_ses_list); in cifs_get_tcp_session()
1752 INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request); in cifs_get_tcp_session()
1753 INIT_DELAYED_WORK(&tcp_ses->reconnect, smb2_reconnect_server); in cifs_get_tcp_session()
1754 mutex_init(&tcp_ses->reconnect_mutex); in cifs_get_tcp_session()
1756 mutex_init(&tcp_ses->refpath_lock); in cifs_get_tcp_session()
1758 memcpy(&tcp_ses->srcaddr, &ctx->srcaddr, in cifs_get_tcp_session()
1759 sizeof(tcp_ses->srcaddr)); in cifs_get_tcp_session()
1760 memcpy(&tcp_ses->dstaddr, &ctx->dstaddr, in cifs_get_tcp_session()
1761 sizeof(tcp_ses->dstaddr)); in cifs_get_tcp_session()
1762 if (ctx->use_client_guid) in cifs_get_tcp_session()
1763 memcpy(tcp_ses->client_guid, ctx->client_guid, in cifs_get_tcp_session()
1766 generate_random_uuid(tcp_ses->client_guid); in cifs_get_tcp_session()
1772 tcp_ses->tcpStatus = CifsNew; in cifs_get_tcp_session()
1773 ++tcp_ses->srv_count; in cifs_get_tcp_session()
1775 if (ctx->echo_interval >= SMB_ECHO_INTERVAL_MIN && in cifs_get_tcp_session()
1776 ctx->echo_interval <= SMB_ECHO_INTERVAL_MAX) in cifs_get_tcp_session()
1777 tcp_ses->echo_interval = ctx->echo_interval * HZ; in cifs_get_tcp_session()
1779 tcp_ses->echo_interval = SMB_ECHO_INTERVAL_DEFAULT * HZ; in cifs_get_tcp_session()
1780 if (tcp_ses->rdma) { in cifs_get_tcp_session()
1783 rc = -ENOENT; in cifs_get_tcp_session()
1786 tcp_ses->smbd_conn = smbd_get_connection( in cifs_get_tcp_session()
1787 tcp_ses, (struct sockaddr *)&ctx->dstaddr); in cifs_get_tcp_session()
1788 if (tcp_ses->smbd_conn) { in cifs_get_tcp_session()
1793 rc = -ENOENT; in cifs_get_tcp_session()
1808 tcp_ses->tsk = kthread_run(cifs_demultiplex_thread, in cifs_get_tcp_session()
1810 if (IS_ERR(tcp_ses->tsk)) { in cifs_get_tcp_session()
1811 rc = PTR_ERR(tcp_ses->tsk); in cifs_get_tcp_session()
1816 tcp_ses->min_offload = ctx->min_offload; in cifs_get_tcp_session()
1817 tcp_ses->retrans = ctx->retrans; in cifs_get_tcp_session()
1823 spin_lock(&tcp_ses->srv_lock); in cifs_get_tcp_session()
1824 tcp_ses->tcpStatus = CifsNeedNegotiate; in cifs_get_tcp_session()
1825 spin_unlock(&tcp_ses->srv_lock); in cifs_get_tcp_session()
1827 if ((ctx->max_credits < 20) || (ctx->max_credits > 60000)) in cifs_get_tcp_session()
1828 tcp_ses->max_credits = SMB2_MAX_CREDITS_AVAILABLE; in cifs_get_tcp_session()
1830 tcp_ses->max_credits = ctx->max_credits; in cifs_get_tcp_session()
1832 tcp_ses->nr_targets = 1; in cifs_get_tcp_session()
1833 tcp_ses->ignore_signature = ctx->ignore_signature; in cifs_get_tcp_session()
1836 list_add(&tcp_ses->tcp_ses_list, &cifs_tcp_ses_list); in cifs_get_tcp_session()
1840 queue_delayed_work(cifsiod_wq, &tcp_ses->echo, tcp_ses->echo_interval); in cifs_get_tcp_session()
1852 cifs_put_tcp_session(tcp_ses->primary_server, false); in cifs_get_tcp_session()
1853 kfree(tcp_ses->hostname); in cifs_get_tcp_session()
1854 kfree(tcp_ses->leaf_fullpath); in cifs_get_tcp_session()
1855 if (tcp_ses->ssocket) in cifs_get_tcp_session()
1856 sock_release(tcp_ses->ssocket); in cifs_get_tcp_session()
1867 if (ctx->sectype != Unspecified && in match_session()
1868 ctx->sectype != ses->sectype) in match_session()
1871 if (!match_super && ctx->dfs_root_ses != ses->dfs_root_ses) in match_session()
1878 if (ses->chan_max < ctx->max_channels) in match_session()
1881 switch (ses->sectype) { in match_session()
1883 if (!uid_eq(ctx->cred_uid, ses->cred_uid)) in match_session()
1888 if (ses->user_name == NULL) { in match_session()
1889 if (!ctx->nullauth) in match_session()
1895 if (strncmp(ses->user_name, in match_session()
1896 ctx->username ? ctx->username : "", in match_session()
1899 if ((ctx->username && strlen(ctx->username) != 0) && in match_session()
1900 ses->password != NULL && in match_session()
1901 strncmp(ses->password, in match_session()
1902 ctx->password ? ctx->password : "", in match_session()
1907 if (strcmp(ctx->local_nls->charset, ses->local_nls->charset)) in match_session()
1914 * cifs_setup_ipc - helper to setup the IPC tcon for the session
1920 * tcon_ipc. The IPC tcon has the same lifetime as the session.
1926 struct cifs_tcon *tcon; in cifs_setup_ipc() local
1929 struct TCP_Server_Info *server = ses->server; in cifs_setup_ipc()
1935 if (ctx->seal) { in cifs_setup_ipc()
1936 if (server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION) in cifs_setup_ipc()
1941 return -EOPNOTSUPP; in cifs_setup_ipc()
1946 tcon = tcon_info_alloc(false, netfs_trace_tcon_ref_new_ipc); in cifs_setup_ipc()
1947 if (tcon == NULL) in cifs_setup_ipc()
1948 return -ENOMEM; in cifs_setup_ipc()
1950 spin_lock(&server->srv_lock); in cifs_setup_ipc()
1951 scnprintf(unc, sizeof(unc), "\\\\%s\\IPC$", server->hostname); in cifs_setup_ipc()
1952 spin_unlock(&server->srv_lock); in cifs_setup_ipc()
1955 tcon->ses = ses; in cifs_setup_ipc()
1956 tcon->ipc = true; in cifs_setup_ipc()
1957 tcon->seal = seal; in cifs_setup_ipc()
1958 rc = server->ops->tree_connect(xid, ses, unc, tcon, ctx->local_nls); in cifs_setup_ipc()
1963 tconInfoFree(tcon, netfs_trace_tcon_ref_free_ipc_fail); in cifs_setup_ipc()
1967 cifs_dbg(FYI, "IPC tcon rc=%d ipc tid=0x%x\n", rc, tcon->tid); in cifs_setup_ipc()
1969 spin_lock(&tcon->tc_lock); in cifs_setup_ipc()
1970 tcon->status = TID_GOOD; in cifs_setup_ipc()
1971 spin_unlock(&tcon->tc_lock); in cifs_setup_ipc()
1972 ses->tcon_ipc = tcon; in cifs_setup_ipc()
1983 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { in cifs_find_smb_ses()
1984 spin_lock(&ses->ses_lock); in cifs_find_smb_ses()
1985 if (ses->ses_status == SES_EXITING) { in cifs_find_smb_ses()
1986 spin_unlock(&ses->ses_lock); in cifs_find_smb_ses()
1989 spin_lock(&ses->chan_lock); in cifs_find_smb_ses()
1991 spin_unlock(&ses->chan_lock); in cifs_find_smb_ses()
1992 spin_unlock(&ses->ses_lock); in cifs_find_smb_ses()
1996 spin_unlock(&ses->chan_lock); in cifs_find_smb_ses()
1997 spin_unlock(&ses->ses_lock); in cifs_find_smb_ses()
2007 struct TCP_Server_Info *server = ses->server; in __cifs_put_smb_ses()
2008 struct cifs_tcon *tcon; in __cifs_put_smb_ses() local
2015 spin_lock(&ses->ses_lock); in __cifs_put_smb_ses()
2017 __func__, ses->Suid, ses->ses_count, ses->ses_status, in __cifs_put_smb_ses()
2018 ses->tcon_ipc ? ses->tcon_ipc->tree_name : "none"); in __cifs_put_smb_ses()
2019 if (ses->ses_status == SES_EXITING || --ses->ses_count > 0) { in __cifs_put_smb_ses()
2020 spin_unlock(&ses->ses_lock); in __cifs_put_smb_ses()
2025 WARN_ON(ses->ses_count < 0); in __cifs_put_smb_ses()
2027 spin_lock(&ses->chan_lock); in __cifs_put_smb_ses()
2029 spin_unlock(&ses->chan_lock); in __cifs_put_smb_ses()
2031 do_logoff = ses->ses_status == SES_GOOD && server->ops->logoff; in __cifs_put_smb_ses()
2032 ses->ses_status = SES_EXITING; in __cifs_put_smb_ses()
2033 tcon = ses->tcon_ipc; in __cifs_put_smb_ses()
2034 ses->tcon_ipc = NULL; in __cifs_put_smb_ses()
2035 spin_unlock(&ses->ses_lock); in __cifs_put_smb_ses()
2043 * files on session close, as specified in MS-SMB2 3.3.5.6 Receiving an in __cifs_put_smb_ses()
2046 tconInfoFree(tcon, netfs_trace_tcon_ref_free_ipc); in __cifs_put_smb_ses()
2049 rc = server->ops->logoff(xid, ses); in __cifs_put_smb_ses()
2056 list_del_init(&ses->smb_ses_list); in __cifs_put_smb_ses()
2060 for (i = 1; i < ses->chan_count; i++) { in __cifs_put_smb_ses()
2061 if (ses->chans[i].iface) { in __cifs_put_smb_ses()
2062 kref_put(&ses->chans[i].iface->refcount, release_iface); in __cifs_put_smb_ses()
2063 ses->chans[i].iface = NULL; in __cifs_put_smb_ses()
2065 cifs_put_tcp_session(ses->chans[i].server, 0); in __cifs_put_smb_ses()
2066 ses->chans[i].server = NULL; in __cifs_put_smb_ses()
2069 /* we now account for primary channel in iface->refcount */ in __cifs_put_smb_ses()
2070 if (ses->chans[0].iface) { in __cifs_put_smb_ses()
2071 kref_put(&ses->chans[0].iface->refcount, release_iface); in __cifs_put_smb_ses()
2072 ses->chans[0].server = NULL; in __cifs_put_smb_ses()
2094 struct TCP_Server_Info *server = ses->server; in cifs_set_cifscreds()
2101 return -ENOMEM; in cifs_set_cifscreds()
2104 switch (server->dstaddr.ss_family) { in cifs_set_cifscreds()
2106 sa = (struct sockaddr_in *)&server->dstaddr; in cifs_set_cifscreds()
2107 sprintf(desc, "cifs:a:%pI4", &sa->sin_addr.s_addr); in cifs_set_cifscreds()
2110 sa6 = (struct sockaddr_in6 *)&server->dstaddr; in cifs_set_cifscreds()
2111 sprintf(desc, "cifs:a:%pI6c", &sa6->sin6_addr.s6_addr); in cifs_set_cifscreds()
2115 server->dstaddr.ss_family); in cifs_set_cifscreds()
2116 rc = -EINVAL; in cifs_set_cifscreds()
2123 if (!ses->domainName) { in cifs_set_cifscreds()
2130 sprintf(desc, "cifs:d:%s", ses->domainName); in cifs_set_cifscreds()
2140 down_read(&key->sem); in cifs_set_cifscreds()
2143 rc = upayload ? PTR_ERR(upayload) : -EINVAL; in cifs_set_cifscreds()
2148 payload = upayload->data; in cifs_set_cifscreds()
2149 delim = strnchr(payload, upayload->datalen, ':'); in cifs_set_cifscreds()
2153 upayload->datalen); in cifs_set_cifscreds()
2154 rc = -EINVAL; in cifs_set_cifscreds()
2158 len = delim - payload; in cifs_set_cifscreds()
2162 rc = -EINVAL; in cifs_set_cifscreds()
2166 ctx->username = kstrndup(payload, len, GFP_KERNEL); in cifs_set_cifscreds()
2167 if (!ctx->username) { in cifs_set_cifscreds()
2170 rc = -ENOMEM; in cifs_set_cifscreds()
2173 cifs_dbg(FYI, "%s: username=%s\n", __func__, ctx->username); in cifs_set_cifscreds()
2175 len = key->datalen - (len + 1); in cifs_set_cifscreds()
2178 rc = -EINVAL; in cifs_set_cifscreds()
2179 kfree(ctx->username); in cifs_set_cifscreds()
2180 ctx->username = NULL; in cifs_set_cifscreds()
2186 ctx->password = kstrndup(delim, len, GFP_KERNEL); in cifs_set_cifscreds()
2187 if (!ctx->password) { in cifs_set_cifscreds()
2190 rc = -ENOMEM; in cifs_set_cifscreds()
2191 kfree(ctx->username); in cifs_set_cifscreds()
2192 ctx->username = NULL; in cifs_set_cifscreds()
2200 if (is_domain && ses->domainName) { in cifs_set_cifscreds()
2201 ctx->domainname = kstrdup(ses->domainName, GFP_KERNEL); in cifs_set_cifscreds()
2202 if (!ctx->domainname) { in cifs_set_cifscreds()
2205 rc = -ENOMEM; in cifs_set_cifscreds()
2206 kfree(ctx->username); in cifs_set_cifscreds()
2207 ctx->username = NULL; in cifs_set_cifscreds()
2208 kfree_sensitive(ctx->password); in cifs_set_cifscreds()
2209 /* no need to free ctx->password2 since not allocated in this path */ in cifs_set_cifscreds()
2210 ctx->password = NULL; in cifs_set_cifscreds()
2215 strscpy(ctx->workstation_name, ses->workstation_name, sizeof(ctx->workstation_name)); in cifs_set_cifscreds()
2218 up_read(&key->sem); in cifs_set_cifscreds()
2230 return -ENOSYS; in cifs_set_cifscreds()
2235 * cifs_get_smb_ses - get a session matching @ctx data from @server
2249 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; in cifs_get_smb_ses()
2250 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; in cifs_get_smb_ses()
2257 ses->ses_status); in cifs_get_smb_ses()
2259 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2261 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2264 mutex_lock(&ses->session_mutex); in cifs_get_smb_ses()
2267 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2268 /* problem -- put our ses reference */ in cifs_get_smb_ses()
2275 ctx->local_nls); in cifs_get_smb_ses()
2277 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2278 /* problem -- put our reference */ in cifs_get_smb_ses()
2283 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2285 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2287 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2295 rc = -ENOMEM; in cifs_get_smb_ses()
2303 ses->server = server; in cifs_get_smb_ses()
2304 if (server->dstaddr.ss_family == AF_INET6) in cifs_get_smb_ses()
2305 sprintf(ses->ip_addr, "%pI6", &addr6->sin6_addr); in cifs_get_smb_ses()
2307 sprintf(ses->ip_addr, "%pI4", &addr->sin_addr); in cifs_get_smb_ses()
2309 if (ctx->username) { in cifs_get_smb_ses()
2310 ses->user_name = kstrdup(ctx->username, GFP_KERNEL); in cifs_get_smb_ses()
2311 if (!ses->user_name) in cifs_get_smb_ses()
2315 /* ctx->password freed at unmount */ in cifs_get_smb_ses()
2316 if (ctx->password) { in cifs_get_smb_ses()
2317 ses->password = kstrdup(ctx->password, GFP_KERNEL); in cifs_get_smb_ses()
2318 if (!ses->password) in cifs_get_smb_ses()
2321 /* ctx->password freed at unmount */ in cifs_get_smb_ses()
2322 if (ctx->password2) { in cifs_get_smb_ses()
2323 ses->password2 = kstrdup(ctx->password2, GFP_KERNEL); in cifs_get_smb_ses()
2324 if (!ses->password2) in cifs_get_smb_ses()
2327 if (ctx->domainname) { in cifs_get_smb_ses()
2328 ses->domainName = kstrdup(ctx->domainname, GFP_KERNEL); in cifs_get_smb_ses()
2329 if (!ses->domainName) in cifs_get_smb_ses()
2333 strscpy(ses->workstation_name, ctx->workstation_name, sizeof(ses->workstation_name)); in cifs_get_smb_ses()
2335 if (ctx->domainauto) in cifs_get_smb_ses()
2336 ses->domainAuto = ctx->domainauto; in cifs_get_smb_ses()
2337 ses->cred_uid = ctx->cred_uid; in cifs_get_smb_ses()
2338 ses->linux_uid = ctx->linux_uid; in cifs_get_smb_ses()
2340 ses->sectype = ctx->sectype; in cifs_get_smb_ses()
2341 ses->sign = ctx->sign; in cifs_get_smb_ses()
2342 ses->local_nls = load_nls(ctx->local_nls->charset); in cifs_get_smb_ses()
2344 /* add server as first channel */ in cifs_get_smb_ses()
2345 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2346 ses->chans[0].server = server; in cifs_get_smb_ses()
2347 ses->chan_count = 1; in cifs_get_smb_ses()
2348 ses->chan_max = ctx->multichannel ? ctx->max_channels:1; in cifs_get_smb_ses()
2349 ses->chans_need_reconnect = 1; in cifs_get_smb_ses()
2350 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2352 mutex_lock(&ses->session_mutex); in cifs_get_smb_ses()
2355 rc = cifs_setup_session(xid, ses, server, ctx->local_nls); in cifs_get_smb_ses()
2356 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2358 /* each channel uses a different signing key */ in cifs_get_smb_ses()
2359 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2360 memcpy(ses->chans[0].signkey, ses->smb3signingkey, in cifs_get_smb_ses()
2361 sizeof(ses->smb3signingkey)); in cifs_get_smb_ses()
2362 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2368 * success, put it on the list and add it as first channel in cifs_get_smb_ses()
2373 ses->dfs_root_ses = ctx->dfs_root_ses; in cifs_get_smb_ses()
2374 list_add(&ses->smb_ses_list, &server->smb_ses_list); in cifs_get_smb_ses()
2390 static int match_tcon(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) in match_tcon() argument
2392 struct TCP_Server_Info *server = tcon->ses->server; in match_tcon()
2394 if (tcon->status == TID_EXITING) in match_tcon()
2397 if (tcon->origin_fullpath) { in match_tcon()
2398 if (!ctx->source || in match_tcon()
2399 !dfs_src_pathname_equal(ctx->source, in match_tcon()
2400 tcon->origin_fullpath)) in match_tcon()
2402 } else if (!server->leaf_fullpath && in match_tcon()
2403 strncmp(tcon->tree_name, ctx->UNC, MAX_TREE_SIZE)) { in match_tcon()
2406 if (tcon->seal != ctx->seal) in match_tcon()
2408 if (tcon->snapshot_time != ctx->snapshot_time) in match_tcon()
2410 if (tcon->handle_timeout != ctx->handle_timeout) in match_tcon()
2412 if (tcon->no_lease != ctx->no_lease) in match_tcon()
2414 if (tcon->nodelete != ctx->nodelete) in match_tcon()
2422 struct cifs_tcon *tcon; in cifs_find_tcon() local
2425 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { in cifs_find_tcon()
2426 spin_lock(&tcon->tc_lock); in cifs_find_tcon()
2427 if (!match_tcon(tcon, ctx)) { in cifs_find_tcon()
2428 spin_unlock(&tcon->tc_lock); in cifs_find_tcon()
2431 ++tcon->tc_count; in cifs_find_tcon()
2432 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count, in cifs_find_tcon()
2434 spin_unlock(&tcon->tc_lock); in cifs_find_tcon()
2436 return tcon; in cifs_find_tcon()
2443 cifs_put_tcon(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace) in cifs_put_tcon() argument
2450 * IPC tcon share the lifetime of their session and are in cifs_put_tcon()
2453 if (tcon == NULL || tcon->ipc) in cifs_put_tcon()
2456 ses = tcon->ses; in cifs_put_tcon()
2457 cifs_dbg(FYI, "%s: tc_count=%d\n", __func__, tcon->tc_count); in cifs_put_tcon()
2459 spin_lock(&tcon->tc_lock); in cifs_put_tcon()
2460 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count - 1, trace); in cifs_put_tcon()
2461 if (--tcon->tc_count > 0) { in cifs_put_tcon()
2462 spin_unlock(&tcon->tc_lock); in cifs_put_tcon()
2468 WARN_ON(tcon->tc_count < 0); in cifs_put_tcon()
2470 list_del_init(&tcon->tcon_list); in cifs_put_tcon()
2471 tcon->status = TID_EXITING; in cifs_put_tcon()
2473 list_replace_init(&tcon->dfs_ses_list, &ses_list); in cifs_put_tcon()
2475 spin_unlock(&tcon->tc_lock); in cifs_put_tcon()
2479 cancel_delayed_work_sync(&tcon->query_interfaces); in cifs_put_tcon()
2481 cancel_delayed_work_sync(&tcon->dfs_cache_work); in cifs_put_tcon()
2484 if (tcon->use_witness) { in cifs_put_tcon()
2487 rc = cifs_swn_unregister(tcon); in cifs_put_tcon()
2495 if (ses->server->ops->tree_disconnect) in cifs_put_tcon()
2496 ses->server->ops->tree_disconnect(xid, tcon); in cifs_put_tcon()
2499 cifs_fscache_release_super_cookie(tcon); in cifs_put_tcon()
2500 tconInfoFree(tcon, netfs_trace_tcon_ref_free); in cifs_put_tcon()
2508 * cifs_get_tcon - get a tcon matching @ctx data from @ses
2512 * - tcon refcount is the number of mount points using the tcon.
2513 * - ses refcount is the number of tcon using the session.
2521 * a) a new tcon already allocated with refcount=1 (1 mount point) and
2522 * its session refcount incremented (1 new tcon). This +1 was
2525 * b) an existing tcon with refcount+1 (add a mount point to it) and
2526 * identical ses refcount (no new tcon). Because of (1) we need to
2532 struct cifs_tcon *tcon; in cifs_get_tcon() local
2536 tcon = cifs_find_tcon(ses, ctx); in cifs_get_tcon()
2537 if (tcon) { in cifs_get_tcon()
2539 * tcon has refcount already incremented but we need to in cifs_get_tcon()
2544 return tcon; in cifs_get_tcon()
2547 if (!ses->server->ops->tree_connect) { in cifs_get_tcon()
2548 rc = -ENOSYS; in cifs_get_tcon()
2552 if (ses->server->dialect >= SMB20_PROT_ID && in cifs_get_tcon()
2553 (ses->server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING)) in cifs_get_tcon()
2554 nohandlecache = ctx->nohandlecache; in cifs_get_tcon()
2557 tcon = tcon_info_alloc(!nohandlecache, netfs_trace_tcon_ref_new); in cifs_get_tcon()
2558 if (tcon == NULL) { in cifs_get_tcon()
2559 rc = -ENOMEM; in cifs_get_tcon()
2562 tcon->nohandlecache = nohandlecache; in cifs_get_tcon()
2564 if (ctx->snapshot_time) { in cifs_get_tcon()
2565 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2568 rc = -EOPNOTSUPP; in cifs_get_tcon()
2571 tcon->snapshot_time = ctx->snapshot_time; in cifs_get_tcon()
2574 if (ctx->handle_timeout) { in cifs_get_tcon()
2575 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2578 rc = -EOPNOTSUPP; in cifs_get_tcon()
2581 tcon->handle_timeout = ctx->handle_timeout; in cifs_get_tcon()
2584 tcon->ses = ses; in cifs_get_tcon()
2585 if (ctx->password) { in cifs_get_tcon()
2586 tcon->password = kstrdup(ctx->password, GFP_KERNEL); in cifs_get_tcon()
2587 if (!tcon->password) { in cifs_get_tcon()
2588 rc = -ENOMEM; in cifs_get_tcon()
2593 if (ctx->seal) { in cifs_get_tcon()
2594 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2597 rc = -EOPNOTSUPP; in cifs_get_tcon()
2599 } else if (tcon->ses->server->capabilities & in cifs_get_tcon()
2601 tcon->seal = true; in cifs_get_tcon()
2604 rc = -EOPNOTSUPP; in cifs_get_tcon()
2609 if (ctx->linux_ext) { in cifs_get_tcon()
2610 if (ses->server->posix_ext_supported) { in cifs_get_tcon()
2611 tcon->posix_extensions = true; in cifs_get_tcon()
2613 } else if ((ses->server->vals->protocol_id == SMB311_PROT_ID) || in cifs_get_tcon()
2614 (strcmp(ses->server->vals->version_string, in cifs_get_tcon()
2616 (strcmp(ses->server->vals->version_string, in cifs_get_tcon()
2619 rc = -EOPNOTSUPP; in cifs_get_tcon()
2621 } else if (ses->server->vals->protocol_id == SMB10_PROT_ID) in cifs_get_tcon()
2626 rc = -EOPNOTSUPP; in cifs_get_tcon()
2631 rc = -EOPNOTSUPP; in cifs_get_tcon()
2637 rc = ses->server->ops->tree_connect(xid, ses, ctx->UNC, tcon, in cifs_get_tcon()
2638 ctx->local_nls); in cifs_get_tcon()
2640 cifs_dbg(FYI, "Tcon rc = %d\n", rc); in cifs_get_tcon()
2644 tcon->use_persistent = false; in cifs_get_tcon()
2646 if (ctx->persistent) { in cifs_get_tcon()
2647 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2650 rc = -EOPNOTSUPP; in cifs_get_tcon()
2652 } else if (ses->server->capabilities & in cifs_get_tcon()
2654 tcon->use_persistent = true; in cifs_get_tcon()
2658 rc = -EOPNOTSUPP; in cifs_get_tcon()
2661 } else if ((tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) in cifs_get_tcon()
2662 && (ses->server->capabilities & SMB2_GLOBAL_CAP_PERSISTENT_HANDLES) in cifs_get_tcon()
2663 && (ctx->nopersistent == false)) { in cifs_get_tcon()
2665 tcon->use_persistent = true; in cifs_get_tcon()
2666 } else if (ctx->resilient) { in cifs_get_tcon()
2667 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2670 rc = -EOPNOTSUPP; in cifs_get_tcon()
2673 tcon->use_resilient = true; in cifs_get_tcon()
2676 tcon->use_witness = false; in cifs_get_tcon()
2677 if (IS_ENABLED(CONFIG_CIFS_SWN_UPCALL) && ctx->witness) { in cifs_get_tcon()
2678 if (ses->server->vals->protocol_id >= SMB30_PROT_ID) { in cifs_get_tcon()
2679 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) { in cifs_get_tcon()
2684 tcon->use_witness = true; in cifs_get_tcon()
2686 rc = cifs_swn_register(tcon); in cifs_get_tcon()
2692 /* TODO: try to extend for non-cluster uses (eg multichannel) */ in cifs_get_tcon()
2694 rc = -EOPNOTSUPP; in cifs_get_tcon()
2699 rc = -EOPNOTSUPP; in cifs_get_tcon()
2705 if (tcon->share_flags & SMB2_SHAREFLAG_NO_CACHING) { in cifs_get_tcon()
2706 if (ctx->cache_ro) in cifs_get_tcon()
2708 else if (ctx->cache_rw) in cifs_get_tcon()
2712 if (ctx->no_lease) { in cifs_get_tcon()
2713 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2716 rc = -EOPNOTSUPP; in cifs_get_tcon()
2719 tcon->no_lease = ctx->no_lease; in cifs_get_tcon()
2727 tcon->retry = ctx->retry; in cifs_get_tcon()
2728 tcon->nocase = ctx->nocase; in cifs_get_tcon()
2729 tcon->broken_sparse_sup = ctx->no_sparse; in cifs_get_tcon()
2730 tcon->max_cached_dirs = ctx->max_cached_dirs; in cifs_get_tcon()
2731 tcon->nodelete = ctx->nodelete; in cifs_get_tcon()
2732 tcon->local_lease = ctx->local_lease; in cifs_get_tcon()
2733 INIT_LIST_HEAD(&tcon->pending_opens); in cifs_get_tcon()
2734 tcon->status = TID_GOOD; in cifs_get_tcon()
2736 INIT_DELAYED_WORK(&tcon->query_interfaces, in cifs_get_tcon()
2738 if (ses->server->dialect >= SMB30_PROT_ID && in cifs_get_tcon()
2739 (ses->server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL)) { in cifs_get_tcon()
2741 queue_delayed_work(cifsiod_wq, &tcon->query_interfaces, in cifs_get_tcon()
2745 INIT_DELAYED_WORK(&tcon->dfs_cache_work, dfs_cache_refresh); in cifs_get_tcon()
2748 list_add(&tcon->tcon_list, &ses->tcon_list); in cifs_get_tcon()
2751 return tcon; in cifs_get_tcon()
2754 tconInfoFree(tcon, netfs_trace_tcon_ref_free_fail); in cifs_get_tcon()
2764 if (!atomic_dec_and_test(&tlink->tl_count) || in cifs_put_tlink()
2765 test_bit(TCON_LINK_IN_TREE, &tlink->tl_flags)) { in cifs_put_tlink()
2766 tlink->tl_time = jiffies; in cifs_put_tlink()
2779 struct cifs_sb_info *new = mnt_data->cifs_sb; in compare_mount_options()
2780 unsigned int oldflags = old->mnt_cifs_flags & CIFS_MOUNT_MASK; in compare_mount_options()
2781 unsigned int newflags = new->mnt_cifs_flags & CIFS_MOUNT_MASK; in compare_mount_options()
2783 if ((sb->s_flags & CIFS_MS_MASK) != (mnt_data->flags & CIFS_MS_MASK)) in compare_mount_options()
2786 if (old->mnt_cifs_serverino_autodisabled) in compare_mount_options()
2796 if (new->ctx->wsize && new->ctx->wsize < old->ctx->wsize) in compare_mount_options()
2799 if (new->ctx->rsize && new->ctx->rsize < old->ctx->rsize) in compare_mount_options()
2802 if (!uid_eq(old->ctx->linux_uid, new->ctx->linux_uid) || in compare_mount_options()
2803 !gid_eq(old->ctx->linux_gid, new->ctx->linux_gid)) in compare_mount_options()
2806 if (old->ctx->file_mode != new->ctx->file_mode || in compare_mount_options()
2807 old->ctx->dir_mode != new->ctx->dir_mode) in compare_mount_options()
2810 if (strcmp(old->local_nls->charset, new->local_nls->charset)) in compare_mount_options()
2813 if (old->ctx->acregmax != new->ctx->acregmax) in compare_mount_options()
2815 if (old->ctx->acdirmax != new->ctx->acdirmax) in compare_mount_options()
2817 if (old->ctx->closetimeo != new->ctx->closetimeo) in compare_mount_options()
2819 if (old->ctx->reparse_type != new->ctx->reparse_type) in compare_mount_options()
2826 struct cifs_tcon *tcon, in match_prepath() argument
2829 struct smb3_fs_context *ctx = mnt_data->ctx; in match_prepath()
2831 struct cifs_sb_info *new = mnt_data->cifs_sb; in match_prepath()
2832 bool old_set = (old->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH) && in match_prepath()
2833 old->prepath; in match_prepath()
2834 bool new_set = (new->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH) && in match_prepath()
2835 new->prepath; in match_prepath()
2837 if (tcon->origin_fullpath && in match_prepath()
2838 dfs_src_pathname_equal(tcon->origin_fullpath, ctx->source)) in match_prepath()
2841 if (old_set && new_set && !strcmp(new->prepath, old->prepath)) in match_prepath()
2857 struct cifs_tcon *tcon; in cifs_match_super() local
2865 if (CIFS_MOUNT_SHUTDOWN & cifs_sb->mnt_cifs_flags) { in cifs_match_super()
2877 tcon = tlink_tcon(tlink); in cifs_match_super()
2878 ses = tcon->ses; in cifs_match_super()
2879 tcp_srv = ses->server; in cifs_match_super()
2881 ctx = mnt_data->ctx; in cifs_match_super()
2883 spin_lock(&tcp_srv->srv_lock); in cifs_match_super()
2884 spin_lock(&ses->ses_lock); in cifs_match_super()
2885 spin_lock(&ses->chan_lock); in cifs_match_super()
2886 spin_lock(&tcon->tc_lock); in cifs_match_super()
2889 !match_tcon(tcon, ctx) || in cifs_match_super()
2890 !match_prepath(sb, tcon, mnt_data)) { in cifs_match_super()
2897 spin_unlock(&tcon->tc_lock); in cifs_match_super()
2898 spin_unlock(&ses->chan_lock); in cifs_match_super()
2899 spin_unlock(&ses->ses_lock); in cifs_match_super()
2900 spin_unlock(&tcp_srv->srv_lock); in cifs_match_super()
2914 struct sock *sk = sock->sk; in cifs_reclassify_socket4()
2917 sock_lock_init_class_and_name(sk, "slock-AF_INET-CIFS", in cifs_reclassify_socket4()
2918 &cifs_slock_key[0], "sk_lock-AF_INET-CIFS", &cifs_key[0]); in cifs_reclassify_socket4()
2924 struct sock *sk = sock->sk; in cifs_reclassify_socket6()
2927 sock_lock_init_class_and_name(sk, "slock-AF_INET6-CIFS", in cifs_reclassify_socket6()
2928 &cifs_slock_key[1], "sk_lock-AF_INET6-CIFS", &cifs_key[1]); in cifs_reclassify_socket6()
2961 if (server->srcaddr.ss_family != AF_UNSPEC) { in bind_socket()
2963 struct socket *socket = server->ssocket; in bind_socket()
2966 (struct sockaddr *) &server->srcaddr, in bind_socket()
2967 sizeof(server->srcaddr)); in bind_socket()
2972 saddr4 = (struct sockaddr_in *)&server->srcaddr; in bind_socket()
2973 saddr6 = (struct sockaddr_in6 *)&server->srcaddr; in bind_socket()
2974 if (saddr6->sin6_family == AF_INET6) in bind_socket()
2976 &saddr6->sin6_addr, rc); in bind_socket()
2979 &saddr4->sin_addr.s_addr, rc); in bind_socket()
2991 * negprot - BB check reconnection in case where second in ip_rfc1001_connect()
3000 if (server->server_RFC1001_name[0] != 0) in ip_rfc1001_connect()
3002 server->server_RFC1001_name, in ip_rfc1001_connect()
3012 if (server->workstation_RFC1001_name[0] != 0) in ip_rfc1001_connect()
3014 server->workstation_RFC1001_name, in ip_rfc1001_connect()
3025 len = sizeof(req) - offsetof(struct rfc1002_session_packet, trailer.session_req); in ip_rfc1001_connect()
3027 smb_buf->smb_buf_length = cpu_to_be32((RFC1002_SESSION_REQUEST << 24) | len); in ip_rfc1001_connect()
3049 saddr = (struct sockaddr *) &server->dstaddr; in generic_ip_connect()
3051 if (server->dstaddr.ss_family == AF_INET6) { in generic_ip_connect()
3052 struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&server->dstaddr; in generic_ip_connect()
3054 sport = ipv6->sin6_port; in generic_ip_connect()
3057 cifs_dbg(FYI, "%s: connecting to [%pI6]:%d\n", __func__, &ipv6->sin6_addr, in generic_ip_connect()
3060 struct sockaddr_in *ipv4 = (struct sockaddr_in *)&server->dstaddr; in generic_ip_connect()
3062 sport = ipv4->sin_port; in generic_ip_connect()
3065 cifs_dbg(FYI, "%s: connecting to %pI4:%d\n", __func__, &ipv4->sin_addr, in generic_ip_connect()
3069 if (server->ssocket) { in generic_ip_connect()
3070 socket = server->ssocket; in generic_ip_connect()
3076 IPPROTO_TCP, &server->ssocket, 1); in generic_ip_connect()
3082 sk = server->ssocket->sk; in generic_ip_connect()
3083 __netns_tracker_free(net, &sk->ns_tracker, false); in generic_ip_connect()
3084 sk->sk_net_refcnt = 1; in generic_ip_connect()
3085 get_net_track(net, &sk->ns_tracker, GFP_KERNEL); in generic_ip_connect()
3090 socket = server->ssocket; in generic_ip_connect()
3091 socket->sk->sk_allocation = GFP_NOFS; in generic_ip_connect()
3092 socket->sk->sk_use_task_frag = false; in generic_ip_connect()
3108 socket->sk->sk_rcvtimeo = 7 * HZ; in generic_ip_connect()
3109 socket->sk->sk_sndtimeo = 5 * HZ; in generic_ip_connect()
3112 if (server->noautotune) { in generic_ip_connect()
3113 if (socket->sk->sk_sndbuf < (200 * 1024)) in generic_ip_connect()
3114 socket->sk->sk_sndbuf = 200 * 1024; in generic_ip_connect()
3115 if (socket->sk->sk_rcvbuf < (140 * 1024)) in generic_ip_connect()
3116 socket->sk->sk_rcvbuf = 140 * 1024; in generic_ip_connect()
3119 if (server->tcp_nodelay) in generic_ip_connect()
3120 tcp_sock_set_nodelay(socket->sk); in generic_ip_connect()
3123 socket->sk->sk_sndbuf, in generic_ip_connect()
3124 socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo); in generic_ip_connect()
3127 server->noblockcnt ? O_NONBLOCK : 0); in generic_ip_connect()
3131 * reconnect failover - if possible. in generic_ip_connect()
3133 if (server->noblockcnt && rc == -EINPROGRESS) in generic_ip_connect()
3137 trace_smb3_connect_err(server->hostname, server->conn_id, &server->dstaddr, rc); in generic_ip_connect()
3139 server->ssocket = NULL; in generic_ip_connect()
3142 trace_smb3_connect_done(server->hostname, server->conn_id, &server->dstaddr); in generic_ip_connect()
3153 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; in ip_connect()
3154 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; in ip_connect()
3156 if (server->dstaddr.ss_family == AF_INET6) in ip_connect()
3157 sport = &addr6->sin6_port; in ip_connect()
3159 sport = &addr->sin_port; in ip_connect()
3179 void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, in reset_cifs_unix_caps() argument
3187 * Perhaps we could add a backpointer to array of sb from tcon in reset_cifs_unix_caps()
3189 * sb as NFS - then we only have one backpointer to sb. in reset_cifs_unix_caps()
3193 __u64 saved_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); in reset_cifs_unix_caps()
3195 if (ctx && ctx->no_linux_ext) { in reset_cifs_unix_caps()
3196 tcon->fsUnixInfo.Capability = 0; in reset_cifs_unix_caps()
3197 tcon->unix_ext = 0; /* Unix Extensions disabled */ in reset_cifs_unix_caps()
3201 tcon->unix_ext = 1; /* Unix Extensions supported */ in reset_cifs_unix_caps()
3203 if (!tcon->unix_ext) { in reset_cifs_unix_caps()
3208 if (!CIFSSMBQFSUnixInfo(xid, tcon)) { in reset_cifs_unix_caps()
3209 __u64 cap = le64_to_cpu(tcon->fsUnixInfo.Capability); in reset_cifs_unix_caps()
3234 cifs_dbg(VFS, "per-share encryption not supported yet\n"); in reset_cifs_unix_caps()
3237 if (ctx && ctx->no_psx_acl) in reset_cifs_unix_caps()
3242 cifs_sb->mnt_cifs_flags |= in reset_cifs_unix_caps()
3246 if (ctx && ctx->posix_paths == 0) in reset_cifs_unix_caps()
3251 cifs_sb->mnt_cifs_flags |= in reset_cifs_unix_caps()
3276 if (CIFSSMBSetFSUnixInfo(xid, tcon, cap)) { in reset_cifs_unix_caps()
3289 struct smb3_fs_context *ctx = cifs_sb->ctx; in cifs_setup_cifs_sb()
3291 INIT_DELAYED_WORK(&cifs_sb->prune_tlinks, cifs_prune_tlinks); in cifs_setup_cifs_sb()
3293 spin_lock_init(&cifs_sb->tlink_tree_lock); in cifs_setup_cifs_sb()
3294 cifs_sb->tlink_tree = RB_ROOT; in cifs_setup_cifs_sb()
3297 ctx->file_mode, ctx->dir_mode); in cifs_setup_cifs_sb()
3300 if (ctx->iocharset == NULL) { in cifs_setup_cifs_sb()
3302 cifs_sb->local_nls = load_nls_default(); in cifs_setup_cifs_sb()
3304 cifs_sb->local_nls = load_nls(ctx->iocharset); in cifs_setup_cifs_sb()
3305 if (cifs_sb->local_nls == NULL) { in cifs_setup_cifs_sb()
3307 ctx->iocharset); in cifs_setup_cifs_sb()
3308 return -ELIBACC; in cifs_setup_cifs_sb()
3311 ctx->local_nls = cifs_sb->local_nls; in cifs_setup_cifs_sb()
3315 if (ctx->direct_io) in cifs_setup_cifs_sb()
3317 if (ctx->cache_ro) { in cifs_setup_cifs_sb()
3319 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RO_CACHE; in cifs_setup_cifs_sb()
3320 } else if (ctx->cache_rw) { in cifs_setup_cifs_sb()
3322 cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_RO_CACHE | in cifs_setup_cifs_sb()
3326 if ((ctx->cifs_acl) && (ctx->dynperm)) in cifs_setup_cifs_sb()
3329 if (ctx->prepath) { in cifs_setup_cifs_sb()
3330 cifs_sb->prepath = kstrdup(ctx->prepath, GFP_KERNEL); in cifs_setup_cifs_sb()
3331 if (cifs_sb->prepath == NULL) in cifs_setup_cifs_sb()
3332 return -ENOMEM; in cifs_setup_cifs_sb()
3333 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH; in cifs_setup_cifs_sb()
3344 if (mnt_ctx->tcon) in cifs_mount_put_conns()
3345 cifs_put_tcon(mnt_ctx->tcon, netfs_trace_tcon_ref_put_mnt_ctx); in cifs_mount_put_conns()
3346 else if (mnt_ctx->ses) in cifs_mount_put_conns()
3347 cifs_put_smb_ses(mnt_ctx->ses); in cifs_mount_put_conns()
3348 else if (mnt_ctx->server) in cifs_mount_put_conns()
3349 cifs_put_tcp_session(mnt_ctx->server, 0); in cifs_mount_put_conns()
3350 mnt_ctx->ses = NULL; in cifs_mount_put_conns()
3351 mnt_ctx->tcon = NULL; in cifs_mount_put_conns()
3352 mnt_ctx->server = NULL; in cifs_mount_put_conns()
3353 mnt_ctx->cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_POSIX_PATHS; in cifs_mount_put_conns()
3354 free_xid(mnt_ctx->xid); in cifs_mount_put_conns()
3367 if (WARN_ON_ONCE(!mnt_ctx || !mnt_ctx->fs_ctx)) { in cifs_mount_get_session()
3368 rc = -EINVAL; in cifs_mount_get_session()
3371 ctx = mnt_ctx->fs_ctx; in cifs_mount_get_session()
3389 if ((ctx->persistent == true) && (!(ses->server->capabilities & in cifs_mount_get_session()
3392 rc = -EOPNOTSUPP; in cifs_mount_get_session()
3396 mnt_ctx->xid = xid; in cifs_mount_get_session()
3397 mnt_ctx->server = server; in cifs_mount_get_session()
3398 mnt_ctx->ses = ses; in cifs_mount_get_session()
3399 mnt_ctx->tcon = NULL; in cifs_mount_get_session()
3409 struct cifs_tcon *tcon = NULL; in cifs_mount_get_tcon() local
3412 if (WARN_ON_ONCE(!mnt_ctx || !mnt_ctx->server || !mnt_ctx->ses || !mnt_ctx->fs_ctx || in cifs_mount_get_tcon()
3413 !mnt_ctx->cifs_sb)) { in cifs_mount_get_tcon()
3414 rc = -EINVAL; in cifs_mount_get_tcon()
3417 server = mnt_ctx->server; in cifs_mount_get_tcon()
3418 ctx = mnt_ctx->fs_ctx; in cifs_mount_get_tcon()
3419 cifs_sb = mnt_ctx->cifs_sb; in cifs_mount_get_tcon()
3421 /* search for existing tcon to this server share */ in cifs_mount_get_tcon()
3422 tcon = cifs_get_tcon(mnt_ctx->ses, ctx); in cifs_mount_get_tcon()
3423 if (IS_ERR(tcon)) { in cifs_mount_get_tcon()
3424 rc = PTR_ERR(tcon); in cifs_mount_get_tcon()
3425 tcon = NULL; in cifs_mount_get_tcon()
3430 if (tcon->posix_extensions) in cifs_mount_get_tcon()
3431 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_POSIX_PATHS; in cifs_mount_get_tcon()
3435 if (cap_unix(tcon->ses)) { in cifs_mount_get_tcon()
3440 reset_cifs_unix_caps(mnt_ctx->xid, tcon, cifs_sb, ctx); in cifs_mount_get_tcon()
3441 spin_lock(&tcon->ses->server->srv_lock); in cifs_mount_get_tcon()
3442 if ((tcon->ses->server->tcpStatus == CifsNeedReconnect) && in cifs_mount_get_tcon()
3443 (le64_to_cpu(tcon->fsUnixInfo.Capability) & in cifs_mount_get_tcon()
3445 spin_unlock(&tcon->ses->server->srv_lock); in cifs_mount_get_tcon()
3446 rc = -EACCES; in cifs_mount_get_tcon()
3449 spin_unlock(&tcon->ses->server->srv_lock); in cifs_mount_get_tcon()
3452 tcon->unix_ext = 0; /* server does not support them */ in cifs_mount_get_tcon()
3454 /* do not care if a following call succeed - informational */ in cifs_mount_get_tcon()
3455 if (!tcon->pipe && server->ops->qfs_tcon) { in cifs_mount_get_tcon()
3456 server->ops->qfs_tcon(mnt_ctx->xid, tcon, cifs_sb); in cifs_mount_get_tcon()
3457 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RO_CACHE) { in cifs_mount_get_tcon()
3458 if (tcon->fsDevInfo.DeviceCharacteristics & in cifs_mount_get_tcon()
3461 else if ((cifs_sb->mnt_cifs_flags & in cifs_mount_get_tcon()
3473 if ((cifs_sb->ctx->wsize == 0) || in cifs_mount_get_tcon()
3474 (cifs_sb->ctx->wsize > server->ops->negotiate_wsize(tcon, ctx))) { in cifs_mount_get_tcon()
3475 cifs_sb->ctx->wsize = in cifs_mount_get_tcon()
3476 round_down(server->ops->negotiate_wsize(tcon, ctx), PAGE_SIZE); in cifs_mount_get_tcon()
3481 if (cifs_sb->ctx->wsize == 0) { in cifs_mount_get_tcon()
3482 cifs_sb->ctx->wsize = PAGE_SIZE; in cifs_mount_get_tcon()
3486 if ((cifs_sb->ctx->rsize == 0) || in cifs_mount_get_tcon()
3487 (cifs_sb->ctx->rsize > server->ops->negotiate_rsize(tcon, ctx))) in cifs_mount_get_tcon()
3488 cifs_sb->ctx->rsize = server->ops->negotiate_rsize(tcon, ctx); in cifs_mount_get_tcon()
3495 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE) in cifs_mount_get_tcon()
3496 cifs_fscache_get_super_cookie(tcon); in cifs_mount_get_tcon()
3499 mnt_ctx->tcon = tcon; in cifs_mount_get_tcon()
3504 struct cifs_tcon *tcon) in mount_setup_tlink() argument
3508 /* hang the tcon off of the superblock */ in mount_setup_tlink()
3511 return -ENOMEM; in mount_setup_tlink()
3513 tlink->tl_uid = ses->linux_uid; in mount_setup_tlink()
3514 tlink->tl_tcon = tcon; in mount_setup_tlink()
3515 tlink->tl_time = jiffies; in mount_setup_tlink()
3516 set_bit(TCON_LINK_MASTER, &tlink->tl_flags); in mount_setup_tlink()
3517 set_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); in mount_setup_tlink()
3519 cifs_sb->master_tlink = tlink; in mount_setup_tlink()
3520 spin_lock(&cifs_sb->tlink_tree_lock); in mount_setup_tlink()
3521 tlink_rb_insert(&cifs_sb->tlink_tree, tlink); in mount_setup_tlink()
3522 spin_unlock(&cifs_sb->tlink_tree_lock); in mount_setup_tlink()
3524 queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks, in mount_setup_tlink()
3532 struct cifs_tcon *tcon, in cifs_are_all_path_components_accessible() argument
3545 rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, ""); in cifs_are_all_path_components_accessible()
3564 * temporarily null-terminate the path at the end of in cifs_are_all_path_components_accessible()
3569 rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, in cifs_are_all_path_components_accessible()
3579 * Return -EREMOTE if it is, otherwise 0 or -errno.
3584 struct cifs_sb_info *cifs_sb = mnt_ctx->cifs_sb; in cifs_is_path_remote()
3585 struct TCP_Server_Info *server = mnt_ctx->server; in cifs_is_path_remote()
3586 unsigned int xid = mnt_ctx->xid; in cifs_is_path_remote()
3587 struct cifs_tcon *tcon = mnt_ctx->tcon; in cifs_is_path_remote() local
3588 struct smb3_fs_context *ctx = mnt_ctx->fs_ctx; in cifs_is_path_remote()
3591 if (!server->ops->is_path_accessible) in cifs_is_path_remote()
3592 return -EOPNOTSUPP; in cifs_is_path_remote()
3595 * cifs_build_path_to_root works only when we have a valid tcon in cifs_is_path_remote()
3597 full_path = cifs_build_path_to_root(ctx, cifs_sb, tcon, in cifs_is_path_remote()
3598 tcon->Flags & SMB_SHARE_IS_IN_DFS); in cifs_is_path_remote()
3600 return -ENOMEM; in cifs_is_path_remote()
3604 rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, in cifs_is_path_remote()
3606 if (rc != 0 && rc != -EREMOTE) in cifs_is_path_remote()
3609 if (rc != -EREMOTE) { in cifs_is_path_remote()
3610 rc = cifs_are_all_path_components_accessible(server, xid, tcon, in cifs_is_path_remote()
3611 cifs_sb, full_path, tcon->Flags & SMB_SHARE_IS_IN_DFS); in cifs_is_path_remote()
3614 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH; in cifs_is_path_remote()
3633 if (!ctx->dfs_conn) in cifs_mount()
3645 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH; in cifs_mount()
3646 kfree(cifs_sb->prepath); in cifs_mount()
3647 cifs_sb->prepath = ctx->prepath; in cifs_mount()
3648 ctx->prepath = NULL; in cifs_mount()
3652 rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon); in cifs_mount()
3680 rc = -EHOSTDOWN; in cifs_mount()
3682 rc = -EACCES; in cifs_mount()
3683 else if (WARN_ON(!mnt_ctx.tcon)) in cifs_mount()
3684 rc = -ENOENT; in cifs_mount()
3690 if (rc == -EREMOTE) in cifs_mount()
3691 rc = -EOPNOTSUPP; in cifs_mount()
3695 rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon); in cifs_mount()
3714 const char *tree, struct cifs_tcon *tcon, in CIFSTCon() argument
3727 return -EIO; in CIFSTCon()
3731 return -ENOMEM; in CIFSTCon()
3738 smb_buffer->Mid = get_next_mid(ses->server); in CIFSTCon()
3739 smb_buffer->Uid = ses->Suid; in CIFSTCon()
3743 pSMB->AndXCommand = 0xFF; in CIFSTCon()
3744 pSMB->Flags = cpu_to_le16(TCON_EXTENDED_SECINFO); in CIFSTCon()
3745 bcc_ptr = &pSMB->Password[0]; in CIFSTCon()
3747 pSMB->PasswordLength = cpu_to_le16(1); /* minimum */ in CIFSTCon()
3752 if (ses->server->sign) in CIFSTCon()
3753 smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; in CIFSTCon()
3755 if (ses->capabilities & CAP_STATUS32) in CIFSTCon()
3756 smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS; in CIFSTCon()
3758 if (ses->capabilities & CAP_DFS) in CIFSTCon()
3759 smb_buffer->Flags2 |= SMBFLG2_DFS; in CIFSTCon()
3761 if (ses->capabilities & CAP_UNICODE) { in CIFSTCon()
3762 smb_buffer->Flags2 |= SMBFLG2_UNICODE; in CIFSTCon()
3776 count = bcc_ptr - &pSMB->Password[0]; in CIFSTCon()
3777 be32_add_cpu(&pSMB->hdr.smb_buf_length, count); in CIFSTCon()
3778 pSMB->ByteCount = cpu_to_le16(count); in CIFSTCon()
3787 tcon->tid = smb_buffer_response->Tid; in CIFSTCon()
3790 length = strnlen(bcc_ptr, bytes_left - 2); in CIFSTCon()
3791 if (smb_buffer->Flags2 & SMBFLG2_UNICODE) in CIFSTCon()
3802 tcon->ipc = true; in CIFSTCon()
3803 tcon->pipe = true; in CIFSTCon()
3812 bytes_left -= (length + 1); in CIFSTCon()
3813 strscpy(tcon->tree_name, tree, sizeof(tcon->tree_name)); in CIFSTCon()
3815 /* mostly informational -- no need to fail on error here */ in CIFSTCon()
3816 kfree(tcon->nativeFileSystem); in CIFSTCon()
3817 tcon->nativeFileSystem = cifs_strndup_from_utf16(bcc_ptr, in CIFSTCon()
3821 cifs_dbg(FYI, "nativeFileSystem=%s\n", tcon->nativeFileSystem); in CIFSTCon()
3823 if ((smb_buffer_response->WordCount == 3) || in CIFSTCon()
3824 (smb_buffer_response->WordCount == 7)) in CIFSTCon()
3826 tcon->Flags = le16_to_cpu(pSMBr->OptionalSupport); in CIFSTCon()
3828 tcon->Flags = 0; in CIFSTCon()
3829 cifs_dbg(FYI, "Tcon flags: 0x%x\n", tcon->Flags); in CIFSTCon()
3836 * need_reconnect when tcon was successful but needed to be in CIFSTCon()
3839 if (tcon->need_reconnect && tcon->unix_ext) { in CIFSTCon()
3840 cifs_dbg(FYI, "resetting caps for %s\n", tcon->tree_name); in CIFSTCon()
3841 tcon->need_reconnect = false; in CIFSTCon()
3842 reset_cifs_unix_caps(xid, tcon, NULL, NULL); in CIFSTCon()
3854 unload_nls(cifs_sb->local_nls); in delayed_free()
3855 smb3_cleanup_fs_context(cifs_sb->ctx); in delayed_free()
3862 struct rb_root *root = &cifs_sb->tlink_tree; in cifs_umount()
3866 cancel_delayed_work_sync(&cifs_sb->prune_tlinks); in cifs_umount()
3868 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3872 clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); in cifs_umount()
3875 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3877 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3879 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3881 kfree(cifs_sb->prepath); in cifs_umount()
3882 call_rcu(&cifs_sb->rcu, delayed_free); in cifs_umount()
3891 if (!server->ops->need_neg || !server->ops->negotiate) in cifs_negotiate_protocol()
3892 return -ENOSYS; in cifs_negotiate_protocol()
3895 spin_lock(&server->srv_lock); in cifs_negotiate_protocol()
3896 if (server->tcpStatus != CifsGood && in cifs_negotiate_protocol()
3897 server->tcpStatus != CifsNew && in cifs_negotiate_protocol()
3898 server->tcpStatus != CifsNeedNegotiate) { in cifs_negotiate_protocol()
3899 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
3900 return -EHOSTDOWN; in cifs_negotiate_protocol()
3903 if (!server->ops->need_neg(server) && in cifs_negotiate_protocol()
3904 server->tcpStatus == CifsGood) { in cifs_negotiate_protocol()
3905 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
3909 server->tcpStatus = CifsInNegotiate; in cifs_negotiate_protocol()
3910 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
3912 rc = server->ops->negotiate(xid, ses, server); in cifs_negotiate_protocol()
3914 spin_lock(&server->srv_lock); in cifs_negotiate_protocol()
3915 if (server->tcpStatus == CifsInNegotiate) in cifs_negotiate_protocol()
3916 server->tcpStatus = CifsGood; in cifs_negotiate_protocol()
3918 rc = -EHOSTDOWN; in cifs_negotiate_protocol()
3919 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
3921 spin_lock(&server->srv_lock); in cifs_negotiate_protocol()
3922 if (server->tcpStatus == CifsInNegotiate) in cifs_negotiate_protocol()
3923 server->tcpStatus = CifsNeedNegotiate; in cifs_negotiate_protocol()
3924 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
3935 int rc = -ENOSYS; in cifs_setup_session()
3936 struct TCP_Server_Info *pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in cifs_setup_session()
3937 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&pserver->dstaddr; in cifs_setup_session()
3938 struct sockaddr_in *addr = (struct sockaddr_in *)&pserver->dstaddr; in cifs_setup_session()
3941 spin_lock(&ses->ses_lock); in cifs_setup_session()
3942 cifs_dbg(FYI, "%s: channel connect bitmap: 0x%lx\n", in cifs_setup_session()
3943 __func__, ses->chans_need_reconnect); in cifs_setup_session()
3945 if (ses->ses_status != SES_GOOD && in cifs_setup_session()
3946 ses->ses_status != SES_NEW && in cifs_setup_session()
3947 ses->ses_status != SES_NEED_RECON) { in cifs_setup_session()
3948 spin_unlock(&ses->ses_lock); in cifs_setup_session()
3949 return -EHOSTDOWN; in cifs_setup_session()
3953 spin_lock(&ses->chan_lock); in cifs_setup_session()
3955 if (ses->ses_status == SES_NEED_RECON) in cifs_setup_session()
3956 ses->ses_status = SES_GOOD; in cifs_setup_session()
3957 spin_unlock(&ses->chan_lock); in cifs_setup_session()
3958 spin_unlock(&ses->ses_lock); in cifs_setup_session()
3964 spin_unlock(&ses->chan_lock); in cifs_setup_session()
3967 ses->ses_status = SES_IN_SETUP; in cifs_setup_session()
3970 ses->iface_last_update = 0; in cifs_setup_session()
3972 spin_unlock(&ses->ses_lock); in cifs_setup_session()
3976 if (server->dstaddr.ss_family == AF_INET6) in cifs_setup_session()
3977 scnprintf(ses->ip_addr, sizeof(ses->ip_addr), "%pI6", &addr6->sin6_addr); in cifs_setup_session()
3979 scnprintf(ses->ip_addr, sizeof(ses->ip_addr), "%pI4", &addr->sin_addr); in cifs_setup_session()
3983 ses->capabilities = server->capabilities; in cifs_setup_session()
3985 ses->capabilities &= (~server->vals->cap_unix); in cifs_setup_session()
3987 if (ses->auth_key.response) { in cifs_setup_session()
3989 ses->auth_key.response); in cifs_setup_session()
3990 kfree_sensitive(ses->auth_key.response); in cifs_setup_session()
3991 ses->auth_key.response = NULL; in cifs_setup_session()
3992 ses->auth_key.len = 0; in cifs_setup_session()
3997 server->sec_mode, server->capabilities, server->timeAdj); in cifs_setup_session()
3999 if (server->ops->sess_setup) in cifs_setup_session()
4000 rc = server->ops->sess_setup(xid, ses, server, nls_info); in cifs_setup_session()
4004 spin_lock(&ses->ses_lock); in cifs_setup_session()
4005 if (ses->ses_status == SES_IN_SETUP) in cifs_setup_session()
4006 ses->ses_status = SES_NEED_RECON; in cifs_setup_session()
4007 spin_lock(&ses->chan_lock); in cifs_setup_session()
4009 spin_unlock(&ses->chan_lock); in cifs_setup_session()
4010 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4012 spin_lock(&ses->ses_lock); in cifs_setup_session()
4013 if (ses->ses_status == SES_IN_SETUP) in cifs_setup_session()
4014 ses->ses_status = SES_GOOD; in cifs_setup_session()
4015 spin_lock(&ses->chan_lock); in cifs_setup_session()
4018 spin_unlock(&ses->chan_lock); in cifs_setup_session()
4019 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4028 ctx->sectype = ses->sectype; in cifs_set_vol_auth()
4031 if (ctx->sectype == Kerberos) in cifs_set_vol_auth()
4043 struct cifs_tcon *tcon = NULL; in cifs_construct_tcon() local
4049 return ERR_PTR(-ENOMEM); in cifs_construct_tcon()
4051 ctx->local_nls = cifs_sb->local_nls; in cifs_construct_tcon()
4052 ctx->linux_uid = fsuid; in cifs_construct_tcon()
4053 ctx->cred_uid = fsuid; in cifs_construct_tcon()
4054 ctx->UNC = master_tcon->tree_name; in cifs_construct_tcon()
4055 ctx->retry = master_tcon->retry; in cifs_construct_tcon()
4056 ctx->nocase = master_tcon->nocase; in cifs_construct_tcon()
4057 ctx->nohandlecache = master_tcon->nohandlecache; in cifs_construct_tcon()
4058 ctx->local_lease = master_tcon->local_lease; in cifs_construct_tcon()
4059 ctx->no_lease = master_tcon->no_lease; in cifs_construct_tcon()
4060 ctx->resilient = master_tcon->use_resilient; in cifs_construct_tcon()
4061 ctx->persistent = master_tcon->use_persistent; in cifs_construct_tcon()
4062 ctx->handle_timeout = master_tcon->handle_timeout; in cifs_construct_tcon()
4063 ctx->no_linux_ext = !master_tcon->unix_ext; in cifs_construct_tcon()
4064 ctx->linux_ext = master_tcon->posix_extensions; in cifs_construct_tcon()
4065 ctx->sectype = master_tcon->ses->sectype; in cifs_construct_tcon()
4066 ctx->sign = master_tcon->ses->sign; in cifs_construct_tcon()
4067 ctx->seal = master_tcon->seal; in cifs_construct_tcon()
4068 ctx->witness = master_tcon->use_witness; in cifs_construct_tcon()
4069 ctx->dfs_root_ses = master_tcon->ses->dfs_root_ses; in cifs_construct_tcon()
4071 rc = cifs_set_vol_auth(ctx, master_tcon->ses); in cifs_construct_tcon()
4073 tcon = ERR_PTR(rc); in cifs_construct_tcon()
4079 ++master_tcon->ses->server->srv_count; in cifs_construct_tcon()
4082 ses = cifs_get_smb_ses(master_tcon->ses->server, ctx); in cifs_construct_tcon()
4084 tcon = ERR_CAST(ses); in cifs_construct_tcon()
4085 cifs_put_tcp_session(master_tcon->ses->server, 0); in cifs_construct_tcon()
4090 spin_lock(&master_tcon->tc_lock); in cifs_construct_tcon()
4091 if (master_tcon->origin_fullpath) { in cifs_construct_tcon()
4092 spin_unlock(&master_tcon->tc_lock); in cifs_construct_tcon()
4093 origin_fullpath = dfs_get_path(cifs_sb, cifs_sb->ctx->source); in cifs_construct_tcon()
4095 tcon = ERR_CAST(origin_fullpath); in cifs_construct_tcon()
4101 spin_unlock(&master_tcon->tc_lock); in cifs_construct_tcon()
4105 tcon = cifs_get_tcon(ses, ctx); in cifs_construct_tcon()
4106 if (IS_ERR(tcon)) { in cifs_construct_tcon()
4113 spin_lock(&tcon->tc_lock); in cifs_construct_tcon()
4114 tcon->origin_fullpath = origin_fullpath; in cifs_construct_tcon()
4115 spin_unlock(&tcon->tc_lock); in cifs_construct_tcon()
4117 queue_delayed_work(dfscache_wq, &tcon->dfs_cache_work, in cifs_construct_tcon()
4124 reset_cifs_unix_caps(0, tcon, NULL, ctx); in cifs_construct_tcon()
4128 kfree(ctx->username); in cifs_construct_tcon()
4129 kfree_sensitive(ctx->password); in cifs_construct_tcon()
4133 return tcon; in cifs_construct_tcon()
4146 struct rb_node *node = root->rb_node; in tlink_rb_search()
4152 if (uid_gt(tlink->tl_uid, uid)) in tlink_rb_search()
4153 node = node->rb_left; in tlink_rb_search()
4154 else if (uid_lt(tlink->tl_uid, uid)) in tlink_rb_search()
4155 node = node->rb_right; in tlink_rb_search()
4166 struct rb_node **new = &(root->rb_node), *parent = NULL; in tlink_rb_insert()
4173 if (uid_gt(tlink->tl_uid, new_tlink->tl_uid)) in tlink_rb_insert()
4174 new = &((*new)->rb_left); in tlink_rb_insert()
4176 new = &((*new)->rb_right); in tlink_rb_insert()
4179 rb_link_node(&new_tlink->tl_rbnode, parent, new); in tlink_rb_insert()
4180 rb_insert_color(&new_tlink->tl_rbnode, root); in tlink_rb_insert()
4184 * Find or construct an appropriate tcon given a cifs_sb and the fsuid of the
4188 * the master tcon for the mount.
4190 * First, search the rbtree for an existing tcon for this fsuid. If one
4209 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) in cifs_sb_tlink()
4212 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4213 tlink = tlink_rb_search(&cifs_sb->tlink_tree, fsuid); in cifs_sb_tlink()
4216 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4221 return ERR_PTR(-ENOMEM); in cifs_sb_tlink()
4222 newtlink->tl_uid = fsuid; in cifs_sb_tlink()
4223 newtlink->tl_tcon = ERR_PTR(-EACCES); in cifs_sb_tlink()
4224 set_bit(TCON_LINK_PENDING, &newtlink->tl_flags); in cifs_sb_tlink()
4225 set_bit(TCON_LINK_IN_TREE, &newtlink->tl_flags); in cifs_sb_tlink()
4228 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4230 tlink = tlink_rb_search(&cifs_sb->tlink_tree, fsuid); in cifs_sb_tlink()
4233 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4238 tlink_rb_insert(&cifs_sb->tlink_tree, tlink); in cifs_sb_tlink()
4239 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4242 err = wait_on_bit(&tlink->tl_flags, TCON_LINK_PENDING, in cifs_sb_tlink()
4246 return ERR_PTR(-ERESTARTSYS); in cifs_sb_tlink()
4250 if (!IS_ERR(tlink->tl_tcon)) in cifs_sb_tlink()
4254 if (time_before(jiffies, tlink->tl_time + TLINK_ERROR_EXPIRE)) { in cifs_sb_tlink()
4255 err = PTR_ERR(tlink->tl_tcon); in cifs_sb_tlink()
4260 if (test_and_set_bit(TCON_LINK_PENDING, &tlink->tl_flags)) in cifs_sb_tlink()
4264 tlink->tl_tcon = cifs_construct_tcon(cifs_sb, fsuid); in cifs_sb_tlink()
4265 clear_bit(TCON_LINK_PENDING, &tlink->tl_flags); in cifs_sb_tlink()
4266 wake_up_bit(&tlink->tl_flags, TCON_LINK_PENDING); in cifs_sb_tlink()
4268 if (IS_ERR(tlink->tl_tcon)) { in cifs_sb_tlink()
4269 err = PTR_ERR(tlink->tl_tcon); in cifs_sb_tlink()
4270 if (err == -ENOKEY) in cifs_sb_tlink()
4271 err = -EACCES; in cifs_sb_tlink()
4288 struct rb_root *root = &cifs_sb->tlink_tree; in cifs_prune_tlinks()
4297 * umounts. Because this function is non-reentrant and is canceled in cifs_prune_tlinks()
4300 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4307 if (test_bit(TCON_LINK_MASTER, &tlink->tl_flags) || in cifs_prune_tlinks()
4308 atomic_read(&tlink->tl_count) != 0 || in cifs_prune_tlinks()
4309 time_after(tlink->tl_time + TLINK_IDLE_EXPIRE, jiffies)) in cifs_prune_tlinks()
4313 clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); in cifs_prune_tlinks()
4316 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4318 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4320 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4322 queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks, in cifs_prune_tlinks()
4327 int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const struct nls_table *nlsc) in cifs_tree_connect() argument
4330 const struct smb_version_operations *ops = tcon->ses->server->ops; in cifs_tree_connect()
4333 spin_lock(&tcon->tc_lock); in cifs_tree_connect()
4335 /* if tcon is marked for needing reconnect, update state */ in cifs_tree_connect()
4336 if (tcon->need_reconnect) in cifs_tree_connect()
4337 tcon->status = TID_NEED_TCON; in cifs_tree_connect()
4339 if (tcon->status == TID_GOOD) { in cifs_tree_connect()
4340 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4344 if (tcon->status != TID_NEW && in cifs_tree_connect()
4345 tcon->status != TID_NEED_TCON) { in cifs_tree_connect()
4346 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4347 return -EHOSTDOWN; in cifs_tree_connect()
4350 tcon->status = TID_IN_TCON; in cifs_tree_connect()
4351 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4353 rc = ops->tree_connect(xid, tcon->ses, tcon->tree_name, tcon, nlsc); in cifs_tree_connect()
4355 spin_lock(&tcon->tc_lock); in cifs_tree_connect()
4356 if (tcon->status == TID_IN_TCON) in cifs_tree_connect()
4357 tcon->status = TID_NEED_TCON; in cifs_tree_connect()
4358 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4360 spin_lock(&tcon->tc_lock); in cifs_tree_connect()
4361 if (tcon->status == TID_IN_TCON) in cifs_tree_connect()
4362 tcon->status = TID_GOOD; in cifs_tree_connect()
4363 tcon->need_reconnect = false; in cifs_tree_connect()
4364 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()