xref: /linux/fs/nfsd/filecache.h (revision d141ec2825b4d3ec52f27c43bdd864090159273a)
1 #ifndef _FS_NFSD_FILECACHE_H
2 #define _FS_NFSD_FILECACHE_H
3 
4 #include <linux/fsnotify_backend.h>
5 
6 /*
7  * Limit the time that the list_lru_one lock is held during
8  * an LRU scan.
9  */
10 #define NFSD_FILE_GC_BATCH     (16UL)
11 
12 /*
13  * This is the fsnotify_mark container that nfsd attaches to the files that it
14  * is holding open. Note that we have a separate refcount here aside from the
15  * one in the fsnotify_mark. We only want a single fsnotify_mark attached to
16  * the inode, and for each nfsd_file to hold a reference to it.
17  *
18  * The fsnotify_mark is itself refcounted, but that's not sufficient to tell us
19  * how to put that reference. If there are still outstanding nfsd_files that
20  * reference the mark, then we would want to call fsnotify_put_mark on it.
21  * If there were not, then we'd need to call fsnotify_destroy_mark. Since we
22  * can't really tell the difference, we use the nfm_mark to keep track of how
23  * many nfsd_files hold references to the mark. When that counter goes to zero
24  * then we know to call fsnotify_destroy_mark on it.
25  */
26 struct nfsd_file_mark {
27 	struct fsnotify_mark	nfm_mark;
28 	refcount_t		nfm_ref;
29 	/* serializes nfsd_fsnotify_recalc_mask() against itself */
30 	struct mutex		nfm_recalc_mutex;
31 };
32 
33 /*
34  * A representation of a file that has been opened by knfsd. These are hashed
35  * in the hashtable by inode pointer value. Note that this object doesn't
36  * hold a reference to the inode by itself, so the nf_inode pointer should
37  * never be dereferenced, only used for comparison.
38  */
39 struct nfsd_file {
40 	struct rhlist_head	nf_rlist;
41 	void			*nf_inode;
42 	struct file		*nf_file;
43 	const struct cred	*nf_cred;
44 	struct net		*nf_net;
45 #define NFSD_FILE_HASHED	(0)
46 #define NFSD_FILE_PENDING	(1)
47 #define NFSD_FILE_REFERENCED	(2)
48 #define NFSD_FILE_GC		(3)
49 #define NFSD_FILE_RECENT	(4)
50 	unsigned long		nf_flags;
51 	refcount_t		nf_ref;
52 	unsigned char		nf_may;
53 
54 	struct nfsd_file_mark	*nf_mark;
55 	struct list_head	nf_lru;
56 	struct list_head	nf_gc;
57 	struct rcu_head		nf_rcu;
58 	ktime_t			nf_birthtime;
59 
60 	u32			nf_dio_mem_align;
61 	u32			nf_dio_offset_align;
62 	u32			nf_dio_read_offset_align;
63 };
64 
65 int nfsd_file_cache_init(void);
66 void nfsd_file_cache_purge(struct net *);
67 void nfsd_file_cache_shutdown(void);
68 int nfsd_file_cache_start_net(struct net *net);
69 void nfsd_file_cache_shutdown_net(struct net *net);
70 void nfsd_file_put(struct nfsd_file *nf);
71 struct net *nfsd_file_put_local(struct nfsd_file __rcu **nf);
72 struct nfsd_file *nfsd_file_get(struct nfsd_file *nf);
73 struct file *nfsd_file_file(struct nfsd_file *nf);
74 void nfsd_file_close_inode_sync(struct inode *inode);
75 void nfsd_file_close_export(struct net *net, const struct path *path);
76 void nfsd_file_net_dispose(struct nfsd_net *nn);
77 bool nfsd_file_is_cached(struct inode *inode);
78 __be32 nfsd_file_acquire_gc(struct svc_rqst *rqstp, struct svc_fh *fhp,
79 		  unsigned int may_flags, struct nfsd_file **nfp);
80 __be32 nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
81 		  unsigned int may_flags, struct nfsd_file **nfp);
82 __be32 nfsd_file_acquire_opened(struct svc_rqst *rqstp, struct svc_fh *fhp,
83 		  unsigned int may_flags, struct file *file,
84 		  struct nfsd_file **nfp);
85 __be32 nfsd_file_acquire_local(struct net *net, struct svc_cred *cred,
86 			       struct auth_domain *client, struct svc_fh *fhp,
87 			       unsigned int may_flags, struct nfsd_file **pnf);
88 __be32 nfsd_file_acquire_dir(struct svc_rqst *rqstp, struct svc_fh *fhp,
89 		  struct nfsd_file **pnf);
90 int nfsd_file_cache_stats_show(struct seq_file *m, void *v);
91 void nfsd_fsnotify_recalc_mask(struct nfsd_file *nf);
92 #endif /* _FS_NFSD_FILECACHE_H */
93