]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/cifs/smb2ops.c
CIFS: Make SMB2_open use cifs_open_parms struct
[mirror_ubuntu-artful-kernel.git] / fs / cifs / smb2ops.c
CommitLineData
1080ef75
SF
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
3a3bab50 20#include <linux/pagemap.h>
6fc05c25 21#include <linux/vfs.h>
1080ef75 22#include "cifsglob.h"
2dc7e1c0
PS
23#include "smb2pdu.h"
24#include "smb2proto.h"
28ea5290
PS
25#include "cifsproto.h"
26#include "cifs_debug.h"
2e44b288 27#include "smb2status.h"
6fc05c25 28#include "smb2glob.h"
28ea5290
PS
29
30static int
31change_conf(struct TCP_Server_Info *server)
32{
33 server->credits += server->echo_credits + server->oplock_credits;
34 server->oplock_credits = server->echo_credits = 0;
35 switch (server->credits) {
36 case 0:
37 return -1;
38 case 1:
39 server->echoes = false;
40 server->oplocks = false;
f96637be 41 cifs_dbg(VFS, "disabling echoes and oplocks\n");
28ea5290
PS
42 break;
43 case 2:
44 server->echoes = true;
45 server->oplocks = false;
46 server->echo_credits = 1;
f96637be 47 cifs_dbg(FYI, "disabling oplocks\n");
28ea5290
PS
48 break;
49 default:
50 server->echoes = true;
51 server->oplocks = true;
52 server->echo_credits = 1;
53 server->oplock_credits = 1;
54 }
55 server->credits -= server->echo_credits + server->oplock_credits;
56 return 0;
57}
58
59static void
60smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
61 const int optype)
62{
63 int *val, rc = 0;
64 spin_lock(&server->req_lock);
65 val = server->ops->get_credits_field(server, optype);
66 *val += add;
67 server->in_flight--;
ec2e4523 68 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
28ea5290 69 rc = change_conf(server);
983c88a4
PS
70 /*
71 * Sometimes server returns 0 credits on oplock break ack - we need to
72 * rebalance credits in this case.
73 */
74 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
75 server->oplocks) {
76 if (server->credits > 1) {
77 server->credits--;
78 server->oplock_credits++;
79 }
80 }
28ea5290
PS
81 spin_unlock(&server->req_lock);
82 wake_up(&server->request_q);
83 if (rc)
84 cifs_reconnect(server);
85}
86
87static void
88smb2_set_credits(struct TCP_Server_Info *server, const int val)
89{
90 spin_lock(&server->req_lock);
91 server->credits = val;
92 spin_unlock(&server->req_lock);
93}
94
95static int *
96smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
97{
98 switch (optype) {
99 case CIFS_ECHO_OP:
100 return &server->echo_credits;
101 case CIFS_OBREAK_OP:
102 return &server->oplock_credits;
103 default:
104 return &server->credits;
105 }
106}
107
108static unsigned int
109smb2_get_credits(struct mid_q_entry *mid)
110{
111 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
112}
2dc7e1c0
PS
113
114static __u64
115smb2_get_next_mid(struct TCP_Server_Info *server)
116{
117 __u64 mid;
118 /* for SMB2 we need the current value */
119 spin_lock(&GlobalMid_Lock);
120 mid = server->CurrentMid++;
121 spin_unlock(&GlobalMid_Lock);
122 return mid;
123}
1080ef75 124
093b2bda
PS
125static struct mid_q_entry *
126smb2_find_mid(struct TCP_Server_Info *server, char *buf)
127{
128 struct mid_q_entry *mid;
129 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
130
131 spin_lock(&GlobalMid_Lock);
132 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
133 if ((mid->mid == hdr->MessageId) &&
134 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
135 (mid->command == hdr->Command)) {
136 spin_unlock(&GlobalMid_Lock);
137 return mid;
138 }
139 }
140 spin_unlock(&GlobalMid_Lock);
141 return NULL;
142}
143
144static void
145smb2_dump_detail(void *buf)
146{
147#ifdef CONFIG_CIFS_DEBUG2
148 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
149
f96637be
JP
150 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
151 smb->Command, smb->Status, smb->Flags, smb->MessageId,
152 smb->ProcessId);
153 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
093b2bda
PS
154#endif
155}
156
ec2e4523
PS
157static bool
158smb2_need_neg(struct TCP_Server_Info *server)
159{
160 return server->max_read == 0;
161}
162
163static int
164smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
165{
166 int rc;
167 ses->server->CurrentMid = 0;
168 rc = SMB2_negotiate(xid, ses);
169 /* BB we probably don't need to retry with modern servers */
170 if (rc == -EAGAIN)
171 rc = -EHOSTDOWN;
172 return rc;
173}
174
3a3bab50
PS
175static unsigned int
176smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
177{
178 struct TCP_Server_Info *server = tcon->ses->server;
179 unsigned int wsize;
180
181 /* start with specified wsize, or default */
182 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
183 wsize = min_t(unsigned int, wsize, server->max_write);
184 /*
185 * limit write size to 2 ** 16, because we don't support multicredit
186 * requests now.
187 */
188 wsize = min_t(unsigned int, wsize, 2 << 15);
189
3a3bab50
PS
190 return wsize;
191}
192
193static unsigned int
194smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
195{
196 struct TCP_Server_Info *server = tcon->ses->server;
197 unsigned int rsize;
198
199 /* start with specified rsize, or default */
200 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
201 rsize = min_t(unsigned int, rsize, server->max_read);
202 /*
203 * limit write size to 2 ** 16, because we don't support multicredit
204 * requests now.
205 */
206 rsize = min_t(unsigned int, rsize, 2 << 15);
207
3a3bab50
PS
208 return rsize;
209}
210
2503a0db
PS
211static int
212smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
213 struct cifs_sb_info *cifs_sb, const char *full_path)
214{
215 int rc;
2503a0db 216 __le16 *utf16_path;
2e44b288 217 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
064f6047
PS
218 struct cifs_open_parms oparms;
219 struct cifs_fid fid;
2503a0db
PS
220
221 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
222 if (!utf16_path)
223 return -ENOMEM;
224
064f6047
PS
225 oparms.tcon = tcon;
226 oparms.desired_access = FILE_READ_ATTRIBUTES;
227 oparms.disposition = FILE_OPEN;
228 oparms.create_options = 0;
229 oparms.fid = &fid;
230
231 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL);
2503a0db
PS
232 if (rc) {
233 kfree(utf16_path);
234 return rc;
235 }
236
064f6047 237 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2503a0db
PS
238 kfree(utf16_path);
239 return rc;
240}
241
be4cb9e3
PS
242static int
243smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
244 struct cifs_sb_info *cifs_sb, const char *full_path,
245 u64 *uniqueid, FILE_ALL_INFO *data)
246{
247 *uniqueid = le64_to_cpu(data->IndexNumber);
248 return 0;
249}
250
b7546bc5
PS
251static int
252smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
253 struct cifs_fid *fid, FILE_ALL_INFO *data)
254{
255 int rc;
256 struct smb2_file_all_info *smb2_data;
257
258 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
259 GFP_KERNEL);
260 if (smb2_data == NULL)
261 return -ENOMEM;
262
263 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
264 smb2_data);
265 if (!rc)
266 move_smb2_info_to_cifs(data, smb2_data);
267 kfree(smb2_data);
268 return rc;
269}
270
9094fad1
PS
271static bool
272smb2_can_echo(struct TCP_Server_Info *server)
273{
274 return server->echoes;
275}
276
d60622eb
PS
277static void
278smb2_clear_stats(struct cifs_tcon *tcon)
279{
280#ifdef CONFIG_CIFS_STATS
281 int i;
282 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
283 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
284 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
285 }
286#endif
287}
288
769ee6a4
SF
289static void
290smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
291{
292 seq_puts(m, "\n\tShare Capabilities:");
293 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
294 seq_puts(m, " DFS,");
295 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
296 seq_puts(m, " CONTINUOUS AVAILABILITY,");
297 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
298 seq_puts(m, " SCALEOUT,");
299 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
300 seq_puts(m, " CLUSTER,");
301 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
302 seq_puts(m, " ASYMMETRIC,");
303 if (tcon->capabilities == 0)
304 seq_puts(m, " None");
305 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
306}
307
d60622eb
PS
308static void
309smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
310{
311#ifdef CONFIG_CIFS_STATS
312 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
313 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
314 seq_printf(m, "\nNegotiates: %d sent %d failed",
315 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
316 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
317 seq_printf(m, "\nSessionSetups: %d sent %d failed",
318 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
319 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
d60622eb
PS
320 seq_printf(m, "\nLogoffs: %d sent %d failed",
321 atomic_read(&sent[SMB2_LOGOFF_HE]),
322 atomic_read(&failed[SMB2_LOGOFF_HE]));
323 seq_printf(m, "\nTreeConnects: %d sent %d failed",
324 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
325 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
326 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
327 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
328 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
329 seq_printf(m, "\nCreates: %d sent %d failed",
330 atomic_read(&sent[SMB2_CREATE_HE]),
331 atomic_read(&failed[SMB2_CREATE_HE]));
332 seq_printf(m, "\nCloses: %d sent %d failed",
333 atomic_read(&sent[SMB2_CLOSE_HE]),
334 atomic_read(&failed[SMB2_CLOSE_HE]));
335 seq_printf(m, "\nFlushes: %d sent %d failed",
336 atomic_read(&sent[SMB2_FLUSH_HE]),
337 atomic_read(&failed[SMB2_FLUSH_HE]));
338 seq_printf(m, "\nReads: %d sent %d failed",
339 atomic_read(&sent[SMB2_READ_HE]),
340 atomic_read(&failed[SMB2_READ_HE]));
341 seq_printf(m, "\nWrites: %d sent %d failed",
342 atomic_read(&sent[SMB2_WRITE_HE]),
343 atomic_read(&failed[SMB2_WRITE_HE]));
344 seq_printf(m, "\nLocks: %d sent %d failed",
345 atomic_read(&sent[SMB2_LOCK_HE]),
346 atomic_read(&failed[SMB2_LOCK_HE]));
347 seq_printf(m, "\nIOCTLs: %d sent %d failed",
348 atomic_read(&sent[SMB2_IOCTL_HE]),
349 atomic_read(&failed[SMB2_IOCTL_HE]));
350 seq_printf(m, "\nCancels: %d sent %d failed",
351 atomic_read(&sent[SMB2_CANCEL_HE]),
352 atomic_read(&failed[SMB2_CANCEL_HE]));
353 seq_printf(m, "\nEchos: %d sent %d failed",
354 atomic_read(&sent[SMB2_ECHO_HE]),
355 atomic_read(&failed[SMB2_ECHO_HE]));
356 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
357 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
358 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
359 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
360 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
361 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
362 seq_printf(m, "\nQueryInfos: %d sent %d failed",
363 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
364 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
365 seq_printf(m, "\nSetInfos: %d sent %d failed",
366 atomic_read(&sent[SMB2_SET_INFO_HE]),
367 atomic_read(&failed[SMB2_SET_INFO_HE]));
368 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
369 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
370 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
371#endif
372}
373
f0df737e
PS
374static void
375smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
376{
2e44b288 377 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
f0df737e
PS
378 cfile->fid.persistent_fid = fid->persistent_fid;
379 cfile->fid.volatile_fid = fid->volatile_fid;
2e44b288 380 smb2_set_oplock_level(cinode, oplock);
b140799a 381 cinode->can_cache_brlcks = cinode->clientCanCacheAll;
f0df737e
PS
382}
383
760ad0ca 384static void
f0df737e
PS
385smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
386 struct cifs_fid *fid)
387{
760ad0ca 388 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
f0df737e
PS
389}
390
7a5cfb19
PS
391static int
392smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
393 struct cifs_fid *fid)
394{
395 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
396}
397
09a4707e
PS
398static unsigned int
399smb2_read_data_offset(char *buf)
400{
401 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
402 return rsp->DataOffset;
403}
404
405static unsigned int
406smb2_read_data_length(char *buf)
407{
408 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
409 return le32_to_cpu(rsp->DataLength);
410}
411
d8e05039
PS
412
413static int
414smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
415 struct cifs_io_parms *parms, unsigned int *bytes_read,
416 char **buf, int *buf_type)
417{
418 parms->persistent_fid = cfile->fid.persistent_fid;
419 parms->volatile_fid = cfile->fid.volatile_fid;
420 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
421}
422
009d3443
PS
423static int
424smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
425 struct cifs_io_parms *parms, unsigned int *written,
426 struct kvec *iov, unsigned long nr_segs)
427{
428
429 parms->persistent_fid = cfile->fid.persistent_fid;
430 parms->volatile_fid = cfile->fid.volatile_fid;
431 return SMB2_write(xid, parms, written, iov, nr_segs);
432}
433
c839ff24
PS
434static int
435smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
436 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
437{
438 __le64 eof = cpu_to_le64(size);
439 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
440 cfile->fid.volatile_fid, cfile->pid, &eof);
441}
442
d324f08d
PS
443static int
444smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
445 const char *path, struct cifs_sb_info *cifs_sb,
446 struct cifs_fid *fid, __u16 search_flags,
447 struct cifs_search_info *srch_inf)
448{
449 __le16 *utf16_path;
450 int rc;
2e44b288 451 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
064f6047 452 struct cifs_open_parms oparms;
d324f08d
PS
453
454 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
455 if (!utf16_path)
456 return -ENOMEM;
457
064f6047
PS
458 oparms.tcon = tcon;
459 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
460 oparms.disposition = FILE_OPEN;
461 oparms.create_options = 0;
462 oparms.fid = fid;
463
464 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL);
d324f08d
PS
465 kfree(utf16_path);
466 if (rc) {
f96637be 467 cifs_dbg(VFS, "open dir failed\n");
d324f08d
PS
468 return rc;
469 }
470
471 srch_inf->entries_in_buffer = 0;
472 srch_inf->index_of_last_entry = 0;
d324f08d 473
064f6047
PS
474 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
475 fid->volatile_fid, 0, srch_inf);
d324f08d 476 if (rc) {
f96637be 477 cifs_dbg(VFS, "query directory failed\n");
064f6047 478 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
d324f08d
PS
479 }
480 return rc;
481}
482
483static int
484smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
485 struct cifs_fid *fid, __u16 search_flags,
486 struct cifs_search_info *srch_inf)
487{
488 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
489 fid->volatile_fid, 0, srch_inf);
490}
491
492static int
493smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
494 struct cifs_fid *fid)
495{
496 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
497}
498
2e44b288
PS
499/*
500* If we negotiate SMB2 protocol and get STATUS_PENDING - update
501* the number of credits and return true. Otherwise - return false.
502*/
503static bool
504smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
505{
506 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
507
12e8a208 508 if (hdr->Status != STATUS_PENDING)
2e44b288
PS
509 return false;
510
511 if (!length) {
512 spin_lock(&server->req_lock);
513 server->credits += le16_to_cpu(hdr->CreditRequest);
514 spin_unlock(&server->req_lock);
515 wake_up(&server->request_q);
516 }
517
518 return true;
519}
520
983c88a4
PS
521static int
522smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
523 struct cifsInodeInfo *cinode)
524{
0822f514
PS
525 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
526 return SMB2_lease_break(0, tcon, cinode->lease_key,
527 smb2_get_lease_state(cinode));
528
983c88a4
PS
529 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
530 fid->volatile_fid,
531 cinode->clientCanCacheRead ? 1 : 0);
532}
533
6fc05c25
PS
534static int
535smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
536 struct kstatfs *buf)
537{
538 int rc;
6fc05c25
PS
539 __le16 srch_path = 0; /* Null - open root of share */
540 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
064f6047
PS
541 struct cifs_open_parms oparms;
542 struct cifs_fid fid;
543
544 oparms.tcon = tcon;
545 oparms.desired_access = FILE_READ_ATTRIBUTES;
546 oparms.disposition = FILE_OPEN;
547 oparms.create_options = 0;
548 oparms.fid = &fid;
6fc05c25 549
064f6047 550 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL);
6fc05c25
PS
551 if (rc)
552 return rc;
553 buf->f_type = SMB2_MAGIC_NUMBER;
064f6047
PS
554 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
555 buf);
556 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
6fc05c25
PS
557 return rc;
558}
559
027e8eec
PS
560static bool
561smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
562{
563 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
564 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
565}
566
f7ba7fe6
PS
567static int
568smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
569 __u64 length, __u32 type, int lock, int unlock, bool wait)
570{
571 if (unlock && !lock)
572 type = SMB2_LOCKFLAG_UNLOCK;
573 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
574 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
575 current->tgid, length, offset, type, wait);
576}
577
b8c32dbb
PS
578static void
579smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
580{
581 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
582}
583
584static void
585smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
586{
587 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
588}
589
590static void
591smb2_new_lease_key(struct cifs_fid *fid)
592{
593 get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
594}
595
1080ef75 596struct smb_version_operations smb21_operations = {
027e8eec 597 .compare_fids = smb2_compare_fids,
2dc7e1c0 598 .setup_request = smb2_setup_request,
c95b8eed 599 .setup_async_request = smb2_setup_async_request,
2dc7e1c0 600 .check_receive = smb2_check_receive,
28ea5290
PS
601 .add_credits = smb2_add_credits,
602 .set_credits = smb2_set_credits,
603 .get_credits_field = smb2_get_credits_field,
604 .get_credits = smb2_get_credits,
2dc7e1c0 605 .get_next_mid = smb2_get_next_mid,
09a4707e
PS
606 .read_data_offset = smb2_read_data_offset,
607 .read_data_length = smb2_read_data_length,
608 .map_error = map_smb2_to_linux_error,
093b2bda
PS
609 .find_mid = smb2_find_mid,
610 .check_message = smb2_check_message,
611 .dump_detail = smb2_dump_detail,
d60622eb
PS
612 .clear_stats = smb2_clear_stats,
613 .print_stats = smb2_print_stats,
983c88a4 614 .is_oplock_break = smb2_is_valid_oplock_break,
ec2e4523
PS
615 .need_neg = smb2_need_neg,
616 .negotiate = smb2_negotiate,
3a3bab50
PS
617 .negotiate_wsize = smb2_negotiate_wsize,
618 .negotiate_rsize = smb2_negotiate_rsize,
5478f9ba
PS
619 .sess_setup = SMB2_sess_setup,
620 .logoff = SMB2_logoff,
faaf946a
PS
621 .tree_connect = SMB2_tcon,
622 .tree_disconnect = SMB2_tdis,
2503a0db 623 .is_path_accessible = smb2_is_path_accessible,
9094fad1
PS
624 .can_echo = smb2_can_echo,
625 .echo = SMB2_echo,
be4cb9e3
PS
626 .query_path_info = smb2_query_path_info,
627 .get_srv_inum = smb2_get_srv_inum,
b7546bc5 628 .query_file_info = smb2_query_file_info,
c839ff24
PS
629 .set_path_size = smb2_set_path_size,
630 .set_file_size = smb2_set_file_size,
1feeaac7 631 .set_file_info = smb2_set_file_info,
a0e73183
PS
632 .mkdir = smb2_mkdir,
633 .mkdir_setinfo = smb2_mkdir_setinfo,
1a500f01 634 .rmdir = smb2_rmdir,
cbe6f439 635 .unlink = smb2_unlink,
35143eb5 636 .rename = smb2_rename_path,
568798cc 637 .create_hardlink = smb2_create_hardlink,
f0df737e
PS
638 .open = smb2_open_file,
639 .set_fid = smb2_set_fid,
640 .close = smb2_close_file,
7a5cfb19 641 .flush = smb2_flush_file,
09a4707e 642 .async_readv = smb2_async_readv,
33319141 643 .async_writev = smb2_async_writev,
d8e05039 644 .sync_read = smb2_sync_read,
009d3443 645 .sync_write = smb2_sync_write,
d324f08d
PS
646 .query_dir_first = smb2_query_dir_first,
647 .query_dir_next = smb2_query_dir_next,
648 .close_dir = smb2_close_dir,
649 .calc_smb_size = smb2_calc_size,
2e44b288 650 .is_status_pending = smb2_is_status_pending,
983c88a4 651 .oplock_response = smb2_oplock_response,
6fc05c25 652 .queryfs = smb2_queryfs,
f7ba7fe6
PS
653 .mand_lock = smb2_mand_lock,
654 .mand_unlock_range = smb2_unlock_range,
b140799a 655 .push_mand_locks = smb2_push_mandatory_locks,
b8c32dbb
PS
656 .get_lease_key = smb2_get_lease_key,
657 .set_lease_key = smb2_set_lease_key,
658 .new_lease_key = smb2_new_lease_key,
38107d45
SF
659 .calc_signature = smb2_calc_signature,
660};
661
662
663struct smb_version_operations smb30_operations = {
664 .compare_fids = smb2_compare_fids,
665 .setup_request = smb2_setup_request,
666 .setup_async_request = smb2_setup_async_request,
667 .check_receive = smb2_check_receive,
668 .add_credits = smb2_add_credits,
669 .set_credits = smb2_set_credits,
670 .get_credits_field = smb2_get_credits_field,
671 .get_credits = smb2_get_credits,
672 .get_next_mid = smb2_get_next_mid,
673 .read_data_offset = smb2_read_data_offset,
674 .read_data_length = smb2_read_data_length,
675 .map_error = map_smb2_to_linux_error,
676 .find_mid = smb2_find_mid,
677 .check_message = smb2_check_message,
678 .dump_detail = smb2_dump_detail,
679 .clear_stats = smb2_clear_stats,
680 .print_stats = smb2_print_stats,
769ee6a4 681 .dump_share_caps = smb2_dump_share_caps,
38107d45
SF
682 .is_oplock_break = smb2_is_valid_oplock_break,
683 .need_neg = smb2_need_neg,
684 .negotiate = smb2_negotiate,
685 .negotiate_wsize = smb2_negotiate_wsize,
686 .negotiate_rsize = smb2_negotiate_rsize,
687 .sess_setup = SMB2_sess_setup,
688 .logoff = SMB2_logoff,
689 .tree_connect = SMB2_tcon,
690 .tree_disconnect = SMB2_tdis,
691 .is_path_accessible = smb2_is_path_accessible,
692 .can_echo = smb2_can_echo,
693 .echo = SMB2_echo,
694 .query_path_info = smb2_query_path_info,
695 .get_srv_inum = smb2_get_srv_inum,
696 .query_file_info = smb2_query_file_info,
697 .set_path_size = smb2_set_path_size,
698 .set_file_size = smb2_set_file_size,
699 .set_file_info = smb2_set_file_info,
700 .mkdir = smb2_mkdir,
701 .mkdir_setinfo = smb2_mkdir_setinfo,
702 .rmdir = smb2_rmdir,
703 .unlink = smb2_unlink,
704 .rename = smb2_rename_path,
705 .create_hardlink = smb2_create_hardlink,
706 .open = smb2_open_file,
707 .set_fid = smb2_set_fid,
708 .close = smb2_close_file,
709 .flush = smb2_flush_file,
710 .async_readv = smb2_async_readv,
711 .async_writev = smb2_async_writev,
712 .sync_read = smb2_sync_read,
713 .sync_write = smb2_sync_write,
714 .query_dir_first = smb2_query_dir_first,
715 .query_dir_next = smb2_query_dir_next,
716 .close_dir = smb2_close_dir,
717 .calc_smb_size = smb2_calc_size,
718 .is_status_pending = smb2_is_status_pending,
719 .oplock_response = smb2_oplock_response,
720 .queryfs = smb2_queryfs,
721 .mand_lock = smb2_mand_lock,
722 .mand_unlock_range = smb2_unlock_range,
723 .push_mand_locks = smb2_push_mandatory_locks,
724 .get_lease_key = smb2_get_lease_key,
725 .set_lease_key = smb2_set_lease_key,
726 .new_lease_key = smb2_new_lease_key,
e65a5cb4 727 .generate_signingkey = generate_smb3signingkey,
38107d45 728 .calc_signature = smb3_calc_signature,
1080ef75
SF
729};
730
dd446b16
SF
731struct smb_version_values smb20_values = {
732 .version_string = SMB20_VERSION_STRING,
733 .protocol_id = SMB20_PROT_ID,
734 .req_capabilities = 0, /* MBZ */
735 .large_lock_type = 0,
736 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
737 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
738 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
739 .header_size = sizeof(struct smb2_hdr),
740 .max_header_size = MAX_SMB2_HDR_SIZE,
741 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
742 .lock_cmd = SMB2_LOCK,
743 .cap_unix = 0,
744 .cap_nt_find = SMB2_NT_FIND,
745 .cap_large_files = SMB2_LARGE_FILES,
63b7d3a4 746 .oplock_read = SMB2_OPLOCK_LEVEL_II,
50285882
JL
747 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
748 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
dd446b16
SF
749};
750
1080ef75
SF
751struct smb_version_values smb21_values = {
752 .version_string = SMB21_VERSION_STRING,
e4aa25e7
SF
753 .protocol_id = SMB21_PROT_ID,
754 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
755 .large_lock_type = 0,
756 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
757 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
758 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
759 .header_size = sizeof(struct smb2_hdr),
760 .max_header_size = MAX_SMB2_HDR_SIZE,
761 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
762 .lock_cmd = SMB2_LOCK,
763 .cap_unix = 0,
764 .cap_nt_find = SMB2_NT_FIND,
765 .cap_large_files = SMB2_LARGE_FILES,
63b7d3a4 766 .oplock_read = SMB2_OPLOCK_LEVEL_II,
50285882
JL
767 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
768 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
e4aa25e7
SF
769};
770
771struct smb_version_values smb30_values = {
772 .version_string = SMB30_VERSION_STRING,
773 .protocol_id = SMB30_PROT_ID,
774 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
027e8eec
PS
775 .large_lock_type = 0,
776 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
777 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
778 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
093b2bda
PS
779 .header_size = sizeof(struct smb2_hdr),
780 .max_header_size = MAX_SMB2_HDR_SIZE,
09a4707e 781 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2dc7e1c0 782 .lock_cmd = SMB2_LOCK,
29e20f9c
PS
783 .cap_unix = 0,
784 .cap_nt_find = SMB2_NT_FIND,
785 .cap_large_files = SMB2_LARGE_FILES,
067785c4 786 .oplock_read = SMB2_OPLOCK_LEVEL_II,
50285882
JL
787 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
788 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1080ef75 789};
20b6d8b4
SF
790
791struct smb_version_values smb302_values = {
792 .version_string = SMB302_VERSION_STRING,
793 .protocol_id = SMB302_PROT_ID,
794 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
795 .large_lock_type = 0,
796 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
797 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
798 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
799 .header_size = sizeof(struct smb2_hdr),
800 .max_header_size = MAX_SMB2_HDR_SIZE,
801 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
802 .lock_cmd = SMB2_LOCK,
803 .cap_unix = 0,
804 .cap_nt_find = SMB2_NT_FIND,
805 .cap_large_files = SMB2_LARGE_FILES,
806 .oplock_read = SMB2_OPLOCK_LEVEL_II,
50285882
JL
807 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
808 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
20b6d8b4 809};