162306a36Sopenharmony_ci/* SPDX-License-Identifier: LGPL-2.1 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (C) International Business Machines Corp., 2002,2008 562306a36Sopenharmony_ci * Author(s): Steve French (sfrench@us.ibm.com) 662306a36Sopenharmony_ci * Jeremy Allison (jra@samba.org) 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci#ifndef _CIFS_GLOB_H 1062306a36Sopenharmony_ci#define _CIFS_GLOB_H 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include <linux/in.h> 1362306a36Sopenharmony_ci#include <linux/in6.h> 1462306a36Sopenharmony_ci#include <linux/inet.h> 1562306a36Sopenharmony_ci#include <linux/slab.h> 1662306a36Sopenharmony_ci#include <linux/scatterlist.h> 1762306a36Sopenharmony_ci#include <linux/mm.h> 1862306a36Sopenharmony_ci#include <linux/mempool.h> 1962306a36Sopenharmony_ci#include <linux/workqueue.h> 2062306a36Sopenharmony_ci#include <linux/utsname.h> 2162306a36Sopenharmony_ci#include <linux/sched/mm.h> 2262306a36Sopenharmony_ci#include <linux/netfs.h> 2362306a36Sopenharmony_ci#include "cifs_fs_sb.h" 2462306a36Sopenharmony_ci#include "cifsacl.h" 2562306a36Sopenharmony_ci#include <crypto/internal/hash.h> 2662306a36Sopenharmony_ci#include <uapi/linux/cifs/cifs_mount.h> 2762306a36Sopenharmony_ci#include "../common/smb2pdu.h" 2862306a36Sopenharmony_ci#include "smb2pdu.h" 2962306a36Sopenharmony_ci#include <linux/filelock.h> 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#define SMB_PATH_MAX 260 3262306a36Sopenharmony_ci#define CIFS_PORT 445 3362306a36Sopenharmony_ci#define RFC1001_PORT 139 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci/* 3662306a36Sopenharmony_ci * The sizes of various internal tables and strings 3762306a36Sopenharmony_ci */ 3862306a36Sopenharmony_ci#define MAX_UID_INFO 16 3962306a36Sopenharmony_ci#define MAX_SES_INFO 2 4062306a36Sopenharmony_ci#define MAX_TCON_INFO 4 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci#define MAX_TREE_SIZE (2 + CIFS_NI_MAXHOST + 1 + CIFS_MAX_SHARE_LEN + 1) 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci#define CIFS_MIN_RCV_POOL 4 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#define MAX_REOPEN_ATT 5 /* these many maximum attempts to reopen a file */ 4762306a36Sopenharmony_ci/* 4862306a36Sopenharmony_ci * default attribute cache timeout (jiffies) 4962306a36Sopenharmony_ci */ 5062306a36Sopenharmony_ci#define CIFS_DEF_ACTIMEO (1 * HZ) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci/* 5362306a36Sopenharmony_ci * max attribute cache timeout (jiffies) - 2^30 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_ci#define CIFS_MAX_ACTIMEO (1 << 30) 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci/* 5862306a36Sopenharmony_ci * Max persistent and resilient handle timeout (milliseconds). 5962306a36Sopenharmony_ci * Windows durable max was 960000 (16 minutes) 6062306a36Sopenharmony_ci */ 6162306a36Sopenharmony_ci#define SMB3_MAX_HANDLE_TIMEOUT 960000 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci/* 6462306a36Sopenharmony_ci * MAX_REQ is the maximum number of requests that WE will send 6562306a36Sopenharmony_ci * on one socket concurrently. 6662306a36Sopenharmony_ci */ 6762306a36Sopenharmony_ci#define CIFS_MAX_REQ 32767 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#define RFC1001_NAME_LEN 15 7062306a36Sopenharmony_ci#define RFC1001_NAME_LEN_WITH_NULL (RFC1001_NAME_LEN + 1) 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci/* maximum length of ip addr as a string (including ipv6 and sctp) */ 7362306a36Sopenharmony_ci#define SERVER_NAME_LENGTH 80 7462306a36Sopenharmony_ci#define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1) 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci/* echo interval in seconds */ 7762306a36Sopenharmony_ci#define SMB_ECHO_INTERVAL_MIN 1 7862306a36Sopenharmony_ci#define SMB_ECHO_INTERVAL_MAX 600 7962306a36Sopenharmony_ci#define SMB_ECHO_INTERVAL_DEFAULT 60 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci/* smb multichannel query server interfaces interval in seconds */ 8262306a36Sopenharmony_ci#define SMB_INTERFACE_POLL_INTERVAL 600 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci/* maximum number of PDUs in one compound */ 8562306a36Sopenharmony_ci#define MAX_COMPOUND 7 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* 8862306a36Sopenharmony_ci * Default number of credits to keep available for SMB3. 8962306a36Sopenharmony_ci * This value is chosen somewhat arbitrarily. The Windows client 9062306a36Sopenharmony_ci * defaults to 128 credits, the Windows server allows clients up to 9162306a36Sopenharmony_ci * 512 credits (or 8K for later versions), and the NetApp server 9262306a36Sopenharmony_ci * does not limit clients at all. Choose a high enough default value 9362306a36Sopenharmony_ci * such that the client shouldn't limit performance, but allow mount 9462306a36Sopenharmony_ci * to override (until you approach 64K, where we limit credits to 65000 9562306a36Sopenharmony_ci * to reduce possibility of seeing more server credit overflow bugs. 9662306a36Sopenharmony_ci */ 9762306a36Sopenharmony_ci#define SMB2_MAX_CREDITS_AVAILABLE 32000 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci#include "cifspdu.h" 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#ifndef XATTR_DOS_ATTRIB 10262306a36Sopenharmony_ci#define XATTR_DOS_ATTRIB "user.DOSATTRIB" 10362306a36Sopenharmony_ci#endif 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci#define CIFS_MAX_WORKSTATION_LEN (__NEW_UTS_LEN + 1) /* reasonable max for client */ 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci#define CIFS_DFS_ROOT_SES(ses) ((ses)->dfs_root_ses ?: (ses)) 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci/* 11062306a36Sopenharmony_ci * CIFS vfs client Status information (based on what we know.) 11162306a36Sopenharmony_ci */ 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci/* associated with each connection */ 11462306a36Sopenharmony_cienum statusEnum { 11562306a36Sopenharmony_ci CifsNew = 0, 11662306a36Sopenharmony_ci CifsGood, 11762306a36Sopenharmony_ci CifsExiting, 11862306a36Sopenharmony_ci CifsNeedReconnect, 11962306a36Sopenharmony_ci CifsNeedNegotiate, 12062306a36Sopenharmony_ci CifsInNegotiate, 12162306a36Sopenharmony_ci}; 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci/* associated with each smb session */ 12462306a36Sopenharmony_cienum ses_status_enum { 12562306a36Sopenharmony_ci SES_NEW = 0, 12662306a36Sopenharmony_ci SES_GOOD, 12762306a36Sopenharmony_ci SES_EXITING, 12862306a36Sopenharmony_ci SES_NEED_RECON, 12962306a36Sopenharmony_ci SES_IN_SETUP 13062306a36Sopenharmony_ci}; 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci/* associated with each tree connection to the server */ 13362306a36Sopenharmony_cienum tid_status_enum { 13462306a36Sopenharmony_ci TID_NEW = 0, 13562306a36Sopenharmony_ci TID_GOOD, 13662306a36Sopenharmony_ci TID_EXITING, 13762306a36Sopenharmony_ci TID_NEED_RECON, 13862306a36Sopenharmony_ci TID_NEED_TCON, 13962306a36Sopenharmony_ci TID_IN_TCON, 14062306a36Sopenharmony_ci TID_NEED_FILES_INVALIDATE, /* currently unused */ 14162306a36Sopenharmony_ci TID_IN_FILES_INVALIDATE 14262306a36Sopenharmony_ci}; 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_cienum securityEnum { 14562306a36Sopenharmony_ci Unspecified = 0, /* not specified */ 14662306a36Sopenharmony_ci NTLMv2, /* Legacy NTLM auth with NTLMv2 hash */ 14762306a36Sopenharmony_ci RawNTLMSSP, /* NTLMSSP without SPNEGO, NTLMv2 hash */ 14862306a36Sopenharmony_ci Kerberos, /* Kerberos via SPNEGO */ 14962306a36Sopenharmony_ci}; 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_cistruct session_key { 15262306a36Sopenharmony_ci unsigned int len; 15362306a36Sopenharmony_ci char *response; 15462306a36Sopenharmony_ci}; 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci/* crypto hashing related structure/fields, not specific to a sec mech */ 15762306a36Sopenharmony_cistruct cifs_secmech { 15862306a36Sopenharmony_ci struct shash_desc *hmacmd5; /* hmacmd5 hash function, for NTLMv2/CR1 hashes */ 15962306a36Sopenharmony_ci struct shash_desc *md5; /* md5 hash function, for CIFS/SMB1 signatures */ 16062306a36Sopenharmony_ci struct shash_desc *hmacsha256; /* hmac-sha256 hash function, for SMB2 signatures */ 16162306a36Sopenharmony_ci struct shash_desc *sha512; /* sha512 hash function, for SMB3.1.1 preauth hash */ 16262306a36Sopenharmony_ci struct shash_desc *aes_cmac; /* block-cipher based MAC function, for SMB3 signatures */ 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci struct crypto_aead *enc; /* smb3 encryption AEAD TFM (AES-CCM and AES-GCM) */ 16562306a36Sopenharmony_ci struct crypto_aead *dec; /* smb3 decryption AEAD TFM (AES-CCM and AES-GCM) */ 16662306a36Sopenharmony_ci}; 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ci/* per smb session structure/fields */ 16962306a36Sopenharmony_cistruct ntlmssp_auth { 17062306a36Sopenharmony_ci bool sesskey_per_smbsess; /* whether session key is per smb session */ 17162306a36Sopenharmony_ci __u32 client_flags; /* sent by client in type 1 ntlmsssp exchange */ 17262306a36Sopenharmony_ci __u32 server_flags; /* sent by server in type 2 ntlmssp exchange */ 17362306a36Sopenharmony_ci unsigned char ciphertext[CIFS_CPHTXT_SIZE]; /* sent to server */ 17462306a36Sopenharmony_ci char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlmssp */ 17562306a36Sopenharmony_ci}; 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_cistruct cifs_cred { 17862306a36Sopenharmony_ci int uid; 17962306a36Sopenharmony_ci int gid; 18062306a36Sopenharmony_ci int mode; 18162306a36Sopenharmony_ci int cecount; 18262306a36Sopenharmony_ci struct cifs_sid osid; 18362306a36Sopenharmony_ci struct cifs_sid gsid; 18462306a36Sopenharmony_ci struct cifs_ntace *ntaces; 18562306a36Sopenharmony_ci struct cifs_ace *aces; 18662306a36Sopenharmony_ci}; 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_cistruct cifs_open_info_data { 18962306a36Sopenharmony_ci bool adjust_tz; 19062306a36Sopenharmony_ci union { 19162306a36Sopenharmony_ci bool reparse_point; 19262306a36Sopenharmony_ci bool symlink; 19362306a36Sopenharmony_ci }; 19462306a36Sopenharmony_ci struct { 19562306a36Sopenharmony_ci __u32 tag; 19662306a36Sopenharmony_ci union { 19762306a36Sopenharmony_ci struct reparse_data_buffer *buf; 19862306a36Sopenharmony_ci struct reparse_posix_data *posix; 19962306a36Sopenharmony_ci }; 20062306a36Sopenharmony_ci } reparse; 20162306a36Sopenharmony_ci char *symlink_target; 20262306a36Sopenharmony_ci union { 20362306a36Sopenharmony_ci struct smb2_file_all_info fi; 20462306a36Sopenharmony_ci struct smb311_posix_qinfo posix_fi; 20562306a36Sopenharmony_ci }; 20662306a36Sopenharmony_ci}; 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_cistatic inline bool cifs_open_data_reparse(struct cifs_open_info_data *data) 20962306a36Sopenharmony_ci{ 21062306a36Sopenharmony_ci struct smb2_file_all_info *fi = &data->fi; 21162306a36Sopenharmony_ci u32 attrs = le32_to_cpu(fi->Attributes); 21262306a36Sopenharmony_ci bool ret; 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci ret = data->reparse_point || (attrs & ATTR_REPARSE); 21562306a36Sopenharmony_ci if (ret) 21662306a36Sopenharmony_ci attrs |= ATTR_REPARSE; 21762306a36Sopenharmony_ci fi->Attributes = cpu_to_le32(attrs); 21862306a36Sopenharmony_ci return ret; 21962306a36Sopenharmony_ci} 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_cistatic inline void cifs_free_open_info(struct cifs_open_info_data *data) 22262306a36Sopenharmony_ci{ 22362306a36Sopenharmony_ci kfree(data->symlink_target); 22462306a36Sopenharmony_ci} 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci/* 22762306a36Sopenharmony_ci ***************************************************************** 22862306a36Sopenharmony_ci * Except the CIFS PDUs themselves all the 22962306a36Sopenharmony_ci * globally interesting structs should go here 23062306a36Sopenharmony_ci ***************************************************************** 23162306a36Sopenharmony_ci */ 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci/* 23462306a36Sopenharmony_ci * A smb_rqst represents a complete request to be issued to a server. It's 23562306a36Sopenharmony_ci * formed by a kvec array, followed by an array of pages. Page data is assumed 23662306a36Sopenharmony_ci * to start at the beginning of the first page. 23762306a36Sopenharmony_ci */ 23862306a36Sopenharmony_cistruct smb_rqst { 23962306a36Sopenharmony_ci struct kvec *rq_iov; /* array of kvecs */ 24062306a36Sopenharmony_ci unsigned int rq_nvec; /* number of kvecs in array */ 24162306a36Sopenharmony_ci size_t rq_iter_size; /* Amount of data in ->rq_iter */ 24262306a36Sopenharmony_ci struct iov_iter rq_iter; /* Data iterator */ 24362306a36Sopenharmony_ci struct xarray rq_buffer; /* Page buffer for encryption */ 24462306a36Sopenharmony_ci}; 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_cistruct mid_q_entry; 24762306a36Sopenharmony_cistruct TCP_Server_Info; 24862306a36Sopenharmony_cistruct cifsFileInfo; 24962306a36Sopenharmony_cistruct cifs_ses; 25062306a36Sopenharmony_cistruct cifs_tcon; 25162306a36Sopenharmony_cistruct dfs_info3_param; 25262306a36Sopenharmony_cistruct cifs_fattr; 25362306a36Sopenharmony_cistruct smb3_fs_context; 25462306a36Sopenharmony_cistruct cifs_fid; 25562306a36Sopenharmony_cistruct cifs_readdata; 25662306a36Sopenharmony_cistruct cifs_writedata; 25762306a36Sopenharmony_cistruct cifs_io_parms; 25862306a36Sopenharmony_cistruct cifs_search_info; 25962306a36Sopenharmony_cistruct cifsInodeInfo; 26062306a36Sopenharmony_cistruct cifs_open_parms; 26162306a36Sopenharmony_cistruct cifs_credits; 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_cistruct smb_version_operations { 26462306a36Sopenharmony_ci int (*send_cancel)(struct TCP_Server_Info *, struct smb_rqst *, 26562306a36Sopenharmony_ci struct mid_q_entry *); 26662306a36Sopenharmony_ci bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *); 26762306a36Sopenharmony_ci /* setup request: allocate mid, sign message */ 26862306a36Sopenharmony_ci struct mid_q_entry *(*setup_request)(struct cifs_ses *, 26962306a36Sopenharmony_ci struct TCP_Server_Info *, 27062306a36Sopenharmony_ci struct smb_rqst *); 27162306a36Sopenharmony_ci /* setup async request: allocate mid, sign message */ 27262306a36Sopenharmony_ci struct mid_q_entry *(*setup_async_request)(struct TCP_Server_Info *, 27362306a36Sopenharmony_ci struct smb_rqst *); 27462306a36Sopenharmony_ci /* check response: verify signature, map error */ 27562306a36Sopenharmony_ci int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *, 27662306a36Sopenharmony_ci bool); 27762306a36Sopenharmony_ci void (*add_credits)(struct TCP_Server_Info *server, 27862306a36Sopenharmony_ci const struct cifs_credits *credits, 27962306a36Sopenharmony_ci const int optype); 28062306a36Sopenharmony_ci void (*set_credits)(struct TCP_Server_Info *, const int); 28162306a36Sopenharmony_ci int * (*get_credits_field)(struct TCP_Server_Info *, const int); 28262306a36Sopenharmony_ci unsigned int (*get_credits)(struct mid_q_entry *); 28362306a36Sopenharmony_ci __u64 (*get_next_mid)(struct TCP_Server_Info *); 28462306a36Sopenharmony_ci void (*revert_current_mid)(struct TCP_Server_Info *server, 28562306a36Sopenharmony_ci const unsigned int val); 28662306a36Sopenharmony_ci /* data offset from read response message */ 28762306a36Sopenharmony_ci unsigned int (*read_data_offset)(char *); 28862306a36Sopenharmony_ci /* 28962306a36Sopenharmony_ci * Data length from read response message 29062306a36Sopenharmony_ci * When in_remaining is true, the returned data length is in 29162306a36Sopenharmony_ci * message field DataRemaining for out-of-band data read (e.g through 29262306a36Sopenharmony_ci * Memory Registration RDMA write in SMBD). 29362306a36Sopenharmony_ci * Otherwise, the returned data length is in message field DataLength. 29462306a36Sopenharmony_ci */ 29562306a36Sopenharmony_ci unsigned int (*read_data_length)(char *, bool in_remaining); 29662306a36Sopenharmony_ci /* map smb to linux error */ 29762306a36Sopenharmony_ci int (*map_error)(char *, bool); 29862306a36Sopenharmony_ci /* find mid corresponding to the response message */ 29962306a36Sopenharmony_ci struct mid_q_entry * (*find_mid)(struct TCP_Server_Info *, char *); 30062306a36Sopenharmony_ci void (*dump_detail)(void *buf, struct TCP_Server_Info *ptcp_info); 30162306a36Sopenharmony_ci void (*clear_stats)(struct cifs_tcon *); 30262306a36Sopenharmony_ci void (*print_stats)(struct seq_file *m, struct cifs_tcon *); 30362306a36Sopenharmony_ci void (*dump_share_caps)(struct seq_file *, struct cifs_tcon *); 30462306a36Sopenharmony_ci /* verify the message */ 30562306a36Sopenharmony_ci int (*check_message)(char *, unsigned int, struct TCP_Server_Info *); 30662306a36Sopenharmony_ci bool (*is_oplock_break)(char *, struct TCP_Server_Info *); 30762306a36Sopenharmony_ci int (*handle_cancelled_mid)(struct mid_q_entry *, struct TCP_Server_Info *); 30862306a36Sopenharmony_ci void (*downgrade_oplock)(struct TCP_Server_Info *server, 30962306a36Sopenharmony_ci struct cifsInodeInfo *cinode, __u32 oplock, 31062306a36Sopenharmony_ci unsigned int epoch, bool *purge_cache); 31162306a36Sopenharmony_ci /* process transaction2 response */ 31262306a36Sopenharmony_ci bool (*check_trans2)(struct mid_q_entry *, struct TCP_Server_Info *, 31362306a36Sopenharmony_ci char *, int); 31462306a36Sopenharmony_ci /* check if we need to negotiate */ 31562306a36Sopenharmony_ci bool (*need_neg)(struct TCP_Server_Info *); 31662306a36Sopenharmony_ci /* negotiate to the server */ 31762306a36Sopenharmony_ci int (*negotiate)(const unsigned int xid, 31862306a36Sopenharmony_ci struct cifs_ses *ses, 31962306a36Sopenharmony_ci struct TCP_Server_Info *server); 32062306a36Sopenharmony_ci /* set negotiated write size */ 32162306a36Sopenharmony_ci unsigned int (*negotiate_wsize)(struct cifs_tcon *tcon, struct smb3_fs_context *ctx); 32262306a36Sopenharmony_ci /* set negotiated read size */ 32362306a36Sopenharmony_ci unsigned int (*negotiate_rsize)(struct cifs_tcon *tcon, struct smb3_fs_context *ctx); 32462306a36Sopenharmony_ci /* setup smb sessionn */ 32562306a36Sopenharmony_ci int (*sess_setup)(const unsigned int, struct cifs_ses *, 32662306a36Sopenharmony_ci struct TCP_Server_Info *server, 32762306a36Sopenharmony_ci const struct nls_table *); 32862306a36Sopenharmony_ci /* close smb session */ 32962306a36Sopenharmony_ci int (*logoff)(const unsigned int, struct cifs_ses *); 33062306a36Sopenharmony_ci /* connect to a server share */ 33162306a36Sopenharmony_ci int (*tree_connect)(const unsigned int, struct cifs_ses *, const char *, 33262306a36Sopenharmony_ci struct cifs_tcon *, const struct nls_table *); 33362306a36Sopenharmony_ci /* close tree connecion */ 33462306a36Sopenharmony_ci int (*tree_disconnect)(const unsigned int, struct cifs_tcon *); 33562306a36Sopenharmony_ci /* get DFS referrals */ 33662306a36Sopenharmony_ci int (*get_dfs_refer)(const unsigned int, struct cifs_ses *, 33762306a36Sopenharmony_ci const char *, struct dfs_info3_param **, 33862306a36Sopenharmony_ci unsigned int *, const struct nls_table *, int); 33962306a36Sopenharmony_ci /* informational QFS call */ 34062306a36Sopenharmony_ci void (*qfs_tcon)(const unsigned int, struct cifs_tcon *, 34162306a36Sopenharmony_ci struct cifs_sb_info *); 34262306a36Sopenharmony_ci /* check if a path is accessible or not */ 34362306a36Sopenharmony_ci int (*is_path_accessible)(const unsigned int, struct cifs_tcon *, 34462306a36Sopenharmony_ci struct cifs_sb_info *, const char *); 34562306a36Sopenharmony_ci /* query path data from the server */ 34662306a36Sopenharmony_ci int (*query_path_info)(const unsigned int xid, 34762306a36Sopenharmony_ci struct cifs_tcon *tcon, 34862306a36Sopenharmony_ci struct cifs_sb_info *cifs_sb, 34962306a36Sopenharmony_ci const char *full_path, 35062306a36Sopenharmony_ci struct cifs_open_info_data *data); 35162306a36Sopenharmony_ci /* query file data from the server */ 35262306a36Sopenharmony_ci int (*query_file_info)(const unsigned int xid, struct cifs_tcon *tcon, 35362306a36Sopenharmony_ci struct cifsFileInfo *cfile, struct cifs_open_info_data *data); 35462306a36Sopenharmony_ci /* query reparse point to determine which type of special file */ 35562306a36Sopenharmony_ci int (*query_reparse_point)(const unsigned int xid, 35662306a36Sopenharmony_ci struct cifs_tcon *tcon, 35762306a36Sopenharmony_ci struct cifs_sb_info *cifs_sb, 35862306a36Sopenharmony_ci const char *full_path, 35962306a36Sopenharmony_ci u32 *tag, struct kvec *rsp, 36062306a36Sopenharmony_ci int *rsp_buftype); 36162306a36Sopenharmony_ci /* get server index number */ 36262306a36Sopenharmony_ci int (*get_srv_inum)(const unsigned int xid, struct cifs_tcon *tcon, 36362306a36Sopenharmony_ci struct cifs_sb_info *cifs_sb, const char *full_path, u64 *uniqueid, 36462306a36Sopenharmony_ci struct cifs_open_info_data *data); 36562306a36Sopenharmony_ci /* set size by path */ 36662306a36Sopenharmony_ci int (*set_path_size)(const unsigned int, struct cifs_tcon *, 36762306a36Sopenharmony_ci const char *, __u64, struct cifs_sb_info *, bool); 36862306a36Sopenharmony_ci /* set size by file handle */ 36962306a36Sopenharmony_ci int (*set_file_size)(const unsigned int, struct cifs_tcon *, 37062306a36Sopenharmony_ci struct cifsFileInfo *, __u64, bool); 37162306a36Sopenharmony_ci /* set attributes */ 37262306a36Sopenharmony_ci int (*set_file_info)(struct inode *, const char *, FILE_BASIC_INFO *, 37362306a36Sopenharmony_ci const unsigned int); 37462306a36Sopenharmony_ci int (*set_compression)(const unsigned int, struct cifs_tcon *, 37562306a36Sopenharmony_ci struct cifsFileInfo *); 37662306a36Sopenharmony_ci /* check if we can send an echo or nor */ 37762306a36Sopenharmony_ci bool (*can_echo)(struct TCP_Server_Info *); 37862306a36Sopenharmony_ci /* send echo request */ 37962306a36Sopenharmony_ci int (*echo)(struct TCP_Server_Info *); 38062306a36Sopenharmony_ci /* create directory */ 38162306a36Sopenharmony_ci int (*posix_mkdir)(const unsigned int xid, struct inode *inode, 38262306a36Sopenharmony_ci umode_t mode, struct cifs_tcon *tcon, 38362306a36Sopenharmony_ci const char *full_path, 38462306a36Sopenharmony_ci struct cifs_sb_info *cifs_sb); 38562306a36Sopenharmony_ci int (*mkdir)(const unsigned int xid, struct inode *inode, umode_t mode, 38662306a36Sopenharmony_ci struct cifs_tcon *tcon, const char *name, 38762306a36Sopenharmony_ci struct cifs_sb_info *sb); 38862306a36Sopenharmony_ci /* set info on created directory */ 38962306a36Sopenharmony_ci void (*mkdir_setinfo)(struct inode *, const char *, 39062306a36Sopenharmony_ci struct cifs_sb_info *, struct cifs_tcon *, 39162306a36Sopenharmony_ci const unsigned int); 39262306a36Sopenharmony_ci /* remove directory */ 39362306a36Sopenharmony_ci int (*rmdir)(const unsigned int, struct cifs_tcon *, const char *, 39462306a36Sopenharmony_ci struct cifs_sb_info *); 39562306a36Sopenharmony_ci /* unlink file */ 39662306a36Sopenharmony_ci int (*unlink)(const unsigned int, struct cifs_tcon *, const char *, 39762306a36Sopenharmony_ci struct cifs_sb_info *); 39862306a36Sopenharmony_ci /* open, rename and delete file */ 39962306a36Sopenharmony_ci int (*rename_pending_delete)(const char *, struct dentry *, 40062306a36Sopenharmony_ci const unsigned int); 40162306a36Sopenharmony_ci /* send rename request */ 40262306a36Sopenharmony_ci int (*rename)(const unsigned int xid, 40362306a36Sopenharmony_ci struct cifs_tcon *tcon, 40462306a36Sopenharmony_ci struct dentry *source_dentry, 40562306a36Sopenharmony_ci const char *from_name, const char *to_name, 40662306a36Sopenharmony_ci struct cifs_sb_info *cifs_sb); 40762306a36Sopenharmony_ci /* send create hardlink request */ 40862306a36Sopenharmony_ci int (*create_hardlink)(const unsigned int xid, 40962306a36Sopenharmony_ci struct cifs_tcon *tcon, 41062306a36Sopenharmony_ci struct dentry *source_dentry, 41162306a36Sopenharmony_ci const char *from_name, const char *to_name, 41262306a36Sopenharmony_ci struct cifs_sb_info *cifs_sb); 41362306a36Sopenharmony_ci /* query symlink target */ 41462306a36Sopenharmony_ci int (*query_symlink)(const unsigned int xid, 41562306a36Sopenharmony_ci struct cifs_tcon *tcon, 41662306a36Sopenharmony_ci struct cifs_sb_info *cifs_sb, 41762306a36Sopenharmony_ci const char *full_path, 41862306a36Sopenharmony_ci char **target_path); 41962306a36Sopenharmony_ci /* open a file for non-posix mounts */ 42062306a36Sopenharmony_ci int (*open)(const unsigned int xid, struct cifs_open_parms *oparms, __u32 *oplock, 42162306a36Sopenharmony_ci void *buf); 42262306a36Sopenharmony_ci /* set fid protocol-specific info */ 42362306a36Sopenharmony_ci void (*set_fid)(struct cifsFileInfo *, struct cifs_fid *, __u32); 42462306a36Sopenharmony_ci /* close a file */ 42562306a36Sopenharmony_ci void (*close)(const unsigned int, struct cifs_tcon *, 42662306a36Sopenharmony_ci struct cifs_fid *); 42762306a36Sopenharmony_ci /* close a file, returning file attributes and timestamps */ 42862306a36Sopenharmony_ci void (*close_getattr)(const unsigned int xid, struct cifs_tcon *tcon, 42962306a36Sopenharmony_ci struct cifsFileInfo *pfile_info); 43062306a36Sopenharmony_ci /* send a flush request to the server */ 43162306a36Sopenharmony_ci int (*flush)(const unsigned int, struct cifs_tcon *, struct cifs_fid *); 43262306a36Sopenharmony_ci /* async read from the server */ 43362306a36Sopenharmony_ci int (*async_readv)(struct cifs_readdata *); 43462306a36Sopenharmony_ci /* async write to the server */ 43562306a36Sopenharmony_ci int (*async_writev)(struct cifs_writedata *, 43662306a36Sopenharmony_ci void (*release)(struct kref *)); 43762306a36Sopenharmony_ci /* sync read from the server */ 43862306a36Sopenharmony_ci int (*sync_read)(const unsigned int, struct cifs_fid *, 43962306a36Sopenharmony_ci struct cifs_io_parms *, unsigned int *, char **, 44062306a36Sopenharmony_ci int *); 44162306a36Sopenharmony_ci /* sync write to the server */ 44262306a36Sopenharmony_ci int (*sync_write)(const unsigned int, struct cifs_fid *, 44362306a36Sopenharmony_ci struct cifs_io_parms *, unsigned int *, struct kvec *, 44462306a36Sopenharmony_ci unsigned long); 44562306a36Sopenharmony_ci /* open dir, start readdir */ 44662306a36Sopenharmony_ci int (*query_dir_first)(const unsigned int, struct cifs_tcon *, 44762306a36Sopenharmony_ci const char *, struct cifs_sb_info *, 44862306a36Sopenharmony_ci struct cifs_fid *, __u16, 44962306a36Sopenharmony_ci struct cifs_search_info *); 45062306a36Sopenharmony_ci /* continue readdir */ 45162306a36Sopenharmony_ci int (*query_dir_next)(const unsigned int, struct cifs_tcon *, 45262306a36Sopenharmony_ci struct cifs_fid *, 45362306a36Sopenharmony_ci __u16, struct cifs_search_info *srch_inf); 45462306a36Sopenharmony_ci /* close dir */ 45562306a36Sopenharmony_ci int (*close_dir)(const unsigned int, struct cifs_tcon *, 45662306a36Sopenharmony_ci struct cifs_fid *); 45762306a36Sopenharmony_ci /* calculate a size of SMB message */ 45862306a36Sopenharmony_ci unsigned int (*calc_smb_size)(void *buf); 45962306a36Sopenharmony_ci /* check for STATUS_PENDING and process the response if yes */ 46062306a36Sopenharmony_ci bool (*is_status_pending)(char *buf, struct TCP_Server_Info *server); 46162306a36Sopenharmony_ci /* check for STATUS_NETWORK_SESSION_EXPIRED */ 46262306a36Sopenharmony_ci bool (*is_session_expired)(char *); 46362306a36Sopenharmony_ci /* send oplock break response */ 46462306a36Sopenharmony_ci int (*oplock_response)(struct cifs_tcon *tcon, __u64 persistent_fid, __u64 volatile_fid, 46562306a36Sopenharmony_ci __u16 net_fid, struct cifsInodeInfo *cifs_inode); 46662306a36Sopenharmony_ci /* query remote filesystem */ 46762306a36Sopenharmony_ci int (*queryfs)(const unsigned int, struct cifs_tcon *, 46862306a36Sopenharmony_ci struct cifs_sb_info *, struct kstatfs *); 46962306a36Sopenharmony_ci /* send mandatory brlock to the server */ 47062306a36Sopenharmony_ci int (*mand_lock)(const unsigned int, struct cifsFileInfo *, __u64, 47162306a36Sopenharmony_ci __u64, __u32, int, int, bool); 47262306a36Sopenharmony_ci /* unlock range of mandatory locks */ 47362306a36Sopenharmony_ci int (*mand_unlock_range)(struct cifsFileInfo *, struct file_lock *, 47462306a36Sopenharmony_ci const unsigned int); 47562306a36Sopenharmony_ci /* push brlocks from the cache to the server */ 47662306a36Sopenharmony_ci int (*push_mand_locks)(struct cifsFileInfo *); 47762306a36Sopenharmony_ci /* get lease key of the inode */ 47862306a36Sopenharmony_ci void (*get_lease_key)(struct inode *, struct cifs_fid *); 47962306a36Sopenharmony_ci /* set lease key of the inode */ 48062306a36Sopenharmony_ci void (*set_lease_key)(struct inode *, struct cifs_fid *); 48162306a36Sopenharmony_ci /* generate new lease key */ 48262306a36Sopenharmony_ci void (*new_lease_key)(struct cifs_fid *); 48362306a36Sopenharmony_ci int (*generate_signingkey)(struct cifs_ses *ses, 48462306a36Sopenharmony_ci struct TCP_Server_Info *server); 48562306a36Sopenharmony_ci int (*calc_signature)(struct smb_rqst *, struct TCP_Server_Info *, 48662306a36Sopenharmony_ci bool allocate_crypto); 48762306a36Sopenharmony_ci int (*set_integrity)(const unsigned int, struct cifs_tcon *tcon, 48862306a36Sopenharmony_ci struct cifsFileInfo *src_file); 48962306a36Sopenharmony_ci int (*enum_snapshots)(const unsigned int xid, struct cifs_tcon *tcon, 49062306a36Sopenharmony_ci struct cifsFileInfo *src_file, void __user *); 49162306a36Sopenharmony_ci int (*notify)(const unsigned int xid, struct file *pfile, 49262306a36Sopenharmony_ci void __user *pbuf, bool return_changes); 49362306a36Sopenharmony_ci int (*query_mf_symlink)(unsigned int, struct cifs_tcon *, 49462306a36Sopenharmony_ci struct cifs_sb_info *, const unsigned char *, 49562306a36Sopenharmony_ci char *, unsigned int *); 49662306a36Sopenharmony_ci int (*create_mf_symlink)(unsigned int, struct cifs_tcon *, 49762306a36Sopenharmony_ci struct cifs_sb_info *, const unsigned char *, 49862306a36Sopenharmony_ci char *, unsigned int *); 49962306a36Sopenharmony_ci /* if we can do cache read operations */ 50062306a36Sopenharmony_ci bool (*is_read_op)(__u32); 50162306a36Sopenharmony_ci /* set oplock level for the inode */ 50262306a36Sopenharmony_ci void (*set_oplock_level)(struct cifsInodeInfo *, __u32, unsigned int, 50362306a36Sopenharmony_ci bool *); 50462306a36Sopenharmony_ci /* create lease context buffer for CREATE request */ 50562306a36Sopenharmony_ci char * (*create_lease_buf)(u8 *lease_key, u8 oplock); 50662306a36Sopenharmony_ci /* parse lease context buffer and return oplock/epoch info */ 50762306a36Sopenharmony_ci __u8 (*parse_lease_buf)(void *buf, unsigned int *epoch, char *lkey); 50862306a36Sopenharmony_ci ssize_t (*copychunk_range)(const unsigned int, 50962306a36Sopenharmony_ci struct cifsFileInfo *src_file, 51062306a36Sopenharmony_ci struct cifsFileInfo *target_file, 51162306a36Sopenharmony_ci u64 src_off, u64 len, u64 dest_off); 51262306a36Sopenharmony_ci int (*duplicate_extents)(const unsigned int, struct cifsFileInfo *src, 51362306a36Sopenharmony_ci struct cifsFileInfo *target_file, u64 src_off, u64 len, 51462306a36Sopenharmony_ci u64 dest_off); 51562306a36Sopenharmony_ci int (*validate_negotiate)(const unsigned int, struct cifs_tcon *); 51662306a36Sopenharmony_ci ssize_t (*query_all_EAs)(const unsigned int, struct cifs_tcon *, 51762306a36Sopenharmony_ci const unsigned char *, const unsigned char *, char *, 51862306a36Sopenharmony_ci size_t, struct cifs_sb_info *); 51962306a36Sopenharmony_ci int (*set_EA)(const unsigned int, struct cifs_tcon *, const char *, 52062306a36Sopenharmony_ci const char *, const void *, const __u16, 52162306a36Sopenharmony_ci const struct nls_table *, struct cifs_sb_info *); 52262306a36Sopenharmony_ci struct cifs_ntsd * (*get_acl)(struct cifs_sb_info *, struct inode *, 52362306a36Sopenharmony_ci const char *, u32 *, u32); 52462306a36Sopenharmony_ci struct cifs_ntsd * (*get_acl_by_fid)(struct cifs_sb_info *, 52562306a36Sopenharmony_ci const struct cifs_fid *, u32 *, u32); 52662306a36Sopenharmony_ci int (*set_acl)(struct cifs_ntsd *, __u32, struct inode *, const char *, 52762306a36Sopenharmony_ci int); 52862306a36Sopenharmony_ci /* writepages retry size */ 52962306a36Sopenharmony_ci unsigned int (*wp_retry_size)(struct inode *); 53062306a36Sopenharmony_ci /* get mtu credits */ 53162306a36Sopenharmony_ci int (*wait_mtu_credits)(struct TCP_Server_Info *, unsigned int, 53262306a36Sopenharmony_ci unsigned int *, struct cifs_credits *); 53362306a36Sopenharmony_ci /* adjust previously taken mtu credits to request size */ 53462306a36Sopenharmony_ci int (*adjust_credits)(struct TCP_Server_Info *server, 53562306a36Sopenharmony_ci struct cifs_credits *credits, 53662306a36Sopenharmony_ci const unsigned int payload_size); 53762306a36Sopenharmony_ci /* check if we need to issue closedir */ 53862306a36Sopenharmony_ci bool (*dir_needs_close)(struct cifsFileInfo *); 53962306a36Sopenharmony_ci long (*fallocate)(struct file *, struct cifs_tcon *, int, loff_t, 54062306a36Sopenharmony_ci loff_t); 54162306a36Sopenharmony_ci /* init transform request - used for encryption for now */ 54262306a36Sopenharmony_ci int (*init_transform_rq)(struct TCP_Server_Info *, int num_rqst, 54362306a36Sopenharmony_ci struct smb_rqst *, struct smb_rqst *); 54462306a36Sopenharmony_ci int (*is_transform_hdr)(void *buf); 54562306a36Sopenharmony_ci int (*receive_transform)(struct TCP_Server_Info *, 54662306a36Sopenharmony_ci struct mid_q_entry **, char **, int *); 54762306a36Sopenharmony_ci enum securityEnum (*select_sectype)(struct TCP_Server_Info *, 54862306a36Sopenharmony_ci enum securityEnum); 54962306a36Sopenharmony_ci int (*next_header)(struct TCP_Server_Info *server, char *buf, 55062306a36Sopenharmony_ci unsigned int *noff); 55162306a36Sopenharmony_ci /* ioctl passthrough for query_info */ 55262306a36Sopenharmony_ci int (*ioctl_query_info)(const unsigned int xid, 55362306a36Sopenharmony_ci struct cifs_tcon *tcon, 55462306a36Sopenharmony_ci struct cifs_sb_info *cifs_sb, 55562306a36Sopenharmony_ci __le16 *path, int is_dir, 55662306a36Sopenharmony_ci unsigned long p); 55762306a36Sopenharmony_ci /* make unix special files (block, char, fifo, socket) */ 55862306a36Sopenharmony_ci int (*make_node)(unsigned int xid, 55962306a36Sopenharmony_ci struct inode *inode, 56062306a36Sopenharmony_ci struct dentry *dentry, 56162306a36Sopenharmony_ci struct cifs_tcon *tcon, 56262306a36Sopenharmony_ci const char *full_path, 56362306a36Sopenharmony_ci umode_t mode, 56462306a36Sopenharmony_ci dev_t device_number); 56562306a36Sopenharmony_ci /* version specific fiemap implementation */ 56662306a36Sopenharmony_ci int (*fiemap)(struct cifs_tcon *tcon, struct cifsFileInfo *, 56762306a36Sopenharmony_ci struct fiemap_extent_info *, u64, u64); 56862306a36Sopenharmony_ci /* version specific llseek implementation */ 56962306a36Sopenharmony_ci loff_t (*llseek)(struct file *, struct cifs_tcon *, loff_t, int); 57062306a36Sopenharmony_ci /* Check for STATUS_IO_TIMEOUT */ 57162306a36Sopenharmony_ci bool (*is_status_io_timeout)(char *buf); 57262306a36Sopenharmony_ci /* Check for STATUS_NETWORK_NAME_DELETED */ 57362306a36Sopenharmony_ci bool (*is_network_name_deleted)(char *buf, struct TCP_Server_Info *srv); 57462306a36Sopenharmony_ci int (*parse_reparse_point)(struct cifs_sb_info *cifs_sb, 57562306a36Sopenharmony_ci struct kvec *rsp_iov, 57662306a36Sopenharmony_ci struct cifs_open_info_data *data); 57762306a36Sopenharmony_ci}; 57862306a36Sopenharmony_ci 57962306a36Sopenharmony_cistruct smb_version_values { 58062306a36Sopenharmony_ci char *version_string; 58162306a36Sopenharmony_ci __u16 protocol_id; 58262306a36Sopenharmony_ci __u32 req_capabilities; 58362306a36Sopenharmony_ci __u32 large_lock_type; 58462306a36Sopenharmony_ci __u32 exclusive_lock_type; 58562306a36Sopenharmony_ci __u32 shared_lock_type; 58662306a36Sopenharmony_ci __u32 unlock_lock_type; 58762306a36Sopenharmony_ci size_t header_preamble_size; 58862306a36Sopenharmony_ci size_t header_size; 58962306a36Sopenharmony_ci size_t max_header_size; 59062306a36Sopenharmony_ci size_t read_rsp_size; 59162306a36Sopenharmony_ci __le16 lock_cmd; 59262306a36Sopenharmony_ci unsigned int cap_unix; 59362306a36Sopenharmony_ci unsigned int cap_nt_find; 59462306a36Sopenharmony_ci unsigned int cap_large_files; 59562306a36Sopenharmony_ci __u16 signing_enabled; 59662306a36Sopenharmony_ci __u16 signing_required; 59762306a36Sopenharmony_ci size_t create_lease_size; 59862306a36Sopenharmony_ci}; 59962306a36Sopenharmony_ci 60062306a36Sopenharmony_ci#define HEADER_SIZE(server) (server->vals->header_size) 60162306a36Sopenharmony_ci#define MAX_HEADER_SIZE(server) (server->vals->max_header_size) 60262306a36Sopenharmony_ci#define HEADER_PREAMBLE_SIZE(server) (server->vals->header_preamble_size) 60362306a36Sopenharmony_ci#define MID_HEADER_SIZE(server) (HEADER_SIZE(server) - 1 - HEADER_PREAMBLE_SIZE(server)) 60462306a36Sopenharmony_ci 60562306a36Sopenharmony_ci/** 60662306a36Sopenharmony_ci * CIFS superblock mount flags (mnt_cifs_flags) to consider when 60762306a36Sopenharmony_ci * trying to reuse existing superblock for a new mount 60862306a36Sopenharmony_ci */ 60962306a36Sopenharmony_ci#define CIFS_MOUNT_MASK (CIFS_MOUNT_NO_PERM | CIFS_MOUNT_SET_UID | \ 61062306a36Sopenharmony_ci CIFS_MOUNT_SERVER_INUM | CIFS_MOUNT_DIRECT_IO | \ 61162306a36Sopenharmony_ci CIFS_MOUNT_NO_XATTR | CIFS_MOUNT_MAP_SPECIAL_CHR | \ 61262306a36Sopenharmony_ci CIFS_MOUNT_MAP_SFM_CHR | \ 61362306a36Sopenharmony_ci CIFS_MOUNT_UNX_EMUL | CIFS_MOUNT_NO_BRL | \ 61462306a36Sopenharmony_ci CIFS_MOUNT_CIFS_ACL | CIFS_MOUNT_OVERR_UID | \ 61562306a36Sopenharmony_ci CIFS_MOUNT_OVERR_GID | CIFS_MOUNT_DYNPERM | \ 61662306a36Sopenharmony_ci CIFS_MOUNT_NOPOSIXBRL | CIFS_MOUNT_NOSSYNC | \ 61762306a36Sopenharmony_ci CIFS_MOUNT_FSCACHE | CIFS_MOUNT_MF_SYMLINKS | \ 61862306a36Sopenharmony_ci CIFS_MOUNT_MULTIUSER | CIFS_MOUNT_STRICT_IO | \ 61962306a36Sopenharmony_ci CIFS_MOUNT_CIFS_BACKUPUID | CIFS_MOUNT_CIFS_BACKUPGID | \ 62062306a36Sopenharmony_ci CIFS_MOUNT_UID_FROM_ACL | CIFS_MOUNT_NO_HANDLE_CACHE | \ 62162306a36Sopenharmony_ci CIFS_MOUNT_NO_DFS | CIFS_MOUNT_MODE_FROM_SID | \ 62262306a36Sopenharmony_ci CIFS_MOUNT_RO_CACHE | CIFS_MOUNT_RW_CACHE) 62362306a36Sopenharmony_ci 62462306a36Sopenharmony_ci/** 62562306a36Sopenharmony_ci * Generic VFS superblock mount flags (s_flags) to consider when 62662306a36Sopenharmony_ci * trying to reuse existing superblock for a new mount 62762306a36Sopenharmony_ci */ 62862306a36Sopenharmony_ci#define CIFS_MS_MASK (SB_RDONLY | SB_MANDLOCK | SB_NOEXEC | SB_NOSUID | \ 62962306a36Sopenharmony_ci SB_NODEV | SB_SYNCHRONOUS) 63062306a36Sopenharmony_ci 63162306a36Sopenharmony_cistruct cifs_mnt_data { 63262306a36Sopenharmony_ci struct cifs_sb_info *cifs_sb; 63362306a36Sopenharmony_ci struct smb3_fs_context *ctx; 63462306a36Sopenharmony_ci int flags; 63562306a36Sopenharmony_ci}; 63662306a36Sopenharmony_ci 63762306a36Sopenharmony_cistatic inline unsigned int 63862306a36Sopenharmony_ciget_rfc1002_length(void *buf) 63962306a36Sopenharmony_ci{ 64062306a36Sopenharmony_ci return be32_to_cpu(*((__be32 *)buf)) & 0xffffff; 64162306a36Sopenharmony_ci} 64262306a36Sopenharmony_ci 64362306a36Sopenharmony_cistatic inline void 64462306a36Sopenharmony_ciinc_rfc1001_len(void *buf, int count) 64562306a36Sopenharmony_ci{ 64662306a36Sopenharmony_ci be32_add_cpu((__be32 *)buf, count); 64762306a36Sopenharmony_ci} 64862306a36Sopenharmony_ci 64962306a36Sopenharmony_cistruct TCP_Server_Info { 65062306a36Sopenharmony_ci struct list_head tcp_ses_list; 65162306a36Sopenharmony_ci struct list_head smb_ses_list; 65262306a36Sopenharmony_ci spinlock_t srv_lock; /* protect anything here that is not protected */ 65362306a36Sopenharmony_ci __u64 conn_id; /* connection identifier (useful for debugging) */ 65462306a36Sopenharmony_ci int srv_count; /* reference counter */ 65562306a36Sopenharmony_ci /* 15 character server name + 0x20 16th byte indicating type = srv */ 65662306a36Sopenharmony_ci char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; 65762306a36Sopenharmony_ci struct smb_version_operations *ops; 65862306a36Sopenharmony_ci struct smb_version_values *vals; 65962306a36Sopenharmony_ci /* updates to tcpStatus protected by cifs_tcp_ses_lock */ 66062306a36Sopenharmony_ci enum statusEnum tcpStatus; /* what we think the status is */ 66162306a36Sopenharmony_ci char *hostname; /* hostname portion of UNC string */ 66262306a36Sopenharmony_ci struct socket *ssocket; 66362306a36Sopenharmony_ci struct sockaddr_storage dstaddr; 66462306a36Sopenharmony_ci struct sockaddr_storage srcaddr; /* locally bind to this IP */ 66562306a36Sopenharmony_ci#ifdef CONFIG_NET_NS 66662306a36Sopenharmony_ci struct net *net; 66762306a36Sopenharmony_ci#endif 66862306a36Sopenharmony_ci wait_queue_head_t response_q; 66962306a36Sopenharmony_ci wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/ 67062306a36Sopenharmony_ci spinlock_t mid_lock; /* protect mid queue and it's entries */ 67162306a36Sopenharmony_ci struct list_head pending_mid_q; 67262306a36Sopenharmony_ci bool noblocksnd; /* use blocking sendmsg */ 67362306a36Sopenharmony_ci bool noautotune; /* do not autotune send buf sizes */ 67462306a36Sopenharmony_ci bool nosharesock; 67562306a36Sopenharmony_ci bool tcp_nodelay; 67662306a36Sopenharmony_ci bool terminate; 67762306a36Sopenharmony_ci unsigned int credits; /* send no more requests at once */ 67862306a36Sopenharmony_ci unsigned int max_credits; /* can override large 32000 default at mnt */ 67962306a36Sopenharmony_ci unsigned int in_flight; /* number of requests on the wire to server */ 68062306a36Sopenharmony_ci unsigned int max_in_flight; /* max number of requests that were on wire */ 68162306a36Sopenharmony_ci spinlock_t req_lock; /* protect the two values above */ 68262306a36Sopenharmony_ci struct mutex _srv_mutex; 68362306a36Sopenharmony_ci unsigned int nofs_flag; 68462306a36Sopenharmony_ci struct task_struct *tsk; 68562306a36Sopenharmony_ci char server_GUID[16]; 68662306a36Sopenharmony_ci __u16 sec_mode; 68762306a36Sopenharmony_ci bool sign; /* is signing enabled on this connection? */ 68862306a36Sopenharmony_ci bool ignore_signature:1; /* skip validation of signatures in SMB2/3 rsp */ 68962306a36Sopenharmony_ci bool session_estab; /* mark when very first sess is established */ 69062306a36Sopenharmony_ci int echo_credits; /* echo reserved slots */ 69162306a36Sopenharmony_ci int oplock_credits; /* oplock break reserved slots */ 69262306a36Sopenharmony_ci bool echoes:1; /* enable echoes */ 69362306a36Sopenharmony_ci __u8 client_guid[SMB2_CLIENT_GUID_SIZE]; /* Client GUID */ 69462306a36Sopenharmony_ci u16 dialect; /* dialect index that server chose */ 69562306a36Sopenharmony_ci bool oplocks:1; /* enable oplocks */ 69662306a36Sopenharmony_ci unsigned int maxReq; /* Clients should submit no more */ 69762306a36Sopenharmony_ci /* than maxReq distinct unanswered SMBs to the server when using */ 69862306a36Sopenharmony_ci /* multiplexed reads or writes (for SMB1/CIFS only, not SMB2/SMB3) */ 69962306a36Sopenharmony_ci unsigned int maxBuf; /* maxBuf specifies the maximum */ 70062306a36Sopenharmony_ci /* message size the server can send or receive for non-raw SMBs */ 70162306a36Sopenharmony_ci /* maxBuf is returned by SMB NegotiateProtocol so maxBuf is only 0 */ 70262306a36Sopenharmony_ci /* when socket is setup (and during reconnect) before NegProt sent */ 70362306a36Sopenharmony_ci unsigned int max_rw; /* maxRw specifies the maximum */ 70462306a36Sopenharmony_ci /* message size the server can send or receive for */ 70562306a36Sopenharmony_ci /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */ 70662306a36Sopenharmony_ci unsigned int capabilities; /* selective disabling of caps by smb sess */ 70762306a36Sopenharmony_ci int timeAdj; /* Adjust for difference in server time zone in sec */ 70862306a36Sopenharmony_ci __u64 CurrentMid; /* multiplex id - rotating counter, protected by GlobalMid_Lock */ 70962306a36Sopenharmony_ci char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */ 71062306a36Sopenharmony_ci /* 16th byte of RFC1001 workstation name is always null */ 71162306a36Sopenharmony_ci char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; 71262306a36Sopenharmony_ci __u32 sequence_number; /* for signing, protected by srv_mutex */ 71362306a36Sopenharmony_ci __u32 reconnect_instance; /* incremented on each reconnect */ 71462306a36Sopenharmony_ci struct session_key session_key; 71562306a36Sopenharmony_ci unsigned long lstrp; /* when we got last response from this server */ 71662306a36Sopenharmony_ci struct cifs_secmech secmech; /* crypto sec mech functs, descriptors */ 71762306a36Sopenharmony_ci#define CIFS_NEGFLAVOR_UNENCAP 1 /* wct == 17, but no ext_sec */ 71862306a36Sopenharmony_ci#define CIFS_NEGFLAVOR_EXTENDED 2 /* wct == 17, ext_sec bit set */ 71962306a36Sopenharmony_ci char negflavor; /* NEGOTIATE response flavor */ 72062306a36Sopenharmony_ci /* extended security flavors that server supports */ 72162306a36Sopenharmony_ci bool sec_ntlmssp; /* supports NTLMSSP */ 72262306a36Sopenharmony_ci bool sec_kerberosu2u; /* supports U2U Kerberos */ 72362306a36Sopenharmony_ci bool sec_kerberos; /* supports plain Kerberos */ 72462306a36Sopenharmony_ci bool sec_mskerberos; /* supports legacy MS Kerberos */ 72562306a36Sopenharmony_ci bool large_buf; /* is current buffer large? */ 72662306a36Sopenharmony_ci /* use SMBD connection instead of socket */ 72762306a36Sopenharmony_ci bool rdma; 72862306a36Sopenharmony_ci /* point to the SMBD connection if RDMA is used instead of socket */ 72962306a36Sopenharmony_ci struct smbd_connection *smbd_conn; 73062306a36Sopenharmony_ci struct delayed_work echo; /* echo ping workqueue job */ 73162306a36Sopenharmony_ci char *smallbuf; /* pointer to current "small" buffer */ 73262306a36Sopenharmony_ci char *bigbuf; /* pointer to current "big" buffer */ 73362306a36Sopenharmony_ci /* Total size of this PDU. Only valid from cifs_demultiplex_thread */ 73462306a36Sopenharmony_ci unsigned int pdu_size; 73562306a36Sopenharmony_ci unsigned int total_read; /* total amount of data read in this pass */ 73662306a36Sopenharmony_ci atomic_t in_send; /* requests trying to send */ 73762306a36Sopenharmony_ci atomic_t num_waiters; /* blocked waiting to get in sendrecv */ 73862306a36Sopenharmony_ci#ifdef CONFIG_CIFS_STATS2 73962306a36Sopenharmony_ci atomic_t num_cmds[NUMBER_OF_SMB2_COMMANDS]; /* total requests by cmd */ 74062306a36Sopenharmony_ci atomic_t smb2slowcmd[NUMBER_OF_SMB2_COMMANDS]; /* count resps > 1 sec */ 74162306a36Sopenharmony_ci __u64 time_per_cmd[NUMBER_OF_SMB2_COMMANDS]; /* total time per cmd */ 74262306a36Sopenharmony_ci __u32 slowest_cmd[NUMBER_OF_SMB2_COMMANDS]; 74362306a36Sopenharmony_ci __u32 fastest_cmd[NUMBER_OF_SMB2_COMMANDS]; 74462306a36Sopenharmony_ci#endif /* STATS2 */ 74562306a36Sopenharmony_ci unsigned int max_read; 74662306a36Sopenharmony_ci unsigned int max_write; 74762306a36Sopenharmony_ci unsigned int min_offload; 74862306a36Sopenharmony_ci __le16 compress_algorithm; 74962306a36Sopenharmony_ci __u16 signing_algorithm; 75062306a36Sopenharmony_ci __le16 cipher_type; 75162306a36Sopenharmony_ci /* save initital negprot hash */ 75262306a36Sopenharmony_ci __u8 preauth_sha_hash[SMB2_PREAUTH_HASH_SIZE]; 75362306a36Sopenharmony_ci bool signing_negotiated; /* true if valid signing context rcvd from server */ 75462306a36Sopenharmony_ci bool posix_ext_supported; 75562306a36Sopenharmony_ci struct delayed_work reconnect; /* reconnect workqueue job */ 75662306a36Sopenharmony_ci struct mutex reconnect_mutex; /* prevent simultaneous reconnects */ 75762306a36Sopenharmony_ci unsigned long echo_interval; 75862306a36Sopenharmony_ci 75962306a36Sopenharmony_ci /* 76062306a36Sopenharmony_ci * Number of targets available for reconnect. The more targets 76162306a36Sopenharmony_ci * the more tasks have to wait to let the demultiplex thread 76262306a36Sopenharmony_ci * reconnect. 76362306a36Sopenharmony_ci */ 76462306a36Sopenharmony_ci int nr_targets; 76562306a36Sopenharmony_ci bool noblockcnt; /* use non-blocking connect() */ 76662306a36Sopenharmony_ci 76762306a36Sopenharmony_ci /* 76862306a36Sopenharmony_ci * If this is a session channel, 76962306a36Sopenharmony_ci * primary_server holds the ref-counted 77062306a36Sopenharmony_ci * pointer to primary channel connection for the session. 77162306a36Sopenharmony_ci */ 77262306a36Sopenharmony_ci#define SERVER_IS_CHAN(server) (!!(server)->primary_server) 77362306a36Sopenharmony_ci struct TCP_Server_Info *primary_server; 77462306a36Sopenharmony_ci __u16 channel_sequence_num; /* incremented on primary channel on each chan reconnect */ 77562306a36Sopenharmony_ci 77662306a36Sopenharmony_ci#ifdef CONFIG_CIFS_SWN_UPCALL 77762306a36Sopenharmony_ci bool use_swn_dstaddr; 77862306a36Sopenharmony_ci struct sockaddr_storage swn_dstaddr; 77962306a36Sopenharmony_ci#endif 78062306a36Sopenharmony_ci struct mutex refpath_lock; /* protects leaf_fullpath */ 78162306a36Sopenharmony_ci /* 78262306a36Sopenharmony_ci * leaf_fullpath: Canonical DFS referral path related to this 78362306a36Sopenharmony_ci * connection. 78462306a36Sopenharmony_ci * It is used in DFS cache refresher, reconnect and may 78562306a36Sopenharmony_ci * change due to nested DFS links. 78662306a36Sopenharmony_ci * 78762306a36Sopenharmony_ci * Protected by @refpath_lock and @srv_lock. The @refpath_lock is 78862306a36Sopenharmony_ci * mostly used for not requiring a copy of @leaf_fullpath when getting 78962306a36Sopenharmony_ci * cached or new DFS referrals (which might also sleep during I/O). 79062306a36Sopenharmony_ci * While @srv_lock is held for making string and NULL comparions against 79162306a36Sopenharmony_ci * both fields as in mount(2) and cache refresh. 79262306a36Sopenharmony_ci * 79362306a36Sopenharmony_ci * format: \\HOST\SHARE[\OPTIONAL PATH] 79462306a36Sopenharmony_ci */ 79562306a36Sopenharmony_ci char *leaf_fullpath; 79662306a36Sopenharmony_ci}; 79762306a36Sopenharmony_ci 79862306a36Sopenharmony_cistatic inline bool is_smb1(struct TCP_Server_Info *server) 79962306a36Sopenharmony_ci{ 80062306a36Sopenharmony_ci return HEADER_PREAMBLE_SIZE(server) != 0; 80162306a36Sopenharmony_ci} 80262306a36Sopenharmony_ci 80362306a36Sopenharmony_cistatic inline void cifs_server_lock(struct TCP_Server_Info *server) 80462306a36Sopenharmony_ci{ 80562306a36Sopenharmony_ci unsigned int nofs_flag = memalloc_nofs_save(); 80662306a36Sopenharmony_ci 80762306a36Sopenharmony_ci mutex_lock(&server->_srv_mutex); 80862306a36Sopenharmony_ci server->nofs_flag = nofs_flag; 80962306a36Sopenharmony_ci} 81062306a36Sopenharmony_ci 81162306a36Sopenharmony_cistatic inline void cifs_server_unlock(struct TCP_Server_Info *server) 81262306a36Sopenharmony_ci{ 81362306a36Sopenharmony_ci unsigned int nofs_flag = server->nofs_flag; 81462306a36Sopenharmony_ci 81562306a36Sopenharmony_ci mutex_unlock(&server->_srv_mutex); 81662306a36Sopenharmony_ci memalloc_nofs_restore(nofs_flag); 81762306a36Sopenharmony_ci} 81862306a36Sopenharmony_ci 81962306a36Sopenharmony_cistruct cifs_credits { 82062306a36Sopenharmony_ci unsigned int value; 82162306a36Sopenharmony_ci unsigned int instance; 82262306a36Sopenharmony_ci}; 82362306a36Sopenharmony_ci 82462306a36Sopenharmony_cistatic inline unsigned int 82562306a36Sopenharmony_ciin_flight(struct TCP_Server_Info *server) 82662306a36Sopenharmony_ci{ 82762306a36Sopenharmony_ci unsigned int num; 82862306a36Sopenharmony_ci 82962306a36Sopenharmony_ci spin_lock(&server->req_lock); 83062306a36Sopenharmony_ci num = server->in_flight; 83162306a36Sopenharmony_ci spin_unlock(&server->req_lock); 83262306a36Sopenharmony_ci return num; 83362306a36Sopenharmony_ci} 83462306a36Sopenharmony_ci 83562306a36Sopenharmony_cistatic inline bool 83662306a36Sopenharmony_cihas_credits(struct TCP_Server_Info *server, int *credits, int num_credits) 83762306a36Sopenharmony_ci{ 83862306a36Sopenharmony_ci int num; 83962306a36Sopenharmony_ci 84062306a36Sopenharmony_ci spin_lock(&server->req_lock); 84162306a36Sopenharmony_ci num = *credits; 84262306a36Sopenharmony_ci spin_unlock(&server->req_lock); 84362306a36Sopenharmony_ci return num >= num_credits; 84462306a36Sopenharmony_ci} 84562306a36Sopenharmony_ci 84662306a36Sopenharmony_cistatic inline void 84762306a36Sopenharmony_ciadd_credits(struct TCP_Server_Info *server, const struct cifs_credits *credits, 84862306a36Sopenharmony_ci const int optype) 84962306a36Sopenharmony_ci{ 85062306a36Sopenharmony_ci server->ops->add_credits(server, credits, optype); 85162306a36Sopenharmony_ci} 85262306a36Sopenharmony_ci 85362306a36Sopenharmony_cistatic inline void 85462306a36Sopenharmony_ciadd_credits_and_wake_if(struct TCP_Server_Info *server, 85562306a36Sopenharmony_ci const struct cifs_credits *credits, const int optype) 85662306a36Sopenharmony_ci{ 85762306a36Sopenharmony_ci if (credits->value) { 85862306a36Sopenharmony_ci server->ops->add_credits(server, credits, optype); 85962306a36Sopenharmony_ci wake_up(&server->request_q); 86062306a36Sopenharmony_ci } 86162306a36Sopenharmony_ci} 86262306a36Sopenharmony_ci 86362306a36Sopenharmony_cistatic inline void 86462306a36Sopenharmony_ciset_credits(struct TCP_Server_Info *server, const int val) 86562306a36Sopenharmony_ci{ 86662306a36Sopenharmony_ci server->ops->set_credits(server, val); 86762306a36Sopenharmony_ci} 86862306a36Sopenharmony_ci 86962306a36Sopenharmony_cistatic inline int 87062306a36Sopenharmony_ciadjust_credits(struct TCP_Server_Info *server, struct cifs_credits *credits, 87162306a36Sopenharmony_ci const unsigned int payload_size) 87262306a36Sopenharmony_ci{ 87362306a36Sopenharmony_ci return server->ops->adjust_credits ? 87462306a36Sopenharmony_ci server->ops->adjust_credits(server, credits, payload_size) : 0; 87562306a36Sopenharmony_ci} 87662306a36Sopenharmony_ci 87762306a36Sopenharmony_cistatic inline __le64 87862306a36Sopenharmony_ciget_next_mid64(struct TCP_Server_Info *server) 87962306a36Sopenharmony_ci{ 88062306a36Sopenharmony_ci return cpu_to_le64(server->ops->get_next_mid(server)); 88162306a36Sopenharmony_ci} 88262306a36Sopenharmony_ci 88362306a36Sopenharmony_cistatic inline __le16 88462306a36Sopenharmony_ciget_next_mid(struct TCP_Server_Info *server) 88562306a36Sopenharmony_ci{ 88662306a36Sopenharmony_ci __u16 mid = server->ops->get_next_mid(server); 88762306a36Sopenharmony_ci /* 88862306a36Sopenharmony_ci * The value in the SMB header should be little endian for easy 88962306a36Sopenharmony_ci * on-the-wire decoding. 89062306a36Sopenharmony_ci */ 89162306a36Sopenharmony_ci return cpu_to_le16(mid); 89262306a36Sopenharmony_ci} 89362306a36Sopenharmony_ci 89462306a36Sopenharmony_cistatic inline void 89562306a36Sopenharmony_cirevert_current_mid(struct TCP_Server_Info *server, const unsigned int val) 89662306a36Sopenharmony_ci{ 89762306a36Sopenharmony_ci if (server->ops->revert_current_mid) 89862306a36Sopenharmony_ci server->ops->revert_current_mid(server, val); 89962306a36Sopenharmony_ci} 90062306a36Sopenharmony_ci 90162306a36Sopenharmony_cistatic inline void 90262306a36Sopenharmony_cirevert_current_mid_from_hdr(struct TCP_Server_Info *server, 90362306a36Sopenharmony_ci const struct smb2_hdr *shdr) 90462306a36Sopenharmony_ci{ 90562306a36Sopenharmony_ci unsigned int num = le16_to_cpu(shdr->CreditCharge); 90662306a36Sopenharmony_ci 90762306a36Sopenharmony_ci return revert_current_mid(server, num > 0 ? num : 1); 90862306a36Sopenharmony_ci} 90962306a36Sopenharmony_ci 91062306a36Sopenharmony_cistatic inline __u16 91162306a36Sopenharmony_ciget_mid(const struct smb_hdr *smb) 91262306a36Sopenharmony_ci{ 91362306a36Sopenharmony_ci return le16_to_cpu(smb->Mid); 91462306a36Sopenharmony_ci} 91562306a36Sopenharmony_ci 91662306a36Sopenharmony_cistatic inline bool 91762306a36Sopenharmony_cicompare_mid(__u16 mid, const struct smb_hdr *smb) 91862306a36Sopenharmony_ci{ 91962306a36Sopenharmony_ci return mid == le16_to_cpu(smb->Mid); 92062306a36Sopenharmony_ci} 92162306a36Sopenharmony_ci 92262306a36Sopenharmony_ci/* 92362306a36Sopenharmony_ci * When the server supports very large reads and writes via POSIX extensions, 92462306a36Sopenharmony_ci * we can allow up to 2^24-1, minus the size of a READ/WRITE_AND_X header, not 92562306a36Sopenharmony_ci * including the RFC1001 length. 92662306a36Sopenharmony_ci * 92762306a36Sopenharmony_ci * Note that this might make for "interesting" allocation problems during 92862306a36Sopenharmony_ci * writeback however as we have to allocate an array of pointers for the 92962306a36Sopenharmony_ci * pages. A 16M write means ~32kb page array with PAGE_SIZE == 4096. 93062306a36Sopenharmony_ci * 93162306a36Sopenharmony_ci * For reads, there is a similar problem as we need to allocate an array 93262306a36Sopenharmony_ci * of kvecs to handle the receive, though that should only need to be done 93362306a36Sopenharmony_ci * once. 93462306a36Sopenharmony_ci */ 93562306a36Sopenharmony_ci#define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4) 93662306a36Sopenharmony_ci#define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP) + 4) 93762306a36Sopenharmony_ci 93862306a36Sopenharmony_ci/* 93962306a36Sopenharmony_ci * When the server doesn't allow large posix writes, only allow a rsize/wsize 94062306a36Sopenharmony_ci * of 2^17-1 minus the size of the call header. That allows for a read or 94162306a36Sopenharmony_ci * write up to the maximum size described by RFC1002. 94262306a36Sopenharmony_ci */ 94362306a36Sopenharmony_ci#define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4) 94462306a36Sopenharmony_ci#define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4) 94562306a36Sopenharmony_ci 94662306a36Sopenharmony_ci#define CIFS_DEFAULT_IOSIZE (1024 * 1024) 94762306a36Sopenharmony_ci 94862306a36Sopenharmony_ci/* 94962306a36Sopenharmony_ci * Windows only supports a max of 60kb reads and 65535 byte writes. Default to 95062306a36Sopenharmony_ci * those values when posix extensions aren't in force. In actuality here, we 95162306a36Sopenharmony_ci * use 65536 to allow for a write that is a multiple of 4k. Most servers seem 95262306a36Sopenharmony_ci * to be ok with the extra byte even though Windows doesn't send writes that 95362306a36Sopenharmony_ci * are that large. 95462306a36Sopenharmony_ci * 95562306a36Sopenharmony_ci * Citation: 95662306a36Sopenharmony_ci * 95762306a36Sopenharmony_ci * https://blogs.msdn.com/b/openspecification/archive/2009/04/10/smb-maximum-transmit-buffer-size-and-performance-tuning.aspx 95862306a36Sopenharmony_ci */ 95962306a36Sopenharmony_ci#define CIFS_DEFAULT_NON_POSIX_RSIZE (60 * 1024) 96062306a36Sopenharmony_ci#define CIFS_DEFAULT_NON_POSIX_WSIZE (65536) 96162306a36Sopenharmony_ci 96262306a36Sopenharmony_ci/* 96362306a36Sopenharmony_ci * Macros to allow the TCP_Server_Info->net field and related code to drop out 96462306a36Sopenharmony_ci * when CONFIG_NET_NS isn't set. 96562306a36Sopenharmony_ci */ 96662306a36Sopenharmony_ci 96762306a36Sopenharmony_ci#ifdef CONFIG_NET_NS 96862306a36Sopenharmony_ci 96962306a36Sopenharmony_cistatic inline struct net *cifs_net_ns(struct TCP_Server_Info *srv) 97062306a36Sopenharmony_ci{ 97162306a36Sopenharmony_ci return srv->net; 97262306a36Sopenharmony_ci} 97362306a36Sopenharmony_ci 97462306a36Sopenharmony_cistatic inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net) 97562306a36Sopenharmony_ci{ 97662306a36Sopenharmony_ci srv->net = net; 97762306a36Sopenharmony_ci} 97862306a36Sopenharmony_ci 97962306a36Sopenharmony_ci#else 98062306a36Sopenharmony_ci 98162306a36Sopenharmony_cistatic inline struct net *cifs_net_ns(struct TCP_Server_Info *srv) 98262306a36Sopenharmony_ci{ 98362306a36Sopenharmony_ci return &init_net; 98462306a36Sopenharmony_ci} 98562306a36Sopenharmony_ci 98662306a36Sopenharmony_cistatic inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net) 98762306a36Sopenharmony_ci{ 98862306a36Sopenharmony_ci} 98962306a36Sopenharmony_ci 99062306a36Sopenharmony_ci#endif 99162306a36Sopenharmony_ci 99262306a36Sopenharmony_cistruct cifs_server_iface { 99362306a36Sopenharmony_ci struct list_head iface_head; 99462306a36Sopenharmony_ci struct kref refcount; 99562306a36Sopenharmony_ci size_t speed; 99662306a36Sopenharmony_ci size_t weight_fulfilled; 99762306a36Sopenharmony_ci unsigned int num_channels; 99862306a36Sopenharmony_ci unsigned int rdma_capable : 1; 99962306a36Sopenharmony_ci unsigned int rss_capable : 1; 100062306a36Sopenharmony_ci unsigned int is_active : 1; /* unset if non existent */ 100162306a36Sopenharmony_ci struct sockaddr_storage sockaddr; 100262306a36Sopenharmony_ci}; 100362306a36Sopenharmony_ci 100462306a36Sopenharmony_ci/* release iface when last ref is dropped */ 100562306a36Sopenharmony_cistatic inline void 100662306a36Sopenharmony_cirelease_iface(struct kref *ref) 100762306a36Sopenharmony_ci{ 100862306a36Sopenharmony_ci struct cifs_server_iface *iface = container_of(ref, 100962306a36Sopenharmony_ci struct cifs_server_iface, 101062306a36Sopenharmony_ci refcount); 101162306a36Sopenharmony_ci kfree(iface); 101262306a36Sopenharmony_ci} 101362306a36Sopenharmony_ci 101462306a36Sopenharmony_cistruct cifs_chan { 101562306a36Sopenharmony_ci unsigned int in_reconnect : 1; /* if session setup in progress for this channel */ 101662306a36Sopenharmony_ci struct TCP_Server_Info *server; 101762306a36Sopenharmony_ci struct cifs_server_iface *iface; /* interface in use */ 101862306a36Sopenharmony_ci __u8 signkey[SMB3_SIGN_KEY_SIZE]; 101962306a36Sopenharmony_ci}; 102062306a36Sopenharmony_ci 102162306a36Sopenharmony_ci#define CIFS_SES_FLAG_SCALE_CHANNELS (0x1) 102262306a36Sopenharmony_ci 102362306a36Sopenharmony_ci/* 102462306a36Sopenharmony_ci * Session structure. One of these for each uid session with a particular host 102562306a36Sopenharmony_ci */ 102662306a36Sopenharmony_cistruct cifs_ses { 102762306a36Sopenharmony_ci struct list_head smb_ses_list; 102862306a36Sopenharmony_ci struct list_head rlist; /* reconnect list */ 102962306a36Sopenharmony_ci struct list_head tcon_list; 103062306a36Sopenharmony_ci struct cifs_tcon *tcon_ipc; 103162306a36Sopenharmony_ci spinlock_t ses_lock; /* protect anything here that is not protected */ 103262306a36Sopenharmony_ci struct mutex session_mutex; 103362306a36Sopenharmony_ci struct TCP_Server_Info *server; /* pointer to server info */ 103462306a36Sopenharmony_ci int ses_count; /* reference counter */ 103562306a36Sopenharmony_ci enum ses_status_enum ses_status; /* updates protected by cifs_tcp_ses_lock */ 103662306a36Sopenharmony_ci unsigned int overrideSecFlg; /* if non-zero override global sec flags */ 103762306a36Sopenharmony_ci char *serverOS; /* name of operating system underlying server */ 103862306a36Sopenharmony_ci char *serverNOS; /* name of network operating system of server */ 103962306a36Sopenharmony_ci char *serverDomain; /* security realm of server */ 104062306a36Sopenharmony_ci __u64 Suid; /* remote smb uid */ 104162306a36Sopenharmony_ci kuid_t linux_uid; /* overriding owner of files on the mount */ 104262306a36Sopenharmony_ci kuid_t cred_uid; /* owner of credentials */ 104362306a36Sopenharmony_ci unsigned int capabilities; 104462306a36Sopenharmony_ci char ip_addr[INET6_ADDRSTRLEN + 1]; /* Max ipv6 (or v4) addr string len */ 104562306a36Sopenharmony_ci char *user_name; /* must not be null except during init of sess 104662306a36Sopenharmony_ci and after mount option parsing we fill it */ 104762306a36Sopenharmony_ci char *domainName; 104862306a36Sopenharmony_ci char *password; 104962306a36Sopenharmony_ci char workstation_name[CIFS_MAX_WORKSTATION_LEN]; 105062306a36Sopenharmony_ci struct session_key auth_key; 105162306a36Sopenharmony_ci struct ntlmssp_auth *ntlmssp; /* ciphertext, flags, server challenge */ 105262306a36Sopenharmony_ci enum securityEnum sectype; /* what security flavor was specified? */ 105362306a36Sopenharmony_ci bool sign; /* is signing required? */ 105462306a36Sopenharmony_ci bool domainAuto:1; 105562306a36Sopenharmony_ci bool expired_pwd; /* track if access denied or expired pwd so can know if need to update */ 105662306a36Sopenharmony_ci unsigned int flags; 105762306a36Sopenharmony_ci __u16 session_flags; 105862306a36Sopenharmony_ci __u8 smb3signingkey[SMB3_SIGN_KEY_SIZE]; 105962306a36Sopenharmony_ci __u8 smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE]; 106062306a36Sopenharmony_ci __u8 smb3decryptionkey[SMB3_ENC_DEC_KEY_SIZE]; 106162306a36Sopenharmony_ci __u8 preauth_sha_hash[SMB2_PREAUTH_HASH_SIZE]; 106262306a36Sopenharmony_ci 106362306a36Sopenharmony_ci /* 106462306a36Sopenharmony_ci * Network interfaces available on the server this session is 106562306a36Sopenharmony_ci * connected to. 106662306a36Sopenharmony_ci * 106762306a36Sopenharmony_ci * Other channels can be opened by connecting and binding this 106862306a36Sopenharmony_ci * session to interfaces from this list. 106962306a36Sopenharmony_ci * 107062306a36Sopenharmony_ci * iface_lock should be taken when accessing any of these fields 107162306a36Sopenharmony_ci */ 107262306a36Sopenharmony_ci spinlock_t iface_lock; 107362306a36Sopenharmony_ci /* ========= begin: protected by iface_lock ======== */ 107462306a36Sopenharmony_ci struct list_head iface_list; 107562306a36Sopenharmony_ci size_t iface_count; 107662306a36Sopenharmony_ci unsigned long iface_last_update; /* jiffies */ 107762306a36Sopenharmony_ci /* ========= end: protected by iface_lock ======== */ 107862306a36Sopenharmony_ci 107962306a36Sopenharmony_ci spinlock_t chan_lock; 108062306a36Sopenharmony_ci /* ========= begin: protected by chan_lock ======== */ 108162306a36Sopenharmony_ci#define CIFS_MAX_CHANNELS 16 108262306a36Sopenharmony_ci#define CIFS_INVAL_CHAN_INDEX (-1) 108362306a36Sopenharmony_ci#define CIFS_ALL_CHANNELS_SET(ses) \ 108462306a36Sopenharmony_ci ((1UL << (ses)->chan_count) - 1) 108562306a36Sopenharmony_ci#define CIFS_ALL_CHANS_GOOD(ses) \ 108662306a36Sopenharmony_ci (!(ses)->chans_need_reconnect) 108762306a36Sopenharmony_ci#define CIFS_ALL_CHANS_NEED_RECONNECT(ses) \ 108862306a36Sopenharmony_ci ((ses)->chans_need_reconnect == CIFS_ALL_CHANNELS_SET(ses)) 108962306a36Sopenharmony_ci#define CIFS_SET_ALL_CHANS_NEED_RECONNECT(ses) \ 109062306a36Sopenharmony_ci ((ses)->chans_need_reconnect = CIFS_ALL_CHANNELS_SET(ses)) 109162306a36Sopenharmony_ci#define CIFS_CHAN_NEEDS_RECONNECT(ses, index) \ 109262306a36Sopenharmony_ci test_bit((index), &(ses)->chans_need_reconnect) 109362306a36Sopenharmony_ci#define CIFS_CHAN_IN_RECONNECT(ses, index) \ 109462306a36Sopenharmony_ci ((ses)->chans[(index)].in_reconnect) 109562306a36Sopenharmony_ci 109662306a36Sopenharmony_ci struct cifs_chan chans[CIFS_MAX_CHANNELS]; 109762306a36Sopenharmony_ci size_t chan_count; 109862306a36Sopenharmony_ci size_t chan_max; 109962306a36Sopenharmony_ci atomic_t chan_seq; /* round robin state */ 110062306a36Sopenharmony_ci 110162306a36Sopenharmony_ci /* 110262306a36Sopenharmony_ci * chans_need_reconnect is a bitmap indicating which of the channels 110362306a36Sopenharmony_ci * under this smb session needs to be reconnected. 110462306a36Sopenharmony_ci * If not multichannel session, only one bit will be used. 110562306a36Sopenharmony_ci * 110662306a36Sopenharmony_ci * We will ask for sess and tcon reconnection only if all the 110762306a36Sopenharmony_ci * channels are marked for needing reconnection. This will 110862306a36Sopenharmony_ci * enable the sessions on top to continue to live till any 110962306a36Sopenharmony_ci * of the channels below are active. 111062306a36Sopenharmony_ci */ 111162306a36Sopenharmony_ci unsigned long chans_need_reconnect; 111262306a36Sopenharmony_ci /* ========= end: protected by chan_lock ======== */ 111362306a36Sopenharmony_ci struct cifs_ses *dfs_root_ses; 111462306a36Sopenharmony_ci struct nls_table *local_nls; 111562306a36Sopenharmony_ci}; 111662306a36Sopenharmony_ci 111762306a36Sopenharmony_cistatic inline bool 111862306a36Sopenharmony_cicap_unix(struct cifs_ses *ses) 111962306a36Sopenharmony_ci{ 112062306a36Sopenharmony_ci return ses->server->vals->cap_unix & ses->capabilities; 112162306a36Sopenharmony_ci} 112262306a36Sopenharmony_ci 112362306a36Sopenharmony_ci/* 112462306a36Sopenharmony_ci * common struct for holding inode info when searching for or updating an 112562306a36Sopenharmony_ci * inode with new info 112662306a36Sopenharmony_ci */ 112762306a36Sopenharmony_ci 112862306a36Sopenharmony_ci#define CIFS_FATTR_JUNCTION 0x1 112962306a36Sopenharmony_ci#define CIFS_FATTR_DELETE_PENDING 0x2 113062306a36Sopenharmony_ci#define CIFS_FATTR_NEED_REVAL 0x4 113162306a36Sopenharmony_ci#define CIFS_FATTR_INO_COLLISION 0x8 113262306a36Sopenharmony_ci#define CIFS_FATTR_UNKNOWN_NLINK 0x10 113362306a36Sopenharmony_ci#define CIFS_FATTR_FAKE_ROOT_INO 0x20 113462306a36Sopenharmony_ci 113562306a36Sopenharmony_cistruct cifs_fattr { 113662306a36Sopenharmony_ci u32 cf_flags; 113762306a36Sopenharmony_ci u32 cf_cifsattrs; 113862306a36Sopenharmony_ci u64 cf_uniqueid; 113962306a36Sopenharmony_ci u64 cf_eof; 114062306a36Sopenharmony_ci u64 cf_bytes; 114162306a36Sopenharmony_ci u64 cf_createtime; 114262306a36Sopenharmony_ci kuid_t cf_uid; 114362306a36Sopenharmony_ci kgid_t cf_gid; 114462306a36Sopenharmony_ci umode_t cf_mode; 114562306a36Sopenharmony_ci dev_t cf_rdev; 114662306a36Sopenharmony_ci unsigned int cf_nlink; 114762306a36Sopenharmony_ci unsigned int cf_dtype; 114862306a36Sopenharmony_ci struct timespec64 cf_atime; 114962306a36Sopenharmony_ci struct timespec64 cf_mtime; 115062306a36Sopenharmony_ci struct timespec64 cf_ctime; 115162306a36Sopenharmony_ci u32 cf_cifstag; 115262306a36Sopenharmony_ci char *cf_symlink_target; 115362306a36Sopenharmony_ci}; 115462306a36Sopenharmony_ci 115562306a36Sopenharmony_ci/* 115662306a36Sopenharmony_ci * there is one of these for each connection to a resource on a particular 115762306a36Sopenharmony_ci * session 115862306a36Sopenharmony_ci */ 115962306a36Sopenharmony_cistruct cifs_tcon { 116062306a36Sopenharmony_ci struct list_head tcon_list; 116162306a36Sopenharmony_ci int tc_count; 116262306a36Sopenharmony_ci struct list_head rlist; /* reconnect list */ 116362306a36Sopenharmony_ci spinlock_t tc_lock; /* protect anything here that is not protected */ 116462306a36Sopenharmony_ci atomic_t num_local_opens; /* num of all opens including disconnected */ 116562306a36Sopenharmony_ci atomic_t num_remote_opens; /* num of all network opens on server */ 116662306a36Sopenharmony_ci struct list_head openFileList; 116762306a36Sopenharmony_ci spinlock_t open_file_lock; /* protects list above */ 116862306a36Sopenharmony_ci struct cifs_ses *ses; /* pointer to session associated with */ 116962306a36Sopenharmony_ci char tree_name[MAX_TREE_SIZE + 1]; /* UNC name of resource in ASCII */ 117062306a36Sopenharmony_ci char *nativeFileSystem; 117162306a36Sopenharmony_ci char *password; /* for share-level security */ 117262306a36Sopenharmony_ci __u32 tid; /* The 4 byte tree id */ 117362306a36Sopenharmony_ci __u16 Flags; /* optional support bits */ 117462306a36Sopenharmony_ci enum tid_status_enum status; 117562306a36Sopenharmony_ci atomic_t num_smbs_sent; 117662306a36Sopenharmony_ci union { 117762306a36Sopenharmony_ci struct { 117862306a36Sopenharmony_ci atomic_t num_writes; 117962306a36Sopenharmony_ci atomic_t num_reads; 118062306a36Sopenharmony_ci atomic_t num_flushes; 118162306a36Sopenharmony_ci atomic_t num_oplock_brks; 118262306a36Sopenharmony_ci atomic_t num_opens; 118362306a36Sopenharmony_ci atomic_t num_closes; 118462306a36Sopenharmony_ci atomic_t num_deletes; 118562306a36Sopenharmony_ci atomic_t num_mkdirs; 118662306a36Sopenharmony_ci atomic_t num_posixopens; 118762306a36Sopenharmony_ci atomic_t num_posixmkdirs; 118862306a36Sopenharmony_ci atomic_t num_rmdirs; 118962306a36Sopenharmony_ci atomic_t num_renames; 119062306a36Sopenharmony_ci atomic_t num_t2renames; 119162306a36Sopenharmony_ci atomic_t num_ffirst; 119262306a36Sopenharmony_ci atomic_t num_fnext; 119362306a36Sopenharmony_ci atomic_t num_fclose; 119462306a36Sopenharmony_ci atomic_t num_hardlinks; 119562306a36Sopenharmony_ci atomic_t num_symlinks; 119662306a36Sopenharmony_ci atomic_t num_locks; 119762306a36Sopenharmony_ci atomic_t num_acl_get; 119862306a36Sopenharmony_ci atomic_t num_acl_set; 119962306a36Sopenharmony_ci } cifs_stats; 120062306a36Sopenharmony_ci struct { 120162306a36Sopenharmony_ci atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS]; 120262306a36Sopenharmony_ci atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS]; 120362306a36Sopenharmony_ci } smb2_stats; 120462306a36Sopenharmony_ci } stats; 120562306a36Sopenharmony_ci __u64 bytes_read; 120662306a36Sopenharmony_ci __u64 bytes_written; 120762306a36Sopenharmony_ci spinlock_t stat_lock; /* protects the two fields above */ 120862306a36Sopenharmony_ci FILE_SYSTEM_DEVICE_INFO fsDevInfo; 120962306a36Sopenharmony_ci FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo; /* ok if fs name truncated */ 121062306a36Sopenharmony_ci FILE_SYSTEM_UNIX_INFO fsUnixInfo; 121162306a36Sopenharmony_ci bool ipc:1; /* set if connection to IPC$ share (always also pipe) */ 121262306a36Sopenharmony_ci bool pipe:1; /* set if connection to pipe share */ 121362306a36Sopenharmony_ci bool print:1; /* set if connection to printer share */ 121462306a36Sopenharmony_ci bool retry:1; 121562306a36Sopenharmony_ci bool nocase:1; 121662306a36Sopenharmony_ci bool nohandlecache:1; /* if strange server resource prob can turn off */ 121762306a36Sopenharmony_ci bool nodelete:1; 121862306a36Sopenharmony_ci bool seal:1; /* transport encryption for this mounted share */ 121962306a36Sopenharmony_ci bool unix_ext:1; /* if false disable Linux extensions to CIFS protocol 122062306a36Sopenharmony_ci for this mount even if server would support */ 122162306a36Sopenharmony_ci bool posix_extensions; /* if true SMB3.11 posix extensions enabled */ 122262306a36Sopenharmony_ci bool local_lease:1; /* check leases (only) on local system not remote */ 122362306a36Sopenharmony_ci bool broken_posix_open; /* e.g. Samba server versions < 3.3.2, 3.2.9 */ 122462306a36Sopenharmony_ci bool broken_sparse_sup; /* if server or share does not support sparse */ 122562306a36Sopenharmony_ci bool need_reconnect:1; /* connection reset, tid now invalid */ 122662306a36Sopenharmony_ci bool need_reopen_files:1; /* need to reopen tcon file handles */ 122762306a36Sopenharmony_ci bool use_resilient:1; /* use resilient instead of durable handles */ 122862306a36Sopenharmony_ci bool use_persistent:1; /* use persistent instead of durable handles */ 122962306a36Sopenharmony_ci bool no_lease:1; /* Do not request leases on files or directories */ 123062306a36Sopenharmony_ci bool use_witness:1; /* use witness protocol */ 123162306a36Sopenharmony_ci __le32 capabilities; 123262306a36Sopenharmony_ci __u32 share_flags; 123362306a36Sopenharmony_ci __u32 maximal_access; 123462306a36Sopenharmony_ci __u32 vol_serial_number; 123562306a36Sopenharmony_ci __le64 vol_create_time; 123662306a36Sopenharmony_ci __u64 snapshot_time; /* for timewarp tokens - timestamp of snapshot */ 123762306a36Sopenharmony_ci __u32 handle_timeout; /* persistent and durable handle timeout in ms */ 123862306a36Sopenharmony_ci __u32 ss_flags; /* sector size flags */ 123962306a36Sopenharmony_ci __u32 perf_sector_size; /* best sector size for perf */ 124062306a36Sopenharmony_ci __u32 max_chunks; 124162306a36Sopenharmony_ci __u32 max_bytes_chunk; 124262306a36Sopenharmony_ci __u32 max_bytes_copy; 124362306a36Sopenharmony_ci __u32 max_cached_dirs; 124462306a36Sopenharmony_ci#ifdef CONFIG_CIFS_FSCACHE 124562306a36Sopenharmony_ci u64 resource_id; /* server resource id */ 124662306a36Sopenharmony_ci struct fscache_volume *fscache; /* cookie for share */ 124762306a36Sopenharmony_ci#endif 124862306a36Sopenharmony_ci struct list_head pending_opens; /* list of incomplete opens */ 124962306a36Sopenharmony_ci struct cached_fids *cfids; 125062306a36Sopenharmony_ci /* BB add field for back pointer to sb struct(s)? */ 125162306a36Sopenharmony_ci#ifdef CONFIG_CIFS_DFS_UPCALL 125262306a36Sopenharmony_ci struct list_head dfs_ses_list; 125362306a36Sopenharmony_ci struct delayed_work dfs_cache_work; 125462306a36Sopenharmony_ci#endif 125562306a36Sopenharmony_ci struct delayed_work query_interfaces; /* query interfaces workqueue job */ 125662306a36Sopenharmony_ci char *origin_fullpath; /* canonical copy of smb3_fs_context::source */ 125762306a36Sopenharmony_ci}; 125862306a36Sopenharmony_ci 125962306a36Sopenharmony_ci/* 126062306a36Sopenharmony_ci * This is a refcounted and timestamped container for a tcon pointer. The 126162306a36Sopenharmony_ci * container holds a tcon reference. It is considered safe to free one of 126262306a36Sopenharmony_ci * these when the tl_count goes to 0. The tl_time is the time of the last 126362306a36Sopenharmony_ci * "get" on the container. 126462306a36Sopenharmony_ci */ 126562306a36Sopenharmony_cistruct tcon_link { 126662306a36Sopenharmony_ci struct rb_node tl_rbnode; 126762306a36Sopenharmony_ci kuid_t tl_uid; 126862306a36Sopenharmony_ci unsigned long tl_flags; 126962306a36Sopenharmony_ci#define TCON_LINK_MASTER 0 127062306a36Sopenharmony_ci#define TCON_LINK_PENDING 1 127162306a36Sopenharmony_ci#define TCON_LINK_IN_TREE 2 127262306a36Sopenharmony_ci unsigned long tl_time; 127362306a36Sopenharmony_ci atomic_t tl_count; 127462306a36Sopenharmony_ci struct cifs_tcon *tl_tcon; 127562306a36Sopenharmony_ci}; 127662306a36Sopenharmony_ci 127762306a36Sopenharmony_ciextern struct tcon_link *cifs_sb_tlink(struct cifs_sb_info *cifs_sb); 127862306a36Sopenharmony_ciextern void smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst); 127962306a36Sopenharmony_ci 128062306a36Sopenharmony_cistatic inline struct cifs_tcon * 128162306a36Sopenharmony_citlink_tcon(struct tcon_link *tlink) 128262306a36Sopenharmony_ci{ 128362306a36Sopenharmony_ci return tlink->tl_tcon; 128462306a36Sopenharmony_ci} 128562306a36Sopenharmony_ci 128662306a36Sopenharmony_cistatic inline struct tcon_link * 128762306a36Sopenharmony_cicifs_sb_master_tlink(struct cifs_sb_info *cifs_sb) 128862306a36Sopenharmony_ci{ 128962306a36Sopenharmony_ci return cifs_sb->master_tlink; 129062306a36Sopenharmony_ci} 129162306a36Sopenharmony_ci 129262306a36Sopenharmony_ciextern void cifs_put_tlink(struct tcon_link *tlink); 129362306a36Sopenharmony_ci 129462306a36Sopenharmony_cistatic inline struct tcon_link * 129562306a36Sopenharmony_cicifs_get_tlink(struct tcon_link *tlink) 129662306a36Sopenharmony_ci{ 129762306a36Sopenharmony_ci if (tlink && !IS_ERR(tlink)) 129862306a36Sopenharmony_ci atomic_inc(&tlink->tl_count); 129962306a36Sopenharmony_ci return tlink; 130062306a36Sopenharmony_ci} 130162306a36Sopenharmony_ci 130262306a36Sopenharmony_ci/* This function is always expected to succeed */ 130362306a36Sopenharmony_ciextern struct cifs_tcon *cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb); 130462306a36Sopenharmony_ci 130562306a36Sopenharmony_ci#define CIFS_OPLOCK_NO_CHANGE 0xfe 130662306a36Sopenharmony_ci 130762306a36Sopenharmony_cistruct cifs_pending_open { 130862306a36Sopenharmony_ci struct list_head olist; 130962306a36Sopenharmony_ci struct tcon_link *tlink; 131062306a36Sopenharmony_ci __u8 lease_key[16]; 131162306a36Sopenharmony_ci __u32 oplock; 131262306a36Sopenharmony_ci}; 131362306a36Sopenharmony_ci 131462306a36Sopenharmony_cistruct cifs_deferred_close { 131562306a36Sopenharmony_ci struct list_head dlist; 131662306a36Sopenharmony_ci struct tcon_link *tlink; 131762306a36Sopenharmony_ci __u16 netfid; 131862306a36Sopenharmony_ci __u64 persistent_fid; 131962306a36Sopenharmony_ci __u64 volatile_fid; 132062306a36Sopenharmony_ci}; 132162306a36Sopenharmony_ci 132262306a36Sopenharmony_ci/* 132362306a36Sopenharmony_ci * This info hangs off the cifsFileInfo structure, pointed to by llist. 132462306a36Sopenharmony_ci * This is used to track byte stream locks on the file 132562306a36Sopenharmony_ci */ 132662306a36Sopenharmony_cistruct cifsLockInfo { 132762306a36Sopenharmony_ci struct list_head llist; /* pointer to next cifsLockInfo */ 132862306a36Sopenharmony_ci struct list_head blist; /* pointer to locks blocked on this */ 132962306a36Sopenharmony_ci wait_queue_head_t block_q; 133062306a36Sopenharmony_ci __u64 offset; 133162306a36Sopenharmony_ci __u64 length; 133262306a36Sopenharmony_ci __u32 pid; 133362306a36Sopenharmony_ci __u16 type; 133462306a36Sopenharmony_ci __u16 flags; 133562306a36Sopenharmony_ci}; 133662306a36Sopenharmony_ci 133762306a36Sopenharmony_ci/* 133862306a36Sopenharmony_ci * One of these for each open instance of a file 133962306a36Sopenharmony_ci */ 134062306a36Sopenharmony_cistruct cifs_search_info { 134162306a36Sopenharmony_ci loff_t index_of_last_entry; 134262306a36Sopenharmony_ci __u16 entries_in_buffer; 134362306a36Sopenharmony_ci __u16 info_level; 134462306a36Sopenharmony_ci __u32 resume_key; 134562306a36Sopenharmony_ci char *ntwrk_buf_start; 134662306a36Sopenharmony_ci char *srch_entries_start; 134762306a36Sopenharmony_ci char *last_entry; 134862306a36Sopenharmony_ci const char *presume_name; 134962306a36Sopenharmony_ci unsigned int resume_name_len; 135062306a36Sopenharmony_ci bool endOfSearch:1; 135162306a36Sopenharmony_ci bool emptyDir:1; 135262306a36Sopenharmony_ci bool unicode:1; 135362306a36Sopenharmony_ci bool smallBuf:1; /* so we know which buf_release function to call */ 135462306a36Sopenharmony_ci}; 135562306a36Sopenharmony_ci 135662306a36Sopenharmony_ci#define ACL_NO_MODE ((umode_t)(-1)) 135762306a36Sopenharmony_cistruct cifs_open_parms { 135862306a36Sopenharmony_ci struct cifs_tcon *tcon; 135962306a36Sopenharmony_ci struct cifs_sb_info *cifs_sb; 136062306a36Sopenharmony_ci int disposition; 136162306a36Sopenharmony_ci int desired_access; 136262306a36Sopenharmony_ci int create_options; 136362306a36Sopenharmony_ci const char *path; 136462306a36Sopenharmony_ci struct cifs_fid *fid; 136562306a36Sopenharmony_ci umode_t mode; 136662306a36Sopenharmony_ci bool reconnect:1; 136762306a36Sopenharmony_ci}; 136862306a36Sopenharmony_ci 136962306a36Sopenharmony_cistruct cifs_fid { 137062306a36Sopenharmony_ci __u16 netfid; 137162306a36Sopenharmony_ci __u64 persistent_fid; /* persist file id for smb2 */ 137262306a36Sopenharmony_ci __u64 volatile_fid; /* volatile file id for smb2 */ 137362306a36Sopenharmony_ci __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for smb2 */ 137462306a36Sopenharmony_ci __u8 create_guid[16]; 137562306a36Sopenharmony_ci __u32 access; 137662306a36Sopenharmony_ci struct cifs_pending_open *pending_open; 137762306a36Sopenharmony_ci unsigned int epoch; 137862306a36Sopenharmony_ci#ifdef CONFIG_CIFS_DEBUG2 137962306a36Sopenharmony_ci __u64 mid; 138062306a36Sopenharmony_ci#endif /* CIFS_DEBUG2 */ 138162306a36Sopenharmony_ci bool purge_cache; 138262306a36Sopenharmony_ci}; 138362306a36Sopenharmony_ci 138462306a36Sopenharmony_cistruct cifs_fid_locks { 138562306a36Sopenharmony_ci struct list_head llist; 138662306a36Sopenharmony_ci struct cifsFileInfo *cfile; /* fid that owns locks */ 138762306a36Sopenharmony_ci struct list_head locks; /* locks held by fid above */ 138862306a36Sopenharmony_ci}; 138962306a36Sopenharmony_ci 139062306a36Sopenharmony_cistruct cifsFileInfo { 139162306a36Sopenharmony_ci /* following two lists are protected by tcon->open_file_lock */ 139262306a36Sopenharmony_ci struct list_head tlist; /* pointer to next fid owned by tcon */ 139362306a36Sopenharmony_ci struct list_head flist; /* next fid (file instance) for this inode */ 139462306a36Sopenharmony_ci /* lock list below protected by cifsi->lock_sem */ 139562306a36Sopenharmony_ci struct cifs_fid_locks *llist; /* brlocks held by this fid */ 139662306a36Sopenharmony_ci kuid_t uid; /* allows finding which FileInfo structure */ 139762306a36Sopenharmony_ci __u32 pid; /* process id who opened file */ 139862306a36Sopenharmony_ci struct cifs_fid fid; /* file id from remote */ 139962306a36Sopenharmony_ci struct list_head rlist; /* reconnect list */ 140062306a36Sopenharmony_ci /* BB add lock scope info here if needed */ 140162306a36Sopenharmony_ci /* lock scope id (0 if none) */ 140262306a36Sopenharmony_ci struct dentry *dentry; 140362306a36Sopenharmony_ci struct tcon_link *tlink; 140462306a36Sopenharmony_ci unsigned int f_flags; 140562306a36Sopenharmony_ci bool invalidHandle:1; /* file closed via session abend */ 140662306a36Sopenharmony_ci bool swapfile:1; 140762306a36Sopenharmony_ci bool oplock_break_cancelled:1; 140862306a36Sopenharmony_ci unsigned int oplock_epoch; /* epoch from the lease break */ 140962306a36Sopenharmony_ci __u32 oplock_level; /* oplock/lease level from the lease break */ 141062306a36Sopenharmony_ci int count; 141162306a36Sopenharmony_ci spinlock_t file_info_lock; /* protects four flag/count fields above */ 141262306a36Sopenharmony_ci struct mutex fh_mutex; /* prevents reopen race after dead ses*/ 141362306a36Sopenharmony_ci struct cifs_search_info srch_inf; 141462306a36Sopenharmony_ci struct work_struct oplock_break; /* work for oplock breaks */ 141562306a36Sopenharmony_ci struct work_struct put; /* work for the final part of _put */ 141662306a36Sopenharmony_ci struct delayed_work deferred; 141762306a36Sopenharmony_ci bool deferred_close_scheduled; /* Flag to indicate close is scheduled */ 141862306a36Sopenharmony_ci char *symlink_target; 141962306a36Sopenharmony_ci}; 142062306a36Sopenharmony_ci 142162306a36Sopenharmony_cistruct cifs_io_parms { 142262306a36Sopenharmony_ci __u16 netfid; 142362306a36Sopenharmony_ci __u64 persistent_fid; /* persist file id for smb2 */ 142462306a36Sopenharmony_ci __u64 volatile_fid; /* volatile file id for smb2 */ 142562306a36Sopenharmony_ci __u32 pid; 142662306a36Sopenharmony_ci __u64 offset; 142762306a36Sopenharmony_ci unsigned int length; 142862306a36Sopenharmony_ci struct cifs_tcon *tcon; 142962306a36Sopenharmony_ci struct TCP_Server_Info *server; 143062306a36Sopenharmony_ci}; 143162306a36Sopenharmony_ci 143262306a36Sopenharmony_cistruct cifs_aio_ctx { 143362306a36Sopenharmony_ci struct kref refcount; 143462306a36Sopenharmony_ci struct list_head list; 143562306a36Sopenharmony_ci struct mutex aio_mutex; 143662306a36Sopenharmony_ci struct completion done; 143762306a36Sopenharmony_ci struct iov_iter iter; 143862306a36Sopenharmony_ci struct kiocb *iocb; 143962306a36Sopenharmony_ci struct cifsFileInfo *cfile; 144062306a36Sopenharmony_ci struct bio_vec *bv; 144162306a36Sopenharmony_ci loff_t pos; 144262306a36Sopenharmony_ci unsigned int nr_pinned_pages; 144362306a36Sopenharmony_ci ssize_t rc; 144462306a36Sopenharmony_ci unsigned int len; 144562306a36Sopenharmony_ci unsigned int total_len; 144662306a36Sopenharmony_ci unsigned int bv_need_unpin; /* If ->bv[] needs unpinning */ 144762306a36Sopenharmony_ci bool should_dirty; 144862306a36Sopenharmony_ci /* 144962306a36Sopenharmony_ci * Indicates if this aio_ctx is for direct_io, 145062306a36Sopenharmony_ci * If yes, iter is a copy of the user passed iov_iter 145162306a36Sopenharmony_ci */ 145262306a36Sopenharmony_ci bool direct_io; 145362306a36Sopenharmony_ci}; 145462306a36Sopenharmony_ci 145562306a36Sopenharmony_ci/* asynchronous read support */ 145662306a36Sopenharmony_cistruct cifs_readdata { 145762306a36Sopenharmony_ci struct kref refcount; 145862306a36Sopenharmony_ci struct list_head list; 145962306a36Sopenharmony_ci struct completion done; 146062306a36Sopenharmony_ci struct cifsFileInfo *cfile; 146162306a36Sopenharmony_ci struct address_space *mapping; 146262306a36Sopenharmony_ci struct cifs_aio_ctx *ctx; 146362306a36Sopenharmony_ci __u64 offset; 146462306a36Sopenharmony_ci ssize_t got_bytes; 146562306a36Sopenharmony_ci unsigned int bytes; 146662306a36Sopenharmony_ci pid_t pid; 146762306a36Sopenharmony_ci int result; 146862306a36Sopenharmony_ci struct work_struct work; 146962306a36Sopenharmony_ci struct iov_iter iter; 147062306a36Sopenharmony_ci struct kvec iov[2]; 147162306a36Sopenharmony_ci struct TCP_Server_Info *server; 147262306a36Sopenharmony_ci#ifdef CONFIG_CIFS_SMB_DIRECT 147362306a36Sopenharmony_ci struct smbd_mr *mr; 147462306a36Sopenharmony_ci#endif 147562306a36Sopenharmony_ci struct cifs_credits credits; 147662306a36Sopenharmony_ci}; 147762306a36Sopenharmony_ci 147862306a36Sopenharmony_ci/* asynchronous write support */ 147962306a36Sopenharmony_cistruct cifs_writedata { 148062306a36Sopenharmony_ci struct kref refcount; 148162306a36Sopenharmony_ci struct list_head list; 148262306a36Sopenharmony_ci struct completion done; 148362306a36Sopenharmony_ci enum writeback_sync_modes sync_mode; 148462306a36Sopenharmony_ci struct work_struct work; 148562306a36Sopenharmony_ci struct cifsFileInfo *cfile; 148662306a36Sopenharmony_ci struct cifs_aio_ctx *ctx; 148762306a36Sopenharmony_ci struct iov_iter iter; 148862306a36Sopenharmony_ci struct bio_vec *bv; 148962306a36Sopenharmony_ci __u64 offset; 149062306a36Sopenharmony_ci pid_t pid; 149162306a36Sopenharmony_ci unsigned int bytes; 149262306a36Sopenharmony_ci int result; 149362306a36Sopenharmony_ci struct TCP_Server_Info *server; 149462306a36Sopenharmony_ci#ifdef CONFIG_CIFS_SMB_DIRECT 149562306a36Sopenharmony_ci struct smbd_mr *mr; 149662306a36Sopenharmony_ci#endif 149762306a36Sopenharmony_ci struct cifs_credits credits; 149862306a36Sopenharmony_ci}; 149962306a36Sopenharmony_ci 150062306a36Sopenharmony_ci/* 150162306a36Sopenharmony_ci * Take a reference on the file private data. Must be called with 150262306a36Sopenharmony_ci * cfile->file_info_lock held. 150362306a36Sopenharmony_ci */ 150462306a36Sopenharmony_cistatic inline void 150562306a36Sopenharmony_cicifsFileInfo_get_locked(struct cifsFileInfo *cifs_file) 150662306a36Sopenharmony_ci{ 150762306a36Sopenharmony_ci ++cifs_file->count; 150862306a36Sopenharmony_ci} 150962306a36Sopenharmony_ci 151062306a36Sopenharmony_cistruct cifsFileInfo *cifsFileInfo_get(struct cifsFileInfo *cifs_file); 151162306a36Sopenharmony_civoid _cifsFileInfo_put(struct cifsFileInfo *cifs_file, bool wait_oplock_hdlr, 151262306a36Sopenharmony_ci bool offload); 151362306a36Sopenharmony_civoid cifsFileInfo_put(struct cifsFileInfo *cifs_file); 151462306a36Sopenharmony_ci 151562306a36Sopenharmony_ci#define CIFS_CACHE_READ_FLG 1 151662306a36Sopenharmony_ci#define CIFS_CACHE_HANDLE_FLG 2 151762306a36Sopenharmony_ci#define CIFS_CACHE_RH_FLG (CIFS_CACHE_READ_FLG | CIFS_CACHE_HANDLE_FLG) 151862306a36Sopenharmony_ci#define CIFS_CACHE_WRITE_FLG 4 151962306a36Sopenharmony_ci#define CIFS_CACHE_RW_FLG (CIFS_CACHE_READ_FLG | CIFS_CACHE_WRITE_FLG) 152062306a36Sopenharmony_ci#define CIFS_CACHE_RHW_FLG (CIFS_CACHE_RW_FLG | CIFS_CACHE_HANDLE_FLG) 152162306a36Sopenharmony_ci 152262306a36Sopenharmony_ci#define CIFS_CACHE_READ(cinode) ((cinode->oplock & CIFS_CACHE_READ_FLG) || (CIFS_SB(cinode->netfs.inode.i_sb)->mnt_cifs_flags & CIFS_MOUNT_RO_CACHE)) 152362306a36Sopenharmony_ci#define CIFS_CACHE_HANDLE(cinode) (cinode->oplock & CIFS_CACHE_HANDLE_FLG) 152462306a36Sopenharmony_ci#define CIFS_CACHE_WRITE(cinode) ((cinode->oplock & CIFS_CACHE_WRITE_FLG) || (CIFS_SB(cinode->netfs.inode.i_sb)->mnt_cifs_flags & CIFS_MOUNT_RW_CACHE)) 152562306a36Sopenharmony_ci 152662306a36Sopenharmony_ci/* 152762306a36Sopenharmony_ci * One of these for each file inode 152862306a36Sopenharmony_ci */ 152962306a36Sopenharmony_ci 153062306a36Sopenharmony_cistruct cifsInodeInfo { 153162306a36Sopenharmony_ci struct netfs_inode netfs; /* Netfslib context and vfs inode */ 153262306a36Sopenharmony_ci bool can_cache_brlcks; 153362306a36Sopenharmony_ci struct list_head llist; /* locks helb by this inode */ 153462306a36Sopenharmony_ci /* 153562306a36Sopenharmony_ci * NOTE: Some code paths call down_read(lock_sem) twice, so 153662306a36Sopenharmony_ci * we must always use cifs_down_write() instead of down_write() 153762306a36Sopenharmony_ci * for this semaphore to avoid deadlocks. 153862306a36Sopenharmony_ci */ 153962306a36Sopenharmony_ci struct rw_semaphore lock_sem; /* protect the fields above */ 154062306a36Sopenharmony_ci /* BB add in lists for dirty pages i.e. write caching info for oplock */ 154162306a36Sopenharmony_ci struct list_head openFileList; 154262306a36Sopenharmony_ci spinlock_t open_file_lock; /* protects openFileList */ 154362306a36Sopenharmony_ci __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */ 154462306a36Sopenharmony_ci unsigned int oplock; /* oplock/lease level we have */ 154562306a36Sopenharmony_ci unsigned int epoch; /* used to track lease state changes */ 154662306a36Sopenharmony_ci#define CIFS_INODE_PENDING_OPLOCK_BREAK (0) /* oplock break in progress */ 154762306a36Sopenharmony_ci#define CIFS_INODE_PENDING_WRITERS (1) /* Writes in progress */ 154862306a36Sopenharmony_ci#define CIFS_INODE_FLAG_UNUSED (2) /* Unused flag */ 154962306a36Sopenharmony_ci#define CIFS_INO_DELETE_PENDING (3) /* delete pending on server */ 155062306a36Sopenharmony_ci#define CIFS_INO_INVALID_MAPPING (4) /* pagecache is invalid */ 155162306a36Sopenharmony_ci#define CIFS_INO_LOCK (5) /* lock bit for synchronization */ 155262306a36Sopenharmony_ci#define CIFS_INO_MODIFIED_ATTR (6) /* Indicate change in mtime/ctime */ 155362306a36Sopenharmony_ci#define CIFS_INO_CLOSE_ON_LOCK (7) /* Not to defer the close when lock is set */ 155462306a36Sopenharmony_ci unsigned long flags; 155562306a36Sopenharmony_ci spinlock_t writers_lock; 155662306a36Sopenharmony_ci unsigned int writers; /* Number of writers on this inode */ 155762306a36Sopenharmony_ci unsigned long time; /* jiffies of last update of inode */ 155862306a36Sopenharmony_ci u64 server_eof; /* current file size on server -- protected by i_lock */ 155962306a36Sopenharmony_ci u64 uniqueid; /* server inode number */ 156062306a36Sopenharmony_ci u64 createtime; /* creation time on server */ 156162306a36Sopenharmony_ci __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for this inode */ 156262306a36Sopenharmony_ci struct list_head deferred_closes; /* list of deferred closes */ 156362306a36Sopenharmony_ci spinlock_t deferred_lock; /* protection on deferred list */ 156462306a36Sopenharmony_ci bool lease_granted; /* Flag to indicate whether lease or oplock is granted. */ 156562306a36Sopenharmony_ci char *symlink_target; 156662306a36Sopenharmony_ci __u32 reparse_tag; 156762306a36Sopenharmony_ci}; 156862306a36Sopenharmony_ci 156962306a36Sopenharmony_cistatic inline struct cifsInodeInfo * 157062306a36Sopenharmony_ciCIFS_I(struct inode *inode) 157162306a36Sopenharmony_ci{ 157262306a36Sopenharmony_ci return container_of(inode, struct cifsInodeInfo, netfs.inode); 157362306a36Sopenharmony_ci} 157462306a36Sopenharmony_ci 157562306a36Sopenharmony_cistatic inline struct cifs_sb_info * 157662306a36Sopenharmony_ciCIFS_SB(struct super_block *sb) 157762306a36Sopenharmony_ci{ 157862306a36Sopenharmony_ci return sb->s_fs_info; 157962306a36Sopenharmony_ci} 158062306a36Sopenharmony_ci 158162306a36Sopenharmony_cistatic inline struct cifs_sb_info * 158262306a36Sopenharmony_ciCIFS_FILE_SB(struct file *file) 158362306a36Sopenharmony_ci{ 158462306a36Sopenharmony_ci return CIFS_SB(file_inode(file)->i_sb); 158562306a36Sopenharmony_ci} 158662306a36Sopenharmony_ci 158762306a36Sopenharmony_cistatic inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb) 158862306a36Sopenharmony_ci{ 158962306a36Sopenharmony_ci if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) 159062306a36Sopenharmony_ci return '/'; 159162306a36Sopenharmony_ci else 159262306a36Sopenharmony_ci return '\\'; 159362306a36Sopenharmony_ci} 159462306a36Sopenharmony_ci 159562306a36Sopenharmony_cistatic inline void 159662306a36Sopenharmony_ciconvert_delimiter(char *path, char delim) 159762306a36Sopenharmony_ci{ 159862306a36Sopenharmony_ci char old_delim, *pos; 159962306a36Sopenharmony_ci 160062306a36Sopenharmony_ci if (delim == '/') 160162306a36Sopenharmony_ci old_delim = '\\'; 160262306a36Sopenharmony_ci else 160362306a36Sopenharmony_ci old_delim = '/'; 160462306a36Sopenharmony_ci 160562306a36Sopenharmony_ci pos = path; 160662306a36Sopenharmony_ci while ((pos = strchr(pos, old_delim))) 160762306a36Sopenharmony_ci *pos = delim; 160862306a36Sopenharmony_ci} 160962306a36Sopenharmony_ci 161062306a36Sopenharmony_ci#define cifs_stats_inc atomic_inc 161162306a36Sopenharmony_ci 161262306a36Sopenharmony_cistatic inline void cifs_stats_bytes_written(struct cifs_tcon *tcon, 161362306a36Sopenharmony_ci unsigned int bytes) 161462306a36Sopenharmony_ci{ 161562306a36Sopenharmony_ci if (bytes) { 161662306a36Sopenharmony_ci spin_lock(&tcon->stat_lock); 161762306a36Sopenharmony_ci tcon->bytes_written += bytes; 161862306a36Sopenharmony_ci spin_unlock(&tcon->stat_lock); 161962306a36Sopenharmony_ci } 162062306a36Sopenharmony_ci} 162162306a36Sopenharmony_ci 162262306a36Sopenharmony_cistatic inline void cifs_stats_bytes_read(struct cifs_tcon *tcon, 162362306a36Sopenharmony_ci unsigned int bytes) 162462306a36Sopenharmony_ci{ 162562306a36Sopenharmony_ci spin_lock(&tcon->stat_lock); 162662306a36Sopenharmony_ci tcon->bytes_read += bytes; 162762306a36Sopenharmony_ci spin_unlock(&tcon->stat_lock); 162862306a36Sopenharmony_ci} 162962306a36Sopenharmony_ci 163062306a36Sopenharmony_ci 163162306a36Sopenharmony_ci/* 163262306a36Sopenharmony_ci * This is the prototype for the mid receive function. This function is for 163362306a36Sopenharmony_ci * receiving the rest of the SMB frame, starting with the WordCount (which is 163462306a36Sopenharmony_ci * just after the MID in struct smb_hdr). Note: 163562306a36Sopenharmony_ci * 163662306a36Sopenharmony_ci * - This will be called by cifsd, with no locks held. 163762306a36Sopenharmony_ci * - The mid will still be on the pending_mid_q. 163862306a36Sopenharmony_ci * - mid->resp_buf will point to the current buffer. 163962306a36Sopenharmony_ci * 164062306a36Sopenharmony_ci * Returns zero on a successful receive, or an error. The receive state in 164162306a36Sopenharmony_ci * the TCP_Server_Info will also be updated. 164262306a36Sopenharmony_ci */ 164362306a36Sopenharmony_citypedef int (mid_receive_t)(struct TCP_Server_Info *server, 164462306a36Sopenharmony_ci struct mid_q_entry *mid); 164562306a36Sopenharmony_ci 164662306a36Sopenharmony_ci/* 164762306a36Sopenharmony_ci * This is the prototype for the mid callback function. This is called once the 164862306a36Sopenharmony_ci * mid has been received off of the socket. When creating one, take special 164962306a36Sopenharmony_ci * care to avoid deadlocks. Things to bear in mind: 165062306a36Sopenharmony_ci * 165162306a36Sopenharmony_ci * - it will be called by cifsd, with no locks held 165262306a36Sopenharmony_ci * - the mid will be removed from any lists 165362306a36Sopenharmony_ci */ 165462306a36Sopenharmony_citypedef void (mid_callback_t)(struct mid_q_entry *mid); 165562306a36Sopenharmony_ci 165662306a36Sopenharmony_ci/* 165762306a36Sopenharmony_ci * This is the protopyte for mid handle function. This is called once the mid 165862306a36Sopenharmony_ci * has been recognized after decryption of the message. 165962306a36Sopenharmony_ci */ 166062306a36Sopenharmony_citypedef int (mid_handle_t)(struct TCP_Server_Info *server, 166162306a36Sopenharmony_ci struct mid_q_entry *mid); 166262306a36Sopenharmony_ci 166362306a36Sopenharmony_ci/* one of these for every pending CIFS request to the server */ 166462306a36Sopenharmony_cistruct mid_q_entry { 166562306a36Sopenharmony_ci struct list_head qhead; /* mids waiting on reply from this server */ 166662306a36Sopenharmony_ci struct kref refcount; 166762306a36Sopenharmony_ci struct TCP_Server_Info *server; /* server corresponding to this mid */ 166862306a36Sopenharmony_ci __u64 mid; /* multiplex id */ 166962306a36Sopenharmony_ci __u16 credits; /* number of credits consumed by this mid */ 167062306a36Sopenharmony_ci __u16 credits_received; /* number of credits from the response */ 167162306a36Sopenharmony_ci __u32 pid; /* process id */ 167262306a36Sopenharmony_ci __u32 sequence_number; /* for CIFS signing */ 167362306a36Sopenharmony_ci unsigned long when_alloc; /* when mid was created */ 167462306a36Sopenharmony_ci#ifdef CONFIG_CIFS_STATS2 167562306a36Sopenharmony_ci unsigned long when_sent; /* time when smb send finished */ 167662306a36Sopenharmony_ci unsigned long when_received; /* when demux complete (taken off wire) */ 167762306a36Sopenharmony_ci#endif 167862306a36Sopenharmony_ci mid_receive_t *receive; /* call receive callback */ 167962306a36Sopenharmony_ci mid_callback_t *callback; /* call completion callback */ 168062306a36Sopenharmony_ci mid_handle_t *handle; /* call handle mid callback */ 168162306a36Sopenharmony_ci void *callback_data; /* general purpose pointer for callback */ 168262306a36Sopenharmony_ci struct task_struct *creator; 168362306a36Sopenharmony_ci void *resp_buf; /* pointer to received SMB header */ 168462306a36Sopenharmony_ci unsigned int resp_buf_size; 168562306a36Sopenharmony_ci int mid_state; /* wish this were enum but can not pass to wait_event */ 168662306a36Sopenharmony_ci unsigned int mid_flags; 168762306a36Sopenharmony_ci __le16 command; /* smb command code */ 168862306a36Sopenharmony_ci unsigned int optype; /* operation type */ 168962306a36Sopenharmony_ci bool large_buf:1; /* if valid response, is pointer to large buf */ 169062306a36Sopenharmony_ci bool multiRsp:1; /* multiple trans2 responses for one request */ 169162306a36Sopenharmony_ci bool multiEnd:1; /* both received */ 169262306a36Sopenharmony_ci bool decrypted:1; /* decrypted entry */ 169362306a36Sopenharmony_ci}; 169462306a36Sopenharmony_ci 169562306a36Sopenharmony_cistruct close_cancelled_open { 169662306a36Sopenharmony_ci struct cifs_fid fid; 169762306a36Sopenharmony_ci struct cifs_tcon *tcon; 169862306a36Sopenharmony_ci struct work_struct work; 169962306a36Sopenharmony_ci __u64 mid; 170062306a36Sopenharmony_ci __u16 cmd; 170162306a36Sopenharmony_ci}; 170262306a36Sopenharmony_ci 170362306a36Sopenharmony_ci/* Make code in transport.c a little cleaner by moving 170462306a36Sopenharmony_ci update of optional stats into function below */ 170562306a36Sopenharmony_cistatic inline void cifs_in_send_inc(struct TCP_Server_Info *server) 170662306a36Sopenharmony_ci{ 170762306a36Sopenharmony_ci atomic_inc(&server->in_send); 170862306a36Sopenharmony_ci} 170962306a36Sopenharmony_ci 171062306a36Sopenharmony_cistatic inline void cifs_in_send_dec(struct TCP_Server_Info *server) 171162306a36Sopenharmony_ci{ 171262306a36Sopenharmony_ci atomic_dec(&server->in_send); 171362306a36Sopenharmony_ci} 171462306a36Sopenharmony_ci 171562306a36Sopenharmony_cistatic inline void cifs_num_waiters_inc(struct TCP_Server_Info *server) 171662306a36Sopenharmony_ci{ 171762306a36Sopenharmony_ci atomic_inc(&server->num_waiters); 171862306a36Sopenharmony_ci} 171962306a36Sopenharmony_ci 172062306a36Sopenharmony_cistatic inline void cifs_num_waiters_dec(struct TCP_Server_Info *server) 172162306a36Sopenharmony_ci{ 172262306a36Sopenharmony_ci atomic_dec(&server->num_waiters); 172362306a36Sopenharmony_ci} 172462306a36Sopenharmony_ci 172562306a36Sopenharmony_ci#ifdef CONFIG_CIFS_STATS2 172662306a36Sopenharmony_cistatic inline void cifs_save_when_sent(struct mid_q_entry *mid) 172762306a36Sopenharmony_ci{ 172862306a36Sopenharmony_ci mid->when_sent = jiffies; 172962306a36Sopenharmony_ci} 173062306a36Sopenharmony_ci#else 173162306a36Sopenharmony_cistatic inline void cifs_save_when_sent(struct mid_q_entry *mid) 173262306a36Sopenharmony_ci{ 173362306a36Sopenharmony_ci} 173462306a36Sopenharmony_ci#endif 173562306a36Sopenharmony_ci 173662306a36Sopenharmony_ci/* for pending dnotify requests */ 173762306a36Sopenharmony_cistruct dir_notify_req { 173862306a36Sopenharmony_ci struct list_head lhead; 173962306a36Sopenharmony_ci __le16 Pid; 174062306a36Sopenharmony_ci __le16 PidHigh; 174162306a36Sopenharmony_ci __u16 Mid; 174262306a36Sopenharmony_ci __u16 Tid; 174362306a36Sopenharmony_ci __u16 Uid; 174462306a36Sopenharmony_ci __u16 netfid; 174562306a36Sopenharmony_ci __u32 filter; /* CompletionFilter (for multishot) */ 174662306a36Sopenharmony_ci int multishot; 174762306a36Sopenharmony_ci struct file *pfile; 174862306a36Sopenharmony_ci}; 174962306a36Sopenharmony_ci 175062306a36Sopenharmony_cistruct dfs_info3_param { 175162306a36Sopenharmony_ci int flags; /* DFSREF_REFERRAL_SERVER, DFSREF_STORAGE_SERVER*/ 175262306a36Sopenharmony_ci int path_consumed; 175362306a36Sopenharmony_ci int server_type; 175462306a36Sopenharmony_ci int ref_flag; 175562306a36Sopenharmony_ci char *path_name; 175662306a36Sopenharmony_ci char *node_name; 175762306a36Sopenharmony_ci int ttl; 175862306a36Sopenharmony_ci}; 175962306a36Sopenharmony_ci 176062306a36Sopenharmony_cistruct file_list { 176162306a36Sopenharmony_ci struct list_head list; 176262306a36Sopenharmony_ci struct cifsFileInfo *cfile; 176362306a36Sopenharmony_ci}; 176462306a36Sopenharmony_ci 176562306a36Sopenharmony_cistruct cifs_mount_ctx { 176662306a36Sopenharmony_ci struct cifs_sb_info *cifs_sb; 176762306a36Sopenharmony_ci struct smb3_fs_context *fs_ctx; 176862306a36Sopenharmony_ci unsigned int xid; 176962306a36Sopenharmony_ci struct TCP_Server_Info *server; 177062306a36Sopenharmony_ci struct cifs_ses *ses; 177162306a36Sopenharmony_ci struct cifs_tcon *tcon; 177262306a36Sopenharmony_ci struct list_head dfs_ses_list; 177362306a36Sopenharmony_ci}; 177462306a36Sopenharmony_ci 177562306a36Sopenharmony_cistatic inline void __free_dfs_info_param(struct dfs_info3_param *param) 177662306a36Sopenharmony_ci{ 177762306a36Sopenharmony_ci kfree(param->path_name); 177862306a36Sopenharmony_ci kfree(param->node_name); 177962306a36Sopenharmony_ci} 178062306a36Sopenharmony_ci 178162306a36Sopenharmony_cistatic inline void free_dfs_info_param(struct dfs_info3_param *param) 178262306a36Sopenharmony_ci{ 178362306a36Sopenharmony_ci if (param) 178462306a36Sopenharmony_ci __free_dfs_info_param(param); 178562306a36Sopenharmony_ci} 178662306a36Sopenharmony_ci 178762306a36Sopenharmony_cistatic inline void zfree_dfs_info_param(struct dfs_info3_param *param) 178862306a36Sopenharmony_ci{ 178962306a36Sopenharmony_ci if (param) { 179062306a36Sopenharmony_ci __free_dfs_info_param(param); 179162306a36Sopenharmony_ci memset(param, 0, sizeof(*param)); 179262306a36Sopenharmony_ci } 179362306a36Sopenharmony_ci} 179462306a36Sopenharmony_ci 179562306a36Sopenharmony_cistatic inline void free_dfs_info_array(struct dfs_info3_param *param, 179662306a36Sopenharmony_ci int number_of_items) 179762306a36Sopenharmony_ci{ 179862306a36Sopenharmony_ci int i; 179962306a36Sopenharmony_ci 180062306a36Sopenharmony_ci if ((number_of_items == 0) || (param == NULL)) 180162306a36Sopenharmony_ci return; 180262306a36Sopenharmony_ci for (i = 0; i < number_of_items; i++) { 180362306a36Sopenharmony_ci kfree(param[i].path_name); 180462306a36Sopenharmony_ci kfree(param[i].node_name); 180562306a36Sopenharmony_ci } 180662306a36Sopenharmony_ci kfree(param); 180762306a36Sopenharmony_ci} 180862306a36Sopenharmony_ci 180962306a36Sopenharmony_cistatic inline bool is_interrupt_error(int error) 181062306a36Sopenharmony_ci{ 181162306a36Sopenharmony_ci switch (error) { 181262306a36Sopenharmony_ci case -EINTR: 181362306a36Sopenharmony_ci case -ERESTARTSYS: 181462306a36Sopenharmony_ci case -ERESTARTNOHAND: 181562306a36Sopenharmony_ci case -ERESTARTNOINTR: 181662306a36Sopenharmony_ci return true; 181762306a36Sopenharmony_ci } 181862306a36Sopenharmony_ci return false; 181962306a36Sopenharmony_ci} 182062306a36Sopenharmony_ci 182162306a36Sopenharmony_cistatic inline bool is_retryable_error(int error) 182262306a36Sopenharmony_ci{ 182362306a36Sopenharmony_ci if (is_interrupt_error(error) || error == -EAGAIN) 182462306a36Sopenharmony_ci return true; 182562306a36Sopenharmony_ci return false; 182662306a36Sopenharmony_ci} 182762306a36Sopenharmony_ci 182862306a36Sopenharmony_cistatic inline bool is_replayable_error(int error) 182962306a36Sopenharmony_ci{ 183062306a36Sopenharmony_ci if (error == -EAGAIN || error == -ECONNABORTED) 183162306a36Sopenharmony_ci return true; 183262306a36Sopenharmony_ci return false; 183362306a36Sopenharmony_ci} 183462306a36Sopenharmony_ci 183562306a36Sopenharmony_ci 183662306a36Sopenharmony_ci/* cifs_get_writable_file() flags */ 183762306a36Sopenharmony_ci#define FIND_WR_ANY 0 183862306a36Sopenharmony_ci#define FIND_WR_FSUID_ONLY 1 183962306a36Sopenharmony_ci#define FIND_WR_WITH_DELETE 2 184062306a36Sopenharmony_ci 184162306a36Sopenharmony_ci#define MID_FREE 0 184262306a36Sopenharmony_ci#define MID_REQUEST_ALLOCATED 1 184362306a36Sopenharmony_ci#define MID_REQUEST_SUBMITTED 2 184462306a36Sopenharmony_ci#define MID_RESPONSE_RECEIVED 4 184562306a36Sopenharmony_ci#define MID_RETRY_NEEDED 8 /* session closed while this request out */ 184662306a36Sopenharmony_ci#define MID_RESPONSE_MALFORMED 0x10 184762306a36Sopenharmony_ci#define MID_SHUTDOWN 0x20 184862306a36Sopenharmony_ci#define MID_RESPONSE_READY 0x40 /* ready for other process handle the rsp */ 184962306a36Sopenharmony_ci 185062306a36Sopenharmony_ci/* Flags */ 185162306a36Sopenharmony_ci#define MID_WAIT_CANCELLED 1 /* Cancelled while waiting for response */ 185262306a36Sopenharmony_ci#define MID_DELETED 2 /* Mid has been dequeued/deleted */ 185362306a36Sopenharmony_ci 185462306a36Sopenharmony_ci/* Types of response buffer returned from SendReceive2 */ 185562306a36Sopenharmony_ci#define CIFS_NO_BUFFER 0 /* Response buffer not returned */ 185662306a36Sopenharmony_ci#define CIFS_SMALL_BUFFER 1 185762306a36Sopenharmony_ci#define CIFS_LARGE_BUFFER 2 185862306a36Sopenharmony_ci#define CIFS_IOVEC 4 /* array of response buffers */ 185962306a36Sopenharmony_ci 186062306a36Sopenharmony_ci/* Type of Request to SendReceive2 */ 186162306a36Sopenharmony_ci#define CIFS_BLOCKING_OP 1 /* operation can block */ 186262306a36Sopenharmony_ci#define CIFS_NON_BLOCKING 2 /* do not block waiting for credits */ 186362306a36Sopenharmony_ci#define CIFS_TIMEOUT_MASK 0x003 /* only one of above set in req */ 186462306a36Sopenharmony_ci#define CIFS_LOG_ERROR 0x010 /* log NT STATUS if non-zero */ 186562306a36Sopenharmony_ci#define CIFS_LARGE_BUF_OP 0x020 /* large request buffer */ 186662306a36Sopenharmony_ci#define CIFS_NO_RSP_BUF 0x040 /* no response buffer required */ 186762306a36Sopenharmony_ci 186862306a36Sopenharmony_ci/* Type of request operation */ 186962306a36Sopenharmony_ci#define CIFS_ECHO_OP 0x080 /* echo request */ 187062306a36Sopenharmony_ci#define CIFS_OBREAK_OP 0x0100 /* oplock break request */ 187162306a36Sopenharmony_ci#define CIFS_NEG_OP 0x0200 /* negotiate request */ 187262306a36Sopenharmony_ci#define CIFS_CP_CREATE_CLOSE_OP 0x0400 /* compound create+close request */ 187362306a36Sopenharmony_ci/* Lower bitmask values are reserved by others below. */ 187462306a36Sopenharmony_ci#define CIFS_SESS_OP 0x2000 /* session setup request */ 187562306a36Sopenharmony_ci#define CIFS_OP_MASK 0x2780 /* mask request type */ 187662306a36Sopenharmony_ci 187762306a36Sopenharmony_ci#define CIFS_HAS_CREDITS 0x0400 /* already has credits */ 187862306a36Sopenharmony_ci#define CIFS_TRANSFORM_REQ 0x0800 /* transform request before sending */ 187962306a36Sopenharmony_ci#define CIFS_NO_SRV_RSP 0x1000 /* there is no server response */ 188062306a36Sopenharmony_ci 188162306a36Sopenharmony_ci/* Security Flags: indicate type of session setup needed */ 188262306a36Sopenharmony_ci#define CIFSSEC_MAY_SIGN 0x00001 188362306a36Sopenharmony_ci#define CIFSSEC_MAY_NTLMV2 0x00004 188462306a36Sopenharmony_ci#define CIFSSEC_MAY_KRB5 0x00008 188562306a36Sopenharmony_ci#define CIFSSEC_MAY_SEAL 0x00040 /* not supported yet */ 188662306a36Sopenharmony_ci#define CIFSSEC_MAY_NTLMSSP 0x00080 /* raw ntlmssp with ntlmv2 */ 188762306a36Sopenharmony_ci 188862306a36Sopenharmony_ci#define CIFSSEC_MUST_SIGN 0x01001 188962306a36Sopenharmony_ci/* note that only one of the following can be set so the 189062306a36Sopenharmony_ciresult of setting MUST flags more than once will be to 189162306a36Sopenharmony_cirequire use of the stronger protocol */ 189262306a36Sopenharmony_ci#define CIFSSEC_MUST_NTLMV2 0x04004 189362306a36Sopenharmony_ci#define CIFSSEC_MUST_KRB5 0x08008 189462306a36Sopenharmony_ci#ifdef CONFIG_CIFS_UPCALL 189562306a36Sopenharmony_ci#define CIFSSEC_MASK 0x8F08F /* flags supported if no weak allowed */ 189662306a36Sopenharmony_ci#else 189762306a36Sopenharmony_ci#define CIFSSEC_MASK 0x87087 /* flags supported if no weak allowed */ 189862306a36Sopenharmony_ci#endif /* UPCALL */ 189962306a36Sopenharmony_ci#define CIFSSEC_MUST_SEAL 0x40040 /* not supported yet */ 190062306a36Sopenharmony_ci#define CIFSSEC_MUST_NTLMSSP 0x80080 /* raw ntlmssp with ntlmv2 */ 190162306a36Sopenharmony_ci 190262306a36Sopenharmony_ci#define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_NTLMSSP) 190362306a36Sopenharmony_ci#define CIFSSEC_MAX (CIFSSEC_MUST_NTLMV2) 190462306a36Sopenharmony_ci#define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP) 190562306a36Sopenharmony_ci/* 190662306a36Sopenharmony_ci ***************************************************************** 190762306a36Sopenharmony_ci * All constants go here 190862306a36Sopenharmony_ci ***************************************************************** 190962306a36Sopenharmony_ci */ 191062306a36Sopenharmony_ci 191162306a36Sopenharmony_ci#define UID_HASH (16) 191262306a36Sopenharmony_ci 191362306a36Sopenharmony_ci/* 191462306a36Sopenharmony_ci * Note that ONE module should define _DECLARE_GLOBALS_HERE to cause the 191562306a36Sopenharmony_ci * following to be declared. 191662306a36Sopenharmony_ci */ 191762306a36Sopenharmony_ci 191862306a36Sopenharmony_ci/**************************************************************************** 191962306a36Sopenharmony_ci * Here are all the locks (spinlock, mutex, semaphore) in cifs.ko, arranged according 192062306a36Sopenharmony_ci * to the locking order. i.e. if two locks are to be held together, the lock that 192162306a36Sopenharmony_ci * appears higher in this list needs to be taken before the other. 192262306a36Sopenharmony_ci * 192362306a36Sopenharmony_ci * If you hold a lock that is lower in this list, and you need to take a higher lock 192462306a36Sopenharmony_ci * (or if you think that one of the functions that you're calling may need to), first 192562306a36Sopenharmony_ci * drop the lock you hold, pick up the higher lock, then the lower one. This will 192662306a36Sopenharmony_ci * ensure that locks are picked up only in one direction in the below table 192762306a36Sopenharmony_ci * (top to bottom). 192862306a36Sopenharmony_ci * 192962306a36Sopenharmony_ci * Also, if you expect a function to be called with a lock held, explicitly document 193062306a36Sopenharmony_ci * this in the comments on top of your function definition. 193162306a36Sopenharmony_ci * 193262306a36Sopenharmony_ci * And also, try to keep the critical sections (lock hold time) to be as minimal as 193362306a36Sopenharmony_ci * possible. Blocking / calling other functions with a lock held always increase 193462306a36Sopenharmony_ci * the risk of a possible deadlock. 193562306a36Sopenharmony_ci * 193662306a36Sopenharmony_ci * Following this rule will avoid unnecessary deadlocks, which can get really hard to 193762306a36Sopenharmony_ci * debug. Also, any new lock that you introduce, please add to this list in the correct 193862306a36Sopenharmony_ci * order. 193962306a36Sopenharmony_ci * 194062306a36Sopenharmony_ci * Please populate this list whenever you introduce new locks in your changes. Or in 194162306a36Sopenharmony_ci * case I've missed some existing locks. Please ensure that it's added in the list 194262306a36Sopenharmony_ci * based on the locking order expected. 194362306a36Sopenharmony_ci * 194462306a36Sopenharmony_ci * ===================================================================================== 194562306a36Sopenharmony_ci * Lock Protects Initialization fn 194662306a36Sopenharmony_ci * ===================================================================================== 194762306a36Sopenharmony_ci * vol_list_lock 194862306a36Sopenharmony_ci * vol_info->ctx_lock vol_info->ctx 194962306a36Sopenharmony_ci * cifs_sb_info->tlink_tree_lock cifs_sb_info->tlink_tree cifs_setup_cifs_sb 195062306a36Sopenharmony_ci * TCP_Server_Info-> TCP_Server_Info cifs_get_tcp_session 195162306a36Sopenharmony_ci * reconnect_mutex 195262306a36Sopenharmony_ci * TCP_Server_Info->srv_mutex TCP_Server_Info cifs_get_tcp_session 195362306a36Sopenharmony_ci * cifs_ses->session_mutex cifs_ses sesInfoAlloc 195462306a36Sopenharmony_ci * cifs_tcon 195562306a36Sopenharmony_ci * cifs_tcon->open_file_lock cifs_tcon->openFileList tconInfoAlloc 195662306a36Sopenharmony_ci * cifs_tcon->pending_opens 195762306a36Sopenharmony_ci * cifs_tcon->stat_lock cifs_tcon->bytes_read tconInfoAlloc 195862306a36Sopenharmony_ci * cifs_tcon->bytes_written 195962306a36Sopenharmony_ci * cifs_tcp_ses_lock cifs_tcp_ses_list sesInfoAlloc 196062306a36Sopenharmony_ci * GlobalMid_Lock GlobalMaxActiveXid init_cifs 196162306a36Sopenharmony_ci * GlobalCurrentXid 196262306a36Sopenharmony_ci * GlobalTotalActiveXid 196362306a36Sopenharmony_ci * TCP_Server_Info->srv_lock (anything in struct not protected by another lock and can change) 196462306a36Sopenharmony_ci * TCP_Server_Info->mid_lock TCP_Server_Info->pending_mid_q cifs_get_tcp_session 196562306a36Sopenharmony_ci * ->CurrentMid 196662306a36Sopenharmony_ci * (any changes in mid_q_entry fields) 196762306a36Sopenharmony_ci * TCP_Server_Info->req_lock TCP_Server_Info->in_flight cifs_get_tcp_session 196862306a36Sopenharmony_ci * ->credits 196962306a36Sopenharmony_ci * ->echo_credits 197062306a36Sopenharmony_ci * ->oplock_credits 197162306a36Sopenharmony_ci * ->reconnect_instance 197262306a36Sopenharmony_ci * cifs_ses->ses_lock (anything that is not protected by another lock and can change) 197362306a36Sopenharmony_ci * cifs_ses->iface_lock cifs_ses->iface_list sesInfoAlloc 197462306a36Sopenharmony_ci * ->iface_count 197562306a36Sopenharmony_ci * ->iface_last_update 197662306a36Sopenharmony_ci * cifs_ses->chan_lock cifs_ses->chans 197762306a36Sopenharmony_ci * ->chans_need_reconnect 197862306a36Sopenharmony_ci * ->chans_in_reconnect 197962306a36Sopenharmony_ci * cifs_tcon->tc_lock (anything that is not protected by another lock and can change) 198062306a36Sopenharmony_ci * cifsInodeInfo->open_file_lock cifsInodeInfo->openFileList cifs_alloc_inode 198162306a36Sopenharmony_ci * cifsInodeInfo->writers_lock cifsInodeInfo->writers cifsInodeInfo_alloc 198262306a36Sopenharmony_ci * cifsInodeInfo->lock_sem cifsInodeInfo->llist cifs_init_once 198362306a36Sopenharmony_ci * ->can_cache_brlcks 198462306a36Sopenharmony_ci * cifsInodeInfo->deferred_lock cifsInodeInfo->deferred_closes cifsInodeInfo_alloc 198562306a36Sopenharmony_ci * cached_fid->fid_mutex cifs_tcon->crfid tcon_info_alloc 198662306a36Sopenharmony_ci * cifsFileInfo->fh_mutex cifsFileInfo cifs_new_fileinfo 198762306a36Sopenharmony_ci * cifsFileInfo->file_info_lock cifsFileInfo->count cifs_new_fileinfo 198862306a36Sopenharmony_ci * ->invalidHandle initiate_cifs_search 198962306a36Sopenharmony_ci * ->oplock_break_cancelled 199062306a36Sopenharmony_ci * cifs_aio_ctx->aio_mutex cifs_aio_ctx cifs_aio_ctx_alloc 199162306a36Sopenharmony_ci ****************************************************************************/ 199262306a36Sopenharmony_ci 199362306a36Sopenharmony_ci#ifdef DECLARE_GLOBALS_HERE 199462306a36Sopenharmony_ci#define GLOBAL_EXTERN 199562306a36Sopenharmony_ci#else 199662306a36Sopenharmony_ci#define GLOBAL_EXTERN extern 199762306a36Sopenharmony_ci#endif 199862306a36Sopenharmony_ci 199962306a36Sopenharmony_ci/* 200062306a36Sopenharmony_ci * the list of TCP_Server_Info structures, ie each of the sockets 200162306a36Sopenharmony_ci * connecting our client to a distinct server (ip address), is 200262306a36Sopenharmony_ci * chained together by cifs_tcp_ses_list. The list of all our SMB 200362306a36Sopenharmony_ci * sessions (and from that the tree connections) can be found 200462306a36Sopenharmony_ci * by iterating over cifs_tcp_ses_list 200562306a36Sopenharmony_ci */ 200662306a36Sopenharmony_ciextern struct list_head cifs_tcp_ses_list; 200762306a36Sopenharmony_ci 200862306a36Sopenharmony_ci/* 200962306a36Sopenharmony_ci * This lock protects the cifs_tcp_ses_list, the list of smb sessions per 201062306a36Sopenharmony_ci * tcp session, and the list of tcon's per smb session. It also protects 201162306a36Sopenharmony_ci * the reference counters for the server, smb session, and tcon. 201262306a36Sopenharmony_ci * generally the locks should be taken in order tcp_ses_lock before 201362306a36Sopenharmony_ci * tcon->open_file_lock and that before file->file_info_lock since the 201462306a36Sopenharmony_ci * structure order is cifs_socket-->cifs_ses-->cifs_tcon-->cifs_file 201562306a36Sopenharmony_ci */ 201662306a36Sopenharmony_ciextern spinlock_t cifs_tcp_ses_lock; 201762306a36Sopenharmony_ci 201862306a36Sopenharmony_ci/* 201962306a36Sopenharmony_ci * Global transaction id (XID) information 202062306a36Sopenharmony_ci */ 202162306a36Sopenharmony_ciextern unsigned int GlobalCurrentXid; /* protected by GlobalMid_Sem */ 202262306a36Sopenharmony_ciextern unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */ 202362306a36Sopenharmony_ciextern unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */ 202462306a36Sopenharmony_ciextern spinlock_t GlobalMid_Lock; /* protects above & list operations on midQ entries */ 202562306a36Sopenharmony_ci 202662306a36Sopenharmony_ci/* 202762306a36Sopenharmony_ci * Global counters, updated atomically 202862306a36Sopenharmony_ci */ 202962306a36Sopenharmony_ciextern atomic_t sesInfoAllocCount; 203062306a36Sopenharmony_ciextern atomic_t tconInfoAllocCount; 203162306a36Sopenharmony_ciextern atomic_t tcpSesNextId; 203262306a36Sopenharmony_ciextern atomic_t tcpSesAllocCount; 203362306a36Sopenharmony_ciextern atomic_t tcpSesReconnectCount; 203462306a36Sopenharmony_ciextern atomic_t tconInfoReconnectCount; 203562306a36Sopenharmony_ci 203662306a36Sopenharmony_ci/* Various Debug counters */ 203762306a36Sopenharmony_ciextern atomic_t buf_alloc_count; /* current number allocated */ 203862306a36Sopenharmony_ciextern atomic_t small_buf_alloc_count; 203962306a36Sopenharmony_ci#ifdef CONFIG_CIFS_STATS2 204062306a36Sopenharmony_ciextern atomic_t total_buf_alloc_count; /* total allocated over all time */ 204162306a36Sopenharmony_ciextern atomic_t total_small_buf_alloc_count; 204262306a36Sopenharmony_ciextern unsigned int slow_rsp_threshold; /* number of secs before logging */ 204362306a36Sopenharmony_ci#endif 204462306a36Sopenharmony_ci 204562306a36Sopenharmony_ci/* Misc globals */ 204662306a36Sopenharmony_ciextern bool enable_oplocks; /* enable or disable oplocks */ 204762306a36Sopenharmony_ciextern bool lookupCacheEnabled; 204862306a36Sopenharmony_ciextern unsigned int global_secflags; /* if on, session setup sent 204962306a36Sopenharmony_ci with more secure ntlmssp2 challenge/resp */ 205062306a36Sopenharmony_ciextern unsigned int sign_CIFS_PDUs; /* enable smb packet signing */ 205162306a36Sopenharmony_ciextern bool enable_gcm_256; /* allow optional negotiate of strongest signing (aes-gcm-256) */ 205262306a36Sopenharmony_ciextern bool require_gcm_256; /* require use of strongest signing (aes-gcm-256) */ 205362306a36Sopenharmony_ciextern bool enable_negotiate_signing; /* request use of faster (GMAC) signing if available */ 205462306a36Sopenharmony_ciextern bool linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/ 205562306a36Sopenharmony_ciextern unsigned int CIFSMaxBufSize; /* max size not including hdr */ 205662306a36Sopenharmony_ciextern unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */ 205762306a36Sopenharmony_ciextern unsigned int cifs_min_small; /* min size of small buf pool */ 205862306a36Sopenharmony_ciextern unsigned int cifs_max_pending; /* MAX requests at once to server*/ 205962306a36Sopenharmony_ciextern unsigned int dir_cache_timeout; /* max time for directory lease caching of dir */ 206062306a36Sopenharmony_ciextern bool disable_legacy_dialects; /* forbid vers=1.0 and vers=2.0 mounts */ 206162306a36Sopenharmony_ciextern atomic_t mid_count; 206262306a36Sopenharmony_ci 206362306a36Sopenharmony_civoid cifs_oplock_break(struct work_struct *work); 206462306a36Sopenharmony_civoid cifs_queue_oplock_break(struct cifsFileInfo *cfile); 206562306a36Sopenharmony_civoid smb2_deferred_work_close(struct work_struct *work); 206662306a36Sopenharmony_ci 206762306a36Sopenharmony_ciextern const struct slow_work_ops cifs_oplock_break_ops; 206862306a36Sopenharmony_ciextern struct workqueue_struct *cifsiod_wq; 206962306a36Sopenharmony_ciextern struct workqueue_struct *decrypt_wq; 207062306a36Sopenharmony_ciextern struct workqueue_struct *fileinfo_put_wq; 207162306a36Sopenharmony_ciextern struct workqueue_struct *cifsoplockd_wq; 207262306a36Sopenharmony_ciextern struct workqueue_struct *deferredclose_wq; 207362306a36Sopenharmony_ciextern __u32 cifs_lock_secret; 207462306a36Sopenharmony_ci 207562306a36Sopenharmony_ciextern mempool_t *cifs_mid_poolp; 207662306a36Sopenharmony_ci 207762306a36Sopenharmony_ci/* Operations for different SMB versions */ 207862306a36Sopenharmony_ci#define SMB1_VERSION_STRING "1.0" 207962306a36Sopenharmony_ci#define SMB20_VERSION_STRING "2.0" 208062306a36Sopenharmony_ci#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY 208162306a36Sopenharmony_ciextern struct smb_version_operations smb1_operations; 208262306a36Sopenharmony_ciextern struct smb_version_values smb1_values; 208362306a36Sopenharmony_ciextern struct smb_version_operations smb20_operations; 208462306a36Sopenharmony_ciextern struct smb_version_values smb20_values; 208562306a36Sopenharmony_ci#endif /* CIFS_ALLOW_INSECURE_LEGACY */ 208662306a36Sopenharmony_ci#define SMB21_VERSION_STRING "2.1" 208762306a36Sopenharmony_ciextern struct smb_version_operations smb21_operations; 208862306a36Sopenharmony_ciextern struct smb_version_values smb21_values; 208962306a36Sopenharmony_ci#define SMBDEFAULT_VERSION_STRING "default" 209062306a36Sopenharmony_ciextern struct smb_version_values smbdefault_values; 209162306a36Sopenharmony_ci#define SMB3ANY_VERSION_STRING "3" 209262306a36Sopenharmony_ciextern struct smb_version_values smb3any_values; 209362306a36Sopenharmony_ci#define SMB30_VERSION_STRING "3.0" 209462306a36Sopenharmony_ciextern struct smb_version_operations smb30_operations; 209562306a36Sopenharmony_ciextern struct smb_version_values smb30_values; 209662306a36Sopenharmony_ci#define SMB302_VERSION_STRING "3.02" 209762306a36Sopenharmony_ci#define ALT_SMB302_VERSION_STRING "3.0.2" 209862306a36Sopenharmony_ci/*extern struct smb_version_operations smb302_operations;*/ /* not needed yet */ 209962306a36Sopenharmony_ciextern struct smb_version_values smb302_values; 210062306a36Sopenharmony_ci#define SMB311_VERSION_STRING "3.1.1" 210162306a36Sopenharmony_ci#define ALT_SMB311_VERSION_STRING "3.11" 210262306a36Sopenharmony_ciextern struct smb_version_operations smb311_operations; 210362306a36Sopenharmony_ciextern struct smb_version_values smb311_values; 210462306a36Sopenharmony_ci 210562306a36Sopenharmony_cistatic inline char *get_security_type_str(enum securityEnum sectype) 210662306a36Sopenharmony_ci{ 210762306a36Sopenharmony_ci switch (sectype) { 210862306a36Sopenharmony_ci case RawNTLMSSP: 210962306a36Sopenharmony_ci return "RawNTLMSSP"; 211062306a36Sopenharmony_ci case Kerberos: 211162306a36Sopenharmony_ci return "Kerberos"; 211262306a36Sopenharmony_ci case NTLMv2: 211362306a36Sopenharmony_ci return "NTLMv2"; 211462306a36Sopenharmony_ci default: 211562306a36Sopenharmony_ci return "Unknown"; 211662306a36Sopenharmony_ci } 211762306a36Sopenharmony_ci} 211862306a36Sopenharmony_ci 211962306a36Sopenharmony_cistatic inline bool is_smb1_server(struct TCP_Server_Info *server) 212062306a36Sopenharmony_ci{ 212162306a36Sopenharmony_ci return strcmp(server->vals->version_string, SMB1_VERSION_STRING) == 0; 212262306a36Sopenharmony_ci} 212362306a36Sopenharmony_ci 212462306a36Sopenharmony_cistatic inline bool is_tcon_dfs(struct cifs_tcon *tcon) 212562306a36Sopenharmony_ci{ 212662306a36Sopenharmony_ci /* 212762306a36Sopenharmony_ci * For SMB1, see MS-CIFS 2.4.55 SMB_COM_TREE_CONNECT_ANDX (0x75) and MS-CIFS 3.3.4.4 DFS 212862306a36Sopenharmony_ci * Subsystem Notifies That a Share Is a DFS Share. 212962306a36Sopenharmony_ci * 213062306a36Sopenharmony_ci * For SMB2+, see MS-SMB2 2.2.10 SMB2 TREE_CONNECT Response and MS-SMB2 3.3.4.14 Server 213162306a36Sopenharmony_ci * Application Updates a Share. 213262306a36Sopenharmony_ci */ 213362306a36Sopenharmony_ci if (!tcon || !tcon->ses || !tcon->ses->server) 213462306a36Sopenharmony_ci return false; 213562306a36Sopenharmony_ci return is_smb1_server(tcon->ses->server) ? tcon->Flags & SMB_SHARE_IS_IN_DFS : 213662306a36Sopenharmony_ci tcon->share_flags & (SHI1005_FLAGS_DFS | SHI1005_FLAGS_DFS_ROOT); 213762306a36Sopenharmony_ci} 213862306a36Sopenharmony_ci 213962306a36Sopenharmony_cistatic inline bool cifs_is_referral_server(struct cifs_tcon *tcon, 214062306a36Sopenharmony_ci const struct dfs_info3_param *ref) 214162306a36Sopenharmony_ci{ 214262306a36Sopenharmony_ci /* 214362306a36Sopenharmony_ci * Check if all targets are capable of handling DFS referrals as per 214462306a36Sopenharmony_ci * MS-DFSC 2.2.4 RESP_GET_DFS_REFERRAL. 214562306a36Sopenharmony_ci */ 214662306a36Sopenharmony_ci return is_tcon_dfs(tcon) || (ref && (ref->flags & DFSREF_REFERRAL_SERVER)); 214762306a36Sopenharmony_ci} 214862306a36Sopenharmony_ci 214962306a36Sopenharmony_cistatic inline u64 cifs_flock_len(const struct file_lock *fl) 215062306a36Sopenharmony_ci{ 215162306a36Sopenharmony_ci return (u64)fl->fl_end - fl->fl_start + 1; 215262306a36Sopenharmony_ci} 215362306a36Sopenharmony_ci 215462306a36Sopenharmony_cistatic inline size_t ntlmssp_workstation_name_size(const struct cifs_ses *ses) 215562306a36Sopenharmony_ci{ 215662306a36Sopenharmony_ci if (WARN_ON_ONCE(!ses || !ses->server)) 215762306a36Sopenharmony_ci return 0; 215862306a36Sopenharmony_ci /* 215962306a36Sopenharmony_ci * Make workstation name no more than 15 chars when using insecure dialects as some legacy 216062306a36Sopenharmony_ci * servers do require it during NTLMSSP. 216162306a36Sopenharmony_ci */ 216262306a36Sopenharmony_ci if (ses->server->dialect <= SMB20_PROT_ID) 216362306a36Sopenharmony_ci return min_t(size_t, sizeof(ses->workstation_name), RFC1001_NAME_LEN_WITH_NULL); 216462306a36Sopenharmony_ci return sizeof(ses->workstation_name); 216562306a36Sopenharmony_ci} 216662306a36Sopenharmony_ci 216762306a36Sopenharmony_cistatic inline void move_cifs_info_to_smb2(struct smb2_file_all_info *dst, const FILE_ALL_INFO *src) 216862306a36Sopenharmony_ci{ 216962306a36Sopenharmony_ci memcpy(dst, src, (size_t)((u8 *)&src->AccessFlags - (u8 *)src)); 217062306a36Sopenharmony_ci dst->AccessFlags = src->AccessFlags; 217162306a36Sopenharmony_ci dst->CurrentByteOffset = src->CurrentByteOffset; 217262306a36Sopenharmony_ci dst->Mode = src->Mode; 217362306a36Sopenharmony_ci dst->AlignmentRequirement = src->AlignmentRequirement; 217462306a36Sopenharmony_ci dst->FileNameLength = src->FileNameLength; 217562306a36Sopenharmony_ci} 217662306a36Sopenharmony_ci 217762306a36Sopenharmony_cistatic inline int cifs_get_num_sgs(const struct smb_rqst *rqst, 217862306a36Sopenharmony_ci int num_rqst, 217962306a36Sopenharmony_ci const u8 *sig) 218062306a36Sopenharmony_ci{ 218162306a36Sopenharmony_ci unsigned int len, skip; 218262306a36Sopenharmony_ci unsigned int nents = 0; 218362306a36Sopenharmony_ci unsigned long addr; 218462306a36Sopenharmony_ci size_t data_size; 218562306a36Sopenharmony_ci int i, j; 218662306a36Sopenharmony_ci 218762306a36Sopenharmony_ci /* 218862306a36Sopenharmony_ci * The first rqst has a transform header where the first 20 bytes are 218962306a36Sopenharmony_ci * not part of the encrypted blob. 219062306a36Sopenharmony_ci */ 219162306a36Sopenharmony_ci skip = 20; 219262306a36Sopenharmony_ci 219362306a36Sopenharmony_ci /* Assumes the first rqst has a transform header as the first iov. 219462306a36Sopenharmony_ci * I.e. 219562306a36Sopenharmony_ci * rqst[0].rq_iov[0] is transform header 219662306a36Sopenharmony_ci * rqst[0].rq_iov[1+] data to be encrypted/decrypted 219762306a36Sopenharmony_ci * rqst[1+].rq_iov[0+] data to be encrypted/decrypted 219862306a36Sopenharmony_ci */ 219962306a36Sopenharmony_ci for (i = 0; i < num_rqst; i++) { 220062306a36Sopenharmony_ci data_size = iov_iter_count(&rqst[i].rq_iter); 220162306a36Sopenharmony_ci 220262306a36Sopenharmony_ci /* We really don't want a mixture of pinned and unpinned pages 220362306a36Sopenharmony_ci * in the sglist. It's hard to keep track of which is what. 220462306a36Sopenharmony_ci * Instead, we convert to a BVEC-type iterator higher up. 220562306a36Sopenharmony_ci */ 220662306a36Sopenharmony_ci if (data_size && 220762306a36Sopenharmony_ci WARN_ON_ONCE(user_backed_iter(&rqst[i].rq_iter))) 220862306a36Sopenharmony_ci return -EIO; 220962306a36Sopenharmony_ci 221062306a36Sopenharmony_ci /* We also don't want to have any extra refs or pins to clean 221162306a36Sopenharmony_ci * up in the sglist. 221262306a36Sopenharmony_ci */ 221362306a36Sopenharmony_ci if (data_size && 221462306a36Sopenharmony_ci WARN_ON_ONCE(iov_iter_extract_will_pin(&rqst[i].rq_iter))) 221562306a36Sopenharmony_ci return -EIO; 221662306a36Sopenharmony_ci 221762306a36Sopenharmony_ci for (j = 0; j < rqst[i].rq_nvec; j++) { 221862306a36Sopenharmony_ci struct kvec *iov = &rqst[i].rq_iov[j]; 221962306a36Sopenharmony_ci 222062306a36Sopenharmony_ci addr = (unsigned long)iov->iov_base + skip; 222162306a36Sopenharmony_ci if (unlikely(is_vmalloc_addr((void *)addr))) { 222262306a36Sopenharmony_ci len = iov->iov_len - skip; 222362306a36Sopenharmony_ci nents += DIV_ROUND_UP(offset_in_page(addr) + len, 222462306a36Sopenharmony_ci PAGE_SIZE); 222562306a36Sopenharmony_ci } else { 222662306a36Sopenharmony_ci nents++; 222762306a36Sopenharmony_ci } 222862306a36Sopenharmony_ci skip = 0; 222962306a36Sopenharmony_ci } 223062306a36Sopenharmony_ci if (data_size) 223162306a36Sopenharmony_ci nents += iov_iter_npages(&rqst[i].rq_iter, INT_MAX); 223262306a36Sopenharmony_ci } 223362306a36Sopenharmony_ci nents += DIV_ROUND_UP(offset_in_page(sig) + SMB2_SIGNATURE_SIZE, PAGE_SIZE); 223462306a36Sopenharmony_ci return nents; 223562306a36Sopenharmony_ci} 223662306a36Sopenharmony_ci 223762306a36Sopenharmony_ci/* We can not use the normal sg_set_buf() as we will sometimes pass a 223862306a36Sopenharmony_ci * stack object as buf. 223962306a36Sopenharmony_ci */ 224062306a36Sopenharmony_cistatic inline void cifs_sg_set_buf(struct sg_table *sgtable, 224162306a36Sopenharmony_ci const void *buf, 224262306a36Sopenharmony_ci unsigned int buflen) 224362306a36Sopenharmony_ci{ 224462306a36Sopenharmony_ci unsigned long addr = (unsigned long)buf; 224562306a36Sopenharmony_ci unsigned int off = offset_in_page(addr); 224662306a36Sopenharmony_ci 224762306a36Sopenharmony_ci addr &= PAGE_MASK; 224862306a36Sopenharmony_ci if (unlikely(is_vmalloc_addr((void *)addr))) { 224962306a36Sopenharmony_ci do { 225062306a36Sopenharmony_ci unsigned int len = min_t(unsigned int, buflen, PAGE_SIZE - off); 225162306a36Sopenharmony_ci 225262306a36Sopenharmony_ci sg_set_page(&sgtable->sgl[sgtable->nents++], 225362306a36Sopenharmony_ci vmalloc_to_page((void *)addr), len, off); 225462306a36Sopenharmony_ci 225562306a36Sopenharmony_ci off = 0; 225662306a36Sopenharmony_ci addr += PAGE_SIZE; 225762306a36Sopenharmony_ci buflen -= len; 225862306a36Sopenharmony_ci } while (buflen); 225962306a36Sopenharmony_ci } else { 226062306a36Sopenharmony_ci sg_set_page(&sgtable->sgl[sgtable->nents++], 226162306a36Sopenharmony_ci virt_to_page((void *)addr), buflen, off); 226262306a36Sopenharmony_ci } 226362306a36Sopenharmony_ci} 226462306a36Sopenharmony_ci 226562306a36Sopenharmony_cistruct smb2_compound_vars { 226662306a36Sopenharmony_ci struct cifs_open_parms oparms; 226762306a36Sopenharmony_ci struct kvec rsp_iov[3]; 226862306a36Sopenharmony_ci struct smb_rqst rqst[3]; 226962306a36Sopenharmony_ci struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; 227062306a36Sopenharmony_ci struct kvec qi_iov; 227162306a36Sopenharmony_ci struct kvec io_iov[SMB2_IOCTL_IOV_SIZE]; 227262306a36Sopenharmony_ci struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE]; 227362306a36Sopenharmony_ci struct kvec close_iov; 227462306a36Sopenharmony_ci struct smb2_file_rename_info rename_info; 227562306a36Sopenharmony_ci struct smb2_file_link_info link_info; 227662306a36Sopenharmony_ci}; 227762306a36Sopenharmony_ci 227862306a36Sopenharmony_ci#endif /* _CIFS_GLOB_H */ 2279