xref: /linux/include/linux/nfs_fs.h (revision bd5e6b056bd0900d8efde90da7a5877dc50842c7)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  linux/include/linux/nfs_fs.h
4  *
5  *  Copyright (C) 1992  Rick Sladkey
6  *
7  *  OS-specific nfs filesystem definitions and declarations
8  */
9 #ifndef _LINUX_NFS_FS_H
10 #define _LINUX_NFS_FS_H
11 
12 #include <uapi/linux/nfs_fs.h>
13 
14 
15 /*
16  * Enable dprintk() debugging support for nfs client.
17  */
18 #ifdef CONFIG_NFS_DEBUG
19 # define NFS_DEBUG
20 #endif
21 
22 #include <linux/in.h>
23 #include <linux/mm.h>
24 #include <linux/pagemap.h>
25 #include <linux/rbtree.h>
26 #include <linux/refcount.h>
27 #include <linux/rwsem.h>
28 #include <linux/wait.h>
29 
30 #include <linux/sunrpc/debug.h>
31 #include <linux/sunrpc/auth.h>
32 #include <linux/sunrpc/clnt.h>
33 
34 #ifdef CONFIG_NFS_FSCACHE
35 #include <linux/netfs.h>
36 #endif
37 
38 #include <linux/nfs.h>
39 #include <linux/nfs2.h>
40 #include <linux/nfs3.h>
41 #include <linux/nfs4.h>
42 #include <linux/nfs_xdr.h>
43 #include <linux/nfs_fs_sb.h>
44 
45 #include <linux/mempool.h>
46 
47 /*
48  * These are the default for number of transports to different server IPs
49  */
50 #define NFS_MAX_TRANSPORTS 16
51 
52 /*
53  * Size of the NFS directory verifier
54  */
55 #define NFS_DIR_VERIFIER_SIZE		2
56 
57 /*
58  * NFSv3/v4 Access mode cache entry
59  */
60 struct nfs_access_entry {
61 	struct rb_node		rb_node;
62 	struct list_head	lru;
63 	kuid_t			fsuid;
64 	kgid_t			fsgid;
65 	struct group_info	*group_info;
66 	u64			timestamp;
67 	__u32			mask;
68 	struct rcu_head		rcu_head;
69 };
70 
71 struct nfs_lock_context {
72 	refcount_t count;
73 	struct list_head list;
74 	struct nfs_open_context *open_context;
75 	fl_owner_t lockowner;
76 	atomic_t io_count;
77 	struct rcu_head	rcu_head;
78 };
79 
80 struct nfs_file_localio {
81 	struct nfsd_file __rcu *ro_file;
82 	struct nfsd_file __rcu *rw_file;
83 	struct list_head list;
84 	void __rcu *nfs_uuid; /* opaque pointer to 'nfs_uuid_t' */
85 };
86 
87 static inline void nfs_localio_file_init(struct nfs_file_localio *nfl)
88 {
89 #if IS_ENABLED(CONFIG_NFS_LOCALIO)
90 	nfl->ro_file = NULL;
91 	nfl->rw_file = NULL;
92 	INIT_LIST_HEAD(&nfl->list);
93 	nfl->nfs_uuid = NULL;
94 #endif
95 }
96 
97 struct nfs4_state;
98 struct nfs_open_context {
99 	struct nfs_lock_context lock_context;
100 	fl_owner_t flock_owner;
101 	struct dentry *dentry;
102 	const struct cred *cred;
103 	struct rpc_cred __rcu *ll_cred;	/* low-level cred - use to check for expiry */
104 	struct nfs4_state *state;
105 	fmode_t mode;
106 
107 	int error;
108 	unsigned long flags;
109 #define NFS_CONTEXT_BAD			(2)
110 #define NFS_CONTEXT_UNLOCK	(3)
111 #define NFS_CONTEXT_FILE_OPEN		(4)
112 #define NFS_CONTEXT_WRITE_SYNC		(5)
113 
114 	struct nfs4_threshold	*mdsthreshold;
115 	struct list_head list;
116 	struct rcu_head	rcu_head;
117 	struct nfs_file_localio nfl;
118 };
119 
120 struct nfs_open_dir_context {
121 	struct list_head list;
122 	atomic_t cache_hits;
123 	atomic_t cache_misses;
124 	unsigned long attr_gencount;
125 	__be32	verf[NFS_DIR_VERIFIER_SIZE];
126 	__u64 dir_cookie;
127 	__u64 last_cookie;
128 	pgoff_t page_index;
129 	unsigned int dtsize;
130 	bool force_clear;
131 	bool eof;
132 	struct rcu_head rcu_head;
133 };
134 
135 /*
136  * NFSv4 delegation
137  */
138 struct nfs_delegation;
139 
140 struct posix_acl;
141 
142 struct nfs4_xattr_cache;
143 
144 /*
145  * nfs fs inode data in memory
146  */
147 struct nfs_inode {
148 	/*
149 	 * NFS file handle
150 	 */
151 	struct nfs_fh		fh;
152 
153 	/*
154 	 * Various flags
155 	 */
156 	unsigned long		flags;			/* atomic bit ops */
157 	unsigned long		cache_validity;		/* bit mask */
158 
159 	/*
160 	 * NFS Attributes not included in struct inode
161 	 */
162 
163 	struct timespec64	btime;
164 
165 	/*
166 	 * read_cache_jiffies is when we started read-caching this inode.
167 	 * attrtimeo is for how long the cached information is assumed
168 	 * to be valid. A successful attribute revalidation doubles
169 	 * attrtimeo (up to acregmax/acdirmax), a failure resets it to
170 	 * acregmin/acdirmin.
171 	 *
172 	 * We need to revalidate the cached attrs for this inode if
173 	 *
174 	 *	jiffies - read_cache_jiffies >= attrtimeo
175 	 *
176 	 * Please note the comparison is greater than or equal
177 	 * so that zero timeout values can be specified.
178 	 */
179 	unsigned long		read_cache_jiffies;
180 	unsigned long		attrtimeo;
181 	unsigned long		attrtimeo_timestamp;
182 
183 	unsigned long		attr_gencount;
184 
185 	struct rb_root		access_cache;
186 	struct list_head	access_cache_entry_lru;
187 	struct list_head	access_cache_inode_lru;
188 
189 	union {
190 		/* Directory */
191 		struct {
192 			/* "Generation counter" for the attribute cache.
193 			 * This is bumped whenever we update the metadata
194 			 * on the server.
195 			 */
196 			unsigned long	cache_change_attribute;
197 			/*
198 			 * This is the cookie verifier used for NFSv3 readdir
199 			 * operations
200 			 */
201 			__be32		cookieverf[NFS_DIR_VERIFIER_SIZE];
202 			/* Readers: in-flight sillydelete RPC calls */
203 			/* Writers: rmdir */
204 			struct rw_semaphore	rmdir_sem;
205 		};
206 		/* Regular file */
207 		struct {
208 			atomic_long_t	nrequests;
209 			atomic_long_t	redirtied_pages;
210 			struct nfs_mds_commit_info commit_info;
211 			struct mutex	commit_mutex;
212 		};
213 	};
214 
215 	/* Open contexts for shared mmap writes */
216 	struct list_head	open_files;
217 
218 	/* Keep track of out-of-order replies.
219 	 * The ooo array contains start/end pairs of
220 	 * numbers from the changeid sequence when
221 	 * the inode's iversion has been updated.
222 	 * It also contains end/start pair (i.e. reverse order)
223 	 * of sections of the changeid sequence that have
224 	 * been seen in replies from the server.
225 	 * Normally these should match and when both
226 	 * A:B and B:A are found in ooo, they are both removed.
227 	 * And if a reply with A:B causes an iversion update
228 	 * of A:B, then neither are added.
229 	 * When a reply has pre_change that doesn't match
230 	 * iversion, then the changeid pair and any consequent
231 	 * change in iversion ARE added.  Later replies
232 	 * might fill in the gaps, or possibly a gap is caused
233 	 * by a change from another client.
234 	 * When a file or directory is opened, if the ooo table
235 	 * is not empty, then we assume the gaps were due to
236 	 * another client and we invalidate the cached data.
237 	 *
238 	 * We can only track a limited number of concurrent gaps.
239 	 * Currently that limit is 16.
240 	 * We allocate the table on demand.  If there is insufficient
241 	 * memory, then we probably cannot cache the file anyway
242 	 * so there is no loss.
243 	 */
244 	struct {
245 		int cnt;
246 		struct {
247 			u64 start, end;
248 		} gap[16];
249 	} *ooo;
250 
251 #if IS_ENABLED(CONFIG_NFS_V4)
252 	struct nfs4_cached_acl	*nfs4_acl;
253         /* NFSv4 state */
254 	struct list_head	open_states;
255 	struct nfs_delegation __rcu *delegation;
256 	struct rw_semaphore	rwsem;
257 
258 	/* pNFS layout information */
259 	struct pnfs_layout_hdr *layout;
260 #endif /* CONFIG_NFS_V4*/
261 	/* how many bytes have been written/read and how many bytes queued up */
262 	__u64 write_io;
263 	__u64 read_io;
264 #ifdef CONFIG_NFS_V4_2
265 	struct nfs4_xattr_cache *xattr_cache;
266 #endif
267 	union {
268 		struct inode		vfs_inode;
269 #ifdef CONFIG_NFS_FSCACHE
270 		struct netfs_inode	netfs; /* netfs context and VFS inode */
271 #endif
272 	};
273 };
274 
275 struct nfs4_copy_state {
276 	struct list_head	copies;
277 	struct list_head	src_copies;
278 	nfs4_stateid		stateid;
279 	struct completion	completion;
280 	uint64_t		count;
281 	struct nfs_writeverf	verf;
282 	int			error;
283 	int			flags;
284 	struct nfs4_state	*parent_src_state;
285 	struct nfs4_state	*parent_dst_state;
286 };
287 
288 /*
289  * Access bit flags
290  */
291 #define NFS_ACCESS_READ        0x0001
292 #define NFS_ACCESS_LOOKUP      0x0002
293 #define NFS_ACCESS_MODIFY      0x0004
294 #define NFS_ACCESS_EXTEND      0x0008
295 #define NFS_ACCESS_DELETE      0x0010
296 #define NFS_ACCESS_EXECUTE     0x0020
297 #define NFS_ACCESS_XAREAD      0x0040
298 #define NFS_ACCESS_XAWRITE     0x0080
299 #define NFS_ACCESS_XALIST      0x0100
300 
301 /*
302  * Cache validity bit flags
303  */
304 #define NFS_INO_INVALID_DATA	BIT(1)		/* cached data is invalid */
305 #define NFS_INO_INVALID_ATIME	BIT(2)		/* cached atime is invalid */
306 #define NFS_INO_INVALID_ACCESS	BIT(3)		/* cached access cred invalid */
307 #define NFS_INO_INVALID_ACL	BIT(4)		/* cached acls are invalid */
308 #define NFS_INO_REVAL_FORCED	BIT(6)		/* force revalidation ignoring a delegation */
309 #define NFS_INO_INVALID_LABEL	BIT(7)		/* cached label is invalid */
310 #define NFS_INO_INVALID_CHANGE	BIT(8)		/* cached change is invalid */
311 #define NFS_INO_INVALID_CTIME	BIT(9)		/* cached ctime is invalid */
312 #define NFS_INO_INVALID_MTIME	BIT(10)		/* cached mtime is invalid */
313 #define NFS_INO_INVALID_SIZE	BIT(11)		/* cached size is invalid */
314 #define NFS_INO_INVALID_OTHER	BIT(12)		/* other attrs are invalid */
315 #define NFS_INO_DATA_INVAL_DEFER	\
316 				BIT(13)		/* Deferred cache invalidation */
317 #define NFS_INO_INVALID_BLOCKS	BIT(14)         /* cached blocks are invalid */
318 #define NFS_INO_INVALID_XATTR	BIT(15)		/* xattrs are invalid */
319 #define NFS_INO_INVALID_NLINK	BIT(16)		/* cached nlinks is invalid */
320 #define NFS_INO_INVALID_MODE	BIT(17)		/* cached mode is invalid */
321 #define NFS_INO_INVALID_BTIME	BIT(18)		/* cached btime is invalid */
322 
323 #define NFS_INO_INVALID_ATTR	(NFS_INO_INVALID_CHANGE \
324 		| NFS_INO_INVALID_CTIME \
325 		| NFS_INO_INVALID_MTIME \
326 		| NFS_INO_INVALID_BTIME \
327 		| NFS_INO_INVALID_SIZE \
328 		| NFS_INO_INVALID_NLINK \
329 		| NFS_INO_INVALID_MODE \
330 		| NFS_INO_INVALID_OTHER)	/* inode metadata is invalid */
331 
332 /*
333  * Bit offsets in flags field
334  */
335 #define NFS_INO_STALE		(1)		/* possible stale inode */
336 #define NFS_INO_ACL_LRU_SET	(2)		/* Inode is on the LRU list */
337 #define NFS_INO_INVALIDATING	(3)		/* inode is being invalidated */
338 #define NFS_INO_PRESERVE_UNLINKED (4)		/* preserve file if removed while open */
339 #define NFS_INO_LAYOUTCOMMIT	(9)		/* layoutcommit required */
340 #define NFS_INO_LAYOUTCOMMITTING (10)		/* layoutcommit inflight */
341 #define NFS_INO_LAYOUTSTATS	(11)		/* layoutstats inflight */
342 #define NFS_INO_ODIRECT		(12)		/* I/O setting is O_DIRECT */
343 #define NFS_INO_REQ_DIR_DELEG	(13)		/* Request a directory delegation */
344 
345 static inline struct nfs_inode *NFS_I(const struct inode *inode)
346 {
347 	return container_of(inode, struct nfs_inode, vfs_inode);
348 }
349 
350 static inline struct nfs_server *NFS_SB(const struct super_block *s)
351 {
352 	return (struct nfs_server *)(s->s_fs_info);
353 }
354 
355 static inline struct nfs_fh *NFS_FH(const struct inode *inode)
356 {
357 	return &NFS_I(inode)->fh;
358 }
359 
360 static inline struct nfs_server *NFS_SERVER(const struct inode *inode)
361 {
362 	return NFS_SB(inode->i_sb);
363 }
364 
365 static inline struct rpc_clnt *NFS_CLIENT(const struct inode *inode)
366 {
367 	return NFS_SERVER(inode)->client;
368 }
369 
370 static inline const struct nfs_rpc_ops *NFS_PROTO(const struct inode *inode)
371 {
372 	return NFS_SERVER(inode)->nfs_client->rpc_ops;
373 }
374 
375 static inline unsigned NFS_MINATTRTIMEO(const struct inode *inode)
376 {
377 	struct nfs_server *nfss = NFS_SERVER(inode);
378 	return S_ISDIR(inode->i_mode) ? nfss->acdirmin : nfss->acregmin;
379 }
380 
381 static inline unsigned NFS_MAXATTRTIMEO(const struct inode *inode)
382 {
383 	struct nfs_server *nfss = NFS_SERVER(inode);
384 	return S_ISDIR(inode->i_mode) ? nfss->acdirmax : nfss->acregmax;
385 }
386 
387 static inline int NFS_STALE(const struct inode *inode)
388 {
389 	return test_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
390 }
391 
392 static inline void nfs_mark_for_revalidate(struct inode *inode)
393 {
394 	struct nfs_inode *nfsi = NFS_I(inode);
395 
396 	spin_lock(&inode->i_lock);
397 	nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL |
398 				NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_CTIME |
399 				NFS_INO_INVALID_SIZE;
400 	if (S_ISDIR(inode->i_mode))
401 		nfsi->cache_validity |= NFS_INO_INVALID_DATA;
402 	spin_unlock(&inode->i_lock);
403 }
404 
405 static inline int nfs_server_capable(const struct inode *inode, int cap)
406 {
407 	return NFS_SERVER(inode)->caps & cap;
408 }
409 
410 /**
411  * nfs_save_change_attribute - Returns the inode attribute change cookie
412  * @dir - pointer to parent directory inode
413  * The "cache change attribute" is updated when we need to revalidate
414  * our dentry cache after a directory was seen to change on the server.
415  */
416 static inline unsigned long nfs_save_change_attribute(struct inode *dir)
417 {
418 	return NFS_I(dir)->cache_change_attribute;
419 }
420 
421 /*
422  * linux/fs/nfs/inode.c
423  */
424 extern int nfs_sync_mapping(struct address_space *mapping);
425 extern void nfs_zap_mapping(struct inode *inode, struct address_space *mapping);
426 extern void nfs_zap_caches(struct inode *);
427 extern void nfs_set_inode_stale(struct inode *inode);
428 extern void nfs_invalidate_atime(struct inode *);
429 extern struct inode *nfs_fhget(struct super_block *, struct nfs_fh *,
430 				struct nfs_fattr *);
431 struct inode *nfs_ilookup(struct super_block *sb, struct nfs_fattr *, struct nfs_fh *);
432 extern int nfs_refresh_inode(struct inode *, struct nfs_fattr *);
433 extern int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr);
434 extern int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fattr);
435 extern int nfs_post_op_update_inode_force_wcc_locked(struct inode *inode, struct nfs_fattr *fattr);
436 extern int nfs_getattr(struct mnt_idmap *, const struct path *,
437 		       struct kstat *, u32, unsigned int);
438 extern void nfs_access_add_cache(struct inode *, struct nfs_access_entry *, const struct cred *);
439 extern void nfs_access_set_mask(struct nfs_access_entry *, u32);
440 extern int nfs_permission(struct mnt_idmap *, struct inode *, int);
441 extern int nfs_open(struct inode *, struct file *);
442 extern int nfs_attribute_cache_expired(struct inode *inode);
443 extern int nfs_revalidate_inode(struct inode *inode, unsigned long flags);
444 extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *);
445 extern int nfs_clear_invalid_mapping(struct address_space *mapping);
446 extern bool nfs_mapping_need_revalidate_inode(struct inode *inode);
447 extern int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping);
448 extern int nfs_revalidate_mapping_rcu(struct inode *inode);
449 extern int nfs_setattr(struct mnt_idmap *, struct dentry *, struct iattr *);
450 extern void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr, struct nfs_fattr *);
451 extern void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr);
452 extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx);
453 extern void put_nfs_open_context(struct nfs_open_context *ctx);
454 extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, const struct cred *cred, fmode_t mode);
455 extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode, struct file *filp);
456 extern void nfs_inode_attach_open_context(struct nfs_open_context *ctx);
457 extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx);
458 extern void nfs_file_clear_open_context(struct file *flip);
459 extern struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx);
460 extern void nfs_put_lock_context(struct nfs_lock_context *l_ctx);
461 extern void nfs_fattr_init(struct nfs_fattr *fattr);
462 extern void nfs_fattr_set_barrier(struct nfs_fattr *fattr);
463 extern unsigned long nfs_inc_attr_generation_counter(void);
464 
465 extern struct nfs_fattr *nfs_alloc_fattr(void);
466 extern struct nfs_fattr *nfs_alloc_fattr_with_label(struct nfs_server *server);
467 
468 static inline void nfs4_label_free(struct nfs4_label *label)
469 {
470 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
471 	if (label) {
472 		kfree(label->label);
473 		kfree(label);
474 	}
475 #endif
476 }
477 
478 static inline void nfs_free_fattr(const struct nfs_fattr *fattr)
479 {
480 	if (fattr)
481 		nfs4_label_free(fattr->label);
482 	kfree(fattr);
483 }
484 
485 extern struct nfs_fh *nfs_alloc_fhandle(void);
486 
487 static inline void nfs_free_fhandle(const struct nfs_fh *fh)
488 {
489 	kfree(fh);
490 }
491 
492 #ifdef NFS_DEBUG
493 extern u32 _nfs_display_fhandle_hash(const struct nfs_fh *fh);
494 static inline u32 nfs_display_fhandle_hash(const struct nfs_fh *fh)
495 {
496 	return _nfs_display_fhandle_hash(fh);
497 }
498 extern void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption);
499 #define nfs_display_fhandle(fh, caption)			\
500 	do {							\
501 		if (unlikely(nfs_debug & NFSDBG_FACILITY))	\
502 			_nfs_display_fhandle(fh, caption);	\
503 	} while (0)
504 #else
505 static inline u32 nfs_display_fhandle_hash(const struct nfs_fh *fh)
506 {
507 	return 0;
508 }
509 static inline void nfs_display_fhandle(const struct nfs_fh *fh,
510 				       const char *caption)
511 {
512 }
513 #endif
514 
515 /*
516  * linux/fs/nfs/nfsroot.c
517  */
518 extern int  nfs_root_data(char **root_device, char **root_data); /*__init*/
519 /* linux/net/ipv4/ipconfig.c: trims ip addr off front of name, too. */
520 extern __be32 root_nfs_parse_addr(char *name); /*__init*/
521 
522 /*
523  * linux/fs/nfs/file.c
524  */
525 extern const struct file_operations nfs_file_operations;
526 #if IS_ENABLED(CONFIG_NFS_V4)
527 extern const struct file_operations nfs4_file_operations;
528 #endif /* CONFIG_NFS_V4 */
529 extern const struct address_space_operations nfs_file_aops;
530 extern const struct address_space_operations nfs_dir_aops;
531 
532 static inline struct nfs_open_context *nfs_file_open_context(struct file *filp)
533 {
534 	return filp->private_data;
535 }
536 
537 static inline const struct cred *nfs_file_cred(struct file *file)
538 {
539 	if (file != NULL) {
540 		struct nfs_open_context *ctx =
541 			nfs_file_open_context(file);
542 		if (ctx)
543 			return ctx->cred;
544 	}
545 	return NULL;
546 }
547 
548 /*
549  * linux/fs/nfs/direct.c
550  */
551 int nfs_swap_rw(struct kiocb *iocb, struct iov_iter *iter);
552 ssize_t nfs_file_direct_read(struct kiocb *iocb,
553 			     struct iov_iter *iter, bool swap);
554 ssize_t nfs_file_direct_write(struct kiocb *iocb,
555 			      struct iov_iter *iter, bool swap);
556 
557 /*
558  * linux/fs/nfs/dir.c
559  */
560 extern const struct file_operations nfs_dir_operations;
561 extern const struct dentry_operations nfs_dentry_operations;
562 
563 extern void nfs_force_lookup_revalidate(struct inode *dir);
564 extern void nfs_set_verifier(struct dentry * dentry, unsigned long verf);
565 #if IS_ENABLED(CONFIG_NFS_V4)
566 extern void nfs_clear_verifier_delegated(struct inode *inode);
567 #endif /* IS_ENABLED(CONFIG_NFS_V4) */
568 extern struct dentry *nfs_add_or_obtain(struct dentry *dentry,
569 			struct nfs_fh *fh, struct nfs_fattr *fattr);
570 extern int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fh,
571 			struct nfs_fattr *fattr);
572 extern int nfs_may_open(struct inode *inode, const struct cred *cred, int openflags);
573 extern void nfs_access_zap_cache(struct inode *inode);
574 extern int nfs_access_get_cached(struct inode *inode, const struct cred *cred,
575 				 u32 *mask, bool may_block);
576 extern int nfs_atomic_open_v23(struct inode *dir, struct dentry *dentry,
577 			       struct file *file, unsigned int open_flags,
578 			       umode_t mode);
579 
580 /*
581  * linux/fs/nfs/symlink.c
582  */
583 extern const struct inode_operations nfs_symlink_inode_operations;
584 
585 /*
586  * linux/fs/nfs/sysctl.c
587  */
588 #ifdef CONFIG_SYSCTL
589 extern int nfs_register_sysctl(void);
590 extern void nfs_unregister_sysctl(void);
591 #else
592 #define nfs_register_sysctl() 0
593 #define nfs_unregister_sysctl() do { } while(0)
594 #endif
595 
596 /*
597  * linux/fs/nfs/namespace.c
598  */
599 extern const struct inode_operations nfs_mountpoint_inode_operations;
600 extern const struct inode_operations nfs_referral_inode_operations;
601 extern int nfs_mountpoint_expiry_timeout;
602 extern void nfs_release_automount_timer(void);
603 
604 /*
605  * linux/fs/nfs/unlink.c
606  */
607 extern void nfs_complete_unlink(struct dentry *dentry, struct inode *);
608 
609 /*
610  * linux/fs/nfs/write.c
611  */
612 extern int  nfs_congestion_kb;
613 extern int  nfs_writepages(struct address_space *, struct writeback_control *);
614 extern int  nfs_flush_incompatible(struct file *file, struct folio *folio);
615 extern int  nfs_update_folio(struct file *file, struct folio *folio,
616 			     unsigned int offset, unsigned int count);
617 
618 /*
619  * Try to write back everything synchronously (but check the
620  * return value!)
621  */
622 extern int nfs_sync_inode(struct inode *inode);
623 extern int nfs_wb_all(struct inode *inode);
624 extern int nfs_wb_folio(struct inode *inode, struct folio *folio);
625 extern int nfs_wb_folio_reclaim(struct inode *inode, struct folio *folio);
626 int nfs_wb_folio_cancel(struct inode *inode, struct folio *folio);
627 extern int  nfs_commit_inode(struct inode *, int);
628 extern struct nfs_commit_data *nfs_commitdata_alloc(void);
629 extern void nfs_commit_free(struct nfs_commit_data *data);
630 void nfs_commit_begin(struct nfs_mds_commit_info *cinfo);
631 bool nfs_commit_end(struct nfs_mds_commit_info *cinfo);
632 
633 static inline bool nfs_have_writebacks(const struct inode *inode)
634 {
635 	if (S_ISREG(inode->i_mode))
636 		return atomic_long_read(&NFS_I(inode)->nrequests) != 0;
637 	return false;
638 }
639 
640 /*
641  * linux/fs/nfs/read.c
642  */
643 int  nfs_read_folio(struct file *, struct folio *);
644 void nfs_readahead(struct readahead_control *);
645 
646 /*
647  * inline functions
648  */
649 
650 static inline loff_t nfs_size_to_loff_t(__u64 size)
651 {
652 	return min_t(u64, size, OFFSET_MAX);
653 }
654 
655 static inline void nfs_ooo_clear(struct nfs_inode *nfsi)
656 {
657 	nfsi->cache_validity &= ~NFS_INO_DATA_INVAL_DEFER;
658 	kfree(nfsi->ooo);
659 	nfsi->ooo = NULL;
660 }
661 
662 static inline bool nfs_ooo_test(struct nfs_inode *nfsi)
663 {
664 	return (nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER) ||
665 		(nfsi->ooo && nfsi->ooo->cnt > 0);
666 
667 }
668 
669 #define NFS_JUKEBOX_RETRY_TIME (5 * HZ)
670 
671 /* We need to block new opens while a file is being unlinked.
672  * If it is opened *before* we decide to unlink, we will silly-rename
673  * instead. If it is opened *after*, then we need to create or will fail.
674  * If we allow the two to race, we could end up with a file that is open
675  * but deleted on the server resulting in ESTALE.
676  * So use ->d_fsdata to record when the unlink is happening
677  * and block dentry revalidation while it is set.
678  */
679 #define NFS_FSDATA_BLOCKED ((void*)1)
680 
681 # undef ifdebug
682 # ifdef NFS_DEBUG
683 #  define ifdebug(fac)		if (unlikely(nfs_debug & NFSDBG_##fac))
684 #  define NFS_IFDEBUG(x)	x
685 # else
686 #  define ifdebug(fac)		if (0)
687 #  define NFS_IFDEBUG(x)
688 # endif
689 #endif
690