forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/fs/cifs/smb2ops.c
....@@ -1,20 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * SMB2 version specific operations
34 *
45 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
5
- *
6
- * This library is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License v2 as published
8
- * by the Free Software Foundation.
9
- *
10
- * This library is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13
- * the GNU Lesser General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Lesser General Public License
16
- * along with this library; if not, write to the Free Software
17
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
186 */
197
208 #include <linux/pagemap.h>
....@@ -22,7 +10,10 @@
2210 #include <linux/falloc.h>
2311 #include <linux/scatterlist.h>
2412 #include <linux/uuid.h>
13
+#include <linux/sort.h>
2514 #include <crypto/aead.h>
15
+#include <linux/fiemap.h>
16
+#include "cifsfs.h"
2617 #include "cifsglob.h"
2718 #include "smb2pdu.h"
2819 #include "smb2proto.h"
....@@ -67,17 +58,29 @@
6758 }
6859
6960 static void
70
-smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
71
- const int optype)
61
+smb2_add_credits(struct TCP_Server_Info *server,
62
+ const struct cifs_credits *credits, const int optype)
7263 {
7364 int *val, rc = -1;
65
+ unsigned int add = credits->value;
66
+ unsigned int instance = credits->instance;
67
+ bool reconnect_detected = false;
7468
7569 spin_lock(&server->req_lock);
7670 val = server->ops->get_credits_field(server, optype);
77
- *val += add;
71
+
72
+ /* eg found case where write overlapping reconnect messed up credits */
73
+ if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
74
+ trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
75
+ server->hostname, *val, add);
76
+ if ((instance == 0) || (instance == server->reconnect_instance))
77
+ *val += add;
78
+ else
79
+ reconnect_detected = true;
80
+
7881 if (*val > 65000) {
7982 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
80
- printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
83
+ pr_warn_once("server overflowed SMB3 credits\n");
8184 }
8285 server->in_flight--;
8386 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
....@@ -96,7 +99,12 @@
9699 spin_unlock(&server->req_lock);
97100 wake_up(&server->request_q);
98101
99
- if (server->tcpStatus == CifsNeedReconnect)
102
+ if (reconnect_detected)
103
+ cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
104
+ add, instance);
105
+
106
+ if (server->tcpStatus == CifsNeedReconnect
107
+ || server->tcpStatus == CifsExiting)
100108 return;
101109
102110 switch (rc) {
....@@ -104,15 +112,17 @@
104112 /* change_conf hasn't been executed */
105113 break;
106114 case 0:
107
- cifs_dbg(VFS, "Possible client or server bug - zero credits\n");
115
+ cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
108116 break;
109117 case 1:
110
- cifs_dbg(VFS, "disabling echoes and oplocks\n");
118
+ cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
111119 break;
112120 case 2:
113121 cifs_dbg(FYI, "disabling oplocks\n");
114122 break;
115123 default:
124
+ trace_smb3_add_credits(server->CurrentMid,
125
+ server->hostname, rc, add);
116126 cifs_dbg(FYI, "add %u credits total=%d\n", add, rc);
117127 }
118128 }
....@@ -122,7 +132,12 @@
122132 {
123133 spin_lock(&server->req_lock);
124134 server->credits = val;
135
+ if (val == 1)
136
+ server->reconnect_instance++;
125137 spin_unlock(&server->req_lock);
138
+ /* don't log while holding the lock */
139
+ if (val == 1)
140
+ cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
126141 }
127142
128143 static int *
....@@ -141,14 +156,12 @@
141156 static unsigned int
142157 smb2_get_credits(struct mid_q_entry *mid)
143158 {
144
- struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf;
145
-
146
- return le16_to_cpu(shdr->CreditRequest);
159
+ return mid->credits_received;
147160 }
148161
149162 static int
150163 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
151
- unsigned int *num, unsigned int *credits)
164
+ unsigned int *num, struct cifs_credits *credits)
152165 {
153166 int rc = 0;
154167 unsigned int scredits;
....@@ -159,7 +172,7 @@
159172 spin_unlock(&server->req_lock);
160173 cifs_num_waiters_inc(server);
161174 rc = wait_event_killable(server->request_q,
162
- has_credits(server, &server->credits));
175
+ has_credits(server, &server->credits, 1));
163176 cifs_num_waiters_dec(server);
164177 if (rc)
165178 return rc;
....@@ -174,7 +187,8 @@
174187 /* can deadlock with reopen */
175188 if (scredits <= 8) {
176189 *num = SMB2_MAX_BUFFER_SIZE;
177
- *credits = 0;
190
+ credits->value = 0;
191
+ credits->instance = 0;
178192 break;
179193 }
180194
....@@ -183,14 +197,50 @@
183197 *num = min_t(unsigned int, size,
184198 scredits * SMB2_MAX_BUFFER_SIZE);
185199
186
- *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
187
- server->credits -= *credits;
200
+ credits->value =
201
+ DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
202
+ credits->instance = server->reconnect_instance;
203
+ server->credits -= credits->value;
188204 server->in_flight++;
205
+ if (server->in_flight > server->max_in_flight)
206
+ server->max_in_flight = server->in_flight;
189207 break;
190208 }
191209 }
192210 spin_unlock(&server->req_lock);
193211 return rc;
212
+}
213
+
214
+static int
215
+smb2_adjust_credits(struct TCP_Server_Info *server,
216
+ struct cifs_credits *credits,
217
+ const unsigned int payload_size)
218
+{
219
+ int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
220
+
221
+ if (!credits->value || credits->value == new_val)
222
+ return 0;
223
+
224
+ if (credits->value < new_val) {
225
+ WARN_ONCE(1, "request has less credits (%d) than required (%d)",
226
+ credits->value, new_val);
227
+ return -ENOTSUPP;
228
+ }
229
+
230
+ spin_lock(&server->req_lock);
231
+
232
+ if (server->reconnect_instance != credits->instance) {
233
+ spin_unlock(&server->req_lock);
234
+ cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
235
+ credits->value - new_val);
236
+ return -EAGAIN;
237
+ }
238
+
239
+ server->credits += credits->value - new_val;
240
+ spin_unlock(&server->req_lock);
241
+ wake_up(&server->request_q);
242
+ credits->value = new_val;
243
+ return 0;
194244 }
195245
196246 static __u64
....@@ -214,14 +264,14 @@
214264 }
215265
216266 static struct mid_q_entry *
217
-smb2_find_mid(struct TCP_Server_Info *server, char *buf)
267
+__smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
218268 {
219269 struct mid_q_entry *mid;
220270 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
221271 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
222272
223273 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
224
- cifs_dbg(VFS, "encrypted frame parsing not supported yet");
274
+ cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
225275 return NULL;
226276 }
227277
....@@ -231,6 +281,10 @@
231281 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
232282 (mid->command == shdr->Command)) {
233283 kref_get(&mid->refcount);
284
+ if (dequeue) {
285
+ list_del_init(&mid->qhead);
286
+ mid->mid_flags |= MID_DELETED;
287
+ }
234288 spin_unlock(&GlobalMid_Lock);
235289 return mid;
236290 }
....@@ -239,16 +293,28 @@
239293 return NULL;
240294 }
241295
296
+static struct mid_q_entry *
297
+smb2_find_mid(struct TCP_Server_Info *server, char *buf)
298
+{
299
+ return __smb2_find_mid(server, buf, false);
300
+}
301
+
302
+static struct mid_q_entry *
303
+smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
304
+{
305
+ return __smb2_find_mid(server, buf, true);
306
+}
307
+
242308 static void
243309 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
244310 {
245311 #ifdef CONFIG_CIFS_DEBUG2
246312 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
247313
248
- cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
314
+ cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
249315 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
250316 shdr->ProcessId);
251
- cifs_dbg(VFS, "smb buf %p len %u\n", buf,
317
+ cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
252318 server->ops->calc_smb_size(buf, server));
253319 #endif
254320 }
....@@ -263,7 +329,8 @@
263329 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
264330 {
265331 int rc;
266
- ses->server->CurrentMid = 0;
332
+
333
+ cifs_ses_server(ses)->CurrentMid = 0;
267334 rc = SMB2_negotiate(xid, ses);
268335 /* BB we probably don't need to retry with modern servers */
269336 if (rc == -EAGAIN)
....@@ -280,11 +347,33 @@
280347 /* start with specified wsize, or default */
281348 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
282349 wsize = min_t(unsigned int, wsize, server->max_write);
350
+ if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
351
+ wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
352
+
353
+ return wsize;
354
+}
355
+
356
+static unsigned int
357
+smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
358
+{
359
+ struct TCP_Server_Info *server = tcon->ses->server;
360
+ unsigned int wsize;
361
+
362
+ /* start with specified wsize, or default */
363
+ wsize = volume_info->wsize ? volume_info->wsize : SMB3_DEFAULT_IOSIZE;
364
+ wsize = min_t(unsigned int, wsize, server->max_write);
283365 #ifdef CONFIG_CIFS_SMB_DIRECT
284366 if (server->rdma) {
285367 if (server->sign)
368
+ /*
369
+ * Account for SMB2 data transfer packet header and
370
+ * possible encryption header
371
+ */
286372 wsize = min_t(unsigned int,
287
- wsize, server->smbd_conn->max_fragmented_send_size);
373
+ wsize,
374
+ server->smbd_conn->max_fragmented_send_size -
375
+ SMB2_READWRITE_PDU_HEADER_SIZE -
376
+ sizeof(struct smb2_transform_hdr));
288377 else
289378 wsize = min_t(unsigned int,
290379 wsize, server->smbd_conn->max_readwrite_size);
....@@ -305,11 +394,34 @@
305394 /* start with specified rsize, or default */
306395 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
307396 rsize = min_t(unsigned int, rsize, server->max_read);
397
+
398
+ if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
399
+ rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
400
+
401
+ return rsize;
402
+}
403
+
404
+static unsigned int
405
+smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
406
+{
407
+ struct TCP_Server_Info *server = tcon->ses->server;
408
+ unsigned int rsize;
409
+
410
+ /* start with specified rsize, or default */
411
+ rsize = volume_info->rsize ? volume_info->rsize : SMB3_DEFAULT_IOSIZE;
412
+ rsize = min_t(unsigned int, rsize, server->max_read);
308413 #ifdef CONFIG_CIFS_SMB_DIRECT
309414 if (server->rdma) {
310415 if (server->sign)
416
+ /*
417
+ * Account for SMB2 data transfer packet header and
418
+ * possible encryption header
419
+ */
311420 rsize = min_t(unsigned int,
312
- rsize, server->smbd_conn->max_fragmented_recv_size);
421
+ rsize,
422
+ server->smbd_conn->max_fragmented_recv_size -
423
+ SMB2_READWRITE_PDU_HEADER_SIZE -
424
+ sizeof(struct smb2_transform_hdr));
313425 else
314426 rsize = min_t(unsigned int,
315427 rsize, server->smbd_conn->max_readwrite_size);
....@@ -321,7 +433,6 @@
321433
322434 return rsize;
323435 }
324
-
325436
326437 static int
327438 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
....@@ -457,6 +568,13 @@
457568 return rc;
458569 }
459570
571
+static int compare_iface(const void *ia, const void *ib)
572
+{
573
+ const struct cifs_server_iface *a = (struct cifs_server_iface *)ia;
574
+ const struct cifs_server_iface *b = (struct cifs_server_iface *)ib;
575
+
576
+ return a->speed == b->speed ? 0 : (a->speed > b->speed ? -1 : 1);
577
+}
460578
461579 static int
462580 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
....@@ -469,15 +587,15 @@
469587 struct cifs_ses *ses = tcon->ses;
470588
471589 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
472
- FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
590
+ FSCTL_QUERY_NETWORK_INTERFACE_INFO,
473591 NULL /* no data input */, 0 /* no data input */,
474
- (char **)&out_buf, &ret_data_len);
592
+ CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
475593 if (rc == -EOPNOTSUPP) {
476594 cifs_dbg(FYI,
477595 "server does not support query network interfaces\n");
478596 goto out;
479597 } else if (rc != 0) {
480
- cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
598
+ cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
481599 goto out;
482600 }
483601
....@@ -485,6 +603,9 @@
485603 &iface_list, &iface_count);
486604 if (rc)
487605 goto out;
606
+
607
+ /* sort interfaces from fastest to slowest */
608
+ sort(iface_list, iface_count, sizeof(*iface_list), compare_iface, NULL);
488609
489610 spin_lock(&ses->iface_lock);
490611 kfree(ses->iface_list);
....@@ -509,6 +630,8 @@
509630 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
510631 cfid->fid->volatile_fid);
511632 cfid->is_valid = false;
633
+ cfid->file_all_info_is_valid = false;
634
+ cfid->has_lease = false;
512635 }
513636 }
514637
....@@ -519,40 +642,60 @@
519642 mutex_unlock(&cfid->fid_mutex);
520643 }
521644
645
+void close_shroot_lease_locked(struct cached_fid *cfid)
646
+{
647
+ if (cfid->has_lease) {
648
+ cfid->has_lease = false;
649
+ kref_put(&cfid->refcount, smb2_close_cached_fid);
650
+ }
651
+}
652
+
653
+void close_shroot_lease(struct cached_fid *cfid)
654
+{
655
+ mutex_lock(&cfid->fid_mutex);
656
+ close_shroot_lease_locked(cfid);
657
+ mutex_unlock(&cfid->fid_mutex);
658
+}
659
+
522660 void
523661 smb2_cached_lease_break(struct work_struct *work)
524662 {
525663 struct cached_fid *cfid = container_of(work,
526664 struct cached_fid, lease_break);
527665
528
- close_shroot(cfid);
666
+ close_shroot_lease(cfid);
529667 }
530668
531669 /*
532670 * Open the directory at the root of a share
533671 */
534
-int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
672
+int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
673
+ struct cifs_sb_info *cifs_sb,
674
+ struct cached_fid **cfid)
535675 {
536
- struct cifs_open_parms oparams;
537
- int rc;
538
- __le16 srch_path = 0; /* Null - since an open of top of share */
676
+ struct cifs_ses *ses = tcon->ses;
677
+ struct TCP_Server_Info *server = ses->server;
678
+ struct cifs_open_parms oparms;
679
+ struct smb2_create_rsp *o_rsp = NULL;
680
+ struct smb2_query_info_rsp *qi_rsp = NULL;
681
+ int resp_buftype[2];
682
+ struct smb_rqst rqst[2];
683
+ struct kvec rsp_iov[2];
684
+ struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
685
+ struct kvec qi_iov[1];
686
+ int rc, flags = 0;
687
+ __le16 utf16_path = 0; /* Null - since an open of top of share */
539688 u8 oplock = SMB2_OPLOCK_LEVEL_II;
689
+ struct cifs_fid *pfid;
540690
541691 mutex_lock(&tcon->crfid.fid_mutex);
542692 if (tcon->crfid.is_valid) {
543693 cifs_dbg(FYI, "found a cached root file handle\n");
544
- memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
694
+ *cfid = &tcon->crfid;
545695 kref_get(&tcon->crfid.refcount);
546696 mutex_unlock(&tcon->crfid.fid_mutex);
547697 return 0;
548698 }
549
-
550
- oparams.tcon = tcon;
551
- oparams.create_options = 0;
552
- oparams.desired_access = FILE_READ_ATTRIBUTES;
553
- oparams.disposition = FILE_OPEN;
554
- oparams.fid = pfid;
555
- oparams.reconnect = false;
556699
557700 /*
558701 * We do not hold the lock for the open because in case
....@@ -560,8 +703,58 @@
560703 * cifs_mark_open_files_invalid() which takes the lock again
561704 * thus causing a deadlock
562705 */
706
+
563707 mutex_unlock(&tcon->crfid.fid_mutex);
564
- rc = SMB2_open(xid, &oparams, &srch_path, &oplock, NULL, NULL, NULL);
708
+
709
+ if (smb3_encryption_required(tcon))
710
+ flags |= CIFS_TRANSFORM_REQ;
711
+
712
+ if (!server->ops->new_lease_key)
713
+ return -EIO;
714
+
715
+ pfid = tcon->crfid.fid;
716
+ server->ops->new_lease_key(pfid);
717
+
718
+ memset(rqst, 0, sizeof(rqst));
719
+ resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
720
+ memset(rsp_iov, 0, sizeof(rsp_iov));
721
+
722
+ /* Open */
723
+ memset(&open_iov, 0, sizeof(open_iov));
724
+ rqst[0].rq_iov = open_iov;
725
+ rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
726
+
727
+ oparms.tcon = tcon;
728
+ oparms.create_options = cifs_create_options(cifs_sb, 0);
729
+ oparms.desired_access = FILE_READ_ATTRIBUTES;
730
+ oparms.disposition = FILE_OPEN;
731
+ oparms.fid = pfid;
732
+ oparms.reconnect = false;
733
+
734
+ rc = SMB2_open_init(tcon, server,
735
+ &rqst[0], &oplock, &oparms, &utf16_path);
736
+ if (rc)
737
+ goto oshr_free;
738
+ smb2_set_next_command(tcon, &rqst[0]);
739
+
740
+ memset(&qi_iov, 0, sizeof(qi_iov));
741
+ rqst[1].rq_iov = qi_iov;
742
+ rqst[1].rq_nvec = 1;
743
+
744
+ rc = SMB2_query_info_init(tcon, server,
745
+ &rqst[1], COMPOUND_FID,
746
+ COMPOUND_FID, FILE_ALL_INFORMATION,
747
+ SMB2_O_INFO_FILE, 0,
748
+ sizeof(struct smb2_file_all_info) +
749
+ PATH_MAX * 2, 0, NULL);
750
+ if (rc)
751
+ goto oshr_free;
752
+
753
+ smb2_set_related(&rqst[1]);
754
+
755
+ rc = compound_send_recv(xid, ses, server,
756
+ flags, 2, rqst,
757
+ resp_buftype, rsp_iov);
565758 mutex_lock(&tcon->crfid.fid_mutex);
566759
567760 /*
....@@ -579,9 +772,9 @@
579772 };
580773
581774 /*
582
- * Caller expects this func to set pfid to a valid
775
+ * caller expects this func to set pfid to a valid
583776 * cached root, so we copy the existing one and get a
584
- * reference
777
+ * reference.
585778 */
586779 memcpy(pfid, tcon->crfid.fid, sizeof(*pfid));
587780 kref_get(&tcon->crfid.refcount);
....@@ -589,29 +782,74 @@
589782 mutex_unlock(&tcon->crfid.fid_mutex);
590783
591784 if (rc == 0) {
592
- /* close extra handle outside of critical section */
593
- SMB2_close(xid, tcon, fid.persistent_fid,
594
- fid.volatile_fid);
785
+ /* close extra handle outside of crit sec */
786
+ SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
595787 }
596
- return 0;
788
+ rc = 0;
789
+ goto oshr_free;
597790 }
598791
599792 /* Cached root is still invalid, continue normaly */
600793
601
- if (rc == 0) {
602
- memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
603
- tcon->crfid.tcon = tcon;
604
- tcon->crfid.is_valid = true;
605
- kref_init(&tcon->crfid.refcount);
606
- kref_get(&tcon->crfid.refcount);
794
+ if (rc) {
795
+ if (rc == -EREMCHG) {
796
+ tcon->need_reconnect = true;
797
+ pr_warn_once("server share %s deleted\n",
798
+ tcon->treeName);
799
+ }
800
+ goto oshr_exit;
607801 }
608802
803
+ atomic_inc(&tcon->num_remote_opens);
804
+
805
+ o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
806
+ oparms.fid->persistent_fid = o_rsp->PersistentFileId;
807
+ oparms.fid->volatile_fid = o_rsp->VolatileFileId;
808
+#ifdef CONFIG_CIFS_DEBUG2
809
+ oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId);
810
+#endif /* CIFS_DEBUG2 */
811
+
812
+ memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
813
+ tcon->crfid.tcon = tcon;
814
+ tcon->crfid.is_valid = true;
815
+ kref_init(&tcon->crfid.refcount);
816
+
817
+ /* BB TBD check to see if oplock level check can be removed below */
818
+ if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) {
819
+ kref_get(&tcon->crfid.refcount);
820
+ tcon->crfid.has_lease = true;
821
+ smb2_parse_contexts(server, o_rsp,
822
+ &oparms.fid->epoch,
823
+ oparms.fid->lease_key, &oplock,
824
+ NULL, NULL);
825
+ } else
826
+ goto oshr_exit;
827
+
828
+ qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
829
+ if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))
830
+ goto oshr_exit;
831
+ if (!smb2_validate_and_copy_iov(
832
+ le16_to_cpu(qi_rsp->OutputBufferOffset),
833
+ sizeof(struct smb2_file_all_info),
834
+ &rsp_iov[1], sizeof(struct smb2_file_all_info),
835
+ (char *)&tcon->crfid.file_all_info))
836
+ tcon->crfid.file_all_info_is_valid = true;
837
+
838
+oshr_exit:
609839 mutex_unlock(&tcon->crfid.fid_mutex);
840
+oshr_free:
841
+ SMB2_open_free(&rqst[0]);
842
+ SMB2_query_info_free(&rqst[1]);
843
+ free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
844
+ free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
845
+ if (rc == 0)
846
+ *cfid = &tcon->crfid;
610847 return rc;
611848 }
612849
613850 static void
614
-smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
851
+smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
852
+ struct cifs_sb_info *cifs_sb)
615853 {
616854 int rc;
617855 __le16 srch_path = 0; /* Null - open root of share */
....@@ -619,20 +857,23 @@
619857 struct cifs_open_parms oparms;
620858 struct cifs_fid fid;
621859 bool no_cached_open = tcon->nohandlecache;
860
+ struct cached_fid *cfid = NULL;
622861
623862 oparms.tcon = tcon;
624863 oparms.desired_access = FILE_READ_ATTRIBUTES;
625864 oparms.disposition = FILE_OPEN;
626
- oparms.create_options = 0;
865
+ oparms.create_options = cifs_create_options(cifs_sb, 0);
627866 oparms.fid = &fid;
628867 oparms.reconnect = false;
629868
630
- if (no_cached_open)
869
+ if (no_cached_open) {
631870 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
632
- NULL);
633
- else
634
- rc = open_shroot(xid, tcon, &fid);
635
-
871
+ NULL, NULL);
872
+ } else {
873
+ rc = open_shroot(xid, tcon, cifs_sb, &cfid);
874
+ if (rc == 0)
875
+ memcpy(&fid, cfid->fid, sizeof(struct cifs_fid));
876
+ }
636877 if (rc)
637878 return;
638879
....@@ -649,13 +890,12 @@
649890 if (no_cached_open)
650891 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
651892 else
652
- close_shroot(&tcon->crfid);
653
-
654
- return;
893
+ close_shroot(cfid);
655894 }
656895
657896 static void
658
-smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
897
+smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
898
+ struct cifs_sb_info *cifs_sb)
659899 {
660900 int rc;
661901 __le16 srch_path = 0; /* Null - open root of share */
....@@ -666,11 +906,12 @@
666906 oparms.tcon = tcon;
667907 oparms.desired_access = FILE_READ_ATTRIBUTES;
668908 oparms.disposition = FILE_OPEN;
669
- oparms.create_options = 0;
909
+ oparms.create_options = cifs_create_options(cifs_sb, 0);
670910 oparms.fid = &fid;
671911 oparms.reconnect = false;
672912
673
- rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
913
+ rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
914
+ NULL, NULL);
674915 if (rc)
675916 return;
676917
....@@ -679,7 +920,6 @@
679920 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
680921 FS_DEVICE_INFORMATION);
681922 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
682
- return;
683923 }
684924
685925 static int
....@@ -702,14 +942,12 @@
702942 oparms.tcon = tcon;
703943 oparms.desired_access = FILE_READ_ATTRIBUTES;
704944 oparms.disposition = FILE_OPEN;
705
- if (backup_cred(cifs_sb))
706
- oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
707
- else
708
- oparms.create_options = 0;
945
+ oparms.create_options = cifs_create_options(cifs_sb, 0);
709946 oparms.fid = &fid;
710947 oparms.reconnect = false;
711948
712
- rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
949
+ rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
950
+ NULL);
713951 if (rc) {
714952 kfree(utf16_path);
715953 return rc;
....@@ -762,20 +1000,20 @@
7621000 size_t name_len, value_len, user_name_len;
7631001
7641002 while (src_size > 0) {
765
- name = &src->ea_data[0];
7661003 name_len = (size_t)src->ea_name_length;
767
- value = &src->ea_data[src->ea_name_length + 1];
7681004 value_len = (size_t)le16_to_cpu(src->ea_value_length);
7691005
770
- if (name_len == 0) {
1006
+ if (name_len == 0)
7711007 break;
772
- }
7731008
7741009 if (src_size < 8 + name_len + 1 + value_len) {
7751010 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
7761011 rc = -EIO;
7771012 goto out;
7781013 }
1014
+
1015
+ name = &src->ea_data[0];
1016
+ value = &src->ea_data[src->ea_name_length + 1];
7791017
7801018 if (ea_name) {
7811019 if (ea_name_len == name_len &&
....@@ -842,72 +1080,50 @@
8421080 {
8431081 int rc;
8441082 __le16 *utf16_path;
845
- __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
846
- struct cifs_open_parms oparms;
847
- struct cifs_fid fid;
848
- struct smb2_file_full_ea_info *smb2_data;
849
- int ea_buf_size = SMB2_MIN_EA_BUF;
1083
+ struct kvec rsp_iov = {NULL, 0};
1084
+ int buftype = CIFS_NO_BUFFER;
1085
+ struct smb2_query_info_rsp *rsp;
1086
+ struct smb2_file_full_ea_info *info = NULL;
8501087
8511088 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
8521089 if (!utf16_path)
8531090 return -ENOMEM;
8541091
855
- oparms.tcon = tcon;
856
- oparms.desired_access = FILE_READ_EA;
857
- oparms.disposition = FILE_OPEN;
858
- if (backup_cred(cifs_sb))
859
- oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
860
- else
861
- oparms.create_options = 0;
862
- oparms.fid = &fid;
863
- oparms.reconnect = false;
864
-
865
- rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
866
- kfree(utf16_path);
1092
+ rc = smb2_query_info_compound(xid, tcon, utf16_path,
1093
+ FILE_READ_EA,
1094
+ FILE_FULL_EA_INFORMATION,
1095
+ SMB2_O_INFO_FILE,
1096
+ CIFSMaxBufSize -
1097
+ MAX_SMB2_CREATE_RESPONSE_SIZE -
1098
+ MAX_SMB2_CLOSE_RESPONSE_SIZE,
1099
+ &rsp_iov, &buftype, cifs_sb);
8671100 if (rc) {
868
- cifs_dbg(FYI, "open failed rc=%d\n", rc);
869
- return rc;
1101
+ /*
1102
+ * If ea_name is NULL (listxattr) and there are no EAs,
1103
+ * return 0 as it's not an error. Otherwise, the specified
1104
+ * ea_name was not found.
1105
+ */
1106
+ if (!ea_name && rc == -ENODATA)
1107
+ rc = 0;
1108
+ goto qeas_exit;
8701109 }
8711110
872
- while (1) {
873
- smb2_data = kzalloc(ea_buf_size, GFP_KERNEL);
874
- if (smb2_data == NULL) {
875
- SMB2_close(xid, tcon, fid.persistent_fid,
876
- fid.volatile_fid);
877
- return -ENOMEM;
878
- }
1111
+ rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1112
+ rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1113
+ le32_to_cpu(rsp->OutputBufferLength),
1114
+ &rsp_iov,
1115
+ sizeof(struct smb2_file_full_ea_info));
1116
+ if (rc)
1117
+ goto qeas_exit;
8791118
880
- rc = SMB2_query_eas(xid, tcon, fid.persistent_fid,
881
- fid.volatile_fid,
882
- ea_buf_size, smb2_data);
1119
+ info = (struct smb2_file_full_ea_info *)(
1120
+ le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1121
+ rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1122
+ le32_to_cpu(rsp->OutputBufferLength), ea_name);
8831123
884
- if (rc != -E2BIG)
885
- break;
886
-
887
- kfree(smb2_data);
888
- ea_buf_size <<= 1;
889
-
890
- if (ea_buf_size > SMB2_MAX_EA_BUF) {
891
- cifs_dbg(VFS, "EA size is too large\n");
892
- SMB2_close(xid, tcon, fid.persistent_fid,
893
- fid.volatile_fid);
894
- return -ENOMEM;
895
- }
896
- }
897
-
898
- SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
899
-
900
- /*
901
- * If ea_name is NULL (listxattr) and there are no EAs, return 0 as it's
902
- * not an error. Otherwise, the specified ea_name was not found.
903
- */
904
- if (!rc)
905
- rc = move_smb2_ea_to_cifs(ea_data, buf_size, smb2_data,
906
- SMB2_MAX_EA_BUF, ea_name);
907
- else if (!ea_name && rc == -ENODATA)
908
- rc = 0;
909
-
910
- kfree(smb2_data);
1124
+ qeas_exit:
1125
+ kfree(utf16_path);
1126
+ free_rsp_buf(buftype, rsp_iov.iov_base);
9111127 return rc;
9121128 }
9131129
....@@ -918,14 +1134,29 @@
9181134 const __u16 ea_value_len, const struct nls_table *nls_codepage,
9191135 struct cifs_sb_info *cifs_sb)
9201136 {
921
- int rc;
922
- __le16 *utf16_path;
923
- __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
924
- struct cifs_open_parms oparms;
925
- struct cifs_fid fid;
926
- struct smb2_file_full_ea_info *ea;
1137
+ struct cifs_ses *ses = tcon->ses;
1138
+ struct TCP_Server_Info *server = cifs_pick_channel(ses);
1139
+ __le16 *utf16_path = NULL;
9271140 int ea_name_len = strlen(ea_name);
1141
+ int flags = CIFS_CP_CREATE_CLOSE_OP;
9281142 int len;
1143
+ struct smb_rqst rqst[3];
1144
+ int resp_buftype[3];
1145
+ struct kvec rsp_iov[3];
1146
+ struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1147
+ struct cifs_open_parms oparms;
1148
+ __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1149
+ struct cifs_fid fid;
1150
+ struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1151
+ unsigned int size[1];
1152
+ void *data[1];
1153
+ struct smb2_file_full_ea_info *ea = NULL;
1154
+ struct kvec close_iov[1];
1155
+ struct smb2_query_info_rsp *rsp;
1156
+ int rc, used_len = 0;
1157
+
1158
+ if (smb3_encryption_required(tcon))
1159
+ flags |= CIFS_TRANSFORM_REQ;
9291160
9301161 if (ea_name_len > 255)
9311162 return -EINVAL;
....@@ -934,28 +1165,82 @@
9341165 if (!utf16_path)
9351166 return -ENOMEM;
9361167
1168
+ memset(rqst, 0, sizeof(rqst));
1169
+ resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1170
+ memset(rsp_iov, 0, sizeof(rsp_iov));
1171
+
1172
+ if (ses->server->ops->query_all_EAs) {
1173
+ if (!ea_value) {
1174
+ rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1175
+ ea_name, NULL, 0,
1176
+ cifs_sb);
1177
+ if (rc == -ENODATA)
1178
+ goto sea_exit;
1179
+ } else {
1180
+ /* If we are adding a attribute we should first check
1181
+ * if there will be enough space available to store
1182
+ * the new EA. If not we should not add it since we
1183
+ * would not be able to even read the EAs back.
1184
+ */
1185
+ rc = smb2_query_info_compound(xid, tcon, utf16_path,
1186
+ FILE_READ_EA,
1187
+ FILE_FULL_EA_INFORMATION,
1188
+ SMB2_O_INFO_FILE,
1189
+ CIFSMaxBufSize -
1190
+ MAX_SMB2_CREATE_RESPONSE_SIZE -
1191
+ MAX_SMB2_CLOSE_RESPONSE_SIZE,
1192
+ &rsp_iov[1], &resp_buftype[1], cifs_sb);
1193
+ if (rc == 0) {
1194
+ rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1195
+ used_len = le32_to_cpu(rsp->OutputBufferLength);
1196
+ }
1197
+ free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1198
+ resp_buftype[1] = CIFS_NO_BUFFER;
1199
+ memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1200
+ rc = 0;
1201
+
1202
+ /* Use a fudge factor of 256 bytes in case we collide
1203
+ * with a different set_EAs command.
1204
+ */
1205
+ if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1206
+ MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1207
+ used_len + ea_name_len + ea_value_len + 1) {
1208
+ rc = -ENOSPC;
1209
+ goto sea_exit;
1210
+ }
1211
+ }
1212
+ }
1213
+
1214
+ /* Open */
1215
+ memset(&open_iov, 0, sizeof(open_iov));
1216
+ rqst[0].rq_iov = open_iov;
1217
+ rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1218
+
1219
+ memset(&oparms, 0, sizeof(oparms));
9371220 oparms.tcon = tcon;
9381221 oparms.desired_access = FILE_WRITE_EA;
9391222 oparms.disposition = FILE_OPEN;
940
- if (backup_cred(cifs_sb))
941
- oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
942
- else
943
- oparms.create_options = 0;
1223
+ oparms.create_options = cifs_create_options(cifs_sb, 0);
9441224 oparms.fid = &fid;
9451225 oparms.reconnect = false;
9461226
947
- rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
948
- kfree(utf16_path);
949
- if (rc) {
950
- cifs_dbg(FYI, "open failed rc=%d\n", rc);
951
- return rc;
952
- }
1227
+ rc = SMB2_open_init(tcon, server,
1228
+ &rqst[0], &oplock, &oparms, utf16_path);
1229
+ if (rc)
1230
+ goto sea_exit;
1231
+ smb2_set_next_command(tcon, &rqst[0]);
1232
+
1233
+
1234
+ /* Set Info */
1235
+ memset(&si_iov, 0, sizeof(si_iov));
1236
+ rqst[1].rq_iov = si_iov;
1237
+ rqst[1].rq_nvec = 1;
9531238
9541239 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
9551240 ea = kzalloc(len, GFP_KERNEL);
9561241 if (ea == NULL) {
957
- SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
958
- return -ENOMEM;
1242
+ rc = -ENOMEM;
1243
+ goto sea_exit;
9591244 }
9601245
9611246 ea->ea_name_length = ea_name_len;
....@@ -963,12 +1248,44 @@
9631248 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
9641249 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
9651250
966
- rc = SMB2_set_ea(xid, tcon, fid.persistent_fid, fid.volatile_fid, ea,
967
- len);
1251
+ size[0] = len;
1252
+ data[0] = ea;
1253
+
1254
+ rc = SMB2_set_info_init(tcon, server,
1255
+ &rqst[1], COMPOUND_FID,
1256
+ COMPOUND_FID, current->tgid,
1257
+ FILE_FULL_EA_INFORMATION,
1258
+ SMB2_O_INFO_FILE, 0, data, size);
1259
+ if (rc)
1260
+ goto sea_exit;
1261
+ smb2_set_next_command(tcon, &rqst[1]);
1262
+ smb2_set_related(&rqst[1]);
1263
+
1264
+
1265
+ /* Close */
1266
+ memset(&close_iov, 0, sizeof(close_iov));
1267
+ rqst[2].rq_iov = close_iov;
1268
+ rqst[2].rq_nvec = 1;
1269
+ rc = SMB2_close_init(tcon, server,
1270
+ &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1271
+ if (rc)
1272
+ goto sea_exit;
1273
+ smb2_set_related(&rqst[2]);
1274
+
1275
+ rc = compound_send_recv(xid, ses, server,
1276
+ flags, 3, rqst,
1277
+ resp_buftype, rsp_iov);
1278
+ /* no need to bump num_remote_opens because handle immediately closed */
1279
+
1280
+ sea_exit:
9681281 kfree(ea);
969
-
970
- SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
971
-
1282
+ kfree(utf16_path);
1283
+ SMB2_open_free(&rqst[0]);
1284
+ SMB2_set_info_free(&rqst[1]);
1285
+ SMB2_close_free(&rqst[2]);
1286
+ free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1287
+ free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1288
+ free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
9721289 return rc;
9731290 }
9741291 #endif
....@@ -983,6 +1300,7 @@
9831300 smb2_clear_stats(struct cifs_tcon *tcon)
9841301 {
9851302 int i;
1303
+
9861304 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
9871305 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
9881306 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
....@@ -1035,6 +1353,9 @@
10351353 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
10361354 (long long)(tcon->bytes_read),
10371355 (long long)(tcon->bytes_written));
1356
+ seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1357
+ atomic_read(&tcon->num_local_opens),
1358
+ atomic_read(&tcon->num_remote_opens));
10381359 seq_printf(m, "\nTreeConnects: %d total %d failed",
10391360 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
10401361 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
....@@ -1087,6 +1408,10 @@
10871408
10881409 cfile->fid.persistent_fid = fid->persistent_fid;
10891410 cfile->fid.volatile_fid = fid->volatile_fid;
1411
+ cfile->fid.access = fid->access;
1412
+#ifdef CONFIG_CIFS_DEBUG2
1413
+ cfile->fid.mid = fid->mid;
1414
+#endif /* CIFS_DEBUG2 */
10901415 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
10911416 &fid->purge_cache);
10921417 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
....@@ -1100,6 +1425,45 @@
11001425 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
11011426 }
11021427
1428
+static void
1429
+smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1430
+ struct cifsFileInfo *cfile)
1431
+{
1432
+ struct smb2_file_network_open_info file_inf;
1433
+ struct inode *inode;
1434
+ int rc;
1435
+
1436
+ rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1437
+ cfile->fid.volatile_fid, &file_inf);
1438
+ if (rc)
1439
+ return;
1440
+
1441
+ inode = d_inode(cfile->dentry);
1442
+
1443
+ spin_lock(&inode->i_lock);
1444
+ CIFS_I(inode)->time = jiffies;
1445
+
1446
+ /* Creation time should not need to be updated on close */
1447
+ if (file_inf.LastWriteTime)
1448
+ inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1449
+ if (file_inf.ChangeTime)
1450
+ inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1451
+ if (file_inf.LastAccessTime)
1452
+ inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1453
+
1454
+ /*
1455
+ * i_blocks is not related to (i_size / i_blksize),
1456
+ * but instead 512 byte (2**9) size is required for
1457
+ * calculating num blocks.
1458
+ */
1459
+ if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1460
+ inode->i_blocks =
1461
+ (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1462
+
1463
+ /* End of file and Attributes should not have to be updated on close */
1464
+ spin_unlock(&inode->i_lock);
1465
+}
1466
+
11031467 static int
11041468 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
11051469 u64 persistent_fid, u64 volatile_fid,
....@@ -1110,16 +1474,15 @@
11101474 struct resume_key_req *res_key;
11111475
11121476 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1113
- FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
1114
- NULL, 0 /* no input */,
1115
- (char **)&res_key, &ret_data_len);
1477
+ FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1478
+ CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
11161479
11171480 if (rc) {
1118
- cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1481
+ cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
11191482 goto req_res_key_exit;
11201483 }
11211484 if (ret_data_len < sizeof(struct resume_key_req)) {
1122
- cifs_dbg(VFS, "Invalid refcopy resume key length\n");
1485
+ cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
11231486 rc = -EINVAL;
11241487 goto req_res_key_exit;
11251488 }
....@@ -1127,6 +1490,247 @@
11271490
11281491 req_res_key_exit:
11291492 kfree(res_key);
1493
+ return rc;
1494
+}
1495
+
1496
+struct iqi_vars {
1497
+ struct smb_rqst rqst[3];
1498
+ struct kvec rsp_iov[3];
1499
+ struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1500
+ struct kvec qi_iov[1];
1501
+ struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1502
+ struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1503
+ struct kvec close_iov[1];
1504
+};
1505
+
1506
+static int
1507
+smb2_ioctl_query_info(const unsigned int xid,
1508
+ struct cifs_tcon *tcon,
1509
+ struct cifs_sb_info *cifs_sb,
1510
+ __le16 *path, int is_dir,
1511
+ unsigned long p)
1512
+{
1513
+ struct iqi_vars *vars;
1514
+ struct smb_rqst *rqst;
1515
+ struct kvec *rsp_iov;
1516
+ struct cifs_ses *ses = tcon->ses;
1517
+ struct TCP_Server_Info *server = cifs_pick_channel(ses);
1518
+ char __user *arg = (char __user *)p;
1519
+ struct smb_query_info qi;
1520
+ struct smb_query_info __user *pqi;
1521
+ int rc = 0;
1522
+ int flags = CIFS_CP_CREATE_CLOSE_OP;
1523
+ struct smb2_query_info_rsp *qi_rsp = NULL;
1524
+ struct smb2_ioctl_rsp *io_rsp = NULL;
1525
+ void *buffer = NULL;
1526
+ int resp_buftype[3];
1527
+ struct cifs_open_parms oparms;
1528
+ u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1529
+ struct cifs_fid fid;
1530
+ unsigned int size[2];
1531
+ void *data[2];
1532
+ int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1533
+ void (*free_req1_func)(struct smb_rqst *r);
1534
+
1535
+ vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1536
+ if (vars == NULL)
1537
+ return -ENOMEM;
1538
+ rqst = &vars->rqst[0];
1539
+ rsp_iov = &vars->rsp_iov[0];
1540
+
1541
+ resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1542
+
1543
+ if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1544
+ rc = -EFAULT;
1545
+ goto free_vars;
1546
+ }
1547
+ if (qi.output_buffer_length > 1024) {
1548
+ rc = -EINVAL;
1549
+ goto free_vars;
1550
+ }
1551
+
1552
+ if (!ses || !server) {
1553
+ rc = -EIO;
1554
+ goto free_vars;
1555
+ }
1556
+
1557
+ if (smb3_encryption_required(tcon))
1558
+ flags |= CIFS_TRANSFORM_REQ;
1559
+
1560
+ if (qi.output_buffer_length) {
1561
+ buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1562
+ if (IS_ERR(buffer)) {
1563
+ rc = PTR_ERR(buffer);
1564
+ goto free_vars;
1565
+ }
1566
+ }
1567
+
1568
+ /* Open */
1569
+ rqst[0].rq_iov = &vars->open_iov[0];
1570
+ rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1571
+
1572
+ memset(&oparms, 0, sizeof(oparms));
1573
+ oparms.tcon = tcon;
1574
+ oparms.disposition = FILE_OPEN;
1575
+ oparms.create_options = cifs_create_options(cifs_sb, create_options);
1576
+ oparms.fid = &fid;
1577
+ oparms.reconnect = false;
1578
+
1579
+ if (qi.flags & PASSTHRU_FSCTL) {
1580
+ switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1581
+ case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1582
+ oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1583
+ break;
1584
+ case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1585
+ oparms.desired_access = GENERIC_ALL;
1586
+ break;
1587
+ case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1588
+ oparms.desired_access = GENERIC_READ;
1589
+ break;
1590
+ case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1591
+ oparms.desired_access = GENERIC_WRITE;
1592
+ break;
1593
+ }
1594
+ } else if (qi.flags & PASSTHRU_SET_INFO) {
1595
+ oparms.desired_access = GENERIC_WRITE;
1596
+ } else {
1597
+ oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1598
+ }
1599
+
1600
+ rc = SMB2_open_init(tcon, server,
1601
+ &rqst[0], &oplock, &oparms, path);
1602
+ if (rc)
1603
+ goto free_output_buffer;
1604
+ smb2_set_next_command(tcon, &rqst[0]);
1605
+
1606
+ /* Query */
1607
+ if (qi.flags & PASSTHRU_FSCTL) {
1608
+ /* Can eventually relax perm check since server enforces too */
1609
+ if (!capable(CAP_SYS_ADMIN)) {
1610
+ rc = -EPERM;
1611
+ goto free_open_req;
1612
+ }
1613
+ rqst[1].rq_iov = &vars->io_iov[0];
1614
+ rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1615
+
1616
+ rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1617
+ qi.info_type, buffer, qi.output_buffer_length,
1618
+ CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1619
+ MAX_SMB2_CLOSE_RESPONSE_SIZE);
1620
+ free_req1_func = SMB2_ioctl_free;
1621
+ } else if (qi.flags == PASSTHRU_SET_INFO) {
1622
+ /* Can eventually relax perm check since server enforces too */
1623
+ if (!capable(CAP_SYS_ADMIN)) {
1624
+ rc = -EPERM;
1625
+ goto free_open_req;
1626
+ }
1627
+ if (qi.output_buffer_length < 8) {
1628
+ rc = -EINVAL;
1629
+ goto free_open_req;
1630
+ }
1631
+ rqst[1].rq_iov = &vars->si_iov[0];
1632
+ rqst[1].rq_nvec = 1;
1633
+
1634
+ /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1635
+ size[0] = 8;
1636
+ data[0] = buffer;
1637
+
1638
+ rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1639
+ current->tgid, FILE_END_OF_FILE_INFORMATION,
1640
+ SMB2_O_INFO_FILE, 0, data, size);
1641
+ free_req1_func = SMB2_set_info_free;
1642
+ } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1643
+ rqst[1].rq_iov = &vars->qi_iov[0];
1644
+ rqst[1].rq_nvec = 1;
1645
+
1646
+ rc = SMB2_query_info_init(tcon, server,
1647
+ &rqst[1], COMPOUND_FID,
1648
+ COMPOUND_FID, qi.file_info_class,
1649
+ qi.info_type, qi.additional_information,
1650
+ qi.input_buffer_length,
1651
+ qi.output_buffer_length, buffer);
1652
+ free_req1_func = SMB2_query_info_free;
1653
+ } else { /* unknown flags */
1654
+ cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1655
+ qi.flags);
1656
+ rc = -EINVAL;
1657
+ }
1658
+
1659
+ if (rc)
1660
+ goto free_open_req;
1661
+ smb2_set_next_command(tcon, &rqst[1]);
1662
+ smb2_set_related(&rqst[1]);
1663
+
1664
+ /* Close */
1665
+ rqst[2].rq_iov = &vars->close_iov[0];
1666
+ rqst[2].rq_nvec = 1;
1667
+
1668
+ rc = SMB2_close_init(tcon, server,
1669
+ &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1670
+ if (rc)
1671
+ goto free_req_1;
1672
+ smb2_set_related(&rqst[2]);
1673
+
1674
+ rc = compound_send_recv(xid, ses, server,
1675
+ flags, 3, rqst,
1676
+ resp_buftype, rsp_iov);
1677
+ if (rc)
1678
+ goto out;
1679
+
1680
+ /* No need to bump num_remote_opens since handle immediately closed */
1681
+ if (qi.flags & PASSTHRU_FSCTL) {
1682
+ pqi = (struct smb_query_info __user *)arg;
1683
+ io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1684
+ if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1685
+ qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1686
+ if (qi.input_buffer_length > 0 &&
1687
+ le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1688
+ > rsp_iov[1].iov_len) {
1689
+ rc = -EFAULT;
1690
+ goto out;
1691
+ }
1692
+
1693
+ if (copy_to_user(&pqi->input_buffer_length,
1694
+ &qi.input_buffer_length,
1695
+ sizeof(qi.input_buffer_length))) {
1696
+ rc = -EFAULT;
1697
+ goto out;
1698
+ }
1699
+
1700
+ if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1701
+ (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1702
+ qi.input_buffer_length))
1703
+ rc = -EFAULT;
1704
+ } else {
1705
+ pqi = (struct smb_query_info __user *)arg;
1706
+ qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1707
+ if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1708
+ qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1709
+ if (copy_to_user(&pqi->input_buffer_length,
1710
+ &qi.input_buffer_length,
1711
+ sizeof(qi.input_buffer_length))) {
1712
+ rc = -EFAULT;
1713
+ goto out;
1714
+ }
1715
+
1716
+ if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1717
+ qi.input_buffer_length))
1718
+ rc = -EFAULT;
1719
+ }
1720
+
1721
+out:
1722
+ free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1723
+ free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1724
+ free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1725
+ SMB2_close_free(&rqst[2]);
1726
+free_req_1:
1727
+ free_req1_func(&rqst[1]);
1728
+free_open_req:
1729
+ SMB2_open_free(&rqst[0]);
1730
+free_output_buffer:
1731
+ kfree(buffer);
1732
+free_vars:
1733
+ kfree(vars);
11301734 return rc;
11311735 }
11321736
....@@ -1144,13 +1748,21 @@
11441748 int chunks_copied = 0;
11451749 bool chunk_sizes_updated = false;
11461750 ssize_t bytes_written, total_bytes_written = 0;
1751
+ struct inode *inode;
11471752
11481753 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1754
+
1755
+ /*
1756
+ * We need to flush all unwritten data before we can send the
1757
+ * copychunk ioctl to the server.
1758
+ */
1759
+ inode = d_inode(trgtfile->dentry);
1760
+ filemap_write_and_wait(inode->i_mapping);
11491761
11501762 if (pcchunk == NULL)
11511763 return -ENOMEM;
11521764
1153
- cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
1765
+ cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
11541766 /* Request a key from the server to identify the source of the copy */
11551767 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
11561768 srcfile->fid.persistent_fid,
....@@ -1178,13 +1790,12 @@
11781790 retbuf = NULL;
11791791 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
11801792 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1181
- true /* is_fsctl */, (char *)pcchunk,
1182
- sizeof(struct copychunk_ioctl), (char **)&retbuf,
1183
- &ret_data_len);
1793
+ (char *)pcchunk, sizeof(struct copychunk_ioctl),
1794
+ CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
11841795 if (rc == 0) {
11851796 if (ret_data_len !=
11861797 sizeof(struct copychunk_ioctl_rsp)) {
1187
- cifs_dbg(VFS, "invalid cchunk response size\n");
1798
+ cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
11881799 rc = -EIO;
11891800 goto cchunk_out;
11901801 }
....@@ -1198,12 +1809,12 @@
11981809 */
11991810 if (le32_to_cpu(retbuf->TotalBytesWritten) >
12001811 le32_to_cpu(pcchunk->Length)) {
1201
- cifs_dbg(VFS, "invalid copy chunk response\n");
1812
+ cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
12021813 rc = -EIO;
12031814 goto cchunk_out;
12041815 }
12051816 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1206
- cifs_dbg(VFS, "invalid num chunks written\n");
1817
+ cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
12071818 rc = -EIO;
12081819 goto cchunk_out;
12091820 }
....@@ -1272,6 +1883,7 @@
12721883 smb2_read_data_offset(char *buf)
12731884 {
12741885 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1886
+
12751887 return rsp->DataOffset;
12761888 }
12771889
....@@ -1339,8 +1951,7 @@
13391951
13401952 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
13411953 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1342
- true /* is_fctl */,
1343
- &setsparse, 1, NULL, NULL);
1954
+ &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
13441955 if (rc) {
13451956 tcon->broken_sparse_sup = true;
13461957 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
....@@ -1376,7 +1987,7 @@
13761987 }
13771988
13781989 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1379
- cfile->fid.volatile_fid, cfile->pid, &eof, false);
1990
+ cfile->fid.volatile_fid, cfile->pid, &eof);
13801991 }
13811992
13821993 static int
....@@ -1387,6 +1998,7 @@
13871998 {
13881999 int rc;
13892000 unsigned int ret_data_len;
2001
+ struct inode *inode;
13902002 struct duplicate_extents_to_file dup_ext_buf;
13912003 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
13922004
....@@ -1400,24 +2012,34 @@
14002012 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
14012013 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
14022014 dup_ext_buf.ByteCount = cpu_to_le64(len);
1403
- cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
2015
+ cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
14042016 src_off, dest_off, len);
14052017
1406
- rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1407
- if (rc)
1408
- goto duplicate_extents_out;
2018
+ inode = d_inode(trgtfile->dentry);
2019
+ if (inode->i_size < dest_off + len) {
2020
+ rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
2021
+ if (rc)
2022
+ goto duplicate_extents_out;
14092023
2024
+ /*
2025
+ * Although also could set plausible allocation size (i_blocks)
2026
+ * here in addition to setting the file size, in reflink
2027
+ * it is likely that the target file is sparse. Its allocation
2028
+ * size will be queried on next revalidate, but it is important
2029
+ * to make sure that file's cached size is updated immediately
2030
+ */
2031
+ cifs_setsize(inode, dest_off + len);
2032
+ }
14102033 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
14112034 trgtfile->fid.volatile_fid,
14122035 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1413
- true /* is_fsctl */,
14142036 (char *)&dup_ext_buf,
14152037 sizeof(struct duplicate_extents_to_file),
1416
- NULL,
2038
+ CIFSMaxBufSize, NULL,
14172039 &ret_data_len);
14182040
14192041 if (ret_data_len > 0)
1420
- cifs_dbg(FYI, "non-zero response length in duplicate extents");
2042
+ cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
14212043
14222044 duplicate_extents_out:
14232045 return rc;
....@@ -1445,16 +2067,17 @@
14452067 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
14462068 cfile->fid.volatile_fid,
14472069 FSCTL_SET_INTEGRITY_INFORMATION,
1448
- true /* is_fsctl */,
14492070 (char *)&integr_info,
14502071 sizeof(struct fsctl_set_integrity_information_req),
1451
- NULL,
2072
+ CIFSMaxBufSize, NULL,
14522073 &ret_data_len);
14532074
14542075 }
14552076
14562077 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
14572078 #define GMT_TOKEN_SIZE 50
2079
+
2080
+#define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
14582081
14592082 /*
14602083 * Input buffer contains (empty) struct smb_snapshot array with size filled in
....@@ -1467,13 +2090,36 @@
14672090 char *retbuf = NULL;
14682091 unsigned int ret_data_len = 0;
14692092 int rc;
2093
+ u32 max_response_size;
14702094 struct smb_snapshot_array snapshot_in;
2095
+
2096
+ /*
2097
+ * On the first query to enumerate the list of snapshots available
2098
+ * for this volume the buffer begins with 0 (number of snapshots
2099
+ * which can be returned is zero since at that point we do not know
2100
+ * how big the buffer needs to be). On the second query,
2101
+ * it (ret_data_len) is set to number of snapshots so we can
2102
+ * know to set the maximum response size larger (see below).
2103
+ */
2104
+ if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2105
+ return -EFAULT;
2106
+
2107
+ /*
2108
+ * Note that for snapshot queries that servers like Azure expect that
2109
+ * the first query be minimal size (and just used to get the number/size
2110
+ * of previous versions) so response size must be specified as EXACTLY
2111
+ * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2112
+ * of eight bytes.
2113
+ */
2114
+ if (ret_data_len == 0)
2115
+ max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2116
+ else
2117
+ max_response_size = CIFSMaxBufSize;
14712118
14722119 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
14732120 cfile->fid.volatile_fid,
14742121 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1475
- true /* is_fsctl */,
1476
- NULL, 0 /* no input data */,
2122
+ NULL, 0 /* no input data */, max_response_size,
14772123 (char **)&retbuf,
14782124 &ret_data_len);
14792125 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
....@@ -1519,6 +2165,67 @@
15192165 return rc;
15202166 }
15212167
2168
+
2169
+
2170
+static int
2171
+smb3_notify(const unsigned int xid, struct file *pfile,
2172
+ void __user *ioc_buf)
2173
+{
2174
+ struct smb3_notify notify;
2175
+ struct dentry *dentry = pfile->f_path.dentry;
2176
+ struct inode *inode = file_inode(pfile);
2177
+ struct cifs_sb_info *cifs_sb;
2178
+ struct cifs_open_parms oparms;
2179
+ struct cifs_fid fid;
2180
+ struct cifs_tcon *tcon;
2181
+ unsigned char *path = NULL;
2182
+ __le16 *utf16_path = NULL;
2183
+ u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2184
+ int rc = 0;
2185
+
2186
+ path = build_path_from_dentry(dentry);
2187
+ if (path == NULL)
2188
+ return -ENOMEM;
2189
+
2190
+ cifs_sb = CIFS_SB(inode->i_sb);
2191
+
2192
+ utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2193
+ if (utf16_path == NULL) {
2194
+ rc = -ENOMEM;
2195
+ goto notify_exit;
2196
+ }
2197
+
2198
+ if (copy_from_user(&notify, ioc_buf, sizeof(struct smb3_notify))) {
2199
+ rc = -EFAULT;
2200
+ goto notify_exit;
2201
+ }
2202
+
2203
+ tcon = cifs_sb_master_tcon(cifs_sb);
2204
+ oparms.tcon = tcon;
2205
+ oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2206
+ oparms.disposition = FILE_OPEN;
2207
+ oparms.create_options = cifs_create_options(cifs_sb, 0);
2208
+ oparms.fid = &fid;
2209
+ oparms.reconnect = false;
2210
+
2211
+ rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2212
+ NULL);
2213
+ if (rc)
2214
+ goto notify_exit;
2215
+
2216
+ rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2217
+ notify.watch_tree, notify.completion_filter);
2218
+
2219
+ SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2220
+
2221
+ cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2222
+
2223
+notify_exit:
2224
+ kfree(path);
2225
+ kfree(utf16_path);
2226
+ return rc;
2227
+}
2228
+
15222229 static int
15232230 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
15242231 const char *path, struct cifs_sb_info *cifs_sb,
....@@ -1526,40 +2233,115 @@
15262233 struct cifs_search_info *srch_inf)
15272234 {
15282235 __le16 *utf16_path;
1529
- int rc;
1530
- __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2236
+ struct smb_rqst rqst[2];
2237
+ struct kvec rsp_iov[2];
2238
+ int resp_buftype[2];
2239
+ struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2240
+ struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2241
+ int rc, flags = 0;
2242
+ u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
15312243 struct cifs_open_parms oparms;
2244
+ struct smb2_query_directory_rsp *qd_rsp = NULL;
2245
+ struct smb2_create_rsp *op_rsp = NULL;
2246
+ struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
15322247
15332248 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
15342249 if (!utf16_path)
15352250 return -ENOMEM;
15362251
2252
+ if (smb3_encryption_required(tcon))
2253
+ flags |= CIFS_TRANSFORM_REQ;
2254
+
2255
+ memset(rqst, 0, sizeof(rqst));
2256
+ resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2257
+ memset(rsp_iov, 0, sizeof(rsp_iov));
2258
+
2259
+ /* Open */
2260
+ memset(&open_iov, 0, sizeof(open_iov));
2261
+ rqst[0].rq_iov = open_iov;
2262
+ rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2263
+
15372264 oparms.tcon = tcon;
15382265 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
15392266 oparms.disposition = FILE_OPEN;
1540
- if (backup_cred(cifs_sb))
1541
- oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1542
- else
1543
- oparms.create_options = 0;
2267
+ oparms.create_options = cifs_create_options(cifs_sb, 0);
15442268 oparms.fid = fid;
15452269 oparms.reconnect = false;
15462270
1547
- rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
1548
- kfree(utf16_path);
1549
- if (rc) {
1550
- cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
1551
- return rc;
1552
- }
2271
+ rc = SMB2_open_init(tcon, server,
2272
+ &rqst[0], &oplock, &oparms, utf16_path);
2273
+ if (rc)
2274
+ goto qdf_free;
2275
+ smb2_set_next_command(tcon, &rqst[0]);
15532276
2277
+ /* Query directory */
15542278 srch_inf->entries_in_buffer = 0;
15552279 srch_inf->index_of_last_entry = 2;
15562280
1557
- rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
1558
- fid->volatile_fid, 0, srch_inf);
1559
- if (rc) {
1560
- cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
1561
- SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2281
+ memset(&qd_iov, 0, sizeof(qd_iov));
2282
+ rqst[1].rq_iov = qd_iov;
2283
+ rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2284
+
2285
+ rc = SMB2_query_directory_init(xid, tcon, server,
2286
+ &rqst[1],
2287
+ COMPOUND_FID, COMPOUND_FID,
2288
+ 0, srch_inf->info_level);
2289
+ if (rc)
2290
+ goto qdf_free;
2291
+
2292
+ smb2_set_related(&rqst[1]);
2293
+
2294
+ rc = compound_send_recv(xid, tcon->ses, server,
2295
+ flags, 2, rqst,
2296
+ resp_buftype, rsp_iov);
2297
+
2298
+ /* If the open failed there is nothing to do */
2299
+ op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2300
+ if (op_rsp == NULL || op_rsp->sync_hdr.Status != STATUS_SUCCESS) {
2301
+ cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2302
+ goto qdf_free;
15622303 }
2304
+ fid->persistent_fid = op_rsp->PersistentFileId;
2305
+ fid->volatile_fid = op_rsp->VolatileFileId;
2306
+
2307
+ /* Anything else than ENODATA means a genuine error */
2308
+ if (rc && rc != -ENODATA) {
2309
+ SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2310
+ cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2311
+ trace_smb3_query_dir_err(xid, fid->persistent_fid,
2312
+ tcon->tid, tcon->ses->Suid, 0, 0, rc);
2313
+ goto qdf_free;
2314
+ }
2315
+
2316
+ atomic_inc(&tcon->num_remote_opens);
2317
+
2318
+ qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2319
+ if (qd_rsp->sync_hdr.Status == STATUS_NO_MORE_FILES) {
2320
+ trace_smb3_query_dir_done(xid, fid->persistent_fid,
2321
+ tcon->tid, tcon->ses->Suid, 0, 0);
2322
+ srch_inf->endOfSearch = true;
2323
+ rc = 0;
2324
+ goto qdf_free;
2325
+ }
2326
+
2327
+ rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2328
+ srch_inf);
2329
+ if (rc) {
2330
+ trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2331
+ tcon->ses->Suid, 0, 0, rc);
2332
+ goto qdf_free;
2333
+ }
2334
+ resp_buftype[1] = CIFS_NO_BUFFER;
2335
+
2336
+ trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2337
+ tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2338
+
2339
+ qdf_free:
2340
+ kfree(utf16_path);
2341
+ SMB2_open_free(&rqst[0]);
2342
+ SMB2_query_directory_free(&rqst[1]);
2343
+ free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2344
+ free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
15632345 return rc;
15642346 }
15652347
....@@ -1580,18 +2362,18 @@
15802362 }
15812363
15822364 /*
1583
-* If we negotiate SMB2 protocol and get STATUS_PENDING - update
1584
-* the number of credits and return true. Otherwise - return false.
1585
-*/
2365
+ * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2366
+ * the number of credits and return true. Otherwise - return false.
2367
+ */
15862368 static bool
1587
-smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
2369
+smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
15882370 {
15892371 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
15902372
15912373 if (shdr->Status != STATUS_PENDING)
15922374 return false;
15932375
1594
- if (!length) {
2376
+ if (shdr->CreditRequest) {
15952377 spin_lock(&server->req_lock);
15962378 server->credits += le16_to_cpu(shdr->CreditRequest);
15972379 spin_unlock(&server->req_lock);
....@@ -1618,6 +2400,17 @@
16182400 return true;
16192401 }
16202402
2403
+static bool
2404
+smb2_is_status_io_timeout(char *buf)
2405
+{
2406
+ struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2407
+
2408
+ if (shdr->Status == STATUS_IO_TIMEOUT)
2409
+ return true;
2410
+ else
2411
+ return false;
2412
+}
2413
+
16212414 static int
16222415 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
16232416 struct cifsInodeInfo *cinode)
....@@ -1631,61 +2424,108 @@
16312424 CIFS_CACHE_READ(cinode) ? 1 : 0);
16322425 }
16332426
1634
-static void
2427
+void
16352428 smb2_set_related(struct smb_rqst *rqst)
16362429 {
16372430 struct smb2_sync_hdr *shdr;
16382431
16392432 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2433
+ if (shdr == NULL) {
2434
+ cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2435
+ return;
2436
+ }
16402437 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
16412438 }
16422439
16432440 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
16442441
1645
-static void
1646
-smb2_set_next_command(struct TCP_Server_Info *server, struct smb_rqst *rqst)
2442
+void
2443
+smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
16472444 {
16482445 struct smb2_sync_hdr *shdr;
2446
+ struct cifs_ses *ses = tcon->ses;
2447
+ struct TCP_Server_Info *server = ses->server;
16492448 unsigned long len = smb_rqst_len(server, rqst);
1650
-
1651
- /* SMB headers in a compound are 8 byte aligned. */
1652
- if (len & 7) {
1653
- rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
1654
- rqst->rq_iov[rqst->rq_nvec].iov_len = 8 - (len & 7);
1655
- rqst->rq_nvec++;
1656
- len = smb_rqst_len(server, rqst);
1657
- }
2449
+ int i, num_padding;
16582450
16592451 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2452
+ if (shdr == NULL) {
2453
+ cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2454
+ return;
2455
+ }
2456
+
2457
+ /* SMB headers in a compound are 8 byte aligned. */
2458
+
2459
+ /* No padding needed */
2460
+ if (!(len & 7))
2461
+ goto finished;
2462
+
2463
+ num_padding = 8 - (len & 7);
2464
+ if (!smb3_encryption_required(tcon)) {
2465
+ /*
2466
+ * If we do not have encryption then we can just add an extra
2467
+ * iov for the padding.
2468
+ */
2469
+ rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2470
+ rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2471
+ rqst->rq_nvec++;
2472
+ len += num_padding;
2473
+ } else {
2474
+ /*
2475
+ * We can not add a small padding iov for the encryption case
2476
+ * because the encryption framework can not handle the padding
2477
+ * iovs.
2478
+ * We have to flatten this into a single buffer and add
2479
+ * the padding to it.
2480
+ */
2481
+ for (i = 1; i < rqst->rq_nvec; i++) {
2482
+ memcpy(rqst->rq_iov[0].iov_base +
2483
+ rqst->rq_iov[0].iov_len,
2484
+ rqst->rq_iov[i].iov_base,
2485
+ rqst->rq_iov[i].iov_len);
2486
+ rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2487
+ }
2488
+ memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2489
+ 0, num_padding);
2490
+ rqst->rq_iov[0].iov_len += num_padding;
2491
+ len += num_padding;
2492
+ rqst->rq_nvec = 1;
2493
+ }
2494
+
2495
+ finished:
16602496 shdr->NextCommand = cpu_to_le32(len);
16612497 }
16622498
1663
-static int
1664
-smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1665
- struct kstatfs *buf)
2499
+/*
2500
+ * Passes the query info response back to the caller on success.
2501
+ * Caller need to free this with free_rsp_buf().
2502
+ */
2503
+int
2504
+smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2505
+ __le16 *utf16_path, u32 desired_access,
2506
+ u32 class, u32 type, u32 output_len,
2507
+ struct kvec *rsp, int *buftype,
2508
+ struct cifs_sb_info *cifs_sb)
16662509 {
1667
- struct smb2_query_info_rsp *rsp;
1668
- struct smb2_fs_full_size_info *info = NULL;
2510
+ struct cifs_ses *ses = tcon->ses;
2511
+ struct TCP_Server_Info *server = cifs_pick_channel(ses);
2512
+ int flags = CIFS_CP_CREATE_CLOSE_OP;
16692513 struct smb_rqst rqst[3];
16702514 int resp_buftype[3];
16712515 struct kvec rsp_iov[3];
16722516 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
16732517 struct kvec qi_iov[1];
16742518 struct kvec close_iov[1];
1675
- struct cifs_ses *ses = tcon->ses;
1676
- struct TCP_Server_Info *server = ses->server;
1677
- __le16 srch_path = 0; /* Null - open root of share */
16782519 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
16792520 struct cifs_open_parms oparms;
16802521 struct cifs_fid fid;
1681
- int flags = 0;
16822522 int rc;
16832523
16842524 if (smb3_encryption_required(tcon))
16852525 flags |= CIFS_TRANSFORM_REQ;
16862526
16872527 memset(rqst, 0, sizeof(rqst));
1688
- memset(resp_buftype, 0, sizeof(resp_buftype));
2528
+ resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
16892529 memset(rsp_iov, 0, sizeof(rsp_iov));
16902530
16912531 memset(&open_iov, 0, sizeof(open_iov));
....@@ -1693,68 +2533,106 @@
16932533 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
16942534
16952535 oparms.tcon = tcon;
1696
- oparms.desired_access = FILE_READ_ATTRIBUTES;
2536
+ oparms.desired_access = desired_access;
16972537 oparms.disposition = FILE_OPEN;
1698
- oparms.create_options = 0;
2538
+ oparms.create_options = cifs_create_options(cifs_sb, 0);
16992539 oparms.fid = &fid;
17002540 oparms.reconnect = false;
17012541
1702
- rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, &srch_path);
2542
+ rc = SMB2_open_init(tcon, server,
2543
+ &rqst[0], &oplock, &oparms, utf16_path);
17032544 if (rc)
1704
- goto qfs_exit;
1705
- smb2_set_next_command(server, &rqst[0]);
2545
+ goto qic_exit;
2546
+ smb2_set_next_command(tcon, &rqst[0]);
17062547
17072548 memset(&qi_iov, 0, sizeof(qi_iov));
17082549 rqst[1].rq_iov = qi_iov;
17092550 rqst[1].rq_nvec = 1;
17102551
1711
- rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1712
- FS_FULL_SIZE_INFORMATION,
1713
- SMB2_O_INFO_FILESYSTEM, 0,
1714
- sizeof(struct smb2_fs_full_size_info));
2552
+ rc = SMB2_query_info_init(tcon, server,
2553
+ &rqst[1], COMPOUND_FID, COMPOUND_FID,
2554
+ class, type, 0,
2555
+ output_len, 0,
2556
+ NULL);
17152557 if (rc)
1716
- goto qfs_exit;
1717
- smb2_set_next_command(server, &rqst[1]);
2558
+ goto qic_exit;
2559
+ smb2_set_next_command(tcon, &rqst[1]);
17182560 smb2_set_related(&rqst[1]);
17192561
17202562 memset(&close_iov, 0, sizeof(close_iov));
17212563 rqst[2].rq_iov = close_iov;
17222564 rqst[2].rq_nvec = 1;
17232565
1724
- rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
2566
+ rc = SMB2_close_init(tcon, server,
2567
+ &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
17252568 if (rc)
1726
- goto qfs_exit;
2569
+ goto qic_exit;
17272570 smb2_set_related(&rqst[2]);
17282571
1729
- rc = compound_send_recv(xid, ses, flags, 3, rqst,
2572
+ rc = compound_send_recv(xid, ses, server,
2573
+ flags, 3, rqst,
17302574 resp_buftype, rsp_iov);
1731
- if (rc)
1732
- goto qfs_exit;
2575
+ if (rc) {
2576
+ free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2577
+ if (rc == -EREMCHG) {
2578
+ tcon->need_reconnect = true;
2579
+ pr_warn_once("server share %s deleted\n",
2580
+ tcon->treeName);
2581
+ }
2582
+ goto qic_exit;
2583
+ }
2584
+ *rsp = rsp_iov[1];
2585
+ *buftype = resp_buftype[1];
17332586
1734
- rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1735
- buf->f_type = SMB2_MAGIC_NUMBER;
1736
- info = (struct smb2_fs_full_size_info *)(
1737
- le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1738
- rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1739
- le32_to_cpu(rsp->OutputBufferLength),
1740
- &rsp_iov[1],
1741
- sizeof(struct smb2_fs_full_size_info));
1742
- if (!rc)
1743
- smb2_copy_fs_info_to_kstatfs(info, buf);
1744
-
1745
-qfs_exit:
2587
+ qic_exit:
17462588 SMB2_open_free(&rqst[0]);
17472589 SMB2_query_info_free(&rqst[1]);
17482590 SMB2_close_free(&rqst[2]);
17492591 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1750
- free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
17512592 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
17522593 return rc;
17532594 }
17542595
17552596 static int
2597
+smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2598
+ struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2599
+{
2600
+ struct smb2_query_info_rsp *rsp;
2601
+ struct smb2_fs_full_size_info *info = NULL;
2602
+ __le16 utf16_path = 0; /* Null - open root of share */
2603
+ struct kvec rsp_iov = {NULL, 0};
2604
+ int buftype = CIFS_NO_BUFFER;
2605
+ int rc;
2606
+
2607
+
2608
+ rc = smb2_query_info_compound(xid, tcon, &utf16_path,
2609
+ FILE_READ_ATTRIBUTES,
2610
+ FS_FULL_SIZE_INFORMATION,
2611
+ SMB2_O_INFO_FILESYSTEM,
2612
+ sizeof(struct smb2_fs_full_size_info),
2613
+ &rsp_iov, &buftype, cifs_sb);
2614
+ if (rc)
2615
+ goto qfs_exit;
2616
+
2617
+ rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2618
+ buf->f_type = SMB2_MAGIC_NUMBER;
2619
+ info = (struct smb2_fs_full_size_info *)(
2620
+ le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2621
+ rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2622
+ le32_to_cpu(rsp->OutputBufferLength),
2623
+ &rsp_iov,
2624
+ sizeof(struct smb2_fs_full_size_info));
2625
+ if (!rc)
2626
+ smb2_copy_fs_info_to_kstatfs(info, buf);
2627
+
2628
+qfs_exit:
2629
+ free_rsp_buf(buftype, rsp_iov.iov_base);
2630
+ return rc;
2631
+}
2632
+
2633
+static int
17562634 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1757
- struct kstatfs *buf)
2635
+ struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
17582636 {
17592637 int rc;
17602638 __le16 srch_path = 0; /* Null - open root of share */
....@@ -1763,16 +2641,17 @@
17632641 struct cifs_fid fid;
17642642
17652643 if (!tcon->posix_extensions)
1766
- return smb2_queryfs(xid, tcon, buf);
2644
+ return smb2_queryfs(xid, tcon, cifs_sb, buf);
17672645
17682646 oparms.tcon = tcon;
17692647 oparms.desired_access = FILE_READ_ATTRIBUTES;
17702648 oparms.disposition = FILE_OPEN;
1771
- oparms.create_options = 0;
2649
+ oparms.create_options = cifs_create_options(cifs_sb, 0);
17722650 oparms.fid = &fid;
17732651 oparms.reconnect = false;
17742652
1775
- rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
2653
+ rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2654
+ NULL, NULL);
17762655 if (rc)
17772656 return rc;
17782657
....@@ -1834,7 +2713,7 @@
18342713 struct get_dfs_referral_rsp *dfs_rsp = NULL;
18352714 u32 dfs_req_size = 0, dfs_rsp_size = 0;
18362715
1837
- cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
2716
+ cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
18382717
18392718 /*
18402719 * Try to use the IPC tcon, otherwise just use any
....@@ -1881,14 +2760,13 @@
18812760 do {
18822761 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
18832762 FSCTL_DFS_GET_REFERRALS,
1884
- true /* is_fsctl */,
1885
- (char *)dfs_req, dfs_req_size,
2763
+ (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
18862764 (char **)&dfs_rsp, &dfs_rsp_size);
18872765 } while (rc == -EAGAIN);
18882766
18892767 if (rc) {
18902768 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
1891
- cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
2769
+ cifs_tcon_dbg(VFS, "ioctl error in %s rc=%d\n", __func__, rc);
18922770 goto out;
18932771 }
18942772
....@@ -1897,7 +2775,7 @@
18972775 nls_codepage, remap, search_name,
18982776 true /* is_unicode */);
18992777 if (rc) {
1900
- cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
2778
+ cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
19012779 goto out;
19022780 }
19032781
....@@ -1913,76 +2791,266 @@
19132791 kfree(dfs_rsp);
19142792 return rc;
19152793 }
2794
+
2795
+static int
2796
+parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2797
+ u32 plen, char **target_path,
2798
+ struct cifs_sb_info *cifs_sb)
2799
+{
2800
+ unsigned int len;
2801
+
2802
+ /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2803
+ len = le16_to_cpu(symlink_buf->ReparseDataLength);
2804
+
2805
+ if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2806
+ cifs_dbg(VFS, "%lld not a supported symlink type\n",
2807
+ le64_to_cpu(symlink_buf->InodeType));
2808
+ return -EOPNOTSUPP;
2809
+ }
2810
+
2811
+ *target_path = cifs_strndup_from_utf16(
2812
+ symlink_buf->PathBuffer,
2813
+ len, true, cifs_sb->local_nls);
2814
+ if (!(*target_path))
2815
+ return -ENOMEM;
2816
+
2817
+ convert_delimiter(*target_path, '/');
2818
+ cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2819
+
2820
+ return 0;
2821
+}
2822
+
2823
+static int
2824
+parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2825
+ u32 plen, char **target_path,
2826
+ struct cifs_sb_info *cifs_sb)
2827
+{
2828
+ unsigned int sub_len;
2829
+ unsigned int sub_offset;
2830
+
2831
+ /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2832
+
2833
+ sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2834
+ sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2835
+ if (sub_offset + 20 > plen ||
2836
+ sub_offset + sub_len + 20 > plen) {
2837
+ cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2838
+ return -EIO;
2839
+ }
2840
+
2841
+ *target_path = cifs_strndup_from_utf16(
2842
+ symlink_buf->PathBuffer + sub_offset,
2843
+ sub_len, true, cifs_sb->local_nls);
2844
+ if (!(*target_path))
2845
+ return -ENOMEM;
2846
+
2847
+ convert_delimiter(*target_path, '/');
2848
+ cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2849
+
2850
+ return 0;
2851
+}
2852
+
2853
+static int
2854
+parse_reparse_point(struct reparse_data_buffer *buf,
2855
+ u32 plen, char **target_path,
2856
+ struct cifs_sb_info *cifs_sb)
2857
+{
2858
+ if (plen < sizeof(struct reparse_data_buffer)) {
2859
+ cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2860
+ plen);
2861
+ return -EIO;
2862
+ }
2863
+
2864
+ if (plen < le16_to_cpu(buf->ReparseDataLength) +
2865
+ sizeof(struct reparse_data_buffer)) {
2866
+ cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2867
+ plen);
2868
+ return -EIO;
2869
+ }
2870
+
2871
+ /* See MS-FSCC 2.1.2 */
2872
+ switch (le32_to_cpu(buf->ReparseTag)) {
2873
+ case IO_REPARSE_TAG_NFS:
2874
+ return parse_reparse_posix(
2875
+ (struct reparse_posix_data *)buf,
2876
+ plen, target_path, cifs_sb);
2877
+ case IO_REPARSE_TAG_SYMLINK:
2878
+ return parse_reparse_symlink(
2879
+ (struct reparse_symlink_data_buffer *)buf,
2880
+ plen, target_path, cifs_sb);
2881
+ default:
2882
+ cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2883
+ le32_to_cpu(buf->ReparseTag));
2884
+ return -EOPNOTSUPP;
2885
+ }
2886
+}
2887
+
19162888 #define SMB2_SYMLINK_STRUCT_SIZE \
19172889 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
19182890
19192891 static int
19202892 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1921
- const char *full_path, char **target_path,
1922
- struct cifs_sb_info *cifs_sb)
2893
+ struct cifs_sb_info *cifs_sb, const char *full_path,
2894
+ char **target_path, bool is_reparse_point)
19232895 {
19242896 int rc;
1925
- __le16 *utf16_path;
2897
+ __le16 *utf16_path = NULL;
19262898 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
19272899 struct cifs_open_parms oparms;
19282900 struct cifs_fid fid;
19292901 struct kvec err_iov = {NULL, 0};
19302902 struct smb2_err_rsp *err_buf = NULL;
1931
- int resp_buftype;
19322903 struct smb2_symlink_err_rsp *symlink;
2904
+ struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
19332905 unsigned int sub_len;
19342906 unsigned int sub_offset;
19352907 unsigned int print_len;
19362908 unsigned int print_offset;
2909
+ int flags = CIFS_CP_CREATE_CLOSE_OP;
2910
+ struct smb_rqst rqst[3];
2911
+ int resp_buftype[3];
2912
+ struct kvec rsp_iov[3];
2913
+ struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2914
+ struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2915
+ struct kvec close_iov[1];
2916
+ struct smb2_create_rsp *create_rsp;
2917
+ struct smb2_ioctl_rsp *ioctl_rsp;
2918
+ struct reparse_data_buffer *reparse_buf;
2919
+ int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2920
+ u32 plen;
19372921
19382922 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2923
+
2924
+ *target_path = NULL;
2925
+
2926
+ if (smb3_encryption_required(tcon))
2927
+ flags |= CIFS_TRANSFORM_REQ;
2928
+
2929
+ memset(rqst, 0, sizeof(rqst));
2930
+ resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2931
+ memset(rsp_iov, 0, sizeof(rsp_iov));
19392932
19402933 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
19412934 if (!utf16_path)
19422935 return -ENOMEM;
19432936
2937
+ /* Open */
2938
+ memset(&open_iov, 0, sizeof(open_iov));
2939
+ rqst[0].rq_iov = open_iov;
2940
+ rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2941
+
2942
+ memset(&oparms, 0, sizeof(oparms));
19442943 oparms.tcon = tcon;
19452944 oparms.desired_access = FILE_READ_ATTRIBUTES;
19462945 oparms.disposition = FILE_OPEN;
1947
- if (backup_cred(cifs_sb))
1948
- oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1949
- else
1950
- oparms.create_options = 0;
2946
+ oparms.create_options = cifs_create_options(cifs_sb, create_options);
19512947 oparms.fid = &fid;
19522948 oparms.reconnect = false;
19532949
1954
- rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_iov,
1955
- &resp_buftype);
1956
- if (!rc)
1957
- SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2950
+ rc = SMB2_open_init(tcon, server,
2951
+ &rqst[0], &oplock, &oparms, utf16_path);
2952
+ if (rc)
2953
+ goto querty_exit;
2954
+ smb2_set_next_command(tcon, &rqst[0]);
2955
+
2956
+
2957
+ /* IOCTL */
2958
+ memset(&io_iov, 0, sizeof(io_iov));
2959
+ rqst[1].rq_iov = io_iov;
2960
+ rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2961
+
2962
+ rc = SMB2_ioctl_init(tcon, server,
2963
+ &rqst[1], fid.persistent_fid,
2964
+ fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
2965
+ CIFSMaxBufSize -
2966
+ MAX_SMB2_CREATE_RESPONSE_SIZE -
2967
+ MAX_SMB2_CLOSE_RESPONSE_SIZE);
2968
+ if (rc)
2969
+ goto querty_exit;
2970
+
2971
+ smb2_set_next_command(tcon, &rqst[1]);
2972
+ smb2_set_related(&rqst[1]);
2973
+
2974
+
2975
+ /* Close */
2976
+ memset(&close_iov, 0, sizeof(close_iov));
2977
+ rqst[2].rq_iov = close_iov;
2978
+ rqst[2].rq_nvec = 1;
2979
+
2980
+ rc = SMB2_close_init(tcon, server,
2981
+ &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2982
+ if (rc)
2983
+ goto querty_exit;
2984
+
2985
+ smb2_set_related(&rqst[2]);
2986
+
2987
+ rc = compound_send_recv(xid, tcon->ses, server,
2988
+ flags, 3, rqst,
2989
+ resp_buftype, rsp_iov);
2990
+
2991
+ create_rsp = rsp_iov[0].iov_base;
2992
+ if (create_rsp && create_rsp->sync_hdr.Status)
2993
+ err_iov = rsp_iov[0];
2994
+ ioctl_rsp = rsp_iov[1].iov_base;
2995
+
2996
+ /*
2997
+ * Open was successful and we got an ioctl response.
2998
+ */
2999
+ if ((rc == 0) && (is_reparse_point)) {
3000
+ /* See MS-FSCC 2.3.23 */
3001
+
3002
+ reparse_buf = (struct reparse_data_buffer *)
3003
+ ((char *)ioctl_rsp +
3004
+ le32_to_cpu(ioctl_rsp->OutputOffset));
3005
+ plen = le32_to_cpu(ioctl_rsp->OutputCount);
3006
+
3007
+ if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3008
+ rsp_iov[1].iov_len) {
3009
+ cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
3010
+ plen);
3011
+ rc = -EIO;
3012
+ goto querty_exit;
3013
+ }
3014
+
3015
+ rc = parse_reparse_point(reparse_buf, plen, target_path,
3016
+ cifs_sb);
3017
+ goto querty_exit;
3018
+ }
3019
+
19583020 if (!rc || !err_iov.iov_base) {
19593021 rc = -ENOENT;
1960
- goto free_path;
3022
+ goto querty_exit;
19613023 }
19623024
19633025 err_buf = err_iov.iov_base;
19643026 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
19653027 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
1966
- rc = -ENOENT;
3028
+ rc = -EINVAL;
3029
+ goto querty_exit;
3030
+ }
3031
+
3032
+ symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
3033
+ if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
3034
+ le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) {
3035
+ rc = -EINVAL;
19673036 goto querty_exit;
19683037 }
19693038
19703039 /* open must fail on symlink - reset rc */
19713040 rc = 0;
1972
- symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
19733041 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
19743042 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
19753043 print_len = le16_to_cpu(symlink->PrintNameLength);
19763044 print_offset = le16_to_cpu(symlink->PrintNameOffset);
19773045
19783046 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
1979
- rc = -ENOENT;
3047
+ rc = -EINVAL;
19803048 goto querty_exit;
19813049 }
19823050
19833051 if (err_iov.iov_len <
19843052 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
1985
- rc = -ENOENT;
3053
+ rc = -EINVAL;
19863054 goto querty_exit;
19873055 }
19883056
....@@ -1997,13 +3065,143 @@
19973065 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
19983066
19993067 querty_exit:
2000
- free_rsp_buf(resp_buftype, err_buf);
2001
- free_path:
3068
+ cifs_dbg(FYI, "query symlink rc %d\n", rc);
20023069 kfree(utf16_path);
3070
+ SMB2_open_free(&rqst[0]);
3071
+ SMB2_ioctl_free(&rqst[1]);
3072
+ SMB2_close_free(&rqst[2]);
3073
+ free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3074
+ free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3075
+ free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
20033076 return rc;
20043077 }
20053078
2006
-#ifdef CONFIG_CIFS_ACL
3079
+int
3080
+smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3081
+ struct cifs_sb_info *cifs_sb, const char *full_path,
3082
+ __u32 *tag)
3083
+{
3084
+ int rc;
3085
+ __le16 *utf16_path = NULL;
3086
+ __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3087
+ struct cifs_open_parms oparms;
3088
+ struct cifs_fid fid;
3089
+ struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3090
+ int flags = CIFS_CP_CREATE_CLOSE_OP;
3091
+ struct smb_rqst rqst[3];
3092
+ int resp_buftype[3];
3093
+ struct kvec rsp_iov[3];
3094
+ struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3095
+ struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3096
+ struct kvec close_iov[1];
3097
+ struct smb2_ioctl_rsp *ioctl_rsp;
3098
+ struct reparse_data_buffer *reparse_buf;
3099
+ u32 plen;
3100
+
3101
+ cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3102
+
3103
+ if (smb3_encryption_required(tcon))
3104
+ flags |= CIFS_TRANSFORM_REQ;
3105
+
3106
+ memset(rqst, 0, sizeof(rqst));
3107
+ resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3108
+ memset(rsp_iov, 0, sizeof(rsp_iov));
3109
+
3110
+ utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3111
+ if (!utf16_path)
3112
+ return -ENOMEM;
3113
+
3114
+ /*
3115
+ * setup smb2open - TODO add optimization to call cifs_get_readable_path
3116
+ * to see if there is a handle already open that we can use
3117
+ */
3118
+ memset(&open_iov, 0, sizeof(open_iov));
3119
+ rqst[0].rq_iov = open_iov;
3120
+ rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3121
+
3122
+ memset(&oparms, 0, sizeof(oparms));
3123
+ oparms.tcon = tcon;
3124
+ oparms.desired_access = FILE_READ_ATTRIBUTES;
3125
+ oparms.disposition = FILE_OPEN;
3126
+ oparms.create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT);
3127
+ oparms.fid = &fid;
3128
+ oparms.reconnect = false;
3129
+
3130
+ rc = SMB2_open_init(tcon, server,
3131
+ &rqst[0], &oplock, &oparms, utf16_path);
3132
+ if (rc)
3133
+ goto query_rp_exit;
3134
+ smb2_set_next_command(tcon, &rqst[0]);
3135
+
3136
+
3137
+ /* IOCTL */
3138
+ memset(&io_iov, 0, sizeof(io_iov));
3139
+ rqst[1].rq_iov = io_iov;
3140
+ rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3141
+
3142
+ rc = SMB2_ioctl_init(tcon, server,
3143
+ &rqst[1], COMPOUND_FID,
3144
+ COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3145
+ CIFSMaxBufSize -
3146
+ MAX_SMB2_CREATE_RESPONSE_SIZE -
3147
+ MAX_SMB2_CLOSE_RESPONSE_SIZE);
3148
+ if (rc)
3149
+ goto query_rp_exit;
3150
+
3151
+ smb2_set_next_command(tcon, &rqst[1]);
3152
+ smb2_set_related(&rqst[1]);
3153
+
3154
+
3155
+ /* Close */
3156
+ memset(&close_iov, 0, sizeof(close_iov));
3157
+ rqst[2].rq_iov = close_iov;
3158
+ rqst[2].rq_nvec = 1;
3159
+
3160
+ rc = SMB2_close_init(tcon, server,
3161
+ &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3162
+ if (rc)
3163
+ goto query_rp_exit;
3164
+
3165
+ smb2_set_related(&rqst[2]);
3166
+
3167
+ rc = compound_send_recv(xid, tcon->ses, server,
3168
+ flags, 3, rqst,
3169
+ resp_buftype, rsp_iov);
3170
+
3171
+ ioctl_rsp = rsp_iov[1].iov_base;
3172
+
3173
+ /*
3174
+ * Open was successful and we got an ioctl response.
3175
+ */
3176
+ if (rc == 0) {
3177
+ /* See MS-FSCC 2.3.23 */
3178
+
3179
+ reparse_buf = (struct reparse_data_buffer *)
3180
+ ((char *)ioctl_rsp +
3181
+ le32_to_cpu(ioctl_rsp->OutputOffset));
3182
+ plen = le32_to_cpu(ioctl_rsp->OutputCount);
3183
+
3184
+ if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3185
+ rsp_iov[1].iov_len) {
3186
+ cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3187
+ plen);
3188
+ rc = -EIO;
3189
+ goto query_rp_exit;
3190
+ }
3191
+ *tag = le32_to_cpu(reparse_buf->ReparseTag);
3192
+ }
3193
+
3194
+ query_rp_exit:
3195
+ kfree(utf16_path);
3196
+ SMB2_open_free(&rqst[0]);
3197
+ SMB2_ioctl_free(&rqst[1]);
3198
+ SMB2_close_free(&rqst[2]);
3199
+ free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3200
+ free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3201
+ free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3202
+ return rc;
3203
+}
3204
+
20073205 static struct cifs_ntsd *
20083206 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
20093207 const struct cifs_fid *cifsfid, u32 *pacllen)
....@@ -2053,11 +3251,6 @@
20533251 tcon = tlink_tcon(tlink);
20543252 xid = get_xid();
20553253
2056
- if (backup_cred(cifs_sb))
2057
- oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2058
- else
2059
- oparms.create_options = 0;
2060
-
20613254 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
20623255 if (!utf16_path) {
20633256 rc = -ENOMEM;
....@@ -2068,10 +3261,17 @@
20683261 oparms.tcon = tcon;
20693262 oparms.desired_access = READ_CONTROL;
20703263 oparms.disposition = FILE_OPEN;
3264
+ /*
3265
+ * When querying an ACL, even if the file is a symlink we want to open
3266
+ * the source not the target, and so the protocol requires that the
3267
+ * client specify this flag when opening a reparse point
3268
+ */
3269
+ oparms.create_options = cifs_create_options(cifs_sb, 0) | OPEN_REPARSE_POINT;
20713270 oparms.fid = &fid;
20723271 oparms.reconnect = false;
20733272
2074
- rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
3273
+ rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3274
+ NULL);
20753275 kfree(utf16_path);
20763276 if (!rc) {
20773277 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
....@@ -2088,7 +3288,6 @@
20883288 return pntsd;
20893289 }
20903290
2091
-#ifdef CONFIG_CIFS_ACL
20923291 static int
20933292 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
20943293 struct inode *inode, const char *path, int aclflag)
....@@ -2110,11 +3309,6 @@
21103309 tcon = tlink_tcon(tlink);
21113310 xid = get_xid();
21123311
2113
- if (backup_cred(cifs_sb))
2114
- oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2115
- else
2116
- oparms.create_options = 0;
2117
-
21183312 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
21193313 access_flags = WRITE_OWNER;
21203314 else
....@@ -2129,12 +3323,14 @@
21293323
21303324 oparms.tcon = tcon;
21313325 oparms.desired_access = access_flags;
3326
+ oparms.create_options = cifs_create_options(cifs_sb, 0);
21323327 oparms.disposition = FILE_OPEN;
21333328 oparms.path = path;
21343329 oparms.fid = &fid;
21353330 oparms.reconnect = false;
21363331
2137
- rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
3332
+ rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3333
+ NULL, NULL);
21383334 kfree(utf16_path);
21393335 if (!rc) {
21403336 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
....@@ -2146,7 +3342,6 @@
21463342 free_xid(xid);
21473343 return rc;
21483344 }
2149
-#endif /* CIFS_ACL */
21503345
21513346 /* Retrieve an ACL from the server */
21523347 static struct cifs_ntsd *
....@@ -2166,22 +3361,26 @@
21663361 cifsFileInfo_put(open_file);
21673362 return pntsd;
21683363 }
2169
-#endif
21703364
21713365 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
21723366 loff_t offset, loff_t len, bool keep_size)
21733367 {
3368
+ struct cifs_ses *ses = tcon->ses;
21743369 struct inode *inode;
21753370 struct cifsInodeInfo *cifsi;
21763371 struct cifsFileInfo *cfile = file->private_data;
21773372 struct file_zero_data_information fsctl_buf;
21783373 long rc;
21793374 unsigned int xid;
3375
+ __le64 eof;
21803376
21813377 xid = get_xid();
21823378
21833379 inode = d_inode(cfile->dentry);
21843380 cifsi = CIFS_I(inode);
3381
+
3382
+ trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3383
+ ses->Suid, offset, len);
21853384
21863385 /*
21873386 * We zero the range through ioctl, so we need remove the page caches
....@@ -2193,51 +3392,49 @@
21933392 if (!CIFS_CACHE_READ(cifsi))
21943393 if (keep_size == false) {
21953394 rc = -EOPNOTSUPP;
3395
+ trace_smb3_zero_err(xid, cfile->fid.persistent_fid,
3396
+ tcon->tid, ses->Suid, offset, len, rc);
21963397 free_xid(xid);
21973398 return rc;
21983399 }
21993400
2200
- /*
2201
- * Must check if file sparse since fallocate -z (zero range) assumes
2202
- * non-sparse allocation
2203
- */
2204
- if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
2205
- rc = -EOPNOTSUPP;
2206
- free_xid(xid);
2207
- return rc;
2208
- }
2209
-
2210
- /*
2211
- * need to make sure we are not asked to extend the file since the SMB3
2212
- * fsctl does not change the file size. In the future we could change
2213
- * this to zero the first part of the range then set the file size
2214
- * which for a non sparse file would zero the newly extended range
2215
- */
2216
- if (keep_size == false)
2217
- if (i_size_read(inode) < offset + len) {
2218
- rc = -EOPNOTSUPP;
2219
- free_xid(xid);
2220
- return rc;
2221
- }
2222
-
2223
- cifs_dbg(FYI, "offset %lld len %lld", offset, len);
3401
+ cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
22243402
22253403 fsctl_buf.FileOffset = cpu_to_le64(offset);
22263404 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
22273405
22283406 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
22293407 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2230
- true /* is_fctl */, (char *)&fsctl_buf,
2231
- sizeof(struct file_zero_data_information), NULL, NULL);
3408
+ (char *)&fsctl_buf,
3409
+ sizeof(struct file_zero_data_information),
3410
+ 0, NULL, NULL);
3411
+ if (rc)
3412
+ goto zero_range_exit;
3413
+
3414
+ /*
3415
+ * do we also need to change the size of the file?
3416
+ */
3417
+ if (keep_size == false && i_size_read(inode) < offset + len) {
3418
+ eof = cpu_to_le64(offset + len);
3419
+ rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3420
+ cfile->fid.volatile_fid, cfile->pid, &eof);
3421
+ }
3422
+
3423
+ zero_range_exit:
22323424 free_xid(xid);
3425
+ if (rc)
3426
+ trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3427
+ ses->Suid, offset, len, rc);
3428
+ else
3429
+ trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3430
+ ses->Suid, offset, len);
22333431 return rc;
22343432 }
22353433
22363434 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
22373435 loff_t offset, loff_t len)
22383436 {
2239
- struct inode *inode;
2240
- struct cifsInodeInfo *cifsi;
3437
+ struct inode *inode = file_inode(file);
22413438 struct cifsFileInfo *cfile = file->private_data;
22423439 struct file_zero_data_information fsctl_buf;
22433440 long rc;
....@@ -2246,15 +3443,12 @@
22463443
22473444 xid = get_xid();
22483445
2249
- inode = d_inode(cfile->dentry);
2250
- cifsi = CIFS_I(inode);
2251
-
3446
+ inode_lock(inode);
22523447 /* Need to make file sparse, if not already, before freeing range. */
22533448 /* Consider adding equivalent for compressed since it could also work */
22543449 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
22553450 rc = -EOPNOTSUPP;
2256
- free_xid(xid);
2257
- return rc;
3451
+ goto out;
22583452 }
22593453
22603454 /*
....@@ -2263,18 +3457,142 @@
22633457 */
22643458 truncate_pagecache_range(inode, offset, offset + len - 1);
22653459
2266
- cifs_dbg(FYI, "offset %lld len %lld", offset, len);
3460
+ cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
22673461
22683462 fsctl_buf.FileOffset = cpu_to_le64(offset);
22693463 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
22703464
22713465 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
22723466 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2273
- true /* is_fctl */, (char *)&fsctl_buf,
2274
- sizeof(struct file_zero_data_information), NULL, NULL);
3467
+ (char *)&fsctl_buf,
3468
+ sizeof(struct file_zero_data_information),
3469
+ CIFSMaxBufSize, NULL, NULL);
3470
+out:
3471
+ inode_unlock(inode);
22753472 free_xid(xid);
22763473 return rc;
22773474 }
3475
+
3476
+static int smb3_simple_fallocate_write_range(unsigned int xid,
3477
+ struct cifs_tcon *tcon,
3478
+ struct cifsFileInfo *cfile,
3479
+ loff_t off, loff_t len,
3480
+ char *buf)
3481
+{
3482
+ struct cifs_io_parms io_parms = {0};
3483
+ int nbytes;
3484
+ int rc = 0;
3485
+ struct kvec iov[2];
3486
+
3487
+ io_parms.netfid = cfile->fid.netfid;
3488
+ io_parms.pid = current->tgid;
3489
+ io_parms.tcon = tcon;
3490
+ io_parms.persistent_fid = cfile->fid.persistent_fid;
3491
+ io_parms.volatile_fid = cfile->fid.volatile_fid;
3492
+
3493
+ while (len) {
3494
+ io_parms.offset = off;
3495
+ io_parms.length = len;
3496
+ if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3497
+ io_parms.length = SMB2_MAX_BUFFER_SIZE;
3498
+ /* iov[0] is reserved for smb header */
3499
+ iov[1].iov_base = buf;
3500
+ iov[1].iov_len = io_parms.length;
3501
+ rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3502
+ if (rc)
3503
+ break;
3504
+ if (nbytes > len)
3505
+ return -EINVAL;
3506
+ buf += nbytes;
3507
+ off += nbytes;
3508
+ len -= nbytes;
3509
+ }
3510
+ return rc;
3511
+}
3512
+
3513
+static int smb3_simple_fallocate_range(unsigned int xid,
3514
+ struct cifs_tcon *tcon,
3515
+ struct cifsFileInfo *cfile,
3516
+ loff_t off, loff_t len)
3517
+{
3518
+ struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3519
+ u32 out_data_len;
3520
+ char *buf = NULL;
3521
+ loff_t l;
3522
+ int rc;
3523
+
3524
+ in_data.file_offset = cpu_to_le64(off);
3525
+ in_data.length = cpu_to_le64(len);
3526
+ rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3527
+ cfile->fid.volatile_fid,
3528
+ FSCTL_QUERY_ALLOCATED_RANGES,
3529
+ (char *)&in_data, sizeof(in_data),
3530
+ 1024 * sizeof(struct file_allocated_range_buffer),
3531
+ (char **)&out_data, &out_data_len);
3532
+ if (rc)
3533
+ goto out;
3534
+
3535
+ buf = kzalloc(1024 * 1024, GFP_KERNEL);
3536
+ if (buf == NULL) {
3537
+ rc = -ENOMEM;
3538
+ goto out;
3539
+ }
3540
+
3541
+ tmp_data = out_data;
3542
+ while (len) {
3543
+ /*
3544
+ * The rest of the region is unmapped so write it all.
3545
+ */
3546
+ if (out_data_len == 0) {
3547
+ rc = smb3_simple_fallocate_write_range(xid, tcon,
3548
+ cfile, off, len, buf);
3549
+ goto out;
3550
+ }
3551
+
3552
+ if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3553
+ rc = -EINVAL;
3554
+ goto out;
3555
+ }
3556
+
3557
+ if (off < le64_to_cpu(tmp_data->file_offset)) {
3558
+ /*
3559
+ * We are at a hole. Write until the end of the region
3560
+ * or until the next allocated data,
3561
+ * whichever comes next.
3562
+ */
3563
+ l = le64_to_cpu(tmp_data->file_offset) - off;
3564
+ if (len < l)
3565
+ l = len;
3566
+ rc = smb3_simple_fallocate_write_range(xid, tcon,
3567
+ cfile, off, l, buf);
3568
+ if (rc)
3569
+ goto out;
3570
+ off = off + l;
3571
+ len = len - l;
3572
+ if (len == 0)
3573
+ goto out;
3574
+ }
3575
+ /*
3576
+ * We are at a section of allocated data, just skip forward
3577
+ * until the end of the data or the end of the region
3578
+ * we are supposed to fallocate, whichever comes first.
3579
+ */
3580
+ l = le64_to_cpu(tmp_data->length);
3581
+ if (len < l)
3582
+ l = len;
3583
+ off += l;
3584
+ len -= l;
3585
+
3586
+ tmp_data = &tmp_data[1];
3587
+ out_data_len -= sizeof(struct file_allocated_range_buffer);
3588
+ }
3589
+
3590
+ out:
3591
+ kfree(out_data);
3592
+ kfree(buf);
3593
+ return rc;
3594
+}
3595
+
22783596
22793597 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
22803598 loff_t off, loff_t len, bool keep_size)
....@@ -2284,39 +3602,96 @@
22843602 struct cifsFileInfo *cfile = file->private_data;
22853603 long rc = -EOPNOTSUPP;
22863604 unsigned int xid;
3605
+ __le64 eof;
22873606
22883607 xid = get_xid();
22893608
22903609 inode = d_inode(cfile->dentry);
22913610 cifsi = CIFS_I(inode);
22923611
3612
+ trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3613
+ tcon->ses->Suid, off, len);
22933614 /* if file not oplocked can't be sure whether asking to extend size */
22943615 if (!CIFS_CACHE_READ(cifsi))
22953616 if (keep_size == false) {
3617
+ trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3618
+ tcon->tid, tcon->ses->Suid, off, len, rc);
22963619 free_xid(xid);
22973620 return rc;
22983621 }
22993622
23003623 /*
3624
+ * Extending the file
3625
+ */
3626
+ if ((keep_size == false) && i_size_read(inode) < off + len) {
3627
+ rc = inode_newsize_ok(inode, off + len);
3628
+ if (rc)
3629
+ goto out;
3630
+
3631
+ if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3632
+ smb2_set_sparse(xid, tcon, cfile, inode, false);
3633
+
3634
+ eof = cpu_to_le64(off + len);
3635
+ rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3636
+ cfile->fid.volatile_fid, cfile->pid, &eof);
3637
+ if (rc == 0) {
3638
+ cifsi->server_eof = off + len;
3639
+ cifs_setsize(inode, off + len);
3640
+ cifs_truncate_page(inode->i_mapping, inode->i_size);
3641
+ truncate_setsize(inode, off + len);
3642
+ }
3643
+ goto out;
3644
+ }
3645
+
3646
+ /*
23013647 * Files are non-sparse by default so falloc may be a no-op
2302
- * Must check if file sparse. If not sparse, and not extending
2303
- * then no need to do anything since file already allocated
3648
+ * Must check if file sparse. If not sparse, and since we are not
3649
+ * extending then no need to do anything since file already allocated
23043650 */
23053651 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
2306
- if (keep_size == true)
3652
+ rc = 0;
3653
+ goto out;
3654
+ }
3655
+
3656
+ if (keep_size == true) {
3657
+ /*
3658
+ * We can not preallocate pages beyond the end of the file
3659
+ * in SMB2
3660
+ */
3661
+ if (off >= i_size_read(inode)) {
23073662 rc = 0;
2308
- /* check if extending file */
2309
- else if (i_size_read(inode) >= off + len)
2310
- /* not extending file and already not sparse */
2311
- rc = 0;
2312
- /* BB: in future add else clause to extend file */
2313
- else
2314
- rc = -EOPNOTSUPP;
2315
- free_xid(xid);
2316
- return rc;
3663
+ goto out;
3664
+ }
3665
+ /*
3666
+ * For fallocates that are partially beyond the end of file,
3667
+ * clamp len so we only fallocate up to the end of file.
3668
+ */
3669
+ if (off + len > i_size_read(inode)) {
3670
+ len = i_size_read(inode) - off;
3671
+ }
23173672 }
23183673
23193674 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3675
+ /*
3676
+ * At this point, we are trying to fallocate an internal
3677
+ * regions of a sparse file. Since smb2 does not have a
3678
+ * fallocate command we have two otions on how to emulate this.
3679
+ * We can either turn the entire file to become non-sparse
3680
+ * which we only do if the fallocate is for virtually
3681
+ * the whole file, or we can overwrite the region with zeroes
3682
+ * using SMB2_write, which could be prohibitevly expensive
3683
+ * if len is large.
3684
+ */
3685
+ /*
3686
+ * We are only trying to fallocate a small region so
3687
+ * just write it with zero.
3688
+ */
3689
+ if (len <= 1024 * 1024) {
3690
+ rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3691
+ off, len);
3692
+ goto out;
3693
+ }
3694
+
23203695 /*
23213696 * Check if falloc starts within first few pages of file
23223697 * and ends within a few pages of the end of file to
....@@ -2327,19 +3702,183 @@
23273702 */
23283703 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
23293704 rc = -EOPNOTSUPP;
2330
- free_xid(xid);
2331
- return rc;
3705
+ goto out;
23323706 }
2333
-
2334
- rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
23353707 }
2336
- /* BB: else ... in future add code to extend file and set sparse */
23373708
3709
+ smb2_set_sparse(xid, tcon, cfile, inode, false);
3710
+ rc = 0;
3711
+
3712
+out:
3713
+ if (rc)
3714
+ trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3715
+ tcon->ses->Suid, off, len, rc);
3716
+ else
3717
+ trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3718
+ tcon->ses->Suid, off, len);
23383719
23393720 free_xid(xid);
23403721 return rc;
23413722 }
23423723
3724
+static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3725
+{
3726
+ struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3727
+ struct cifsInodeInfo *cifsi;
3728
+ struct inode *inode;
3729
+ int rc = 0;
3730
+ struct file_allocated_range_buffer in_data, *out_data = NULL;
3731
+ u32 out_data_len;
3732
+ unsigned int xid;
3733
+
3734
+ if (whence != SEEK_HOLE && whence != SEEK_DATA)
3735
+ return generic_file_llseek(file, offset, whence);
3736
+
3737
+ inode = d_inode(cfile->dentry);
3738
+ cifsi = CIFS_I(inode);
3739
+
3740
+ if (offset < 0 || offset >= i_size_read(inode))
3741
+ return -ENXIO;
3742
+
3743
+ xid = get_xid();
3744
+ /*
3745
+ * We need to be sure that all dirty pages are written as they
3746
+ * might fill holes on the server.
3747
+ * Note that we also MUST flush any written pages since at least
3748
+ * some servers (Windows2016) will not reflect recent writes in
3749
+ * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3750
+ */
3751
+ wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3752
+ if (wrcfile) {
3753
+ filemap_write_and_wait(inode->i_mapping);
3754
+ smb2_flush_file(xid, tcon, &wrcfile->fid);
3755
+ cifsFileInfo_put(wrcfile);
3756
+ }
3757
+
3758
+ if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3759
+ if (whence == SEEK_HOLE)
3760
+ offset = i_size_read(inode);
3761
+ goto lseek_exit;
3762
+ }
3763
+
3764
+ in_data.file_offset = cpu_to_le64(offset);
3765
+ in_data.length = cpu_to_le64(i_size_read(inode));
3766
+
3767
+ rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3768
+ cfile->fid.volatile_fid,
3769
+ FSCTL_QUERY_ALLOCATED_RANGES,
3770
+ (char *)&in_data, sizeof(in_data),
3771
+ sizeof(struct file_allocated_range_buffer),
3772
+ (char **)&out_data, &out_data_len);
3773
+ if (rc == -E2BIG)
3774
+ rc = 0;
3775
+ if (rc)
3776
+ goto lseek_exit;
3777
+
3778
+ if (whence == SEEK_HOLE && out_data_len == 0)
3779
+ goto lseek_exit;
3780
+
3781
+ if (whence == SEEK_DATA && out_data_len == 0) {
3782
+ rc = -ENXIO;
3783
+ goto lseek_exit;
3784
+ }
3785
+
3786
+ if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3787
+ rc = -EINVAL;
3788
+ goto lseek_exit;
3789
+ }
3790
+ if (whence == SEEK_DATA) {
3791
+ offset = le64_to_cpu(out_data->file_offset);
3792
+ goto lseek_exit;
3793
+ }
3794
+ if (offset < le64_to_cpu(out_data->file_offset))
3795
+ goto lseek_exit;
3796
+
3797
+ offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3798
+
3799
+ lseek_exit:
3800
+ free_xid(xid);
3801
+ kfree(out_data);
3802
+ if (!rc)
3803
+ return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3804
+ else
3805
+ return rc;
3806
+}
3807
+
3808
+static int smb3_fiemap(struct cifs_tcon *tcon,
3809
+ struct cifsFileInfo *cfile,
3810
+ struct fiemap_extent_info *fei, u64 start, u64 len)
3811
+{
3812
+ unsigned int xid;
3813
+ struct file_allocated_range_buffer in_data, *out_data;
3814
+ u32 out_data_len;
3815
+ int i, num, rc, flags, last_blob;
3816
+ u64 next;
3817
+
3818
+ rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3819
+ if (rc)
3820
+ return rc;
3821
+
3822
+ xid = get_xid();
3823
+ again:
3824
+ in_data.file_offset = cpu_to_le64(start);
3825
+ in_data.length = cpu_to_le64(len);
3826
+
3827
+ rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3828
+ cfile->fid.volatile_fid,
3829
+ FSCTL_QUERY_ALLOCATED_RANGES,
3830
+ (char *)&in_data, sizeof(in_data),
3831
+ 1024 * sizeof(struct file_allocated_range_buffer),
3832
+ (char **)&out_data, &out_data_len);
3833
+ if (rc == -E2BIG) {
3834
+ last_blob = 0;
3835
+ rc = 0;
3836
+ } else
3837
+ last_blob = 1;
3838
+ if (rc)
3839
+ goto out;
3840
+
3841
+ if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3842
+ rc = -EINVAL;
3843
+ goto out;
3844
+ }
3845
+ if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3846
+ rc = -EINVAL;
3847
+ goto out;
3848
+ }
3849
+
3850
+ num = out_data_len / sizeof(struct file_allocated_range_buffer);
3851
+ for (i = 0; i < num; i++) {
3852
+ flags = 0;
3853
+ if (i == num - 1 && last_blob)
3854
+ flags |= FIEMAP_EXTENT_LAST;
3855
+
3856
+ rc = fiemap_fill_next_extent(fei,
3857
+ le64_to_cpu(out_data[i].file_offset),
3858
+ le64_to_cpu(out_data[i].file_offset),
3859
+ le64_to_cpu(out_data[i].length),
3860
+ flags);
3861
+ if (rc < 0)
3862
+ goto out;
3863
+ if (rc == 1) {
3864
+ rc = 0;
3865
+ goto out;
3866
+ }
3867
+ }
3868
+
3869
+ if (!last_blob) {
3870
+ next = le64_to_cpu(out_data[num - 1].file_offset) +
3871
+ le64_to_cpu(out_data[num - 1].length);
3872
+ len = len - (next - start);
3873
+ start = next;
3874
+ goto again;
3875
+ }
3876
+
3877
+ out:
3878
+ free_xid(xid);
3879
+ kfree(out_data);
3880
+ return rc;
3881
+}
23433882
23443883 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
23453884 loff_t off, loff_t len)
....@@ -2489,11 +4028,13 @@
24894028 }
24904029 }
24914030
4031
+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
24924032 static bool
24934033 smb2_is_read_op(__u32 oplock)
24944034 {
24954035 return oplock == SMB2_OPLOCK_LEVEL_II;
24964036 }
4037
+#endif /* CIFS_ALLOW_INSECURE_LEGACY */
24974038
24984039 static bool
24994040 smb21_is_read_op(__u32 oplock)
....@@ -2606,7 +4147,7 @@
26064147
26074148 static void
26084149 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
2609
- struct smb_rqst *old_rq)
4150
+ struct smb_rqst *old_rq, __le16 cipher_type)
26104151 {
26114152 struct smb2_sync_hdr *shdr =
26124153 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
....@@ -2615,7 +4156,11 @@
26154156 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
26164157 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
26174158 tr_hdr->Flags = cpu_to_le16(0x01);
2618
- get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
4159
+ if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4160
+ (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4161
+ get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4162
+ else
4163
+ get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
26194164 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
26204165 }
26214166
....@@ -2671,7 +4216,7 @@
26714216 smb2_sg_set_buf(&sg[idx++],
26724217 rqst[i].rq_iov[j].iov_base + skip,
26734218 rqst[i].rq_iov[j].iov_len - skip);
2674
- }
4219
+ }
26754220
26764221 for (j = 0; j < rqst[i].rq_npages; j++) {
26774222 unsigned int len, offset;
....@@ -2691,14 +4236,16 @@
26914236 u8 *ses_enc_key;
26924237
26934238 spin_lock(&cifs_tcp_ses_lock);
2694
- list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2695
- if (ses->Suid != ses_id)
2696
- continue;
2697
- ses_enc_key = enc ? ses->smb3encryptionkey :
2698
- ses->smb3decryptionkey;
2699
- memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
2700
- spin_unlock(&cifs_tcp_ses_lock);
2701
- return 0;
4239
+ list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
4240
+ list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
4241
+ if (ses->Suid == ses_id) {
4242
+ ses_enc_key = enc ? ses->smb3encryptionkey :
4243
+ ses->smb3decryptionkey;
4244
+ memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4245
+ spin_unlock(&cifs_tcp_ses_lock);
4246
+ return 0;
4247
+ }
4248
+ }
27024249 }
27034250 spin_unlock(&cifs_tcp_ses_lock);
27044251
....@@ -2721,7 +4268,7 @@
27214268 int rc = 0;
27224269 struct scatterlist *sg;
27234270 u8 sign[SMB2_SIGNATURE_SIZE] = {};
2724
- u8 key[SMB3_SIGN_KEY_SIZE];
4271
+ u8 key[SMB3_ENC_DEC_KEY_SIZE];
27254272 struct aead_request *req;
27264273 char *iv;
27274274 unsigned int iv_len;
....@@ -2731,34 +4278,40 @@
27314278
27324279 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
27334280 if (rc) {
2734
- cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4281
+ cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
27354282 enc ? "en" : "de");
27364283 return rc;
27374284 }
27384285
27394286 rc = smb3_crypto_aead_allocate(server);
27404287 if (rc) {
2741
- cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4288
+ cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
27424289 return rc;
27434290 }
27444291
27454292 tfm = enc ? server->secmech.ccmaesencrypt :
27464293 server->secmech.ccmaesdecrypt;
2747
- rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
4294
+
4295
+ if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4296
+ (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4297
+ rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4298
+ else
4299
+ rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4300
+
27484301 if (rc) {
2749
- cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4302
+ cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
27504303 return rc;
27514304 }
27524305
27534306 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
27544307 if (rc) {
2755
- cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4308
+ cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
27564309 return rc;
27574310 }
27584311
27594312 req = aead_request_alloc(tfm, GFP_KERNEL);
27604313 if (!req) {
2761
- cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
4314
+ cifs_server_dbg(VFS, "%s: Failed to alloc aead request\n", __func__);
27624315 return -ENOMEM;
27634316 }
27644317
....@@ -2769,7 +4322,7 @@
27694322
27704323 sg = init_sg(num_rqst, rqst, sign);
27714324 if (!sg) {
2772
- cifs_dbg(VFS, "%s: Failed to init sg", __func__);
4325
+ cifs_server_dbg(VFS, "%s: Failed to init sg\n", __func__);
27734326 rc = -ENOMEM;
27744327 goto free_req;
27754328 }
....@@ -2777,12 +4330,18 @@
27774330 iv_len = crypto_aead_ivsize(tfm);
27784331 iv = kzalloc(iv_len, GFP_KERNEL);
27794332 if (!iv) {
2780
- cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
4333
+ cifs_server_dbg(VFS, "%s: Failed to alloc iv\n", __func__);
27814334 rc = -ENOMEM;
27824335 goto free_sg;
27834336 }
2784
- iv[0] = 3;
2785
- memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
4337
+
4338
+ if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4339
+ (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4340
+ memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4341
+ else {
4342
+ iv[0] = 3;
4343
+ memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4344
+ }
27864345
27874346 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
27884347 aead_request_set_ad(req, assoc_data_len);
....@@ -2882,10 +4441,10 @@
28824441 }
28834442
28844443 /* fill the 1st iov with a transform header */
2885
- fill_transform_hdr(tr_hdr, orig_len, old_rq);
4444
+ fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
28864445
28874446 rc = crypt_message(server, num_rqst, new_rq, 1);
2888
- cifs_dbg(FYI, "encrypt message returned %d", rc);
4447
+ cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
28894448 if (rc)
28904449 goto err_free;
28914450
....@@ -2907,7 +4466,8 @@
29074466 static int
29084467 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
29094468 unsigned int buf_data_size, struct page **pages,
2910
- unsigned int npages, unsigned int page_data_size)
4469
+ unsigned int npages, unsigned int page_data_size,
4470
+ bool is_offloaded)
29114471 {
29124472 struct kvec iov[2];
29134473 struct smb_rqst rqst = {NULL};
....@@ -2926,14 +4486,15 @@
29264486 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
29274487
29284488 rc = crypt_message(server, 1, &rqst, 0);
2929
- cifs_dbg(FYI, "decrypt message returned %d\n", rc);
4489
+ cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
29304490
29314491 if (rc)
29324492 return rc;
29334493
29344494 memmove(buf, iov[1].iov_base, buf_data_size);
29354495
2936
- server->total_read = buf_data_size + page_data_size;
4496
+ if (!is_offloaded)
4497
+ server->total_read = buf_data_size + page_data_size;
29374498
29384499 return rc;
29394500 }
....@@ -2998,7 +4559,8 @@
29984559 static int
29994560 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
30004561 char *buf, unsigned int buf_len, struct page **pages,
3001
- unsigned int npages, unsigned int page_data_size)
4562
+ unsigned int npages, unsigned int page_data_size,
4563
+ bool is_offloaded)
30024564 {
30034565 unsigned int data_offset;
30044566 unsigned int data_len;
....@@ -3014,19 +4576,19 @@
30144576 bool use_rdma_mr = false;
30154577
30164578 if (shdr->Command != SMB2_READ) {
3017
- cifs_dbg(VFS, "only big read responses are supported\n");
4579
+ cifs_server_dbg(VFS, "only big read responses are supported\n");
30184580 return -ENOTSUPP;
30194581 }
30204582
30214583 if (server->ops->is_session_expired &&
30224584 server->ops->is_session_expired(buf)) {
3023
- cifs_reconnect(server);
3024
- wake_up(&server->response_q);
4585
+ if (!is_offloaded)
4586
+ cifs_reconnect(server);
30254587 return -1;
30264588 }
30274589
30284590 if (server->ops->is_status_pending &&
3029
- server->ops->is_status_pending(buf, server, 0))
4591
+ server->ops->is_status_pending(buf, server))
30304592 return -1;
30314593
30324594 /* set up first two iov to get credits */
....@@ -3045,7 +4607,10 @@
30454607 cifs_dbg(FYI, "%s: server returned error %d\n",
30464608 __func__, rdata->result);
30474609 /* normal error on read response */
3048
- dequeue_mid(mid, false);
4610
+ if (is_offloaded)
4611
+ mid->mid_state = MID_RESPONSE_RECEIVED;
4612
+ else
4613
+ dequeue_mid(mid, false);
30494614 return 0;
30504615 }
30514616
....@@ -3069,7 +4634,10 @@
30694634 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
30704635 __func__, data_offset);
30714636 rdata->result = -EIO;
3072
- dequeue_mid(mid, rdata->result);
4637
+ if (is_offloaded)
4638
+ mid->mid_state = MID_RESPONSE_MALFORMED;
4639
+ else
4640
+ dequeue_mid(mid, rdata->result);
30734641 return 0;
30744642 }
30754643
....@@ -3085,36 +4653,48 @@
30854653 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
30864654 __func__, data_offset);
30874655 rdata->result = -EIO;
3088
- dequeue_mid(mid, rdata->result);
4656
+ if (is_offloaded)
4657
+ mid->mid_state = MID_RESPONSE_MALFORMED;
4658
+ else
4659
+ dequeue_mid(mid, rdata->result);
30894660 return 0;
30904661 }
30914662
30924663 if (data_len > page_data_size - pad_len) {
30934664 /* data_len is corrupt -- discard frame */
30944665 rdata->result = -EIO;
3095
- dequeue_mid(mid, rdata->result);
4666
+ if (is_offloaded)
4667
+ mid->mid_state = MID_RESPONSE_MALFORMED;
4668
+ else
4669
+ dequeue_mid(mid, rdata->result);
30964670 return 0;
30974671 }
30984672
30994673 rdata->result = init_read_bvec(pages, npages, page_data_size,
31004674 cur_off, &bvec);
31014675 if (rdata->result != 0) {
3102
- dequeue_mid(mid, rdata->result);
4676
+ if (is_offloaded)
4677
+ mid->mid_state = MID_RESPONSE_MALFORMED;
4678
+ else
4679
+ dequeue_mid(mid, rdata->result);
31034680 return 0;
31044681 }
31054682
3106
- iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len);
4683
+ iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
31074684 } else if (buf_len >= data_offset + data_len) {
31084685 /* read response payload is in buf */
31094686 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
31104687 iov.iov_base = buf + data_offset;
31114688 iov.iov_len = data_len;
3112
- iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len);
4689
+ iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
31134690 } else {
31144691 /* read response payload cannot be in both buf and pages */
31154692 WARN_ONCE(1, "buf can not contain only a part of read data");
31164693 rdata->result = -EIO;
3117
- dequeue_mid(mid, rdata->result);
4694
+ if (is_offloaded)
4695
+ mid->mid_state = MID_RESPONSE_MALFORMED;
4696
+ else
4697
+ dequeue_mid(mid, rdata->result);
31184698 return 0;
31194699 }
31204700
....@@ -3125,12 +4705,82 @@
31254705 if (length < 0)
31264706 return length;
31274707
3128
- dequeue_mid(mid, false);
4708
+ if (is_offloaded)
4709
+ mid->mid_state = MID_RESPONSE_RECEIVED;
4710
+ else
4711
+ dequeue_mid(mid, false);
31294712 return length;
31304713 }
31314714
4715
+struct smb2_decrypt_work {
4716
+ struct work_struct decrypt;
4717
+ struct TCP_Server_Info *server;
4718
+ struct page **ppages;
4719
+ char *buf;
4720
+ unsigned int npages;
4721
+ unsigned int len;
4722
+};
4723
+
4724
+
4725
+static void smb2_decrypt_offload(struct work_struct *work)
4726
+{
4727
+ struct smb2_decrypt_work *dw = container_of(work,
4728
+ struct smb2_decrypt_work, decrypt);
4729
+ int i, rc;
4730
+ struct mid_q_entry *mid;
4731
+
4732
+ rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4733
+ dw->ppages, dw->npages, dw->len, true);
4734
+ if (rc) {
4735
+ cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4736
+ goto free_pages;
4737
+ }
4738
+
4739
+ dw->server->lstrp = jiffies;
4740
+ mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4741
+ if (mid == NULL)
4742
+ cifs_dbg(FYI, "mid not found\n");
4743
+ else {
4744
+ mid->decrypted = true;
4745
+ rc = handle_read_data(dw->server, mid, dw->buf,
4746
+ dw->server->vals->read_rsp_size,
4747
+ dw->ppages, dw->npages, dw->len,
4748
+ true);
4749
+ if (rc >= 0) {
4750
+#ifdef CONFIG_CIFS_STATS2
4751
+ mid->when_received = jiffies;
4752
+#endif
4753
+ mid->callback(mid);
4754
+ } else {
4755
+ spin_lock(&GlobalMid_Lock);
4756
+ if (dw->server->tcpStatus == CifsNeedReconnect) {
4757
+ mid->mid_state = MID_RETRY_NEEDED;
4758
+ spin_unlock(&GlobalMid_Lock);
4759
+ mid->callback(mid);
4760
+ } else {
4761
+ mid->mid_state = MID_REQUEST_SUBMITTED;
4762
+ mid->mid_flags &= ~(MID_DELETED);
4763
+ list_add_tail(&mid->qhead,
4764
+ &dw->server->pending_mid_q);
4765
+ spin_unlock(&GlobalMid_Lock);
4766
+ }
4767
+ }
4768
+ cifs_mid_q_entry_release(mid);
4769
+ }
4770
+
4771
+free_pages:
4772
+ for (i = dw->npages-1; i >= 0; i--)
4773
+ put_page(dw->ppages[i]);
4774
+
4775
+ kfree(dw->ppages);
4776
+ cifs_small_buf_release(dw->buf);
4777
+ kfree(dw);
4778
+}
4779
+
4780
+
31324781 static int
3133
-receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
4782
+receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4783
+ int *num_mids)
31344784 {
31354785 char *buf = server->smallbuf;
31364786 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
....@@ -3140,7 +4790,9 @@
31404790 unsigned int buflen = server->pdu_size;
31414791 int rc;
31424792 int i = 0;
4793
+ struct smb2_decrypt_work *dw;
31434794
4795
+ *num_mids = 1;
31444796 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
31454797 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
31464798
....@@ -3176,8 +4828,34 @@
31764828 if (rc)
31774829 goto free_pages;
31784830
4831
+ /*
4832
+ * For large reads, offload to different thread for better performance,
4833
+ * use more cores decrypting which can be expensive
4834
+ */
4835
+
4836
+ if ((server->min_offload) && (server->in_flight > 1) &&
4837
+ (server->pdu_size >= server->min_offload)) {
4838
+ dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4839
+ if (dw == NULL)
4840
+ goto non_offloaded_decrypt;
4841
+
4842
+ dw->buf = server->smallbuf;
4843
+ server->smallbuf = (char *)cifs_small_buf_get();
4844
+
4845
+ INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4846
+
4847
+ dw->npages = npages;
4848
+ dw->server = server;
4849
+ dw->ppages = pages;
4850
+ dw->len = len;
4851
+ queue_work(decrypt_wq, &dw->decrypt);
4852
+ *num_mids = 0; /* worker thread takes care of finding mid */
4853
+ return -1;
4854
+ }
4855
+
4856
+non_offloaded_decrypt:
31794857 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
3180
- pages, npages, len);
4858
+ pages, npages, len, false);
31814859 if (rc)
31824860 goto free_pages;
31834861
....@@ -3189,7 +4867,7 @@
31894867 (*mid)->decrypted = true;
31904868 rc = handle_read_data(server, *mid, buf,
31914869 server->vals->read_rsp_size,
3192
- pages, npages, len);
4870
+ pages, npages, len, false);
31934871 }
31944872
31954873 free_pages:
....@@ -3233,7 +4911,7 @@
32334911 server->total_read += length;
32344912
32354913 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
3236
- length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
4914
+ length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
32374915 if (length)
32384916 return length;
32394917
....@@ -3260,7 +4938,7 @@
32604938 }
32614939
32624940 if (*num_mids >= MAX_COMPOUND) {
3263
- cifs_dbg(VFS, "too many PDUs in compound\n");
4941
+ cifs_server_dbg(VFS, "too many PDUs in compound\n");
32644942 return -1;
32654943 }
32664944 bufs[*num_mids] = buf;
....@@ -3306,24 +4984,21 @@
33064984
33074985 if (pdu_length < sizeof(struct smb2_transform_hdr) +
33084986 sizeof(struct smb2_sync_hdr)) {
3309
- cifs_dbg(VFS, "Transform message is too small (%u)\n",
4987
+ cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
33104988 pdu_length);
33114989 cifs_reconnect(server);
3312
- wake_up(&server->response_q);
33134990 return -ECONNABORTED;
33144991 }
33154992
33164993 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
3317
- cifs_dbg(VFS, "Transform message is broken\n");
4994
+ cifs_server_dbg(VFS, "Transform message is broken\n");
33184995 cifs_reconnect(server);
3319
- wake_up(&server->response_q);
33204996 return -ECONNABORTED;
33214997 }
33224998
33234999 /* TODO: add support for compounds containing READ. */
33245000 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
3325
- *num_mids = 1;
3326
- return receive_encrypted_read(server, &mids[0]);
5001
+ return receive_encrypted_read(server, &mids[0], num_mids);
33275002 }
33285003
33295004 return receive_encrypted_standard(server, mids, bufs, num_mids);
....@@ -3335,7 +5010,7 @@
33355010 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
33365011
33375012 return handle_read_data(server, mid, buf, server->pdu_size,
3338
- NULL, 0, 0);
5013
+ NULL, 0, 0, false);
33395014 }
33405015
33415016 static int
....@@ -3351,6 +5026,101 @@
33515026 return le32_to_cpu(hdr->NextCommand);
33525027 }
33535028
5029
+static int
5030
+smb2_make_node(unsigned int xid, struct inode *inode,
5031
+ struct dentry *dentry, struct cifs_tcon *tcon,
5032
+ char *full_path, umode_t mode, dev_t dev)
5033
+{
5034
+ struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5035
+ int rc = -EPERM;
5036
+ FILE_ALL_INFO *buf = NULL;
5037
+ struct cifs_io_parms io_parms = {0};
5038
+ __u32 oplock = 0;
5039
+ struct cifs_fid fid;
5040
+ struct cifs_open_parms oparms;
5041
+ unsigned int bytes_written;
5042
+ struct win_dev *pdev;
5043
+ struct kvec iov[2];
5044
+
5045
+ /*
5046
+ * Check if mounted with mount parm 'sfu' mount parm.
5047
+ * SFU emulation should work with all servers, but only
5048
+ * supports block and char device (no socket & fifo),
5049
+ * and was used by default in earlier versions of Windows
5050
+ */
5051
+ if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5052
+ goto out;
5053
+
5054
+ /*
5055
+ * TODO: Add ability to create instead via reparse point. Windows (e.g.
5056
+ * their current NFS server) uses this approach to expose special files
5057
+ * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5058
+ */
5059
+
5060
+ if (!S_ISCHR(mode) && !S_ISBLK(mode))
5061
+ goto out;
5062
+
5063
+ cifs_dbg(FYI, "sfu compat create special file\n");
5064
+
5065
+ buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
5066
+ if (buf == NULL) {
5067
+ rc = -ENOMEM;
5068
+ goto out;
5069
+ }
5070
+
5071
+ oparms.tcon = tcon;
5072
+ oparms.cifs_sb = cifs_sb;
5073
+ oparms.desired_access = GENERIC_WRITE;
5074
+ oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5075
+ CREATE_OPTION_SPECIAL);
5076
+ oparms.disposition = FILE_CREATE;
5077
+ oparms.path = full_path;
5078
+ oparms.fid = &fid;
5079
+ oparms.reconnect = false;
5080
+
5081
+ if (tcon->ses->server->oplocks)
5082
+ oplock = REQ_OPLOCK;
5083
+ else
5084
+ oplock = 0;
5085
+ rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
5086
+ if (rc)
5087
+ goto out;
5088
+
5089
+ /*
5090
+ * BB Do not bother to decode buf since no local inode yet to put
5091
+ * timestamps in, but we can reuse it safely.
5092
+ */
5093
+
5094
+ pdev = (struct win_dev *)buf;
5095
+ io_parms.pid = current->tgid;
5096
+ io_parms.tcon = tcon;
5097
+ io_parms.offset = 0;
5098
+ io_parms.length = sizeof(struct win_dev);
5099
+ iov[1].iov_base = buf;
5100
+ iov[1].iov_len = sizeof(struct win_dev);
5101
+ if (S_ISCHR(mode)) {
5102
+ memcpy(pdev->type, "IntxCHR", 8);
5103
+ pdev->major = cpu_to_le64(MAJOR(dev));
5104
+ pdev->minor = cpu_to_le64(MINOR(dev));
5105
+ rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5106
+ &bytes_written, iov, 1);
5107
+ } else if (S_ISBLK(mode)) {
5108
+ memcpy(pdev->type, "IntxBLK", 8);
5109
+ pdev->major = cpu_to_le64(MAJOR(dev));
5110
+ pdev->minor = cpu_to_le64(MINOR(dev));
5111
+ rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5112
+ &bytes_written, iov, 1);
5113
+ }
5114
+ tcon->ses->server->ops->close(xid, tcon, &fid);
5115
+ d_drop(dentry);
5116
+
5117
+ /* FIXME: add code here to set EAs */
5118
+out:
5119
+ kfree(buf);
5120
+ return rc;
5121
+}
5122
+
5123
+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
33545124 struct smb_version_operations smb20_operations = {
33555125 .compare_fids = smb2_compare_fids,
33565126 .setup_request = smb2_setup_request,
....@@ -3438,13 +5208,17 @@
34385208 .query_all_EAs = smb2_query_eas,
34395209 .set_EA = smb2_set_ea,
34405210 #endif /* CIFS_XATTR */
3441
-#ifdef CONFIG_CIFS_ACL
34425211 .get_acl = get_smb2_acl,
34435212 .get_acl_by_fid = get_smb2_acl_by_fid,
34445213 .set_acl = set_smb2_acl,
3445
-#endif /* CIFS_ACL */
34465214 .next_header = smb2_next_header,
5215
+ .ioctl_query_info = smb2_ioctl_query_info,
5216
+ .make_node = smb2_make_node,
5217
+ .fiemap = smb3_fiemap,
5218
+ .llseek = smb3_llseek,
5219
+ .is_status_io_timeout = smb2_is_status_io_timeout,
34475220 };
5221
+#endif /* CIFS_ALLOW_INSECURE_LEGACY */
34485222
34495223 struct smb_version_operations smb21_operations = {
34505224 .compare_fids = smb2_compare_fids,
....@@ -3456,6 +5230,7 @@
34565230 .get_credits_field = smb2_get_credits_field,
34575231 .get_credits = smb2_get_credits,
34585232 .wait_mtu_credits = smb2_wait_mtu_credits,
5233
+ .adjust_credits = smb2_adjust_credits,
34595234 .get_next_mid = smb2_get_next_mid,
34605235 .revert_current_mid = smb2_revert_current_mid,
34615236 .read_data_offset = smb2_read_data_offset,
....@@ -3528,18 +5303,22 @@
35285303 .wp_retry_size = smb2_wp_retry_size,
35295304 .dir_needs_close = smb2_dir_needs_close,
35305305 .enum_snapshots = smb3_enum_snapshots,
5306
+ .notify = smb3_notify,
35315307 .get_dfs_refer = smb2_get_dfs_refer,
35325308 .select_sectype = smb2_select_sectype,
35335309 #ifdef CONFIG_CIFS_XATTR
35345310 .query_all_EAs = smb2_query_eas,
35355311 .set_EA = smb2_set_ea,
35365312 #endif /* CIFS_XATTR */
3537
-#ifdef CONFIG_CIFS_ACL
35385313 .get_acl = get_smb2_acl,
35395314 .get_acl_by_fid = get_smb2_acl_by_fid,
35405315 .set_acl = set_smb2_acl,
3541
-#endif /* CIFS_ACL */
35425316 .next_header = smb2_next_header,
5317
+ .ioctl_query_info = smb2_ioctl_query_info,
5318
+ .make_node = smb2_make_node,
5319
+ .fiemap = smb3_fiemap,
5320
+ .llseek = smb3_llseek,
5321
+ .is_status_io_timeout = smb2_is_status_io_timeout,
35435322 };
35445323
35455324 struct smb_version_operations smb30_operations = {
....@@ -3552,6 +5331,7 @@
35525331 .get_credits_field = smb2_get_credits_field,
35535332 .get_credits = smb2_get_credits,
35545333 .wait_mtu_credits = smb2_wait_mtu_credits,
5334
+ .adjust_credits = smb2_adjust_credits,
35555335 .get_next_mid = smb2_get_next_mid,
35565336 .revert_current_mid = smb2_revert_current_mid,
35575337 .read_data_offset = smb2_read_data_offset,
....@@ -3568,8 +5348,8 @@
35685348 .downgrade_oplock = smb3_downgrade_oplock,
35695349 .need_neg = smb2_need_neg,
35705350 .negotiate = smb2_negotiate,
3571
- .negotiate_wsize = smb2_negotiate_wsize,
3572
- .negotiate_rsize = smb2_negotiate_rsize,
5351
+ .negotiate_wsize = smb3_negotiate_wsize,
5352
+ .negotiate_rsize = smb3_negotiate_rsize,
35735353 .sess_setup = SMB2_sess_setup,
35745354 .logoff = SMB2_logoff,
35755355 .tree_connect = SMB2_tcon,
....@@ -3579,6 +5359,8 @@
35795359 .can_echo = smb2_can_echo,
35805360 .echo = SMB2_echo,
35815361 .query_path_info = smb2_query_path_info,
5362
+ /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5363
+ .query_reparse_tag = smb2_query_reparse_tag,
35825364 .get_srv_inum = smb2_get_srv_inum,
35835365 .query_file_info = smb2_query_file_info,
35845366 .set_path_size = smb2_set_path_size,
....@@ -3597,6 +5379,7 @@
35975379 .open = smb2_open_file,
35985380 .set_fid = smb2_set_fid,
35995381 .close = smb2_close_file,
5382
+ .close_getattr = smb2_close_getattr,
36005383 .flush = smb2_flush_file,
36015384 .async_readv = smb2_async_readv,
36025385 .async_writev = smb2_async_writev,
....@@ -3630,6 +5413,7 @@
36305413 .dir_needs_close = smb2_dir_needs_close,
36315414 .fallocate = smb3_fallocate,
36325415 .enum_snapshots = smb3_enum_snapshots,
5416
+ .notify = smb3_notify,
36335417 .init_transform_rq = smb3_init_transform_rq,
36345418 .is_transform_hdr = smb3_is_transform_hdr,
36355419 .receive_transform = smb3_receive_transform,
....@@ -3639,12 +5423,15 @@
36395423 .query_all_EAs = smb2_query_eas,
36405424 .set_EA = smb2_set_ea,
36415425 #endif /* CIFS_XATTR */
3642
-#ifdef CONFIG_CIFS_ACL
36435426 .get_acl = get_smb2_acl,
36445427 .get_acl_by_fid = get_smb2_acl_by_fid,
36455428 .set_acl = set_smb2_acl,
3646
-#endif /* CIFS_ACL */
36475429 .next_header = smb2_next_header,
5430
+ .ioctl_query_info = smb2_ioctl_query_info,
5431
+ .make_node = smb2_make_node,
5432
+ .fiemap = smb3_fiemap,
5433
+ .llseek = smb3_llseek,
5434
+ .is_status_io_timeout = smb2_is_status_io_timeout,
36485435 };
36495436
36505437 struct smb_version_operations smb311_operations = {
....@@ -3657,6 +5444,7 @@
36575444 .get_credits_field = smb2_get_credits_field,
36585445 .get_credits = smb2_get_credits,
36595446 .wait_mtu_credits = smb2_wait_mtu_credits,
5447
+ .adjust_credits = smb2_adjust_credits,
36605448 .get_next_mid = smb2_get_next_mid,
36615449 .revert_current_mid = smb2_revert_current_mid,
36625450 .read_data_offset = smb2_read_data_offset,
....@@ -3673,8 +5461,8 @@
36735461 .downgrade_oplock = smb3_downgrade_oplock,
36745462 .need_neg = smb2_need_neg,
36755463 .negotiate = smb2_negotiate,
3676
- .negotiate_wsize = smb2_negotiate_wsize,
3677
- .negotiate_rsize = smb2_negotiate_rsize,
5464
+ .negotiate_wsize = smb3_negotiate_wsize,
5465
+ .negotiate_rsize = smb3_negotiate_rsize,
36785466 .sess_setup = SMB2_sess_setup,
36795467 .logoff = SMB2_logoff,
36805468 .tree_connect = SMB2_tcon,
....@@ -3684,6 +5472,7 @@
36845472 .can_echo = smb2_can_echo,
36855473 .echo = SMB2_echo,
36865474 .query_path_info = smb2_query_path_info,
5475
+ .query_reparse_tag = smb2_query_reparse_tag,
36875476 .get_srv_inum = smb2_get_srv_inum,
36885477 .query_file_info = smb2_query_file_info,
36895478 .set_path_size = smb2_set_path_size,
....@@ -3703,6 +5492,7 @@
37035492 .open = smb2_open_file,
37045493 .set_fid = smb2_set_fid,
37055494 .close = smb2_close_file,
5495
+ .close_getattr = smb2_close_getattr,
37065496 .flush = smb2_flush_file,
37075497 .async_readv = smb2_async_readv,
37085498 .async_writev = smb2_async_writev,
....@@ -3736,6 +5526,7 @@
37365526 .dir_needs_close = smb2_dir_needs_close,
37375527 .fallocate = smb3_fallocate,
37385528 .enum_snapshots = smb3_enum_snapshots,
5529
+ .notify = smb3_notify,
37395530 .init_transform_rq = smb3_init_transform_rq,
37405531 .is_transform_hdr = smb3_is_transform_hdr,
37415532 .receive_transform = smb3_receive_transform,
....@@ -3745,14 +5536,18 @@
37455536 .query_all_EAs = smb2_query_eas,
37465537 .set_EA = smb2_set_ea,
37475538 #endif /* CIFS_XATTR */
3748
-#ifdef CONFIG_CIFS_ACL
37495539 .get_acl = get_smb2_acl,
37505540 .get_acl_by_fid = get_smb2_acl_by_fid,
37515541 .set_acl = set_smb2_acl,
3752
-#endif /* CIFS_ACL */
37535542 .next_header = smb2_next_header,
5543
+ .ioctl_query_info = smb2_ioctl_query_info,
5544
+ .make_node = smb2_make_node,
5545
+ .fiemap = smb3_fiemap,
5546
+ .llseek = smb3_llseek,
5547
+ .is_status_io_timeout = smb2_is_status_io_timeout,
37545548 };
37555549
5550
+#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
37565551 struct smb_version_values smb20_values = {
37575552 .version_string = SMB20_VERSION_STRING,
37585553 .protocol_id = SMB20_PROT_ID,
....@@ -3773,6 +5568,7 @@
37735568 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
37745569 .create_lease_size = sizeof(struct create_lease),
37755570 };
5571
+#endif /* ALLOW_INSECURE_LEGACY */
37765572
37775573 struct smb_version_values smb21_values = {
37785574 .version_string = SMB21_VERSION_STRING,