xref: /openbmc/linux/fs/nfsd/filecache.h (revision aad29a73199b7fbccfbabea3f1ee627ad1924f52)
165294c1fSJeff Layton #ifndef _FS_NFSD_FILECACHE_H
265294c1fSJeff Layton #define _FS_NFSD_FILECACHE_H
365294c1fSJeff Layton 
465294c1fSJeff Layton #include <linux/fsnotify_backend.h>
565294c1fSJeff Layton 
665294c1fSJeff Layton /*
765294c1fSJeff Layton  * This is the fsnotify_mark container that nfsd attaches to the files that it
865294c1fSJeff Layton  * is holding open. Note that we have a separate refcount here aside from the
965294c1fSJeff Layton  * one in the fsnotify_mark. We only want a single fsnotify_mark attached to
1065294c1fSJeff Layton  * the inode, and for each nfsd_file to hold a reference to it.
1165294c1fSJeff Layton  *
1265294c1fSJeff Layton  * The fsnotify_mark is itself refcounted, but that's not sufficient to tell us
1365294c1fSJeff Layton  * how to put that reference. If there are still outstanding nfsd_files that
1465294c1fSJeff Layton  * reference the mark, then we would want to call fsnotify_put_mark on it.
1565294c1fSJeff Layton  * If there were not, then we'd need to call fsnotify_destroy_mark. Since we
1665294c1fSJeff Layton  * can't really tell the difference, we use the nfm_mark to keep track of how
1765294c1fSJeff Layton  * many nfsd_files hold references to the mark. When that counter goes to zero
1865294c1fSJeff Layton  * then we know to call fsnotify_destroy_mark on it.
1965294c1fSJeff Layton  */
2065294c1fSJeff Layton struct nfsd_file_mark {
2165294c1fSJeff Layton 	struct fsnotify_mark	nfm_mark;
22689827cdSTrond Myklebust 	refcount_t		nfm_ref;
2365294c1fSJeff Layton };
2465294c1fSJeff Layton 
2565294c1fSJeff Layton /*
2665294c1fSJeff Layton  * A representation of a file that has been opened by knfsd. These are hashed
2765294c1fSJeff Layton  * in the hashtable by inode pointer value. Note that this object doesn't
2865294c1fSJeff Layton  * hold a reference to the inode by itself, so the nf_inode pointer should
2965294c1fSJeff Layton  * never be dereferenced, only used for comparison.
3065294c1fSJeff Layton  */
3165294c1fSJeff Layton struct nfsd_file {
32c4c649abSChuck Lever 	struct rhlist_head	nf_rlist;
33c4c649abSChuck Lever 	void			*nf_inode;
3465294c1fSJeff Layton 	struct file		*nf_file;
3565294c1fSJeff Layton 	const struct cred	*nf_cred;
365e113224STrond Myklebust 	struct net		*nf_net;
3765294c1fSJeff Layton #define NFSD_FILE_HASHED	(0)
3865294c1fSJeff Layton #define NFSD_FILE_PENDING	(1)
3923ba98deSJeff Layton #define NFSD_FILE_REFERENCED	(2)
404d1ea845SChuck Lever #define NFSD_FILE_GC		(3)
4165294c1fSJeff Layton 	unsigned long		nf_flags;
42689827cdSTrond Myklebust 	refcount_t		nf_ref;
4365294c1fSJeff Layton 	unsigned char		nf_may;
44c4c649abSChuck Lever 
4565294c1fSJeff Layton 	struct nfsd_file_mark	*nf_mark;
46c4c649abSChuck Lever 	struct list_head	nf_lru;
47*80d39b50SYouzhong Yang 	struct list_head	nf_gc;
48c4c649abSChuck Lever 	struct rcu_head		nf_rcu;
49904940e9SChuck Lever 	ktime_t			nf_birthtime;
5065294c1fSJeff Layton };
5165294c1fSJeff Layton 
5265294c1fSJeff Layton int nfsd_file_cache_init(void);
535e113224STrond Myklebust void nfsd_file_cache_purge(struct net *);
5465294c1fSJeff Layton void nfsd_file_cache_shutdown(void);
559542e6a6STrond Myklebust int nfsd_file_cache_start_net(struct net *net);
569542e6a6STrond Myklebust void nfsd_file_cache_shutdown_net(struct net *net);
5765294c1fSJeff Layton void nfsd_file_put(struct nfsd_file *nf);
5865294c1fSJeff Layton struct nfsd_file *nfsd_file_get(struct nfsd_file *nf);
5965294c1fSJeff Layton void nfsd_file_close_inode_sync(struct inode *inode);
6065294c1fSJeff Layton bool nfsd_file_is_cached(struct inode *inode);
614d1ea845SChuck Lever __be32 nfsd_file_acquire_gc(struct svc_rqst *rqstp, struct svc_fh *fhp,
624d1ea845SChuck Lever 		  unsigned int may_flags, struct nfsd_file **nfp);
6365294c1fSJeff Layton __be32 nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
6465294c1fSJeff Layton 		  unsigned int may_flags, struct nfsd_file **nfp);
650b3a551fSJeff Layton __be32 nfsd_file_acquire_opened(struct svc_rqst *rqstp, struct svc_fh *fhp,
660b3a551fSJeff Layton 		  unsigned int may_flags, struct file *file,
670b3a551fSJeff Layton 		  struct nfsd_file **nfp);
681342f9ddSChenXiaoSong int nfsd_file_cache_stats_show(struct seq_file *m, void *v);
6965294c1fSJeff Layton #endif /* _FS_NFSD_FILECACHE_H */
70