Lines Matching +full:tcon +full:- +full:channel

1 // SPDX-License-Identifier: GPL-2.0
38 server->credits += server->echo_credits + server->oplock_credits; in change_conf()
39 if (server->credits > server->max_credits) in change_conf()
40 server->credits = server->max_credits; in change_conf()
41 server->oplock_credits = server->echo_credits = 0; in change_conf()
42 switch (server->credits) { in change_conf()
46 server->echoes = false; in change_conf()
47 server->oplocks = false; in change_conf()
50 server->echoes = true; in change_conf()
51 server->oplocks = false; in change_conf()
52 server->echo_credits = 1; in change_conf()
55 server->echoes = true; in change_conf()
57 server->oplocks = true; in change_conf()
58 server->oplock_credits = 1; in change_conf()
60 server->oplocks = false; in change_conf()
62 server->echo_credits = 1; in change_conf()
64 server->credits -= server->echo_credits + server->oplock_credits; in change_conf()
65 return server->credits + server->echo_credits + server->oplock_credits; in change_conf()
72 int *val, rc = -1; in smb2_add_credits()
74 unsigned int add = credits->value; in smb2_add_credits()
75 unsigned int instance = credits->instance; in smb2_add_credits()
79 spin_lock(&server->req_lock); in smb2_add_credits()
80 val = server->ops->get_credits_field(server, optype); in smb2_add_credits()
86 if ((instance == 0) || (instance == server->reconnect_instance)) in smb2_add_credits()
94 trace_smb3_overflow_credits(server->CurrentMid, in smb2_add_credits()
95 server->conn_id, server->hostname, *val, in smb2_add_credits()
96 add, server->in_flight); in smb2_add_credits()
98 if (credits->in_flight_check > 1) { in smb2_add_credits()
100 credits->rreq_debug_id, credits->rreq_debug_index); in smb2_add_credits()
102 credits->in_flight_check = 2; in smb2_add_credits()
104 if (WARN_ON_ONCE(server->in_flight == 0)) { in smb2_add_credits()
106 credits->rreq_debug_id, credits->rreq_debug_index); in smb2_add_credits()
107 trace_smb3_rw_credits(credits->rreq_debug_id, in smb2_add_credits()
108 credits->rreq_debug_index, in smb2_add_credits()
109 credits->value, in smb2_add_credits()
110 server->credits, server->in_flight, 0, in smb2_add_credits()
113 server->in_flight--; in smb2_add_credits()
114 if (server->in_flight == 0 && in smb2_add_credits()
119 * Sometimes server returns 0 credits on oplock break ack - we need to in smb2_add_credits()
122 else if (server->in_flight > 0 && server->oplock_credits == 0 && in smb2_add_credits()
123 server->oplocks) { in smb2_add_credits()
124 if (server->credits > 1) { in smb2_add_credits()
125 server->credits--; in smb2_add_credits()
126 server->oplock_credits++; in smb2_add_credits()
128 } else if ((server->in_flight > 0) && (server->oplock_credits > 3) && in smb2_add_credits()
134 in_flight = server->in_flight; in smb2_add_credits()
135 spin_unlock(&server->req_lock); in smb2_add_credits()
136 wake_up(&server->request_q); in smb2_add_credits()
139 trace_smb3_reconnect_detected(server->CurrentMid, in smb2_add_credits()
140 server->conn_id, server->hostname, scredits, add, in_flight); in smb2_add_credits()
147 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid, in smb2_add_credits()
148 server->conn_id, server->hostname, scredits, add, in_flight); in smb2_add_credits()
149 …cifs_dbg(FYI, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d… in smb2_add_credits()
153 spin_lock(&server->srv_lock); in smb2_add_credits()
154 if (server->tcpStatus == CifsNeedReconnect in smb2_add_credits()
155 || server->tcpStatus == CifsExiting) { in smb2_add_credits()
156 spin_unlock(&server->srv_lock); in smb2_add_credits()
159 spin_unlock(&server->srv_lock); in smb2_add_credits()
162 case -1: in smb2_add_credits()
166 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n"); in smb2_add_credits()
179 trace_smb3_add_credits(server->CurrentMid, in smb2_add_credits()
180 server->conn_id, server->hostname, scredits, add, in_flight); in smb2_add_credits()
189 spin_lock(&server->req_lock); in smb2_set_credits()
190 server->credits = val; in smb2_set_credits()
192 server->reconnect_instance++; in smb2_set_credits()
194 * ChannelSequence updated for all channels in primary channel so that consistent in smb2_set_credits()
195 * across SMB3 requests sent on any channel. See MS-SMB2 3.2.4.1 and 3.2.7.1 in smb2_set_credits()
198 server->primary_server->channel_sequence_num++; in smb2_set_credits()
200 server->channel_sequence_num++; in smb2_set_credits()
202 scredits = server->credits; in smb2_set_credits()
203 in_flight = server->in_flight; in smb2_set_credits()
204 spin_unlock(&server->req_lock); in smb2_set_credits()
206 trace_smb3_set_credits(server->CurrentMid, in smb2_set_credits()
207 server->conn_id, server->hostname, scredits, val, in_flight); in smb2_set_credits()
220 return &server->echo_credits; in smb2_get_credits_field()
222 return &server->oplock_credits; in smb2_get_credits_field()
224 return &server->credits; in smb2_get_credits_field()
231 return mid->credits_received; in smb2_get_credits()
241 spin_lock(&server->req_lock); in smb2_wait_mtu_credits()
243 spin_unlock(&server->req_lock); in smb2_wait_mtu_credits()
245 spin_lock(&server->srv_lock); in smb2_wait_mtu_credits()
246 if (server->tcpStatus == CifsExiting) { in smb2_wait_mtu_credits()
247 spin_unlock(&server->srv_lock); in smb2_wait_mtu_credits()
248 return -ENOENT; in smb2_wait_mtu_credits()
250 spin_unlock(&server->srv_lock); in smb2_wait_mtu_credits()
252 spin_lock(&server->req_lock); in smb2_wait_mtu_credits()
253 if (server->credits <= 0) { in smb2_wait_mtu_credits()
254 spin_unlock(&server->req_lock); in smb2_wait_mtu_credits()
256 rc = wait_event_killable(server->request_q, in smb2_wait_mtu_credits()
257 has_credits(server, &server->credits, 1)); in smb2_wait_mtu_credits()
261 spin_lock(&server->req_lock); in smb2_wait_mtu_credits()
263 scredits = server->credits; in smb2_wait_mtu_credits()
267 credits->value = 0; in smb2_wait_mtu_credits()
268 credits->instance = 0; in smb2_wait_mtu_credits()
273 scredits -= 8; in smb2_wait_mtu_credits()
277 credits->value = in smb2_wait_mtu_credits()
279 credits->instance = server->reconnect_instance; in smb2_wait_mtu_credits()
280 server->credits -= credits->value; in smb2_wait_mtu_credits()
281 server->in_flight++; in smb2_wait_mtu_credits()
282 if (server->in_flight > server->max_in_flight) in smb2_wait_mtu_credits()
283 server->max_in_flight = server->in_flight; in smb2_wait_mtu_credits()
287 scredits = server->credits; in smb2_wait_mtu_credits()
288 in_flight = server->in_flight; in smb2_wait_mtu_credits()
289 spin_unlock(&server->req_lock); in smb2_wait_mtu_credits()
291 trace_smb3_wait_credits(server->CurrentMid, in smb2_wait_mtu_credits()
292 server->conn_id, server->hostname, scredits, -(credits->value), in_flight); in smb2_wait_mtu_credits()
294 __func__, credits->value, scredits); in smb2_wait_mtu_credits()
304 struct cifs_credits *credits = &subreq->credits; in smb2_adjust_credits()
305 int new_val = DIV_ROUND_UP(subreq->subreq.len - subreq->subreq.transferred, in smb2_adjust_credits()
309 if (!credits->value || credits->value == new_val) in smb2_adjust_credits()
312 if (credits->value < new_val) { in smb2_adjust_credits()
313 trace_smb3_rw_credits(subreq->rreq->debug_id, in smb2_adjust_credits()
314 subreq->subreq.debug_index, in smb2_adjust_credits()
315 credits->value, in smb2_adjust_credits()
316 server->credits, server->in_flight, in smb2_adjust_credits()
317 new_val - credits->value, in smb2_adjust_credits()
319 trace_smb3_too_many_credits(server->CurrentMid, in smb2_adjust_credits()
320 server->conn_id, server->hostname, 0, credits->value - new_val, 0); in smb2_adjust_credits()
322 subreq->rreq->debug_id, subreq->subreq.debug_index, in smb2_adjust_credits()
323 credits->value, new_val); in smb2_adjust_credits()
325 return -EOPNOTSUPP; in smb2_adjust_credits()
328 spin_lock(&server->req_lock); in smb2_adjust_credits()
330 if (server->reconnect_instance != credits->instance) { in smb2_adjust_credits()
331 scredits = server->credits; in smb2_adjust_credits()
332 in_flight = server->in_flight; in smb2_adjust_credits()
333 spin_unlock(&server->req_lock); in smb2_adjust_credits()
335 trace_smb3_rw_credits(subreq->rreq->debug_id, in smb2_adjust_credits()
336 subreq->subreq.debug_index, in smb2_adjust_credits()
337 credits->value, in smb2_adjust_credits()
338 server->credits, server->in_flight, in smb2_adjust_credits()
339 new_val - credits->value, in smb2_adjust_credits()
341 trace_smb3_reconnect_detected(server->CurrentMid, in smb2_adjust_credits()
342 server->conn_id, server->hostname, scredits, in smb2_adjust_credits()
343 credits->value - new_val, in_flight); in smb2_adjust_credits()
345 subreq->rreq->debug_id, subreq->subreq.debug_index, in smb2_adjust_credits()
346 credits->value - new_val); in smb2_adjust_credits()
347 return -EAGAIN; in smb2_adjust_credits()
350 trace_smb3_rw_credits(subreq->rreq->debug_id, in smb2_adjust_credits()
351 subreq->subreq.debug_index, in smb2_adjust_credits()
352 credits->value, in smb2_adjust_credits()
353 server->credits, server->in_flight, in smb2_adjust_credits()
354 new_val - credits->value, trace); in smb2_adjust_credits()
355 server->credits += credits->value - new_val; in smb2_adjust_credits()
356 scredits = server->credits; in smb2_adjust_credits()
357 in_flight = server->in_flight; in smb2_adjust_credits()
358 spin_unlock(&server->req_lock); in smb2_adjust_credits()
359 wake_up(&server->request_q); in smb2_adjust_credits()
361 trace_smb3_adj_credits(server->CurrentMid, in smb2_adjust_credits()
362 server->conn_id, server->hostname, scredits, in smb2_adjust_credits()
363 credits->value - new_val, in_flight); in smb2_adjust_credits()
365 __func__, credits->value - new_val, scredits); in smb2_adjust_credits()
367 credits->value = new_val; in smb2_adjust_credits()
377 spin_lock(&server->mid_lock); in smb2_get_next_mid()
378 mid = server->CurrentMid++; in smb2_get_next_mid()
379 spin_unlock(&server->mid_lock); in smb2_get_next_mid()
386 spin_lock(&server->mid_lock); in smb2_revert_current_mid()
387 if (server->CurrentMid >= val) in smb2_revert_current_mid()
388 server->CurrentMid -= val; in smb2_revert_current_mid()
389 spin_unlock(&server->mid_lock); in smb2_revert_current_mid()
397 __u64 wire_mid = le64_to_cpu(shdr->MessageId); in __smb2_find_mid()
399 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) { in __smb2_find_mid()
404 spin_lock(&server->mid_lock); in __smb2_find_mid()
405 list_for_each_entry(mid, &server->pending_mid_q, qhead) { in __smb2_find_mid()
406 if ((mid->mid == wire_mid) && in __smb2_find_mid()
407 (mid->mid_state == MID_REQUEST_SUBMITTED) && in __smb2_find_mid()
408 (mid->command == shdr->Command)) { in __smb2_find_mid()
409 kref_get(&mid->refcount); in __smb2_find_mid()
411 list_del_init(&mid->qhead); in __smb2_find_mid()
412 mid->mid_flags |= MID_DELETED; in __smb2_find_mid()
414 spin_unlock(&server->mid_lock); in __smb2_find_mid()
418 spin_unlock(&server->mid_lock); in __smb2_find_mid()
441 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId, in smb2_dump_detail()
442 shdr->Id.SyncId.ProcessId); in smb2_dump_detail()
443 if (!server->ops->check_message(buf, server->total_read, server)) { in smb2_dump_detail()
445 server->ops->calc_smb_size(buf)); in smb2_dump_detail()
453 return server->max_read == 0; in smb2_need_neg()
463 spin_lock(&server->mid_lock); in smb2_negotiate()
464 server->CurrentMid = 0; in smb2_negotiate()
465 spin_unlock(&server->mid_lock); in smb2_negotiate()
468 if (rc == -EAGAIN) in smb2_negotiate()
469 rc = -EHOSTDOWN; in smb2_negotiate()
474 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) in smb2_negotiate_wsize() argument
476 struct TCP_Server_Info *server = tcon->ses->server; in smb2_negotiate_wsize()
480 wsize = ctx->wsize ? ctx->wsize : CIFS_DEFAULT_IOSIZE; in smb2_negotiate_wsize()
481 wsize = min_t(unsigned int, wsize, server->max_write); in smb2_negotiate_wsize()
482 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) in smb2_negotiate_wsize()
489 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) in smb3_negotiate_wsize() argument
491 struct TCP_Server_Info *server = tcon->ses->server; in smb3_negotiate_wsize()
495 wsize = ctx->wsize ? ctx->wsize : SMB3_DEFAULT_IOSIZE; in smb3_negotiate_wsize()
496 wsize = min_t(unsigned int, wsize, server->max_write); in smb3_negotiate_wsize()
498 if (server->rdma) { in smb3_negotiate_wsize()
499 if (server->sign) in smb3_negotiate_wsize()
506 server->smbd_conn->max_fragmented_send_size - in smb3_negotiate_wsize()
507 SMB2_READWRITE_PDU_HEADER_SIZE - in smb3_negotiate_wsize()
511 wsize, server->smbd_conn->max_readwrite_size); in smb3_negotiate_wsize()
514 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) in smb3_negotiate_wsize()
521 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) in smb2_negotiate_rsize() argument
523 struct TCP_Server_Info *server = tcon->ses->server; in smb2_negotiate_rsize()
527 rsize = ctx->rsize ? ctx->rsize : CIFS_DEFAULT_IOSIZE; in smb2_negotiate_rsize()
528 rsize = min_t(unsigned int, rsize, server->max_read); in smb2_negotiate_rsize()
530 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) in smb2_negotiate_rsize()
537 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx) in smb3_negotiate_rsize() argument
539 struct TCP_Server_Info *server = tcon->ses->server; in smb3_negotiate_rsize()
543 rsize = ctx->rsize ? ctx->rsize : SMB3_DEFAULT_IOSIZE; in smb3_negotiate_rsize()
544 rsize = min_t(unsigned int, rsize, server->max_read); in smb3_negotiate_rsize()
546 if (server->rdma) { in smb3_negotiate_rsize()
547 if (server->sign) in smb3_negotiate_rsize()
554 server->smbd_conn->max_fragmented_recv_size - in smb3_negotiate_rsize()
555 SMB2_READWRITE_PDU_HEADER_SIZE - in smb3_negotiate_rsize()
559 rsize, server->smbd_conn->max_readwrite_size); in smb3_negotiate_rsize()
563 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) in smb3_negotiate_rsize()
573 * return -1 otherwise.
581 if (a->rdma_capable == b->rdma_capable) { in iface_cmp()
582 if (a->rss_capable == b->rss_capable) { in iface_cmp()
583 if (a->speed == b->speed) { in iface_cmp()
584 cmp_ret = cifs_ipaddr_cmp((struct sockaddr *) &a->sockaddr, in iface_cmp()
585 (struct sockaddr *) &b->sockaddr); in iface_cmp()
591 return -1; in iface_cmp()
592 } else if (a->speed > b->speed) in iface_cmp()
595 return -1; in iface_cmp()
596 } else if (a->rss_capable > b->rss_capable) in iface_cmp()
599 return -1; in iface_cmp()
600 } else if (a->rdma_capable > b->rdma_capable) in iface_cmp()
603 return -1; in iface_cmp()
625 spin_lock(&ses->iface_lock); in parse_server_interfaces()
627 if (ses->iface_last_update && in parse_server_interfaces()
628 time_before(jiffies, ses->iface_last_update + in parse_server_interfaces()
630 spin_unlock(&ses->iface_lock); in parse_server_interfaces()
637 list_for_each_entry_safe(iface, niface, &ses->iface_list, in parse_server_interfaces()
639 iface->is_active = 0; in parse_server_interfaces()
641 spin_unlock(&ses->iface_lock); in parse_server_interfaces()
649 if ((ses->chan_max > 1) && in_mount) in parse_server_interfaces()
653 ses->server->hostname); in parse_server_interfaces()
654 rc = -EOPNOTSUPP; in parse_server_interfaces()
655 ses->iface_last_update = jiffies; in parse_server_interfaces()
661 tmp_iface.speed = le64_to_cpu(p->LinkSpeed); in parse_server_interfaces()
662 tmp_iface.rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0; in parse_server_interfaces()
663 tmp_iface.rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0; in parse_server_interfaces()
665 switch (p->Family) { in parse_server_interfaces()
673 p4 = (struct iface_info_ipv4 *)p->Buffer; in parse_server_interfaces()
674 addr4->sin_family = AF_INET; in parse_server_interfaces()
675 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4); in parse_server_interfaces()
677 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */ in parse_server_interfaces()
678 addr4->sin_port = cpu_to_be16(CIFS_PORT); in parse_server_interfaces()
681 &addr4->sin_addr); in parse_server_interfaces()
685 p6 = (struct iface_info_ipv6 *)p->Buffer; in parse_server_interfaces()
686 addr6->sin6_family = AF_INET6; in parse_server_interfaces()
687 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16); in parse_server_interfaces()
689 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */ in parse_server_interfaces()
690 addr6->sin6_flowinfo = 0; in parse_server_interfaces()
691 addr6->sin6_scope_id = 0; in parse_server_interfaces()
692 addr6->sin6_port = cpu_to_be16(CIFS_PORT); in parse_server_interfaces()
695 &addr6->sin6_addr); in parse_server_interfaces()
710 spin_lock(&ses->iface_lock); in parse_server_interfaces()
711 list_for_each_entry_safe(iface, niface, &ses->iface_list, in parse_server_interfaces()
715 iface->is_active = 1; in parse_server_interfaces()
716 spin_unlock(&ses->iface_lock); in parse_server_interfaces()
720 kref_get(&iface->refcount); in parse_server_interfaces()
724 spin_unlock(&ses->iface_lock); in parse_server_interfaces()
730 rc = -ENOMEM; in parse_server_interfaces()
736 kref_init(&info->refcount); in parse_server_interfaces()
737 info->is_active = 1; in parse_server_interfaces()
739 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, ses->iface_count); in parse_server_interfaces()
740 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed); in parse_server_interfaces()
742 le32_to_cpu(p->Capability)); in parse_server_interfaces()
744 spin_lock(&ses->iface_lock); in parse_server_interfaces()
745 if (!list_entry_is_head(iface, &ses->iface_list, iface_head)) { in parse_server_interfaces()
746 list_add_tail(&info->iface_head, &iface->iface_head); in parse_server_interfaces()
747 kref_put(&iface->refcount, release_iface); in parse_server_interfaces()
749 list_add_tail(&info->iface_head, &ses->iface_list); in parse_server_interfaces()
751 ses->iface_count++; in parse_server_interfaces()
752 spin_unlock(&ses->iface_lock); in parse_server_interfaces()
755 next = le32_to_cpu(p->Next); in parse_server_interfaces()
757 bytes_left -= sizeof(*p); in parse_server_interfaces()
761 bytes_left -= next; in parse_server_interfaces()
766 rc = -EINVAL; in parse_server_interfaces()
771 if ((bytes_left > 8) || p->Next) in parse_server_interfaces()
774 ses->iface_last_update = jiffies; in parse_server_interfaces()
780 spin_lock(&ses->iface_lock); in parse_server_interfaces()
781 list_for_each_entry_safe(iface, niface, &ses->iface_list, in parse_server_interfaces()
783 if (!iface->is_active) { in parse_server_interfaces()
784 list_del(&iface->iface_head); in parse_server_interfaces()
785 kref_put(&iface->refcount, release_iface); in parse_server_interfaces()
786 ses->iface_count--; in parse_server_interfaces()
789 spin_unlock(&ses->iface_lock); in parse_server_interfaces()
795 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount) in SMB3_request_interfaces() argument
800 struct cifs_ses *ses = tcon->ses; in SMB3_request_interfaces()
804 if (ses->iface_last_update && in SMB3_request_interfaces()
805 time_before(jiffies, ses->iface_last_update + in SMB3_request_interfaces()
809 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, in SMB3_request_interfaces()
813 if (rc == -EOPNOTSUPP) { in SMB3_request_interfaces()
827 spin_lock(&ses->chan_lock); in SMB3_request_interfaces()
828 pserver = ses->chans[0].server; in SMB3_request_interfaces()
830 spin_unlock(&ses->chan_lock); in SMB3_request_interfaces()
832 spin_lock(&ses->chan_lock); in SMB3_request_interfaces()
834 spin_unlock(&ses->chan_lock); in SMB3_request_interfaces()
842 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, in smb3_qfs_tcon() argument
846 __le16 srch_path = 0; /* Null - open root of share */ in smb3_qfs_tcon()
853 .tcon = tcon, in smb3_qfs_tcon()
861 rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid); in smb3_qfs_tcon()
863 memcpy(&fid, &cfid->fid, sizeof(struct cifs_fid)); in smb3_qfs_tcon()
870 SMB3_request_interfaces(xid, tcon, true /* called during mount */); in smb3_qfs_tcon()
872 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_qfs_tcon()
874 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_qfs_tcon()
876 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_qfs_tcon()
878 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_qfs_tcon()
881 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb3_qfs_tcon()
887 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, in smb2_qfs_tcon() argument
891 __le16 srch_path = 0; /* Null - open root of share */ in smb2_qfs_tcon()
897 .tcon = tcon, in smb2_qfs_tcon()
910 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb2_qfs_tcon()
912 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb2_qfs_tcon()
914 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb2_qfs_tcon()
918 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, in smb2_is_path_accessible() argument
931 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid); in smb2_is_path_accessible()
933 if (cfid->has_lease) { in smb2_is_path_accessible()
942 return -ENOMEM; in smb2_is_path_accessible()
945 .tcon = tcon, in smb2_is_path_accessible()
961 if (rc != -EREMOTE && hdr->Status == STATUS_OBJECT_NAME_INVALID) { in smb2_is_path_accessible()
962 rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb, in smb2_is_path_accessible()
969 rc = -EREMOTE; in smb2_is_path_accessible()
971 if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb && in smb2_is_path_accessible()
972 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS)) in smb2_is_path_accessible()
973 rc = -EOPNOTSUPP; in smb2_is_path_accessible()
977 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb2_is_path_accessible()
985 static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, in smb2_get_srv_inum() argument
989 *uniqueid = le64_to_cpu(data->fi.IndexNumber); in smb2_get_srv_inum()
993 static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_file_info() argument
996 struct cifs_fid *fid = &cfile->fid; in smb2_query_file_info()
998 if (cfile->symlink_target) { in smb2_query_file_info()
999 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL); in smb2_query_file_info()
1000 if (!data->symlink_target) in smb2_query_file_info()
1001 return -ENOMEM; in smb2_query_file_info()
1003 return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi); in smb2_query_file_info()
1019 name_len = (size_t)src->ea_name_length; in move_smb2_ea_to_cifs()
1020 value_len = (size_t)le16_to_cpu(src->ea_value_length); in move_smb2_ea_to_cifs()
1027 rc = -EIO; in move_smb2_ea_to_cifs()
1031 name = &src->ea_data[0]; in move_smb2_ea_to_cifs()
1032 value = &src->ea_data[src->ea_name_length + 1]; in move_smb2_ea_to_cifs()
1041 rc = -ERANGE; in move_smb2_ea_to_cifs()
1052 /* skip copy - calc size only */ in move_smb2_ea_to_cifs()
1055 dst_size -= user_name_len; in move_smb2_ea_to_cifs()
1058 memcpy(dst, src->ea_data, name_len); in move_smb2_ea_to_cifs()
1065 rc = -ERANGE; in move_smb2_ea_to_cifs()
1070 if (!src->next_entry_offset) in move_smb2_ea_to_cifs()
1073 if (src_size < le32_to_cpu(src->next_entry_offset)) { in move_smb2_ea_to_cifs()
1075 rc = -ERANGE; in move_smb2_ea_to_cifs()
1078 src_size -= le32_to_cpu(src->next_entry_offset); in move_smb2_ea_to_cifs()
1080 le32_to_cpu(src->next_entry_offset)); in move_smb2_ea_to_cifs()
1085 rc = -ENODATA; in move_smb2_ea_to_cifs()
1092 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_eas() argument
1103 rc = smb2_query_info_compound(xid, tcon, path, in smb2_query_eas()
1107 CIFSMaxBufSize - in smb2_query_eas()
1108 MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_query_eas()
1117 if (!ea_name && rc == -ENODATA) in smb2_query_eas()
1123 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in smb2_query_eas()
1124 le32_to_cpu(rsp->OutputBufferLength), in smb2_query_eas()
1131 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in smb2_query_eas()
1133 le32_to_cpu(rsp->OutputBufferLength), ea_name); in smb2_query_eas()
1141 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_ea() argument
1147 struct cifs_ses *ses = tcon->ses; in smb2_set_ea()
1172 if (smb3_encryption_required(tcon)) in smb2_set_ea()
1176 return -EINVAL; in smb2_set_ea()
1180 return -ENOMEM; in smb2_set_ea()
1186 rc = -ENOMEM; in smb2_set_ea()
1189 rqst = vars->rqst; in smb2_set_ea()
1190 rsp_iov = vars->rsp_iov; in smb2_set_ea()
1192 if (ses->server->ops->query_all_EAs) { in smb2_set_ea()
1194 rc = ses->server->ops->query_all_EAs(xid, tcon, path, in smb2_set_ea()
1197 if (rc == -ENODATA) in smb2_set_ea()
1205 rc = smb2_query_info_compound(xid, tcon, path, in smb2_set_ea()
1209 CIFSMaxBufSize - in smb2_set_ea()
1210 MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_set_ea()
1215 used_len = le32_to_cpu(rsp->OutputBufferLength); in smb2_set_ea()
1225 if (CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_set_ea()
1226 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 < in smb2_set_ea()
1228 rc = -ENOSPC; in smb2_set_ea()
1235 rqst[0].rq_iov = vars->open_iov; in smb2_set_ea()
1239 .tcon = tcon, in smb2_set_ea()
1248 rc = SMB2_open_init(tcon, server, in smb2_set_ea()
1252 smb2_set_next_command(tcon, &rqst[0]); in smb2_set_ea()
1256 rqst[1].rq_iov = vars->si_iov; in smb2_set_ea()
1262 rc = -ENOMEM; in smb2_set_ea()
1266 ea->ea_name_length = ea_name_len; in smb2_set_ea()
1267 ea->ea_value_length = cpu_to_le16(ea_value_len); in smb2_set_ea()
1268 memcpy(ea->ea_data, ea_name, ea_name_len + 1); in smb2_set_ea()
1269 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len); in smb2_set_ea()
1274 rc = SMB2_set_info_init(tcon, server, in smb2_set_ea()
1276 COMPOUND_FID, current->tgid, in smb2_set_ea()
1281 smb2_set_next_command(tcon, &rqst[1]); in smb2_set_ea()
1285 rqst[2].rq_iov = &vars->close_iov; in smb2_set_ea()
1287 rc = SMB2_close_init(tcon, server, in smb2_set_ea()
1317 smb2_should_replay(tcon, &retries, &cur_sleep)) in smb2_set_ea()
1327 return server->echoes; in smb2_can_echo()
1331 smb2_clear_stats(struct cifs_tcon *tcon) in smb2_clear_stats() argument
1336 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0); in smb2_clear_stats()
1337 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0); in smb2_clear_stats()
1342 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon) in smb2_dump_share_caps() argument
1345 if (tcon->capabilities & SMB2_SHARE_CAP_DFS) in smb2_dump_share_caps()
1347 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) in smb2_dump_share_caps()
1349 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT) in smb2_dump_share_caps()
1351 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) in smb2_dump_share_caps()
1353 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC) in smb2_dump_share_caps()
1355 if (tcon->capabilities == 0) in smb2_dump_share_caps()
1357 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE) in smb2_dump_share_caps()
1359 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE) in smb2_dump_share_caps()
1361 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY) in smb2_dump_share_caps()
1363 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED) in smb2_dump_share_caps()
1364 seq_puts(m, " TRIM-support,"); in smb2_dump_share_caps()
1366 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags); in smb2_dump_share_caps()
1367 seq_printf(m, "\n\ttid: 0x%x", tcon->tid); in smb2_dump_share_caps()
1368 if (tcon->perf_sector_size) in smb2_dump_share_caps()
1370 tcon->perf_sector_size); in smb2_dump_share_caps()
1371 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access); in smb2_dump_share_caps()
1375 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) in smb2_print_stats() argument
1377 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent; in smb2_print_stats()
1378 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed; in smb2_print_stats()
1382 * totals (requests sent) since those SMBs are per-session not per tcon in smb2_print_stats()
1385 (long long)(tcon->bytes_read), in smb2_print_stats()
1386 (long long)(tcon->bytes_written)); in smb2_print_stats()
1388 atomic_read(&tcon->num_local_opens), in smb2_print_stats()
1389 atomic_read(&tcon->num_remote_opens)); in smb2_print_stats()
1437 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); in smb2_set_fid()
1438 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; in smb2_set_fid()
1440 cfile->fid.persistent_fid = fid->persistent_fid; in smb2_set_fid()
1441 cfile->fid.volatile_fid = fid->volatile_fid; in smb2_set_fid()
1442 cfile->fid.access = fid->access; in smb2_set_fid()
1444 cfile->fid.mid = fid->mid; in smb2_set_fid()
1446 server->ops->set_oplock_level(cinode, oplock, fid->epoch, in smb2_set_fid()
1447 &fid->purge_cache); in smb2_set_fid()
1448 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode); in smb2_set_fid()
1449 memcpy(cfile->fid.create_guid, fid->create_guid, 16); in smb2_set_fid()
1453 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, in smb2_close_file() argument
1456 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_close_file()
1460 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon, in smb2_close_getattr() argument
1467 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid, in smb2_close_getattr()
1468 cfile->fid.volatile_fid, &file_inf); in smb2_close_getattr()
1472 inode = d_inode(cfile->dentry); in smb2_close_getattr()
1474 spin_lock(&inode->i_lock); in smb2_close_getattr()
1475 CIFS_I(inode)->time = jiffies; in smb2_close_getattr()
1494 inode->i_blocks = in smb2_close_getattr()
1495 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9; in smb2_close_getattr()
1498 spin_unlock(&inode->i_lock); in smb2_close_getattr()
1503 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, in SMB2_request_res_key() argument
1511 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid, in SMB2_request_res_key()
1515 if (rc == -EOPNOTSUPP) { in SMB2_request_res_key()
1516 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name); in SMB2_request_res_key()
1524 rc = -EINVAL; in SMB2_request_res_key()
1527 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE); in SMB2_request_res_key()
1536 struct cifs_tcon *tcon, in smb2_ioctl_query_info() argument
1544 struct cifs_ses *ses = tcon->ses; in smb2_ioctl_query_info()
1572 return -ENOMEM; in smb2_ioctl_query_info()
1573 rqst = &vars->rqst[0]; in smb2_ioctl_query_info()
1574 rsp_iov = &vars->rsp_iov[0]; in smb2_ioctl_query_info()
1579 rc = -EFAULT; in smb2_ioctl_query_info()
1583 rc = -EINVAL; in smb2_ioctl_query_info()
1588 rc = -EIO; in smb2_ioctl_query_info()
1592 if (smb3_encryption_required(tcon)) in smb2_ioctl_query_info()
1604 rqst[0].rq_iov = &vars->open_iov[0]; in smb2_ioctl_query_info()
1608 .tcon = tcon, in smb2_ioctl_query_info()
1636 rc = SMB2_open_init(tcon, server, in smb2_ioctl_query_info()
1640 smb2_set_next_command(tcon, &rqst[0]); in smb2_ioctl_query_info()
1646 rc = -EPERM; in smb2_ioctl_query_info()
1649 rqst[1].rq_iov = &vars->io_iov[0]; in smb2_ioctl_query_info()
1652 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID, in smb2_ioctl_query_info()
1654 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE - in smb2_ioctl_query_info()
1660 rc = -EPERM; in smb2_ioctl_query_info()
1664 rc = -EINVAL; in smb2_ioctl_query_info()
1667 rqst[1].rq_iov = vars->si_iov; in smb2_ioctl_query_info()
1670 /* MS-FSCC 2.4.13 FileEndOfFileInformation */ in smb2_ioctl_query_info()
1674 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID, in smb2_ioctl_query_info()
1675 current->tgid, FILE_END_OF_FILE_INFORMATION, in smb2_ioctl_query_info()
1679 rqst[1].rq_iov = &vars->qi_iov; in smb2_ioctl_query_info()
1682 rc = SMB2_query_info_init(tcon, server, in smb2_ioctl_query_info()
1692 rc = -EINVAL; in smb2_ioctl_query_info()
1697 smb2_set_next_command(tcon, &rqst[1]); in smb2_ioctl_query_info()
1701 rqst[2].rq_iov = &vars->close_iov; in smb2_ioctl_query_info()
1704 rc = SMB2_close_init(tcon, server, in smb2_ioctl_query_info()
1726 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length) in smb2_ioctl_query_info()
1727 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount); in smb2_ioctl_query_info()
1729 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length in smb2_ioctl_query_info()
1731 rc = -EFAULT; in smb2_ioctl_query_info()
1735 if (copy_to_user(&pqi->input_buffer_length, in smb2_ioctl_query_info()
1738 rc = -EFAULT; in smb2_ioctl_query_info()
1743 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset), in smb2_ioctl_query_info()
1745 rc = -EFAULT; in smb2_ioctl_query_info()
1749 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length) in smb2_ioctl_query_info()
1750 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength); in smb2_ioctl_query_info()
1751 if (copy_to_user(&pqi->input_buffer_length, in smb2_ioctl_query_info()
1754 rc = -EFAULT; in smb2_ioctl_query_info()
1758 if (copy_to_user(pqi + 1, qi_rsp->Buffer, in smb2_ioctl_query_info()
1760 rc = -EFAULT; in smb2_ioctl_query_info()
1778 smb2_should_replay(tcon, &retries, &cur_sleep)) in smb2_ioctl_query_info()
1794 struct cifs_tcon *tcon; in smb2_copychunk_range() local
1801 return -ENOMEM; in smb2_copychunk_range()
1805 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), in smb2_copychunk_range()
1806 srcfile->fid.persistent_fid, in smb2_copychunk_range()
1807 srcfile->fid.volatile_fid, pcchunk); in smb2_copychunk_range()
1814 pcchunk->ChunkCount = cpu_to_le32(1); in smb2_copychunk_range()
1815 pcchunk->Reserved = 0; in smb2_copychunk_range()
1816 pcchunk->Reserved2 = 0; in smb2_copychunk_range()
1818 tcon = tlink_tcon(trgtfile->tlink); in smb2_copychunk_range()
1820 trace_smb3_copychunk_enter(xid, srcfile->fid.volatile_fid, in smb2_copychunk_range()
1821 trgtfile->fid.volatile_fid, tcon->tid, in smb2_copychunk_range()
1822 tcon->ses->Suid, src_off, dest_off, len); in smb2_copychunk_range()
1825 pcchunk->SourceOffset = cpu_to_le64(src_off); in smb2_copychunk_range()
1826 pcchunk->TargetOffset = cpu_to_le64(dest_off); in smb2_copychunk_range()
1827 pcchunk->Length = in smb2_copychunk_range()
1828 cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk)); in smb2_copychunk_range()
1833 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, in smb2_copychunk_range()
1834 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE, in smb2_copychunk_range()
1841 rc = -EIO; in smb2_copychunk_range()
1844 if (retbuf->TotalBytesWritten == 0) { in smb2_copychunk_range()
1846 rc = -EIO; in smb2_copychunk_range()
1852 if (le32_to_cpu(retbuf->TotalBytesWritten) > in smb2_copychunk_range()
1853 le32_to_cpu(pcchunk->Length)) { in smb2_copychunk_range()
1855 rc = -EIO; in smb2_copychunk_range()
1858 if (le32_to_cpu(retbuf->ChunksWritten) != 1) { in smb2_copychunk_range()
1860 rc = -EIO; in smb2_copychunk_range()
1865 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten); in smb2_copychunk_range()
1868 len -= bytes_written; in smb2_copychunk_range()
1872 le32_to_cpu(retbuf->ChunksWritten), in smb2_copychunk_range()
1873 le32_to_cpu(retbuf->ChunkBytesWritten), in smb2_copychunk_range()
1875 trace_smb3_copychunk_done(xid, srcfile->fid.volatile_fid, in smb2_copychunk_range()
1876 trgtfile->fid.volatile_fid, tcon->tid, in smb2_copychunk_range()
1877 tcon->ses->Suid, src_off, dest_off, len); in smb2_copychunk_range()
1878 } else if (rc == -EINVAL) { in smb2_copychunk_range()
1883 le32_to_cpu(retbuf->ChunksWritten), in smb2_copychunk_range()
1884 le32_to_cpu(retbuf->ChunkBytesWritten), in smb2_copychunk_range()
1885 le32_to_cpu(retbuf->TotalBytesWritten)); in smb2_copychunk_range()
1898 if (le32_to_cpu(retbuf->ChunkBytesWritten) < in smb2_copychunk_range()
1899 tcon->max_bytes_chunk) in smb2_copychunk_range()
1900 tcon->max_bytes_chunk = in smb2_copychunk_range()
1901 le32_to_cpu(retbuf->ChunkBytesWritten); in smb2_copychunk_range()
1921 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, in smb2_flush_file() argument
1924 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_flush_file()
1932 return rsp->DataOffset; in smb2_read_data_offset()
1941 return le32_to_cpu(rsp->DataRemaining); in smb2_read_data_length()
1943 return le32_to_cpu(rsp->DataLength); in smb2_read_data_length()
1952 parms->persistent_fid = pfid->persistent_fid; in smb2_sync_read()
1953 parms->volatile_fid = pfid->volatile_fid; in smb2_sync_read()
1963 parms->persistent_fid = pfid->persistent_fid; in smb2_sync_write()
1964 parms->volatile_fid = pfid->volatile_fid; in smb2_sync_write()
1969 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_sparse() argument
1978 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse) in smb2_set_sparse()
1981 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse) in smb2_set_sparse()
1994 if (tcon->broken_sparse_sup) in smb2_set_sparse()
1997 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb2_set_sparse()
1998 cfile->fid.volatile_fid, FSCTL_SET_SPARSE, in smb2_set_sparse()
2001 tcon->broken_sparse_sup = true; in smb2_set_sparse()
2007 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE; in smb2_set_sparse()
2009 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE); in smb2_set_sparse()
2015 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_file_size() argument
2024 inode = d_inode(cfile->dentry); in smb2_set_file_size()
2026 if (!set_alloc && (size > inode->i_size + 8192)) { in smb2_set_file_size()
2030 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse); in smb2_set_file_size()
2033 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb2_set_file_size()
2034 cfile->fid.volatile_fid, cfile->pid, size); in smb2_set_file_size()
2047 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink); in smb2_duplicate_extents() local
2050 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) & in smb2_duplicate_extents()
2052 return -EOPNOTSUPP; in smb2_duplicate_extents()
2054 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid; in smb2_duplicate_extents()
2055 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid; in smb2_duplicate_extents()
2061 trace_smb3_clone_enter(xid, srcfile->fid.volatile_fid, in smb2_duplicate_extents()
2062 trgtfile->fid.volatile_fid, tcon->tid, in smb2_duplicate_extents()
2063 tcon->ses->Suid, src_off, dest_off, len); in smb2_duplicate_extents()
2064 inode = d_inode(trgtfile->dentry); in smb2_duplicate_extents()
2065 if (inode->i_size < dest_off + len) { in smb2_duplicate_extents()
2066 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); in smb2_duplicate_extents()
2080 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, in smb2_duplicate_extents()
2081 trgtfile->fid.volatile_fid, in smb2_duplicate_extents()
2089 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n"); in smb2_duplicate_extents()
2093 trace_smb3_clone_err(xid, srcfile->fid.volatile_fid, in smb2_duplicate_extents()
2094 trgtfile->fid.volatile_fid, in smb2_duplicate_extents()
2095 tcon->tid, tcon->ses->Suid, src_off, in smb2_duplicate_extents()
2098 trace_smb3_clone_done(xid, srcfile->fid.volatile_fid, in smb2_duplicate_extents()
2099 trgtfile->fid.volatile_fid, tcon->tid, in smb2_duplicate_extents()
2100 tcon->ses->Suid, src_off, dest_off, len); in smb2_duplicate_extents()
2105 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, in smb2_set_compression() argument
2108 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid, in smb2_set_compression()
2109 cfile->fid.volatile_fid); in smb2_set_compression()
2113 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon, in smb3_set_integrity() argument
2123 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_set_integrity()
2124 cfile->fid.volatile_fid, in smb3_set_integrity()
2133 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2136 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2140 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2143 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon, in smb3_enum_snapshots() argument
2161 return -EFAULT; in smb3_enum_snapshots()
2175 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_enum_snapshots()
2176 cfile->fid.volatile_fid, in smb3_enum_snapshots()
2190 rc = -EFAULT; in smb3_enum_snapshots()
2217 rc = -EFAULT; in smb3_enum_snapshots()
2232 struct dentry *dentry = pfile->f_path.dentry; in smb3_notify()
2234 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in smb3_notify()
2237 struct cifs_tcon *tcon; in smb3_notify() local
2254 rc = -ENOMEM; in smb3_notify()
2260 rc = -EFAULT; in smb3_notify()
2265 rc = -EFAULT; in smb3_notify()
2271 tcon = cifs_sb_master_tcon(cifs_sb); in smb3_notify()
2273 .tcon = tcon, in smb3_notify()
2286 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid, in smb3_notify()
2290 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb3_notify()
2297 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len)) in smb3_notify()
2298 rc = -EFAULT; in smb3_notify()
2299 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len))) in smb3_notify()
2300 rc = -EFAULT; in smb3_notify()
2310 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_dir_first() argument
2333 server = cifs_pick_channel(tcon->ses); in smb2_query_dir_first()
2337 return -ENOMEM; in smb2_query_dir_first()
2339 if (smb3_encryption_required(tcon)) in smb2_query_dir_first()
2352 .tcon = tcon, in smb2_query_dir_first()
2361 rc = SMB2_open_init(tcon, server, in smb2_query_dir_first()
2365 smb2_set_next_command(tcon, &rqst[0]); in smb2_query_dir_first()
2368 srch_inf->entries_in_buffer = 0; in smb2_query_dir_first()
2369 srch_inf->index_of_last_entry = 2; in smb2_query_dir_first()
2375 rc = SMB2_query_directory_init(xid, tcon, server, in smb2_query_dir_first()
2378 0, srch_inf->info_level); in smb2_query_dir_first()
2389 rc = compound_send_recv(xid, tcon->ses, server, in smb2_query_dir_first()
2395 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) { in smb2_query_dir_first()
2399 fid->persistent_fid = op_rsp->PersistentFileId; in smb2_query_dir_first()
2400 fid->volatile_fid = op_rsp->VolatileFileId; in smb2_query_dir_first()
2403 if (rc && rc != -ENODATA) { in smb2_query_dir_first()
2404 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_query_dir_first()
2406 trace_smb3_query_dir_err(xid, fid->persistent_fid, in smb2_query_dir_first()
2407 tcon->tid, tcon->ses->Suid, 0, 0, rc); in smb2_query_dir_first()
2411 atomic_inc(&tcon->num_remote_opens); in smb2_query_dir_first()
2414 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) { in smb2_query_dir_first()
2415 trace_smb3_query_dir_done(xid, fid->persistent_fid, in smb2_query_dir_first()
2416 tcon->tid, tcon->ses->Suid, 0, 0); in smb2_query_dir_first()
2417 srch_inf->endOfSearch = true; in smb2_query_dir_first()
2422 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1], in smb2_query_dir_first()
2425 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid, in smb2_query_dir_first()
2426 tcon->ses->Suid, 0, 0, rc); in smb2_query_dir_first()
2431 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid, in smb2_query_dir_first()
2432 tcon->ses->Suid, 0, srch_inf->entries_in_buffer); in smb2_query_dir_first()
2442 smb2_should_replay(tcon, &retries, &cur_sleep)) in smb2_query_dir_first()
2449 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_dir_next() argument
2453 return SMB2_query_directory(xid, tcon, fid->persistent_fid, in smb2_query_dir_next()
2454 fid->volatile_fid, 0, srch_inf); in smb2_query_dir_next()
2458 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, in smb2_close_dir() argument
2461 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); in smb2_close_dir()
2465 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2466 * the number of credits and return true. Otherwise - return false.
2474 if (shdr->Status != STATUS_PENDING) in smb2_is_status_pending()
2477 if (shdr->CreditRequest) { in smb2_is_status_pending()
2478 spin_lock(&server->req_lock); in smb2_is_status_pending()
2479 server->credits += le16_to_cpu(shdr->CreditRequest); in smb2_is_status_pending()
2480 scredits = server->credits; in smb2_is_status_pending()
2481 in_flight = server->in_flight; in smb2_is_status_pending()
2482 spin_unlock(&server->req_lock); in smb2_is_status_pending()
2483 wake_up(&server->request_q); in smb2_is_status_pending()
2485 trace_smb3_pend_credits(server->CurrentMid, in smb2_is_status_pending()
2486 server->conn_id, server->hostname, scredits, in smb2_is_status_pending()
2487 le16_to_cpu(shdr->CreditRequest), in_flight); in smb2_is_status_pending()
2489 __func__, le16_to_cpu(shdr->CreditRequest), scredits); in smb2_is_status_pending()
2500 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED && in smb2_is_session_expired()
2501 shdr->Status != STATUS_USER_SESSION_DELETED) in smb2_is_session_expired()
2504 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId), in smb2_is_session_expired()
2505 le64_to_cpu(shdr->SessionId), in smb2_is_session_expired()
2506 le16_to_cpu(shdr->Command), in smb2_is_session_expired()
2507 le64_to_cpu(shdr->MessageId)); in smb2_is_session_expired()
2518 if (shdr->Status == STATUS_IO_TIMEOUT) in smb2_is_status_io_timeout()
2530 struct cifs_tcon *tcon; in smb2_is_network_name_deleted() local
2532 if (shdr->Status != STATUS_NETWORK_NAME_DELETED) in smb2_is_network_name_deleted()
2535 /* If server is a channel, select the primary channel */ in smb2_is_network_name_deleted()
2536 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in smb2_is_network_name_deleted()
2539 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) { in smb2_is_network_name_deleted()
2542 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { in smb2_is_network_name_deleted()
2543 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) { in smb2_is_network_name_deleted()
2544 spin_lock(&tcon->tc_lock); in smb2_is_network_name_deleted()
2545 tcon->need_reconnect = true; in smb2_is_network_name_deleted()
2546 spin_unlock(&tcon->tc_lock); in smb2_is_network_name_deleted()
2549 tcon->tree_name); in smb2_is_network_name_deleted()
2560 smb2_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid, in smb2_oplock_response() argument
2563 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) in smb2_oplock_response()
2564 return SMB2_lease_break(0, tcon, cinode->lease_key, in smb2_oplock_response()
2567 return SMB2_oplock_break(0, tcon, persistent_fid, volatile_fid, in smb2_oplock_response()
2576 if (server->dialect < SMB30_PROT_ID) in smb2_set_replay()
2579 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base); in smb2_set_replay()
2584 shdr->Flags |= SMB2_FLAGS_REPLAY_OPERATION; in smb2_set_replay()
2592 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base); in smb2_set_related()
2597 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS; in smb2_set_related()
2603 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst) in smb2_set_next_command() argument
2606 struct cifs_ses *ses = tcon->ses; in smb2_set_next_command()
2607 struct TCP_Server_Info *server = ses->server; in smb2_set_next_command()
2611 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base); in smb2_set_next_command()
2623 num_padding = 8 - (len & 7); in smb2_set_next_command()
2624 if (!smb3_encryption_required(tcon)) { in smb2_set_next_command()
2629 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding; in smb2_set_next_command()
2630 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding; in smb2_set_next_command()
2631 rqst->rq_nvec++; in smb2_set_next_command()
2641 for (i = 1; i < rqst->rq_nvec; i++) { in smb2_set_next_command()
2642 memcpy(rqst->rq_iov[0].iov_base + in smb2_set_next_command()
2643 rqst->rq_iov[0].iov_len, in smb2_set_next_command()
2644 rqst->rq_iov[i].iov_base, in smb2_set_next_command()
2645 rqst->rq_iov[i].iov_len); in smb2_set_next_command()
2646 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len; in smb2_set_next_command()
2648 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len, in smb2_set_next_command()
2650 rqst->rq_iov[0].iov_len += num_padding; in smb2_set_next_command()
2652 rqst->rq_nvec = 1; in smb2_set_next_command()
2656 shdr->NextCommand = cpu_to_le32(len); in smb2_set_next_command()
2662 bool smb2_should_replay(struct cifs_tcon *tcon, in smb2_should_replay() argument
2669 if (tcon->retry || (*pretries)++ < tcon->ses->server->retrans) { in smb2_should_replay()
2685 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, in smb2_query_info_compound() argument
2692 struct cifs_ses *ses = tcon->ses; in smb2_query_info_compound()
2716 return -ENOMEM; in smb2_query_info_compound()
2718 if (smb3_encryption_required(tcon)) in smb2_query_info_compound()
2724 rc = -ENOMEM; in smb2_query_info_compound()
2727 rqst = vars->rqst; in smb2_query_info_compound()
2728 rsp_iov = vars->rsp_iov; in smb2_query_info_compound()
2734 open_cached_dir(xid, tcon, path, cifs_sb, false, in smb2_query_info_compound()
2737 rqst[0].rq_iov = vars->open_iov; in smb2_query_info_compound()
2741 .tcon = tcon, in smb2_query_info_compound()
2750 rc = SMB2_open_init(tcon, server, in smb2_query_info_compound()
2754 smb2_set_next_command(tcon, &rqst[0]); in smb2_query_info_compound()
2756 rqst[1].rq_iov = &vars->qi_iov; in smb2_query_info_compound()
2760 rc = SMB2_query_info_init(tcon, server, in smb2_query_info_compound()
2762 cfid->fid.persistent_fid, in smb2_query_info_compound()
2763 cfid->fid.volatile_fid, in smb2_query_info_compound()
2768 rc = SMB2_query_info_init(tcon, server, in smb2_query_info_compound()
2779 smb2_set_next_command(tcon, &rqst[1]); in smb2_query_info_compound()
2783 rqst[2].rq_iov = &vars->close_iov; in smb2_query_info_compound()
2786 rc = SMB2_close_init(tcon, server, in smb2_query_info_compound()
2811 if (rc == -EREMCHG) { in smb2_query_info_compound()
2812 tcon->need_reconnect = true; in smb2_query_info_compound()
2814 tcon->tree_name); in smb2_query_info_compound()
2834 smb2_should_replay(tcon, &retries, &cur_sleep)) in smb2_query_info_compound()
2841 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, in smb2_queryfs() argument
2851 rc = smb2_query_info_compound(xid, tcon, path, in smb2_queryfs()
2861 buf->f_type = SMB2_SUPER_MAGIC; in smb2_queryfs()
2863 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp); in smb2_queryfs()
2864 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset), in smb2_queryfs()
2865 le32_to_cpu(rsp->OutputBufferLength), in smb2_queryfs()
2872 trace_smb3_qfs_done(xid, tcon->tid, tcon->ses->Suid, tcon->tree_name, rc); in smb2_queryfs()
2878 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon, in smb311_queryfs() argument
2887 if (!tcon->posix_extensions) in smb311_queryfs()
2888 return smb2_queryfs(xid, tcon, path, cifs_sb, buf); in smb311_queryfs()
2891 .tcon = tcon, in smb311_queryfs()
2901 return -ENOMEM; in smb311_queryfs()
2909 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid, in smb311_queryfs()
2911 buf->f_type = SMB2_SUPER_MAGIC; in smb311_queryfs()
2912 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in smb311_queryfs()
2919 return ob1->fid.persistent_fid == ob2->fid.persistent_fid && in smb2_compare_fids()
2920 ob1->fid.volatile_fid == ob2->fid.volatile_fid; in smb2_compare_fids()
2929 return SMB2_lock(xid, tlink_tcon(cfile->tlink), in smb2_mand_lock()
2930 cfile->fid.persistent_fid, cfile->fid.volatile_fid, in smb2_mand_lock()
2931 current->tgid, length, offset, type, wait); in smb2_mand_lock()
2937 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); in smb2_get_lease_key()
2943 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); in smb2_set_lease_key()
2949 generate_random_uuid(fid->lease_key); in smb2_new_lease_key()
2962 struct cifs_tcon *tcon; in smb2_get_dfs_refer() local
2971 * Try to use the IPC tcon, otherwise just use any in smb2_get_dfs_refer()
2973 tcon = ses->tcon_ipc; in smb2_get_dfs_refer()
2974 if (tcon == NULL) { in smb2_get_dfs_refer()
2976 tcon = list_first_entry_or_null(&ses->tcon_list, in smb2_get_dfs_refer()
2979 if (tcon) { in smb2_get_dfs_refer()
2980 tcon->tc_count++; in smb2_get_dfs_refer()
2981 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count, in smb2_get_dfs_refer()
2987 if (tcon == NULL) { in smb2_get_dfs_refer()
2988 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n", in smb2_get_dfs_refer()
2990 rc = -ENOTCONN; in smb2_get_dfs_refer()
2998 rc = -ENOMEM; in smb2_get_dfs_refer()
3005 rc = -ENOMEM; in smb2_get_dfs_refer()
3010 dfs_req->MaxReferralLevel = DFS_VERSION; in smb2_get_dfs_refer()
3012 /* Path to resolve in an UTF-16 null-terminated string */ in smb2_get_dfs_refer()
3013 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len); in smb2_get_dfs_refer()
3016 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID, in smb2_get_dfs_refer()
3026 rc = -EIO; in smb2_get_dfs_refer()
3028 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP) in smb2_get_dfs_refer()
3043 if (tcon && !tcon->ipc) { in smb2_get_dfs_refer()
3046 tcon->tc_count--; in smb2_get_dfs_refer()
3047 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count, in smb2_get_dfs_refer()
3050 WARN_ON(tcon->tc_count < 0); in smb2_get_dfs_refer()
3065 int rc = -EOPNOTSUPP; in get_smb2_acl_by_fid()
3074 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid, in get_smb2_acl_by_fid()
3075 cifsfid->volatile_fid, (void **)&pntsd, pacllen, in get_smb2_acl_by_fid()
3096 struct cifs_tcon *tcon; in get_smb2_acl_by_path() local
3106 tcon = tlink_tcon(tlink); in get_smb2_acl_by_path()
3111 rc = -ENOMEM; in get_smb2_acl_by_path()
3117 .tcon = tcon, in get_smb2_acl_by_path()
3142 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in get_smb2_acl_by_path()
3161 struct cifs_tcon *tcon; in set_smb2_acl() local
3162 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in set_smb2_acl()
3172 tcon = tlink_tcon(tlink); in set_smb2_acl()
3184 rc = -ENOMEM; in set_smb2_acl()
3190 .tcon = tcon, in set_smb2_acl()
3204 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); in set_smb2_acl()
3226 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info); in get_smb2_acl()
3231 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon, in smb3_zero_data() argument
3234 struct cifsFileInfo *cfile = file->private_data; in smb3_zero_data()
3242 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_zero_data()
3243 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, in smb3_zero_data()
3249 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, in smb3_zero_range() argument
3253 struct cifs_ses *ses = tcon->ses; in smb3_zero_range()
3256 struct cifsFileInfo *cfile = file->private_data; in smb3_zero_range()
3264 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_zero_range()
3265 ses->Suid, offset, len); in smb3_zero_range()
3268 filemap_invalidate_lock(inode->i_mapping); in smb3_zero_range()
3271 remote_size = ictx->remote_i_size; in smb3_zero_range()
3275 rc = filemap_write_and_wait_range(inode->i_mapping, offset, top - 1); in smb3_zero_range()
3284 truncate_pagecache_range(inode, offset, offset + len - 1); in smb3_zero_range()
3287 rc = -EOPNOTSUPP; in smb3_zero_range()
3291 rc = smb3_zero_data(file, tcon, offset, len, xid); in smb3_zero_range()
3300 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb3_zero_range()
3301 cfile->fid.volatile_fid, cfile->pid, new_size); in smb3_zero_range()
3304 netfs_resize_file(&cifsi->netfs, new_size, true); in smb3_zero_range()
3305 if (offset < cifsi->netfs.zero_point) in smb3_zero_range()
3306 cifsi->netfs.zero_point = offset; in smb3_zero_range()
3312 filemap_invalidate_unlock(inode->i_mapping); in smb3_zero_range()
3316 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_zero_range()
3317 ses->Suid, offset, len, rc); in smb3_zero_range()
3319 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_zero_range()
3320 ses->Suid, offset, len); in smb3_zero_range()
3324 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, in smb3_punch_hole() argument
3328 struct cifsFileInfo *cfile = file->private_data; in smb3_punch_hole()
3340 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) { in smb3_punch_hole()
3341 rc = -EOPNOTSUPP; in smb3_punch_hole()
3345 filemap_invalidate_lock(inode->i_mapping); in smb3_punch_hole()
3350 truncate_pagecache_range(inode, offset, offset + len - 1); in smb3_punch_hole()
3357 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_punch_hole()
3358 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, in smb3_punch_hole()
3369 * that we locally hole-punch the tail of the dirty data, the proposed in smb3_punch_hole()
3373 remote_i_size = netfs_inode(inode)->remote_i_size; in smb3_punch_hole()
3376 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb3_punch_hole()
3377 cfile->fid.volatile_fid, cfile->pid, extend_to); in smb3_punch_hole()
3379 netfs_inode(inode)->remote_i_size = extend_to; in smb3_punch_hole()
3383 filemap_invalidate_unlock(inode->i_mapping); in smb3_punch_hole()
3391 struct cifs_tcon *tcon, in smb3_simple_fallocate_write_range() argument
3401 io_parms.netfid = cfile->fid.netfid; in smb3_simple_fallocate_write_range()
3402 io_parms.pid = current->tgid; in smb3_simple_fallocate_write_range()
3403 io_parms.tcon = tcon; in smb3_simple_fallocate_write_range()
3404 io_parms.persistent_fid = cfile->fid.persistent_fid; in smb3_simple_fallocate_write_range()
3405 io_parms.volatile_fid = cfile->fid.volatile_fid; in smb3_simple_fallocate_write_range()
3419 return -EINVAL; in smb3_simple_fallocate_write_range()
3422 len -= nbytes; in smb3_simple_fallocate_write_range()
3428 struct cifs_tcon *tcon, in smb3_simple_fallocate_range() argument
3440 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_simple_fallocate_range()
3441 cfile->fid.volatile_fid, in smb3_simple_fallocate_range()
3451 rc = -ENOMEM; in smb3_simple_fallocate_range()
3461 rc = smb3_simple_fallocate_write_range(xid, tcon, in smb3_simple_fallocate_range()
3467 rc = -EINVAL; in smb3_simple_fallocate_range()
3471 if (off < le64_to_cpu(tmp_data->file_offset)) { in smb3_simple_fallocate_range()
3477 l = le64_to_cpu(tmp_data->file_offset) - off; in smb3_simple_fallocate_range()
3480 rc = smb3_simple_fallocate_write_range(xid, tcon, in smb3_simple_fallocate_range()
3485 len = len - l; in smb3_simple_fallocate_range()
3494 l = le64_to_cpu(tmp_data->length); in smb3_simple_fallocate_range()
3498 len -= l; in smb3_simple_fallocate_range()
3501 out_data_len -= sizeof(struct file_allocated_range_buffer); in smb3_simple_fallocate_range()
3511 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, in smb3_simple_falloc() argument
3516 struct cifsFileInfo *cfile = file->private_data; in smb3_simple_falloc()
3517 long rc = -EOPNOTSUPP; in smb3_simple_falloc()
3523 inode = d_inode(cfile->dentry); in smb3_simple_falloc()
3526 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_simple_falloc()
3527 tcon->ses->Suid, off, len); in smb3_simple_falloc()
3531 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, in smb3_simple_falloc()
3532 tcon->tid, tcon->ses->Suid, off, len, rc); in smb3_simple_falloc()
3545 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) in smb3_simple_falloc()
3546 smb2_set_sparse(xid, tcon, cfile, inode, false); in smb3_simple_falloc()
3549 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb3_simple_falloc()
3550 cfile->fid.volatile_fid, cfile->pid, new_eof); in smb3_simple_falloc()
3552 netfs_resize_file(&cifsi->netfs, new_eof, true); in smb3_simple_falloc()
3554 cifs_truncate_page(inode->i_mapping, inode->i_size); in smb3_simple_falloc()
3561 * Files are non-sparse by default so falloc may be a no-op in smb3_simple_falloc()
3565 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { in smb3_simple_falloc()
3584 len = i_size_read(inode) - off; in smb3_simple_falloc()
3593 * We can either turn the entire file to become non-sparse in smb3_simple_falloc()
3604 rc = smb3_simple_fallocate_range(xid, tcon, cfile, in smb3_simple_falloc()
3615 * or end of the file non-sparse via set_sparse is harmless. in smb3_simple_falloc()
3618 rc = -EOPNOTSUPP; in smb3_simple_falloc()
3623 smb2_set_sparse(xid, tcon, cfile, inode, false); in smb3_simple_falloc()
3628 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_simple_falloc()
3629 tcon->ses->Suid, off, len, rc); in smb3_simple_falloc()
3631 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid, in smb3_simple_falloc()
3632 tcon->ses->Suid, off, len); in smb3_simple_falloc()
3638 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, in smb3_collapse_range() argument
3645 struct cifsFileInfo *cfile = file->private_data; in smb3_collapse_range()
3646 struct netfs_inode *ictx = &cifsi->netfs; in smb3_collapse_range()
3656 rc = -EINVAL; in smb3_collapse_range()
3660 filemap_invalidate_lock(inode->i_mapping); in smb3_collapse_range()
3661 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1); in smb3_collapse_range()
3666 ictx->zero_point = old_eof; in smb3_collapse_range()
3669 old_eof - off - len, off); in smb3_collapse_range()
3673 new_eof = old_eof - len; in smb3_collapse_range()
3674 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb3_collapse_range()
3675 cfile->fid.volatile_fid, cfile->pid, new_eof); in smb3_collapse_range()
3682 netfs_resize_file(&cifsi->netfs, new_eof, true); in smb3_collapse_range()
3683 ictx->zero_point = new_eof; in smb3_collapse_range()
3686 filemap_invalidate_unlock(inode->i_mapping); in smb3_collapse_range()
3693 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, in smb3_insert_range() argument
3698 struct cifsFileInfo *cfile = file->private_data; in smb3_insert_range()
3709 rc = -EINVAL; in smb3_insert_range()
3713 count = old_eof - off; in smb3_insert_range()
3716 filemap_invalidate_lock(inode->i_mapping); in smb3_insert_range()
3717 rc = filemap_write_and_wait_range(inode->i_mapping, off, new_eof - 1); in smb3_insert_range()
3722 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, in smb3_insert_range()
3723 cfile->fid.volatile_fid, cfile->pid, new_eof); in smb3_insert_range()
3728 netfs_resize_file(&cifsi->netfs, i_size_read(inode), true); in smb3_insert_range()
3734 cifsi->netfs.zero_point = new_eof; in smb3_insert_range()
3736 rc = smb3_zero_data(file, tcon, off, len, xid); in smb3_insert_range()
3742 filemap_invalidate_unlock(inode->i_mapping); in smb3_insert_range()
3749 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence) in smb3_llseek() argument
3751 struct cifsFileInfo *wrcfile, *cfile = file->private_data; in smb3_llseek()
3762 inode = d_inode(cfile->dentry); in smb3_llseek()
3766 return -ENXIO; in smb3_llseek()
3778 filemap_write_and_wait(inode->i_mapping); in smb3_llseek()
3779 smb2_flush_file(xid, tcon, &wrcfile->fid); in smb3_llseek()
3783 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) { in smb3_llseek()
3792 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_llseek()
3793 cfile->fid.volatile_fid, in smb3_llseek()
3798 if (rc == -E2BIG) in smb3_llseek()
3807 rc = -ENXIO; in smb3_llseek()
3812 rc = -EINVAL; in smb3_llseek()
3816 offset = le64_to_cpu(out_data->file_offset); in smb3_llseek()
3819 if (offset < le64_to_cpu(out_data->file_offset)) in smb3_llseek()
3822 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length); in smb3_llseek()
3828 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes); in smb3_llseek()
3833 static int smb3_fiemap(struct cifs_tcon *tcon, in smb3_fiemap() argument
3843 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0); in smb3_fiemap()
3852 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid, in smb3_fiemap()
3853 cfile->fid.volatile_fid, in smb3_fiemap()
3858 if (rc == -E2BIG) { in smb3_fiemap()
3867 rc = -EINVAL; in smb3_fiemap()
3871 rc = -EINVAL; in smb3_fiemap()
3878 if (i == num - 1 && last_blob) in smb3_fiemap()
3895 next = le64_to_cpu(out_data[num - 1].file_offset) + in smb3_fiemap()
3896 le64_to_cpu(out_data[num - 1].length); in smb3_fiemap()
3897 len = len - (next - start); in smb3_fiemap()
3908 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, in smb3_fallocate() argument
3913 return smb3_punch_hole(file, tcon, off, len); in smb3_fallocate()
3916 return smb3_zero_range(file, tcon, off, len, true); in smb3_fallocate()
3917 return smb3_zero_range(file, tcon, off, len, false); in smb3_fallocate()
3919 return smb3_simple_falloc(file, tcon, off, len, true); in smb3_fallocate()
3921 return smb3_collapse_range(file, tcon, off, len); in smb3_fallocate()
3923 return smb3_insert_range(file, tcon, off, len); in smb3_fallocate()
3925 return smb3_simple_falloc(file, tcon, off, len, false); in smb3_fallocate()
3927 return -EOPNOTSUPP; in smb3_fallocate()
3935 server->ops->set_oplock_level(cinode, oplock, 0, NULL); in smb2_downgrade_oplock()
3947 unsigned int old_state = cinode->oplock; in smb3_downgrade_oplock()
3948 unsigned int old_epoch = cinode->epoch; in smb3_downgrade_oplock()
3953 cinode->epoch = epoch; in smb3_downgrade_oplock()
3956 new_state = cinode->oplock; in smb3_downgrade_oplock()
3962 else if (old_state == new_state && (epoch - old_epoch > 1)) in smb3_downgrade_oplock()
3971 cinode->lease_granted = false; in smb2_set_oplock_level()
3975 cinode->oplock = CIFS_CACHE_RHW_FLG; in smb2_set_oplock_level()
3977 &cinode->netfs.inode); in smb2_set_oplock_level()
3979 cinode->oplock = CIFS_CACHE_RW_FLG; in smb2_set_oplock_level()
3981 &cinode->netfs.inode); in smb2_set_oplock_level()
3983 cinode->oplock = CIFS_CACHE_READ_FLG; in smb2_set_oplock_level()
3985 &cinode->netfs.inode); in smb2_set_oplock_level()
3987 cinode->oplock = 0; in smb2_set_oplock_level()
3998 cinode->lease_granted = true; in smb21_set_oplock_level()
4022 cinode->oplock = new_oplock; in smb21_set_oplock_level()
4024 &cinode->netfs.inode); in smb21_set_oplock_level()
4031 unsigned int old_oplock = cinode->oplock; in smb3_set_oplock_level()
4038 if (cinode->oplock == CIFS_CACHE_READ_FLG && in smb3_set_oplock_level()
4039 (epoch - cinode->epoch > 0)) in smb3_set_oplock_level()
4041 else if (cinode->oplock == CIFS_CACHE_RH_FLG && in smb3_set_oplock_level()
4042 (epoch - cinode->epoch > 1)) in smb3_set_oplock_level()
4044 else if (cinode->oplock == CIFS_CACHE_RHW_FLG && in smb3_set_oplock_level()
4045 (epoch - cinode->epoch > 1)) in smb3_set_oplock_level()
4047 else if (cinode->oplock == 0 && in smb3_set_oplock_level()
4048 (epoch - cinode->epoch > 0)) in smb3_set_oplock_level()
4051 if (cinode->oplock == CIFS_CACHE_RH_FLG && in smb3_set_oplock_level()
4052 (epoch - cinode->epoch > 0)) in smb3_set_oplock_level()
4054 else if (cinode->oplock == CIFS_CACHE_RHW_FLG && in smb3_set_oplock_level()
4055 (epoch - cinode->epoch > 1)) in smb3_set_oplock_level()
4058 cinode->epoch = epoch; in smb3_set_oplock_level()
4099 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE); in smb2_create_lease_buf()
4100 buf->lcontext.LeaseState = map_oplock_to_lease(oplock); in smb2_create_lease_buf()
4102 buf->ccontext.DataOffset = cpu_to_le16(offsetof in smb2_create_lease_buf()
4104 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); in smb2_create_lease_buf()
4105 buf->ccontext.NameOffset = cpu_to_le16(offsetof in smb2_create_lease_buf()
4107 buf->ccontext.NameLength = cpu_to_le16(4); in smb2_create_lease_buf()
4109 buf->Name[0] = 'R'; in smb2_create_lease_buf()
4110 buf->Name[1] = 'q'; in smb2_create_lease_buf()
4111 buf->Name[2] = 'L'; in smb2_create_lease_buf()
4112 buf->Name[3] = 's'; in smb2_create_lease_buf()
4125 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE); in smb3_create_lease_buf()
4126 buf->lcontext.LeaseState = map_oplock_to_lease(oplock); in smb3_create_lease_buf()
4128 buf->ccontext.DataOffset = cpu_to_le16(offsetof in smb3_create_lease_buf()
4130 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2)); in smb3_create_lease_buf()
4131 buf->ccontext.NameOffset = cpu_to_le16(offsetof in smb3_create_lease_buf()
4133 buf->ccontext.NameLength = cpu_to_le16(4); in smb3_create_lease_buf()
4135 buf->Name[0] = 'R'; in smb3_create_lease_buf()
4136 buf->Name[1] = 'q'; in smb3_create_lease_buf()
4137 buf->Name[2] = 'L'; in smb3_create_lease_buf()
4138 buf->Name[3] = 's'; in smb3_create_lease_buf()
4148 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE) in smb2_parse_lease_buf()
4150 return le32_to_cpu(lc->lcontext.LeaseState); in smb2_parse_lease_buf()
4158 *epoch = le16_to_cpu(lc->lcontext.Epoch); in smb3_parse_lease_buf()
4159 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE) in smb3_parse_lease_buf()
4162 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE); in smb3_parse_lease_buf()
4163 return le32_to_cpu(lc->lcontext.LeaseState); in smb3_parse_lease_buf()
4169 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize, in smb2_wp_retry_size()
4176 return !cfile->invalidHandle; in smb2_dir_needs_close()
4184 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base; in fill_transform_hdr()
4187 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; in fill_transform_hdr()
4188 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len); in fill_transform_hdr()
4189 tr_hdr->Flags = cpu_to_le16(0x01); in fill_transform_hdr()
4192 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE); in fill_transform_hdr()
4194 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE); in fill_transform_hdr()
4195 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8); in fill_transform_hdr()
4213 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1); in smb2_aead_req_alloc()
4222 return ERR_PTR(-ENOMEM); in smb2_aead_req_alloc()
4227 sgt->sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size, in smb2_aead_req_alloc()
4262 rqst[i].rq_iov[j].iov_len - skip); in smb2_get_aead_req()
4270 num_sgs - sgtable.nents, 0); in smb2_get_aead_req()
4276 sg_mark_end(&sgtable.sgl[sgtable.nents - 1]); in smb2_get_aead_req()
4288 /* If server is a channel, select the primary channel */ in smb2_get_enc_key()
4289 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server; in smb2_get_enc_key()
4292 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) { in smb2_get_enc_key()
4293 if (ses->Suid == ses_id) { in smb2_get_enc_key()
4294 spin_lock(&ses->ses_lock); in smb2_get_enc_key()
4295 ses_enc_key = enc ? ses->smb3encryptionkey : in smb2_get_enc_key()
4296 ses->smb3decryptionkey; in smb2_get_enc_key()
4298 spin_unlock(&ses->ses_lock); in smb2_get_enc_key()
4307 return -EAGAIN; in smb2_get_enc_key()
4311 * iov[0] - transform header (associate data),
4312 * iov[1-N] - SMB2 header and pages - data to encrypt.
4313 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4322 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20; in crypt_message()
4329 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize); in crypt_message()
4333 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key); in crypt_message()
4336 enc ? "en" : "de", le64_to_cpu(tr_hdr->SessionId)); in crypt_message()
4340 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) || in crypt_message()
4341 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) in crypt_message()
4363 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE); in crypt_message()
4367 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) || in crypt_message()
4368 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) in crypt_message()
4369 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE); in crypt_message()
4372 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE); in crypt_message()
4382 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE); in crypt_message()
4399 buffer = folioq->next; in cifs_clear_folioq_buffer()
4420 tail->next = p; in cifs_alloc_folioq_buffer()
4421 p->prev = tail; in cifs_alloc_folioq_buffer()
4433 size -= folioq_folio_size(tail, slot); in cifs_alloc_folioq_buffer()
4449 for (; buffer; buffer = buffer->next) { in cifs_copy_iter_to_folioq()
4458 size -= part; in cifs_copy_iter_to_folioq()
4474 * a smb2_transform_hdr and is pre-allocated by the caller.
4481 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4490 int rc = -ENOMEM; in smb3_init_transform_rq()
4493 struct smb_rqst *old = &old_rq[i - 1]; in smb3_init_transform_rq()
4496 size_t size = iov_iter_count(&old->rq_iter); in smb3_init_transform_rq()
4499 new->rq_iov = old->rq_iov; in smb3_init_transform_rq()
4500 new->rq_nvec = old->rq_nvec; in smb3_init_transform_rq()
4507 new->rq_buffer = buffer; in smb3_init_transform_rq()
4508 iov_iter_folio_queue(&new->rq_iter, ITER_SOURCE, in smb3_init_transform_rq()
4511 if (!cifs_copy_iter_to_folioq(&old->rq_iter, size, buffer)) { in smb3_init_transform_rq()
4512 rc = -EIO; in smb3_init_transform_rq()
4519 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type); in smb3_init_transform_rq()
4521 rc = crypt_message(server, num_rqst, new_rq, 1, server->secmech.enc); in smb3_init_transform_rq()
4529 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]); in smb3_init_transform_rq()
4538 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM; in smb3_is_transform_hdr()
4565 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) || in decrypt_raw_data()
4566 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)) in decrypt_raw_data()
4577 if (unlikely(!server->secmech.dec)) in decrypt_raw_data()
4578 return -EIO; in decrypt_raw_data()
4580 tfm = server->secmech.dec; in decrypt_raw_data()
4595 server->total_read = buf_data_size + iter_size; in decrypt_raw_data()
4604 for (; folioq; folioq = folioq->next) { in cifs_copy_folioq_to_iter()
4608 size_t n, len = umin(fsize - skip, data_size); in cifs_copy_folioq_to_iter()
4613 return -EIO; in cifs_copy_folioq_to_iter()
4615 data_size -= n; in cifs_copy_folioq_to_iter()
4633 struct cifs_io_subrequest *rdata = mid->callback_data; in handle_read_data()
4638 if (shdr->Command != SMB2_READ) { in handle_read_data()
4640 return -EOPNOTSUPP; in handle_read_data()
4643 if (server->ops->is_session_expired && in handle_read_data()
4644 server->ops->is_session_expired(buf)) { in handle_read_data()
4647 return -1; in handle_read_data()
4650 if (server->ops->is_status_pending && in handle_read_data()
4651 server->ops->is_status_pending(buf, server)) in handle_read_data()
4652 return -1; in handle_read_data()
4655 rdata->iov[0].iov_base = buf; in handle_read_data()
4656 rdata->iov[0].iov_len = 0; in handle_read_data()
4657 rdata->iov[1].iov_base = buf; in handle_read_data()
4658 rdata->iov[1].iov_len = in handle_read_data()
4659 min_t(unsigned int, buf_len, server->vals->read_rsp_size); in handle_read_data()
4661 rdata->iov[0].iov_base, rdata->iov[0].iov_len); in handle_read_data()
4663 rdata->iov[1].iov_base, rdata->iov[1].iov_len); in handle_read_data()
4665 rdata->result = server->ops->map_error(buf, true); in handle_read_data()
4666 if (rdata->result != 0) { in handle_read_data()
4668 __func__, rdata->result); in handle_read_data()
4671 mid->mid_state = MID_RESPONSE_RECEIVED; in handle_read_data()
4677 data_offset = server->ops->read_data_offset(buf); in handle_read_data()
4679 use_rdma_mr = rdata->mr; in handle_read_data()
4681 data_len = server->ops->read_data_length(buf, use_rdma_mr); in handle_read_data()
4683 if (data_offset < server->vals->read_rsp_size) { in handle_read_data()
4691 data_offset = server->vals->read_rsp_size; in handle_read_data()
4696 rdata->result = -EIO; in handle_read_data()
4698 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4700 dequeue_mid(mid, rdata->result); in handle_read_data()
4704 pad_len = data_offset - server->vals->read_rsp_size; in handle_read_data()
4715 rdata->result = -EIO; in handle_read_data()
4717 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4719 dequeue_mid(mid, rdata->result); in handle_read_data()
4723 if (data_len > buffer_len - pad_len) { in handle_read_data()
4724 /* data_len is corrupt -- discard frame */ in handle_read_data()
4725 rdata->result = -EIO; in handle_read_data()
4727 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4729 dequeue_mid(mid, rdata->result); in handle_read_data()
4734 rdata->result = cifs_copy_folioq_to_iter(buffer, buffer_len, in handle_read_data()
4735 cur_off, &rdata->subreq.io_iter); in handle_read_data()
4736 if (rdata->result != 0) { in handle_read_data()
4738 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4740 dequeue_mid(mid, rdata->result); in handle_read_data()
4743 rdata->got_bytes = buffer_len; in handle_read_data()
4748 length = copy_to_iter(buf + data_offset, data_len, &rdata->subreq.io_iter); in handle_read_data()
4751 rdata->got_bytes = data_len; in handle_read_data()
4755 rdata->result = -EIO; in handle_read_data()
4757 mid->mid_state = MID_RESPONSE_MALFORMED; in handle_read_data()
4759 dequeue_mid(mid, rdata->result); in handle_read_data()
4764 mid->mid_state = MID_RESPONSE_RECEIVED; in handle_read_data()
4787 iov_iter_folio_queue(&iter, ITER_DEST, dw->buffer, 0, 0, dw->len); in smb2_decrypt_offload()
4788 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size, in smb2_decrypt_offload()
4795 dw->server->lstrp = jiffies; in smb2_decrypt_offload()
4796 mid = smb2_find_dequeue_mid(dw->server, dw->buf); in smb2_decrypt_offload()
4800 mid->decrypted = true; in smb2_decrypt_offload()
4801 rc = handle_read_data(dw->server, mid, dw->buf, in smb2_decrypt_offload()
4802 dw->server->vals->read_rsp_size, in smb2_decrypt_offload()
4803 dw->buffer, dw->len, in smb2_decrypt_offload()
4807 mid->when_received = jiffies; in smb2_decrypt_offload()
4809 if (dw->server->ops->is_network_name_deleted) in smb2_decrypt_offload()
4810 dw->server->ops->is_network_name_deleted(dw->buf, in smb2_decrypt_offload()
4811 dw->server); in smb2_decrypt_offload()
4813 mid->callback(mid); in smb2_decrypt_offload()
4815 spin_lock(&dw->server->srv_lock); in smb2_decrypt_offload()
4816 if (dw->server->tcpStatus == CifsNeedReconnect) { in smb2_decrypt_offload()
4817 spin_lock(&dw->server->mid_lock); in smb2_decrypt_offload()
4818 mid->mid_state = MID_RETRY_NEEDED; in smb2_decrypt_offload()
4819 spin_unlock(&dw->server->mid_lock); in smb2_decrypt_offload()
4820 spin_unlock(&dw->server->srv_lock); in smb2_decrypt_offload()
4821 mid->callback(mid); in smb2_decrypt_offload()
4823 spin_lock(&dw->server->mid_lock); in smb2_decrypt_offload()
4824 mid->mid_state = MID_REQUEST_SUBMITTED; in smb2_decrypt_offload()
4825 mid->mid_flags &= ~(MID_DELETED); in smb2_decrypt_offload()
4826 list_add_tail(&mid->qhead, in smb2_decrypt_offload()
4827 &dw->server->pending_mid_q); in smb2_decrypt_offload()
4828 spin_unlock(&dw->server->mid_lock); in smb2_decrypt_offload()
4829 spin_unlock(&dw->server->srv_lock); in smb2_decrypt_offload()
4836 cifs_clear_folioq_buffer(dw->buffer); in smb2_decrypt_offload()
4837 cifs_small_buf_release(dw->buf); in smb2_decrypt_offload()
4846 char *buf = server->smallbuf; in receive_encrypted_read()
4850 unsigned int buflen = server->pdu_size; in receive_encrypted_read()
4856 return -ENOMEM; in receive_encrypted_read()
4857 INIT_WORK(&dw->decrypt, smb2_decrypt_offload); in receive_encrypted_read()
4858 dw->server = server; in receive_encrypted_read()
4861 len = min_t(unsigned int, buflen, server->vals->read_rsp_size + in receive_encrypted_read()
4862 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1; in receive_encrypted_read()
4864 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len); in receive_encrypted_read()
4867 server->total_read += rc; in receive_encrypted_read()
4869 len = le32_to_cpu(tr_hdr->OriginalMessageSize) - in receive_encrypted_read()
4870 server->vals->read_rsp_size; in receive_encrypted_read()
4871 dw->len = len; in receive_encrypted_read()
4872 len = round_up(dw->len, PAGE_SIZE); in receive_encrypted_read()
4874 rc = -ENOMEM; in receive_encrypted_read()
4875 dw->buffer = cifs_alloc_folioq_buffer(len); in receive_encrypted_read()
4876 if (!dw->buffer) in receive_encrypted_read()
4879 iov_iter_folio_queue(&iter, ITER_DEST, dw->buffer, 0, 0, len); in receive_encrypted_read()
4882 rc = cifs_read_iter_from_socket(server, &iter, dw->len); in receive_encrypted_read()
4886 server->total_read += rc; in receive_encrypted_read()
4891 iov_iter_zero(len - rc, &tmp); in receive_encrypted_read()
4893 iov_iter_truncate(&iter, dw->len); in receive_encrypted_read()
4904 if ((server->min_offload) && (server->in_flight > 1) && in receive_encrypted_read()
4905 (server->pdu_size >= server->min_offload)) { in receive_encrypted_read()
4906 dw->buf = server->smallbuf; in receive_encrypted_read()
4907 server->smallbuf = (char *)cifs_small_buf_get(); in receive_encrypted_read()
4909 queue_work(decrypt_wq, &dw->decrypt); in receive_encrypted_read()
4911 return -1; in receive_encrypted_read()
4914 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size, in receive_encrypted_read()
4924 (*mid)->decrypted = true; in receive_encrypted_read()
4926 server->vals->read_rsp_size, in receive_encrypted_read()
4927 dw->buffer, dw->len, false); in receive_encrypted_read()
4929 if (server->ops->is_network_name_deleted) { in receive_encrypted_read()
4930 server->ops->is_network_name_deleted(buf, in receive_encrypted_read()
4937 cifs_clear_folioq_buffer(dw->buffer); in receive_encrypted_read()
4952 char *buf = server->smallbuf; in receive_encrypted_standard()
4954 unsigned int pdu_length = server->pdu_size; in receive_encrypted_standard()
4965 server->large_buf = true; in receive_encrypted_standard()
4966 memcpy(server->bigbuf, buf, server->total_read); in receive_encrypted_standard()
4967 buf = server->bigbuf; in receive_encrypted_standard()
4971 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, in receive_encrypted_standard()
4972 pdu_length - HEADER_SIZE(server) + 1); in receive_encrypted_standard()
4975 server->total_read += length; in receive_encrypted_standard()
4977 buf_size = pdu_length - sizeof(struct smb2_transform_hdr); in receive_encrypted_standard()
4982 next_is_large = server->large_buf; in receive_encrypted_standard()
4985 next_cmd = le32_to_cpu(shdr->NextCommand); in receive_encrypted_standard()
4988 return -1; in receive_encrypted_standard()
4993 memcpy(next_buffer, buf + next_cmd, pdu_length - next_cmd); in receive_encrypted_standard()
5001 mid_entry->decrypted = true; in receive_encrypted_standard()
5002 mid_entry->resp_buf_size = server->pdu_size; in receive_encrypted_standard()
5007 return -1; in receive_encrypted_standard()
5012 if (mid_entry && mid_entry->handle) in receive_encrypted_standard()
5013 ret = mid_entry->handle(server, mid_entry); in receive_encrypted_standard()
5018 pdu_length -= next_cmd; in receive_encrypted_standard()
5019 server->large_buf = next_is_large; in receive_encrypted_standard()
5021 server->bigbuf = buf = next_buffer; in receive_encrypted_standard()
5023 server->smallbuf = buf = next_buffer; in receive_encrypted_standard()
5028 * server->smallbuf and server->bigbuf are still valid. We need in receive_encrypted_standard()
5045 char *buf = server->smallbuf; in smb3_receive_transform()
5046 unsigned int pdu_length = server->pdu_size; in smb3_receive_transform()
5048 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize); in smb3_receive_transform()
5055 return -ECONNABORTED; in smb3_receive_transform()
5061 return -ECONNABORTED; in smb3_receive_transform()
5075 char *buf = server->large_buf ? server->bigbuf : server->smallbuf; in smb3_handle_read_data()
5077 return handle_read_data(server, mid, buf, server->pdu_size, in smb3_handle_read_data()
5087 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) { in smb2_next_header()
5088 *noff = le32_to_cpu(t_hdr->OriginalMessageSize); in smb2_next_header()
5090 return -EINVAL; in smb2_next_header()
5092 *noff = le32_to_cpu(hdr->NextCommand); in smb2_next_header()
5095 return -EINVAL; in smb2_next_header()
5100 struct dentry *dentry, struct cifs_tcon *tcon, in __cifs_sfu_make_node() argument
5104 struct TCP_Server_Info *server = tcon->ses->server; in __cifs_sfu_make_node()
5107 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in __cifs_sfu_make_node()
5120 __u32 oplock = server->oplocks ? REQ_OPLOCK : 0; in __cifs_sfu_make_node()
5144 &data_len, cifs_sb->local_nls, in __cifs_sfu_make_node()
5147 rc = -ENOMEM; in __cifs_sfu_make_node()
5150 data_len -= 2; /* symlink is without trailing wide-nul */ in __cifs_sfu_make_node()
5166 rc = -EPERM; in __cifs_sfu_make_node()
5170 oparms = CIFS_OPARMS(cifs_sb, tcon, full_path, GENERIC_WRITE, in __cifs_sfu_make_node()
5175 rc = server->ops->open(xid, &oparms, &oplock, NULL); in __cifs_sfu_make_node()
5180 io_parms.pid = current->tgid; in __cifs_sfu_make_node()
5181 io_parms.tcon = tcon; in __cifs_sfu_make_node()
5188 rc = server->ops->sync_write(xid, &fid, &io_parms, in __cifs_sfu_make_node()
5190 iov, ARRAY_SIZE(iov)-1); in __cifs_sfu_make_node()
5193 server->ops->close(xid, tcon, &fid); in __cifs_sfu_make_node()
5201 struct dentry *dentry, struct cifs_tcon *tcon, in cifs_sfu_make_node() argument
5207 rc = __cifs_sfu_make_node(xid, inode, dentry, tcon, in cifs_sfu_make_node()
5212 if (tcon->posix_extensions) { in cifs_sfu_make_node()
5214 inode->i_sb, xid); in cifs_sfu_make_node()
5215 } else if (tcon->unix_ext) { in cifs_sfu_make_node()
5217 inode->i_sb, xid); in cifs_sfu_make_node()
5220 inode->i_sb, xid, NULL); in cifs_sfu_make_node()
5228 struct dentry *dentry, struct cifs_tcon *tcon, in smb2_make_node() argument
5231 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); in smb2_make_node()
5240 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) { in smb2_make_node()
5241 rc = cifs_sfu_make_node(xid, inode, dentry, tcon, in smb2_make_node()
5244 rc = smb2_mknod_reparse(xid, inode, dentry, tcon, in smb2_make_node()