xref: /linux/fs/nfsd/nfsd.h (revision d141ec2825b4d3ec52f27c43bdd864090159273a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Hodge-podge collection of knfsd-related stuff.
4  * I will sort this out later.
5  *
6  * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
7  */
8 
9 #ifndef LINUX_NFSD_NFSD_H
10 #define LINUX_NFSD_NFSD_H
11 
12 #include <linux/types.h>
13 #include <linux/mount.h>
14 
15 #include <linux/nfs.h>
16 #include <linux/nfs2.h>
17 #include <linux/nfs3.h>
18 #include <linux/nfs4.h>
19 #include <linux/sunrpc/svc.h>
20 #include <linux/sunrpc/svc_xprt.h>
21 
22 #include <uapi/linux/nfsd/debug.h>
23 
24 #undef ifdebug
25 #ifdef CONFIG_SUNRPC_DEBUG
26 # define ifdebug(flag)		if (nfsd_debug & NFSDDBG_##flag)
27 #else
28 # define ifdebug(flag)		if (0)
29 #endif
30 
31 /*
32  * nfsd version
33  */
34 #define NFSD_MINVERS			2
35 #define	NFSD_MAXVERS			4
36 #define NFSD_SUPPORTED_MINOR_VERSION	2
37 bool nfsd_support_version(int vers);
38 
39 /*
40  * Default and maximum payload size (NFS READ or WRITE), in bytes.
41  * The maximum is an implementation limit.
42  */
43 enum {
44 	NFSSVC_DEFBLKSIZE       = 4 * 1024 * 1024,
45 	NFSSVC_MAXBLKSIZE       = RPCSVC_MAXPAYLOAD,
46 };
47 
48 /* Maximum number of operations per session compound */
49 #define NFSD_MAX_OPS_PER_COMPOUND	200
50 
51 extern struct svc_program	nfsd_programs[];
52 extern const struct svc_version	nfsd_version2, nfsd_version3, nfsd_version4;
53 extern struct mutex		nfsd_mutex;
54 extern atomic_t			nfsd_th_cnt;		/* number of available threads */
55 
56 extern const struct seq_operations nfs_exports_op;
57 
58 struct nfsd_thread_local_info {
59 	struct nfs4_client	**ntli_lease_breaker;
60 	int			ntli_cachetype;
61 };
62 
63 /*
64  * Common void argument and result helpers
65  */
66 struct nfsd_voidargs { };
67 struct nfsd_voidres { };
68 bool		nfssvc_decode_voidarg(struct svc_rqst *rqstp,
69 				      struct xdr_stream *xdr);
70 bool		nfssvc_encode_voidres(struct svc_rqst *rqstp,
71 				      struct xdr_stream *xdr);
72 
73 /*
74  * Function prototypes.
75  */
76 int		nfsd_svc(int n, int *nservers, struct net *net,
77 			 const struct cred *cred, const char *scope);
78 int		nfsd_dispatch(struct svc_rqst *rqstp);
79 
80 int		nfsd_nrthreads(struct net *);
81 int		nfsd_nrpools(struct net *);
82 int		nfsd_get_nrthreads(int n, int *, struct net *);
83 int		nfsd_set_nrthreads(int n, int *, struct net *);
84 void		nfsd_shutdown_threads(struct net *net);
85 
86 struct svc_rqst *nfsd_current_rqst(void);
87 
88 struct nfsdfs_client {
89 	struct kref cl_ref;
90 	void (*cl_release)(struct kref *kref);
91 };
92 
93 struct nfsd_net;
94 
95 struct nfsdfs_client *get_nfsdfs_client(struct inode *);
96 struct dentry *nfsd_client_mkdir(struct nfsd_net *nn,
97 				 struct nfsdfs_client *ncl, u32 id,
98 				 const struct tree_descr *,
99 				 struct dentry **fdentries);
100 void nfsd_client_rmdir(struct dentry *dentry);
101 int nfsd_cache_notify(struct cache_detail *cd, struct cache_head *h, u32 cache_type);
102 
103 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
104 #ifdef CONFIG_NFSD_V2_ACL
105 extern const struct svc_version nfsd_acl_version2;
106 #else
107 #define nfsd_acl_version2 NULL
108 #endif
109 #ifdef CONFIG_NFSD_V3_ACL
110 extern const struct svc_version nfsd_acl_version3;
111 #else
112 #define nfsd_acl_version3 NULL
113 #endif
114 #endif
115 
116 #if IS_ENABLED(CONFIG_NFS_LOCALIO)
117 extern const struct svc_version localio_version1;
118 #endif
119 
120 enum vers_op {NFSD_SET, NFSD_CLEAR, NFSD_TEST, NFSD_AVAIL };
121 int nfsd_vers(struct nfsd_net *nn, int vers, enum vers_op change);
122 int nfsd_minorversion(struct nfsd_net *nn, u32 minorversion, enum vers_op change);
123 void nfsd_reset_versions(struct nfsd_net *nn);
124 int nfsd_create_serv(struct net *net);
125 void nfsd_destroy_serv(struct net *net);
126 
127 #ifdef CONFIG_DEBUG_FS
128 void nfsd_debugfs_init(void);
129 void nfsd_debugfs_exit(void);
130 #else
nfsd_debugfs_init(void)131 static inline void nfsd_debugfs_init(void) {}
nfsd_debugfs_exit(void)132 static inline void nfsd_debugfs_exit(void) {}
133 #endif
134 
135 extern bool nfsd_disable_splice_read __read_mostly;
136 extern bool nfsd_delegts_enabled __read_mostly;
137 
138 enum {
139 	/* Any new NFSD_IO enum value must be added at the end */
140 	NFSD_IO_BUFFERED,
141 	NFSD_IO_DONTCACHE,
142 	NFSD_IO_DIRECT,
143 };
144 
145 extern u64 nfsd_io_cache_read __read_mostly;
146 extern u64 nfsd_io_cache_write __read_mostly;
147 
148 extern int nfsd_max_blksize;
149 
nfsd_v4client(struct svc_rqst * rq)150 static inline int nfsd_v4client(struct svc_rqst *rq)
151 {
152 	return rq && rq->rq_prog == NFS_PROGRAM && rq->rq_vers == 4;
153 }
154 
155 /*
156  * NFSv4 State
157  */
158 #ifdef CONFIG_NFSD_V4
159 extern unsigned long max_delegations;
160 int nfsd4_init_slabs(void);
161 void nfsd4_free_slabs(void);
162 int nfs4_state_start(void);
163 int nfs4_state_start_net(struct net *net);
164 void nfs4_state_shutdown(void);
165 void nfs4_state_shutdown_net(struct net *net);
166 int nfs4_reset_recoverydir(char *recdir);
167 char * nfs4_recoverydir(void);
168 bool nfsd4_spo_must_allow(struct svc_rqst *rqstp);
169 int nfsd4_create_laundry_wq(void);
170 void nfsd4_destroy_laundry_wq(void);
171 bool nfsd_wait_for_delegreturn(struct svc_rqst *rqstp, struct inode *inode);
172 #else
nfsd4_init_slabs(void)173 static inline int nfsd4_init_slabs(void) { return 0; }
nfsd4_free_slabs(void)174 static inline void nfsd4_free_slabs(void) { }
nfs4_state_start(void)175 static inline int nfs4_state_start(void) { return 0; }
nfs4_state_start_net(struct net * net)176 static inline int nfs4_state_start_net(struct net *net) { return 0; }
nfs4_state_shutdown(void)177 static inline void nfs4_state_shutdown(void) { }
nfs4_state_shutdown_net(struct net * net)178 static inline void nfs4_state_shutdown_net(struct net *net) { }
nfs4_reset_recoverydir(char * recdir)179 static inline int nfs4_reset_recoverydir(char *recdir) { return 0; }
nfs4_recoverydir(void)180 static inline char * nfs4_recoverydir(void) {return NULL; }
nfsd4_spo_must_allow(struct svc_rqst * rqstp)181 static inline bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
182 {
183 	return false;
184 }
nfsd4_create_laundry_wq(void)185 static inline int nfsd4_create_laundry_wq(void) { return 0; };
nfsd4_destroy_laundry_wq(void)186 static inline void nfsd4_destroy_laundry_wq(void) {};
nfsd_wait_for_delegreturn(struct svc_rqst * rqstp,struct inode * inode)187 static inline bool nfsd_wait_for_delegreturn(struct svc_rqst *rqstp,
188 					      struct inode *inode)
189 {
190 	return false;
191 }
192 #endif
193 
194 /*
195  * lockd binding
196  */
197 void		nfsd_lockd_init(void);
198 void		nfsd_lockd_shutdown(void);
199 
200 
201 /*
202  * These macros provide pre-xdr'ed values for faster operation.
203  */
204 #define	nfs_ok			cpu_to_be32(NFS_OK)
205 #define	nfserr_perm		cpu_to_be32(NFSERR_PERM)
206 #define	nfserr_noent		cpu_to_be32(NFSERR_NOENT)
207 #define	nfserr_io		cpu_to_be32(NFSERR_IO)
208 #define	nfserr_nxio		cpu_to_be32(NFSERR_NXIO)
209 #define	nfserr_acces		cpu_to_be32(NFSERR_ACCES)
210 #define	nfserr_exist		cpu_to_be32(NFSERR_EXIST)
211 #define	nfserr_xdev		cpu_to_be32(NFSERR_XDEV)
212 #define	nfserr_nodev		cpu_to_be32(NFSERR_NODEV)
213 #define	nfserr_notdir		cpu_to_be32(NFSERR_NOTDIR)
214 #define	nfserr_isdir		cpu_to_be32(NFSERR_ISDIR)
215 #define	nfserr_inval		cpu_to_be32(NFSERR_INVAL)
216 #define	nfserr_fbig		cpu_to_be32(NFSERR_FBIG)
217 #define	nfserr_nospc		cpu_to_be32(NFSERR_NOSPC)
218 #define	nfserr_rofs		cpu_to_be32(NFSERR_ROFS)
219 #define	nfserr_mlink		cpu_to_be32(NFSERR_MLINK)
220 #define	nfserr_nametoolong	cpu_to_be32(NFSERR_NAMETOOLONG)
221 #define	nfserr_notempty		cpu_to_be32(NFSERR_NOTEMPTY)
222 #define	nfserr_dquot		cpu_to_be32(NFSERR_DQUOT)
223 #define	nfserr_stale		cpu_to_be32(NFSERR_STALE)
224 #define	nfserr_remote		cpu_to_be32(NFSERR_REMOTE)
225 #define	nfserr_wflush		cpu_to_be32(NFSERR_WFLUSH)
226 #define	nfserr_badhandle	cpu_to_be32(NFSERR_BADHANDLE)
227 #define	nfserr_notsync		cpu_to_be32(NFSERR_NOT_SYNC)
228 #define	nfserr_badcookie	cpu_to_be32(NFSERR_BAD_COOKIE)
229 #define	nfserr_notsupp		cpu_to_be32(NFSERR_NOTSUPP)
230 #define	nfserr_toosmall		cpu_to_be32(NFSERR_TOOSMALL)
231 #define	nfserr_serverfault	cpu_to_be32(NFSERR_SERVERFAULT)
232 #define	nfserr_badtype		cpu_to_be32(NFSERR_BADTYPE)
233 #define	nfserr_jukebox		cpu_to_be32(NFSERR_JUKEBOX)
234 #define	nfserr_denied		cpu_to_be32(NFSERR_DENIED)
235 #define	nfserr_deadlock		cpu_to_be32(NFSERR_DEADLOCK)
236 #define nfserr_expired          cpu_to_be32(NFSERR_EXPIRED)
237 #define	nfserr_bad_cookie	cpu_to_be32(NFSERR_BAD_COOKIE)
238 #define	nfserr_same		cpu_to_be32(NFSERR_SAME)
239 #define	nfserr_clid_inuse	cpu_to_be32(NFSERR_CLID_INUSE)
240 #define	nfserr_stale_clientid	cpu_to_be32(NFSERR_STALE_CLIENTID)
241 #define	nfserr_resource		cpu_to_be32(NFSERR_RESOURCE)
242 #define	nfserr_moved		cpu_to_be32(NFSERR_MOVED)
243 #define	nfserr_nofilehandle	cpu_to_be32(NFSERR_NOFILEHANDLE)
244 #define	nfserr_minor_vers_mismatch	cpu_to_be32(NFSERR_MINOR_VERS_MISMATCH)
245 #define nfserr_share_denied	cpu_to_be32(NFSERR_SHARE_DENIED)
246 #define nfserr_stale_stateid	cpu_to_be32(NFSERR_STALE_STATEID)
247 #define nfserr_old_stateid	cpu_to_be32(NFSERR_OLD_STATEID)
248 #define nfserr_bad_stateid	cpu_to_be32(NFSERR_BAD_STATEID)
249 #define nfserr_bad_seqid	cpu_to_be32(NFSERR_BAD_SEQID)
250 #define	nfserr_symlink		cpu_to_be32(NFSERR_SYMLINK)
251 #define	nfserr_not_same		cpu_to_be32(NFSERR_NOT_SAME)
252 #define nfserr_lock_range	cpu_to_be32(NFSERR_LOCK_RANGE)
253 #define	nfserr_restorefh	cpu_to_be32(NFSERR_RESTOREFH)
254 #define	nfserr_attrnotsupp	cpu_to_be32(NFSERR_ATTRNOTSUPP)
255 #define	nfserr_bad_xdr		cpu_to_be32(NFSERR_BAD_XDR)
256 #define	nfserr_openmode		cpu_to_be32(NFSERR_OPENMODE)
257 #define	nfserr_badowner		cpu_to_be32(NFSERR_BADOWNER)
258 #define	nfserr_locks_held	cpu_to_be32(NFSERR_LOCKS_HELD)
259 #define	nfserr_op_illegal	cpu_to_be32(NFSERR_OP_ILLEGAL)
260 #define	nfserr_grace		cpu_to_be32(NFSERR_GRACE)
261 #define	nfserr_no_grace		cpu_to_be32(NFSERR_NO_GRACE)
262 #define	nfserr_reclaim_bad	cpu_to_be32(NFSERR_RECLAIM_BAD)
263 #define	nfserr_badname		cpu_to_be32(NFSERR_BADNAME)
264 #define	nfserr_admin_revoked	cpu_to_be32(NFS4ERR_ADMIN_REVOKED)
265 #define	nfserr_cb_path_down	cpu_to_be32(NFSERR_CB_PATH_DOWN)
266 #define	nfserr_locked		cpu_to_be32(NFSERR_LOCKED)
267 #define	nfserr_wrongsec		cpu_to_be32(NFSERR_WRONGSEC)
268 #define nfserr_delay			cpu_to_be32(NFS4ERR_DELAY)
269 #define nfserr_badiomode		cpu_to_be32(NFS4ERR_BADIOMODE)
270 #define nfserr_badlayout		cpu_to_be32(NFS4ERR_BADLAYOUT)
271 #define nfserr_bad_session_digest	cpu_to_be32(NFS4ERR_BAD_SESSION_DIGEST)
272 #define nfserr_badsession		cpu_to_be32(NFS4ERR_BADSESSION)
273 #define nfserr_badslot			cpu_to_be32(NFS4ERR_BADSLOT)
274 #define nfserr_complete_already		cpu_to_be32(NFS4ERR_COMPLETE_ALREADY)
275 #define nfserr_conn_not_bound_to_session cpu_to_be32(NFS4ERR_CONN_NOT_BOUND_TO_SESSION)
276 #define nfserr_deleg_already_wanted	cpu_to_be32(NFS4ERR_DELEG_ALREADY_WANTED)
277 #define nfserr_back_chan_busy		cpu_to_be32(NFS4ERR_BACK_CHAN_BUSY)
278 #define nfserr_layouttrylater		cpu_to_be32(NFS4ERR_LAYOUTTRYLATER)
279 #define nfserr_layoutunavailable	cpu_to_be32(NFS4ERR_LAYOUTUNAVAILABLE)
280 #define nfserr_nomatching_layout	cpu_to_be32(NFS4ERR_NOMATCHING_LAYOUT)
281 #define nfserr_recallconflict		cpu_to_be32(NFS4ERR_RECALLCONFLICT)
282 #define nfserr_unknown_layouttype	cpu_to_be32(NFS4ERR_UNKNOWN_LAYOUTTYPE)
283 #define nfserr_seq_misordered		cpu_to_be32(NFS4ERR_SEQ_MISORDERED)
284 #define nfserr_sequence_pos		cpu_to_be32(NFS4ERR_SEQUENCE_POS)
285 #define nfserr_req_too_big		cpu_to_be32(NFS4ERR_REQ_TOO_BIG)
286 #define nfserr_rep_too_big		cpu_to_be32(NFS4ERR_REP_TOO_BIG)
287 #define nfserr_rep_too_big_to_cache	cpu_to_be32(NFS4ERR_REP_TOO_BIG_TO_CACHE)
288 #define nfserr_retry_uncached_rep	cpu_to_be32(NFS4ERR_RETRY_UNCACHED_REP)
289 #define nfserr_unsafe_compound		cpu_to_be32(NFS4ERR_UNSAFE_COMPOUND)
290 #define nfserr_too_many_ops		cpu_to_be32(NFS4ERR_TOO_MANY_OPS)
291 #define nfserr_op_not_in_session	cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION)
292 #define nfserr_hash_alg_unsupp		cpu_to_be32(NFS4ERR_HASH_ALG_UNSUPP)
293 #define nfserr_clientid_busy		cpu_to_be32(NFS4ERR_CLIENTID_BUSY)
294 #define nfserr_pnfs_io_hole		cpu_to_be32(NFS4ERR_PNFS_IO_HOLE)
295 #define nfserr_seq_false_retry		cpu_to_be32(NFS4ERR_SEQ_FALSE_RETRY)
296 #define nfserr_bad_high_slot		cpu_to_be32(NFS4ERR_BAD_HIGH_SLOT)
297 #define nfserr_deadsession		cpu_to_be32(NFS4ERR_DEADSESSION)
298 #define nfserr_encr_alg_unsupp		cpu_to_be32(NFS4ERR_ENCR_ALG_UNSUPP)
299 #define nfserr_pnfs_no_layout		cpu_to_be32(NFS4ERR_PNFS_NO_LAYOUT)
300 #define nfserr_not_only_op		cpu_to_be32(NFS4ERR_NOT_ONLY_OP)
301 #define nfserr_wrong_cred		cpu_to_be32(NFS4ERR_WRONG_CRED)
302 #define nfserr_wrong_type		cpu_to_be32(NFS4ERR_WRONG_TYPE)
303 #define nfserr_dirdeleg_unavail		cpu_to_be32(NFS4ERR_DIRDELEG_UNAVAIL)
304 #define nfserr_reject_deleg		cpu_to_be32(NFS4ERR_REJECT_DELEG)
305 #define nfserr_returnconflict		cpu_to_be32(NFS4ERR_RETURNCONFLICT)
306 #define nfserr_deleg_revoked		cpu_to_be32(NFS4ERR_DELEG_REVOKED)
307 #define nfserr_partner_notsupp		cpu_to_be32(NFS4ERR_PARTNER_NOTSUPP)
308 #define nfserr_partner_no_auth		cpu_to_be32(NFS4ERR_PARTNER_NO_AUTH)
309 #define nfserr_union_notsupp		cpu_to_be32(NFS4ERR_UNION_NOTSUPP)
310 #define nfserr_offload_denied		cpu_to_be32(NFS4ERR_OFFLOAD_DENIED)
311 #define nfserr_wrong_lfs		cpu_to_be32(NFS4ERR_WRONG_LFS)
312 #define nfserr_badlabel			cpu_to_be32(NFS4ERR_BADLABEL)
313 #define nfserr_file_open		cpu_to_be32(NFS4ERR_FILE_OPEN)
314 #define nfserr_xattr2big		cpu_to_be32(NFS4ERR_XATTR2BIG)
315 #define nfserr_noxattr			cpu_to_be32(NFS4ERR_NOXATTR)
316 
317 /*
318  * Error codes for internal use.  These are based at an impossible
319  * nfsstat4 value so that, once converted to be32, they cannot conflict
320  * with any value defined by the protocol (compare the nlm__int__* codes
321  * in fs/lockd/lockd.h).
322  */
323 enum {
324 /* end-of-file indicator in readdir */
325 	NFSERR_EOF = 30000,
326 #define	nfserr_eof		cpu_to_be32(NFSERR_EOF)
327 
328 /* replay detected */
329 	NFSERR_REPLAY_ME,
330 #define	nfserr_replay_me	cpu_to_be32(NFSERR_REPLAY_ME)
331 
332 /* nfs41 replay detected */
333 	NFSERR_REPLAY_CACHE,
334 #define	nfserr_replay_cache	cpu_to_be32(NFSERR_REPLAY_CACHE)
335 
336 /* symlink found where dir expected - handled differently to
337  * other symlink found errors by NFSv3.
338  */
339 	NFSERR_SYMLINK_NOT_DIR,
340 #define	nfserr_symlink_not_dir	cpu_to_be32(NFSERR_SYMLINK_NOT_DIR)
341 };
342 
343 #ifdef CONFIG_NFSD_V4
344 
345 /* before processing a COMPOUND operation, we have to check that there
346  * is enough space in the buffer for XDR encode to succeed.  otherwise,
347  * we might process an operation with side effects, and be unable to
348  * tell the client that the operation succeeded.
349  *
350  * COMPOUND_SLACK_SPACE - this is the minimum bytes of buffer space
351  * needed to encode an "ordinary" _successful_ operation.  (GETATTR,
352  * READ, READDIR, and READLINK have their own buffer checks.)  if we
353  * fall below this level, we fail the next operation with NFS4ERR_RESOURCE.
354  *
355  * COMPOUND_ERR_SLACK_SPACE - this is the minimum bytes of buffer space
356  * needed to encode an operation which has failed with NFS4ERR_RESOURCE.
357  * care is taken to ensure that we never fall below this level for any
358  * reason.
359  */
360 #define	COMPOUND_SLACK_SPACE		140    /* OP_GETFH */
361 #define COMPOUND_ERR_SLACK_SPACE	16     /* OP_SETATTR */
362 
363 #define NFSD_LAUNDROMAT_MINTIMEOUT      1   /* seconds */
364 #define	NFSD_COURTESY_CLIENT_TIMEOUT	(24 * 60 * 60)	/* seconds */
365 #define	NFSD_CLIENT_MAX_TRIM_PER_RUN	128
366 #define	NFS4_CLIENTS_PER_GB		1024
367 #define NFSD_DELEGRETURN_TIMEOUT	(HZ / 34)	/* 30ms */
368 #define	NFSD_CB_GETATTR_TIMEOUT		NFSD_DELEGRETURN_TIMEOUT
369 
370 extern int nfsd4_is_junction(struct dentry *dentry);
371 extern int register_cld_notifier(void);
372 extern void unregister_cld_notifier(void);
373 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
374 extern void nfsd4_ssc_init_umount_work(struct nfsd_net *nn);
375 #endif
376 
377 extern void nfsd4_init_leases_net(struct nfsd_net *nn);
378 
379 #else /* CONFIG_NFSD_V4 */
nfsd4_is_junction(struct dentry * dentry)380 static inline int nfsd4_is_junction(struct dentry *dentry)
381 {
382 	return 0;
383 }
384 
nfsd4_init_leases_net(struct nfsd_net * nn)385 static inline void nfsd4_init_leases_net(struct nfsd_net *nn) { };
386 
387 #define register_cld_notifier() 0
388 #define unregister_cld_notifier() do { } while(0)
389 
390 #endif /* CONFIG_NFSD_V4 */
391 
392 #endif /* LINUX_NFSD_NFSD_H */
393