]> git.karo-electronics.de Git - karo-tx-linux.git/blob - fs/cifs/smb2ops.c
Query File System Alignment
[karo-tx-linux.git] / fs / cifs / smb2ops.c
1 /*
2  *  SMB2 version specific operations
3  *
4  *  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
18  */
19
20 #include <linux/pagemap.h>
21 #include <linux/vfs.h>
22 #include "cifsglob.h"
23 #include "smb2pdu.h"
24 #include "smb2proto.h"
25 #include "cifsproto.h"
26 #include "cifs_debug.h"
27 #include "cifs_unicode.h"
28 #include "smb2status.h"
29 #include "smb2glob.h"
30
31 static int
32 change_conf(struct TCP_Server_Info *server)
33 {
34         server->credits += server->echo_credits + server->oplock_credits;
35         server->oplock_credits = server->echo_credits = 0;
36         switch (server->credits) {
37         case 0:
38                 return -1;
39         case 1:
40                 server->echoes = false;
41                 server->oplocks = false;
42                 cifs_dbg(VFS, "disabling echoes and oplocks\n");
43                 break;
44         case 2:
45                 server->echoes = true;
46                 server->oplocks = false;
47                 server->echo_credits = 1;
48                 cifs_dbg(FYI, "disabling oplocks\n");
49                 break;
50         default:
51                 server->echoes = true;
52                 server->oplocks = true;
53                 server->echo_credits = 1;
54                 server->oplock_credits = 1;
55         }
56         server->credits -= server->echo_credits + server->oplock_credits;
57         return 0;
58 }
59
60 static void
61 smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
62                  const int optype)
63 {
64         int *val, rc = 0;
65         spin_lock(&server->req_lock);
66         val = server->ops->get_credits_field(server, optype);
67         *val += add;
68         server->in_flight--;
69         if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
70                 rc = change_conf(server);
71         /*
72          * Sometimes server returns 0 credits on oplock break ack - we need to
73          * rebalance credits in this case.
74          */
75         else if (server->in_flight > 0 && server->oplock_credits == 0 &&
76                  server->oplocks) {
77                 if (server->credits > 1) {
78                         server->credits--;
79                         server->oplock_credits++;
80                 }
81         }
82         spin_unlock(&server->req_lock);
83         wake_up(&server->request_q);
84         if (rc)
85                 cifs_reconnect(server);
86 }
87
88 static void
89 smb2_set_credits(struct TCP_Server_Info *server, const int val)
90 {
91         spin_lock(&server->req_lock);
92         server->credits = val;
93         spin_unlock(&server->req_lock);
94 }
95
96 static int *
97 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
98 {
99         switch (optype) {
100         case CIFS_ECHO_OP:
101                 return &server->echo_credits;
102         case CIFS_OBREAK_OP:
103                 return &server->oplock_credits;
104         default:
105                 return &server->credits;
106         }
107 }
108
109 static unsigned int
110 smb2_get_credits(struct mid_q_entry *mid)
111 {
112         return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
113 }
114
115 static __u64
116 smb2_get_next_mid(struct TCP_Server_Info *server)
117 {
118         __u64 mid;
119         /* for SMB2 we need the current value */
120         spin_lock(&GlobalMid_Lock);
121         mid = server->CurrentMid++;
122         spin_unlock(&GlobalMid_Lock);
123         return mid;
124 }
125
126 static struct mid_q_entry *
127 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
128 {
129         struct mid_q_entry *mid;
130         struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
131
132         spin_lock(&GlobalMid_Lock);
133         list_for_each_entry(mid, &server->pending_mid_q, qhead) {
134                 if ((mid->mid == hdr->MessageId) &&
135                     (mid->mid_state == MID_REQUEST_SUBMITTED) &&
136                     (mid->command == hdr->Command)) {
137                         spin_unlock(&GlobalMid_Lock);
138                         return mid;
139                 }
140         }
141         spin_unlock(&GlobalMid_Lock);
142         return NULL;
143 }
144
145 static void
146 smb2_dump_detail(void *buf)
147 {
148 #ifdef CONFIG_CIFS_DEBUG2
149         struct smb2_hdr *smb = (struct smb2_hdr *)buf;
150
151         cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
152                  smb->Command, smb->Status, smb->Flags, smb->MessageId,
153                  smb->ProcessId);
154         cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
155 #endif
156 }
157
158 static bool
159 smb2_need_neg(struct TCP_Server_Info *server)
160 {
161         return server->max_read == 0;
162 }
163
164 static int
165 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
166 {
167         int rc;
168         ses->server->CurrentMid = 0;
169         rc = SMB2_negotiate(xid, ses);
170         /* BB we probably don't need to retry with modern servers */
171         if (rc == -EAGAIN)
172                 rc = -EHOSTDOWN;
173         return rc;
174 }
175
176 static unsigned int
177 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
178 {
179         struct TCP_Server_Info *server = tcon->ses->server;
180         unsigned int wsize;
181
182         /* start with specified wsize, or default */
183         wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
184         wsize = min_t(unsigned int, wsize, server->max_write);
185         /*
186          * limit write size to 2 ** 16, because we don't support multicredit
187          * requests now.
188          */
189         wsize = min_t(unsigned int, wsize, 2 << 15);
190
191         return wsize;
192 }
193
194 static unsigned int
195 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
196 {
197         struct TCP_Server_Info *server = tcon->ses->server;
198         unsigned int rsize;
199
200         /* start with specified rsize, or default */
201         rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
202         rsize = min_t(unsigned int, rsize, server->max_read);
203         /*
204          * limit write size to 2 ** 16, because we don't support multicredit
205          * requests now.
206          */
207         rsize = min_t(unsigned int, rsize, 2 << 15);
208
209         return rsize;
210 }
211
212 static void
213 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
214 {
215         int rc;
216         __le16 srch_path = 0; /* Null - open root of share */
217         u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
218         struct cifs_open_parms oparms;
219         struct cifs_fid fid;
220
221         oparms.tcon = tcon;
222         oparms.desired_access = FILE_READ_ATTRIBUTES;
223         oparms.disposition = FILE_OPEN;
224         oparms.create_options = 0;
225         oparms.fid = &fid;
226         oparms.reconnect = false;
227
228         rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
229         if (rc)
230                 return;
231
232         SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
233                         FS_ATTRIBUTE_INFORMATION);
234         SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
235                         FS_DEVICE_INFORMATION);
236         SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
237                         FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
238         SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
239         return;
240 }
241
242 static void
243 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
244 {
245         int rc;
246         __le16 srch_path = 0; /* Null - open root of share */
247         u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
248         struct cifs_open_parms oparms;
249         struct cifs_fid fid;
250
251         oparms.tcon = tcon;
252         oparms.desired_access = FILE_READ_ATTRIBUTES;
253         oparms.disposition = FILE_OPEN;
254         oparms.create_options = 0;
255         oparms.fid = &fid;
256         oparms.reconnect = false;
257
258         rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
259         if (rc)
260                 return;
261
262         SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
263                         FS_ATTRIBUTE_INFORMATION);
264         SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
265                         FS_DEVICE_INFORMATION);
266         SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
267         return;
268 }
269
270 static int
271 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
272                         struct cifs_sb_info *cifs_sb, const char *full_path)
273 {
274         int rc;
275         __le16 *utf16_path;
276         __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
277         struct cifs_open_parms oparms;
278         struct cifs_fid fid;
279
280         utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
281         if (!utf16_path)
282                 return -ENOMEM;
283
284         oparms.tcon = tcon;
285         oparms.desired_access = FILE_READ_ATTRIBUTES;
286         oparms.disposition = FILE_OPEN;
287         oparms.create_options = 0;
288         oparms.fid = &fid;
289         oparms.reconnect = false;
290
291         rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
292         if (rc) {
293                 kfree(utf16_path);
294                 return rc;
295         }
296
297         rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
298         kfree(utf16_path);
299         return rc;
300 }
301
302 static int
303 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
304                   struct cifs_sb_info *cifs_sb, const char *full_path,
305                   u64 *uniqueid, FILE_ALL_INFO *data)
306 {
307         *uniqueid = le64_to_cpu(data->IndexNumber);
308         return 0;
309 }
310
311 static int
312 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
313                      struct cifs_fid *fid, FILE_ALL_INFO *data)
314 {
315         int rc;
316         struct smb2_file_all_info *smb2_data;
317
318         smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
319                             GFP_KERNEL);
320         if (smb2_data == NULL)
321                 return -ENOMEM;
322
323         rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
324                              smb2_data);
325         if (!rc)
326                 move_smb2_info_to_cifs(data, smb2_data);
327         kfree(smb2_data);
328         return rc;
329 }
330
331 static bool
332 smb2_can_echo(struct TCP_Server_Info *server)
333 {
334         return server->echoes;
335 }
336
337 static void
338 smb2_clear_stats(struct cifs_tcon *tcon)
339 {
340 #ifdef CONFIG_CIFS_STATS
341         int i;
342         for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
343                 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
344                 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
345         }
346 #endif
347 }
348
349 static void
350 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
351 {
352         seq_puts(m, "\n\tShare Capabilities:");
353         if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
354                 seq_puts(m, " DFS,");
355         if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
356                 seq_puts(m, " CONTINUOUS AVAILABILITY,");
357         if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
358                 seq_puts(m, " SCALEOUT,");
359         if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
360                 seq_puts(m, " CLUSTER,");
361         if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
362                 seq_puts(m, " ASYMMETRIC,");
363         if (tcon->capabilities == 0)
364                 seq_puts(m, " None");
365         if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
366                 seq_puts(m, " Aligned,");
367         if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
368                 seq_puts(m, " Partition Aligned,");
369         if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
370                 seq_puts(m, " SSD,");
371         if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
372                 seq_puts(m, " TRIM-support,");
373
374         seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
375         if (tcon->perf_sector_size)
376                 seq_printf(m, "\tOptimal sector size: 0x%x",
377                            tcon->perf_sector_size);
378 }
379
380 static void
381 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
382 {
383 #ifdef CONFIG_CIFS_STATS
384         atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
385         atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
386         seq_printf(m, "\nNegotiates: %d sent %d failed",
387                    atomic_read(&sent[SMB2_NEGOTIATE_HE]),
388                    atomic_read(&failed[SMB2_NEGOTIATE_HE]));
389         seq_printf(m, "\nSessionSetups: %d sent %d failed",
390                    atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
391                    atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
392         seq_printf(m, "\nLogoffs: %d sent %d failed",
393                    atomic_read(&sent[SMB2_LOGOFF_HE]),
394                    atomic_read(&failed[SMB2_LOGOFF_HE]));
395         seq_printf(m, "\nTreeConnects: %d sent %d failed",
396                    atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
397                    atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
398         seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
399                    atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
400                    atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
401         seq_printf(m, "\nCreates: %d sent %d failed",
402                    atomic_read(&sent[SMB2_CREATE_HE]),
403                    atomic_read(&failed[SMB2_CREATE_HE]));
404         seq_printf(m, "\nCloses: %d sent %d failed",
405                    atomic_read(&sent[SMB2_CLOSE_HE]),
406                    atomic_read(&failed[SMB2_CLOSE_HE]));
407         seq_printf(m, "\nFlushes: %d sent %d failed",
408                    atomic_read(&sent[SMB2_FLUSH_HE]),
409                    atomic_read(&failed[SMB2_FLUSH_HE]));
410         seq_printf(m, "\nReads: %d sent %d failed",
411                    atomic_read(&sent[SMB2_READ_HE]),
412                    atomic_read(&failed[SMB2_READ_HE]));
413         seq_printf(m, "\nWrites: %d sent %d failed",
414                    atomic_read(&sent[SMB2_WRITE_HE]),
415                    atomic_read(&failed[SMB2_WRITE_HE]));
416         seq_printf(m, "\nLocks: %d sent %d failed",
417                    atomic_read(&sent[SMB2_LOCK_HE]),
418                    atomic_read(&failed[SMB2_LOCK_HE]));
419         seq_printf(m, "\nIOCTLs: %d sent %d failed",
420                    atomic_read(&sent[SMB2_IOCTL_HE]),
421                    atomic_read(&failed[SMB2_IOCTL_HE]));
422         seq_printf(m, "\nCancels: %d sent %d failed",
423                    atomic_read(&sent[SMB2_CANCEL_HE]),
424                    atomic_read(&failed[SMB2_CANCEL_HE]));
425         seq_printf(m, "\nEchos: %d sent %d failed",
426                    atomic_read(&sent[SMB2_ECHO_HE]),
427                    atomic_read(&failed[SMB2_ECHO_HE]));
428         seq_printf(m, "\nQueryDirectories: %d sent %d failed",
429                    atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
430                    atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
431         seq_printf(m, "\nChangeNotifies: %d sent %d failed",
432                    atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
433                    atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
434         seq_printf(m, "\nQueryInfos: %d sent %d failed",
435                    atomic_read(&sent[SMB2_QUERY_INFO_HE]),
436                    atomic_read(&failed[SMB2_QUERY_INFO_HE]));
437         seq_printf(m, "\nSetInfos: %d sent %d failed",
438                    atomic_read(&sent[SMB2_SET_INFO_HE]),
439                    atomic_read(&failed[SMB2_SET_INFO_HE]));
440         seq_printf(m, "\nOplockBreaks: %d sent %d failed",
441                    atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
442                    atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
443 #endif
444 }
445
446 static void
447 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
448 {
449         struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
450         struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
451
452         cfile->fid.persistent_fid = fid->persistent_fid;
453         cfile->fid.volatile_fid = fid->volatile_fid;
454         server->ops->set_oplock_level(cinode, oplock, fid->epoch,
455                                       &fid->purge_cache);
456         cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
457 }
458
459 static void
460 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
461                 struct cifs_fid *fid)
462 {
463         SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
464 }
465
466 static int
467 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
468                 struct cifs_fid *fid)
469 {
470         return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
471 }
472
473 static unsigned int
474 smb2_read_data_offset(char *buf)
475 {
476         struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
477         return rsp->DataOffset;
478 }
479
480 static unsigned int
481 smb2_read_data_length(char *buf)
482 {
483         struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
484         return le32_to_cpu(rsp->DataLength);
485 }
486
487
488 static int
489 smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
490                struct cifs_io_parms *parms, unsigned int *bytes_read,
491                char **buf, int *buf_type)
492 {
493         parms->persistent_fid = cfile->fid.persistent_fid;
494         parms->volatile_fid = cfile->fid.volatile_fid;
495         return SMB2_read(xid, parms, bytes_read, buf, buf_type);
496 }
497
498 static int
499 smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
500                 struct cifs_io_parms *parms, unsigned int *written,
501                 struct kvec *iov, unsigned long nr_segs)
502 {
503
504         parms->persistent_fid = cfile->fid.persistent_fid;
505         parms->volatile_fid = cfile->fid.volatile_fid;
506         return SMB2_write(xid, parms, written, iov, nr_segs);
507 }
508
509 static int
510 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
511                    struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
512 {
513         __le64 eof = cpu_to_le64(size);
514         return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
515                             cfile->fid.volatile_fid, cfile->pid, &eof);
516 }
517
518 static int
519 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
520                    struct cifsFileInfo *cfile)
521 {
522         return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
523                             cfile->fid.volatile_fid);
524 }
525
526 static int
527 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
528                      const char *path, struct cifs_sb_info *cifs_sb,
529                      struct cifs_fid *fid, __u16 search_flags,
530                      struct cifs_search_info *srch_inf)
531 {
532         __le16 *utf16_path;
533         int rc;
534         __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
535         struct cifs_open_parms oparms;
536
537         utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
538         if (!utf16_path)
539                 return -ENOMEM;
540
541         oparms.tcon = tcon;
542         oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
543         oparms.disposition = FILE_OPEN;
544         oparms.create_options = 0;
545         oparms.fid = fid;
546         oparms.reconnect = false;
547
548         rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
549         kfree(utf16_path);
550         if (rc) {
551                 cifs_dbg(VFS, "open dir failed\n");
552                 return rc;
553         }
554
555         srch_inf->entries_in_buffer = 0;
556         srch_inf->index_of_last_entry = 0;
557
558         rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
559                                   fid->volatile_fid, 0, srch_inf);
560         if (rc) {
561                 cifs_dbg(VFS, "query directory failed\n");
562                 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
563         }
564         return rc;
565 }
566
567 static int
568 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
569                     struct cifs_fid *fid, __u16 search_flags,
570                     struct cifs_search_info *srch_inf)
571 {
572         return SMB2_query_directory(xid, tcon, fid->persistent_fid,
573                                     fid->volatile_fid, 0, srch_inf);
574 }
575
576 static int
577 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
578                struct cifs_fid *fid)
579 {
580         return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
581 }
582
583 /*
584 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
585 * the number of credits and return true. Otherwise - return false.
586 */
587 static bool
588 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
589 {
590         struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
591
592         if (hdr->Status != STATUS_PENDING)
593                 return false;
594
595         if (!length) {
596                 spin_lock(&server->req_lock);
597                 server->credits += le16_to_cpu(hdr->CreditRequest);
598                 spin_unlock(&server->req_lock);
599                 wake_up(&server->request_q);
600         }
601
602         return true;
603 }
604
605 static int
606 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
607                      struct cifsInodeInfo *cinode)
608 {
609         if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
610                 return SMB2_lease_break(0, tcon, cinode->lease_key,
611                                         smb2_get_lease_state(cinode));
612
613         return SMB2_oplock_break(0, tcon, fid->persistent_fid,
614                                  fid->volatile_fid,
615                                  CIFS_CACHE_READ(cinode) ? 1 : 0);
616 }
617
618 static int
619 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
620              struct kstatfs *buf)
621 {
622         int rc;
623         __le16 srch_path = 0; /* Null - open root of share */
624         u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
625         struct cifs_open_parms oparms;
626         struct cifs_fid fid;
627
628         oparms.tcon = tcon;
629         oparms.desired_access = FILE_READ_ATTRIBUTES;
630         oparms.disposition = FILE_OPEN;
631         oparms.create_options = 0;
632         oparms.fid = &fid;
633         oparms.reconnect = false;
634
635         rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
636         if (rc)
637                 return rc;
638         buf->f_type = SMB2_MAGIC_NUMBER;
639         rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
640                            buf);
641         SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
642         return rc;
643 }
644
645 static bool
646 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
647 {
648         return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
649                ob1->fid.volatile_fid == ob2->fid.volatile_fid;
650 }
651
652 static int
653 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
654                __u64 length, __u32 type, int lock, int unlock, bool wait)
655 {
656         if (unlock && !lock)
657                 type = SMB2_LOCKFLAG_UNLOCK;
658         return SMB2_lock(xid, tlink_tcon(cfile->tlink),
659                          cfile->fid.persistent_fid, cfile->fid.volatile_fid,
660                          current->tgid, length, offset, type, wait);
661 }
662
663 static void
664 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
665 {
666         memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
667 }
668
669 static void
670 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
671 {
672         memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
673 }
674
675 static void
676 smb2_new_lease_key(struct cifs_fid *fid)
677 {
678         get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
679 }
680
681 static int
682 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
683                    const char *full_path, char **target_path,
684                    struct cifs_sb_info *cifs_sb)
685 {
686         int rc;
687         __le16 *utf16_path;
688         __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
689         struct cifs_open_parms oparms;
690         struct cifs_fid fid;
691         struct smb2_err_rsp *err_buf = NULL;
692         struct smb2_symlink_err_rsp *symlink;
693         unsigned int sub_len, sub_offset;
694
695         cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
696
697         utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
698         if (!utf16_path)
699                 return -ENOMEM;
700
701         oparms.tcon = tcon;
702         oparms.desired_access = FILE_READ_ATTRIBUTES;
703         oparms.disposition = FILE_OPEN;
704         oparms.create_options = 0;
705         oparms.fid = &fid;
706         oparms.reconnect = false;
707
708         rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
709
710         if (!rc || !err_buf) {
711                 kfree(utf16_path);
712                 return -ENOENT;
713         }
714         /* open must fail on symlink - reset rc */
715         rc = 0;
716         symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
717         sub_len = le16_to_cpu(symlink->SubstituteNameLength);
718         sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
719         *target_path = cifs_strndup_from_utf16(
720                                 (char *)symlink->PathBuffer + sub_offset,
721                                 sub_len, true, cifs_sb->local_nls);
722         if (!(*target_path)) {
723                 kfree(utf16_path);
724                 return -ENOMEM;
725         }
726         convert_delimiter(*target_path, '/');
727         cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
728         kfree(utf16_path);
729         return rc;
730 }
731
732 static void
733 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
734                       unsigned int epoch, bool *purge_cache)
735 {
736         oplock &= 0xFF;
737         if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
738                 return;
739         if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
740                 cinode->oplock = CIFS_CACHE_RHW_FLG;
741                 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
742                          &cinode->vfs_inode);
743         } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
744                 cinode->oplock = CIFS_CACHE_RW_FLG;
745                 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
746                          &cinode->vfs_inode);
747         } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
748                 cinode->oplock = CIFS_CACHE_READ_FLG;
749                 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
750                          &cinode->vfs_inode);
751         } else
752                 cinode->oplock = 0;
753 }
754
755 static void
756 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
757                        unsigned int epoch, bool *purge_cache)
758 {
759         char message[5] = {0};
760
761         oplock &= 0xFF;
762         if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
763                 return;
764
765         cinode->oplock = 0;
766         if (oplock & SMB2_LEASE_READ_CACHING_HE) {
767                 cinode->oplock |= CIFS_CACHE_READ_FLG;
768                 strcat(message, "R");
769         }
770         if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
771                 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
772                 strcat(message, "H");
773         }
774         if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
775                 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
776                 strcat(message, "W");
777         }
778         if (!cinode->oplock)
779                 strcat(message, "None");
780         cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
781                  &cinode->vfs_inode);
782 }
783
784 static void
785 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
786                       unsigned int epoch, bool *purge_cache)
787 {
788         unsigned int old_oplock = cinode->oplock;
789
790         smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
791
792         if (purge_cache) {
793                 *purge_cache = false;
794                 if (old_oplock == CIFS_CACHE_READ_FLG) {
795                         if (cinode->oplock == CIFS_CACHE_READ_FLG &&
796                             (epoch - cinode->epoch > 0))
797                                 *purge_cache = true;
798                         else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
799                                  (epoch - cinode->epoch > 1))
800                                 *purge_cache = true;
801                         else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
802                                  (epoch - cinode->epoch > 1))
803                                 *purge_cache = true;
804                         else if (cinode->oplock == 0 &&
805                                  (epoch - cinode->epoch > 0))
806                                 *purge_cache = true;
807                 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
808                         if (cinode->oplock == CIFS_CACHE_RH_FLG &&
809                             (epoch - cinode->epoch > 0))
810                                 *purge_cache = true;
811                         else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
812                                  (epoch - cinode->epoch > 1))
813                                 *purge_cache = true;
814                 }
815                 cinode->epoch = epoch;
816         }
817 }
818
819 static bool
820 smb2_is_read_op(__u32 oplock)
821 {
822         return oplock == SMB2_OPLOCK_LEVEL_II;
823 }
824
825 static bool
826 smb21_is_read_op(__u32 oplock)
827 {
828         return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
829                !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
830 }
831
832 static __le32
833 map_oplock_to_lease(u8 oplock)
834 {
835         if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
836                 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
837         else if (oplock == SMB2_OPLOCK_LEVEL_II)
838                 return SMB2_LEASE_READ_CACHING;
839         else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
840                 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
841                        SMB2_LEASE_WRITE_CACHING;
842         return 0;
843 }
844
845 static char *
846 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
847 {
848         struct create_lease *buf;
849
850         buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
851         if (!buf)
852                 return NULL;
853
854         buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
855         buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
856         buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
857
858         buf->ccontext.DataOffset = cpu_to_le16(offsetof
859                                         (struct create_lease, lcontext));
860         buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
861         buf->ccontext.NameOffset = cpu_to_le16(offsetof
862                                 (struct create_lease, Name));
863         buf->ccontext.NameLength = cpu_to_le16(4);
864         buf->Name[0] = 'R';
865         buf->Name[1] = 'q';
866         buf->Name[2] = 'L';
867         buf->Name[3] = 's';
868         return (char *)buf;
869 }
870
871 static char *
872 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
873 {
874         struct create_lease_v2 *buf;
875
876         buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
877         if (!buf)
878                 return NULL;
879
880         buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
881         buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
882         buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
883
884         buf->ccontext.DataOffset = cpu_to_le16(offsetof
885                                         (struct create_lease_v2, lcontext));
886         buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
887         buf->ccontext.NameOffset = cpu_to_le16(offsetof
888                                 (struct create_lease_v2, Name));
889         buf->ccontext.NameLength = cpu_to_le16(4);
890         buf->Name[0] = 'R';
891         buf->Name[1] = 'q';
892         buf->Name[2] = 'L';
893         buf->Name[3] = 's';
894         return (char *)buf;
895 }
896
897 static __u8
898 smb2_parse_lease_buf(void *buf, unsigned int *epoch)
899 {
900         struct create_lease *lc = (struct create_lease *)buf;
901
902         *epoch = 0; /* not used */
903         if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
904                 return SMB2_OPLOCK_LEVEL_NOCHANGE;
905         return le32_to_cpu(lc->lcontext.LeaseState);
906 }
907
908 static __u8
909 smb3_parse_lease_buf(void *buf, unsigned int *epoch)
910 {
911         struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
912
913         *epoch = le16_to_cpu(lc->lcontext.Epoch);
914         if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
915                 return SMB2_OPLOCK_LEVEL_NOCHANGE;
916         return le32_to_cpu(lc->lcontext.LeaseState);
917 }
918
919 struct smb_version_operations smb20_operations = {
920         .compare_fids = smb2_compare_fids,
921         .setup_request = smb2_setup_request,
922         .setup_async_request = smb2_setup_async_request,
923         .check_receive = smb2_check_receive,
924         .add_credits = smb2_add_credits,
925         .set_credits = smb2_set_credits,
926         .get_credits_field = smb2_get_credits_field,
927         .get_credits = smb2_get_credits,
928         .get_next_mid = smb2_get_next_mid,
929         .read_data_offset = smb2_read_data_offset,
930         .read_data_length = smb2_read_data_length,
931         .map_error = map_smb2_to_linux_error,
932         .find_mid = smb2_find_mid,
933         .check_message = smb2_check_message,
934         .dump_detail = smb2_dump_detail,
935         .clear_stats = smb2_clear_stats,
936         .print_stats = smb2_print_stats,
937         .is_oplock_break = smb2_is_valid_oplock_break,
938         .need_neg = smb2_need_neg,
939         .negotiate = smb2_negotiate,
940         .negotiate_wsize = smb2_negotiate_wsize,
941         .negotiate_rsize = smb2_negotiate_rsize,
942         .sess_setup = SMB2_sess_setup,
943         .logoff = SMB2_logoff,
944         .tree_connect = SMB2_tcon,
945         .tree_disconnect = SMB2_tdis,
946         .qfs_tcon = smb2_qfs_tcon,
947         .is_path_accessible = smb2_is_path_accessible,
948         .can_echo = smb2_can_echo,
949         .echo = SMB2_echo,
950         .query_path_info = smb2_query_path_info,
951         .get_srv_inum = smb2_get_srv_inum,
952         .query_file_info = smb2_query_file_info,
953         .set_path_size = smb2_set_path_size,
954         .set_file_size = smb2_set_file_size,
955         .set_file_info = smb2_set_file_info,
956         .set_compression = smb2_set_compression,
957         .mkdir = smb2_mkdir,
958         .mkdir_setinfo = smb2_mkdir_setinfo,
959         .rmdir = smb2_rmdir,
960         .unlink = smb2_unlink,
961         .rename = smb2_rename_path,
962         .create_hardlink = smb2_create_hardlink,
963         .query_symlink = smb2_query_symlink,
964         .open = smb2_open_file,
965         .set_fid = smb2_set_fid,
966         .close = smb2_close_file,
967         .flush = smb2_flush_file,
968         .async_readv = smb2_async_readv,
969         .async_writev = smb2_async_writev,
970         .sync_read = smb2_sync_read,
971         .sync_write = smb2_sync_write,
972         .query_dir_first = smb2_query_dir_first,
973         .query_dir_next = smb2_query_dir_next,
974         .close_dir = smb2_close_dir,
975         .calc_smb_size = smb2_calc_size,
976         .is_status_pending = smb2_is_status_pending,
977         .oplock_response = smb2_oplock_response,
978         .queryfs = smb2_queryfs,
979         .mand_lock = smb2_mand_lock,
980         .mand_unlock_range = smb2_unlock_range,
981         .push_mand_locks = smb2_push_mandatory_locks,
982         .get_lease_key = smb2_get_lease_key,
983         .set_lease_key = smb2_set_lease_key,
984         .new_lease_key = smb2_new_lease_key,
985         .calc_signature = smb2_calc_signature,
986         .is_read_op = smb2_is_read_op,
987         .set_oplock_level = smb2_set_oplock_level,
988         .create_lease_buf = smb2_create_lease_buf,
989         .parse_lease_buf = smb2_parse_lease_buf,
990 };
991
992 struct smb_version_operations smb21_operations = {
993         .compare_fids = smb2_compare_fids,
994         .setup_request = smb2_setup_request,
995         .setup_async_request = smb2_setup_async_request,
996         .check_receive = smb2_check_receive,
997         .add_credits = smb2_add_credits,
998         .set_credits = smb2_set_credits,
999         .get_credits_field = smb2_get_credits_field,
1000         .get_credits = smb2_get_credits,
1001         .get_next_mid = smb2_get_next_mid,
1002         .read_data_offset = smb2_read_data_offset,
1003         .read_data_length = smb2_read_data_length,
1004         .map_error = map_smb2_to_linux_error,
1005         .find_mid = smb2_find_mid,
1006         .check_message = smb2_check_message,
1007         .dump_detail = smb2_dump_detail,
1008         .clear_stats = smb2_clear_stats,
1009         .print_stats = smb2_print_stats,
1010         .is_oplock_break = smb2_is_valid_oplock_break,
1011         .need_neg = smb2_need_neg,
1012         .negotiate = smb2_negotiate,
1013         .negotiate_wsize = smb2_negotiate_wsize,
1014         .negotiate_rsize = smb2_negotiate_rsize,
1015         .sess_setup = SMB2_sess_setup,
1016         .logoff = SMB2_logoff,
1017         .tree_connect = SMB2_tcon,
1018         .tree_disconnect = SMB2_tdis,
1019         .qfs_tcon = smb2_qfs_tcon,
1020         .is_path_accessible = smb2_is_path_accessible,
1021         .can_echo = smb2_can_echo,
1022         .echo = SMB2_echo,
1023         .query_path_info = smb2_query_path_info,
1024         .get_srv_inum = smb2_get_srv_inum,
1025         .query_file_info = smb2_query_file_info,
1026         .set_path_size = smb2_set_path_size,
1027         .set_file_size = smb2_set_file_size,
1028         .set_file_info = smb2_set_file_info,
1029         .set_compression = smb2_set_compression,
1030         .mkdir = smb2_mkdir,
1031         .mkdir_setinfo = smb2_mkdir_setinfo,
1032         .rmdir = smb2_rmdir,
1033         .unlink = smb2_unlink,
1034         .rename = smb2_rename_path,
1035         .create_hardlink = smb2_create_hardlink,
1036         .query_symlink = smb2_query_symlink,
1037         .open = smb2_open_file,
1038         .set_fid = smb2_set_fid,
1039         .close = smb2_close_file,
1040         .flush = smb2_flush_file,
1041         .async_readv = smb2_async_readv,
1042         .async_writev = smb2_async_writev,
1043         .sync_read = smb2_sync_read,
1044         .sync_write = smb2_sync_write,
1045         .query_dir_first = smb2_query_dir_first,
1046         .query_dir_next = smb2_query_dir_next,
1047         .close_dir = smb2_close_dir,
1048         .calc_smb_size = smb2_calc_size,
1049         .is_status_pending = smb2_is_status_pending,
1050         .oplock_response = smb2_oplock_response,
1051         .queryfs = smb2_queryfs,
1052         .mand_lock = smb2_mand_lock,
1053         .mand_unlock_range = smb2_unlock_range,
1054         .push_mand_locks = smb2_push_mandatory_locks,
1055         .get_lease_key = smb2_get_lease_key,
1056         .set_lease_key = smb2_set_lease_key,
1057         .new_lease_key = smb2_new_lease_key,
1058         .calc_signature = smb2_calc_signature,
1059         .is_read_op = smb21_is_read_op,
1060         .set_oplock_level = smb21_set_oplock_level,
1061         .create_lease_buf = smb2_create_lease_buf,
1062         .parse_lease_buf = smb2_parse_lease_buf,
1063 };
1064
1065 struct smb_version_operations smb30_operations = {
1066         .compare_fids = smb2_compare_fids,
1067         .setup_request = smb2_setup_request,
1068         .setup_async_request = smb2_setup_async_request,
1069         .check_receive = smb2_check_receive,
1070         .add_credits = smb2_add_credits,
1071         .set_credits = smb2_set_credits,
1072         .get_credits_field = smb2_get_credits_field,
1073         .get_credits = smb2_get_credits,
1074         .get_next_mid = smb2_get_next_mid,
1075         .read_data_offset = smb2_read_data_offset,
1076         .read_data_length = smb2_read_data_length,
1077         .map_error = map_smb2_to_linux_error,
1078         .find_mid = smb2_find_mid,
1079         .check_message = smb2_check_message,
1080         .dump_detail = smb2_dump_detail,
1081         .clear_stats = smb2_clear_stats,
1082         .print_stats = smb2_print_stats,
1083         .dump_share_caps = smb2_dump_share_caps,
1084         .is_oplock_break = smb2_is_valid_oplock_break,
1085         .need_neg = smb2_need_neg,
1086         .negotiate = smb2_negotiate,
1087         .negotiate_wsize = smb2_negotiate_wsize,
1088         .negotiate_rsize = smb2_negotiate_rsize,
1089         .sess_setup = SMB2_sess_setup,
1090         .logoff = SMB2_logoff,
1091         .tree_connect = SMB2_tcon,
1092         .tree_disconnect = SMB2_tdis,
1093         .qfs_tcon = smb3_qfs_tcon,
1094         .is_path_accessible = smb2_is_path_accessible,
1095         .can_echo = smb2_can_echo,
1096         .echo = SMB2_echo,
1097         .query_path_info = smb2_query_path_info,
1098         .get_srv_inum = smb2_get_srv_inum,
1099         .query_file_info = smb2_query_file_info,
1100         .set_path_size = smb2_set_path_size,
1101         .set_file_size = smb2_set_file_size,
1102         .set_file_info = smb2_set_file_info,
1103         .set_compression = smb2_set_compression,
1104         .mkdir = smb2_mkdir,
1105         .mkdir_setinfo = smb2_mkdir_setinfo,
1106         .rmdir = smb2_rmdir,
1107         .unlink = smb2_unlink,
1108         .rename = smb2_rename_path,
1109         .create_hardlink = smb2_create_hardlink,
1110         .query_symlink = smb2_query_symlink,
1111         .open = smb2_open_file,
1112         .set_fid = smb2_set_fid,
1113         .close = smb2_close_file,
1114         .flush = smb2_flush_file,
1115         .async_readv = smb2_async_readv,
1116         .async_writev = smb2_async_writev,
1117         .sync_read = smb2_sync_read,
1118         .sync_write = smb2_sync_write,
1119         .query_dir_first = smb2_query_dir_first,
1120         .query_dir_next = smb2_query_dir_next,
1121         .close_dir = smb2_close_dir,
1122         .calc_smb_size = smb2_calc_size,
1123         .is_status_pending = smb2_is_status_pending,
1124         .oplock_response = smb2_oplock_response,
1125         .queryfs = smb2_queryfs,
1126         .mand_lock = smb2_mand_lock,
1127         .mand_unlock_range = smb2_unlock_range,
1128         .push_mand_locks = smb2_push_mandatory_locks,
1129         .get_lease_key = smb2_get_lease_key,
1130         .set_lease_key = smb2_set_lease_key,
1131         .new_lease_key = smb2_new_lease_key,
1132         .generate_signingkey = generate_smb3signingkey,
1133         .calc_signature = smb3_calc_signature,
1134         .is_read_op = smb21_is_read_op,
1135         .set_oplock_level = smb3_set_oplock_level,
1136         .create_lease_buf = smb3_create_lease_buf,
1137         .parse_lease_buf = smb3_parse_lease_buf,
1138 };
1139
1140 struct smb_version_values smb20_values = {
1141         .version_string = SMB20_VERSION_STRING,
1142         .protocol_id = SMB20_PROT_ID,
1143         .req_capabilities = 0, /* MBZ */
1144         .large_lock_type = 0,
1145         .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1146         .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1147         .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1148         .header_size = sizeof(struct smb2_hdr),
1149         .max_header_size = MAX_SMB2_HDR_SIZE,
1150         .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1151         .lock_cmd = SMB2_LOCK,
1152         .cap_unix = 0,
1153         .cap_nt_find = SMB2_NT_FIND,
1154         .cap_large_files = SMB2_LARGE_FILES,
1155         .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1156         .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1157         .create_lease_size = sizeof(struct create_lease),
1158 };
1159
1160 struct smb_version_values smb21_values = {
1161         .version_string = SMB21_VERSION_STRING,
1162         .protocol_id = SMB21_PROT_ID,
1163         .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
1164         .large_lock_type = 0,
1165         .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1166         .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1167         .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1168         .header_size = sizeof(struct smb2_hdr),
1169         .max_header_size = MAX_SMB2_HDR_SIZE,
1170         .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1171         .lock_cmd = SMB2_LOCK,
1172         .cap_unix = 0,
1173         .cap_nt_find = SMB2_NT_FIND,
1174         .cap_large_files = SMB2_LARGE_FILES,
1175         .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1176         .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1177         .create_lease_size = sizeof(struct create_lease),
1178 };
1179
1180 struct smb_version_values smb30_values = {
1181         .version_string = SMB30_VERSION_STRING,
1182         .protocol_id = SMB30_PROT_ID,
1183         .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
1184         .large_lock_type = 0,
1185         .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1186         .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1187         .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1188         .header_size = sizeof(struct smb2_hdr),
1189         .max_header_size = MAX_SMB2_HDR_SIZE,
1190         .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1191         .lock_cmd = SMB2_LOCK,
1192         .cap_unix = 0,
1193         .cap_nt_find = SMB2_NT_FIND,
1194         .cap_large_files = SMB2_LARGE_FILES,
1195         .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1196         .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1197         .create_lease_size = sizeof(struct create_lease_v2),
1198 };
1199
1200 struct smb_version_values smb302_values = {
1201         .version_string = SMB302_VERSION_STRING,
1202         .protocol_id = SMB302_PROT_ID,
1203         .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
1204         .large_lock_type = 0,
1205         .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1206         .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1207         .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1208         .header_size = sizeof(struct smb2_hdr),
1209         .max_header_size = MAX_SMB2_HDR_SIZE,
1210         .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1211         .lock_cmd = SMB2_LOCK,
1212         .cap_unix = 0,
1213         .cap_nt_find = SMB2_NT_FIND,
1214         .cap_large_files = SMB2_LARGE_FILES,
1215         .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1216         .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1217         .create_lease_size = sizeof(struct create_lease_v2),
1218 };