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 };
30 
31 /*
32  * A representation of a file that has been opened by knfsd. These are hashed
33  * in the hashtable by inode pointer value. Note that this object doesn't
34  * hold a reference to the inode by itself, so the nf_inode pointer should
35  * never be dereferenced, only used for comparison.
36  */
37 struct nfsd_file {
38 	struct rhlist_head	nf_rlist;
39 	void			*nf_inode;
40 	struct file		*nf_file;
41 	const struct cred	*nf_cred;
42 	struct net		*nf_net;
43 #define NFSD_FILE_HASHED	(0)
44 #define NFSD_FILE_PENDING	(1)
45 #define NFSD_FILE_REFERENCED	(2)
46 #define NFSD_FILE_GC		(3)
47 #define NFSD_FILE_RECENT	(4)
48 	unsigned long		nf_flags;
49 	refcount_t		nf_ref;
50 	unsigned char		nf_may;
51 
52 	struct nfsd_file_mark	*nf_mark;
53 	struct list_head	nf_lru;
54 	struct list_head	nf_gc;
55 	struct rcu_head		nf_rcu;
56 	ktime_t			nf_birthtime;
57 };
58 
59 int nfsd_file_cache_init(void);
60 void nfsd_file_cache_purge(struct net *);
61 void nfsd_file_cache_shutdown(void);
62 int nfsd_file_cache_start_net(struct net *net);
63 void nfsd_file_cache_shutdown_net(struct net *net);
64 void nfsd_file_put(struct nfsd_file *nf);
65 struct net *nfsd_file_put_local(struct nfsd_file __rcu **nf);
66 struct nfsd_file *nfsd_file_get_local(struct nfsd_file *nf);
67 struct nfsd_file *nfsd_file_get(struct nfsd_file *nf);
68 struct file *nfsd_file_file(struct nfsd_file *nf);
69 void nfsd_file_close_inode_sync(struct inode *inode);
70 void nfsd_file_net_dispose(struct nfsd_net *nn);
71 bool nfsd_file_is_cached(struct inode *inode);
72 __be32 nfsd_file_acquire_gc(struct svc_rqst *rqstp, struct svc_fh *fhp,
73 		  unsigned int may_flags, struct nfsd_file **nfp);
74 __be32 nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
75 		  unsigned int may_flags, struct nfsd_file **nfp);
76 __be32 nfsd_file_acquire_opened(struct svc_rqst *rqstp, struct svc_fh *fhp,
77 		  unsigned int may_flags, struct file *file,
78 		  struct nfsd_file **nfp);
79 __be32 nfsd_file_acquire_local(struct net *net, struct svc_cred *cred,
80 			       struct auth_domain *client, struct svc_fh *fhp,
81 			       unsigned int may_flags, struct nfsd_file **pnf);
82 int nfsd_file_cache_stats_show(struct seq_file *m, void *v);
83 #endif /* _FS_NFSD_FILECACHE_H */
84