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