2 * SMB2 version specific operations
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
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.
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.
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
20 #include <linux/pagemap.h>
21 #include <linux/vfs.h>
24 #include "smb2proto.h"
25 #include "cifsproto.h"
26 #include "cifs_debug.h"
27 #include "cifs_unicode.h"
28 #include "smb2status.h"
32 change_conf(struct TCP_Server_Info
*server
)
34 server
->credits
+= server
->echo_credits
+ server
->oplock_credits
;
35 server
->oplock_credits
= server
->echo_credits
= 0;
36 switch (server
->credits
) {
40 server
->echoes
= false;
41 server
->oplocks
= false;
42 cifs_dbg(VFS
, "disabling echoes and oplocks\n");
45 server
->echoes
= true;
46 server
->oplocks
= false;
47 server
->echo_credits
= 1;
48 cifs_dbg(FYI
, "disabling oplocks\n");
51 server
->echoes
= true;
52 server
->oplocks
= true;
53 server
->echo_credits
= 1;
54 server
->oplock_credits
= 1;
56 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
61 smb2_add_credits(struct TCP_Server_Info
*server
, const unsigned int add
,
65 spin_lock(&server
->req_lock
);
66 val
= server
->ops
->get_credits_field(server
, optype
);
69 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
70 rc
= change_conf(server
);
72 * Sometimes server returns 0 credits on oplock break ack - we need to
73 * rebalance credits in this case.
75 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
77 if (server
->credits
> 1) {
79 server
->oplock_credits
++;
82 spin_unlock(&server
->req_lock
);
83 wake_up(&server
->request_q
);
85 cifs_reconnect(server
);
89 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
91 spin_lock(&server
->req_lock
);
92 server
->credits
= val
;
93 spin_unlock(&server
->req_lock
);
97 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
101 return &server
->echo_credits
;
103 return &server
->oplock_credits
;
105 return &server
->credits
;
110 smb2_get_credits(struct mid_q_entry
*mid
)
112 return le16_to_cpu(((struct smb2_hdr
*)mid
->resp_buf
)->CreditRequest
);
116 smb2_get_next_mid(struct TCP_Server_Info
*server
)
119 /* for SMB2 we need the current value */
120 spin_lock(&GlobalMid_Lock
);
121 mid
= server
->CurrentMid
++;
122 spin_unlock(&GlobalMid_Lock
);
126 static struct mid_q_entry
*
127 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
129 struct mid_q_entry
*mid
;
130 struct smb2_hdr
*hdr
= (struct smb2_hdr
*)buf
;
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
);
141 spin_unlock(&GlobalMid_Lock
);
146 smb2_dump_detail(void *buf
)
148 #ifdef CONFIG_CIFS_DEBUG2
149 struct smb2_hdr
*smb
= (struct smb2_hdr
*)buf
;
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
,
154 cifs_dbg(VFS
, "smb buf %p len %u\n", smb
, smb2_calc_size(smb
));
159 smb2_need_neg(struct TCP_Server_Info
*server
)
161 return server
->max_read
== 0;
165 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
168 ses
->server
->CurrentMid
= 0;
169 rc
= SMB2_negotiate(xid
, ses
);
170 /* BB we probably don't need to retry with modern servers */
177 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
179 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
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
);
186 * limit write size to 2 ** 16, because we don't support multicredit
189 wsize
= min_t(unsigned int, wsize
, 2 << 15);
195 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
197 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
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
);
204 * limit write size to 2 ** 16, because we don't support multicredit
207 rsize
= min_t(unsigned int, rsize
, 2 << 15);
213 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
214 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
218 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
219 struct cifs_open_parms oparms
;
222 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
227 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
228 oparms
.disposition
= FILE_OPEN
;
229 oparms
.create_options
= 0;
231 oparms
.reconnect
= false;
233 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
239 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
245 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
246 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
247 u64
*uniqueid
, FILE_ALL_INFO
*data
)
249 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
254 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
255 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
258 struct smb2_file_all_info
*smb2_data
;
260 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + MAX_NAME
* 2,
262 if (smb2_data
== NULL
)
265 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
268 move_smb2_info_to_cifs(data
, smb2_data
);
274 smb2_can_echo(struct TCP_Server_Info
*server
)
276 return server
->echoes
;
280 smb2_clear_stats(struct cifs_tcon
*tcon
)
282 #ifdef CONFIG_CIFS_STATS
284 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
285 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
286 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
292 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
294 seq_puts(m
, "\n\tShare Capabilities:");
295 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
296 seq_puts(m
, " DFS,");
297 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
298 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
299 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
300 seq_puts(m
, " SCALEOUT,");
301 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
302 seq_puts(m
, " CLUSTER,");
303 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
304 seq_puts(m
, " ASYMMETRIC,");
305 if (tcon
->capabilities
== 0)
306 seq_puts(m
, " None");
307 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
311 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
313 #ifdef CONFIG_CIFS_STATS
314 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
315 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
316 seq_printf(m
, "\nNegotiates: %d sent %d failed",
317 atomic_read(&sent
[SMB2_NEGOTIATE_HE
]),
318 atomic_read(&failed
[SMB2_NEGOTIATE_HE
]));
319 seq_printf(m
, "\nSessionSetups: %d sent %d failed",
320 atomic_read(&sent
[SMB2_SESSION_SETUP_HE
]),
321 atomic_read(&failed
[SMB2_SESSION_SETUP_HE
]));
322 seq_printf(m
, "\nLogoffs: %d sent %d failed",
323 atomic_read(&sent
[SMB2_LOGOFF_HE
]),
324 atomic_read(&failed
[SMB2_LOGOFF_HE
]));
325 seq_printf(m
, "\nTreeConnects: %d sent %d failed",
326 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
327 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
328 seq_printf(m
, "\nTreeDisconnects: %d sent %d failed",
329 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
330 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
331 seq_printf(m
, "\nCreates: %d sent %d failed",
332 atomic_read(&sent
[SMB2_CREATE_HE
]),
333 atomic_read(&failed
[SMB2_CREATE_HE
]));
334 seq_printf(m
, "\nCloses: %d sent %d failed",
335 atomic_read(&sent
[SMB2_CLOSE_HE
]),
336 atomic_read(&failed
[SMB2_CLOSE_HE
]));
337 seq_printf(m
, "\nFlushes: %d sent %d failed",
338 atomic_read(&sent
[SMB2_FLUSH_HE
]),
339 atomic_read(&failed
[SMB2_FLUSH_HE
]));
340 seq_printf(m
, "\nReads: %d sent %d failed",
341 atomic_read(&sent
[SMB2_READ_HE
]),
342 atomic_read(&failed
[SMB2_READ_HE
]));
343 seq_printf(m
, "\nWrites: %d sent %d failed",
344 atomic_read(&sent
[SMB2_WRITE_HE
]),
345 atomic_read(&failed
[SMB2_WRITE_HE
]));
346 seq_printf(m
, "\nLocks: %d sent %d failed",
347 atomic_read(&sent
[SMB2_LOCK_HE
]),
348 atomic_read(&failed
[SMB2_LOCK_HE
]));
349 seq_printf(m
, "\nIOCTLs: %d sent %d failed",
350 atomic_read(&sent
[SMB2_IOCTL_HE
]),
351 atomic_read(&failed
[SMB2_IOCTL_HE
]));
352 seq_printf(m
, "\nCancels: %d sent %d failed",
353 atomic_read(&sent
[SMB2_CANCEL_HE
]),
354 atomic_read(&failed
[SMB2_CANCEL_HE
]));
355 seq_printf(m
, "\nEchos: %d sent %d failed",
356 atomic_read(&sent
[SMB2_ECHO_HE
]),
357 atomic_read(&failed
[SMB2_ECHO_HE
]));
358 seq_printf(m
, "\nQueryDirectories: %d sent %d failed",
359 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
360 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
361 seq_printf(m
, "\nChangeNotifies: %d sent %d failed",
362 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
363 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
364 seq_printf(m
, "\nQueryInfos: %d sent %d failed",
365 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
366 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
367 seq_printf(m
, "\nSetInfos: %d sent %d failed",
368 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
369 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
370 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
371 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
372 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
377 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
379 struct cifsInodeInfo
*cinode
= CIFS_I(cfile
->dentry
->d_inode
);
380 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
382 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
383 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
384 server
->ops
->set_oplock_level(cinode
, oplock
);
385 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
389 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
390 struct cifs_fid
*fid
)
392 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
396 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
397 struct cifs_fid
*fid
)
399 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
403 smb2_read_data_offset(char *buf
)
405 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
406 return rsp
->DataOffset
;
410 smb2_read_data_length(char *buf
)
412 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
413 return le32_to_cpu(rsp
->DataLength
);
418 smb2_sync_read(const unsigned int xid
, struct cifsFileInfo
*cfile
,
419 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
420 char **buf
, int *buf_type
)
422 parms
->persistent_fid
= cfile
->fid
.persistent_fid
;
423 parms
->volatile_fid
= cfile
->fid
.volatile_fid
;
424 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
428 smb2_sync_write(const unsigned int xid
, struct cifsFileInfo
*cfile
,
429 struct cifs_io_parms
*parms
, unsigned int *written
,
430 struct kvec
*iov
, unsigned long nr_segs
)
433 parms
->persistent_fid
= cfile
->fid
.persistent_fid
;
434 parms
->volatile_fid
= cfile
->fid
.volatile_fid
;
435 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
439 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
440 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
442 __le64 eof
= cpu_to_le64(size
);
443 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
444 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
448 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
449 const char *path
, struct cifs_sb_info
*cifs_sb
,
450 struct cifs_fid
*fid
, __u16 search_flags
,
451 struct cifs_search_info
*srch_inf
)
455 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
456 struct cifs_open_parms oparms
;
458 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
463 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
464 oparms
.disposition
= FILE_OPEN
;
465 oparms
.create_options
= 0;
467 oparms
.reconnect
= false;
469 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
472 cifs_dbg(VFS
, "open dir failed\n");
476 srch_inf
->entries_in_buffer
= 0;
477 srch_inf
->index_of_last_entry
= 0;
479 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
480 fid
->volatile_fid
, 0, srch_inf
);
482 cifs_dbg(VFS
, "query directory failed\n");
483 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
489 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
490 struct cifs_fid
*fid
, __u16 search_flags
,
491 struct cifs_search_info
*srch_inf
)
493 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
494 fid
->volatile_fid
, 0, srch_inf
);
498 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
499 struct cifs_fid
*fid
)
501 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
505 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
506 * the number of credits and return true. Otherwise - return false.
509 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
511 struct smb2_hdr
*hdr
= (struct smb2_hdr
*)buf
;
513 if (hdr
->Status
!= STATUS_PENDING
)
517 spin_lock(&server
->req_lock
);
518 server
->credits
+= le16_to_cpu(hdr
->CreditRequest
);
519 spin_unlock(&server
->req_lock
);
520 wake_up(&server
->request_q
);
527 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
528 struct cifsInodeInfo
*cinode
)
530 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
531 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
532 smb2_get_lease_state(cinode
));
534 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
536 CIFS_CACHE_READ(cinode
) ? 1 : 0);
540 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
544 __le16 srch_path
= 0; /* Null - open root of share */
545 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
546 struct cifs_open_parms oparms
;
550 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
551 oparms
.disposition
= FILE_OPEN
;
552 oparms
.create_options
= 0;
554 oparms
.reconnect
= false;
556 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
559 buf
->f_type
= SMB2_MAGIC_NUMBER
;
560 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
562 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
567 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
569 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
570 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
574 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
575 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
578 type
= SMB2_LOCKFLAG_UNLOCK
;
579 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
580 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
581 current
->tgid
, length
, offset
, type
, wait
);
585 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
587 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
591 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
593 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
597 smb2_new_lease_key(struct cifs_fid
*fid
)
599 get_random_bytes(fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
603 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
604 const char *full_path
, char **target_path
,
605 struct cifs_sb_info
*cifs_sb
)
609 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
610 struct cifs_open_parms oparms
;
612 struct smb2_err_rsp
*err_buf
= NULL
;
613 struct smb2_symlink_err_rsp
*symlink
;
614 unsigned int sub_len
, sub_offset
;
616 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
618 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
623 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
624 oparms
.disposition
= FILE_OPEN
;
625 oparms
.create_options
= 0;
627 oparms
.reconnect
= false;
629 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
631 if (!rc
|| !err_buf
) {
635 /* open must fail on symlink - reset rc */
637 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
638 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
639 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
640 *target_path
= cifs_strndup_from_utf16(
641 (char *)symlink
->PathBuffer
+ sub_offset
,
642 sub_len
, true, cifs_sb
->local_nls
);
643 if (!(*target_path
)) {
647 convert_delimiter(*target_path
, '/');
648 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
654 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
)
657 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
659 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
660 cinode
->oplock
= CIFS_CACHE_READ_FLG
| CIFS_CACHE_WRITE_FLG
|
661 CIFS_CACHE_HANDLE_FLG
;
662 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
664 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
665 cinode
->oplock
= CIFS_CACHE_READ_FLG
| CIFS_CACHE_WRITE_FLG
;
666 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
668 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
669 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
670 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
677 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
)
679 char message
[5] = {0};
682 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
686 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
687 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
688 strcat(message
, "R");
690 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
691 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
692 strcat(message
, "H");
694 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
695 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
696 strcat(message
, "W");
699 strcat(message
, "None");
700 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
705 smb2_is_read_op(__u32 oplock
)
707 return oplock
== SMB2_OPLOCK_LEVEL_II
;
711 smb21_is_read_op(__u32 oplock
)
713 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
714 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
718 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
720 struct create_lease
*buf
;
722 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
726 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
727 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
728 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
729 buf
->lcontext
.LeaseState
= SMB2_LEASE_WRITE_CACHING
|
730 SMB2_LEASE_READ_CACHING
;
731 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
732 buf
->lcontext
.LeaseState
= SMB2_LEASE_READ_CACHING
;
733 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
734 buf
->lcontext
.LeaseState
= SMB2_LEASE_HANDLE_CACHING
|
735 SMB2_LEASE_READ_CACHING
|
736 SMB2_LEASE_WRITE_CACHING
;
738 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
739 (struct create_lease
, lcontext
));
740 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
741 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
742 (struct create_lease
, Name
));
743 buf
->ccontext
.NameLength
= cpu_to_le16(4);
752 smb2_parse_lease_buf(void *buf
)
754 struct create_lease
*lc
= (struct create_lease
*)buf
;
756 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
757 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
758 return le32_to_cpu(lc
->lcontext
.LeaseState
);
761 struct smb_version_operations smb20_operations
= {
762 .compare_fids
= smb2_compare_fids
,
763 .setup_request
= smb2_setup_request
,
764 .setup_async_request
= smb2_setup_async_request
,
765 .check_receive
= smb2_check_receive
,
766 .add_credits
= smb2_add_credits
,
767 .set_credits
= smb2_set_credits
,
768 .get_credits_field
= smb2_get_credits_field
,
769 .get_credits
= smb2_get_credits
,
770 .get_next_mid
= smb2_get_next_mid
,
771 .read_data_offset
= smb2_read_data_offset
,
772 .read_data_length
= smb2_read_data_length
,
773 .map_error
= map_smb2_to_linux_error
,
774 .find_mid
= smb2_find_mid
,
775 .check_message
= smb2_check_message
,
776 .dump_detail
= smb2_dump_detail
,
777 .clear_stats
= smb2_clear_stats
,
778 .print_stats
= smb2_print_stats
,
779 .is_oplock_break
= smb2_is_valid_oplock_break
,
780 .need_neg
= smb2_need_neg
,
781 .negotiate
= smb2_negotiate
,
782 .negotiate_wsize
= smb2_negotiate_wsize
,
783 .negotiate_rsize
= smb2_negotiate_rsize
,
784 .sess_setup
= SMB2_sess_setup
,
785 .logoff
= SMB2_logoff
,
786 .tree_connect
= SMB2_tcon
,
787 .tree_disconnect
= SMB2_tdis
,
788 .is_path_accessible
= smb2_is_path_accessible
,
789 .can_echo
= smb2_can_echo
,
791 .query_path_info
= smb2_query_path_info
,
792 .get_srv_inum
= smb2_get_srv_inum
,
793 .query_file_info
= smb2_query_file_info
,
794 .set_path_size
= smb2_set_path_size
,
795 .set_file_size
= smb2_set_file_size
,
796 .set_file_info
= smb2_set_file_info
,
798 .mkdir_setinfo
= smb2_mkdir_setinfo
,
800 .unlink
= smb2_unlink
,
801 .rename
= smb2_rename_path
,
802 .create_hardlink
= smb2_create_hardlink
,
803 .query_symlink
= smb2_query_symlink
,
804 .open
= smb2_open_file
,
805 .set_fid
= smb2_set_fid
,
806 .close
= smb2_close_file
,
807 .flush
= smb2_flush_file
,
808 .async_readv
= smb2_async_readv
,
809 .async_writev
= smb2_async_writev
,
810 .sync_read
= smb2_sync_read
,
811 .sync_write
= smb2_sync_write
,
812 .query_dir_first
= smb2_query_dir_first
,
813 .query_dir_next
= smb2_query_dir_next
,
814 .close_dir
= smb2_close_dir
,
815 .calc_smb_size
= smb2_calc_size
,
816 .is_status_pending
= smb2_is_status_pending
,
817 .oplock_response
= smb2_oplock_response
,
818 .queryfs
= smb2_queryfs
,
819 .mand_lock
= smb2_mand_lock
,
820 .mand_unlock_range
= smb2_unlock_range
,
821 .push_mand_locks
= smb2_push_mandatory_locks
,
822 .get_lease_key
= smb2_get_lease_key
,
823 .set_lease_key
= smb2_set_lease_key
,
824 .new_lease_key
= smb2_new_lease_key
,
825 .calc_signature
= smb2_calc_signature
,
826 .is_read_op
= smb2_is_read_op
,
827 .set_oplock_level
= smb2_set_oplock_level
,
828 .create_lease_buf
= smb2_create_lease_buf
,
829 .parse_lease_buf
= smb2_parse_lease_buf
,
832 struct smb_version_operations smb21_operations
= {
833 .compare_fids
= smb2_compare_fids
,
834 .setup_request
= smb2_setup_request
,
835 .setup_async_request
= smb2_setup_async_request
,
836 .check_receive
= smb2_check_receive
,
837 .add_credits
= smb2_add_credits
,
838 .set_credits
= smb2_set_credits
,
839 .get_credits_field
= smb2_get_credits_field
,
840 .get_credits
= smb2_get_credits
,
841 .get_next_mid
= smb2_get_next_mid
,
842 .read_data_offset
= smb2_read_data_offset
,
843 .read_data_length
= smb2_read_data_length
,
844 .map_error
= map_smb2_to_linux_error
,
845 .find_mid
= smb2_find_mid
,
846 .check_message
= smb2_check_message
,
847 .dump_detail
= smb2_dump_detail
,
848 .clear_stats
= smb2_clear_stats
,
849 .print_stats
= smb2_print_stats
,
850 .is_oplock_break
= smb2_is_valid_oplock_break
,
851 .need_neg
= smb2_need_neg
,
852 .negotiate
= smb2_negotiate
,
853 .negotiate_wsize
= smb2_negotiate_wsize
,
854 .negotiate_rsize
= smb2_negotiate_rsize
,
855 .sess_setup
= SMB2_sess_setup
,
856 .logoff
= SMB2_logoff
,
857 .tree_connect
= SMB2_tcon
,
858 .tree_disconnect
= SMB2_tdis
,
859 .is_path_accessible
= smb2_is_path_accessible
,
860 .can_echo
= smb2_can_echo
,
862 .query_path_info
= smb2_query_path_info
,
863 .get_srv_inum
= smb2_get_srv_inum
,
864 .query_file_info
= smb2_query_file_info
,
865 .set_path_size
= smb2_set_path_size
,
866 .set_file_size
= smb2_set_file_size
,
867 .set_file_info
= smb2_set_file_info
,
869 .mkdir_setinfo
= smb2_mkdir_setinfo
,
871 .unlink
= smb2_unlink
,
872 .rename
= smb2_rename_path
,
873 .create_hardlink
= smb2_create_hardlink
,
874 .query_symlink
= smb2_query_symlink
,
875 .open
= smb2_open_file
,
876 .set_fid
= smb2_set_fid
,
877 .close
= smb2_close_file
,
878 .flush
= smb2_flush_file
,
879 .async_readv
= smb2_async_readv
,
880 .async_writev
= smb2_async_writev
,
881 .sync_read
= smb2_sync_read
,
882 .sync_write
= smb2_sync_write
,
883 .query_dir_first
= smb2_query_dir_first
,
884 .query_dir_next
= smb2_query_dir_next
,
885 .close_dir
= smb2_close_dir
,
886 .calc_smb_size
= smb2_calc_size
,
887 .is_status_pending
= smb2_is_status_pending
,
888 .oplock_response
= smb2_oplock_response
,
889 .queryfs
= smb2_queryfs
,
890 .mand_lock
= smb2_mand_lock
,
891 .mand_unlock_range
= smb2_unlock_range
,
892 .push_mand_locks
= smb2_push_mandatory_locks
,
893 .get_lease_key
= smb2_get_lease_key
,
894 .set_lease_key
= smb2_set_lease_key
,
895 .new_lease_key
= smb2_new_lease_key
,
896 .calc_signature
= smb2_calc_signature
,
897 .is_read_op
= smb21_is_read_op
,
898 .set_oplock_level
= smb21_set_oplock_level
,
899 .create_lease_buf
= smb2_create_lease_buf
,
900 .parse_lease_buf
= smb2_parse_lease_buf
,
903 struct smb_version_operations smb30_operations
= {
904 .compare_fids
= smb2_compare_fids
,
905 .setup_request
= smb2_setup_request
,
906 .setup_async_request
= smb2_setup_async_request
,
907 .check_receive
= smb2_check_receive
,
908 .add_credits
= smb2_add_credits
,
909 .set_credits
= smb2_set_credits
,
910 .get_credits_field
= smb2_get_credits_field
,
911 .get_credits
= smb2_get_credits
,
912 .get_next_mid
= smb2_get_next_mid
,
913 .read_data_offset
= smb2_read_data_offset
,
914 .read_data_length
= smb2_read_data_length
,
915 .map_error
= map_smb2_to_linux_error
,
916 .find_mid
= smb2_find_mid
,
917 .check_message
= smb2_check_message
,
918 .dump_detail
= smb2_dump_detail
,
919 .clear_stats
= smb2_clear_stats
,
920 .print_stats
= smb2_print_stats
,
921 .dump_share_caps
= smb2_dump_share_caps
,
922 .is_oplock_break
= smb2_is_valid_oplock_break
,
923 .need_neg
= smb2_need_neg
,
924 .negotiate
= smb2_negotiate
,
925 .negotiate_wsize
= smb2_negotiate_wsize
,
926 .negotiate_rsize
= smb2_negotiate_rsize
,
927 .sess_setup
= SMB2_sess_setup
,
928 .logoff
= SMB2_logoff
,
929 .tree_connect
= SMB2_tcon
,
930 .tree_disconnect
= SMB2_tdis
,
931 .is_path_accessible
= smb2_is_path_accessible
,
932 .can_echo
= smb2_can_echo
,
934 .query_path_info
= smb2_query_path_info
,
935 .get_srv_inum
= smb2_get_srv_inum
,
936 .query_file_info
= smb2_query_file_info
,
937 .set_path_size
= smb2_set_path_size
,
938 .set_file_size
= smb2_set_file_size
,
939 .set_file_info
= smb2_set_file_info
,
941 .mkdir_setinfo
= smb2_mkdir_setinfo
,
943 .unlink
= smb2_unlink
,
944 .rename
= smb2_rename_path
,
945 .create_hardlink
= smb2_create_hardlink
,
946 .query_symlink
= smb2_query_symlink
,
947 .open
= smb2_open_file
,
948 .set_fid
= smb2_set_fid
,
949 .close
= smb2_close_file
,
950 .flush
= smb2_flush_file
,
951 .async_readv
= smb2_async_readv
,
952 .async_writev
= smb2_async_writev
,
953 .sync_read
= smb2_sync_read
,
954 .sync_write
= smb2_sync_write
,
955 .query_dir_first
= smb2_query_dir_first
,
956 .query_dir_next
= smb2_query_dir_next
,
957 .close_dir
= smb2_close_dir
,
958 .calc_smb_size
= smb2_calc_size
,
959 .is_status_pending
= smb2_is_status_pending
,
960 .oplock_response
= smb2_oplock_response
,
961 .queryfs
= smb2_queryfs
,
962 .mand_lock
= smb2_mand_lock
,
963 .mand_unlock_range
= smb2_unlock_range
,
964 .push_mand_locks
= smb2_push_mandatory_locks
,
965 .get_lease_key
= smb2_get_lease_key
,
966 .set_lease_key
= smb2_set_lease_key
,
967 .new_lease_key
= smb2_new_lease_key
,
968 .generate_signingkey
= generate_smb3signingkey
,
969 .calc_signature
= smb3_calc_signature
,
970 .is_read_op
= smb21_is_read_op
,
971 .set_oplock_level
= smb21_set_oplock_level
,
972 .create_lease_buf
= smb2_create_lease_buf
,
973 .parse_lease_buf
= smb2_parse_lease_buf
,
976 struct smb_version_values smb20_values
= {
977 .version_string
= SMB20_VERSION_STRING
,
978 .protocol_id
= SMB20_PROT_ID
,
979 .req_capabilities
= 0, /* MBZ */
980 .large_lock_type
= 0,
981 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
982 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
983 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
984 .header_size
= sizeof(struct smb2_hdr
),
985 .max_header_size
= MAX_SMB2_HDR_SIZE
,
986 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
987 .lock_cmd
= SMB2_LOCK
,
989 .cap_nt_find
= SMB2_NT_FIND
,
990 .cap_large_files
= SMB2_LARGE_FILES
,
991 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
992 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
993 .create_lease_size
= sizeof(struct create_lease
),
996 struct smb_version_values smb21_values
= {
997 .version_string
= SMB21_VERSION_STRING
,
998 .protocol_id
= SMB21_PROT_ID
,
999 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
1000 .large_lock_type
= 0,
1001 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1002 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1003 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1004 .header_size
= sizeof(struct smb2_hdr
),
1005 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1006 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1007 .lock_cmd
= SMB2_LOCK
,
1009 .cap_nt_find
= SMB2_NT_FIND
,
1010 .cap_large_files
= SMB2_LARGE_FILES
,
1011 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1012 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1013 .create_lease_size
= sizeof(struct create_lease
),
1016 struct smb_version_values smb30_values
= {
1017 .version_string
= SMB30_VERSION_STRING
,
1018 .protocol_id
= SMB30_PROT_ID
,
1019 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
,
1020 .large_lock_type
= 0,
1021 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1022 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1023 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1024 .header_size
= sizeof(struct smb2_hdr
),
1025 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1026 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1027 .lock_cmd
= SMB2_LOCK
,
1029 .cap_nt_find
= SMB2_NT_FIND
,
1030 .cap_large_files
= SMB2_LARGE_FILES
,
1031 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1032 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1033 .create_lease_size
= sizeof(struct create_lease
),
1036 struct smb_version_values smb302_values
= {
1037 .version_string
= SMB302_VERSION_STRING
,
1038 .protocol_id
= SMB302_PROT_ID
,
1039 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
,
1040 .large_lock_type
= 0,
1041 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1042 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1043 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1044 .header_size
= sizeof(struct smb2_hdr
),
1045 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1046 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1047 .lock_cmd
= SMB2_LOCK
,
1049 .cap_nt_find
= SMB2_NT_FIND
,
1050 .cap_large_files
= SMB2_LARGE_FILES
,
1051 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1052 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1053 .create_lease_size
= sizeof(struct create_lease
),