xref: /linux/include/linux/nfs_fs_sb.h (revision b88fe2b5dd018c2b856fd6c32b82f25033e908d4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NFS_FS_SB
3 #define _NFS_FS_SB
4 
5 #include <linux/list.h>
6 #include <linux/backing-dev.h>
7 #include <linux/idr.h>
8 #include <linux/wait.h>
9 #include <linux/nfs_xdr.h>
10 #include <linux/sunrpc/xprt.h>
11 #include <linux/nfslocalio.h>
12 
13 #include <linux/atomic.h>
14 #include <linux/refcount.h>
15 
16 struct nfs4_session;
17 struct nfs_iostats;
18 struct nlm_host;
19 struct nfs4_sequence_args;
20 struct nfs4_sequence_res;
21 struct nfs_server;
22 struct nfs4_minor_version_ops;
23 struct nfs41_server_scope;
24 struct nfs41_impl_id;
25 
26 /*
27  * The nfs_client identifies our client state to the server.
28  */
29 struct nfs_client {
30 	refcount_t		cl_count;
31 	atomic_t		cl_mds_count;
32 	int			cl_cons_state;	/* current construction state (-ve: init error) */
33 #define NFS_CS_READY		0		/* ready to be used */
34 #define NFS_CS_INITING		1		/* busy initialising */
35 #define NFS_CS_SESSION_INITING	2		/* busy initialising  session */
36 	unsigned long		cl_res_state;	/* NFS resources state */
37 #define NFS_CS_CALLBACK		1		/* - callback started */
38 #define NFS_CS_IDMAP		2		/* - idmap started */
39 #define NFS_CS_RENEWD		3		/* - renewd started */
40 #define NFS_CS_STOP_RENEW	4		/* no more state to renew */
41 #define NFS_CS_CHECK_LEASE_TIME	5		/* need to check lease time */
42 	unsigned long		cl_flags;	/* behavior switches */
43 #define NFS_CS_NORESVPORT	0		/* - use ephemeral src port */
44 #define NFS_CS_DISCRTRY		1		/* - disconnect on RPC retry */
45 #define NFS_CS_MIGRATION	2		/* - transparent state migr */
46 #define NFS_CS_INFINITE_SLOTS	3		/* - don't limit TCP slots */
47 #define NFS_CS_NO_RETRANS_TIMEOUT	4	/* - Disable retransmit timeouts */
48 #define NFS_CS_TSM_POSSIBLE	5		/* - Maybe state migration */
49 #define NFS_CS_NOPING		6		/* - don't ping on connect */
50 #define NFS_CS_DS		7		/* - Server is a DS */
51 #define NFS_CS_REUSEPORT	8		/* - reuse src port on reconnect */
52 #define NFS_CS_PNFS		9		/* - Server used for pnfs */
53 	struct sockaddr_storage	cl_addr;	/* server identifier */
54 	size_t			cl_addrlen;
55 	char *			cl_hostname;	/* hostname of server */
56 	char *			cl_acceptor;	/* GSSAPI acceptor name */
57 	struct list_head	cl_share_link;	/* link in global client list */
58 	struct list_head	cl_superblocks;	/* List of nfs_server structs */
59 
60 	struct rpc_clnt *	cl_rpcclient;
61 	const struct nfs_rpc_ops *rpc_ops;	/* NFS protocol vector */
62 	int			cl_proto;	/* Network transport protocol */
63 	struct nfs_subversion *	cl_nfs_mod;	/* pointer to nfs version module */
64 
65 	u32			cl_minorversion;/* NFSv4 minorversion */
66 	unsigned int		cl_nconnect;	/* Number of connections */
67 	unsigned int		cl_max_connect; /* max number of xprts allowed */
68 	const char *		cl_principal;	/* used for machine cred */
69 	struct xprtsec_parms	cl_xprtsec;	/* xprt security policy */
70 
71 #if IS_ENABLED(CONFIG_NFS_V4)
72 	struct list_head	cl_ds_clients; /* auth flavor data servers */
73 	u64			cl_clientid;	/* constant */
74 	nfs4_verifier		cl_confirm;	/* Clientid verifier */
75 	unsigned long		cl_state;
76 
77 	spinlock_t		cl_lock;
78 
79 	unsigned long		cl_lease_time;
80 	unsigned long		cl_last_renewal;
81 	struct delayed_work	cl_renewd;
82 
83 	struct rpc_wait_queue	cl_rpcwaitq;
84 
85 	/* idmapper */
86 	struct idmap *		cl_idmap;
87 
88 	/* Client owner identifier */
89 	const char *		cl_owner_id;
90 
91 	u32			cl_cb_ident;	/* v4.0 callback identifier */
92 	const struct nfs4_minor_version_ops *cl_mvops;
93 	unsigned long		cl_mig_gen;
94 
95 	/* NFSv4.0 transport blocking */
96 	struct nfs4_slot_table	*cl_slot_tbl;
97 
98 	/* The sequence id to use for the next CREATE_SESSION */
99 	u32			cl_seqid;
100 	/* The flags used for obtaining the clientid during EXCHANGE_ID */
101 	u32			cl_exchange_flags;
102 	struct nfs4_session	*cl_session;	/* shared session */
103 	bool			cl_preserve_clid;
104 	struct nfs41_server_owner *cl_serverowner;
105 	struct nfs41_server_scope *cl_serverscope;
106 	struct nfs41_impl_id	*cl_implid;
107 	/* nfs 4.1+ state protection modes: */
108 	unsigned long		cl_sp4_flags;
109 #define NFS_SP4_MACH_CRED_MINIMAL  1	/* Minimal sp4_mach_cred - state ops
110 					 * must use machine cred */
111 #define NFS_SP4_MACH_CRED_CLEANUP  2	/* CLOSE and LOCKU */
112 #define NFS_SP4_MACH_CRED_SECINFO  3	/* SECINFO and SECINFO_NO_NAME */
113 #define NFS_SP4_MACH_CRED_STATEID  4	/* TEST_STATEID and FREE_STATEID */
114 #define NFS_SP4_MACH_CRED_WRITE    5	/* WRITE */
115 #define NFS_SP4_MACH_CRED_COMMIT   6	/* COMMIT */
116 #define NFS_SP4_MACH_CRED_PNFS_CLEANUP  7 /* LAYOUTRETURN */
117 #if IS_ENABLED(CONFIG_NFS_V4_1)
118 	wait_queue_head_t	cl_lock_waitq;
119 #endif /* CONFIG_NFS_V4_1 */
120 #endif /* CONFIG_NFS_V4 */
121 
122 	/* Our own IP address, as a null-terminated string.
123 	 * This is used to generate the mv0 callback address.
124 	 */
125 	char			cl_ipaddr[48];
126 	struct net		*cl_net;
127 	struct list_head	pending_cb_stateids;
128 	struct rcu_head		rcu;
129 
130 #if IS_ENABLED(CONFIG_NFS_LOCALIO)
131 	struct timespec64	cl_nfssvc_boot;
132 	seqlock_t		cl_boot_lock;
133 	nfs_uuid_t		cl_uuid;
134 	struct work_struct	cl_local_probe_work;
135 #endif /* CONFIG_NFS_LOCALIO */
136 };
137 
138 /*
139  * NFS client parameters stored in the superblock.
140  */
141 struct nfs_server {
142 	struct nfs_client *	nfs_client;	/* shared client and NFS4 state */
143 	struct list_head	client_link;	/* List of other nfs_server structs
144 						 * that share the same client
145 						 */
146 	struct list_head	master_link;	/* link in master servers list */
147 	struct rpc_clnt *	client;		/* RPC client handle */
148 	struct rpc_clnt *	client_acl;	/* ACL RPC client handle */
149 	struct nlm_host		*nlm_host;	/* NLM client handle */
150 	struct nfs_iostats __percpu *io_stats;	/* I/O statistics */
151 	wait_queue_head_t	write_congestion_wait;	/* wait until write congestion eases */
152 	atomic_long_t		writeback;	/* number of writeback pages */
153 	unsigned int		write_congested;/* flag set when writeback gets too high */
154 	unsigned int		flags;		/* various flags */
155 
156 /* The following are for internal use only. Also see uapi/linux/nfs_mount.h */
157 #define NFS_MOUNT_LOOKUP_CACHE_NONEG	0x10000
158 #define NFS_MOUNT_LOOKUP_CACHE_NONE	0x20000
159 #define NFS_MOUNT_NORESVPORT		0x40000
160 #define NFS_MOUNT_LEGACY_INTERFACE	0x80000
161 #define NFS_MOUNT_LOCAL_FLOCK		0x100000
162 #define NFS_MOUNT_LOCAL_FCNTL		0x200000
163 #define NFS_MOUNT_SOFTERR		0x400000
164 #define NFS_MOUNT_SOFTREVAL		0x800000
165 #define NFS_MOUNT_WRITE_EAGER		0x01000000
166 #define NFS_MOUNT_WRITE_WAIT		0x02000000
167 #define NFS_MOUNT_TRUNK_DISCOVERY	0x04000000
168 #define NFS_MOUNT_SHUTDOWN			0x08000000
169 #define NFS_MOUNT_NO_ALIGNWRITE		0x10000000
170 
171 	unsigned int		fattr_valid;	/* Valid attributes */
172 	unsigned int		caps;		/* server capabilities */
173 	unsigned int		rsize;		/* read size */
174 	unsigned int		rpages;		/* read size (in pages) */
175 	unsigned int		wsize;		/* write size */
176 	unsigned int		wpages;		/* write size (in pages) */
177 	unsigned int		wtmult;		/* server disk block size */
178 	unsigned int		dtsize;		/* readdir size */
179 	unsigned short		port;		/* "port=" setting */
180 	unsigned int		bsize;		/* server block size */
181 #ifdef CONFIG_NFS_V4_2
182 	unsigned int		gxasize;	/* getxattr size */
183 	unsigned int		sxasize;	/* setxattr size */
184 	unsigned int		lxasize;	/* listxattr size */
185 #endif
186 	unsigned int		acregmin;	/* attr cache timeouts */
187 	unsigned int		acregmax;
188 	unsigned int		acdirmin;
189 	unsigned int		acdirmax;
190 	unsigned int		namelen;
191 	unsigned int		options;	/* extra options enabled by mount */
192 	unsigned int		clone_blksize;	/* granularity of a CLONE operation */
193 #define NFS_OPTION_FSCACHE	0x00000001	/* - local caching enabled */
194 #define NFS_OPTION_MIGRATION	0x00000002	/* - NFSv4 migration enabled */
195 
196 	enum nfs4_change_attr_type
197 				change_attr_type;/* Description of change attribute */
198 
199 	struct nfs_fsid		fsid;
200 	int			s_sysfs_id;	/* sysfs dentry index */
201 	__u64			maxfilesize;	/* maximum file size */
202 	struct timespec64	time_delta;	/* smallest time granularity */
203 	unsigned long		mount_time;	/* when this fs was mounted */
204 	struct super_block	*super;		/* VFS super block */
205 	dev_t			s_dev;		/* superblock dev numbers */
206 	struct nfs_auth_info	auth_info;	/* parsed auth flavors */
207 
208 #ifdef CONFIG_NFS_FSCACHE
209 	struct fscache_volume	*fscache;	/* superblock cookie */
210 	char			*fscache_uniq;	/* Uniquifier (or NULL) */
211 #endif
212 
213 	u32			pnfs_blksize;	/* layout_blksize attr */
214 #if IS_ENABLED(CONFIG_NFS_V4)
215 	u32			attr_bitmask[3];/* V4 bitmask representing the set
216 						   of attributes supported on this
217 						   filesystem */
218 	u32			attr_bitmask_nl[3];
219 						/* V4 bitmask representing the
220 						   set of attributes supported
221 						   on this filesystem excluding
222 						   the label support bit. */
223 	u32			exclcreat_bitmask[3];
224 						/* V4 bitmask representing the
225 						   set of attributes supported
226 						   on this filesystem for the
227 						   exclusive create. */
228 	u32			cache_consistency_bitmask[3];
229 						/* V4 bitmask representing the subset
230 						   of change attribute, size, ctime
231 						   and mtime attributes supported by
232 						   the server */
233 	u32			acl_bitmask;	/* V4 bitmask representing the ACEs
234 						   that are supported on this
235 						   filesystem */
236 	u32			fh_expire_type;	/* V4 bitmask representing file
237 						   handle volatility type for
238 						   this filesystem */
239 	struct pnfs_layoutdriver_type  *pnfs_curr_ld; /* Active layout driver */
240 	struct rpc_wait_queue	roc_rpcwaitq;
241 	void			*pnfs_ld_data;	/* per mount point data */
242 
243 	/* the following fields are protected by nfs_client->cl_lock */
244 	struct rb_root		state_owners;
245 #endif
246 	atomic64_t		owner_ctr;
247 	struct list_head	state_owners_lru;
248 	struct list_head	layouts;
249 	struct list_head	delegations;
250 	struct list_head	ss_copies;
251 	struct list_head	ss_src_copies;
252 
253 	unsigned long		delegation_gen;
254 	unsigned long		mig_gen;
255 	unsigned long		mig_status;
256 #define NFS_MIG_IN_TRANSITION		(1)
257 #define NFS_MIG_FAILED			(2)
258 #define NFS_MIG_TSM_POSSIBLE		(3)
259 
260 	void (*destroy)(struct nfs_server *);
261 
262 	atomic_t active; /* Keep trace of any activity to this server */
263 
264 	/* mountd-related mount options */
265 	struct sockaddr_storage	mountd_address;
266 	size_t			mountd_addrlen;
267 	u32			mountd_version;
268 	unsigned short		mountd_port;
269 	unsigned short		mountd_protocol;
270 	struct rpc_wait_queue	uoc_rpcwaitq;
271 
272 	/* XDR related information */
273 	unsigned int		read_hdrsize;
274 
275 	/* User namespace info */
276 	const struct cred	*cred;
277 	bool			has_sec_mnt_opts;
278 	struct kobject		kobj;
279 	struct rcu_head		rcu;
280 };
281 
282 /* Server capabilities */
283 #define NFS_CAP_READDIRPLUS	(1U << 0)
284 #define NFS_CAP_HARDLINKS	(1U << 1)
285 #define NFS_CAP_SYMLINKS	(1U << 2)
286 #define NFS_CAP_ACLS		(1U << 3)
287 #define NFS_CAP_ATOMIC_OPEN	(1U << 4)
288 #define NFS_CAP_LGOPEN		(1U << 5)
289 #define NFS_CAP_CASE_INSENSITIVE	(1U << 6)
290 #define NFS_CAP_CASE_PRESERVING	(1U << 7)
291 #define NFS_CAP_REBOOT_LAYOUTRETURN	(1U << 8)
292 #define NFS_CAP_OPEN_XOR	(1U << 12)
293 #define NFS_CAP_DELEGTIME	(1U << 13)
294 #define NFS_CAP_POSIX_LOCK	(1U << 14)
295 #define NFS_CAP_UIDGID_NOMAP	(1U << 15)
296 #define NFS_CAP_STATEID_NFSV41	(1U << 16)
297 #define NFS_CAP_ATOMIC_OPEN_V1	(1U << 17)
298 #define NFS_CAP_SECURITY_LABEL	(1U << 18)
299 #define NFS_CAP_SEEK		(1U << 19)
300 #define NFS_CAP_ALLOCATE	(1U << 20)
301 #define NFS_CAP_DEALLOCATE	(1U << 21)
302 #define NFS_CAP_LAYOUTSTATS	(1U << 22)
303 #define NFS_CAP_CLONE		(1U << 23)
304 #define NFS_CAP_COPY		(1U << 24)
305 #define NFS_CAP_OFFLOAD_CANCEL	(1U << 25)
306 #define NFS_CAP_LAYOUTERROR	(1U << 26)
307 #define NFS_CAP_COPY_NOTIFY	(1U << 27)
308 #define NFS_CAP_XATTR		(1U << 28)
309 #define NFS_CAP_READ_PLUS	(1U << 29)
310 #define NFS_CAP_FS_LOCATIONS	(1U << 30)
311 #define NFS_CAP_MOVEABLE	(1U << 31)
312 #endif
313