xref: /openbmc/linux/fs/nfsd/filecache.c (revision 29d4bdbbb910f33d6058d2c51278f00f656df325)
165294c1fSJeff Layton /*
265294c1fSJeff Layton  * Open file cache.
365294c1fSJeff Layton  *
465294c1fSJeff Layton  * (c) 2015 - Jeff Layton <jeff.layton@primarydata.com>
565294c1fSJeff Layton  */
665294c1fSJeff Layton 
765294c1fSJeff Layton #include <linux/hash.h>
865294c1fSJeff Layton #include <linux/slab.h>
965294c1fSJeff Layton #include <linux/file.h>
10cbcc268bSMatthew Wilcox (Oracle) #include <linux/pagemap.h>
1165294c1fSJeff Layton #include <linux/sched.h>
1265294c1fSJeff Layton #include <linux/list_lru.h>
1365294c1fSJeff Layton #include <linux/fsnotify_backend.h>
1465294c1fSJeff Layton #include <linux/fsnotify.h>
1565294c1fSJeff Layton #include <linux/seq_file.h>
1665294c1fSJeff Layton 
1765294c1fSJeff Layton #include "vfs.h"
1865294c1fSJeff Layton #include "nfsd.h"
1965294c1fSJeff Layton #include "nfsfh.h"
205e113224STrond Myklebust #include "netns.h"
2165294c1fSJeff Layton #include "filecache.h"
2265294c1fSJeff Layton #include "trace.h"
2365294c1fSJeff Layton 
2465294c1fSJeff Layton #define NFSDDBG_FACILITY	NFSDDBG_FH
2565294c1fSJeff Layton 
2665294c1fSJeff Layton /* FIXME: dynamically size this for the machine somehow? */
2765294c1fSJeff Layton #define NFSD_FILE_HASH_BITS                   12
2865294c1fSJeff Layton #define NFSD_FILE_HASH_SIZE                  (1 << NFSD_FILE_HASH_BITS)
2965294c1fSJeff Layton #define NFSD_LAUNDRETTE_DELAY		     (2 * HZ)
3065294c1fSJeff Layton 
3165294c1fSJeff Layton #define NFSD_FILE_SHUTDOWN		     (1)
3265294c1fSJeff Layton #define NFSD_FILE_LRU_THRESHOLD		     (4096UL)
3365294c1fSJeff Layton #define NFSD_FILE_LRU_LIMIT		     (NFSD_FILE_LRU_THRESHOLD << 2)
3465294c1fSJeff Layton 
3565294c1fSJeff Layton /* We only care about NFSD_MAY_READ/WRITE for this cache */
3665294c1fSJeff Layton #define NFSD_FILE_MAY_MASK	(NFSD_MAY_READ|NFSD_MAY_WRITE)
3765294c1fSJeff Layton 
3865294c1fSJeff Layton struct nfsd_fcache_bucket {
3965294c1fSJeff Layton 	struct hlist_head	nfb_head;
4065294c1fSJeff Layton 	spinlock_t		nfb_lock;
4165294c1fSJeff Layton 	unsigned int		nfb_count;
4265294c1fSJeff Layton 	unsigned int		nfb_maxcount;
4365294c1fSJeff Layton };
4465294c1fSJeff Layton 
4565294c1fSJeff Layton static DEFINE_PER_CPU(unsigned long, nfsd_file_cache_hits);
46*29d4bdbbSChuck Lever static DEFINE_PER_CPU(unsigned long, nfsd_file_acquisitions);
4765294c1fSJeff Layton 
489542e6a6STrond Myklebust struct nfsd_fcache_disposal {
499542e6a6STrond Myklebust 	struct work_struct work;
509542e6a6STrond Myklebust 	spinlock_t lock;
519542e6a6STrond Myklebust 	struct list_head freeme;
529542e6a6STrond Myklebust };
539542e6a6STrond Myklebust 
5450d0def9SChen Zhou static struct workqueue_struct *nfsd_filecache_wq __read_mostly;
559542e6a6STrond Myklebust 
5665294c1fSJeff Layton static struct kmem_cache		*nfsd_file_slab;
5765294c1fSJeff Layton static struct kmem_cache		*nfsd_file_mark_slab;
5865294c1fSJeff Layton static struct nfsd_fcache_bucket	*nfsd_file_hashtbl;
5965294c1fSJeff Layton static struct list_lru			nfsd_file_lru;
6065294c1fSJeff Layton static long				nfsd_file_lru_flags;
6165294c1fSJeff Layton static struct fsnotify_group		*nfsd_file_fsnotify_group;
6265294c1fSJeff Layton static atomic_long_t			nfsd_filecache_count;
6365294c1fSJeff Layton static struct delayed_work		nfsd_filecache_laundrette;
6465294c1fSJeff Layton 
659542e6a6STrond Myklebust static void nfsd_file_gc(void);
6665294c1fSJeff Layton 
6765294c1fSJeff Layton static void
689542e6a6STrond Myklebust nfsd_file_schedule_laundrette(void)
6965294c1fSJeff Layton {
7065294c1fSJeff Layton 	long count = atomic_long_read(&nfsd_filecache_count);
7165294c1fSJeff Layton 
7265294c1fSJeff Layton 	if (count == 0 || test_bit(NFSD_FILE_SHUTDOWN, &nfsd_file_lru_flags))
7365294c1fSJeff Layton 		return;
7465294c1fSJeff Layton 
759542e6a6STrond Myklebust 	queue_delayed_work(system_wq, &nfsd_filecache_laundrette,
769542e6a6STrond Myklebust 			NFSD_LAUNDRETTE_DELAY);
7765294c1fSJeff Layton }
7865294c1fSJeff Layton 
7965294c1fSJeff Layton static void
8065294c1fSJeff Layton nfsd_file_slab_free(struct rcu_head *rcu)
8165294c1fSJeff Layton {
8265294c1fSJeff Layton 	struct nfsd_file *nf = container_of(rcu, struct nfsd_file, nf_rcu);
8365294c1fSJeff Layton 
8465294c1fSJeff Layton 	put_cred(nf->nf_cred);
8565294c1fSJeff Layton 	kmem_cache_free(nfsd_file_slab, nf);
8665294c1fSJeff Layton }
8765294c1fSJeff Layton 
8865294c1fSJeff Layton static void
8965294c1fSJeff Layton nfsd_file_mark_free(struct fsnotify_mark *mark)
9065294c1fSJeff Layton {
9165294c1fSJeff Layton 	struct nfsd_file_mark *nfm = container_of(mark, struct nfsd_file_mark,
9265294c1fSJeff Layton 						  nfm_mark);
9365294c1fSJeff Layton 
9465294c1fSJeff Layton 	kmem_cache_free(nfsd_file_mark_slab, nfm);
9565294c1fSJeff Layton }
9665294c1fSJeff Layton 
9765294c1fSJeff Layton static struct nfsd_file_mark *
9865294c1fSJeff Layton nfsd_file_mark_get(struct nfsd_file_mark *nfm)
9965294c1fSJeff Layton {
100689827cdSTrond Myklebust 	if (!refcount_inc_not_zero(&nfm->nfm_ref))
10165294c1fSJeff Layton 		return NULL;
10265294c1fSJeff Layton 	return nfm;
10365294c1fSJeff Layton }
10465294c1fSJeff Layton 
10565294c1fSJeff Layton static void
10665294c1fSJeff Layton nfsd_file_mark_put(struct nfsd_file_mark *nfm)
10765294c1fSJeff Layton {
108689827cdSTrond Myklebust 	if (refcount_dec_and_test(&nfm->nfm_ref)) {
10965294c1fSJeff Layton 		fsnotify_destroy_mark(&nfm->nfm_mark, nfsd_file_fsnotify_group);
11065294c1fSJeff Layton 		fsnotify_put_mark(&nfm->nfm_mark);
11165294c1fSJeff Layton 	}
11265294c1fSJeff Layton }
11365294c1fSJeff Layton 
11465294c1fSJeff Layton static struct nfsd_file_mark *
11565294c1fSJeff Layton nfsd_file_mark_find_or_create(struct nfsd_file *nf)
11665294c1fSJeff Layton {
11765294c1fSJeff Layton 	int			err;
11865294c1fSJeff Layton 	struct fsnotify_mark	*mark;
11965294c1fSJeff Layton 	struct nfsd_file_mark	*nfm = NULL, *new;
12065294c1fSJeff Layton 	struct inode *inode = nf->nf_inode;
12165294c1fSJeff Layton 
12265294c1fSJeff Layton 	do {
123b8962a9dSAmir Goldstein 		fsnotify_group_lock(nfsd_file_fsnotify_group);
12465294c1fSJeff Layton 		mark = fsnotify_find_mark(&inode->i_fsnotify_marks,
12565294c1fSJeff Layton 					  nfsd_file_fsnotify_group);
12665294c1fSJeff Layton 		if (mark) {
12765294c1fSJeff Layton 			nfm = nfsd_file_mark_get(container_of(mark,
12865294c1fSJeff Layton 						 struct nfsd_file_mark,
12965294c1fSJeff Layton 						 nfm_mark));
130b8962a9dSAmir Goldstein 			fsnotify_group_unlock(nfsd_file_fsnotify_group);
13190d2f1daSTrond Myklebust 			if (nfm) {
13265294c1fSJeff Layton 				fsnotify_put_mark(mark);
13365294c1fSJeff Layton 				break;
13490d2f1daSTrond Myklebust 			}
13590d2f1daSTrond Myklebust 			/* Avoid soft lockup race with nfsd_file_mark_put() */
13690d2f1daSTrond Myklebust 			fsnotify_destroy_mark(mark, nfsd_file_fsnotify_group);
13790d2f1daSTrond Myklebust 			fsnotify_put_mark(mark);
138b8962a9dSAmir Goldstein 		} else {
139b8962a9dSAmir Goldstein 			fsnotify_group_unlock(nfsd_file_fsnotify_group);
140b8962a9dSAmir Goldstein 		}
14165294c1fSJeff Layton 
14265294c1fSJeff Layton 		/* allocate a new nfm */
14365294c1fSJeff Layton 		new = kmem_cache_alloc(nfsd_file_mark_slab, GFP_KERNEL);
14465294c1fSJeff Layton 		if (!new)
14565294c1fSJeff Layton 			return NULL;
14665294c1fSJeff Layton 		fsnotify_init_mark(&new->nfm_mark, nfsd_file_fsnotify_group);
14765294c1fSJeff Layton 		new->nfm_mark.mask = FS_ATTRIB|FS_DELETE_SELF;
148689827cdSTrond Myklebust 		refcount_set(&new->nfm_ref, 1);
14965294c1fSJeff Layton 
15065294c1fSJeff Layton 		err = fsnotify_add_inode_mark(&new->nfm_mark, inode, 0);
15165294c1fSJeff Layton 
15265294c1fSJeff Layton 		/*
15365294c1fSJeff Layton 		 * If the add was successful, then return the object.
15465294c1fSJeff Layton 		 * Otherwise, we need to put the reference we hold on the
15565294c1fSJeff Layton 		 * nfm_mark. The fsnotify code will take a reference and put
15665294c1fSJeff Layton 		 * it on failure, so we can't just free it directly. It's also
15765294c1fSJeff Layton 		 * not safe to call fsnotify_destroy_mark on it as the
15865294c1fSJeff Layton 		 * mark->group will be NULL. Thus, we can't let the nfm_ref
15965294c1fSJeff Layton 		 * counter drive the destruction at this point.
16065294c1fSJeff Layton 		 */
16165294c1fSJeff Layton 		if (likely(!err))
16265294c1fSJeff Layton 			nfm = new;
16365294c1fSJeff Layton 		else
16465294c1fSJeff Layton 			fsnotify_put_mark(&new->nfm_mark);
16565294c1fSJeff Layton 	} while (unlikely(err == -EEXIST));
16665294c1fSJeff Layton 
16765294c1fSJeff Layton 	return nfm;
16865294c1fSJeff Layton }
16965294c1fSJeff Layton 
17065294c1fSJeff Layton static struct nfsd_file *
1715e113224STrond Myklebust nfsd_file_alloc(struct inode *inode, unsigned int may, unsigned int hashval,
1725e113224STrond Myklebust 		struct net *net)
17365294c1fSJeff Layton {
17465294c1fSJeff Layton 	struct nfsd_file *nf;
17565294c1fSJeff Layton 
17665294c1fSJeff Layton 	nf = kmem_cache_alloc(nfsd_file_slab, GFP_KERNEL);
17765294c1fSJeff Layton 	if (nf) {
17865294c1fSJeff Layton 		INIT_HLIST_NODE(&nf->nf_node);
17965294c1fSJeff Layton 		INIT_LIST_HEAD(&nf->nf_lru);
18065294c1fSJeff Layton 		nf->nf_file = NULL;
18165294c1fSJeff Layton 		nf->nf_cred = get_current_cred();
1825e113224STrond Myklebust 		nf->nf_net = net;
18365294c1fSJeff Layton 		nf->nf_flags = 0;
18465294c1fSJeff Layton 		nf->nf_inode = inode;
18565294c1fSJeff Layton 		nf->nf_hashval = hashval;
186689827cdSTrond Myklebust 		refcount_set(&nf->nf_ref, 1);
18765294c1fSJeff Layton 		nf->nf_may = may & NFSD_FILE_MAY_MASK;
18865294c1fSJeff Layton 		nf->nf_mark = NULL;
18965294c1fSJeff Layton 		trace_nfsd_file_alloc(nf);
19065294c1fSJeff Layton 	}
19165294c1fSJeff Layton 	return nf;
19265294c1fSJeff Layton }
19365294c1fSJeff Layton 
19465294c1fSJeff Layton static bool
19565294c1fSJeff Layton nfsd_file_free(struct nfsd_file *nf)
19665294c1fSJeff Layton {
19765294c1fSJeff Layton 	bool flush = false;
19865294c1fSJeff Layton 
19965294c1fSJeff Layton 	trace_nfsd_file_put_final(nf);
20065294c1fSJeff Layton 	if (nf->nf_mark)
20165294c1fSJeff Layton 		nfsd_file_mark_put(nf->nf_mark);
20265294c1fSJeff Layton 	if (nf->nf_file) {
20365294c1fSJeff Layton 		get_file(nf->nf_file);
20465294c1fSJeff Layton 		filp_close(nf->nf_file, NULL);
20565294c1fSJeff Layton 		fput(nf->nf_file);
20665294c1fSJeff Layton 		flush = true;
20765294c1fSJeff Layton 	}
20865294c1fSJeff Layton 	call_rcu(&nf->nf_rcu, nfsd_file_slab_free);
20965294c1fSJeff Layton 	return flush;
21065294c1fSJeff Layton }
21165294c1fSJeff Layton 
212055b24a8STrond Myklebust static bool
213055b24a8STrond Myklebust nfsd_file_check_writeback(struct nfsd_file *nf)
214055b24a8STrond Myklebust {
215055b24a8STrond Myklebust 	struct file *file = nf->nf_file;
216055b24a8STrond Myklebust 	struct address_space *mapping;
217055b24a8STrond Myklebust 
218055b24a8STrond Myklebust 	if (!file || !(file->f_mode & FMODE_WRITE))
219055b24a8STrond Myklebust 		return false;
220055b24a8STrond Myklebust 	mapping = file->f_mapping;
221055b24a8STrond Myklebust 	return mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) ||
222055b24a8STrond Myklebust 		mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK);
223055b24a8STrond Myklebust }
224055b24a8STrond Myklebust 
225055b24a8STrond Myklebust static int
226055b24a8STrond Myklebust nfsd_file_check_write_error(struct nfsd_file *nf)
227055b24a8STrond Myklebust {
228055b24a8STrond Myklebust 	struct file *file = nf->nf_file;
229055b24a8STrond Myklebust 
230055b24a8STrond Myklebust 	if (!file || !(file->f_mode & FMODE_WRITE))
231055b24a8STrond Myklebust 		return 0;
232055b24a8STrond Myklebust 	return filemap_check_wb_err(file->f_mapping, READ_ONCE(file->f_wb_err));
233055b24a8STrond Myklebust }
234055b24a8STrond Myklebust 
23565294c1fSJeff Layton static void
2366b8a9433STrond Myklebust nfsd_file_flush(struct nfsd_file *nf)
2376b8a9433STrond Myklebust {
2386b8a9433STrond Myklebust 	if (nf->nf_file && vfs_fsync(nf->nf_file, 1) != 0)
2396b8a9433STrond Myklebust 		nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id));
2406b8a9433STrond Myklebust }
2416b8a9433STrond Myklebust 
2426b8a9433STrond Myklebust static void
24365294c1fSJeff Layton nfsd_file_do_unhash(struct nfsd_file *nf)
24465294c1fSJeff Layton {
24565294c1fSJeff Layton 	lockdep_assert_held(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock);
24665294c1fSJeff Layton 
24765294c1fSJeff Layton 	trace_nfsd_file_unhash(nf);
24865294c1fSJeff Layton 
249055b24a8STrond Myklebust 	if (nfsd_file_check_write_error(nf))
2503988a578SChuck Lever 		nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id));
25165294c1fSJeff Layton 	--nfsd_file_hashtbl[nf->nf_hashval].nfb_count;
25265294c1fSJeff Layton 	hlist_del_rcu(&nf->nf_node);
25365294c1fSJeff Layton 	atomic_long_dec(&nfsd_filecache_count);
25465294c1fSJeff Layton }
25565294c1fSJeff Layton 
25665294c1fSJeff Layton static bool
25765294c1fSJeff Layton nfsd_file_unhash(struct nfsd_file *nf)
25865294c1fSJeff Layton {
25965294c1fSJeff Layton 	if (test_and_clear_bit(NFSD_FILE_HASHED, &nf->nf_flags)) {
26065294c1fSJeff Layton 		nfsd_file_do_unhash(nf);
26136ebbdb9STrond Myklebust 		if (!list_empty(&nf->nf_lru))
26236ebbdb9STrond Myklebust 			list_lru_del(&nfsd_file_lru, &nf->nf_lru);
26365294c1fSJeff Layton 		return true;
26465294c1fSJeff Layton 	}
26565294c1fSJeff Layton 	return false;
26665294c1fSJeff Layton }
26765294c1fSJeff Layton 
26865294c1fSJeff Layton /*
26965294c1fSJeff Layton  * Return true if the file was unhashed.
27065294c1fSJeff Layton  */
27165294c1fSJeff Layton static bool
27265294c1fSJeff Layton nfsd_file_unhash_and_release_locked(struct nfsd_file *nf, struct list_head *dispose)
27365294c1fSJeff Layton {
27465294c1fSJeff Layton 	lockdep_assert_held(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock);
27565294c1fSJeff Layton 
27665294c1fSJeff Layton 	trace_nfsd_file_unhash_and_release_locked(nf);
27765294c1fSJeff Layton 	if (!nfsd_file_unhash(nf))
27865294c1fSJeff Layton 		return false;
27965294c1fSJeff Layton 	/* keep final reference for nfsd_file_lru_dispose */
280689827cdSTrond Myklebust 	if (refcount_dec_not_one(&nf->nf_ref))
28165294c1fSJeff Layton 		return true;
28265294c1fSJeff Layton 
28365294c1fSJeff Layton 	list_add(&nf->nf_lru, dispose);
28465294c1fSJeff Layton 	return true;
28565294c1fSJeff Layton }
28665294c1fSJeff Layton 
287b6669305STrond Myklebust static void
28865294c1fSJeff Layton nfsd_file_put_noref(struct nfsd_file *nf)
28965294c1fSJeff Layton {
29065294c1fSJeff Layton 	trace_nfsd_file_put(nf);
29165294c1fSJeff Layton 
292689827cdSTrond Myklebust 	if (refcount_dec_and_test(&nf->nf_ref)) {
29365294c1fSJeff Layton 		WARN_ON(test_bit(NFSD_FILE_HASHED, &nf->nf_flags));
29465294c1fSJeff Layton 		nfsd_file_free(nf);
29565294c1fSJeff Layton 	}
29665294c1fSJeff Layton }
29765294c1fSJeff Layton 
29865294c1fSJeff Layton void
29965294c1fSJeff Layton nfsd_file_put(struct nfsd_file *nf)
30065294c1fSJeff Layton {
30108af54b3SChuck Lever 	might_sleep();
30208af54b3SChuck Lever 
30365294c1fSJeff Layton 	set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags);
30499939792STrond Myklebust 	if (test_bit(NFSD_FILE_HASHED, &nf->nf_flags) == 0) {
3056b8a9433STrond Myklebust 		nfsd_file_flush(nf);
306b6669305STrond Myklebust 		nfsd_file_put_noref(nf);
307b6c71c66SChuck Lever 	} else if (nf->nf_file) {
308b6669305STrond Myklebust 		nfsd_file_put_noref(nf);
3099542e6a6STrond Myklebust 		nfsd_file_schedule_laundrette();
310b6c71c66SChuck Lever 	} else
311b6c71c66SChuck Lever 		nfsd_file_put_noref(nf);
312b6c71c66SChuck Lever 
3139542e6a6STrond Myklebust 	if (atomic_long_read(&nfsd_filecache_count) >= NFSD_FILE_LRU_LIMIT)
3149542e6a6STrond Myklebust 		nfsd_file_gc();
31565294c1fSJeff Layton }
31665294c1fSJeff Layton 
31765294c1fSJeff Layton struct nfsd_file *
31865294c1fSJeff Layton nfsd_file_get(struct nfsd_file *nf)
31965294c1fSJeff Layton {
320689827cdSTrond Myklebust 	if (likely(refcount_inc_not_zero(&nf->nf_ref)))
32165294c1fSJeff Layton 		return nf;
32265294c1fSJeff Layton 	return NULL;
32365294c1fSJeff Layton }
32465294c1fSJeff Layton 
32565294c1fSJeff Layton static void
32665294c1fSJeff Layton nfsd_file_dispose_list(struct list_head *dispose)
32765294c1fSJeff Layton {
32865294c1fSJeff Layton 	struct nfsd_file *nf;
32965294c1fSJeff Layton 
33065294c1fSJeff Layton 	while(!list_empty(dispose)) {
33165294c1fSJeff Layton 		nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
33265294c1fSJeff Layton 		list_del(&nf->nf_lru);
3336b8a9433STrond Myklebust 		nfsd_file_flush(nf);
33465294c1fSJeff Layton 		nfsd_file_put_noref(nf);
33565294c1fSJeff Layton 	}
33665294c1fSJeff Layton }
33765294c1fSJeff Layton 
33865294c1fSJeff Layton static void
33965294c1fSJeff Layton nfsd_file_dispose_list_sync(struct list_head *dispose)
34065294c1fSJeff Layton {
34165294c1fSJeff Layton 	bool flush = false;
34265294c1fSJeff Layton 	struct nfsd_file *nf;
34365294c1fSJeff Layton 
34465294c1fSJeff Layton 	while(!list_empty(dispose)) {
34565294c1fSJeff Layton 		nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
34665294c1fSJeff Layton 		list_del(&nf->nf_lru);
3476b8a9433STrond Myklebust 		nfsd_file_flush(nf);
348689827cdSTrond Myklebust 		if (!refcount_dec_and_test(&nf->nf_ref))
34965294c1fSJeff Layton 			continue;
35065294c1fSJeff Layton 		if (nfsd_file_free(nf))
35165294c1fSJeff Layton 			flush = true;
35265294c1fSJeff Layton 	}
35365294c1fSJeff Layton 	if (flush)
35465294c1fSJeff Layton 		flush_delayed_fput();
35565294c1fSJeff Layton }
35665294c1fSJeff Layton 
3579542e6a6STrond Myklebust static void
3589542e6a6STrond Myklebust nfsd_file_list_remove_disposal(struct list_head *dst,
3599542e6a6STrond Myklebust 		struct nfsd_fcache_disposal *l)
3609542e6a6STrond Myklebust {
3619542e6a6STrond Myklebust 	spin_lock(&l->lock);
3629542e6a6STrond Myklebust 	list_splice_init(&l->freeme, dst);
3639542e6a6STrond Myklebust 	spin_unlock(&l->lock);
3649542e6a6STrond Myklebust }
3659542e6a6STrond Myklebust 
3669542e6a6STrond Myklebust static void
3679542e6a6STrond Myklebust nfsd_file_list_add_disposal(struct list_head *files, struct net *net)
3689542e6a6STrond Myklebust {
3691463b38eSNeilBrown 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
3701463b38eSNeilBrown 	struct nfsd_fcache_disposal *l = nn->fcache_disposal;
3719542e6a6STrond Myklebust 
3729542e6a6STrond Myklebust 	spin_lock(&l->lock);
3739542e6a6STrond Myklebust 	list_splice_tail_init(files, &l->freeme);
3749542e6a6STrond Myklebust 	spin_unlock(&l->lock);
3759542e6a6STrond Myklebust 	queue_work(nfsd_filecache_wq, &l->work);
3769542e6a6STrond Myklebust }
3779542e6a6STrond Myklebust 
3789542e6a6STrond Myklebust static void
3799542e6a6STrond Myklebust nfsd_file_list_add_pernet(struct list_head *dst, struct list_head *src,
3809542e6a6STrond Myklebust 		struct net *net)
3819542e6a6STrond Myklebust {
3829542e6a6STrond Myklebust 	struct nfsd_file *nf, *tmp;
3839542e6a6STrond Myklebust 
3849542e6a6STrond Myklebust 	list_for_each_entry_safe(nf, tmp, src, nf_lru) {
3859542e6a6STrond Myklebust 		if (nf->nf_net == net)
3869542e6a6STrond Myklebust 			list_move_tail(&nf->nf_lru, dst);
3879542e6a6STrond Myklebust 	}
3889542e6a6STrond Myklebust }
3899542e6a6STrond Myklebust 
3909542e6a6STrond Myklebust static void
3919542e6a6STrond Myklebust nfsd_file_dispose_list_delayed(struct list_head *dispose)
3929542e6a6STrond Myklebust {
3939542e6a6STrond Myklebust 	LIST_HEAD(list);
3949542e6a6STrond Myklebust 	struct nfsd_file *nf;
3959542e6a6STrond Myklebust 
3969542e6a6STrond Myklebust 	while(!list_empty(dispose)) {
3979542e6a6STrond Myklebust 		nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
3989542e6a6STrond Myklebust 		nfsd_file_list_add_pernet(&list, dispose, nf->nf_net);
3999542e6a6STrond Myklebust 		nfsd_file_list_add_disposal(&list, nf->nf_net);
4009542e6a6STrond Myklebust 	}
4019542e6a6STrond Myklebust }
4029542e6a6STrond Myklebust 
40365294c1fSJeff Layton /*
40465294c1fSJeff Layton  * Note this can deadlock with nfsd_file_cache_purge.
40565294c1fSJeff Layton  */
40665294c1fSJeff Layton static enum lru_status
40765294c1fSJeff Layton nfsd_file_lru_cb(struct list_head *item, struct list_lru_one *lru,
40865294c1fSJeff Layton 		 spinlock_t *lock, void *arg)
40965294c1fSJeff Layton 	__releases(lock)
41065294c1fSJeff Layton 	__acquires(lock)
41165294c1fSJeff Layton {
41265294c1fSJeff Layton 	struct list_head *head = arg;
41365294c1fSJeff Layton 	struct nfsd_file *nf = list_entry(item, struct nfsd_file, nf_lru);
41465294c1fSJeff Layton 
41565294c1fSJeff Layton 	/*
41665294c1fSJeff Layton 	 * Do a lockless refcount check. The hashtable holds one reference, so
41765294c1fSJeff Layton 	 * we look to see if anything else has a reference, or if any have
41865294c1fSJeff Layton 	 * been put since the shrinker last ran. Those don't get unhashed and
41965294c1fSJeff Layton 	 * released.
42065294c1fSJeff Layton 	 *
42165294c1fSJeff Layton 	 * Note that in the put path, we set the flag and then decrement the
42265294c1fSJeff Layton 	 * counter. Here we check the counter and then test and clear the flag.
42365294c1fSJeff Layton 	 * That order is deliberate to ensure that we can do this locklessly.
42465294c1fSJeff Layton 	 */
425689827cdSTrond Myklebust 	if (refcount_read(&nf->nf_ref) > 1)
42665294c1fSJeff Layton 		goto out_skip;
427055b24a8STrond Myklebust 
428055b24a8STrond Myklebust 	/*
429055b24a8STrond Myklebust 	 * Don't throw out files that are still undergoing I/O or
430055b24a8STrond Myklebust 	 * that have uncleared errors pending.
431055b24a8STrond Myklebust 	 */
432055b24a8STrond Myklebust 	if (nfsd_file_check_writeback(nf))
433055b24a8STrond Myklebust 		goto out_skip;
434055b24a8STrond Myklebust 
43565294c1fSJeff Layton 	if (test_and_clear_bit(NFSD_FILE_REFERENCED, &nf->nf_flags))
436bd6e1cecSTrond Myklebust 		goto out_skip;
43765294c1fSJeff Layton 
43865294c1fSJeff Layton 	if (!test_and_clear_bit(NFSD_FILE_HASHED, &nf->nf_flags))
43965294c1fSJeff Layton 		goto out_skip;
44065294c1fSJeff Layton 
44165294c1fSJeff Layton 	list_lru_isolate_move(lru, &nf->nf_lru, head);
44265294c1fSJeff Layton 	return LRU_REMOVED;
44365294c1fSJeff Layton out_skip:
44465294c1fSJeff Layton 	return LRU_SKIP;
44565294c1fSJeff Layton }
44665294c1fSJeff Layton 
4479542e6a6STrond Myklebust static unsigned long
4489542e6a6STrond Myklebust nfsd_file_lru_walk_list(struct shrink_control *sc)
44965294c1fSJeff Layton {
4509542e6a6STrond Myklebust 	LIST_HEAD(head);
45136ebbdb9STrond Myklebust 	struct nfsd_file *nf;
4529542e6a6STrond Myklebust 	unsigned long ret;
45336ebbdb9STrond Myklebust 
4549542e6a6STrond Myklebust 	if (sc)
4559542e6a6STrond Myklebust 		ret = list_lru_shrink_walk(&nfsd_file_lru, sc,
4569542e6a6STrond Myklebust 				nfsd_file_lru_cb, &head);
4579542e6a6STrond Myklebust 	else
4589542e6a6STrond Myklebust 		ret = list_lru_walk(&nfsd_file_lru,
4599542e6a6STrond Myklebust 				nfsd_file_lru_cb,
4609542e6a6STrond Myklebust 				&head, LONG_MAX);
4619542e6a6STrond Myklebust 	list_for_each_entry(nf, &head, nf_lru) {
46265294c1fSJeff Layton 		spin_lock(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock);
46365294c1fSJeff Layton 		nfsd_file_do_unhash(nf);
46465294c1fSJeff Layton 		spin_unlock(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock);
46565294c1fSJeff Layton 	}
4669542e6a6STrond Myklebust 	nfsd_file_dispose_list_delayed(&head);
4679542e6a6STrond Myklebust 	return ret;
4689542e6a6STrond Myklebust }
4699542e6a6STrond Myklebust 
4709542e6a6STrond Myklebust static void
4719542e6a6STrond Myklebust nfsd_file_gc(void)
4729542e6a6STrond Myklebust {
4739542e6a6STrond Myklebust 	nfsd_file_lru_walk_list(NULL);
4749542e6a6STrond Myklebust }
4759542e6a6STrond Myklebust 
4769542e6a6STrond Myklebust static void
4779542e6a6STrond Myklebust nfsd_file_gc_worker(struct work_struct *work)
4789542e6a6STrond Myklebust {
4799542e6a6STrond Myklebust 	nfsd_file_gc();
4809542e6a6STrond Myklebust 	nfsd_file_schedule_laundrette();
48165294c1fSJeff Layton }
48265294c1fSJeff Layton 
48365294c1fSJeff Layton static unsigned long
48465294c1fSJeff Layton nfsd_file_lru_count(struct shrinker *s, struct shrink_control *sc)
48565294c1fSJeff Layton {
48665294c1fSJeff Layton 	return list_lru_count(&nfsd_file_lru);
48765294c1fSJeff Layton }
48865294c1fSJeff Layton 
48965294c1fSJeff Layton static unsigned long
49065294c1fSJeff Layton nfsd_file_lru_scan(struct shrinker *s, struct shrink_control *sc)
49165294c1fSJeff Layton {
4929542e6a6STrond Myklebust 	return nfsd_file_lru_walk_list(sc);
49365294c1fSJeff Layton }
49465294c1fSJeff Layton 
49565294c1fSJeff Layton static struct shrinker	nfsd_file_shrinker = {
49665294c1fSJeff Layton 	.scan_objects = nfsd_file_lru_scan,
49765294c1fSJeff Layton 	.count_objects = nfsd_file_lru_count,
49865294c1fSJeff Layton 	.seeks = 1,
49965294c1fSJeff Layton };
50065294c1fSJeff Layton 
50165294c1fSJeff Layton static void
50265294c1fSJeff Layton __nfsd_file_close_inode(struct inode *inode, unsigned int hashval,
50365294c1fSJeff Layton 			struct list_head *dispose)
50465294c1fSJeff Layton {
50565294c1fSJeff Layton 	struct nfsd_file	*nf;
50665294c1fSJeff Layton 	struct hlist_node	*tmp;
50765294c1fSJeff Layton 
50865294c1fSJeff Layton 	spin_lock(&nfsd_file_hashtbl[hashval].nfb_lock);
50965294c1fSJeff Layton 	hlist_for_each_entry_safe(nf, tmp, &nfsd_file_hashtbl[hashval].nfb_head, nf_node) {
51065294c1fSJeff Layton 		if (inode == nf->nf_inode)
51165294c1fSJeff Layton 			nfsd_file_unhash_and_release_locked(nf, dispose);
51265294c1fSJeff Layton 	}
51365294c1fSJeff Layton 	spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock);
51465294c1fSJeff Layton }
51565294c1fSJeff Layton 
51665294c1fSJeff Layton /**
51765294c1fSJeff Layton  * nfsd_file_close_inode_sync - attempt to forcibly close a nfsd_file
51865294c1fSJeff Layton  * @inode: inode of the file to attempt to remove
51965294c1fSJeff Layton  *
52065294c1fSJeff Layton  * Walk the whole hash bucket, looking for any files that correspond to "inode".
52165294c1fSJeff Layton  * If any do, then unhash them and put the hashtable reference to them and
52265294c1fSJeff Layton  * destroy any that had their last reference put. Also ensure that any of the
52365294c1fSJeff Layton  * fputs also have their final __fput done as well.
52465294c1fSJeff Layton  */
52565294c1fSJeff Layton void
52665294c1fSJeff Layton nfsd_file_close_inode_sync(struct inode *inode)
52765294c1fSJeff Layton {
52865294c1fSJeff Layton 	unsigned int		hashval = (unsigned int)hash_long(inode->i_ino,
52965294c1fSJeff Layton 						NFSD_FILE_HASH_BITS);
53065294c1fSJeff Layton 	LIST_HEAD(dispose);
53165294c1fSJeff Layton 
53265294c1fSJeff Layton 	__nfsd_file_close_inode(inode, hashval, &dispose);
53365294c1fSJeff Layton 	trace_nfsd_file_close_inode_sync(inode, hashval, !list_empty(&dispose));
53465294c1fSJeff Layton 	nfsd_file_dispose_list_sync(&dispose);
53565294c1fSJeff Layton }
53665294c1fSJeff Layton 
53765294c1fSJeff Layton /**
53819598141STrond Myklebust  * nfsd_file_close_inode - attempt a delayed close of a nfsd_file
53965294c1fSJeff Layton  * @inode: inode of the file to attempt to remove
54065294c1fSJeff Layton  *
54165294c1fSJeff Layton  * Walk the whole hash bucket, looking for any files that correspond to "inode".
54265294c1fSJeff Layton  * If any do, then unhash them and put the hashtable reference to them and
54365294c1fSJeff Layton  * destroy any that had their last reference put.
54465294c1fSJeff Layton  */
54565294c1fSJeff Layton static void
54665294c1fSJeff Layton nfsd_file_close_inode(struct inode *inode)
54765294c1fSJeff Layton {
54865294c1fSJeff Layton 	unsigned int		hashval = (unsigned int)hash_long(inode->i_ino,
54965294c1fSJeff Layton 						NFSD_FILE_HASH_BITS);
55065294c1fSJeff Layton 	LIST_HEAD(dispose);
55165294c1fSJeff Layton 
55265294c1fSJeff Layton 	__nfsd_file_close_inode(inode, hashval, &dispose);
55365294c1fSJeff Layton 	trace_nfsd_file_close_inode(inode, hashval, !list_empty(&dispose));
5549542e6a6STrond Myklebust 	nfsd_file_dispose_list_delayed(&dispose);
55565294c1fSJeff Layton }
55665294c1fSJeff Layton 
55765294c1fSJeff Layton /**
55865294c1fSJeff Layton  * nfsd_file_delayed_close - close unused nfsd_files
55965294c1fSJeff Layton  * @work: dummy
56065294c1fSJeff Layton  *
56165294c1fSJeff Layton  * Walk the LRU list and close any entries that have not been used since
56265294c1fSJeff Layton  * the last scan.
56365294c1fSJeff Layton  *
56465294c1fSJeff Layton  * Note this can deadlock with nfsd_file_cache_purge.
56565294c1fSJeff Layton  */
56665294c1fSJeff Layton static void
56765294c1fSJeff Layton nfsd_file_delayed_close(struct work_struct *work)
56865294c1fSJeff Layton {
56965294c1fSJeff Layton 	LIST_HEAD(head);
5709542e6a6STrond Myklebust 	struct nfsd_fcache_disposal *l = container_of(work,
5719542e6a6STrond Myklebust 			struct nfsd_fcache_disposal, work);
57265294c1fSJeff Layton 
5739542e6a6STrond Myklebust 	nfsd_file_list_remove_disposal(&head, l);
5749542e6a6STrond Myklebust 	nfsd_file_dispose_list(&head);
57565294c1fSJeff Layton }
57665294c1fSJeff Layton 
57765294c1fSJeff Layton static int
57865294c1fSJeff Layton nfsd_file_lease_notifier_call(struct notifier_block *nb, unsigned long arg,
57965294c1fSJeff Layton 			    void *data)
58065294c1fSJeff Layton {
58165294c1fSJeff Layton 	struct file_lock *fl = data;
58265294c1fSJeff Layton 
58365294c1fSJeff Layton 	/* Only close files for F_SETLEASE leases */
58465294c1fSJeff Layton 	if (fl->fl_flags & FL_LEASE)
58565294c1fSJeff Layton 		nfsd_file_close_inode_sync(file_inode(fl->fl_file));
58665294c1fSJeff Layton 	return 0;
58765294c1fSJeff Layton }
58865294c1fSJeff Layton 
58965294c1fSJeff Layton static struct notifier_block nfsd_file_lease_notifier = {
59065294c1fSJeff Layton 	.notifier_call = nfsd_file_lease_notifier_call,
59165294c1fSJeff Layton };
59265294c1fSJeff Layton 
59365294c1fSJeff Layton static int
594b9a1b977SAmir Goldstein nfsd_file_fsnotify_handle_event(struct fsnotify_mark *mark, u32 mask,
595b9a1b977SAmir Goldstein 				struct inode *inode, struct inode *dir,
596950cc0d2SAmir Goldstein 				const struct qstr *name, u32 cookie)
59765294c1fSJeff Layton {
59824dca905SGabriel Krisman Bertazi 	if (WARN_ON_ONCE(!inode))
59924dca905SGabriel Krisman Bertazi 		return 0;
60024dca905SGabriel Krisman Bertazi 
60165294c1fSJeff Layton 	trace_nfsd_file_fsnotify_handle_event(inode, mask);
60265294c1fSJeff Layton 
60365294c1fSJeff Layton 	/* Should be no marks on non-regular files */
60465294c1fSJeff Layton 	if (!S_ISREG(inode->i_mode)) {
60565294c1fSJeff Layton 		WARN_ON_ONCE(1);
60665294c1fSJeff Layton 		return 0;
60765294c1fSJeff Layton 	}
60865294c1fSJeff Layton 
60965294c1fSJeff Layton 	/* don't close files if this was not the last link */
61065294c1fSJeff Layton 	if (mask & FS_ATTRIB) {
61165294c1fSJeff Layton 		if (inode->i_nlink)
61265294c1fSJeff Layton 			return 0;
61365294c1fSJeff Layton 	}
61465294c1fSJeff Layton 
61565294c1fSJeff Layton 	nfsd_file_close_inode(inode);
61665294c1fSJeff Layton 	return 0;
61765294c1fSJeff Layton }
61865294c1fSJeff Layton 
61965294c1fSJeff Layton 
62065294c1fSJeff Layton static const struct fsnotify_ops nfsd_file_fsnotify_ops = {
621b9a1b977SAmir Goldstein 	.handle_inode_event = nfsd_file_fsnotify_handle_event,
62265294c1fSJeff Layton 	.free_mark = nfsd_file_mark_free,
62365294c1fSJeff Layton };
62465294c1fSJeff Layton 
62565294c1fSJeff Layton int
62665294c1fSJeff Layton nfsd_file_cache_init(void)
62765294c1fSJeff Layton {
62865294c1fSJeff Layton 	int		ret = -ENOMEM;
62965294c1fSJeff Layton 	unsigned int	i;
63065294c1fSJeff Layton 
63165294c1fSJeff Layton 	clear_bit(NFSD_FILE_SHUTDOWN, &nfsd_file_lru_flags);
63265294c1fSJeff Layton 
63365294c1fSJeff Layton 	if (nfsd_file_hashtbl)
63465294c1fSJeff Layton 		return 0;
63565294c1fSJeff Layton 
6369542e6a6STrond Myklebust 	nfsd_filecache_wq = alloc_workqueue("nfsd_filecache", 0, 0);
6379542e6a6STrond Myklebust 	if (!nfsd_filecache_wq)
6389542e6a6STrond Myklebust 		goto out;
6399542e6a6STrond Myklebust 
6404d2eeafeSAmir Goldstein 	nfsd_file_hashtbl = kvcalloc(NFSD_FILE_HASH_SIZE,
64165294c1fSJeff Layton 				sizeof(*nfsd_file_hashtbl), GFP_KERNEL);
64265294c1fSJeff Layton 	if (!nfsd_file_hashtbl) {
64365294c1fSJeff Layton 		pr_err("nfsd: unable to allocate nfsd_file_hashtbl\n");
64465294c1fSJeff Layton 		goto out_err;
64565294c1fSJeff Layton 	}
64665294c1fSJeff Layton 
64765294c1fSJeff Layton 	nfsd_file_slab = kmem_cache_create("nfsd_file",
64865294c1fSJeff Layton 				sizeof(struct nfsd_file), 0, 0, NULL);
64965294c1fSJeff Layton 	if (!nfsd_file_slab) {
65065294c1fSJeff Layton 		pr_err("nfsd: unable to create nfsd_file_slab\n");
65165294c1fSJeff Layton 		goto out_err;
65265294c1fSJeff Layton 	}
65365294c1fSJeff Layton 
65465294c1fSJeff Layton 	nfsd_file_mark_slab = kmem_cache_create("nfsd_file_mark",
65565294c1fSJeff Layton 					sizeof(struct nfsd_file_mark), 0, 0, NULL);
65665294c1fSJeff Layton 	if (!nfsd_file_mark_slab) {
65765294c1fSJeff Layton 		pr_err("nfsd: unable to create nfsd_file_mark_slab\n");
65865294c1fSJeff Layton 		goto out_err;
65965294c1fSJeff Layton 	}
66065294c1fSJeff Layton 
66165294c1fSJeff Layton 
66265294c1fSJeff Layton 	ret = list_lru_init(&nfsd_file_lru);
66365294c1fSJeff Layton 	if (ret) {
66465294c1fSJeff Layton 		pr_err("nfsd: failed to init nfsd_file_lru: %d\n", ret);
66565294c1fSJeff Layton 		goto out_err;
66665294c1fSJeff Layton 	}
66765294c1fSJeff Layton 
66865294c1fSJeff Layton 	ret = register_shrinker(&nfsd_file_shrinker);
66965294c1fSJeff Layton 	if (ret) {
67065294c1fSJeff Layton 		pr_err("nfsd: failed to register nfsd_file_shrinker: %d\n", ret);
67165294c1fSJeff Layton 		goto out_lru;
67265294c1fSJeff Layton 	}
67365294c1fSJeff Layton 
67465294c1fSJeff Layton 	ret = lease_register_notifier(&nfsd_file_lease_notifier);
67565294c1fSJeff Layton 	if (ret) {
67665294c1fSJeff Layton 		pr_err("nfsd: unable to register lease notifier: %d\n", ret);
67765294c1fSJeff Layton 		goto out_shrinker;
67865294c1fSJeff Layton 	}
67965294c1fSJeff Layton 
680867a448dSAmir Goldstein 	nfsd_file_fsnotify_group = fsnotify_alloc_group(&nfsd_file_fsnotify_ops,
681b8962a9dSAmir Goldstein 							FSNOTIFY_GROUP_NOFS);
68265294c1fSJeff Layton 	if (IS_ERR(nfsd_file_fsnotify_group)) {
68365294c1fSJeff Layton 		pr_err("nfsd: unable to create fsnotify group: %ld\n",
68465294c1fSJeff Layton 			PTR_ERR(nfsd_file_fsnotify_group));
685231307dfSHuang Guobin 		ret = PTR_ERR(nfsd_file_fsnotify_group);
68665294c1fSJeff Layton 		nfsd_file_fsnotify_group = NULL;
68765294c1fSJeff Layton 		goto out_notifier;
68865294c1fSJeff Layton 	}
68965294c1fSJeff Layton 
69065294c1fSJeff Layton 	for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) {
69165294c1fSJeff Layton 		INIT_HLIST_HEAD(&nfsd_file_hashtbl[i].nfb_head);
69265294c1fSJeff Layton 		spin_lock_init(&nfsd_file_hashtbl[i].nfb_lock);
69365294c1fSJeff Layton 	}
69465294c1fSJeff Layton 
6959542e6a6STrond Myklebust 	INIT_DELAYED_WORK(&nfsd_filecache_laundrette, nfsd_file_gc_worker);
69665294c1fSJeff Layton out:
69765294c1fSJeff Layton 	return ret;
69865294c1fSJeff Layton out_notifier:
69965294c1fSJeff Layton 	lease_unregister_notifier(&nfsd_file_lease_notifier);
70065294c1fSJeff Layton out_shrinker:
70165294c1fSJeff Layton 	unregister_shrinker(&nfsd_file_shrinker);
70265294c1fSJeff Layton out_lru:
70365294c1fSJeff Layton 	list_lru_destroy(&nfsd_file_lru);
70465294c1fSJeff Layton out_err:
70565294c1fSJeff Layton 	kmem_cache_destroy(nfsd_file_slab);
70665294c1fSJeff Layton 	nfsd_file_slab = NULL;
70765294c1fSJeff Layton 	kmem_cache_destroy(nfsd_file_mark_slab);
70865294c1fSJeff Layton 	nfsd_file_mark_slab = NULL;
7094d2eeafeSAmir Goldstein 	kvfree(nfsd_file_hashtbl);
71065294c1fSJeff Layton 	nfsd_file_hashtbl = NULL;
7119542e6a6STrond Myklebust 	destroy_workqueue(nfsd_filecache_wq);
7129542e6a6STrond Myklebust 	nfsd_filecache_wq = NULL;
71365294c1fSJeff Layton 	goto out;
71465294c1fSJeff Layton }
71565294c1fSJeff Layton 
71665294c1fSJeff Layton /*
71765294c1fSJeff Layton  * Note this can deadlock with nfsd_file_lru_cb.
71865294c1fSJeff Layton  */
71965294c1fSJeff Layton void
7205e113224STrond Myklebust nfsd_file_cache_purge(struct net *net)
72165294c1fSJeff Layton {
72265294c1fSJeff Layton 	unsigned int		i;
72365294c1fSJeff Layton 	struct nfsd_file	*nf;
7245e113224STrond Myklebust 	struct hlist_node	*next;
72565294c1fSJeff Layton 	LIST_HEAD(dispose);
72665294c1fSJeff Layton 	bool del;
72765294c1fSJeff Layton 
72865294c1fSJeff Layton 	if (!nfsd_file_hashtbl)
72965294c1fSJeff Layton 		return;
73065294c1fSJeff Layton 
73165294c1fSJeff Layton 	for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) {
7325e113224STrond Myklebust 		struct nfsd_fcache_bucket *nfb = &nfsd_file_hashtbl[i];
7335e113224STrond Myklebust 
7345e113224STrond Myklebust 		spin_lock(&nfb->nfb_lock);
7355e113224STrond Myklebust 		hlist_for_each_entry_safe(nf, next, &nfb->nfb_head, nf_node) {
7365e113224STrond Myklebust 			if (net && nf->nf_net != net)
7375e113224STrond Myklebust 				continue;
73865294c1fSJeff Layton 			del = nfsd_file_unhash_and_release_locked(nf, &dispose);
73965294c1fSJeff Layton 
74065294c1fSJeff Layton 			/*
74165294c1fSJeff Layton 			 * Deadlock detected! Something marked this entry as
74265294c1fSJeff Layton 			 * unhased, but hasn't removed it from the hash list.
74365294c1fSJeff Layton 			 */
74465294c1fSJeff Layton 			WARN_ON_ONCE(!del);
74565294c1fSJeff Layton 		}
7465e113224STrond Myklebust 		spin_unlock(&nfb->nfb_lock);
74765294c1fSJeff Layton 		nfsd_file_dispose_list(&dispose);
74865294c1fSJeff Layton 	}
74965294c1fSJeff Layton }
75065294c1fSJeff Layton 
7519542e6a6STrond Myklebust static struct nfsd_fcache_disposal *
7521463b38eSNeilBrown nfsd_alloc_fcache_disposal(void)
7539542e6a6STrond Myklebust {
7549542e6a6STrond Myklebust 	struct nfsd_fcache_disposal *l;
7559542e6a6STrond Myklebust 
7569542e6a6STrond Myklebust 	l = kmalloc(sizeof(*l), GFP_KERNEL);
7579542e6a6STrond Myklebust 	if (!l)
7589542e6a6STrond Myklebust 		return NULL;
7599542e6a6STrond Myklebust 	INIT_WORK(&l->work, nfsd_file_delayed_close);
7609542e6a6STrond Myklebust 	spin_lock_init(&l->lock);
7619542e6a6STrond Myklebust 	INIT_LIST_HEAD(&l->freeme);
7629542e6a6STrond Myklebust 	return l;
7639542e6a6STrond Myklebust }
7649542e6a6STrond Myklebust 
7659542e6a6STrond Myklebust static void
7669542e6a6STrond Myklebust nfsd_free_fcache_disposal(struct nfsd_fcache_disposal *l)
7679542e6a6STrond Myklebust {
7689542e6a6STrond Myklebust 	cancel_work_sync(&l->work);
7699542e6a6STrond Myklebust 	nfsd_file_dispose_list(&l->freeme);
7701463b38eSNeilBrown 	kfree(l);
7719542e6a6STrond Myklebust }
7729542e6a6STrond Myklebust 
7739542e6a6STrond Myklebust static void
7749542e6a6STrond Myklebust nfsd_free_fcache_disposal_net(struct net *net)
7759542e6a6STrond Myklebust {
7761463b38eSNeilBrown 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
7771463b38eSNeilBrown 	struct nfsd_fcache_disposal *l = nn->fcache_disposal;
7789542e6a6STrond Myklebust 
7799542e6a6STrond Myklebust 	nfsd_free_fcache_disposal(l);
7809542e6a6STrond Myklebust }
7819542e6a6STrond Myklebust 
7829542e6a6STrond Myklebust int
7839542e6a6STrond Myklebust nfsd_file_cache_start_net(struct net *net)
7849542e6a6STrond Myklebust {
7851463b38eSNeilBrown 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
7861463b38eSNeilBrown 
7871463b38eSNeilBrown 	nn->fcache_disposal = nfsd_alloc_fcache_disposal();
7881463b38eSNeilBrown 	return nn->fcache_disposal ? 0 : -ENOMEM;
7899542e6a6STrond Myklebust }
7909542e6a6STrond Myklebust 
7919542e6a6STrond Myklebust void
7929542e6a6STrond Myklebust nfsd_file_cache_shutdown_net(struct net *net)
7939542e6a6STrond Myklebust {
7949542e6a6STrond Myklebust 	nfsd_file_cache_purge(net);
7959542e6a6STrond Myklebust 	nfsd_free_fcache_disposal_net(net);
7969542e6a6STrond Myklebust }
7979542e6a6STrond Myklebust 
79865294c1fSJeff Layton void
79965294c1fSJeff Layton nfsd_file_cache_shutdown(void)
80065294c1fSJeff Layton {
80165294c1fSJeff Layton 	set_bit(NFSD_FILE_SHUTDOWN, &nfsd_file_lru_flags);
80265294c1fSJeff Layton 
80365294c1fSJeff Layton 	lease_unregister_notifier(&nfsd_file_lease_notifier);
80465294c1fSJeff Layton 	unregister_shrinker(&nfsd_file_shrinker);
80565294c1fSJeff Layton 	/*
80665294c1fSJeff Layton 	 * make sure all callers of nfsd_file_lru_cb are done before
80765294c1fSJeff Layton 	 * calling nfsd_file_cache_purge
80865294c1fSJeff Layton 	 */
80965294c1fSJeff Layton 	cancel_delayed_work_sync(&nfsd_filecache_laundrette);
8105e113224STrond Myklebust 	nfsd_file_cache_purge(NULL);
81165294c1fSJeff Layton 	list_lru_destroy(&nfsd_file_lru);
81265294c1fSJeff Layton 	rcu_barrier();
81365294c1fSJeff Layton 	fsnotify_put_group(nfsd_file_fsnotify_group);
81465294c1fSJeff Layton 	nfsd_file_fsnotify_group = NULL;
81565294c1fSJeff Layton 	kmem_cache_destroy(nfsd_file_slab);
81665294c1fSJeff Layton 	nfsd_file_slab = NULL;
81765294c1fSJeff Layton 	fsnotify_wait_marks_destroyed();
81865294c1fSJeff Layton 	kmem_cache_destroy(nfsd_file_mark_slab);
81965294c1fSJeff Layton 	nfsd_file_mark_slab = NULL;
8204d2eeafeSAmir Goldstein 	kvfree(nfsd_file_hashtbl);
82165294c1fSJeff Layton 	nfsd_file_hashtbl = NULL;
8229542e6a6STrond Myklebust 	destroy_workqueue(nfsd_filecache_wq);
8239542e6a6STrond Myklebust 	nfsd_filecache_wq = NULL;
82465294c1fSJeff Layton }
82565294c1fSJeff Layton 
82665294c1fSJeff Layton static bool
82765294c1fSJeff Layton nfsd_match_cred(const struct cred *c1, const struct cred *c2)
82865294c1fSJeff Layton {
82965294c1fSJeff Layton 	int i;
83065294c1fSJeff Layton 
83165294c1fSJeff Layton 	if (!uid_eq(c1->fsuid, c2->fsuid))
83265294c1fSJeff Layton 		return false;
83365294c1fSJeff Layton 	if (!gid_eq(c1->fsgid, c2->fsgid))
83465294c1fSJeff Layton 		return false;
83565294c1fSJeff Layton 	if (c1->group_info == NULL || c2->group_info == NULL)
83665294c1fSJeff Layton 		return c1->group_info == c2->group_info;
83765294c1fSJeff Layton 	if (c1->group_info->ngroups != c2->group_info->ngroups)
83865294c1fSJeff Layton 		return false;
83965294c1fSJeff Layton 	for (i = 0; i < c1->group_info->ngroups; i++) {
84065294c1fSJeff Layton 		if (!gid_eq(c1->group_info->gid[i], c2->group_info->gid[i]))
84165294c1fSJeff Layton 			return false;
84265294c1fSJeff Layton 	}
84365294c1fSJeff Layton 	return true;
84465294c1fSJeff Layton }
84565294c1fSJeff Layton 
84665294c1fSJeff Layton static struct nfsd_file *
84765294c1fSJeff Layton nfsd_file_find_locked(struct inode *inode, unsigned int may_flags,
8485e113224STrond Myklebust 			unsigned int hashval, struct net *net)
84965294c1fSJeff Layton {
85065294c1fSJeff Layton 	struct nfsd_file *nf;
85165294c1fSJeff Layton 	unsigned char need = may_flags & NFSD_FILE_MAY_MASK;
85265294c1fSJeff Layton 
85365294c1fSJeff Layton 	hlist_for_each_entry_rcu(nf, &nfsd_file_hashtbl[hashval].nfb_head,
854057a2274SMadhuparna Bhowmik 				 nf_node, lockdep_is_held(&nfsd_file_hashtbl[hashval].nfb_lock)) {
855ae3c57b5SJ. Bruce Fields 		if (nf->nf_may != need)
85665294c1fSJeff Layton 			continue;
85765294c1fSJeff Layton 		if (nf->nf_inode != inode)
85865294c1fSJeff Layton 			continue;
8595e113224STrond Myklebust 		if (nf->nf_net != net)
8605e113224STrond Myklebust 			continue;
86165294c1fSJeff Layton 		if (!nfsd_match_cred(nf->nf_cred, current_cred()))
86265294c1fSJeff Layton 			continue;
863d30881f5STrond Myklebust 		if (!test_bit(NFSD_FILE_HASHED, &nf->nf_flags))
864d30881f5STrond Myklebust 			continue;
86565294c1fSJeff Layton 		if (nfsd_file_get(nf) != NULL)
86665294c1fSJeff Layton 			return nf;
86765294c1fSJeff Layton 	}
86865294c1fSJeff Layton 	return NULL;
86965294c1fSJeff Layton }
87065294c1fSJeff Layton 
87165294c1fSJeff Layton /**
87265294c1fSJeff Layton  * nfsd_file_is_cached - are there any cached open files for this fh?
87365294c1fSJeff Layton  * @inode: inode of the file to check
87465294c1fSJeff Layton  *
87565294c1fSJeff Layton  * Scan the hashtable for open files that match this fh. Returns true if there
87665294c1fSJeff Layton  * are any, and false if not.
87765294c1fSJeff Layton  */
87865294c1fSJeff Layton bool
87965294c1fSJeff Layton nfsd_file_is_cached(struct inode *inode)
88065294c1fSJeff Layton {
88165294c1fSJeff Layton 	bool			ret = false;
88265294c1fSJeff Layton 	struct nfsd_file	*nf;
88365294c1fSJeff Layton 	unsigned int		hashval;
88465294c1fSJeff Layton 
88565294c1fSJeff Layton         hashval = (unsigned int)hash_long(inode->i_ino, NFSD_FILE_HASH_BITS);
88665294c1fSJeff Layton 
88765294c1fSJeff Layton 	rcu_read_lock();
88865294c1fSJeff Layton 	hlist_for_each_entry_rcu(nf, &nfsd_file_hashtbl[hashval].nfb_head,
88965294c1fSJeff Layton 				 nf_node) {
89065294c1fSJeff Layton 		if (inode == nf->nf_inode) {
89165294c1fSJeff Layton 			ret = true;
89265294c1fSJeff Layton 			break;
89365294c1fSJeff Layton 		}
89465294c1fSJeff Layton 	}
89565294c1fSJeff Layton 	rcu_read_unlock();
89665294c1fSJeff Layton 	trace_nfsd_file_is_cached(inode, hashval, (int)ret);
89765294c1fSJeff Layton 	return ret;
89865294c1fSJeff Layton }
89965294c1fSJeff Layton 
900fb70bf12SChuck Lever static __be32
901fb70bf12SChuck Lever nfsd_do_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
902fb70bf12SChuck Lever 		     unsigned int may_flags, struct nfsd_file **pnf, bool open)
90365294c1fSJeff Layton {
90465294c1fSJeff Layton 	__be32	status;
9055e113224STrond Myklebust 	struct net *net = SVC_NET(rqstp);
90665294c1fSJeff Layton 	struct nfsd_file *nf, *new;
90765294c1fSJeff Layton 	struct inode *inode;
90865294c1fSJeff Layton 	unsigned int hashval;
90928c7d86bSTrond Myklebust 	bool retry = true;
91065294c1fSJeff Layton 
91165294c1fSJeff Layton 	/* FIXME: skip this if fh_dentry is already set? */
91265294c1fSJeff Layton 	status = fh_verify(rqstp, fhp, S_IFREG,
91365294c1fSJeff Layton 				may_flags|NFSD_MAY_OWNER_OVERRIDE);
91465294c1fSJeff Layton 	if (status != nfs_ok)
91565294c1fSJeff Layton 		return status;
91665294c1fSJeff Layton 
91765294c1fSJeff Layton 	inode = d_inode(fhp->fh_dentry);
91865294c1fSJeff Layton 	hashval = (unsigned int)hash_long(inode->i_ino, NFSD_FILE_HASH_BITS);
91965294c1fSJeff Layton retry:
92065294c1fSJeff Layton 	rcu_read_lock();
9215e113224STrond Myklebust 	nf = nfsd_file_find_locked(inode, may_flags, hashval, net);
92265294c1fSJeff Layton 	rcu_read_unlock();
92365294c1fSJeff Layton 	if (nf)
92465294c1fSJeff Layton 		goto wait_for_construction;
92565294c1fSJeff Layton 
9265e113224STrond Myklebust 	new = nfsd_file_alloc(inode, may_flags, hashval, net);
92765294c1fSJeff Layton 	if (!new) {
92865294c1fSJeff Layton 		trace_nfsd_file_acquire(rqstp, hashval, inode, may_flags,
92965294c1fSJeff Layton 					NULL, nfserr_jukebox);
93065294c1fSJeff Layton 		return nfserr_jukebox;
93165294c1fSJeff Layton 	}
93265294c1fSJeff Layton 
93365294c1fSJeff Layton 	spin_lock(&nfsd_file_hashtbl[hashval].nfb_lock);
9345e113224STrond Myklebust 	nf = nfsd_file_find_locked(inode, may_flags, hashval, net);
93565294c1fSJeff Layton 	if (nf == NULL)
93665294c1fSJeff Layton 		goto open_file;
93765294c1fSJeff Layton 	spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock);
93865294c1fSJeff Layton 	nfsd_file_slab_free(&new->nf_rcu);
93965294c1fSJeff Layton 
94065294c1fSJeff Layton wait_for_construction:
94165294c1fSJeff Layton 	wait_on_bit(&nf->nf_flags, NFSD_FILE_PENDING, TASK_UNINTERRUPTIBLE);
94265294c1fSJeff Layton 
94365294c1fSJeff Layton 	/* Did construction of this file fail? */
94465294c1fSJeff Layton 	if (!test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) {
94528c7d86bSTrond Myklebust 		if (!retry) {
94628c7d86bSTrond Myklebust 			status = nfserr_jukebox;
94728c7d86bSTrond Myklebust 			goto out;
94828c7d86bSTrond Myklebust 		}
94928c7d86bSTrond Myklebust 		retry = false;
95065294c1fSJeff Layton 		nfsd_file_put_noref(nf);
95165294c1fSJeff Layton 		goto retry;
95265294c1fSJeff Layton 	}
95365294c1fSJeff Layton 
95465294c1fSJeff Layton 	this_cpu_inc(nfsd_file_cache_hits);
95565294c1fSJeff Layton 
95623ba98deSJeff Layton 	status = nfserrno(nfsd_open_break_lease(file_inode(nf->nf_file), may_flags));
95765294c1fSJeff Layton out:
95865294c1fSJeff Layton 	if (status == nfs_ok) {
959*29d4bdbbSChuck Lever 		if (open)
960*29d4bdbbSChuck Lever 			this_cpu_inc(nfsd_file_acquisitions);
96165294c1fSJeff Layton 		*pnf = nf;
96265294c1fSJeff Layton 	} else {
96365294c1fSJeff Layton 		nfsd_file_put(nf);
96465294c1fSJeff Layton 		nf = NULL;
96565294c1fSJeff Layton 	}
96665294c1fSJeff Layton 
96765294c1fSJeff Layton 	trace_nfsd_file_acquire(rqstp, hashval, inode, may_flags, nf, status);
96865294c1fSJeff Layton 	return status;
96965294c1fSJeff Layton open_file:
97065294c1fSJeff Layton 	nf = new;
97165294c1fSJeff Layton 	/* Take reference for the hashtable */
972689827cdSTrond Myklebust 	refcount_inc(&nf->nf_ref);
97365294c1fSJeff Layton 	__set_bit(NFSD_FILE_HASHED, &nf->nf_flags);
97465294c1fSJeff Layton 	__set_bit(NFSD_FILE_PENDING, &nf->nf_flags);
97565294c1fSJeff Layton 	list_lru_add(&nfsd_file_lru, &nf->nf_lru);
97665294c1fSJeff Layton 	hlist_add_head_rcu(&nf->nf_node, &nfsd_file_hashtbl[hashval].nfb_head);
97765294c1fSJeff Layton 	++nfsd_file_hashtbl[hashval].nfb_count;
97865294c1fSJeff Layton 	nfsd_file_hashtbl[hashval].nfb_maxcount = max(nfsd_file_hashtbl[hashval].nfb_maxcount,
97965294c1fSJeff Layton 			nfsd_file_hashtbl[hashval].nfb_count);
98065294c1fSJeff Layton 	spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock);
9819542e6a6STrond Myklebust 	if (atomic_long_inc_return(&nfsd_filecache_count) >= NFSD_FILE_LRU_THRESHOLD)
9829542e6a6STrond Myklebust 		nfsd_file_gc();
98365294c1fSJeff Layton 
98465294c1fSJeff Layton 	nf->nf_mark = nfsd_file_mark_find_or_create(nf);
985fb70bf12SChuck Lever 	if (nf->nf_mark) {
9860122e882SChuck Lever 		if (open) {
987f4d84c52SChuck Lever 			status = nfsd_open_verified(rqstp, fhp, may_flags,
988f4d84c52SChuck Lever 						    &nf->nf_file);
9890122e882SChuck Lever 			trace_nfsd_file_open(nf, status);
9900122e882SChuck Lever 		} else
991fb70bf12SChuck Lever 			status = nfs_ok;
992fb70bf12SChuck Lever 	} else
99365294c1fSJeff Layton 		status = nfserr_jukebox;
99465294c1fSJeff Layton 	/*
99565294c1fSJeff Layton 	 * If construction failed, or we raced with a call to unlink()
99665294c1fSJeff Layton 	 * then unhash.
99765294c1fSJeff Layton 	 */
99865294c1fSJeff Layton 	if (status != nfs_ok || inode->i_nlink == 0) {
99965294c1fSJeff Layton 		bool do_free;
100065294c1fSJeff Layton 		spin_lock(&nfsd_file_hashtbl[hashval].nfb_lock);
100165294c1fSJeff Layton 		do_free = nfsd_file_unhash(nf);
100265294c1fSJeff Layton 		spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock);
100365294c1fSJeff Layton 		if (do_free)
100465294c1fSJeff Layton 			nfsd_file_put_noref(nf);
100565294c1fSJeff Layton 	}
100665294c1fSJeff Layton 	clear_bit_unlock(NFSD_FILE_PENDING, &nf->nf_flags);
100765294c1fSJeff Layton 	smp_mb__after_atomic();
100865294c1fSJeff Layton 	wake_up_bit(&nf->nf_flags, NFSD_FILE_PENDING);
100965294c1fSJeff Layton 	goto out;
101065294c1fSJeff Layton }
101165294c1fSJeff Layton 
1012fb70bf12SChuck Lever /**
1013fb70bf12SChuck Lever  * nfsd_file_acquire - Get a struct nfsd_file with an open file
1014fb70bf12SChuck Lever  * @rqstp: the RPC transaction being executed
1015fb70bf12SChuck Lever  * @fhp: the NFS filehandle of the file to be opened
1016fb70bf12SChuck Lever  * @may_flags: NFSD_MAY_ settings for the file
1017fb70bf12SChuck Lever  * @pnf: OUT: new or found "struct nfsd_file" object
1018fb70bf12SChuck Lever  *
1019fb70bf12SChuck Lever  * Returns nfs_ok and sets @pnf on success; otherwise an nfsstat in
1020fb70bf12SChuck Lever  * network byte order is returned.
1021fb70bf12SChuck Lever  */
1022fb70bf12SChuck Lever __be32
1023fb70bf12SChuck Lever nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
1024fb70bf12SChuck Lever 		  unsigned int may_flags, struct nfsd_file **pnf)
1025fb70bf12SChuck Lever {
1026fb70bf12SChuck Lever 	return nfsd_do_file_acquire(rqstp, fhp, may_flags, pnf, true);
1027fb70bf12SChuck Lever }
1028fb70bf12SChuck Lever 
1029fb70bf12SChuck Lever /**
1030fb70bf12SChuck Lever  * nfsd_file_create - Get a struct nfsd_file, do not open
1031fb70bf12SChuck Lever  * @rqstp: the RPC transaction being executed
1032fb70bf12SChuck Lever  * @fhp: the NFS filehandle of the file just created
1033fb70bf12SChuck Lever  * @may_flags: NFSD_MAY_ settings for the file
1034fb70bf12SChuck Lever  * @pnf: OUT: new or found "struct nfsd_file" object
1035fb70bf12SChuck Lever  *
1036fb70bf12SChuck Lever  * Returns nfs_ok and sets @pnf on success; otherwise an nfsstat in
1037fb70bf12SChuck Lever  * network byte order is returned.
1038fb70bf12SChuck Lever  */
1039fb70bf12SChuck Lever __be32
1040fb70bf12SChuck Lever nfsd_file_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
1041fb70bf12SChuck Lever 		 unsigned int may_flags, struct nfsd_file **pnf)
1042fb70bf12SChuck Lever {
1043fb70bf12SChuck Lever 	return nfsd_do_file_acquire(rqstp, fhp, may_flags, pnf, false);
1044fb70bf12SChuck Lever }
1045fb70bf12SChuck Lever 
104665294c1fSJeff Layton /*
104765294c1fSJeff Layton  * Note that fields may be added, removed or reordered in the future. Programs
104865294c1fSJeff Layton  * scraping this file for info should test the labels to ensure they're
104965294c1fSJeff Layton  * getting the correct field.
105065294c1fSJeff Layton  */
105165294c1fSJeff Layton static int nfsd_file_cache_stats_show(struct seq_file *m, void *v)
105265294c1fSJeff Layton {
1053*29d4bdbbSChuck Lever 	unsigned long hits = 0, acquisitions = 0;
105465294c1fSJeff Layton 	unsigned int i, count = 0, longest = 0;
1055*29d4bdbbSChuck Lever 	unsigned long lru = 0;
105665294c1fSJeff Layton 
105765294c1fSJeff Layton 	/*
105865294c1fSJeff Layton 	 * No need for spinlocks here since we're not terribly interested in
105965294c1fSJeff Layton 	 * accuracy. We do take the nfsd_mutex simply to ensure that we
106065294c1fSJeff Layton 	 * don't end up racing with server shutdown
106165294c1fSJeff Layton 	 */
106265294c1fSJeff Layton 	mutex_lock(&nfsd_mutex);
106365294c1fSJeff Layton 	if (nfsd_file_hashtbl) {
106465294c1fSJeff Layton 		for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) {
106565294c1fSJeff Layton 			count += nfsd_file_hashtbl[i].nfb_count;
106665294c1fSJeff Layton 			longest = max(longest, nfsd_file_hashtbl[i].nfb_count);
106765294c1fSJeff Layton 		}
10680fd244c1SChuck Lever 		lru = list_lru_count(&nfsd_file_lru);
106965294c1fSJeff Layton 	}
107065294c1fSJeff Layton 	mutex_unlock(&nfsd_mutex);
107165294c1fSJeff Layton 
1072*29d4bdbbSChuck Lever 	for_each_possible_cpu(i) {
107365294c1fSJeff Layton 		hits += per_cpu(nfsd_file_cache_hits, i);
1074*29d4bdbbSChuck Lever 		acquisitions += per_cpu(nfsd_file_acquisitions, i);
1075*29d4bdbbSChuck Lever 	}
107665294c1fSJeff Layton 
107765294c1fSJeff Layton 	seq_printf(m, "total entries: %u\n", count);
107865294c1fSJeff Layton 	seq_printf(m, "longest chain: %u\n", longest);
10790fd244c1SChuck Lever 	seq_printf(m, "lru entries:   %lu\n", lru);
108065294c1fSJeff Layton 	seq_printf(m, "cache hits:    %lu\n", hits);
1081*29d4bdbbSChuck Lever 	seq_printf(m, "acquisitions:  %lu\n", acquisitions);
108265294c1fSJeff Layton 	return 0;
108365294c1fSJeff Layton }
108465294c1fSJeff Layton 
108565294c1fSJeff Layton int nfsd_file_cache_stats_open(struct inode *inode, struct file *file)
108665294c1fSJeff Layton {
108765294c1fSJeff Layton 	return single_open(file, nfsd_file_cache_stats_show, NULL);
108865294c1fSJeff Layton }
1089