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>
22 #include <linux/falloc.h>
25 #include "smb2proto.h"
26 #include "cifsproto.h"
27 #include "cifs_debug.h"
28 #include "cifs_unicode.h"
29 #include "smb2status.h"
33 change_conf(struct TCP_Server_Info
*server
)
35 server
->credits
+= server
->echo_credits
+ server
->oplock_credits
;
36 server
->oplock_credits
= server
->echo_credits
= 0;
37 switch (server
->credits
) {
41 server
->echoes
= false;
42 server
->oplocks
= false;
43 cifs_dbg(VFS
, "disabling echoes and oplocks\n");
46 server
->echoes
= true;
47 server
->oplocks
= false;
48 server
->echo_credits
= 1;
49 cifs_dbg(FYI
, "disabling oplocks\n");
52 server
->echoes
= true;
53 server
->oplocks
= true;
54 server
->echo_credits
= 1;
55 server
->oplock_credits
= 1;
57 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
62 smb2_add_credits(struct TCP_Server_Info
*server
, const unsigned int add
,
66 spin_lock(&server
->req_lock
);
67 val
= server
->ops
->get_credits_field(server
, optype
);
70 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
71 rc
= change_conf(server
);
73 * Sometimes server returns 0 credits on oplock break ack - we need to
74 * rebalance credits in this case.
76 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
78 if (server
->credits
> 1) {
80 server
->oplock_credits
++;
83 spin_unlock(&server
->req_lock
);
84 wake_up(&server
->request_q
);
86 cifs_reconnect(server
);
90 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
92 spin_lock(&server
->req_lock
);
93 server
->credits
= val
;
94 spin_unlock(&server
->req_lock
);
98 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
102 return &server
->echo_credits
;
104 return &server
->oplock_credits
;
106 return &server
->credits
;
111 smb2_get_credits(struct mid_q_entry
*mid
)
113 return le16_to_cpu(((struct smb2_hdr
*)mid
->resp_buf
)->CreditRequest
);
117 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
118 unsigned int *num
, unsigned int *credits
)
121 unsigned int scredits
;
123 spin_lock(&server
->req_lock
);
125 if (server
->credits
<= 0) {
126 spin_unlock(&server
->req_lock
);
127 cifs_num_waiters_inc(server
);
128 rc
= wait_event_killable(server
->request_q
,
129 has_credits(server
, &server
->credits
));
130 cifs_num_waiters_dec(server
);
133 spin_lock(&server
->req_lock
);
135 if (server
->tcpStatus
== CifsExiting
) {
136 spin_unlock(&server
->req_lock
);
140 scredits
= server
->credits
;
141 /* can deadlock with reopen */
143 *num
= SMB2_MAX_BUFFER_SIZE
;
148 /* leave one credit for a possible reopen */
150 *num
= min_t(unsigned int, size
,
151 scredits
* SMB2_MAX_BUFFER_SIZE
);
153 *credits
= DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
154 server
->credits
-= *credits
;
159 spin_unlock(&server
->req_lock
);
164 smb2_get_next_mid(struct TCP_Server_Info
*server
)
167 /* for SMB2 we need the current value */
168 spin_lock(&GlobalMid_Lock
);
169 mid
= server
->CurrentMid
++;
170 spin_unlock(&GlobalMid_Lock
);
174 static struct mid_q_entry
*
175 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
177 struct mid_q_entry
*mid
;
178 struct smb2_hdr
*hdr
= (struct smb2_hdr
*)buf
;
180 spin_lock(&GlobalMid_Lock
);
181 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
182 if ((mid
->mid
== hdr
->MessageId
) &&
183 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
184 (mid
->command
== hdr
->Command
)) {
185 spin_unlock(&GlobalMid_Lock
);
189 spin_unlock(&GlobalMid_Lock
);
194 smb2_dump_detail(void *buf
)
196 #ifdef CONFIG_CIFS_DEBUG2
197 struct smb2_hdr
*smb
= (struct smb2_hdr
*)buf
;
199 cifs_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
200 smb
->Command
, smb
->Status
, smb
->Flags
, smb
->MessageId
,
202 cifs_dbg(VFS
, "smb buf %p len %u\n", smb
, smb2_calc_size(smb
));
207 smb2_need_neg(struct TCP_Server_Info
*server
)
209 return server
->max_read
== 0;
213 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
216 ses
->server
->CurrentMid
= 0;
217 rc
= SMB2_negotiate(xid
, ses
);
218 /* BB we probably don't need to retry with modern servers */
225 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
227 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
230 /* start with specified wsize, or default */
231 wsize
= volume_info
->wsize
? volume_info
->wsize
: CIFS_DEFAULT_IOSIZE
;
232 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
234 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
235 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
241 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
243 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
246 /* start with specified rsize, or default */
247 rsize
= volume_info
->rsize
? volume_info
->rsize
: CIFS_DEFAULT_IOSIZE
;
248 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
250 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
251 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
256 #ifdef CONFIG_CIFS_STATS2
258 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
261 unsigned int ret_data_len
= 0;
262 struct network_interface_info_ioctl_rsp
*out_buf
;
264 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
265 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
266 NULL
/* no data input */, 0 /* no data input */,
267 (char **)&out_buf
, &ret_data_len
);
269 if ((rc
== 0) && (ret_data_len
> 0)) {
270 /* Dump info on first interface */
271 cifs_dbg(FYI
, "Adapter Capability 0x%x\t",
272 le32_to_cpu(out_buf
->Capability
));
273 cifs_dbg(FYI
, "Link Speed %lld\n",
274 le64_to_cpu(out_buf
->LinkSpeed
));
276 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
283 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
286 __le16 srch_path
= 0; /* Null - open root of share */
287 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
288 struct cifs_open_parms oparms
;
292 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
293 oparms
.disposition
= FILE_OPEN
;
294 oparms
.create_options
= 0;
296 oparms
.reconnect
= false;
298 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
302 #ifdef CONFIG_CIFS_STATS2
303 SMB3_request_interfaces(xid
, tcon
);
306 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
307 FS_ATTRIBUTE_INFORMATION
);
308 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
309 FS_DEVICE_INFORMATION
);
310 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
311 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
312 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
317 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
320 __le16 srch_path
= 0; /* Null - open root of share */
321 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
322 struct cifs_open_parms oparms
;
326 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
327 oparms
.disposition
= FILE_OPEN
;
328 oparms
.create_options
= 0;
330 oparms
.reconnect
= false;
332 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
336 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
337 FS_ATTRIBUTE_INFORMATION
);
338 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
339 FS_DEVICE_INFORMATION
);
340 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
345 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
346 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
350 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
351 struct cifs_open_parms oparms
;
354 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
359 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
360 oparms
.disposition
= FILE_OPEN
;
361 oparms
.create_options
= 0;
363 oparms
.reconnect
= false;
365 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
371 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
377 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
378 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
379 u64
*uniqueid
, FILE_ALL_INFO
*data
)
381 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
386 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
387 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
390 struct smb2_file_all_info
*smb2_data
;
392 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + MAX_NAME
* 2,
394 if (smb2_data
== NULL
)
397 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
400 move_smb2_info_to_cifs(data
, smb2_data
);
406 smb2_can_echo(struct TCP_Server_Info
*server
)
408 return server
->echoes
;
412 smb2_clear_stats(struct cifs_tcon
*tcon
)
414 #ifdef CONFIG_CIFS_STATS
416 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
417 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
418 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
424 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
426 seq_puts(m
, "\n\tShare Capabilities:");
427 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
428 seq_puts(m
, " DFS,");
429 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
430 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
431 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
432 seq_puts(m
, " SCALEOUT,");
433 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
434 seq_puts(m
, " CLUSTER,");
435 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
436 seq_puts(m
, " ASYMMETRIC,");
437 if (tcon
->capabilities
== 0)
438 seq_puts(m
, " None");
439 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
440 seq_puts(m
, " Aligned,");
441 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
442 seq_puts(m
, " Partition Aligned,");
443 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
444 seq_puts(m
, " SSD,");
445 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
446 seq_puts(m
, " TRIM-support,");
448 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
449 if (tcon
->perf_sector_size
)
450 seq_printf(m
, "\tOptimal sector size: 0x%x",
451 tcon
->perf_sector_size
);
455 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
457 #ifdef CONFIG_CIFS_STATS
458 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
459 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
460 seq_printf(m
, "\nNegotiates: %d sent %d failed",
461 atomic_read(&sent
[SMB2_NEGOTIATE_HE
]),
462 atomic_read(&failed
[SMB2_NEGOTIATE_HE
]));
463 seq_printf(m
, "\nSessionSetups: %d sent %d failed",
464 atomic_read(&sent
[SMB2_SESSION_SETUP_HE
]),
465 atomic_read(&failed
[SMB2_SESSION_SETUP_HE
]));
466 seq_printf(m
, "\nLogoffs: %d sent %d failed",
467 atomic_read(&sent
[SMB2_LOGOFF_HE
]),
468 atomic_read(&failed
[SMB2_LOGOFF_HE
]));
469 seq_printf(m
, "\nTreeConnects: %d sent %d failed",
470 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
471 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
472 seq_printf(m
, "\nTreeDisconnects: %d sent %d failed",
473 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
474 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
475 seq_printf(m
, "\nCreates: %d sent %d failed",
476 atomic_read(&sent
[SMB2_CREATE_HE
]),
477 atomic_read(&failed
[SMB2_CREATE_HE
]));
478 seq_printf(m
, "\nCloses: %d sent %d failed",
479 atomic_read(&sent
[SMB2_CLOSE_HE
]),
480 atomic_read(&failed
[SMB2_CLOSE_HE
]));
481 seq_printf(m
, "\nFlushes: %d sent %d failed",
482 atomic_read(&sent
[SMB2_FLUSH_HE
]),
483 atomic_read(&failed
[SMB2_FLUSH_HE
]));
484 seq_printf(m
, "\nReads: %d sent %d failed",
485 atomic_read(&sent
[SMB2_READ_HE
]),
486 atomic_read(&failed
[SMB2_READ_HE
]));
487 seq_printf(m
, "\nWrites: %d sent %d failed",
488 atomic_read(&sent
[SMB2_WRITE_HE
]),
489 atomic_read(&failed
[SMB2_WRITE_HE
]));
490 seq_printf(m
, "\nLocks: %d sent %d failed",
491 atomic_read(&sent
[SMB2_LOCK_HE
]),
492 atomic_read(&failed
[SMB2_LOCK_HE
]));
493 seq_printf(m
, "\nIOCTLs: %d sent %d failed",
494 atomic_read(&sent
[SMB2_IOCTL_HE
]),
495 atomic_read(&failed
[SMB2_IOCTL_HE
]));
496 seq_printf(m
, "\nCancels: %d sent %d failed",
497 atomic_read(&sent
[SMB2_CANCEL_HE
]),
498 atomic_read(&failed
[SMB2_CANCEL_HE
]));
499 seq_printf(m
, "\nEchos: %d sent %d failed",
500 atomic_read(&sent
[SMB2_ECHO_HE
]),
501 atomic_read(&failed
[SMB2_ECHO_HE
]));
502 seq_printf(m
, "\nQueryDirectories: %d sent %d failed",
503 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
504 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
505 seq_printf(m
, "\nChangeNotifies: %d sent %d failed",
506 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
507 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
508 seq_printf(m
, "\nQueryInfos: %d sent %d failed",
509 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
510 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
511 seq_printf(m
, "\nSetInfos: %d sent %d failed",
512 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
513 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
514 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
515 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
516 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
521 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
523 struct cifsInodeInfo
*cinode
= CIFS_I(cfile
->dentry
->d_inode
);
524 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
526 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
527 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
528 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
530 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
534 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
535 struct cifs_fid
*fid
)
537 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
541 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
542 u64 persistent_fid
, u64 volatile_fid
,
543 struct copychunk_ioctl
*pcchunk
)
546 unsigned int ret_data_len
;
547 struct resume_key_req
*res_key
;
549 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
550 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
551 NULL
, 0 /* no input */,
552 (char **)&res_key
, &ret_data_len
);
555 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
556 goto req_res_key_exit
;
558 if (ret_data_len
< sizeof(struct resume_key_req
)) {
559 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
561 goto req_res_key_exit
;
563 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
571 smb2_clone_range(const unsigned int xid
,
572 struct cifsFileInfo
*srcfile
,
573 struct cifsFileInfo
*trgtfile
, u64 src_off
,
574 u64 len
, u64 dest_off
)
577 unsigned int ret_data_len
;
578 struct copychunk_ioctl
*pcchunk
;
579 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
580 struct cifs_tcon
*tcon
;
581 int chunks_copied
= 0;
582 bool chunk_sizes_updated
= false;
584 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
589 cifs_dbg(FYI
, "in smb2_clone_range - about to call request res key\n");
590 /* Request a key from the server to identify the source of the copy */
591 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
592 srcfile
->fid
.persistent_fid
,
593 srcfile
->fid
.volatile_fid
, pcchunk
);
595 /* Note: request_res_key sets res_key null only if rc !=0 */
599 /* For now array only one chunk long, will make more flexible later */
600 pcchunk
->ChunkCount
= __constant_cpu_to_le32(1);
601 pcchunk
->Reserved
= 0;
602 pcchunk
->Reserved2
= 0;
604 tcon
= tlink_tcon(trgtfile
->tlink
);
607 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
608 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
610 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
612 /* Request server copy to target from src identified by key */
613 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
614 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
615 true /* is_fsctl */, (char *)pcchunk
,
616 sizeof(struct copychunk_ioctl
), (char **)&retbuf
,
620 sizeof(struct copychunk_ioctl_rsp
)) {
621 cifs_dbg(VFS
, "invalid cchunk response size\n");
625 if (retbuf
->TotalBytesWritten
== 0) {
626 cifs_dbg(FYI
, "no bytes copied\n");
631 * Check if server claimed to write more than we asked
633 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
634 le32_to_cpu(pcchunk
->Length
)) {
635 cifs_dbg(VFS
, "invalid copy chunk response\n");
639 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
640 cifs_dbg(VFS
, "invalid num chunks written\n");
646 src_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
647 dest_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
648 len
-= le32_to_cpu(retbuf
->TotalBytesWritten
);
650 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %d\n",
651 le32_to_cpu(retbuf
->ChunksWritten
),
652 le32_to_cpu(retbuf
->ChunkBytesWritten
),
653 le32_to_cpu(retbuf
->TotalBytesWritten
));
654 } else if (rc
== -EINVAL
) {
655 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
658 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
659 le32_to_cpu(retbuf
->ChunksWritten
),
660 le32_to_cpu(retbuf
->ChunkBytesWritten
),
661 le32_to_cpu(retbuf
->TotalBytesWritten
));
664 * Check if this is the first request using these sizes,
665 * (ie check if copy succeed once with original sizes
666 * and check if the server gave us different sizes after
667 * we already updated max sizes on previous request).
668 * if not then why is the server returning an error now
670 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
673 /* Check that server is not asking us to grow size */
674 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
675 tcon
->max_bytes_chunk
)
676 tcon
->max_bytes_chunk
=
677 le32_to_cpu(retbuf
->ChunkBytesWritten
);
679 goto cchunk_out
; /* server gave us bogus size */
681 /* No need to change MaxChunks since already set to 1 */
682 chunk_sizes_updated
= true;
692 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
693 struct cifs_fid
*fid
)
695 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
699 smb2_read_data_offset(char *buf
)
701 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
702 return rsp
->DataOffset
;
706 smb2_read_data_length(char *buf
)
708 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
709 return le32_to_cpu(rsp
->DataLength
);
714 smb2_sync_read(const unsigned int xid
, struct cifsFileInfo
*cfile
,
715 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
716 char **buf
, int *buf_type
)
718 parms
->persistent_fid
= cfile
->fid
.persistent_fid
;
719 parms
->volatile_fid
= cfile
->fid
.volatile_fid
;
720 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
724 smb2_sync_write(const unsigned int xid
, struct cifsFileInfo
*cfile
,
725 struct cifs_io_parms
*parms
, unsigned int *written
,
726 struct kvec
*iov
, unsigned long nr_segs
)
729 parms
->persistent_fid
= cfile
->fid
.persistent_fid
;
730 parms
->volatile_fid
= cfile
->fid
.volatile_fid
;
731 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
734 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
735 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
736 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
738 struct cifsInodeInfo
*cifsi
;
741 cifsi
= CIFS_I(inode
);
743 /* if file already sparse don't bother setting sparse again */
744 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
745 return true; /* already sparse */
747 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
748 return true; /* already not sparse */
751 * Can't check for sparse support on share the usual way via the
752 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
753 * since Samba server doesn't set the flag on the share, yet
754 * supports the set sparse FSCTL and returns sparse correctly
755 * in the file attributes. If we fail setting sparse though we
756 * mark that server does not support sparse files for this share
757 * to avoid repeatedly sending the unsupported fsctl to server
758 * if the file is repeatedly extended.
760 if (tcon
->broken_sparse_sup
)
763 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
764 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
765 true /* is_fctl */, &setsparse
, 1, NULL
, NULL
);
767 tcon
->broken_sparse_sup
= true;
768 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
773 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
775 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
781 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
782 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
784 __le64 eof
= cpu_to_le64(size
);
788 * If extending file more than one page make sparse. Many Linux fs
789 * make files sparse by default when extending via ftruncate
791 inode
= cfile
->dentry
->d_inode
;
793 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
796 /* whether set sparse succeeds or not, extend the file */
797 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
800 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
801 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
, false);
805 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
806 struct cifsFileInfo
*cfile
)
808 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
809 cfile
->fid
.volatile_fid
);
813 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
814 const char *path
, struct cifs_sb_info
*cifs_sb
,
815 struct cifs_fid
*fid
, __u16 search_flags
,
816 struct cifs_search_info
*srch_inf
)
820 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
821 struct cifs_open_parms oparms
;
823 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
828 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
829 oparms
.disposition
= FILE_OPEN
;
830 oparms
.create_options
= 0;
832 oparms
.reconnect
= false;
834 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
837 cifs_dbg(VFS
, "open dir failed\n");
841 srch_inf
->entries_in_buffer
= 0;
842 srch_inf
->index_of_last_entry
= 0;
844 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
845 fid
->volatile_fid
, 0, srch_inf
);
847 cifs_dbg(VFS
, "query directory failed\n");
848 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
854 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
855 struct cifs_fid
*fid
, __u16 search_flags
,
856 struct cifs_search_info
*srch_inf
)
858 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
859 fid
->volatile_fid
, 0, srch_inf
);
863 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
864 struct cifs_fid
*fid
)
866 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
870 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
871 * the number of credits and return true. Otherwise - return false.
874 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
876 struct smb2_hdr
*hdr
= (struct smb2_hdr
*)buf
;
878 if (hdr
->Status
!= STATUS_PENDING
)
882 spin_lock(&server
->req_lock
);
883 server
->credits
+= le16_to_cpu(hdr
->CreditRequest
);
884 spin_unlock(&server
->req_lock
);
885 wake_up(&server
->request_q
);
892 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
893 struct cifsInodeInfo
*cinode
)
895 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
896 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
897 smb2_get_lease_state(cinode
));
899 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
901 CIFS_CACHE_READ(cinode
) ? 1 : 0);
905 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
909 __le16 srch_path
= 0; /* Null - open root of share */
910 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
911 struct cifs_open_parms oparms
;
915 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
916 oparms
.disposition
= FILE_OPEN
;
917 oparms
.create_options
= 0;
919 oparms
.reconnect
= false;
921 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
924 buf
->f_type
= SMB2_MAGIC_NUMBER
;
925 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
927 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
932 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
934 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
935 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
939 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
940 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
943 type
= SMB2_LOCKFLAG_UNLOCK
;
944 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
945 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
946 current
->tgid
, length
, offset
, type
, wait
);
950 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
952 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
956 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
958 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
962 smb2_new_lease_key(struct cifs_fid
*fid
)
964 get_random_bytes(fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
968 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
969 const char *full_path
, char **target_path
,
970 struct cifs_sb_info
*cifs_sb
)
974 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
975 struct cifs_open_parms oparms
;
977 struct smb2_err_rsp
*err_buf
= NULL
;
978 struct smb2_symlink_err_rsp
*symlink
;
979 unsigned int sub_len
, sub_offset
;
981 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
983 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
988 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
989 oparms
.disposition
= FILE_OPEN
;
990 oparms
.create_options
= 0;
992 oparms
.reconnect
= false;
994 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
996 if (!rc
|| !err_buf
) {
1000 /* open must fail on symlink - reset rc */
1002 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
1003 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
1004 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
1005 *target_path
= cifs_strndup_from_utf16(
1006 (char *)symlink
->PathBuffer
+ sub_offset
,
1007 sub_len
, true, cifs_sb
->local_nls
);
1008 if (!(*target_path
)) {
1012 convert_delimiter(*target_path
, '/');
1013 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
1018 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
1019 loff_t offset
, loff_t len
, bool keep_size
)
1021 struct inode
*inode
;
1022 struct cifsInodeInfo
*cifsi
;
1023 struct cifsFileInfo
*cfile
= file
->private_data
;
1024 struct file_zero_data_information fsctl_buf
;
1030 inode
= cfile
->dentry
->d_inode
;
1031 cifsi
= CIFS_I(inode
);
1033 /* if file not oplocked can't be sure whether asking to extend size */
1034 if (!CIFS_CACHE_READ(cifsi
))
1035 if (keep_size
== false)
1039 * Must check if file sparse since fallocate -z (zero range) assumes
1040 * non-sparse allocation
1042 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
))
1046 * need to make sure we are not asked to extend the file since the SMB3
1047 * fsctl does not change the file size. In the future we could change
1048 * this to zero the first part of the range then set the file size
1049 * which for a non sparse file would zero the newly extended range
1051 if (keep_size
== false)
1052 if (i_size_read(inode
) < offset
+ len
)
1055 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1057 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1058 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1060 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1061 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1062 true /* is_fctl */, (char *)&fsctl_buf
,
1063 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1068 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
1069 loff_t offset
, loff_t len
)
1071 struct inode
*inode
;
1072 struct cifsInodeInfo
*cifsi
;
1073 struct cifsFileInfo
*cfile
= file
->private_data
;
1074 struct file_zero_data_information fsctl_buf
;
1077 __u8 set_sparse
= 1;
1081 inode
= cfile
->dentry
->d_inode
;
1082 cifsi
= CIFS_I(inode
);
1084 /* Need to make file sparse, if not already, before freeing range. */
1085 /* Consider adding equivalent for compressed since it could also work */
1086 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
))
1089 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1091 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1092 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1094 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1095 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1096 true /* is_fctl */, (char *)&fsctl_buf
,
1097 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1102 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
1103 loff_t off
, loff_t len
)
1105 /* KEEP_SIZE already checked for by do_fallocate */
1106 if (mode
& FALLOC_FL_PUNCH_HOLE
)
1107 return smb3_punch_hole(file
, tcon
, off
, len
);
1108 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
1109 if (mode
& FALLOC_FL_KEEP_SIZE
)
1110 return smb3_zero_range(file
, tcon
, off
, len
, true);
1111 return smb3_zero_range(file
, tcon
, off
, len
, false);
1118 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
1119 struct cifsInodeInfo
*cinode
, bool set_level2
)
1122 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
1125 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
1129 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1130 unsigned int epoch
, bool *purge_cache
)
1133 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1135 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
1136 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
1137 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
1138 &cinode
->vfs_inode
);
1139 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
1140 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
1141 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
1142 &cinode
->vfs_inode
);
1143 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
1144 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
1145 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
1146 &cinode
->vfs_inode
);
1152 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1153 unsigned int epoch
, bool *purge_cache
)
1155 char message
[5] = {0};
1158 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1162 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
1163 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
1164 strcat(message
, "R");
1166 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
1167 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
1168 strcat(message
, "H");
1170 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
1171 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
1172 strcat(message
, "W");
1174 if (!cinode
->oplock
)
1175 strcat(message
, "None");
1176 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
1177 &cinode
->vfs_inode
);
1181 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1182 unsigned int epoch
, bool *purge_cache
)
1184 unsigned int old_oplock
= cinode
->oplock
;
1186 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
1189 *purge_cache
= false;
1190 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
1191 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
1192 (epoch
- cinode
->epoch
> 0))
1193 *purge_cache
= true;
1194 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1195 (epoch
- cinode
->epoch
> 1))
1196 *purge_cache
= true;
1197 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1198 (epoch
- cinode
->epoch
> 1))
1199 *purge_cache
= true;
1200 else if (cinode
->oplock
== 0 &&
1201 (epoch
- cinode
->epoch
> 0))
1202 *purge_cache
= true;
1203 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
1204 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1205 (epoch
- cinode
->epoch
> 0))
1206 *purge_cache
= true;
1207 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1208 (epoch
- cinode
->epoch
> 1))
1209 *purge_cache
= true;
1211 cinode
->epoch
= epoch
;
1216 smb2_is_read_op(__u32 oplock
)
1218 return oplock
== SMB2_OPLOCK_LEVEL_II
;
1222 smb21_is_read_op(__u32 oplock
)
1224 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
1225 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
1229 map_oplock_to_lease(u8 oplock
)
1231 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
1232 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
1233 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
1234 return SMB2_LEASE_READ_CACHING
;
1235 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
1236 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
1237 SMB2_LEASE_WRITE_CACHING
;
1242 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
1244 struct create_lease
*buf
;
1246 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
1250 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1251 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1252 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1254 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1255 (struct create_lease
, lcontext
));
1256 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
1257 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1258 (struct create_lease
, Name
));
1259 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1260 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1269 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
1271 struct create_lease_v2
*buf
;
1273 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
1277 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1278 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1279 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1281 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1282 (struct create_lease_v2
, lcontext
));
1283 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
1284 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1285 (struct create_lease_v2
, Name
));
1286 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1287 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1296 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
)
1298 struct create_lease
*lc
= (struct create_lease
*)buf
;
1300 *epoch
= 0; /* not used */
1301 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1302 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1303 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1307 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
)
1309 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
1311 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
1312 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1313 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1314 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1318 smb2_wp_retry_size(struct inode
*inode
)
1320 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
1321 SMB2_MAX_BUFFER_SIZE
);
1325 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
1327 return !cfile
->invalidHandle
;
1330 struct smb_version_operations smb20_operations
= {
1331 .compare_fids
= smb2_compare_fids
,
1332 .setup_request
= smb2_setup_request
,
1333 .setup_async_request
= smb2_setup_async_request
,
1334 .check_receive
= smb2_check_receive
,
1335 .add_credits
= smb2_add_credits
,
1336 .set_credits
= smb2_set_credits
,
1337 .get_credits_field
= smb2_get_credits_field
,
1338 .get_credits
= smb2_get_credits
,
1339 .wait_mtu_credits
= cifs_wait_mtu_credits
,
1340 .get_next_mid
= smb2_get_next_mid
,
1341 .read_data_offset
= smb2_read_data_offset
,
1342 .read_data_length
= smb2_read_data_length
,
1343 .map_error
= map_smb2_to_linux_error
,
1344 .find_mid
= smb2_find_mid
,
1345 .check_message
= smb2_check_message
,
1346 .dump_detail
= smb2_dump_detail
,
1347 .clear_stats
= smb2_clear_stats
,
1348 .print_stats
= smb2_print_stats
,
1349 .is_oplock_break
= smb2_is_valid_oplock_break
,
1350 .downgrade_oplock
= smb2_downgrade_oplock
,
1351 .need_neg
= smb2_need_neg
,
1352 .negotiate
= smb2_negotiate
,
1353 .negotiate_wsize
= smb2_negotiate_wsize
,
1354 .negotiate_rsize
= smb2_negotiate_rsize
,
1355 .sess_setup
= SMB2_sess_setup
,
1356 .logoff
= SMB2_logoff
,
1357 .tree_connect
= SMB2_tcon
,
1358 .tree_disconnect
= SMB2_tdis
,
1359 .qfs_tcon
= smb2_qfs_tcon
,
1360 .is_path_accessible
= smb2_is_path_accessible
,
1361 .can_echo
= smb2_can_echo
,
1363 .query_path_info
= smb2_query_path_info
,
1364 .get_srv_inum
= smb2_get_srv_inum
,
1365 .query_file_info
= smb2_query_file_info
,
1366 .set_path_size
= smb2_set_path_size
,
1367 .set_file_size
= smb2_set_file_size
,
1368 .set_file_info
= smb2_set_file_info
,
1369 .set_compression
= smb2_set_compression
,
1370 .mkdir
= smb2_mkdir
,
1371 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1372 .rmdir
= smb2_rmdir
,
1373 .unlink
= smb2_unlink
,
1374 .rename
= smb2_rename_path
,
1375 .create_hardlink
= smb2_create_hardlink
,
1376 .query_symlink
= smb2_query_symlink
,
1377 .open
= smb2_open_file
,
1378 .set_fid
= smb2_set_fid
,
1379 .close
= smb2_close_file
,
1380 .flush
= smb2_flush_file
,
1381 .async_readv
= smb2_async_readv
,
1382 .async_writev
= smb2_async_writev
,
1383 .sync_read
= smb2_sync_read
,
1384 .sync_write
= smb2_sync_write
,
1385 .query_dir_first
= smb2_query_dir_first
,
1386 .query_dir_next
= smb2_query_dir_next
,
1387 .close_dir
= smb2_close_dir
,
1388 .calc_smb_size
= smb2_calc_size
,
1389 .is_status_pending
= smb2_is_status_pending
,
1390 .oplock_response
= smb2_oplock_response
,
1391 .queryfs
= smb2_queryfs
,
1392 .mand_lock
= smb2_mand_lock
,
1393 .mand_unlock_range
= smb2_unlock_range
,
1394 .push_mand_locks
= smb2_push_mandatory_locks
,
1395 .get_lease_key
= smb2_get_lease_key
,
1396 .set_lease_key
= smb2_set_lease_key
,
1397 .new_lease_key
= smb2_new_lease_key
,
1398 .calc_signature
= smb2_calc_signature
,
1399 .is_read_op
= smb2_is_read_op
,
1400 .set_oplock_level
= smb2_set_oplock_level
,
1401 .create_lease_buf
= smb2_create_lease_buf
,
1402 .parse_lease_buf
= smb2_parse_lease_buf
,
1403 .clone_range
= smb2_clone_range
,
1404 .wp_retry_size
= smb2_wp_retry_size
,
1405 .dir_needs_close
= smb2_dir_needs_close
,
1408 struct smb_version_operations smb21_operations
= {
1409 .compare_fids
= smb2_compare_fids
,
1410 .setup_request
= smb2_setup_request
,
1411 .setup_async_request
= smb2_setup_async_request
,
1412 .check_receive
= smb2_check_receive
,
1413 .add_credits
= smb2_add_credits
,
1414 .set_credits
= smb2_set_credits
,
1415 .get_credits_field
= smb2_get_credits_field
,
1416 .get_credits
= smb2_get_credits
,
1417 .wait_mtu_credits
= smb2_wait_mtu_credits
,
1418 .get_next_mid
= smb2_get_next_mid
,
1419 .read_data_offset
= smb2_read_data_offset
,
1420 .read_data_length
= smb2_read_data_length
,
1421 .map_error
= map_smb2_to_linux_error
,
1422 .find_mid
= smb2_find_mid
,
1423 .check_message
= smb2_check_message
,
1424 .dump_detail
= smb2_dump_detail
,
1425 .clear_stats
= smb2_clear_stats
,
1426 .print_stats
= smb2_print_stats
,
1427 .is_oplock_break
= smb2_is_valid_oplock_break
,
1428 .downgrade_oplock
= smb2_downgrade_oplock
,
1429 .need_neg
= smb2_need_neg
,
1430 .negotiate
= smb2_negotiate
,
1431 .negotiate_wsize
= smb2_negotiate_wsize
,
1432 .negotiate_rsize
= smb2_negotiate_rsize
,
1433 .sess_setup
= SMB2_sess_setup
,
1434 .logoff
= SMB2_logoff
,
1435 .tree_connect
= SMB2_tcon
,
1436 .tree_disconnect
= SMB2_tdis
,
1437 .qfs_tcon
= smb2_qfs_tcon
,
1438 .is_path_accessible
= smb2_is_path_accessible
,
1439 .can_echo
= smb2_can_echo
,
1441 .query_path_info
= smb2_query_path_info
,
1442 .get_srv_inum
= smb2_get_srv_inum
,
1443 .query_file_info
= smb2_query_file_info
,
1444 .set_path_size
= smb2_set_path_size
,
1445 .set_file_size
= smb2_set_file_size
,
1446 .set_file_info
= smb2_set_file_info
,
1447 .set_compression
= smb2_set_compression
,
1448 .mkdir
= smb2_mkdir
,
1449 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1450 .rmdir
= smb2_rmdir
,
1451 .unlink
= smb2_unlink
,
1452 .rename
= smb2_rename_path
,
1453 .create_hardlink
= smb2_create_hardlink
,
1454 .query_symlink
= smb2_query_symlink
,
1455 .open
= smb2_open_file
,
1456 .set_fid
= smb2_set_fid
,
1457 .close
= smb2_close_file
,
1458 .flush
= smb2_flush_file
,
1459 .async_readv
= smb2_async_readv
,
1460 .async_writev
= smb2_async_writev
,
1461 .sync_read
= smb2_sync_read
,
1462 .sync_write
= smb2_sync_write
,
1463 .query_dir_first
= smb2_query_dir_first
,
1464 .query_dir_next
= smb2_query_dir_next
,
1465 .close_dir
= smb2_close_dir
,
1466 .calc_smb_size
= smb2_calc_size
,
1467 .is_status_pending
= smb2_is_status_pending
,
1468 .oplock_response
= smb2_oplock_response
,
1469 .queryfs
= smb2_queryfs
,
1470 .mand_lock
= smb2_mand_lock
,
1471 .mand_unlock_range
= smb2_unlock_range
,
1472 .push_mand_locks
= smb2_push_mandatory_locks
,
1473 .get_lease_key
= smb2_get_lease_key
,
1474 .set_lease_key
= smb2_set_lease_key
,
1475 .new_lease_key
= smb2_new_lease_key
,
1476 .calc_signature
= smb2_calc_signature
,
1477 .is_read_op
= smb21_is_read_op
,
1478 .set_oplock_level
= smb21_set_oplock_level
,
1479 .create_lease_buf
= smb2_create_lease_buf
,
1480 .parse_lease_buf
= smb2_parse_lease_buf
,
1481 .clone_range
= smb2_clone_range
,
1482 .wp_retry_size
= smb2_wp_retry_size
,
1483 .dir_needs_close
= smb2_dir_needs_close
,
1486 struct smb_version_operations smb30_operations
= {
1487 .compare_fids
= smb2_compare_fids
,
1488 .setup_request
= smb2_setup_request
,
1489 .setup_async_request
= smb2_setup_async_request
,
1490 .check_receive
= smb2_check_receive
,
1491 .add_credits
= smb2_add_credits
,
1492 .set_credits
= smb2_set_credits
,
1493 .get_credits_field
= smb2_get_credits_field
,
1494 .get_credits
= smb2_get_credits
,
1495 .wait_mtu_credits
= smb2_wait_mtu_credits
,
1496 .get_next_mid
= smb2_get_next_mid
,
1497 .read_data_offset
= smb2_read_data_offset
,
1498 .read_data_length
= smb2_read_data_length
,
1499 .map_error
= map_smb2_to_linux_error
,
1500 .find_mid
= smb2_find_mid
,
1501 .check_message
= smb2_check_message
,
1502 .dump_detail
= smb2_dump_detail
,
1503 .clear_stats
= smb2_clear_stats
,
1504 .print_stats
= smb2_print_stats
,
1505 .dump_share_caps
= smb2_dump_share_caps
,
1506 .is_oplock_break
= smb2_is_valid_oplock_break
,
1507 .downgrade_oplock
= smb2_downgrade_oplock
,
1508 .need_neg
= smb2_need_neg
,
1509 .negotiate
= smb2_negotiate
,
1510 .negotiate_wsize
= smb2_negotiate_wsize
,
1511 .negotiate_rsize
= smb2_negotiate_rsize
,
1512 .sess_setup
= SMB2_sess_setup
,
1513 .logoff
= SMB2_logoff
,
1514 .tree_connect
= SMB2_tcon
,
1515 .tree_disconnect
= SMB2_tdis
,
1516 .qfs_tcon
= smb3_qfs_tcon
,
1517 .is_path_accessible
= smb2_is_path_accessible
,
1518 .can_echo
= smb2_can_echo
,
1520 .query_path_info
= smb2_query_path_info
,
1521 .get_srv_inum
= smb2_get_srv_inum
,
1522 .query_file_info
= smb2_query_file_info
,
1523 .set_path_size
= smb2_set_path_size
,
1524 .set_file_size
= smb2_set_file_size
,
1525 .set_file_info
= smb2_set_file_info
,
1526 .set_compression
= smb2_set_compression
,
1527 .mkdir
= smb2_mkdir
,
1528 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1529 .rmdir
= smb2_rmdir
,
1530 .unlink
= smb2_unlink
,
1531 .rename
= smb2_rename_path
,
1532 .create_hardlink
= smb2_create_hardlink
,
1533 .query_symlink
= smb2_query_symlink
,
1534 .open
= smb2_open_file
,
1535 .set_fid
= smb2_set_fid
,
1536 .close
= smb2_close_file
,
1537 .flush
= smb2_flush_file
,
1538 .async_readv
= smb2_async_readv
,
1539 .async_writev
= smb2_async_writev
,
1540 .sync_read
= smb2_sync_read
,
1541 .sync_write
= smb2_sync_write
,
1542 .query_dir_first
= smb2_query_dir_first
,
1543 .query_dir_next
= smb2_query_dir_next
,
1544 .close_dir
= smb2_close_dir
,
1545 .calc_smb_size
= smb2_calc_size
,
1546 .is_status_pending
= smb2_is_status_pending
,
1547 .oplock_response
= smb2_oplock_response
,
1548 .queryfs
= smb2_queryfs
,
1549 .mand_lock
= smb2_mand_lock
,
1550 .mand_unlock_range
= smb2_unlock_range
,
1551 .push_mand_locks
= smb2_push_mandatory_locks
,
1552 .get_lease_key
= smb2_get_lease_key
,
1553 .set_lease_key
= smb2_set_lease_key
,
1554 .new_lease_key
= smb2_new_lease_key
,
1555 .generate_signingkey
= generate_smb3signingkey
,
1556 .calc_signature
= smb3_calc_signature
,
1557 .is_read_op
= smb21_is_read_op
,
1558 .set_oplock_level
= smb3_set_oplock_level
,
1559 .create_lease_buf
= smb3_create_lease_buf
,
1560 .parse_lease_buf
= smb3_parse_lease_buf
,
1561 .clone_range
= smb2_clone_range
,
1562 .validate_negotiate
= smb3_validate_negotiate
,
1563 .wp_retry_size
= smb2_wp_retry_size
,
1564 .dir_needs_close
= smb2_dir_needs_close
,
1565 .fallocate
= smb3_fallocate
,
1568 struct smb_version_values smb20_values
= {
1569 .version_string
= SMB20_VERSION_STRING
,
1570 .protocol_id
= SMB20_PROT_ID
,
1571 .req_capabilities
= 0, /* MBZ */
1572 .large_lock_type
= 0,
1573 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1574 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1575 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1576 .header_size
= sizeof(struct smb2_hdr
),
1577 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1578 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1579 .lock_cmd
= SMB2_LOCK
,
1581 .cap_nt_find
= SMB2_NT_FIND
,
1582 .cap_large_files
= SMB2_LARGE_FILES
,
1583 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1584 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1585 .create_lease_size
= sizeof(struct create_lease
),
1588 struct smb_version_values smb21_values
= {
1589 .version_string
= SMB21_VERSION_STRING
,
1590 .protocol_id
= SMB21_PROT_ID
,
1591 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
1592 .large_lock_type
= 0,
1593 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1594 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1595 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1596 .header_size
= sizeof(struct smb2_hdr
),
1597 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1598 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1599 .lock_cmd
= SMB2_LOCK
,
1601 .cap_nt_find
= SMB2_NT_FIND
,
1602 .cap_large_files
= SMB2_LARGE_FILES
,
1603 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1604 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1605 .create_lease_size
= sizeof(struct create_lease
),
1608 struct smb_version_values smb30_values
= {
1609 .version_string
= SMB30_VERSION_STRING
,
1610 .protocol_id
= SMB30_PROT_ID
,
1611 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
,
1612 .large_lock_type
= 0,
1613 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1614 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1615 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1616 .header_size
= sizeof(struct smb2_hdr
),
1617 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1618 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1619 .lock_cmd
= SMB2_LOCK
,
1621 .cap_nt_find
= SMB2_NT_FIND
,
1622 .cap_large_files
= SMB2_LARGE_FILES
,
1623 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1624 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1625 .create_lease_size
= sizeof(struct create_lease_v2
),
1628 struct smb_version_values smb302_values
= {
1629 .version_string
= SMB302_VERSION_STRING
,
1630 .protocol_id
= SMB302_PROT_ID
,
1631 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
,
1632 .large_lock_type
= 0,
1633 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1634 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1635 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1636 .header_size
= sizeof(struct smb2_hdr
),
1637 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1638 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1639 .lock_cmd
= SMB2_LOCK
,
1641 .cap_nt_find
= SMB2_NT_FIND
,
1642 .cap_large_files
= SMB2_LARGE_FILES
,
1643 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1644 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1645 .create_lease_size
= sizeof(struct create_lease_v2
),