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()
139 queue_delayed_work(cifsiod_wq, &tcon->query_interfaces, in smb2_query_server_interfaces()
145 spin_lock(&server->srv_lock); \
146 if (server->tcpStatus != CifsExiting) \
147 server->tcpStatus = CifsNeedReconnect; \
148 spin_unlock(&server->srv_lock); \
169 /* if we need to signal just this channel */ in cifs_signal_cifsd_for_reconnect()
176 server = server->primary_server; in cifs_signal_cifsd_for_reconnect()
179 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { in cifs_signal_cifsd_for_reconnect()
180 spin_lock(&ses->ses_lock); in cifs_signal_cifsd_for_reconnect()
181 if (ses->ses_status == SES_EXITING) { in cifs_signal_cifsd_for_reconnect()
182 spin_unlock(&ses->ses_lock); in cifs_signal_cifsd_for_reconnect()
185 spin_lock(&ses->chan_lock); in cifs_signal_cifsd_for_reconnect()
186 for (i = 1; i < ses->chan_count; i++) { in cifs_signal_cifsd_for_reconnect()
187 nserver = ses->chans[i].server; in cifs_signal_cifsd_for_reconnect()
190 nserver->srv_count++; in cifs_signal_cifsd_for_reconnect()
191 list_add(&nserver->rlist, &reco); in cifs_signal_cifsd_for_reconnect()
193 spin_unlock(&ses->chan_lock); in cifs_signal_cifsd_for_reconnect()
194 spin_unlock(&ses->ses_lock); in cifs_signal_cifsd_for_reconnect()
199 list_del_init(&server->rlist); in cifs_signal_cifsd_for_reconnect()
221 struct cifs_tcon *tcon; in cifs_mark_tcp_ses_conns_for_reconnect() local
229 /* If server is a channel, select the primary channel */ in cifs_mark_tcp_ses_conns_for_reconnect()
230 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in cifs_mark_tcp_ses_conns_for_reconnect()
240 if (server->terminate) { in cifs_mark_tcp_ses_conns_for_reconnect()
246 list_for_each_entry_safe(ses, nses, &pserver->smb_ses_list, smb_ses_list) { in cifs_mark_tcp_ses_conns_for_reconnect()
247 spin_lock(&ses->ses_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
248 if (ses->ses_status == SES_EXITING) { in cifs_mark_tcp_ses_conns_for_reconnect()
249 spin_unlock(&ses->ses_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
252 spin_unlock(&ses->ses_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
254 spin_lock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
257 spin_unlock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
262 spin_unlock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
264 spin_lock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
268 spin_unlock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
277 cifs_dbg(FYI, "%s: channel connect bitmap: 0x%lx\n", in cifs_mark_tcp_ses_conns_for_reconnect()
278 __func__, ses->chans_need_reconnect); in cifs_mark_tcp_ses_conns_for_reconnect()
280 /* If all channels need reconnect, then tcon needs reconnect */ in cifs_mark_tcp_ses_conns_for_reconnect()
282 spin_unlock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
285 spin_unlock(&ses->chan_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
287 spin_lock(&ses->ses_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
288 ses->ses_status = SES_NEED_RECON; in cifs_mark_tcp_ses_conns_for_reconnect()
289 spin_unlock(&ses->ses_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
291 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { in cifs_mark_tcp_ses_conns_for_reconnect()
292 tcon->need_reconnect = true; in cifs_mark_tcp_ses_conns_for_reconnect()
293 spin_lock(&tcon->tc_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
294 tcon->status = TID_NEED_RECON; in cifs_mark_tcp_ses_conns_for_reconnect()
295 spin_unlock(&tcon->tc_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
297 cancel_delayed_work(&tcon->query_interfaces); in cifs_mark_tcp_ses_conns_for_reconnect()
299 if (ses->tcon_ipc) { in cifs_mark_tcp_ses_conns_for_reconnect()
300 ses->tcon_ipc->need_reconnect = true; in cifs_mark_tcp_ses_conns_for_reconnect()
301 spin_lock(&ses->tcon_ipc->tc_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
302 ses->tcon_ipc->status = TID_NEED_RECON; in cifs_mark_tcp_ses_conns_for_reconnect()
303 spin_unlock(&ses->tcon_ipc->tc_lock); in cifs_mark_tcp_ses_conns_for_reconnect()
315 server->maxBuf = 0; in cifs_abort_connection()
316 server->max_read = 0; in cifs_abort_connection()
321 if (server->ssocket) { in cifs_abort_connection()
322 cifs_dbg(FYI, "State: 0x%x Flags: 0x%lx\n", server->ssocket->state, in cifs_abort_connection()
323 server->ssocket->flags); in cifs_abort_connection()
324 kernel_sock_shutdown(server->ssocket, SHUT_WR); in cifs_abort_connection()
325 cifs_dbg(FYI, "Post shutdown state: 0x%x Flags: 0x%lx\n", server->ssocket->state, in cifs_abort_connection()
326 server->ssocket->flags); in cifs_abort_connection()
327 sock_release(server->ssocket); in cifs_abort_connection()
328 server->ssocket = NULL; in cifs_abort_connection()
330 server->sequence_number = 0; in cifs_abort_connection()
331 server->session_estab = false; in cifs_abort_connection()
332 kfree_sensitive(server->session_key.response); in cifs_abort_connection()
333 server->session_key.response = NULL; in cifs_abort_connection()
334 server->session_key.len = 0; in cifs_abort_connection()
335 server->lstrp = jiffies; in cifs_abort_connection()
340 spin_lock(&server->mid_lock); in cifs_abort_connection()
341 list_for_each_entry_safe(mid, nmid, &server->pending_mid_q, qhead) { in cifs_abort_connection()
342 kref_get(&mid->refcount); in cifs_abort_connection()
343 if (mid->mid_state == MID_REQUEST_SUBMITTED) in cifs_abort_connection()
344 mid->mid_state = MID_RETRY_NEEDED; in cifs_abort_connection()
345 list_move(&mid->qhead, &retry_list); in cifs_abort_connection()
346 mid->mid_flags |= MID_DELETED; in cifs_abort_connection()
348 spin_unlock(&server->mid_lock); in cifs_abort_connection()
353 list_del_init(&mid->qhead); in cifs_abort_connection()
354 mid->callback(mid); in cifs_abort_connection()
367 spin_lock(&server->srv_lock); in cifs_tcp_ses_needs_reconnect()
368 server->nr_targets = num_targets; in cifs_tcp_ses_needs_reconnect()
369 if (server->tcpStatus == CifsExiting) { in cifs_tcp_ses_needs_reconnect()
371 spin_unlock(&server->srv_lock); in cifs_tcp_ses_needs_reconnect()
372 wake_up(&server->response_q); in cifs_tcp_ses_needs_reconnect()
377 trace_smb3_reconnect(server->CurrentMid, server->conn_id, in cifs_tcp_ses_needs_reconnect()
378 server->hostname); in cifs_tcp_ses_needs_reconnect()
379 server->tcpStatus = CifsNeedReconnect; in cifs_tcp_ses_needs_reconnect()
381 spin_unlock(&server->srv_lock); in cifs_tcp_ses_needs_reconnect()
391 * wake up waiters on reconnection? - (not needed currently)
394 * the smb session (and tcon) for reconnect as well. This value
395 * doesn't really matter for non-multichannel scenario.
423 /* resolve the hostname again to make sure that IP address is up-to-date */ in __cifs_reconnect()
439 spin_lock(&server->srv_lock); in __cifs_reconnect()
440 if (server->tcpStatus != CifsExiting) in __cifs_reconnect()
441 server->tcpStatus = CifsNeedNegotiate; in __cifs_reconnect()
442 spin_unlock(&server->srv_lock); in __cifs_reconnect()
445 mod_delayed_work(cifsiod_wq, &server->reconnect, 0); in __cifs_reconnect()
447 } while (server->tcpStatus == CifsNeedReconnect); in __cifs_reconnect()
449 spin_lock(&server->srv_lock); in __cifs_reconnect()
450 if (server->tcpStatus == CifsNeedNegotiate) in __cifs_reconnect()
451 mod_delayed_work(cifsiod_wq, &server->echo, 0); in __cifs_reconnect()
452 spin_unlock(&server->srv_lock); in __cifs_reconnect()
454 wake_up(&server->response_q); in __cifs_reconnect()
465 if (server->hostname != target) { in __reconnect_target_unlocked()
468 spin_lock(&server->srv_lock); in __reconnect_target_unlocked()
469 kfree(server->hostname); in __reconnect_target_unlocked()
470 server->hostname = hostname; in __reconnect_target_unlocked()
471 spin_unlock(&server->srv_lock); in __reconnect_target_unlocked()
476 server->hostname); in __reconnect_target_unlocked()
479 /* resolve the hostname again to make sure that IP address is up-to-date. */ in __reconnect_target_unlocked()
503 return __reconnect_target_unlocked(server, server->hostname); in reconnect_target_unlocked()
528 * targets (server->nr_targets). It's also possible that the cached referral was cleared in reconnect_dfs_server()
532 mutex_lock(&server->refpath_lock); in reconnect_dfs_server()
533 if (!dfs_cache_noreq_find(server->leaf_fullpath + 1, NULL, &tl)) in reconnect_dfs_server()
535 mutex_unlock(&server->refpath_lock); in reconnect_dfs_server()
565 * process waiting for reconnect will know it needs to re-establish session and tcon in reconnect_dfs_server()
570 spin_lock(&server->srv_lock); in reconnect_dfs_server()
571 if (server->tcpStatus != CifsExiting) in reconnect_dfs_server()
572 server->tcpStatus = CifsNeedNegotiate; in reconnect_dfs_server()
573 spin_unlock(&server->srv_lock); in reconnect_dfs_server()
576 mod_delayed_work(cifsiod_wq, &server->reconnect, 0); in reconnect_dfs_server()
577 } while (server->tcpStatus == CifsNeedReconnect); in reconnect_dfs_server()
579 mutex_lock(&server->refpath_lock); in reconnect_dfs_server()
580 dfs_cache_noreq_update_tgthint(server->leaf_fullpath + 1, target_hint); in reconnect_dfs_server()
581 mutex_unlock(&server->refpath_lock); in reconnect_dfs_server()
585 spin_lock(&server->srv_lock); in reconnect_dfs_server()
586 if (server->tcpStatus == CifsNeedNegotiate) in reconnect_dfs_server()
587 mod_delayed_work(cifsiod_wq, &server->echo, 0); in reconnect_dfs_server()
588 spin_unlock(&server->srv_lock); in reconnect_dfs_server()
590 wake_up(&server->response_q); in reconnect_dfs_server()
596 mutex_lock(&server->refpath_lock); in cifs_reconnect()
597 if (!server->leaf_fullpath) { in cifs_reconnect()
598 mutex_unlock(&server->refpath_lock); in cifs_reconnect()
601 mutex_unlock(&server->refpath_lock); in cifs_reconnect()
624 if (server->tcpStatus == CifsNeedReconnect || in cifs_echo_request()
625 server->tcpStatus == CifsExiting || in cifs_echo_request()
626 server->tcpStatus == CifsNew || in cifs_echo_request()
627 (server->ops->can_echo && !server->ops->can_echo(server)) || in cifs_echo_request()
628 time_before(jiffies, server->lstrp + server->echo_interval - HZ)) in cifs_echo_request()
631 rc = server->ops->echo ? server->ops->echo(server) : -ENOSYS; in cifs_echo_request()
638 queue_delayed_work(cifsiod_wq, &server->echo, server->echo_interval); in cifs_echo_request()
644 if (!server->bigbuf) { in allocate_buffers()
645 server->bigbuf = (char *)cifs_buf_get(); in allocate_buffers()
646 if (!server->bigbuf) { in allocate_buffers()
652 } else if (server->large_buf) { in allocate_buffers()
654 memset(server->bigbuf, 0, HEADER_SIZE(server)); in allocate_buffers()
657 if (!server->smallbuf) { in allocate_buffers()
658 server->smallbuf = (char *)cifs_small_buf_get(); in allocate_buffers()
659 if (!server->smallbuf) { in allocate_buffers()
668 memset(server->smallbuf, 0, HEADER_SIZE(server)); in allocate_buffers()
683 spin_lock(&server->srv_lock); in server_unresponsive()
684 if (server->tcpStatus == CifsInNegotiate && in server_unresponsive()
685 time_after(jiffies, server->neg_start + 20 * HZ)) { in server_unresponsive()
686 spin_unlock(&server->srv_lock); in server_unresponsive()
701 if ((server->tcpStatus == CifsGood || in server_unresponsive()
702 server->tcpStatus == CifsNeedNegotiate) && in server_unresponsive()
703 (!server->ops->can_echo || server->ops->can_echo(server)) && in server_unresponsive()
704 time_after(jiffies, server->lstrp + 3 * server->echo_interval)) { in server_unresponsive()
705 spin_unlock(&server->srv_lock); in server_unresponsive()
707 (3 * server->echo_interval) / HZ); in server_unresponsive()
711 spin_unlock(&server->srv_lock); in server_unresponsive()
721 spin_lock(&server->req_lock); in zero_credits()
722 val = server->credits + server->echo_credits + server->oplock_credits; in zero_credits()
723 if (server->in_flight == 0 && val == 0) { in zero_credits()
724 spin_unlock(&server->req_lock); in zero_credits()
727 spin_unlock(&server->req_lock); in zero_credits()
743 return -ECONNABORTED; in cifs_readv_from_socket()
747 return -ECONNABORTED; in cifs_readv_from_socket()
748 if (cifs_rdma_enabled(server) && server->smbd_conn) in cifs_readv_from_socket()
749 length = smbd_recv(server->smbd_conn, smb_msg); in cifs_readv_from_socket()
751 length = sock_recvmsg(server->ssocket, smb_msg, 0); in cifs_readv_from_socket()
753 spin_lock(&server->srv_lock); in cifs_readv_from_socket()
754 if (server->tcpStatus == CifsExiting) { in cifs_readv_from_socket()
755 spin_unlock(&server->srv_lock); in cifs_readv_from_socket()
756 return -ESHUTDOWN; in cifs_readv_from_socket()
759 if (server->tcpStatus == CifsNeedReconnect) { in cifs_readv_from_socket()
760 spin_unlock(&server->srv_lock); in cifs_readv_from_socket()
762 return -ECONNABORTED; in cifs_readv_from_socket()
764 spin_unlock(&server->srv_lock); in cifs_readv_from_socket()
766 if (length == -ERESTARTSYS || in cifs_readv_from_socket()
767 length == -EAGAIN || in cifs_readv_from_socket()
768 length == -EINTR) { in cifs_readv_from_socket()
782 return -ECONNABORTED; in cifs_readv_from_socket()
873 cifs_set_port((struct sockaddr *)&server->dstaddr, CIFS_PORT); in is_smb_response()
888 mid->when_received = jiffies; in dequeue_mid()
890 spin_lock(&mid->server->mid_lock); in dequeue_mid()
892 mid->mid_state = MID_RESPONSE_RECEIVED; in dequeue_mid()
894 mid->mid_state = MID_RESPONSE_MALFORMED; in dequeue_mid()
899 if (mid->mid_flags & MID_DELETED) { in dequeue_mid()
900 spin_unlock(&mid->server->mid_lock); in dequeue_mid()
903 list_del_init(&mid->qhead); in dequeue_mid()
904 mid->mid_flags |= MID_DELETED; in dequeue_mid()
905 spin_unlock(&mid->server->mid_lock); in dequeue_mid()
920 return le16_to_cpu(shdr->CreditRequest); in smb2_get_credits_from_hdr()
927 if (server->ops->check_trans2 && in handle_mid()
928 server->ops->check_trans2(mid, server, buf, malformed)) in handle_mid()
930 mid->credits_received = smb2_get_credits_from_hdr(buf, server); in handle_mid()
931 mid->resp_buf = buf; in handle_mid()
932 mid->large_buf = server->large_buf; in handle_mid()
933 /* Was previous buf put in mpx struct for multi-rsp? */ in handle_mid()
934 if (!mid->multiRsp) { in handle_mid()
936 if (server->large_buf) in handle_mid()
937 server->bigbuf = NULL; in handle_mid()
939 server->smallbuf = NULL; in handle_mid()
947 bool srv_sign_required = server->sec_mode & server->vals->signing_required; in cifs_enable_signing()
948 bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled; in cifs_enable_signing()
970 return -EOPNOTSUPP; in cifs_enable_signing()
972 server->sign = true; in cifs_enable_signing()
979 return -EOPNOTSUPP; in cifs_enable_signing()
981 server->sign = true; in cifs_enable_signing()
984 if (cifs_rdma_enabled(server) && server->sign) in cifs_enable_signing()
996 spin_lock(&server->srv_lock); in clean_demultiplex_info()
997 list_del_init(&server->tcp_ses_list); in clean_demultiplex_info()
998 spin_unlock(&server->srv_lock); in clean_demultiplex_info()
1000 cancel_delayed_work_sync(&server->echo); in clean_demultiplex_info()
1002 spin_lock(&server->srv_lock); in clean_demultiplex_info()
1003 server->tcpStatus = CifsExiting; in clean_demultiplex_info()
1004 spin_unlock(&server->srv_lock); in clean_demultiplex_info()
1005 wake_up_all(&server->response_q); in clean_demultiplex_info()
1008 spin_lock(&server->req_lock); in clean_demultiplex_info()
1009 if (server->credits <= 0) in clean_demultiplex_info()
1010 server->credits = 1; in clean_demultiplex_info()
1011 spin_unlock(&server->req_lock); in clean_demultiplex_info()
1016 * same server - they now will see the session is in exit state and get in clean_demultiplex_info()
1019 wake_up_all(&server->request_q); in clean_demultiplex_info()
1024 if (server->ssocket) { in clean_demultiplex_info()
1025 sock_release(server->ssocket); in clean_demultiplex_info()
1026 server->ssocket = NULL; in clean_demultiplex_info()
1029 if (!list_empty(&server->pending_mid_q)) { in clean_demultiplex_info()
1035 spin_lock(&server->mid_lock); in clean_demultiplex_info()
1036 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { in clean_demultiplex_info()
1038 cifs_dbg(FYI, "Clearing mid %llu\n", mid_entry->mid); in clean_demultiplex_info()
1039 kref_get(&mid_entry->refcount); in clean_demultiplex_info()
1040 mid_entry->mid_state = MID_SHUTDOWN; in clean_demultiplex_info()
1041 list_move(&mid_entry->qhead, &dispose_list); in clean_demultiplex_info()
1042 mid_entry->mid_flags |= MID_DELETED; in clean_demultiplex_info()
1044 spin_unlock(&server->mid_lock); in clean_demultiplex_info()
1049 cifs_dbg(FYI, "Callback mid %llu\n", mid_entry->mid); in clean_demultiplex_info()
1050 list_del_init(&mid_entry->qhead); in clean_demultiplex_info()
1051 mid_entry->callback(mid_entry); in clean_demultiplex_info()
1058 if (!list_empty(&server->pending_mid_q)) { in clean_demultiplex_info()
1076 kfree(server->leaf_fullpath); in clean_demultiplex_info()
1077 kfree(server->hostname); in clean_demultiplex_info()
1089 char *buf = server->smallbuf; in standard_receive3()
1090 unsigned int pdu_length = server->pdu_size; in standard_receive3()
1093 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server) - in standard_receive3()
1097 return -ECONNABORTED; in standard_receive3()
1101 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) { in standard_receive3()
1102 server->large_buf = true; in standard_receive3()
1103 memcpy(server->bigbuf, buf, server->total_read); in standard_receive3()
1104 buf = server->bigbuf; in standard_receive3()
1108 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, in standard_receive3()
1109 pdu_length - MID_HEADER_SIZE(server)); in standard_receive3()
1113 server->total_read += length; in standard_receive3()
1115 dump_smb(buf, server->total_read); in standard_receive3()
1123 char *buf = server->large_buf ? server->bigbuf : server->smallbuf; in cifs_handle_standard()
1134 rc = server->ops->check_message(buf, server->total_read, server); in cifs_handle_standard()
1137 min_t(unsigned int, server->total_read, 48)); in cifs_handle_standard()
1139 if (server->ops->is_session_expired && in cifs_handle_standard()
1140 server->ops->is_session_expired(buf)) { in cifs_handle_standard()
1142 return -1; in cifs_handle_standard()
1145 if (server->ops->is_status_pending && in cifs_handle_standard()
1146 server->ops->is_status_pending(buf, server)) in cifs_handle_standard()
1147 return -1; in cifs_handle_standard()
1168 if (shdr->CreditRequest) { in smb2_add_credits_from_hdr()
1169 spin_lock(&server->req_lock); in smb2_add_credits_from_hdr()
1170 server->credits += le16_to_cpu(shdr->CreditRequest); in smb2_add_credits_from_hdr()
1171 scredits = server->credits; in smb2_add_credits_from_hdr()
1172 in_flight = server->in_flight; in smb2_add_credits_from_hdr()
1173 spin_unlock(&server->req_lock); in smb2_add_credits_from_hdr()
1174 wake_up(&server->request_q); in smb2_add_credits_from_hdr()
1176 trace_smb3_hdr_credits(server->CurrentMid, in smb2_add_credits_from_hdr()
1177 server->conn_id, server->hostname, scredits, in smb2_add_credits_from_hdr()
1178 le16_to_cpu(shdr->CreditRequest), in_flight); in smb2_add_credits_from_hdr()
1180 __func__, le16_to_cpu(shdr->CreditRequest), in smb2_add_credits_from_hdr()
1209 while (server->tcpStatus != CifsExiting) { in cifs_demultiplex_thread()
1216 server->large_buf = false; in cifs_demultiplex_thread()
1217 buf = server->smallbuf; in cifs_demultiplex_thread()
1225 server->total_read = length; in cifs_demultiplex_thread()
1227 server->total_read = 0; in cifs_demultiplex_thread()
1230 * The right amount was read from socket - 4 bytes, in cifs_demultiplex_thread()
1241 server->pdu_size = pdu_length; in cifs_demultiplex_thread()
1244 if (server->pdu_size < MID_HEADER_SIZE(server)) { in cifs_demultiplex_thread()
1246 server->pdu_size); in cifs_demultiplex_thread()
1257 server->total_read += length; in cifs_demultiplex_thread()
1259 if (server->ops->next_header) { in cifs_demultiplex_thread()
1260 if (server->ops->next_header(server, buf, &next_offset)) { in cifs_demultiplex_thread()
1267 server->pdu_size = next_offset; in cifs_demultiplex_thread()
1274 if (server->ops->is_transform_hdr && in cifs_demultiplex_thread()
1275 server->ops->receive_transform && in cifs_demultiplex_thread()
1276 server->ops->is_transform_hdr(buf)) { in cifs_demultiplex_thread()
1277 length = server->ops->receive_transform(server, in cifs_demultiplex_thread()
1282 mids[0] = server->ops->find_mid(server, buf); in cifs_demultiplex_thread()
1286 if (!mids[0] || !mids[0]->receive) in cifs_demultiplex_thread()
1289 length = mids[0]->receive(server, mids[0]); in cifs_demultiplex_thread()
1299 if (server->ops->is_status_io_timeout && in cifs_demultiplex_thread()
1300 server->ops->is_status_io_timeout(buf)) { in cifs_demultiplex_thread()
1312 server->lstrp = jiffies; in cifs_demultiplex_thread()
1316 mids[i]->resp_buf_size = server->pdu_size; in cifs_demultiplex_thread()
1319 if (server->ops->is_network_name_deleted && in cifs_demultiplex_thread()
1320 server->ops->is_network_name_deleted(bufs[i], in cifs_demultiplex_thread()
1327 if (!mids[i]->multiRsp || mids[i]->multiEnd) in cifs_demultiplex_thread()
1328 mids[i]->callback(mids[i]); in cifs_demultiplex_thread()
1331 } else if (server->ops->is_oplock_break && in cifs_demultiplex_thread()
1332 server->ops->is_oplock_break(bufs[i], in cifs_demultiplex_thread()
1343 if (server->ops->dump_detail) in cifs_demultiplex_thread()
1344 server->ops->dump_detail(bufs[i], in cifs_demultiplex_thread()
1351 if (pdu_length > server->pdu_size) { in cifs_demultiplex_thread()
1354 pdu_length -= server->pdu_size; in cifs_demultiplex_thread()
1355 server->total_read = 0; in cifs_demultiplex_thread()
1356 server->large_buf = false; in cifs_demultiplex_thread()
1357 buf = server->smallbuf; in cifs_demultiplex_thread()
1367 /* buffer usually freed in free_mid - need to free it here on exit */ in cifs_demultiplex_thread()
1368 cifs_buf_release(server->bigbuf); in cifs_demultiplex_thread()
1369 if (server->smallbuf) /* no sense logging a debug message if NULL */ in cifs_demultiplex_thread()
1370 cifs_small_buf_release(server->smallbuf); in cifs_demultiplex_thread()
1372 task_to_wake = xchg(&server->tsk, NULL); in cifs_demultiplex_thread()
1375 /* if server->tsk was NULL then wait for a signal before exiting */ in cifs_demultiplex_thread()
1397 switch (srcaddr->sa_family) { in cifs_ipaddr_cmp()
1399 switch (rhs->sa_family) { in cifs_ipaddr_cmp()
1406 return -1; in cifs_ipaddr_cmp()
1409 switch (rhs->sa_family) { in cifs_ipaddr_cmp()
1411 return -1; in cifs_ipaddr_cmp()
1418 return -1; in cifs_ipaddr_cmp()
1422 switch (rhs->sa_family) { in cifs_ipaddr_cmp()
1425 return -1; in cifs_ipaddr_cmp()
1431 return -1; in cifs_ipaddr_cmp()
1435 return -1; /* don't expect to be here */ in cifs_ipaddr_cmp()
1446 switch (srcaddr->sa_family) { in cifs_match_ipaddr()
1448 return (rhs->sa_family == AF_UNSPEC); in cifs_match_ipaddr()
1453 return (saddr4->sin_addr.s_addr == vaddr4->sin_addr.s_addr); in cifs_match_ipaddr()
1459 return (ipv6_addr_equal(&saddr6->sin6_addr, &vaddr6->sin6_addr) in cifs_match_ipaddr()
1460 && saddr6->sin6_scope_id == vaddr6->sin6_scope_id); in cifs_match_ipaddr()
1470 * and if it fails - with 139 ports. It should be called only if address
1479 if (server->rdma) in match_port()
1482 switch (addr->sa_family) { in match_port()
1484 sport = &((struct sockaddr_in *) &server->dstaddr)->sin_port; in match_port()
1485 port = ((struct sockaddr_in *) addr)->sin_port; in match_port()
1488 sport = &((struct sockaddr_in6 *) &server->dstaddr)->sin6_port; in match_port()
1489 port = ((struct sockaddr_in6 *) addr)->sin6_port; in match_port()
1509 if (!cifs_match_ipaddr(addr, (struct sockaddr *)&server->dstaddr)) in match_server_address()
1519 * The select_sectype function should either return the ctx->sectype in match_security()
1523 if (server->ops->select_sectype(server, ctx->sectype) in match_security()
1530 * the server->sign had better be too. in match_security()
1532 if (ctx->sign && !server->sign) in match_security()
1543 struct sockaddr *addr = (struct sockaddr *)&ctx->dstaddr; in match_server()
1545 lockdep_assert_held(&server->srv_lock); in match_server()
1547 if (ctx->nosharesock) in match_server()
1551 if (server->nosharesock) in match_server()
1554 if (!match_super && (ctx->dfs_conn || server->dfs_conn)) in match_server()
1558 if (strcmp(ctx->vals->version_string, SMB3ANY_VERSION_STRING) == 0) { in match_server()
1559 if (server->vals->protocol_id < SMB30_PROT_ID) in match_server()
1561 } else if (strcmp(ctx->vals->version_string, in match_server()
1563 if (server->vals->protocol_id < SMB21_PROT_ID) in match_server()
1565 } else if ((server->vals != ctx->vals) || (server->ops != ctx->ops)) in match_server()
1568 if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns)) in match_server()
1571 if (!cifs_match_ipaddr((struct sockaddr *)&ctx->srcaddr, in match_server()
1572 (struct sockaddr *)&server->srcaddr)) in match_server()
1576 * really match either @server->leaf_fullpath or @server->dstaddr in match_server()
1578 * server -- in case of domain-based DFS referrals or DFS links -- as in match_server()
1581 * Otherwise, match the DFS referral in @server->leaf_fullpath or the in match_server()
1582 * destination address in @server->dstaddr. in match_server()
1588 if (!ctx->nodfs) { in match_server()
1589 if (server->leaf_fullpath) { in match_server()
1590 if (!ctx->leaf_fullpath || in match_server()
1591 strcasecmp(server->leaf_fullpath, in match_server()
1592 ctx->leaf_fullpath)) in match_server()
1594 } else if (ctx->leaf_fullpath) { in match_server()
1597 } else if (server->leaf_fullpath) { in match_server()
1606 if (!server->leaf_fullpath && in match_server()
1607 (strcasecmp(server->hostname, ctx->server_hostname) || in match_server()
1615 if (server->echo_interval != ctx->echo_interval * HZ) in match_server()
1618 if (server->rdma != ctx->rdma) in match_server()
1621 if (server->ignore_signature != ctx->ignore_signature) in match_server()
1624 if (server->min_offload != ctx->min_offload) in match_server()
1627 if (server->retrans != ctx->retrans) in match_server()
1640 spin_lock(&server->srv_lock); in cifs_find_tcp_session()
1647 spin_unlock(&server->srv_lock); in cifs_find_tcp_session()
1650 spin_unlock(&server->srv_lock); in cifs_find_tcp_session()
1652 ++server->srv_count; in cifs_find_tcp_session()
1667 if (--server->srv_count > 0) { in cifs_put_tcp_session()
1673 WARN_ON(server->srv_count < 0); in cifs_put_tcp_session()
1675 list_del_init(&server->tcp_ses_list); in cifs_put_tcp_session()
1678 cancel_delayed_work_sync(&server->echo); in cifs_put_tcp_session()
1687 cancel_delayed_work(&server->reconnect); in cifs_put_tcp_session()
1689 cancel_delayed_work_sync(&server->reconnect); in cifs_put_tcp_session()
1691 /* For secondary channels, we pick up ref-count on the primary server */ in cifs_put_tcp_session()
1693 cifs_put_tcp_session(server->primary_server, from_reconnect); in cifs_put_tcp_session()
1695 spin_lock(&server->srv_lock); in cifs_put_tcp_session()
1696 server->tcpStatus = CifsExiting; in cifs_put_tcp_session()
1697 spin_unlock(&server->srv_lock); in cifs_put_tcp_session()
1701 kfree_sensitive(server->session_key.response); in cifs_put_tcp_session()
1702 server->session_key.response = NULL; in cifs_put_tcp_session()
1703 server->session_key.len = 0; in cifs_put_tcp_session()
1705 task = xchg(&server->tsk, NULL); in cifs_put_tcp_session()
1717 cifs_dbg(FYI, "UNC: %s\n", ctx->UNC); in cifs_get_tcp_session()
1726 rc = -ENOMEM; in cifs_get_tcp_session()
1730 tcp_ses->hostname = kstrdup(ctx->server_hostname, GFP_KERNEL); in cifs_get_tcp_session()
1731 if (!tcp_ses->hostname) { in cifs_get_tcp_session()
1732 rc = -ENOMEM; in cifs_get_tcp_session()
1736 if (ctx->leaf_fullpath) { in cifs_get_tcp_session()
1737 tcp_ses->leaf_fullpath = kstrdup(ctx->leaf_fullpath, GFP_KERNEL); in cifs_get_tcp_session()
1738 if (!tcp_ses->leaf_fullpath) { in cifs_get_tcp_session()
1739 rc = -ENOMEM; in cifs_get_tcp_session()
1744 if (ctx->nosharesock) in cifs_get_tcp_session()
1745 tcp_ses->nosharesock = true; in cifs_get_tcp_session()
1746 tcp_ses->dfs_conn = ctx->dfs_conn; in cifs_get_tcp_session()
1748 tcp_ses->ops = ctx->ops; in cifs_get_tcp_session()
1749 tcp_ses->vals = ctx->vals; in cifs_get_tcp_session()
1750 cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns)); in cifs_get_tcp_session()
1752 tcp_ses->conn_id = atomic_inc_return(&tcpSesNextId); in cifs_get_tcp_session()
1753 tcp_ses->noblockcnt = ctx->rootfs; in cifs_get_tcp_session()
1754 tcp_ses->noblocksnd = ctx->noblocksnd || ctx->rootfs; in cifs_get_tcp_session()
1755 tcp_ses->noautotune = ctx->noautotune; in cifs_get_tcp_session()
1756 tcp_ses->tcp_nodelay = ctx->sockopt_tcp_nodelay; in cifs_get_tcp_session()
1757 tcp_ses->rdma = ctx->rdma; in cifs_get_tcp_session()
1758 tcp_ses->in_flight = 0; in cifs_get_tcp_session()
1759 tcp_ses->max_in_flight = 0; in cifs_get_tcp_session()
1760 tcp_ses->credits = 1; in cifs_get_tcp_session()
1763 ++primary_server->srv_count; in cifs_get_tcp_session()
1765 tcp_ses->primary_server = primary_server; in cifs_get_tcp_session()
1767 init_waitqueue_head(&tcp_ses->response_q); in cifs_get_tcp_session()
1768 init_waitqueue_head(&tcp_ses->request_q); in cifs_get_tcp_session()
1769 INIT_LIST_HEAD(&tcp_ses->pending_mid_q); in cifs_get_tcp_session()
1770 mutex_init(&tcp_ses->_srv_mutex); in cifs_get_tcp_session()
1771 memcpy(tcp_ses->workstation_RFC1001_name, in cifs_get_tcp_session()
1772 ctx->source_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL); in cifs_get_tcp_session()
1773 memcpy(tcp_ses->server_RFC1001_name, in cifs_get_tcp_session()
1774 ctx->target_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL); in cifs_get_tcp_session()
1775 tcp_ses->session_estab = false; in cifs_get_tcp_session()
1776 tcp_ses->sequence_number = 0; in cifs_get_tcp_session()
1777 tcp_ses->channel_sequence_num = 0; /* only tracked for primary channel */ in cifs_get_tcp_session()
1778 tcp_ses->reconnect_instance = 1; in cifs_get_tcp_session()
1779 tcp_ses->lstrp = jiffies; in cifs_get_tcp_session()
1780 tcp_ses->compression.requested = ctx->compress; in cifs_get_tcp_session()
1781 spin_lock_init(&tcp_ses->req_lock); in cifs_get_tcp_session()
1782 spin_lock_init(&tcp_ses->srv_lock); in cifs_get_tcp_session()
1783 spin_lock_init(&tcp_ses->mid_lock); in cifs_get_tcp_session()
1784 INIT_LIST_HEAD(&tcp_ses->tcp_ses_list); in cifs_get_tcp_session()
1785 INIT_LIST_HEAD(&tcp_ses->smb_ses_list); in cifs_get_tcp_session()
1786 INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request); in cifs_get_tcp_session()
1787 INIT_DELAYED_WORK(&tcp_ses->reconnect, smb2_reconnect_server); in cifs_get_tcp_session()
1788 mutex_init(&tcp_ses->reconnect_mutex); in cifs_get_tcp_session()
1790 mutex_init(&tcp_ses->refpath_lock); in cifs_get_tcp_session()
1792 memcpy(&tcp_ses->srcaddr, &ctx->srcaddr, in cifs_get_tcp_session()
1793 sizeof(tcp_ses->srcaddr)); in cifs_get_tcp_session()
1794 memcpy(&tcp_ses->dstaddr, &ctx->dstaddr, in cifs_get_tcp_session()
1795 sizeof(tcp_ses->dstaddr)); in cifs_get_tcp_session()
1796 if (ctx->use_client_guid) in cifs_get_tcp_session()
1797 memcpy(tcp_ses->client_guid, ctx->client_guid, in cifs_get_tcp_session()
1800 generate_random_uuid(tcp_ses->client_guid); in cifs_get_tcp_session()
1806 tcp_ses->tcpStatus = CifsNew; in cifs_get_tcp_session()
1807 ++tcp_ses->srv_count; in cifs_get_tcp_session()
1809 if (ctx->echo_interval >= SMB_ECHO_INTERVAL_MIN && in cifs_get_tcp_session()
1810 ctx->echo_interval <= SMB_ECHO_INTERVAL_MAX) in cifs_get_tcp_session()
1811 tcp_ses->echo_interval = ctx->echo_interval * HZ; in cifs_get_tcp_session()
1813 tcp_ses->echo_interval = SMB_ECHO_INTERVAL_DEFAULT * HZ; in cifs_get_tcp_session()
1814 if (tcp_ses->rdma) { in cifs_get_tcp_session()
1817 rc = -ENOENT; in cifs_get_tcp_session()
1820 tcp_ses->smbd_conn = smbd_get_connection( in cifs_get_tcp_session()
1821 tcp_ses, (struct sockaddr *)&ctx->dstaddr); in cifs_get_tcp_session()
1822 if (tcp_ses->smbd_conn) { in cifs_get_tcp_session()
1827 rc = -ENOENT; in cifs_get_tcp_session()
1842 tcp_ses->tsk = kthread_run(cifs_demultiplex_thread, in cifs_get_tcp_session()
1844 if (IS_ERR(tcp_ses->tsk)) { in cifs_get_tcp_session()
1845 rc = PTR_ERR(tcp_ses->tsk); in cifs_get_tcp_session()
1850 tcp_ses->min_offload = ctx->min_offload; in cifs_get_tcp_session()
1851 tcp_ses->retrans = ctx->retrans; in cifs_get_tcp_session()
1857 spin_lock(&tcp_ses->srv_lock); in cifs_get_tcp_session()
1858 tcp_ses->tcpStatus = CifsNeedNegotiate; in cifs_get_tcp_session()
1859 spin_unlock(&tcp_ses->srv_lock); in cifs_get_tcp_session()
1861 if ((ctx->max_credits < 20) || (ctx->max_credits > 60000)) in cifs_get_tcp_session()
1862 tcp_ses->max_credits = SMB2_MAX_CREDITS_AVAILABLE; in cifs_get_tcp_session()
1864 tcp_ses->max_credits = ctx->max_credits; in cifs_get_tcp_session()
1866 tcp_ses->nr_targets = 1; in cifs_get_tcp_session()
1867 tcp_ses->ignore_signature = ctx->ignore_signature; in cifs_get_tcp_session()
1870 list_add(&tcp_ses->tcp_ses_list, &cifs_tcp_ses_list); in cifs_get_tcp_session()
1874 queue_delayed_work(cifsiod_wq, &tcp_ses->echo, tcp_ses->echo_interval); in cifs_get_tcp_session()
1886 cifs_put_tcp_session(tcp_ses->primary_server, false); in cifs_get_tcp_session()
1887 kfree(tcp_ses->hostname); in cifs_get_tcp_session()
1888 kfree(tcp_ses->leaf_fullpath); in cifs_get_tcp_session()
1889 if (tcp_ses->ssocket) in cifs_get_tcp_session()
1890 sock_release(tcp_ses->ssocket); in cifs_get_tcp_session()
1901 struct TCP_Server_Info *server = ses->server; in match_session()
1904 if (!match_super && ctx->dfs_root_ses != ses->dfs_root_ses) in match_session()
1911 if (ses->chan_max < ctx->max_channels) in match_session()
1914 ctx_sec = server->ops->select_sectype(server, ctx->sectype); in match_session()
1915 ses_sec = server->ops->select_sectype(server, ses->sectype); in match_session()
1923 if (!uid_eq(ctx->cred_uid, ses->cred_uid)) in match_session()
1930 if (ses->user_name == NULL) { in match_session()
1931 if (!ctx->nullauth) in match_session()
1937 if (strncmp(ses->user_name, in match_session()
1938 ctx->username ? ctx->username : "", in match_session()
1941 if ((ctx->username && strlen(ctx->username) != 0) && in match_session()
1942 ses->password != NULL) { in match_session()
1950 if (ses->password2 != NULL && ctx->password2 != NULL) { in match_session()
1951 if (!((strncmp(ses->password, ctx->password ? in match_session()
1952 ctx->password : "", CIFS_MAX_PASSWORD_LEN) == 0 && in match_session()
1953 strncmp(ses->password2, ctx->password2, in match_session()
1955 (strncmp(ses->password, ctx->password2, in match_session()
1957 strncmp(ses->password2, ctx->password ? in match_session()
1958 ctx->password : "", CIFS_MAX_PASSWORD_LEN) == 0))) in match_session()
1961 } else if ((ses->password2 == NULL && ctx->password2 != NULL) || in match_session()
1962 (ses->password2 != NULL && ctx->password2 == NULL)) { in match_session()
1966 if (strncmp(ses->password, ctx->password ? in match_session()
1967 ctx->password : "", CIFS_MAX_PASSWORD_LEN)) in match_session()
1973 if (strcmp(ctx->local_nls->charset, ses->local_nls->charset)) in match_session()
1980 * cifs_setup_ipc - helper to setup the IPC tcon for the session
1986 * tcon_ipc. The IPC tcon has the same lifetime as the session.
1992 struct cifs_tcon *tcon; in cifs_setup_ipc() local
1995 struct TCP_Server_Info *server = ses->server; in cifs_setup_ipc()
2001 if (ctx->seal) { in cifs_setup_ipc()
2002 if (server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION) in cifs_setup_ipc()
2007 return -EOPNOTSUPP; in cifs_setup_ipc()
2012 tcon = tcon_info_alloc(false, netfs_trace_tcon_ref_new_ipc); in cifs_setup_ipc()
2013 if (tcon == NULL) in cifs_setup_ipc()
2014 return -ENOMEM; in cifs_setup_ipc()
2016 spin_lock(&server->srv_lock); in cifs_setup_ipc()
2017 scnprintf(unc, sizeof(unc), "\\\\%s\\IPC$", server->hostname); in cifs_setup_ipc()
2018 spin_unlock(&server->srv_lock); in cifs_setup_ipc()
2021 tcon->ses = ses; in cifs_setup_ipc()
2022 tcon->ipc = true; in cifs_setup_ipc()
2023 tcon->seal = seal; in cifs_setup_ipc()
2024 rc = server->ops->tree_connect(xid, ses, unc, tcon, ctx->local_nls); in cifs_setup_ipc()
2029 tconInfoFree(tcon, netfs_trace_tcon_ref_free_ipc_fail); in cifs_setup_ipc()
2033 cifs_dbg(FYI, "IPC tcon rc=%d ipc tid=0x%x\n", rc, tcon->tid); in cifs_setup_ipc()
2035 spin_lock(&tcon->tc_lock); in cifs_setup_ipc()
2036 tcon->status = TID_GOOD; in cifs_setup_ipc()
2037 spin_unlock(&tcon->tc_lock); in cifs_setup_ipc()
2038 ses->tcon_ipc = tcon; in cifs_setup_ipc()
2049 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { in cifs_find_smb_ses()
2050 spin_lock(&ses->ses_lock); in cifs_find_smb_ses()
2051 if (ses->ses_status == SES_EXITING) { in cifs_find_smb_ses()
2052 spin_unlock(&ses->ses_lock); in cifs_find_smb_ses()
2055 spin_lock(&ses->chan_lock); in cifs_find_smb_ses()
2057 spin_unlock(&ses->chan_lock); in cifs_find_smb_ses()
2058 spin_unlock(&ses->ses_lock); in cifs_find_smb_ses()
2062 spin_unlock(&ses->chan_lock); in cifs_find_smb_ses()
2063 spin_unlock(&ses->ses_lock); in cifs_find_smb_ses()
2073 struct TCP_Server_Info *server = ses->server; in __cifs_put_smb_ses()
2074 struct cifs_tcon *tcon; in __cifs_put_smb_ses() local
2081 spin_lock(&ses->ses_lock); in __cifs_put_smb_ses()
2083 __func__, ses->Suid, ses->ses_count, ses->ses_status, in __cifs_put_smb_ses()
2084 ses->tcon_ipc ? ses->tcon_ipc->tree_name : "none"); in __cifs_put_smb_ses()
2085 if (ses->ses_status == SES_EXITING || --ses->ses_count > 0) { in __cifs_put_smb_ses()
2086 spin_unlock(&ses->ses_lock); in __cifs_put_smb_ses()
2091 WARN_ON(ses->ses_count < 0); in __cifs_put_smb_ses()
2093 spin_lock(&ses->chan_lock); in __cifs_put_smb_ses()
2095 spin_unlock(&ses->chan_lock); in __cifs_put_smb_ses()
2097 do_logoff = ses->ses_status == SES_GOOD && server->ops->logoff; in __cifs_put_smb_ses()
2098 ses->ses_status = SES_EXITING; in __cifs_put_smb_ses()
2099 tcon = ses->tcon_ipc; in __cifs_put_smb_ses()
2100 ses->tcon_ipc = NULL; in __cifs_put_smb_ses()
2101 spin_unlock(&ses->ses_lock); in __cifs_put_smb_ses()
2109 * files on session close, as specified in MS-SMB2 3.3.5.6 Receiving an in __cifs_put_smb_ses()
2112 tconInfoFree(tcon, netfs_trace_tcon_ref_free_ipc); in __cifs_put_smb_ses()
2115 rc = server->ops->logoff(xid, ses); in __cifs_put_smb_ses()
2123 list_del_init(&ses->smb_ses_list); in __cifs_put_smb_ses()
2127 for (i = 1; i < ses->chan_count; i++) { in __cifs_put_smb_ses()
2128 if (ses->chans[i].iface) { in __cifs_put_smb_ses()
2129 kref_put(&ses->chans[i].iface->refcount, release_iface); in __cifs_put_smb_ses()
2130 ses->chans[i].iface = NULL; in __cifs_put_smb_ses()
2132 cifs_put_tcp_session(ses->chans[i].server, 0); in __cifs_put_smb_ses()
2133 ses->chans[i].server = NULL; in __cifs_put_smb_ses()
2136 /* we now account for primary channel in iface->refcount */ in __cifs_put_smb_ses()
2137 if (ses->chans[0].iface) { in __cifs_put_smb_ses()
2138 kref_put(&ses->chans[0].iface->refcount, release_iface); in __cifs_put_smb_ses()
2139 ses->chans[0].server = NULL; in __cifs_put_smb_ses()
2161 struct TCP_Server_Info *server = ses->server; in cifs_set_cifscreds()
2168 return -ENOMEM; in cifs_set_cifscreds()
2171 switch (server->dstaddr.ss_family) { in cifs_set_cifscreds()
2173 sa = (struct sockaddr_in *)&server->dstaddr; in cifs_set_cifscreds()
2174 sprintf(desc, "cifs:a:%pI4", &sa->sin_addr.s_addr); in cifs_set_cifscreds()
2177 sa6 = (struct sockaddr_in6 *)&server->dstaddr; in cifs_set_cifscreds()
2178 sprintf(desc, "cifs:a:%pI6c", &sa6->sin6_addr.s6_addr); in cifs_set_cifscreds()
2182 server->dstaddr.ss_family); in cifs_set_cifscreds()
2183 rc = -EINVAL; in cifs_set_cifscreds()
2190 if (!ses->domainName) { in cifs_set_cifscreds()
2197 sprintf(desc, "cifs:d:%s", ses->domainName); in cifs_set_cifscreds()
2207 down_read(&key->sem); in cifs_set_cifscreds()
2210 rc = upayload ? PTR_ERR(upayload) : -EINVAL; in cifs_set_cifscreds()
2215 payload = upayload->data; in cifs_set_cifscreds()
2216 delim = strnchr(payload, upayload->datalen, ':'); in cifs_set_cifscreds()
2220 upayload->datalen); in cifs_set_cifscreds()
2221 rc = -EINVAL; in cifs_set_cifscreds()
2225 len = delim - payload; in cifs_set_cifscreds()
2229 rc = -EINVAL; in cifs_set_cifscreds()
2233 ctx->username = kstrndup(payload, len, GFP_KERNEL); in cifs_set_cifscreds()
2234 if (!ctx->username) { in cifs_set_cifscreds()
2237 rc = -ENOMEM; in cifs_set_cifscreds()
2240 cifs_dbg(FYI, "%s: username=%s\n", __func__, ctx->username); in cifs_set_cifscreds()
2242 len = key->datalen - (len + 1); in cifs_set_cifscreds()
2245 rc = -EINVAL; in cifs_set_cifscreds()
2246 kfree(ctx->username); in cifs_set_cifscreds()
2247 ctx->username = NULL; in cifs_set_cifscreds()
2253 ctx->password = kstrndup(delim, len, GFP_KERNEL); in cifs_set_cifscreds()
2254 if (!ctx->password) { in cifs_set_cifscreds()
2257 rc = -ENOMEM; in cifs_set_cifscreds()
2258 kfree(ctx->username); in cifs_set_cifscreds()
2259 ctx->username = NULL; in cifs_set_cifscreds()
2267 if (is_domain && ses->domainName) { in cifs_set_cifscreds()
2268 ctx->domainname = kstrdup(ses->domainName, GFP_KERNEL); in cifs_set_cifscreds()
2269 if (!ctx->domainname) { in cifs_set_cifscreds()
2272 rc = -ENOMEM; in cifs_set_cifscreds()
2273 kfree(ctx->username); in cifs_set_cifscreds()
2274 ctx->username = NULL; in cifs_set_cifscreds()
2275 kfree_sensitive(ctx->password); in cifs_set_cifscreds()
2276 /* no need to free ctx->password2 since not allocated in this path */ in cifs_set_cifscreds()
2277 ctx->password = NULL; in cifs_set_cifscreds()
2282 strscpy(ctx->workstation_name, ses->workstation_name, sizeof(ctx->workstation_name)); in cifs_set_cifscreds()
2285 up_read(&key->sem); in cifs_set_cifscreds()
2297 return -ENOSYS; in cifs_set_cifscreds()
2302 * cifs_get_smb_ses - get a session matching @ctx data from @server
2317 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; in cifs_get_smb_ses()
2318 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; in cifs_get_smb_ses()
2325 ses->ses_status); in cifs_get_smb_ses()
2327 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2329 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2332 mutex_lock(&ses->session_mutex); in cifs_get_smb_ses()
2337 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2338 /* problem -- put our ses reference */ in cifs_get_smb_ses()
2345 ctx->local_nls); in cifs_get_smb_ses()
2347 if (((rc == -EACCES) || (rc == -EKEYEXPIRED) || in cifs_get_smb_ses()
2348 (rc == -EKEYREVOKED)) && !retries && ses->password2) { in cifs_get_smb_ses()
2351 swap(ses->password, ses->password2); in cifs_get_smb_ses()
2354 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2355 /* problem -- put our reference */ in cifs_get_smb_ses()
2360 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2362 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2364 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2372 rc = -ENOMEM; in cifs_get_smb_ses()
2380 ses->server = server; in cifs_get_smb_ses()
2381 if (server->dstaddr.ss_family == AF_INET6) in cifs_get_smb_ses()
2382 sprintf(ses->ip_addr, "%pI6", &addr6->sin6_addr); in cifs_get_smb_ses()
2384 sprintf(ses->ip_addr, "%pI4", &addr->sin_addr); in cifs_get_smb_ses()
2386 if (ctx->username) { in cifs_get_smb_ses()
2387 ses->user_name = kstrdup(ctx->username, GFP_KERNEL); in cifs_get_smb_ses()
2388 if (!ses->user_name) in cifs_get_smb_ses()
2392 /* ctx->password freed at unmount */ in cifs_get_smb_ses()
2393 if (ctx->password) { in cifs_get_smb_ses()
2394 ses->password = kstrdup(ctx->password, GFP_KERNEL); in cifs_get_smb_ses()
2395 if (!ses->password) in cifs_get_smb_ses()
2398 /* ctx->password freed at unmount */ in cifs_get_smb_ses()
2399 if (ctx->password2) { in cifs_get_smb_ses()
2400 ses->password2 = kstrdup(ctx->password2, GFP_KERNEL); in cifs_get_smb_ses()
2401 if (!ses->password2) in cifs_get_smb_ses()
2404 if (ctx->domainname) { in cifs_get_smb_ses()
2405 ses->domainName = kstrdup(ctx->domainname, GFP_KERNEL); in cifs_get_smb_ses()
2406 if (!ses->domainName) in cifs_get_smb_ses()
2410 strscpy(ses->workstation_name, ctx->workstation_name, sizeof(ses->workstation_name)); in cifs_get_smb_ses()
2412 if (ctx->domainauto) in cifs_get_smb_ses()
2413 ses->domainAuto = ctx->domainauto; in cifs_get_smb_ses()
2414 ses->cred_uid = ctx->cred_uid; in cifs_get_smb_ses()
2415 ses->linux_uid = ctx->linux_uid; in cifs_get_smb_ses()
2417 ses->sectype = ctx->sectype; in cifs_get_smb_ses()
2418 ses->sign = ctx->sign; in cifs_get_smb_ses()
2419 ses->local_nls = load_nls(ctx->local_nls->charset); in cifs_get_smb_ses()
2421 /* add server as first channel */ in cifs_get_smb_ses()
2422 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2423 ses->chans[0].server = server; in cifs_get_smb_ses()
2424 ses->chan_count = 1; in cifs_get_smb_ses()
2425 ses->chan_max = ctx->multichannel ? ctx->max_channels:1; in cifs_get_smb_ses()
2426 ses->chans_need_reconnect = 1; in cifs_get_smb_ses()
2427 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2430 mutex_lock(&ses->session_mutex); in cifs_get_smb_ses()
2433 rc = cifs_setup_session(xid, ses, server, ctx->local_nls); in cifs_get_smb_ses()
2434 mutex_unlock(&ses->session_mutex); in cifs_get_smb_ses()
2436 /* each channel uses a different signing key */ in cifs_get_smb_ses()
2437 spin_lock(&ses->chan_lock); in cifs_get_smb_ses()
2438 memcpy(ses->chans[0].signkey, ses->smb3signingkey, in cifs_get_smb_ses()
2439 sizeof(ses->smb3signingkey)); in cifs_get_smb_ses()
2440 spin_unlock(&ses->chan_lock); in cifs_get_smb_ses()
2443 if (((rc == -EACCES) || (rc == -EKEYEXPIRED) || in cifs_get_smb_ses()
2444 (rc == -EKEYREVOKED)) && !retries && ses->password2) { in cifs_get_smb_ses()
2447 swap(ses->password, ses->password2); in cifs_get_smb_ses()
2454 * success, put it on the list and add it as first channel in cifs_get_smb_ses()
2459 ses->dfs_root_ses = ctx->dfs_root_ses; in cifs_get_smb_ses()
2460 list_add(&ses->smb_ses_list, &server->smb_ses_list); in cifs_get_smb_ses()
2476 static int match_tcon(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) in match_tcon() argument
2478 struct TCP_Server_Info *server = tcon->ses->server; in match_tcon()
2480 if (tcon->status == TID_EXITING) in match_tcon()
2483 if (tcon->origin_fullpath) { in match_tcon()
2484 if (!ctx->source || in match_tcon()
2485 !dfs_src_pathname_equal(ctx->source, in match_tcon()
2486 tcon->origin_fullpath)) in match_tcon()
2488 } else if (!server->leaf_fullpath && in match_tcon()
2489 strncmp(tcon->tree_name, ctx->UNC, MAX_TREE_SIZE)) { in match_tcon()
2492 if (tcon->seal != ctx->seal) in match_tcon()
2494 if (tcon->snapshot_time != ctx->snapshot_time) in match_tcon()
2496 if (tcon->handle_timeout != ctx->handle_timeout) in match_tcon()
2498 if (tcon->no_lease != ctx->no_lease) in match_tcon()
2500 if (tcon->nodelete != ctx->nodelete) in match_tcon()
2502 if (tcon->posix_extensions != ctx->linux_ext) in match_tcon()
2510 struct cifs_tcon *tcon; in cifs_find_tcon() local
2513 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { in cifs_find_tcon()
2514 spin_lock(&tcon->tc_lock); in cifs_find_tcon()
2515 if (!match_tcon(tcon, ctx)) { in cifs_find_tcon()
2516 spin_unlock(&tcon->tc_lock); in cifs_find_tcon()
2519 ++tcon->tc_count; in cifs_find_tcon()
2520 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count, in cifs_find_tcon()
2522 spin_unlock(&tcon->tc_lock); in cifs_find_tcon()
2524 return tcon; in cifs_find_tcon()
2531 cifs_put_tcon(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace) in cifs_put_tcon() argument
2538 * IPC tcon share the lifetime of their session and are in cifs_put_tcon()
2541 if (tcon == NULL || tcon->ipc) in cifs_put_tcon()
2544 ses = tcon->ses; in cifs_put_tcon()
2545 cifs_dbg(FYI, "%s: tc_count=%d\n", __func__, tcon->tc_count); in cifs_put_tcon()
2547 spin_lock(&tcon->tc_lock); in cifs_put_tcon()
2548 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count - 1, trace); in cifs_put_tcon()
2549 if (--tcon->tc_count > 0) { in cifs_put_tcon()
2550 spin_unlock(&tcon->tc_lock); in cifs_put_tcon()
2556 WARN_ON(tcon->tc_count < 0); in cifs_put_tcon()
2558 list_del_init(&tcon->tcon_list); in cifs_put_tcon()
2559 tcon->status = TID_EXITING; in cifs_put_tcon()
2560 spin_unlock(&tcon->tc_lock); in cifs_put_tcon()
2564 cancel_delayed_work_sync(&tcon->query_interfaces); in cifs_put_tcon()
2566 cancel_delayed_work_sync(&tcon->dfs_cache_work); in cifs_put_tcon()
2567 list_replace_init(&tcon->dfs_ses_list, &ses_list); in cifs_put_tcon()
2570 if (tcon->use_witness) { in cifs_put_tcon()
2573 rc = cifs_swn_unregister(tcon); in cifs_put_tcon()
2581 if (ses->server->ops->tree_disconnect) in cifs_put_tcon()
2582 ses->server->ops->tree_disconnect(xid, tcon); in cifs_put_tcon()
2585 cifs_fscache_release_super_cookie(tcon); in cifs_put_tcon()
2586 tconInfoFree(tcon, netfs_trace_tcon_ref_free); in cifs_put_tcon()
2594 * cifs_get_tcon - get a tcon matching @ctx data from @ses
2598 * - tcon refcount is the number of mount points using the tcon.
2599 * - ses refcount is the number of tcon using the session.
2607 * a) a new tcon already allocated with refcount=1 (1 mount point) and
2608 * its session refcount incremented (1 new tcon). This +1 was
2611 * b) an existing tcon with refcount+1 (add a mount point to it) and
2612 * identical ses refcount (no new tcon). Because of (1) we need to
2618 struct cifs_tcon *tcon; in cifs_get_tcon() local
2622 tcon = cifs_find_tcon(ses, ctx); in cifs_get_tcon()
2623 if (tcon) { in cifs_get_tcon()
2625 * tcon has refcount already incremented but we need to in cifs_get_tcon()
2630 return tcon; in cifs_get_tcon()
2633 if (!ses->server->ops->tree_connect) { in cifs_get_tcon()
2634 rc = -ENOSYS; in cifs_get_tcon()
2638 if (ses->server->dialect >= SMB20_PROT_ID && in cifs_get_tcon()
2639 (ses->server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING)) in cifs_get_tcon()
2640 nohandlecache = ctx->nohandlecache || !dir_cache_timeout; in cifs_get_tcon()
2643 tcon = tcon_info_alloc(!nohandlecache, netfs_trace_tcon_ref_new); in cifs_get_tcon()
2644 if (tcon == NULL) { in cifs_get_tcon()
2645 rc = -ENOMEM; in cifs_get_tcon()
2648 tcon->nohandlecache = nohandlecache; in cifs_get_tcon()
2650 if (ctx->snapshot_time) { in cifs_get_tcon()
2651 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2654 rc = -EOPNOTSUPP; in cifs_get_tcon()
2657 tcon->snapshot_time = ctx->snapshot_time; in cifs_get_tcon()
2660 if (ctx->handle_timeout) { in cifs_get_tcon()
2661 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2664 rc = -EOPNOTSUPP; in cifs_get_tcon()
2667 tcon->handle_timeout = ctx->handle_timeout; in cifs_get_tcon()
2670 tcon->ses = ses; in cifs_get_tcon()
2671 if (ctx->password) { in cifs_get_tcon()
2672 tcon->password = kstrdup(ctx->password, GFP_KERNEL); in cifs_get_tcon()
2673 if (!tcon->password) { in cifs_get_tcon()
2674 rc = -ENOMEM; in cifs_get_tcon()
2679 if (ctx->seal) { in cifs_get_tcon()
2680 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2683 rc = -EOPNOTSUPP; in cifs_get_tcon()
2685 } else if (tcon->ses->server->capabilities & in cifs_get_tcon()
2687 tcon->seal = true; in cifs_get_tcon()
2690 rc = -EOPNOTSUPP; in cifs_get_tcon()
2695 if (ctx->linux_ext) { in cifs_get_tcon()
2696 if (ses->server->posix_ext_supported) { in cifs_get_tcon()
2697 tcon->posix_extensions = true; in cifs_get_tcon()
2699 } else if ((ses->server->vals->protocol_id == SMB311_PROT_ID) || in cifs_get_tcon()
2700 (strcmp(ses->server->vals->version_string, in cifs_get_tcon()
2702 (strcmp(ses->server->vals->version_string, in cifs_get_tcon()
2705 rc = -EOPNOTSUPP; in cifs_get_tcon()
2707 } else if (ses->server->vals->protocol_id == SMB10_PROT_ID) in cifs_get_tcon()
2712 rc = -EOPNOTSUPP; in cifs_get_tcon()
2717 rc = -EOPNOTSUPP; in cifs_get_tcon()
2723 rc = ses->server->ops->tree_connect(xid, ses, ctx->UNC, tcon, in cifs_get_tcon()
2724 ctx->local_nls); in cifs_get_tcon()
2726 cifs_dbg(FYI, "Tcon rc = %d\n", rc); in cifs_get_tcon()
2730 tcon->use_persistent = false; in cifs_get_tcon()
2732 if (ctx->persistent) { in cifs_get_tcon()
2733 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2736 rc = -EOPNOTSUPP; in cifs_get_tcon()
2738 } else if (ses->server->capabilities & in cifs_get_tcon()
2740 tcon->use_persistent = true; in cifs_get_tcon()
2744 rc = -EOPNOTSUPP; in cifs_get_tcon()
2747 } else if ((tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) in cifs_get_tcon()
2748 && (ses->server->capabilities & SMB2_GLOBAL_CAP_PERSISTENT_HANDLES) in cifs_get_tcon()
2749 && (ctx->nopersistent == false)) { in cifs_get_tcon()
2751 tcon->use_persistent = true; in cifs_get_tcon()
2752 } else if (ctx->resilient) { in cifs_get_tcon()
2753 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2756 rc = -EOPNOTSUPP; in cifs_get_tcon()
2759 tcon->use_resilient = true; in cifs_get_tcon()
2762 tcon->use_witness = false; in cifs_get_tcon()
2763 if (IS_ENABLED(CONFIG_CIFS_SWN_UPCALL) && ctx->witness) { in cifs_get_tcon()
2764 if (ses->server->vals->protocol_id >= SMB30_PROT_ID) { in cifs_get_tcon()
2765 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) { in cifs_get_tcon()
2770 tcon->use_witness = true; in cifs_get_tcon()
2772 rc = cifs_swn_register(tcon); in cifs_get_tcon()
2778 /* TODO: try to extend for non-cluster uses (eg multichannel) */ in cifs_get_tcon()
2780 rc = -EOPNOTSUPP; in cifs_get_tcon()
2785 rc = -EOPNOTSUPP; in cifs_get_tcon()
2791 if (tcon->share_flags & SMB2_SHAREFLAG_NO_CACHING) { in cifs_get_tcon()
2792 if (ctx->cache_ro) in cifs_get_tcon()
2794 else if (ctx->cache_rw) in cifs_get_tcon()
2798 if (ctx->no_lease) { in cifs_get_tcon()
2799 if (ses->server->vals->protocol_id == 0) { in cifs_get_tcon()
2802 rc = -EOPNOTSUPP; in cifs_get_tcon()
2805 tcon->no_lease = ctx->no_lease; in cifs_get_tcon()
2813 tcon->retry = ctx->retry; in cifs_get_tcon()
2814 tcon->nocase = ctx->nocase; in cifs_get_tcon()
2815 tcon->broken_sparse_sup = ctx->no_sparse; in cifs_get_tcon()
2816 tcon->max_cached_dirs = ctx->max_cached_dirs; in cifs_get_tcon()
2817 tcon->nodelete = ctx->nodelete; in cifs_get_tcon()
2818 tcon->local_lease = ctx->local_lease; in cifs_get_tcon()
2819 tcon->status = TID_GOOD; in cifs_get_tcon()
2821 if (ses->server->dialect >= SMB30_PROT_ID && in cifs_get_tcon()
2822 (ses->server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL)) { in cifs_get_tcon()
2824 queue_delayed_work(cifsiod_wq, &tcon->query_interfaces, in cifs_get_tcon()
2828 list_add(&tcon->tcon_list, &ses->tcon_list); in cifs_get_tcon()
2831 return tcon; in cifs_get_tcon()
2834 tconInfoFree(tcon, netfs_trace_tcon_ref_free_fail); in cifs_get_tcon()
2844 if (!atomic_dec_and_test(&tlink->tl_count) || in cifs_put_tlink()
2845 test_bit(TCON_LINK_IN_TREE, &tlink->tl_flags)) { in cifs_put_tlink()
2846 tlink->tl_time = jiffies; in cifs_put_tlink()
2859 struct cifs_sb_info *new = mnt_data->cifs_sb; in compare_mount_options()
2860 unsigned int oldflags = old->mnt_cifs_flags & CIFS_MOUNT_MASK; in compare_mount_options()
2861 unsigned int newflags = new->mnt_cifs_flags & CIFS_MOUNT_MASK; in compare_mount_options()
2863 if ((sb->s_flags & CIFS_MS_MASK) != (mnt_data->flags & CIFS_MS_MASK)) in compare_mount_options()
2866 if (old->mnt_cifs_serverino_autodisabled) in compare_mount_options()
2876 if (new->ctx->wsize && new->ctx->wsize < old->ctx->wsize) in compare_mount_options()
2879 if (new->ctx->rsize && new->ctx->rsize < old->ctx->rsize) in compare_mount_options()
2882 if (!uid_eq(old->ctx->linux_uid, new->ctx->linux_uid) || in compare_mount_options()
2883 !gid_eq(old->ctx->linux_gid, new->ctx->linux_gid)) in compare_mount_options()
2886 if (old->ctx->file_mode != new->ctx->file_mode || in compare_mount_options()
2887 old->ctx->dir_mode != new->ctx->dir_mode) in compare_mount_options()
2890 if (strcmp(old->local_nls->charset, new->local_nls->charset)) in compare_mount_options()
2893 if (old->ctx->acregmax != new->ctx->acregmax) in compare_mount_options()
2895 if (old->ctx->acdirmax != new->ctx->acdirmax) in compare_mount_options()
2897 if (old->ctx->closetimeo != new->ctx->closetimeo) in compare_mount_options()
2899 if (old->ctx->reparse_type != new->ctx->reparse_type) in compare_mount_options()
2906 struct cifs_tcon *tcon, in match_prepath() argument
2909 struct smb3_fs_context *ctx = mnt_data->ctx; in match_prepath()
2911 struct cifs_sb_info *new = mnt_data->cifs_sb; in match_prepath()
2912 bool old_set = (old->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH) && in match_prepath()
2913 old->prepath; in match_prepath()
2914 bool new_set = (new->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH) && in match_prepath()
2915 new->prepath; in match_prepath()
2917 if (tcon->origin_fullpath && in match_prepath()
2918 dfs_src_pathname_equal(tcon->origin_fullpath, ctx->source)) in match_prepath()
2921 if (old_set && new_set && !strcmp(new->prepath, old->prepath)) in match_prepath()
2937 struct cifs_tcon *tcon; in cifs_match_super() local
2945 if (CIFS_MOUNT_SHUTDOWN & cifs_sb->mnt_cifs_flags) { in cifs_match_super()
2957 tcon = tlink_tcon(tlink); in cifs_match_super()
2958 ses = tcon->ses; in cifs_match_super()
2959 tcp_srv = ses->server; in cifs_match_super()
2961 ctx = mnt_data->ctx; in cifs_match_super()
2963 spin_lock(&tcp_srv->srv_lock); in cifs_match_super()
2964 spin_lock(&ses->ses_lock); in cifs_match_super()
2965 spin_lock(&ses->chan_lock); in cifs_match_super()
2966 spin_lock(&tcon->tc_lock); in cifs_match_super()
2969 !match_tcon(tcon, ctx) || in cifs_match_super()
2970 !match_prepath(sb, tcon, mnt_data)) { in cifs_match_super()
2977 spin_unlock(&tcon->tc_lock); in cifs_match_super()
2978 spin_unlock(&ses->chan_lock); in cifs_match_super()
2979 spin_unlock(&ses->ses_lock); in cifs_match_super()
2980 spin_unlock(&tcp_srv->srv_lock); in cifs_match_super()
2994 struct sock *sk = sock->sk; in cifs_reclassify_socket4()
2997 sock_lock_init_class_and_name(sk, "slock-AF_INET-CIFS", in cifs_reclassify_socket4()
2998 &cifs_slock_key[0], "sk_lock-AF_INET-CIFS", &cifs_key[0]); in cifs_reclassify_socket4()
3004 struct sock *sk = sock->sk; in cifs_reclassify_socket6()
3007 sock_lock_init_class_and_name(sk, "slock-AF_INET6-CIFS", in cifs_reclassify_socket6()
3008 &cifs_slock_key[1], "sk_lock-AF_INET6-CIFS", &cifs_key[1]); in cifs_reclassify_socket6()
3041 if (server->srcaddr.ss_family != AF_UNSPEC) { in bind_socket()
3043 struct socket *socket = server->ssocket; in bind_socket()
3046 (struct sockaddr *) &server->srcaddr, in bind_socket()
3047 sizeof(server->srcaddr)); in bind_socket()
3052 saddr4 = (struct sockaddr_in *)&server->srcaddr; in bind_socket()
3053 saddr6 = (struct sockaddr_in6 *)&server->srcaddr; in bind_socket()
3054 if (saddr6->sin6_family == AF_INET6) in bind_socket()
3056 &saddr6->sin6_addr, rc); in bind_socket()
3059 &saddr4->sin_addr.s_addr, rc); in bind_socket()
3071 * negprot - BB check reconnection in case where second in ip_rfc1001_connect()
3082 if (server->server_RFC1001_name[0] != 0) in ip_rfc1001_connect()
3084 server->server_RFC1001_name, in ip_rfc1001_connect()
3094 if (server->workstation_RFC1001_name[0] != 0) in ip_rfc1001_connect()
3096 server->workstation_RFC1001_name, in ip_rfc1001_connect()
3117 return (rc == -EINTR || rc == -EAGAIN) ? rc : -ECONNABORTED; in ip_rfc1001_connect()
3139 saddr = (struct sockaddr *) &server->dstaddr; in generic_ip_connect()
3141 if (server->dstaddr.ss_family == AF_INET6) { in generic_ip_connect()
3142 struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&server->dstaddr; in generic_ip_connect()
3144 sport = ipv6->sin6_port; in generic_ip_connect()
3147 cifs_dbg(FYI, "%s: connecting to [%pI6]:%d\n", __func__, &ipv6->sin6_addr, in generic_ip_connect()
3150 struct sockaddr_in *ipv4 = (struct sockaddr_in *)&server->dstaddr; in generic_ip_connect()
3152 sport = ipv4->sin_port; in generic_ip_connect()
3155 cifs_dbg(FYI, "%s: connecting to %pI4:%d\n", __func__, &ipv4->sin_addr, in generic_ip_connect()
3159 if (server->ssocket) { in generic_ip_connect()
3160 socket = server->ssocket; in generic_ip_connect()
3166 IPPROTO_TCP, &server->ssocket, 1); in generic_ip_connect()
3172 sk = server->ssocket->sk; in generic_ip_connect()
3173 __netns_tracker_free(net, &sk->ns_tracker, false); in generic_ip_connect()
3174 sk->sk_net_refcnt = 1; in generic_ip_connect()
3175 get_net_track(net, &sk->ns_tracker, GFP_KERNEL); in generic_ip_connect()
3180 socket = server->ssocket; in generic_ip_connect()
3181 socket->sk->sk_allocation = GFP_NOFS; in generic_ip_connect()
3182 socket->sk->sk_use_task_frag = false; in generic_ip_connect()
3198 socket->sk->sk_rcvtimeo = 7 * HZ; in generic_ip_connect()
3199 socket->sk->sk_sndtimeo = 5 * HZ; in generic_ip_connect()
3202 if (server->noautotune) { in generic_ip_connect()
3203 if (socket->sk->sk_sndbuf < (200 * 1024)) in generic_ip_connect()
3204 socket->sk->sk_sndbuf = 200 * 1024; in generic_ip_connect()
3205 if (socket->sk->sk_rcvbuf < (140 * 1024)) in generic_ip_connect()
3206 socket->sk->sk_rcvbuf = 140 * 1024; in generic_ip_connect()
3209 if (server->tcp_nodelay) in generic_ip_connect()
3210 tcp_sock_set_nodelay(socket->sk); in generic_ip_connect()
3213 socket->sk->sk_sndbuf, in generic_ip_connect()
3214 socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo); in generic_ip_connect()
3217 server->noblockcnt ? O_NONBLOCK : 0); in generic_ip_connect()
3221 * reconnect failover - if possible. in generic_ip_connect()
3223 if (server->noblockcnt && rc == -EINPROGRESS) in generic_ip_connect()
3227 trace_smb3_connect_err(server->hostname, server->conn_id, &server->dstaddr, rc); in generic_ip_connect()
3229 server->ssocket = NULL; in generic_ip_connect()
3232 trace_smb3_connect_done(server->hostname, server->conn_id, &server->dstaddr); in generic_ip_connect()
3243 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; in ip_connect()
3244 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; in ip_connect()
3246 if (server->dstaddr.ss_family == AF_INET6) in ip_connect()
3247 sport = &addr6->sin6_port; in ip_connect()
3249 sport = &addr->sin_port; in ip_connect()
3269 void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, in reset_cifs_unix_caps() argument
3277 * Perhaps we could add a backpointer to array of sb from tcon in reset_cifs_unix_caps()
3279 * sb as NFS - then we only have one backpointer to sb. in reset_cifs_unix_caps()
3283 __u64 saved_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); in reset_cifs_unix_caps()
3285 if (ctx && ctx->no_linux_ext) { in reset_cifs_unix_caps()
3286 tcon->fsUnixInfo.Capability = 0; in reset_cifs_unix_caps()
3287 tcon->unix_ext = 0; /* Unix Extensions disabled */ in reset_cifs_unix_caps()
3291 tcon->unix_ext = 1; /* Unix Extensions supported */ in reset_cifs_unix_caps()
3293 if (!tcon->unix_ext) { in reset_cifs_unix_caps()
3298 if (!CIFSSMBQFSUnixInfo(xid, tcon)) { in reset_cifs_unix_caps()
3299 __u64 cap = le64_to_cpu(tcon->fsUnixInfo.Capability); in reset_cifs_unix_caps()
3324 cifs_dbg(VFS, "per-share encryption not supported yet\n"); in reset_cifs_unix_caps()
3327 if (ctx && ctx->no_psx_acl) in reset_cifs_unix_caps()
3332 cifs_sb->mnt_cifs_flags |= in reset_cifs_unix_caps()
3336 if (ctx && ctx->posix_paths == 0) in reset_cifs_unix_caps()
3341 cifs_sb->mnt_cifs_flags |= in reset_cifs_unix_caps()
3366 if (CIFSSMBSetFSUnixInfo(xid, tcon, cap)) { in reset_cifs_unix_caps()
3379 struct smb3_fs_context *ctx = cifs_sb->ctx; in cifs_setup_cifs_sb()
3381 INIT_DELAYED_WORK(&cifs_sb->prune_tlinks, cifs_prune_tlinks); in cifs_setup_cifs_sb()
3383 spin_lock_init(&cifs_sb->tlink_tree_lock); in cifs_setup_cifs_sb()
3384 cifs_sb->tlink_tree = RB_ROOT; in cifs_setup_cifs_sb()
3387 ctx->file_mode, ctx->dir_mode); in cifs_setup_cifs_sb()
3390 if (ctx->iocharset == NULL) { in cifs_setup_cifs_sb()
3392 cifs_sb->local_nls = load_nls_default(); in cifs_setup_cifs_sb()
3394 cifs_sb->local_nls = load_nls(ctx->iocharset); in cifs_setup_cifs_sb()
3395 if (cifs_sb->local_nls == NULL) { in cifs_setup_cifs_sb()
3397 ctx->iocharset); in cifs_setup_cifs_sb()
3398 return -ELIBACC; in cifs_setup_cifs_sb()
3401 ctx->local_nls = cifs_sb->local_nls; in cifs_setup_cifs_sb()
3405 if (ctx->direct_io) in cifs_setup_cifs_sb()
3407 if (ctx->cache_ro) { in cifs_setup_cifs_sb()
3409 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RO_CACHE; in cifs_setup_cifs_sb()
3410 } else if (ctx->cache_rw) { in cifs_setup_cifs_sb()
3412 cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_RO_CACHE | in cifs_setup_cifs_sb()
3416 if ((ctx->cifs_acl) && (ctx->dynperm)) in cifs_setup_cifs_sb()
3419 if (ctx->prepath) { in cifs_setup_cifs_sb()
3420 cifs_sb->prepath = kstrdup(ctx->prepath, GFP_KERNEL); in cifs_setup_cifs_sb()
3421 if (cifs_sb->prepath == NULL) in cifs_setup_cifs_sb()
3422 return -ENOMEM; in cifs_setup_cifs_sb()
3423 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH; in cifs_setup_cifs_sb()
3434 if (mnt_ctx->tcon) in cifs_mount_put_conns()
3435 cifs_put_tcon(mnt_ctx->tcon, netfs_trace_tcon_ref_put_mnt_ctx); in cifs_mount_put_conns()
3436 else if (mnt_ctx->ses) in cifs_mount_put_conns()
3437 cifs_put_smb_ses(mnt_ctx->ses); in cifs_mount_put_conns()
3438 else if (mnt_ctx->server) in cifs_mount_put_conns()
3439 cifs_put_tcp_session(mnt_ctx->server, 0); in cifs_mount_put_conns()
3440 mnt_ctx->ses = NULL; in cifs_mount_put_conns()
3441 mnt_ctx->tcon = NULL; in cifs_mount_put_conns()
3442 mnt_ctx->server = NULL; in cifs_mount_put_conns()
3443 mnt_ctx->cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_POSIX_PATHS; in cifs_mount_put_conns()
3444 free_xid(mnt_ctx->xid); in cifs_mount_put_conns()
3457 if (WARN_ON_ONCE(!mnt_ctx || !mnt_ctx->fs_ctx)) { in cifs_mount_get_session()
3458 rc = -EINVAL; in cifs_mount_get_session()
3461 ctx = mnt_ctx->fs_ctx; in cifs_mount_get_session()
3479 if ((ctx->persistent == true) && (!(ses->server->capabilities & in cifs_mount_get_session()
3482 rc = -EOPNOTSUPP; in cifs_mount_get_session()
3486 mnt_ctx->xid = xid; in cifs_mount_get_session()
3487 mnt_ctx->server = server; in cifs_mount_get_session()
3488 mnt_ctx->ses = ses; in cifs_mount_get_session()
3489 mnt_ctx->tcon = NULL; in cifs_mount_get_session()
3499 struct cifs_tcon *tcon = NULL; in cifs_mount_get_tcon() local
3502 if (WARN_ON_ONCE(!mnt_ctx || !mnt_ctx->server || !mnt_ctx->ses || !mnt_ctx->fs_ctx || in cifs_mount_get_tcon()
3503 !mnt_ctx->cifs_sb)) { in cifs_mount_get_tcon()
3504 rc = -EINVAL; in cifs_mount_get_tcon()
3507 server = mnt_ctx->server; in cifs_mount_get_tcon()
3508 ctx = mnt_ctx->fs_ctx; in cifs_mount_get_tcon()
3509 cifs_sb = mnt_ctx->cifs_sb; in cifs_mount_get_tcon()
3511 /* search for existing tcon to this server share */ in cifs_mount_get_tcon()
3512 tcon = cifs_get_tcon(mnt_ctx->ses, ctx); in cifs_mount_get_tcon()
3513 if (IS_ERR(tcon)) { in cifs_mount_get_tcon()
3514 rc = PTR_ERR(tcon); in cifs_mount_get_tcon()
3515 tcon = NULL; in cifs_mount_get_tcon()
3520 if (tcon->posix_extensions) in cifs_mount_get_tcon()
3521 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_POSIX_PATHS; in cifs_mount_get_tcon()
3525 if (cap_unix(tcon->ses)) { in cifs_mount_get_tcon()
3530 reset_cifs_unix_caps(mnt_ctx->xid, tcon, cifs_sb, ctx); in cifs_mount_get_tcon()
3531 spin_lock(&tcon->ses->server->srv_lock); in cifs_mount_get_tcon()
3532 if ((tcon->ses->server->tcpStatus == CifsNeedReconnect) && in cifs_mount_get_tcon()
3533 (le64_to_cpu(tcon->fsUnixInfo.Capability) & in cifs_mount_get_tcon()
3535 spin_unlock(&tcon->ses->server->srv_lock); in cifs_mount_get_tcon()
3536 rc = -EACCES; in cifs_mount_get_tcon()
3539 spin_unlock(&tcon->ses->server->srv_lock); in cifs_mount_get_tcon()
3542 tcon->unix_ext = 0; /* server does not support them */ in cifs_mount_get_tcon()
3544 /* do not care if a following call succeed - informational */ in cifs_mount_get_tcon()
3545 if (!tcon->pipe && server->ops->qfs_tcon) { in cifs_mount_get_tcon()
3546 server->ops->qfs_tcon(mnt_ctx->xid, tcon, cifs_sb); in cifs_mount_get_tcon()
3547 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RO_CACHE) { in cifs_mount_get_tcon()
3548 if (tcon->fsDevInfo.DeviceCharacteristics & in cifs_mount_get_tcon()
3551 else if ((cifs_sb->mnt_cifs_flags & in cifs_mount_get_tcon()
3563 if ((cifs_sb->ctx->wsize == 0) || in cifs_mount_get_tcon()
3564 (cifs_sb->ctx->wsize > server->ops->negotiate_wsize(tcon, ctx))) { in cifs_mount_get_tcon()
3565 cifs_sb->ctx->wsize = in cifs_mount_get_tcon()
3566 round_down(server->ops->negotiate_wsize(tcon, ctx), PAGE_SIZE); in cifs_mount_get_tcon()
3571 if (cifs_sb->ctx->wsize == 0) { in cifs_mount_get_tcon()
3572 cifs_sb->ctx->wsize = PAGE_SIZE; in cifs_mount_get_tcon()
3576 if ((cifs_sb->ctx->rsize == 0) || in cifs_mount_get_tcon()
3577 (cifs_sb->ctx->rsize > server->ops->negotiate_rsize(tcon, ctx))) in cifs_mount_get_tcon()
3578 cifs_sb->ctx->rsize = server->ops->negotiate_rsize(tcon, ctx); in cifs_mount_get_tcon()
3585 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE) in cifs_mount_get_tcon()
3586 cifs_fscache_get_super_cookie(tcon); in cifs_mount_get_tcon()
3589 mnt_ctx->tcon = tcon; in cifs_mount_get_tcon()
3594 struct cifs_tcon *tcon) in mount_setup_tlink() argument
3598 /* hang the tcon off of the superblock */ in mount_setup_tlink()
3601 return -ENOMEM; in mount_setup_tlink()
3603 tlink->tl_uid = ses->linux_uid; in mount_setup_tlink()
3604 tlink->tl_tcon = tcon; in mount_setup_tlink()
3605 tlink->tl_time = jiffies; in mount_setup_tlink()
3606 set_bit(TCON_LINK_MASTER, &tlink->tl_flags); in mount_setup_tlink()
3607 set_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); in mount_setup_tlink()
3609 cifs_sb->master_tlink = tlink; in mount_setup_tlink()
3610 spin_lock(&cifs_sb->tlink_tree_lock); in mount_setup_tlink()
3611 tlink_rb_insert(&cifs_sb->tlink_tree, tlink); in mount_setup_tlink()
3612 spin_unlock(&cifs_sb->tlink_tree_lock); in mount_setup_tlink()
3614 queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks, in mount_setup_tlink()
3622 struct cifs_tcon *tcon, in cifs_are_all_path_components_accessible() argument
3635 rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, ""); in cifs_are_all_path_components_accessible()
3654 * temporarily null-terminate the path at the end of in cifs_are_all_path_components_accessible()
3659 rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, in cifs_are_all_path_components_accessible()
3669 * Return -EREMOTE if it is, otherwise 0 or -errno.
3674 struct cifs_sb_info *cifs_sb = mnt_ctx->cifs_sb; in cifs_is_path_remote()
3675 struct TCP_Server_Info *server = mnt_ctx->server; in cifs_is_path_remote()
3676 unsigned int xid = mnt_ctx->xid; in cifs_is_path_remote()
3677 struct cifs_tcon *tcon = mnt_ctx->tcon; in cifs_is_path_remote() local
3678 struct smb3_fs_context *ctx = mnt_ctx->fs_ctx; in cifs_is_path_remote()
3681 if (!server->ops->is_path_accessible) in cifs_is_path_remote()
3682 return -EOPNOTSUPP; in cifs_is_path_remote()
3685 * cifs_build_path_to_root works only when we have a valid tcon in cifs_is_path_remote()
3687 full_path = cifs_build_path_to_root(ctx, cifs_sb, tcon, in cifs_is_path_remote()
3688 tcon->Flags & SMB_SHARE_IS_IN_DFS); in cifs_is_path_remote()
3690 return -ENOMEM; in cifs_is_path_remote()
3694 rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, in cifs_is_path_remote()
3696 if (rc != 0 && rc != -EREMOTE) in cifs_is_path_remote()
3699 if (rc != -EREMOTE) { in cifs_is_path_remote()
3700 rc = cifs_are_all_path_components_accessible(server, xid, tcon, in cifs_is_path_remote()
3701 cifs_sb, full_path, tcon->Flags & SMB_SHARE_IS_IN_DFS); in cifs_is_path_remote()
3704 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH; in cifs_is_path_remote()
3723 if (!ctx->dfs_conn) in cifs_mount()
3735 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_USE_PREFIX_PATH; in cifs_mount()
3736 kfree(cifs_sb->prepath); in cifs_mount()
3737 cifs_sb->prepath = ctx->prepath; in cifs_mount()
3738 ctx->prepath = NULL; in cifs_mount()
3742 rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon); in cifs_mount()
3770 rc = -EHOSTDOWN; in cifs_mount()
3772 rc = -EACCES; in cifs_mount()
3773 else if (WARN_ON(!mnt_ctx.tcon)) in cifs_mount()
3774 rc = -ENOENT; in cifs_mount()
3780 if (rc == -EREMOTE) in cifs_mount()
3781 rc = -EOPNOTSUPP; in cifs_mount()
3785 rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon); in cifs_mount()
3804 const char *tree, struct cifs_tcon *tcon, in CIFSTCon() argument
3817 return -EIO; in CIFSTCon()
3821 return -ENOMEM; in CIFSTCon()
3828 smb_buffer->Mid = get_next_mid(ses->server); in CIFSTCon()
3829 smb_buffer->Uid = ses->Suid; in CIFSTCon()
3833 pSMB->AndXCommand = 0xFF; in CIFSTCon()
3834 pSMB->Flags = cpu_to_le16(TCON_EXTENDED_SECINFO); in CIFSTCon()
3835 bcc_ptr = &pSMB->Password[0]; in CIFSTCon()
3837 pSMB->PasswordLength = cpu_to_le16(1); /* minimum */ in CIFSTCon()
3842 if (ses->server->sign) in CIFSTCon()
3843 smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; in CIFSTCon()
3845 if (ses->capabilities & CAP_STATUS32) in CIFSTCon()
3846 smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS; in CIFSTCon()
3848 if (ses->capabilities & CAP_DFS) in CIFSTCon()
3849 smb_buffer->Flags2 |= SMBFLG2_DFS; in CIFSTCon()
3851 if (ses->capabilities & CAP_UNICODE) { in CIFSTCon()
3852 smb_buffer->Flags2 |= SMBFLG2_UNICODE; in CIFSTCon()
3866 count = bcc_ptr - &pSMB->Password[0]; in CIFSTCon()
3867 be32_add_cpu(&pSMB->hdr.smb_buf_length, count); in CIFSTCon()
3868 pSMB->ByteCount = cpu_to_le16(count); in CIFSTCon()
3877 tcon->tid = smb_buffer_response->Tid; in CIFSTCon()
3880 length = strnlen(bcc_ptr, bytes_left - 2); in CIFSTCon()
3881 if (smb_buffer->Flags2 & SMBFLG2_UNICODE) in CIFSTCon()
3892 tcon->ipc = true; in CIFSTCon()
3893 tcon->pipe = true; in CIFSTCon()
3902 bytes_left -= (length + 1); in CIFSTCon()
3903 strscpy(tcon->tree_name, tree, sizeof(tcon->tree_name)); in CIFSTCon()
3905 /* mostly informational -- no need to fail on error here */ in CIFSTCon()
3906 kfree(tcon->nativeFileSystem); in CIFSTCon()
3907 tcon->nativeFileSystem = cifs_strndup_from_utf16(bcc_ptr, in CIFSTCon()
3911 cifs_dbg(FYI, "nativeFileSystem=%s\n", tcon->nativeFileSystem); in CIFSTCon()
3913 if ((smb_buffer_response->WordCount == 3) || in CIFSTCon()
3914 (smb_buffer_response->WordCount == 7)) in CIFSTCon()
3916 tcon->Flags = le16_to_cpu(pSMBr->OptionalSupport); in CIFSTCon()
3918 tcon->Flags = 0; in CIFSTCon()
3919 cifs_dbg(FYI, "Tcon flags: 0x%x\n", tcon->Flags); in CIFSTCon()
3926 * need_reconnect when tcon was successful but needed to be in CIFSTCon()
3929 if (tcon->need_reconnect && tcon->unix_ext) { in CIFSTCon()
3930 cifs_dbg(FYI, "resetting caps for %s\n", tcon->tree_name); in CIFSTCon()
3931 tcon->need_reconnect = false; in CIFSTCon()
3932 reset_cifs_unix_caps(xid, tcon, NULL, NULL); in CIFSTCon()
3944 unload_nls(cifs_sb->local_nls); in delayed_free()
3945 smb3_cleanup_fs_context(cifs_sb->ctx); in delayed_free()
3952 struct rb_root *root = &cifs_sb->tlink_tree; in cifs_umount()
3956 cancel_delayed_work_sync(&cifs_sb->prune_tlinks); in cifs_umount()
3958 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3962 clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); in cifs_umount()
3965 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3967 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3969 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_umount()
3971 kfree(cifs_sb->prepath); in cifs_umount()
3972 call_rcu(&cifs_sb->rcu, delayed_free); in cifs_umount()
3982 if (!server->ops->need_neg || !server->ops->negotiate) in cifs_negotiate_protocol()
3983 return -ENOSYS; in cifs_negotiate_protocol()
3987 spin_lock(&server->srv_lock); in cifs_negotiate_protocol()
3988 if (server->tcpStatus != CifsGood && in cifs_negotiate_protocol()
3989 server->tcpStatus != CifsNew && in cifs_negotiate_protocol()
3990 server->tcpStatus != CifsNeedNegotiate) { in cifs_negotiate_protocol()
3991 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
3992 return -EHOSTDOWN; in cifs_negotiate_protocol()
3995 if (!server->ops->need_neg(server) && in cifs_negotiate_protocol()
3996 server->tcpStatus == CifsGood) { in cifs_negotiate_protocol()
3997 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
4001 server->lstrp = jiffies; in cifs_negotiate_protocol()
4002 server->tcpStatus = CifsInNegotiate; in cifs_negotiate_protocol()
4003 server->neg_start = jiffies; in cifs_negotiate_protocol()
4004 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
4006 rc = server->ops->negotiate(xid, ses, server); in cifs_negotiate_protocol()
4007 if (rc == -EAGAIN) { in cifs_negotiate_protocol()
4013 rc = -EHOSTDOWN; in cifs_negotiate_protocol()
4016 spin_lock(&server->srv_lock); in cifs_negotiate_protocol()
4017 if (server->tcpStatus == CifsInNegotiate) in cifs_negotiate_protocol()
4018 server->tcpStatus = CifsGood; in cifs_negotiate_protocol()
4020 rc = -EHOSTDOWN; in cifs_negotiate_protocol()
4021 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
4023 spin_lock(&server->srv_lock); in cifs_negotiate_protocol()
4024 if (server->tcpStatus == CifsInNegotiate) in cifs_negotiate_protocol()
4025 server->tcpStatus = CifsNeedNegotiate; in cifs_negotiate_protocol()
4026 spin_unlock(&server->srv_lock); in cifs_negotiate_protocol()
4037 int rc = -ENOSYS; in cifs_setup_session()
4038 struct TCP_Server_Info *pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in cifs_setup_session()
4039 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&pserver->dstaddr; in cifs_setup_session()
4040 struct sockaddr_in *addr = (struct sockaddr_in *)&pserver->dstaddr; in cifs_setup_session()
4043 spin_lock(&ses->ses_lock); in cifs_setup_session()
4044 cifs_dbg(FYI, "%s: channel connect bitmap: 0x%lx\n", in cifs_setup_session()
4045 __func__, ses->chans_need_reconnect); in cifs_setup_session()
4047 if (ses->ses_status != SES_GOOD && in cifs_setup_session()
4048 ses->ses_status != SES_NEW && in cifs_setup_session()
4049 ses->ses_status != SES_NEED_RECON) { in cifs_setup_session()
4050 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4051 return -EHOSTDOWN; in cifs_setup_session()
4055 spin_lock(&ses->chan_lock); in cifs_setup_session()
4057 if (ses->ses_status == SES_NEED_RECON) in cifs_setup_session()
4058 ses->ses_status = SES_GOOD; in cifs_setup_session()
4059 spin_unlock(&ses->chan_lock); in cifs_setup_session()
4060 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4066 spin_unlock(&ses->chan_lock); in cifs_setup_session()
4069 ses->ses_status = SES_IN_SETUP; in cifs_setup_session()
4072 ses->iface_last_update = 0; in cifs_setup_session()
4074 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4078 if (server->dstaddr.ss_family == AF_INET6) in cifs_setup_session()
4079 scnprintf(ses->ip_addr, sizeof(ses->ip_addr), "%pI6", &addr6->sin6_addr); in cifs_setup_session()
4081 scnprintf(ses->ip_addr, sizeof(ses->ip_addr), "%pI4", &addr->sin_addr); in cifs_setup_session()
4085 ses->capabilities = server->capabilities; in cifs_setup_session()
4087 ses->capabilities &= (~server->vals->cap_unix); in cifs_setup_session()
4089 if (ses->auth_key.response) { in cifs_setup_session()
4091 ses->auth_key.response); in cifs_setup_session()
4092 kfree_sensitive(ses->auth_key.response); in cifs_setup_session()
4093 ses->auth_key.response = NULL; in cifs_setup_session()
4094 ses->auth_key.len = 0; in cifs_setup_session()
4099 server->sec_mode, server->capabilities, server->timeAdj); in cifs_setup_session()
4101 if (server->ops->sess_setup) in cifs_setup_session()
4102 rc = server->ops->sess_setup(xid, ses, server, nls_info); in cifs_setup_session()
4106 spin_lock(&ses->ses_lock); in cifs_setup_session()
4107 if (ses->ses_status == SES_IN_SETUP) in cifs_setup_session()
4108 ses->ses_status = SES_NEED_RECON; in cifs_setup_session()
4109 spin_lock(&ses->chan_lock); in cifs_setup_session()
4111 spin_unlock(&ses->chan_lock); in cifs_setup_session()
4112 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4114 spin_lock(&ses->ses_lock); in cifs_setup_session()
4115 if (ses->ses_status == SES_IN_SETUP) in cifs_setup_session()
4116 ses->ses_status = SES_GOOD; in cifs_setup_session()
4117 spin_lock(&ses->chan_lock); in cifs_setup_session()
4120 spin_unlock(&ses->chan_lock); in cifs_setup_session()
4121 spin_unlock(&ses->ses_lock); in cifs_setup_session()
4130 ctx->sectype = ses->sectype; in cifs_set_vol_auth()
4133 if (ctx->sectype == Kerberos) in cifs_set_vol_auth()
4145 struct cifs_tcon *tcon = NULL; in cifs_construct_tcon() local
4151 return ERR_PTR(-ENOMEM); in cifs_construct_tcon()
4153 ctx->local_nls = cifs_sb->local_nls; in cifs_construct_tcon()
4154 ctx->linux_uid = fsuid; in cifs_construct_tcon()
4155 ctx->cred_uid = fsuid; in cifs_construct_tcon()
4156 ctx->UNC = master_tcon->tree_name; in cifs_construct_tcon()
4157 ctx->retry = master_tcon->retry; in cifs_construct_tcon()
4158 ctx->nocase = master_tcon->nocase; in cifs_construct_tcon()
4159 ctx->nohandlecache = master_tcon->nohandlecache; in cifs_construct_tcon()
4160 ctx->local_lease = master_tcon->local_lease; in cifs_construct_tcon()
4161 ctx->no_lease = master_tcon->no_lease; in cifs_construct_tcon()
4162 ctx->resilient = master_tcon->use_resilient; in cifs_construct_tcon()
4163 ctx->persistent = master_tcon->use_persistent; in cifs_construct_tcon()
4164 ctx->handle_timeout = master_tcon->handle_timeout; in cifs_construct_tcon()
4165 ctx->no_linux_ext = !master_tcon->unix_ext; in cifs_construct_tcon()
4166 ctx->linux_ext = master_tcon->posix_extensions; in cifs_construct_tcon()
4167 ctx->sectype = master_tcon->ses->sectype; in cifs_construct_tcon()
4168 ctx->sign = master_tcon->ses->sign; in cifs_construct_tcon()
4169 ctx->seal = master_tcon->seal; in cifs_construct_tcon()
4170 ctx->witness = master_tcon->use_witness; in cifs_construct_tcon()
4171 ctx->dfs_root_ses = master_tcon->ses->dfs_root_ses; in cifs_construct_tcon()
4173 rc = cifs_set_vol_auth(ctx, master_tcon->ses); in cifs_construct_tcon()
4175 tcon = ERR_PTR(rc); in cifs_construct_tcon()
4181 ++master_tcon->ses->server->srv_count; in cifs_construct_tcon()
4184 ses = cifs_get_smb_ses(master_tcon->ses->server, ctx); in cifs_construct_tcon()
4186 tcon = (struct cifs_tcon *)ses; in cifs_construct_tcon()
4187 cifs_put_tcp_session(master_tcon->ses->server, 0); in cifs_construct_tcon()
4192 spin_lock(&master_tcon->tc_lock); in cifs_construct_tcon()
4193 if (master_tcon->origin_fullpath) { in cifs_construct_tcon()
4194 spin_unlock(&master_tcon->tc_lock); in cifs_construct_tcon()
4195 origin_fullpath = dfs_get_path(cifs_sb, cifs_sb->ctx->source); in cifs_construct_tcon()
4197 tcon = ERR_CAST(origin_fullpath); in cifs_construct_tcon()
4203 spin_unlock(&master_tcon->tc_lock); in cifs_construct_tcon()
4207 tcon = cifs_get_tcon(ses, ctx); in cifs_construct_tcon()
4208 if (IS_ERR(tcon)) { in cifs_construct_tcon()
4215 spin_lock(&tcon->tc_lock); in cifs_construct_tcon()
4216 tcon->origin_fullpath = origin_fullpath; in cifs_construct_tcon()
4217 spin_unlock(&tcon->tc_lock); in cifs_construct_tcon()
4219 queue_delayed_work(dfscache_wq, &tcon->dfs_cache_work, in cifs_construct_tcon()
4226 reset_cifs_unix_caps(0, tcon, NULL, ctx); in cifs_construct_tcon()
4230 kfree(ctx->username); in cifs_construct_tcon()
4231 kfree_sensitive(ctx->password); in cifs_construct_tcon()
4235 return tcon; in cifs_construct_tcon()
4248 struct rb_node *node = root->rb_node; in tlink_rb_search()
4254 if (uid_gt(tlink->tl_uid, uid)) in tlink_rb_search()
4255 node = node->rb_left; in tlink_rb_search()
4256 else if (uid_lt(tlink->tl_uid, uid)) in tlink_rb_search()
4257 node = node->rb_right; in tlink_rb_search()
4268 struct rb_node **new = &(root->rb_node), *parent = NULL; in tlink_rb_insert()
4275 if (uid_gt(tlink->tl_uid, new_tlink->tl_uid)) in tlink_rb_insert()
4276 new = &((*new)->rb_left); in tlink_rb_insert()
4278 new = &((*new)->rb_right); in tlink_rb_insert()
4281 rb_link_node(&new_tlink->tl_rbnode, parent, new); in tlink_rb_insert()
4282 rb_insert_color(&new_tlink->tl_rbnode, root); in tlink_rb_insert()
4286 * Find or construct an appropriate tcon given a cifs_sb and the fsuid of the
4290 * the master tcon for the mount.
4292 * First, search the rbtree for an existing tcon for this fsuid. If one
4308 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)) in cifs_sb_tlink()
4311 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 return ERR_PTR(-ENOMEM); in cifs_sb_tlink()
4321 newtlink->tl_uid = fsuid; in cifs_sb_tlink()
4322 newtlink->tl_tcon = ERR_PTR(-EACCES); in cifs_sb_tlink()
4323 set_bit(TCON_LINK_PENDING, &newtlink->tl_flags); in cifs_sb_tlink()
4324 set_bit(TCON_LINK_IN_TREE, &newtlink->tl_flags); in cifs_sb_tlink()
4327 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4329 tlink = tlink_rb_search(&cifs_sb->tlink_tree, fsuid); in cifs_sb_tlink()
4332 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4337 tlink_rb_insert(&cifs_sb->tlink_tree, tlink); in cifs_sb_tlink()
4338 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_sb_tlink()
4341 ret = wait_on_bit(&tlink->tl_flags, TCON_LINK_PENDING, in cifs_sb_tlink()
4345 return ERR_PTR(-ERESTARTSYS); in cifs_sb_tlink()
4349 if (!IS_ERR(tlink->tl_tcon)) in cifs_sb_tlink()
4353 if (time_before(jiffies, tlink->tl_time + TLINK_ERROR_EXPIRE)) { in cifs_sb_tlink()
4355 return ERR_PTR(-EACCES); in cifs_sb_tlink()
4358 if (test_and_set_bit(TCON_LINK_PENDING, &tlink->tl_flags)) in cifs_sb_tlink()
4362 tlink->tl_tcon = cifs_construct_tcon(cifs_sb, fsuid); in cifs_sb_tlink()
4363 clear_bit(TCON_LINK_PENDING, &tlink->tl_flags); in cifs_sb_tlink()
4364 wake_up_bit(&tlink->tl_flags, TCON_LINK_PENDING); in cifs_sb_tlink()
4366 if (IS_ERR(tlink->tl_tcon)) { in cifs_sb_tlink()
4368 return ERR_PTR(-EACCES); in cifs_sb_tlink()
4383 struct rb_root *root = &cifs_sb->tlink_tree; in cifs_prune_tlinks()
4392 * umounts. Because this function is non-reentrant and is canceled in cifs_prune_tlinks()
4395 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4402 if (test_bit(TCON_LINK_MASTER, &tlink->tl_flags) || in cifs_prune_tlinks()
4403 atomic_read(&tlink->tl_count) != 0 || in cifs_prune_tlinks()
4404 time_after(tlink->tl_time + TLINK_IDLE_EXPIRE, jiffies)) in cifs_prune_tlinks()
4408 clear_bit(TCON_LINK_IN_TREE, &tlink->tl_flags); in cifs_prune_tlinks()
4411 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4413 spin_lock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4415 spin_unlock(&cifs_sb->tlink_tree_lock); in cifs_prune_tlinks()
4417 queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks, in cifs_prune_tlinks()
4422 int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const struct nls_table *nlsc) in cifs_tree_connect() argument
4425 const struct smb_version_operations *ops = tcon->ses->server->ops; in cifs_tree_connect()
4428 spin_lock(&tcon->tc_lock); in cifs_tree_connect()
4430 /* if tcon is marked for needing reconnect, update state */ in cifs_tree_connect()
4431 if (tcon->need_reconnect) in cifs_tree_connect()
4432 tcon->status = TID_NEED_TCON; in cifs_tree_connect()
4434 if (tcon->status == TID_GOOD) { in cifs_tree_connect()
4435 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4439 if (tcon->status != TID_NEW && in cifs_tree_connect()
4440 tcon->status != TID_NEED_TCON) { in cifs_tree_connect()
4441 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4442 return -EHOSTDOWN; in cifs_tree_connect()
4445 tcon->status = TID_IN_TCON; in cifs_tree_connect()
4446 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4448 rc = ops->tree_connect(xid, tcon->ses, tcon->tree_name, tcon, nlsc); in cifs_tree_connect()
4450 spin_lock(&tcon->tc_lock); in cifs_tree_connect()
4451 if (tcon->status == TID_IN_TCON) in cifs_tree_connect()
4452 tcon->status = TID_NEED_TCON; in cifs_tree_connect()
4453 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()
4455 spin_lock(&tcon->tc_lock); in cifs_tree_connect()
4456 if (tcon->status == TID_IN_TCON) in cifs_tree_connect()
4457 tcon->status = TID_GOOD; in cifs_tree_connect()
4458 tcon->need_reconnect = false; in cifs_tree_connect()
4459 spin_unlock(&tcon->tc_lock); in cifs_tree_connect()