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()
855 cifs_set_port((struct sockaddr *)&server->dstaddr, CIFS_PORT); in is_smb_response()
870 mid->when_received = jiffies; in dequeue_mid()
872 spin_lock(&mid->server->mid_lock); in dequeue_mid()
874 mid->mid_state = MID_RESPONSE_RECEIVED; in dequeue_mid()
876 mid->mid_state = MID_RESPONSE_MALFORMED; in dequeue_mid()
881 if (mid->mid_flags & MID_DELETED) { in dequeue_mid()
882 spin_unlock(&mid->server->mid_lock); in dequeue_mid()
885 list_del_init(&mid->qhead); in dequeue_mid()
886 mid->mid_flags |= MID_DELETED; in dequeue_mid()
887 spin_unlock(&mid->server->mid_lock); in dequeue_mid()
902 return le16_to_cpu(shdr->CreditRequest); in smb2_get_credits_from_hdr()
909 if (server->ops->check_trans2 && in handle_mid()
910 server->ops->check_trans2(mid, server, buf, malformed)) in handle_mid()
912 mid->credits_received = smb2_get_credits_from_hdr(buf, server); in handle_mid()
913 mid->resp_buf = buf; in handle_mid()
914 mid->large_buf = server->large_buf; in handle_mid()
915 /* Was previous buf put in mpx struct for multi-rsp? */ in handle_mid()
916 if (!mid->multiRsp) { in handle_mid()
918 if (server->large_buf) in handle_mid()
919 server->bigbuf = NULL; in handle_mid()
921 server->smallbuf = NULL; in handle_mid()
929 bool srv_sign_required = server->sec_mode & server->vals->signing_required; in cifs_enable_signing()
930 bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled; in cifs_enable_signing()
952 return -EOPNOTSUPP; in cifs_enable_signing()
954 server->sign = true; in cifs_enable_signing()
961 return -EOPNOTSUPP; in cifs_enable_signing()
963 server->sign = true; in cifs_enable_signing()
966 if (cifs_rdma_enabled(server) && server->sign) in cifs_enable_signing()
978 spin_lock(&server->srv_lock); in clean_demultiplex_info()
979 list_del_init(&server->tcp_ses_list); in clean_demultiplex_info()
980 spin_unlock(&server->srv_lock); in clean_demultiplex_info()
982 cancel_delayed_work_sync(&server->echo); in clean_demultiplex_info()
984 spin_lock(&server->srv_lock); in clean_demultiplex_info()
985 server->tcpStatus = CifsExiting; in clean_demultiplex_info()
986 spin_unlock(&server->srv_lock); in clean_demultiplex_info()
987 wake_up_all(&server->response_q); in clean_demultiplex_info()
990 spin_lock(&server->req_lock); in clean_demultiplex_info()
991 if (server->credits <= 0) in clean_demultiplex_info()
992 server->credits = 1; in clean_demultiplex_info()
993 spin_unlock(&server->req_lock); in clean_demultiplex_info()
998 * same server - they now will see the session is in exit state and get in clean_demultiplex_info()
1001 wake_up_all(&server->request_q); in clean_demultiplex_info()
1007 if (server->ssocket) { in clean_demultiplex_info()
1008 sock_release(server->ssocket); in clean_demultiplex_info()
1009 server->ssocket = NULL; in clean_demultiplex_info()
1015 if (!list_empty(&server->pending_mid_q)) { in clean_demultiplex_info()
1021 spin_lock(&server->mid_lock); in clean_demultiplex_info()
1022 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { in clean_demultiplex_info()
1024 cifs_dbg(FYI, "Clearing mid %llu\n", mid_entry->mid); in clean_demultiplex_info()
1025 kref_get(&mid_entry->refcount); in clean_demultiplex_info()
1026 mid_entry->mid_state = MID_SHUTDOWN; in clean_demultiplex_info()
1027 list_move(&mid_entry->qhead, &dispose_list); in clean_demultiplex_info()
1028 mid_entry->mid_flags |= MID_DELETED; in clean_demultiplex_info()
1030 spin_unlock(&server->mid_lock); in clean_demultiplex_info()
1035 cifs_dbg(FYI, "Callback mid %llu\n", mid_entry->mid); in clean_demultiplex_info()
1036 list_del_init(&mid_entry->qhead); in clean_demultiplex_info()
1037 mid_entry->callback(mid_entry); in clean_demultiplex_info()
1044 if (!list_empty(&server->pending_mid_q)) { in clean_demultiplex_info()
1063 kfree(server->leaf_fullpath); in clean_demultiplex_info()
1064 kfree(server->hostname); in clean_demultiplex_info()
1076 char *buf = server->smallbuf; in standard_receive3()
1077 unsigned int pdu_length = server->pdu_size; in standard_receive3()
1080 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server) - in standard_receive3()
1084 return -ECONNABORTED; in standard_receive3()
1088 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) { in standard_receive3()
1089 server->large_buf = true; in standard_receive3()
1090 memcpy(server->bigbuf, buf, server->total_read); in standard_receive3()
1091 buf = server->bigbuf; in standard_receive3()
1095 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, in standard_receive3()
1096 pdu_length - MID_HEADER_SIZE(server)); in standard_receive3()
1100 server->total_read += length; in standard_receive3()
1102 dump_smb(buf, server->total_read); in standard_receive3()
1110 char *buf = server->large_buf ? server->bigbuf : server->smallbuf; in cifs_handle_standard()
1121 rc = server->ops->check_message(buf, server->total_read, server); in cifs_handle_standard()
1124 min_t(unsigned int, server->total_read, 48)); in cifs_handle_standard()
1126 if (server->ops->is_session_expired && in cifs_handle_standard()
1127 server->ops->is_session_expired(buf)) { in cifs_handle_standard()
1129 return -1; in cifs_handle_standard()
1132 if (server->ops->is_status_pending && in cifs_handle_standard()
1133 server->ops->is_status_pending(buf, server)) in cifs_handle_standard()
1134 return -1; in cifs_handle_standard()
1155 if (shdr->CreditRequest) { in smb2_add_credits_from_hdr()
1156 spin_lock(&server->req_lock); in smb2_add_credits_from_hdr()
1157 server->credits += le16_to_cpu(shdr->CreditRequest); in smb2_add_credits_from_hdr()
1158 scredits = server->credits; in smb2_add_credits_from_hdr()
1159 in_flight = server->in_flight; in smb2_add_credits_from_hdr()
1160 spin_unlock(&server->req_lock); in smb2_add_credits_from_hdr()
1161 wake_up(&server->request_q); in smb2_add_credits_from_hdr()
1163 trace_smb3_hdr_credits(server->CurrentMid, in smb2_add_credits_from_hdr()
1164 server->conn_id, server->hostname, scredits, in smb2_add_credits_from_hdr()
1165 le16_to_cpu(shdr->CreditRequest), in_flight); in smb2_add_credits_from_hdr()
1167 __func__, le16_to_cpu(shdr->CreditRequest), in smb2_add_credits_from_hdr()
1196 while (server->tcpStatus != CifsExiting) { in cifs_demultiplex_thread()
1203 server->large_buf = false; in cifs_demultiplex_thread()
1204 buf = server->smallbuf; in cifs_demultiplex_thread()
1212 server->total_read = length; in cifs_demultiplex_thread()
1214 server->total_read = 0; in cifs_demultiplex_thread()
1217 * The right amount was read from socket - 4 bytes, in cifs_demultiplex_thread()
1228 server->pdu_size = pdu_length; in cifs_demultiplex_thread()
1231 if (server->pdu_size < MID_HEADER_SIZE(server)) { in cifs_demultiplex_thread()
1233 server->pdu_size); in cifs_demultiplex_thread()
1244 server->total_read += length; in cifs_demultiplex_thread()
1246 if (server->ops->next_header) { in cifs_demultiplex_thread()
1247 if (server->ops->next_header(server, buf, &next_offset)) { in cifs_demultiplex_thread()
1254 server->pdu_size = next_offset; in cifs_demultiplex_thread()
1261 if (server->ops->is_transform_hdr && in cifs_demultiplex_thread()
1262 server->ops->receive_transform && in cifs_demultiplex_thread()
1263 server->ops->is_transform_hdr(buf)) { in cifs_demultiplex_thread()
1264 length = server->ops->receive_transform(server, in cifs_demultiplex_thread()
1269 mids[0] = server->ops->find_mid(server, buf); in cifs_demultiplex_thread()
1273 if (!mids[0] || !mids[0]->receive) in cifs_demultiplex_thread()
1276 length = mids[0]->receive(server, mids[0]); in cifs_demultiplex_thread()
1286 if (server->ops->is_status_io_timeout && in cifs_demultiplex_thread()
1287 server->ops->is_status_io_timeout(buf)) { in cifs_demultiplex_thread()
1299 server->lstrp = jiffies; in cifs_demultiplex_thread()
1303 mids[i]->resp_buf_size = server->pdu_size; in cifs_demultiplex_thread()
1306 if (server->ops->is_network_name_deleted && in cifs_demultiplex_thread()
1307 server->ops->is_network_name_deleted(bufs[i], in cifs_demultiplex_thread()
1314 if (!mids[i]->multiRsp || mids[i]->multiEnd) in cifs_demultiplex_thread()
1315 mids[i]->callback(mids[i]); in cifs_demultiplex_thread()
1318 } else if (server->ops->is_oplock_break && in cifs_demultiplex_thread()
1319 server->ops->is_oplock_break(bufs[i], in cifs_demultiplex_thread()
1330 if (server->ops->dump_detail) in cifs_demultiplex_thread()
1331 server->ops->dump_detail(bufs[i], in cifs_demultiplex_thread()
1338 if (pdu_length > server->pdu_size) { in cifs_demultiplex_thread()
1341 pdu_length -= server->pdu_size; in cifs_demultiplex_thread()
1342 server->total_read = 0; in cifs_demultiplex_thread()
1343 server->large_buf = false; in cifs_demultiplex_thread()
1344 buf = server->smallbuf; in cifs_demultiplex_thread()
1354 /* buffer usually freed in free_mid - need to free it here on exit */ in cifs_demultiplex_thread()
1355 cifs_buf_release(server->bigbuf); in cifs_demultiplex_thread()
1356 if (server->smallbuf) /* no sense logging a debug message if NULL */ in cifs_demultiplex_thread()
1357 cifs_small_buf_release(server->smallbuf); in cifs_demultiplex_thread()
1359 task_to_wake = xchg(&server->tsk, NULL); in cifs_demultiplex_thread()
1362 /* if server->tsk was NULL then wait for a signal before exiting */ in cifs_demultiplex_thread()
1384 switch (srcaddr->sa_family) { in cifs_ipaddr_cmp()
1386 switch (rhs->sa_family) { in cifs_ipaddr_cmp()
1393 return -1; in cifs_ipaddr_cmp()
1396 switch (rhs->sa_family) { in cifs_ipaddr_cmp()
1398 return -1; in cifs_ipaddr_cmp()
1405 return -1; in cifs_ipaddr_cmp()
1409 switch (rhs->sa_family) { in cifs_ipaddr_cmp()
1412 return -1; in cifs_ipaddr_cmp()
1418 return -1; in cifs_ipaddr_cmp()
1422 return -1; /* don't expect to be here */ in cifs_ipaddr_cmp()
1433 switch (srcaddr->sa_family) { in cifs_match_ipaddr()
1435 return (rhs->sa_family == AF_UNSPEC); in cifs_match_ipaddr()
1440 return (saddr4->sin_addr.s_addr == vaddr4->sin_addr.s_addr); in cifs_match_ipaddr()
1446 return (ipv6_addr_equal(&saddr6->sin6_addr, &vaddr6->sin6_addr) in cifs_match_ipaddr()
1447 && saddr6->sin6_scope_id == vaddr6->sin6_scope_id); in cifs_match_ipaddr()
1457 * and if it fails - with 139 ports. It should be called only if address
1466 if (server->rdma) in match_port()
1469 switch (addr->sa_family) { in match_port()
1471 sport = &((struct sockaddr_in *) &server->dstaddr)->sin_port; in match_port()
1472 port = ((struct sockaddr_in *) addr)->sin_port; in match_port()
1475 sport = &((struct sockaddr_in6 *) &server->dstaddr)->sin6_port; in match_port()
1476 port = ((struct sockaddr_in6 *) addr)->sin6_port; in match_port()
1496 if (!cifs_match_ipaddr(addr, (struct sockaddr *)&server->dstaddr)) in match_server_address()
1506 * The select_sectype function should either return the ctx->sectype in match_security()
1510 if (server->ops->select_sectype(server, ctx->sectype) in match_security()
1517 * the server->sign had better be too. in match_security()
1519 if (ctx->sign && !server->sign) in match_security()
1530 struct sockaddr *addr = (struct sockaddr *)&ctx->dstaddr; in match_server()
1532 lockdep_assert_held(&server->srv_lock); in match_server()
1534 if (ctx->nosharesock) in match_server()
1538 if (server->nosharesock) in match_server()
1542 if (strcmp(ctx->vals->version_string, SMB3ANY_VERSION_STRING) == 0) { in match_server()
1543 if (server->vals->protocol_id < SMB30_PROT_ID) in match_server()
1545 } else if (strcmp(ctx->vals->version_string, in match_server()
1547 if (server->vals->protocol_id < SMB21_PROT_ID) in match_server()
1549 } else if ((server->vals != ctx->vals) || (server->ops != ctx->ops)) in match_server()
1552 if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns)) in match_server()
1555 if (!cifs_match_ipaddr((struct sockaddr *)&ctx->srcaddr, in match_server()
1556 (struct sockaddr *)&server->srcaddr)) in match_server()
1560 * really match either @server->leaf_fullpath or @server->dstaddr in match_server()
1562 * server -- in case of domain-based DFS referrals or DFS links -- as in match_server()
1565 * Otherwise, match the DFS referral in @server->leaf_fullpath or the in match_server()
1566 * destination address in @server->dstaddr. in match_server()
1572 if (!ctx->nodfs) { in match_server()
1573 if (server->leaf_fullpath) { in match_server()
1574 if (!ctx->leaf_fullpath || in match_server()
1575 strcasecmp(server->leaf_fullpath, in match_server()
1576 ctx->leaf_fullpath)) in match_server()
1578 } else if (ctx->leaf_fullpath) { in match_server()
1581 } else if (server->leaf_fullpath) { in match_server()
1590 if (!server->leaf_fullpath && in match_server()
1591 (strcasecmp(server->hostname, ctx->server_hostname) || in match_server()
1599 if (server->echo_interval != ctx->echo_interval * HZ) in match_server()
1602 if (server->rdma != ctx->rdma) in match_server()
1605 if (server->ignore_signature != ctx->ignore_signature) in match_server()
1608 if (server->min_offload != ctx->min_offload) in match_server()
1611 if (server->retrans != ctx->retrans) in match_server()
1624 spin_lock(&server->srv_lock); in cifs_find_tcp_session()
1631 spin_unlock(&server->srv_lock); in cifs_find_tcp_session()
1634 spin_unlock(&server->srv_lock); in cifs_find_tcp_session()
1636 ++server->srv_count; in cifs_find_tcp_session()
1651 if (--server->srv_count > 0) { in cifs_put_tcp_session()
1657 WARN_ON(server->srv_count < 0); in cifs_put_tcp_session()
1659 list_del_init(&server->tcp_ses_list); in cifs_put_tcp_session()
1662 cancel_delayed_work_sync(&server->echo); in cifs_put_tcp_session()
1671 cancel_delayed_work(&server->reconnect); in cifs_put_tcp_session()
1673 cancel_delayed_work_sync(&server->reconnect); in cifs_put_tcp_session()
1675 /* For secondary channels, we pick up ref-count on the primary server */ in cifs_put_tcp_session()
1677 cifs_put_tcp_session(server->primary_server, from_reconnect); in cifs_put_tcp_session()
1679 spin_lock(&server->srv_lock); in cifs_put_tcp_session()
1680 server->tcpStatus = CifsExiting; in cifs_put_tcp_session()
1681 spin_unlock(&server->srv_lock); in cifs_put_tcp_session()
1685 kfree_sensitive(server->session_key.response); in cifs_put_tcp_session()
1686 server->session_key.response = NULL; in cifs_put_tcp_session()
1687 server->session_key.len = 0; in cifs_put_tcp_session()
1689 task = xchg(&server->tsk, NULL); in cifs_put_tcp_session()
1701 cifs_dbg(FYI, "UNC: %s\n", ctx->UNC); in cifs_get_tcp_session()
1710 rc = -ENOMEM; in cifs_get_tcp_session()
1714 tcp_ses->hostname = kstrdup(ctx->server_hostname, GFP_KERNEL); in cifs_get_tcp_session()
1715 if (!tcp_ses->hostname) { in cifs_get_tcp_session()
1716 rc = -ENOMEM; in cifs_get_tcp_session()
1720 if (ctx->leaf_fullpath) { in cifs_get_tcp_session()
1721 tcp_ses->leaf_fullpath = kstrdup(ctx->leaf_fullpath, GFP_KERNEL); in cifs_get_tcp_session()
1722 if (!tcp_ses->leaf_fullpath) { in cifs_get_tcp_session()
1723 rc = -ENOMEM; in cifs_get_tcp_session()
1728 if (ctx->nosharesock) in cifs_get_tcp_session()
1729 tcp_ses->nosharesock = true; in cifs_get_tcp_session()
1731 tcp_ses->ops = ctx->ops; in cifs_get_tcp_session()
1732 tcp_ses->vals = ctx->vals; in cifs_get_tcp_session()
1735 cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns)); in cifs_get_tcp_session()
1737 tcp_ses->conn_id = atomic_inc_return(&tcpSesNextId); in cifs_get_tcp_session()
1738 tcp_ses->noblockcnt = ctx->rootfs; in cifs_get_tcp_session()
1739 tcp_ses->noblocksnd = ctx->noblocksnd || ctx->rootfs; in cifs_get_tcp_session()
1740 tcp_ses->noautotune = ctx->noautotune; in cifs_get_tcp_session()
1741 tcp_ses->tcp_nodelay = ctx->sockopt_tcp_nodelay; in cifs_get_tcp_session()
1742 tcp_ses->rdma = ctx->rdma; in cifs_get_tcp_session()
1743 tcp_ses->in_flight = 0; in cifs_get_tcp_session()
1744 tcp_ses->max_in_flight = 0; in cifs_get_tcp_session()
1745 tcp_ses->credits = 1; in cifs_get_tcp_session()
1748 ++primary_server->srv_count; in cifs_get_tcp_session()
1750 tcp_ses->primary_server = primary_server; in cifs_get_tcp_session()
1752 init_waitqueue_head(&tcp_ses->response_q); in cifs_get_tcp_session()
1753 init_waitqueue_head(&tcp_ses->request_q); in cifs_get_tcp_session()
1754 INIT_LIST_HEAD(&tcp_ses->pending_mid_q); in cifs_get_tcp_session()
1755 mutex_init(&tcp_ses->_srv_mutex); in cifs_get_tcp_session()
1756 memcpy(tcp_ses->workstation_RFC1001_name, in cifs_get_tcp_session()
1757 ctx->source_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL); in cifs_get_tcp_session()
1758 memcpy(tcp_ses->server_RFC1001_name, in cifs_get_tcp_session()
1759 ctx->target_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL); in cifs_get_tcp_session()
1760 tcp_ses->session_estab = false; in cifs_get_tcp_session()
1761 tcp_ses->sequence_number = 0; in cifs_get_tcp_session()
1762 tcp_ses->channel_sequence_num = 0; /* only tracked for primary channel */ in cifs_get_tcp_session()
1763 tcp_ses->reconnect_instance = 1; in cifs_get_tcp_session()
1764 tcp_ses->lstrp = jiffies; in cifs_get_tcp_session()
1765 tcp_ses->compression.requested = ctx->compress; in cifs_get_tcp_session()
1766 spin_lock_init(&tcp_ses->req_lock); in cifs_get_tcp_session()
1767 spin_lock_init(&tcp_ses->srv_lock); in cifs_get_tcp_session()
1768 spin_lock_init(&tcp_ses->mid_lock); in cifs_get_tcp_session()
1769 INIT_LIST_HEAD(&tcp_ses->tcp_ses_list); in cifs_get_tcp_session()
1770 INIT_LIST_HEAD(&tcp_ses->smb_ses_list); in cifs_get_tcp_session()
1771 INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request); in cifs_get_tcp_session()
1772 INIT_DELAYED_WORK(&tcp_ses->reconnect, smb2_reconnect_server); in cifs_get_tcp_session()
1773 mutex_init(&tcp_ses->reconnect_mutex); in cifs_get_tcp_session()
1775 mutex_init(&tcp_ses->refpath_lock); in cifs_get_tcp_session()
1777 memcpy(&tcp_ses->srcaddr, &ctx->srcaddr, in cifs_get_tcp_session()
1778 sizeof(tcp_ses->srcaddr)); in cifs_get_tcp_session()
1779 memcpy(&tcp_ses->dstaddr, &ctx->dstaddr, in cifs_get_tcp_session()
1780 sizeof(tcp_ses->dstaddr)); in cifs_get_tcp_session()
1781 if (ctx->use_client_guid) in cifs_get_tcp_session()
1782 memcpy(tcp_ses->client_guid, ctx->client_guid, in cifs_get_tcp_session()
1785 generate_random_uuid(tcp_ses->client_guid); in cifs_get_tcp_session()
1791 tcp_ses->tcpStatus = CifsNew; in cifs_get_tcp_session()
1792 ++tcp_ses->srv_count; in cifs_get_tcp_session()
1794 if (ctx->echo_interval >= SMB_ECHO_INTERVAL_MIN && in cifs_get_tcp_session()
1795 ctx->echo_interval <= SMB_ECHO_INTERVAL_MAX) in cifs_get_tcp_session()
1796 tcp_ses->echo_interval = ctx->echo_interval * HZ; in cifs_get_tcp_session()
1798 tcp_ses->echo_interval = SMB_ECHO_INTERVAL_DEFAULT * HZ; in cifs_get_tcp_session()
1799 if (tcp_ses->rdma) { in cifs_get_tcp_session()
1802 rc = -ENOENT; in cifs_get_tcp_session()
1805 tcp_ses->smbd_conn = smbd_get_connection( in cifs_get_tcp_session()
1806 tcp_ses, (struct sockaddr *)&ctx->dstaddr); in cifs_get_tcp_session()
1807 if (tcp_ses->smbd_conn) { in cifs_get_tcp_session()
1812 rc = -ENOENT; in cifs_get_tcp_session()
1827 tcp_ses->tsk = kthread_run(cifs_demultiplex_thread, in cifs_get_tcp_session()
1829 if (IS_ERR(tcp_ses->tsk)) { in cifs_get_tcp_session()
1830 rc = PTR_ERR(tcp_ses->tsk); in cifs_get_tcp_session()
1835 tcp_ses->min_offload = ctx->min_offload; in cifs_get_tcp_session()
1836 tcp_ses->retrans = ctx->retrans; in cifs_get_tcp_session()
1842 spin_lock(&tcp_ses->srv_lock); in cifs_get_tcp_session()
1843 tcp_ses->tcpStatus = CifsNeedNegotiate; in cifs_get_tcp_session()
1844 spin_unlock(&tcp_ses->srv_lock); in cifs_get_tcp_session()
1846 if ((ctx->max_credits < 20) || (ctx->max_credits > 60000)) in cifs_get_tcp_session()
1847 tcp_ses->max_credits = SMB2_MAX_CREDITS_AVAILABLE; in cifs_get_tcp_session()
1849 tcp_ses->max_credits = ctx->max_credits; in cifs_get_tcp_session()
1851 tcp_ses->nr_targets = 1; in cifs_get_tcp_session()
1852 tcp_ses->ignore_signature = ctx->ignore_signature; in cifs_get_tcp_session()
1855 list_add(&tcp_ses->tcp_ses_list, &cifs_tcp_ses_list); in cifs_get_tcp_session()
1859 queue_delayed_work(cifsiod_wq, &tcp_ses->echo, tcp_ses->echo_interval); in cifs_get_tcp_session()
1872 cifs_put_tcp_session(tcp_ses->primary_server, false); in cifs_get_tcp_session()
1873 kfree(tcp_ses->hostname); in cifs_get_tcp_session()
1874 kfree(tcp_ses->leaf_fullpath); in cifs_get_tcp_session()
1875 if (tcp_ses->ssocket) { in cifs_get_tcp_session()
1876 sock_release(tcp_ses->ssocket); in cifs_get_tcp_session()
1887 struct TCP_Server_Info *server = ses->server; in match_session()
1890 if (ctx->dfs_root_ses != ses->dfs_root_ses) in match_session()
1897 if (ses->chan_max < ctx->max_channels) in match_session()
1900 ctx_sec = server->ops->select_sectype(server, ctx->sectype); in match_session()
1901 ses_sec = server->ops->select_sectype(server, ses->sectype); in match_session()
1909 if (!uid_eq(ctx->cred_uid, ses->cred_uid)) in match_session()
1916 if (ses->user_name == NULL) { in match_session()
1917 if (!ctx->nullauth) in match_session()
1923 if (strncmp(ses->user_name, in match_session()
1924 ctx->username ? ctx->username : "", in match_session()
1927 if ((ctx->username && strlen(ctx->username) != 0) && in match_session()
1928 ses->password != NULL) { in match_session()
1936 if (ses->password2 != NULL && ctx->password2 != NULL) { in match_session()
1937 if (!((strncmp(ses->password, ctx->password ? in match_session()
1938 ctx->password : "", CIFS_MAX_PASSWORD_LEN) == 0 && in match_session()
1939 strncmp(ses->password2, ctx->password2, in match_session()
1941 (strncmp(ses->password, ctx->password2, in match_session()
1943 strncmp(ses->password2, ctx->password ? in match_session()
1944 ctx->password : "", CIFS_MAX_PASSWORD_LEN) == 0))) in match_session()
1947 } else if ((ses->password2 == NULL && ctx->password2 != NULL) || in match_session()
1948 (ses->password2 != NULL && ctx->password2 == NULL)) { in match_session()
1952 if (strncmp(ses->password, ctx->password ? in match_session()
1953 ctx->password : "", CIFS_MAX_PASSWORD_LEN)) in match_session()
1959 if (strcmp(ctx->local_nls->charset, ses->local_nls->charset)) in match_session()
1966 * cifs_setup_ipc - helper to setup the IPC tcon for the session
1972 * tcon_ipc. The IPC tcon has the same lifetime as the session.
1978 struct cifs_tcon *tcon; in cifs_setup_ipc() local
1981 struct TCP_Server_Info *server = ses->server; in cifs_setup_ipc()
1987 if (ctx->seal) { in cifs_setup_ipc()
1988 if (server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION) in cifs_setup_ipc()
1993 return -EOPNOTSUPP; in cifs_setup_ipc()
1998 tcon = tcon_info_alloc(false, netfs_trace_tcon_ref_new_ipc); in cifs_setup_ipc()
1999 if (tcon == NULL) in cifs_setup_ipc()
2000 return -ENOMEM; in cifs_setup_ipc()
2002 spin_lock(&server->srv_lock); in cifs_setup_ipc()
2003 scnprintf(unc, sizeof(unc), "\\\\%s\\IPC$", server->hostname); in cifs_setup_ipc()
2004 spin_unlock(&server->srv_lock); in cifs_setup_ipc()
2007 tcon->ses = ses; in cifs_setup_ipc()
2008 tcon->ipc = true; in cifs_setup_ipc()
2009 tcon->seal = seal; in cifs_setup_ipc()
2010 rc = server->ops->tree_connect(xid, ses, unc, tcon, ctx->local_nls); in cifs_setup_ipc()
2015 tconInfoFree(tcon, netfs_trace_tcon_ref_free_ipc_fail); in cifs_setup_ipc()
2019 cifs_dbg(FYI, "IPC tcon rc=%d ipc tid=0x%x\n", rc, tcon->tid); in cifs_setup_ipc()
2021 spin_lock(&tcon->tc_lock); in cifs_setup_ipc()
2022 tcon->status = TID_GOOD; in cifs_setup_ipc()
2023 spin_unlock(&tcon->tc_lock); in cifs_setup_ipc()
2024 ses->tcon_ipc = tcon; in cifs_setup_ipc()
2035 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { in cifs_find_smb_ses()
2036 spin_lock(&ses->ses_lock); in cifs_find_smb_ses()
2037 if (ses->ses_status == SES_EXITING) { in cifs_find_smb_ses()
2038 spin_unlock(&ses->ses_lock); in cifs_find_smb_ses()
2041 spin_lock(&ses->chan_lock); in cifs_find_smb_ses()
2043 spin_unlock(&ses->chan_lock); in cifs_find_smb_ses()
2044 spin_unlock(&ses->ses_lock); in cifs_find_smb_ses()
2048 spin_unlock(&ses->chan_lock); in cifs_find_smb_ses()
2049 spin_unlock(&ses->ses_lock); in cifs_find_smb_ses()
2059 struct TCP_Server_Info *server = ses->server; in __cifs_put_smb_ses()
2060 struct cifs_tcon *tcon; in __cifs_put_smb_ses() local
2067 spin_lock(&ses->ses_lock); in __cifs_put_smb_ses()
2069 __func__, ses->Suid, ses->ses_count, ses->ses_status, in __cifs_put_smb_ses()
2070 ses->tcon_ipc ? ses->tcon_ipc->tree_name : "none"); in __cifs_put_smb_ses()
2071 if (ses->ses_status == SES_EXITING || --ses->ses_count > 0) { in __cifs_put_smb_ses()
2072 spin_unlock(&ses->ses_lock); in __cifs_put_smb_ses()
2077 WARN_ON(ses->ses_count < 0); in __cifs_put_smb_ses()
2079 spin_lock(&ses->chan_lock); in __cifs_put_smb_ses()
2081 spin_unlock(&ses->chan_lock); in __cifs_put_smb_ses()
2083 do_logoff = ses->ses_status == SES_GOOD && server->ops->logoff; in __cifs_put_smb_ses()
2084 ses->ses_status = SES_EXITING; in __cifs_put_smb_ses()
2085 tcon = ses->tcon_ipc; in __cifs_put_smb_ses()
2086 ses->tcon_ipc = NULL; in __cifs_put_smb_ses()
2087 spin_unlock(&ses->ses_lock); in __cifs_put_smb_ses()
2095 * files on session close, as specified in MS-SMB2 3.3.5.6 Receiving an in __cifs_put_smb_ses()
2098 tconInfoFree(tcon, netfs_trace_tcon_ref_free_ipc); in __cifs_put_smb_ses()
2101 rc = server->ops->logoff(xid, ses); in __cifs_put_smb_ses()
2109 list_del_init(&ses->smb_ses_list); in __cifs_put_smb_ses()
2113 for (i = 1; i < ses->chan_count; i++) { in __cifs_put_smb_ses()
2114 if (ses->chans[i].iface) { in __cifs_put_smb_ses()
2115 kref_put(&ses->chans[i].iface->refcount, release_iface); in __cifs_put_smb_ses()
2116 ses->chans[i].iface = NULL; in __cifs_put_smb_ses()
2118 cifs_put_tcp_session(ses->chans[i].server, 0); in __cifs_put_smb_ses()
2119 ses->chans[i].server = NULL; in __cifs_put_smb_ses()
2122 /* we now account for primary channel in iface->refcount */ in __cifs_put_smb_ses()
2123 if (ses->chans[0].iface) { in __cifs_put_smb_ses()
2124 kref_put(&ses->chans[0].iface->refcount, release_iface); in __cifs_put_smb_ses()
2125 ses->chans[0].server = NULL; in __cifs_put_smb_ses()
2147 struct TCP_Server_Info *server = ses->server; in cifs_set_cifscreds()
2154 return -ENOMEM; in cifs_set_cifscreds()
2157 switch (server->dstaddr.ss_family) { in cifs_set_cifscreds()
2159 sa = (struct sockaddr_in *)&server->dstaddr; in cifs_set_cifscreds()
2160 sprintf(desc, "cifs:a:%pI4", &sa->sin_addr.s_addr); in cifs_set_cifscreds()
2163 sa6 = (struct sockaddr_in6 *)&server->dstaddr; in cifs_set_cifscreds()
2164 sprintf(desc, "cifs:a:%pI6c", &sa6->sin6_addr.s6_addr); in cifs_set_cifscreds()
2168 server->dstaddr.ss_family); in cifs_set_cifscreds()
2169 rc = -EINVAL; in cifs_set_cifscreds()
2176 if (!ses->domainName) { in cifs_set_cifscreds()
2183 sprintf(desc, "cifs:d:%s", ses->domainName); in cifs_set_cifscreds()
2193 down_read(&key->sem); in cifs_set_cifscreds()
2196 rc = upayload ? PTR_ERR(upayload) : -EINVAL; in cifs_set_cifscreds()
2201 payload = upayload->data; in cifs_set_cifscreds()
2202 delim = strnchr(payload, upayload->datalen, ':'); in cifs_set_cifscreds()
2206 upayload->datalen); in cifs_set_cifscreds()
2207 rc = -EINVAL; in cifs_set_cifscreds()
2211 len = delim - payload; in cifs_set_cifscreds()
2215 rc = -EINVAL; in cifs_set_cifscreds()
2219 ctx->username = kstrndup(payload, len, GFP_KERNEL); in cifs_set_cifscreds()
2220 if (!ctx->username) { in cifs_set_cifscreds()
2223 rc = -ENOMEM; in cifs_set_cifscreds()
2226 cifs_dbg(FYI, "%s: username=%s\n", __func__, ctx->username); in cifs_set_cifscreds()
2228 len = key->datalen - (len + 1); in cifs_set_cifscreds()
2231 rc = -EINVAL; in cifs_set_cifscreds()
2232 kfree(ctx->username); in cifs_set_cifscreds()
2233 ctx->username = NULL; in cifs_set_cifscreds()
2239 ctx->password = kstrndup(delim, len, GFP_KERNEL); in cifs_set_cifscreds()
2240 if (!ctx->password) { in cifs_set_cifscreds()
2243 rc = -ENOMEM; in cifs_set_cifscreds()
2244 kfree(ctx->username); in cifs_set_cifscreds()
2245 ctx->username = NULL; in cifs_set_cifscreds()
2253 if (is_domain && ses->domainName) { in cifs_set_cifscreds()
2254 ctx->domainname = kstrdup(ses->domainName, GFP_KERNEL); in cifs_set_cifscreds()
2255 if (!ctx->domainname) { in cifs_set_cifscreds()
2258 rc = -ENOMEM; in cifs_set_cifscreds()
2259 kfree(ctx->username); in cifs_set_cifscreds()
2260 ctx->username = NULL; in cifs_set_cifscreds()
2261 kfree_sensitive(ctx->password); in cifs_set_cifscreds()
2262 /* no need to free ctx->password2 since not allocated in this path */ in cifs_set_cifscreds()
2263 ctx->password = NULL; in cifs_set_cifscreds()
2268 strscpy(ctx->workstation_name, ses->workstation_name, sizeof(ctx->workstation_name)); in cifs_set_cifscreds()
2271 up_read(&key->sem); in cifs_set_cifscreds()
2283 return -ENOSYS; in cifs_set_cifscreds()
2288 * cifs_get_smb_ses - get a session matching @ctx data from @server
2303 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; in cifs_get_smb_ses()
2304 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; in cifs_get_smb_ses()
2311 ses->ses_status); in cifs_get_smb_ses()
2313 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2315 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2318 mutex_lock(&ses->session_mutex); in cifs_get_smb_ses()
2323 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2324 /* problem -- put our ses reference */ in cifs_get_smb_ses()
2331 ctx->local_nls); in cifs_get_smb_ses()
2333 if (((rc == -EACCES) || (rc == -EKEYEXPIRED) || in cifs_get_smb_ses()
2334 (rc == -EKEYREVOKED)) && !retries && ses->password2) { in cifs_get_smb_ses()
2337 swap(ses->password, ses->password2); in cifs_get_smb_ses()
2340 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2341 /* problem -- put our reference */ in cifs_get_smb_ses()
2346 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2348 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2350 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2358 rc = -ENOMEM; in cifs_get_smb_ses()
2366 ses->server = server; in cifs_get_smb_ses()
2367 if (server->dstaddr.ss_family == AF_INET6) in cifs_get_smb_ses()
2368 sprintf(ses->ip_addr, "%pI6", &addr6->sin6_addr); in cifs_get_smb_ses()
2370 sprintf(ses->ip_addr, "%pI4", &addr->sin_addr); in cifs_get_smb_ses()
2372 if (ctx->username) { in cifs_get_smb_ses()
2373 ses->user_name = kstrdup(ctx->username, GFP_KERNEL); in cifs_get_smb_ses()
2374 if (!ses->user_name) in cifs_get_smb_ses()
2378 /* ctx->password freed at unmount */ in cifs_get_smb_ses()
2379 if (ctx->password) { in cifs_get_smb_ses()
2380 ses->password = kstrdup(ctx->password, GFP_KERNEL); in cifs_get_smb_ses()
2381 if (!ses->password) in cifs_get_smb_ses()
2384 /* ctx->password freed at unmount */ in cifs_get_smb_ses()
2385 if (ctx->password2) { in cifs_get_smb_ses()
2386 ses->password2 = kstrdup(ctx->password2, GFP_KERNEL); in cifs_get_smb_ses()
2387 if (!ses->password2) in cifs_get_smb_ses()
2390 if (ctx->domainname) { in cifs_get_smb_ses()
2391 ses->domainName = kstrdup(ctx->domainname, GFP_KERNEL); in cifs_get_smb_ses()
2392 if (!ses->domainName) in cifs_get_smb_ses()
2396 strscpy(ses->workstation_name, ctx->workstation_name, sizeof(ses->workstation_name)); in cifs_get_smb_ses()
2398 if (ctx->domainauto) in cifs_get_smb_ses()
2399 ses->domainAuto = ctx->domainauto; in cifs_get_smb_ses()
2400 ses->cred_uid = ctx->cred_uid; in cifs_get_smb_ses()
2401 ses->linux_uid = ctx->linux_uid; in cifs_get_smb_ses()
2403 ses->sectype = ctx->sectype; in cifs_get_smb_ses()
2404 ses->sign = ctx->sign; in cifs_get_smb_ses()
2405 ses->local_nls = load_nls(ctx->local_nls->charset); in cifs_get_smb_ses()
2407 /* add server as first channel */ in cifs_get_smb_ses()
2408 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2409 ses->chans[0].server = server; in cifs_get_smb_ses()
2410 ses->chan_count = 1; in cifs_get_smb_ses()
2411 ses->chan_max = ctx->multichannel ? ctx->max_channels:1; in cifs_get_smb_ses()
2412 ses->chans_need_reconnect = 1; in cifs_get_smb_ses()
2413 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2416 mutex_lock(&ses->session_mutex); in cifs_get_smb_ses()
2419 rc = cifs_setup_session(xid, ses, server, ctx->local_nls); in cifs_get_smb_ses()
2420 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2422 /* each channel uses a different signing key */ in cifs_get_smb_ses()
2423 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2424 memcpy(ses->chans[0].signkey, ses->smb3signingkey, in cifs_get_smb_ses()
2425 sizeof(ses->smb3signingkey)); in cifs_get_smb_ses()
2426 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2429 if (((rc == -EACCES) || (rc == -EKEYEXPIRED) || in cifs_get_smb_ses()
2430 (rc == -EKEYREVOKED)) && !retries && ses->password2) { in cifs_get_smb_ses()
2433 swap(ses->password, ses->password2); in cifs_get_smb_ses()
2440 * success, put it on the list and add it as first channel in cifs_get_smb_ses()
2445 if (ctx->dfs_root_ses) in cifs_get_smb_ses()
2446 cifs_smb_ses_inc_refcount(ctx->dfs_root_ses); in cifs_get_smb_ses()
2447 ses->dfs_root_ses = ctx->dfs_root_ses; in cifs_get_smb_ses()
2448 list_add(&ses->smb_ses_list, &server->smb_ses_list); in cifs_get_smb_ses()
2464 static int match_tcon(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) in match_tcon() argument
2466 struct TCP_Server_Info *server = tcon->ses->server; in match_tcon()
2468 if (tcon->status == TID_EXITING) in match_tcon()
2471 if (tcon->origin_fullpath) { in match_tcon()
2472 if (!ctx->source || in match_tcon()
2473 !dfs_src_pathname_equal(ctx->source, in match_tcon()
2474 tcon->origin_fullpath)) in match_tcon()
2476 } else if (!server->leaf_fullpath && in match_tcon()
2477 strncmp(tcon->tree_name, ctx->UNC, MAX_TREE_SIZE)) { in match_tcon()
2480 if (tcon->seal != ctx->seal) in match_tcon()
2482 if (tcon->snapshot_time != ctx->snapshot_time) in match_tcon()
2484 if (tcon->handle_timeout != ctx->handle_timeout) in match_tcon()
2486 if (tcon->no_lease != ctx->no_lease) in match_tcon()
2488 if (tcon->nodelete != ctx->nodelete) in match_tcon()
2496 struct cifs_tcon *tcon; in cifs_find_tcon() local
2499 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { in cifs_find_tcon()
2500 spin_lock(&tcon->tc_lock); in cifs_find_tcon()
2501 if (!match_tcon(tcon, ctx)) { in cifs_find_tcon()
2502 spin_unlock(&tcon->tc_lock); in cifs_find_tcon()
2505 ++tcon->tc_count; in cifs_find_tcon()
2506 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count, in cifs_find_tcon()
2508 spin_unlock(&tcon->tc_lock); in cifs_find_tcon()
2510 return tcon; in cifs_find_tcon()
2517 cifs_put_tcon(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace) in cifs_put_tcon() argument
2523 * IPC tcon share the lifetime of their session and are in cifs_put_tcon()
2526 if (tcon == NULL || tcon->ipc) in cifs_put_tcon()
2529 ses = tcon->ses; in cifs_put_tcon()
2530 cifs_dbg(FYI, "%s: tc_count=%d\n", __func__, tcon->tc_count); in cifs_put_tcon()
2532 spin_lock(&tcon->tc_lock); in cifs_put_tcon()
2533 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count - 1, trace); in cifs_put_tcon()
2534 if (--tcon->tc_count > 0) { in cifs_put_tcon()
2535 spin_unlock(&tcon->tc_lock); in cifs_put_tcon()
2541 WARN_ON(tcon->tc_count < 0); in cifs_put_tcon()
2543 list_del_init(&tcon->tcon_list); in cifs_put_tcon()
2544 tcon->status = TID_EXITING; in cifs_put_tcon()
2545 spin_unlock(&tcon->tc_lock); in cifs_put_tcon()
2549 cancel_delayed_work_sync(&tcon->query_interfaces); in cifs_put_tcon()
2551 cancel_delayed_work_sync(&tcon->dfs_cache_work); in cifs_put_tcon()
2554 if (tcon->use_witness) { in cifs_put_tcon()
2557 rc = cifs_swn_unregister(tcon); in cifs_put_tcon()
2565 if (ses->server->ops->tree_disconnect) in cifs_put_tcon()
2566 ses->server->ops->tree_disconnect(xid, tcon); in cifs_put_tcon()
2569 cifs_fscache_release_super_cookie(tcon); in cifs_put_tcon()
2570 tconInfoFree(tcon, netfs_trace_tcon_ref_free); in cifs_put_tcon()
2575 * cifs_get_tcon - get a tcon matching @ctx data from @ses
2579 * - tcon refcount is the number of mount points using the tcon.
2580 * - ses refcount is the number of tcon using the session.
2588 * a) a new tcon already allocated with refcount=1 (1 mount point) and
2589 * its session refcount incremented (1 new tcon). This +1 was
2592 * b) an existing tcon with refcount+1 (add a mount point to it) and
2593 * identical ses refcount (no new tcon). Because of (1) we need to
2599 struct cifs_tcon *tcon; in cifs_get_tcon() local
2603 tcon = cifs_find_tcon(ses, ctx); in cifs_get_tcon()
2604 if (tcon) { in cifs_get_tcon()
2606 * tcon has refcount already incremented but we need to in cifs_get_tcon()
2611 return tcon; in cifs_get_tcon()
2614 if (!ses->server->ops->tree_connect) { in cifs_get_tcon()
2615 rc = -ENOSYS; in cifs_get_tcon()
2619 if (ses->server->dialect >= SMB20_PROT_ID && in cifs_get_tcon()
2620 (ses->server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING)) in cifs_get_tcon()
2621 nohandlecache = ctx->nohandlecache || !dir_cache_timeout; in cifs_get_tcon()
2624 tcon = tcon_info_alloc(!nohandlecache, netfs_trace_tcon_ref_new); in cifs_get_tcon()
2625 if (tcon == NULL) { in cifs_get_tcon()
2626 rc = -ENOMEM; in cifs_get_tcon()
2629 tcon->nohandlecache = nohandlecache; in cifs_get_tcon()
2631 if (ctx->snapshot_time) { in cifs_get_tcon()
2632 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2635 rc = -EOPNOTSUPP; in cifs_get_tcon()
2638 tcon->snapshot_time = ctx->snapshot_time; in cifs_get_tcon()
2641 if (ctx->handle_timeout) { in cifs_get_tcon()
2642 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2645 rc = -EOPNOTSUPP; in cifs_get_tcon()
2648 tcon->handle_timeout = ctx->handle_timeout; in cifs_get_tcon()
2651 tcon->ses = ses; in cifs_get_tcon()
2652 if (ctx->password) { in cifs_get_tcon()
2653 tcon->password = kstrdup(ctx->password, GFP_KERNEL); in cifs_get_tcon()
2654 if (!tcon->password) { in cifs_get_tcon()
2655 rc = -ENOMEM; in cifs_get_tcon()
2660 if (ctx->seal) { in cifs_get_tcon()
2661 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2664 rc = -EOPNOTSUPP; in cifs_get_tcon()
2666 } else if (tcon->ses->server->capabilities & in cifs_get_tcon()
2668 tcon->seal = true; in cifs_get_tcon()
2671 rc = -EOPNOTSUPP; in cifs_get_tcon()
2676 if (ctx->linux_ext) { in cifs_get_tcon()
2677 if (ses->server->posix_ext_supported) { in cifs_get_tcon()
2678 tcon->posix_extensions = true; in cifs_get_tcon()
2680 } else if ((ses->server->vals->protocol_id == SMB311_PROT_ID) || in cifs_get_tcon()
2681 (strcmp(ses->server->vals->version_string, in cifs_get_tcon()
2683 (strcmp(ses->server->vals->version_string, in cifs_get_tcon()
2686 rc = -EOPNOTSUPP; in cifs_get_tcon()
2688 } else if (ses->server->vals->protocol_id == SMB10_PROT_ID) in cifs_get_tcon()
2693 rc = -EOPNOTSUPP; in cifs_get_tcon()
2698 rc = -EOPNOTSUPP; in cifs_get_tcon()
2704 rc = ses->server->ops->tree_connect(xid, ses, ctx->UNC, tcon, in cifs_get_tcon()
2705 ctx->local_nls); in cifs_get_tcon()
2707 cifs_dbg(FYI, "Tcon rc = %d\n", rc); in cifs_get_tcon()
2711 tcon->use_persistent = false; in cifs_get_tcon()
2713 if (ctx->persistent) { in cifs_get_tcon()
2714 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2717 rc = -EOPNOTSUPP; in cifs_get_tcon()
2719 } else if (ses->server->capabilities & in cifs_get_tcon()
2721 tcon->use_persistent = true; in cifs_get_tcon()
2725 rc = -EOPNOTSUPP; in cifs_get_tcon()
2728 } else if ((tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) in cifs_get_tcon()
2729 && (ses->server->capabilities & SMB2_GLOBAL_CAP_PERSISTENT_HANDLES) in cifs_get_tcon()
2730 && (ctx->nopersistent == false)) { in cifs_get_tcon()
2732 tcon->use_persistent = true; in cifs_get_tcon()
2733 } else if (ctx->resilient) { in cifs_get_tcon()
2734 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2737 rc = -EOPNOTSUPP; in cifs_get_tcon()
2740 tcon->use_resilient = true; in cifs_get_tcon()
2743 tcon->use_witness = false; in cifs_get_tcon()
2744 if (IS_ENABLED(CONFIG_CIFS_SWN_UPCALL) && ctx->witness) { in cifs_get_tcon()
2745 if (ses->server->vals->protocol_id >= SMB30_PROT_ID) { in cifs_get_tcon()
2746 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) { in cifs_get_tcon()
2751 tcon->use_witness = true; in cifs_get_tcon()
2753 rc = cifs_swn_register(tcon); in cifs_get_tcon()
2759 /* TODO: try to extend for non-cluster uses (eg multichannel) */ in cifs_get_tcon()
2761 rc = -EOPNOTSUPP; in cifs_get_tcon()
2766 rc = -EOPNOTSUPP; in cifs_get_tcon()
2772 if (tcon->share_flags & SMB2_SHAREFLAG_NO_CACHING) { in cifs_get_tcon()
2773 if (ctx->cache_ro) in cifs_get_tcon()
2775 else if (ctx->cache_rw) in cifs_get_tcon()
2779 if (ctx->no_lease) { in cifs_get_tcon()
2780 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2783 rc = -EOPNOTSUPP; in cifs_get_tcon()
2786 tcon->no_lease = ctx->no_lease; in cifs_get_tcon()
2794 tcon->retry = ctx->retry; in cifs_get_tcon()
2795 tcon->nocase = ctx->nocase; in cifs_get_tcon()
2796 tcon->broken_sparse_sup = ctx->no_sparse; in cifs_get_tcon()
2797 tcon->max_cached_dirs = ctx->max_cached_dirs; in cifs_get_tcon()
2798 tcon->nodelete = ctx->nodelete; in cifs_get_tcon()
2799 tcon->local_lease = ctx->local_lease; in cifs_get_tcon()
2800 INIT_LIST_HEAD(&tcon->pending_opens); in cifs_get_tcon()
2801 tcon->status = TID_GOOD; in cifs_get_tcon()
2803 INIT_DELAYED_WORK(&tcon->query_interfaces, in cifs_get_tcon()
2805 if (ses->server->dialect >= SMB30_PROT_ID && in cifs_get_tcon()
2806 (ses->server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL)) { in cifs_get_tcon()
2808 queue_delayed_work(cifsiod_wq, &tcon->query_interfaces, in cifs_get_tcon()
2812 INIT_DELAYED_WORK(&tcon->dfs_cache_work, dfs_cache_refresh); in cifs_get_tcon()
2815 list_add(&tcon->tcon_list, &ses->tcon_list); in cifs_get_tcon()
2818 return tcon; in cifs_get_tcon()
2821 tconInfoFree(tcon, netfs_trace_tcon_ref_free_fail); in cifs_get_tcon()
2831 if (!atomic_dec_and_test(&tlink->tl_count) || in cifs_put_tlink()
2832 test_bit(TCON_LINK_IN_TREE, &tlink->tl_flags)) { in cifs_put_tlink()
2833 tlink->tl_time = jiffies; in cifs_put_tlink()
2846 struct cifs_sb_info *new = mnt_data->cifs_sb; in compare_mount_options()
2847 unsigned int oldflags = old->mnt_cifs_flags & CIFS_MOUNT_MASK; in compare_mount_options()
2848 unsigned int newflags = new->mnt_cifs_flags & CIFS_MOUNT_MASK; in compare_mount_options()
2850 if ((sb->s_flags & CIFS_MS_MASK) != (mnt_data->flags & CIFS_MS_MASK)) in compare_mount_options()
2853 if (old->mnt_cifs_serverino_autodisabled) in compare_mount_options()
2863 if (new->ctx->wsize && new->ctx->wsize < old->ctx->wsize) in compare_mount_options()
2866 if (new->ctx->rsize && new->ctx->rsize < old->ctx->rsize) in compare_mount_options()
2869 if (!uid_eq(old->ctx->linux_uid, new->ctx->linux_uid) || in compare_mount_options()
2870 !gid_eq(old->ctx->linux_gid, new->ctx->linux_gid)) in compare_mount_options()
2873 if (old->ctx->file_mode != new->ctx->file_mode || in compare_mount_options()
2874 old->ctx->dir_mode != new->ctx->dir_mode) in compare_mount_options()
2877 if (strcmp(old->local_nls->charset, new->local_nls->charset)) in compare_mount_options()
2880 if (old->ctx->acregmax != new->ctx->acregmax) in compare_mount_options()
2882 if (old->ctx->acdirmax != new->ctx->acdirmax) in compare_mount_options()
2884 if (old->ctx->closetimeo != new->ctx->closetimeo) in compare_mount_options()
2886 if (old->ctx->reparse_type != new->ctx->reparse_type) in compare_mount_options()
2893 struct cifs_tcon *tcon, in match_prepath() argument
2896 struct smb3_fs_context *ctx = mnt_data->ctx; in match_prepath()
2898 struct cifs_sb_info *new = mnt_data->cifs_sb; in match_prepath()
2899 bool old_set = (old->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH) && in match_prepath()
2900 old->prepath; in match_prepath()
2901 bool new_set = (new->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH) && in match_prepath()
2902 new->prepath; in match_prepath()
2904 if (tcon->origin_fullpath && in match_prepath()
2905 dfs_src_pathname_equal(tcon->origin_fullpath, ctx->source)) in match_prepath()
2908 if (old_set && new_set && !strcmp(new->prepath, old->prepath)) in match_prepath()
2924 struct cifs_tcon *tcon; in cifs_match_super() local
2932 if (CIFS_MOUNT_SHUTDOWN & cifs_sb->mnt_cifs_flags) { in cifs_match_super()
2944 tcon = tlink_tcon(tlink); in cifs_match_super()
2945 ses = tcon->ses; in cifs_match_super()
2946 tcp_srv = ses->server; in cifs_match_super()
2948 ctx = mnt_data->ctx; in cifs_match_super()
2950 spin_lock(&tcp_srv->srv_lock); in cifs_match_super()
2951 spin_lock(&ses->ses_lock); in cifs_match_super()
2952 spin_lock(&ses->chan_lock); in cifs_match_super()
2953 spin_lock(&tcon->tc_lock); in cifs_match_super()
2956 !match_tcon(tcon, ctx) || in cifs_match_super()
2957 !match_prepath(sb, tcon, mnt_data)) { in cifs_match_super()
2964 spin_unlock(&tcon->tc_lock); in cifs_match_super()
2965 spin_unlock(&ses->chan_lock); in cifs_match_super()
2966 spin_unlock(&ses->ses_lock); in cifs_match_super()
2967 spin_unlock(&tcp_srv->srv_lock); in cifs_match_super()
2981 struct sock *sk = sock->sk; in cifs_reclassify_socket4()
2984 sock_lock_init_class_and_name(sk, "slock-AF_INET-CIFS", in cifs_reclassify_socket4()
2985 &cifs_slock_key[0], "sk_lock-AF_INET-CIFS", &cifs_key[0]); in cifs_reclassify_socket4()
2991 struct sock *sk = sock->sk; in cifs_reclassify_socket6()
2994 sock_lock_init_class_and_name(sk, "slock-AF_INET6-CIFS", in cifs_reclassify_socket6()
2995 &cifs_slock_key[1], "sk_lock-AF_INET6-CIFS", &cifs_key[1]); in cifs_reclassify_socket6()
3028 if (server->srcaddr.ss_family != AF_UNSPEC) { in bind_socket()
3030 struct socket *socket = server->ssocket; in bind_socket()
3033 (struct sockaddr *) &server->srcaddr, in bind_socket()
3034 sizeof(server->srcaddr)); in bind_socket()
3039 saddr4 = (struct sockaddr_in *)&server->srcaddr; in bind_socket()
3040 saddr6 = (struct sockaddr_in6 *)&server->srcaddr; in bind_socket()
3041 if (saddr6->sin6_family == AF_INET6) in bind_socket()
3043 &saddr6->sin6_addr, rc); in bind_socket()
3046 &saddr4->sin_addr.s_addr, rc); in bind_socket()
3058 * negprot - BB check reconnection in case where second in ip_rfc1001_connect()
3067 if (server->server_RFC1001_name[0] != 0) in ip_rfc1001_connect()
3069 server->server_RFC1001_name, in ip_rfc1001_connect()
3079 if (server->workstation_RFC1001_name[0] != 0) in ip_rfc1001_connect()
3081 server->workstation_RFC1001_name, in ip_rfc1001_connect()
3092 len = sizeof(req) - offsetof(struct rfc1002_session_packet, trailer.session_req); in ip_rfc1001_connect()
3094 smb_buf->smb_buf_length = cpu_to_be32((RFC1002_SESSION_REQUEST << 24) | len); in ip_rfc1001_connect()
3116 saddr = (struct sockaddr *) &server->dstaddr; in generic_ip_connect()
3118 if (server->dstaddr.ss_family == AF_INET6) { in generic_ip_connect()
3119 struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&server->dstaddr; in generic_ip_connect()
3121 sport = ipv6->sin6_port; in generic_ip_connect()
3124 cifs_dbg(FYI, "%s: connecting to [%pI6]:%d\n", __func__, &ipv6->sin6_addr, in generic_ip_connect()
3127 struct sockaddr_in *ipv4 = (struct sockaddr_in *)&server->dstaddr; in generic_ip_connect()
3129 sport = ipv4->sin_port; in generic_ip_connect()
3132 cifs_dbg(FYI, "%s: connecting to %pI4:%d\n", __func__, &ipv4->sin_addr, in generic_ip_connect()
3136 if (server->ssocket) { in generic_ip_connect()
3137 socket = server->ssocket; in generic_ip_connect()
3141 rc = sock_create_kern(net, sfamily, SOCK_STREAM, IPPROTO_TCP, &server->ssocket); in generic_ip_connect()
3157 socket = server->ssocket; in generic_ip_connect()
3158 socket->sk->sk_allocation = GFP_NOFS; in generic_ip_connect()
3159 socket->sk->sk_use_task_frag = false; in generic_ip_connect()
3177 socket->sk->sk_rcvtimeo = 7 * HZ; in generic_ip_connect()
3178 socket->sk->sk_sndtimeo = 5 * HZ; in generic_ip_connect()
3181 if (server->noautotune) { in generic_ip_connect()
3182 if (socket->sk->sk_sndbuf < (200 * 1024)) in generic_ip_connect()
3183 socket->sk->sk_sndbuf = 200 * 1024; in generic_ip_connect()
3184 if (socket->sk->sk_rcvbuf < (140 * 1024)) in generic_ip_connect()
3185 socket->sk->sk_rcvbuf = 140 * 1024; in generic_ip_connect()
3188 if (server->tcp_nodelay) in generic_ip_connect()
3189 tcp_sock_set_nodelay(socket->sk); in generic_ip_connect()
3192 socket->sk->sk_sndbuf, in generic_ip_connect()
3193 socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo); in generic_ip_connect()
3196 server->noblockcnt ? O_NONBLOCK : 0); in generic_ip_connect()
3200 * reconnect failover - if possible. in generic_ip_connect()
3202 if (server->noblockcnt && rc == -EINPROGRESS) in generic_ip_connect()
3206 trace_smb3_connect_err(server->hostname, server->conn_id, &server->dstaddr, rc); in generic_ip_connect()
3209 server->ssocket = NULL; in generic_ip_connect()
3212 trace_smb3_connect_done(server->hostname, server->conn_id, &server->dstaddr); in generic_ip_connect()
3226 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; in ip_connect()
3227 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; in ip_connect()
3229 if (server->dstaddr.ss_family == AF_INET6) in ip_connect()
3230 sport = &addr6->sin6_port; in ip_connect()
3232 sport = &addr->sin_port; in ip_connect()
3252 void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, in reset_cifs_unix_caps() argument
3260 * Perhaps we could add a backpointer to array of sb from tcon in reset_cifs_unix_caps()
3262 * sb as NFS - then we only have one backpointer to sb. in reset_cifs_unix_caps()
3266 __u64 saved_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); in reset_cifs_unix_caps()
3268 if (ctx && ctx->no_linux_ext) { in reset_cifs_unix_caps()
3269 tcon->fsUnixInfo.Capability = 0; in reset_cifs_unix_caps()
3270 tcon->unix_ext = 0; /* Unix Extensions disabled */ in reset_cifs_unix_caps()
3274 tcon->unix_ext = 1; /* Unix Extensions supported */ in reset_cifs_unix_caps()
3276 if (!tcon->unix_ext) { in reset_cifs_unix_caps()
3281 if (!CIFSSMBQFSUnixInfo(xid, tcon)) { in reset_cifs_unix_caps()
3282 __u64 cap = le64_to_cpu(tcon->fsUnixInfo.Capability); in reset_cifs_unix_caps()
3307 cifs_dbg(VFS, "per-share encryption not supported yet\n"); in reset_cifs_unix_caps()
3310 if (ctx && ctx->no_psx_acl) in reset_cifs_unix_caps()
3315 cifs_sb->mnt_cifs_flags |= in reset_cifs_unix_caps()
3319 if (ctx && ctx->posix_paths == 0) in reset_cifs_unix_caps()
3324 cifs_sb->mnt_cifs_flags |= in reset_cifs_unix_caps()
3349 if (CIFSSMBSetFSUnixInfo(xid, tcon, cap)) { in reset_cifs_unix_caps()
3362 struct smb3_fs_context *ctx = cifs_sb->ctx; in cifs_setup_cifs_sb()
3364 INIT_DELAYED_WORK(&cifs_sb->prune_tlinks, cifs_prune_tlinks); in cifs_setup_cifs_sb()
3366 spin_lock_init(&cifs_sb->tlink_tree_lock); in cifs_setup_cifs_sb()
3367 cifs_sb->tlink_tree = RB_ROOT; in cifs_setup_cifs_sb()
3370 ctx->file_mode, ctx->dir_mode); in cifs_setup_cifs_sb()
3373 if (ctx->iocharset == NULL) { in cifs_setup_cifs_sb()
3375 cifs_sb->local_nls = load_nls_default(); in cifs_setup_cifs_sb()
3377 cifs_sb->local_nls = load_nls(ctx->iocharset); in cifs_setup_cifs_sb()
3378 if (cifs_sb->local_nls == NULL) { in cifs_setup_cifs_sb()
3380 ctx->iocharset); in cifs_setup_cifs_sb()
3381 return -ELIBACC; in cifs_setup_cifs_sb()
3384 ctx->local_nls = cifs_sb->local_nls; in cifs_setup_cifs_sb()
3388 if (ctx->direct_io) in cifs_setup_cifs_sb()
3390 if (ctx->cache_ro) { in cifs_setup_cifs_sb()
3392 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RO_CACHE; in cifs_setup_cifs_sb()
3393 } else if (ctx->cache_rw) { in cifs_setup_cifs_sb()
3395 cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_RO_CACHE | in cifs_setup_cifs_sb()
3399 if ((ctx->cifs_acl) && (ctx->dynperm)) in cifs_setup_cifs_sb()
3402 if (ctx->prepath) { in cifs_setup_cifs_sb()
3403 cifs_sb->prepath = kstrdup(ctx->prepath, GFP_KERNEL); in cifs_setup_cifs_sb()
3404 if (cifs_sb->prepath == NULL) in cifs_setup_cifs_sb()
3405 return -ENOMEM; in cifs_setup_cifs_sb()
3406 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH; in cifs_setup_cifs_sb()
3417 if (mnt_ctx->tcon) in cifs_mount_put_conns()
3418 cifs_put_tcon(mnt_ctx->tcon, netfs_trace_tcon_ref_put_mnt_ctx); in cifs_mount_put_conns()
3419 else if (mnt_ctx->ses) in cifs_mount_put_conns()
3420 cifs_put_smb_ses(mnt_ctx->ses); in cifs_mount_put_conns()
3421 else if (mnt_ctx->server) in cifs_mount_put_conns()
3422 cifs_put_tcp_session(mnt_ctx->server, 0); in cifs_mount_put_conns()
3423 mnt_ctx->ses = NULL; in cifs_mount_put_conns()
3424 mnt_ctx->tcon = NULL; in cifs_mount_put_conns()
3425 mnt_ctx->server = NULL; in cifs_mount_put_conns()
3426 mnt_ctx->cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_POSIX_PATHS; in cifs_mount_put_conns()
3427 free_xid(mnt_ctx->xid); in cifs_mount_put_conns()
3440 if (WARN_ON_ONCE(!mnt_ctx || !mnt_ctx->fs_ctx)) { in cifs_mount_get_session()
3441 rc = -EINVAL; in cifs_mount_get_session()
3444 ctx = mnt_ctx->fs_ctx; in cifs_mount_get_session()
3462 if ((ctx->persistent == true) && (!(ses->server->capabilities & in cifs_mount_get_session()
3465 rc = -EOPNOTSUPP; in cifs_mount_get_session()
3469 mnt_ctx->xid = xid; in cifs_mount_get_session()
3470 mnt_ctx->server = server; in cifs_mount_get_session()
3471 mnt_ctx->ses = ses; in cifs_mount_get_session()
3472 mnt_ctx->tcon = NULL; in cifs_mount_get_session()
3482 struct cifs_tcon *tcon = NULL; in cifs_mount_get_tcon() local
3485 if (WARN_ON_ONCE(!mnt_ctx || !mnt_ctx->server || !mnt_ctx->ses || !mnt_ctx->fs_ctx || in cifs_mount_get_tcon()
3486 !mnt_ctx->cifs_sb)) { in cifs_mount_get_tcon()
3487 rc = -EINVAL; in cifs_mount_get_tcon()
3490 server = mnt_ctx->server; in cifs_mount_get_tcon()
3491 ctx = mnt_ctx->fs_ctx; in cifs_mount_get_tcon()
3492 cifs_sb = mnt_ctx->cifs_sb; in cifs_mount_get_tcon()
3494 /* search for existing tcon to this server share */ in cifs_mount_get_tcon()
3495 tcon = cifs_get_tcon(mnt_ctx->ses, ctx); in cifs_mount_get_tcon()
3496 if (IS_ERR(tcon)) { in cifs_mount_get_tcon()
3497 rc = PTR_ERR(tcon); in cifs_mount_get_tcon()
3498 tcon = NULL; in cifs_mount_get_tcon()
3503 if (tcon->posix_extensions) in cifs_mount_get_tcon()
3504 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_POSIX_PATHS; in cifs_mount_get_tcon()
3508 if (cap_unix(tcon->ses)) { in cifs_mount_get_tcon()
3513 reset_cifs_unix_caps(mnt_ctx->xid, tcon, cifs_sb, ctx); in cifs_mount_get_tcon()
3514 spin_lock(&tcon->ses->server->srv_lock); in cifs_mount_get_tcon()
3515 if ((tcon->ses->server->tcpStatus == CifsNeedReconnect) && in cifs_mount_get_tcon()
3516 (le64_to_cpu(tcon->fsUnixInfo.Capability) & in cifs_mount_get_tcon()
3518 spin_unlock(&tcon->ses->server->srv_lock); in cifs_mount_get_tcon()
3519 rc = -EACCES; in cifs_mount_get_tcon()
3522 spin_unlock(&tcon->ses->server->srv_lock); in cifs_mount_get_tcon()
3525 tcon->unix_ext = 0; /* server does not support them */ in cifs_mount_get_tcon()
3527 /* do not care if a following call succeed - informational */ in cifs_mount_get_tcon()
3528 if (!tcon->pipe && server->ops->qfs_tcon) { in cifs_mount_get_tcon()
3529 server->ops->qfs_tcon(mnt_ctx->xid, tcon, cifs_sb); in cifs_mount_get_tcon()
3530 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RO_CACHE) { in cifs_mount_get_tcon()
3531 if (tcon->fsDevInfo.DeviceCharacteristics & in cifs_mount_get_tcon()
3534 else if ((cifs_sb->mnt_cifs_flags & in cifs_mount_get_tcon()
3546 if ((cifs_sb->ctx->wsize == 0) || in cifs_mount_get_tcon()
3547 (cifs_sb->ctx->wsize > server->ops->negotiate_wsize(tcon, ctx))) { in cifs_mount_get_tcon()
3548 cifs_sb->ctx->wsize = in cifs_mount_get_tcon()
3549 round_down(server->ops->negotiate_wsize(tcon, ctx), PAGE_SIZE); in cifs_mount_get_tcon()
3554 if (cifs_sb->ctx->wsize == 0) { in cifs_mount_get_tcon()
3555 cifs_sb->ctx->wsize = PAGE_SIZE; in cifs_mount_get_tcon()
3559 if ((cifs_sb->ctx->rsize == 0) || in cifs_mount_get_tcon()
3560 (cifs_sb->ctx->rsize > server->ops->negotiate_rsize(tcon, ctx))) in cifs_mount_get_tcon()
3561 cifs_sb->ctx->rsize = server->ops->negotiate_rsize(tcon, ctx); in cifs_mount_get_tcon()
3568 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE) in cifs_mount_get_tcon()
3569 cifs_fscache_get_super_cookie(tcon); in cifs_mount_get_tcon()
3572 mnt_ctx->tcon = tcon; in cifs_mount_get_tcon()
3577 struct cifs_tcon *tcon) in mount_setup_tlink() argument
3581 /* hang the tcon off of the superblock */ in mount_setup_tlink()
3584 return -ENOMEM; in mount_setup_tlink()
3586 tlink->tl_uid = ses->linux_uid; in mount_setup_tlink()
3587 tlink->tl_tcon = tcon; in mount_setup_tlink()
3588 tlink->tl_time = jiffies; in mount_setup_tlink()
3589 set_bit(TCON_LINK_MASTER, &tlink->tl_flags); in mount_setup_tlink()
3590 set_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); in mount_setup_tlink()
3592 cifs_sb->master_tlink = tlink; in mount_setup_tlink()
3593 spin_lock(&cifs_sb->tlink_tree_lock); in mount_setup_tlink()
3594 tlink_rb_insert(&cifs_sb->tlink_tree, tlink); in mount_setup_tlink()
3595 spin_unlock(&cifs_sb->tlink_tree_lock); in mount_setup_tlink()
3597 queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks, in mount_setup_tlink()
3605 struct cifs_tcon *tcon, in cifs_are_all_path_components_accessible() argument
3618 rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, ""); in cifs_are_all_path_components_accessible()
3637 * temporarily null-terminate the path at the end of in cifs_are_all_path_components_accessible()
3642 rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, in cifs_are_all_path_components_accessible()
3652 * Return -EREMOTE if it is, otherwise 0 or -errno.
3657 struct cifs_sb_info *cifs_sb = mnt_ctx->cifs_sb; in cifs_is_path_remote()
3658 struct TCP_Server_Info *server = mnt_ctx->server; in cifs_is_path_remote()
3659 unsigned int xid = mnt_ctx->xid; in cifs_is_path_remote()
3660 struct cifs_tcon *tcon = mnt_ctx->tcon; in cifs_is_path_remote() local
3661 struct smb3_fs_context *ctx = mnt_ctx->fs_ctx; in cifs_is_path_remote()
3664 if (!server->ops->is_path_accessible) in cifs_is_path_remote()
3665 return -EOPNOTSUPP; in cifs_is_path_remote()
3668 * cifs_build_path_to_root works only when we have a valid tcon in cifs_is_path_remote()
3670 full_path = cifs_build_path_to_root(ctx, cifs_sb, tcon, in cifs_is_path_remote()
3671 tcon->Flags & SMB_SHARE_IS_IN_DFS); in cifs_is_path_remote()
3673 return -ENOMEM; in cifs_is_path_remote()
3677 rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, in cifs_is_path_remote()
3679 if (rc != 0 && rc != -EREMOTE) in cifs_is_path_remote()
3682 if (rc != -EREMOTE) { in cifs_is_path_remote()
3683 rc = cifs_are_all_path_components_accessible(server, xid, tcon, in cifs_is_path_remote()
3684 cifs_sb, full_path, tcon->Flags & SMB_SHARE_IS_IN_DFS); in cifs_is_path_remote()
3687 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH; in cifs_is_path_remote()
3719 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH; in cifs_mount()
3720 kfree(cifs_sb->prepath); in cifs_mount()
3721 cifs_sb->prepath = ctx->prepath; in cifs_mount()
3722 ctx->prepath = NULL; in cifs_mount()
3726 rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon); in cifs_mount()
3754 rc = -EHOSTDOWN; in cifs_mount()
3756 rc = -EACCES; in cifs_mount()
3757 else if (WARN_ON(!mnt_ctx.tcon)) in cifs_mount()
3758 rc = -ENOENT; in cifs_mount()
3764 if (rc == -EREMOTE) in cifs_mount()
3765 rc = -EOPNOTSUPP; in cifs_mount()
3769 rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon); in cifs_mount()
3788 const char *tree, struct cifs_tcon *tcon, in CIFSTCon() argument
3801 return -EIO; in CIFSTCon()
3805 return -ENOMEM; in CIFSTCon()
3812 smb_buffer->Mid = get_next_mid(ses->server); in CIFSTCon()
3813 smb_buffer->Uid = ses->Suid; in CIFSTCon()
3817 pSMB->AndXCommand = 0xFF; in CIFSTCon()
3818 pSMB->Flags = cpu_to_le16(TCON_EXTENDED_SECINFO); in CIFSTCon()
3819 bcc_ptr = &pSMB->Password[0]; in CIFSTCon()
3821 pSMB->PasswordLength = cpu_to_le16(1); /* minimum */ in CIFSTCon()
3826 if (ses->server->sign) in CIFSTCon()
3827 smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; in CIFSTCon()
3829 if (ses->capabilities & CAP_STATUS32) in CIFSTCon()
3830 smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS; in CIFSTCon()
3832 if (ses->capabilities & CAP_DFS) in CIFSTCon()
3833 smb_buffer->Flags2 |= SMBFLG2_DFS; in CIFSTCon()
3835 if (ses->capabilities & CAP_UNICODE) { in CIFSTCon()
3836 smb_buffer->Flags2 |= SMBFLG2_UNICODE; in CIFSTCon()
3850 count = bcc_ptr - &pSMB->Password[0]; in CIFSTCon()
3851 be32_add_cpu(&pSMB->hdr.smb_buf_length, count); in CIFSTCon()
3852 pSMB->ByteCount = cpu_to_le16(count); in CIFSTCon()
3861 tcon->tid = smb_buffer_response->Tid; in CIFSTCon()
3864 length = strnlen(bcc_ptr, bytes_left - 2); in CIFSTCon()
3865 if (smb_buffer->Flags2 & SMBFLG2_UNICODE) in CIFSTCon()
3876 tcon->ipc = true; in CIFSTCon()
3877 tcon->pipe = true; in CIFSTCon()
3886 bytes_left -= (length + 1); in CIFSTCon()
3887 strscpy(tcon->tree_name, tree, sizeof(tcon->tree_name)); in CIFSTCon()
3889 /* mostly informational -- no need to fail on error here */ in CIFSTCon()
3890 kfree(tcon->nativeFileSystem); in CIFSTCon()
3891 tcon->nativeFileSystem = cifs_strndup_from_utf16(bcc_ptr, in CIFSTCon()
3895 cifs_dbg(FYI, "nativeFileSystem=%s\n", tcon->nativeFileSystem); in CIFSTCon()
3897 if ((smb_buffer_response->WordCount == 3) || in CIFSTCon()
3898 (smb_buffer_response->WordCount == 7)) in CIFSTCon()
3900 tcon->Flags = le16_to_cpu(pSMBr->OptionalSupport); in CIFSTCon()
3902 tcon->Flags = 0; in CIFSTCon()
3903 cifs_dbg(FYI, "Tcon flags: 0x%x\n", tcon->Flags); in CIFSTCon()
3910 * need_reconnect when tcon was successful but needed to be in CIFSTCon()
3913 if (tcon->need_reconnect && tcon->unix_ext) { in CIFSTCon()
3914 cifs_dbg(FYI, "resetting caps for %s\n", tcon->tree_name); in CIFSTCon()
3915 tcon->need_reconnect = false; in CIFSTCon()
3916 reset_cifs_unix_caps(xid, tcon, NULL, NULL); in CIFSTCon()
3928 unload_nls(cifs_sb->local_nls); in delayed_free()
3929 smb3_cleanup_fs_context(cifs_sb->ctx); in delayed_free()
3936 struct rb_root *root = &cifs_sb->tlink_tree; in cifs_umount()
3940 cancel_delayed_work_sync(&cifs_sb->prune_tlinks); in cifs_umount()
3942 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3946 clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); in cifs_umount()
3949 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3951 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3953 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3955 kfree(cifs_sb->prepath); in cifs_umount()
3956 call_rcu(&cifs_sb->rcu, delayed_free); in cifs_umount()
3965 if (!server->ops->need_neg || !server->ops->negotiate) in cifs_negotiate_protocol()
3966 return -ENOSYS; in cifs_negotiate_protocol()
3969 spin_lock(&server->srv_lock); in cifs_negotiate_protocol()
3970 if (server->tcpStatus != CifsGood && in cifs_negotiate_protocol()
3971 server->tcpStatus != CifsNew && in cifs_negotiate_protocol()
3972 server->tcpStatus != CifsNeedNegotiate) { in cifs_negotiate_protocol()
3973 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
3974 return -EHOSTDOWN; in cifs_negotiate_protocol()
3977 if (!server->ops->need_neg(server) && in cifs_negotiate_protocol()
3978 server->tcpStatus == CifsGood) { in cifs_negotiate_protocol()
3979 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
3983 server->tcpStatus = CifsInNegotiate; in cifs_negotiate_protocol()
3984 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
3986 rc = server->ops->negotiate(xid, ses, server); in cifs_negotiate_protocol()
3988 spin_lock(&server->srv_lock); in cifs_negotiate_protocol()
3989 if (server->tcpStatus == CifsInNegotiate) in cifs_negotiate_protocol()
3990 server->tcpStatus = CifsGood; in cifs_negotiate_protocol()
3992 rc = -EHOSTDOWN; in cifs_negotiate_protocol()
3993 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
3995 spin_lock(&server->srv_lock); in cifs_negotiate_protocol()
3996 if (server->tcpStatus == CifsInNegotiate) in cifs_negotiate_protocol()
3997 server->tcpStatus = CifsNeedNegotiate; in cifs_negotiate_protocol()
3998 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
4009 int rc = -ENOSYS; in cifs_setup_session()
4010 struct TCP_Server_Info *pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in cifs_setup_session()
4011 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&pserver->dstaddr; in cifs_setup_session()
4012 struct sockaddr_in *addr = (struct sockaddr_in *)&pserver->dstaddr; in cifs_setup_session()
4015 spin_lock(&ses->ses_lock); in cifs_setup_session()
4016 cifs_dbg(FYI, "%s: channel connect bitmap: 0x%lx\n", in cifs_setup_session()
4017 __func__, ses->chans_need_reconnect); in cifs_setup_session()
4019 if (ses->ses_status != SES_GOOD && in cifs_setup_session()
4020 ses->ses_status != SES_NEW && in cifs_setup_session()
4021 ses->ses_status != SES_NEED_RECON) { in cifs_setup_session()
4022 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4023 return -EHOSTDOWN; in cifs_setup_session()
4027 spin_lock(&ses->chan_lock); in cifs_setup_session()
4029 if (ses->ses_status == SES_NEED_RECON) in cifs_setup_session()
4030 ses->ses_status = SES_GOOD; in cifs_setup_session()
4031 spin_unlock(&ses->chan_lock); in cifs_setup_session()
4032 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4038 spin_unlock(&ses->chan_lock); in cifs_setup_session()
4041 ses->ses_status = SES_IN_SETUP; in cifs_setup_session()
4044 ses->iface_last_update = 0; in cifs_setup_session()
4046 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4050 if (server->dstaddr.ss_family == AF_INET6) in cifs_setup_session()
4051 scnprintf(ses->ip_addr, sizeof(ses->ip_addr), "%pI6", &addr6->sin6_addr); in cifs_setup_session()
4053 scnprintf(ses->ip_addr, sizeof(ses->ip_addr), "%pI4", &addr->sin_addr); in cifs_setup_session()
4057 ses->capabilities = server->capabilities; in cifs_setup_session()
4059 ses->capabilities &= (~server->vals->cap_unix); in cifs_setup_session()
4061 if (ses->auth_key.response) { in cifs_setup_session()
4063 ses->auth_key.response); in cifs_setup_session()
4064 kfree_sensitive(ses->auth_key.response); in cifs_setup_session()
4065 ses->auth_key.response = NULL; in cifs_setup_session()
4066 ses->auth_key.len = 0; in cifs_setup_session()
4071 server->sec_mode, server->capabilities, server->timeAdj); in cifs_setup_session()
4073 if (server->ops->sess_setup) in cifs_setup_session()
4074 rc = server->ops->sess_setup(xid, ses, server, nls_info); in cifs_setup_session()
4078 spin_lock(&ses->ses_lock); in cifs_setup_session()
4079 if (ses->ses_status == SES_IN_SETUP) in cifs_setup_session()
4080 ses->ses_status = SES_NEED_RECON; in cifs_setup_session()
4081 spin_lock(&ses->chan_lock); in cifs_setup_session()
4083 spin_unlock(&ses->chan_lock); in cifs_setup_session()
4084 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4086 spin_lock(&ses->ses_lock); in cifs_setup_session()
4087 if (ses->ses_status == SES_IN_SETUP) in cifs_setup_session()
4088 ses->ses_status = SES_GOOD; in cifs_setup_session()
4089 spin_lock(&ses->chan_lock); in cifs_setup_session()
4092 spin_unlock(&ses->chan_lock); in cifs_setup_session()
4093 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4102 ctx->sectype = ses->sectype; in cifs_set_vol_auth()
4105 if (ctx->sectype == Kerberos) in cifs_set_vol_auth()
4117 struct cifs_tcon *tcon = NULL; in __cifs_construct_tcon() local
4123 return ERR_PTR(-ENOMEM); in __cifs_construct_tcon()
4125 ctx->local_nls = cifs_sb->local_nls; in __cifs_construct_tcon()
4126 ctx->linux_uid = fsuid; in __cifs_construct_tcon()
4127 ctx->cred_uid = fsuid; in __cifs_construct_tcon()
4128 ctx->UNC = master_tcon->tree_name; in __cifs_construct_tcon()
4129 ctx->retry = master_tcon->retry; in __cifs_construct_tcon()
4130 ctx->nocase = master_tcon->nocase; in __cifs_construct_tcon()
4131 ctx->nohandlecache = master_tcon->nohandlecache; in __cifs_construct_tcon()
4132 ctx->local_lease = master_tcon->local_lease; in __cifs_construct_tcon()
4133 ctx->no_lease = master_tcon->no_lease; in __cifs_construct_tcon()
4134 ctx->resilient = master_tcon->use_resilient; in __cifs_construct_tcon()
4135 ctx->persistent = master_tcon->use_persistent; in __cifs_construct_tcon()
4136 ctx->handle_timeout = master_tcon->handle_timeout; in __cifs_construct_tcon()
4137 ctx->no_linux_ext = !master_tcon->unix_ext; in __cifs_construct_tcon()
4138 ctx->linux_ext = master_tcon->posix_extensions; in __cifs_construct_tcon()
4139 ctx->sectype = master_tcon->ses->sectype; in __cifs_construct_tcon()
4140 ctx->sign = master_tcon->ses->sign; in __cifs_construct_tcon()
4141 ctx->seal = master_tcon->seal; in __cifs_construct_tcon()
4142 ctx->witness = master_tcon->use_witness; in __cifs_construct_tcon()
4143 ctx->dfs_root_ses = master_tcon->ses->dfs_root_ses; in __cifs_construct_tcon()
4145 rc = cifs_set_vol_auth(ctx, master_tcon->ses); in __cifs_construct_tcon()
4147 tcon = ERR_PTR(rc); in __cifs_construct_tcon()
4153 ++master_tcon->ses->server->srv_count; in __cifs_construct_tcon()
4156 ses = cifs_get_smb_ses(master_tcon->ses->server, ctx); in __cifs_construct_tcon()
4158 tcon = (struct cifs_tcon *)ses; in __cifs_construct_tcon()
4159 cifs_put_tcp_session(master_tcon->ses->server, 0); in __cifs_construct_tcon()
4164 spin_lock(&master_tcon->tc_lock); in __cifs_construct_tcon()
4165 if (master_tcon->origin_fullpath) { in __cifs_construct_tcon()
4166 spin_unlock(&master_tcon->tc_lock); in __cifs_construct_tcon()
4167 origin_fullpath = dfs_get_path(cifs_sb, cifs_sb->ctx->source); in __cifs_construct_tcon()
4169 tcon = ERR_CAST(origin_fullpath); in __cifs_construct_tcon()
4175 spin_unlock(&master_tcon->tc_lock); in __cifs_construct_tcon()
4179 tcon = cifs_get_tcon(ses, ctx); in __cifs_construct_tcon()
4180 if (IS_ERR(tcon)) { in __cifs_construct_tcon()
4187 spin_lock(&tcon->tc_lock); in __cifs_construct_tcon()
4188 tcon->origin_fullpath = origin_fullpath; in __cifs_construct_tcon()
4189 spin_unlock(&tcon->tc_lock); in __cifs_construct_tcon()
4191 queue_delayed_work(dfscache_wq, &tcon->dfs_cache_work, in __cifs_construct_tcon()
4198 reset_cifs_unix_caps(0, tcon, NULL, ctx); in __cifs_construct_tcon()
4202 kfree(ctx->username); in __cifs_construct_tcon()
4203 kfree_sensitive(ctx->password); in __cifs_construct_tcon()
4207 return tcon; in __cifs_construct_tcon()
4231 struct rb_node *node = root->rb_node; in tlink_rb_search()
4237 if (uid_gt(tlink->tl_uid, uid)) in tlink_rb_search()
4238 node = node->rb_left; in tlink_rb_search()
4239 else if (uid_lt(tlink->tl_uid, uid)) in tlink_rb_search()
4240 node = node->rb_right; in tlink_rb_search()
4251 struct rb_node **new = &(root->rb_node), *parent = NULL; in tlink_rb_insert()
4258 if (uid_gt(tlink->tl_uid, new_tlink->tl_uid)) in tlink_rb_insert()
4259 new = &((*new)->rb_left); in tlink_rb_insert()
4261 new = &((*new)->rb_right); in tlink_rb_insert()
4264 rb_link_node(&new_tlink->tl_rbnode, parent, new); in tlink_rb_insert()
4265 rb_insert_color(&new_tlink->tl_rbnode, root); in tlink_rb_insert()
4269 * Find or construct an appropriate tcon given a cifs_sb and the fsuid of the
4273 * the master tcon for the mount.
4275 * First, search the rbtree for an existing tcon for this fsuid. If one
4291 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) in cifs_sb_tlink()
4294 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4295 tlink = tlink_rb_search(&cifs_sb->tlink_tree, fsuid); in cifs_sb_tlink()
4298 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4303 return ERR_PTR(-ENOMEM); in cifs_sb_tlink()
4304 newtlink->tl_uid = fsuid; in cifs_sb_tlink()
4305 newtlink->tl_tcon = ERR_PTR(-EACCES); in cifs_sb_tlink()
4306 set_bit(TCON_LINK_PENDING, &newtlink->tl_flags); in cifs_sb_tlink()
4307 set_bit(TCON_LINK_IN_TREE, &newtlink->tl_flags); in cifs_sb_tlink()
4310 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4312 tlink = tlink_rb_search(&cifs_sb->tlink_tree, fsuid); in cifs_sb_tlink()
4315 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4320 tlink_rb_insert(&cifs_sb->tlink_tree, tlink); in cifs_sb_tlink()
4321 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4324 ret = wait_on_bit(&tlink->tl_flags, TCON_LINK_PENDING, in cifs_sb_tlink()
4328 return ERR_PTR(-ERESTARTSYS); in cifs_sb_tlink()
4332 if (!IS_ERR(tlink->tl_tcon)) in cifs_sb_tlink()
4336 if (time_before(jiffies, tlink->tl_time + TLINK_ERROR_EXPIRE)) { in cifs_sb_tlink()
4338 return ERR_PTR(-EACCES); in cifs_sb_tlink()
4341 if (test_and_set_bit(TCON_LINK_PENDING, &tlink->tl_flags)) in cifs_sb_tlink()
4345 tlink->tl_tcon = cifs_construct_tcon(cifs_sb, fsuid); in cifs_sb_tlink()
4346 clear_bit(TCON_LINK_PENDING, &tlink->tl_flags); in cifs_sb_tlink()
4347 wake_up_bit(&tlink->tl_flags, TCON_LINK_PENDING); in cifs_sb_tlink()
4349 if (IS_ERR(tlink->tl_tcon)) { in cifs_sb_tlink()
4351 return ERR_PTR(-EACCES); in cifs_sb_tlink()
4366 struct rb_root *root = &cifs_sb->tlink_tree; in cifs_prune_tlinks()
4375 * umounts. Because this function is non-reentrant and is canceled in cifs_prune_tlinks()
4378 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4385 if (test_bit(TCON_LINK_MASTER, &tlink->tl_flags) || in cifs_prune_tlinks()
4386 atomic_read(&tlink->tl_count) != 0 || in cifs_prune_tlinks()
4387 time_after(tlink->tl_time + TLINK_IDLE_EXPIRE, jiffies)) in cifs_prune_tlinks()
4391 clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); in cifs_prune_tlinks()
4394 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4396 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4398 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4400 queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks, in cifs_prune_tlinks()
4405 int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const struct nls_table *nlsc) in cifs_tree_connect() argument
4408 const struct smb_version_operations *ops = tcon->ses->server->ops; in cifs_tree_connect()
4411 spin_lock(&tcon->tc_lock); in cifs_tree_connect()
4413 /* if tcon is marked for needing reconnect, update state */ in cifs_tree_connect()
4414 if (tcon->need_reconnect) in cifs_tree_connect()
4415 tcon->status = TID_NEED_TCON; in cifs_tree_connect()
4417 if (tcon->status == TID_GOOD) { in cifs_tree_connect()
4418 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4422 if (tcon->status != TID_NEW && in cifs_tree_connect()
4423 tcon->status != TID_NEED_TCON) { in cifs_tree_connect()
4424 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4425 return -EHOSTDOWN; in cifs_tree_connect()
4428 tcon->status = TID_IN_TCON; in cifs_tree_connect()
4429 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4431 rc = ops->tree_connect(xid, tcon->ses, tcon->tree_name, tcon, nlsc); in cifs_tree_connect()
4433 spin_lock(&tcon->tc_lock); in cifs_tree_connect()
4434 if (tcon->status == TID_IN_TCON) in cifs_tree_connect()
4435 tcon->status = TID_NEED_TCON; in cifs_tree_connect()
4436 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4438 spin_lock(&tcon->tc_lock); in cifs_tree_connect()
4439 if (tcon->status == TID_IN_TCON) in cifs_tree_connect()
4440 tcon->status = TID_GOOD; in cifs_tree_connect()
4441 tcon->need_reconnect = false; in cifs_tree_connect()
4442 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()