xref: /OK3568_Linux_fs/kernel/fs/cifs/cifsglob.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *   fs/cifs/cifsglob.h
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *   Copyright (C) International Business Machines  Corp., 2002,2008
5*4882a593Smuzhiyun  *   Author(s): Steve French (sfrench@us.ibm.com)
6*4882a593Smuzhiyun  *              Jeremy Allison (jra@samba.org)
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *   This library is free software; you can redistribute it and/or modify
9*4882a593Smuzhiyun  *   it under the terms of the GNU Lesser General Public License as published
10*4882a593Smuzhiyun  *   by the Free Software Foundation; either version 2.1 of the License, or
11*4882a593Smuzhiyun  *   (at your option) any later version.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  *   This library is distributed in the hope that it will be useful,
14*4882a593Smuzhiyun  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15*4882a593Smuzhiyun  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
16*4882a593Smuzhiyun  *   the GNU Lesser General Public License for more details.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun #ifndef _CIFS_GLOB_H
20*4882a593Smuzhiyun #define _CIFS_GLOB_H
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #include <linux/in.h>
23*4882a593Smuzhiyun #include <linux/in6.h>
24*4882a593Smuzhiyun #include <linux/slab.h>
25*4882a593Smuzhiyun #include <linux/mempool.h>
26*4882a593Smuzhiyun #include <linux/workqueue.h>
27*4882a593Smuzhiyun #include "cifs_fs_sb.h"
28*4882a593Smuzhiyun #include "cifsacl.h"
29*4882a593Smuzhiyun #include <crypto/internal/hash.h>
30*4882a593Smuzhiyun #include <linux/scatterlist.h>
31*4882a593Smuzhiyun #include <uapi/linux/cifs/cifs_mount.h>
32*4882a593Smuzhiyun #include "smb2pdu.h"
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #define CIFS_MAGIC_NUMBER 0xFF534D42      /* the first four bytes of SMB PDUs */
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #define SMB_PATH_MAX 260
37*4882a593Smuzhiyun #define CIFS_PORT 445
38*4882a593Smuzhiyun #define RFC1001_PORT 139
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /*
41*4882a593Smuzhiyun  * The sizes of various internal tables and strings
42*4882a593Smuzhiyun  */
43*4882a593Smuzhiyun #define MAX_UID_INFO 16
44*4882a593Smuzhiyun #define MAX_SES_INFO 2
45*4882a593Smuzhiyun #define MAX_TCON_INFO 4
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun #define MAX_TREE_SIZE (2 + CIFS_NI_MAXHOST + 1 + CIFS_MAX_SHARE_LEN + 1)
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun #define CIFS_MIN_RCV_POOL 4
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun #define MAX_REOPEN_ATT	5 /* these many maximum attempts to reopen a file */
52*4882a593Smuzhiyun /*
53*4882a593Smuzhiyun  * default attribute cache timeout (jiffies)
54*4882a593Smuzhiyun  */
55*4882a593Smuzhiyun #define CIFS_DEF_ACTIMEO (1 * HZ)
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /*
58*4882a593Smuzhiyun  * max attribute cache timeout (jiffies) - 2^30
59*4882a593Smuzhiyun  */
60*4882a593Smuzhiyun #define CIFS_MAX_ACTIMEO (1 << 30)
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun /*
63*4882a593Smuzhiyun  * Max persistent and resilient handle timeout (milliseconds).
64*4882a593Smuzhiyun  * Windows durable max was 960000 (16 minutes)
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun #define SMB3_MAX_HANDLE_TIMEOUT 960000
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun /*
69*4882a593Smuzhiyun  * MAX_REQ is the maximum number of requests that WE will send
70*4882a593Smuzhiyun  * on one socket concurrently.
71*4882a593Smuzhiyun  */
72*4882a593Smuzhiyun #define CIFS_MAX_REQ 32767
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun #define RFC1001_NAME_LEN 15
75*4882a593Smuzhiyun #define RFC1001_NAME_LEN_WITH_NULL (RFC1001_NAME_LEN + 1)
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /* maximum length of ip addr as a string (including ipv6 and sctp) */
78*4882a593Smuzhiyun #define SERVER_NAME_LENGTH 80
79*4882a593Smuzhiyun #define SERVER_NAME_LEN_WITH_NULL     (SERVER_NAME_LENGTH + 1)
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun /* echo interval in seconds */
82*4882a593Smuzhiyun #define SMB_ECHO_INTERVAL_MIN 1
83*4882a593Smuzhiyun #define SMB_ECHO_INTERVAL_MAX 600
84*4882a593Smuzhiyun #define SMB_ECHO_INTERVAL_DEFAULT 60
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /* maximum number of PDUs in one compound */
87*4882a593Smuzhiyun #define MAX_COMPOUND 5
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun /*
90*4882a593Smuzhiyun  * Default number of credits to keep available for SMB3.
91*4882a593Smuzhiyun  * This value is chosen somewhat arbitrarily. The Windows client
92*4882a593Smuzhiyun  * defaults to 128 credits, the Windows server allows clients up to
93*4882a593Smuzhiyun  * 512 credits (or 8K for later versions), and the NetApp server
94*4882a593Smuzhiyun  * does not limit clients at all.  Choose a high enough default value
95*4882a593Smuzhiyun  * such that the client shouldn't limit performance, but allow mount
96*4882a593Smuzhiyun  * to override (until you approach 64K, where we limit credits to 65000
97*4882a593Smuzhiyun  * to reduce possibility of seeing more server credit overflow bugs.
98*4882a593Smuzhiyun  */
99*4882a593Smuzhiyun #define SMB2_MAX_CREDITS_AVAILABLE 32000
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun #include "cifspdu.h"
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun #ifndef XATTR_DOS_ATTRIB
104*4882a593Smuzhiyun #define XATTR_DOS_ATTRIB "user.DOSATTRIB"
105*4882a593Smuzhiyun #endif
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun /*
108*4882a593Smuzhiyun  * CIFS vfs client Status information (based on what we know.)
109*4882a593Smuzhiyun  */
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /* associated with each tcp and smb session */
112*4882a593Smuzhiyun enum statusEnum {
113*4882a593Smuzhiyun 	CifsNew = 0,
114*4882a593Smuzhiyun 	CifsGood,
115*4882a593Smuzhiyun 	CifsExiting,
116*4882a593Smuzhiyun 	CifsNeedReconnect,
117*4882a593Smuzhiyun 	CifsNeedNegotiate
118*4882a593Smuzhiyun };
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun enum securityEnum {
121*4882a593Smuzhiyun 	Unspecified = 0,	/* not specified */
122*4882a593Smuzhiyun 	LANMAN,			/* Legacy LANMAN auth */
123*4882a593Smuzhiyun 	NTLM,			/* Legacy NTLM012 auth with NTLM hash */
124*4882a593Smuzhiyun 	NTLMv2,			/* Legacy NTLM auth with NTLMv2 hash */
125*4882a593Smuzhiyun 	RawNTLMSSP,		/* NTLMSSP without SPNEGO, NTLMv2 hash */
126*4882a593Smuzhiyun 	Kerberos,		/* Kerberos via SPNEGO */
127*4882a593Smuzhiyun };
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun struct session_key {
130*4882a593Smuzhiyun 	unsigned int len;
131*4882a593Smuzhiyun 	char *response;
132*4882a593Smuzhiyun };
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun /* crypto security descriptor definition */
135*4882a593Smuzhiyun struct sdesc {
136*4882a593Smuzhiyun 	struct shash_desc shash;
137*4882a593Smuzhiyun 	char ctx[];
138*4882a593Smuzhiyun };
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun /* crypto hashing related structure/fields, not specific to a sec mech */
141*4882a593Smuzhiyun struct cifs_secmech {
142*4882a593Smuzhiyun 	struct crypto_shash *hmacmd5; /* hmac-md5 hash function */
143*4882a593Smuzhiyun 	struct crypto_shash *md5; /* md5 hash function */
144*4882a593Smuzhiyun 	struct crypto_shash *hmacsha256; /* hmac-sha256 hash function */
145*4882a593Smuzhiyun 	struct crypto_shash *cmacaes; /* block-cipher based MAC function */
146*4882a593Smuzhiyun 	struct crypto_shash *sha512; /* sha512 hash function */
147*4882a593Smuzhiyun 	struct sdesc *sdeschmacmd5;  /* ctxt to generate ntlmv2 hash, CR1 */
148*4882a593Smuzhiyun 	struct sdesc *sdescmd5; /* ctxt to generate cifs/smb signature */
149*4882a593Smuzhiyun 	struct sdesc *sdeschmacsha256;  /* ctxt to generate smb2 signature */
150*4882a593Smuzhiyun 	struct sdesc *sdesccmacaes;  /* ctxt to generate smb3 signature */
151*4882a593Smuzhiyun 	struct sdesc *sdescsha512; /* ctxt to generate smb3.11 signing key */
152*4882a593Smuzhiyun 	struct crypto_aead *ccmaesencrypt; /* smb3 encryption aead */
153*4882a593Smuzhiyun 	struct crypto_aead *ccmaesdecrypt; /* smb3 decryption aead */
154*4882a593Smuzhiyun };
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun /* per smb session structure/fields */
157*4882a593Smuzhiyun struct ntlmssp_auth {
158*4882a593Smuzhiyun 	bool sesskey_per_smbsess; /* whether session key is per smb session */
159*4882a593Smuzhiyun 	__u32 client_flags; /* sent by client in type 1 ntlmsssp exchange */
160*4882a593Smuzhiyun 	__u32 server_flags; /* sent by server in type 2 ntlmssp exchange */
161*4882a593Smuzhiyun 	unsigned char ciphertext[CIFS_CPHTXT_SIZE]; /* sent to server */
162*4882a593Smuzhiyun 	char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlmssp */
163*4882a593Smuzhiyun };
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun struct cifs_cred {
166*4882a593Smuzhiyun 	int uid;
167*4882a593Smuzhiyun 	int gid;
168*4882a593Smuzhiyun 	int mode;
169*4882a593Smuzhiyun 	int cecount;
170*4882a593Smuzhiyun 	struct cifs_sid osid;
171*4882a593Smuzhiyun 	struct cifs_sid gsid;
172*4882a593Smuzhiyun 	struct cifs_ntace *ntaces;
173*4882a593Smuzhiyun 	struct cifs_ace *aces;
174*4882a593Smuzhiyun };
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun /*
177*4882a593Smuzhiyun  *****************************************************************
178*4882a593Smuzhiyun  * Except the CIFS PDUs themselves all the
179*4882a593Smuzhiyun  * globally interesting structs should go here
180*4882a593Smuzhiyun  *****************************************************************
181*4882a593Smuzhiyun  */
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun /*
184*4882a593Smuzhiyun  * A smb_rqst represents a complete request to be issued to a server. It's
185*4882a593Smuzhiyun  * formed by a kvec array, followed by an array of pages. Page data is assumed
186*4882a593Smuzhiyun  * to start at the beginning of the first page.
187*4882a593Smuzhiyun  */
188*4882a593Smuzhiyun struct smb_rqst {
189*4882a593Smuzhiyun 	struct kvec	*rq_iov;	/* array of kvecs */
190*4882a593Smuzhiyun 	unsigned int	rq_nvec;	/* number of kvecs in array */
191*4882a593Smuzhiyun 	struct page	**rq_pages;	/* pointer to array of page ptrs */
192*4882a593Smuzhiyun 	unsigned int	rq_offset;	/* the offset to the 1st page */
193*4882a593Smuzhiyun 	unsigned int	rq_npages;	/* number pages in array */
194*4882a593Smuzhiyun 	unsigned int	rq_pagesz;	/* page size to use */
195*4882a593Smuzhiyun 	unsigned int	rq_tailsz;	/* length of last page */
196*4882a593Smuzhiyun };
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun struct mid_q_entry;
199*4882a593Smuzhiyun struct TCP_Server_Info;
200*4882a593Smuzhiyun struct cifsFileInfo;
201*4882a593Smuzhiyun struct cifs_ses;
202*4882a593Smuzhiyun struct cifs_tcon;
203*4882a593Smuzhiyun struct dfs_info3_param;
204*4882a593Smuzhiyun struct cifs_fattr;
205*4882a593Smuzhiyun struct smb_vol;
206*4882a593Smuzhiyun struct cifs_fid;
207*4882a593Smuzhiyun struct cifs_readdata;
208*4882a593Smuzhiyun struct cifs_writedata;
209*4882a593Smuzhiyun struct cifs_io_parms;
210*4882a593Smuzhiyun struct cifs_search_info;
211*4882a593Smuzhiyun struct cifsInodeInfo;
212*4882a593Smuzhiyun struct cifs_open_parms;
213*4882a593Smuzhiyun struct cifs_credits;
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun struct smb_version_operations {
216*4882a593Smuzhiyun 	int (*send_cancel)(struct TCP_Server_Info *, struct smb_rqst *,
217*4882a593Smuzhiyun 			   struct mid_q_entry *);
218*4882a593Smuzhiyun 	bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *);
219*4882a593Smuzhiyun 	/* setup request: allocate mid, sign message */
220*4882a593Smuzhiyun 	struct mid_q_entry *(*setup_request)(struct cifs_ses *,
221*4882a593Smuzhiyun 					     struct TCP_Server_Info *,
222*4882a593Smuzhiyun 					     struct smb_rqst *);
223*4882a593Smuzhiyun 	/* setup async request: allocate mid, sign message */
224*4882a593Smuzhiyun 	struct mid_q_entry *(*setup_async_request)(struct TCP_Server_Info *,
225*4882a593Smuzhiyun 						struct smb_rqst *);
226*4882a593Smuzhiyun 	/* check response: verify signature, map error */
227*4882a593Smuzhiyun 	int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *,
228*4882a593Smuzhiyun 			     bool);
229*4882a593Smuzhiyun 	void (*add_credits)(struct TCP_Server_Info *server,
230*4882a593Smuzhiyun 			    const struct cifs_credits *credits,
231*4882a593Smuzhiyun 			    const int optype);
232*4882a593Smuzhiyun 	void (*set_credits)(struct TCP_Server_Info *, const int);
233*4882a593Smuzhiyun 	int * (*get_credits_field)(struct TCP_Server_Info *, const int);
234*4882a593Smuzhiyun 	unsigned int (*get_credits)(struct mid_q_entry *);
235*4882a593Smuzhiyun 	__u64 (*get_next_mid)(struct TCP_Server_Info *);
236*4882a593Smuzhiyun 	void (*revert_current_mid)(struct TCP_Server_Info *server,
237*4882a593Smuzhiyun 				   const unsigned int val);
238*4882a593Smuzhiyun 	/* data offset from read response message */
239*4882a593Smuzhiyun 	unsigned int (*read_data_offset)(char *);
240*4882a593Smuzhiyun 	/*
241*4882a593Smuzhiyun 	 * Data length from read response message
242*4882a593Smuzhiyun 	 * When in_remaining is true, the returned data length is in
243*4882a593Smuzhiyun 	 * message field DataRemaining for out-of-band data read (e.g through
244*4882a593Smuzhiyun 	 * Memory Registration RDMA write in SMBD).
245*4882a593Smuzhiyun 	 * Otherwise, the returned data length is in message field DataLength.
246*4882a593Smuzhiyun 	 */
247*4882a593Smuzhiyun 	unsigned int (*read_data_length)(char *, bool in_remaining);
248*4882a593Smuzhiyun 	/* map smb to linux error */
249*4882a593Smuzhiyun 	int (*map_error)(char *, bool);
250*4882a593Smuzhiyun 	/* find mid corresponding to the response message */
251*4882a593Smuzhiyun 	struct mid_q_entry * (*find_mid)(struct TCP_Server_Info *, char *);
252*4882a593Smuzhiyun 	void (*dump_detail)(void *buf, struct TCP_Server_Info *ptcp_info);
253*4882a593Smuzhiyun 	void (*clear_stats)(struct cifs_tcon *);
254*4882a593Smuzhiyun 	void (*print_stats)(struct seq_file *m, struct cifs_tcon *);
255*4882a593Smuzhiyun 	void (*dump_share_caps)(struct seq_file *, struct cifs_tcon *);
256*4882a593Smuzhiyun 	/* verify the message */
257*4882a593Smuzhiyun 	int (*check_message)(char *, unsigned int, struct TCP_Server_Info *);
258*4882a593Smuzhiyun 	bool (*is_oplock_break)(char *, struct TCP_Server_Info *);
259*4882a593Smuzhiyun 	int (*handle_cancelled_mid)(struct mid_q_entry *, struct TCP_Server_Info *);
260*4882a593Smuzhiyun 	void (*downgrade_oplock)(struct TCP_Server_Info *server,
261*4882a593Smuzhiyun 				 struct cifsInodeInfo *cinode, __u32 oplock,
262*4882a593Smuzhiyun 				 unsigned int epoch, bool *purge_cache);
263*4882a593Smuzhiyun 	/* process transaction2 response */
264*4882a593Smuzhiyun 	bool (*check_trans2)(struct mid_q_entry *, struct TCP_Server_Info *,
265*4882a593Smuzhiyun 			     char *, int);
266*4882a593Smuzhiyun 	/* check if we need to negotiate */
267*4882a593Smuzhiyun 	bool (*need_neg)(struct TCP_Server_Info *);
268*4882a593Smuzhiyun 	/* negotiate to the server */
269*4882a593Smuzhiyun 	int (*negotiate)(const unsigned int, struct cifs_ses *);
270*4882a593Smuzhiyun 	/* set negotiated write size */
271*4882a593Smuzhiyun 	unsigned int (*negotiate_wsize)(struct cifs_tcon *, struct smb_vol *);
272*4882a593Smuzhiyun 	/* set negotiated read size */
273*4882a593Smuzhiyun 	unsigned int (*negotiate_rsize)(struct cifs_tcon *, struct smb_vol *);
274*4882a593Smuzhiyun 	/* setup smb sessionn */
275*4882a593Smuzhiyun 	int (*sess_setup)(const unsigned int, struct cifs_ses *,
276*4882a593Smuzhiyun 			  const struct nls_table *);
277*4882a593Smuzhiyun 	/* close smb session */
278*4882a593Smuzhiyun 	int (*logoff)(const unsigned int, struct cifs_ses *);
279*4882a593Smuzhiyun 	/* connect to a server share */
280*4882a593Smuzhiyun 	int (*tree_connect)(const unsigned int, struct cifs_ses *, const char *,
281*4882a593Smuzhiyun 			    struct cifs_tcon *, const struct nls_table *);
282*4882a593Smuzhiyun 	/* close tree connecion */
283*4882a593Smuzhiyun 	int (*tree_disconnect)(const unsigned int, struct cifs_tcon *);
284*4882a593Smuzhiyun 	/* get DFS referrals */
285*4882a593Smuzhiyun 	int (*get_dfs_refer)(const unsigned int, struct cifs_ses *,
286*4882a593Smuzhiyun 			     const char *, struct dfs_info3_param **,
287*4882a593Smuzhiyun 			     unsigned int *, const struct nls_table *, int);
288*4882a593Smuzhiyun 	/* informational QFS call */
289*4882a593Smuzhiyun 	void (*qfs_tcon)(const unsigned int, struct cifs_tcon *,
290*4882a593Smuzhiyun 			 struct cifs_sb_info *);
291*4882a593Smuzhiyun 	/* check if a path is accessible or not */
292*4882a593Smuzhiyun 	int (*is_path_accessible)(const unsigned int, struct cifs_tcon *,
293*4882a593Smuzhiyun 				  struct cifs_sb_info *, const char *);
294*4882a593Smuzhiyun 	/* query path data from the server */
295*4882a593Smuzhiyun 	int (*query_path_info)(const unsigned int, struct cifs_tcon *,
296*4882a593Smuzhiyun 			       struct cifs_sb_info *, const char *,
297*4882a593Smuzhiyun 			       FILE_ALL_INFO *, bool *, bool *);
298*4882a593Smuzhiyun 	/* query file data from the server */
299*4882a593Smuzhiyun 	int (*query_file_info)(const unsigned int, struct cifs_tcon *,
300*4882a593Smuzhiyun 			       struct cifs_fid *, FILE_ALL_INFO *);
301*4882a593Smuzhiyun 	/* query reparse tag from srv to determine which type of special file */
302*4882a593Smuzhiyun 	int (*query_reparse_tag)(const unsigned int xid, struct cifs_tcon *tcon,
303*4882a593Smuzhiyun 				struct cifs_sb_info *cifs_sb, const char *path,
304*4882a593Smuzhiyun 				__u32 *reparse_tag);
305*4882a593Smuzhiyun 	/* get server index number */
306*4882a593Smuzhiyun 	int (*get_srv_inum)(const unsigned int, struct cifs_tcon *,
307*4882a593Smuzhiyun 			    struct cifs_sb_info *, const char *,
308*4882a593Smuzhiyun 			    u64 *uniqueid, FILE_ALL_INFO *);
309*4882a593Smuzhiyun 	/* set size by path */
310*4882a593Smuzhiyun 	int (*set_path_size)(const unsigned int, struct cifs_tcon *,
311*4882a593Smuzhiyun 			     const char *, __u64, struct cifs_sb_info *, bool);
312*4882a593Smuzhiyun 	/* set size by file handle */
313*4882a593Smuzhiyun 	int (*set_file_size)(const unsigned int, struct cifs_tcon *,
314*4882a593Smuzhiyun 			     struct cifsFileInfo *, __u64, bool);
315*4882a593Smuzhiyun 	/* set attributes */
316*4882a593Smuzhiyun 	int (*set_file_info)(struct inode *, const char *, FILE_BASIC_INFO *,
317*4882a593Smuzhiyun 			     const unsigned int);
318*4882a593Smuzhiyun 	int (*set_compression)(const unsigned int, struct cifs_tcon *,
319*4882a593Smuzhiyun 			       struct cifsFileInfo *);
320*4882a593Smuzhiyun 	/* check if we can send an echo or nor */
321*4882a593Smuzhiyun 	bool (*can_echo)(struct TCP_Server_Info *);
322*4882a593Smuzhiyun 	/* send echo request */
323*4882a593Smuzhiyun 	int (*echo)(struct TCP_Server_Info *);
324*4882a593Smuzhiyun 	/* create directory */
325*4882a593Smuzhiyun 	int (*posix_mkdir)(const unsigned int xid, struct inode *inode,
326*4882a593Smuzhiyun 			umode_t mode, struct cifs_tcon *tcon,
327*4882a593Smuzhiyun 			const char *full_path,
328*4882a593Smuzhiyun 			struct cifs_sb_info *cifs_sb);
329*4882a593Smuzhiyun 	int (*mkdir)(const unsigned int xid, struct inode *inode, umode_t mode,
330*4882a593Smuzhiyun 		     struct cifs_tcon *tcon, const char *name,
331*4882a593Smuzhiyun 		     struct cifs_sb_info *sb);
332*4882a593Smuzhiyun 	/* set info on created directory */
333*4882a593Smuzhiyun 	void (*mkdir_setinfo)(struct inode *, const char *,
334*4882a593Smuzhiyun 			      struct cifs_sb_info *, struct cifs_tcon *,
335*4882a593Smuzhiyun 			      const unsigned int);
336*4882a593Smuzhiyun 	/* remove directory */
337*4882a593Smuzhiyun 	int (*rmdir)(const unsigned int, struct cifs_tcon *, const char *,
338*4882a593Smuzhiyun 		     struct cifs_sb_info *);
339*4882a593Smuzhiyun 	/* unlink file */
340*4882a593Smuzhiyun 	int (*unlink)(const unsigned int, struct cifs_tcon *, const char *,
341*4882a593Smuzhiyun 		      struct cifs_sb_info *);
342*4882a593Smuzhiyun 	/* open, rename and delete file */
343*4882a593Smuzhiyun 	int (*rename_pending_delete)(const char *, struct dentry *,
344*4882a593Smuzhiyun 				     const unsigned int);
345*4882a593Smuzhiyun 	/* send rename request */
346*4882a593Smuzhiyun 	int (*rename)(const unsigned int, struct cifs_tcon *, const char *,
347*4882a593Smuzhiyun 		      const char *, struct cifs_sb_info *);
348*4882a593Smuzhiyun 	/* send create hardlink request */
349*4882a593Smuzhiyun 	int (*create_hardlink)(const unsigned int, struct cifs_tcon *,
350*4882a593Smuzhiyun 			       const char *, const char *,
351*4882a593Smuzhiyun 			       struct cifs_sb_info *);
352*4882a593Smuzhiyun 	/* query symlink target */
353*4882a593Smuzhiyun 	int (*query_symlink)(const unsigned int, struct cifs_tcon *,
354*4882a593Smuzhiyun 			     struct cifs_sb_info *, const char *,
355*4882a593Smuzhiyun 			     char **, bool);
356*4882a593Smuzhiyun 	/* open a file for non-posix mounts */
357*4882a593Smuzhiyun 	int (*open)(const unsigned int, struct cifs_open_parms *,
358*4882a593Smuzhiyun 		    __u32 *, FILE_ALL_INFO *);
359*4882a593Smuzhiyun 	/* set fid protocol-specific info */
360*4882a593Smuzhiyun 	void (*set_fid)(struct cifsFileInfo *, struct cifs_fid *, __u32);
361*4882a593Smuzhiyun 	/* close a file */
362*4882a593Smuzhiyun 	void (*close)(const unsigned int, struct cifs_tcon *,
363*4882a593Smuzhiyun 		      struct cifs_fid *);
364*4882a593Smuzhiyun 	/* close a file, returning file attributes and timestamps */
365*4882a593Smuzhiyun 	void (*close_getattr)(const unsigned int xid, struct cifs_tcon *tcon,
366*4882a593Smuzhiyun 		      struct cifsFileInfo *pfile_info);
367*4882a593Smuzhiyun 	/* send a flush request to the server */
368*4882a593Smuzhiyun 	int (*flush)(const unsigned int, struct cifs_tcon *, struct cifs_fid *);
369*4882a593Smuzhiyun 	/* async read from the server */
370*4882a593Smuzhiyun 	int (*async_readv)(struct cifs_readdata *);
371*4882a593Smuzhiyun 	/* async write to the server */
372*4882a593Smuzhiyun 	int (*async_writev)(struct cifs_writedata *,
373*4882a593Smuzhiyun 			    void (*release)(struct kref *));
374*4882a593Smuzhiyun 	/* sync read from the server */
375*4882a593Smuzhiyun 	int (*sync_read)(const unsigned int, struct cifs_fid *,
376*4882a593Smuzhiyun 			 struct cifs_io_parms *, unsigned int *, char **,
377*4882a593Smuzhiyun 			 int *);
378*4882a593Smuzhiyun 	/* sync write to the server */
379*4882a593Smuzhiyun 	int (*sync_write)(const unsigned int, struct cifs_fid *,
380*4882a593Smuzhiyun 			  struct cifs_io_parms *, unsigned int *, struct kvec *,
381*4882a593Smuzhiyun 			  unsigned long);
382*4882a593Smuzhiyun 	/* open dir, start readdir */
383*4882a593Smuzhiyun 	int (*query_dir_first)(const unsigned int, struct cifs_tcon *,
384*4882a593Smuzhiyun 			       const char *, struct cifs_sb_info *,
385*4882a593Smuzhiyun 			       struct cifs_fid *, __u16,
386*4882a593Smuzhiyun 			       struct cifs_search_info *);
387*4882a593Smuzhiyun 	/* continue readdir */
388*4882a593Smuzhiyun 	int (*query_dir_next)(const unsigned int, struct cifs_tcon *,
389*4882a593Smuzhiyun 			      struct cifs_fid *,
390*4882a593Smuzhiyun 			      __u16, struct cifs_search_info *srch_inf);
391*4882a593Smuzhiyun 	/* close dir */
392*4882a593Smuzhiyun 	int (*close_dir)(const unsigned int, struct cifs_tcon *,
393*4882a593Smuzhiyun 			 struct cifs_fid *);
394*4882a593Smuzhiyun 	/* calculate a size of SMB message */
395*4882a593Smuzhiyun 	unsigned int (*calc_smb_size)(void *buf, struct TCP_Server_Info *ptcpi);
396*4882a593Smuzhiyun 	/* check for STATUS_PENDING and process the response if yes */
397*4882a593Smuzhiyun 	bool (*is_status_pending)(char *buf, struct TCP_Server_Info *server);
398*4882a593Smuzhiyun 	/* check for STATUS_NETWORK_SESSION_EXPIRED */
399*4882a593Smuzhiyun 	bool (*is_session_expired)(char *);
400*4882a593Smuzhiyun 	/* send oplock break response */
401*4882a593Smuzhiyun 	int (*oplock_response)(struct cifs_tcon *, struct cifs_fid *,
402*4882a593Smuzhiyun 			       struct cifsInodeInfo *);
403*4882a593Smuzhiyun 	/* query remote filesystem */
404*4882a593Smuzhiyun 	int (*queryfs)(const unsigned int, struct cifs_tcon *,
405*4882a593Smuzhiyun 		       struct cifs_sb_info *, struct kstatfs *);
406*4882a593Smuzhiyun 	/* send mandatory brlock to the server */
407*4882a593Smuzhiyun 	int (*mand_lock)(const unsigned int, struct cifsFileInfo *, __u64,
408*4882a593Smuzhiyun 			 __u64, __u32, int, int, bool);
409*4882a593Smuzhiyun 	/* unlock range of mandatory locks */
410*4882a593Smuzhiyun 	int (*mand_unlock_range)(struct cifsFileInfo *, struct file_lock *,
411*4882a593Smuzhiyun 				 const unsigned int);
412*4882a593Smuzhiyun 	/* push brlocks from the cache to the server */
413*4882a593Smuzhiyun 	int (*push_mand_locks)(struct cifsFileInfo *);
414*4882a593Smuzhiyun 	/* get lease key of the inode */
415*4882a593Smuzhiyun 	void (*get_lease_key)(struct inode *, struct cifs_fid *);
416*4882a593Smuzhiyun 	/* set lease key of the inode */
417*4882a593Smuzhiyun 	void (*set_lease_key)(struct inode *, struct cifs_fid *);
418*4882a593Smuzhiyun 	/* generate new lease key */
419*4882a593Smuzhiyun 	void (*new_lease_key)(struct cifs_fid *);
420*4882a593Smuzhiyun 	int (*generate_signingkey)(struct cifs_ses *);
421*4882a593Smuzhiyun 	int (*calc_signature)(struct smb_rqst *, struct TCP_Server_Info *,
422*4882a593Smuzhiyun 				bool allocate_crypto);
423*4882a593Smuzhiyun 	int (*set_integrity)(const unsigned int, struct cifs_tcon *tcon,
424*4882a593Smuzhiyun 			     struct cifsFileInfo *src_file);
425*4882a593Smuzhiyun 	int (*enum_snapshots)(const unsigned int xid, struct cifs_tcon *tcon,
426*4882a593Smuzhiyun 			     struct cifsFileInfo *src_file, void __user *);
427*4882a593Smuzhiyun 	int (*notify)(const unsigned int xid, struct file *pfile,
428*4882a593Smuzhiyun 			     void __user *pbuf);
429*4882a593Smuzhiyun 	int (*query_mf_symlink)(unsigned int, struct cifs_tcon *,
430*4882a593Smuzhiyun 				struct cifs_sb_info *, const unsigned char *,
431*4882a593Smuzhiyun 				char *, unsigned int *);
432*4882a593Smuzhiyun 	int (*create_mf_symlink)(unsigned int, struct cifs_tcon *,
433*4882a593Smuzhiyun 				 struct cifs_sb_info *, const unsigned char *,
434*4882a593Smuzhiyun 				 char *, unsigned int *);
435*4882a593Smuzhiyun 	/* if we can do cache read operations */
436*4882a593Smuzhiyun 	bool (*is_read_op)(__u32);
437*4882a593Smuzhiyun 	/* set oplock level for the inode */
438*4882a593Smuzhiyun 	void (*set_oplock_level)(struct cifsInodeInfo *, __u32, unsigned int,
439*4882a593Smuzhiyun 				 bool *);
440*4882a593Smuzhiyun 	/* create lease context buffer for CREATE request */
441*4882a593Smuzhiyun 	char * (*create_lease_buf)(u8 *lease_key, u8 oplock);
442*4882a593Smuzhiyun 	/* parse lease context buffer and return oplock/epoch info */
443*4882a593Smuzhiyun 	__u8 (*parse_lease_buf)(void *buf, unsigned int *epoch, char *lkey);
444*4882a593Smuzhiyun 	ssize_t (*copychunk_range)(const unsigned int,
445*4882a593Smuzhiyun 			struct cifsFileInfo *src_file,
446*4882a593Smuzhiyun 			struct cifsFileInfo *target_file,
447*4882a593Smuzhiyun 			u64 src_off, u64 len, u64 dest_off);
448*4882a593Smuzhiyun 	int (*duplicate_extents)(const unsigned int, struct cifsFileInfo *src,
449*4882a593Smuzhiyun 			struct cifsFileInfo *target_file, u64 src_off, u64 len,
450*4882a593Smuzhiyun 			u64 dest_off);
451*4882a593Smuzhiyun 	int (*validate_negotiate)(const unsigned int, struct cifs_tcon *);
452*4882a593Smuzhiyun 	ssize_t (*query_all_EAs)(const unsigned int, struct cifs_tcon *,
453*4882a593Smuzhiyun 			const unsigned char *, const unsigned char *, char *,
454*4882a593Smuzhiyun 			size_t, struct cifs_sb_info *);
455*4882a593Smuzhiyun 	int (*set_EA)(const unsigned int, struct cifs_tcon *, const char *,
456*4882a593Smuzhiyun 			const char *, const void *, const __u16,
457*4882a593Smuzhiyun 			const struct nls_table *, struct cifs_sb_info *);
458*4882a593Smuzhiyun 	struct cifs_ntsd * (*get_acl)(struct cifs_sb_info *, struct inode *,
459*4882a593Smuzhiyun 			const char *, u32 *);
460*4882a593Smuzhiyun 	struct cifs_ntsd * (*get_acl_by_fid)(struct cifs_sb_info *,
461*4882a593Smuzhiyun 			const struct cifs_fid *, u32 *);
462*4882a593Smuzhiyun 	int (*set_acl)(struct cifs_ntsd *, __u32, struct inode *, const char *,
463*4882a593Smuzhiyun 			int);
464*4882a593Smuzhiyun 	/* writepages retry size */
465*4882a593Smuzhiyun 	unsigned int (*wp_retry_size)(struct inode *);
466*4882a593Smuzhiyun 	/* get mtu credits */
467*4882a593Smuzhiyun 	int (*wait_mtu_credits)(struct TCP_Server_Info *, unsigned int,
468*4882a593Smuzhiyun 				unsigned int *, struct cifs_credits *);
469*4882a593Smuzhiyun 	/* adjust previously taken mtu credits to request size */
470*4882a593Smuzhiyun 	int (*adjust_credits)(struct TCP_Server_Info *server,
471*4882a593Smuzhiyun 			      struct cifs_credits *credits,
472*4882a593Smuzhiyun 			      const unsigned int payload_size);
473*4882a593Smuzhiyun 	/* check if we need to issue closedir */
474*4882a593Smuzhiyun 	bool (*dir_needs_close)(struct cifsFileInfo *);
475*4882a593Smuzhiyun 	long (*fallocate)(struct file *, struct cifs_tcon *, int, loff_t,
476*4882a593Smuzhiyun 			  loff_t);
477*4882a593Smuzhiyun 	/* init transform request - used for encryption for now */
478*4882a593Smuzhiyun 	int (*init_transform_rq)(struct TCP_Server_Info *, int num_rqst,
479*4882a593Smuzhiyun 				 struct smb_rqst *, struct smb_rqst *);
480*4882a593Smuzhiyun 	int (*is_transform_hdr)(void *buf);
481*4882a593Smuzhiyun 	int (*receive_transform)(struct TCP_Server_Info *,
482*4882a593Smuzhiyun 				 struct mid_q_entry **, char **, int *);
483*4882a593Smuzhiyun 	enum securityEnum (*select_sectype)(struct TCP_Server_Info *,
484*4882a593Smuzhiyun 			    enum securityEnum);
485*4882a593Smuzhiyun 	int (*next_header)(char *);
486*4882a593Smuzhiyun 	/* ioctl passthrough for query_info */
487*4882a593Smuzhiyun 	int (*ioctl_query_info)(const unsigned int xid,
488*4882a593Smuzhiyun 				struct cifs_tcon *tcon,
489*4882a593Smuzhiyun 				struct cifs_sb_info *cifs_sb,
490*4882a593Smuzhiyun 				__le16 *path, int is_dir,
491*4882a593Smuzhiyun 				unsigned long p);
492*4882a593Smuzhiyun 	/* make unix special files (block, char, fifo, socket) */
493*4882a593Smuzhiyun 	int (*make_node)(unsigned int xid,
494*4882a593Smuzhiyun 			 struct inode *inode,
495*4882a593Smuzhiyun 			 struct dentry *dentry,
496*4882a593Smuzhiyun 			 struct cifs_tcon *tcon,
497*4882a593Smuzhiyun 			 char *full_path,
498*4882a593Smuzhiyun 			 umode_t mode,
499*4882a593Smuzhiyun 			 dev_t device_number);
500*4882a593Smuzhiyun 	/* version specific fiemap implementation */
501*4882a593Smuzhiyun 	int (*fiemap)(struct cifs_tcon *tcon, struct cifsFileInfo *,
502*4882a593Smuzhiyun 		      struct fiemap_extent_info *, u64, u64);
503*4882a593Smuzhiyun 	/* version specific llseek implementation */
504*4882a593Smuzhiyun 	loff_t (*llseek)(struct file *, struct cifs_tcon *, loff_t, int);
505*4882a593Smuzhiyun 	/* Check for STATUS_IO_TIMEOUT */
506*4882a593Smuzhiyun 	bool (*is_status_io_timeout)(char *buf);
507*4882a593Smuzhiyun };
508*4882a593Smuzhiyun 
509*4882a593Smuzhiyun struct smb_version_values {
510*4882a593Smuzhiyun 	char		*version_string;
511*4882a593Smuzhiyun 	__u16		protocol_id;
512*4882a593Smuzhiyun 	__u32		req_capabilities;
513*4882a593Smuzhiyun 	__u32		large_lock_type;
514*4882a593Smuzhiyun 	__u32		exclusive_lock_type;
515*4882a593Smuzhiyun 	__u32		shared_lock_type;
516*4882a593Smuzhiyun 	__u32		unlock_lock_type;
517*4882a593Smuzhiyun 	size_t		header_preamble_size;
518*4882a593Smuzhiyun 	size_t		header_size;
519*4882a593Smuzhiyun 	size_t		max_header_size;
520*4882a593Smuzhiyun 	size_t		read_rsp_size;
521*4882a593Smuzhiyun 	__le16		lock_cmd;
522*4882a593Smuzhiyun 	unsigned int	cap_unix;
523*4882a593Smuzhiyun 	unsigned int	cap_nt_find;
524*4882a593Smuzhiyun 	unsigned int	cap_large_files;
525*4882a593Smuzhiyun 	__u16		signing_enabled;
526*4882a593Smuzhiyun 	__u16		signing_required;
527*4882a593Smuzhiyun 	size_t		create_lease_size;
528*4882a593Smuzhiyun };
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun #define HEADER_SIZE(server) (server->vals->header_size)
531*4882a593Smuzhiyun #define MAX_HEADER_SIZE(server) (server->vals->max_header_size)
532*4882a593Smuzhiyun 
533*4882a593Smuzhiyun struct smb_vol {
534*4882a593Smuzhiyun 	char *username;
535*4882a593Smuzhiyun 	char *password;
536*4882a593Smuzhiyun 	char *domainname;
537*4882a593Smuzhiyun 	char *UNC;
538*4882a593Smuzhiyun 	char *iocharset;  /* local code page for mapping to and from Unicode */
539*4882a593Smuzhiyun 	char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
540*4882a593Smuzhiyun 	char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
541*4882a593Smuzhiyun 	kuid_t cred_uid;
542*4882a593Smuzhiyun 	kuid_t linux_uid;
543*4882a593Smuzhiyun 	kgid_t linux_gid;
544*4882a593Smuzhiyun 	kuid_t backupuid;
545*4882a593Smuzhiyun 	kgid_t backupgid;
546*4882a593Smuzhiyun 	umode_t file_mode;
547*4882a593Smuzhiyun 	umode_t dir_mode;
548*4882a593Smuzhiyun 	enum securityEnum sectype; /* sectype requested via mnt opts */
549*4882a593Smuzhiyun 	bool sign; /* was signing requested via mnt opts? */
550*4882a593Smuzhiyun 	bool ignore_signature:1;
551*4882a593Smuzhiyun 	bool retry:1;
552*4882a593Smuzhiyun 	bool intr:1;
553*4882a593Smuzhiyun 	bool setuids:1;
554*4882a593Smuzhiyun 	bool setuidfromacl:1;
555*4882a593Smuzhiyun 	bool override_uid:1;
556*4882a593Smuzhiyun 	bool override_gid:1;
557*4882a593Smuzhiyun 	bool dynperm:1;
558*4882a593Smuzhiyun 	bool noperm:1;
559*4882a593Smuzhiyun 	bool nodelete:1;
560*4882a593Smuzhiyun 	bool mode_ace:1;
561*4882a593Smuzhiyun 	bool no_psx_acl:1; /* set if posix acl support should be disabled */
562*4882a593Smuzhiyun 	bool cifs_acl:1;
563*4882a593Smuzhiyun 	bool backupuid_specified; /* mount option  backupuid  is specified */
564*4882a593Smuzhiyun 	bool backupgid_specified; /* mount option  backupgid  is specified */
565*4882a593Smuzhiyun 	bool no_xattr:1;   /* set if xattr (EA) support should be disabled*/
566*4882a593Smuzhiyun 	bool server_ino:1; /* use inode numbers from server ie UniqueId */
567*4882a593Smuzhiyun 	bool direct_io:1;
568*4882a593Smuzhiyun 	bool strict_io:1; /* strict cache behavior */
569*4882a593Smuzhiyun 	bool cache_ro:1;
570*4882a593Smuzhiyun 	bool cache_rw:1;
571*4882a593Smuzhiyun 	bool remap:1;      /* set to remap seven reserved chars in filenames */
572*4882a593Smuzhiyun 	bool sfu_remap:1;  /* remap seven reserved chars ala SFU */
573*4882a593Smuzhiyun 	bool posix_paths:1; /* unset to not ask for posix pathnames. */
574*4882a593Smuzhiyun 	bool no_linux_ext:1;
575*4882a593Smuzhiyun 	bool linux_ext:1;
576*4882a593Smuzhiyun 	bool sfu_emul:1;
577*4882a593Smuzhiyun 	bool nullauth:1;   /* attempt to authenticate with null user */
578*4882a593Smuzhiyun 	bool nocase:1;     /* request case insensitive filenames */
579*4882a593Smuzhiyun 	bool nobrl:1;      /* disable sending byte range locks to srv */
580*4882a593Smuzhiyun 	bool nohandlecache:1; /* disable caching dir handles if srvr probs */
581*4882a593Smuzhiyun 	bool mand_lock:1;  /* send mandatory not posix byte range lock reqs */
582*4882a593Smuzhiyun 	bool seal:1;       /* request transport encryption on share */
583*4882a593Smuzhiyun 	bool nodfs:1;      /* Do not request DFS, even if available */
584*4882a593Smuzhiyun 	bool local_lease:1; /* check leases only on local system, not remote */
585*4882a593Smuzhiyun 	bool noblocksnd:1;
586*4882a593Smuzhiyun 	bool noautotune:1;
587*4882a593Smuzhiyun 	bool nostrictsync:1; /* do not force expensive SMBflush on every sync */
588*4882a593Smuzhiyun 	bool no_lease:1;     /* disable requesting leases */
589*4882a593Smuzhiyun 	bool fsc:1;	/* enable fscache */
590*4882a593Smuzhiyun 	bool mfsymlinks:1; /* use Minshall+French Symlinks */
591*4882a593Smuzhiyun 	bool multiuser:1;
592*4882a593Smuzhiyun 	bool rwpidforward:1; /* pid forward for read/write operations */
593*4882a593Smuzhiyun 	bool nosharesock:1;
594*4882a593Smuzhiyun 	bool persistent:1;
595*4882a593Smuzhiyun 	bool nopersistent:1;
596*4882a593Smuzhiyun 	bool resilient:1; /* noresilient not required since not fored for CA */
597*4882a593Smuzhiyun 	bool domainauto:1;
598*4882a593Smuzhiyun 	bool rdma:1;
599*4882a593Smuzhiyun 	bool multichannel:1;
600*4882a593Smuzhiyun 	bool use_client_guid:1;
601*4882a593Smuzhiyun 	/* reuse existing guid for multichannel */
602*4882a593Smuzhiyun 	u8 client_guid[SMB2_CLIENT_GUID_SIZE];
603*4882a593Smuzhiyun 	unsigned int bsize;
604*4882a593Smuzhiyun 	unsigned int rsize;
605*4882a593Smuzhiyun 	unsigned int wsize;
606*4882a593Smuzhiyun 	unsigned int min_offload;
607*4882a593Smuzhiyun 	bool sockopt_tcp_nodelay:1;
608*4882a593Smuzhiyun 	unsigned long actimeo; /* attribute cache timeout (jiffies) */
609*4882a593Smuzhiyun 	struct smb_version_operations *ops;
610*4882a593Smuzhiyun 	struct smb_version_values *vals;
611*4882a593Smuzhiyun 	char *prepath;
612*4882a593Smuzhiyun 	struct sockaddr_storage dstaddr; /* destination address */
613*4882a593Smuzhiyun 	struct sockaddr_storage srcaddr; /* allow binding to a local IP */
614*4882a593Smuzhiyun 	struct nls_table *local_nls;
615*4882a593Smuzhiyun 	unsigned int echo_interval; /* echo interval in secs */
616*4882a593Smuzhiyun 	__u64 snapshot_time; /* needed for timewarp tokens */
617*4882a593Smuzhiyun 	__u32 handle_timeout; /* persistent and durable handle timeout in ms */
618*4882a593Smuzhiyun 	unsigned int max_credits; /* smb3 max_credits 10 < credits < 60000 */
619*4882a593Smuzhiyun 	unsigned int max_channels;
620*4882a593Smuzhiyun 	__u16 compression; /* compression algorithm 0xFFFF default 0=disabled */
621*4882a593Smuzhiyun 	bool rootfs:1; /* if it's a SMB root file system */
622*4882a593Smuzhiyun };
623*4882a593Smuzhiyun 
624*4882a593Smuzhiyun /**
625*4882a593Smuzhiyun  * CIFS superblock mount flags (mnt_cifs_flags) to consider when
626*4882a593Smuzhiyun  * trying to reuse existing superblock for a new mount
627*4882a593Smuzhiyun  */
628*4882a593Smuzhiyun #define CIFS_MOUNT_MASK (CIFS_MOUNT_NO_PERM | CIFS_MOUNT_SET_UID | \
629*4882a593Smuzhiyun 			 CIFS_MOUNT_SERVER_INUM | CIFS_MOUNT_DIRECT_IO | \
630*4882a593Smuzhiyun 			 CIFS_MOUNT_NO_XATTR | CIFS_MOUNT_MAP_SPECIAL_CHR | \
631*4882a593Smuzhiyun 			 CIFS_MOUNT_MAP_SFM_CHR | \
632*4882a593Smuzhiyun 			 CIFS_MOUNT_UNX_EMUL | CIFS_MOUNT_NO_BRL | \
633*4882a593Smuzhiyun 			 CIFS_MOUNT_CIFS_ACL | CIFS_MOUNT_OVERR_UID | \
634*4882a593Smuzhiyun 			 CIFS_MOUNT_OVERR_GID | CIFS_MOUNT_DYNPERM | \
635*4882a593Smuzhiyun 			 CIFS_MOUNT_NOPOSIXBRL | CIFS_MOUNT_NOSSYNC | \
636*4882a593Smuzhiyun 			 CIFS_MOUNT_FSCACHE | CIFS_MOUNT_MF_SYMLINKS | \
637*4882a593Smuzhiyun 			 CIFS_MOUNT_MULTIUSER | CIFS_MOUNT_STRICT_IO | \
638*4882a593Smuzhiyun 			 CIFS_MOUNT_CIFS_BACKUPUID | CIFS_MOUNT_CIFS_BACKUPGID | \
639*4882a593Smuzhiyun 			 CIFS_MOUNT_UID_FROM_ACL | CIFS_MOUNT_NO_HANDLE_CACHE | \
640*4882a593Smuzhiyun 			 CIFS_MOUNT_NO_DFS | CIFS_MOUNT_MODE_FROM_SID | \
641*4882a593Smuzhiyun 			 CIFS_MOUNT_RO_CACHE | CIFS_MOUNT_RW_CACHE)
642*4882a593Smuzhiyun 
643*4882a593Smuzhiyun /**
644*4882a593Smuzhiyun  * Generic VFS superblock mount flags (s_flags) to consider when
645*4882a593Smuzhiyun  * trying to reuse existing superblock for a new mount
646*4882a593Smuzhiyun  */
647*4882a593Smuzhiyun #define CIFS_MS_MASK (SB_RDONLY | SB_MANDLOCK | SB_NOEXEC | SB_NOSUID | \
648*4882a593Smuzhiyun 		      SB_NODEV | SB_SYNCHRONOUS)
649*4882a593Smuzhiyun 
650*4882a593Smuzhiyun struct cifs_mnt_data {
651*4882a593Smuzhiyun 	struct cifs_sb_info *cifs_sb;
652*4882a593Smuzhiyun 	struct smb_vol *vol;
653*4882a593Smuzhiyun 	int flags;
654*4882a593Smuzhiyun };
655*4882a593Smuzhiyun 
656*4882a593Smuzhiyun static inline unsigned int
get_rfc1002_length(void * buf)657*4882a593Smuzhiyun get_rfc1002_length(void *buf)
658*4882a593Smuzhiyun {
659*4882a593Smuzhiyun 	return be32_to_cpu(*((__be32 *)buf)) & 0xffffff;
660*4882a593Smuzhiyun }
661*4882a593Smuzhiyun 
662*4882a593Smuzhiyun static inline void
inc_rfc1001_len(void * buf,int count)663*4882a593Smuzhiyun inc_rfc1001_len(void *buf, int count)
664*4882a593Smuzhiyun {
665*4882a593Smuzhiyun 	be32_add_cpu((__be32 *)buf, count);
666*4882a593Smuzhiyun }
667*4882a593Smuzhiyun 
668*4882a593Smuzhiyun struct TCP_Server_Info {
669*4882a593Smuzhiyun 	struct list_head tcp_ses_list;
670*4882a593Smuzhiyun 	struct list_head smb_ses_list;
671*4882a593Smuzhiyun 	int srv_count; /* reference counter */
672*4882a593Smuzhiyun 	/* 15 character server name + 0x20 16th byte indicating type = srv */
673*4882a593Smuzhiyun 	char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
674*4882a593Smuzhiyun 	struct smb_version_operations	*ops;
675*4882a593Smuzhiyun 	struct smb_version_values	*vals;
676*4882a593Smuzhiyun 	enum statusEnum tcpStatus; /* what we think the status is */
677*4882a593Smuzhiyun 	char *hostname; /* hostname portion of UNC string */
678*4882a593Smuzhiyun 	struct socket *ssocket;
679*4882a593Smuzhiyun 	struct sockaddr_storage dstaddr;
680*4882a593Smuzhiyun 	struct sockaddr_storage srcaddr; /* locally bind to this IP */
681*4882a593Smuzhiyun #ifdef CONFIG_NET_NS
682*4882a593Smuzhiyun 	struct net *net;
683*4882a593Smuzhiyun #endif
684*4882a593Smuzhiyun 	wait_queue_head_t response_q;
685*4882a593Smuzhiyun 	wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
686*4882a593Smuzhiyun 	struct list_head pending_mid_q;
687*4882a593Smuzhiyun 	bool noblocksnd;		/* use blocking sendmsg */
688*4882a593Smuzhiyun 	bool noautotune;		/* do not autotune send buf sizes */
689*4882a593Smuzhiyun 	bool tcp_nodelay;
690*4882a593Smuzhiyun 	unsigned int credits;  /* send no more requests at once */
691*4882a593Smuzhiyun 	unsigned int max_credits; /* can override large 32000 default at mnt */
692*4882a593Smuzhiyun 	unsigned int in_flight;  /* number of requests on the wire to server */
693*4882a593Smuzhiyun 	unsigned int max_in_flight; /* max number of requests that were on wire */
694*4882a593Smuzhiyun 	spinlock_t req_lock;  /* protect the two values above */
695*4882a593Smuzhiyun 	struct mutex srv_mutex;
696*4882a593Smuzhiyun 	struct task_struct *tsk;
697*4882a593Smuzhiyun 	char server_GUID[16];
698*4882a593Smuzhiyun 	__u16 sec_mode;
699*4882a593Smuzhiyun 	bool sign; /* is signing enabled on this connection? */
700*4882a593Smuzhiyun 	bool ignore_signature:1; /* skip validation of signatures in SMB2/3 rsp */
701*4882a593Smuzhiyun 	bool session_estab; /* mark when very first sess is established */
702*4882a593Smuzhiyun 	int echo_credits;  /* echo reserved slots */
703*4882a593Smuzhiyun 	int oplock_credits;  /* oplock break reserved slots */
704*4882a593Smuzhiyun 	bool echoes:1; /* enable echoes */
705*4882a593Smuzhiyun 	__u8 client_guid[SMB2_CLIENT_GUID_SIZE]; /* Client GUID */
706*4882a593Smuzhiyun 	u16 dialect; /* dialect index that server chose */
707*4882a593Smuzhiyun 	bool oplocks:1; /* enable oplocks */
708*4882a593Smuzhiyun 	unsigned int maxReq;	/* Clients should submit no more */
709*4882a593Smuzhiyun 	/* than maxReq distinct unanswered SMBs to the server when using  */
710*4882a593Smuzhiyun 	/* multiplexed reads or writes (for SMB1/CIFS only, not SMB2/SMB3) */
711*4882a593Smuzhiyun 	unsigned int maxBuf;	/* maxBuf specifies the maximum */
712*4882a593Smuzhiyun 	/* message size the server can send or receive for non-raw SMBs */
713*4882a593Smuzhiyun 	/* maxBuf is returned by SMB NegotiateProtocol so maxBuf is only 0 */
714*4882a593Smuzhiyun 	/* when socket is setup (and during reconnect) before NegProt sent */
715*4882a593Smuzhiyun 	unsigned int max_rw;	/* maxRw specifies the maximum */
716*4882a593Smuzhiyun 	/* message size the server can send or receive for */
717*4882a593Smuzhiyun 	/* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */
718*4882a593Smuzhiyun 	unsigned int capabilities; /* selective disabling of caps by smb sess */
719*4882a593Smuzhiyun 	int timeAdj;  /* Adjust for difference in server time zone in sec */
720*4882a593Smuzhiyun 	__u64 CurrentMid;         /* multiplex id - rotating counter */
721*4882a593Smuzhiyun 	char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */
722*4882a593Smuzhiyun 	/* 16th byte of RFC1001 workstation name is always null */
723*4882a593Smuzhiyun 	char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
724*4882a593Smuzhiyun 	__u32 sequence_number; /* for signing, protected by srv_mutex */
725*4882a593Smuzhiyun 	__u32 reconnect_instance; /* incremented on each reconnect */
726*4882a593Smuzhiyun 	struct session_key session_key;
727*4882a593Smuzhiyun 	unsigned long lstrp; /* when we got last response from this server */
728*4882a593Smuzhiyun 	struct cifs_secmech secmech; /* crypto sec mech functs, descriptors */
729*4882a593Smuzhiyun #define	CIFS_NEGFLAVOR_LANMAN	0	/* wct == 13, LANMAN */
730*4882a593Smuzhiyun #define	CIFS_NEGFLAVOR_UNENCAP	1	/* wct == 17, but no ext_sec */
731*4882a593Smuzhiyun #define	CIFS_NEGFLAVOR_EXTENDED	2	/* wct == 17, ext_sec bit set */
732*4882a593Smuzhiyun 	char	negflavor;	/* NEGOTIATE response flavor */
733*4882a593Smuzhiyun 	/* extended security flavors that server supports */
734*4882a593Smuzhiyun 	bool	sec_ntlmssp;		/* supports NTLMSSP */
735*4882a593Smuzhiyun 	bool	sec_kerberosu2u;	/* supports U2U Kerberos */
736*4882a593Smuzhiyun 	bool	sec_kerberos;		/* supports plain Kerberos */
737*4882a593Smuzhiyun 	bool	sec_mskerberos;		/* supports legacy MS Kerberos */
738*4882a593Smuzhiyun 	bool	large_buf;		/* is current buffer large? */
739*4882a593Smuzhiyun 	/* use SMBD connection instead of socket */
740*4882a593Smuzhiyun 	bool	rdma;
741*4882a593Smuzhiyun 	/* point to the SMBD connection if RDMA is used instead of socket */
742*4882a593Smuzhiyun 	struct smbd_connection *smbd_conn;
743*4882a593Smuzhiyun 	struct delayed_work	echo; /* echo ping workqueue job */
744*4882a593Smuzhiyun 	char	*smallbuf;	/* pointer to current "small" buffer */
745*4882a593Smuzhiyun 	char	*bigbuf;	/* pointer to current "big" buffer */
746*4882a593Smuzhiyun 	/* Total size of this PDU. Only valid from cifs_demultiplex_thread */
747*4882a593Smuzhiyun 	unsigned int pdu_size;
748*4882a593Smuzhiyun 	unsigned int total_read; /* total amount of data read in this pass */
749*4882a593Smuzhiyun 	atomic_t in_send; /* requests trying to send */
750*4882a593Smuzhiyun 	atomic_t num_waiters;   /* blocked waiting to get in sendrecv */
751*4882a593Smuzhiyun #ifdef CONFIG_CIFS_FSCACHE
752*4882a593Smuzhiyun 	struct fscache_cookie   *fscache; /* client index cache cookie */
753*4882a593Smuzhiyun #endif
754*4882a593Smuzhiyun #ifdef CONFIG_CIFS_STATS2
755*4882a593Smuzhiyun 	atomic_t num_cmds[NUMBER_OF_SMB2_COMMANDS]; /* total requests by cmd */
756*4882a593Smuzhiyun 	atomic_t smb2slowcmd[NUMBER_OF_SMB2_COMMANDS]; /* count resps > 1 sec */
757*4882a593Smuzhiyun 	__u64 time_per_cmd[NUMBER_OF_SMB2_COMMANDS]; /* total time per cmd */
758*4882a593Smuzhiyun 	__u32 slowest_cmd[NUMBER_OF_SMB2_COMMANDS];
759*4882a593Smuzhiyun 	__u32 fastest_cmd[NUMBER_OF_SMB2_COMMANDS];
760*4882a593Smuzhiyun #endif /* STATS2 */
761*4882a593Smuzhiyun 	unsigned int	max_read;
762*4882a593Smuzhiyun 	unsigned int	max_write;
763*4882a593Smuzhiyun 	unsigned int	min_offload;
764*4882a593Smuzhiyun 	__le16	compress_algorithm;
765*4882a593Smuzhiyun 	__le16	cipher_type;
766*4882a593Smuzhiyun 	 /* save initital negprot hash */
767*4882a593Smuzhiyun 	__u8	preauth_sha_hash[SMB2_PREAUTH_HASH_SIZE];
768*4882a593Smuzhiyun 	bool	posix_ext_supported;
769*4882a593Smuzhiyun 	struct delayed_work reconnect; /* reconnect workqueue job */
770*4882a593Smuzhiyun 	struct mutex reconnect_mutex; /* prevent simultaneous reconnects */
771*4882a593Smuzhiyun 	unsigned long echo_interval;
772*4882a593Smuzhiyun 
773*4882a593Smuzhiyun 	/*
774*4882a593Smuzhiyun 	 * Number of targets available for reconnect. The more targets
775*4882a593Smuzhiyun 	 * the more tasks have to wait to let the demultiplex thread
776*4882a593Smuzhiyun 	 * reconnect.
777*4882a593Smuzhiyun 	 */
778*4882a593Smuzhiyun 	int nr_targets;
779*4882a593Smuzhiyun 	bool noblockcnt; /* use non-blocking connect() */
780*4882a593Smuzhiyun 	bool is_channel; /* if a session channel */
781*4882a593Smuzhiyun };
782*4882a593Smuzhiyun 
783*4882a593Smuzhiyun struct cifs_credits {
784*4882a593Smuzhiyun 	unsigned int value;
785*4882a593Smuzhiyun 	unsigned int instance;
786*4882a593Smuzhiyun };
787*4882a593Smuzhiyun 
788*4882a593Smuzhiyun static inline unsigned int
in_flight(struct TCP_Server_Info * server)789*4882a593Smuzhiyun in_flight(struct TCP_Server_Info *server)
790*4882a593Smuzhiyun {
791*4882a593Smuzhiyun 	unsigned int num;
792*4882a593Smuzhiyun 	spin_lock(&server->req_lock);
793*4882a593Smuzhiyun 	num = server->in_flight;
794*4882a593Smuzhiyun 	spin_unlock(&server->req_lock);
795*4882a593Smuzhiyun 	return num;
796*4882a593Smuzhiyun }
797*4882a593Smuzhiyun 
798*4882a593Smuzhiyun static inline bool
has_credits(struct TCP_Server_Info * server,int * credits,int num_credits)799*4882a593Smuzhiyun has_credits(struct TCP_Server_Info *server, int *credits, int num_credits)
800*4882a593Smuzhiyun {
801*4882a593Smuzhiyun 	int num;
802*4882a593Smuzhiyun 	spin_lock(&server->req_lock);
803*4882a593Smuzhiyun 	num = *credits;
804*4882a593Smuzhiyun 	spin_unlock(&server->req_lock);
805*4882a593Smuzhiyun 	return num >= num_credits;
806*4882a593Smuzhiyun }
807*4882a593Smuzhiyun 
808*4882a593Smuzhiyun static inline void
add_credits(struct TCP_Server_Info * server,const struct cifs_credits * credits,const int optype)809*4882a593Smuzhiyun add_credits(struct TCP_Server_Info *server, const struct cifs_credits *credits,
810*4882a593Smuzhiyun 	    const int optype)
811*4882a593Smuzhiyun {
812*4882a593Smuzhiyun 	server->ops->add_credits(server, credits, optype);
813*4882a593Smuzhiyun }
814*4882a593Smuzhiyun 
815*4882a593Smuzhiyun static inline void
add_credits_and_wake_if(struct TCP_Server_Info * server,const struct cifs_credits * credits,const int optype)816*4882a593Smuzhiyun add_credits_and_wake_if(struct TCP_Server_Info *server,
817*4882a593Smuzhiyun 			const struct cifs_credits *credits, const int optype)
818*4882a593Smuzhiyun {
819*4882a593Smuzhiyun 	if (credits->value) {
820*4882a593Smuzhiyun 		server->ops->add_credits(server, credits, optype);
821*4882a593Smuzhiyun 		wake_up(&server->request_q);
822*4882a593Smuzhiyun 	}
823*4882a593Smuzhiyun }
824*4882a593Smuzhiyun 
825*4882a593Smuzhiyun static inline void
set_credits(struct TCP_Server_Info * server,const int val)826*4882a593Smuzhiyun set_credits(struct TCP_Server_Info *server, const int val)
827*4882a593Smuzhiyun {
828*4882a593Smuzhiyun 	server->ops->set_credits(server, val);
829*4882a593Smuzhiyun }
830*4882a593Smuzhiyun 
831*4882a593Smuzhiyun static inline int
adjust_credits(struct TCP_Server_Info * server,struct cifs_credits * credits,const unsigned int payload_size)832*4882a593Smuzhiyun adjust_credits(struct TCP_Server_Info *server, struct cifs_credits *credits,
833*4882a593Smuzhiyun 	       const unsigned int payload_size)
834*4882a593Smuzhiyun {
835*4882a593Smuzhiyun 	return server->ops->adjust_credits ?
836*4882a593Smuzhiyun 		server->ops->adjust_credits(server, credits, payload_size) : 0;
837*4882a593Smuzhiyun }
838*4882a593Smuzhiyun 
839*4882a593Smuzhiyun static inline __le64
get_next_mid64(struct TCP_Server_Info * server)840*4882a593Smuzhiyun get_next_mid64(struct TCP_Server_Info *server)
841*4882a593Smuzhiyun {
842*4882a593Smuzhiyun 	return cpu_to_le64(server->ops->get_next_mid(server));
843*4882a593Smuzhiyun }
844*4882a593Smuzhiyun 
845*4882a593Smuzhiyun static inline __le16
get_next_mid(struct TCP_Server_Info * server)846*4882a593Smuzhiyun get_next_mid(struct TCP_Server_Info *server)
847*4882a593Smuzhiyun {
848*4882a593Smuzhiyun 	__u16 mid = server->ops->get_next_mid(server);
849*4882a593Smuzhiyun 	/*
850*4882a593Smuzhiyun 	 * The value in the SMB header should be little endian for easy
851*4882a593Smuzhiyun 	 * on-the-wire decoding.
852*4882a593Smuzhiyun 	 */
853*4882a593Smuzhiyun 	return cpu_to_le16(mid);
854*4882a593Smuzhiyun }
855*4882a593Smuzhiyun 
856*4882a593Smuzhiyun static inline void
revert_current_mid(struct TCP_Server_Info * server,const unsigned int val)857*4882a593Smuzhiyun revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
858*4882a593Smuzhiyun {
859*4882a593Smuzhiyun 	if (server->ops->revert_current_mid)
860*4882a593Smuzhiyun 		server->ops->revert_current_mid(server, val);
861*4882a593Smuzhiyun }
862*4882a593Smuzhiyun 
863*4882a593Smuzhiyun static inline void
revert_current_mid_from_hdr(struct TCP_Server_Info * server,const struct smb2_sync_hdr * shdr)864*4882a593Smuzhiyun revert_current_mid_from_hdr(struct TCP_Server_Info *server,
865*4882a593Smuzhiyun 			    const struct smb2_sync_hdr *shdr)
866*4882a593Smuzhiyun {
867*4882a593Smuzhiyun 	unsigned int num = le16_to_cpu(shdr->CreditCharge);
868*4882a593Smuzhiyun 
869*4882a593Smuzhiyun 	return revert_current_mid(server, num > 0 ? num : 1);
870*4882a593Smuzhiyun }
871*4882a593Smuzhiyun 
872*4882a593Smuzhiyun static inline __u16
get_mid(const struct smb_hdr * smb)873*4882a593Smuzhiyun get_mid(const struct smb_hdr *smb)
874*4882a593Smuzhiyun {
875*4882a593Smuzhiyun 	return le16_to_cpu(smb->Mid);
876*4882a593Smuzhiyun }
877*4882a593Smuzhiyun 
878*4882a593Smuzhiyun static inline bool
compare_mid(__u16 mid,const struct smb_hdr * smb)879*4882a593Smuzhiyun compare_mid(__u16 mid, const struct smb_hdr *smb)
880*4882a593Smuzhiyun {
881*4882a593Smuzhiyun 	return mid == le16_to_cpu(smb->Mid);
882*4882a593Smuzhiyun }
883*4882a593Smuzhiyun 
884*4882a593Smuzhiyun /*
885*4882a593Smuzhiyun  * When the server supports very large reads and writes via POSIX extensions,
886*4882a593Smuzhiyun  * we can allow up to 2^24-1, minus the size of a READ/WRITE_AND_X header, not
887*4882a593Smuzhiyun  * including the RFC1001 length.
888*4882a593Smuzhiyun  *
889*4882a593Smuzhiyun  * Note that this might make for "interesting" allocation problems during
890*4882a593Smuzhiyun  * writeback however as we have to allocate an array of pointers for the
891*4882a593Smuzhiyun  * pages. A 16M write means ~32kb page array with PAGE_SIZE == 4096.
892*4882a593Smuzhiyun  *
893*4882a593Smuzhiyun  * For reads, there is a similar problem as we need to allocate an array
894*4882a593Smuzhiyun  * of kvecs to handle the receive, though that should only need to be done
895*4882a593Smuzhiyun  * once.
896*4882a593Smuzhiyun  */
897*4882a593Smuzhiyun #define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4)
898*4882a593Smuzhiyun #define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP) + 4)
899*4882a593Smuzhiyun 
900*4882a593Smuzhiyun /*
901*4882a593Smuzhiyun  * When the server doesn't allow large posix writes, only allow a rsize/wsize
902*4882a593Smuzhiyun  * of 2^17-1 minus the size of the call header. That allows for a read or
903*4882a593Smuzhiyun  * write up to the maximum size described by RFC1002.
904*4882a593Smuzhiyun  */
905*4882a593Smuzhiyun #define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4)
906*4882a593Smuzhiyun #define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4)
907*4882a593Smuzhiyun 
908*4882a593Smuzhiyun /*
909*4882a593Smuzhiyun  * The default wsize is 1M. find_get_pages seems to return a maximum of 256
910*4882a593Smuzhiyun  * pages in a single call. With PAGE_SIZE == 4k, this means we can fill
911*4882a593Smuzhiyun  * a single wsize request with a single call.
912*4882a593Smuzhiyun  */
913*4882a593Smuzhiyun #define CIFS_DEFAULT_IOSIZE (1024 * 1024)
914*4882a593Smuzhiyun #define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
915*4882a593Smuzhiyun 
916*4882a593Smuzhiyun /*
917*4882a593Smuzhiyun  * Windows only supports a max of 60kb reads and 65535 byte writes. Default to
918*4882a593Smuzhiyun  * those values when posix extensions aren't in force. In actuality here, we
919*4882a593Smuzhiyun  * use 65536 to allow for a write that is a multiple of 4k. Most servers seem
920*4882a593Smuzhiyun  * to be ok with the extra byte even though Windows doesn't send writes that
921*4882a593Smuzhiyun  * are that large.
922*4882a593Smuzhiyun  *
923*4882a593Smuzhiyun  * Citation:
924*4882a593Smuzhiyun  *
925*4882a593Smuzhiyun  * https://blogs.msdn.com/b/openspecification/archive/2009/04/10/smb-maximum-transmit-buffer-size-and-performance-tuning.aspx
926*4882a593Smuzhiyun  */
927*4882a593Smuzhiyun #define CIFS_DEFAULT_NON_POSIX_RSIZE (60 * 1024)
928*4882a593Smuzhiyun #define CIFS_DEFAULT_NON_POSIX_WSIZE (65536)
929*4882a593Smuzhiyun 
930*4882a593Smuzhiyun /*
931*4882a593Smuzhiyun  * Macros to allow the TCP_Server_Info->net field and related code to drop out
932*4882a593Smuzhiyun  * when CONFIG_NET_NS isn't set.
933*4882a593Smuzhiyun  */
934*4882a593Smuzhiyun 
935*4882a593Smuzhiyun #ifdef CONFIG_NET_NS
936*4882a593Smuzhiyun 
cifs_net_ns(struct TCP_Server_Info * srv)937*4882a593Smuzhiyun static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv)
938*4882a593Smuzhiyun {
939*4882a593Smuzhiyun 	return srv->net;
940*4882a593Smuzhiyun }
941*4882a593Smuzhiyun 
cifs_set_net_ns(struct TCP_Server_Info * srv,struct net * net)942*4882a593Smuzhiyun static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net)
943*4882a593Smuzhiyun {
944*4882a593Smuzhiyun 	srv->net = net;
945*4882a593Smuzhiyun }
946*4882a593Smuzhiyun 
947*4882a593Smuzhiyun #else
948*4882a593Smuzhiyun 
cifs_net_ns(struct TCP_Server_Info * srv)949*4882a593Smuzhiyun static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv)
950*4882a593Smuzhiyun {
951*4882a593Smuzhiyun 	return &init_net;
952*4882a593Smuzhiyun }
953*4882a593Smuzhiyun 
cifs_set_net_ns(struct TCP_Server_Info * srv,struct net * net)954*4882a593Smuzhiyun static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net)
955*4882a593Smuzhiyun {
956*4882a593Smuzhiyun }
957*4882a593Smuzhiyun 
958*4882a593Smuzhiyun #endif
959*4882a593Smuzhiyun 
960*4882a593Smuzhiyun struct cifs_server_iface {
961*4882a593Smuzhiyun 	size_t speed;
962*4882a593Smuzhiyun 	unsigned int rdma_capable : 1;
963*4882a593Smuzhiyun 	unsigned int rss_capable : 1;
964*4882a593Smuzhiyun 	struct sockaddr_storage sockaddr;
965*4882a593Smuzhiyun };
966*4882a593Smuzhiyun 
967*4882a593Smuzhiyun struct cifs_chan {
968*4882a593Smuzhiyun 	struct TCP_Server_Info *server;
969*4882a593Smuzhiyun 	__u8 signkey[SMB3_SIGN_KEY_SIZE];
970*4882a593Smuzhiyun };
971*4882a593Smuzhiyun 
972*4882a593Smuzhiyun /*
973*4882a593Smuzhiyun  * Session structure.  One of these for each uid session with a particular host
974*4882a593Smuzhiyun  */
975*4882a593Smuzhiyun struct cifs_ses {
976*4882a593Smuzhiyun 	struct list_head smb_ses_list;
977*4882a593Smuzhiyun 	struct list_head tcon_list;
978*4882a593Smuzhiyun 	struct cifs_tcon *tcon_ipc;
979*4882a593Smuzhiyun 	struct mutex session_mutex;
980*4882a593Smuzhiyun 	struct TCP_Server_Info *server;	/* pointer to server info */
981*4882a593Smuzhiyun 	int ses_count;		/* reference counter */
982*4882a593Smuzhiyun 	enum statusEnum status;  /* updates protected by GlobalMid_Lock */
983*4882a593Smuzhiyun 	unsigned overrideSecFlg;  /* if non-zero override global sec flags */
984*4882a593Smuzhiyun 	char *serverOS;		/* name of operating system underlying server */
985*4882a593Smuzhiyun 	char *serverNOS;	/* name of network operating system of server */
986*4882a593Smuzhiyun 	char *serverDomain;	/* security realm of server */
987*4882a593Smuzhiyun 	__u64 Suid;		/* remote smb uid  */
988*4882a593Smuzhiyun 	kuid_t linux_uid;	/* overriding owner of files on the mount */
989*4882a593Smuzhiyun 	kuid_t cred_uid;	/* owner of credentials */
990*4882a593Smuzhiyun 	unsigned int capabilities;
991*4882a593Smuzhiyun 	char serverName[SERVER_NAME_LEN_WITH_NULL];
992*4882a593Smuzhiyun 	char *user_name;	/* must not be null except during init of sess
993*4882a593Smuzhiyun 				   and after mount option parsing we fill it */
994*4882a593Smuzhiyun 	char *domainName;
995*4882a593Smuzhiyun 	char *password;
996*4882a593Smuzhiyun 	struct session_key auth_key;
997*4882a593Smuzhiyun 	struct ntlmssp_auth *ntlmssp; /* ciphertext, flags, server challenge */
998*4882a593Smuzhiyun 	enum securityEnum sectype; /* what security flavor was specified? */
999*4882a593Smuzhiyun 	bool sign;		/* is signing required? */
1000*4882a593Smuzhiyun 	bool need_reconnect:1; /* connection reset, uid now invalid */
1001*4882a593Smuzhiyun 	bool domainAuto:1;
1002*4882a593Smuzhiyun 	bool binding:1; /* are we binding the session? */
1003*4882a593Smuzhiyun 	__u16 session_flags;
1004*4882a593Smuzhiyun 	__u8 smb3signingkey[SMB3_SIGN_KEY_SIZE];
1005*4882a593Smuzhiyun 	__u8 smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE];
1006*4882a593Smuzhiyun 	__u8 smb3decryptionkey[SMB3_ENC_DEC_KEY_SIZE];
1007*4882a593Smuzhiyun 	__u8 preauth_sha_hash[SMB2_PREAUTH_HASH_SIZE];
1008*4882a593Smuzhiyun 
1009*4882a593Smuzhiyun 	__u8 binding_preauth_sha_hash[SMB2_PREAUTH_HASH_SIZE];
1010*4882a593Smuzhiyun 
1011*4882a593Smuzhiyun 	/*
1012*4882a593Smuzhiyun 	 * Network interfaces available on the server this session is
1013*4882a593Smuzhiyun 	 * connected to.
1014*4882a593Smuzhiyun 	 *
1015*4882a593Smuzhiyun 	 * Other channels can be opened by connecting and binding this
1016*4882a593Smuzhiyun 	 * session to interfaces from this list.
1017*4882a593Smuzhiyun 	 *
1018*4882a593Smuzhiyun 	 * iface_lock should be taken when accessing any of these fields
1019*4882a593Smuzhiyun 	 */
1020*4882a593Smuzhiyun 	spinlock_t iface_lock;
1021*4882a593Smuzhiyun 	struct cifs_server_iface *iface_list;
1022*4882a593Smuzhiyun 	size_t iface_count;
1023*4882a593Smuzhiyun 	unsigned long iface_last_update; /* jiffies */
1024*4882a593Smuzhiyun 
1025*4882a593Smuzhiyun #define CIFS_MAX_CHANNELS 16
1026*4882a593Smuzhiyun 	struct cifs_chan chans[CIFS_MAX_CHANNELS];
1027*4882a593Smuzhiyun 	struct cifs_chan *binding_chan;
1028*4882a593Smuzhiyun 	size_t chan_count;
1029*4882a593Smuzhiyun 	size_t chan_max;
1030*4882a593Smuzhiyun 	atomic_t chan_seq; /* round robin state */
1031*4882a593Smuzhiyun };
1032*4882a593Smuzhiyun 
1033*4882a593Smuzhiyun /*
1034*4882a593Smuzhiyun  * When binding a new channel, we need to access the channel which isn't fully
1035*4882a593Smuzhiyun  * established yet.
1036*4882a593Smuzhiyun  */
1037*4882a593Smuzhiyun 
1038*4882a593Smuzhiyun static inline
cifs_ses_binding_channel(struct cifs_ses * ses)1039*4882a593Smuzhiyun struct cifs_chan *cifs_ses_binding_channel(struct cifs_ses *ses)
1040*4882a593Smuzhiyun {
1041*4882a593Smuzhiyun 	if (ses->binding)
1042*4882a593Smuzhiyun 		return ses->binding_chan;
1043*4882a593Smuzhiyun 	else
1044*4882a593Smuzhiyun 		return NULL;
1045*4882a593Smuzhiyun }
1046*4882a593Smuzhiyun 
1047*4882a593Smuzhiyun /*
1048*4882a593Smuzhiyun  * Returns the server pointer of the session. When binding a new
1049*4882a593Smuzhiyun  * channel this returns the last channel which isn't fully established
1050*4882a593Smuzhiyun  * yet.
1051*4882a593Smuzhiyun  *
1052*4882a593Smuzhiyun  * This function should be use for negprot/sess.setup codepaths. For
1053*4882a593Smuzhiyun  * the other requests see cifs_pick_channel().
1054*4882a593Smuzhiyun  */
1055*4882a593Smuzhiyun static inline
cifs_ses_server(struct cifs_ses * ses)1056*4882a593Smuzhiyun struct TCP_Server_Info *cifs_ses_server(struct cifs_ses *ses)
1057*4882a593Smuzhiyun {
1058*4882a593Smuzhiyun 	if (ses->binding)
1059*4882a593Smuzhiyun 		return ses->binding_chan->server;
1060*4882a593Smuzhiyun 	else
1061*4882a593Smuzhiyun 		return ses->server;
1062*4882a593Smuzhiyun }
1063*4882a593Smuzhiyun 
1064*4882a593Smuzhiyun static inline bool
cap_unix(struct cifs_ses * ses)1065*4882a593Smuzhiyun cap_unix(struct cifs_ses *ses)
1066*4882a593Smuzhiyun {
1067*4882a593Smuzhiyun 	return ses->server->vals->cap_unix & ses->capabilities;
1068*4882a593Smuzhiyun }
1069*4882a593Smuzhiyun 
1070*4882a593Smuzhiyun struct cached_fid {
1071*4882a593Smuzhiyun 	bool is_valid:1;	/* Do we have a useable root fid */
1072*4882a593Smuzhiyun 	bool file_all_info_is_valid:1;
1073*4882a593Smuzhiyun 	bool has_lease:1;
1074*4882a593Smuzhiyun 	struct kref refcount;
1075*4882a593Smuzhiyun 	struct cifs_fid *fid;
1076*4882a593Smuzhiyun 	struct mutex fid_mutex;
1077*4882a593Smuzhiyun 	struct cifs_tcon *tcon;
1078*4882a593Smuzhiyun 	struct work_struct lease_break;
1079*4882a593Smuzhiyun 	struct smb2_file_all_info file_all_info;
1080*4882a593Smuzhiyun };
1081*4882a593Smuzhiyun 
1082*4882a593Smuzhiyun /*
1083*4882a593Smuzhiyun  * there is one of these for each connection to a resource on a particular
1084*4882a593Smuzhiyun  * session
1085*4882a593Smuzhiyun  */
1086*4882a593Smuzhiyun struct cifs_tcon {
1087*4882a593Smuzhiyun 	struct list_head tcon_list;
1088*4882a593Smuzhiyun 	int tc_count;
1089*4882a593Smuzhiyun 	struct list_head rlist; /* reconnect list */
1090*4882a593Smuzhiyun 	atomic_t num_local_opens;  /* num of all opens including disconnected */
1091*4882a593Smuzhiyun 	atomic_t num_remote_opens; /* num of all network opens on server */
1092*4882a593Smuzhiyun 	struct list_head openFileList;
1093*4882a593Smuzhiyun 	spinlock_t open_file_lock; /* protects list above */
1094*4882a593Smuzhiyun 	struct cifs_ses *ses;	/* pointer to session associated with */
1095*4882a593Smuzhiyun 	char treeName[MAX_TREE_SIZE + 1]; /* UNC name of resource in ASCII */
1096*4882a593Smuzhiyun 	char *nativeFileSystem;
1097*4882a593Smuzhiyun 	char *password;		/* for share-level security */
1098*4882a593Smuzhiyun 	__u32 tid;		/* The 4 byte tree id */
1099*4882a593Smuzhiyun 	__u16 Flags;		/* optional support bits */
1100*4882a593Smuzhiyun 	enum statusEnum tidStatus;
1101*4882a593Smuzhiyun 	atomic_t num_smbs_sent;
1102*4882a593Smuzhiyun 	union {
1103*4882a593Smuzhiyun 		struct {
1104*4882a593Smuzhiyun 			atomic_t num_writes;
1105*4882a593Smuzhiyun 			atomic_t num_reads;
1106*4882a593Smuzhiyun 			atomic_t num_flushes;
1107*4882a593Smuzhiyun 			atomic_t num_oplock_brks;
1108*4882a593Smuzhiyun 			atomic_t num_opens;
1109*4882a593Smuzhiyun 			atomic_t num_closes;
1110*4882a593Smuzhiyun 			atomic_t num_deletes;
1111*4882a593Smuzhiyun 			atomic_t num_mkdirs;
1112*4882a593Smuzhiyun 			atomic_t num_posixopens;
1113*4882a593Smuzhiyun 			atomic_t num_posixmkdirs;
1114*4882a593Smuzhiyun 			atomic_t num_rmdirs;
1115*4882a593Smuzhiyun 			atomic_t num_renames;
1116*4882a593Smuzhiyun 			atomic_t num_t2renames;
1117*4882a593Smuzhiyun 			atomic_t num_ffirst;
1118*4882a593Smuzhiyun 			atomic_t num_fnext;
1119*4882a593Smuzhiyun 			atomic_t num_fclose;
1120*4882a593Smuzhiyun 			atomic_t num_hardlinks;
1121*4882a593Smuzhiyun 			atomic_t num_symlinks;
1122*4882a593Smuzhiyun 			atomic_t num_locks;
1123*4882a593Smuzhiyun 			atomic_t num_acl_get;
1124*4882a593Smuzhiyun 			atomic_t num_acl_set;
1125*4882a593Smuzhiyun 		} cifs_stats;
1126*4882a593Smuzhiyun 		struct {
1127*4882a593Smuzhiyun 			atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
1128*4882a593Smuzhiyun 			atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
1129*4882a593Smuzhiyun 		} smb2_stats;
1130*4882a593Smuzhiyun 	} stats;
1131*4882a593Smuzhiyun 	__u64    bytes_read;
1132*4882a593Smuzhiyun 	__u64    bytes_written;
1133*4882a593Smuzhiyun 	spinlock_t stat_lock;  /* protects the two fields above */
1134*4882a593Smuzhiyun 	FILE_SYSTEM_DEVICE_INFO fsDevInfo;
1135*4882a593Smuzhiyun 	FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo; /* ok if fs name truncated */
1136*4882a593Smuzhiyun 	FILE_SYSTEM_UNIX_INFO fsUnixInfo;
1137*4882a593Smuzhiyun 	bool ipc:1;   /* set if connection to IPC$ share (always also pipe) */
1138*4882a593Smuzhiyun 	bool pipe:1;  /* set if connection to pipe share */
1139*4882a593Smuzhiyun 	bool print:1; /* set if connection to printer share */
1140*4882a593Smuzhiyun 	bool retry:1;
1141*4882a593Smuzhiyun 	bool nocase:1;
1142*4882a593Smuzhiyun 	bool nohandlecache:1; /* if strange server resource prob can turn off */
1143*4882a593Smuzhiyun 	bool nodelete:1;
1144*4882a593Smuzhiyun 	bool seal:1;      /* transport encryption for this mounted share */
1145*4882a593Smuzhiyun 	bool unix_ext:1;  /* if false disable Linux extensions to CIFS protocol
1146*4882a593Smuzhiyun 				for this mount even if server would support */
1147*4882a593Smuzhiyun 	bool posix_extensions; /* if true SMB3.11 posix extensions enabled */
1148*4882a593Smuzhiyun 	bool local_lease:1; /* check leases (only) on local system not remote */
1149*4882a593Smuzhiyun 	bool broken_posix_open; /* e.g. Samba server versions < 3.3.2, 3.2.9 */
1150*4882a593Smuzhiyun 	bool broken_sparse_sup; /* if server or share does not support sparse */
1151*4882a593Smuzhiyun 	bool need_reconnect:1; /* connection reset, tid now invalid */
1152*4882a593Smuzhiyun 	bool need_reopen_files:1; /* need to reopen tcon file handles */
1153*4882a593Smuzhiyun 	bool use_resilient:1; /* use resilient instead of durable handles */
1154*4882a593Smuzhiyun 	bool use_persistent:1; /* use persistent instead of durable handles */
1155*4882a593Smuzhiyun 	bool no_lease:1;    /* Do not request leases on files or directories */
1156*4882a593Smuzhiyun 	__le32 capabilities;
1157*4882a593Smuzhiyun 	__u32 share_flags;
1158*4882a593Smuzhiyun 	__u32 maximal_access;
1159*4882a593Smuzhiyun 	__u32 vol_serial_number;
1160*4882a593Smuzhiyun 	__le64 vol_create_time;
1161*4882a593Smuzhiyun 	__u64 snapshot_time; /* for timewarp tokens - timestamp of snapshot */
1162*4882a593Smuzhiyun 	__u32 handle_timeout; /* persistent and durable handle timeout in ms */
1163*4882a593Smuzhiyun 	__u32 ss_flags;		/* sector size flags */
1164*4882a593Smuzhiyun 	__u32 perf_sector_size; /* best sector size for perf */
1165*4882a593Smuzhiyun 	__u32 max_chunks;
1166*4882a593Smuzhiyun 	__u32 max_bytes_chunk;
1167*4882a593Smuzhiyun 	__u32 max_bytes_copy;
1168*4882a593Smuzhiyun #ifdef CONFIG_CIFS_FSCACHE
1169*4882a593Smuzhiyun 	u64 resource_id;		/* server resource id */
1170*4882a593Smuzhiyun 	struct fscache_cookie *fscache;	/* cookie for share */
1171*4882a593Smuzhiyun #endif
1172*4882a593Smuzhiyun 	struct list_head pending_opens;	/* list of incomplete opens */
1173*4882a593Smuzhiyun 	struct cached_fid crfid; /* Cached root fid */
1174*4882a593Smuzhiyun 	/* BB add field for back pointer to sb struct(s)? */
1175*4882a593Smuzhiyun #ifdef CONFIG_CIFS_DFS_UPCALL
1176*4882a593Smuzhiyun 	char *dfs_path;
1177*4882a593Smuzhiyun 	int remap:2;
1178*4882a593Smuzhiyun 	struct list_head ulist; /* cache update list */
1179*4882a593Smuzhiyun #endif
1180*4882a593Smuzhiyun };
1181*4882a593Smuzhiyun 
1182*4882a593Smuzhiyun /*
1183*4882a593Smuzhiyun  * This is a refcounted and timestamped container for a tcon pointer. The
1184*4882a593Smuzhiyun  * container holds a tcon reference. It is considered safe to free one of
1185*4882a593Smuzhiyun  * these when the tl_count goes to 0. The tl_time is the time of the last
1186*4882a593Smuzhiyun  * "get" on the container.
1187*4882a593Smuzhiyun  */
1188*4882a593Smuzhiyun struct tcon_link {
1189*4882a593Smuzhiyun 	struct rb_node		tl_rbnode;
1190*4882a593Smuzhiyun 	kuid_t			tl_uid;
1191*4882a593Smuzhiyun 	unsigned long		tl_flags;
1192*4882a593Smuzhiyun #define TCON_LINK_MASTER	0
1193*4882a593Smuzhiyun #define TCON_LINK_PENDING	1
1194*4882a593Smuzhiyun #define TCON_LINK_IN_TREE	2
1195*4882a593Smuzhiyun 	unsigned long		tl_time;
1196*4882a593Smuzhiyun 	atomic_t		tl_count;
1197*4882a593Smuzhiyun 	struct cifs_tcon	*tl_tcon;
1198*4882a593Smuzhiyun };
1199*4882a593Smuzhiyun 
1200*4882a593Smuzhiyun extern struct tcon_link *cifs_sb_tlink(struct cifs_sb_info *cifs_sb);
1201*4882a593Smuzhiyun extern void smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst);
1202*4882a593Smuzhiyun 
1203*4882a593Smuzhiyun static inline struct cifs_tcon *
tlink_tcon(struct tcon_link * tlink)1204*4882a593Smuzhiyun tlink_tcon(struct tcon_link *tlink)
1205*4882a593Smuzhiyun {
1206*4882a593Smuzhiyun 	return tlink->tl_tcon;
1207*4882a593Smuzhiyun }
1208*4882a593Smuzhiyun 
1209*4882a593Smuzhiyun static inline struct tcon_link *
cifs_sb_master_tlink(struct cifs_sb_info * cifs_sb)1210*4882a593Smuzhiyun cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb)
1211*4882a593Smuzhiyun {
1212*4882a593Smuzhiyun 	return cifs_sb->master_tlink;
1213*4882a593Smuzhiyun }
1214*4882a593Smuzhiyun 
1215*4882a593Smuzhiyun extern void cifs_put_tlink(struct tcon_link *tlink);
1216*4882a593Smuzhiyun 
1217*4882a593Smuzhiyun static inline struct tcon_link *
cifs_get_tlink(struct tcon_link * tlink)1218*4882a593Smuzhiyun cifs_get_tlink(struct tcon_link *tlink)
1219*4882a593Smuzhiyun {
1220*4882a593Smuzhiyun 	if (tlink && !IS_ERR(tlink))
1221*4882a593Smuzhiyun 		atomic_inc(&tlink->tl_count);
1222*4882a593Smuzhiyun 	return tlink;
1223*4882a593Smuzhiyun }
1224*4882a593Smuzhiyun 
1225*4882a593Smuzhiyun /* This function is always expected to succeed */
1226*4882a593Smuzhiyun extern struct cifs_tcon *cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb);
1227*4882a593Smuzhiyun 
1228*4882a593Smuzhiyun #define CIFS_OPLOCK_NO_CHANGE 0xfe
1229*4882a593Smuzhiyun 
1230*4882a593Smuzhiyun struct cifs_pending_open {
1231*4882a593Smuzhiyun 	struct list_head olist;
1232*4882a593Smuzhiyun 	struct tcon_link *tlink;
1233*4882a593Smuzhiyun 	__u8 lease_key[16];
1234*4882a593Smuzhiyun 	__u32 oplock;
1235*4882a593Smuzhiyun };
1236*4882a593Smuzhiyun 
1237*4882a593Smuzhiyun /*
1238*4882a593Smuzhiyun  * This info hangs off the cifsFileInfo structure, pointed to by llist.
1239*4882a593Smuzhiyun  * This is used to track byte stream locks on the file
1240*4882a593Smuzhiyun  */
1241*4882a593Smuzhiyun struct cifsLockInfo {
1242*4882a593Smuzhiyun 	struct list_head llist;	/* pointer to next cifsLockInfo */
1243*4882a593Smuzhiyun 	struct list_head blist; /* pointer to locks blocked on this */
1244*4882a593Smuzhiyun 	wait_queue_head_t block_q;
1245*4882a593Smuzhiyun 	__u64 offset;
1246*4882a593Smuzhiyun 	__u64 length;
1247*4882a593Smuzhiyun 	__u32 pid;
1248*4882a593Smuzhiyun 	__u16 type;
1249*4882a593Smuzhiyun 	__u16 flags;
1250*4882a593Smuzhiyun };
1251*4882a593Smuzhiyun 
1252*4882a593Smuzhiyun /*
1253*4882a593Smuzhiyun  * One of these for each open instance of a file
1254*4882a593Smuzhiyun  */
1255*4882a593Smuzhiyun struct cifs_search_info {
1256*4882a593Smuzhiyun 	loff_t index_of_last_entry;
1257*4882a593Smuzhiyun 	__u16 entries_in_buffer;
1258*4882a593Smuzhiyun 	__u16 info_level;
1259*4882a593Smuzhiyun 	__u32 resume_key;
1260*4882a593Smuzhiyun 	char *ntwrk_buf_start;
1261*4882a593Smuzhiyun 	char *srch_entries_start;
1262*4882a593Smuzhiyun 	char *last_entry;
1263*4882a593Smuzhiyun 	const char *presume_name;
1264*4882a593Smuzhiyun 	unsigned int resume_name_len;
1265*4882a593Smuzhiyun 	bool endOfSearch:1;
1266*4882a593Smuzhiyun 	bool emptyDir:1;
1267*4882a593Smuzhiyun 	bool unicode:1;
1268*4882a593Smuzhiyun 	bool smallBuf:1; /* so we know which buf_release function to call */
1269*4882a593Smuzhiyun };
1270*4882a593Smuzhiyun 
1271*4882a593Smuzhiyun #define ACL_NO_MODE	((umode_t)(-1))
1272*4882a593Smuzhiyun struct cifs_open_parms {
1273*4882a593Smuzhiyun 	struct cifs_tcon *tcon;
1274*4882a593Smuzhiyun 	struct cifs_sb_info *cifs_sb;
1275*4882a593Smuzhiyun 	int disposition;
1276*4882a593Smuzhiyun 	int desired_access;
1277*4882a593Smuzhiyun 	int create_options;
1278*4882a593Smuzhiyun 	const char *path;
1279*4882a593Smuzhiyun 	struct cifs_fid *fid;
1280*4882a593Smuzhiyun 	umode_t mode;
1281*4882a593Smuzhiyun 	bool reconnect:1;
1282*4882a593Smuzhiyun };
1283*4882a593Smuzhiyun 
1284*4882a593Smuzhiyun struct cifs_fid {
1285*4882a593Smuzhiyun 	__u16 netfid;
1286*4882a593Smuzhiyun 	__u64 persistent_fid;	/* persist file id for smb2 */
1287*4882a593Smuzhiyun 	__u64 volatile_fid;	/* volatile file id for smb2 */
1288*4882a593Smuzhiyun 	__u8 lease_key[SMB2_LEASE_KEY_SIZE];	/* lease key for smb2 */
1289*4882a593Smuzhiyun 	__u8 create_guid[16];
1290*4882a593Smuzhiyun 	__u32 access;
1291*4882a593Smuzhiyun 	struct cifs_pending_open *pending_open;
1292*4882a593Smuzhiyun 	unsigned int epoch;
1293*4882a593Smuzhiyun #ifdef CONFIG_CIFS_DEBUG2
1294*4882a593Smuzhiyun 	__u64 mid;
1295*4882a593Smuzhiyun #endif /* CIFS_DEBUG2 */
1296*4882a593Smuzhiyun 	bool purge_cache;
1297*4882a593Smuzhiyun };
1298*4882a593Smuzhiyun 
1299*4882a593Smuzhiyun struct cifs_fid_locks {
1300*4882a593Smuzhiyun 	struct list_head llist;
1301*4882a593Smuzhiyun 	struct cifsFileInfo *cfile;	/* fid that owns locks */
1302*4882a593Smuzhiyun 	struct list_head locks;		/* locks held by fid above */
1303*4882a593Smuzhiyun };
1304*4882a593Smuzhiyun 
1305*4882a593Smuzhiyun struct cifsFileInfo {
1306*4882a593Smuzhiyun 	/* following two lists are protected by tcon->open_file_lock */
1307*4882a593Smuzhiyun 	struct list_head tlist;	/* pointer to next fid owned by tcon */
1308*4882a593Smuzhiyun 	struct list_head flist;	/* next fid (file instance) for this inode */
1309*4882a593Smuzhiyun 	/* lock list below protected by cifsi->lock_sem */
1310*4882a593Smuzhiyun 	struct cifs_fid_locks *llist;	/* brlocks held by this fid */
1311*4882a593Smuzhiyun 	kuid_t uid;		/* allows finding which FileInfo structure */
1312*4882a593Smuzhiyun 	__u32 pid;		/* process id who opened file */
1313*4882a593Smuzhiyun 	struct cifs_fid fid;	/* file id from remote */
1314*4882a593Smuzhiyun 	struct list_head rlist; /* reconnect list */
1315*4882a593Smuzhiyun 	/* BB add lock scope info here if needed */ ;
1316*4882a593Smuzhiyun 	/* lock scope id (0 if none) */
1317*4882a593Smuzhiyun 	struct dentry *dentry;
1318*4882a593Smuzhiyun 	struct tcon_link *tlink;
1319*4882a593Smuzhiyun 	unsigned int f_flags;
1320*4882a593Smuzhiyun 	bool invalidHandle:1;	/* file closed via session abend */
1321*4882a593Smuzhiyun 	bool swapfile:1;
1322*4882a593Smuzhiyun 	bool oplock_break_cancelled:1;
1323*4882a593Smuzhiyun 	unsigned int oplock_epoch; /* epoch from the lease break */
1324*4882a593Smuzhiyun 	__u32 oplock_level; /* oplock/lease level from the lease break */
1325*4882a593Smuzhiyun 	int count;
1326*4882a593Smuzhiyun 	spinlock_t file_info_lock; /* protects four flag/count fields above */
1327*4882a593Smuzhiyun 	struct mutex fh_mutex; /* prevents reopen race after dead ses*/
1328*4882a593Smuzhiyun 	struct cifs_search_info srch_inf;
1329*4882a593Smuzhiyun 	struct work_struct oplock_break; /* work for oplock breaks */
1330*4882a593Smuzhiyun 	struct work_struct put; /* work for the final part of _put */
1331*4882a593Smuzhiyun };
1332*4882a593Smuzhiyun 
1333*4882a593Smuzhiyun struct cifs_io_parms {
1334*4882a593Smuzhiyun 	__u16 netfid;
1335*4882a593Smuzhiyun 	__u64 persistent_fid;	/* persist file id for smb2 */
1336*4882a593Smuzhiyun 	__u64 volatile_fid;	/* volatile file id for smb2 */
1337*4882a593Smuzhiyun 	__u32 pid;
1338*4882a593Smuzhiyun 	__u64 offset;
1339*4882a593Smuzhiyun 	unsigned int length;
1340*4882a593Smuzhiyun 	struct cifs_tcon *tcon;
1341*4882a593Smuzhiyun 	struct TCP_Server_Info *server;
1342*4882a593Smuzhiyun };
1343*4882a593Smuzhiyun 
1344*4882a593Smuzhiyun struct cifs_aio_ctx {
1345*4882a593Smuzhiyun 	struct kref		refcount;
1346*4882a593Smuzhiyun 	struct list_head	list;
1347*4882a593Smuzhiyun 	struct mutex		aio_mutex;
1348*4882a593Smuzhiyun 	struct completion	done;
1349*4882a593Smuzhiyun 	struct iov_iter		iter;
1350*4882a593Smuzhiyun 	struct kiocb		*iocb;
1351*4882a593Smuzhiyun 	struct cifsFileInfo	*cfile;
1352*4882a593Smuzhiyun 	struct bio_vec		*bv;
1353*4882a593Smuzhiyun 	loff_t			pos;
1354*4882a593Smuzhiyun 	unsigned int		npages;
1355*4882a593Smuzhiyun 	ssize_t			rc;
1356*4882a593Smuzhiyun 	unsigned int		len;
1357*4882a593Smuzhiyun 	unsigned int		total_len;
1358*4882a593Smuzhiyun 	bool			should_dirty;
1359*4882a593Smuzhiyun 	/*
1360*4882a593Smuzhiyun 	 * Indicates if this aio_ctx is for direct_io,
1361*4882a593Smuzhiyun 	 * If yes, iter is a copy of the user passed iov_iter
1362*4882a593Smuzhiyun 	 */
1363*4882a593Smuzhiyun 	bool			direct_io;
1364*4882a593Smuzhiyun };
1365*4882a593Smuzhiyun 
1366*4882a593Smuzhiyun struct cifs_readdata;
1367*4882a593Smuzhiyun 
1368*4882a593Smuzhiyun /* asynchronous read support */
1369*4882a593Smuzhiyun struct cifs_readdata {
1370*4882a593Smuzhiyun 	struct kref			refcount;
1371*4882a593Smuzhiyun 	struct list_head		list;
1372*4882a593Smuzhiyun 	struct completion		done;
1373*4882a593Smuzhiyun 	struct cifsFileInfo		*cfile;
1374*4882a593Smuzhiyun 	struct address_space		*mapping;
1375*4882a593Smuzhiyun 	struct cifs_aio_ctx		*ctx;
1376*4882a593Smuzhiyun 	__u64				offset;
1377*4882a593Smuzhiyun 	unsigned int			bytes;
1378*4882a593Smuzhiyun 	unsigned int			got_bytes;
1379*4882a593Smuzhiyun 	pid_t				pid;
1380*4882a593Smuzhiyun 	int				result;
1381*4882a593Smuzhiyun 	struct work_struct		work;
1382*4882a593Smuzhiyun 	int (*read_into_pages)(struct TCP_Server_Info *server,
1383*4882a593Smuzhiyun 				struct cifs_readdata *rdata,
1384*4882a593Smuzhiyun 				unsigned int len);
1385*4882a593Smuzhiyun 	int (*copy_into_pages)(struct TCP_Server_Info *server,
1386*4882a593Smuzhiyun 				struct cifs_readdata *rdata,
1387*4882a593Smuzhiyun 				struct iov_iter *iter);
1388*4882a593Smuzhiyun 	struct kvec			iov[2];
1389*4882a593Smuzhiyun 	struct TCP_Server_Info		*server;
1390*4882a593Smuzhiyun #ifdef CONFIG_CIFS_SMB_DIRECT
1391*4882a593Smuzhiyun 	struct smbd_mr			*mr;
1392*4882a593Smuzhiyun #endif
1393*4882a593Smuzhiyun 	unsigned int			pagesz;
1394*4882a593Smuzhiyun 	unsigned int			page_offset;
1395*4882a593Smuzhiyun 	unsigned int			tailsz;
1396*4882a593Smuzhiyun 	struct cifs_credits		credits;
1397*4882a593Smuzhiyun 	unsigned int			nr_pages;
1398*4882a593Smuzhiyun 	struct page			**pages;
1399*4882a593Smuzhiyun };
1400*4882a593Smuzhiyun 
1401*4882a593Smuzhiyun struct cifs_writedata;
1402*4882a593Smuzhiyun 
1403*4882a593Smuzhiyun /* asynchronous write support */
1404*4882a593Smuzhiyun struct cifs_writedata {
1405*4882a593Smuzhiyun 	struct kref			refcount;
1406*4882a593Smuzhiyun 	struct list_head		list;
1407*4882a593Smuzhiyun 	struct completion		done;
1408*4882a593Smuzhiyun 	enum writeback_sync_modes	sync_mode;
1409*4882a593Smuzhiyun 	struct work_struct		work;
1410*4882a593Smuzhiyun 	struct cifsFileInfo		*cfile;
1411*4882a593Smuzhiyun 	struct cifs_aio_ctx		*ctx;
1412*4882a593Smuzhiyun 	__u64				offset;
1413*4882a593Smuzhiyun 	pid_t				pid;
1414*4882a593Smuzhiyun 	unsigned int			bytes;
1415*4882a593Smuzhiyun 	int				result;
1416*4882a593Smuzhiyun 	struct TCP_Server_Info		*server;
1417*4882a593Smuzhiyun #ifdef CONFIG_CIFS_SMB_DIRECT
1418*4882a593Smuzhiyun 	struct smbd_mr			*mr;
1419*4882a593Smuzhiyun #endif
1420*4882a593Smuzhiyun 	unsigned int			pagesz;
1421*4882a593Smuzhiyun 	unsigned int			page_offset;
1422*4882a593Smuzhiyun 	unsigned int			tailsz;
1423*4882a593Smuzhiyun 	struct cifs_credits		credits;
1424*4882a593Smuzhiyun 	unsigned int			nr_pages;
1425*4882a593Smuzhiyun 	struct page			**pages;
1426*4882a593Smuzhiyun };
1427*4882a593Smuzhiyun 
1428*4882a593Smuzhiyun /*
1429*4882a593Smuzhiyun  * Take a reference on the file private data. Must be called with
1430*4882a593Smuzhiyun  * cfile->file_info_lock held.
1431*4882a593Smuzhiyun  */
1432*4882a593Smuzhiyun static inline void
cifsFileInfo_get_locked(struct cifsFileInfo * cifs_file)1433*4882a593Smuzhiyun cifsFileInfo_get_locked(struct cifsFileInfo *cifs_file)
1434*4882a593Smuzhiyun {
1435*4882a593Smuzhiyun 	++cifs_file->count;
1436*4882a593Smuzhiyun }
1437*4882a593Smuzhiyun 
1438*4882a593Smuzhiyun struct cifsFileInfo *cifsFileInfo_get(struct cifsFileInfo *cifs_file);
1439*4882a593Smuzhiyun void _cifsFileInfo_put(struct cifsFileInfo *cifs_file, bool wait_oplock_hdlr,
1440*4882a593Smuzhiyun 		       bool offload);
1441*4882a593Smuzhiyun void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
1442*4882a593Smuzhiyun 
1443*4882a593Smuzhiyun #define CIFS_CACHE_READ_FLG	1
1444*4882a593Smuzhiyun #define CIFS_CACHE_HANDLE_FLG	2
1445*4882a593Smuzhiyun #define CIFS_CACHE_RH_FLG	(CIFS_CACHE_READ_FLG | CIFS_CACHE_HANDLE_FLG)
1446*4882a593Smuzhiyun #define CIFS_CACHE_WRITE_FLG	4
1447*4882a593Smuzhiyun #define CIFS_CACHE_RW_FLG	(CIFS_CACHE_READ_FLG | CIFS_CACHE_WRITE_FLG)
1448*4882a593Smuzhiyun #define CIFS_CACHE_RHW_FLG	(CIFS_CACHE_RW_FLG | CIFS_CACHE_HANDLE_FLG)
1449*4882a593Smuzhiyun 
1450*4882a593Smuzhiyun #define CIFS_CACHE_READ(cinode) ((cinode->oplock & CIFS_CACHE_READ_FLG) || (CIFS_SB(cinode->vfs_inode.i_sb)->mnt_cifs_flags & CIFS_MOUNT_RO_CACHE))
1451*4882a593Smuzhiyun #define CIFS_CACHE_HANDLE(cinode) (cinode->oplock & CIFS_CACHE_HANDLE_FLG)
1452*4882a593Smuzhiyun #define CIFS_CACHE_WRITE(cinode) ((cinode->oplock & CIFS_CACHE_WRITE_FLG) || (CIFS_SB(cinode->vfs_inode.i_sb)->mnt_cifs_flags & CIFS_MOUNT_RW_CACHE))
1453*4882a593Smuzhiyun 
1454*4882a593Smuzhiyun /*
1455*4882a593Smuzhiyun  * One of these for each file inode
1456*4882a593Smuzhiyun  */
1457*4882a593Smuzhiyun 
1458*4882a593Smuzhiyun struct cifsInodeInfo {
1459*4882a593Smuzhiyun 	bool can_cache_brlcks;
1460*4882a593Smuzhiyun 	struct list_head llist;	/* locks helb by this inode */
1461*4882a593Smuzhiyun 	/*
1462*4882a593Smuzhiyun 	 * NOTE: Some code paths call down_read(lock_sem) twice, so
1463*4882a593Smuzhiyun 	 * we must always use cifs_down_write() instead of down_write()
1464*4882a593Smuzhiyun 	 * for this semaphore to avoid deadlocks.
1465*4882a593Smuzhiyun 	 */
1466*4882a593Smuzhiyun 	struct rw_semaphore lock_sem;	/* protect the fields above */
1467*4882a593Smuzhiyun 	/* BB add in lists for dirty pages i.e. write caching info for oplock */
1468*4882a593Smuzhiyun 	struct list_head openFileList;
1469*4882a593Smuzhiyun 	spinlock_t	open_file_lock;	/* protects openFileList */
1470*4882a593Smuzhiyun 	__u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
1471*4882a593Smuzhiyun 	unsigned int oplock;		/* oplock/lease level we have */
1472*4882a593Smuzhiyun 	unsigned int epoch;		/* used to track lease state changes */
1473*4882a593Smuzhiyun #define CIFS_INODE_PENDING_OPLOCK_BREAK   (0) /* oplock break in progress */
1474*4882a593Smuzhiyun #define CIFS_INODE_PENDING_WRITERS	  (1) /* Writes in progress */
1475*4882a593Smuzhiyun #define CIFS_INODE_FLAG_UNUSED		  (2) /* Unused flag */
1476*4882a593Smuzhiyun #define CIFS_INO_DELETE_PENDING		  (3) /* delete pending on server */
1477*4882a593Smuzhiyun #define CIFS_INO_INVALID_MAPPING	  (4) /* pagecache is invalid */
1478*4882a593Smuzhiyun #define CIFS_INO_LOCK			  (5) /* lock bit for synchronization */
1479*4882a593Smuzhiyun 	unsigned long flags;
1480*4882a593Smuzhiyun 	spinlock_t writers_lock;
1481*4882a593Smuzhiyun 	unsigned int writers;		/* Number of writers on this inode */
1482*4882a593Smuzhiyun 	unsigned long time;		/* jiffies of last update of inode */
1483*4882a593Smuzhiyun 	u64  server_eof;		/* current file size on server -- protected by i_lock */
1484*4882a593Smuzhiyun 	u64  uniqueid;			/* server inode number */
1485*4882a593Smuzhiyun 	u64  createtime;		/* creation time on server */
1486*4882a593Smuzhiyun 	__u8 lease_key[SMB2_LEASE_KEY_SIZE];	/* lease key for this inode */
1487*4882a593Smuzhiyun #ifdef CONFIG_CIFS_FSCACHE
1488*4882a593Smuzhiyun 	struct fscache_cookie *fscache;
1489*4882a593Smuzhiyun #endif
1490*4882a593Smuzhiyun 	struct inode vfs_inode;
1491*4882a593Smuzhiyun };
1492*4882a593Smuzhiyun 
1493*4882a593Smuzhiyun static inline struct cifsInodeInfo *
CIFS_I(struct inode * inode)1494*4882a593Smuzhiyun CIFS_I(struct inode *inode)
1495*4882a593Smuzhiyun {
1496*4882a593Smuzhiyun 	return container_of(inode, struct cifsInodeInfo, vfs_inode);
1497*4882a593Smuzhiyun }
1498*4882a593Smuzhiyun 
1499*4882a593Smuzhiyun static inline struct cifs_sb_info *
CIFS_SB(struct super_block * sb)1500*4882a593Smuzhiyun CIFS_SB(struct super_block *sb)
1501*4882a593Smuzhiyun {
1502*4882a593Smuzhiyun 	return sb->s_fs_info;
1503*4882a593Smuzhiyun }
1504*4882a593Smuzhiyun 
1505*4882a593Smuzhiyun static inline struct cifs_sb_info *
CIFS_FILE_SB(struct file * file)1506*4882a593Smuzhiyun CIFS_FILE_SB(struct file *file)
1507*4882a593Smuzhiyun {
1508*4882a593Smuzhiyun 	return CIFS_SB(file_inode(file)->i_sb);
1509*4882a593Smuzhiyun }
1510*4882a593Smuzhiyun 
CIFS_DIR_SEP(const struct cifs_sb_info * cifs_sb)1511*4882a593Smuzhiyun static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
1512*4882a593Smuzhiyun {
1513*4882a593Smuzhiyun 	if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
1514*4882a593Smuzhiyun 		return '/';
1515*4882a593Smuzhiyun 	else
1516*4882a593Smuzhiyun 		return '\\';
1517*4882a593Smuzhiyun }
1518*4882a593Smuzhiyun 
1519*4882a593Smuzhiyun static inline void
convert_delimiter(char * path,char delim)1520*4882a593Smuzhiyun convert_delimiter(char *path, char delim)
1521*4882a593Smuzhiyun {
1522*4882a593Smuzhiyun 	char old_delim, *pos;
1523*4882a593Smuzhiyun 
1524*4882a593Smuzhiyun 	if (delim == '/')
1525*4882a593Smuzhiyun 		old_delim = '\\';
1526*4882a593Smuzhiyun 	else
1527*4882a593Smuzhiyun 		old_delim = '/';
1528*4882a593Smuzhiyun 
1529*4882a593Smuzhiyun 	pos = path;
1530*4882a593Smuzhiyun 	while ((pos = strchr(pos, old_delim)))
1531*4882a593Smuzhiyun 		*pos = delim;
1532*4882a593Smuzhiyun }
1533*4882a593Smuzhiyun 
1534*4882a593Smuzhiyun #define cifs_stats_inc atomic_inc
1535*4882a593Smuzhiyun 
cifs_stats_bytes_written(struct cifs_tcon * tcon,unsigned int bytes)1536*4882a593Smuzhiyun static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
1537*4882a593Smuzhiyun 					    unsigned int bytes)
1538*4882a593Smuzhiyun {
1539*4882a593Smuzhiyun 	if (bytes) {
1540*4882a593Smuzhiyun 		spin_lock(&tcon->stat_lock);
1541*4882a593Smuzhiyun 		tcon->bytes_written += bytes;
1542*4882a593Smuzhiyun 		spin_unlock(&tcon->stat_lock);
1543*4882a593Smuzhiyun 	}
1544*4882a593Smuzhiyun }
1545*4882a593Smuzhiyun 
cifs_stats_bytes_read(struct cifs_tcon * tcon,unsigned int bytes)1546*4882a593Smuzhiyun static inline void cifs_stats_bytes_read(struct cifs_tcon *tcon,
1547*4882a593Smuzhiyun 					 unsigned int bytes)
1548*4882a593Smuzhiyun {
1549*4882a593Smuzhiyun 	spin_lock(&tcon->stat_lock);
1550*4882a593Smuzhiyun 	tcon->bytes_read += bytes;
1551*4882a593Smuzhiyun 	spin_unlock(&tcon->stat_lock);
1552*4882a593Smuzhiyun }
1553*4882a593Smuzhiyun 
1554*4882a593Smuzhiyun 
1555*4882a593Smuzhiyun /*
1556*4882a593Smuzhiyun  * This is the prototype for the mid receive function. This function is for
1557*4882a593Smuzhiyun  * receiving the rest of the SMB frame, starting with the WordCount (which is
1558*4882a593Smuzhiyun  * just after the MID in struct smb_hdr). Note:
1559*4882a593Smuzhiyun  *
1560*4882a593Smuzhiyun  * - This will be called by cifsd, with no locks held.
1561*4882a593Smuzhiyun  * - The mid will still be on the pending_mid_q.
1562*4882a593Smuzhiyun  * - mid->resp_buf will point to the current buffer.
1563*4882a593Smuzhiyun  *
1564*4882a593Smuzhiyun  * Returns zero on a successful receive, or an error. The receive state in
1565*4882a593Smuzhiyun  * the TCP_Server_Info will also be updated.
1566*4882a593Smuzhiyun  */
1567*4882a593Smuzhiyun typedef int (mid_receive_t)(struct TCP_Server_Info *server,
1568*4882a593Smuzhiyun 			    struct mid_q_entry *mid);
1569*4882a593Smuzhiyun 
1570*4882a593Smuzhiyun /*
1571*4882a593Smuzhiyun  * This is the prototype for the mid callback function. This is called once the
1572*4882a593Smuzhiyun  * mid has been received off of the socket. When creating one, take special
1573*4882a593Smuzhiyun  * care to avoid deadlocks. Things to bear in mind:
1574*4882a593Smuzhiyun  *
1575*4882a593Smuzhiyun  * - it will be called by cifsd, with no locks held
1576*4882a593Smuzhiyun  * - the mid will be removed from any lists
1577*4882a593Smuzhiyun  */
1578*4882a593Smuzhiyun typedef void (mid_callback_t)(struct mid_q_entry *mid);
1579*4882a593Smuzhiyun 
1580*4882a593Smuzhiyun /*
1581*4882a593Smuzhiyun  * This is the protopyte for mid handle function. This is called once the mid
1582*4882a593Smuzhiyun  * has been recognized after decryption of the message.
1583*4882a593Smuzhiyun  */
1584*4882a593Smuzhiyun typedef int (mid_handle_t)(struct TCP_Server_Info *server,
1585*4882a593Smuzhiyun 			    struct mid_q_entry *mid);
1586*4882a593Smuzhiyun 
1587*4882a593Smuzhiyun /* one of these for every pending CIFS request to the server */
1588*4882a593Smuzhiyun struct mid_q_entry {
1589*4882a593Smuzhiyun 	struct list_head qhead;	/* mids waiting on reply from this server */
1590*4882a593Smuzhiyun 	struct kref refcount;
1591*4882a593Smuzhiyun 	struct TCP_Server_Info *server;	/* server corresponding to this mid */
1592*4882a593Smuzhiyun 	__u64 mid;		/* multiplex id */
1593*4882a593Smuzhiyun 	__u16 credits;		/* number of credits consumed by this mid */
1594*4882a593Smuzhiyun 	__u16 credits_received;	/* number of credits from the response */
1595*4882a593Smuzhiyun 	__u32 pid;		/* process id */
1596*4882a593Smuzhiyun 	__u32 sequence_number;  /* for CIFS signing */
1597*4882a593Smuzhiyun 	unsigned long when_alloc;  /* when mid was created */
1598*4882a593Smuzhiyun #ifdef CONFIG_CIFS_STATS2
1599*4882a593Smuzhiyun 	unsigned long when_sent; /* time when smb send finished */
1600*4882a593Smuzhiyun 	unsigned long when_received; /* when demux complete (taken off wire) */
1601*4882a593Smuzhiyun #endif
1602*4882a593Smuzhiyun 	mid_receive_t *receive; /* call receive callback */
1603*4882a593Smuzhiyun 	mid_callback_t *callback; /* call completion callback */
1604*4882a593Smuzhiyun 	mid_handle_t *handle; /* call handle mid callback */
1605*4882a593Smuzhiyun 	void *callback_data;	  /* general purpose pointer for callback */
1606*4882a593Smuzhiyun 	struct task_struct *creator;
1607*4882a593Smuzhiyun 	void *resp_buf;		/* pointer to received SMB header */
1608*4882a593Smuzhiyun 	unsigned int resp_buf_size;
1609*4882a593Smuzhiyun 	int mid_state;	/* wish this were enum but can not pass to wait_event */
1610*4882a593Smuzhiyun 	unsigned int mid_flags;
1611*4882a593Smuzhiyun 	__le16 command;		/* smb command code */
1612*4882a593Smuzhiyun 	unsigned int optype;	/* operation type */
1613*4882a593Smuzhiyun 	bool large_buf:1;	/* if valid response, is pointer to large buf */
1614*4882a593Smuzhiyun 	bool multiRsp:1;	/* multiple trans2 responses for one request  */
1615*4882a593Smuzhiyun 	bool multiEnd:1;	/* both received */
1616*4882a593Smuzhiyun 	bool decrypted:1;	/* decrypted entry */
1617*4882a593Smuzhiyun };
1618*4882a593Smuzhiyun 
1619*4882a593Smuzhiyun struct close_cancelled_open {
1620*4882a593Smuzhiyun 	struct cifs_fid         fid;
1621*4882a593Smuzhiyun 	struct cifs_tcon        *tcon;
1622*4882a593Smuzhiyun 	struct work_struct      work;
1623*4882a593Smuzhiyun 	__u64 mid;
1624*4882a593Smuzhiyun 	__u16 cmd;
1625*4882a593Smuzhiyun };
1626*4882a593Smuzhiyun 
1627*4882a593Smuzhiyun /*	Make code in transport.c a little cleaner by moving
1628*4882a593Smuzhiyun 	update of optional stats into function below */
cifs_in_send_inc(struct TCP_Server_Info * server)1629*4882a593Smuzhiyun static inline void cifs_in_send_inc(struct TCP_Server_Info *server)
1630*4882a593Smuzhiyun {
1631*4882a593Smuzhiyun 	atomic_inc(&server->in_send);
1632*4882a593Smuzhiyun }
1633*4882a593Smuzhiyun 
cifs_in_send_dec(struct TCP_Server_Info * server)1634*4882a593Smuzhiyun static inline void cifs_in_send_dec(struct TCP_Server_Info *server)
1635*4882a593Smuzhiyun {
1636*4882a593Smuzhiyun 	atomic_dec(&server->in_send);
1637*4882a593Smuzhiyun }
1638*4882a593Smuzhiyun 
cifs_num_waiters_inc(struct TCP_Server_Info * server)1639*4882a593Smuzhiyun static inline void cifs_num_waiters_inc(struct TCP_Server_Info *server)
1640*4882a593Smuzhiyun {
1641*4882a593Smuzhiyun 	atomic_inc(&server->num_waiters);
1642*4882a593Smuzhiyun }
1643*4882a593Smuzhiyun 
cifs_num_waiters_dec(struct TCP_Server_Info * server)1644*4882a593Smuzhiyun static inline void cifs_num_waiters_dec(struct TCP_Server_Info *server)
1645*4882a593Smuzhiyun {
1646*4882a593Smuzhiyun 	atomic_dec(&server->num_waiters);
1647*4882a593Smuzhiyun }
1648*4882a593Smuzhiyun 
1649*4882a593Smuzhiyun #ifdef CONFIG_CIFS_STATS2
cifs_save_when_sent(struct mid_q_entry * mid)1650*4882a593Smuzhiyun static inline void cifs_save_when_sent(struct mid_q_entry *mid)
1651*4882a593Smuzhiyun {
1652*4882a593Smuzhiyun 	mid->when_sent = jiffies;
1653*4882a593Smuzhiyun }
1654*4882a593Smuzhiyun #else
cifs_save_when_sent(struct mid_q_entry * mid)1655*4882a593Smuzhiyun static inline void cifs_save_when_sent(struct mid_q_entry *mid)
1656*4882a593Smuzhiyun {
1657*4882a593Smuzhiyun }
1658*4882a593Smuzhiyun #endif
1659*4882a593Smuzhiyun 
1660*4882a593Smuzhiyun /* for pending dnotify requests */
1661*4882a593Smuzhiyun struct dir_notify_req {
1662*4882a593Smuzhiyun 	struct list_head lhead;
1663*4882a593Smuzhiyun 	__le16 Pid;
1664*4882a593Smuzhiyun 	__le16 PidHigh;
1665*4882a593Smuzhiyun 	__u16 Mid;
1666*4882a593Smuzhiyun 	__u16 Tid;
1667*4882a593Smuzhiyun 	__u16 Uid;
1668*4882a593Smuzhiyun 	__u16 netfid;
1669*4882a593Smuzhiyun 	__u32 filter; /* CompletionFilter (for multishot) */
1670*4882a593Smuzhiyun 	int multishot;
1671*4882a593Smuzhiyun 	struct file *pfile;
1672*4882a593Smuzhiyun };
1673*4882a593Smuzhiyun 
1674*4882a593Smuzhiyun struct dfs_info3_param {
1675*4882a593Smuzhiyun 	int flags; /* DFSREF_REFERRAL_SERVER, DFSREF_STORAGE_SERVER*/
1676*4882a593Smuzhiyun 	int path_consumed;
1677*4882a593Smuzhiyun 	int server_type;
1678*4882a593Smuzhiyun 	int ref_flag;
1679*4882a593Smuzhiyun 	char *path_name;
1680*4882a593Smuzhiyun 	char *node_name;
1681*4882a593Smuzhiyun 	int ttl;
1682*4882a593Smuzhiyun };
1683*4882a593Smuzhiyun 
1684*4882a593Smuzhiyun /*
1685*4882a593Smuzhiyun  * common struct for holding inode info when searching for or updating an
1686*4882a593Smuzhiyun  * inode with new info
1687*4882a593Smuzhiyun  */
1688*4882a593Smuzhiyun 
1689*4882a593Smuzhiyun #define CIFS_FATTR_DFS_REFERRAL		0x1
1690*4882a593Smuzhiyun #define CIFS_FATTR_DELETE_PENDING	0x2
1691*4882a593Smuzhiyun #define CIFS_FATTR_NEED_REVAL		0x4
1692*4882a593Smuzhiyun #define CIFS_FATTR_INO_COLLISION	0x8
1693*4882a593Smuzhiyun #define CIFS_FATTR_UNKNOWN_NLINK	0x10
1694*4882a593Smuzhiyun #define CIFS_FATTR_FAKE_ROOT_INO	0x20
1695*4882a593Smuzhiyun 
1696*4882a593Smuzhiyun struct cifs_fattr {
1697*4882a593Smuzhiyun 	u32		cf_flags;
1698*4882a593Smuzhiyun 	u32		cf_cifsattrs;
1699*4882a593Smuzhiyun 	u64		cf_uniqueid;
1700*4882a593Smuzhiyun 	u64		cf_eof;
1701*4882a593Smuzhiyun 	u64		cf_bytes;
1702*4882a593Smuzhiyun 	u64		cf_createtime;
1703*4882a593Smuzhiyun 	kuid_t		cf_uid;
1704*4882a593Smuzhiyun 	kgid_t		cf_gid;
1705*4882a593Smuzhiyun 	umode_t		cf_mode;
1706*4882a593Smuzhiyun 	dev_t		cf_rdev;
1707*4882a593Smuzhiyun 	unsigned int	cf_nlink;
1708*4882a593Smuzhiyun 	unsigned int	cf_dtype;
1709*4882a593Smuzhiyun 	struct timespec64 cf_atime;
1710*4882a593Smuzhiyun 	struct timespec64 cf_mtime;
1711*4882a593Smuzhiyun 	struct timespec64 cf_ctime;
1712*4882a593Smuzhiyun 	u32             cf_cifstag;
1713*4882a593Smuzhiyun };
1714*4882a593Smuzhiyun 
free_dfs_info_param(struct dfs_info3_param * param)1715*4882a593Smuzhiyun static inline void free_dfs_info_param(struct dfs_info3_param *param)
1716*4882a593Smuzhiyun {
1717*4882a593Smuzhiyun 	if (param) {
1718*4882a593Smuzhiyun 		kfree(param->path_name);
1719*4882a593Smuzhiyun 		kfree(param->node_name);
1720*4882a593Smuzhiyun 	}
1721*4882a593Smuzhiyun }
1722*4882a593Smuzhiyun 
free_dfs_info_array(struct dfs_info3_param * param,int number_of_items)1723*4882a593Smuzhiyun static inline void free_dfs_info_array(struct dfs_info3_param *param,
1724*4882a593Smuzhiyun 				       int number_of_items)
1725*4882a593Smuzhiyun {
1726*4882a593Smuzhiyun 	int i;
1727*4882a593Smuzhiyun 	if ((number_of_items == 0) || (param == NULL))
1728*4882a593Smuzhiyun 		return;
1729*4882a593Smuzhiyun 	for (i = 0; i < number_of_items; i++) {
1730*4882a593Smuzhiyun 		kfree(param[i].path_name);
1731*4882a593Smuzhiyun 		kfree(param[i].node_name);
1732*4882a593Smuzhiyun 	}
1733*4882a593Smuzhiyun 	kfree(param);
1734*4882a593Smuzhiyun }
1735*4882a593Smuzhiyun 
is_interrupt_error(int error)1736*4882a593Smuzhiyun static inline bool is_interrupt_error(int error)
1737*4882a593Smuzhiyun {
1738*4882a593Smuzhiyun 	switch (error) {
1739*4882a593Smuzhiyun 	case -EINTR:
1740*4882a593Smuzhiyun 	case -ERESTARTSYS:
1741*4882a593Smuzhiyun 	case -ERESTARTNOHAND:
1742*4882a593Smuzhiyun 	case -ERESTARTNOINTR:
1743*4882a593Smuzhiyun 		return true;
1744*4882a593Smuzhiyun 	}
1745*4882a593Smuzhiyun 	return false;
1746*4882a593Smuzhiyun }
1747*4882a593Smuzhiyun 
is_retryable_error(int error)1748*4882a593Smuzhiyun static inline bool is_retryable_error(int error)
1749*4882a593Smuzhiyun {
1750*4882a593Smuzhiyun 	if (is_interrupt_error(error) || error == -EAGAIN)
1751*4882a593Smuzhiyun 		return true;
1752*4882a593Smuzhiyun 	return false;
1753*4882a593Smuzhiyun }
1754*4882a593Smuzhiyun 
1755*4882a593Smuzhiyun 
1756*4882a593Smuzhiyun /* cifs_get_writable_file() flags */
1757*4882a593Smuzhiyun #define FIND_WR_ANY         0
1758*4882a593Smuzhiyun #define FIND_WR_FSUID_ONLY  1
1759*4882a593Smuzhiyun #define FIND_WR_WITH_DELETE 2
1760*4882a593Smuzhiyun 
1761*4882a593Smuzhiyun #define   MID_FREE 0
1762*4882a593Smuzhiyun #define   MID_REQUEST_ALLOCATED 1
1763*4882a593Smuzhiyun #define   MID_REQUEST_SUBMITTED 2
1764*4882a593Smuzhiyun #define   MID_RESPONSE_RECEIVED 4
1765*4882a593Smuzhiyun #define   MID_RETRY_NEEDED      8 /* session closed while this request out */
1766*4882a593Smuzhiyun #define   MID_RESPONSE_MALFORMED 0x10
1767*4882a593Smuzhiyun #define   MID_SHUTDOWN		 0x20
1768*4882a593Smuzhiyun 
1769*4882a593Smuzhiyun /* Flags */
1770*4882a593Smuzhiyun #define   MID_WAIT_CANCELLED	 1 /* Cancelled while waiting for response */
1771*4882a593Smuzhiyun #define   MID_DELETED            2 /* Mid has been dequeued/deleted */
1772*4882a593Smuzhiyun 
1773*4882a593Smuzhiyun /* Types of response buffer returned from SendReceive2 */
1774*4882a593Smuzhiyun #define   CIFS_NO_BUFFER        0    /* Response buffer not returned */
1775*4882a593Smuzhiyun #define   CIFS_SMALL_BUFFER     1
1776*4882a593Smuzhiyun #define   CIFS_LARGE_BUFFER     2
1777*4882a593Smuzhiyun #define   CIFS_IOVEC            4    /* array of response buffers */
1778*4882a593Smuzhiyun 
1779*4882a593Smuzhiyun /* Type of Request to SendReceive2 */
1780*4882a593Smuzhiyun #define   CIFS_BLOCKING_OP      1    /* operation can block */
1781*4882a593Smuzhiyun #define   CIFS_NON_BLOCKING     2    /* do not block waiting for credits */
1782*4882a593Smuzhiyun #define   CIFS_TIMEOUT_MASK 0x003    /* only one of above set in req */
1783*4882a593Smuzhiyun #define   CIFS_LOG_ERROR    0x010    /* log NT STATUS if non-zero */
1784*4882a593Smuzhiyun #define   CIFS_LARGE_BUF_OP 0x020    /* large request buffer */
1785*4882a593Smuzhiyun #define   CIFS_NO_RSP_BUF   0x040    /* no response buffer required */
1786*4882a593Smuzhiyun 
1787*4882a593Smuzhiyun /* Type of request operation */
1788*4882a593Smuzhiyun #define   CIFS_ECHO_OP            0x080  /* echo request */
1789*4882a593Smuzhiyun #define   CIFS_OBREAK_OP          0x0100 /* oplock break request */
1790*4882a593Smuzhiyun #define   CIFS_NEG_OP             0x0200 /* negotiate request */
1791*4882a593Smuzhiyun #define   CIFS_CP_CREATE_CLOSE_OP 0x0400 /* compound create+close request */
1792*4882a593Smuzhiyun #define   CIFS_OP_MASK            0x0780 /* mask request type */
1793*4882a593Smuzhiyun 
1794*4882a593Smuzhiyun #define   CIFS_HAS_CREDITS 0x0400    /* already has credits */
1795*4882a593Smuzhiyun #define   CIFS_TRANSFORM_REQ 0x0800    /* transform request before sending */
1796*4882a593Smuzhiyun #define   CIFS_NO_SRV_RSP    0x1000    /* there is no server response */
1797*4882a593Smuzhiyun 
1798*4882a593Smuzhiyun /* Security Flags: indicate type of session setup needed */
1799*4882a593Smuzhiyun #define   CIFSSEC_MAY_SIGN	0x00001
1800*4882a593Smuzhiyun #define   CIFSSEC_MAY_NTLM	0x00002
1801*4882a593Smuzhiyun #define   CIFSSEC_MAY_NTLMV2	0x00004
1802*4882a593Smuzhiyun #define   CIFSSEC_MAY_KRB5	0x00008
1803*4882a593Smuzhiyun #ifdef CONFIG_CIFS_WEAK_PW_HASH
1804*4882a593Smuzhiyun #define   CIFSSEC_MAY_LANMAN	0x00010
1805*4882a593Smuzhiyun #define   CIFSSEC_MAY_PLNTXT	0x00020
1806*4882a593Smuzhiyun #else
1807*4882a593Smuzhiyun #define   CIFSSEC_MAY_LANMAN    0
1808*4882a593Smuzhiyun #define   CIFSSEC_MAY_PLNTXT    0
1809*4882a593Smuzhiyun #endif /* weak passwords */
1810*4882a593Smuzhiyun #define   CIFSSEC_MAY_SEAL	0x00040 /* not supported yet */
1811*4882a593Smuzhiyun #define   CIFSSEC_MAY_NTLMSSP	0x00080 /* raw ntlmssp with ntlmv2 */
1812*4882a593Smuzhiyun 
1813*4882a593Smuzhiyun #define   CIFSSEC_MUST_SIGN	0x01001
1814*4882a593Smuzhiyun /* note that only one of the following can be set so the
1815*4882a593Smuzhiyun result of setting MUST flags more than once will be to
1816*4882a593Smuzhiyun require use of the stronger protocol */
1817*4882a593Smuzhiyun #define   CIFSSEC_MUST_NTLM	0x02002
1818*4882a593Smuzhiyun #define   CIFSSEC_MUST_NTLMV2	0x04004
1819*4882a593Smuzhiyun #define   CIFSSEC_MUST_KRB5	0x08008
1820*4882a593Smuzhiyun #ifdef CONFIG_CIFS_WEAK_PW_HASH
1821*4882a593Smuzhiyun #define   CIFSSEC_MUST_LANMAN	0x10010
1822*4882a593Smuzhiyun #define   CIFSSEC_MUST_PLNTXT	0x20020
1823*4882a593Smuzhiyun #ifdef CONFIG_CIFS_UPCALL
1824*4882a593Smuzhiyun #define   CIFSSEC_MASK          0xBF0BF /* allows weak security but also krb5 */
1825*4882a593Smuzhiyun #else
1826*4882a593Smuzhiyun #define   CIFSSEC_MASK          0xB70B7 /* current flags supported if weak */
1827*4882a593Smuzhiyun #endif /* UPCALL */
1828*4882a593Smuzhiyun #else /* do not allow weak pw hash */
1829*4882a593Smuzhiyun #define   CIFSSEC_MUST_LANMAN	0
1830*4882a593Smuzhiyun #define   CIFSSEC_MUST_PLNTXT	0
1831*4882a593Smuzhiyun #ifdef CONFIG_CIFS_UPCALL
1832*4882a593Smuzhiyun #define   CIFSSEC_MASK          0x8F08F /* flags supported if no weak allowed */
1833*4882a593Smuzhiyun #else
1834*4882a593Smuzhiyun #define	  CIFSSEC_MASK          0x87087 /* flags supported if no weak allowed */
1835*4882a593Smuzhiyun #endif /* UPCALL */
1836*4882a593Smuzhiyun #endif /* WEAK_PW_HASH */
1837*4882a593Smuzhiyun #define   CIFSSEC_MUST_SEAL	0x40040 /* not supported yet */
1838*4882a593Smuzhiyun #define   CIFSSEC_MUST_NTLMSSP	0x80080 /* raw ntlmssp with ntlmv2 */
1839*4882a593Smuzhiyun 
1840*4882a593Smuzhiyun #define   CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_NTLMSSP)
1841*4882a593Smuzhiyun #define   CIFSSEC_MAX (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_NTLMV2)
1842*4882a593Smuzhiyun #define   CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_LANMAN | CIFSSEC_MAY_PLNTXT | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)
1843*4882a593Smuzhiyun /*
1844*4882a593Smuzhiyun  *****************************************************************
1845*4882a593Smuzhiyun  * All constants go here
1846*4882a593Smuzhiyun  *****************************************************************
1847*4882a593Smuzhiyun  */
1848*4882a593Smuzhiyun 
1849*4882a593Smuzhiyun #define UID_HASH (16)
1850*4882a593Smuzhiyun 
1851*4882a593Smuzhiyun /*
1852*4882a593Smuzhiyun  * Note that ONE module should define _DECLARE_GLOBALS_HERE to cause the
1853*4882a593Smuzhiyun  * following to be declared.
1854*4882a593Smuzhiyun  */
1855*4882a593Smuzhiyun 
1856*4882a593Smuzhiyun /****************************************************************************
1857*4882a593Smuzhiyun  *  Locking notes.  All updates to global variables and lists should be
1858*4882a593Smuzhiyun  *                  protected by spinlocks or semaphores.
1859*4882a593Smuzhiyun  *
1860*4882a593Smuzhiyun  *  Spinlocks
1861*4882a593Smuzhiyun  *  ---------
1862*4882a593Smuzhiyun  *  GlobalMid_Lock protects:
1863*4882a593Smuzhiyun  *	list operations on pending_mid_q and oplockQ
1864*4882a593Smuzhiyun  *      updates to XID counters, multiplex id  and SMB sequence numbers
1865*4882a593Smuzhiyun  *      list operations on global DnotifyReqList
1866*4882a593Smuzhiyun  *      updates to ses->status
1867*4882a593Smuzhiyun  *  tcp_ses_lock protects:
1868*4882a593Smuzhiyun  *	list operations on tcp and SMB session lists
1869*4882a593Smuzhiyun  *  tcon->open_file_lock protects the list of open files hanging off the tcon
1870*4882a593Smuzhiyun  *  inode->open_file_lock protects the openFileList hanging off the inode
1871*4882a593Smuzhiyun  *  cfile->file_info_lock protects counters and fields in cifs file struct
1872*4882a593Smuzhiyun  *  f_owner.lock protects certain per file struct operations
1873*4882a593Smuzhiyun  *  mapping->page_lock protects certain per page operations
1874*4882a593Smuzhiyun  *
1875*4882a593Smuzhiyun  *  Note that the cifs_tcon.open_file_lock should be taken before
1876*4882a593Smuzhiyun  *  not after the cifsInodeInfo.open_file_lock
1877*4882a593Smuzhiyun  *
1878*4882a593Smuzhiyun  *  Semaphores
1879*4882a593Smuzhiyun  *  ----------
1880*4882a593Smuzhiyun  *  sesSem     operations on smb session
1881*4882a593Smuzhiyun  *  tconSem    operations on tree connection
1882*4882a593Smuzhiyun  *  fh_sem      file handle reconnection operations
1883*4882a593Smuzhiyun  *
1884*4882a593Smuzhiyun  ****************************************************************************/
1885*4882a593Smuzhiyun 
1886*4882a593Smuzhiyun #ifdef DECLARE_GLOBALS_HERE
1887*4882a593Smuzhiyun #define GLOBAL_EXTERN
1888*4882a593Smuzhiyun #else
1889*4882a593Smuzhiyun #define GLOBAL_EXTERN extern
1890*4882a593Smuzhiyun #endif
1891*4882a593Smuzhiyun 
1892*4882a593Smuzhiyun /*
1893*4882a593Smuzhiyun  * the list of TCP_Server_Info structures, ie each of the sockets
1894*4882a593Smuzhiyun  * connecting our client to a distinct server (ip address), is
1895*4882a593Smuzhiyun  * chained together by cifs_tcp_ses_list. The list of all our SMB
1896*4882a593Smuzhiyun  * sessions (and from that the tree connections) can be found
1897*4882a593Smuzhiyun  * by iterating over cifs_tcp_ses_list
1898*4882a593Smuzhiyun  */
1899*4882a593Smuzhiyun GLOBAL_EXTERN struct list_head		cifs_tcp_ses_list;
1900*4882a593Smuzhiyun 
1901*4882a593Smuzhiyun /*
1902*4882a593Smuzhiyun  * This lock protects the cifs_tcp_ses_list, the list of smb sessions per
1903*4882a593Smuzhiyun  * tcp session, and the list of tcon's per smb session. It also protects
1904*4882a593Smuzhiyun  * the reference counters for the server, smb session, and tcon. It also
1905*4882a593Smuzhiyun  * protects some fields in the TCP_Server_Info struct such as dstaddr. Finally,
1906*4882a593Smuzhiyun  * changes to the tcon->tidStatus should be done while holding this lock.
1907*4882a593Smuzhiyun  * generally the locks should be taken in order tcp_ses_lock before
1908*4882a593Smuzhiyun  * tcon->open_file_lock and that before file->file_info_lock since the
1909*4882a593Smuzhiyun  * structure order is cifs_socket-->cifs_ses-->cifs_tcon-->cifs_file
1910*4882a593Smuzhiyun  */
1911*4882a593Smuzhiyun GLOBAL_EXTERN spinlock_t		cifs_tcp_ses_lock;
1912*4882a593Smuzhiyun 
1913*4882a593Smuzhiyun #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1914*4882a593Smuzhiyun /* Outstanding dir notify requests */
1915*4882a593Smuzhiyun GLOBAL_EXTERN struct list_head GlobalDnotifyReqList;
1916*4882a593Smuzhiyun /* DirNotify response queue */
1917*4882a593Smuzhiyun GLOBAL_EXTERN struct list_head GlobalDnotifyRsp_Q;
1918*4882a593Smuzhiyun #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1919*4882a593Smuzhiyun 
1920*4882a593Smuzhiyun /*
1921*4882a593Smuzhiyun  * Global transaction id (XID) information
1922*4882a593Smuzhiyun  */
1923*4882a593Smuzhiyun GLOBAL_EXTERN unsigned int GlobalCurrentXid;	/* protected by GlobalMid_Sem */
1924*4882a593Smuzhiyun GLOBAL_EXTERN unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
1925*4882a593Smuzhiyun GLOBAL_EXTERN unsigned int GlobalMaxActiveXid;	/* prot by GlobalMid_Sem */
1926*4882a593Smuzhiyun GLOBAL_EXTERN spinlock_t GlobalMid_Lock;  /* protects above & list operations */
1927*4882a593Smuzhiyun 					  /* on midQ entries */
1928*4882a593Smuzhiyun /*
1929*4882a593Smuzhiyun  *  Global counters, updated atomically
1930*4882a593Smuzhiyun  */
1931*4882a593Smuzhiyun GLOBAL_EXTERN atomic_t sesInfoAllocCount;
1932*4882a593Smuzhiyun GLOBAL_EXTERN atomic_t tconInfoAllocCount;
1933*4882a593Smuzhiyun GLOBAL_EXTERN atomic_t tcpSesAllocCount;
1934*4882a593Smuzhiyun GLOBAL_EXTERN atomic_t tcpSesReconnectCount;
1935*4882a593Smuzhiyun GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
1936*4882a593Smuzhiyun 
1937*4882a593Smuzhiyun /* Various Debug counters */
1938*4882a593Smuzhiyun GLOBAL_EXTERN atomic_t bufAllocCount;    /* current number allocated  */
1939*4882a593Smuzhiyun #ifdef CONFIG_CIFS_STATS2
1940*4882a593Smuzhiyun GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
1941*4882a593Smuzhiyun GLOBAL_EXTERN atomic_t totSmBufAllocCount;
1942*4882a593Smuzhiyun extern unsigned int slow_rsp_threshold; /* number of secs before logging */
1943*4882a593Smuzhiyun #endif
1944*4882a593Smuzhiyun GLOBAL_EXTERN atomic_t smBufAllocCount;
1945*4882a593Smuzhiyun GLOBAL_EXTERN atomic_t midCount;
1946*4882a593Smuzhiyun 
1947*4882a593Smuzhiyun /* Misc globals */
1948*4882a593Smuzhiyun extern bool enable_oplocks; /* enable or disable oplocks */
1949*4882a593Smuzhiyun extern bool lookupCacheEnabled;
1950*4882a593Smuzhiyun extern unsigned int global_secflags;	/* if on, session setup sent
1951*4882a593Smuzhiyun 				with more secure ntlmssp2 challenge/resp */
1952*4882a593Smuzhiyun extern unsigned int sign_CIFS_PDUs;  /* enable smb packet signing */
1953*4882a593Smuzhiyun extern bool enable_gcm_256; /* allow optional negotiate of strongest signing (aes-gcm-256) */
1954*4882a593Smuzhiyun extern bool require_gcm_256; /* require use of strongest signing (aes-gcm-256) */
1955*4882a593Smuzhiyun extern bool linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
1956*4882a593Smuzhiyun extern unsigned int CIFSMaxBufSize;  /* max size not including hdr */
1957*4882a593Smuzhiyun extern unsigned int cifs_min_rcv;    /* min size of big ntwrk buf pool */
1958*4882a593Smuzhiyun extern unsigned int cifs_min_small;  /* min size of small buf pool */
1959*4882a593Smuzhiyun extern unsigned int cifs_max_pending; /* MAX requests at once to server*/
1960*4882a593Smuzhiyun extern bool disable_legacy_dialects;  /* forbid vers=1.0 and vers=2.0 mounts */
1961*4882a593Smuzhiyun 
1962*4882a593Smuzhiyun GLOBAL_EXTERN struct rb_root uidtree;
1963*4882a593Smuzhiyun GLOBAL_EXTERN struct rb_root gidtree;
1964*4882a593Smuzhiyun GLOBAL_EXTERN spinlock_t siduidlock;
1965*4882a593Smuzhiyun GLOBAL_EXTERN spinlock_t sidgidlock;
1966*4882a593Smuzhiyun GLOBAL_EXTERN struct rb_root siduidtree;
1967*4882a593Smuzhiyun GLOBAL_EXTERN struct rb_root sidgidtree;
1968*4882a593Smuzhiyun GLOBAL_EXTERN spinlock_t uidsidlock;
1969*4882a593Smuzhiyun GLOBAL_EXTERN spinlock_t gidsidlock;
1970*4882a593Smuzhiyun 
1971*4882a593Smuzhiyun void cifs_oplock_break(struct work_struct *work);
1972*4882a593Smuzhiyun void cifs_queue_oplock_break(struct cifsFileInfo *cfile);
1973*4882a593Smuzhiyun 
1974*4882a593Smuzhiyun extern const struct slow_work_ops cifs_oplock_break_ops;
1975*4882a593Smuzhiyun extern struct workqueue_struct *cifsiod_wq;
1976*4882a593Smuzhiyun extern struct workqueue_struct *decrypt_wq;
1977*4882a593Smuzhiyun extern struct workqueue_struct *fileinfo_put_wq;
1978*4882a593Smuzhiyun extern struct workqueue_struct *cifsoplockd_wq;
1979*4882a593Smuzhiyun extern __u32 cifs_lock_secret;
1980*4882a593Smuzhiyun 
1981*4882a593Smuzhiyun extern mempool_t *cifs_mid_poolp;
1982*4882a593Smuzhiyun 
1983*4882a593Smuzhiyun /* Operations for different SMB versions */
1984*4882a593Smuzhiyun #define SMB1_VERSION_STRING	"1.0"
1985*4882a593Smuzhiyun #define SMB20_VERSION_STRING    "2.0"
1986*4882a593Smuzhiyun #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
1987*4882a593Smuzhiyun extern struct smb_version_operations smb1_operations;
1988*4882a593Smuzhiyun extern struct smb_version_values smb1_values;
1989*4882a593Smuzhiyun extern struct smb_version_operations smb20_operations;
1990*4882a593Smuzhiyun extern struct smb_version_values smb20_values;
1991*4882a593Smuzhiyun #endif /* CIFS_ALLOW_INSECURE_LEGACY */
1992*4882a593Smuzhiyun #define SMB21_VERSION_STRING	"2.1"
1993*4882a593Smuzhiyun extern struct smb_version_operations smb21_operations;
1994*4882a593Smuzhiyun extern struct smb_version_values smb21_values;
1995*4882a593Smuzhiyun #define SMBDEFAULT_VERSION_STRING "default"
1996*4882a593Smuzhiyun extern struct smb_version_values smbdefault_values;
1997*4882a593Smuzhiyun #define SMB3ANY_VERSION_STRING "3"
1998*4882a593Smuzhiyun extern struct smb_version_values smb3any_values;
1999*4882a593Smuzhiyun #define SMB30_VERSION_STRING	"3.0"
2000*4882a593Smuzhiyun extern struct smb_version_operations smb30_operations;
2001*4882a593Smuzhiyun extern struct smb_version_values smb30_values;
2002*4882a593Smuzhiyun #define SMB302_VERSION_STRING	"3.02"
2003*4882a593Smuzhiyun #define ALT_SMB302_VERSION_STRING "3.0.2"
2004*4882a593Smuzhiyun /*extern struct smb_version_operations smb302_operations;*/ /* not needed yet */
2005*4882a593Smuzhiyun extern struct smb_version_values smb302_values;
2006*4882a593Smuzhiyun #define SMB311_VERSION_STRING	"3.1.1"
2007*4882a593Smuzhiyun #define ALT_SMB311_VERSION_STRING "3.11"
2008*4882a593Smuzhiyun extern struct smb_version_operations smb311_operations;
2009*4882a593Smuzhiyun extern struct smb_version_values smb311_values;
2010*4882a593Smuzhiyun 
get_security_type_str(enum securityEnum sectype)2011*4882a593Smuzhiyun static inline char *get_security_type_str(enum securityEnum sectype)
2012*4882a593Smuzhiyun {
2013*4882a593Smuzhiyun 	switch (sectype) {
2014*4882a593Smuzhiyun 	case RawNTLMSSP:
2015*4882a593Smuzhiyun 		return "RawNTLMSSP";
2016*4882a593Smuzhiyun 	case Kerberos:
2017*4882a593Smuzhiyun 		return "Kerberos";
2018*4882a593Smuzhiyun 	case NTLMv2:
2019*4882a593Smuzhiyun 		return "NTLMv2";
2020*4882a593Smuzhiyun 	case NTLM:
2021*4882a593Smuzhiyun 		return "NTLM";
2022*4882a593Smuzhiyun 	case LANMAN:
2023*4882a593Smuzhiyun 		return "LANMAN";
2024*4882a593Smuzhiyun 	default:
2025*4882a593Smuzhiyun 		return "Unknown";
2026*4882a593Smuzhiyun 	}
2027*4882a593Smuzhiyun }
2028*4882a593Smuzhiyun 
is_smb1_server(struct TCP_Server_Info * server)2029*4882a593Smuzhiyun static inline bool is_smb1_server(struct TCP_Server_Info *server)
2030*4882a593Smuzhiyun {
2031*4882a593Smuzhiyun 	return strcmp(server->vals->version_string, SMB1_VERSION_STRING) == 0;
2032*4882a593Smuzhiyun }
2033*4882a593Smuzhiyun 
is_tcon_dfs(struct cifs_tcon * tcon)2034*4882a593Smuzhiyun static inline bool is_tcon_dfs(struct cifs_tcon *tcon)
2035*4882a593Smuzhiyun {
2036*4882a593Smuzhiyun 	/*
2037*4882a593Smuzhiyun 	 * For SMB1, see MS-CIFS 2.4.55 SMB_COM_TREE_CONNECT_ANDX (0x75) and MS-CIFS 3.3.4.4 DFS
2038*4882a593Smuzhiyun 	 * Subsystem Notifies That a Share Is a DFS Share.
2039*4882a593Smuzhiyun 	 *
2040*4882a593Smuzhiyun 	 * For SMB2+, see MS-SMB2 2.2.10 SMB2 TREE_CONNECT Response and MS-SMB2 3.3.4.14 Server
2041*4882a593Smuzhiyun 	 * Application Updates a Share.
2042*4882a593Smuzhiyun 	 */
2043*4882a593Smuzhiyun 	if (!tcon || !tcon->ses || !tcon->ses->server)
2044*4882a593Smuzhiyun 		return false;
2045*4882a593Smuzhiyun 	return is_smb1_server(tcon->ses->server) ? tcon->Flags & SMB_SHARE_IS_IN_DFS :
2046*4882a593Smuzhiyun 		tcon->share_flags & (SHI1005_FLAGS_DFS | SHI1005_FLAGS_DFS_ROOT);
2047*4882a593Smuzhiyun }
2048*4882a593Smuzhiyun 
2049*4882a593Smuzhiyun #endif	/* _CIFS_GLOB_H */
2050