Merge tag 'for-linus-6.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/uml...
[linux-block.git] / fs / cifs / cifsglob.h
CommitLineData
929be906 1/* SPDX-License-Identifier: LGPL-2.1 */
1da177e4 2/*
1da177e4 3 *
366781c1 4 * Copyright (C) International Business Machines Corp., 2002,2008
1da177e4 5 * Author(s): Steve French (sfrench@us.ibm.com)
7ee1af76 6 * Jeremy Allison (jra@samba.org)
1da177e4 7 *
1da177e4 8 */
abd2e44d
SJ
9#ifndef _CIFS_GLOB_H
10#define _CIFS_GLOB_H
11
1da177e4
LT
12#include <linux/in.h>
13#include <linux/in6.h>
b438fcf1 14#include <linux/inet.h>
5a0e3ad6 15#include <linux/slab.h>
2dc7e1c0 16#include <linux/mempool.h>
9b646972 17#include <linux/workqueue.h>
49bd49f9 18#include <linux/utsname.h>
cc391b69 19#include <linux/sched/mm.h>
bc899ee1 20#include <linux/netfs.h>
1da177e4 21#include "cifs_fs_sb.h"
442aa310 22#include "cifsacl.h"
d2b91521
SP
23#include <crypto/internal/hash.h>
24#include <linux/scatterlist.h>
8c3a2b4c 25#include <uapi/linux/cifs/cifs_mount.h>
0d35e382 26#include "../smbfs_common/smb2pdu.h"
d60622eb 27#include "smb2pdu.h"
d2b91521 28
8d8b26e5 29#define SMB_PATH_MAX 260
e2292430
AA
30#define CIFS_PORT 445
31#define RFC1001_PORT 139
32
1da177e4
LT
33/*
34 * The sizes of various internal tables and strings
35 */
36#define MAX_UID_INFO 16
37#define MAX_SES_INFO 2
38#define MAX_TCON_INFO 4
39
cdf1246f 40#define MAX_TREE_SIZE (2 + CIFS_NI_MAXHOST + 1 + CIFS_MAX_SHARE_LEN + 1)
1da177e4
LT
41
42#define CIFS_MIN_RCV_POOL 4
43
2c0c2a08 44#define MAX_REOPEN_ATT 5 /* these many maximum attempts to reopen a file */
6d20e840
SJ
45/*
46 * default attribute cache timeout (jiffies)
47 */
48#define CIFS_DEF_ACTIMEO (1 * HZ)
49
50/*
51 * max attribute cache timeout (jiffies) - 2^30
52 */
53#define CIFS_MAX_ACTIMEO (1 << 30)
54
ca567eb2
SF
55/*
56 * Max persistent and resilient handle timeout (milliseconds).
57 * Windows durable max was 960000 (16 minutes)
58 */
59#define SMB3_MAX_HANDLE_TIMEOUT 960000
60
1da177e4
LT
61/*
62 * MAX_REQ is the maximum number of requests that WE will send
10b9b98e 63 * on one socket concurrently.
1da177e4 64 */
10b9b98e 65#define CIFS_MAX_REQ 32767
1da177e4 66
8ecaf67a
JL
67#define RFC1001_NAME_LEN 15
68#define RFC1001_NAME_LEN_WITH_NULL (RFC1001_NAME_LEN + 1)
69
b327a717
AA
70/* maximum length of ip addr as a string (including ipv6 and sctp) */
71#define SERVER_NAME_LENGTH 80
1da177e4
LT
72#define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1)
73
adfeb3e0
SF
74/* echo interval in seconds */
75#define SMB_ECHO_INTERVAL_MIN 1
76#define SMB_ECHO_INTERVAL_MAX 600
77#define SMB_ECHO_INTERVAL_DEFAULT 60
9094fad1 78
4ac0536f
PA
79/* dns resolution intervals in seconds */
80#define SMB_DNS_RESOLVE_INTERVAL_MIN 120
506c1da4
SP
81#define SMB_DNS_RESOLVE_INTERVAL_DEFAULT 600
82
6e1c1c08
SP
83/* smb multichannel query server interfaces interval in seconds */
84#define SMB_INTERFACE_POLL_INTERVAL 600
85
b24df3e3
RS
86/* maximum number of PDUs in one compound */
87#define MAX_COMPOUND 5
88
141891f4
SF
89/*
90 * Default number of credits to keep available for SMB3.
91 * This value is chosen somewhat arbitrarily. The Windows client
92 * defaults to 128 credits, the Windows server allows clients up to
93 * 512 credits (or 8K for later versions), and the NetApp server
94 * does not limit clients at all. Choose a high enough default value
95 * such that the client shouldn't limit performance, but allow mount
96 * to override (until you approach 64K, where we limit credits to 65000
97 * to reduce possibility of seeing more server credit overflow bugs.
98 */
99#define SMB2_MAX_CREDITS_AVAILABLE 32000
100
1da177e4
LT
101#include "cifspdu.h"
102
1da177e4
LT
103#ifndef XATTR_DOS_ATTRIB
104#define XATTR_DOS_ATTRIB "user.DOSATTRIB"
105#endif
106
49bd49f9
SP
107#define CIFS_MAX_WORKSTATION_LEN (__NEW_UTS_LEN + 1) /* reasonable max for client */
108
1da177e4
LT
109/*
110 * CIFS vfs client Status information (based on what we know.)
111 */
112
dd3cd870 113/* associated with each connection */
1da177e4
LT
114enum statusEnum {
115 CifsNew = 0,
116 CifsGood,
117 CifsExiting,
fd88ce93 118 CifsNeedReconnect,
73f9bfbe
SP
119 CifsNeedNegotiate,
120 CifsInNegotiate,
dd3cd870
SP
121};
122
123/* associated with each smb session */
124enum ses_status_enum {
125 SES_NEW = 0,
126 SES_GOOD,
127 SES_EXITING,
128 SES_NEED_RECON,
129 SES_IN_SETUP
fdf59eb5
SF
130};
131
132/* associated with each tree connection to the server */
133enum tid_status_enum {
134 TID_NEW = 0,
135 TID_GOOD,
136 TID_EXITING,
137 TID_NEED_RECON,
138 TID_NEED_TCON,
139 TID_IN_TCON,
140 TID_NEED_FILES_INVALIDATE, /* currently unused */
141 TID_IN_FILES_INVALIDATE
1da177e4
LT
142};
143
144enum securityEnum {
515d82ff 145 Unspecified = 0, /* not specified */
1da177e4 146 NTLMv2, /* Legacy NTLM auth with NTLMv2 hash */
ac683924 147 RawNTLMSSP, /* NTLMSSP without SPNEGO, NTLMv2 hash */
c16fefa5 148 Kerberos, /* Kerberos via SPNEGO */
1da177e4
LT
149};
150
5f98ca9a 151struct session_key {
b609f06a 152 unsigned int len;
21e73393 153 char *response;
b609f06a
SF
154};
155
f7c5445a 156/* crypto hashing related structure/fields, not specific to a sec mech */
d2b91521 157struct cifs_secmech {
1f3d5477
EM
158 struct shash_desc *hmacmd5; /* hmacmd5 hash function, for NTLMv2/CR1 hashes */
159 struct shash_desc *md5; /* md5 hash function, for CIFS/SMB1 signatures */
160 struct shash_desc *hmacsha256; /* hmac-sha256 hash function, for SMB2 signatures */
161 struct shash_desc *sha512; /* sha512 hash function, for SMB3.1.1 preauth hash */
162 struct shash_desc *aes_cmac; /* block-cipher based MAC function, for SMB3 signatures */
163
164 struct crypto_aead *enc; /* smb3 encryption AEAD TFM (AES-CCM and AES-GCM) */
165 struct crypto_aead *dec; /* smb3 decryption AEAD TFM (AES-CCM and AES-GCM) */
d2b91521
SP
166};
167
d3686d54 168/* per smb session structure/fields */
d2b91521 169struct ntlmssp_auth {
5c234aa5 170 bool sesskey_per_smbsess; /* whether session key is per smb session */
d2b91521
SP
171 __u32 client_flags; /* sent by client in type 1 ntlmsssp exchange */
172 __u32 server_flags; /* sent by server in type 2 ntlmssp exchange */
173 unsigned char ciphertext[CIFS_CPHTXT_SIZE]; /* sent to server */
d3686d54 174 char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlmssp */
d2b91521
SP
175};
176
442aa310
SF
177struct cifs_cred {
178 int uid;
179 int gid;
180 int mode;
181 int cecount;
182 struct cifs_sid osid;
183 struct cifs_sid gsid;
184 struct cifs_ntace *ntaces;
185 struct cifs_ace *aces;
186};
187
1da177e4
LT
188/*
189 *****************************************************************
190 * Except the CIFS PDUs themselves all the
191 * globally interesting structs should go here
192 *****************************************************************
193 */
194
bf5ea0e2
JL
195/*
196 * A smb_rqst represents a complete request to be issued to a server. It's
197 * formed by a kvec array, followed by an array of pages. Page data is assumed
198 * to start at the beginning of the first page.
199 */
200struct smb_rqst {
201 struct kvec *rq_iov; /* array of kvecs */
202 unsigned int rq_nvec; /* number of kvecs in array */
203 struct page **rq_pages; /* pointer to array of page ptrs */
57a929a6 204 unsigned int rq_offset; /* the offset to the 1st page */
bf5ea0e2
JL
205 unsigned int rq_npages; /* number pages in array */
206 unsigned int rq_pagesz; /* page size to use */
207 unsigned int rq_tailsz; /* length of last page */
208};
209
121b046a
JL
210struct mid_q_entry;
211struct TCP_Server_Info;
55157dfb 212struct cifsFileInfo;
082d0642 213struct cifs_ses;
2e6e02ab 214struct cifs_tcon;
b669f33c 215struct dfs_info3_param;
1208ef1f 216struct cifs_fattr;
3fa1c6d1 217struct smb3_fs_context;
fb1214e4 218struct cifs_fid;
fc9c5966 219struct cifs_readdata;
c9de5c80 220struct cifs_writedata;
f9c6e234 221struct cifs_io_parms;
92fc65a7 222struct cifs_search_info;
95a3f2f3 223struct cifsInodeInfo;
226730b4 224struct cifs_open_parms;
335b7b62 225struct cifs_credits;
121b046a 226
23db65f5 227struct smb_version_operations {
fb2036d8 228 int (*send_cancel)(struct TCP_Server_Info *, struct smb_rqst *,
121b046a 229 struct mid_q_entry *);
55157dfb 230 bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *);
082d0642 231 /* setup request: allocate mid, sign message */
fec344e3 232 struct mid_q_entry *(*setup_request)(struct cifs_ses *,
f780bd3f
AA
233 struct TCP_Server_Info *,
234 struct smb_rqst *);
45740847 235 /* setup async request: allocate mid, sign message */
fec344e3
JL
236 struct mid_q_entry *(*setup_async_request)(struct TCP_Server_Info *,
237 struct smb_rqst *);
082d0642
PS
238 /* check response: verify signature, map error */
239 int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *,
240 bool);
335b7b62
PS
241 void (*add_credits)(struct TCP_Server_Info *server,
242 const struct cifs_credits *credits,
243 const int optype);
45275789 244 void (*set_credits)(struct TCP_Server_Info *, const int);
a891f0f8
PS
245 int * (*get_credits_field)(struct TCP_Server_Info *, const int);
246 unsigned int (*get_credits)(struct mid_q_entry *);
88257360 247 __u64 (*get_next_mid)(struct TCP_Server_Info *);
c781af7e
PS
248 void (*revert_current_mid)(struct TCP_Server_Info *server,
249 const unsigned int val);
eb378711
PS
250 /* data offset from read response message */
251 unsigned int (*read_data_offset)(char *);
74dcf418
LL
252 /*
253 * Data length from read response message
254 * When in_remaining is true, the returned data length is in
255 * message field DataRemaining for out-of-band data read (e.g through
256 * Memory Registration RDMA write in SMBD).
257 * Otherwise, the returned data length is in message field DataLength.
258 */
259 unsigned int (*read_data_length)(char *, bool in_remaining);
eb378711
PS
260 /* map smb to linux error */
261 int (*map_error)(char *, bool);
8aa26f3e
PS
262 /* find mid corresponding to the response message */
263 struct mid_q_entry * (*find_mid)(struct TCP_Server_Info *, char *);
14547f7d 264 void (*dump_detail)(void *buf, struct TCP_Server_Info *ptcp_info);
44c58186
PS
265 void (*clear_stats)(struct cifs_tcon *);
266 void (*print_stats)(struct seq_file *m, struct cifs_tcon *);
769ee6a4 267 void (*dump_share_caps)(struct seq_file *, struct cifs_tcon *);
8aa26f3e 268 /* verify the message */
373512ec 269 int (*check_message)(char *, unsigned int, struct TCP_Server_Info *);
8aa26f3e 270 bool (*is_oplock_break)(char *, struct TCP_Server_Info *);
04ad69c3 271 int (*handle_cancelled_mid)(struct mid_q_entry *, struct TCP_Server_Info *);
9bd45408
PS
272 void (*downgrade_oplock)(struct TCP_Server_Info *server,
273 struct cifsInodeInfo *cinode, __u32 oplock,
274 unsigned int epoch, bool *purge_cache);
316cf94a
PS
275 /* process transaction2 response */
276 bool (*check_trans2)(struct mid_q_entry *, struct TCP_Server_Info *,
277 char *, int);
286170aa
PS
278 /* check if we need to negotiate */
279 bool (*need_neg)(struct TCP_Server_Info *);
280 /* negotiate to the server */
f486ef8e
SP
281 int (*negotiate)(const unsigned int xid,
282 struct cifs_ses *ses,
283 struct TCP_Server_Info *server);
24985c53 284 /* set negotiated write size */
3fa1c6d1 285 unsigned int (*negotiate_wsize)(struct cifs_tcon *tcon, struct smb3_fs_context *ctx);
24985c53 286 /* set negotiated read size */
3fa1c6d1 287 unsigned int (*negotiate_rsize)(struct cifs_tcon *tcon, struct smb3_fs_context *ctx);
58c45c58
PS
288 /* setup smb sessionn */
289 int (*sess_setup)(const unsigned int, struct cifs_ses *,
f486ef8e 290 struct TCP_Server_Info *server,
58c45c58
PS
291 const struct nls_table *);
292 /* close smb session */
293 int (*logoff)(const unsigned int, struct cifs_ses *);
2e6e02ab
PS
294 /* connect to a server share */
295 int (*tree_connect)(const unsigned int, struct cifs_ses *, const char *,
296 struct cifs_tcon *, const struct nls_table *);
297 /* close tree connecion */
298 int (*tree_disconnect)(const unsigned int, struct cifs_tcon *);
b669f33c
PS
299 /* get DFS referrals */
300 int (*get_dfs_refer)(const unsigned int, struct cifs_ses *,
301 const char *, struct dfs_info3_param **,
302 unsigned int *, const struct nls_table *, int);
af4281dc 303 /* informational QFS call */
0f060936
AG
304 void (*qfs_tcon)(const unsigned int, struct cifs_tcon *,
305 struct cifs_sb_info *);
68889f26
PS
306 /* check if a path is accessible or not */
307 int (*is_path_accessible)(const unsigned int, struct cifs_tcon *,
308 struct cifs_sb_info *, const char *);
1208ef1f
PS
309 /* query path data from the server */
310 int (*query_path_info)(const unsigned int, struct cifs_tcon *,
311 struct cifs_sb_info *, const char *,
eb85d94b 312 FILE_ALL_INFO *, bool *, bool *);
4ad65044
PS
313 /* query file data from the server */
314 int (*query_file_info)(const unsigned int, struct cifs_tcon *,
315 struct cifs_fid *, FILE_ALL_INFO *);
2e4564b3
SF
316 /* query reparse tag from srv to determine which type of special file */
317 int (*query_reparse_tag)(const unsigned int xid, struct cifs_tcon *tcon,
318 struct cifs_sb_info *cifs_sb, const char *path,
319 __u32 *reparse_tag);
1208ef1f
PS
320 /* get server index number */
321 int (*get_srv_inum)(const unsigned int, struct cifs_tcon *,
322 struct cifs_sb_info *, const char *,
323 u64 *uniqueid, FILE_ALL_INFO *);
d1433418
PS
324 /* set size by path */
325 int (*set_path_size)(const unsigned int, struct cifs_tcon *,
326 const char *, __u64, struct cifs_sb_info *, bool);
327 /* set size by file handle */
328 int (*set_file_size)(const unsigned int, struct cifs_tcon *,
329 struct cifsFileInfo *, __u64, bool);
6bdf6dbd
PS
330 /* set attributes */
331 int (*set_file_info)(struct inode *, const char *, FILE_BASIC_INFO *,
332 const unsigned int);
64a5cfa6
SF
333 int (*set_compression)(const unsigned int, struct cifs_tcon *,
334 struct cifsFileInfo *);
f6d76178
PS
335 /* check if we can send an echo or nor */
336 bool (*can_echo)(struct TCP_Server_Info *);
337 /* send echo request */
338 int (*echo)(struct TCP_Server_Info *);
f436720e 339 /* create directory */
bea851b8
SF
340 int (*posix_mkdir)(const unsigned int xid, struct inode *inode,
341 umode_t mode, struct cifs_tcon *tcon,
342 const char *full_path,
343 struct cifs_sb_info *cifs_sb);
c3ca78e2
SF
344 int (*mkdir)(const unsigned int xid, struct inode *inode, umode_t mode,
345 struct cifs_tcon *tcon, const char *name,
346 struct cifs_sb_info *sb);
f436720e
PS
347 /* set info on created directory */
348 void (*mkdir_setinfo)(struct inode *, const char *,
349 struct cifs_sb_info *, struct cifs_tcon *,
350 const unsigned int);
f958ca5d
PS
351 /* remove directory */
352 int (*rmdir)(const unsigned int, struct cifs_tcon *, const char *,
353 struct cifs_sb_info *);
ed6875e0
PS
354 /* unlink file */
355 int (*unlink)(const unsigned int, struct cifs_tcon *, const char *,
356 struct cifs_sb_info *);
357 /* open, rename and delete file */
358 int (*rename_pending_delete)(const char *, struct dentry *,
359 const unsigned int);
8ceb9843
PS
360 /* send rename request */
361 int (*rename)(const unsigned int, struct cifs_tcon *, const char *,
362 const char *, struct cifs_sb_info *);
d6e906f1
SF
363 /* send create hardlink request */
364 int (*create_hardlink)(const unsigned int, struct cifs_tcon *,
365 const char *, const char *,
366 struct cifs_sb_info *);
b42bf888
PS
367 /* query symlink target */
368 int (*query_symlink)(const unsigned int, struct cifs_tcon *,
ebaf546a
RS
369 struct cifs_sb_info *, const char *,
370 char **, bool);
fb1214e4 371 /* open a file for non-posix mounts */
226730b4
PS
372 int (*open)(const unsigned int, struct cifs_open_parms *,
373 __u32 *, FILE_ALL_INFO *);
fb1214e4
PS
374 /* set fid protocol-specific info */
375 void (*set_fid)(struct cifsFileInfo *, struct cifs_fid *, __u32);
0ff78a22 376 /* close a file */
760ad0ca
PS
377 void (*close)(const unsigned int, struct cifs_tcon *,
378 struct cifs_fid *);
43f8a6a7
SF
379 /* close a file, returning file attributes and timestamps */
380 void (*close_getattr)(const unsigned int xid, struct cifs_tcon *tcon,
381 struct cifsFileInfo *pfile_info);
1d8c4c00
PS
382 /* send a flush request to the server */
383 int (*flush)(const unsigned int, struct cifs_tcon *, struct cifs_fid *);
fc9c5966
PS
384 /* async read from the server */
385 int (*async_readv)(struct cifs_readdata *);
c9de5c80 386 /* async write to the server */
4a5c80d7
SF
387 int (*async_writev)(struct cifs_writedata *,
388 void (*release)(struct kref *));
f9c6e234 389 /* sync read from the server */
db8b631d 390 int (*sync_read)(const unsigned int, struct cifs_fid *,
f9c6e234
PS
391 struct cifs_io_parms *, unsigned int *, char **,
392 int *);
ba9ad725 393 /* sync write to the server */
db8b631d 394 int (*sync_write)(const unsigned int, struct cifs_fid *,
ba9ad725
PS
395 struct cifs_io_parms *, unsigned int *, struct kvec *,
396 unsigned long);
92fc65a7
PS
397 /* open dir, start readdir */
398 int (*query_dir_first)(const unsigned int, struct cifs_tcon *,
399 const char *, struct cifs_sb_info *,
400 struct cifs_fid *, __u16,
401 struct cifs_search_info *);
402 /* continue readdir */
403 int (*query_dir_next)(const unsigned int, struct cifs_tcon *,
404 struct cifs_fid *,
405 __u16, struct cifs_search_info *srch_inf);
406 /* close dir */
407 int (*close_dir)(const unsigned int, struct cifs_tcon *,
408 struct cifs_fid *);
409 /* calculate a size of SMB message */
68ed1449 410 unsigned int (*calc_smb_size)(void *buf);
66265f13
PS
411 /* check for STATUS_PENDING and process the response if yes */
412 bool (*is_status_pending)(char *buf, struct TCP_Server_Info *server);
511c54a2
PS
413 /* check for STATUS_NETWORK_SESSION_EXPIRED */
414 bool (*is_session_expired)(char *);
95a3f2f3
PS
415 /* send oplock break response */
416 int (*oplock_response)(struct cifs_tcon *, struct cifs_fid *,
417 struct cifsInodeInfo *);
76ec5e33
PS
418 /* query remote filesystem */
419 int (*queryfs)(const unsigned int, struct cifs_tcon *,
0f060936 420 struct cifs_sb_info *, struct kstatfs *);
d39a4f71
PS
421 /* send mandatory brlock to the server */
422 int (*mand_lock)(const unsigned int, struct cifsFileInfo *, __u64,
423 __u64, __u32, int, int, bool);
424 /* unlock range of mandatory locks */
425 int (*mand_unlock_range)(struct cifsFileInfo *, struct file_lock *,
426 const unsigned int);
427 /* push brlocks from the cache to the server */
428 int (*push_mand_locks)(struct cifsFileInfo *);
b8c32dbb 429 /* get lease key of the inode */
a41a28bd 430 void (*get_lease_key)(struct inode *, struct cifs_fid *);
b8c32dbb 431 /* set lease key of the inode */
a41a28bd 432 void (*set_lease_key)(struct inode *, struct cifs_fid *);
b8c32dbb 433 /* generate new lease key */
a41a28bd 434 void (*new_lease_key)(struct cifs_fid *);
f486ef8e
SP
435 int (*generate_signingkey)(struct cifs_ses *ses,
436 struct TCP_Server_Info *server);
eda1c54f
LL
437 int (*calc_signature)(struct smb_rqst *, struct TCP_Server_Info *,
438 bool allocate_crypto);
b3152e2c
SF
439 int (*set_integrity)(const unsigned int, struct cifs_tcon *tcon,
440 struct cifsFileInfo *src_file);
834170c8
SF
441 int (*enum_snapshots)(const unsigned int xid, struct cifs_tcon *tcon,
442 struct cifsFileInfo *src_file, void __user *);
d26c2ddd
SF
443 int (*notify)(const unsigned int xid, struct file *pfile,
444 void __user *pbuf);
b5be1a1c
SP
445 int (*query_mf_symlink)(unsigned int, struct cifs_tcon *,
446 struct cifs_sb_info *, const unsigned char *,
447 char *, unsigned int *);
cbb0aba6
SP
448 int (*create_mf_symlink)(unsigned int, struct cifs_tcon *,
449 struct cifs_sb_info *, const unsigned char *,
450 char *, unsigned int *);
53ef1016
PS
451 /* if we can do cache read operations */
452 bool (*is_read_op)(__u32);
453 /* set oplock level for the inode */
42873b0a
PS
454 void (*set_oplock_level)(struct cifsInodeInfo *, __u32, unsigned int,
455 bool *);
a41a28bd 456 /* create lease context buffer for CREATE request */
729c0c9d 457 char * (*create_lease_buf)(u8 *lease_key, u8 oplock);
42873b0a 458 /* parse lease context buffer and return oplock/epoch info */
96164ab2 459 __u8 (*parse_lease_buf)(void *buf, unsigned int *epoch, char *lkey);
620d8745 460 ssize_t (*copychunk_range)(const unsigned int,
312bbc59 461 struct cifsFileInfo *src_file,
620d8745
SP
462 struct cifsFileInfo *target_file,
463 u64 src_off, u64 len, u64 dest_off);
02b16665
SF
464 int (*duplicate_extents)(const unsigned int, struct cifsFileInfo *src,
465 struct cifsFileInfo *target_file, u64 src_off, u64 len,
466 u64 dest_off);
ff1c038a 467 int (*validate_negotiate)(const unsigned int, struct cifs_tcon *);
666753c3
SF
468 ssize_t (*query_all_EAs)(const unsigned int, struct cifs_tcon *,
469 const unsigned char *, const unsigned char *, char *,
67b4c889 470 size_t, struct cifs_sb_info *);
666753c3
SF
471 int (*set_EA)(const unsigned int, struct cifs_tcon *, const char *,
472 const char *, const void *, const __u16,
5517554e 473 const struct nls_table *, struct cifs_sb_info *);
83e3bc23 474 struct cifs_ntsd * (*get_acl)(struct cifs_sb_info *, struct inode *,
3970acf7 475 const char *, u32 *, u32);
42eacf9e 476 struct cifs_ntsd * (*get_acl_by_fid)(struct cifs_sb_info *,
3970acf7 477 const struct cifs_fid *, u32 *, u32);
83e3bc23
SF
478 int (*set_acl)(struct cifs_ntsd *, __u32, struct inode *, const char *,
479 int);
7f6c5008
PS
480 /* writepages retry size */
481 unsigned int (*wp_retry_size)(struct inode *);
cb7e9eab
PS
482 /* get mtu credits */
483 int (*wait_mtu_credits)(struct TCP_Server_Info *, unsigned int,
335b7b62 484 unsigned int *, struct cifs_credits *);
9a1c67e8
PS
485 /* adjust previously taken mtu credits to request size */
486 int (*adjust_credits)(struct TCP_Server_Info *server,
487 struct cifs_credits *credits,
488 const unsigned int payload_size);
52755808
PS
489 /* check if we need to issue closedir */
490 bool (*dir_needs_close)(struct cifsFileInfo *);
31742c5a
SF
491 long (*fallocate)(struct file *, struct cifs_tcon *, int, loff_t,
492 loff_t);
7fb8986e 493 /* init transform request - used for encryption for now */
b2c96de7
RS
494 int (*init_transform_rq)(struct TCP_Server_Info *, int num_rqst,
495 struct smb_rqst *, struct smb_rqst *);
9bb17e09
PS
496 int (*is_transform_hdr)(void *buf);
497 int (*receive_transform)(struct TCP_Server_Info *,
b24df3e3 498 struct mid_q_entry **, char **, int *);
ef65aaed
SP
499 enum securityEnum (*select_sectype)(struct TCP_Server_Info *,
500 enum securityEnum);
8ce79ec3 501 int (*next_header)(char *);
f5b05d62
RS
502 /* ioctl passthrough for query_info */
503 int (*ioctl_query_info)(const unsigned int xid,
8d8b26e5 504 struct cifs_tcon *tcon,
0f060936 505 struct cifs_sb_info *cifs_sb,
8d8b26e5 506 __le16 *path, int is_dir,
f5b05d62 507 unsigned long p);
c847dccf
AA
508 /* make unix special files (block, char, fifo, socket) */
509 int (*make_node)(unsigned int xid,
510 struct inode *inode,
511 struct dentry *dentry,
512 struct cifs_tcon *tcon,
55869139 513 const char *full_path,
c847dccf
AA
514 umode_t mode,
515 dev_t device_number);
2f3ebaba
RS
516 /* version specific fiemap implementation */
517 int (*fiemap)(struct cifs_tcon *tcon, struct cifsFileInfo *,
518 struct fiemap_extent_info *, u64, u64);
dece44e3
RS
519 /* version specific llseek implementation */
520 loff_t (*llseek)(struct file *, struct cifs_tcon *, loff_t, int);
8e670f77
RS
521 /* Check for STATUS_IO_TIMEOUT */
522 bool (*is_status_io_timeout)(char *buf);
9e550b08
RS
523 /* Check for STATUS_NETWORK_NAME_DELETED */
524 void (*is_network_name_deleted)(char *buf, struct TCP_Server_Info *srv);
23db65f5
JL
525};
526
527struct smb_version_values {
528 char *version_string;
e4aa25e7
SF
529 __u16 protocol_id;
530 __u32 req_capabilities;
106dc538
PS
531 __u32 large_lock_type;
532 __u32 exclusive_lock_type;
533 __u32 shared_lock_type;
534 __u32 unlock_lock_type;
93012bf9 535 size_t header_preamble_size;
1887f601
PS
536 size_t header_size;
537 size_t max_header_size;
eb378711 538 size_t read_rsp_size;
2dc7e1c0 539 __le16 lock_cmd;
29e20f9c
PS
540 unsigned int cap_unix;
541 unsigned int cap_nt_find;
542 unsigned int cap_large_files;
50285882
JL
543 __u16 signing_enabled;
544 __u16 signing_required;
a41a28bd 545 size_t create_lease_size;
23db65f5
JL
546};
547
1887f601
PS
548#define HEADER_SIZE(server) (server->vals->header_size)
549#define MAX_HEADER_SIZE(server) (server->vals->max_header_size)
9789de8b 550#define HEADER_PREAMBLE_SIZE(server) (server->vals->header_preamble_size)
b6b3624d 551#define MID_HEADER_SIZE(server) (HEADER_SIZE(server) - 1 - HEADER_PREAMBLE_SIZE(server))
1887f601 552
d070f9dd
AA
553/**
554 * CIFS superblock mount flags (mnt_cifs_flags) to consider when
555 * trying to reuse existing superblock for a new mount
556 */
25c7f41e
PS
557#define CIFS_MOUNT_MASK (CIFS_MOUNT_NO_PERM | CIFS_MOUNT_SET_UID | \
558 CIFS_MOUNT_SERVER_INUM | CIFS_MOUNT_DIRECT_IO | \
559 CIFS_MOUNT_NO_XATTR | CIFS_MOUNT_MAP_SPECIAL_CHR | \
2baa2682 560 CIFS_MOUNT_MAP_SFM_CHR | \
25c7f41e
PS
561 CIFS_MOUNT_UNX_EMUL | CIFS_MOUNT_NO_BRL | \
562 CIFS_MOUNT_CIFS_ACL | CIFS_MOUNT_OVERR_UID | \
563 CIFS_MOUNT_OVERR_GID | CIFS_MOUNT_DYNPERM | \
564 CIFS_MOUNT_NOPOSIXBRL | CIFS_MOUNT_NOSSYNC | \
565 CIFS_MOUNT_FSCACHE | CIFS_MOUNT_MF_SYMLINKS | \
3d3ea8e6 566 CIFS_MOUNT_MULTIUSER | CIFS_MOUNT_STRICT_IO | \
d070f9dd 567 CIFS_MOUNT_CIFS_BACKUPUID | CIFS_MOUNT_CIFS_BACKUPGID | \
6552d6a0 568 CIFS_MOUNT_UID_FROM_ACL | CIFS_MOUNT_NO_HANDLE_CACHE | \
83bbfa70 569 CIFS_MOUNT_NO_DFS | CIFS_MOUNT_MODE_FROM_SID | \
41e033fe 570 CIFS_MOUNT_RO_CACHE | CIFS_MOUNT_RW_CACHE)
25c7f41e 571
d070f9dd
AA
572/**
573 * Generic VFS superblock mount flags (s_flags) to consider when
574 * trying to reuse existing superblock for a new mount
575 */
1751e8a6
LT
576#define CIFS_MS_MASK (SB_RDONLY | SB_MANDLOCK | SB_NOEXEC | SB_NOSUID | \
577 SB_NODEV | SB_SYNCHRONOUS)
25c7f41e
PS
578
579struct cifs_mnt_data {
580 struct cifs_sb_info *cifs_sb;
3fa1c6d1 581 struct smb3_fs_context *ctx;
25c7f41e
PS
582 int flags;
583};
584
792af7b0
PS
585static inline unsigned int
586get_rfc1002_length(void *buf)
587{
dca1c8d1 588 return be32_to_cpu(*((__be32 *)buf)) & 0xffffff;
792af7b0
PS
589}
590
ec2e4523
PS
591static inline void
592inc_rfc1001_len(void *buf, int count)
593{
594 be32_add_cpu((__be32 *)buf, count);
595}
596
1da177e4 597struct TCP_Server_Info {
3b795210
SF
598 struct list_head tcp_ses_list;
599 struct list_head smb_ses_list;
d7d7a66a 600 spinlock_t srv_lock; /* protect anything here that is not protected */
6d82c27a 601 __u64 conn_id; /* connection identifier (useful for debugging) */
e7ddee90 602 int srv_count; /* reference counter */
a10faeb2 603 /* 15 character server name + 0x20 16th byte indicating type = srv */
8ecaf67a 604 char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
23db65f5
JL
605 struct smb_version_operations *ops;
606 struct smb_version_values *vals;
080dc5e5 607 /* updates to tcpStatus protected by cifs_tcp_ses_lock */
c3dccf48 608 enum statusEnum tcpStatus; /* what we think the status is */
c359cf3c 609 char *hostname; /* hostname portion of UNC string */
1da177e4 610 struct socket *ssocket;
a9f1b85e 611 struct sockaddr_storage dstaddr;
3eb9a889 612 struct sockaddr_storage srcaddr; /* locally bind to this IP */
f1d0c998
RL
613#ifdef CONFIG_NET_NS
614 struct net *net;
615#endif
d38d8c74 616 wait_queue_head_t response_q;
1da177e4 617 wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
d7d7a66a 618 spinlock_t mid_lock; /* protect mid queue and it's entries */
1da177e4 619 struct list_head pending_mid_q;
edf1ae40
SF
620 bool noblocksnd; /* use blocking sendmsg */
621 bool noautotune; /* do not autotune send buf sizes */
c9f1c19c 622 bool nosharesock;
6a5fa236 623 bool tcp_nodelay;
141891f4
SF
624 unsigned int credits; /* send no more requests at once */
625 unsigned int max_credits; /* can override large 32000 default at mnt */
fc40f9cf 626 unsigned int in_flight; /* number of requests on the wire to server */
1b63f184 627 unsigned int max_in_flight; /* max number of requests that were on wire */
2d86dbc9 628 spinlock_t req_lock; /* protect the two values above */
cc391b69
VW
629 struct mutex _srv_mutex;
630 unsigned int nofs_flag;
1da177e4
LT
631 struct task_struct *tsk;
632 char server_GUID[16];
286170aa 633 __u16 sec_mode;
38d77c50 634 bool sign; /* is signing enabled on this connection? */
4f5c10f1 635 bool ignore_signature:1; /* skip validation of signatures in SMB2/3 rsp */
c3dccf48 636 bool session_estab; /* mark when very first sess is established */
28ea5290
PS
637 int echo_credits; /* echo reserved slots */
638 int oplock_credits; /* oplock break reserved slots */
639 bool echoes:1; /* enable echoes */
39552ea8 640 __u8 client_guid[SMB2_CLIENT_GUID_SIZE]; /* Client GUID */
c3dccf48 641 u16 dialect; /* dialect index that server chose */
10b9b98e 642 bool oplocks:1; /* enable oplocks */
1da177e4
LT
643 unsigned int maxReq; /* Clients should submit no more */
644 /* than maxReq distinct unanswered SMBs to the server when using */
11911b95 645 /* multiplexed reads or writes (for SMB1/CIFS only, not SMB2/SMB3) */
1da177e4
LT
646 unsigned int maxBuf; /* maxBuf specifies the maximum */
647 /* message size the server can send or receive for non-raw SMBs */
7e90d705
SF
648 /* maxBuf is returned by SMB NegotiateProtocol so maxBuf is only 0 */
649 /* when socket is setup (and during reconnect) before NegProt sent */
eca6acf9 650 unsigned int max_rw; /* maxRw specifies the maximum */
1da177e4
LT
651 /* message size the server can send or receive for */
652 /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */
29e20f9c 653 unsigned int capabilities; /* selective disabling of caps by smb sess */
de7ed55d 654 int timeAdj; /* Adjust for difference in server time zone in sec */
0fa757b5 655 __u64 CurrentMid; /* multiplex id - rotating counter, protected by GlobalMid_Lock */
d3ba50b1 656 char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */
a10faeb2 657 /* 16th byte of RFC1001 workstation name is always null */
8ecaf67a 658 char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
a0f8b4fb 659 __u32 sequence_number; /* for signing, protected by srv_mutex */
9e1a37da 660 __u32 reconnect_instance; /* incremented on each reconnect */
5f98ca9a 661 struct session_key session_key;
3a5ff61c 662 unsigned long lstrp; /* when we got last response from this server */
d2b91521 663 struct cifs_secmech secmech; /* crypto sec mech functs, descriptors */
e598d1d8
JL
664#define CIFS_NEGFLAVOR_UNENCAP 1 /* wct == 17, but no ext_sec */
665#define CIFS_NEGFLAVOR_EXTENDED 2 /* wct == 17, ext_sec bit set */
666 char negflavor; /* NEGOTIATE response flavor */
26efa0ba 667 /* extended security flavors that server supports */
c3dccf48
JL
668 bool sec_ntlmssp; /* supports NTLMSSP */
669 bool sec_kerberosu2u; /* supports U2U Kerberos */
26efa0ba
JL
670 bool sec_kerberos; /* supports plain Kerberos */
671 bool sec_mskerberos; /* supports legacy MS Kerberos */
2a37ef94 672 bool large_buf; /* is current buffer large? */
8339dd32
LL
673 /* use SMBD connection instead of socket */
674 bool rdma;
675 /* point to the SMBD connection if RDMA is used instead of socket */
676 struct smbd_connection *smbd_conn;
c74093b6 677 struct delayed_work echo; /* echo ping workqueue job */
506c1da4 678 struct delayed_work resolve; /* dns resolution workqueue job */
2a37ef94
JL
679 char *smallbuf; /* pointer to current "small" buffer */
680 char *bigbuf; /* pointer to current "big" buffer */
2e96467d
RS
681 /* Total size of this PDU. Only valid from cifs_demultiplex_thread */
682 unsigned int pdu_size;
2a37ef94 683 unsigned int total_read; /* total amount of data read in this pass */
1ae9a5a5
SF
684 atomic_t in_send; /* requests trying to send */
685 atomic_t num_waiters; /* blocked waiting to get in sendrecv */
c3dccf48 686#ifdef CONFIG_CIFS_STATS2
433b8dd7 687 atomic_t num_cmds[NUMBER_OF_SMB2_COMMANDS]; /* total requests by cmd */
468d6779 688 atomic_t smb2slowcmd[NUMBER_OF_SMB2_COMMANDS]; /* count resps > 1 sec */
433b8dd7
SF
689 __u64 time_per_cmd[NUMBER_OF_SMB2_COMMANDS]; /* total time per cmd */
690 __u32 slowest_cmd[NUMBER_OF_SMB2_COMMANDS];
691 __u32 fastest_cmd[NUMBER_OF_SMB2_COMMANDS];
468d6779 692#endif /* STATS2 */
ec2e4523
PS
693 unsigned int max_read;
694 unsigned int max_write;
563317ec 695 unsigned int min_offload;
26ea888f 696 __le16 compress_algorithm;
53d31a3f 697 __u16 signing_algorithm;
5100d8a3 698 __le16 cipher_type;
8bd68c6e
AA
699 /* save initital negprot hash */
700 __u8 preauth_sha_hash[SMB2_PREAUTH_HASH_SIZE];
53d31a3f 701 bool signing_negotiated; /* true if valid signing context rcvd from server */
fcef0db6 702 bool posix_ext_supported;
53e0e11e
PS
703 struct delayed_work reconnect; /* reconnect workqueue job */
704 struct mutex reconnect_mutex; /* prevent simultaneous reconnects */
adfeb3e0 705 unsigned long echo_interval;
93d5cb51
PA
706
707 /*
708 * Number of targets available for reconnect. The more targets
709 * the more tasks have to wait to let the demultiplex thread
710 * reconnect.
711 */
712 int nr_targets;
8eecd1c2 713 bool noblockcnt; /* use non-blocking connect() */
0f2b305a
SP
714
715 /*
716 * If this is a session channel,
717 * primary_server holds the ref-counted
718 * pointer to primary channel connection for the session.
719 */
720#define CIFS_SERVER_IS_CHAN(server) (!!(server)->primary_server)
721 struct TCP_Server_Info *primary_server;
722
121d947d
SC
723#ifdef CONFIG_CIFS_SWN_UPCALL
724 bool use_swn_dstaddr;
725 struct sockaddr_storage swn_dstaddr;
726#endif
cdc33630
PA
727#ifdef CONFIG_CIFS_DFS_UPCALL
728 bool is_dfs_conn; /* if a dfs connection */
c88f7dcd
PA
729 struct mutex refpath_lock; /* protects leaf_fullpath */
730 /*
731 * Canonical DFS full paths that were used to chase referrals in mount and reconnect.
732 *
733 * origin_fullpath: first or original referral path
734 * leaf_fullpath: last referral path (might be changed due to nested links in reconnect)
735 *
736 * current_fullpath: pointer to either origin_fullpath or leaf_fullpath
737 * NOTE: cannot be accessed outside cifs_reconnect() and smb2_reconnect()
738 *
739 * format: \\HOST\SHARE\[OPTIONAL PATH]
740 */
741 char *origin_fullpath, *leaf_fullpath, *current_fullpath;
cdc33630 742#endif
1da177e4
LT
743};
744
d291e703
ZX
745static inline bool is_smb1(struct TCP_Server_Info *server)
746{
747 return HEADER_PREAMBLE_SIZE(server) != 0;
748}
749
cc391b69
VW
750static inline void cifs_server_lock(struct TCP_Server_Info *server)
751{
752 unsigned int nofs_flag = memalloc_nofs_save();
753
754 mutex_lock(&server->_srv_mutex);
755 server->nofs_flag = nofs_flag;
756}
757
758static inline void cifs_server_unlock(struct TCP_Server_Info *server)
759{
760 unsigned int nofs_flag = server->nofs_flag;
761
762 mutex_unlock(&server->_srv_mutex);
763 memalloc_nofs_restore(nofs_flag);
764}
765
335b7b62
PS
766struct cifs_credits {
767 unsigned int value;
768 unsigned int instance;
769};
770
fc40f9cf
PS
771static inline unsigned int
772in_flight(struct TCP_Server_Info *server)
773{
774 unsigned int num;
775 spin_lock(&server->req_lock);
776 num = server->in_flight;
777 spin_unlock(&server->req_lock);
778 return num;
779}
780
2d86dbc9 781static inline bool
b227d215 782has_credits(struct TCP_Server_Info *server, int *credits, int num_credits)
fc40f9cf 783{
2d86dbc9 784 int num;
fc40f9cf 785 spin_lock(&server->req_lock);
bc205ed1 786 num = *credits;
fc40f9cf 787 spin_unlock(&server->req_lock);
b227d215 788 return num >= num_credits;
fc40f9cf
PS
789}
790
45275789 791static inline void
34f4deb7 792add_credits(struct TCP_Server_Info *server, const struct cifs_credits *credits,
a891f0f8 793 const int optype)
45275789 794{
34f4deb7 795 server->ops->add_credits(server, credits, optype);
45275789
PS
796}
797
cb7e9eab 798static inline void
335b7b62
PS
799add_credits_and_wake_if(struct TCP_Server_Info *server,
800 const struct cifs_credits *credits, const int optype)
cb7e9eab 801{
335b7b62
PS
802 if (credits->value) {
803 server->ops->add_credits(server, credits, optype);
cb7e9eab
PS
804 wake_up(&server->request_q);
805 }
806}
807
45275789
PS
808static inline void
809set_credits(struct TCP_Server_Info *server, const int val)
810{
811 server->ops->set_credits(server, val);
812}
813
9a1c67e8
PS
814static inline int
815adjust_credits(struct TCP_Server_Info *server, struct cifs_credits *credits,
816 const unsigned int payload_size)
817{
818 return server->ops->adjust_credits ?
819 server->ops->adjust_credits(server, credits, payload_size) : 0;
820}
821
9235d098 822static inline __le64
3d378d3f 823get_next_mid64(struct TCP_Server_Info *server)
88257360 824{
9235d098 825 return cpu_to_le64(server->ops->get_next_mid(server));
88257360
PS
826}
827
3d378d3f
TG
828static inline __le16
829get_next_mid(struct TCP_Server_Info *server)
830{
9235d098 831 __u16 mid = server->ops->get_next_mid(server);
3d378d3f
TG
832 /*
833 * The value in the SMB header should be little endian for easy
834 * on-the-wire decoding.
835 */
836 return cpu_to_le16(mid);
837}
838
c781af7e
PS
839static inline void
840revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
841{
842 if (server->ops->revert_current_mid)
843 server->ops->revert_current_mid(server, val);
844}
845
846static inline void
847revert_current_mid_from_hdr(struct TCP_Server_Info *server,
0d35e382 848 const struct smb2_hdr *shdr)
c781af7e
PS
849{
850 unsigned int num = le16_to_cpu(shdr->CreditCharge);
851
852 return revert_current_mid(server, num > 0 ? num : 1);
853}
854
3d378d3f
TG
855static inline __u16
856get_mid(const struct smb_hdr *smb)
857{
858 return le16_to_cpu(smb->Mid);
859}
860
861static inline bool
862compare_mid(__u16 mid, const struct smb_hdr *smb)
863{
864 return mid == le16_to_cpu(smb->Mid);
865}
866
24985c53
PS
867/*
868 * When the server supports very large reads and writes via POSIX extensions,
869 * we can allow up to 2^24-1, minus the size of a READ/WRITE_AND_X header, not
870 * including the RFC1001 length.
871 *
872 * Note that this might make for "interesting" allocation problems during
873 * writeback however as we have to allocate an array of pointers for the
ea1754a0 874 * pages. A 16M write means ~32kb page array with PAGE_SIZE == 4096.
24985c53
PS
875 *
876 * For reads, there is a similar problem as we need to allocate an array
877 * of kvecs to handle the receive, though that should only need to be done
878 * once.
879 */
880#define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4)
881#define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP) + 4)
882
883/*
884 * When the server doesn't allow large posix writes, only allow a rsize/wsize
885 * of 2^17-1 minus the size of the call header. That allows for a read or
886 * write up to the maximum size described by RFC1002.
887 */
888#define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4)
889#define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4)
890
24985c53
PS
891#define CIFS_DEFAULT_IOSIZE (1024 * 1024)
892
893/*
894 * Windows only supports a max of 60kb reads and 65535 byte writes. Default to
895 * those values when posix extensions aren't in force. In actuality here, we
896 * use 65536 to allow for a write that is a multiple of 4k. Most servers seem
897 * to be ok with the extra byte even though Windows doesn't send writes that
898 * are that large.
899 *
900 * Citation:
901 *
cba22b1c 902 * https://blogs.msdn.com/b/openspecification/archive/2009/04/10/smb-maximum-transmit-buffer-size-and-performance-tuning.aspx
24985c53
PS
903 */
904#define CIFS_DEFAULT_NON_POSIX_RSIZE (60 * 1024)
905#define CIFS_DEFAULT_NON_POSIX_WSIZE (65536)
906
f1d0c998
RL
907/*
908 * Macros to allow the TCP_Server_Info->net field and related code to drop out
909 * when CONFIG_NET_NS isn't set.
910 */
911
912#ifdef CONFIG_NET_NS
913
914static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv)
915{
916 return srv->net;
917}
918
919static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net)
920{
921 srv->net = net;
922}
923
924#else
925
926static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv)
927{
928 return &init_net;
929}
930
931static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net)
932{
933}
934
935#endif
936
b6f0dd5d 937struct cifs_server_iface {
aa45dadd
SP
938 struct list_head iface_head;
939 struct kref refcount;
b6f0dd5d
AA
940 size_t speed;
941 unsigned int rdma_capable : 1;
942 unsigned int rss_capable : 1;
aa45dadd 943 unsigned int is_active : 1; /* unset if non existent */
b6f0dd5d
AA
944 struct sockaddr_storage sockaddr;
945};
946
aa45dadd
SP
947/* release iface when last ref is dropped */
948static inline void
949release_iface(struct kref *ref)
950{
951 struct cifs_server_iface *iface = container_of(ref,
952 struct cifs_server_iface,
953 refcount);
954 list_del_init(&iface->iface_head);
955 kfree(iface);
956}
957
958/*
959 * compare two interfaces a and b
960 * return 0 if everything matches.
961 * return 1 if a has higher link speed, or rdma capable, or rss capable
962 * return -1 otherwise.
963 */
964static inline int
965iface_cmp(struct cifs_server_iface *a, struct cifs_server_iface *b)
966{
967 int cmp_ret = 0;
968
969 WARN_ON(!a || !b);
970 if (a->speed == b->speed) {
971 if (a->rdma_capable == b->rdma_capable) {
972 if (a->rss_capable == b->rss_capable) {
973 cmp_ret = memcmp(&a->sockaddr, &b->sockaddr,
974 sizeof(a->sockaddr));
975 if (!cmp_ret)
976 return 0;
977 else if (cmp_ret > 0)
978 return 1;
979 else
980 return -1;
981 } else if (a->rss_capable > b->rss_capable)
982 return 1;
983 else
984 return -1;
985 } else if (a->rdma_capable > b->rdma_capable)
986 return 1;
987 else
988 return -1;
989 } else if (a->speed > b->speed)
990 return 1;
991 else
992 return -1;
993}
994
bcc88801 995struct cifs_chan {
5752bf64 996 unsigned int in_reconnect : 1; /* if session setup in progress for this channel */
bcc88801 997 struct TCP_Server_Info *server;
aa45dadd 998 struct cifs_server_iface *iface; /* interface in use */
bcc88801
AA
999 __u8 signkey[SMB3_SIGN_KEY_SIZE];
1000};
1001
1da177e4
LT
1002/*
1003 * Session structure. One of these for each uid session with a particular host
1004 */
96daf2b0 1005struct cifs_ses {
14fbf50d 1006 struct list_head smb_ses_list;
3663c904 1007 struct list_head rlist; /* reconnect list */
3b795210 1008 struct list_head tcon_list;
b327a717 1009 struct cifs_tcon *tcon_ipc;
d7d7a66a 1010 spinlock_t ses_lock; /* protect anything here that is not protected */
d7b619cf 1011 struct mutex session_mutex;
1da177e4 1012 struct TCP_Server_Info *server; /* pointer to server info */
14fbf50d 1013 int ses_count; /* reference counter */
dd3cd870 1014 enum ses_status_enum ses_status; /* updates protected by cifs_tcp_ses_lock */
750d1151 1015 unsigned overrideSecFlg; /* if non-zero override global sec flags */
ad009ac9
SF
1016 char *serverOS; /* name of operating system underlying server */
1017 char *serverNOS; /* name of network operating system of server */
1da177e4 1018 char *serverDomain; /* security realm of server */
286170aa 1019 __u64 Suid; /* remote smb uid */
64ed39dd
EB
1020 kuid_t linux_uid; /* overriding owner of files on the mount */
1021 kuid_t cred_uid; /* owner of credentials */
29e20f9c 1022 unsigned int capabilities;
b438fcf1 1023 char ip_addr[INET6_ADDRSTRLEN + 1]; /* Max ipv6 (or v4) addr string len */
34c87901
SF
1024 char *user_name; /* must not be null except during init of sess
1025 and after mount option parsing we fill it */
d38d8c74
SF
1026 char *domainName;
1027 char *password;
de3a9e94 1028 char workstation_name[CIFS_MAX_WORKSTATION_LEN];
5d0d2882 1029 struct session_key auth_key;
d3686d54 1030 struct ntlmssp_auth *ntlmssp; /* ciphertext, flags, server challenge */
28e11bd8
JL
1031 enum securityEnum sectype; /* what security flavor was specified? */
1032 bool sign; /* is signing required? */
39566443 1033 bool domainAuto:1;
5478f9ba 1034 __u16 session_flags;
373512ec 1035 __u8 smb3signingkey[SMB3_SIGN_KEY_SIZE];
45a4546c
SP
1036 __u8 smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE];
1037 __u8 smb3decryptionkey[SMB3_ENC_DEC_KEY_SIZE];
8bd68c6e 1038 __u8 preauth_sha_hash[SMB2_PREAUTH_HASH_SIZE];
b6f0dd5d
AA
1039
1040 /*
1041 * Network interfaces available on the server this session is
1042 * connected to.
1043 *
1044 * Other channels can be opened by connecting and binding this
1045 * session to interfaces from this list.
1046 *
1047 * iface_lock should be taken when accessing any of these fields
1048 */
1049 spinlock_t iface_lock;
724244cd 1050 /* ========= begin: protected by iface_lock ======== */
aa45dadd 1051 struct list_head iface_list;
b6f0dd5d
AA
1052 size_t iface_count;
1053 unsigned long iface_last_update; /* jiffies */
724244cd 1054 /* ========= end: protected by iface_lock ======== */
bcc88801 1055
724244cd
SP
1056 spinlock_t chan_lock;
1057 /* ========= begin: protected by chan_lock ======== */
bcc88801 1058#define CIFS_MAX_CHANNELS 16
d1a931ce
SP
1059#define CIFS_ALL_CHANNELS_SET(ses) \
1060 ((1UL << (ses)->chan_count) - 1)
5752bf64
SP
1061#define CIFS_ALL_CHANS_GOOD(ses) \
1062 (!(ses)->chans_need_reconnect)
d1a931ce
SP
1063#define CIFS_ALL_CHANS_NEED_RECONNECT(ses) \
1064 ((ses)->chans_need_reconnect == CIFS_ALL_CHANNELS_SET(ses))
183eea2e
SP
1065#define CIFS_SET_ALL_CHANS_NEED_RECONNECT(ses) \
1066 ((ses)->chans_need_reconnect = CIFS_ALL_CHANNELS_SET(ses))
d1a931ce
SP
1067#define CIFS_CHAN_NEEDS_RECONNECT(ses, index) \
1068 test_bit((index), &(ses)->chans_need_reconnect)
5752bf64
SP
1069#define CIFS_CHAN_IN_RECONNECT(ses, index) \
1070 ((ses)->chans[(index)].in_reconnect)
d1a931ce 1071
bcc88801
AA
1072 struct cifs_chan chans[CIFS_MAX_CHANNELS];
1073 size_t chan_count;
1074 size_t chan_max;
1075 atomic_t chan_seq; /* round robin state */
d1a931ce
SP
1076
1077 /*
1078 * chans_need_reconnect is a bitmap indicating which of the channels
1079 * under this smb session needs to be reconnected.
1080 * If not multichannel session, only one bit will be used.
f486ef8e
SP
1081 *
1082 * We will ask for sess and tcon reconnection only if all the
1083 * channels are marked for needing reconnection. This will
1084 * enable the sessions on top to continue to live till any
1085 * of the channels below are active.
d1a931ce
SP
1086 */
1087 unsigned long chans_need_reconnect;
724244cd 1088 /* ========= end: protected by chan_lock ======== */
1da177e4 1089};
233839b1 1090
29e20f9c
PS
1091static inline bool
1092cap_unix(struct cifs_ses *ses)
1093{
1094 return ses->server->vals->cap_unix & ses->capabilities;
1095}
1096
f695b289
RS
1097/*
1098 * common struct for holding inode info when searching for or updating an
1099 * inode with new info
1100 */
1101
1102#define CIFS_FATTR_DFS_REFERRAL 0x1
1103#define CIFS_FATTR_DELETE_PENDING 0x2
1104#define CIFS_FATTR_NEED_REVAL 0x4
1105#define CIFS_FATTR_INO_COLLISION 0x8
1106#define CIFS_FATTR_UNKNOWN_NLINK 0x10
1107#define CIFS_FATTR_FAKE_ROOT_INO 0x20
1108
1109struct cifs_fattr {
1110 u32 cf_flags;
1111 u32 cf_cifsattrs;
1112 u64 cf_uniqueid;
1113 u64 cf_eof;
1114 u64 cf_bytes;
1115 u64 cf_createtime;
1116 kuid_t cf_uid;
1117 kgid_t cf_gid;
1118 umode_t cf_mode;
1119 dev_t cf_rdev;
1120 unsigned int cf_nlink;
1121 unsigned int cf_dtype;
1122 struct timespec64 cf_atime;
1123 struct timespec64 cf_mtime;
1124 struct timespec64 cf_ctime;
1125 u32 cf_cifstag;
1126};
1127
1da177e4
LT
1128/*
1129 * there is one of these for each connection to a resource on a particular
d38d8c74 1130 * session
1da177e4 1131 */
96daf2b0 1132struct cifs_tcon {
f1987b44
JL
1133 struct list_head tcon_list;
1134 int tc_count;
53e0e11e 1135 struct list_head rlist; /* reconnect list */
d7d7a66a 1136 spinlock_t tc_lock; /* protect anything here that is not protected */
fae8044c
SF
1137 atomic_t num_local_opens; /* num of all opens including disconnected */
1138 atomic_t num_remote_opens; /* num of all network opens on server */
1da177e4 1139 struct list_head openFileList;
3afca265 1140 spinlock_t open_file_lock; /* protects list above */
96daf2b0 1141 struct cifs_ses *ses; /* pointer to session associated with */
68e14569 1142 char tree_name[MAX_TREE_SIZE + 1]; /* UNC name of resource in ASCII */
1da177e4 1143 char *nativeFileSystem;
00e485b0 1144 char *password; /* for share-level security */
faaf946a 1145 __u32 tid; /* The 4 byte tree id */
1da177e4 1146 __u16 Flags; /* optional support bits */
fdf59eb5 1147 enum tid_status_enum status;
1da177e4 1148 atomic_t num_smbs_sent;
44c58186
PS
1149 union {
1150 struct {
1151 atomic_t num_writes;
1152 atomic_t num_reads;
1153 atomic_t num_flushes;
1154 atomic_t num_oplock_brks;
1155 atomic_t num_opens;
1156 atomic_t num_closes;
1157 atomic_t num_deletes;
1158 atomic_t num_mkdirs;
1159 atomic_t num_posixopens;
1160 atomic_t num_posixmkdirs;
1161 atomic_t num_rmdirs;
1162 atomic_t num_renames;
1163 atomic_t num_t2renames;
1164 atomic_t num_ffirst;
1165 atomic_t num_fnext;
1166 atomic_t num_fclose;
1167 atomic_t num_hardlinks;
1168 atomic_t num_symlinks;
1169 atomic_t num_locks;
1170 atomic_t num_acl_get;
1171 atomic_t num_acl_set;
1172 } cifs_stats;
d60622eb
PS
1173 struct {
1174 atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
1175 atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
1176 } smb2_stats;
44c58186 1177 } stats;
1da177e4
LT
1178 __u64 bytes_read;
1179 __u64 bytes_written;
3afca265 1180 spinlock_t stat_lock; /* protects the two fields above */
1da177e4 1181 FILE_SYSTEM_DEVICE_INFO fsDevInfo;
254e55ed 1182 FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo; /* ok if fs name truncated */
1da177e4 1183 FILE_SYSTEM_UNIX_INFO fsUnixInfo;
b327a717
AA
1184 bool ipc:1; /* set if connection to IPC$ share (always also pipe) */
1185 bool pipe:1; /* set if connection to pipe share */
1186 bool print:1; /* set if connection to printer share */
4b18f2a9
SF
1187 bool retry:1;
1188 bool nocase:1;
3d4ef9a1 1189 bool nohandlecache:1; /* if strange server resource prob can turn off */
82e9367c 1190 bool nodelete:1;
95b1cb90 1191 bool seal:1; /* transport encryption for this mounted share */
4b18f2a9 1192 bool unix_ext:1; /* if false disable Linux extensions to CIFS protocol
c18c842b 1193 for this mount even if server would support */
b326614e 1194 bool posix_extensions; /* if true SMB3.11 posix extensions enabled */
84210e91 1195 bool local_lease:1; /* check leases (only) on local system not remote */
64cc2c63 1196 bool broken_posix_open; /* e.g. Samba server versions < 3.3.2, 3.2.9 */
3d1a3745 1197 bool broken_sparse_sup; /* if server or share does not support sparse */
3b795210 1198 bool need_reconnect:1; /* connection reset, tid now invalid */
96a988ff 1199 bool need_reopen_files:1; /* need to reopen tcon file handles */
592fafe6 1200 bool use_resilient:1; /* use resilient instead of durable handles */
b618f001 1201 bool use_persistent:1; /* use persistent instead of durable handles */
3e7a02d4 1202 bool no_lease:1; /* Do not request leases on files or directories */
b7fd0fa0 1203 bool use_witness:1; /* use witness protocol */
769ee6a4 1204 __le32 capabilities;
faaf946a
PS
1205 __u32 share_flags;
1206 __u32 maximal_access;
1207 __u32 vol_serial_number;
1208 __le64 vol_create_time;
8b217fe7 1209 __u64 snapshot_time; /* for timewarp tokens - timestamp of snapshot */
ca567eb2 1210 __u32 handle_timeout; /* persistent and durable handle timeout in ms */
af6a12ea
SF
1211 __u32 ss_flags; /* sector size flags */
1212 __u32 perf_sector_size; /* best sector size for perf */
de9f68df
SF
1213 __u32 max_chunks;
1214 __u32 max_bytes_chunk;
1215 __u32 max_bytes_copy;
d03382ce
SJ
1216#ifdef CONFIG_CIFS_FSCACHE
1217 u64 resource_id; /* server resource id */
70431bfd 1218 struct fscache_volume *fscache; /* cookie for share */
d03382ce 1219#endif
233839b1 1220 struct list_head pending_opens; /* list of incomplete opens */
aea6794e 1221 struct cached_fids *cfids;
c18c842b 1222 /* BB add field for back pointer to sb struct(s)? */
54be1f6c 1223#ifdef CONFIG_CIFS_DFS_UPCALL
54be1f6c
PA
1224 struct list_head ulist; /* cache update list */
1225#endif
6e1c1c08 1226 struct delayed_work query_interfaces; /* query interfaces workqueue job */
1da177e4
LT
1227};
1228
7ffec372
JL
1229/*
1230 * This is a refcounted and timestamped container for a tcon pointer. The
1231 * container holds a tcon reference. It is considered safe to free one of
1232 * these when the tl_count goes to 0. The tl_time is the time of the last
1233 * "get" on the container.
1234 */
1235struct tcon_link {
b647c35f 1236 struct rb_node tl_rbnode;
6d4a0832 1237 kuid_t tl_uid;
9d002df4
JL
1238 unsigned long tl_flags;
1239#define TCON_LINK_MASTER 0
1240#define TCON_LINK_PENDING 1
1241#define TCON_LINK_IN_TREE 2
1242 unsigned long tl_time;
1243 atomic_t tl_count;
96daf2b0 1244 struct cifs_tcon *tl_tcon;
7ffec372
JL
1245};
1246
9d002df4 1247extern struct tcon_link *cifs_sb_tlink(struct cifs_sb_info *cifs_sb);
b2c96de7 1248extern void smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst);
7ffec372 1249
96daf2b0 1250static inline struct cifs_tcon *
7ffec372
JL
1251tlink_tcon(struct tcon_link *tlink)
1252{
9d002df4 1253 return tlink->tl_tcon;
7ffec372
JL
1254}
1255
8ddecf5f
AA
1256static inline struct tcon_link *
1257cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb)
1258{
1259 return cifs_sb->master_tlink;
1260}
1261
9d002df4 1262extern void cifs_put_tlink(struct tcon_link *tlink);
7ffec372 1263
13cfb733
JL
1264static inline struct tcon_link *
1265cifs_get_tlink(struct tcon_link *tlink)
1266{
9d002df4
JL
1267 if (tlink && !IS_ERR(tlink))
1268 atomic_inc(&tlink->tl_count);
13cfb733
JL
1269 return tlink;
1270}
1271
7ffec372 1272/* This function is always expected to succeed */
96daf2b0 1273extern struct cifs_tcon *cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb);
7ffec372 1274
233839b1
PS
1275#define CIFS_OPLOCK_NO_CHANGE 0xfe
1276
1277struct cifs_pending_open {
1278 struct list_head olist;
1279 struct tcon_link *tlink;
1280 __u8 lease_key[16];
1281 __u32 oplock;
1282};
1283
c3f207ab
RS
1284struct cifs_deferred_close {
1285 struct list_head dlist;
1286 struct tcon_link *tlink;
1287 __u16 netfid;
1288 __u64 persistent_fid;
1289 __u64 volatile_fid;
1290};
1291
1da177e4 1292/*
7ee1af76
JA
1293 * This info hangs off the cifsFileInfo structure, pointed to by llist.
1294 * This is used to track byte stream locks on the file
1da177e4
LT
1295 */
1296struct cifsLockInfo {
7ee1af76 1297 struct list_head llist; /* pointer to next cifsLockInfo */
85160e03
PS
1298 struct list_head blist; /* pointer to locks blocked on this */
1299 wait_queue_head_t block_q;
7ee1af76
JA
1300 __u64 offset;
1301 __u64 length;
03776f45 1302 __u32 pid;
9645759c
RS
1303 __u16 type;
1304 __u16 flags;
1da177e4
LT
1305};
1306
1307/*
1308 * One of these for each open instance of a file
1309 */
1310struct cifs_search_info {
1311 loff_t index_of_last_entry;
1312 __u16 entries_in_buffer;
1313 __u16 info_level;
1314 __u32 resume_key;
d38d8c74
SF
1315 char *ntwrk_buf_start;
1316 char *srch_entries_start;
0752f152 1317 char *last_entry;
eaf35b1e 1318 const char *presume_name;
1da177e4 1319 unsigned int resume_name_len;
4b18f2a9
SF
1320 bool endOfSearch:1;
1321 bool emptyDir:1;
1322 bool unicode:1;
1323 bool smallBuf:1; /* so we know which buf_release function to call */
1da177e4
LT
1324};
1325
d0959b08 1326#define ACL_NO_MODE ((umode_t)(-1))
226730b4
PS
1327struct cifs_open_parms {
1328 struct cifs_tcon *tcon;
1329 struct cifs_sb_info *cifs_sb;
1330 int disposition;
1331 int desired_access;
1332 int create_options;
1333 const char *path;
1334 struct cifs_fid *fid;
ce558b0e 1335 umode_t mode;
9cbc0b73 1336 bool reconnect:1;
226730b4
PS
1337};
1338
4b4de76e
PS
1339struct cifs_fid {
1340 __u16 netfid;
f0df737e
PS
1341 __u64 persistent_fid; /* persist file id for smb2 */
1342 __u64 volatile_fid; /* volatile file id for smb2 */
b8c32dbb 1343 __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for smb2 */
b56eae4d 1344 __u8 create_guid[16];
86f740f2 1345 __u32 access;
233839b1 1346 struct cifs_pending_open *pending_open;
42873b0a 1347 unsigned int epoch;
dfe33f9a
SF
1348#ifdef CONFIG_CIFS_DEBUG2
1349 __u64 mid;
1350#endif /* CIFS_DEBUG2 */
42873b0a 1351 bool purge_cache;
4b4de76e
PS
1352};
1353
f45d3416
PS
1354struct cifs_fid_locks {
1355 struct list_head llist;
1356 struct cifsFileInfo *cfile; /* fid that owns locks */
1357 struct list_head locks; /* locks held by fid above */
1358};
1359
1da177e4 1360struct cifsFileInfo {
3afca265 1361 /* following two lists are protected by tcon->open_file_lock */
1da177e4
LT
1362 struct list_head tlist; /* pointer to next fid owned by tcon */
1363 struct list_head flist; /* next fid (file instance) for this inode */
3afca265 1364 /* lock list below protected by cifsi->lock_sem */
f45d3416 1365 struct cifs_fid_locks *llist; /* brlocks held by this fid */
fef59fd7 1366 kuid_t uid; /* allows finding which FileInfo structure */
1da177e4 1367 __u32 pid; /* process id who opened file */
4b4de76e 1368 struct cifs_fid fid; /* file id from remote */
f2cca6a7 1369 struct list_head rlist; /* reconnect list */
1da177e4
LT
1370 /* BB add lock scope info here if needed */ ;
1371 /* lock scope id (0 if none) */
a5e18bc3 1372 struct dentry *dentry;
13cfb733 1373 struct tcon_link *tlink;
3afca265 1374 unsigned int f_flags;
4b18f2a9 1375 bool invalidHandle:1; /* file closed via session abend */
4e8aea30 1376 bool swapfile:1;
3bc303c2 1377 bool oplock_break_cancelled:1;
9bd45408
PS
1378 unsigned int oplock_epoch; /* epoch from the lease break */
1379 __u32 oplock_level; /* oplock/lease level from the lease break */
3afca265
SF
1380 int count;
1381 spinlock_t file_info_lock; /* protects four flag/count fields above */
a6ce4932 1382 struct mutex fh_mutex; /* prevents reopen race after dead ses*/
1da177e4 1383 struct cifs_search_info srch_inf;
9b646972 1384 struct work_struct oplock_break; /* work for oplock breaks */
32546a95 1385 struct work_struct put; /* work for the final part of _put */
c3f207ab 1386 struct delayed_work deferred;
860b69a9 1387 bool deferred_close_scheduled; /* Flag to indicate close is scheduled */
1da177e4
LT
1388};
1389
fa2989f4
PS
1390struct cifs_io_parms {
1391 __u16 netfid;
09a4707e
PS
1392 __u64 persistent_fid; /* persist file id for smb2 */
1393 __u64 volatile_fid; /* volatile file id for smb2 */
fa2989f4
PS
1394 __u32 pid;
1395 __u64 offset;
1396 unsigned int length;
96daf2b0 1397 struct cifs_tcon *tcon;
352d96f3 1398 struct TCP_Server_Info *server;
fa2989f4
PS
1399};
1400
ccf7f408
PS
1401struct cifs_aio_ctx {
1402 struct kref refcount;
1403 struct list_head list;
1404 struct mutex aio_mutex;
1405 struct completion done;
1406 struct iov_iter iter;
1407 struct kiocb *iocb;
1408 struct cifsFileInfo *cfile;
1409 struct bio_vec *bv;
c610c4b6 1410 loff_t pos;
ccf7f408
PS
1411 unsigned int npages;
1412 ssize_t rc;
1413 unsigned int len;
1414 unsigned int total_len;
1415 bool should_dirty;
6e6e2b86
LL
1416 /*
1417 * Indicates if this aio_ctx is for direct_io,
1418 * If yes, iter is a copy of the user passed iov_iter
1419 */
1420 bool direct_io;
ccf7f408
PS
1421};
1422
09a4707e
PS
1423/* asynchronous read support */
1424struct cifs_readdata {
1425 struct kref refcount;
1426 struct list_head list;
1427 struct completion done;
1428 struct cifsFileInfo *cfile;
1429 struct address_space *mapping;
6685c5e2 1430 struct cifs_aio_ctx *ctx;
09a4707e
PS
1431 __u64 offset;
1432 unsigned int bytes;
34a54d61 1433 unsigned int got_bytes;
09a4707e
PS
1434 pid_t pid;
1435 int result;
09a4707e 1436 struct work_struct work;
8321fec4
JL
1437 int (*read_into_pages)(struct TCP_Server_Info *server,
1438 struct cifs_readdata *rdata,
1439 unsigned int len);
d70b9104
PS
1440 int (*copy_into_pages)(struct TCP_Server_Info *server,
1441 struct cifs_readdata *rdata,
1442 struct iov_iter *iter);
738f9de5 1443 struct kvec iov[2];
352d96f3 1444 struct TCP_Server_Info *server;
74dcf418
LL
1445#ifdef CONFIG_CIFS_SMB_DIRECT
1446 struct smbd_mr *mr;
1447#endif
8321fec4 1448 unsigned int pagesz;
57a929a6 1449 unsigned int page_offset;
8321fec4 1450 unsigned int tailsz;
335b7b62 1451 struct cifs_credits credits;
c5fab6f4 1452 unsigned int nr_pages;
f9f5aca1 1453 struct page **pages;
09a4707e
PS
1454};
1455
33319141
PS
1456/* asynchronous write support */
1457struct cifs_writedata {
1458 struct kref refcount;
1459 struct list_head list;
1460 struct completion done;
1461 enum writeback_sync_modes sync_mode;
1462 struct work_struct work;
1463 struct cifsFileInfo *cfile;
c610c4b6 1464 struct cifs_aio_ctx *ctx;
33319141
PS
1465 __u64 offset;
1466 pid_t pid;
1467 unsigned int bytes;
1468 int result;
352d96f3 1469 struct TCP_Server_Info *server;
db223a59
LL
1470#ifdef CONFIG_CIFS_SMB_DIRECT
1471 struct smbd_mr *mr;
1472#endif
eddb079d 1473 unsigned int pagesz;
57a929a6 1474 unsigned int page_offset;
eddb079d 1475 unsigned int tailsz;
335b7b62 1476 struct cifs_credits credits;
33319141 1477 unsigned int nr_pages;
8e7360f6 1478 struct page **pages;
33319141
PS
1479};
1480
5f6dbc9e
JL
1481/*
1482 * Take a reference on the file private data. Must be called with
3afca265 1483 * cfile->file_info_lock held.
5f6dbc9e 1484 */
764a1b1a
JL
1485static inline void
1486cifsFileInfo_get_locked(struct cifsFileInfo *cifs_file)
6ab409b5 1487{
5f6dbc9e 1488 ++cifs_file->count;
6ab409b5
DK
1489}
1490
764a1b1a 1491struct cifsFileInfo *cifsFileInfo_get(struct cifsFileInfo *cifs_file);
32546a95
RS
1492void _cifsFileInfo_put(struct cifsFileInfo *cifs_file, bool wait_oplock_hdlr,
1493 bool offload);
b33879aa 1494void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
6ab409b5 1495
18cceb6a
PS
1496#define CIFS_CACHE_READ_FLG 1
1497#define CIFS_CACHE_HANDLE_FLG 2
42873b0a 1498#define CIFS_CACHE_RH_FLG (CIFS_CACHE_READ_FLG | CIFS_CACHE_HANDLE_FLG)
18cceb6a 1499#define CIFS_CACHE_WRITE_FLG 4
42873b0a
PS
1500#define CIFS_CACHE_RW_FLG (CIFS_CACHE_READ_FLG | CIFS_CACHE_WRITE_FLG)
1501#define CIFS_CACHE_RHW_FLG (CIFS_CACHE_RW_FLG | CIFS_CACHE_HANDLE_FLG)
18cceb6a 1502
874c8ca1 1503#define CIFS_CACHE_READ(cinode) ((cinode->oplock & CIFS_CACHE_READ_FLG) || (CIFS_SB(cinode->netfs.inode.i_sb)->mnt_cifs_flags & CIFS_MOUNT_RO_CACHE))
53ef1016 1504#define CIFS_CACHE_HANDLE(cinode) (cinode->oplock & CIFS_CACHE_HANDLE_FLG)
874c8ca1 1505#define CIFS_CACHE_WRITE(cinode) ((cinode->oplock & CIFS_CACHE_WRITE_FLG) || (CIFS_SB(cinode->netfs.inode.i_sb)->mnt_cifs_flags & CIFS_MOUNT_RW_CACHE))
18cceb6a 1506
1da177e4
LT
1507/*
1508 * One of these for each file inode
1509 */
1510
1511struct cifsInodeInfo {
874c8ca1 1512 struct netfs_inode netfs; /* Netfslib context and vfs inode */
d59dad2b 1513 bool can_cache_brlcks;
f45d3416 1514 struct list_head llist; /* locks helb by this inode */
d46b0da7
DW
1515 /*
1516 * NOTE: Some code paths call down_read(lock_sem) twice, so
a03f507d 1517 * we must always use cifs_down_write() instead of down_write()
d46b0da7
DW
1518 * for this semaphore to avoid deadlocks.
1519 */
1b4b55a1 1520 struct rw_semaphore lock_sem; /* protect the fields above */
d38d8c74 1521 /* BB add in lists for dirty pages i.e. write caching info for oplock */
1da177e4 1522 struct list_head openFileList;
487317c9 1523 spinlock_t open_file_lock; /* protects openFileList */
1da177e4 1524 __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
18cceb6a 1525 unsigned int oplock; /* oplock/lease level we have */
42873b0a 1526 unsigned int epoch; /* used to track lease state changes */
c11f1df5
SP
1527#define CIFS_INODE_PENDING_OPLOCK_BREAK (0) /* oplock break in progress */
1528#define CIFS_INODE_PENDING_WRITERS (1) /* Writes in progress */
9bd45408 1529#define CIFS_INODE_FLAG_UNUSED (2) /* Unused flag */
aff8d5ca
JL
1530#define CIFS_INO_DELETE_PENDING (3) /* delete pending on server */
1531#define CIFS_INO_INVALID_MAPPING (4) /* pagecache is invalid */
4f73c7d3 1532#define CIFS_INO_LOCK (5) /* lock bit for synchronization */
c3f207ab 1533#define CIFS_INO_MODIFIED_ATTR (6) /* Indicate change in mtime/ctime */
35866f3f 1534#define CIFS_INO_CLOSE_ON_LOCK (7) /* Not to defer the close when lock is set */
aff8d5ca 1535 unsigned long flags;
c11f1df5
SP
1536 spinlock_t writers_lock;
1537 unsigned int writers; /* Number of writers on this inode */
aae62fdb 1538 unsigned long time; /* jiffies of last update of inode */
597b027f 1539 u64 server_eof; /* current file size on server -- protected by i_lock */
cc0bad75 1540 u64 uniqueid; /* server inode number */
20054bd6 1541 u64 createtime; /* creation time on server */
b8c32dbb 1542 __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for this inode */
c3f207ab
RS
1543 struct list_head deferred_closes; /* list of deferred closes */
1544 spinlock_t deferred_lock; /* protection on deferred list */
0ab95c25 1545 bool lease_granted; /* Flag to indicate whether lease or oplock is granted. */
1da177e4
LT
1546};
1547
1548static inline struct cifsInodeInfo *
1549CIFS_I(struct inode *inode)
1550{
874c8ca1 1551 return container_of(inode, struct cifsInodeInfo, netfs.inode);
1da177e4
LT
1552}
1553
1554static inline struct cifs_sb_info *
1555CIFS_SB(struct super_block *sb)
1556{
1557 return sb->s_fs_info;
1558}
1559
7119e220
AV
1560static inline struct cifs_sb_info *
1561CIFS_FILE_SB(struct file *file)
1562{
1563 return CIFS_SB(file_inode(file)->i_sb);
1564}
1565
ab2f218f 1566static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
ac67055e
JA
1567{
1568 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
1569 return '/';
1570 else
1571 return '\\';
1572}
1da177e4 1573
f87d39d9
SF
1574static inline void
1575convert_delimiter(char *path, char delim)
1576{
1cc9bd68 1577 char old_delim, *pos;
f87d39d9
SF
1578
1579 if (delim == '/')
1580 old_delim = '\\';
1581 else
1582 old_delim = '/';
1583
1cc9bd68
SF
1584 pos = path;
1585 while ((pos = strchr(pos, old_delim)))
1586 *pos = delim;
f87d39d9
SF
1587}
1588
a4544347
SF
1589#define cifs_stats_inc atomic_inc
1590
96daf2b0 1591static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
a4544347
SF
1592 unsigned int bytes)
1593{
1594 if (bytes) {
1595 spin_lock(&tcon->stat_lock);
1596 tcon->bytes_written += bytes;
1597 spin_unlock(&tcon->stat_lock);
1598 }
1599}
1600
96daf2b0 1601static inline void cifs_stats_bytes_read(struct cifs_tcon *tcon,
a4544347
SF
1602 unsigned int bytes)
1603{
1604 spin_lock(&tcon->stat_lock);
1605 tcon->bytes_read += bytes;
1606 spin_unlock(&tcon->stat_lock);
1607}
a4544347 1608
2b84a36c
JL
1609
1610/*
44d22d84
JL
1611 * This is the prototype for the mid receive function. This function is for
1612 * receiving the rest of the SMB frame, starting with the WordCount (which is
1613 * just after the MID in struct smb_hdr). Note:
1614 *
1615 * - This will be called by cifsd, with no locks held.
1616 * - The mid will still be on the pending_mid_q.
1617 * - mid->resp_buf will point to the current buffer.
1618 *
1619 * Returns zero on a successful receive, or an error. The receive state in
1620 * the TCP_Server_Info will also be updated.
1621 */
1622typedef int (mid_receive_t)(struct TCP_Server_Info *server,
1623 struct mid_q_entry *mid);
1624
1625/*
1626 * This is the prototype for the mid callback function. This is called once the
1627 * mid has been received off of the socket. When creating one, take special
1628 * care to avoid deadlocks. Things to bear in mind:
2b84a36c 1629 *
3c1105df
JL
1630 * - it will be called by cifsd, with no locks held
1631 * - the mid will be removed from any lists
2b84a36c
JL
1632 */
1633typedef void (mid_callback_t)(struct mid_q_entry *mid);
1634
9b7c18a2
PS
1635/*
1636 * This is the protopyte for mid handle function. This is called once the mid
1637 * has been recognized after decryption of the message.
1638 */
1639typedef int (mid_handle_t)(struct TCP_Server_Info *server,
1640 struct mid_q_entry *mid);
1641
1da177e4
LT
1642/* one of these for every pending CIFS request to the server */
1643struct mid_q_entry {
1644 struct list_head qhead; /* mids waiting on reply from this server */
696e420b 1645 struct kref refcount;
2dc7e1c0 1646 struct TCP_Server_Info *server; /* server corresponding to this mid */
7c9421e1 1647 __u64 mid; /* multiplex id */
c781af7e 1648 __u16 credits; /* number of credits consumed by this mid */
86a7964b 1649 __u16 credits_received; /* number of credits from the response */
7c9421e1 1650 __u32 pid; /* process id */
1da177e4 1651 __u32 sequence_number; /* for CIFS signing */
1047abc1
SF
1652 unsigned long when_alloc; /* when mid was created */
1653#ifdef CONFIG_CIFS_STATS2
1654 unsigned long when_sent; /* time when smb send finished */
1655 unsigned long when_received; /* when demux complete (taken off wire) */
1656#endif
44d22d84 1657 mid_receive_t *receive; /* call receive callback */
2b84a36c 1658 mid_callback_t *callback; /* call completion callback */
9b7c18a2 1659 mid_handle_t *handle; /* call handle mid callback */
2b84a36c 1660 void *callback_data; /* general purpose pointer for callback */
f1f27ad7 1661 struct task_struct *creator;
d4e4854f 1662 void *resp_buf; /* pointer to received SMB header */
e19b2bc0 1663 unsigned int resp_buf_size;
7c9421e1 1664 int mid_state; /* wish this were enum but can not pass to wait_event */
38bd4906 1665 unsigned int mid_flags;
7c9421e1 1666 __le16 command; /* smb command code */
8a26f0f7 1667 unsigned int optype; /* operation type */
7c9421e1 1668 bool large_buf:1; /* if valid response, is pointer to large buf */
4b18f2a9
SF
1669 bool multiRsp:1; /* multiple trans2 responses for one request */
1670 bool multiEnd:1; /* both received */
4326ed2f 1671 bool decrypted:1; /* decrypted entry */
1da177e4
LT
1672};
1673
38bd4906
SP
1674struct close_cancelled_open {
1675 struct cifs_fid fid;
1676 struct cifs_tcon *tcon;
1677 struct work_struct work;
87bc2376
RS
1678 __u64 mid;
1679 __u16 cmd;
38bd4906
SP
1680};
1681
789e6661
SF
1682/* Make code in transport.c a little cleaner by moving
1683 update of optional stats into function below */
789e6661
SF
1684static inline void cifs_in_send_inc(struct TCP_Server_Info *server)
1685{
1686 atomic_inc(&server->in_send);
1687}
1688
1689static inline void cifs_in_send_dec(struct TCP_Server_Info *server)
1690{
1691 atomic_dec(&server->in_send);
1692}
1693
1694static inline void cifs_num_waiters_inc(struct TCP_Server_Info *server)
1695{
1696 atomic_inc(&server->num_waiters);
1697}
1698
1699static inline void cifs_num_waiters_dec(struct TCP_Server_Info *server)
1700{
1701 atomic_dec(&server->num_waiters);
1702}
1703
1ae9a5a5 1704#ifdef CONFIG_CIFS_STATS2
789e6661
SF
1705static inline void cifs_save_when_sent(struct mid_q_entry *mid)
1706{
1707 mid->when_sent = jiffies;
1708}
1709#else
789e6661
SF
1710static inline void cifs_save_when_sent(struct mid_q_entry *mid)
1711{
1712}
1713#endif
1da177e4 1714
ff5dbd9e
SF
1715/* for pending dnotify requests */
1716struct dir_notify_req {
13cd4b7f
SF
1717 struct list_head lhead;
1718 __le16 Pid;
1719 __le16 PidHigh;
1720 __u16 Mid;
1721 __u16 Tid;
1722 __u16 Uid;
1723 __u16 netfid;
1724 __u32 filter; /* CompletionFilter (for multishot) */
1725 int multishot;
1726 struct file *pfile;
ff5dbd9e
SF
1727};
1728
366781c1
SF
1729struct dfs_info3_param {
1730 int flags; /* DFSREF_REFERRAL_SERVER, DFSREF_STORAGE_SERVER*/
8aad018b 1731 int path_consumed;
366781c1
SF
1732 int server_type;
1733 int ref_flag;
1734 char *path_name;
1735 char *node_name;
e7b602f4 1736 int ttl;
366781c1
SF
1737};
1738
9e992755
RS
1739struct file_list {
1740 struct list_head list;
1741 struct cifsFileInfo *cfile;
1742};
1743
366781c1
SF
1744static inline void free_dfs_info_param(struct dfs_info3_param *param)
1745{
1746 if (param) {
1747 kfree(param->path_name);
1748 kfree(param->node_name);
366781c1
SF
1749 }
1750}
1751
1752static inline void free_dfs_info_array(struct dfs_info3_param *param,
1753 int number_of_items)
1754{
1755 int i;
1756 if ((number_of_items == 0) || (param == NULL))
1757 return;
1758 for (i = 0; i < number_of_items; i++) {
1759 kfree(param[i].path_name);
1760 kfree(param[i].node_name);
1761 }
1762 kfree(param);
1763}
1764
9a66396f
PS
1765static inline bool is_interrupt_error(int error)
1766{
1767 switch (error) {
1768 case -EINTR:
1769 case -ERESTARTSYS:
1770 case -ERESTARTNOHAND:
1771 case -ERESTARTNOINTR:
1772 return true;
1773 }
1774 return false;
1775}
1776
1777static inline bool is_retryable_error(int error)
1778{
1779 if (is_interrupt_error(error) || error == -EAGAIN)
1780 return true;
1781 return false;
1782}
1783
86f740f2
AA
1784
1785/* cifs_get_writable_file() flags */
1786#define FIND_WR_ANY 0
1787#define FIND_WR_FSUID_ONLY 1
1788#define FIND_WR_WITH_DELETE 2
1789
1da177e4
LT
1790#define MID_FREE 0
1791#define MID_REQUEST_ALLOCATED 1
1792#define MID_REQUEST_SUBMITTED 2
1793#define MID_RESPONSE_RECEIVED 4
1794#define MID_RETRY_NEEDED 8 /* session closed while this request out */
71823baf 1795#define MID_RESPONSE_MALFORMED 0x10
3c1105df 1796#define MID_SHUTDOWN 0x20
ec637e3f 1797
38bd4906
SP
1798/* Flags */
1799#define MID_WAIT_CANCELLED 1 /* Cancelled while waiting for response */
ddf83afb 1800#define MID_DELETED 2 /* Mid has been dequeued/deleted */
38bd4906 1801
ec637e3f
SF
1802/* Types of response buffer returned from SendReceive2 */
1803#define CIFS_NO_BUFFER 0 /* Response buffer not returned */
1804#define CIFS_SMALL_BUFFER 1
1805#define CIFS_LARGE_BUFFER 2
1806#define CIFS_IOVEC 4 /* array of response buffers */
1da177e4 1807
133672ef 1808/* Type of Request to SendReceive2 */
7749981e 1809#define CIFS_BLOCKING_OP 1 /* operation can block */
392e1c5d 1810#define CIFS_NON_BLOCKING 2 /* do not block waiting for credits */
7749981e 1811#define CIFS_TIMEOUT_MASK 0x003 /* only one of above set in req */
133672ef
SF
1812#define CIFS_LOG_ERROR 0x010 /* log NT STATUS if non-zero */
1813#define CIFS_LARGE_BUF_OP 0x020 /* large request buffer */
392e1c5d 1814#define CIFS_NO_RSP_BUF 0x040 /* no response buffer required */
133672ef 1815
a891f0f8 1816/* Type of request operation */
04ad69c3
PA
1817#define CIFS_ECHO_OP 0x080 /* echo request */
1818#define CIFS_OBREAK_OP 0x0100 /* oplock break request */
1819#define CIFS_NEG_OP 0x0200 /* negotiate request */
1820#define CIFS_CP_CREATE_CLOSE_OP 0x0400 /* compound create+close request */
0f56db83 1821/* Lower bitmask values are reserved by others below. */
04ad69c3
PA
1822#define CIFS_SESS_OP 0x2000 /* session setup request */
1823#define CIFS_OP_MASK 0x2780 /* mask request type */
7fb8986e 1824
04ad69c3
PA
1825#define CIFS_HAS_CREDITS 0x0400 /* already has credits */
1826#define CIFS_TRANSFORM_REQ 0x0800 /* transform request before sending */
1827#define CIFS_NO_SRV_RSP 0x1000 /* there is no server response */
a891f0f8 1828
3979877e
SF
1829/* Security Flags: indicate type of session setup needed */
1830#define CIFSSEC_MAY_SIGN 0x00001
3979877e
SF
1831#define CIFSSEC_MAY_NTLMV2 0x00004
1832#define CIFSSEC_MAY_KRB5 0x00008
3979877e 1833#define CIFSSEC_MAY_SEAL 0x00040 /* not supported yet */
ac683924 1834#define CIFSSEC_MAY_NTLMSSP 0x00080 /* raw ntlmssp with ntlmv2 */
3979877e
SF
1835
1836#define CIFSSEC_MUST_SIGN 0x01001
1837/* note that only one of the following can be set so the
1838result of setting MUST flags more than once will be to
1839require use of the stronger protocol */
3979877e
SF
1840#define CIFSSEC_MUST_NTLMV2 0x04004
1841#define CIFSSEC_MUST_KRB5 0x08008
0d3a01fa 1842#ifdef CONFIG_CIFS_UPCALL
ac683924 1843#define CIFSSEC_MASK 0x8F08F /* flags supported if no weak allowed */
d38d8c74 1844#else
ac683924 1845#define CIFSSEC_MASK 0x87087 /* flags supported if no weak allowed */
016ec75f 1846#endif /* UPCALL */
3979877e 1847#define CIFSSEC_MUST_SEAL 0x40040 /* not supported yet */
ac683924 1848#define CIFSSEC_MUST_NTLMSSP 0x80080 /* raw ntlmssp with ntlmv2 */
3979877e 1849
896a8fc2 1850#define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_NTLMSSP)
76a3c92e
RS
1851#define CIFSSEC_MAX (CIFSSEC_MUST_NTLMV2)
1852#define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)
1da177e4
LT
1853/*
1854 *****************************************************************
1855 * All constants go here
1856 *****************************************************************
1857 */
1858
1859#define UID_HASH (16)
1860
1861/*
1862 * Note that ONE module should define _DECLARE_GLOBALS_HERE to cause the
1863 * following to be declared.
1864 */
1865
1866/****************************************************************************
d7d7a66a
SP
1867 * Here are all the locks (spinlock, mutex, semaphore) in cifs.ko, arranged according
1868 * to the locking order. i.e. if two locks are to be held together, the lock that
1869 * appears higher in this list needs to be taken before the other.
1da177e4 1870 *
d7d7a66a
SP
1871 * If you hold a lock that is lower in this list, and you need to take a higher lock
1872 * (or if you think that one of the functions that you're calling may need to), first
1873 * drop the lock you hold, pick up the higher lock, then the lower one. This will
1874 * ensure that locks are picked up only in one direction in the below table
1875 * (top to bottom).
1da177e4 1876 *
d7d7a66a
SP
1877 * Also, if you expect a function to be called with a lock held, explicitly document
1878 * this in the comments on top of your function definition.
487317c9 1879 *
d7d7a66a
SP
1880 * And also, try to keep the critical sections (lock hold time) to be as minimal as
1881 * possible. Blocking / calling other functions with a lock held always increase
1882 * the risk of a possible deadlock.
1da177e4 1883 *
d7d7a66a
SP
1884 * Following this rule will avoid unnecessary deadlocks, which can get really hard to
1885 * debug. Also, any new lock that you introduce, please add to this list in the correct
1886 * order.
1887 *
1888 * Please populate this list whenever you introduce new locks in your changes. Or in
1889 * case I've missed some existing locks. Please ensure that it's added in the list
1890 * based on the locking order expected.
1891 *
1892 * =====================================================================================
1893 * Lock Protects Initialization fn
1894 * =====================================================================================
1895 * vol_list_lock
1896 * vol_info->ctx_lock vol_info->ctx
1897 * cifs_sb_info->tlink_tree_lock cifs_sb_info->tlink_tree cifs_setup_cifs_sb
1898 * TCP_Server_Info-> TCP_Server_Info cifs_get_tcp_session
1899 * reconnect_mutex
1900 * TCP_Server_Info->srv_mutex TCP_Server_Info cifs_get_tcp_session
1901 * cifs_ses->session_mutex cifs_ses sesInfoAlloc
1902 * cifs_tcon
1903 * cifs_tcon->open_file_lock cifs_tcon->openFileList tconInfoAlloc
1904 * cifs_tcon->pending_opens
1905 * cifs_tcon->stat_lock cifs_tcon->bytes_read tconInfoAlloc
1906 * cifs_tcon->bytes_written
1907 * cifs_tcp_ses_lock cifs_tcp_ses_list sesInfoAlloc
1908 * GlobalMid_Lock GlobalMaxActiveXid init_cifs
1909 * GlobalCurrentXid
1910 * GlobalTotalActiveXid
1911 * TCP_Server_Info->srv_lock (anything in struct not protected by another lock and can change)
1912 * TCP_Server_Info->mid_lock TCP_Server_Info->pending_mid_q cifs_get_tcp_session
1913 * ->CurrentMid
1914 * (any changes in mid_q_entry fields)
1915 * TCP_Server_Info->req_lock TCP_Server_Info->in_flight cifs_get_tcp_session
1916 * ->credits
1917 * ->echo_credits
1918 * ->oplock_credits
1919 * ->reconnect_instance
1920 * cifs_ses->ses_lock (anything that is not protected by another lock and can change)
1921 * cifs_ses->iface_lock cifs_ses->iface_list sesInfoAlloc
1922 * ->iface_count
1923 * ->iface_last_update
1924 * cifs_ses->chan_lock cifs_ses->chans
1925 * ->chans_need_reconnect
1926 * ->chans_in_reconnect
1927 * cifs_tcon->tc_lock (anything that is not protected by another lock and can change)
1928 * cifsInodeInfo->open_file_lock cifsInodeInfo->openFileList cifs_alloc_inode
1929 * cifsInodeInfo->writers_lock cifsInodeInfo->writers cifsInodeInfo_alloc
1930 * cifsInodeInfo->lock_sem cifsInodeInfo->llist cifs_init_once
1931 * ->can_cache_brlcks
1932 * cifsInodeInfo->deferred_lock cifsInodeInfo->deferred_closes cifsInodeInfo_alloc
1933 * cached_fid->fid_mutex cifs_tcon->crfid tconInfoAlloc
1934 * cifsFileInfo->fh_mutex cifsFileInfo cifs_new_fileinfo
1935 * cifsFileInfo->file_info_lock cifsFileInfo->count cifs_new_fileinfo
1936 * ->invalidHandle initiate_cifs_search
1937 * ->oplock_break_cancelled
1938 * cifs_aio_ctx->aio_mutex cifs_aio_ctx cifs_aio_ctx_alloc
1da177e4
LT
1939 ****************************************************************************/
1940
1941#ifdef DECLARE_GLOBALS_HERE
1942#define GLOBAL_EXTERN
1943#else
1944#define GLOBAL_EXTERN extern
1945#endif
1946
e7ddee90
JL
1947/*
1948 * the list of TCP_Server_Info structures, ie each of the sockets
fb396016 1949 * connecting our client to a distinct server (ip address), is
e7ddee90 1950 * chained together by cifs_tcp_ses_list. The list of all our SMB
fb396016 1951 * sessions (and from that the tree connections) can be found
e7ddee90
JL
1952 * by iterating over cifs_tcp_ses_list
1953 */
89e42f49 1954extern struct list_head cifs_tcp_ses_list;
e7ddee90 1955
f1987b44
JL
1956/*
1957 * This lock protects the cifs_tcp_ses_list, the list of smb sessions per
1958 * tcp session, and the list of tcon's per smb session. It also protects
d7d7a66a 1959 * the reference counters for the server, smb session, and tcon.
3afca265
SF
1960 * generally the locks should be taken in order tcp_ses_lock before
1961 * tcon->open_file_lock and that before file->file_info_lock since the
1962 * structure order is cifs_socket-->cifs_ses-->cifs_tcon-->cifs_file
f1987b44 1963 */
89e42f49 1964extern spinlock_t cifs_tcp_ses_lock;
ddb4cbfc 1965
1da177e4
LT
1966/*
1967 * Global transaction id (XID) information
1968 */
1bfa25ee
SF
1969extern unsigned int GlobalCurrentXid; /* protected by GlobalMid_Sem */
1970extern unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
1971extern unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */
1972extern spinlock_t GlobalMid_Lock; /* protects above & list operations on midQ entries */
1973
1da177e4
LT
1974/*
1975 * Global counters, updated atomically
1976 */
1bfa25ee
SF
1977extern atomic_t sesInfoAllocCount;
1978extern atomic_t tconInfoAllocCount;
1979extern atomic_t tcpSesNextId;
1980extern atomic_t tcpSesAllocCount;
1981extern atomic_t tcpSesReconnectCount;
1982extern atomic_t tconInfoReconnectCount;
1da177e4 1983
aaa9bbe0 1984/* Various Debug counters */
c2c17ddb
SF
1985extern atomic_t buf_alloc_count; /* current number allocated */
1986extern atomic_t small_buf_alloc_count;
4498eed5 1987#ifdef CONFIG_CIFS_STATS2
c2c17ddb
SF
1988extern atomic_t total_buf_alloc_count; /* total allocated over all time */
1989extern atomic_t total_small_buf_alloc_count;
00778e22 1990extern unsigned int slow_rsp_threshold; /* number of secs before logging */
4498eed5 1991#endif
1da177e4
LT
1992
1993/* Misc globals */
f92a720e
SF
1994extern bool enable_oplocks; /* enable or disable oplocks */
1995extern bool lookupCacheEnabled;
1996extern unsigned int global_secflags; /* if on, session setup sent
1da177e4 1997 with more secure ntlmssp2 challenge/resp */
f92a720e 1998extern unsigned int sign_CIFS_PDUs; /* enable smb packet signing */
29e27923 1999extern bool enable_gcm_256; /* allow optional negotiate of strongest signing (aes-gcm-256) */
fbfd0b46 2000extern bool require_gcm_256; /* require use of strongest signing (aes-gcm-256) */
53d31a3f 2001extern bool enable_negotiate_signing; /* request use of faster (GMAC) signing if available */
f92a720e
SF
2002extern bool linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
2003extern unsigned int CIFSMaxBufSize; /* max size not including hdr */
2004extern unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
2005extern unsigned int cifs_min_small; /* min size of small buf pool */
2006extern unsigned int cifs_max_pending; /* MAX requests at once to server*/
2007extern bool disable_legacy_dialects; /* forbid vers=1.0 and vers=2.0 mounts */
c2c17ddb 2008extern atomic_t mid_count;
1da177e4 2009
9b646972 2010void cifs_oplock_break(struct work_struct *work);
b98749ca 2011void cifs_queue_oplock_break(struct cifsFileInfo *cfile);
c3f207ab 2012void smb2_deferred_work_close(struct work_struct *work);
3b7433b8 2013
c3f207ab 2014extern const struct slow_work_ops cifs_oplock_break_ops;
da472fc8 2015extern struct workqueue_struct *cifsiod_wq;
35cf94a3 2016extern struct workqueue_struct *decrypt_wq;
32546a95 2017extern struct workqueue_struct *fileinfo_put_wq;
3998e6b8 2018extern struct workqueue_struct *cifsoplockd_wq;
c3f207ab 2019extern struct workqueue_struct *deferredclose_wq;
3d22462a 2020extern __u32 cifs_lock_secret;
abd2e44d 2021
2dc7e1c0
PS
2022extern mempool_t *cifs_mid_poolp;
2023
23db65f5
JL
2024/* Operations for different SMB versions */
2025#define SMB1_VERSION_STRING "1.0"
7ef93ffc
SF
2026#define SMB20_VERSION_STRING "2.0"
2027#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
23db65f5
JL
2028extern struct smb_version_operations smb1_operations;
2029extern struct smb_version_values smb1_values;
53ef1016 2030extern struct smb_version_operations smb20_operations;
e4aa25e7 2031extern struct smb_version_values smb20_values;
7ef93ffc 2032#endif /* CIFS_ALLOW_INSECURE_LEGACY */
1080ef75
SF
2033#define SMB21_VERSION_STRING "2.1"
2034extern struct smb_version_operations smb21_operations;
2035extern struct smb_version_values smb21_values;
9764c02f
SF
2036#define SMBDEFAULT_VERSION_STRING "default"
2037extern struct smb_version_values smbdefault_values;
2038#define SMB3ANY_VERSION_STRING "3"
2039extern struct smb_version_values smb3any_values;
e4aa25e7 2040#define SMB30_VERSION_STRING "3.0"
38107d45 2041extern struct smb_version_operations smb30_operations;
e4aa25e7 2042extern struct smb_version_values smb30_values;
20b6d8b4 2043#define SMB302_VERSION_STRING "3.02"
4a3b38ae 2044#define ALT_SMB302_VERSION_STRING "3.0.2"
20b6d8b4
SF
2045/*extern struct smb_version_operations smb302_operations;*/ /* not needed yet */
2046extern struct smb_version_values smb302_values;
5f7fbf73 2047#define SMB311_VERSION_STRING "3.1.1"
aab1893d
SF
2048#define ALT_SMB311_VERSION_STRING "3.11"
2049extern struct smb_version_operations smb311_operations;
5f7fbf73 2050extern struct smb_version_values smb311_values;
b8f7442b 2051
0b0430c6
K
2052static inline char *get_security_type_str(enum securityEnum sectype)
2053{
2054 switch (sectype) {
2055 case RawNTLMSSP:
2056 return "RawNTLMSSP";
2057 case Kerberos:
2058 return "Kerberos";
2059 case NTLMv2:
2060 return "NTLMv2";
0b0430c6
K
2061 default:
2062 return "Unknown";
2063 }
2064}
2065
b8f7442b
AA
2066static inline bool is_smb1_server(struct TCP_Server_Info *server)
2067{
2068 return strcmp(server->vals->version_string, SMB1_VERSION_STRING) == 0;
2069}
2070
e183785f
PA
2071static inline bool is_tcon_dfs(struct cifs_tcon *tcon)
2072{
2073 /*
2074 * For SMB1, see MS-CIFS 2.4.55 SMB_COM_TREE_CONNECT_ANDX (0x75) and MS-CIFS 3.3.4.4 DFS
2075 * Subsystem Notifies That a Share Is a DFS Share.
2076 *
2077 * For SMB2+, see MS-SMB2 2.2.10 SMB2 TREE_CONNECT Response and MS-SMB2 3.3.4.14 Server
2078 * Application Updates a Share.
2079 */
2080 if (!tcon || !tcon->ses || !tcon->ses->server)
2081 return false;
2082 return is_smb1_server(tcon->ses->server) ? tcon->Flags & SMB_SHARE_IS_IN_DFS :
2083 tcon->share_flags & (SHI1005_FLAGS_DFS | SHI1005_FLAGS_DFS_ROOT);
2084}
2085
c88f7dcd
PA
2086static inline bool cifs_is_referral_server(struct cifs_tcon *tcon,
2087 const struct dfs_info3_param *ref)
2088{
2089 /*
2090 * Check if all targets are capable of handling DFS referrals as per
2091 * MS-DFSC 2.2.4 RESP_GET_DFS_REFERRAL.
2092 */
2093 return is_tcon_dfs(tcon) || (ref && (ref->flags & DFSREF_REFERRAL_SERVER));
2094}
2095
773891ff 2096static inline u64 cifs_flock_len(const struct file_lock *fl)
d80c6984 2097{
773891ff 2098 return (u64)fl->fl_end - fl->fl_start + 1;
d80c6984
PA
2099}
2100
de3a9e94
PA
2101static inline size_t ntlmssp_workstation_name_size(const struct cifs_ses *ses)
2102{
2103 if (WARN_ON_ONCE(!ses || !ses->server))
2104 return 0;
2105 /*
2106 * Make workstation name no more than 15 chars when using insecure dialects as some legacy
2107 * servers do require it during NTLMSSP.
2108 */
2109 if (ses->server->dialect <= SMB20_PROT_ID)
2110 return min_t(size_t, sizeof(ses->workstation_name), RFC1001_NAME_LEN_WITH_NULL);
2111 return sizeof(ses->workstation_name);
2112}
2113
abd2e44d 2114#endif /* _CIFS_GLOB_H */