Lines Matching +full:tcon +full:- +full:top
1 // SPDX-License-Identifier: GPL-2.0
32 server->credits += server->echo_credits + server->oplock_credits; in change_conf()
33 server->oplock_credits = server->echo_credits = 0; in change_conf()
34 switch (server->credits) { in change_conf()
38 server->echoes = false; in change_conf()
39 server->oplocks = false; in change_conf()
42 server->echoes = true; in change_conf()
43 server->oplocks = false; in change_conf()
44 server->echo_credits = 1; in change_conf()
47 server->echoes = true; in change_conf()
49 server->oplocks = true; in change_conf()
50 server->oplock_credits = 1; in change_conf()
52 server->oplocks = false; in change_conf()
54 server->echo_credits = 1; in change_conf()
56 server->credits -= server->echo_credits + server->oplock_credits; in change_conf()
57 return server->credits + server->echo_credits + server->oplock_credits; in change_conf()
64 int *val, rc = -1; in smb2_add_credits()
65 unsigned int add = credits->value; in smb2_add_credits()
66 unsigned int instance = credits->instance; in smb2_add_credits()
69 spin_lock(&server->req_lock); in smb2_add_credits()
70 val = server->ops->get_credits_field(server, optype); in smb2_add_credits()
74 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid, in smb2_add_credits()
75 server->hostname, *val, add); in smb2_add_credits()
76 if ((instance == 0) || (instance == server->reconnect_instance)) in smb2_add_credits()
85 server->in_flight--; in smb2_add_credits()
86 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) in smb2_add_credits()
89 * Sometimes server returns 0 credits on oplock break ack - we need to in smb2_add_credits()
92 else if (server->in_flight > 0 && server->oplock_credits == 0 && in smb2_add_credits()
93 server->oplocks) { in smb2_add_credits()
94 if (server->credits > 1) { in smb2_add_credits()
95 server->credits--; in smb2_add_credits()
96 server->oplock_credits++; in smb2_add_credits()
99 spin_unlock(&server->req_lock); in smb2_add_credits()
100 wake_up(&server->request_q); in smb2_add_credits()
106 if (server->tcpStatus == CifsNeedReconnect in smb2_add_credits()
107 || server->tcpStatus == CifsExiting) in smb2_add_credits()
111 case -1: in smb2_add_credits()
115 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n"); in smb2_add_credits()
124 trace_smb3_add_credits(server->CurrentMid, in smb2_add_credits()
125 server->hostname, rc, add); in smb2_add_credits()
133 spin_lock(&server->req_lock); in smb2_set_credits()
134 server->credits = val; in smb2_set_credits()
136 server->reconnect_instance++; in smb2_set_credits()
137 spin_unlock(&server->req_lock); in smb2_set_credits()
148 return &server->echo_credits; in smb2_get_credits_field()
150 return &server->oplock_credits; in smb2_get_credits_field()
152 return &server->credits; in smb2_get_credits_field()
159 return mid->credits_received; in smb2_get_credits()
169 spin_lock(&server->req_lock); in smb2_wait_mtu_credits()
171 if (server->credits <= 0) { in smb2_wait_mtu_credits()
172 spin_unlock(&server->req_lock); in smb2_wait_mtu_credits()
174 rc = wait_event_killable(server->request_q, in smb2_wait_mtu_credits()
175 has_credits(server, &server->credits, 1)); in smb2_wait_mtu_credits()
179 spin_lock(&server->req_lock); in smb2_wait_mtu_credits()
181 if (server->tcpStatus == CifsExiting) { in smb2_wait_mtu_credits()
182 spin_unlock(&server->req_lock); in smb2_wait_mtu_credits()
183 return -ENOENT; in smb2_wait_mtu_credits()
186 scredits = server->credits; in smb2_wait_mtu_credits()
190 credits->value = 0; in smb2_wait_mtu_credits()
191 credits->instance = 0; in smb2_wait_mtu_credits()
196 scredits -= 8; in smb2_wait_mtu_credits()
200 credits->value = in smb2_wait_mtu_credits()
202 credits->instance = server->reconnect_instance; in smb2_wait_mtu_credits()
203 server->credits -= credits->value; in smb2_wait_mtu_credits()
204 server->in_flight++; in smb2_wait_mtu_credits()
205 if (server->in_flight > server->max_in_flight) in smb2_wait_mtu_credits()
206 server->max_in_flight = server->in_flight; in smb2_wait_mtu_credits()
210 spin_unlock(&server->req_lock); in smb2_wait_mtu_credits()
221 if (!credits->value || credits->value == new_val) in smb2_adjust_credits()
224 if (credits->value < new_val) { in smb2_adjust_credits()
226 credits->value, new_val); in smb2_adjust_credits()
227 return -ENOTSUPP; in smb2_adjust_credits()
230 spin_lock(&server->req_lock); in smb2_adjust_credits()
232 if (server->reconnect_instance != credits->instance) { in smb2_adjust_credits()
233 spin_unlock(&server->req_lock); in smb2_adjust_credits()
235 credits->value - new_val); in smb2_adjust_credits()
236 return -EAGAIN; in smb2_adjust_credits()
239 server->credits += credits->value - new_val; in smb2_adjust_credits()
240 spin_unlock(&server->req_lock); in smb2_adjust_credits()
241 wake_up(&server->request_q); in smb2_adjust_credits()
242 credits->value = new_val; in smb2_adjust_credits()
252 mid = server->CurrentMid++; in smb2_get_next_mid()
261 if (server->CurrentMid >= val) in smb2_revert_current_mid()
262 server->CurrentMid -= val; in smb2_revert_current_mid()
271 __u64 wire_mid = le64_to_cpu(shdr->MessageId); in __smb2_find_mid()
273 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) { in __smb2_find_mid()
279 list_for_each_entry(mid, &server->pending_mid_q, qhead) { in __smb2_find_mid()
280 if ((mid->mid == wire_mid) && in __smb2_find_mid()
281 (mid->mid_state == MID_REQUEST_SUBMITTED) && in __smb2_find_mid()
282 (mid->command == shdr->Command)) { in __smb2_find_mid()
283 kref_get(&mid->refcount); in __smb2_find_mid()
285 list_del_init(&mid->qhead); in __smb2_find_mid()
286 mid->mid_flags |= MID_DELETED; in __smb2_find_mid()
315 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId, in smb2_dump_detail()
316 shdr->ProcessId); in smb2_dump_detail()
318 server->ops->calc_smb_size(buf, server)); in smb2_dump_detail()
325 return server->max_read == 0; in smb2_need_neg()
333 cifs_ses_server(ses)->CurrentMid = 0; in smb2_negotiate()
336 if (rc == -EAGAIN) in smb2_negotiate()
337 rc = -EHOSTDOWN; in smb2_negotiate()
342 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) in smb2_negotiate_wsize() argument
344 struct TCP_Server_Info *server = tcon->ses->server; in smb2_negotiate_wsize()
348 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; in smb2_negotiate_wsize()
349 wsize = min_t(unsigned int, wsize, server->max_write); in smb2_negotiate_wsize()
350 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) in smb2_negotiate_wsize()
357 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) in smb3_negotiate_wsize() argument
359 struct TCP_Server_Info *server = tcon->ses->server; in smb3_negotiate_wsize()
363 wsize = volume_info->wsize ? volume_info->wsize : SMB3_DEFAULT_IOSIZE; in smb3_negotiate_wsize()
364 wsize = min_t(unsigned int, wsize, server->max_write); in smb3_negotiate_wsize()
366 if (server->rdma) { in smb3_negotiate_wsize()
367 if (server->sign) in smb3_negotiate_wsize()
374 server->smbd_conn->max_fragmented_send_size - in smb3_negotiate_wsize()
375 SMB2_READWRITE_PDU_HEADER_SIZE - in smb3_negotiate_wsize()
379 wsize, server->smbd_conn->max_readwrite_size); in smb3_negotiate_wsize()
382 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) in smb3_negotiate_wsize()
389 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) in smb2_negotiate_rsize() argument
391 struct TCP_Server_Info *server = tcon->ses->server; in smb2_negotiate_rsize()
395 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; in smb2_negotiate_rsize()
396 rsize = min_t(unsigned int, rsize, server->max_read); in smb2_negotiate_rsize()
398 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) in smb2_negotiate_rsize()
405 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) in smb3_negotiate_rsize() argument
407 struct TCP_Server_Info *server = tcon->ses->server; in smb3_negotiate_rsize()
411 rsize = volume_info->rsize ? volume_info->rsize : SMB3_DEFAULT_IOSIZE; in smb3_negotiate_rsize()
412 rsize = min_t(unsigned int, rsize, server->max_read); in smb3_negotiate_rsize()
414 if (server->rdma) { in smb3_negotiate_rsize()
415 if (server->sign) in smb3_negotiate_rsize()
422 server->smbd_conn->max_fragmented_recv_size - in smb3_negotiate_rsize()
423 SMB2_READWRITE_PDU_HEADER_SIZE - in smb3_negotiate_rsize()
427 rsize, server->smbd_conn->max_readwrite_size); in smb3_negotiate_rsize()
431 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) in smb3_negotiate_rsize()
465 next = le32_to_cpu(p->Next); in parse_server_interfaces()
467 bytes_left -= sizeof(*p); in parse_server_interfaces()
471 bytes_left -= next; in parse_server_interfaces()
476 rc = -EINVAL; in parse_server_interfaces()
480 if (bytes_left || p->Next) in parse_server_interfaces()
490 rc = -ENOMEM; in parse_server_interfaces()
498 info->speed = le64_to_cpu(p->LinkSpeed); in parse_server_interfaces()
499 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE); in parse_server_interfaces()
500 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE); in parse_server_interfaces()
503 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed); in parse_server_interfaces()
505 le32_to_cpu(p->Capability)); in parse_server_interfaces()
507 switch (p->Family) { in parse_server_interfaces()
514 addr4 = (struct sockaddr_in *)&info->sockaddr; in parse_server_interfaces()
515 p4 = (struct iface_info_ipv4 *)p->Buffer; in parse_server_interfaces()
516 addr4->sin_family = AF_INET; in parse_server_interfaces()
517 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4); in parse_server_interfaces()
519 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */ in parse_server_interfaces()
520 addr4->sin_port = cpu_to_be16(CIFS_PORT); in parse_server_interfaces()
523 &addr4->sin_addr); in parse_server_interfaces()
526 addr6 = (struct sockaddr_in6 *)&info->sockaddr; in parse_server_interfaces()
527 p6 = (struct iface_info_ipv6 *)p->Buffer; in parse_server_interfaces()
528 addr6->sin6_family = AF_INET6; in parse_server_interfaces()
529 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16); in parse_server_interfaces()
531 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */ in parse_server_interfaces()
532 addr6->sin6_flowinfo = 0; in parse_server_interfaces()
533 addr6->sin6_scope_id = 0; in parse_server_interfaces()
534 addr6->sin6_port = cpu_to_be16(CIFS_PORT); in parse_server_interfaces()
537 &addr6->sin6_addr); in parse_server_interfaces()
549 next = le32_to_cpu(p->Next); in parse_server_interfaces()
553 bytes_left -= next; in parse_server_interfaces()
557 rc = -EINVAL; in parse_server_interfaces()
575 return a->speed == b->speed ? 0 : (a->speed > b->speed ? -1 : 1); in compare_iface()
579 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon) in SMB3_request_interfaces() argument
586 struct cifs_ses *ses = tcon->ses; in SMB3_request_interfaces()
588 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, in SMB3_request_interfaces()
592 if (rc == -EOPNOTSUPP) { in SMB3_request_interfaces()
609 spin_lock(&ses->iface_lock); in SMB3_request_interfaces()
610 kfree(ses->iface_list); in SMB3_request_interfaces()
611 ses->iface_list = iface_list; in SMB3_request_interfaces()
612 ses->iface_count = iface_count; in SMB3_request_interfaces()
613 ses->iface_last_update = jiffies; in SMB3_request_interfaces()
614 spin_unlock(&ses->iface_lock); in SMB3_request_interfaces()
627 if (cfid->is_valid) { in smb2_close_cached_fid()
629 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid, in smb2_close_cached_fid()
630 cfid->fid->volatile_fid); in smb2_close_cached_fid()
631 cfid->is_valid = false; in smb2_close_cached_fid()
632 cfid->file_all_info_is_valid = false; in smb2_close_cached_fid()
633 cfid->has_lease = false; in smb2_close_cached_fid()
639 mutex_lock(&cfid->fid_mutex); in close_shroot()
640 kref_put(&cfid->refcount, smb2_close_cached_fid); in close_shroot()
641 mutex_unlock(&cfid->fid_mutex); in close_shroot()
646 if (cfid->has_lease) { in close_shroot_lease_locked()
647 cfid->has_lease = false; in close_shroot_lease_locked()
648 kref_put(&cfid->refcount, smb2_close_cached_fid); in close_shroot_lease_locked()
654 mutex_lock(&cfid->fid_mutex); in close_shroot_lease()
656 mutex_unlock(&cfid->fid_mutex); in close_shroot_lease()
671 int open_shroot(unsigned int xid, struct cifs_tcon *tcon, in open_shroot() argument
675 struct cifs_ses *ses = tcon->ses; in open_shroot()
676 struct TCP_Server_Info *server = ses->server; in open_shroot()
686 __le16 utf16_path = 0; /* Null - since an open of top of share */ in open_shroot()
690 mutex_lock(&tcon->crfid.fid_mutex); in open_shroot()
691 if (tcon->crfid.is_valid) { in open_shroot()
693 *cfid = &tcon->crfid; in open_shroot()
694 kref_get(&tcon->crfid.refcount); in open_shroot()
695 mutex_unlock(&tcon->crfid.fid_mutex); in open_shroot()
706 mutex_unlock(&tcon->crfid.fid_mutex); in open_shroot()
708 if (smb3_encryption_required(tcon)) in open_shroot()
711 if (!server->ops->new_lease_key) in open_shroot()
712 return -EIO; in open_shroot()
714 pfid = tcon->crfid.fid; in open_shroot()
715 server->ops->new_lease_key(pfid); in open_shroot()
726 oparms.tcon = tcon; in open_shroot()
733 rc = SMB2_open_init(tcon, server, in open_shroot()
737 smb2_set_next_command(tcon, &rqst[0]); in open_shroot()
743 rc = SMB2_query_info_init(tcon, server, in open_shroot()
757 mutex_lock(&tcon->crfid.fid_mutex); in open_shroot()
761 * been successfully re-opened from a concurrent process in open_shroot()
764 if (tcon->crfid.is_valid) { in open_shroot()
769 .persistent_fid = pfid->persistent_fid, in open_shroot()
770 .volatile_fid = pfid->volatile_fid, in open_shroot()
778 memcpy(pfid, tcon->crfid.fid, sizeof(*pfid)); in open_shroot()
779 kref_get(&tcon->crfid.refcount); in open_shroot()
781 mutex_unlock(&tcon->crfid.fid_mutex); in open_shroot()
785 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in open_shroot()
794 if (rc == -EREMCHG) { in open_shroot()
795 tcon->need_reconnect = true; in open_shroot()
797 tcon->treeName); in open_shroot()
802 atomic_inc(&tcon->num_remote_opens); in open_shroot()
805 oparms.fid->persistent_fid = o_rsp->PersistentFileId; in open_shroot()
806 oparms.fid->volatile_fid = o_rsp->VolatileFileId; in open_shroot()
808 oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId); in open_shroot()
811 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid)); in open_shroot()
812 tcon->crfid.tcon = tcon; in open_shroot()
813 tcon->crfid.is_valid = true; in open_shroot()
814 kref_init(&tcon->crfid.refcount); in open_shroot()
817 if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) { in open_shroot()
818 kref_get(&tcon->crfid.refcount); in open_shroot()
819 tcon->crfid.has_lease = true; in open_shroot()
821 &oparms.fid->epoch, in open_shroot()
822 oparms.fid->lease_key, &oplock, in open_shroot()
828 if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info)) in open_shroot()
831 le16_to_cpu(qi_rsp->OutputBufferOffset), in open_shroot()
834 (char *)&tcon->crfid.file_all_info)) in open_shroot()
835 tcon->crfid.file_all_info_is_valid = true; in open_shroot()
838 mutex_unlock(&tcon->crfid.fid_mutex); in open_shroot()
845 *cfid = &tcon->crfid; in open_shroot()
850 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, in smb3_qfs_tcon() argument
854 __le16 srch_path = 0; /* Null - open root of share */ in smb3_qfs_tcon()
858 bool no_cached_open = tcon->nohandlecache; in smb3_qfs_tcon()
861 oparms.tcon = tcon; in smb3_qfs_tcon()
872 rc = open_shroot(xid, tcon, cifs_sb, &cfid); in smb3_qfs_tcon()
874 memcpy(&fid, cfid->fid, sizeof(struct cifs_fid)); in smb3_qfs_tcon()
879 SMB3_request_interfaces(xid, tcon); in smb3_qfs_tcon()
881 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_qfs_tcon()
883 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_qfs_tcon()
885 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_qfs_tcon()
887 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_qfs_tcon()
890 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb3_qfs_tcon()
896 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, in smb2_qfs_tcon() argument
900 __le16 srch_path = 0; /* Null - open root of share */ in smb2_qfs_tcon()
905 oparms.tcon = tcon; in smb2_qfs_tcon()
917 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb2_qfs_tcon()
919 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb2_qfs_tcon()
921 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb2_qfs_tcon()
925 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, in smb2_is_path_accessible() argument
934 if ((*full_path == 0) && tcon->crfid.is_valid) in smb2_is_path_accessible()
939 return -ENOMEM; in smb2_is_path_accessible()
941 oparms.tcon = tcon; in smb2_is_path_accessible()
955 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb2_is_path_accessible()
961 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, in smb2_get_srv_inum() argument
965 *uniqueid = le64_to_cpu(data->IndexNumber); in smb2_get_srv_inum()
970 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_file_info() argument
979 return -ENOMEM; in smb2_query_file_info()
981 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, in smb2_query_file_info()
1002 name = &src->ea_data[0]; in move_smb2_ea_to_cifs()
1003 name_len = (size_t)src->ea_name_length; in move_smb2_ea_to_cifs()
1004 value = &src->ea_data[src->ea_name_length + 1]; in move_smb2_ea_to_cifs()
1005 value_len = (size_t)le16_to_cpu(src->ea_value_length); in move_smb2_ea_to_cifs()
1012 rc = -EIO; in move_smb2_ea_to_cifs()
1023 rc = -ERANGE; in move_smb2_ea_to_cifs()
1034 /* skip copy - calc size only */ in move_smb2_ea_to_cifs()
1037 dst_size -= user_name_len; in move_smb2_ea_to_cifs()
1040 memcpy(dst, src->ea_data, name_len); in move_smb2_ea_to_cifs()
1047 rc = -ERANGE; in move_smb2_ea_to_cifs()
1052 if (!src->next_entry_offset) in move_smb2_ea_to_cifs()
1055 if (src_size < le32_to_cpu(src->next_entry_offset)) { in move_smb2_ea_to_cifs()
1057 rc = -ERANGE; in move_smb2_ea_to_cifs()
1060 src_size -= le32_to_cpu(src->next_entry_offset); in move_smb2_ea_to_cifs()
1062 le32_to_cpu(src->next_entry_offset)); in move_smb2_ea_to_cifs()
1067 rc = -ENODATA; in move_smb2_ea_to_cifs()
1074 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_eas() argument
1088 return -ENOMEM; in smb2_query_eas()
1090 rc = smb2_query_info_compound(xid, tcon, utf16_path, in smb2_query_eas()
1094 CIFSMaxBufSize - in smb2_query_eas()
1095 MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_query_eas()
1104 if (!ea_name && rc == -ENODATA) in smb2_query_eas()
1110 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in smb2_query_eas()
1111 le32_to_cpu(rsp->OutputBufferLength), in smb2_query_eas()
1118 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in smb2_query_eas()
1120 le32_to_cpu(rsp->OutputBufferLength), ea_name); in smb2_query_eas()
1130 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_ea() argument
1135 struct cifs_ses *ses = tcon->ses; in smb2_set_ea()
1156 if (smb3_encryption_required(tcon)) in smb2_set_ea()
1160 return -EINVAL; in smb2_set_ea()
1164 return -ENOMEM; in smb2_set_ea()
1170 if (ses->server->ops->query_all_EAs) { in smb2_set_ea()
1172 rc = ses->server->ops->query_all_EAs(xid, tcon, path, in smb2_set_ea()
1175 if (rc == -ENODATA) in smb2_set_ea()
1183 rc = smb2_query_info_compound(xid, tcon, utf16_path, in smb2_set_ea()
1187 CIFSMaxBufSize - in smb2_set_ea()
1188 MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_set_ea()
1193 used_len = le32_to_cpu(rsp->OutputBufferLength); in smb2_set_ea()
1203 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_set_ea()
1204 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 < in smb2_set_ea()
1206 rc = -ENOSPC; in smb2_set_ea()
1218 oparms.tcon = tcon; in smb2_set_ea()
1225 rc = SMB2_open_init(tcon, server, in smb2_set_ea()
1229 smb2_set_next_command(tcon, &rqst[0]); in smb2_set_ea()
1240 rc = -ENOMEM; in smb2_set_ea()
1244 ea->ea_name_length = ea_name_len; in smb2_set_ea()
1245 ea->ea_value_length = cpu_to_le16(ea_value_len); in smb2_set_ea()
1246 memcpy(ea->ea_data, ea_name, ea_name_len + 1); in smb2_set_ea()
1247 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len); in smb2_set_ea()
1252 rc = SMB2_set_info_init(tcon, server, in smb2_set_ea()
1254 COMPOUND_FID, current->tgid, in smb2_set_ea()
1257 smb2_set_next_command(tcon, &rqst[1]); in smb2_set_ea()
1265 rc = SMB2_close_init(tcon, server, in smb2_set_ea()
1290 return server->echoes; in smb2_can_echo()
1294 smb2_clear_stats(struct cifs_tcon *tcon) in smb2_clear_stats() argument
1299 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); in smb2_clear_stats()
1300 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); in smb2_clear_stats()
1305 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) in smb2_dump_share_caps() argument
1308 if (tcon->capabilities & SMB2_SHARE_CAP_DFS) in smb2_dump_share_caps()
1310 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) in smb2_dump_share_caps()
1312 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) in smb2_dump_share_caps()
1314 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) in smb2_dump_share_caps()
1316 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) in smb2_dump_share_caps()
1318 if (tcon->capabilities == 0) in smb2_dump_share_caps()
1320 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE) in smb2_dump_share_caps()
1322 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE) in smb2_dump_share_caps()
1324 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY) in smb2_dump_share_caps()
1326 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED) in smb2_dump_share_caps()
1327 seq_puts(m, " TRIM-support,"); in smb2_dump_share_caps()
1329 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); in smb2_dump_share_caps()
1330 seq_printf(m, "\n\ttid: 0x%x", tcon->tid); in smb2_dump_share_caps()
1331 if (tcon->perf_sector_size) in smb2_dump_share_caps()
1333 tcon->perf_sector_size); in smb2_dump_share_caps()
1334 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access); in smb2_dump_share_caps()
1338 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) in smb2_print_stats() argument
1340 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; in smb2_print_stats()
1341 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; in smb2_print_stats()
1345 * totals (requests sent) since those SMBs are per-session not per tcon in smb2_print_stats()
1348 (long long)(tcon->bytes_read), in smb2_print_stats()
1349 (long long)(tcon->bytes_written)); in smb2_print_stats()
1351 atomic_read(&tcon->num_local_opens), in smb2_print_stats()
1352 atomic_read(&tcon->num_remote_opens)); in smb2_print_stats()
1400 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); in smb2_set_fid()
1401 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; in smb2_set_fid()
1403 cfile->fid.persistent_fid = fid->persistent_fid; in smb2_set_fid()
1404 cfile->fid.volatile_fid = fid->volatile_fid; in smb2_set_fid()
1405 cfile->fid.access = fid->access; in smb2_set_fid()
1407 cfile->fid.mid = fid->mid; in smb2_set_fid()
1409 server->ops->set_oplock_level(cinode, oplock, fid->epoch, in smb2_set_fid()
1410 &fid->purge_cache); in smb2_set_fid()
1411 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); in smb2_set_fid()
1412 memcpy(cfile->fid.create_guid, fid->create_guid, 16); in smb2_set_fid()
1416 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, in smb2_close_file() argument
1419 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_close_file()
1423 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon, in smb2_close_getattr() argument
1430 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid, in smb2_close_getattr()
1431 cfile->fid.volatile_fid, &file_inf); in smb2_close_getattr()
1435 inode = d_inode(cfile->dentry); in smb2_close_getattr()
1437 spin_lock(&inode->i_lock); in smb2_close_getattr()
1438 CIFS_I(inode)->time = jiffies; in smb2_close_getattr()
1442 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime); in smb2_close_getattr()
1444 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime); in smb2_close_getattr()
1446 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime); in smb2_close_getattr()
1454 inode->i_blocks = in smb2_close_getattr()
1455 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9; in smb2_close_getattr()
1458 spin_unlock(&inode->i_lock); in smb2_close_getattr()
1462 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_request_res_key() argument
1470 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, in SMB2_request_res_key()
1481 rc = -EINVAL; in SMB2_request_res_key()
1484 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE); in SMB2_request_res_key()
1503 struct cifs_tcon *tcon, in smb2_ioctl_query_info() argument
1511 struct cifs_ses *ses = tcon->ses; in smb2_ioctl_query_info()
1531 return -ENOMEM; in smb2_ioctl_query_info()
1532 rqst = &vars->rqst[0]; in smb2_ioctl_query_info()
1533 rsp_iov = &vars->rsp_iov[0]; in smb2_ioctl_query_info()
1542 return -EINVAL; in smb2_ioctl_query_info()
1547 return -EIO; in smb2_ioctl_query_info()
1550 if (smb3_encryption_required(tcon)) in smb2_ioctl_query_info()
1561 rqst[0].rq_iov = &vars->open_iov[0]; in smb2_ioctl_query_info()
1565 oparms.tcon = tcon; in smb2_ioctl_query_info()
1592 rc = SMB2_open_init(tcon, server, in smb2_ioctl_query_info()
1596 smb2_set_next_command(tcon, &rqst[0]); in smb2_ioctl_query_info()
1602 rc = -EPERM; in smb2_ioctl_query_info()
1604 rqst[1].rq_iov = &vars->io_iov[0]; in smb2_ioctl_query_info()
1607 rc = SMB2_ioctl_init(tcon, server, in smb2_ioctl_query_info()
1612 CIFSMaxBufSize - in smb2_ioctl_query_info()
1613 MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_ioctl_query_info()
1619 rc = -EPERM; in smb2_ioctl_query_info()
1621 rqst[1].rq_iov = &vars->si_iov[0]; in smb2_ioctl_query_info()
1627 rc = SMB2_set_info_init(tcon, server, in smb2_ioctl_query_info()
1630 current->tgid, in smb2_ioctl_query_info()
1635 rqst[1].rq_iov = &vars->qi_iov[0]; in smb2_ioctl_query_info()
1638 rc = SMB2_query_info_init(tcon, server, in smb2_ioctl_query_info()
1647 rc = -EINVAL; in smb2_ioctl_query_info()
1652 smb2_set_next_command(tcon, &rqst[1]); in smb2_ioctl_query_info()
1656 rqst[2].rq_iov = &vars->close_iov[0]; in smb2_ioctl_query_info()
1659 rc = SMB2_close_init(tcon, server, in smb2_ioctl_query_info()
1675 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length) in smb2_ioctl_query_info()
1676 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount); in smb2_ioctl_query_info()
1678 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length in smb2_ioctl_query_info()
1682 if (copy_to_user(&pqi->input_buffer_length, in smb2_ioctl_query_info()
1688 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset), in smb2_ioctl_query_info()
1694 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length) in smb2_ioctl_query_info()
1695 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength); in smb2_ioctl_query_info()
1696 if (copy_to_user(&pqi->input_buffer_length, in smb2_ioctl_query_info()
1701 if (copy_to_user(pqi + 1, qi_rsp->Buffer, in smb2_ioctl_query_info()
1722 rc = -EFAULT; in smb2_ioctl_query_info()
1736 struct cifs_tcon *tcon; in smb2_copychunk_range() local
1744 return -ENOMEM; in smb2_copychunk_range()
1748 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), in smb2_copychunk_range()
1749 srcfile->fid.persistent_fid, in smb2_copychunk_range()
1750 srcfile->fid.volatile_fid, pcchunk); in smb2_copychunk_range()
1757 pcchunk->ChunkCount = cpu_to_le32(1); in smb2_copychunk_range()
1758 pcchunk->Reserved = 0; in smb2_copychunk_range()
1759 pcchunk->Reserved2 = 0; in smb2_copychunk_range()
1761 tcon = tlink_tcon(trgtfile->tlink); in smb2_copychunk_range()
1764 pcchunk->SourceOffset = cpu_to_le64(src_off); in smb2_copychunk_range()
1765 pcchunk->TargetOffset = cpu_to_le64(dest_off); in smb2_copychunk_range()
1766 pcchunk->Length = in smb2_copychunk_range()
1767 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk)); in smb2_copychunk_range()
1770 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, in smb2_copychunk_range()
1771 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, in smb2_copychunk_range()
1779 rc = -EIO; in smb2_copychunk_range()
1782 if (retbuf->TotalBytesWritten == 0) { in smb2_copychunk_range()
1784 rc = -EIO; in smb2_copychunk_range()
1790 if (le32_to_cpu(retbuf->TotalBytesWritten) > in smb2_copychunk_range()
1791 le32_to_cpu(pcchunk->Length)) { in smb2_copychunk_range()
1793 rc = -EIO; in smb2_copychunk_range()
1796 if (le32_to_cpu(retbuf->ChunksWritten) != 1) { in smb2_copychunk_range()
1798 rc = -EIO; in smb2_copychunk_range()
1803 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten); in smb2_copychunk_range()
1806 len -= bytes_written; in smb2_copychunk_range()
1810 le32_to_cpu(retbuf->ChunksWritten), in smb2_copychunk_range()
1811 le32_to_cpu(retbuf->ChunkBytesWritten), in smb2_copychunk_range()
1813 } else if (rc == -EINVAL) { in smb2_copychunk_range()
1818 le32_to_cpu(retbuf->ChunksWritten), in smb2_copychunk_range()
1819 le32_to_cpu(retbuf->ChunkBytesWritten), in smb2_copychunk_range()
1820 le32_to_cpu(retbuf->TotalBytesWritten)); in smb2_copychunk_range()
1833 if (le32_to_cpu(retbuf->ChunkBytesWritten) < in smb2_copychunk_range()
1834 tcon->max_bytes_chunk) in smb2_copychunk_range()
1835 tcon->max_bytes_chunk = in smb2_copychunk_range()
1836 le32_to_cpu(retbuf->ChunkBytesWritten); in smb2_copychunk_range()
1856 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, in smb2_flush_file() argument
1859 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_flush_file()
1867 return rsp->DataOffset; in smb2_read_data_offset()
1876 return le32_to_cpu(rsp->DataRemaining); in smb2_read_data_length()
1878 return le32_to_cpu(rsp->DataLength); in smb2_read_data_length()
1887 parms->persistent_fid = pfid->persistent_fid; in smb2_sync_read()
1888 parms->volatile_fid = pfid->volatile_fid; in smb2_sync_read()
1898 parms->persistent_fid = pfid->persistent_fid; in smb2_sync_write()
1899 parms->volatile_fid = pfid->volatile_fid; in smb2_sync_write()
1904 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_sparse() argument
1913 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse) in smb2_set_sparse()
1916 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse) in smb2_set_sparse()
1929 if (tcon->broken_sparse_sup) in smb2_set_sparse()
1932 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb2_set_sparse()
1933 cfile->fid.volatile_fid, FSCTL_SET_SPARSE, in smb2_set_sparse()
1937 tcon->broken_sparse_sup = true; in smb2_set_sparse()
1943 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE; in smb2_set_sparse()
1945 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE); in smb2_set_sparse()
1951 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_file_size() argument
1961 inode = d_inode(cfile->dentry); in smb2_set_file_size()
1963 if (!set_alloc && (size > inode->i_size + 8192)) { in smb2_set_file_size()
1967 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse); in smb2_set_file_size()
1970 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb2_set_file_size()
1971 cfile->fid.volatile_fid, cfile->pid, &eof); in smb2_set_file_size()
1983 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink); in smb2_duplicate_extents() local
1986 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) & in smb2_duplicate_extents()
1988 return -EOPNOTSUPP; in smb2_duplicate_extents()
1990 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid; in smb2_duplicate_extents()
1991 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid; in smb2_duplicate_extents()
1998 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); in smb2_duplicate_extents()
2002 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, in smb2_duplicate_extents()
2003 trgtfile->fid.volatile_fid, in smb2_duplicate_extents()
2012 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n"); in smb2_duplicate_extents()
2019 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_compression() argument
2022 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, in smb2_set_compression()
2023 cfile->fid.volatile_fid); in smb2_set_compression()
2027 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon, in smb3_set_integrity() argument
2037 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_set_integrity()
2038 cfile->fid.volatile_fid, in smb3_set_integrity()
2048 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2051 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2055 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2058 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon, in smb3_enum_snapshots() argument
2076 return -EFAULT; in smb3_enum_snapshots()
2090 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_enum_snapshots()
2091 cfile->fid.volatile_fid, in smb3_enum_snapshots()
2106 rc = -EFAULT; in smb3_enum_snapshots()
2133 rc = -EFAULT; in smb3_enum_snapshots()
2147 struct dentry *dentry = pfile->f_path.dentry; in smb3_notify()
2152 struct cifs_tcon *tcon; in smb3_notify() local
2160 return -ENOMEM; in smb3_notify()
2162 cifs_sb = CIFS_SB(inode->i_sb); in smb3_notify()
2166 rc = -ENOMEM; in smb3_notify()
2171 rc = -EFAULT; in smb3_notify()
2175 tcon = cifs_sb_master_tcon(cifs_sb); in smb3_notify()
2176 oparms.tcon = tcon; in smb3_notify()
2188 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_notify()
2191 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb3_notify()
2202 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_dir_first() argument
2218 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); in smb2_query_dir_first()
2222 return -ENOMEM; in smb2_query_dir_first()
2224 if (smb3_encryption_required(tcon)) in smb2_query_dir_first()
2236 oparms.tcon = tcon; in smb2_query_dir_first()
2243 rc = SMB2_open_init(tcon, server, in smb2_query_dir_first()
2247 smb2_set_next_command(tcon, &rqst[0]); in smb2_query_dir_first()
2250 srch_inf->entries_in_buffer = 0; in smb2_query_dir_first()
2251 srch_inf->index_of_last_entry = 2; in smb2_query_dir_first()
2257 rc = SMB2_query_directory_init(xid, tcon, server, in smb2_query_dir_first()
2260 0, srch_inf->info_level); in smb2_query_dir_first()
2266 rc = compound_send_recv(xid, tcon->ses, server, in smb2_query_dir_first()
2272 if (op_rsp == NULL || op_rsp->sync_hdr.Status != STATUS_SUCCESS) { in smb2_query_dir_first()
2276 fid->persistent_fid = op_rsp->PersistentFileId; in smb2_query_dir_first()
2277 fid->volatile_fid = op_rsp->VolatileFileId; in smb2_query_dir_first()
2280 if (rc && rc != -ENODATA) { in smb2_query_dir_first()
2281 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_query_dir_first()
2283 trace_smb3_query_dir_err(xid, fid->persistent_fid, in smb2_query_dir_first()
2284 tcon->tid, tcon->ses->Suid, 0, 0, rc); in smb2_query_dir_first()
2288 atomic_inc(&tcon->num_remote_opens); in smb2_query_dir_first()
2291 if (qd_rsp->sync_hdr.Status == STATUS_NO_MORE_FILES) { in smb2_query_dir_first()
2292 trace_smb3_query_dir_done(xid, fid->persistent_fid, in smb2_query_dir_first()
2293 tcon->tid, tcon->ses->Suid, 0, 0); in smb2_query_dir_first()
2294 srch_inf->endOfSearch = true; in smb2_query_dir_first()
2299 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1], in smb2_query_dir_first()
2302 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid, in smb2_query_dir_first()
2303 tcon->ses->Suid, 0, 0, rc); in smb2_query_dir_first()
2308 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid, in smb2_query_dir_first()
2309 tcon->ses->Suid, 0, srch_inf->entries_in_buffer); in smb2_query_dir_first()
2321 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_dir_next() argument
2325 return SMB2_query_directory(xid, tcon, fid->persistent_fid, in smb2_query_dir_next()
2326 fid->volatile_fid, 0, srch_inf); in smb2_query_dir_next()
2330 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, in smb2_close_dir() argument
2333 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_close_dir()
2337 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2338 * the number of credits and return true. Otherwise - return false.
2345 if (shdr->Status != STATUS_PENDING) in smb2_is_status_pending()
2348 if (shdr->CreditRequest) { in smb2_is_status_pending()
2349 spin_lock(&server->req_lock); in smb2_is_status_pending()
2350 server->credits += le16_to_cpu(shdr->CreditRequest); in smb2_is_status_pending()
2351 spin_unlock(&server->req_lock); in smb2_is_status_pending()
2352 wake_up(&server->request_q); in smb2_is_status_pending()
2363 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED && in smb2_is_session_expired()
2364 shdr->Status != STATUS_USER_SESSION_DELETED) in smb2_is_session_expired()
2367 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId, in smb2_is_session_expired()
2368 le16_to_cpu(shdr->Command), in smb2_is_session_expired()
2369 le64_to_cpu(shdr->MessageId)); in smb2_is_session_expired()
2380 if (shdr->Status == STATUS_IO_TIMEOUT) in smb2_is_status_io_timeout()
2387 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, in smb2_oplock_response() argument
2390 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) in smb2_oplock_response()
2391 return SMB2_lease_break(0, tcon, cinode->lease_key, in smb2_oplock_response()
2394 return SMB2_oplock_break(0, tcon, fid->persistent_fid, in smb2_oplock_response()
2395 fid->volatile_fid, in smb2_oplock_response()
2404 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base); in smb2_set_related()
2409 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS; in smb2_set_related()
2415 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst) in smb2_set_next_command() argument
2418 struct cifs_ses *ses = tcon->ses; in smb2_set_next_command()
2419 struct TCP_Server_Info *server = ses->server; in smb2_set_next_command()
2423 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base); in smb2_set_next_command()
2435 num_padding = 8 - (len & 7); in smb2_set_next_command()
2436 if (!smb3_encryption_required(tcon)) { in smb2_set_next_command()
2441 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding; in smb2_set_next_command()
2442 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding; in smb2_set_next_command()
2443 rqst->rq_nvec++; in smb2_set_next_command()
2453 for (i = 1; i < rqst->rq_nvec; i++) { in smb2_set_next_command()
2454 memcpy(rqst->rq_iov[0].iov_base + in smb2_set_next_command()
2455 rqst->rq_iov[0].iov_len, in smb2_set_next_command()
2456 rqst->rq_iov[i].iov_base, in smb2_set_next_command()
2457 rqst->rq_iov[i].iov_len); in smb2_set_next_command()
2458 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len; in smb2_set_next_command()
2460 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len, in smb2_set_next_command()
2462 rqst->rq_iov[0].iov_len += num_padding; in smb2_set_next_command()
2464 rqst->rq_nvec = 1; in smb2_set_next_command()
2468 shdr->NextCommand = cpu_to_le32(len); in smb2_set_next_command()
2476 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_info_compound() argument
2482 struct cifs_ses *ses = tcon->ses; in smb2_query_info_compound()
2496 if (smb3_encryption_required(tcon)) in smb2_query_info_compound()
2507 oparms.tcon = tcon; in smb2_query_info_compound()
2514 rc = SMB2_open_init(tcon, server, in smb2_query_info_compound()
2518 smb2_set_next_command(tcon, &rqst[0]); in smb2_query_info_compound()
2524 rc = SMB2_query_info_init(tcon, server, in smb2_query_info_compound()
2531 smb2_set_next_command(tcon, &rqst[1]); in smb2_query_info_compound()
2538 rc = SMB2_close_init(tcon, server, in smb2_query_info_compound()
2549 if (rc == -EREMCHG) { in smb2_query_info_compound()
2550 tcon->need_reconnect = true; in smb2_query_info_compound()
2552 tcon->treeName); in smb2_query_info_compound()
2569 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, in smb2_queryfs() argument
2574 __le16 utf16_path = 0; /* Null - open root of share */ in smb2_queryfs()
2580 rc = smb2_query_info_compound(xid, tcon, &utf16_path, in smb2_queryfs()
2590 buf->f_type = SMB2_MAGIC_NUMBER; in smb2_queryfs()
2592 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in smb2_queryfs()
2593 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in smb2_queryfs()
2594 le32_to_cpu(rsp->OutputBufferLength), in smb2_queryfs()
2606 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon, in smb311_queryfs() argument
2610 __le16 srch_path = 0; /* Null - open root of share */ in smb311_queryfs()
2615 if (!tcon->posix_extensions) in smb311_queryfs()
2616 return smb2_queryfs(xid, tcon, cifs_sb, buf); in smb311_queryfs()
2618 oparms.tcon = tcon; in smb311_queryfs()
2630 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid, in smb311_queryfs()
2632 buf->f_type = SMB2_MAGIC_NUMBER; in smb311_queryfs()
2633 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb311_queryfs()
2640 return ob1->fid.persistent_fid == ob2->fid.persistent_fid && in smb2_compare_fids()
2641 ob1->fid.volatile_fid == ob2->fid.volatile_fid; in smb2_compare_fids()
2650 return SMB2_lock(xid, tlink_tcon(cfile->tlink), in smb2_mand_lock()
2651 cfile->fid.persistent_fid, cfile->fid.volatile_fid, in smb2_mand_lock()
2652 current->tgid, length, offset, type, wait); in smb2_mand_lock()
2658 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); in smb2_get_lease_key()
2664 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); in smb2_set_lease_key()
2670 generate_random_uuid(fid->lease_key); in smb2_new_lease_key()
2683 struct cifs_tcon *tcon; in smb2_get_dfs_refer() local
2691 * Try to use the IPC tcon, otherwise just use any in smb2_get_dfs_refer()
2693 tcon = ses->tcon_ipc; in smb2_get_dfs_refer()
2694 if (tcon == NULL) { in smb2_get_dfs_refer()
2696 tcon = list_first_entry_or_null(&ses->tcon_list, in smb2_get_dfs_refer()
2699 if (tcon) in smb2_get_dfs_refer()
2700 tcon->tc_count++; in smb2_get_dfs_refer()
2704 if (tcon == NULL) { in smb2_get_dfs_refer()
2705 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n", in smb2_get_dfs_refer()
2707 rc = -ENOTCONN; in smb2_get_dfs_refer()
2715 rc = -ENOMEM; in smb2_get_dfs_refer()
2722 rc = -ENOMEM; in smb2_get_dfs_refer()
2727 dfs_req->MaxReferralLevel = DFS_VERSION; in smb2_get_dfs_refer()
2729 /* Path to resolve in an UTF-16 null-terminated string */ in smb2_get_dfs_refer()
2730 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len); in smb2_get_dfs_refer()
2733 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, in smb2_get_dfs_refer()
2738 } while (rc == -EAGAIN); in smb2_get_dfs_refer()
2741 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP)) in smb2_get_dfs_refer()
2756 if (tcon && !tcon->ipc) { in smb2_get_dfs_refer()
2759 tcon->tc_count--; in smb2_get_dfs_refer()
2775 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */ in parse_reparse_posix()
2776 len = le16_to_cpu(symlink_buf->ReparseDataLength); in parse_reparse_posix()
2778 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) { in parse_reparse_posix()
2780 le64_to_cpu(symlink_buf->InodeType)); in parse_reparse_posix()
2781 return -EOPNOTSUPP; in parse_reparse_posix()
2785 symlink_buf->PathBuffer, in parse_reparse_posix()
2786 len, true, cifs_sb->local_nls); in parse_reparse_posix()
2788 return -ENOMEM; in parse_reparse_posix()
2804 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */ in parse_reparse_symlink()
2806 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset); in parse_reparse_symlink()
2807 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength); in parse_reparse_symlink()
2811 return -EIO; in parse_reparse_symlink()
2815 symlink_buf->PathBuffer + sub_offset, in parse_reparse_symlink()
2816 sub_len, true, cifs_sb->local_nls); in parse_reparse_symlink()
2818 return -ENOMEM; in parse_reparse_symlink()
2834 return -EIO; in parse_reparse_point()
2837 if (plen < le16_to_cpu(buf->ReparseDataLength) + in parse_reparse_point()
2841 return -EIO; in parse_reparse_point()
2844 /* See MS-FSCC 2.1.2 */ in parse_reparse_point()
2845 switch (le32_to_cpu(buf->ReparseTag)) { in parse_reparse_point()
2856 le32_to_cpu(buf->ReparseTag)); in parse_reparse_point()
2857 return -EOPNOTSUPP; in parse_reparse_point()
2862 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2865 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_symlink() argument
2877 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); in smb2_query_symlink()
2899 if (smb3_encryption_required(tcon)) in smb2_query_symlink()
2908 return -ENOMEM; in smb2_query_symlink()
2916 oparms.tcon = tcon; in smb2_query_symlink()
2923 rc = SMB2_open_init(tcon, server, in smb2_query_symlink()
2927 smb2_set_next_command(tcon, &rqst[0]); in smb2_query_symlink()
2935 rc = SMB2_ioctl_init(tcon, server, in smb2_query_symlink()
2939 CIFSMaxBufSize - in smb2_query_symlink()
2940 MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_query_symlink()
2945 smb2_set_next_command(tcon, &rqst[1]); in smb2_query_symlink()
2954 rc = SMB2_close_init(tcon, server, in smb2_query_symlink()
2961 rc = compound_send_recv(xid, tcon->ses, server, in smb2_query_symlink()
2966 if (create_rsp && create_rsp->sync_hdr.Status) in smb2_query_symlink()
2974 /* See MS-FSCC 2.3.23 */ in smb2_query_symlink()
2978 le32_to_cpu(ioctl_rsp->OutputOffset)); in smb2_query_symlink()
2979 plen = le32_to_cpu(ioctl_rsp->OutputCount); in smb2_query_symlink()
2981 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) > in smb2_query_symlink()
2985 rc = -EIO; in smb2_query_symlink()
2995 rc = -ENOENT; in smb2_query_symlink()
3000 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) || in smb2_query_symlink()
3002 rc = -EINVAL; in smb2_query_symlink()
3006 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; in smb2_query_symlink()
3007 if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG || in smb2_query_symlink()
3008 le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) { in smb2_query_symlink()
3009 rc = -EINVAL; in smb2_query_symlink()
3013 /* open must fail on symlink - reset rc */ in smb2_query_symlink()
3015 sub_len = le16_to_cpu(symlink->SubstituteNameLength); in smb2_query_symlink()
3016 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); in smb2_query_symlink()
3017 print_len = le16_to_cpu(symlink->PrintNameLength); in smb2_query_symlink()
3018 print_offset = le16_to_cpu(symlink->PrintNameOffset); in smb2_query_symlink()
3021 rc = -EINVAL; in smb2_query_symlink()
3027 rc = -EINVAL; in smb2_query_symlink()
3032 (char *)symlink->PathBuffer + sub_offset, in smb2_query_symlink()
3033 sub_len, true, cifs_sb->local_nls); in smb2_query_symlink()
3035 rc = -ENOMEM; in smb2_query_symlink()
3054 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_reparse_tag() argument
3063 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); in smb2_query_reparse_tag()
3077 if (smb3_encryption_required(tcon)) in smb2_query_reparse_tag()
3086 return -ENOMEM; in smb2_query_reparse_tag()
3089 * setup smb2open - TODO add optimization to call cifs_get_readable_path in smb2_query_reparse_tag()
3097 oparms.tcon = tcon; in smb2_query_reparse_tag()
3104 rc = SMB2_open_init(tcon, server, in smb2_query_reparse_tag()
3108 smb2_set_next_command(tcon, &rqst[0]); in smb2_query_reparse_tag()
3116 rc = SMB2_ioctl_init(tcon, server, in smb2_query_reparse_tag()
3120 CIFSMaxBufSize - in smb2_query_reparse_tag()
3121 MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_query_reparse_tag()
3126 smb2_set_next_command(tcon, &rqst[1]); in smb2_query_reparse_tag()
3135 rc = SMB2_close_init(tcon, server, in smb2_query_reparse_tag()
3142 rc = compound_send_recv(xid, tcon->ses, server, in smb2_query_reparse_tag()
3152 /* See MS-FSCC 2.3.23 */ in smb2_query_reparse_tag()
3156 le32_to_cpu(ioctl_rsp->OutputOffset)); in smb2_query_reparse_tag()
3157 plen = le32_to_cpu(ioctl_rsp->OutputCount); in smb2_query_reparse_tag()
3159 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) > in smb2_query_reparse_tag()
3163 rc = -EIO; in smb2_query_reparse_tag()
3166 *tag = le32_to_cpu(reparse_buf->ReparseTag); in smb2_query_reparse_tag()
3186 int rc = -EOPNOTSUPP; in get_smb2_acl_by_fid()
3195 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid, in get_smb2_acl_by_fid()
3196 cifsfid->volatile_fid, (void **)&pntsd, pacllen); in get_smb2_acl_by_fid()
3216 struct cifs_tcon *tcon; in get_smb2_acl_by_path() local
3226 tcon = tlink_tcon(tlink); in get_smb2_acl_by_path()
3231 rc = -ENOMEM; in get_smb2_acl_by_path()
3236 oparms.tcon = tcon; in get_smb2_acl_by_path()
3254 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in get_smb2_acl_by_path()
3273 struct cifs_tcon *tcon; in set_smb2_acl() local
3274 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in set_smb2_acl()
3284 tcon = tlink_tcon(tlink); in set_smb2_acl()
3294 rc = -ENOMEM; in set_smb2_acl()
3299 oparms.tcon = tcon; in set_smb2_acl()
3313 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in set_smb2_acl()
3335 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen); in get_smb2_acl()
3340 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, in smb3_zero_range() argument
3343 struct cifs_ses *ses = tcon->ses; in smb3_zero_range()
3346 struct cifsFileInfo *cfile = file->private_data; in smb3_zero_range()
3354 inode = d_inode(cfile->dentry); in smb3_zero_range()
3357 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_zero_range()
3358 ses->Suid, offset, len); in smb3_zero_range()
3364 truncate_pagecache_range(inode, offset, offset + len - 1); in smb3_zero_range()
3369 rc = -EOPNOTSUPP; in smb3_zero_range()
3370 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, in smb3_zero_range()
3371 tcon->tid, ses->Suid, offset, len, rc); in smb3_zero_range()
3381 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_zero_range()
3382 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, true, in smb3_zero_range()
3394 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb3_zero_range()
3395 cfile->fid.volatile_fid, cfile->pid, &eof); in smb3_zero_range()
3401 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_zero_range()
3402 ses->Suid, offset, len, rc); in smb3_zero_range()
3404 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_zero_range()
3405 ses->Suid, offset, len); in smb3_zero_range()
3409 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, in smb3_punch_hole() argument
3413 struct cifsFileInfo *cfile = file->private_data; in smb3_punch_hole()
3421 inode = d_inode(cfile->dentry); in smb3_punch_hole()
3425 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) { in smb3_punch_hole()
3426 rc = -EOPNOTSUPP; in smb3_punch_hole()
3435 truncate_pagecache_range(inode, offset, offset + len - 1); in smb3_punch_hole()
3442 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_punch_hole()
3443 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, in smb3_punch_hole()
3451 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, in smb3_simple_falloc() argument
3456 struct cifsFileInfo *cfile = file->private_data; in smb3_simple_falloc()
3457 long rc = -EOPNOTSUPP; in smb3_simple_falloc()
3463 inode = d_inode(cfile->dentry); in smb3_simple_falloc()
3466 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_simple_falloc()
3467 tcon->ses->Suid, off, len); in smb3_simple_falloc()
3471 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, in smb3_simple_falloc()
3472 tcon->tid, tcon->ses->Suid, off, len, rc); in smb3_simple_falloc()
3485 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) in smb3_simple_falloc()
3486 smb2_set_sparse(xid, tcon, cfile, inode, false); in smb3_simple_falloc()
3489 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb3_simple_falloc()
3490 cfile->fid.volatile_fid, cfile->pid, &eof); in smb3_simple_falloc()
3492 cifsi->server_eof = off + len; in smb3_simple_falloc()
3494 cifs_truncate_page(inode->i_mapping, inode->i_size); in smb3_simple_falloc()
3501 * Files are non-sparse by default so falloc may be a no-op in smb3_simple_falloc()
3505 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { in smb3_simple_falloc()
3517 * or end of the file non-sparse via set_sparse is harmless. in smb3_simple_falloc()
3520 rc = -EOPNOTSUPP; in smb3_simple_falloc()
3525 smb2_set_sparse(xid, tcon, cfile, inode, false); in smb3_simple_falloc()
3530 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_simple_falloc()
3531 tcon->ses->Suid, off, len, rc); in smb3_simple_falloc()
3533 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_simple_falloc()
3534 tcon->ses->Suid, off, len); in smb3_simple_falloc()
3540 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence) in smb3_llseek() argument
3542 struct cifsFileInfo *wrcfile, *cfile = file->private_data; in smb3_llseek()
3553 inode = d_inode(cfile->dentry); in smb3_llseek()
3557 return -ENXIO; in smb3_llseek()
3569 filemap_write_and_wait(inode->i_mapping); in smb3_llseek()
3570 smb2_flush_file(xid, tcon, &wrcfile->fid); in smb3_llseek()
3574 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) { in smb3_llseek()
3583 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_llseek()
3584 cfile->fid.volatile_fid, in smb3_llseek()
3589 if (rc == -E2BIG) in smb3_llseek()
3598 rc = -ENXIO; in smb3_llseek()
3603 rc = -EINVAL; in smb3_llseek()
3607 offset = le64_to_cpu(out_data->file_offset); in smb3_llseek()
3610 if (offset < le64_to_cpu(out_data->file_offset)) in smb3_llseek()
3613 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length); in smb3_llseek()
3619 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes); in smb3_llseek()
3624 static int smb3_fiemap(struct cifs_tcon *tcon, in smb3_fiemap() argument
3634 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0); in smb3_fiemap()
3643 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_fiemap()
3644 cfile->fid.volatile_fid, in smb3_fiemap()
3649 if (rc == -E2BIG) { in smb3_fiemap()
3658 rc = -EINVAL; in smb3_fiemap()
3662 rc = -EINVAL; in smb3_fiemap()
3669 if (i == num - 1 && last_blob) in smb3_fiemap()
3686 next = le64_to_cpu(out_data[num - 1].file_offset) + in smb3_fiemap()
3687 le64_to_cpu(out_data[num - 1].length); in smb3_fiemap()
3688 len = len - (next - start); in smb3_fiemap()
3699 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, in smb3_fallocate() argument
3704 return smb3_punch_hole(file, tcon, off, len); in smb3_fallocate()
3707 return smb3_zero_range(file, tcon, off, len, true); in smb3_fallocate()
3708 return smb3_zero_range(file, tcon, off, len, false); in smb3_fallocate()
3710 return smb3_simple_falloc(file, tcon, off, len, true); in smb3_fallocate()
3712 return smb3_simple_falloc(file, tcon, off, len, false); in smb3_fallocate()
3714 return -EOPNOTSUPP; in smb3_fallocate()
3722 server->ops->set_oplock_level(cinode, oplock, 0, NULL); in smb2_downgrade_oplock()
3734 unsigned int old_state = cinode->oplock; in smb3_downgrade_oplock()
3735 unsigned int old_epoch = cinode->epoch; in smb3_downgrade_oplock()
3740 cinode->epoch = epoch; in smb3_downgrade_oplock()
3743 new_state = cinode->oplock; in smb3_downgrade_oplock()
3749 else if (old_state == new_state && (epoch - old_epoch > 1)) in smb3_downgrade_oplock()
3761 cinode->oplock = CIFS_CACHE_RHW_FLG; in smb2_set_oplock_level()
3763 &cinode->vfs_inode); in smb2_set_oplock_level()
3765 cinode->oplock = CIFS_CACHE_RW_FLG; in smb2_set_oplock_level()
3767 &cinode->vfs_inode); in smb2_set_oplock_level()
3769 cinode->oplock = CIFS_CACHE_READ_FLG; in smb2_set_oplock_level()
3771 &cinode->vfs_inode); in smb2_set_oplock_level()
3773 cinode->oplock = 0; in smb2_set_oplock_level()
3807 cinode->oplock = new_oplock; in smb21_set_oplock_level()
3809 &cinode->vfs_inode); in smb21_set_oplock_level()
3816 unsigned int old_oplock = cinode->oplock; in smb3_set_oplock_level()
3823 if (cinode->oplock == CIFS_CACHE_READ_FLG && in smb3_set_oplock_level()
3824 (epoch - cinode->epoch > 0)) in smb3_set_oplock_level()
3826 else if (cinode->oplock == CIFS_CACHE_RH_FLG && in smb3_set_oplock_level()
3827 (epoch - cinode->epoch > 1)) in smb3_set_oplock_level()
3829 else if (cinode->oplock == CIFS_CACHE_RHW_FLG && in smb3_set_oplock_level()
3830 (epoch - cinode->epoch > 1)) in smb3_set_oplock_level()
3832 else if (cinode->oplock == 0 && in smb3_set_oplock_level()
3833 (epoch - cinode->epoch > 0)) in smb3_set_oplock_level()
3836 if (cinode->oplock == CIFS_CACHE_RH_FLG && in smb3_set_oplock_level()
3837 (epoch - cinode->epoch > 0)) in smb3_set_oplock_level()
3839 else if (cinode->oplock == CIFS_CACHE_RHW_FLG && in smb3_set_oplock_level()
3840 (epoch - cinode->epoch > 1)) in smb3_set_oplock_level()
3843 cinode->epoch = epoch; in smb3_set_oplock_level()
3882 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE); in smb2_create_lease_buf()
3883 buf->lcontext.LeaseState = map_oplock_to_lease(oplock); in smb2_create_lease_buf()
3885 buf->ccontext.DataOffset = cpu_to_le16(offsetof in smb2_create_lease_buf()
3887 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); in smb2_create_lease_buf()
3888 buf->ccontext.NameOffset = cpu_to_le16(offsetof in smb2_create_lease_buf()
3890 buf->ccontext.NameLength = cpu_to_le16(4); in smb2_create_lease_buf()
3892 buf->Name[0] = 'R'; in smb2_create_lease_buf()
3893 buf->Name[1] = 'q'; in smb2_create_lease_buf()
3894 buf->Name[2] = 'L'; in smb2_create_lease_buf()
3895 buf->Name[3] = 's'; in smb2_create_lease_buf()
3908 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE); in smb3_create_lease_buf()
3909 buf->lcontext.LeaseState = map_oplock_to_lease(oplock); in smb3_create_lease_buf()
3911 buf->ccontext.DataOffset = cpu_to_le16(offsetof in smb3_create_lease_buf()
3913 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); in smb3_create_lease_buf()
3914 buf->ccontext.NameOffset = cpu_to_le16(offsetof in smb3_create_lease_buf()
3916 buf->ccontext.NameLength = cpu_to_le16(4); in smb3_create_lease_buf()
3918 buf->Name[0] = 'R'; in smb3_create_lease_buf()
3919 buf->Name[1] = 'q'; in smb3_create_lease_buf()
3920 buf->Name[2] = 'L'; in smb3_create_lease_buf()
3921 buf->Name[3] = 's'; in smb3_create_lease_buf()
3931 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) in smb2_parse_lease_buf()
3933 return le32_to_cpu(lc->lcontext.LeaseState); in smb2_parse_lease_buf()
3941 *epoch = le16_to_cpu(lc->lcontext.Epoch); in smb3_parse_lease_buf()
3942 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) in smb3_parse_lease_buf()
3945 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE); in smb3_parse_lease_buf()
3946 return le32_to_cpu(lc->lcontext.LeaseState); in smb3_parse_lease_buf()
3952 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize, in smb2_wp_retry_size()
3959 return !cfile->invalidHandle; in smb2_dir_needs_close()
3967 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base; in fill_transform_hdr()
3970 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; in fill_transform_hdr()
3971 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len); in fill_transform_hdr()
3972 tr_hdr->Flags = cpu_to_le16(0x01); in fill_transform_hdr()
3975 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE); in fill_transform_hdr()
3977 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE); in fill_transform_hdr()
3978 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8); in fill_transform_hdr()
4032 rqst[i].rq_iov[j].iov_len - skip); in init_sg()
4054 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { in smb2_get_enc_key()
4055 if (ses->Suid == ses_id) { in smb2_get_enc_key()
4056 ses_enc_key = enc ? ses->smb3encryptionkey : in smb2_get_enc_key()
4057 ses->smb3decryptionkey; in smb2_get_enc_key()
4070 * iov[0] - transform header (associate data),
4071 * iov[1-N] - SMB2 header and pages - data to encrypt.
4072 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4081 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20; in crypt_message()
4091 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize); in crypt_message()
4093 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key); in crypt_message()
4106 tfm = enc ? server->secmech.ccmaesencrypt : in crypt_message()
4107 server->secmech.ccmaesdecrypt; in crypt_message()
4109 if (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM) in crypt_message()
4128 return -ENOMEM; in crypt_message()
4132 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE); in crypt_message()
4139 rc = -ENOMEM; in crypt_message()
4147 rc = -ENOMEM; in crypt_message()
4151 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) || in crypt_message()
4152 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) in crypt_message()
4153 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE); in crypt_message()
4156 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE); in crypt_message()
4169 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE); in crypt_message()
4186 for (j = rqst[i].rq_npages - 1; j >= 0; j--) in smb3_free_compound_rqst()
4196 * a smb2_transform_hdr and is pre-allocated by the caller.
4203 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4215 int rc = -ENOMEM; in smb3_init_transform_rq()
4218 npages = old_rq[i - 1].rq_npages; in smb3_init_transform_rq()
4226 new_rq[i].rq_offset = old_rq[i - 1].rq_offset; in smb3_init_transform_rq()
4227 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz; in smb3_init_transform_rq()
4228 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz; in smb3_init_transform_rq()
4229 new_rq[i].rq_iov = old_rq[i - 1].rq_iov; in smb3_init_transform_rq()
4230 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec; in smb3_init_transform_rq()
4232 orig_len += smb_rqst_len(server, &old_rq[i - 1]); in smb3_init_transform_rq()
4248 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset; in smb3_init_transform_rq()
4252 kunmap(old_rq[i - 1].rq_pages[j]); in smb3_init_transform_rq()
4257 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type); in smb3_init_transform_rq()
4267 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]); in smb3_init_transform_rq()
4276 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM; in smb3_is_transform_hdr()
4310 server->total_read = buf_data_size + page_data_size; in decrypt_raw_data()
4330 len -= n; in read_data_into_pages()
4332 zero_user(page, len, PAGE_SIZE - len); in read_data_into_pages()
4338 server->total_read += length; in read_data_into_pages()
4353 return -ENOMEM; in init_read_bvec()
4359 data_size -= bvec[i].bv_len; in init_read_bvec()
4365 return -EIO; in init_read_bvec()
4383 struct cifs_readdata *rdata = mid->callback_data; in handle_read_data()
4391 if (shdr->Command != SMB2_READ) { in handle_read_data()
4393 return -ENOTSUPP; in handle_read_data()
4396 if (server->ops->is_session_expired && in handle_read_data()
4397 server->ops->is_session_expired(buf)) { in handle_read_data()
4400 return -1; in handle_read_data()
4403 if (server->ops->is_status_pending && in handle_read_data()
4404 server->ops->is_status_pending(buf, server)) in handle_read_data()
4405 return -1; in handle_read_data()
4408 rdata->iov[0].iov_base = buf; in handle_read_data()
4409 rdata->iov[0].iov_len = 0; in handle_read_data()
4410 rdata->iov[1].iov_base = buf; in handle_read_data()
4411 rdata->iov[1].iov_len = in handle_read_data()
4412 min_t(unsigned int, buf_len, server->vals->read_rsp_size); in handle_read_data()
4414 rdata->iov[0].iov_base, rdata->iov[0].iov_len); in handle_read_data()
4416 rdata->iov[1].iov_base, rdata->iov[1].iov_len); in handle_read_data()
4418 rdata->result = server->ops->map_error(buf, true); in handle_read_data()
4419 if (rdata->result != 0) { in handle_read_data()
4421 __func__, rdata->result); in handle_read_data()
4424 mid->mid_state = MID_RESPONSE_RECEIVED; in handle_read_data()
4430 data_offset = server->ops->read_data_offset(buf); in handle_read_data()
4432 use_rdma_mr = rdata->mr; in handle_read_data()
4434 data_len = server->ops->read_data_length(buf, use_rdma_mr); in handle_read_data()
4436 if (data_offset < server->vals->read_rsp_size) { in handle_read_data()
4444 data_offset = server->vals->read_rsp_size; in handle_read_data()
4449 rdata->result = -EIO; in handle_read_data()
4451 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4453 dequeue_mid(mid, rdata->result); in handle_read_data()
4457 pad_len = data_offset - server->vals->read_rsp_size; in handle_read_data()
4468 rdata->result = -EIO; in handle_read_data()
4470 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4472 dequeue_mid(mid, rdata->result); in handle_read_data()
4476 if (data_len > page_data_size - pad_len) { in handle_read_data()
4477 /* data_len is corrupt -- discard frame */ in handle_read_data()
4478 rdata->result = -EIO; in handle_read_data()
4480 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4482 dequeue_mid(mid, rdata->result); in handle_read_data()
4486 rdata->result = init_read_bvec(pages, npages, page_data_size, in handle_read_data()
4488 if (rdata->result != 0) { in handle_read_data()
4490 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4492 dequeue_mid(mid, rdata->result); in handle_read_data()
4506 rdata->result = -EIO; in handle_read_data()
4508 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4510 dequeue_mid(mid, rdata->result); in handle_read_data()
4514 length = rdata->copy_into_pages(server, rdata, &iter); in handle_read_data()
4522 mid->mid_state = MID_RESPONSE_RECEIVED; in handle_read_data()
4545 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size, in smb2_decrypt_offload()
4546 dw->ppages, dw->npages, dw->len, true); in smb2_decrypt_offload()
4552 dw->server->lstrp = jiffies; in smb2_decrypt_offload()
4553 mid = smb2_find_dequeue_mid(dw->server, dw->buf); in smb2_decrypt_offload()
4557 mid->decrypted = true; in smb2_decrypt_offload()
4558 rc = handle_read_data(dw->server, mid, dw->buf, in smb2_decrypt_offload()
4559 dw->server->vals->read_rsp_size, in smb2_decrypt_offload()
4560 dw->ppages, dw->npages, dw->len, in smb2_decrypt_offload()
4564 mid->when_received = jiffies; in smb2_decrypt_offload()
4566 mid->callback(mid); in smb2_decrypt_offload()
4569 if (dw->server->tcpStatus == CifsNeedReconnect) { in smb2_decrypt_offload()
4570 mid->mid_state = MID_RETRY_NEEDED; in smb2_decrypt_offload()
4572 mid->callback(mid); in smb2_decrypt_offload()
4574 mid->mid_state = MID_REQUEST_SUBMITTED; in smb2_decrypt_offload()
4575 mid->mid_flags &= ~(MID_DELETED); in smb2_decrypt_offload()
4576 list_add_tail(&mid->qhead, in smb2_decrypt_offload()
4577 &dw->server->pending_mid_q); in smb2_decrypt_offload()
4585 for (i = dw->npages-1; i >= 0; i--) in smb2_decrypt_offload()
4586 put_page(dw->ppages[i]); in smb2_decrypt_offload()
4588 kfree(dw->ppages); in smb2_decrypt_offload()
4589 cifs_small_buf_release(dw->buf); in smb2_decrypt_offload()
4598 char *buf = server->smallbuf; in receive_encrypted_read()
4603 unsigned int buflen = server->pdu_size; in receive_encrypted_read()
4609 len = min_t(unsigned int, buflen, server->vals->read_rsp_size + in receive_encrypted_read()
4610 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1; in receive_encrypted_read()
4612 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len); in receive_encrypted_read()
4615 server->total_read += rc; in receive_encrypted_read()
4617 len = le32_to_cpu(tr_hdr->OriginalMessageSize) - in receive_encrypted_read()
4618 server->vals->read_rsp_size; in receive_encrypted_read()
4623 rc = -ENOMEM; in receive_encrypted_read()
4630 rc = -ENOMEM; in receive_encrypted_read()
4649 if ((server->min_offload) && (server->in_flight > 1) && in receive_encrypted_read()
4650 (server->pdu_size >= server->min_offload)) { in receive_encrypted_read()
4655 dw->buf = server->smallbuf; in receive_encrypted_read()
4656 server->smallbuf = (char *)cifs_small_buf_get(); in receive_encrypted_read()
4658 INIT_WORK(&dw->decrypt, smb2_decrypt_offload); in receive_encrypted_read()
4660 dw->npages = npages; in receive_encrypted_read()
4661 dw->server = server; in receive_encrypted_read()
4662 dw->ppages = pages; in receive_encrypted_read()
4663 dw->len = len; in receive_encrypted_read()
4664 queue_work(decrypt_wq, &dw->decrypt); in receive_encrypted_read()
4666 return -1; in receive_encrypted_read()
4670 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size, in receive_encrypted_read()
4680 (*mid)->decrypted = true; in receive_encrypted_read()
4682 server->vals->read_rsp_size, in receive_encrypted_read()
4687 for (i = i - 1; i >= 0; i--) in receive_encrypted_read()
4702 char *buf = server->smallbuf; in receive_encrypted_standard()
4704 unsigned int pdu_length = server->pdu_size; in receive_encrypted_standard()
4714 server->large_buf = true; in receive_encrypted_standard()
4715 memcpy(server->bigbuf, buf, server->total_read); in receive_encrypted_standard()
4716 buf = server->bigbuf; in receive_encrypted_standard()
4720 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, in receive_encrypted_standard()
4721 pdu_length - HEADER_SIZE(server) + 1); in receive_encrypted_standard()
4724 server->total_read += length; in receive_encrypted_standard()
4726 buf_size = pdu_length - sizeof(struct smb2_transform_hdr); in receive_encrypted_standard()
4731 next_is_large = server->large_buf; in receive_encrypted_standard()
4734 if (shdr->NextCommand) { in receive_encrypted_standard()
4740 buf + le32_to_cpu(shdr->NextCommand), in receive_encrypted_standard()
4741 pdu_length - le32_to_cpu(shdr->NextCommand)); in receive_encrypted_standard()
4749 mid_entry->decrypted = true; in receive_encrypted_standard()
4750 mid_entry->resp_buf_size = server->pdu_size; in receive_encrypted_standard()
4755 return -1; in receive_encrypted_standard()
4760 if (mid_entry && mid_entry->handle) in receive_encrypted_standard()
4761 ret = mid_entry->handle(server, mid_entry); in receive_encrypted_standard()
4765 if (ret == 0 && shdr->NextCommand) { in receive_encrypted_standard()
4766 pdu_length -= le32_to_cpu(shdr->NextCommand); in receive_encrypted_standard()
4767 server->large_buf = next_is_large; in receive_encrypted_standard()
4769 server->bigbuf = buf = next_buffer; in receive_encrypted_standard()
4771 server->smallbuf = buf = next_buffer; in receive_encrypted_standard()
4776 * server->smallbuf and server->bigbuf are still valid. We need in receive_encrypted_standard()
4793 char *buf = server->smallbuf; in smb3_receive_transform()
4794 unsigned int pdu_length = server->pdu_size; in smb3_receive_transform()
4796 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize); in smb3_receive_transform()
4803 return -ECONNABORTED; in smb3_receive_transform()
4809 return -ECONNABORTED; in smb3_receive_transform()
4823 char *buf = server->large_buf ? server->bigbuf : server->smallbuf; in smb3_handle_read_data()
4825 return handle_read_data(server, mid, buf, server->pdu_size, in smb3_handle_read_data()
4835 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) in smb2_next_header()
4837 le32_to_cpu(t_hdr->OriginalMessageSize); in smb2_next_header()
4839 return le32_to_cpu(hdr->NextCommand); in smb2_next_header()
4844 struct dentry *dentry, struct cifs_tcon *tcon, in smb2_make_node() argument
4847 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in smb2_make_node()
4848 int rc = -EPERM; in smb2_make_node()
4864 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)) in smb2_make_node()
4880 rc = -ENOMEM; in smb2_make_node()
4884 oparms.tcon = tcon; in smb2_make_node()
4894 if (tcon->ses->server->oplocks) in smb2_make_node()
4898 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf); in smb2_make_node()
4908 io_parms.pid = current->tgid; in smb2_make_node()
4909 io_parms.tcon = tcon; in smb2_make_node()
4915 memcpy(pdev->type, "IntxCHR", 8); in smb2_make_node()
4916 pdev->major = cpu_to_le64(MAJOR(dev)); in smb2_make_node()
4917 pdev->minor = cpu_to_le64(MINOR(dev)); in smb2_make_node()
4918 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms, in smb2_make_node()
4921 memcpy(pdev->type, "IntxBLK", 8); in smb2_make_node()
4922 pdev->major = cpu_to_le64(MAJOR(dev)); in smb2_make_node()
4923 pdev->minor = cpu_to_le64(MINOR(dev)); in smb2_make_node()
4924 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms, in smb2_make_node()
4927 tcon->ses->server->ops->close(xid, tcon, &fid); in smb2_make_node()
5373 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5394 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5415 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5436 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5457 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5478 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5499 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,