• Home
  • Raw
  • Download

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()
481 if ((bytes_left > 8) || p->Next) in parse_server_interfaces()
491 rc = -ENOMEM; in parse_server_interfaces()
499 info->speed = le64_to_cpu(p->LinkSpeed); in parse_server_interfaces()
500 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0; in parse_server_interfaces()
501 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0; in parse_server_interfaces()
504 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed); in parse_server_interfaces()
506 le32_to_cpu(p->Capability)); in parse_server_interfaces()
508 switch (p->Family) { in parse_server_interfaces()
515 addr4 = (struct sockaddr_in *)&info->sockaddr; in parse_server_interfaces()
516 p4 = (struct iface_info_ipv4 *)p->Buffer; in parse_server_interfaces()
517 addr4->sin_family = AF_INET; in parse_server_interfaces()
518 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4); in parse_server_interfaces()
520 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */ in parse_server_interfaces()
521 addr4->sin_port = cpu_to_be16(CIFS_PORT); in parse_server_interfaces()
524 &addr4->sin_addr); in parse_server_interfaces()
527 addr6 = (struct sockaddr_in6 *)&info->sockaddr; in parse_server_interfaces()
528 p6 = (struct iface_info_ipv6 *)p->Buffer; in parse_server_interfaces()
529 addr6->sin6_family = AF_INET6; in parse_server_interfaces()
530 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16); in parse_server_interfaces()
532 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */ in parse_server_interfaces()
533 addr6->sin6_flowinfo = 0; in parse_server_interfaces()
534 addr6->sin6_scope_id = 0; in parse_server_interfaces()
535 addr6->sin6_port = cpu_to_be16(CIFS_PORT); in parse_server_interfaces()
538 &addr6->sin6_addr); in parse_server_interfaces()
550 next = le32_to_cpu(p->Next); in parse_server_interfaces()
554 bytes_left -= next; in parse_server_interfaces()
558 rc = -EINVAL; in parse_server_interfaces()
576 return a->speed == b->speed ? 0 : (a->speed > b->speed ? -1 : 1); in compare_iface()
580 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon) in SMB3_request_interfaces() argument
587 struct cifs_ses *ses = tcon->ses; in SMB3_request_interfaces()
589 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, in SMB3_request_interfaces()
593 if (rc == -EOPNOTSUPP) { in SMB3_request_interfaces()
610 spin_lock(&ses->iface_lock); in SMB3_request_interfaces()
611 kfree(ses->iface_list); in SMB3_request_interfaces()
612 ses->iface_list = iface_list; in SMB3_request_interfaces()
613 ses->iface_count = iface_count; in SMB3_request_interfaces()
614 ses->iface_last_update = jiffies; in SMB3_request_interfaces()
615 spin_unlock(&ses->iface_lock); in SMB3_request_interfaces()
628 if (cfid->is_valid) { in smb2_close_cached_fid()
630 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid, in smb2_close_cached_fid()
631 cfid->fid->volatile_fid); in smb2_close_cached_fid()
632 cfid->is_valid = false; in smb2_close_cached_fid()
633 cfid->file_all_info_is_valid = false; in smb2_close_cached_fid()
634 cfid->has_lease = false; in smb2_close_cached_fid()
640 mutex_lock(&cfid->fid_mutex); in close_shroot()
641 kref_put(&cfid->refcount, smb2_close_cached_fid); in close_shroot()
642 mutex_unlock(&cfid->fid_mutex); in close_shroot()
647 if (cfid->has_lease) { in close_shroot_lease_locked()
648 cfid->has_lease = false; in close_shroot_lease_locked()
649 kref_put(&cfid->refcount, smb2_close_cached_fid); in close_shroot_lease_locked()
655 mutex_lock(&cfid->fid_mutex); in close_shroot_lease()
657 mutex_unlock(&cfid->fid_mutex); in close_shroot_lease()
672 int open_shroot(unsigned int xid, struct cifs_tcon *tcon, in open_shroot() argument
676 struct cifs_ses *ses = tcon->ses; in open_shroot()
677 struct TCP_Server_Info *server = ses->server; in open_shroot()
687 __le16 utf16_path = 0; /* Null - since an open of top of share */ in open_shroot()
691 mutex_lock(&tcon->crfid.fid_mutex); in open_shroot()
692 if (tcon->crfid.is_valid) { in open_shroot()
694 *cfid = &tcon->crfid; in open_shroot()
695 kref_get(&tcon->crfid.refcount); in open_shroot()
696 mutex_unlock(&tcon->crfid.fid_mutex); in open_shroot()
707 mutex_unlock(&tcon->crfid.fid_mutex); in open_shroot()
709 if (smb3_encryption_required(tcon)) in open_shroot()
712 if (!server->ops->new_lease_key) in open_shroot()
713 return -EIO; in open_shroot()
715 pfid = tcon->crfid.fid; in open_shroot()
716 server->ops->new_lease_key(pfid); in open_shroot()
727 oparms.tcon = tcon; in open_shroot()
734 rc = SMB2_open_init(tcon, server, in open_shroot()
738 smb2_set_next_command(tcon, &rqst[0]); in open_shroot()
744 rc = SMB2_query_info_init(tcon, server, in open_shroot()
758 mutex_lock(&tcon->crfid.fid_mutex); in open_shroot()
762 * been successfully re-opened from a concurrent process in open_shroot()
765 if (tcon->crfid.is_valid) { in open_shroot()
770 .persistent_fid = pfid->persistent_fid, in open_shroot()
771 .volatile_fid = pfid->volatile_fid, in open_shroot()
779 memcpy(pfid, tcon->crfid.fid, sizeof(*pfid)); in open_shroot()
780 kref_get(&tcon->crfid.refcount); in open_shroot()
782 mutex_unlock(&tcon->crfid.fid_mutex); in open_shroot()
786 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in open_shroot()
795 if (rc == -EREMCHG) { in open_shroot()
796 tcon->need_reconnect = true; in open_shroot()
798 tcon->treeName); in open_shroot()
803 atomic_inc(&tcon->num_remote_opens); in open_shroot()
806 oparms.fid->persistent_fid = o_rsp->PersistentFileId; in open_shroot()
807 oparms.fid->volatile_fid = o_rsp->VolatileFileId; in open_shroot()
809 oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId); in open_shroot()
812 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid)); in open_shroot()
813 tcon->crfid.tcon = tcon; in open_shroot()
814 tcon->crfid.is_valid = true; in open_shroot()
815 kref_init(&tcon->crfid.refcount); in open_shroot()
818 if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) { in open_shroot()
819 kref_get(&tcon->crfid.refcount); in open_shroot()
820 tcon->crfid.has_lease = true; in open_shroot()
822 &oparms.fid->epoch, in open_shroot()
823 oparms.fid->lease_key, &oplock, in open_shroot()
829 if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info)) in open_shroot()
832 le16_to_cpu(qi_rsp->OutputBufferOffset), in open_shroot()
835 (char *)&tcon->crfid.file_all_info)) in open_shroot()
836 tcon->crfid.file_all_info_is_valid = true; in open_shroot()
839 mutex_unlock(&tcon->crfid.fid_mutex); in open_shroot()
846 *cfid = &tcon->crfid; in open_shroot()
851 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, in smb3_qfs_tcon() argument
855 __le16 srch_path = 0; /* Null - open root of share */ in smb3_qfs_tcon()
859 bool no_cached_open = tcon->nohandlecache; in smb3_qfs_tcon()
863 .tcon = tcon, in smb3_qfs_tcon()
874 rc = open_shroot(xid, tcon, cifs_sb, &cfid); in smb3_qfs_tcon()
876 memcpy(&fid, cfid->fid, sizeof(struct cifs_fid)); in smb3_qfs_tcon()
881 SMB3_request_interfaces(xid, tcon); 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()
889 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_qfs_tcon()
892 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb3_qfs_tcon()
898 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, in smb2_qfs_tcon() argument
902 __le16 srch_path = 0; /* Null - open root of share */ in smb2_qfs_tcon()
907 oparms.tcon = tcon; in smb2_qfs_tcon()
919 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb2_qfs_tcon()
921 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb2_qfs_tcon()
923 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb2_qfs_tcon()
927 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, in smb2_is_path_accessible() argument
936 if ((*full_path == 0) && tcon->crfid.is_valid) in smb2_is_path_accessible()
941 return -ENOMEM; in smb2_is_path_accessible()
943 oparms.tcon = tcon; in smb2_is_path_accessible()
957 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb2_is_path_accessible()
963 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, in smb2_get_srv_inum() argument
967 *uniqueid = le64_to_cpu(data->IndexNumber); in smb2_get_srv_inum()
972 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_file_info() argument
981 return -ENOMEM; in smb2_query_file_info()
983 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, in smb2_query_file_info()
1004 name_len = (size_t)src->ea_name_length; 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()
1016 name = &src->ea_data[0]; in move_smb2_ea_to_cifs()
1017 value = &src->ea_data[src->ea_name_length + 1]; in move_smb2_ea_to_cifs()
1026 rc = -ERANGE; in move_smb2_ea_to_cifs()
1037 /* skip copy - calc size only */ in move_smb2_ea_to_cifs()
1040 dst_size -= user_name_len; in move_smb2_ea_to_cifs()
1043 memcpy(dst, src->ea_data, name_len); in move_smb2_ea_to_cifs()
1050 rc = -ERANGE; in move_smb2_ea_to_cifs()
1055 if (!src->next_entry_offset) in move_smb2_ea_to_cifs()
1058 if (src_size < le32_to_cpu(src->next_entry_offset)) { in move_smb2_ea_to_cifs()
1060 rc = -ERANGE; in move_smb2_ea_to_cifs()
1063 src_size -= le32_to_cpu(src->next_entry_offset); in move_smb2_ea_to_cifs()
1065 le32_to_cpu(src->next_entry_offset)); in move_smb2_ea_to_cifs()
1070 rc = -ENODATA; in move_smb2_ea_to_cifs()
1077 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_eas() argument
1091 return -ENOMEM; in smb2_query_eas()
1093 rc = smb2_query_info_compound(xid, tcon, utf16_path, in smb2_query_eas()
1097 CIFSMaxBufSize - in smb2_query_eas()
1098 MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_query_eas()
1107 if (!ea_name && rc == -ENODATA) in smb2_query_eas()
1113 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in smb2_query_eas()
1114 le32_to_cpu(rsp->OutputBufferLength), in smb2_query_eas()
1121 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in smb2_query_eas()
1123 le32_to_cpu(rsp->OutputBufferLength), ea_name); in smb2_query_eas()
1133 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_ea() argument
1138 struct cifs_ses *ses = tcon->ses; in smb2_set_ea()
1159 if (smb3_encryption_required(tcon)) in smb2_set_ea()
1163 return -EINVAL; in smb2_set_ea()
1167 return -ENOMEM; in smb2_set_ea()
1173 if (ses->server->ops->query_all_EAs) { in smb2_set_ea()
1175 rc = ses->server->ops->query_all_EAs(xid, tcon, path, in smb2_set_ea()
1178 if (rc == -ENODATA) in smb2_set_ea()
1186 rc = smb2_query_info_compound(xid, tcon, utf16_path, in smb2_set_ea()
1190 CIFSMaxBufSize - in smb2_set_ea()
1191 MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_set_ea()
1196 used_len = le32_to_cpu(rsp->OutputBufferLength); in smb2_set_ea()
1206 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_set_ea()
1207 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 < in smb2_set_ea()
1209 rc = -ENOSPC; in smb2_set_ea()
1221 oparms.tcon = tcon; in smb2_set_ea()
1228 rc = SMB2_open_init(tcon, server, in smb2_set_ea()
1232 smb2_set_next_command(tcon, &rqst[0]); in smb2_set_ea()
1243 rc = -ENOMEM; in smb2_set_ea()
1247 ea->ea_name_length = ea_name_len; in smb2_set_ea()
1248 ea->ea_value_length = cpu_to_le16(ea_value_len); in smb2_set_ea()
1249 memcpy(ea->ea_data, ea_name, ea_name_len + 1); in smb2_set_ea()
1250 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len); in smb2_set_ea()
1255 rc = SMB2_set_info_init(tcon, server, in smb2_set_ea()
1257 COMPOUND_FID, current->tgid, in smb2_set_ea()
1262 smb2_set_next_command(tcon, &rqst[1]); in smb2_set_ea()
1270 rc = SMB2_close_init(tcon, server, in smb2_set_ea()
1297 return server->echoes; in smb2_can_echo()
1301 smb2_clear_stats(struct cifs_tcon *tcon) in smb2_clear_stats() argument
1306 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); in smb2_clear_stats()
1307 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); in smb2_clear_stats()
1312 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) in smb2_dump_share_caps() argument
1315 if (tcon->capabilities & SMB2_SHARE_CAP_DFS) in smb2_dump_share_caps()
1317 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) in smb2_dump_share_caps()
1319 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) in smb2_dump_share_caps()
1321 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) in smb2_dump_share_caps()
1323 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) in smb2_dump_share_caps()
1325 if (tcon->capabilities == 0) in smb2_dump_share_caps()
1327 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE) in smb2_dump_share_caps()
1329 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE) in smb2_dump_share_caps()
1331 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY) in smb2_dump_share_caps()
1333 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED) in smb2_dump_share_caps()
1334 seq_puts(m, " TRIM-support,"); in smb2_dump_share_caps()
1336 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); in smb2_dump_share_caps()
1337 seq_printf(m, "\n\ttid: 0x%x", tcon->tid); in smb2_dump_share_caps()
1338 if (tcon->perf_sector_size) in smb2_dump_share_caps()
1340 tcon->perf_sector_size); in smb2_dump_share_caps()
1341 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access); in smb2_dump_share_caps()
1345 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) in smb2_print_stats() argument
1347 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; in smb2_print_stats()
1348 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; in smb2_print_stats()
1352 * totals (requests sent) since those SMBs are per-session not per tcon in smb2_print_stats()
1355 (long long)(tcon->bytes_read), in smb2_print_stats()
1356 (long long)(tcon->bytes_written)); in smb2_print_stats()
1358 atomic_read(&tcon->num_local_opens), in smb2_print_stats()
1359 atomic_read(&tcon->num_remote_opens)); in smb2_print_stats()
1407 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); in smb2_set_fid()
1408 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; in smb2_set_fid()
1410 cfile->fid.persistent_fid = fid->persistent_fid; in smb2_set_fid()
1411 cfile->fid.volatile_fid = fid->volatile_fid; in smb2_set_fid()
1412 cfile->fid.access = fid->access; in smb2_set_fid()
1414 cfile->fid.mid = fid->mid; in smb2_set_fid()
1416 server->ops->set_oplock_level(cinode, oplock, fid->epoch, in smb2_set_fid()
1417 &fid->purge_cache); in smb2_set_fid()
1418 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); in smb2_set_fid()
1419 memcpy(cfile->fid.create_guid, fid->create_guid, 16); in smb2_set_fid()
1423 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, in smb2_close_file() argument
1426 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_close_file()
1430 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon, in smb2_close_getattr() argument
1437 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid, in smb2_close_getattr()
1438 cfile->fid.volatile_fid, &file_inf); in smb2_close_getattr()
1442 inode = d_inode(cfile->dentry); in smb2_close_getattr()
1444 spin_lock(&inode->i_lock); in smb2_close_getattr()
1445 CIFS_I(inode)->time = jiffies; in smb2_close_getattr()
1449 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime); in smb2_close_getattr()
1451 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime); in smb2_close_getattr()
1453 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime); in smb2_close_getattr()
1461 inode->i_blocks = in smb2_close_getattr()
1462 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9; in smb2_close_getattr()
1465 spin_unlock(&inode->i_lock); in smb2_close_getattr()
1469 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_request_res_key() argument
1477 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, in SMB2_request_res_key()
1487 rc = -EINVAL; in SMB2_request_res_key()
1490 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE); in SMB2_request_res_key()
1509 struct cifs_tcon *tcon, in smb2_ioctl_query_info() argument
1517 struct cifs_ses *ses = tcon->ses; in smb2_ioctl_query_info()
1538 return -ENOMEM; in smb2_ioctl_query_info()
1539 rqst = &vars->rqst[0]; in smb2_ioctl_query_info()
1540 rsp_iov = &vars->rsp_iov[0]; in smb2_ioctl_query_info()
1545 rc = -EFAULT; in smb2_ioctl_query_info()
1549 rc = -EINVAL; in smb2_ioctl_query_info()
1554 rc = -EIO; in smb2_ioctl_query_info()
1558 if (smb3_encryption_required(tcon)) in smb2_ioctl_query_info()
1570 rqst[0].rq_iov = &vars->open_iov[0]; in smb2_ioctl_query_info()
1574 oparms.tcon = tcon; in smb2_ioctl_query_info()
1601 rc = SMB2_open_init(tcon, server, in smb2_ioctl_query_info()
1605 smb2_set_next_command(tcon, &rqst[0]); in smb2_ioctl_query_info()
1611 rc = -EPERM; in smb2_ioctl_query_info()
1614 rqst[1].rq_iov = &vars->io_iov[0]; in smb2_ioctl_query_info()
1617 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID, in smb2_ioctl_query_info()
1619 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_ioctl_query_info()
1625 rc = -EPERM; in smb2_ioctl_query_info()
1629 rc = -EINVAL; in smb2_ioctl_query_info()
1632 rqst[1].rq_iov = &vars->si_iov[0]; in smb2_ioctl_query_info()
1635 /* MS-FSCC 2.4.13 FileEndOfFileInformation */ in smb2_ioctl_query_info()
1639 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID, in smb2_ioctl_query_info()
1640 current->tgid, FILE_END_OF_FILE_INFORMATION, in smb2_ioctl_query_info()
1644 rqst[1].rq_iov = &vars->qi_iov[0]; in smb2_ioctl_query_info()
1647 rc = SMB2_query_info_init(tcon, server, in smb2_ioctl_query_info()
1657 rc = -EINVAL; in smb2_ioctl_query_info()
1662 smb2_set_next_command(tcon, &rqst[1]); in smb2_ioctl_query_info()
1666 rqst[2].rq_iov = &vars->close_iov[0]; in smb2_ioctl_query_info()
1669 rc = SMB2_close_init(tcon, server, in smb2_ioctl_query_info()
1685 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length) in smb2_ioctl_query_info()
1686 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount); in smb2_ioctl_query_info()
1688 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length in smb2_ioctl_query_info()
1690 rc = -EFAULT; in smb2_ioctl_query_info()
1694 if (copy_to_user(&pqi->input_buffer_length, in smb2_ioctl_query_info()
1697 rc = -EFAULT; in smb2_ioctl_query_info()
1702 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset), in smb2_ioctl_query_info()
1704 rc = -EFAULT; in smb2_ioctl_query_info()
1708 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length) in smb2_ioctl_query_info()
1709 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength); in smb2_ioctl_query_info()
1710 if (copy_to_user(&pqi->input_buffer_length, in smb2_ioctl_query_info()
1713 rc = -EFAULT; in smb2_ioctl_query_info()
1717 if (copy_to_user(pqi + 1, qi_rsp->Buffer, in smb2_ioctl_query_info()
1719 rc = -EFAULT; in smb2_ioctl_query_info()
1748 struct cifs_tcon *tcon; in smb2_copychunk_range() local
1760 inode = d_inode(trgtfile->dentry); in smb2_copychunk_range()
1761 filemap_write_and_wait(inode->i_mapping); in smb2_copychunk_range()
1764 return -ENOMEM; in smb2_copychunk_range()
1768 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), in smb2_copychunk_range()
1769 srcfile->fid.persistent_fid, in smb2_copychunk_range()
1770 srcfile->fid.volatile_fid, pcchunk); in smb2_copychunk_range()
1777 pcchunk->ChunkCount = cpu_to_le32(1); in smb2_copychunk_range()
1778 pcchunk->Reserved = 0; in smb2_copychunk_range()
1779 pcchunk->Reserved2 = 0; in smb2_copychunk_range()
1781 tcon = tlink_tcon(trgtfile->tlink); in smb2_copychunk_range()
1784 pcchunk->SourceOffset = cpu_to_le64(src_off); in smb2_copychunk_range()
1785 pcchunk->TargetOffset = cpu_to_le64(dest_off); in smb2_copychunk_range()
1786 pcchunk->Length = in smb2_copychunk_range()
1787 cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk)); in smb2_copychunk_range()
1792 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, in smb2_copychunk_range()
1793 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, in smb2_copychunk_range()
1800 rc = -EIO; in smb2_copychunk_range()
1803 if (retbuf->TotalBytesWritten == 0) { in smb2_copychunk_range()
1805 rc = -EIO; in smb2_copychunk_range()
1811 if (le32_to_cpu(retbuf->TotalBytesWritten) > in smb2_copychunk_range()
1812 le32_to_cpu(pcchunk->Length)) { in smb2_copychunk_range()
1814 rc = -EIO; in smb2_copychunk_range()
1817 if (le32_to_cpu(retbuf->ChunksWritten) != 1) { in smb2_copychunk_range()
1819 rc = -EIO; in smb2_copychunk_range()
1824 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten); in smb2_copychunk_range()
1827 len -= bytes_written; in smb2_copychunk_range()
1831 le32_to_cpu(retbuf->ChunksWritten), in smb2_copychunk_range()
1832 le32_to_cpu(retbuf->ChunkBytesWritten), in smb2_copychunk_range()
1834 } else if (rc == -EINVAL) { in smb2_copychunk_range()
1839 le32_to_cpu(retbuf->ChunksWritten), in smb2_copychunk_range()
1840 le32_to_cpu(retbuf->ChunkBytesWritten), in smb2_copychunk_range()
1841 le32_to_cpu(retbuf->TotalBytesWritten)); in smb2_copychunk_range()
1854 if (le32_to_cpu(retbuf->ChunkBytesWritten) < in smb2_copychunk_range()
1855 tcon->max_bytes_chunk) in smb2_copychunk_range()
1856 tcon->max_bytes_chunk = in smb2_copychunk_range()
1857 le32_to_cpu(retbuf->ChunkBytesWritten); in smb2_copychunk_range()
1877 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, in smb2_flush_file() argument
1880 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_flush_file()
1888 return rsp->DataOffset; in smb2_read_data_offset()
1897 return le32_to_cpu(rsp->DataRemaining); in smb2_read_data_length()
1899 return le32_to_cpu(rsp->DataLength); in smb2_read_data_length()
1908 parms->persistent_fid = pfid->persistent_fid; in smb2_sync_read()
1909 parms->volatile_fid = pfid->volatile_fid; in smb2_sync_read()
1919 parms->persistent_fid = pfid->persistent_fid; in smb2_sync_write()
1920 parms->volatile_fid = pfid->volatile_fid; in smb2_sync_write()
1925 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_sparse() argument
1934 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse) in smb2_set_sparse()
1937 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse) in smb2_set_sparse()
1950 if (tcon->broken_sparse_sup) in smb2_set_sparse()
1953 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb2_set_sparse()
1954 cfile->fid.volatile_fid, FSCTL_SET_SPARSE, in smb2_set_sparse()
1957 tcon->broken_sparse_sup = true; in smb2_set_sparse()
1963 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE; in smb2_set_sparse()
1965 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE); in smb2_set_sparse()
1971 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_file_size() argument
1981 inode = d_inode(cfile->dentry); in smb2_set_file_size()
1983 if (!set_alloc && (size > inode->i_size + 8192)) { in smb2_set_file_size()
1987 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse); in smb2_set_file_size()
1990 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb2_set_file_size()
1991 cfile->fid.volatile_fid, cfile->pid, &eof); in smb2_set_file_size()
2004 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink); in smb2_duplicate_extents() local
2007 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) & in smb2_duplicate_extents()
2009 return -EOPNOTSUPP; in smb2_duplicate_extents()
2011 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid; in smb2_duplicate_extents()
2012 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid; in smb2_duplicate_extents()
2019 inode = d_inode(trgtfile->dentry); in smb2_duplicate_extents()
2020 if (inode->i_size < dest_off + len) { in smb2_duplicate_extents()
2021 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); in smb2_duplicate_extents()
2034 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, in smb2_duplicate_extents()
2035 trgtfile->fid.volatile_fid, in smb2_duplicate_extents()
2043 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n"); in smb2_duplicate_extents()
2050 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_compression() argument
2053 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, in smb2_set_compression()
2054 cfile->fid.volatile_fid); in smb2_set_compression()
2058 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon, in smb3_set_integrity() argument
2068 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_set_integrity()
2069 cfile->fid.volatile_fid, in smb3_set_integrity()
2078 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2081 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2085 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2088 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon, in smb3_enum_snapshots() argument
2106 return -EFAULT; in smb3_enum_snapshots()
2120 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_enum_snapshots()
2121 cfile->fid.volatile_fid, in smb3_enum_snapshots()
2135 rc = -EFAULT; in smb3_enum_snapshots()
2162 rc = -EFAULT; in smb3_enum_snapshots()
2176 struct dentry *dentry = pfile->f_path.dentry; in smb3_notify()
2181 struct cifs_tcon *tcon; in smb3_notify() local
2189 return -ENOMEM; in smb3_notify()
2191 cifs_sb = CIFS_SB(inode->i_sb); in smb3_notify()
2195 rc = -ENOMEM; in smb3_notify()
2200 rc = -EFAULT; in smb3_notify()
2204 tcon = cifs_sb_master_tcon(cifs_sb); in smb3_notify()
2205 oparms.tcon = tcon; in smb3_notify()
2217 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_notify()
2220 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb3_notify()
2231 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_dir_first() argument
2247 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); in smb2_query_dir_first()
2251 return -ENOMEM; in smb2_query_dir_first()
2253 if (smb3_encryption_required(tcon)) in smb2_query_dir_first()
2265 oparms.tcon = tcon; in smb2_query_dir_first()
2272 rc = SMB2_open_init(tcon, server, in smb2_query_dir_first()
2276 smb2_set_next_command(tcon, &rqst[0]); in smb2_query_dir_first()
2279 srch_inf->entries_in_buffer = 0; in smb2_query_dir_first()
2280 srch_inf->index_of_last_entry = 2; in smb2_query_dir_first()
2286 rc = SMB2_query_directory_init(xid, tcon, server, in smb2_query_dir_first()
2289 0, srch_inf->info_level); in smb2_query_dir_first()
2295 rc = compound_send_recv(xid, tcon->ses, server, in smb2_query_dir_first()
2301 if (op_rsp == NULL || op_rsp->sync_hdr.Status != STATUS_SUCCESS) { in smb2_query_dir_first()
2305 fid->persistent_fid = op_rsp->PersistentFileId; in smb2_query_dir_first()
2306 fid->volatile_fid = op_rsp->VolatileFileId; in smb2_query_dir_first()
2309 if (rc && rc != -ENODATA) { in smb2_query_dir_first()
2310 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_query_dir_first()
2312 trace_smb3_query_dir_err(xid, fid->persistent_fid, in smb2_query_dir_first()
2313 tcon->tid, tcon->ses->Suid, 0, 0, rc); in smb2_query_dir_first()
2317 atomic_inc(&tcon->num_remote_opens); in smb2_query_dir_first()
2320 if (qd_rsp->sync_hdr.Status == STATUS_NO_MORE_FILES) { in smb2_query_dir_first()
2321 trace_smb3_query_dir_done(xid, fid->persistent_fid, in smb2_query_dir_first()
2322 tcon->tid, tcon->ses->Suid, 0, 0); in smb2_query_dir_first()
2323 srch_inf->endOfSearch = true; in smb2_query_dir_first()
2328 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1], in smb2_query_dir_first()
2331 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid, in smb2_query_dir_first()
2332 tcon->ses->Suid, 0, 0, rc); in smb2_query_dir_first()
2337 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid, in smb2_query_dir_first()
2338 tcon->ses->Suid, 0, srch_inf->entries_in_buffer); in smb2_query_dir_first()
2350 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_dir_next() argument
2354 return SMB2_query_directory(xid, tcon, fid->persistent_fid, in smb2_query_dir_next()
2355 fid->volatile_fid, 0, srch_inf); in smb2_query_dir_next()
2359 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, in smb2_close_dir() argument
2362 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_close_dir()
2366 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2367 * the number of credits and return true. Otherwise - return false.
2374 if (shdr->Status != STATUS_PENDING) in smb2_is_status_pending()
2377 if (shdr->CreditRequest) { in smb2_is_status_pending()
2378 spin_lock(&server->req_lock); in smb2_is_status_pending()
2379 server->credits += le16_to_cpu(shdr->CreditRequest); in smb2_is_status_pending()
2380 spin_unlock(&server->req_lock); in smb2_is_status_pending()
2381 wake_up(&server->request_q); in smb2_is_status_pending()
2392 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED && in smb2_is_session_expired()
2393 shdr->Status != STATUS_USER_SESSION_DELETED) in smb2_is_session_expired()
2396 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId, in smb2_is_session_expired()
2397 le16_to_cpu(shdr->Command), in smb2_is_session_expired()
2398 le64_to_cpu(shdr->MessageId)); in smb2_is_session_expired()
2409 if (shdr->Status == STATUS_IO_TIMEOUT) in smb2_is_status_io_timeout()
2416 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, in smb2_oplock_response() argument
2419 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) in smb2_oplock_response()
2420 return SMB2_lease_break(0, tcon, cinode->lease_key, in smb2_oplock_response()
2423 return SMB2_oplock_break(0, tcon, fid->persistent_fid, in smb2_oplock_response()
2424 fid->volatile_fid, in smb2_oplock_response()
2433 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base); in smb2_set_related()
2438 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS; in smb2_set_related()
2444 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst) in smb2_set_next_command() argument
2447 struct cifs_ses *ses = tcon->ses; in smb2_set_next_command()
2448 struct TCP_Server_Info *server = ses->server; in smb2_set_next_command()
2452 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base); in smb2_set_next_command()
2464 num_padding = 8 - (len & 7); in smb2_set_next_command()
2465 if (!smb3_encryption_required(tcon)) { in smb2_set_next_command()
2470 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding; in smb2_set_next_command()
2471 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding; in smb2_set_next_command()
2472 rqst->rq_nvec++; in smb2_set_next_command()
2482 for (i = 1; i < rqst->rq_nvec; i++) { in smb2_set_next_command()
2483 memcpy(rqst->rq_iov[0].iov_base + in smb2_set_next_command()
2484 rqst->rq_iov[0].iov_len, in smb2_set_next_command()
2485 rqst->rq_iov[i].iov_base, in smb2_set_next_command()
2486 rqst->rq_iov[i].iov_len); in smb2_set_next_command()
2487 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len; in smb2_set_next_command()
2489 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len, in smb2_set_next_command()
2491 rqst->rq_iov[0].iov_len += num_padding; in smb2_set_next_command()
2493 rqst->rq_nvec = 1; in smb2_set_next_command()
2497 shdr->NextCommand = cpu_to_le32(len); in smb2_set_next_command()
2505 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_info_compound() argument
2511 struct cifs_ses *ses = tcon->ses; in smb2_query_info_compound()
2525 if (smb3_encryption_required(tcon)) in smb2_query_info_compound()
2536 oparms.tcon = tcon; in smb2_query_info_compound()
2543 rc = SMB2_open_init(tcon, server, in smb2_query_info_compound()
2547 smb2_set_next_command(tcon, &rqst[0]); in smb2_query_info_compound()
2553 rc = SMB2_query_info_init(tcon, server, in smb2_query_info_compound()
2560 smb2_set_next_command(tcon, &rqst[1]); in smb2_query_info_compound()
2567 rc = SMB2_close_init(tcon, server, in smb2_query_info_compound()
2578 if (rc == -EREMCHG) { in smb2_query_info_compound()
2579 tcon->need_reconnect = true; in smb2_query_info_compound()
2581 tcon->treeName); in smb2_query_info_compound()
2598 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, in smb2_queryfs() argument
2603 __le16 utf16_path = 0; /* Null - open root of share */ in smb2_queryfs()
2609 rc = smb2_query_info_compound(xid, tcon, &utf16_path, in smb2_queryfs()
2619 buf->f_type = SMB2_MAGIC_NUMBER; in smb2_queryfs()
2621 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in smb2_queryfs()
2622 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in smb2_queryfs()
2623 le32_to_cpu(rsp->OutputBufferLength), in smb2_queryfs()
2635 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon, in smb311_queryfs() argument
2639 __le16 srch_path = 0; /* Null - open root of share */ in smb311_queryfs()
2644 if (!tcon->posix_extensions) in smb311_queryfs()
2645 return smb2_queryfs(xid, tcon, cifs_sb, buf); in smb311_queryfs()
2647 oparms.tcon = tcon; in smb311_queryfs()
2659 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid, in smb311_queryfs()
2661 buf->f_type = SMB2_MAGIC_NUMBER; in smb311_queryfs()
2662 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb311_queryfs()
2669 return ob1->fid.persistent_fid == ob2->fid.persistent_fid && in smb2_compare_fids()
2670 ob1->fid.volatile_fid == ob2->fid.volatile_fid; in smb2_compare_fids()
2679 return SMB2_lock(xid, tlink_tcon(cfile->tlink), in smb2_mand_lock()
2680 cfile->fid.persistent_fid, cfile->fid.volatile_fid, in smb2_mand_lock()
2681 current->tgid, length, offset, type, wait); in smb2_mand_lock()
2687 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); in smb2_get_lease_key()
2693 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); in smb2_set_lease_key()
2699 generate_random_uuid(fid->lease_key); in smb2_new_lease_key()
2712 struct cifs_tcon *tcon; in smb2_get_dfs_refer() local
2720 * Try to use the IPC tcon, otherwise just use any in smb2_get_dfs_refer()
2722 tcon = ses->tcon_ipc; in smb2_get_dfs_refer()
2723 if (tcon == NULL) { in smb2_get_dfs_refer()
2725 tcon = list_first_entry_or_null(&ses->tcon_list, in smb2_get_dfs_refer()
2728 if (tcon) in smb2_get_dfs_refer()
2729 tcon->tc_count++; in smb2_get_dfs_refer()
2733 if (tcon == NULL) { in smb2_get_dfs_refer()
2734 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n", in smb2_get_dfs_refer()
2736 rc = -ENOTCONN; in smb2_get_dfs_refer()
2744 rc = -ENOMEM; in smb2_get_dfs_refer()
2751 rc = -ENOMEM; in smb2_get_dfs_refer()
2756 dfs_req->MaxReferralLevel = DFS_VERSION; in smb2_get_dfs_refer()
2758 /* Path to resolve in an UTF-16 null-terminated string */ in smb2_get_dfs_refer()
2759 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len); in smb2_get_dfs_refer()
2762 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, in smb2_get_dfs_refer()
2766 } while (rc == -EAGAIN); in smb2_get_dfs_refer()
2769 rc = -EIO; in smb2_get_dfs_refer()
2771 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP)) in smb2_get_dfs_refer()
2786 if (tcon && !tcon->ipc) { in smb2_get_dfs_refer()
2789 tcon->tc_count--; in smb2_get_dfs_refer()
2805 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */ in parse_reparse_posix()
2806 len = le16_to_cpu(symlink_buf->ReparseDataLength); in parse_reparse_posix()
2808 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) { in parse_reparse_posix()
2810 le64_to_cpu(symlink_buf->InodeType)); in parse_reparse_posix()
2811 return -EOPNOTSUPP; in parse_reparse_posix()
2815 symlink_buf->PathBuffer, in parse_reparse_posix()
2816 len, true, cifs_sb->local_nls); in parse_reparse_posix()
2818 return -ENOMEM; in parse_reparse_posix()
2834 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */ in parse_reparse_symlink()
2836 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset); in parse_reparse_symlink()
2837 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength); in parse_reparse_symlink()
2841 return -EIO; in parse_reparse_symlink()
2845 symlink_buf->PathBuffer + sub_offset, in parse_reparse_symlink()
2846 sub_len, true, cifs_sb->local_nls); in parse_reparse_symlink()
2848 return -ENOMEM; in parse_reparse_symlink()
2864 return -EIO; in parse_reparse_point()
2867 if (plen < le16_to_cpu(buf->ReparseDataLength) + in parse_reparse_point()
2871 return -EIO; in parse_reparse_point()
2874 /* See MS-FSCC 2.1.2 */ in parse_reparse_point()
2875 switch (le32_to_cpu(buf->ReparseTag)) { in parse_reparse_point()
2886 le32_to_cpu(buf->ReparseTag)); in parse_reparse_point()
2887 return -EOPNOTSUPP; in parse_reparse_point()
2892 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2895 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_symlink() argument
2907 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); in smb2_query_symlink()
2929 if (smb3_encryption_required(tcon)) in smb2_query_symlink()
2938 return -ENOMEM; in smb2_query_symlink()
2946 oparms.tcon = tcon; in smb2_query_symlink()
2953 rc = SMB2_open_init(tcon, server, in smb2_query_symlink()
2957 smb2_set_next_command(tcon, &rqst[0]); in smb2_query_symlink()
2965 rc = SMB2_ioctl_init(tcon, server, in smb2_query_symlink()
2968 CIFSMaxBufSize - in smb2_query_symlink()
2969 MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_query_symlink()
2974 smb2_set_next_command(tcon, &rqst[1]); in smb2_query_symlink()
2983 rc = SMB2_close_init(tcon, server, in smb2_query_symlink()
2990 rc = compound_send_recv(xid, tcon->ses, server, in smb2_query_symlink()
2995 if (create_rsp && create_rsp->sync_hdr.Status) in smb2_query_symlink()
3003 /* See MS-FSCC 2.3.23 */ in smb2_query_symlink()
3007 le32_to_cpu(ioctl_rsp->OutputOffset)); in smb2_query_symlink()
3008 plen = le32_to_cpu(ioctl_rsp->OutputCount); in smb2_query_symlink()
3010 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) > in smb2_query_symlink()
3014 rc = -EIO; in smb2_query_symlink()
3024 rc = -ENOENT; in smb2_query_symlink()
3029 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) || in smb2_query_symlink()
3031 rc = -EINVAL; in smb2_query_symlink()
3035 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData; in smb2_query_symlink()
3036 if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG || in smb2_query_symlink()
3037 le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) { in smb2_query_symlink()
3038 rc = -EINVAL; in smb2_query_symlink()
3042 /* open must fail on symlink - reset rc */ in smb2_query_symlink()
3044 sub_len = le16_to_cpu(symlink->SubstituteNameLength); in smb2_query_symlink()
3045 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset); in smb2_query_symlink()
3046 print_len = le16_to_cpu(symlink->PrintNameLength); in smb2_query_symlink()
3047 print_offset = le16_to_cpu(symlink->PrintNameOffset); in smb2_query_symlink()
3050 rc = -EINVAL; in smb2_query_symlink()
3056 rc = -EINVAL; in smb2_query_symlink()
3061 (char *)symlink->PathBuffer + sub_offset, in smb2_query_symlink()
3062 sub_len, true, cifs_sb->local_nls); in smb2_query_symlink()
3064 rc = -ENOMEM; in smb2_query_symlink()
3083 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_reparse_tag() argument
3092 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses); in smb2_query_reparse_tag()
3106 if (smb3_encryption_required(tcon)) in smb2_query_reparse_tag()
3115 return -ENOMEM; in smb2_query_reparse_tag()
3118 * setup smb2open - TODO add optimization to call cifs_get_readable_path in smb2_query_reparse_tag()
3126 oparms.tcon = tcon; in smb2_query_reparse_tag()
3133 rc = SMB2_open_init(tcon, server, in smb2_query_reparse_tag()
3137 smb2_set_next_command(tcon, &rqst[0]); in smb2_query_reparse_tag()
3145 rc = SMB2_ioctl_init(tcon, server, in smb2_query_reparse_tag()
3148 CIFSMaxBufSize - in smb2_query_reparse_tag()
3149 MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_query_reparse_tag()
3154 smb2_set_next_command(tcon, &rqst[1]); in smb2_query_reparse_tag()
3163 rc = SMB2_close_init(tcon, server, in smb2_query_reparse_tag()
3170 rc = compound_send_recv(xid, tcon->ses, server, in smb2_query_reparse_tag()
3180 /* See MS-FSCC 2.3.23 */ in smb2_query_reparse_tag()
3181 off = le32_to_cpu(ioctl_rsp->OutputOffset); in smb2_query_reparse_tag()
3182 count = le32_to_cpu(ioctl_rsp->OutputCount); in smb2_query_reparse_tag()
3187 rc = -EIO; in smb2_query_reparse_tag()
3194 count < le16_to_cpu(reparse_buf->ReparseDataLength) + len) { in smb2_query_reparse_tag()
3197 rc = -EIO; in smb2_query_reparse_tag()
3200 *tag = le32_to_cpu(reparse_buf->ReparseTag); in smb2_query_reparse_tag()
3220 int rc = -EOPNOTSUPP; in get_smb2_acl_by_fid()
3229 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid, in get_smb2_acl_by_fid()
3230 cifsfid->volatile_fid, (void **)&pntsd, pacllen); in get_smb2_acl_by_fid()
3250 struct cifs_tcon *tcon; in get_smb2_acl_by_path() local
3260 tcon = tlink_tcon(tlink); in get_smb2_acl_by_path()
3265 rc = -ENOMEM; in get_smb2_acl_by_path()
3270 oparms.tcon = tcon; in get_smb2_acl_by_path()
3288 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in get_smb2_acl_by_path()
3307 struct cifs_tcon *tcon; in set_smb2_acl() local
3308 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in set_smb2_acl()
3318 tcon = tlink_tcon(tlink); in set_smb2_acl()
3328 rc = -ENOMEM; in set_smb2_acl()
3333 oparms.tcon = tcon; in set_smb2_acl()
3347 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in set_smb2_acl()
3369 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen); in get_smb2_acl()
3374 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, in smb3_zero_range() argument
3377 struct cifs_ses *ses = tcon->ses; in smb3_zero_range()
3380 struct cifsFileInfo *cfile = file->private_data; in smb3_zero_range()
3388 inode = d_inode(cfile->dentry); in smb3_zero_range()
3391 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_zero_range()
3392 ses->Suid, offset, len); in smb3_zero_range()
3398 truncate_pagecache_range(inode, offset, offset + len - 1); in smb3_zero_range()
3403 rc = -EOPNOTSUPP; in smb3_zero_range()
3404 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, in smb3_zero_range()
3405 tcon->tid, ses->Suid, offset, len, rc); in smb3_zero_range()
3415 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_zero_range()
3416 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, in smb3_zero_range()
3428 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb3_zero_range()
3429 cfile->fid.volatile_fid, cfile->pid, &eof); in smb3_zero_range()
3435 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_zero_range()
3436 ses->Suid, offset, len, rc); in smb3_zero_range()
3438 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_zero_range()
3439 ses->Suid, offset, len); in smb3_zero_range()
3443 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, in smb3_punch_hole() argument
3447 struct cifsFileInfo *cfile = file->private_data; in smb3_punch_hole()
3458 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) { in smb3_punch_hole()
3459 rc = -EOPNOTSUPP; in smb3_punch_hole()
3467 truncate_pagecache_range(inode, offset, offset + len - 1); in smb3_punch_hole()
3474 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_punch_hole()
3475 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, in smb3_punch_hole()
3486 struct cifs_tcon *tcon, in smb3_simple_fallocate_write_range() argument
3496 io_parms.netfid = cfile->fid.netfid; in smb3_simple_fallocate_write_range()
3497 io_parms.pid = current->tgid; in smb3_simple_fallocate_write_range()
3498 io_parms.tcon = tcon; in smb3_simple_fallocate_write_range()
3499 io_parms.persistent_fid = cfile->fid.persistent_fid; in smb3_simple_fallocate_write_range()
3500 io_parms.volatile_fid = cfile->fid.volatile_fid; in smb3_simple_fallocate_write_range()
3514 return -EINVAL; in smb3_simple_fallocate_write_range()
3517 len -= nbytes; in smb3_simple_fallocate_write_range()
3523 struct cifs_tcon *tcon, in smb3_simple_fallocate_range() argument
3535 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_simple_fallocate_range()
3536 cfile->fid.volatile_fid, in smb3_simple_fallocate_range()
3546 rc = -ENOMEM; in smb3_simple_fallocate_range()
3556 rc = smb3_simple_fallocate_write_range(xid, tcon, in smb3_simple_fallocate_range()
3562 rc = -EINVAL; in smb3_simple_fallocate_range()
3566 if (off < le64_to_cpu(tmp_data->file_offset)) { in smb3_simple_fallocate_range()
3572 l = le64_to_cpu(tmp_data->file_offset) - off; in smb3_simple_fallocate_range()
3575 rc = smb3_simple_fallocate_write_range(xid, tcon, in smb3_simple_fallocate_range()
3580 len = len - l; in smb3_simple_fallocate_range()
3589 l = le64_to_cpu(tmp_data->length); in smb3_simple_fallocate_range()
3593 len -= l; in smb3_simple_fallocate_range()
3596 out_data_len -= sizeof(struct file_allocated_range_buffer); in smb3_simple_fallocate_range()
3606 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, in smb3_simple_falloc() argument
3611 struct cifsFileInfo *cfile = file->private_data; in smb3_simple_falloc()
3612 long rc = -EOPNOTSUPP; in smb3_simple_falloc()
3618 inode = d_inode(cfile->dentry); in smb3_simple_falloc()
3621 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_simple_falloc()
3622 tcon->ses->Suid, off, len); in smb3_simple_falloc()
3626 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, in smb3_simple_falloc()
3627 tcon->tid, tcon->ses->Suid, off, len, rc); in smb3_simple_falloc()
3640 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) in smb3_simple_falloc()
3641 smb2_set_sparse(xid, tcon, cfile, inode, false); in smb3_simple_falloc()
3644 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb3_simple_falloc()
3645 cfile->fid.volatile_fid, cfile->pid, &eof); in smb3_simple_falloc()
3647 cifsi->server_eof = off + len; in smb3_simple_falloc()
3649 cifs_truncate_page(inode->i_mapping, inode->i_size); in smb3_simple_falloc()
3656 * Files are non-sparse by default so falloc may be a no-op in smb3_simple_falloc()
3660 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { in smb3_simple_falloc()
3679 len = i_size_read(inode) - off; in smb3_simple_falloc()
3688 * We can either turn the entire file to become non-sparse in smb3_simple_falloc()
3699 rc = smb3_simple_fallocate_range(xid, tcon, cfile, in smb3_simple_falloc()
3710 * or end of the file non-sparse via set_sparse is harmless. in smb3_simple_falloc()
3713 rc = -EOPNOTSUPP; in smb3_simple_falloc()
3718 smb2_set_sparse(xid, tcon, cfile, inode, false); in smb3_simple_falloc()
3723 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_simple_falloc()
3724 tcon->ses->Suid, off, len, rc); in smb3_simple_falloc()
3726 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_simple_falloc()
3727 tcon->ses->Suid, off, len); in smb3_simple_falloc()
3733 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence) in smb3_llseek() argument
3735 struct cifsFileInfo *wrcfile, *cfile = file->private_data; in smb3_llseek()
3746 inode = d_inode(cfile->dentry); in smb3_llseek()
3750 return -ENXIO; in smb3_llseek()
3762 filemap_write_and_wait(inode->i_mapping); in smb3_llseek()
3763 smb2_flush_file(xid, tcon, &wrcfile->fid); in smb3_llseek()
3767 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) { in smb3_llseek()
3776 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_llseek()
3777 cfile->fid.volatile_fid, in smb3_llseek()
3782 if (rc == -E2BIG) in smb3_llseek()
3791 rc = -ENXIO; in smb3_llseek()
3796 rc = -EINVAL; in smb3_llseek()
3800 offset = le64_to_cpu(out_data->file_offset); in smb3_llseek()
3803 if (offset < le64_to_cpu(out_data->file_offset)) in smb3_llseek()
3806 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length); in smb3_llseek()
3812 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes); in smb3_llseek()
3817 static int smb3_fiemap(struct cifs_tcon *tcon, in smb3_fiemap() argument
3827 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0); in smb3_fiemap()
3836 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_fiemap()
3837 cfile->fid.volatile_fid, in smb3_fiemap()
3842 if (rc == -E2BIG) { in smb3_fiemap()
3851 rc = -EINVAL; in smb3_fiemap()
3855 rc = -EINVAL; in smb3_fiemap()
3862 if (i == num - 1 && last_blob) in smb3_fiemap()
3879 next = le64_to_cpu(out_data[num - 1].file_offset) + in smb3_fiemap()
3880 le64_to_cpu(out_data[num - 1].length); in smb3_fiemap()
3881 len = len - (next - start); in smb3_fiemap()
3892 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, in smb3_fallocate() argument
3897 return smb3_punch_hole(file, tcon, off, len); in smb3_fallocate()
3900 return smb3_zero_range(file, tcon, off, len, true); in smb3_fallocate()
3901 return smb3_zero_range(file, tcon, off, len, false); in smb3_fallocate()
3903 return smb3_simple_falloc(file, tcon, off, len, true); in smb3_fallocate()
3905 return smb3_simple_falloc(file, tcon, off, len, false); in smb3_fallocate()
3907 return -EOPNOTSUPP; in smb3_fallocate()
3915 server->ops->set_oplock_level(cinode, oplock, 0, NULL); in smb2_downgrade_oplock()
3927 unsigned int old_state = cinode->oplock; in smb3_downgrade_oplock()
3928 unsigned int old_epoch = cinode->epoch; in smb3_downgrade_oplock()
3933 cinode->epoch = epoch; in smb3_downgrade_oplock()
3936 new_state = cinode->oplock; in smb3_downgrade_oplock()
3942 else if (old_state == new_state && (epoch - old_epoch > 1)) in smb3_downgrade_oplock()
3954 cinode->oplock = CIFS_CACHE_RHW_FLG; in smb2_set_oplock_level()
3956 &cinode->vfs_inode); in smb2_set_oplock_level()
3958 cinode->oplock = CIFS_CACHE_RW_FLG; in smb2_set_oplock_level()
3960 &cinode->vfs_inode); in smb2_set_oplock_level()
3962 cinode->oplock = CIFS_CACHE_READ_FLG; in smb2_set_oplock_level()
3964 &cinode->vfs_inode); in smb2_set_oplock_level()
3966 cinode->oplock = 0; in smb2_set_oplock_level()
4000 cinode->oplock = new_oplock; in smb21_set_oplock_level()
4002 &cinode->vfs_inode); in smb21_set_oplock_level()
4009 unsigned int old_oplock = cinode->oplock; in smb3_set_oplock_level()
4016 if (cinode->oplock == CIFS_CACHE_READ_FLG && in smb3_set_oplock_level()
4017 (epoch - cinode->epoch > 0)) in smb3_set_oplock_level()
4019 else if (cinode->oplock == CIFS_CACHE_RH_FLG && in smb3_set_oplock_level()
4020 (epoch - cinode->epoch > 1)) in smb3_set_oplock_level()
4022 else if (cinode->oplock == CIFS_CACHE_RHW_FLG && in smb3_set_oplock_level()
4023 (epoch - cinode->epoch > 1)) in smb3_set_oplock_level()
4025 else if (cinode->oplock == 0 && in smb3_set_oplock_level()
4026 (epoch - cinode->epoch > 0)) in smb3_set_oplock_level()
4029 if (cinode->oplock == CIFS_CACHE_RH_FLG && in smb3_set_oplock_level()
4030 (epoch - cinode->epoch > 0)) in smb3_set_oplock_level()
4032 else if (cinode->oplock == CIFS_CACHE_RHW_FLG && in smb3_set_oplock_level()
4033 (epoch - cinode->epoch > 1)) in smb3_set_oplock_level()
4036 cinode->epoch = epoch; in smb3_set_oplock_level()
4077 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE); in smb2_create_lease_buf()
4078 buf->lcontext.LeaseState = map_oplock_to_lease(oplock); in smb2_create_lease_buf()
4080 buf->ccontext.DataOffset = cpu_to_le16(offsetof in smb2_create_lease_buf()
4082 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); in smb2_create_lease_buf()
4083 buf->ccontext.NameOffset = cpu_to_le16(offsetof in smb2_create_lease_buf()
4085 buf->ccontext.NameLength = cpu_to_le16(4); in smb2_create_lease_buf()
4087 buf->Name[0] = 'R'; in smb2_create_lease_buf()
4088 buf->Name[1] = 'q'; in smb2_create_lease_buf()
4089 buf->Name[2] = 'L'; in smb2_create_lease_buf()
4090 buf->Name[3] = 's'; in smb2_create_lease_buf()
4103 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE); in smb3_create_lease_buf()
4104 buf->lcontext.LeaseState = map_oplock_to_lease(oplock); in smb3_create_lease_buf()
4106 buf->ccontext.DataOffset = cpu_to_le16(offsetof in smb3_create_lease_buf()
4108 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); in smb3_create_lease_buf()
4109 buf->ccontext.NameOffset = cpu_to_le16(offsetof in smb3_create_lease_buf()
4111 buf->ccontext.NameLength = cpu_to_le16(4); in smb3_create_lease_buf()
4113 buf->Name[0] = 'R'; in smb3_create_lease_buf()
4114 buf->Name[1] = 'q'; in smb3_create_lease_buf()
4115 buf->Name[2] = 'L'; in smb3_create_lease_buf()
4116 buf->Name[3] = 's'; in smb3_create_lease_buf()
4126 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) in smb2_parse_lease_buf()
4128 return le32_to_cpu(lc->lcontext.LeaseState); in smb2_parse_lease_buf()
4136 *epoch = le16_to_cpu(lc->lcontext.Epoch); in smb3_parse_lease_buf()
4137 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) in smb3_parse_lease_buf()
4140 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE); in smb3_parse_lease_buf()
4141 return le32_to_cpu(lc->lcontext.LeaseState); in smb3_parse_lease_buf()
4147 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize, in smb2_wp_retry_size()
4154 return !cfile->invalidHandle; in smb2_dir_needs_close()
4162 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base; in fill_transform_hdr()
4165 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; in fill_transform_hdr()
4166 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len); in fill_transform_hdr()
4167 tr_hdr->Flags = cpu_to_le16(0x01); in fill_transform_hdr()
4170 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE); in fill_transform_hdr()
4172 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE); in fill_transform_hdr()
4173 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8); in fill_transform_hdr()
4189 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1); in smb2_aead_req_alloc()
4240 addr = (unsigned long)iov->iov_base + skip; in smb2_get_aead_req()
4241 len = iov->iov_len - skip; in smb2_get_aead_req()
4262 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { in smb2_get_enc_key()
4263 if (ses->Suid == ses_id) { in smb2_get_enc_key()
4264 ses_enc_key = enc ? ses->smb3encryptionkey : in smb2_get_enc_key()
4265 ses->smb3decryptionkey; in smb2_get_enc_key()
4274 return -EAGAIN; in smb2_get_enc_key()
4278 * iov[0] - transform header (associate data),
4279 * iov[1-N] - SMB2 header and pages - data to encrypt.
4280 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4289 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20; in crypt_message()
4298 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize); in crypt_message()
4301 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key); in crypt_message()
4314 tfm = enc ? server->secmech.ccmaesencrypt : in crypt_message()
4315 server->secmech.ccmaesdecrypt; in crypt_message()
4317 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) || in crypt_message()
4318 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) in crypt_message()
4336 return -ENOMEM; in crypt_message()
4339 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE); in crypt_message()
4343 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) || in crypt_message()
4344 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) in crypt_message()
4345 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE); in crypt_message()
4348 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE); in crypt_message()
4362 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE); in crypt_message()
4375 for (j = rqst[i].rq_npages - 1; j >= 0; j--) in smb3_free_compound_rqst()
4385 * a smb2_transform_hdr and is pre-allocated by the caller.
4392 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4404 int rc = -ENOMEM; in smb3_init_transform_rq()
4407 npages = old_rq[i - 1].rq_npages; in smb3_init_transform_rq()
4415 new_rq[i].rq_offset = old_rq[i - 1].rq_offset; in smb3_init_transform_rq()
4416 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz; in smb3_init_transform_rq()
4417 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz; in smb3_init_transform_rq()
4418 new_rq[i].rq_iov = old_rq[i - 1].rq_iov; in smb3_init_transform_rq()
4419 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec; in smb3_init_transform_rq()
4421 orig_len += smb_rqst_len(server, &old_rq[i - 1]); in smb3_init_transform_rq()
4437 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset; in smb3_init_transform_rq()
4441 kunmap(old_rq[i - 1].rq_pages[j]); in smb3_init_transform_rq()
4446 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type); in smb3_init_transform_rq()
4456 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]); in smb3_init_transform_rq()
4465 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM; in smb3_is_transform_hdr()
4499 server->total_read = buf_data_size + page_data_size; in decrypt_raw_data()
4519 len -= n; in read_data_into_pages()
4521 zero_user(page, len, PAGE_SIZE - len); in read_data_into_pages()
4527 server->total_read += length; in read_data_into_pages()
4542 return -ENOMEM; in init_read_bvec()
4548 data_size -= bvec[i].bv_len; in init_read_bvec()
4554 return -EIO; in init_read_bvec()
4572 struct cifs_readdata *rdata = mid->callback_data; in handle_read_data()
4580 if (shdr->Command != SMB2_READ) { in handle_read_data()
4582 return -ENOTSUPP; in handle_read_data()
4585 if (server->ops->is_session_expired && in handle_read_data()
4586 server->ops->is_session_expired(buf)) { in handle_read_data()
4589 return -1; in handle_read_data()
4592 if (server->ops->is_status_pending && in handle_read_data()
4593 server->ops->is_status_pending(buf, server)) in handle_read_data()
4594 return -1; in handle_read_data()
4597 rdata->iov[0].iov_base = buf; in handle_read_data()
4598 rdata->iov[0].iov_len = 0; in handle_read_data()
4599 rdata->iov[1].iov_base = buf; in handle_read_data()
4600 rdata->iov[1].iov_len = in handle_read_data()
4601 min_t(unsigned int, buf_len, server->vals->read_rsp_size); in handle_read_data()
4603 rdata->iov[0].iov_base, rdata->iov[0].iov_len); in handle_read_data()
4605 rdata->iov[1].iov_base, rdata->iov[1].iov_len); in handle_read_data()
4607 rdata->result = server->ops->map_error(buf, true); in handle_read_data()
4608 if (rdata->result != 0) { in handle_read_data()
4610 __func__, rdata->result); in handle_read_data()
4613 mid->mid_state = MID_RESPONSE_RECEIVED; in handle_read_data()
4619 data_offset = server->ops->read_data_offset(buf); in handle_read_data()
4621 use_rdma_mr = rdata->mr; in handle_read_data()
4623 data_len = server->ops->read_data_length(buf, use_rdma_mr); in handle_read_data()
4625 if (data_offset < server->vals->read_rsp_size) { in handle_read_data()
4633 data_offset = server->vals->read_rsp_size; in handle_read_data()
4638 rdata->result = -EIO; in handle_read_data()
4640 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4642 dequeue_mid(mid, rdata->result); in handle_read_data()
4646 pad_len = data_offset - server->vals->read_rsp_size; in handle_read_data()
4657 rdata->result = -EIO; in handle_read_data()
4659 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4661 dequeue_mid(mid, rdata->result); in handle_read_data()
4665 if (data_len > page_data_size - pad_len) { in handle_read_data()
4666 /* data_len is corrupt -- discard frame */ in handle_read_data()
4667 rdata->result = -EIO; in handle_read_data()
4669 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4671 dequeue_mid(mid, rdata->result); in handle_read_data()
4675 rdata->result = init_read_bvec(pages, npages, page_data_size, in handle_read_data()
4677 if (rdata->result != 0) { in handle_read_data()
4679 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4681 dequeue_mid(mid, rdata->result); in handle_read_data()
4695 rdata->result = -EIO; in handle_read_data()
4697 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4699 dequeue_mid(mid, rdata->result); in handle_read_data()
4703 length = rdata->copy_into_pages(server, rdata, &iter); in handle_read_data()
4711 mid->mid_state = MID_RESPONSE_RECEIVED; in handle_read_data()
4734 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size, in smb2_decrypt_offload()
4735 dw->ppages, dw->npages, dw->len, true); in smb2_decrypt_offload()
4741 dw->server->lstrp = jiffies; in smb2_decrypt_offload()
4742 mid = smb2_find_dequeue_mid(dw->server, dw->buf); in smb2_decrypt_offload()
4746 mid->decrypted = true; in smb2_decrypt_offload()
4747 rc = handle_read_data(dw->server, mid, dw->buf, in smb2_decrypt_offload()
4748 dw->server->vals->read_rsp_size, in smb2_decrypt_offload()
4749 dw->ppages, dw->npages, dw->len, in smb2_decrypt_offload()
4753 mid->when_received = jiffies; in smb2_decrypt_offload()
4755 mid->callback(mid); in smb2_decrypt_offload()
4758 if (dw->server->tcpStatus == CifsNeedReconnect) { in smb2_decrypt_offload()
4759 mid->mid_state = MID_RETRY_NEEDED; in smb2_decrypt_offload()
4761 mid->callback(mid); in smb2_decrypt_offload()
4763 mid->mid_state = MID_REQUEST_SUBMITTED; in smb2_decrypt_offload()
4764 mid->mid_flags &= ~(MID_DELETED); in smb2_decrypt_offload()
4765 list_add_tail(&mid->qhead, in smb2_decrypt_offload()
4766 &dw->server->pending_mid_q); in smb2_decrypt_offload()
4774 for (i = dw->npages-1; i >= 0; i--) in smb2_decrypt_offload()
4775 put_page(dw->ppages[i]); in smb2_decrypt_offload()
4777 kfree(dw->ppages); in smb2_decrypt_offload()
4778 cifs_small_buf_release(dw->buf); in smb2_decrypt_offload()
4787 char *buf = server->smallbuf; in receive_encrypted_read()
4792 unsigned int buflen = server->pdu_size; in receive_encrypted_read()
4798 len = min_t(unsigned int, buflen, server->vals->read_rsp_size + in receive_encrypted_read()
4799 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1; in receive_encrypted_read()
4801 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len); in receive_encrypted_read()
4804 server->total_read += rc; in receive_encrypted_read()
4806 len = le32_to_cpu(tr_hdr->OriginalMessageSize) - in receive_encrypted_read()
4807 server->vals->read_rsp_size; in receive_encrypted_read()
4812 rc = -ENOMEM; in receive_encrypted_read()
4819 rc = -ENOMEM; in receive_encrypted_read()
4838 if ((server->min_offload) && (server->in_flight > 1) && in receive_encrypted_read()
4839 (server->pdu_size >= server->min_offload)) { in receive_encrypted_read()
4844 dw->buf = server->smallbuf; in receive_encrypted_read()
4845 server->smallbuf = (char *)cifs_small_buf_get(); in receive_encrypted_read()
4847 INIT_WORK(&dw->decrypt, smb2_decrypt_offload); in receive_encrypted_read()
4849 dw->npages = npages; in receive_encrypted_read()
4850 dw->server = server; in receive_encrypted_read()
4851 dw->ppages = pages; in receive_encrypted_read()
4852 dw->len = len; in receive_encrypted_read()
4853 queue_work(decrypt_wq, &dw->decrypt); in receive_encrypted_read()
4855 return -1; in receive_encrypted_read()
4859 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size, in receive_encrypted_read()
4869 (*mid)->decrypted = true; in receive_encrypted_read()
4871 server->vals->read_rsp_size, in receive_encrypted_read()
4876 for (i = i - 1; i >= 0; i--) in receive_encrypted_read()
4891 char *buf = server->smallbuf; in receive_encrypted_standard()
4893 unsigned int pdu_length = server->pdu_size; in receive_encrypted_standard()
4903 server->large_buf = true; in receive_encrypted_standard()
4904 memcpy(server->bigbuf, buf, server->total_read); in receive_encrypted_standard()
4905 buf = server->bigbuf; in receive_encrypted_standard()
4909 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, in receive_encrypted_standard()
4910 pdu_length - HEADER_SIZE(server) + 1); in receive_encrypted_standard()
4913 server->total_read += length; in receive_encrypted_standard()
4915 buf_size = pdu_length - sizeof(struct smb2_transform_hdr); in receive_encrypted_standard()
4920 next_is_large = server->large_buf; in receive_encrypted_standard()
4923 if (shdr->NextCommand) { in receive_encrypted_standard()
4929 buf + le32_to_cpu(shdr->NextCommand), in receive_encrypted_standard()
4930 pdu_length - le32_to_cpu(shdr->NextCommand)); in receive_encrypted_standard()
4938 mid_entry->decrypted = true; in receive_encrypted_standard()
4939 mid_entry->resp_buf_size = server->pdu_size; in receive_encrypted_standard()
4944 return -1; in receive_encrypted_standard()
4949 if (mid_entry && mid_entry->handle) in receive_encrypted_standard()
4950 ret = mid_entry->handle(server, mid_entry); in receive_encrypted_standard()
4954 if (ret == 0 && shdr->NextCommand) { in receive_encrypted_standard()
4955 pdu_length -= le32_to_cpu(shdr->NextCommand); in receive_encrypted_standard()
4956 server->large_buf = next_is_large; in receive_encrypted_standard()
4958 server->bigbuf = buf = next_buffer; in receive_encrypted_standard()
4960 server->smallbuf = buf = next_buffer; in receive_encrypted_standard()
4965 * server->smallbuf and server->bigbuf are still valid. We need in receive_encrypted_standard()
4982 char *buf = server->smallbuf; in smb3_receive_transform()
4983 unsigned int pdu_length = server->pdu_size; in smb3_receive_transform()
4985 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize); in smb3_receive_transform()
4992 return -ECONNABORTED; in smb3_receive_transform()
4998 return -ECONNABORTED; in smb3_receive_transform()
5012 char *buf = server->large_buf ? server->bigbuf : server->smallbuf; in smb3_handle_read_data()
5014 return handle_read_data(server, mid, buf, server->pdu_size, in smb3_handle_read_data()
5024 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) in smb2_next_header()
5026 le32_to_cpu(t_hdr->OriginalMessageSize); in smb2_next_header()
5028 return le32_to_cpu(hdr->NextCommand); in smb2_next_header()
5033 struct dentry *dentry, struct cifs_tcon *tcon, in smb2_make_node() argument
5036 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in smb2_make_node()
5037 int rc = -EPERM; in smb2_make_node()
5053 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)) in smb2_make_node()
5069 rc = -ENOMEM; in smb2_make_node()
5073 oparms.tcon = tcon; in smb2_make_node()
5083 if (tcon->ses->server->oplocks) in smb2_make_node()
5087 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf); in smb2_make_node()
5097 io_parms.pid = current->tgid; in smb2_make_node()
5098 io_parms.tcon = tcon; in smb2_make_node()
5104 memcpy(pdev->type, "IntxCHR", 8); in smb2_make_node()
5105 pdev->major = cpu_to_le64(MAJOR(dev)); in smb2_make_node()
5106 pdev->minor = cpu_to_le64(MINOR(dev)); in smb2_make_node()
5107 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms, in smb2_make_node()
5110 memcpy(pdev->type, "IntxBLK", 8); in smb2_make_node()
5111 pdev->major = cpu_to_le64(MAJOR(dev)); in smb2_make_node()
5112 pdev->minor = cpu_to_le64(MINOR(dev)); in smb2_make_node()
5113 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms, in smb2_make_node()
5116 tcon->ses->server->ops->close(xid, tcon, &fid); in smb2_make_node()