History

Merge tag 'nfsd-5.4' of git://linux-nfs.org/~bfields/linux

Pull nfsd updates from Bruce Fields: "Highlights: - Add a new knfsd file cache, so that we don't have to open and close on each (NFSv2/v3) READ or WRITE. This can speed up read and write in some cases. It also replaces our readahead cache. - Prevent silent data loss on write errors, by treating write errors like server reboots for the purposes of write caching, thus forcing clients to resend their writes. - Tweak the code that allocates sessions to be more forgiving, so that NFSv4.1 mounts are less likely to hang when a server already has a lot of clients. - Eliminate an arbitrary limit on NFSv4 ACL sizes; they should now be limited only by the backend filesystem and the maximum RPC size. - Allow the server to enforce use of the correct kerberos credentials when a client reclaims state after a reboot. And some miscellaneous smaller bugfixes and cleanup" * tag 'nfsd-5.4' of git://linux-nfs.org/~bfields/linux: (34 commits) sunrpc: clean up indentation issue nfsd: fix nfs read eof detection nfsd: Make nfsd_reset_boot_verifier_locked static nfsd: degraded slot-count more gracefully as allocation nears exhaustion. nfsd: handle drc over-allocation gracefully. nfsd: add support for upcall version 2 nfsd: add a "GetVersion" upcall for nfsdcld nfsd: Reset the boot verifier on all write I/O errors nfsd: Don't garbage collect files that might contain write errors nfsd: Support the server resetting the boot verifier nfsd: nfsd_file cache entries should be per net namespace nfsd: eliminate an unnecessary acl size limit Deprecate nfsd fault injection nfsd: remove duplicated include from filecache.c nfsd: Fix the documentation for svcxdr_tmpalloc() nfsd: Fix up some unused variable warnings nfsd: close cached files prior to a REMOVE or RENAME that would replace target nfsd: rip out the raparms cache nfsd: have nfsd_test_lock use the nfsd_file cache nfsd: hook up nfs4_preprocess_stateid_op to the nfsd_file cache ...

Linus Torvalds committed 7 years ago

Commit 298fb762 parents 8f744bd e41f9ef40 files · +2083 −600Browse files

Unified · Split

40 files
  1. fs/file_table.c +1 −0
  2. fs/locks.c +62 −0
  3. fs/nfsd/Kconfig +2 −1
  4. fs/nfsd/Makefile +2 −1
  5. fs/nfsd/acl.h +0 −8
  6. fs/nfsd/blocklayout.c +2 −1
  7. fs/nfsd/export.c +13 −0
  8. fs/nfsd/filecache.c +934 −0
  9. fs/nfsd/filecache.h +61 −0
  10. fs/nfsd/netns.h +4 −0
  11. fs/nfsd/nfs3proc.c +2 −7
  12. fs/nfsd/nfs3xdr.c +9 −4
  13. fs/nfsd/nfs4callback.c +15 −20
  14. fs/nfsd/nfs4layouts.c +6 −6
  15. fs/nfsd/nfs4proc.c +46 −51
  16. fs/nfsd/nfs4recover.c +325 −63
  17. fs/nfsd/nfs4state.c +130 −109
  18. fs/nfsd/nfs4xdr.c +29 −27
  19. fs/nfsd/nfsctl.c +1 −0
  20. fs/nfsd/nfsproc.c +3 −1
  21. fs/nfsd/nfssvc.c +37 −11
  22. fs/nfsd/state.h +7 −6
  23. fs/nfsd/trace.h +140 −0
  24. fs/nfsd/vfs.c +146 −205
  25. fs/nfsd/vfs.h +9 −28
  26. fs/nfsd/xdr3.h +1 −1
  27. fs/nfsd/xdr4.h +9 −10
  28. fs/notify/fsnotify.h +0 −2
  29. fs/notify/group.c +2 −0
  30. fs/notify/mark.c +6 −0
  31. include/linux/fs.h +5 −0
  32. include/linux/fsnotify_backend.h +2 −0
  33. include/linux/sunrpc/cache.h +4 −3
  34. include/linux/sunrpc/svc_rdma.h +3 −3
  35. include/uapi/linux/nfsd/cld.h +39 −2
  36. net/sunrpc/cache.c +11 −4
  37. net/sunrpc/svc.c +2 −2
  38. net/sunrpc/xprtrdma/svc_rdma.c +0 −7
  39. net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +10 −14
  40. net/sunrpc/xprtrdma/svc_rdma_transport.c +3 −3
fs/file_table.c+1−0
@@ -327,6 +327,7 @@ void flush_delayed_fput(void) · 326 unmodified lines
327327 {
328328 delayed_fput(NULL);
329329 }
330+EXPORT_SYMBOL_GPL(flush_delayed_fput);
330331
331332 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
332333
fs/locks.c+62−0
@@ -212,6 +212,7 @@ struct file_lock_list_struct { · 211 unmodified lines
212212 static DEFINE_PER_CPU(struct file_lock_list_struct, file_lock_list);
213213 DEFINE_STATIC_PERCPU_RWSEM(file_rwsem);
214214
215+
215216 /*
216217 * The blocked_hash is used to find POSIX lock loops for deadlock detection.
217218 * It is protected by blocked_lock_lock.
@@ -1991,6 +1992,64 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp, · 1773 unmodified lines
19911992 }
19921993 EXPORT_SYMBOL(generic_setlease);
19931994
1995+#if IS_ENABLED(CONFIG_SRCU)
1996+/*
1997+ * Kernel subsystems can register to be notified on any attempt to set
1998+ * a new lease with the lease_notifier_chain. This is used by (e.g.) nfsd
1999+ * to close files that it may have cached when there is an attempt to set a
2000+ * conflicting lease.
2001+ */
2002+static struct srcu_notifier_head lease_notifier_chain;
2003+
2004+static inline void
2005+lease_notifier_chain_init(void)
2006+{
2007+ srcu_init_notifier_head(&lease_notifier_chain);
2008+}
2009+
2010+static inline void
2011+setlease_notifier(long arg, struct file_lock *lease)
2012+{
2013+ if (arg != F_UNLCK)
2014+ srcu_notifier_call_chain(&lease_notifier_chain, arg, lease);
2015+}
2016+
2017+int lease_register_notifier(struct notifier_block *nb)
2018+{
2019+ return srcu_notifier_chain_register(&lease_notifier_chain, nb);
2020+}
2021+EXPORT_SYMBOL_GPL(lease_register_notifier);
2022+
2023+void lease_unregister_notifier(struct notifier_block *nb)
2024+{
2025+ srcu_notifier_chain_unregister(&lease_notifier_chain, nb);
2026+}
2027+EXPORT_SYMBOL_GPL(lease_unregister_notifier);
2028+
2029+#else /* !IS_ENABLED(CONFIG_SRCU) */
2030+static inline void
2031+lease_notifier_chain_init(void)
2032+{
2033+}
2034+
2035+static inline void
2036+setlease_notifier(long arg, struct file_lock *lease)
2037+{
2038+}
2039+
2040+int lease_register_notifier(struct notifier_block *nb)
2041+{
2042+ return 0;
2043+}
2044+EXPORT_SYMBOL_GPL(lease_register_notifier);
2045+
2046+void lease_unregister_notifier(struct notifier_block *nb)
2047+{
2048+}
2049+EXPORT_SYMBOL_GPL(lease_unregister_notifier);
2050+
2051+#endif /* IS_ENABLED(CONFIG_SRCU) */
2052+
19942053 /**
19952054 * vfs_setlease - sets a lease on an open file
19962055 * @filp: file pointer
@@ -2011,6 +2070,8 @@ EXPORT_SYMBOL(generic_setlease); · 14 unmodified lines
20112070 int
20122071 vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **priv)
20132072 {
2073+ if (lease)
2074+ setlease_notifier(arg, *lease);
20142075 if (filp->f_op->setlease)
20152076 return filp->f_op->setlease(filp, arg, lease, priv);
20162077 else
@@ -2924,6 +2985,7 @@ static int __init filelock_init(void) · 907 unmodified lines
29242985 INIT_HLIST_HEAD(&fll->hlist);
29252986 }
29262987
2988+ lease_notifier_chain_init();
29272989 return 0;
29282990 }
29292991 core_initcall(filelock_init);
fs/nfsd/Kconfig+2−1
@@ -3,6 +3,7 @@ config NFSD · 2 unmodified lines
33 tristate "NFS server support"
44 depends on INET
55 depends on FILE_LOCKING
6+ depends on FSNOTIFY
67 select LOCKD
78 select SUNRPC
89 select EXPORTFS
@@ -147,7 +148,7 @@ config NFSD_V4_SECURITY_LABEL · 138 unmodified lines
147148
148149 config NFSD_FAULT_INJECTION
149150 bool "NFS server manual fault injection"
150− depends on NFSD_V4 && DEBUG_KERNEL && DEBUG_FS
151+ depends on NFSD_V4 && DEBUG_KERNEL && DEBUG_FS && BROKEN
151152 help
152153 This option enables support for manually injecting faults
153154 into the NFS server. This is intended to be used for
fs/nfsd/Makefile+2−1
@@ -11,7 +11,8 @@ obj-$(CONFIG_NFSD) += nfsd.o · 10 unmodified lines
1111 nfsd-y += trace.o
1212
1313 nfsd-y += nfssvc.o nfsctl.o nfsproc.o nfsfh.o vfs.o \
14− export.o auth.o lockd.o nfscache.o nfsxdr.o stats.o
14+ export.o auth.o lockd.o nfscache.o nfsxdr.o \
15+ stats.o filecache.o
1516 nfsd-$(CONFIG_NFSD_FAULT_INJECTION) += fault_inject.o
1617 nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o
1718 nfsd-$(CONFIG_NFSD_V3) += nfs3proc.o nfs3xdr.o
fs/nfsd/acl.h+0−8
@@ -39,14 +39,6 @@ struct nfs4_acl; · 38 unmodified lines
3939 struct svc_fh;
4040 struct svc_rqst;
4141
42−/*
43− * Maximum ACL we'll accept from a client; chosen (somewhat
44− * arbitrarily) so that kmalloc'ing the ACL shouldn't require a
45− * high-order allocation. This allows 204 ACEs on x86_64:
46− */
47−#define NFS4_ACL_MAX ((PAGE_SIZE - sizeof(struct nfs4_acl)) \
48− / sizeof(struct nfs4_ace))
49−
5042 int nfs4_acl_bytes(int entries);
5143 int nfs4_acl_get_whotype(char *, u32);
5244 __be32 nfs4_acl_write_who(struct xdr_stream *xdr, int who);
fs/nfsd/blocklayout.c+2−1
@@ -15,6 +15,7 @@ · 14 unmodified lines
1515
1616 #include "blocklayoutxdr.h"
1717 #include "pnfs.h"
18+#include "filecache.h"
1819
1920 #define NFSDDBG_FACILITY NFSDDBG_PNFS
2021
@@ -404,7 +405,7 @@ static void · 383 unmodified lines
404405 nfsd4_scsi_fence_client(struct nfs4_layout_stateid *ls)
405406 {
406407 struct nfs4_client *clp = ls->ls_stid.sc_client;
407− struct block_device *bdev = ls->ls_file->f_path.mnt->mnt_sb->s_bdev;
408+ struct block_device *bdev = ls->ls_file->nf_file->f_path.mnt->mnt_sb->s_bdev;
408409
409410 bdev->bd_disk->fops->pr_ops->pr_preempt(bdev, NFSD_MDS_PR_KEY,
410411 nfsd4_scsi_pr_key(clp), 0, true);
fs/nfsd/export.c+13−0
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #include "nfsfh.h"
2323 #include "netns.h"
2424 #include "pnfs.h"
25+#include "filecache.h"
2526
2627 #define NFSDDBG_FACILITY NFSDDBG_EXPORT
2728
@@ -232,6 +233,17 @@ static struct cache_head *expkey_alloc(void) · 204 unmodified lines
232233 return NULL;
233234 }
234235
236+static void expkey_flush(void)
237+{
238+ /*
239+ * Take the nfsd_mutex here to ensure that the file cache is not
240+ * destroyed while we're in the middle of flushing.
241+ */
242+ mutex_lock(&nfsd_mutex);
243+ nfsd_file_cache_purge(current->nsproxy->net_ns);
244+ mutex_unlock(&nfsd_mutex);
245+}
246+
235247 static const struct cache_detail svc_expkey_cache_template = {
236248 .owner = THIS_MODULE,
237249 .hash_size = EXPKEY_HASHMAX,
@@ -244,6 +256,7 @@ static const struct cache_detail svc_expkey_cache_template = { · 6 unmodified lines
244256 .init = expkey_init,
245257 .update = expkey_update,
246258 .alloc = expkey_alloc,
259+ .flush = expkey_flush,
247260 };
248261
249262 static int
fs/nfsd/filecache.c+934−0
@@ -0,0 +1,934 @@
1+/*
2+ * Open file cache.
3+ *
4+ * (c) 2015 - Jeff Layton <jeff.layton@primarydata.com>
5+ */
6+
7+#include <linux/hash.h>
8+#include <linux/slab.h>
9+#include <linux/file.h>
10+#include <linux/sched.h>
11+#include <linux/list_lru.h>
12+#include <linux/fsnotify_backend.h>
13+#include <linux/fsnotify.h>
14+#include <linux/seq_file.h>
15+
16+#include "vfs.h"
17+#include "nfsd.h"
18+#include "nfsfh.h"
19+#include "netns.h"
20+#include "filecache.h"
21+#include "trace.h"
22+
23+#define NFSDDBG_FACILITY NFSDDBG_FH
24+
25+/* FIXME: dynamically size this for the machine somehow? */
26+#define NFSD_FILE_HASH_BITS 12
27+#define NFSD_FILE_HASH_SIZE (1 << NFSD_FILE_HASH_BITS)
28+#define NFSD_LAUNDRETTE_DELAY (2 * HZ)
29+
30+#define NFSD_FILE_LRU_RESCAN (0)
31+#define NFSD_FILE_SHUTDOWN (1)
32+#define NFSD_FILE_LRU_THRESHOLD (4096UL)
33+#define NFSD_FILE_LRU_LIMIT (NFSD_FILE_LRU_THRESHOLD << 2)
34+
35+/* We only care about NFSD_MAY_READ/WRITE for this cache */
36+#define NFSD_FILE_MAY_MASK (NFSD_MAY_READ|NFSD_MAY_WRITE)
37+
38+struct nfsd_fcache_bucket {
39+ struct hlist_head nfb_head;
40+ spinlock_t nfb_lock;
41+ unsigned int nfb_count;
42+ unsigned int nfb_maxcount;
43+};
44+
45+static DEFINE_PER_CPU(unsigned long, nfsd_file_cache_hits);
46+
47+static struct kmem_cache *nfsd_file_slab;
48+static struct kmem_cache *nfsd_file_mark_slab;
49+static struct nfsd_fcache_bucket *nfsd_file_hashtbl;
50+static struct list_lru nfsd_file_lru;
51+static long nfsd_file_lru_flags;
52+static struct fsnotify_group *nfsd_file_fsnotify_group;
53+static atomic_long_t nfsd_filecache_count;
54+static struct delayed_work nfsd_filecache_laundrette;
55+
56+enum nfsd_file_laundrette_ctl {
57+ NFSD_FILE_LAUNDRETTE_NOFLUSH = 0,
58+ NFSD_FILE_LAUNDRETTE_MAY_FLUSH
59+};
60+
61+static void
62+nfsd_file_schedule_laundrette(enum nfsd_file_laundrette_ctl ctl)
63+{
64+ long count = atomic_long_read(&nfsd_filecache_count);
65+
66+ if (count == 0 || test_bit(NFSD_FILE_SHUTDOWN, &nfsd_file_lru_flags))
67+ return;
68+
69+ /* Be more aggressive about scanning if over the threshold */
70+ if (count > NFSD_FILE_LRU_THRESHOLD)
71+ mod_delayed_work(system_wq, &nfsd_filecache_laundrette, 0);
72+ else
73+ schedule_delayed_work(&nfsd_filecache_laundrette, NFSD_LAUNDRETTE_DELAY);
74+
75+ if (ctl == NFSD_FILE_LAUNDRETTE_NOFLUSH)
76+ return;
77+
78+ /* ...and don't delay flushing if we're out of control */
79+ if (count >= NFSD_FILE_LRU_LIMIT)
80+ flush_delayed_work(&nfsd_filecache_laundrette);
81+}
82+
83+static void
84+nfsd_file_slab_free(struct rcu_head *rcu)
85+{
86+ struct nfsd_file *nf = container_of(rcu, struct nfsd_file, nf_rcu);
87+
88+ put_cred(nf->nf_cred);
89+ kmem_cache_free(nfsd_file_slab, nf);
90+}
91+
92+static void
93+nfsd_file_mark_free(struct fsnotify_mark *mark)
94+{
95+ struct nfsd_file_mark *nfm = container_of(mark, struct nfsd_file_mark,
96+ nfm_mark);
97+
98+ kmem_cache_free(nfsd_file_mark_slab, nfm);
99+}
100+
101+static struct nfsd_file_mark *
102+nfsd_file_mark_get(struct nfsd_file_mark *nfm)
103+{
104+ if (!atomic_inc_not_zero(&nfm->nfm_ref))
105+ return NULL;
106+ return nfm;
107+}
108+
109+static void
110+nfsd_file_mark_put(struct nfsd_file_mark *nfm)
111+{
112+ if (atomic_dec_and_test(&nfm->nfm_ref)) {
113+
114+ fsnotify_destroy_mark(&nfm->nfm_mark, nfsd_file_fsnotify_group);
115+ fsnotify_put_mark(&nfm->nfm_mark);
116+ }
117+}
118+
119+static struct nfsd_file_mark *
120+nfsd_file_mark_find_or_create(struct nfsd_file *nf)
121+{
122+ int err;
123+ struct fsnotify_mark *mark;
124+ struct nfsd_file_mark *nfm = NULL, *new;
125+ struct inode *inode = nf->nf_inode;
126+
127+ do {
128+ mutex_lock(&nfsd_file_fsnotify_group->mark_mutex);
129+ mark = fsnotify_find_mark(&inode->i_fsnotify_marks,
130+ nfsd_file_fsnotify_group);
131+ if (mark) {
132+ nfm = nfsd_file_mark_get(container_of(mark,
133+ struct nfsd_file_mark,
134+ nfm_mark));
135+ mutex_unlock(&nfsd_file_fsnotify_group->mark_mutex);
136+ fsnotify_put_mark(mark);
137+ if (likely(nfm))
138+ break;
139+ } else
140+ mutex_unlock(&nfsd_file_fsnotify_group->mark_mutex);
141+
142+ /* allocate a new nfm */
143+ new = kmem_cache_alloc(nfsd_file_mark_slab, GFP_KERNEL);
144+ if (!new)
145+ return NULL;
146+ fsnotify_init_mark(&new->nfm_mark, nfsd_file_fsnotify_group);
147+ new->nfm_mark.mask = FS_ATTRIB|FS_DELETE_SELF;
148+ atomic_set(&new->nfm_ref, 1);
149+
150+ err = fsnotify_add_inode_mark(&new->nfm_mark, inode, 0);
151+
152+ /*
153+ * If the add was successful, then return the object.
154+ * Otherwise, we need to put the reference we hold on the
155+ * nfm_mark. The fsnotify code will take a reference and put
156+ * it on failure, so we can't just free it directly. It's also
157+ * not safe to call fsnotify_destroy_mark on it as the
158+ * mark->group will be NULL. Thus, we can't let the nfm_ref
159+ * counter drive the destruction at this point.
160+ */
161+ if (likely(!err))
162+ nfm = new;
163+ else
164+ fsnotify_put_mark(&new->nfm_mark);
165+ } while (unlikely(err == -EEXIST));
166+
167+ return nfm;
168+}
169+
170+static struct nfsd_file *
171+nfsd_file_alloc(struct inode *inode, unsigned int may, unsigned int hashval,
172+ struct net *net)
173+{
174+ struct nfsd_file *nf;
175+
176+ nf = kmem_cache_alloc(nfsd_file_slab, GFP_KERNEL);
177+ if (nf) {
178+ INIT_HLIST_NODE(&nf->nf_node);
179+ INIT_LIST_HEAD(&nf->nf_lru);
180+ nf->nf_file = NULL;
181+ nf->nf_cred = get_current_cred();
182+ nf->nf_net = net;
183+ nf->nf_flags = 0;
184+ nf->nf_inode = inode;
185+ nf->nf_hashval = hashval;
186+ atomic_set(&nf->nf_ref, 1);
187+ nf->nf_may = may & NFSD_FILE_MAY_MASK;
188+ if (may & NFSD_MAY_NOT_BREAK_LEASE) {
189+ if (may & NFSD_MAY_WRITE)
190+ __set_bit(NFSD_FILE_BREAK_WRITE, &nf->nf_flags);
191+ if (may & NFSD_MAY_READ)
192+ __set_bit(NFSD_FILE_BREAK_READ, &nf->nf_flags);
193+ }
194+ nf->nf_mark = NULL;
195+ trace_nfsd_file_alloc(nf);
196+ }
197+ return nf;
198+}
199+
200+static bool
201+nfsd_file_free(struct nfsd_file *nf)
202+{
203+ bool flush = false;
204+
205+ trace_nfsd_file_put_final(nf);
206+ if (nf->nf_mark)
207+ nfsd_file_mark_put(nf->nf_mark);
208+ if (nf->nf_file) {
209+ get_file(nf->nf_file);
210+ filp_close(nf->nf_file, NULL);
211+ fput(nf->nf_file);
212+ flush = true;
213+ }
214+ call_rcu(&nf->nf_rcu, nfsd_file_slab_free);
215+ return flush;
216+}
217+
218+static bool
219+nfsd_file_check_writeback(struct nfsd_file *nf)
220+{
221+ struct file *file = nf->nf_file;
222+ struct address_space *mapping;
223+
224+ if (!file || !(file->f_mode & FMODE_WRITE))
225+ return false;
226+ mapping = file->f_mapping;
227+ return mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) ||
228+ mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK);
229+}
230+
231+static int
232+nfsd_file_check_write_error(struct nfsd_file *nf)
233+{
234+ struct file *file = nf->nf_file;
235+
236+ if (!file || !(file->f_mode & FMODE_WRITE))
237+ return 0;
238+ return filemap_check_wb_err(file->f_mapping, READ_ONCE(file->f_wb_err));
239+}
240+
241+static bool
242+nfsd_file_in_use(struct nfsd_file *nf)
243+{
244+ return nfsd_file_check_writeback(nf) ||
245+ nfsd_file_check_write_error(nf);
246+}
247+
248+static void
249+nfsd_file_do_unhash(struct nfsd_file *nf)
250+{
251+ lockdep_assert_held(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock);
252+
253+ trace_nfsd_file_unhash(nf);
254+
255+ if (nfsd_file_check_write_error(nf))
256+ nfsd_reset_boot_verifier(net_generic(nf->nf_net, nfsd_net_id));
257+ --nfsd_file_hashtbl[nf->nf_hashval].nfb_count;
258+ hlist_del_rcu(&nf->nf_node);
259+ if (!list_empty(&nf->nf_lru))
260+ list_lru_del(&nfsd_file_lru, &nf->nf_lru);
261+ atomic_long_dec(&nfsd_filecache_count);
262+}
263+
264+static bool
265+nfsd_file_unhash(struct nfsd_file *nf)
266+{
267+ if (test_and_clear_bit(NFSD_FILE_HASHED, &nf->nf_flags)) {
268+ nfsd_file_do_unhash(nf);
269+ return true;
270+ }
271+ return false;
272+}
273+
274+/*
275+ * Return true if the file was unhashed.
276+ */
277+static bool
278+nfsd_file_unhash_and_release_locked(struct nfsd_file *nf, struct list_head *dispose)
279+{
280+ lockdep_assert_held(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock);
281+
282+ trace_nfsd_file_unhash_and_release_locked(nf);
283+ if (!nfsd_file_unhash(nf))
284+ return false;
285+ /* keep final reference for nfsd_file_lru_dispose */
286+ if (atomic_add_unless(&nf->nf_ref, -1, 1))
287+ return true;
288+
289+ list_add(&nf->nf_lru, dispose);
290+ return true;
291+}
292+
293+static int
294+nfsd_file_put_noref(struct nfsd_file *nf)
295+{
296+ int count;
297+ trace_nfsd_file_put(nf);
298+
299+ count = atomic_dec_return(&nf->nf_ref);
300+ if (!count) {
301+ WARN_ON(test_bit(NFSD_FILE_HASHED, &nf->nf_flags));
302+ nfsd_file_free(nf);
303+ }
304+ return count;
305+}
306+
307+void
308+nfsd_file_put(struct nfsd_file *nf)
309+{
310+ bool is_hashed = test_bit(NFSD_FILE_HASHED, &nf->nf_flags) != 0;
311+ bool unused = !nfsd_file_in_use(nf);
312+
313+ set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags);
314+ if (nfsd_file_put_noref(nf) == 1 && is_hashed && unused)
315+ nfsd_file_schedule_laundrette(NFSD_FILE_LAUNDRETTE_MAY_FLUSH);
316+}
317+
318+struct nfsd_file *
319+nfsd_file_get(struct nfsd_file *nf)
320+{
321+ if (likely(atomic_inc_not_zero(&nf->nf_ref)))
322+ return nf;
323+ return NULL;
324+}
325+
326+static void
327+nfsd_file_dispose_list(struct list_head *dispose)
328+{
329+ struct nfsd_file *nf;
330+
331+ while(!list_empty(dispose)) {
332+ nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
333+ list_del(&nf->nf_lru);
334+ nfsd_file_put_noref(nf);
335+ }
336+}
337+
338+static void
339+nfsd_file_dispose_list_sync(struct list_head *dispose)
340+{
341+ bool flush = false;
342+ struct nfsd_file *nf;
343+
344+ while(!list_empty(dispose)) {
345+ nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
346+ list_del(&nf->nf_lru);
347+ if (!atomic_dec_and_test(&nf->nf_ref))
348+ continue;
349+ if (nfsd_file_free(nf))
350+ flush = true;
351+ }
352+ if (flush)
353+ flush_delayed_fput();
354+}
355+
356+/*
357+ * Note this can deadlock with nfsd_file_cache_purge.
358+ */
359+static enum lru_status
360+nfsd_file_lru_cb(struct list_head *item, struct list_lru_one *lru,
361+ spinlock_t *lock, void *arg)
362+ __releases(lock)
363+ __acquires(lock)
364+{
365+ struct list_head *head = arg;
366+ struct nfsd_file *nf = list_entry(item, struct nfsd_file, nf_lru);
367+
368+ /*
369+ * Do a lockless refcount check. The hashtable holds one reference, so
370+ * we look to see if anything else has a reference, or if any have
371+ * been put since the shrinker last ran. Those don't get unhashed and
372+ * released.
373+ *
374+ * Note that in the put path, we set the flag and then decrement the
375+ * counter. Here we check the counter and then test and clear the flag.
376+ * That order is deliberate to ensure that we can do this locklessly.
377+ */
378+ if (atomic_read(&nf->nf_ref) > 1)
379+ goto out_skip;
380+
381+ /*
382+ * Don't throw out files that are still undergoing I/O or
383+ * that have uncleared errors pending.
384+ */
385+ if (nfsd_file_check_writeback(nf))
386+ goto out_skip;
387+
388+ if (test_and_clear_bit(NFSD_FILE_REFERENCED, &nf->nf_flags))
389+ goto out_rescan;
390+
391+ if (!test_and_clear_bit(NFSD_FILE_HASHED, &nf->nf_flags))
392+ goto out_skip;
393+
394+ list_lru_isolate_move(lru, &nf->nf_lru, head);
395+ return LRU_REMOVED;
396+out_rescan:
397+ set_bit(NFSD_FILE_LRU_RESCAN, &nfsd_file_lru_flags);
398+out_skip:
399+ return LRU_SKIP;
400+}
401+
402+static void
403+nfsd_file_lru_dispose(struct list_head *head)
404+{
405+ while(!list_empty(head)) {
406+ struct nfsd_file *nf = list_first_entry(head,
407+ struct nfsd_file, nf_lru);
408+ list_del_init(&nf->nf_lru);
409+ spin_lock(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock);
410+ nfsd_file_do_unhash(nf);
411+ spin_unlock(&nfsd_file_hashtbl[nf->nf_hashval].nfb_lock);
412+ nfsd_file_put_noref(nf);
413+ }
414+}
415+
416+static unsigned long
417+nfsd_file_lru_count(struct shrinker *s, struct shrink_control *sc)
418+{
419+ return list_lru_count(&nfsd_file_lru);
420+}
421+
422+static unsigned long
423+nfsd_file_lru_scan(struct shrinker *s, struct shrink_control *sc)
424+{
425+ LIST_HEAD(head);
426+ unsigned long ret;
427+
428+ ret = list_lru_shrink_walk(&nfsd_file_lru, sc, nfsd_file_lru_cb, &head);
429+ nfsd_file_lru_dispose(&head);
430+ return ret;
431+}
432+
433+static struct shrinker nfsd_file_shrinker = {
434+ .scan_objects = nfsd_file_lru_scan,
435+ .count_objects = nfsd_file_lru_count,
436+ .seeks = 1,
437+};
438+
439+static void
440+__nfsd_file_close_inode(struct inode *inode, unsigned int hashval,
441+ struct list_head *dispose)
442+{
443+ struct nfsd_file *nf;
444+ struct hlist_node *tmp;
445+
446+ spin_lock(&nfsd_file_hashtbl[hashval].nfb_lock);
447+ hlist_for_each_entry_safe(nf, tmp, &nfsd_file_hashtbl[hashval].nfb_head, nf_node) {
448+ if (inode == nf->nf_inode)
449+ nfsd_file_unhash_and_release_locked(nf, dispose);
450+ }
451+ spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock);
452+}
453+
454+/**
455+ * nfsd_file_close_inode_sync - attempt to forcibly close a nfsd_file
456+ * @inode: inode of the file to attempt to remove
457+ *
458+ * Walk the whole hash bucket, looking for any files that correspond to "inode".
459+ * If any do, then unhash them and put the hashtable reference to them and
460+ * destroy any that had their last reference put. Also ensure that any of the
461+ * fputs also have their final __fput done as well.
462+ */
463+void
464+nfsd_file_close_inode_sync(struct inode *inode)
465+{
466+ unsigned int hashval = (unsigned int)hash_long(inode->i_ino,
467+ NFSD_FILE_HASH_BITS);
468+ LIST_HEAD(dispose);
469+
470+ __nfsd_file_close_inode(inode, hashval, &dispose);
471+ trace_nfsd_file_close_inode_sync(inode, hashval, !list_empty(&dispose));
472+ nfsd_file_dispose_list_sync(&dispose);
473+}
474+
475+/**
476+ * nfsd_file_close_inode_sync - attempt to forcibly close a nfsd_file
477+ * @inode: inode of the file to attempt to remove
478+ *
479+ * Walk the whole hash bucket, looking for any files that correspond to "inode".
480+ * If any do, then unhash them and put the hashtable reference to them and
481+ * destroy any that had their last reference put.
482+ */
483+static void
484+nfsd_file_close_inode(struct inode *inode)
485+{
486+ unsigned int hashval = (unsigned int)hash_long(inode->i_ino,
487+ NFSD_FILE_HASH_BITS);
488+ LIST_HEAD(dispose);
489+
490+ __nfsd_file_close_inode(inode, hashval, &dispose);
491+ trace_nfsd_file_close_inode(inode, hashval, !list_empty(&dispose));
492+ nfsd_file_dispose_list(&dispose);
493+}
494+
495+/**
496+ * nfsd_file_delayed_close - close unused nfsd_files
497+ * @work: dummy
498+ *
499+ * Walk the LRU list and close any entries that have not been used since
500+ * the last scan.
501+ *
502+ * Note this can deadlock with nfsd_file_cache_purge.
503+ */
504+static void
505+nfsd_file_delayed_close(struct work_struct *work)
506+{
507+ LIST_HEAD(head);
508+
509+ list_lru_walk(&nfsd_file_lru, nfsd_file_lru_cb, &head, LONG_MAX);
510+
511+ if (test_and_clear_bit(NFSD_FILE_LRU_RESCAN, &nfsd_file_lru_flags))
512+ nfsd_file_schedule_laundrette(NFSD_FILE_LAUNDRETTE_NOFLUSH);
513+
514+ if (!list_empty(&head)) {
515+ nfsd_file_lru_dispose(&head);
516+ flush_delayed_fput();
517+ }
518+}
519+
520+static int
521+nfsd_file_lease_notifier_call(struct notifier_block *nb, unsigned long arg,
522+ void *data)
523+{
524+ struct file_lock *fl = data;
525+
526+ /* Only close files for F_SETLEASE leases */
527+ if (fl->fl_flags & FL_LEASE)
528+ nfsd_file_close_inode_sync(file_inode(fl->fl_file));
529+ return 0;
530+}
531+
532+static struct notifier_block nfsd_file_lease_notifier = {
533+ .notifier_call = nfsd_file_lease_notifier_call,
534+};
535+
536+static int
537+nfsd_file_fsnotify_handle_event(struct fsnotify_group *group,
538+ struct inode *inode,
539+ u32 mask, const void *data, int data_type,
540+ const struct qstr *file_name, u32 cookie,
541+ struct fsnotify_iter_info *iter_info)
542+{
543+ trace_nfsd_file_fsnotify_handle_event(inode, mask);
544+
545+ /* Should be no marks on non-regular files */
546+ if (!S_ISREG(inode->i_mode)) {
547+ WARN_ON_ONCE(1);
548+ return 0;
549+ }
550+
551+ /* don't close files if this was not the last link */
552+ if (mask & FS_ATTRIB) {
553+ if (inode->i_nlink)
554+ return 0;
555+ }
556+
557+ nfsd_file_close_inode(inode);
558+ return 0;
559+}
560+
561+
562+static const struct fsnotify_ops nfsd_file_fsnotify_ops = {
563+ .handle_event = nfsd_file_fsnotify_handle_event,
564+ .free_mark = nfsd_file_mark_free,
565+};
566+
567+int
568+nfsd_file_cache_init(void)
569+{
570+ int ret = -ENOMEM;
571+ unsigned int i;
572+
573+ clear_bit(NFSD_FILE_SHUTDOWN, &nfsd_file_lru_flags);
574+
575+ if (nfsd_file_hashtbl)
576+ return 0;
577+
578+ nfsd_file_hashtbl = kcalloc(NFSD_FILE_HASH_SIZE,
579+ sizeof(*nfsd_file_hashtbl), GFP_KERNEL);
580+ if (!nfsd_file_hashtbl) {
581+ pr_err("nfsd: unable to allocate nfsd_file_hashtbl\n");
582+ goto out_err;
583+ }
584+
585+ nfsd_file_slab = kmem_cache_create("nfsd_file",
586+ sizeof(struct nfsd_file), 0, 0, NULL);
587+ if (!nfsd_file_slab) {
588+ pr_err("nfsd: unable to create nfsd_file_slab\n");
589+ goto out_err;
590+ }
591+
592+ nfsd_file_mark_slab = kmem_cache_create("nfsd_file_mark",
593+ sizeof(struct nfsd_file_mark), 0, 0, NULL);
594+ if (!nfsd_file_mark_slab) {
595+ pr_err("nfsd: unable to create nfsd_file_mark_slab\n");
596+ goto out_err;
597+ }
598+
599+
600+ ret = list_lru_init(&nfsd_file_lru);
601+ if (ret) {
602+ pr_err("nfsd: failed to init nfsd_file_lru: %d\n", ret);
603+ goto out_err;
604+ }
605+
606+ ret = register_shrinker(&nfsd_file_shrinker);
607+ if (ret) {
608+ pr_err("nfsd: failed to register nfsd_file_shrinker: %d\n", ret);
609+ goto out_lru;
610+ }
611+
612+ ret = lease_register_notifier(&nfsd_file_lease_notifier);
613+ if (ret) {
614+ pr_err("nfsd: unable to register lease notifier: %d\n", ret);
615+ goto out_shrinker;
616+ }
617+
618+ nfsd_file_fsnotify_group = fsnotify_alloc_group(&nfsd_file_fsnotify_ops);
619+ if (IS_ERR(nfsd_file_fsnotify_group)) {
620+ pr_err("nfsd: unable to create fsnotify group: %ld\n",
621+ PTR_ERR(nfsd_file_fsnotify_group));
622+ nfsd_file_fsnotify_group = NULL;
623+ goto out_notifier;
624+ }
625+
626+ for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) {
627+ INIT_HLIST_HEAD(&nfsd_file_hashtbl[i].nfb_head);
628+ spin_lock_init(&nfsd_file_hashtbl[i].nfb_lock);
629+ }
630+
631+ INIT_DELAYED_WORK(&nfsd_filecache_laundrette, nfsd_file_delayed_close);
632+out:
633+ return ret;
634+out_notifier:
635+ lease_unregister_notifier(&nfsd_file_lease_notifier);
636+out_shrinker:
637+ unregister_shrinker(&nfsd_file_shrinker);
638+out_lru:
639+ list_lru_destroy(&nfsd_file_lru);
640+out_err:
641+ kmem_cache_destroy(nfsd_file_slab);
642+ nfsd_file_slab = NULL;
643+ kmem_cache_destroy(nfsd_file_mark_slab);
644+ nfsd_file_mark_slab = NULL;
645+ kfree(nfsd_file_hashtbl);
646+ nfsd_file_hashtbl = NULL;
647+ goto out;
648+}
649+
650+/*
651+ * Note this can deadlock with nfsd_file_lru_cb.
652+ */
653+void
654+nfsd_file_cache_purge(struct net *net)
655+{
656+ unsigned int i;
657+ struct nfsd_file *nf;
658+ struct hlist_node *next;
659+ LIST_HEAD(dispose);
660+ bool del;
661+
662+ if (!nfsd_file_hashtbl)
663+ return;
664+
665+ for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) {
666+ struct nfsd_fcache_bucket *nfb = &nfsd_file_hashtbl[i];
667+
668+ spin_lock(&nfb->nfb_lock);
669+ hlist_for_each_entry_safe(nf, next, &nfb->nfb_head, nf_node) {
670+ if (net && nf->nf_net != net)
671+ continue;
672+ del = nfsd_file_unhash_and_release_locked(nf, &dispose);
673+
674+ /*
675+ * Deadlock detected! Something marked this entry as
676+ * unhased, but hasn't removed it from the hash list.
677+ */
678+ WARN_ON_ONCE(!del);
679+ }
680+ spin_unlock(&nfb->nfb_lock);
681+ nfsd_file_dispose_list(&dispose);
682+ }
683+}
684+
685+void
686+nfsd_file_cache_shutdown(void)
687+{
688+ LIST_HEAD(dispose);
689+
690+ set_bit(NFSD_FILE_SHUTDOWN, &nfsd_file_lru_flags);
691+
692+ lease_unregister_notifier(&nfsd_file_lease_notifier);
693+ unregister_shrinker(&nfsd_file_shrinker);
694+ /*
695+ * make sure all callers of nfsd_file_lru_cb are done before
696+ * calling nfsd_file_cache_purge
697+ */
698+ cancel_delayed_work_sync(&nfsd_filecache_laundrette);
699+ nfsd_file_cache_purge(NULL);
700+ list_lru_destroy(&nfsd_file_lru);
701+ rcu_barrier();
702+ fsnotify_put_group(nfsd_file_fsnotify_group);
703+ nfsd_file_fsnotify_group = NULL;
704+ kmem_cache_destroy(nfsd_file_slab);
705+ nfsd_file_slab = NULL;
706+ fsnotify_wait_marks_destroyed();
707+ kmem_cache_destroy(nfsd_file_mark_slab);
708+ nfsd_file_mark_slab = NULL;
709+ kfree(nfsd_file_hashtbl);
710+ nfsd_file_hashtbl = NULL;
711+}
712+
713+static bool
714+nfsd_match_cred(const struct cred *c1, const struct cred *c2)
715+{
716+ int i;
717+
718+ if (!uid_eq(c1->fsuid, c2->fsuid))
719+ return false;
720+ if (!gid_eq(c1->fsgid, c2->fsgid))
721+ return false;
722+ if (c1->group_info == NULL || c2->group_info == NULL)
723+ return c1->group_info == c2->group_info;
724+ if (c1->group_info->ngroups != c2->group_info->ngroups)
725+ return false;
726+ for (i = 0; i < c1->group_info->ngroups; i++) {
727+ if (!gid_eq(c1->group_info->gid[i], c2->group_info->gid[i]))
728+ return false;
729+ }
730+ return true;
731+}
732+
733+static struct nfsd_file *
734+nfsd_file_find_locked(struct inode *inode, unsigned int may_flags,
735+ unsigned int hashval, struct net *net)
736+{
737+ struct nfsd_file *nf;
738+ unsigned char need = may_flags & NFSD_FILE_MAY_MASK;
739+
740+ hlist_for_each_entry_rcu(nf, &nfsd_file_hashtbl[hashval].nfb_head,
741+ nf_node) {
742+ if ((need & nf->nf_may) != need)
743+ continue;
744+ if (nf->nf_inode != inode)
745+ continue;
746+ if (nf->nf_net != net)
747+ continue;
748+ if (!nfsd_match_cred(nf->nf_cred, current_cred()))
749+ continue;
750+ if (nfsd_file_get(nf) != NULL)
751+ return nf;
752+ }
753+ return NULL;
754+}
755+
756+/**
757+ * nfsd_file_is_cached - are there any cached open files for this fh?
758+ * @inode: inode of the file to check
759+ *
760+ * Scan the hashtable for open files that match this fh. Returns true if there
761+ * are any, and false if not.
762+ */
763+bool
764+nfsd_file_is_cached(struct inode *inode)
765+{
766+ bool ret = false;
767+ struct nfsd_file *nf;
768+ unsigned int hashval;
769+
770+ hashval = (unsigned int)hash_long(inode->i_ino, NFSD_FILE_HASH_BITS);
771+
772+ rcu_read_lock();
773+ hlist_for_each_entry_rcu(nf, &nfsd_file_hashtbl[hashval].nfb_head,
774+ nf_node) {
775+ if (inode == nf->nf_inode) {
776+ ret = true;
777+ break;
778+ }
779+ }
780+ rcu_read_unlock();
781+ trace_nfsd_file_is_cached(inode, hashval, (int)ret);
782+ return ret;
783+}
784+
785+__be32
786+nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
787+ unsigned int may_flags, struct nfsd_file **pnf)
788+{
789+ __be32 status;
790+ struct net *net = SVC_NET(rqstp);
791+ struct nfsd_file *nf, *new;
792+ struct inode *inode;
793+ unsigned int hashval;
794+
795+ /* FIXME: skip this if fh_dentry is already set? */
796+ status = fh_verify(rqstp, fhp, S_IFREG,
797+ may_flags|NFSD_MAY_OWNER_OVERRIDE);
798+ if (status != nfs_ok)
799+ return status;
800+
801+ inode = d_inode(fhp->fh_dentry);
802+ hashval = (unsigned int)hash_long(inode->i_ino, NFSD_FILE_HASH_BITS);
803+retry:
804+ rcu_read_lock();
805+ nf = nfsd_file_find_locked(inode, may_flags, hashval, net);
806+ rcu_read_unlock();
807+ if (nf)
808+ goto wait_for_construction;
809+
810+ new = nfsd_file_alloc(inode, may_flags, hashval, net);
811+ if (!new) {
812+ trace_nfsd_file_acquire(rqstp, hashval, inode, may_flags,
813+ NULL, nfserr_jukebox);
814+ return nfserr_jukebox;
815+ }
816+
817+ spin_lock(&nfsd_file_hashtbl[hashval].nfb_lock);
818+ nf = nfsd_file_find_locked(inode, may_flags, hashval, net);
819+ if (nf == NULL)
820+ goto open_file;
821+ spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock);
822+ nfsd_file_slab_free(&new->nf_rcu);
823+
824+wait_for_construction:
825+ wait_on_bit(&nf->nf_flags, NFSD_FILE_PENDING, TASK_UNINTERRUPTIBLE);
826+
827+ /* Did construction of this file fail? */
828+ if (!test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) {
829+ nfsd_file_put_noref(nf);
830+ goto retry;
831+ }
832+
833+ this_cpu_inc(nfsd_file_cache_hits);
834+
835+ if (!(may_flags & NFSD_MAY_NOT_BREAK_LEASE)) {
836+ bool write = (may_flags & NFSD_MAY_WRITE);
837+
838+ if (test_bit(NFSD_FILE_BREAK_READ, &nf->nf_flags) ||
839+ (test_bit(NFSD_FILE_BREAK_WRITE, &nf->nf_flags) && write)) {
840+ status = nfserrno(nfsd_open_break_lease(
841+ file_inode(nf->nf_file), may_flags));
842+ if (status == nfs_ok) {
843+ clear_bit(NFSD_FILE_BREAK_READ, &nf->nf_flags);
844+ if (write)
845+ clear_bit(NFSD_FILE_BREAK_WRITE,
846+ &nf->nf_flags);
847+ }
848+ }
849+ }
850+out:
851+ if (status == nfs_ok) {
852+ *pnf = nf;
853+ } else {
854+ nfsd_file_put(nf);
855+ nf = NULL;
856+ }
857+
858+ trace_nfsd_file_acquire(rqstp, hashval, inode, may_flags, nf, status);
859+ return status;
860+open_file:
861+ nf = new;
862+ /* Take reference for the hashtable */
863+ atomic_inc(&nf->nf_ref);
864+ __set_bit(NFSD_FILE_HASHED, &nf->nf_flags);
865+ __set_bit(NFSD_FILE_PENDING, &nf->nf_flags);
866+ list_lru_add(&nfsd_file_lru, &nf->nf_lru);
867+ hlist_add_head_rcu(&nf->nf_node, &nfsd_file_hashtbl[hashval].nfb_head);
868+ ++nfsd_file_hashtbl[hashval].nfb_count;
869+ nfsd_file_hashtbl[hashval].nfb_maxcount = max(nfsd_file_hashtbl[hashval].nfb_maxcount,
870+ nfsd_file_hashtbl[hashval].nfb_count);
871+ spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock);
872+ atomic_long_inc(&nfsd_filecache_count);
873+
874+ nf->nf_mark = nfsd_file_mark_find_or_create(nf);
875+ if (nf->nf_mark)
876+ status = nfsd_open_verified(rqstp, fhp, S_IFREG,
877+ may_flags, &nf->nf_file);
878+ else
879+ status = nfserr_jukebox;
880+ /*
881+ * If construction failed, or we raced with a call to unlink()
882+ * then unhash.
883+ */
884+ if (status != nfs_ok || inode->i_nlink == 0) {
885+ bool do_free;
886+ spin_lock(&nfsd_file_hashtbl[hashval].nfb_lock);
887+ do_free = nfsd_file_unhash(nf);
888+ spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock);
889+ if (do_free)
890+ nfsd_file_put_noref(nf);
891+ }
892+ clear_bit_unlock(NFSD_FILE_PENDING, &nf->nf_flags);
893+ smp_mb__after_atomic();
894+ wake_up_bit(&nf->nf_flags, NFSD_FILE_PENDING);
895+ goto out;
896+}
897+
898+/*
899+ * Note that fields may be added, removed or reordered in the future. Programs
900+ * scraping this file for info should test the labels to ensure they're
901+ * getting the correct field.
902+ */
903+static int nfsd_file_cache_stats_show(struct seq_file *m, void *v)
904+{
905+ unsigned int i, count = 0, longest = 0;
906+ unsigned long hits = 0;
907+
908+ /*
909+ * No need for spinlocks here since we're not terribly interested in
910+ * accuracy. We do take the nfsd_mutex simply to ensure that we
911+ * don't end up racing with server shutdown
912+ */
913+ mutex_lock(&nfsd_mutex);
914+ if (nfsd_file_hashtbl) {
915+ for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) {
916+ count += nfsd_file_hashtbl[i].nfb_count;
917+ longest = max(longest, nfsd_file_hashtbl[i].nfb_count);
918+ }
919+ }
920+ mutex_unlock(&nfsd_mutex);
921+
922+ for_each_possible_cpu(i)
923+ hits += per_cpu(nfsd_file_cache_hits, i);
924+
925+ seq_printf(m, "total entries: %u\n", count);
926+ seq_printf(m, "longest chain: %u\n", longest);
927+ seq_printf(m, "cache hits: %lu\n", hits);
928+ return 0;
929+}
930+
931+int nfsd_file_cache_stats_open(struct inode *inode, struct file *file)
932+{
933+ return single_open(file, nfsd_file_cache_stats_show, NULL);
934+}
fs/nfsd/filecache.h+61−0
@@ -0,0 +1,61 @@
1+#ifndef _FS_NFSD_FILECACHE_H
2+#define _FS_NFSD_FILECACHE_H
3+
4+#include <linux/fsnotify_backend.h>
5+
6+/*
7+ * This is the fsnotify_mark container that nfsd attaches to the files that it
8+ * is holding open. Note that we have a separate refcount here aside from the
9+ * one in the fsnotify_mark. We only want a single fsnotify_mark attached to
10+ * the inode, and for each nfsd_file to hold a reference to it.
11+ *
12+ * The fsnotify_mark is itself refcounted, but that's not sufficient to tell us
13+ * how to put that reference. If there are still outstanding nfsd_files that
14+ * reference the mark, then we would want to call fsnotify_put_mark on it.
15+ * If there were not, then we'd need to call fsnotify_destroy_mark. Since we
16+ * can't really tell the difference, we use the nfm_mark to keep track of how
17+ * many nfsd_files hold references to the mark. When that counter goes to zero
18+ * then we know to call fsnotify_destroy_mark on it.
19+ */
20+struct nfsd_file_mark {
21+ struct fsnotify_mark nfm_mark;
22+ atomic_t nfm_ref;
23+};
24+
25+/*
26+ * A representation of a file that has been opened by knfsd. These are hashed
27+ * in the hashtable by inode pointer value. Note that this object doesn't
28+ * hold a reference to the inode by itself, so the nf_inode pointer should
29+ * never be dereferenced, only used for comparison.
30+ */
31+struct nfsd_file {
32+ struct hlist_node nf_node;
33+ struct list_head nf_lru;
34+ struct rcu_head nf_rcu;
35+ struct file *nf_file;
36+ const struct cred *nf_cred;
37+ struct net *nf_net;
38+#define NFSD_FILE_HASHED (0)
39+#define NFSD_FILE_PENDING (1)
40+#define NFSD_FILE_BREAK_READ (2)
41+#define NFSD_FILE_BREAK_WRITE (3)
42+#define NFSD_FILE_REFERENCED (4)
43+ unsigned long nf_flags;
44+ struct inode *nf_inode;
45+ unsigned int nf_hashval;
46+ atomic_t nf_ref;
47+ unsigned char nf_may;
48+ struct nfsd_file_mark *nf_mark;
49+};
50+
51+int nfsd_file_cache_init(void);
52+void nfsd_file_cache_purge(struct net *);
53+void nfsd_file_cache_shutdown(void);
54+void nfsd_file_put(struct nfsd_file *nf);
55+struct nfsd_file *nfsd_file_get(struct nfsd_file *nf);
56+void nfsd_file_close_inode_sync(struct inode *inode);
57+bool nfsd_file_is_cached(struct inode *inode);
58+__be32 nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
59+ unsigned int may_flags, struct nfsd_file **nfp);
60+int nfsd_file_cache_stats_open(struct inode *, struct file *);
61+#endif /* _FS_NFSD_FILECACHE_H */
fs/nfsd/netns.h+4−0
@@ -104,6 +104,7 @@ struct nfsd_net { · 103 unmodified lines
104104
105105 /* Time of server startup */
106106 struct timespec64 nfssvc_boot;
107+ seqlock_t boot_lock;
107108
108109 /*
109110 * Max number of connections this nfsd container will allow. Defaults
@@ -179,4 +180,7 @@ struct nfsd_net { · 69 unmodified lines
179180 extern void nfsd_netns_free_versions(struct nfsd_net *nn);
180181
181182 extern unsigned int nfsd_net_id;
183+
184+void nfsd_copy_boot_verifier(__be32 verf[2], struct nfsd_net *nn);
185+void nfsd_reset_boot_verifier(struct nfsd_net *nn);
182186 #endif /* __NFSD_NETNS_H__ */
fs/nfsd/nfs3proc.c+2−7
@@ -172,13 +172,8 @@ nfsd3_proc_read(struct svc_rqst *rqstp) · 171 unmodified lines
172172 nfserr = nfsd_read(rqstp, &resp->fh,
173173 argp->offset,
174174 rqstp->rq_vec, argp->vlen,
175− &resp->count);
176− if (nfserr == 0) {
177− struct inode *inode = d_inode(resp->fh.fh_dentry);
178− resp->eof = nfsd_eof_on_read(cnt, resp->count, argp->offset,
179− inode->i_size);
180− }
181−
175+ &resp->count,
176+ &resp->eof);
182177 RETURN_STATUS(nfserr);
183178 }
184179
fs/nfsd/nfs3xdr.c+9−4
@@ -27,6 +27,7 @@ static u32 nfs3_ftypes[] = { · 26 unmodified lines
2727 NF3SOCK, NF3BAD, NF3LNK, NF3BAD,
2828 };
2929
30+
3031 /*
3132 * XDR functions for basic NFS types
3233 */
@@ -751,14 +752,16 @@ nfs3svc_encode_writeres(struct svc_rqst *rqstp, __be32 *p) · 718 unmodified lines
751752 {
752753 struct nfsd3_writeres *resp = rqstp->rq_resp;
753754 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
755+ __be32 verf[2];
754756
755757 p = encode_wcc_data(rqstp, p, &resp->fh);
756758 if (resp->status == 0) {
757759 *p++ = htonl(resp->count);
758760 *p++ = htonl(resp->committed);
759761 /* unique identifier, y2038 overflow can be ignored */
760− *p++ = htonl((u32)nn->nfssvc_boot.tv_sec);
761− *p++ = htonl(nn->nfssvc_boot.tv_nsec);
762+ nfsd_copy_boot_verifier(verf, nn);
763+ *p++ = verf[0];
764+ *p++ = verf[1];
762765 }
763766 return xdr_ressize_check(rqstp, p);
764767 }
@@ -1125,13 +1128,15 @@ nfs3svc_encode_commitres(struct svc_rqst *rqstp, __be32 *p) · 360 unmodified lines
11251128 {
11261129 struct nfsd3_commitres *resp = rqstp->rq_resp;
11271130 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
1131+ __be32 verf[2];
11281132
11291133 p = encode_wcc_data(rqstp, p, &resp->fh);
11301134 /* Write verifier */
11311135 if (resp->status == 0) {
11321136 /* unique identifier, y2038 overflow can be ignored */
1133− *p++ = htonl((u32)nn->nfssvc_boot.tv_sec);
1134− *p++ = htonl(nn->nfssvc_boot.tv_nsec);
1137+ nfsd_copy_boot_verifier(verf, nn);
1138+ *p++ = verf[0];
1139+ *p++ = verf[1];
11351140 }
11361141 return xdr_ressize_check(rqstp, p);
11371142 }
fs/nfsd/nfs4callback.c+15−20
@@ -512,11 +512,9 @@ static int nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp, · 511 unmodified lines
512512 if (unlikely(status))
513513 return status;
514514
515− if (cb != NULL) {
516− status = decode_cb_sequence4res(xdr, cb);
517− if (unlikely(status || cb->cb_seq_status))
518− return status;
519− }
515+ status = decode_cb_sequence4res(xdr, cb);
516+ if (unlikely(status || cb->cb_seq_status))
517+ return status;
520518
521519 return decode_cb_op_status(xdr, OP_CB_RECALL, &cb->cb_status);
522520 }
@@ -604,11 +602,10 @@ static int nfs4_xdr_dec_cb_layout(struct rpc_rqst *rqstp, · 81 unmodified lines
604602 if (unlikely(status))
605603 return status;
606604
607− if (cb) {
608− status = decode_cb_sequence4res(xdr, cb);
609− if (unlikely(status || cb->cb_seq_status))
610− return status;
611− }
605+ status = decode_cb_sequence4res(xdr, cb);
606+ if (unlikely(status || cb->cb_seq_status))
607+ return status;
608+
612609 return decode_cb_op_status(xdr, OP_CB_LAYOUTRECALL, &cb->cb_status);
613610 }
614611 #endif /* CONFIG_NFSD_PNFS */
@@ -663,11 +660,10 @@ static int nfs4_xdr_dec_cb_notify_lock(struct rpc_rqst *rqstp, · 48 unmodified lines
663660 if (unlikely(status))
664661 return status;
665662
666− if (cb) {
667− status = decode_cb_sequence4res(xdr, cb);
668− if (unlikely(status || cb->cb_seq_status))
669− return status;
670− }
663+ status = decode_cb_sequence4res(xdr, cb);
664+ if (unlikely(status || cb->cb_seq_status))
665+ return status;
666+
671667 return decode_cb_op_status(xdr, OP_CB_NOTIFY_LOCK, &cb->cb_status);
672668 }
673669
@@ -759,11 +755,10 @@ static int nfs4_xdr_dec_cb_offload(struct rpc_rqst *rqstp, · 85 unmodified lines
759755 if (unlikely(status))
760756 return status;
761757
762− if (cb) {
763− status = decode_cb_sequence4res(xdr, cb);
764− if (unlikely(status || cb->cb_seq_status))
765− return status;
766− }
758+ status = decode_cb_sequence4res(xdr, cb);
759+ if (unlikely(status || cb->cb_seq_status))
760+ return status;
761+
767762 return decode_cb_op_status(xdr, OP_CB_OFFLOAD, &cb->cb_status);
768763 }
769764 /*
fs/nfsd/nfs4layouts.c+6−6
@@ -169,8 +169,8 @@ nfsd4_free_layout_stateid(struct nfs4_stid *stid) · 168 unmodified lines
169169 spin_unlock(&fp->fi_lock);
170170
171171 if (!nfsd4_layout_ops[ls->ls_layout_type]->disable_recalls)
172− vfs_setlease(ls->ls_file, F_UNLCK, NULL, (void **)&ls);
173− fput(ls->ls_file);
172+ vfs_setlease(ls->ls_file->nf_file, F_UNLCK, NULL, (void **)&ls);
173+ nfsd_file_put(ls->ls_file);
174174
175175 if (ls->ls_recalled)
176176 atomic_dec(&ls->ls_stid.sc_file->fi_lo_recalls);
@@ -197,7 +197,7 @@ nfsd4_layout_setlease(struct nfs4_layout_stateid *ls) · 20 unmodified lines
197197 fl->fl_end = OFFSET_MAX;
198198 fl->fl_owner = ls;
199199 fl->fl_pid = current->tgid;
200− fl->fl_file = ls->ls_file;
200+ fl->fl_file = ls->ls_file->nf_file;
201201
202202 status = vfs_setlease(fl->fl_file, fl->fl_type, &fl, NULL);
203203 if (status) {
@@ -236,13 +236,13 @@ nfsd4_alloc_layout_stateid(struct nfsd4_compound_state *cstate, · 32 unmodified lines
236236 NFSPROC4_CLNT_CB_LAYOUT);
237237
238238 if (parent->sc_type == NFS4_DELEG_STID)
239− ls->ls_file = get_file(fp->fi_deleg_file);
239+ ls->ls_file = nfsd_file_get(fp->fi_deleg_file);
240240 else
241241 ls->ls_file = find_any_file(fp);
242242 BUG_ON(!ls->ls_file);
243243
244244 if (nfsd4_layout_setlease(ls)) {
245− fput(ls->ls_file);
245+ nfsd_file_put(ls->ls_file);
246246 put_nfs4_file(fp);
247247 kmem_cache_free(nfs4_layout_stateid_cache, ls);
248248 return NULL;
@@ -626,7 +626,7 @@ nfsd4_cb_layout_fail(struct nfs4_layout_stateid *ls) · 377 unmodified lines
626626
627627 argv[0] = (char *)nfsd_recall_failed;
628628 argv[1] = addr_str;
629− argv[2] = ls->ls_file->f_path.mnt->mnt_sb->s_id;
629+ argv[2] = ls->ls_file->nf_file->f_path.mnt->mnt_sb->s_id;
630630 argv[3] = NULL;
631631
632632 error = call_usermodehelper(nfsd_recall_failed, argv, envp,
fs/nfsd/nfs4proc.c+46−51
@@ -568,17 +568,11 @@ nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 567 unmodified lines
568568
569569 static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
570570 {
571− __be32 verf[2];
572− struct nfsd_net *nn = net_generic(net, nfsd_net_id);
571+ __be32 *verf = (__be32 *)verifier->data;
573572
574− /*
575− * This is opaque to client, so no need to byte-swap. Use
576− * __force to keep sparse happy. y2038 time_t overflow is
577− * irrelevant in this usage.
578− */
579− verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec;
580− verf[1] = (__force __be32)nn->nfssvc_boot.tv_nsec;
581− memcpy(verifier->data, verf, sizeof(verifier->data));
573+ BUILD_BUG_ON(2*sizeof(*verf) != sizeof(verifier->data));
574+
575+ nfsd_copy_boot_verifier(verf, net_generic(net, nfsd_net_id));
582576 }
583577
584578 static __be32
@@ -761,7 +755,7 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 176 unmodified lines
761755 struct nfsd4_read *read = &u->read;
762756 __be32 status;
763757
764− read->rd_filp = NULL;
758+ read->rd_nf = NULL;
765759 if (read->rd_offset >= OFFSET_MAX)
766760 return nfserr_inval;
767761
@@ -782,7 +776,7 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 14 unmodified lines
782776 /* check stateid */
783777 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
784778 &read->rd_stateid, RD_STATE,
785− &read->rd_filp, &read->rd_tmp_file);
779+ &read->rd_nf);
786780 if (status) {
787781 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
788782 goto out;
@@ -798,8 +792,8 @@ out: · 9 unmodified lines
798792 static void
799793 nfsd4_read_release(union nfsd4_op_u *u)
800794 {
801− if (u->read.rd_filp)
802− fput(u->read.rd_filp);
795+ if (u->read.rd_nf)
796+ nfsd_file_put(u->read.rd_nf);
803797 trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
804798 u->read.rd_offset, u->read.rd_length);
805799 }
@@ -954,7 +948,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 148 unmodified lines
954948 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
955949 status = nfs4_preprocess_stateid_op(rqstp, cstate,
956950 &cstate->current_fh, &setattr->sa_stateid,
957− WR_STATE, NULL, NULL);
951+ WR_STATE, NULL);
958952 if (status) {
959953 dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
960954 return status;
@@ -993,7 +987,7 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 32 unmodified lines
993987 {
994988 struct nfsd4_write *write = &u->write;
995989 stateid_t *stateid = &write->wr_stateid;
996− struct file *filp = NULL;
990+ struct nfsd_file *nf = NULL;
997991 __be32 status = nfs_ok;
998992 unsigned long cnt;
999993 int nvecs;
@@ -1005,7 +999,7 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 5 unmodified lines
1005999 trace_nfsd_write_start(rqstp, &cstate->current_fh,
10061000 write->wr_offset, cnt);
10071001 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1008− stateid, WR_STATE, &filp, NULL);
1002+ stateid, WR_STATE, &nf);
10091003 if (status) {
10101004 dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
10111005 return status;
@@ -1018,10 +1012,10 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 6 unmodified lines
10181012 &write->wr_head, write->wr_buflen);
10191013 WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
10201014
1021− status = nfsd_vfs_write(rqstp, &cstate->current_fh, filp,
1015+ status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf->nf_file,
10221016 write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
10231017 write->wr_how_written);
1024− fput(filp);
1018+ nfsd_file_put(nf);
10251019
10261020 write->wr_bytes_written = cnt;
10271021 trace_nfsd_write_done(rqstp, &cstate->current_fh,
@@ -1031,8 +1025,8 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 3 unmodified lines
10311025
10321026 static __be32
10331027 nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1034− stateid_t *src_stateid, struct file **src,
1035− stateid_t *dst_stateid, struct file **dst)
1028+ stateid_t *src_stateid, struct nfsd_file **src,
1029+ stateid_t *dst_stateid, struct nfsd_file **dst)
10361030 {
10371031 __be32 status;
10381032
@@ -1040,22 +1034,22 @@ nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 1 unmodified line
10401034 return nfserr_nofilehandle;
10411035
10421036 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
1043− src_stateid, RD_STATE, src, NULL);
1037+ src_stateid, RD_STATE, src);
10441038 if (status) {
10451039 dprintk("NFSD: %s: couldn't process src stateid!\n", __func__);
10461040 goto out;
10471041 }
10481042
10491043 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
1050− dst_stateid, WR_STATE, dst, NULL);
1044+ dst_stateid, WR_STATE, dst);
10511045 if (status) {
10521046 dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__);
10531047 goto out_put_src;
10541048 }
10551049
10561050 /* fix up for NFS-specific error code */
1057− if (!S_ISREG(file_inode(*src)->i_mode) ||
1058− !S_ISREG(file_inode(*dst)->i_mode)) {
1051+ if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) ||
1052+ !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) {
10591053 status = nfserr_wrong_type;
10601054 goto out_put_dst;
10611055 }
@@ -1063,9 +1057,9 @@ nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 1 unmodified line
10631057 out:
10641058 return status;
10651059 out_put_dst:
1066− fput(*dst);
1060+ nfsd_file_put(*dst);
10671061 out_put_src:
1068− fput(*src);
1062+ nfsd_file_put(*src);
10691063 goto out;
10701064 }
10711065
@@ -1074,7 +1068,7 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 2 unmodified lines
10741068 union nfsd4_op_u *u)
10751069 {
10761070 struct nfsd4_clone *clone = &u->clone;
1077− struct file *src, *dst;
1071+ struct nfsd_file *src, *dst;
10781072 __be32 status;
10791073
10801074 status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src,
@@ -1082,11 +1076,11 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 1 unmodified line
10821076 if (status)
10831077 goto out;
10841078
1085− status = nfsd4_clone_file_range(src, clone->cl_src_pos,
1086− dst, clone->cl_dst_pos, clone->cl_count);
1079+ status = nfsd4_clone_file_range(src->nf_file, clone->cl_src_pos,
1080+ dst->nf_file, clone->cl_dst_pos, clone->cl_count);
10871081
1088− fput(dst);
1089− fput(src);
1082+ nfsd_file_put(dst);
1083+ nfsd_file_put(src);
10901084 out:
10911085 return status;
10921086 }
@@ -1176,8 +1170,9 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) · 83 unmodified lines
11761170 do {
11771171 if (kthread_should_stop())
11781172 break;
1179− bytes_copied = nfsd_copy_file_range(copy->file_src, src_pos,
1180− copy->file_dst, dst_pos, bytes_total);
1173+ bytes_copied = nfsd_copy_file_range(copy->nf_src->nf_file,
1174+ src_pos, copy->nf_dst->nf_file, dst_pos,
1175+ bytes_total);
11811176 if (bytes_copied <= 0)
11821177 break;
11831178 bytes_total -= bytes_copied;
@@ -1204,8 +1199,8 @@ static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync) · 20 unmodified lines
12041199 status = nfs_ok;
12051200 }
12061201
1207− fput(copy->file_src);
1208− fput(copy->file_dst);
1202+ nfsd_file_put(copy->nf_src);
1203+ nfsd_file_put(copy->nf_dst);
12091204 return status;
12101205 }
12111206
@@ -1218,16 +1213,16 @@ static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) · 6 unmodified lines
12181213 memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res));
12191214 memcpy(&dst->fh, &src->fh, sizeof(src->fh));
12201215 dst->cp_clp = src->cp_clp;
1221− dst->file_dst = get_file(src->file_dst);
1222− dst->file_src = get_file(src->file_src);
1216+ dst->nf_dst = nfsd_file_get(src->nf_dst);
1217+ dst->nf_src = nfsd_file_get(src->nf_src);
12231218 memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid));
12241219 }
12251220
12261221 static void cleanup_async_copy(struct nfsd4_copy *copy)
12271222 {
12281223 nfs4_free_cp_state(copy);
1229− fput(copy->file_dst);
1230− fput(copy->file_src);
1224+ nfsd_file_put(copy->nf_dst);
1225+ nfsd_file_put(copy->nf_src);
12311226 spin_lock(&copy->cp_clp->async_lock);
12321227 list_del(&copy->copies);
12331228 spin_unlock(&copy->cp_clp->async_lock);
@@ -1264,8 +1259,8 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 30 unmodified lines
12641259 struct nfsd4_copy *async_copy = NULL;
12651260
12661261 status = nfsd4_verify_copy(rqstp, cstate, &copy->cp_src_stateid,
1267− &copy->file_src, &copy->cp_dst_stateid,
1268− &copy->file_dst);
1262+ &copy->nf_src, &copy->cp_dst_stateid,
1263+ &copy->nf_dst);
12691264 if (status)
12701265 goto out;
12711266
@@ -1347,21 +1342,21 @@ nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 75 unmodified lines
13471342 struct nfsd4_fallocate *fallocate, int flags)
13481343 {
13491344 __be32 status;
1350− struct file *file;
1345+ struct nfsd_file *nf;
13511346
13521347 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
13531348 &fallocate->falloc_stateid,
1354− WR_STATE, &file, NULL);
1349+ WR_STATE, &nf);
13551350 if (status != nfs_ok) {
13561351 dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
13571352 return status;
13581353 }
13591354
1360− status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file,
1355+ status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file,
13611356 fallocate->falloc_offset,
13621357 fallocate->falloc_length,
13631358 flags);
1364− fput(file);
1359+ nfsd_file_put(nf);
13651360 return status;
13661361 }
13671362 static __be32
@@ -1406,11 +1401,11 @@ nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 38 unmodified lines
14061401 struct nfsd4_seek *seek = &u->seek;
14071402 int whence;
14081403 __be32 status;
1409− struct file *file;
1404+ struct nfsd_file *nf;
14101405
14111406 status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
14121407 &seek->seek_stateid,
1413− RD_STATE, &file, NULL);
1408+ RD_STATE, &nf);
14141409 if (status) {
14151410 dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
14161411 return status;
@@ -1432,14 +1427,14 @@ nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 15 unmodified lines
14321427 * Note: This call does change file->f_pos, but nothing in NFSD
14331428 * should ever file->f_pos.
14341429 */
1435− seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence);
1430+ seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence);
14361431 if (seek->seek_pos < 0)
14371432 status = nfserrno(seek->seek_pos);
1438− else if (seek->seek_pos >= i_size_read(file_inode(file)))
1433+ else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file)))
14391434 seek->seek_eof = true;
14401435
14411436 out:
1442− fput(file);
1437+ nfsd_file_put(nf);
14431438 return status;
14441439 }
14451440
fs/nfsd/nfs4recover.c+325−63
@@ -59,8 +59,13 @@ struct nfsd4_client_tracking_ops { · 58 unmodified lines
5959 void (*remove)(struct nfs4_client *);
6060 int (*check)(struct nfs4_client *);
6161 void (*grace_done)(struct nfsd_net *);
62+ uint8_t version;
63+ size_t msglen;
6264 };
6365
66+static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops;
67+static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops_v2;
68+
6469 /* Globals */
6570 static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";
6671
@@ -173,6 +178,7 @@ __nfsd4_create_reclaim_record_grace(struct nfs4_client *clp, · 106 unmodified lines
173178 const char *dname, int len, struct nfsd_net *nn)
174179 {
175180 struct xdr_netobj name;
181+ struct xdr_netobj princhash = { .len = 0, .data = NULL };
176182 struct nfs4_client_reclaim *crp;
177183
178184 name.data = kmemdup(dname, len, GFP_KERNEL);
@@ -182,7 +188,7 @@ __nfsd4_create_reclaim_record_grace(struct nfs4_client *clp, · 3 unmodified lines
182188 return;
183189 }
184190 name.len = len;
185− crp = nfs4_client_to_reclaim(name, nn);
191+ crp = nfs4_client_to_reclaim(name, princhash, nn);
186192 if (!crp) {
187193 kfree(name.data);
188194 return;
@@ -482,6 +488,7 @@ static int · 293 unmodified lines
482488 load_recdir(struct dentry *parent, struct dentry *child, struct nfsd_net *nn)
483489 {
484490 struct xdr_netobj name;
491+ struct xdr_netobj princhash = { .len = 0, .data = NULL };
485492
486493 if (child->d_name.len != HEXDIR_LEN - 1) {
487494 printk("%s: illegal name %pd in recovery directory\n",
@@ -496,7 +503,7 @@ load_recdir(struct dentry *parent, struct dentry *child, struct nfsd_net *nn) · 8 unmodified lines
496503 goto out;
497504 }
498505 name.len = HEXDIR_LEN;
499− if (!nfs4_client_to_reclaim(name, nn))
506+ if (!nfs4_client_to_reclaim(name, princhash, nn))
500507 kfree(name.data);
501508 out:
502509 return 0;
@@ -718,6 +725,8 @@ static const struct nfsd4_client_tracking_ops nfsd4_legacy_tracking_ops = { · 215 unmodified lines
718725 .remove = nfsd4_remove_clid_dir,
719726 .check = nfsd4_check_legacy_client,
720727 .grace_done = nfsd4_recdir_purge_old,
728+ .version = 1,
729+ .msglen = 0,
721730 };
722731
723732 /* Globals */
@@ -731,25 +740,32 @@ struct cld_net { · 7 unmodified lines
731740 struct list_head cn_list;
732741 unsigned int cn_xid;
733742 bool cn_has_legacy;
743+ struct crypto_shash *cn_tfm;
734744 };
735745
736746 struct cld_upcall {
737747 struct list_head cu_list;
738748 struct cld_net *cu_net;
739749 struct completion cu_done;
740− struct cld_msg cu_msg;
750+ union {
751+ struct cld_msg_hdr cu_hdr;
752+ struct cld_msg cu_msg;
753+ struct cld_msg_v2 cu_msg_v2;
754+ } cu_u;
741755 };
742756
743757 static int
744−__cld_pipe_upcall(struct rpc_pipe *pipe, struct cld_msg *cmsg)
758+__cld_pipe_upcall(struct rpc_pipe *pipe, void *cmsg)
745759 {
746760 int ret;
747761 struct rpc_pipe_msg msg;
748− struct cld_upcall *cup = container_of(cmsg, struct cld_upcall, cu_msg);
762+ struct cld_upcall *cup = container_of(cmsg, struct cld_upcall, cu_u);
763+ struct nfsd_net *nn = net_generic(pipe->dentry->d_sb->s_fs_info,
764+ nfsd_net_id);
749765
750766 memset(&msg, 0, sizeof(msg));
751767 msg.data = cmsg;
752− msg.len = sizeof(*cmsg);
768+ msg.len = nn->client_tracking_ops->msglen;
753769
754770 ret = rpc_queue_upcall(pipe, &msg);
755771 if (ret < 0) {
@@ -765,7 +781,7 @@ out: · 9 unmodified lines
765781 }
766782
767783 static int
768−cld_pipe_upcall(struct rpc_pipe *pipe, struct cld_msg *cmsg)
784+cld_pipe_upcall(struct rpc_pipe *pipe, void *cmsg)
769785 {
770786 int ret;
771787
@@ -781,11 +797,11 @@ cld_pipe_upcall(struct rpc_pipe *pipe, struct cld_msg *cmsg) · 9 unmodified lines
781797 }
782798
783799 static ssize_t
784−__cld_pipe_inprogress_downcall(const struct cld_msg __user *cmsg,
800+__cld_pipe_inprogress_downcall(const struct cld_msg_v2 __user *cmsg,
785801 struct nfsd_net *nn)
786802 {
787− uint8_t cmd;
788− struct xdr_netobj name;
803+ uint8_t cmd, princhashlen;
804+ struct xdr_netobj name, princhash = { .len = 0, .data = NULL };
789805 uint16_t namelen;
790806 struct cld_net *cn = nn->cld_net;
791807
@@ -794,22 +810,48 @@ __cld_pipe_inprogress_downcall(const struct cld_msg __user *cmsg, · 2 unmodified lines
794810 return -EFAULT;
795811 }
796812 if (cmd == Cld_GraceStart) {
797− if (get_user(namelen, &cmsg->cm_u.cm_name.cn_len))
798− return -EFAULT;
799− name.data = memdup_user(&cmsg->cm_u.cm_name.cn_id, namelen);
800− if (IS_ERR_OR_NULL(name.data))
801− return -EFAULT;
802− name.len = namelen;
813+ if (nn->client_tracking_ops->version >= 2) {
814+ const struct cld_clntinfo __user *ci;
815+
816+ ci = &cmsg->cm_u.cm_clntinfo;
817+ if (get_user(namelen, &ci->cc_name.cn_len))
818+ return -EFAULT;
819+ name.data = memdup_user(&ci->cc_name.cn_id, namelen);
820+ if (IS_ERR_OR_NULL(name.data))
821+ return -EFAULT;
822+ name.len = namelen;
823+ get_user(princhashlen, &ci->cc_princhash.cp_len);
824+ if (princhashlen > 0) {
825+ princhash.data = memdup_user(
826+ &ci->cc_princhash.cp_data,
827+ princhashlen);
828+ if (IS_ERR_OR_NULL(princhash.data))
829+ return -EFAULT;
830+ princhash.len = princhashlen;
831+ } else
832+ princhash.len = 0;
833+ } else {
834+ const struct cld_name __user *cnm;
835+
836+ cnm = &cmsg->cm_u.cm_name;
837+ if (get_user(namelen, &cnm->cn_len))
838+ return -EFAULT;
839+ name.data = memdup_user(&cnm->cn_id, namelen);
840+ if (IS_ERR_OR_NULL(name.data))
841+ return -EFAULT;
842+ name.len = namelen;
843+ }
803844 if (name.len > 5 && memcmp(name.data, "hash:", 5) == 0) {
804845 name.len = name.len - 5;
805846 memmove(name.data, name.data + 5, name.len);
806847 cn->cn_has_legacy = true;
807848 }
808− if (!nfs4_client_to_reclaim(name, nn)) {
849+ if (!nfs4_client_to_reclaim(name, princhash, nn)) {
809850 kfree(name.data);
851+ kfree(princhash.data);
810852 return -EFAULT;
811853 }
812− return sizeof(*cmsg);
854+ return nn->client_tracking_ops->msglen;
813855 }
814856 return -EFAULT;
815857 }
@@ -818,21 +860,22 @@ static ssize_t · 2 unmodified lines
818860 cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
819861 {
820862 struct cld_upcall *tmp, *cup;
821− struct cld_msg __user *cmsg = (struct cld_msg __user *)src;
863+ struct cld_msg_hdr __user *hdr = (struct cld_msg_hdr __user *)src;
864+ struct cld_msg_v2 __user *cmsg = (struct cld_msg_v2 __user *)src;
822865 uint32_t xid;
823866 struct nfsd_net *nn = net_generic(file_inode(filp)->i_sb->s_fs_info,
824867 nfsd_net_id);
825868 struct cld_net *cn = nn->cld_net;
826869 int16_t status;
827870
828− if (mlen != sizeof(*cmsg)) {
871+ if (mlen != nn->client_tracking_ops->msglen) {
829872 dprintk("%s: got %zu bytes, expected %zu\n", __func__, mlen,
830− sizeof(*cmsg));
873+ nn->client_tracking_ops->msglen);
831874 return -EINVAL;
832875 }
833876
834877 /* copy just the xid so we can try to find that */
835− if (copy_from_user(&xid, &cmsg->cm_xid, sizeof(xid)) != 0) {
878+ if (copy_from_user(&xid, &hdr->cm_xid, sizeof(xid)) != 0) {
836879 dprintk("%s: error when copying xid from userspace", __func__);
837880 return -EFAULT;
838881 }
@@ -842,7 +885,7 @@ cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) · 3 unmodified lines
842885 * list (for -EINPROGRESS, we just want to make sure the xid is
843886 * valid, not remove the upcall from the list)
844887 */
845− if (get_user(status, &cmsg->cm_status)) {
888+ if (get_user(status, &hdr->cm_status)) {
846889 dprintk("%s: error when copying status from userspace", __func__);
847890 return -EFAULT;
848891 }
@@ -851,7 +894,7 @@ cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) · 2 unmodified lines
851894 cup = NULL;
852895 spin_lock(&cn->cn_lock);
853896 list_for_each_entry(tmp, &cn->cn_list, cu_list) {
854− if (get_unaligned(&tmp->cu_msg.cm_xid) == xid) {
897+ if (get_unaligned(&tmp->cu_u.cu_hdr.cm_xid) == xid) {
855898 cup = tmp;
856899 if (status != -EINPROGRESS)
857900 list_del_init(&cup->cu_list);
@@ -869,7 +912,7 @@ cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) · 11 unmodified lines
869912 if (status == -EINPROGRESS)
870913 return __cld_pipe_inprogress_downcall(cmsg, nn);
871914
872− if (copy_from_user(&cup->cu_msg, src, mlen) != 0)
915+ if (copy_from_user(&cup->cu_u.cu_msg_v2, src, mlen) != 0)
873916 return -EFAULT;
874917
875918 complete(&cup->cu_done);
@@ -881,7 +924,7 @@ cld_pipe_destroy_msg(struct rpc_pipe_msg *msg) · 5 unmodified lines
881924 {
882925 struct cld_msg *cmsg = msg->data;
883926 struct cld_upcall *cup = container_of(cmsg, struct cld_upcall,
884− cu_msg);
927+ cu_u.cu_msg);
885928
886929 /* errno >= 0 means we got a downcall */
887930 if (msg->errno >= 0)
@@ -1007,14 +1050,17 @@ nfsd4_remove_cld_pipe(struct net *net) · 119 unmodified lines
10071050
10081051 nfsd4_cld_unregister_net(net, cn->cn_pipe);
10091052 rpc_destroy_pipe_data(cn->cn_pipe);
1053+ if (cn->cn_tfm)
1054+ crypto_free_shash(cn->cn_tfm);
10101055 kfree(nn->cld_net);
10111056 nn->cld_net = NULL;
10121057 }
10131058
10141059 static struct cld_upcall *
1015−alloc_cld_upcall(struct cld_net *cn)
1060+alloc_cld_upcall(struct nfsd_net *nn)
10161061 {
10171062 struct cld_upcall *new, *tmp;
1063+ struct cld_net *cn = nn->cld_net;
10181064
10191065 new = kzalloc(sizeof(*new), GFP_KERNEL);
10201066 if (!new)
@@ -1024,20 +1070,20 @@ alloc_cld_upcall(struct cld_net *cn) · 3 unmodified lines
10241070 restart_search:
10251071 spin_lock(&cn->cn_lock);
10261072 list_for_each_entry(tmp, &cn->cn_list, cu_list) {
1027− if (tmp->cu_msg.cm_xid == cn->cn_xid) {
1073+ if (tmp->cu_u.cu_msg.cm_xid == cn->cn_xid) {
10281074 cn->cn_xid++;
10291075 spin_unlock(&cn->cn_lock);
10301076 goto restart_search;
10311077 }
10321078 }
10331079 init_completion(&new->cu_done);
1034− new->cu_msg.cm_vers = CLD_UPCALL_VERSION;
1035− put_unaligned(cn->cn_xid++, &new->cu_msg.cm_xid);
1080+ new->cu_u.cu_msg.cm_vers = nn->client_tracking_ops->version;
1081+ put_unaligned(cn->cn_xid++, &new->cu_u.cu_msg.cm_xid);
10361082 new->cu_net = cn;
10371083 list_add(&new->cu_list, &cn->cn_list);
10381084 spin_unlock(&cn->cn_lock);
10391085
1040− dprintk("%s: allocated xid %u\n", __func__, new->cu_msg.cm_xid);
1086+ dprintk("%s: allocated xid %u\n", __func__, new->cu_u.cu_msg.cm_xid);
10411087
10421088 return new;
10431089 }
@@ -1066,20 +1112,20 @@ nfsd4_cld_create(struct nfs4_client *clp) · 22 unmodified lines
10661112 if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
10671113 return;
10681114
1069− cup = alloc_cld_upcall(cn);
1115+ cup = alloc_cld_upcall(nn);
10701116 if (!cup) {
10711117 ret = -ENOMEM;
10721118 goto out_err;
10731119 }
10741120
1075− cup->cu_msg.cm_cmd = Cld_Create;
1076− cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
1077− memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
1121+ cup->cu_u.cu_msg.cm_cmd = Cld_Create;
1122+ cup->cu_u.cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
1123+ memcpy(cup->cu_u.cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
10781124 clp->cl_name.len);
10791125
1080− ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1126+ ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg);
10811127 if (!ret) {
1082− ret = cup->cu_msg.cm_status;
1128+ ret = cup->cu_u.cu_msg.cm_status;
10831129 set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
10841130 }
10851131
@@ -1090,6 +1136,75 @@ out_err: · 4 unmodified lines
10901136 "record on stable storage: %d\n", ret);
10911137 }
10921138
1139+/* Ask daemon to create a new record */
1140+static void
1141+nfsd4_cld_create_v2(struct nfs4_client *clp)
1142+{
1143+ int ret;
1144+ struct cld_upcall *cup;
1145+ struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
1146+ struct cld_net *cn = nn->cld_net;
1147+ struct cld_msg_v2 *cmsg;
1148+ struct crypto_shash *tfm = cn->cn_tfm;
1149+ struct xdr_netobj cksum;
1150+ char *principal = NULL;
1151+ SHASH_DESC_ON_STACK(desc, tfm);
1152+
1153+ /* Don't upcall if it's already stored */
1154+ if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
1155+ return;
1156+
1157+ cup = alloc_cld_upcall(nn);
1158+ if (!cup) {
1159+ ret = -ENOMEM;
1160+ goto out_err;
1161+ }
1162+
1163+ cmsg = &cup->cu_u.cu_msg_v2;
1164+ cmsg->cm_cmd = Cld_Create;
1165+ cmsg->cm_u.cm_clntinfo.cc_name.cn_len = clp->cl_name.len;
1166+ memcpy(cmsg->cm_u.cm_clntinfo.cc_name.cn_id, clp->cl_name.data,
1167+ clp->cl_name.len);
1168+ if (clp->cl_cred.cr_raw_principal)
1169+ principal = clp->cl_cred.cr_raw_principal;
1170+ else if (clp->cl_cred.cr_principal)
1171+ principal = clp->cl_cred.cr_principal;
1172+ if (principal) {
1173+ desc->tfm = tfm;
1174+ cksum.len = crypto_shash_digestsize(tfm);
1175+ cksum.data = kmalloc(cksum.len, GFP_KERNEL);
1176+ if (cksum.data == NULL) {
1177+ ret = -ENOMEM;
1178+ goto out;
1179+ }
1180+ ret = crypto_shash_digest(desc, principal, strlen(principal),
1181+ cksum.data);
1182+ shash_desc_zero(desc);
1183+ if (ret) {
1184+ kfree(cksum.data);
1185+ goto out;
1186+ }
1187+ cmsg->cm_u.cm_clntinfo.cc_princhash.cp_len = cksum.len;
1188+ memcpy(cmsg->cm_u.cm_clntinfo.cc_princhash.cp_data,
1189+ cksum.data, cksum.len);
1190+ kfree(cksum.data);
1191+ } else
1192+ cmsg->cm_u.cm_clntinfo.cc_princhash.cp_len = 0;
1193+
1194+ ret = cld_pipe_upcall(cn->cn_pipe, cmsg);
1195+ if (!ret) {
1196+ ret = cmsg->cm_status;
1197+ set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
1198+ }
1199+
1200+out:
1201+ free_cld_upcall(cup);
1202+out_err:
1203+ if (ret)
1204+ pr_err("NFSD: Unable to create client record on stable storage: %d\n",
1205+ ret);
1206+}
1207+
10931208 /* Ask daemon to create a new record */
10941209 static void
10951210 nfsd4_cld_remove(struct nfs4_client *clp)
@@ -1103,20 +1218,20 @@ nfsd4_cld_remove(struct nfs4_client *clp) · 7 unmodified lines
11031218 if (!test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
11041219 return;
11051220
1106− cup = alloc_cld_upcall(cn);
1221+ cup = alloc_cld_upcall(nn);
11071222 if (!cup) {
11081223 ret = -ENOMEM;
11091224 goto out_err;
11101225 }
11111226
1112− cup->cu_msg.cm_cmd = Cld_Remove;
1113− cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
1114− memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
1227+ cup->cu_u.cu_msg.cm_cmd = Cld_Remove;
1228+ cup->cu_u.cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
1229+ memcpy(cup->cu_u.cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
11151230 clp->cl_name.len);
11161231
1117− ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1232+ ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg);
11181233 if (!ret) {
1119− ret = cup->cu_msg.cm_status;
1234+ ret = cup->cu_u.cu_msg.cm_status;
11201235 clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
11211236 }
11221237
@@ -1145,21 +1260,21 @@ nfsd4_cld_check_v0(struct nfs4_client *clp) · 22 unmodified lines
11451260 if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
11461261 return 0;
11471262
1148− cup = alloc_cld_upcall(cn);
1263+ cup = alloc_cld_upcall(nn);
11491264 if (!cup) {
11501265 printk(KERN_ERR "NFSD: Unable to check client record on "
11511266 "stable storage: %d\n", -ENOMEM);
11521267 return -ENOMEM;
11531268 }
11541269
1155− cup->cu_msg.cm_cmd = Cld_Check;
1156− cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
1157− memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
1270+ cup->cu_u.cu_msg.cm_cmd = Cld_Check;
1271+ cup->cu_u.cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
1272+ memcpy(cup->cu_u.cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
11581273 clp->cl_name.len);
11591274
1160− ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1275+ ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg);
11611276 if (!ret) {
1162− ret = cup->cu_msg.cm_status;
1277+ ret = cup->cu_u.cu_msg.cm_status;
11631278 set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
11641279 }
11651280
@@ -1216,6 +1331,79 @@ found: · 50 unmodified lines
12161331 return 0;
12171332 }
12181333
1334+static int
1335+nfsd4_cld_check_v2(struct nfs4_client *clp)
1336+{
1337+ struct nfs4_client_reclaim *crp;
1338+ struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
1339+ struct cld_net *cn = nn->cld_net;
1340+ int status;
1341+ char dname[HEXDIR_LEN];
1342+ struct xdr_netobj name;
1343+ struct crypto_shash *tfm = cn->cn_tfm;
1344+ struct xdr_netobj cksum;
1345+ char *principal = NULL;
1346+ SHASH_DESC_ON_STACK(desc, tfm);
1347+
1348+ /* did we already find that this client is stable? */
1349+ if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
1350+ return 0;
1351+
1352+ /* look for it in the reclaim hashtable otherwise */
1353+ crp = nfsd4_find_reclaim_client(clp->cl_name, nn);
1354+ if (crp)
1355+ goto found;
1356+
1357+ if (cn->cn_has_legacy) {
1358+ status = nfs4_make_rec_clidname(dname, &clp->cl_name);
1359+ if (status)
1360+ return -ENOENT;
1361+
1362+ name.data = kmemdup(dname, HEXDIR_LEN, GFP_KERNEL);
1363+ if (!name.data) {
1364+ dprintk("%s: failed to allocate memory for name.data\n",
1365+ __func__);
1366+ return -ENOENT;
1367+ }
1368+ name.len = HEXDIR_LEN;
1369+ crp = nfsd4_find_reclaim_client(name, nn);
1370+ kfree(name.data);
1371+ if (crp)
1372+ goto found;
1373+
1374+ }
1375+ return -ENOENT;
1376+found:
1377+ if (crp->cr_princhash.len) {
1378+ if (clp->cl_cred.cr_raw_principal)
1379+ principal = clp->cl_cred.cr_raw_principal;
1380+ else if (clp->cl_cred.cr_principal)
1381+ principal = clp->cl_cred.cr_principal;
1382+ if (principal == NULL)
1383+ return -ENOENT;
1384+ desc->tfm = tfm;
1385+ cksum.len = crypto_shash_digestsize(tfm);
1386+ cksum.data = kmalloc(cksum.len, GFP_KERNEL);
1387+ if (cksum.data == NULL)
1388+ return -ENOENT;
1389+ status = crypto_shash_digest(desc, principal, strlen(principal),
1390+ cksum.data);
1391+ shash_desc_zero(desc);
1392+ if (status) {
1393+ kfree(cksum.data);
1394+ return -ENOENT;
1395+ }
1396+ if (memcmp(crp->cr_princhash.data, cksum.data,
1397+ crp->cr_princhash.len)) {
1398+ kfree(cksum.data);
1399+ return -ENOENT;
1400+ }
1401+ kfree(cksum.data);
1402+ }
1403+ crp->cr_clp = clp;
1404+ return 0;
1405+}
1406+
12191407 static int
12201408 nfsd4_cld_grace_start(struct nfsd_net *nn)
12211409 {
@@ -1223,16 +1411,16 @@ nfsd4_cld_grace_start(struct nfsd_net *nn) · 1 unmodified line
12231411 struct cld_upcall *cup;
12241412 struct cld_net *cn = nn->cld_net;
12251413
1226− cup = alloc_cld_upcall(cn);
1414+ cup = alloc_cld_upcall(nn);
12271415 if (!cup) {
12281416 ret = -ENOMEM;
12291417 goto out_err;
12301418 }
12311419
1232− cup->cu_msg.cm_cmd = Cld_GraceStart;
1233− ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1420+ cup->cu_u.cu_msg.cm_cmd = Cld_GraceStart;
1421+ ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg);
12341422 if (!ret)
1235− ret = cup->cu_msg.cm_status;
1423+ ret = cup->cu_u.cu_msg.cm_status;
12361424
12371425 free_cld_upcall(cup);
12381426 out_err:
@@ -1250,17 +1438,17 @@ nfsd4_cld_grace_done_v0(struct nfsd_net *nn) · 11 unmodified lines
12501438 struct cld_upcall *cup;
12511439 struct cld_net *cn = nn->cld_net;
12521440
1253− cup = alloc_cld_upcall(cn);
1441+ cup = alloc_cld_upcall(nn);
12541442 if (!cup) {
12551443 ret = -ENOMEM;
12561444 goto out_err;
12571445 }
12581446
1259− cup->cu_msg.cm_cmd = Cld_GraceDone;
1260− cup->cu_msg.cm_u.cm_gracetime = (int64_t)nn->boot_time;
1261− ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1447+ cup->cu_u.cu_msg.cm_cmd = Cld_GraceDone;
1448+ cup->cu_u.cu_msg.cm_u.cm_gracetime = (int64_t)nn->boot_time;
1449+ ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg);
12621450 if (!ret)
1263− ret = cup->cu_msg.cm_status;
1451+ ret = cup->cu_u.cu_msg.cm_status;
12641452
12651453 free_cld_upcall(cup);
12661454 out_err:
@@ -1279,16 +1467,16 @@ nfsd4_cld_grace_done(struct nfsd_net *nn) · 12 unmodified lines
12791467 struct cld_upcall *cup;
12801468 struct cld_net *cn = nn->cld_net;
12811469
1282− cup = alloc_cld_upcall(cn);
1470+ cup = alloc_cld_upcall(nn);
12831471 if (!cup) {
12841472 ret = -ENOMEM;
12851473 goto out_err;
12861474 }
12871475
1288− cup->cu_msg.cm_cmd = Cld_GraceDone;
1289− ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1476+ cup->cu_u.cu_msg.cm_cmd = Cld_GraceDone;
1477+ ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg);
12901478 if (!ret)
1291− ret = cup->cu_msg.cm_status;
1479+ ret = cup->cu_u.cu_msg.cm_status;
12921480
12931481 free_cld_upcall(cup);
12941482 out_err:
@@ -1336,6 +1524,53 @@ cld_running(struct nfsd_net *nn) · 41 unmodified lines
13361524 return pipe->nreaders || pipe->nwriters;
13371525 }
13381526
1527+static int
1528+nfsd4_cld_get_version(struct nfsd_net *nn)
1529+{
1530+ int ret = 0;
1531+ struct cld_upcall *cup;
1532+ struct cld_net *cn = nn->cld_net;
1533+ uint8_t version;
1534+
1535+ cup = alloc_cld_upcall(nn);
1536+ if (!cup) {
1537+ ret = -ENOMEM;
1538+ goto out_err;
1539+ }
1540+ cup->cu_u.cu_msg.cm_cmd = Cld_GetVersion;
1541+ ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg);
1542+ if (!ret) {
1543+ ret = cup->cu_u.cu_msg.cm_status;
1544+ if (ret)
1545+ goto out_free;
1546+ version = cup->cu_u.cu_msg.cm_u.cm_version;
1547+ dprintk("%s: userspace returned version %u\n",
1548+ __func__, version);
1549+ if (version < 1)
1550+ version = 1;
1551+ else if (version > CLD_UPCALL_VERSION)
1552+ version = CLD_UPCALL_VERSION;
1553+
1554+ switch (version) {
1555+ case 1:
1556+ nn->client_tracking_ops = &nfsd4_cld_tracking_ops;
1557+ break;
1558+ case 2:
1559+ nn->client_tracking_ops = &nfsd4_cld_tracking_ops_v2;
1560+ break;
1561+ default:
1562+ break;
1563+ }
1564+ }
1565+out_free:
1566+ free_cld_upcall(cup);
1567+out_err:
1568+ if (ret)
1569+ dprintk("%s: Unable to get version from userspace: %d\n",
1570+ __func__, ret);
1571+ return ret;
1572+}
1573+
13391574 static int
13401575 nfsd4_cld_tracking_init(struct net *net)
13411576 {
@@ -1351,6 +1586,11 @@ nfsd4_cld_tracking_init(struct net *net) · 9 unmodified lines
13511586 status = __nfsd4_init_cld_pipe(net);
13521587 if (status)
13531588 goto err_shutdown;
1589+ nn->cld_net->cn_tfm = crypto_alloc_shash("sha256", 0, 0);
1590+ if (IS_ERR(nn->cld_net->cn_tfm)) {
1591+ status = PTR_ERR(nn->cld_net->cn_tfm);
1592+ goto err_remove;
1593+ }
13541594
13551595 /*
13561596 * rpc pipe upcalls take 30 seconds to time out, so we don't want to
@@ -1368,10 +1608,14 @@ nfsd4_cld_tracking_init(struct net *net) · 11 unmodified lines
13681608 goto err_remove;
13691609 }
13701610
1611+ status = nfsd4_cld_get_version(nn);
1612+ if (status == -EOPNOTSUPP)
1613+ pr_warn("NFSD: nfsdcld GetVersion upcall failed. Please upgrade nfsdcld.\n");
1614+
13711615 status = nfsd4_cld_grace_start(nn);
13721616 if (status) {
13731617 if (status == -EOPNOTSUPP)
1374− printk(KERN_WARNING "NFSD: Please upgrade nfsdcld.\n");
1618+ pr_warn("NFSD: nfsdcld GraceStart upcall failed. Please upgrade nfsdcld.\n");
13751619 nfs4_release_reclaim(nn);
13761620 goto err_remove;
13771621 } else
@@ -1403,6 +1647,8 @@ static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops_v0 = { · 25 unmodified lines
14031647 .remove = nfsd4_cld_remove,
14041648 .check = nfsd4_cld_check_v0,
14051649 .grace_done = nfsd4_cld_grace_done_v0,
1650+ .version = 1,
1651+ .msglen = sizeof(struct cld_msg),
14061652 };
14071653
14081654 /* For newer nfsdcld's */
@@ -1413,6 +1659,20 @@ static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops = { · 4 unmodified lines
14131659 .remove = nfsd4_cld_remove,
14141660 .check = nfsd4_cld_check,
14151661 .grace_done = nfsd4_cld_grace_done,
1662+ .version = 1,
1663+ .msglen = sizeof(struct cld_msg),
1664+};
1665+
1666+/* v2 create/check ops include the principal, if available */
1667+static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops_v2 = {
1668+ .init = nfsd4_cld_tracking_init,
1669+ .exit = nfsd4_cld_tracking_exit,
1670+ .create = nfsd4_cld_create_v2,
1671+ .remove = nfsd4_cld_remove,
1672+ .check = nfsd4_cld_check_v2,
1673+ .grace_done = nfsd4_cld_grace_done,
1674+ .version = 2,
1675+ .msglen = sizeof(struct cld_msg_v2),
14161676 };
14171677
14181678 /* upcall via usermodehelper */
@@ -1760,6 +2020,8 @@ static const struct nfsd4_client_tracking_ops nfsd4_umh_tracking_ops = { · 341 unmodified lines
17602020 .remove = nfsd4_umh_cltrack_remove,
17612021 .check = nfsd4_umh_cltrack_check,
17622022 .grace_done = nfsd4_umh_cltrack_grace_done,
2023+ .version = 1,
2024+ .msglen = 0,
17632025 };
17642026
17652027 int
fs/nfsd/nfs4state.c+130−109
@@ -50,6 +50,7 @@ · 49 unmodified lines
5050
5151 #include "netns.h"
5252 #include "pnfs.h"
53+#include "filecache.h"
5354
5455 #define NFSDDBG_FACILITY NFSDDBG_PROC
5556
@@ -429,18 +430,18 @@ put_nfs4_file(struct nfs4_file *fi) · 373 unmodified lines
429430 }
430431 }
431432
432−static struct file *
433+static struct nfsd_file *
433434 __nfs4_get_fd(struct nfs4_file *f, int oflag)
434435 {
435436 if (f->fi_fds[oflag])
436− return get_file(f->fi_fds[oflag]);
437+ return nfsd_file_get(f->fi_fds[oflag]);
437438 return NULL;
438439 }
439440
440−static struct file *
441+static struct nfsd_file *
441442 find_writeable_file_locked(struct nfs4_file *f)
442443 {
443− struct file *ret;
444+ struct nfsd_file *ret;
444445
445446 lockdep_assert_held(&f->fi_lock);
446447
@@ -450,10 +451,10 @@ find_writeable_file_locked(struct nfs4_file *f) · 3 unmodified lines
450451 return ret;
451452 }
452453
453−static struct file *
454+static struct nfsd_file *
454455 find_writeable_file(struct nfs4_file *f)
455456 {
456− struct file *ret;
457+ struct nfsd_file *ret;
457458
458459 spin_lock(&f->fi_lock);
459460 ret = find_writeable_file_locked(f);
@@ -462,9 +463,10 @@ find_writeable_file(struct nfs4_file *f) · 2 unmodified lines
462463 return ret;
463464 }
464465
465−static struct file *find_readable_file_locked(struct nfs4_file *f)
466+static struct nfsd_file *
467+find_readable_file_locked(struct nfs4_file *f)
466468 {
467− struct file *ret;
469+ struct nfsd_file *ret;
468470
469471 lockdep_assert_held(&f->fi_lock);
470472
@@ -474,10 +476,10 @@ static struct file *find_readable_file_locked(struct nfs4_file *f) · 3 unmodified lines
474476 return ret;
475477 }
476478
477−static struct file *
479+static struct nfsd_file *
478480 find_readable_file(struct nfs4_file *f)
479481 {
480− struct file *ret;
482+ struct nfsd_file *ret;
481483
482484 spin_lock(&f->fi_lock);
483485 ret = find_readable_file_locked(f);
@@ -486,10 +488,10 @@ find_readable_file(struct nfs4_file *f) · 2 unmodified lines
486488 return ret;
487489 }
488490
489−struct file *
491+struct nfsd_file *
490492 find_any_file(struct nfs4_file *f)
491493 {
492− struct file *ret;
494+ struct nfsd_file *ret;
493495
494496 spin_lock(&f->fi_lock);
495497 ret = __nfs4_get_fd(f, O_RDWR);
@@ -590,17 +592,17 @@ static void __nfs4_file_put_access(struct nfs4_file *fp, int oflag) · 94 unmodified lines
590592 might_lock(&fp->fi_lock);
591593
592594 if (atomic_dec_and_lock(&fp->fi_access[oflag], &fp->fi_lock)) {
593− struct file *f1 = NULL;
594− struct file *f2 = NULL;
595+ struct nfsd_file *f1 = NULL;
596+ struct nfsd_file *f2 = NULL;
595597
596598 swap(f1, fp->fi_fds[oflag]);
597599 if (atomic_read(&fp->fi_access[1 - oflag]) == 0)
598600 swap(f2, fp->fi_fds[O_RDWR]);
599601 spin_unlock(&fp->fi_lock);
600602 if (f1)
601− fput(f1);
603+ nfsd_file_put(f1);
602604 if (f2)
603− fput(f2);
605+ nfsd_file_put(f2);
604606 }
605607 }
606608
@@ -933,25 +935,25 @@ nfs4_inc_and_copy_stateid(stateid_t *dst, struct nfs4_stid *stid) · 326 unmodified lines
933935
934936 static void put_deleg_file(struct nfs4_file *fp)
935937 {
936− struct file *filp = NULL;
938+ struct nfsd_file *nf = NULL;
937939
938940 spin_lock(&fp->fi_lock);
939941 if (--fp->fi_delegees == 0)
940− swap(filp, fp->fi_deleg_file);
942+ swap(nf, fp->fi_deleg_file);
941943 spin_unlock(&fp->fi_lock);
942944
943− if (filp)
944− fput(filp);
945+ if (nf)
946+ nfsd_file_put(nf);
945947 }
946948
947949 static void nfs4_unlock_deleg_lease(struct nfs4_delegation *dp)
948950 {
949951 struct nfs4_file *fp = dp->dl_stid.sc_file;
950− struct file *filp = fp->fi_deleg_file;
952+ struct nfsd_file *nf = fp->fi_deleg_file;
951953
952954 WARN_ON_ONCE(!fp->fi_delegees);
953955
954− vfs_setlease(filp, F_UNLCK, NULL, (void **)&dp);
956+ vfs_setlease(nf->nf_file, F_UNLCK, NULL, (void **)&dp);
955957 put_deleg_file(fp);
956958 }
957959
@@ -1289,11 +1291,14 @@ static void nfs4_free_lock_stateid(struct nfs4_stid *stid) · 331 unmodified lines
12891291 {
12901292 struct nfs4_ol_stateid *stp = openlockstateid(stid);
12911293 struct nfs4_lockowner *lo = lockowner(stp->st_stateowner);
1292− struct file *file;
1294+ struct nfsd_file *nf;
12931295
1294− file = find_any_file(stp->st_stid.sc_file);
1295− if (file)
1296− filp_close(file, (fl_owner_t)lo);
1296+ nf = find_any_file(stp->st_stid.sc_file);
1297+ if (nf) {
1298+ get_file(nf->nf_file);
1299+ filp_close(nf->nf_file, (fl_owner_t)lo);
1300+ nfsd_file_put(nf);
1301+ }
12971302 nfs4_free_ol_stateid(stid);
12981303 }
12991304
@@ -1563,21 +1568,39 @@ static inline u32 slot_bytes(struct nfsd4_channel_attrs *ca) · 263 unmodified lines
15631568 * re-negotiate active sessions and reduce their slot usage to make
15641569 * room for new connections. For now we just fail the create session.
15651570 */
1566−static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca)
1571+static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca, struct nfsd_net *nn)
15671572 {
15681573 u32 slotsize = slot_bytes(ca);
15691574 u32 num = ca->maxreqs;
15701575 unsigned long avail, total_avail;
1576+ unsigned int scale_factor;
15711577
15721578 spin_lock(&nfsd_drc_lock);
1573− total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used;
1579+ if (nfsd_drc_max_mem > nfsd_drc_mem_used)
1580+ total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used;
1581+ else
1582+ /* We have handed out more space than we chose in
1583+ * set_max_drc() to allow. That isn't really a
1584+ * problem as long as that doesn't make us think we
1585+ * have lots more due to integer overflow.
1586+ */
1587+ total_avail = 0;
15741588 avail = min((unsigned long)NFSD_MAX_MEM_PER_SESSION, total_avail);
15751589 /*
1576− * Never use more than a third of the remaining memory,
1577− * unless it's the only way to give this client a slot:
1590+ * Never use more than a fraction of the remaining memory,
1591+ * unless it's the only way to give this client a slot.
1592+ * The chosen fraction is either 1/8 or 1/number of threads,
1593+ * whichever is smaller. This ensures there are adequate
1594+ * slots to support multiple clients per thread.
1595+ * Give the client one slot even if that would require
1596+ * over-allocation--it is better than failure.
15781597 */
1579− avail = clamp_t(unsigned long, avail, slotsize, total_avail/3);
1598+ scale_factor = max_t(unsigned int, 8, nn->nfsd_serv->sv_nrthreads);
1599+
1600+ avail = clamp_t(unsigned long, avail, slotsize,
1601+ total_avail/scale_factor);
15801602 num = min_t(int, num, avail / slotsize);
1603+ num = max_t(int, num, 1);
15811604 nfsd_drc_mem_used += num * slotsize;
15821605 spin_unlock(&nfsd_drc_lock);
15831606
@@ -2323,9 +2346,9 @@ static void states_stop(struct seq_file *s, void *v) · 739 unmodified lines
23232346 spin_unlock(&clp->cl_lock);
23242347 }
23252348
2326−static void nfs4_show_superblock(struct seq_file *s, struct file *f)
2349+static void nfs4_show_superblock(struct seq_file *s, struct nfsd_file *f)
23272350 {
2328− struct inode *inode = file_inode(f);
2351+ struct inode *inode = f->nf_inode;
23292352
23302353 seq_printf(s, "superblock: \"%02x:%02x:%ld\"",
23312354 MAJOR(inode->i_sb->s_dev),
@@ -2343,7 +2366,7 @@ static int nfs4_show_open(struct seq_file *s, struct nfs4_stid *st) · 11 unmodified lines
23432366 {
23442367 struct nfs4_ol_stateid *ols;
23452368 struct nfs4_file *nf;
2346− struct file *file;
2369+ struct nfsd_file *file;
23472370 struct nfs4_stateowner *oo;
23482371 unsigned int access, deny;
23492372
@@ -2370,7 +2393,7 @@ static int nfs4_show_open(struct seq_file *s, struct nfs4_stid *st) · 20 unmodified lines
23702393 seq_printf(s, ", ");
23712394 nfs4_show_owner(s, oo);
23722395 seq_printf(s, " }\n");
2373− fput(file);
2396+ nfsd_file_put(file);
23742397
23752398 return 0;
23762399 }
@@ -2379,7 +2402,7 @@ static int nfs4_show_lock(struct seq_file *s, struct nfs4_stid *st) · 2 unmodified lines
23792402 {
23802403 struct nfs4_ol_stateid *ols;
23812404 struct nfs4_file *nf;
2382− struct file *file;
2405+ struct nfsd_file *file;
23832406 struct nfs4_stateowner *oo;
23842407
23852408 ols = openlockstateid(st);
@@ -2401,7 +2424,7 @@ static int nfs4_show_lock(struct seq_file *s, struct nfs4_stid *st) · 15 unmodified lines
24012424 seq_printf(s, ", ");
24022425 nfs4_show_owner(s, oo);
24032426 seq_printf(s, " }\n");
2404− fput(file);
2427+ nfsd_file_put(file);
24052428
24062429 return 0;
24072430 }
@@ -2410,7 +2433,7 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st) · 2 unmodified lines
24102433 {
24112434 struct nfs4_delegation *ds;
24122435 struct nfs4_file *nf;
2413− struct file *file;
2436+ struct nfsd_file *file;
24142437
24152438 ds = delegstateid(st);
24162439 nf = st->sc_file;
@@ -2433,7 +2456,7 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st) · 16 unmodified lines
24332456 static int nfs4_show_layout(struct seq_file *s, struct nfs4_stid *st)
24342457 {
24352458 struct nfs4_layout_stateid *ls;
2436− struct file *file;
2459+ struct nfsd_file *file;
24372460
24382461 ls = container_of(st, struct nfs4_layout_stateid, ls_stid);
24392462 file = ls->ls_file;
@@ -3169,10 +3192,10 @@ static __be32 check_forechannel_attrs(struct nfsd4_channel_attrs *ca, struct nfs · 729 unmodified lines
31693192 * performance. When short on memory we therefore prefer to
31703193 * decrease number of slots instead of their size. Clients that
31713194 * request larger slots than they need will get poor results:
3195+ * Note that we always allow at least one slot, because our
3196+ * accounting is soft and provides no guarantees either way.
31723197 */
3173− ca->maxreqs = nfsd4_get_drc_mem(ca);
3174− if (!ca->maxreqs)
3175− return nfserr_jukebox;
3198+ ca->maxreqs = nfsd4_get_drc_mem(ca, nn);
31763199
31773200 return nfs_ok;
31783201 }
@@ -4651,7 +4674,7 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp, · 1472 unmodified lines
46514674 struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp,
46524675 struct nfsd4_open *open)
46534676 {
4654− struct file *filp = NULL;
4677+ struct nfsd_file *nf = NULL;
46554678 __be32 status;
46564679 int oflag = nfs4_access_to_omode(open->op_share_access);
46574680 int access = nfs4_access_to_access(open->op_share_access);
@@ -4687,18 +4710,18 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp, · 29 unmodified lines
46874710
46884711 if (!fp->fi_fds[oflag]) {
46894712 spin_unlock(&fp->fi_lock);
4690− status = nfsd_open(rqstp, cur_fh, S_IFREG, access, &filp);
4713+ status = nfsd_file_acquire(rqstp, cur_fh, access, &nf);
46914714 if (status)
46924715 goto out_put_access;
46934716 spin_lock(&fp->fi_lock);
46944717 if (!fp->fi_fds[oflag]) {
4695− fp->fi_fds[oflag] = filp;
4696− filp = NULL;
4718+ fp->fi_fds[oflag] = nf;
4719+ nf = NULL;
46974720 }
46984721 }
46994722 spin_unlock(&fp->fi_lock);
4700− if (filp)
4701− fput(filp);
4723+ if (nf)
4724+ nfsd_file_put(nf);
47024725
47034726 status = nfsd4_truncate(rqstp, cur_fh, open);
47044727 if (status)
@@ -4767,7 +4790,7 @@ static struct file_lock *nfs4_alloc_init_lease(struct nfs4_delegation *dp, · 62 unmodified lines
47674790 fl->fl_end = OFFSET_MAX;
47684791 fl->fl_owner = (fl_owner_t)dp;
47694792 fl->fl_pid = current->tgid;
4770− fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file;
4793+ fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file;
47714794 return fl;
47724795 }
47734796
@@ -4777,7 +4800,7 @@ nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh, · 3 unmodified lines
47774800 {
47784801 int status = 0;
47794802 struct nfs4_delegation *dp;
4780− struct file *filp;
4803+ struct nfsd_file *nf;
47814804 struct file_lock *fl;
47824805
47834806 /*
@@ -4788,8 +4811,8 @@ nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh, · 4 unmodified lines
47884811 if (fp->fi_had_conflict)
47894812 return ERR_PTR(-EAGAIN);
47904813
4791− filp = find_readable_file(fp);
4792− if (!filp) {
4814+ nf = find_readable_file(fp);
4815+ if (!nf) {
47934816 /* We should always have a readable file here */
47944817 WARN_ON_ONCE(1);
47954818 return ERR_PTR(-EBADF);
@@ -4799,17 +4822,17 @@ nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh, · 3 unmodified lines
47994822 if (nfs4_delegation_exists(clp, fp))
48004823 status = -EAGAIN;
48014824 else if (!fp->fi_deleg_file) {
4802− fp->fi_deleg_file = filp;
4825+ fp->fi_deleg_file = nf;
48034826 /* increment early to prevent fi_deleg_file from being
48044827 * cleared */
48054828 fp->fi_delegees = 1;
4806− filp = NULL;
4829+ nf = NULL;
48074830 } else
48084831 fp->fi_delegees++;
48094832 spin_unlock(&fp->fi_lock);
48104833 spin_unlock(&state_lock);
4811− if (filp)
4812− fput(filp);
4834+ if (nf)
4835+ nfsd_file_put(nf);
48134836 if (status)
48144837 return ERR_PTR(status);
48154838
@@ -4822,7 +4845,7 @@ nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh, · 6 unmodified lines
48224845 if (!fl)
48234846 goto out_clnt_odstate;
48244847
4825− status = vfs_setlease(fp->fi_deleg_file, fl->fl_type, &fl, NULL);
4848+ status = vfs_setlease(fp->fi_deleg_file->nf_file, fl->fl_type, &fl, NULL);
48264849 if (fl)
48274850 locks_free_lock(fl);
48284851 if (status)
@@ -4842,7 +4865,7 @@ nfs4_set_delegation(struct nfs4_client *clp, struct svc_fh *fh, · 13 unmodified lines
48424865
48434866 return dp;
48444867 out_unlock:
4845− vfs_setlease(fp->fi_deleg_file, F_UNLCK, NULL, (void **)&dp);
4868+ vfs_setlease(fp->fi_deleg_file->nf_file, F_UNLCK, NULL, (void **)&dp);
48464869 out_clnt_odstate:
48474870 put_clnt_odstate(dp->dl_clnt_odstate);
48484871 nfs4_put_stid(&dp->dl_stid);
@@ -5513,7 +5536,7 @@ nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate, · 664 unmodified lines
55135536 return nfs_ok;
55145537 }
55155538
5516−static struct file *
5539+static struct nfsd_file *
55175540 nfs4_find_file(struct nfs4_stid *s, int flags)
55185541 {
55195542 if (!s)
@@ -5523,7 +5546,7 @@ nfs4_find_file(struct nfs4_stid *s, int flags) · 3 unmodified lines
55235546 case NFS4_DELEG_STID:
55245547 if (WARN_ON_ONCE(!s->sc_file->fi_deleg_file))
55255548 return NULL;
5526− return get_file(s->sc_file->fi_deleg_file);
5549+ return nfsd_file_get(s->sc_file->fi_deleg_file);
55275550 case NFS4_OPEN_STID:
55285551 case NFS4_LOCK_STID:
55295552 if (flags & RD_STATE)
@@ -5549,32 +5572,28 @@ nfs4_check_olstateid(struct nfs4_ol_stateid *ols, int flags) · 19 unmodified lines
55495572
55505573 static __be32
55515574 nfs4_check_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfs4_stid *s,
5552− struct file **filpp, bool *tmp_file, int flags)
5575+ struct nfsd_file **nfp, int flags)
55535576 {
55545577 int acc = (flags & RD_STATE) ? NFSD_MAY_READ : NFSD_MAY_WRITE;
5555− struct file *file;
5578+ struct nfsd_file *nf;
55565579 __be32 status;
55575580
5558− file = nfs4_find_file(s, flags);
5559− if (file) {
5581+ nf = nfs4_find_file(s, flags);
5582+ if (nf) {
55605583 status = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry,
55615584 acc | NFSD_MAY_OWNER_OVERRIDE);
55625585 if (status) {
5563− fput(file);
5564− return status;
5586+ nfsd_file_put(nf);
5587+ goto out;
55655588 }
5566−
5567− *filpp = file;
55685589 } else {
5569− status = nfsd_open(rqstp, fhp, S_IFREG, acc, filpp);
5590+ status = nfsd_file_acquire(rqstp, fhp, acc, &nf);
55705591 if (status)
55715592 return status;
5572−
5573− if (tmp_file)
5574− *tmp_file = true;
55755593 }
5576−
5577− return 0;
5594+ *nfp = nf;
5595+out:
5596+ return status;
55785597 }
55795598
55805599 /*
@@ -5583,7 +5602,7 @@ nfs4_check_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfs4_stid *s, · 2 unmodified lines
55835602 __be32
55845603 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
55855604 struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
5586− stateid_t *stateid, int flags, struct file **filpp, bool *tmp_file)
5605+ stateid_t *stateid, int flags, struct nfsd_file **nfp)
55875606 {
55885607 struct inode *ino = d_inode(fhp->fh_dentry);
55895608 struct net *net = SVC_NET(rqstp);
@@ -5591,10 +5610,8 @@ nfs4_preprocess_stateid_op(struct svc_rqst *rqstp, · 1 unmodified line
55915610 struct nfs4_stid *s = NULL;
55925611 __be32 status;
55935612
5594− if (filpp)
5595− *filpp = NULL;
5596− if (tmp_file)
5597− *tmp_file = false;
5613+ if (nfp)
5614+ *nfp = NULL;
55985615
55995616 if (grace_disallows_io(net, ino))
56005617 return nfserr_grace;
@@ -5631,8 +5648,8 @@ nfs4_preprocess_stateid_op(struct svc_rqst *rqstp, · 30 unmodified lines
56315648 status = nfs4_check_fh(fhp, s);
56325649
56335650 done:
5634− if (!status && filpp)
5635− status = nfs4_check_file(rqstp, fhp, s, filpp, tmp_file, flags);
5651+ if (status == nfs_ok && nfp)
5652+ status = nfs4_check_file(rqstp, fhp, s, nfp, flags);
56365653 out:
56375654 if (s)
56385655 nfs4_put_stid(s);
@@ -6392,7 +6409,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 753 unmodified lines
63926409 struct nfs4_ol_stateid *lock_stp = NULL;
63936410 struct nfs4_ol_stateid *open_stp = NULL;
63946411 struct nfs4_file *fp;
6395− struct file *filp = NULL;
6412+ struct nfsd_file *nf = NULL;
63966413 struct nfsd4_blocked_lock *nbl = NULL;
63976414 struct file_lock *file_lock = NULL;
63986415 struct file_lock *conflock = NULL;
@@ -6474,8 +6491,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 75 unmodified lines
64746491 /* Fallthrough */
64756492 case NFS4_READ_LT:
64766493 spin_lock(&fp->fi_lock);
6477− filp = find_readable_file_locked(fp);
6478− if (filp)
6494+ nf = find_readable_file_locked(fp);
6495+ if (nf)
64796496 get_lock_access(lock_stp, NFS4_SHARE_ACCESS_READ);
64806497 spin_unlock(&fp->fi_lock);
64816498 fl_type = F_RDLCK;
@@ -6486,8 +6503,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 4 unmodified lines
64866503 /* Fallthrough */
64876504 case NFS4_WRITE_LT:
64886505 spin_lock(&fp->fi_lock);
6489− filp = find_writeable_file_locked(fp);
6490− if (filp)
6506+ nf = find_writeable_file_locked(fp);
6507+ if (nf)
64916508 get_lock_access(lock_stp, NFS4_SHARE_ACCESS_WRITE);
64926509 spin_unlock(&fp->fi_lock);
64936510 fl_type = F_WRLCK;
@@ -6497,7 +6514,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 3 unmodified lines
64976514 goto out;
64986515 }
64996516
6500− if (!filp) {
6517+ if (!nf) {
65016518 status = nfserr_openmode;
65026519 goto out;
65036520 }
@@ -6513,7 +6530,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 9 unmodified lines
65136530 file_lock->fl_type = fl_type;
65146531 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(&lock_sop->lo_owner));
65156532 file_lock->fl_pid = current->tgid;
6516− file_lock->fl_file = filp;
6533+ file_lock->fl_file = nf->nf_file;
65176534 file_lock->fl_flags = fl_flags;
65186535 file_lock->fl_lmops = &nfsd_posix_mng_ops;
65196536 file_lock->fl_start = lock->lk_offset;
@@ -6535,7 +6552,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 15 unmodified lines
65356552 spin_unlock(&nn->blocked_locks_lock);
65366553 }
65376554
6538− err = vfs_lock_file(filp, F_SETLK, file_lock, conflock);
6555+ err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, conflock);
65396556 switch (err) {
65406557 case 0: /* success! */
65416558 nfs4_inc_and_copy_stateid(&lock->lk_resp_stateid, &lock_stp->st_stid);
@@ -6570,8 +6587,8 @@ out: · 28 unmodified lines
65706587 }
65716588 free_blocked_lock(nbl);
65726589 }
6573− if (filp)
6574− fput(filp);
6590+ if (nf)
6591+ nfsd_file_put(nf);
65756592 if (lock_stp) {
65766593 /* Bump seqid manually if the 4.0 replay owner is openowner */
65776594 if (cstate->replay_owner &&
@@ -6606,11 +6623,11 @@ out: · 28 unmodified lines
66066623 */
66076624 static __be32 nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file_lock *lock)
66086625 {
6609− struct file *file;
6610− __be32 err = nfsd_open(rqstp, fhp, S_IFREG, NFSD_MAY_READ, &file);
6626+ struct nfsd_file *nf;
6627+ __be32 err = nfsd_file_acquire(rqstp, fhp, NFSD_MAY_READ, &nf);
66116628 if (!err) {
6612− err = nfserrno(vfs_test_lock(file, lock));
6613− fput(file);
6629+ err = nfserrno(vfs_test_lock(nf->nf_file, lock));
6630+ nfsd_file_put(nf);
66146631 }
66156632 return err;
66166633 }
@@ -6698,7 +6715,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 81 unmodified lines
66986715 {
66996716 struct nfsd4_locku *locku = &u->locku;
67006717 struct nfs4_ol_stateid *stp;
6701− struct file *filp = NULL;
6718+ struct nfsd_file *nf = NULL;
67026719 struct file_lock *file_lock = NULL;
67036720 __be32 status;
67046721 int err;
@@ -6716,8 +6733,8 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 11 unmodified lines
67166733 &stp, nn);
67176734 if (status)
67186735 goto out;
6719− filp = find_any_file(stp->st_stid.sc_file);
6720− if (!filp) {
6736+ nf = find_any_file(stp->st_stid.sc_file);
6737+ if (!nf) {
67216738 status = nfserr_lock_range;
67226739 goto put_stateid;
67236740 }
@@ -6725,13 +6742,13 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 1 unmodified line
67256742 if (!file_lock) {
67266743 dprintk("NFSD: %s: unable to allocate lock!\n", __func__);
67276744 status = nfserr_jukebox;
6728− goto fput;
6745+ goto put_file;
67296746 }
67306747
67316748 file_lock->fl_type = F_UNLCK;
67326749 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(stp->st_stateowner));
67336750 file_lock->fl_pid = current->tgid;
6734− file_lock->fl_file = filp;
6751+ file_lock->fl_file = nf->nf_file;
67356752 file_lock->fl_flags = FL_POSIX;
67366753 file_lock->fl_lmops = &nfsd_posix_mng_ops;
67376754 file_lock->fl_start = locku->lu_offset;
@@ -6740,14 +6757,14 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · 2 unmodified lines
67406757 locku->lu_length);
67416758 nfs4_transform_lock_offset(file_lock);
67426759
6743− err = vfs_lock_file(filp, F_SETLK, file_lock, NULL);
6760+ err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, NULL);
67446761 if (err) {
67456762 dprintk("NFSD: nfs4_locku: vfs_lock_file failed!\n");
67466763 goto out_nfserr;
67476764 }
67486765 nfs4_inc_and_copy_stateid(&locku->lu_stateid, &stp->st_stid);
6749−fput:
6750− fput(filp);
6766+put_file:
6767+ nfsd_file_put(nf);
67516768 put_stateid:
67526769 mutex_unlock(&stp->st_mutex);
67536770 nfs4_put_stid(&stp->st_stid);
@@ -6759,7 +6776,7 @@ out: · 5 unmodified lines
67596776
67606777 out_nfserr:
67616778 status = nfserrno(err);
6762− goto fput;
6779+ goto put_file;
67636780 }
67646781
67656782 /*
@@ -6772,17 +6789,17 @@ check_for_locks(struct nfs4_file *fp, struct nfs4_lockowner *lowner) · 6 unmodified lines
67726789 {
67736790 struct file_lock *fl;
67746791 int status = false;
6775− struct file *filp = find_any_file(fp);
6792+ struct nfsd_file *nf = find_any_file(fp);
67766793 struct inode *inode;
67776794 struct file_lock_context *flctx;
67786795
6779− if (!filp) {
6796+ if (!nf) {
67806797 /* Any valid lock stateid should have some sort of access */
67816798 WARN_ON_ONCE(1);
67826799 return status;
67836800 }
67846801
6785− inode = locks_inode(filp);
6802+ inode = locks_inode(nf->nf_file);
67866803 flctx = inode->i_flctx;
67876804
67886805 if (flctx && !list_empty_careful(&flctx->flc_posix)) {
@@ -6795,7 +6812,7 @@ check_for_locks(struct nfs4_file *fp, struct nfs4_lockowner *lowner) · 6 unmodified lines
67956812 }
67966813 spin_unlock(&flctx->flc_lock);
67976814 }
6798− fput(filp);
6815+ nfsd_file_put(nf);
67996816 return status;
68006817 }
68016818
@@ -6888,7 +6905,8 @@ nfs4_has_reclaimed_state(struct xdr_netobj name, struct nfsd_net *nn) · 86 unmodified lines
68886905 * will be freed in nfs4_remove_reclaim_record in the normal case).
68896906 */
68906907 struct nfs4_client_reclaim *
6891−nfs4_client_to_reclaim(struct xdr_netobj name, struct nfsd_net *nn)
6908+nfs4_client_to_reclaim(struct xdr_netobj name, struct xdr_netobj princhash,
6909+ struct nfsd_net *nn)
68926910 {
68936911 unsigned int strhashval;
68946912 struct nfs4_client_reclaim *crp;
@@ -6901,6 +6919,8 @@ nfs4_client_to_reclaim(struct xdr_netobj name, struct nfsd_net *nn) · 6 unmodified lines
69016919 list_add(&crp->cr_strhash, &nn->reclaim_str_hashtbl[strhashval]);
69026920 crp->cr_name.data = name.data;
69036921 crp->cr_name.len = name.len;
6922+ crp->cr_princhash.data = princhash.data;
6923+ crp->cr_princhash.len = princhash.len;
69046924 crp->cr_clp = NULL;
69056925 nn->reclaim_str_hashtbl_size++;
69066926 }
@@ -6912,6 +6932,7 @@ nfs4_remove_reclaim_record(struct nfs4_client_reclaim *crp, struct nfsd_net *nn) · 5 unmodified lines
69126932 {
69136933 list_del(&crp->cr_strhash);
69146934 kfree(crp->cr_name.data);
6935+ kfree(crp->cr_princhash.data);
69156936 kfree(crp);
69166937 nn->reclaim_str_hashtbl_size--;
69176938 }
fs/nfsd/nfs4xdr.c+29−27
@@ -49,6 +49,7 @@ · 48 unmodified lines
4949 #include "cache.h"
5050 #include "netns.h"
5151 #include "pnfs.h"
52+#include "filecache.h"
5253
5354 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
5455 #include <linux/security.h>
@@ -203,6 +204,13 @@ static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes) · 148 unmodified lines
203204 return p;
204205 }
205206
207+static unsigned int compoundargs_bytes_left(struct nfsd4_compoundargs *argp)
208+{
209+ unsigned int this = (char *)argp->end - (char *)argp->p;
210+
211+ return this + argp->pagelen;
212+}
213+
206214 static int zero_clientid(clientid_t *clid)
207215 {
208216 return (clid->cl_boot == 0) && (clid->cl_id == 0);
@@ -211,10 +219,10 @@ static int zero_clientid(clientid_t *clid) · 2 unmodified lines
211219 /**
212220 * svcxdr_tmpalloc - allocate memory to be freed after compound processing
213221 * @argp: NFSv4 compound argument structure
214− * @p: pointer to be freed (with kfree())
222+ * @len: length of buffer to allocate
215223 *
216− * Marks @p to be freed when processing the compound operation
217− * described in @argp finishes.
224+ * Allocates a buffer of size @len to be freed when processing the compound
225+ * operation described in @argp finishes.
218226 */
219227 static void *
220228 svcxdr_tmpalloc(struct nfsd4_compoundargs *argp, u32 len)
@@ -347,7 +355,12 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, · 126 unmodified lines
347355 READ_BUF(4); len += 4;
348356 nace = be32_to_cpup(p++);
349357
350− if (nace > NFS4_ACL_MAX)
358+ if (nace > compoundargs_bytes_left(argp)/20)
359+ /*
360+ * Even with 4-byte names there wouldn't be
361+ * space for that many aces; something fishy is
362+ * going on:
363+ */
351364 return nfserr_fbig;
352365
353366 *acl = svcxdr_tmpalloc(argp, nfs4_acl_bytes(nace));
@@ -1418,7 +1431,6 @@ nfsd4_decode_create_session(struct nfsd4_compoundargs *argp, · 1064 unmodified lines
14181431 struct nfsd4_create_session *sess)
14191432 {
14201433 DECODE_HEAD;
1421− u32 dummy;
14221434
14231435 READ_BUF(16);
14241436 COPYMEM(&sess->clientid, 8);
@@ -1427,7 +1439,7 @@ nfsd4_decode_create_session(struct nfsd4_compoundargs *argp, · 2 unmodified lines
14271439
14281440 /* Fore channel attrs */
14291441 READ_BUF(28);
1430− dummy = be32_to_cpup(p++); /* headerpadsz is always 0 */
1442+ p++; /* headerpadsz is always 0 */
14311443 sess->fore_channel.maxreq_sz = be32_to_cpup(p++);
14321444 sess->fore_channel.maxresp_sz = be32_to_cpup(p++);
14331445 sess->fore_channel.maxresp_cached = be32_to_cpup(p++);
@@ -1444,7 +1456,7 @@ nfsd4_decode_create_session(struct nfsd4_compoundargs *argp, · 10 unmodified lines
14441456
14451457 /* Back channel attrs */
14461458 READ_BUF(28);
1447− dummy = be32_to_cpup(p++); /* headerpadsz is always 0 */
1459+ p++; /* headerpadsz is always 0 */
14481460 sess->back_channel.maxreq_sz = be32_to_cpup(p++);
14491461 sess->back_channel.maxresp_sz = be32_to_cpup(p++);
14501462 sess->back_channel.maxresp_cached = be32_to_cpup(p++);
@@ -1736,7 +1748,6 @@ static __be32 · 285 unmodified lines
17361748 nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy)
17371749 {
17381750 DECODE_HEAD;
1739− unsigned int tmp;
17401751
17411752 status = nfsd4_decode_stateid(argp, &copy->cp_src_stateid);
17421753 if (status)
@@ -1751,7 +1762,7 @@ nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy) · 8 unmodified lines
17511762 p = xdr_decode_hyper(p, &copy->cp_count);
17521763 p++; /* ca_consecutive: we always do consecutive copies */
17531764 copy->cp_synchronous = be32_to_cpup(p++);
1754− tmp = be32_to_cpup(p); /* Source server list not supported */
1765+ /* tmp = be32_to_cpup(p); Source server list not supported */
17551766
17561767 DECODE_TAIL;
17571768 }
@@ -3217,9 +3228,8 @@ nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_ · 1459 unmodified lines
32173228 if (!p)
32183229 return nfserr_resource;
32193230 encode_cinfo(p, &create->cr_cinfo);
3220− nfserr = nfsd4_encode_bitmap(xdr, create->cr_bmval[0],
3231+ return nfsd4_encode_bitmap(xdr, create->cr_bmval[0],
32213232 create->cr_bmval[1], create->cr_bmval[2]);
3222− return 0;
32233233 }
32243234
32253235 static __be32
@@ -3462,7 +3472,7 @@ static __be32 nfsd4_encode_splice_read( · 236 unmodified lines
34623472
34633473 len = maxcount;
34643474 nfserr = nfsd_splice_read(read->rd_rqstp, read->rd_fhp,
3465− file, read->rd_offset, &maxcount);
3475+ file, read->rd_offset, &maxcount, &eof);
34663476 read->rd_length = maxcount;
34673477 if (nfserr) {
34683478 /*
@@ -3474,9 +3484,6 @@ static __be32 nfsd4_encode_splice_read( · 5 unmodified lines
34743484 return nfserr;
34753485 }
34763486
3477− eof = nfsd_eof_on_read(len, maxcount, read->rd_offset,
3478− d_inode(read->rd_fhp->fh_dentry)->i_size);
3479−
34803487 *(p++) = htonl(eof);
34813488 *(p++) = htonl(maxcount);
34823489
@@ -3547,15 +3554,13 @@ static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, · 64 unmodified lines
35473554
35483555 len = maxcount;
35493556 nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset,
3550− resp->rqstp->rq_vec, read->rd_vlen, &maxcount);
3557+ resp->rqstp->rq_vec, read->rd_vlen, &maxcount,
3558+ &eof);
35513559 read->rd_length = maxcount;
35523560 if (nfserr)
35533561 return nfserr;
35543562 xdr_truncate_encode(xdr, starting_len + 8 + ((maxcount+3)&~3));
35553563
3556− eof = nfsd_eof_on_read(len, maxcount, read->rd_offset,
3557− d_inode(read->rd_fhp->fh_dentry)->i_size);
3558−
35593564 tmp = htonl(eof);
35603565 write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4);
35613566 tmp = htonl(maxcount);
@@ -3574,11 +3579,14 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, · 12 unmodified lines
35743579 {
35753580 unsigned long maxcount;
35763581 struct xdr_stream *xdr = &resp->xdr;
3577− struct file *file = read->rd_filp;
3582+ struct file *file;
35783583 int starting_len = xdr->buf->len;
3579− struct raparms *ra = NULL;
35803584 __be32 *p;
35813585
3586+ if (nfserr)
3587+ return nfserr;
3588+ file = read->rd_nf->nf_file;
3589+
35823590 p = xdr_reserve_space(xdr, 8); /* eof flag and byte count */
35833591 if (!p) {
35843592 WARN_ON_ONCE(test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags));
@@ -3596,18 +3604,12 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, · 11 unmodified lines
35963604 (xdr->buf->buflen - xdr->buf->len));
35973605 maxcount = min_t(unsigned long, maxcount, read->rd_length);
35983606
3599− if (read->rd_tmp_file)
3600− ra = nfsd_init_raparms(file);
3601−
36023607 if (file->f_op->splice_read &&
36033608 test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags))
36043609 nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount);
36053610 else
36063611 nfserr = nfsd4_encode_readv(resp, read, file, maxcount);
36073612
3608− if (ra)
3609− nfsd_put_raparams(file, ra);
3610−
36113613 if (nfserr)
36123614 xdr_truncate_encode(xdr, starting_len);
36133615
fs/nfsd/nfsctl.c+1−0
@@ -1476,6 +1476,7 @@ static __net_init int nfsd_init_net(struct net *net) · 1475 unmodified lines
14761476
14771477 atomic_set(&nn->ntf_refcnt, 0);
14781478 init_waitqueue_head(&nn->ntf_wq);
1479+ seqlock_init(&nn->boot_lock);
14791480
14801481 mnt = vfs_kern_mount(&nfsd_fs_type, SB_KERNMOUNT, "nfsd", NULL);
14811482 if (IS_ERR(mnt)) {
fs/nfsd/nfsproc.c+3−1
@@ -172,6 +172,7 @@ nfsd_proc_read(struct svc_rqst *rqstp) · 171 unmodified lines
172172 struct nfsd_readargs *argp = rqstp->rq_argp;
173173 struct nfsd_readres *resp = rqstp->rq_resp;
174174 __be32 nfserr;
175+ u32 eof;
175176
176177 dprintk("nfsd: READ %s %d bytes at %d\n",
177178 SVCFH_fmt(&argp->fh),
@@ -195,7 +196,8 @@ nfsd_proc_read(struct svc_rqst *rqstp) · 17 unmodified lines
195196 nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh),
196197 argp->offset,
197198 rqstp->rq_vec, argp->vlen,
198− &resp->count);
199+ &resp->count,
200+ &eof);
199201
200202 if (nfserr) return nfserr;
201203 return fh_getattr(&resp->fh, &resp->stat);
fs/nfsd/nfssvc.c+37−11
@@ -27,6 +27,7 @@ · 26 unmodified lines
2727 #include "cache.h"
2828 #include "vfs.h"
2929 #include "netns.h"
30+#include "filecache.h"
3031
3132 #define NFSDDBG_FACILITY NFSDDBG_SVC
3233
@@ -313,22 +314,17 @@ static int nfsd_startup_generic(int nrservs) · 280 unmodified lines
313314 if (nfsd_users++)
314315 return 0;
315316
316− /*
317− * Readahead param cache - will no-op if it already exists.
318− * (Note therefore results will be suboptimal if number of
319− * threads is modified after nfsd start.)
320− */
321− ret = nfsd_racache_init(2*nrservs);
317+ ret = nfsd_file_cache_init();
322318 if (ret)
323319 goto dec_users;
324320
325321 ret = nfs4_state_start();
326322 if (ret)
327− goto out_racache;
323+ goto out_file_cache;
328324 return 0;
329325
330−out_racache:
331− nfsd_racache_shutdown();
326+out_file_cache:
327+ nfsd_file_cache_shutdown();
332328 dec_users:
333329 nfsd_users--;
334330 return ret;
@@ -340,7 +336,7 @@ static void nfsd_shutdown_generic(void) · 5 unmodified lines
340336 return;
341337
342338 nfs4_state_shutdown();
343− nfsd_racache_shutdown();
339+ nfsd_file_cache_shutdown();
344340 }
345341
346342 static bool nfsd_needs_lockd(struct nfsd_net *nn)
@@ -348,6 +344,35 @@ static bool nfsd_needs_lockd(struct nfsd_net *nn) · 1 unmodified line
348344 return nfsd_vers(nn, 2, NFSD_TEST) || nfsd_vers(nn, 3, NFSD_TEST);
349345 }
350346
347+void nfsd_copy_boot_verifier(__be32 verf[2], struct nfsd_net *nn)
348+{
349+ int seq = 0;
350+
351+ do {
352+ read_seqbegin_or_lock(&nn->boot_lock, &seq);
353+ /*
354+ * This is opaque to client, so no need to byte-swap. Use
355+ * __force to keep sparse happy. y2038 time_t overflow is
356+ * irrelevant in this usage
357+ */
358+ verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec;
359+ verf[1] = (__force __be32)nn->nfssvc_boot.tv_nsec;
360+ } while (need_seqretry(&nn->boot_lock, seq));
361+ done_seqretry(&nn->boot_lock, seq);
362+}
363+
364+static void nfsd_reset_boot_verifier_locked(struct nfsd_net *nn)
365+{
366+ ktime_get_real_ts64(&nn->nfssvc_boot);
367+}
368+
369+void nfsd_reset_boot_verifier(struct nfsd_net *nn)
370+{
371+ write_seqlock(&nn->boot_lock);
372+ nfsd_reset_boot_verifier_locked(nn);
373+ write_sequnlock(&nn->boot_lock);
374+}
375+
351376 static int nfsd_startup_net(int nrservs, struct net *net, const struct cred *cred)
352377 {
353378 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
@@ -391,6 +416,7 @@ static void nfsd_shutdown_net(struct net *net) · 37 unmodified lines
391416 {
392417 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
393418
419+ nfsd_file_cache_purge(net);
394420 nfs4_state_shutdown_net(net);
395421 if (nn->lockd_up) {
396422 lockd_down(net);
@@ -599,7 +625,7 @@ int nfsd_create_serv(struct net *net) · 202 unmodified lines
599625 #endif
600626 }
601627 atomic_inc(&nn->ntf_refcnt);
602− ktime_get_real_ts64(&nn->nfssvc_boot); /* record boot time */
628+ nfsd_reset_boot_verifier(nn);
603629 return 0;
604630 }
605631
fs/nfsd/state.h+7−6
@@ -378,6 +378,7 @@ struct nfs4_client_reclaim { · 377 unmodified lines
378378 struct list_head cr_strhash; /* hash by cr_name */
379379 struct nfs4_client *cr_clp; /* pointer to associated clp */
380380 struct xdr_netobj cr_name; /* recovery dir name */
381+ struct xdr_netobj cr_princhash;
381382 };
382383
383384 /* A reasonable value for REPLAY_ISIZE was estimated as follows:
@@ -506,7 +507,7 @@ struct nfs4_file { · 122 unmodified lines
506507 };
507508 struct list_head fi_clnt_odstate;
508509 /* One each for O_RDONLY, O_WRONLY, O_RDWR: */
509− struct file * fi_fds[3];
510+ struct nfsd_file *fi_fds[3];
510511 /*
511512 * Each open or lock stateid contributes 0-4 to the counts
512513 * below depending on which bits are set in st_access_bitmap:
@@ -516,7 +517,7 @@ struct nfs4_file { · 3 unmodified lines
516517 */
517518 atomic_t fi_access[2];
518519 u32 fi_share_deny;
519− struct file *fi_deleg_file;
520+ struct nfsd_file *fi_deleg_file;
520521 int fi_delegees;
521522 struct knfsd_fh fi_fhandle;
522523 bool fi_had_conflict;
@@ -565,7 +566,7 @@ struct nfs4_layout_stateid { · 42 unmodified lines
565566 spinlock_t ls_lock;
566567 struct list_head ls_layouts;
567568 u32 ls_layout_type;
568− struct file *ls_file;
569+ struct nfsd_file *ls_file;
569570 struct nfsd4_callback ls_recall;
570571 stateid_t ls_recall_sid;
571572 bool ls_recalled;
@@ -616,7 +617,7 @@ struct nfsd4_copy; · 44 unmodified lines
616617
617618 extern __be32 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
618619 struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
619− stateid_t *stateid, int flags, struct file **filp, bool *tmp_file);
620+ stateid_t *stateid, int flags, struct nfsd_file **filp);
620621 __be32 nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
621622 stateid_t *stateid, unsigned char typemask,
622623 struct nfs4_stid **s, struct nfsd_net *nn);
@@ -645,7 +646,7 @@ extern void nfsd4_shutdown_callback(struct nfs4_client *); · 22 unmodified lines
645646 extern void nfsd4_shutdown_copy(struct nfs4_client *clp);
646647 extern void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp);
647648 extern struct nfs4_client_reclaim *nfs4_client_to_reclaim(struct xdr_netobj name,
648− struct nfsd_net *nn);
649+ struct xdr_netobj princhash, struct nfsd_net *nn);
649650 extern bool nfs4_has_reclaimed_state(struct xdr_netobj name, struct nfsd_net *nn);
650651
651652 struct nfs4_file *find_file(struct knfsd_fh *fh);
@@ -657,7 +658,7 @@ static inline void get_nfs4_file(struct nfs4_file *fi) · 5 unmodified lines
657658 {
658659 refcount_inc(&fi->fi_ref);
659660 }
660−struct file *find_any_file(struct nfs4_file *f);
661+struct nfsd_file *find_any_file(struct nfs4_file *f);
661662
662663 /* grace period management */
663664 void nfsd4_end_grace(struct nfsd_net *nn);
fs/nfsd/trace.h+140−0
@@ -126,6 +126,8 @@ DEFINE_NFSD_ERR_EVENT(read_err); · 125 unmodified lines
126126 DEFINE_NFSD_ERR_EVENT(write_err);
127127
128128 #include "state.h"
129+#include "filecache.h"
130+#include "vfs.h"
129131
130132 DECLARE_EVENT_CLASS(nfsd_stateid_class,
131133 TP_PROTO(stateid_t *stp),
@@ -164,6 +166,144 @@ DEFINE_STATEID_EVENT(layout_recall_done); · 32 unmodified lines
164166 DEFINE_STATEID_EVENT(layout_recall_fail);
165167 DEFINE_STATEID_EVENT(layout_recall_release);
166168
169+#define show_nf_flags(val) \
170+ __print_flags(val, "|", \
171+ { 1 << NFSD_FILE_HASHED, "HASHED" }, \
172+ { 1 << NFSD_FILE_PENDING, "PENDING" }, \
173+ { 1 << NFSD_FILE_BREAK_READ, "BREAK_READ" }, \
174+ { 1 << NFSD_FILE_BREAK_WRITE, "BREAK_WRITE" }, \
175+ { 1 << NFSD_FILE_REFERENCED, "REFERENCED"})
176+
177+/* FIXME: This should probably be fleshed out in the future. */
178+#define show_nf_may(val) \
179+ __print_flags(val, "|", \
180+ { NFSD_MAY_READ, "READ" }, \
181+ { NFSD_MAY_WRITE, "WRITE" }, \
182+ { NFSD_MAY_NOT_BREAK_LEASE, "NOT_BREAK_LEASE" })
183+
184+DECLARE_EVENT_CLASS(nfsd_file_class,
185+ TP_PROTO(struct nfsd_file *nf),
186+ TP_ARGS(nf),
187+ TP_STRUCT__entry(
188+ __field(unsigned int, nf_hashval)
189+ __field(void *, nf_inode)
190+ __field(int, nf_ref)
191+ __field(unsigned long, nf_flags)
192+ __field(unsigned char, nf_may)
193+ __field(struct file *, nf_file)
194+ ),
195+ TP_fast_assign(
196+ __entry->nf_hashval = nf->nf_hashval;
197+ __entry->nf_inode = nf->nf_inode;
198+ __entry->nf_ref = atomic_read(&nf->nf_ref);
199+ __entry->nf_flags = nf->nf_flags;
200+ __entry->nf_may = nf->nf_may;
201+ __entry->nf_file = nf->nf_file;
202+ ),
203+ TP_printk("hash=0x%x inode=0x%p ref=%d flags=%s may=%s file=%p",
204+ __entry->nf_hashval,
205+ __entry->nf_inode,
206+ __entry->nf_ref,
207+ show_nf_flags(__entry->nf_flags),
208+ show_nf_may(__entry->nf_may),
209+ __entry->nf_file)
210+)
211+
212+#define DEFINE_NFSD_FILE_EVENT(name) \
213+DEFINE_EVENT(nfsd_file_class, name, \
214+ TP_PROTO(struct nfsd_file *nf), \
215+ TP_ARGS(nf))
216+
217+DEFINE_NFSD_FILE_EVENT(nfsd_file_alloc);
218+DEFINE_NFSD_FILE_EVENT(nfsd_file_put_final);
219+DEFINE_NFSD_FILE_EVENT(nfsd_file_unhash);
220+DEFINE_NFSD_FILE_EVENT(nfsd_file_put);
221+DEFINE_NFSD_FILE_EVENT(nfsd_file_unhash_and_release_locked);
222+
223+TRACE_EVENT(nfsd_file_acquire,
224+ TP_PROTO(struct svc_rqst *rqstp, unsigned int hash,
225+ struct inode *inode, unsigned int may_flags,
226+ struct nfsd_file *nf, __be32 status),
227+
228+ TP_ARGS(rqstp, hash, inode, may_flags, nf, status),
229+
230+ TP_STRUCT__entry(
231+ __field(__be32, xid)
232+ __field(unsigned int, hash)
233+ __field(void *, inode)
234+ __field(unsigned int, may_flags)
235+ __field(int, nf_ref)
236+ __field(unsigned long, nf_flags)
237+ __field(unsigned char, nf_may)
238+ __field(struct file *, nf_file)
239+ __field(__be32, status)
240+ ),
241+
242+ TP_fast_assign(
243+ __entry->xid = rqstp->rq_xid;
244+ __entry->hash = hash;
245+ __entry->inode = inode;
246+ __entry->may_flags = may_flags;
247+ __entry->nf_ref = nf ? atomic_read(&nf->nf_ref) : 0;
248+ __entry->nf_flags = nf ? nf->nf_flags : 0;
249+ __entry->nf_may = nf ? nf->nf_may : 0;
250+ __entry->nf_file = nf ? nf->nf_file : NULL;
251+ __entry->status = status;
252+ ),
253+
254+ TP_printk("xid=0x%x hash=0x%x inode=0x%p may_flags=%s ref=%d nf_flags=%s nf_may=%s nf_file=0x%p status=%u",
255+ be32_to_cpu(__entry->xid), __entry->hash, __entry->inode,
256+ show_nf_may(__entry->may_flags), __entry->nf_ref,
257+ show_nf_flags(__entry->nf_flags),
258+ show_nf_may(__entry->nf_may), __entry->nf_file,
259+ be32_to_cpu(__entry->status))
260+);
261+
262+DECLARE_EVENT_CLASS(nfsd_file_search_class,
263+ TP_PROTO(struct inode *inode, unsigned int hash, int found),
264+ TP_ARGS(inode, hash, found),
265+ TP_STRUCT__entry(
266+ __field(struct inode *, inode)
267+ __field(unsigned int, hash)
268+ __field(int, found)
269+ ),
270+ TP_fast_assign(
271+ __entry->inode = inode;
272+ __entry->hash = hash;
273+ __entry->found = found;
274+ ),
275+ TP_printk("hash=0x%x inode=0x%p found=%d", __entry->hash,
276+ __entry->inode, __entry->found)
277+);
278+
279+#define DEFINE_NFSD_FILE_SEARCH_EVENT(name) \
280+DEFINE_EVENT(nfsd_file_search_class, name, \
281+ TP_PROTO(struct inode *inode, unsigned int hash, int found), \
282+ TP_ARGS(inode, hash, found))
283+
284+DEFINE_NFSD_FILE_SEARCH_EVENT(nfsd_file_close_inode_sync);
285+DEFINE_NFSD_FILE_SEARCH_EVENT(nfsd_file_close_inode);
286+DEFINE_NFSD_FILE_SEARCH_EVENT(nfsd_file_is_cached);
287+
288+TRACE_EVENT(nfsd_file_fsnotify_handle_event,
289+ TP_PROTO(struct inode *inode, u32 mask),
290+ TP_ARGS(inode, mask),
291+ TP_STRUCT__entry(
292+ __field(struct inode *, inode)
293+ __field(unsigned int, nlink)
294+ __field(umode_t, mode)
295+ __field(u32, mask)
296+ ),
297+ TP_fast_assign(
298+ __entry->inode = inode;
299+ __entry->nlink = inode->i_nlink;
300+ __entry->mode = inode->i_mode;
301+ __entry->mask = mask;
302+ ),
303+ TP_printk("inode=0x%p nlink=%u mode=0%ho mask=0x%x", __entry->inode,
304+ __entry->nlink, __entry->mode, __entry->mask)
305+);
306+
167307 #endif /* _NFSD_TRACE_H */
168308
169309 #undef TRACE_INCLUDE_PATH
fs/nfsd/vfs.c+146−205
@@ -44,38 +44,11 @@ · 43 unmodified lines
4444
4545 #include "nfsd.h"
4646 #include "vfs.h"
47+#include "filecache.h"
4748 #include "trace.h"
4849
4950 #define NFSDDBG_FACILITY NFSDDBG_FILEOP
5051
51−
52−/*
53− * This is a cache of readahead params that help us choose the proper
54− * readahead strategy. Initially, we set all readahead parameters to 0
55− * and let the VFS handle things.
56− * If you increase the number of cached files very much, you'll need to
57− * add a hash table here.
58− */
59−struct raparms {
60− struct raparms *p_next;
61− unsigned int p_count;
62− ino_t p_ino;
63− dev_t p_dev;
64− int p_set;
65− struct file_ra_state p_ra;
66− unsigned int p_hindex;
67−};
68−
69−struct raparm_hbucket {
70− struct raparms *pb_head;
71− spinlock_t pb_lock;
72−} ____cacheline_aligned_in_smp;
73−
74−#define RAPARM_HASH_BITS 4
75−#define RAPARM_HASH_SIZE (1<<RAPARM_HASH_BITS)
76−#define RAPARM_HASH_MASK (RAPARM_HASH_SIZE-1)
77−static struct raparm_hbucket raparm_hash[RAPARM_HASH_SIZE];
78−
7952 /*
8053 * Called from nfsd_lookup and encode_dirent. Check if we have crossed
8154 * a mount point.
@@ -699,7 +672,7 @@ nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access, u32 *suppor · 617 unmodified lines
699672 }
700673 #endif /* CONFIG_NFSD_V3 */
701674
702−static int nfsd_open_break_lease(struct inode *inode, int access)
675+int nfsd_open_break_lease(struct inode *inode, int access)
703676 {
704677 unsigned int mode;
705678
@@ -715,8 +688,8 @@ static int nfsd_open_break_lease(struct inode *inode, int access) · 9 unmodified lines
715688 * and additional flags.
716689 * N.B. After this call fhp needs an fh_put
717690 */
718−__be32
719−nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
691+static __be32
692+__nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
720693 int may_flags, struct file **filp)
721694 {
722695 struct path path;
@@ -726,25 +699,6 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, · 3 unmodified lines
726699 __be32 err;
727700 int host_err = 0;
728701
729− validate_process_creds();
730−
731− /*
732− * If we get here, then the client has already done an "open",
733− * and (hopefully) checked permission - so allow OWNER_OVERRIDE
734− * in case a chmod has now revoked permission.
735− *
736− * Arguably we should also allow the owner override for
737− * directories, but we never have and it doesn't seem to have
738− * caused anyone a problem. If we were to change this, note
739− * also that our filldir callbacks would need a variant of
740− * lookup_one_len that doesn't check permissions.
741− */
742− if (type == S_IFREG)
743− may_flags |= NFSD_MAY_OWNER_OVERRIDE;
744− err = fh_verify(rqstp, fhp, type, may_flags);
745− if (err)
746− goto out;
747−
748702 path.mnt = fhp->fh_export->ex_path.mnt;
749703 path.dentry = fhp->fh_dentry;
750704 inode = d_inode(path.dentry);
@@ -798,67 +752,46 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, · 47 unmodified lines
798752 out_nfserr:
799753 err = nfserrno(host_err);
800754 out:
801− validate_process_creds();
802755 return err;
803756 }
804757
805−struct raparms *
806−nfsd_init_raparms(struct file *file)
758+__be32
759+nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
760+ int may_flags, struct file **filp)
807761 {
808− struct inode *inode = file_inode(file);
809− dev_t dev = inode->i_sb->s_dev;
810− ino_t ino = inode->i_ino;
811− struct raparms *ra, **rap, **frap = NULL;
812− int depth = 0;
813− unsigned int hash;
814− struct raparm_hbucket *rab;
815−
816− hash = jhash_2words(dev, ino, 0xfeedbeef) & RAPARM_HASH_MASK;
817− rab = &raparm_hash[hash];
818−
819− spin_lock(&rab->pb_lock);
820− for (rap = &rab->pb_head; (ra = *rap); rap = &ra->p_next) {
821− if (ra->p_ino == ino && ra->p_dev == dev)
822− goto found;
823− depth++;
824− if (ra->p_count == 0)
825− frap = rap;
826− }
827− depth = nfsdstats.ra_size;
828− if (!frap) {
829− spin_unlock(&rab->pb_lock);
830− return NULL;
831− }
832− rap = frap;
833− ra = *frap;
834− ra->p_dev = dev;
835− ra->p_ino = ino;
836− ra->p_set = 0;
837− ra->p_hindex = hash;
838−found:
839− if (rap != &rab->pb_head) {
840− *rap = ra->p_next;
841− ra->p_next = rab->pb_head;
842− rab->pb_head = ra;
843− }
844− ra->p_count++;
845− nfsdstats.ra_depth[depth*10/nfsdstats.ra_size]++;
846− spin_unlock(&rab->pb_lock);
762+ __be32 err;
847763
848− if (ra->p_set)
849− file->f_ra = ra->p_ra;
850− return ra;
764+ validate_process_creds();
765+ /*
766+ * If we get here, then the client has already done an "open",
767+ * and (hopefully) checked permission - so allow OWNER_OVERRIDE
768+ * in case a chmod has now revoked permission.
769+ *
770+ * Arguably we should also allow the owner override for
771+ * directories, but we never have and it doesn't seem to have
772+ * caused anyone a problem. If we were to change this, note
773+ * also that our filldir callbacks would need a variant of
774+ * lookup_one_len that doesn't check permissions.
775+ */
776+ if (type == S_IFREG)
777+ may_flags |= NFSD_MAY_OWNER_OVERRIDE;
778+ err = fh_verify(rqstp, fhp, type, may_flags);
779+ if (!err)
780+ err = __nfsd_open(rqstp, fhp, type, may_flags, filp);
781+ validate_process_creds();
782+ return err;
851783 }
852784
853−void nfsd_put_raparams(struct file *file, struct raparms *ra)
785+__be32
786+nfsd_open_verified(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
787+ int may_flags, struct file **filp)
854788 {
855− struct raparm_hbucket *rab = &raparm_hash[ra->p_hindex];
789+ __be32 err;
856790
857− spin_lock(&rab->pb_lock);
858− ra->p_ra = file->f_ra;
859− ra->p_set = 1;
860− ra->p_count--;
861− spin_unlock(&rab->pb_lock);
791+ validate_process_creds();
792+ err = __nfsd_open(rqstp, fhp, type, may_flags, filp);
793+ validate_process_creds();
794+ return err;
862795 }
863796
864797 /*
@@ -901,12 +834,23 @@ static int nfsd_direct_splice_actor(struct pipe_inode_info *pipe, · 36 unmodified lines
901834 return __splice_from_pipe(pipe, sd, nfsd_splice_actor);
902835 }
903836
837+static u32 nfsd_eof_on_read(struct file *file, loff_t offset, ssize_t len,
838+ size_t expected)
839+{
840+ if (expected != 0 && len == 0)
841+ return 1;
842+ if (offset+len >= i_size_read(file_inode(file)))
843+ return 1;
844+ return 0;
845+}
846+
904847 static __be32 nfsd_finish_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
905848 struct file *file, loff_t offset,
906− unsigned long *count, int host_err)
849+ unsigned long *count, u32 *eof, ssize_t host_err)
907850 {
908851 if (host_err >= 0) {
909852 nfsdstats.io_read += host_err;
853+ *eof = nfsd_eof_on_read(file, offset, host_err, *count);
910854 *count = host_err;
911855 fsnotify_access(file);
912856 trace_nfsd_read_io_done(rqstp, fhp, offset, *count);
@@ -918,7 +862,8 @@ static __be32 nfsd_finish_read(struct svc_rqst *rqstp, struct svc_fh *fhp, · 5 unmodified lines
918862 }
919863
920864 __be32 nfsd_splice_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
921− struct file *file, loff_t offset, unsigned long *count)
865+ struct file *file, loff_t offset, unsigned long *count,
866+ u32 *eof)
922867 {
923868 struct splice_desc sd = {
924869 .len = 0,
@@ -926,25 +871,27 @@ __be32 nfsd_splice_read(struct svc_rqst *rqstp, struct svc_fh *fhp, · 1 unmodified line
926871 .pos = offset,
927872 .u.data = rqstp,
928873 };
929− int host_err;
874+ ssize_t host_err;
930875
931876 trace_nfsd_read_splice(rqstp, fhp, offset, *count);
932877 rqstp->rq_next_page = rqstp->rq_respages + 1;
933878 host_err = splice_direct_to_actor(file, &sd, nfsd_direct_splice_actor);
934− return nfsd_finish_read(rqstp, fhp, file, offset, count, host_err);
879+ return nfsd_finish_read(rqstp, fhp, file, offset, count, eof, host_err);
935880 }
936881
937882 __be32 nfsd_readv(struct svc_rqst *rqstp, struct svc_fh *fhp,
938883 struct file *file, loff_t offset,
939− struct kvec *vec, int vlen, unsigned long *count)
884+ struct kvec *vec, int vlen, unsigned long *count,
885+ u32 *eof)
940886 {
941887 struct iov_iter iter;
942− int host_err;
888+ loff_t ppos = offset;
889+ ssize_t host_err;
943890
944891 trace_nfsd_read_vector(rqstp, fhp, offset, *count);
945892 iov_iter_kvec(&iter, READ, vec, vlen, *count);
946− host_err = vfs_iter_read(file, &iter, &offset, 0);
947− return nfsd_finish_read(rqstp, fhp, file, offset, count, host_err);
893+ host_err = vfs_iter_read(file, &iter, &ppos, 0);
894+ return nfsd_finish_read(rqstp, fhp, file, offset, count, eof, host_err);
948895 }
949896
950897 /*
@@ -1025,8 +972,12 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file, · 74 unmodified lines
1025972 nfsdstats.io_write += *cnt;
1026973 fsnotify_modify(file);
1027974
1028− if (stable && use_wgather)
975+ if (stable && use_wgather) {
1029976 host_err = wait_for_concurrent_writes(file);
977+ if (host_err < 0)
978+ nfsd_reset_boot_verifier(net_generic(SVC_NET(rqstp),
979+ nfsd_net_id));
980+ }
1030981
1031982 out_nfserr:
1032983 if (host_err >= 0) {
@@ -1047,27 +998,25 @@ out_nfserr: · 14 unmodified lines
1047998 * N.B. After this call fhp needs an fh_put
1048999 */
10491000 __be32 nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
1050− loff_t offset, struct kvec *vec, int vlen, unsigned long *count)
1001+ loff_t offset, struct kvec *vec, int vlen, unsigned long *count,
1002+ u32 *eof)
10511003 {
1004+ struct nfsd_file *nf;
10521005 struct file *file;
1053− struct raparms *ra;
10541006 __be32 err;
10551007
10561008 trace_nfsd_read_start(rqstp, fhp, offset, *count);
1057− err = nfsd_open(rqstp, fhp, S_IFREG, NFSD_MAY_READ, &file);
1009+ err = nfsd_file_acquire(rqstp, fhp, NFSD_MAY_READ, &nf);
10581010 if (err)
10591011 return err;
10601012
1061− ra = nfsd_init_raparms(file);
1062−
1013+ file = nf->nf_file;
10631014 if (file->f_op->splice_read && test_bit(RQ_SPLICE_OK, &rqstp->rq_flags))
1064− err = nfsd_splice_read(rqstp, fhp, file, offset, count);
1015+ err = nfsd_splice_read(rqstp, fhp, file, offset, count, eof);
10651016 else
1066− err = nfsd_readv(rqstp, fhp, file, offset, vec, vlen, count);
1017+ err = nfsd_readv(rqstp, fhp, file, offset, vec, vlen, count, eof);
10671018
1068− if (ra)
1069− nfsd_put_raparams(file, ra);
1070− fput(file);
1019+ nfsd_file_put(nf);
10711020
10721021 trace_nfsd_read_done(rqstp, fhp, offset, *count);
10731022
@@ -1083,17 +1032,18 @@ __be32 · 9 unmodified lines
10831032 nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
10841033 struct kvec *vec, int vlen, unsigned long *cnt, int stable)
10851034 {
1086− struct file *file = NULL;
1087− __be32 err = 0;
1035+ struct nfsd_file *nf;
1036+ __be32 err;
10881037
10891038 trace_nfsd_write_start(rqstp, fhp, offset, *cnt);
10901039
1091− err = nfsd_open(rqstp, fhp, S_IFREG, NFSD_MAY_WRITE, &file);
1040+ err = nfsd_file_acquire(rqstp, fhp, NFSD_MAY_WRITE, &nf);
10921041 if (err)
10931042 goto out;
10941043
1095− err = nfsd_vfs_write(rqstp, fhp, file, offset, vec, vlen, cnt, stable);
1096− fput(file);
1044+ err = nfsd_vfs_write(rqstp, fhp, nf->nf_file, offset, vec,
1045+ vlen, cnt, stable);
1046+ nfsd_file_put(nf);
10971047 out:
10981048 trace_nfsd_write_done(rqstp, fhp, offset, *cnt);
10991049 return err;
@@ -1113,9 +1063,9 @@ __be32 · 13 unmodified lines
11131063 nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
11141064 loff_t offset, unsigned long count)
11151065 {
1116− struct file *file;
1117− loff_t end = LLONG_MAX;
1118− __be32 err = nfserr_inval;
1066+ struct nfsd_file *nf;
1067+ loff_t end = LLONG_MAX;
1068+ __be32 err = nfserr_inval;
11191069
11201070 if (offset < 0)
11211071 goto out;
@@ -1125,20 +1075,27 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, · 3 unmodified lines
11251075 goto out;
11261076 }
11271077
1128− err = nfsd_open(rqstp, fhp, S_IFREG,
1129− NFSD_MAY_WRITE|NFSD_MAY_NOT_BREAK_LEASE, &file);
1078+ err = nfsd_file_acquire(rqstp, fhp,
1079+ NFSD_MAY_WRITE|NFSD_MAY_NOT_BREAK_LEASE, &nf);
11301080 if (err)
11311081 goto out;
11321082 if (EX_ISSYNC(fhp->fh_export)) {
1133− int err2 = vfs_fsync_range(file, offset, end, 0);
1083+ int err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
11341084
1135− if (err2 != -EINVAL)
1136− err = nfserrno(err2);
1137− else
1085+ switch (err2) {
1086+ case 0:
1087+ break;
1088+ case -EINVAL:
11381089 err = nfserr_notsupp;
1090+ break;
1091+ default:
1092+ err = nfserrno(err2);
1093+ nfsd_reset_boot_verifier(net_generic(nf->nf_net,
1094+ nfsd_net_id));
1095+ }
11391096 }
11401097
1141− fput(file);
1098+ nfsd_file_put(nf);
11421099 out:
11431100 return err;
11441101 }
@@ -1659,6 +1616,26 @@ out_nfserr: · 514 unmodified lines
16591616 goto out_unlock;
16601617 }
16611618
1619+static void
1620+nfsd_close_cached_files(struct dentry *dentry)
1621+{
1622+ struct inode *inode = d_inode(dentry);
1623+
1624+ if (inode && S_ISREG(inode->i_mode))
1625+ nfsd_file_close_inode_sync(inode);
1626+}
1627+
1628+static bool
1629+nfsd_has_cached_files(struct dentry *dentry)
1630+{
1631+ bool ret = false;
1632+ struct inode *inode = d_inode(dentry);
1633+
1634+ if (inode && S_ISREG(inode->i_mode))
1635+ ret = nfsd_file_is_cached(inode);
1636+ return ret;
1637+}
1638+
16621639 /*
16631640 * Rename a file
16641641 * N.B. After this call _both_ ffhp and tfhp need an fh_put
@@ -1671,6 +1648,7 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, · 6 unmodified lines
16711648 struct inode *fdir, *tdir;
16721649 __be32 err;
16731650 int host_err;
1651+ bool has_cached = false;
16741652
16751653 err = fh_verify(rqstp, ffhp, S_IFDIR, NFSD_MAY_REMOVE);
16761654 if (err)
@@ -1689,6 +1667,7 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, · 12 unmodified lines
16891667 if (!flen || isdotent(fname, flen) || !tlen || isdotent(tname, tlen))
16901668 goto out;
16911669
1670+retry:
16921671 host_err = fh_want_write(ffhp);
16931672 if (host_err) {
16941673 err = nfserrno(host_err);
@@ -1728,11 +1707,16 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, · 33 unmodified lines
17281707 if (ffhp->fh_export->ex_path.dentry != tfhp->fh_export->ex_path.dentry)
17291708 goto out_dput_new;
17301709
1731− host_err = vfs_rename(fdir, odentry, tdir, ndentry, NULL, 0);
1732− if (!host_err) {
1733− host_err = commit_metadata(tfhp);
1734− if (!host_err)
1735− host_err = commit_metadata(ffhp);
1710+ if (nfsd_has_cached_files(ndentry)) {
1711+ has_cached = true;
1712+ goto out_dput_old;
1713+ } else {
1714+ host_err = vfs_rename(fdir, odentry, tdir, ndentry, NULL, 0);
1715+ if (!host_err) {
1716+ host_err = commit_metadata(tfhp);
1717+ if (!host_err)
1718+ host_err = commit_metadata(ffhp);
1719+ }
17361720 }
17371721 out_dput_new:
17381722 dput(ndentry);
@@ -1745,12 +1729,26 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, · 6 unmodified lines
17451729 * as that would do the wrong thing if the two directories
17461730 * were the same, so again we do it by hand.
17471731 */
1748− fill_post_wcc(ffhp);
1749− fill_post_wcc(tfhp);
1732+ if (!has_cached) {
1733+ fill_post_wcc(ffhp);
1734+ fill_post_wcc(tfhp);
1735+ }
17501736 unlock_rename(tdentry, fdentry);
17511737 ffhp->fh_locked = tfhp->fh_locked = false;
17521738 fh_drop_write(ffhp);
17531739
1740+ /*
1741+ * If the target dentry has cached open files, then we need to try to
1742+ * close them prior to doing the rename. Flushing delayed fput
1743+ * shouldn't be done with locks held however, so we delay it until this
1744+ * point and then reattempt the whole shebang.
1745+ */
1746+ if (has_cached) {
1747+ has_cached = false;
1748+ nfsd_close_cached_files(ndentry);
1749+ dput(ndentry);
1750+ goto retry;
1751+ }
17541752 out:
17551753 return err;
17561754 }
@@ -1797,10 +1795,13 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, · 40 unmodified lines
17971795 if (!type)
17981796 type = d_inode(rdentry)->i_mode & S_IFMT;
17991797
1800− if (type != S_IFDIR)
1798+ if (type != S_IFDIR) {
1799+ nfsd_close_cached_files(rdentry);
18011800 host_err = vfs_unlink(dirp, rdentry, NULL);
1802− else
1801+ } else {
18031802 host_err = vfs_rmdir(dirp, rdentry);
1803+ }
1804+
18041805 if (!host_err)
18051806 host_err = commit_metadata(fhp);
18061807 dput(rdentry);
@@ -2074,63 +2075,3 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp, · 267 unmodified lines
20742075
20752076 return err? nfserrno(err) : 0;
20762077 }
2077−
2078−void
2079−nfsd_racache_shutdown(void)
2080−{
2081− struct raparms *raparm, *last_raparm;
2082− unsigned int i;
2083−
2084− dprintk("nfsd: freeing readahead buffers.\n");
2085−
2086− for (i = 0; i < RAPARM_HASH_SIZE; i++) {
2087− raparm = raparm_hash[i].pb_head;
2088− while(raparm) {
2089− last_raparm = raparm;
2090− raparm = raparm->p_next;
2091− kfree(last_raparm);
2092− }
2093− raparm_hash[i].pb_head = NULL;
2094− }
2095−}
2096−/*
2097− * Initialize readahead param cache
2098− */
2099−int
2100−nfsd_racache_init(int cache_size)
2101−{
2102− int i;
2103− int j = 0;
2104− int nperbucket;
2105− struct raparms **raparm = NULL;
2106−
2107−
2108− if (raparm_hash[0].pb_head)
2109− return 0;
2110− nperbucket = DIV_ROUND_UP(cache_size, RAPARM_HASH_SIZE);
2111− nperbucket = max(2, nperbucket);
2112− cache_size = nperbucket * RAPARM_HASH_SIZE;
2113−
2114− dprintk("nfsd: allocating %d readahead buffers.\n", cache_size);
2115−
2116− for (i = 0; i < RAPARM_HASH_SIZE; i++) {
2117− spin_lock_init(&raparm_hash[i].pb_lock);
2118−
2119− raparm = &raparm_hash[i].pb_head;
2120− for (j = 0; j < nperbucket; j++) {
2121− *raparm = kzalloc(sizeof(struct raparms), GFP_KERNEL);
2122− if (!*raparm)
2123− goto out_nomem;
2124− raparm = &(*raparm)->p_next;
2125− }
2126− *raparm = NULL;
2127− }
2128−
2129− nfsdstats.ra_size = cache_size;
2130− return 0;
2131−
2132−out_nomem:
2133− dprintk("nfsd: kmalloc failed, freeing readahead buffers\n");
2134− nfsd_racache_shutdown();
2135− return -ENOMEM;
2136−}
fs/nfsd/vfs.h+9−28
@@ -40,8 +40,6 @@ · 39 unmodified lines
4040 typedef int (*nfsd_filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
4141
4242 /* nfsd/vfs.c */
43−int nfsd_racache_init(int);
44−void nfsd_racache_shutdown(void);
4543 int nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
4644 struct svc_export **expp);
4745 __be32 nfsd_lookup(struct svc_rqst *, struct svc_fh *,
@@ -75,18 +73,23 @@ __be32 do_nfsd_create(struct svc_rqst *, struct svc_fh *, · 27 unmodified lines
7573 __be32 nfsd_commit(struct svc_rqst *, struct svc_fh *,
7674 loff_t, unsigned long);
7775 #endif /* CONFIG_NFSD_V3 */
76+int nfsd_open_break_lease(struct inode *, int);
7877 __be32 nfsd_open(struct svc_rqst *, struct svc_fh *, umode_t,
7978 int, struct file **);
80−struct raparms;
79+__be32 nfsd_open_verified(struct svc_rqst *, struct svc_fh *, umode_t,
80+ int, struct file **);
8181 __be32 nfsd_splice_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
8282 struct file *file, loff_t offset,
83− unsigned long *count);
83+ unsigned long *count,
84+ u32 *eof);
8485 __be32 nfsd_readv(struct svc_rqst *rqstp, struct svc_fh *fhp,
8586 struct file *file, loff_t offset,
8687 struct kvec *vec, int vlen,
87− unsigned long *count);
88+ unsigned long *count,
89+ u32 *eof);
8890 __be32 nfsd_read(struct svc_rqst *, struct svc_fh *,
89− loff_t, struct kvec *, int, unsigned long *);
91+ loff_t, struct kvec *, int, unsigned long *,
92+ u32 *eof);
9093 __be32 nfsd_write(struct svc_rqst *, struct svc_fh *, loff_t,
9194 struct kvec *, int, unsigned long *, int);
9295 __be32 nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
@@ -115,9 +118,6 @@ __be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *, · 22 unmodified lines
115118 __be32 nfsd_permission(struct svc_rqst *, struct svc_export *,
116119 struct dentry *, int);
117120
118−struct raparms *nfsd_init_raparms(struct file *file);
119−void nfsd_put_raparams(struct file *file, struct raparms *ra);
120−
121121 static inline int fh_want_write(struct svc_fh *fh)
122122 {
123123 int ret;
@@ -152,23 +152,4 @@ static inline int nfsd_create_is_exclusive(int createmode) · 28 unmodified lines
152152 || createmode == NFS4_CREATE_EXCLUSIVE4_1;
153153 }
154154
155−static inline bool nfsd_eof_on_read(long requested, long read,
156− loff_t offset, loff_t size)
157−{
158− /* We assume a short read means eof: */
159− if (requested > read)
160− return true;
161− /*
162− * A non-short read might also reach end of file. The spec
163− * still requires us to set eof in that case.
164− *
165− * Further operations may have modified the file size since
166− * the read, so the following check is not atomic with the read.
167− * We've only seen that cause a problem for a client in the case
168− * where the read returned a count of 0 without setting eof.
169− * That case was fixed by the addition of the above check.
170− */
171− return (offset + read >= size);
172−}
173−
174155 #endif /* LINUX_NFSD_VFS_H */
fs/nfsd/xdr3.h+1−1
@@ -151,7 +151,7 @@ struct nfsd3_readres { · 150 unmodified lines
151151 __be32 status;
152152 struct svc_fh fh;
153153 unsigned long count;
154− int eof;
154+ __u32 eof;
155155 };
156156
157157 struct nfsd3_writeres {
fs/nfsd/xdr4.h+9−10
@@ -273,15 +273,14 @@ struct nfsd4_open_downgrade { · 272 unmodified lines
273273
274274
275275 struct nfsd4_read {
276− stateid_t rd_stateid; /* request */
277− u64 rd_offset; /* request */
278− u32 rd_length; /* request */
279− int rd_vlen;
280− struct file *rd_filp;
281− bool rd_tmp_file;
276+ stateid_t rd_stateid; /* request */
277+ u64 rd_offset; /* request */
278+ u32 rd_length; /* request */
279+ int rd_vlen;
280+ struct nfsd_file *rd_nf;
282281
283− struct svc_rqst *rd_rqstp; /* response */
284− struct svc_fh * rd_fhp; /* response */
282+ struct svc_rqst *rd_rqstp; /* response */
283+ struct svc_fh *rd_fhp; /* response */
285284 };
286285
287286 struct nfsd4_readdir {
@@ -538,8 +537,8 @@ struct nfsd4_copy { · 250 unmodified lines
538537
539538 struct nfs4_client *cp_clp;
540539
541− struct file *file_src;
542− struct file *file_dst;
540+ struct nfsd_file *nf_src;
541+ struct nfsd_file *nf_dst;
543542
544543 stateid_t cp_stateid;
545544
fs/notify/fsnotify.h+0−2
@@ -54,8 +54,6 @@ static inline void fsnotify_clear_marks_by_sb(struct super_block *sb) · 53 unmodified lines
5454 {
5555 fsnotify_destroy_marks(&sb->s_fsnotify_marks);
5656 }
57−/* Wait until all marks queued for destruction are destroyed */
58−extern void fsnotify_wait_marks_destroyed(void);
5957
6058 /*
6159 * update the dentry->d_flags of all of inode's children to indicate if inode cares
fs/notify/group.c+2−0
@@ -108,6 +108,7 @@ void fsnotify_put_group(struct fsnotify_group *group) · 107 unmodified lines
108108 if (refcount_dec_and_test(&group->refcnt))
109109 fsnotify_final_destroy_group(group);
110110 }
111+EXPORT_SYMBOL_GPL(fsnotify_put_group);
111112
112113 /*
113114 * Create a new fsnotify_group and hold a reference for the group returned.
@@ -137,6 +138,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) · 23 unmodified lines
137138
138139 return group;
139140 }
141+EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
140142
141143 int fsnotify_fasync(int fd, struct file *file, int on)
142144 {
fs/notify/mark.c+6−0
@@ -276,6 +276,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark) · 275 unmodified lines
276276 queue_delayed_work(system_unbound_wq, &reaper_work,
277277 FSNOTIFY_REAPER_DELAY);
278278 }
279+EXPORT_SYMBOL_GPL(fsnotify_put_mark);
279280
280281 /*
281282 * Get mark reference when we found the mark via lockless traversal of object
@@ -430,6 +431,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark, · 148 unmodified lines
430431 mutex_unlock(&group->mark_mutex);
431432 fsnotify_free_mark(mark);
432433 }
434+EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
433435
434436 /*
435437 * Sorting function for lists of fsnotify marks.
@@ -685,6 +687,7 @@ int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp, · 249 unmodified lines
685687 mutex_unlock(&group->mark_mutex);
686688 return ret;
687689 }
690+EXPORT_SYMBOL_GPL(fsnotify_add_mark);
688691
689692 /*
690693 * Given a list of marks, find the mark associated with given group. If found
@@ -711,6 +714,7 @@ struct fsnotify_mark *fsnotify_find_mark(fsnotify_connp_t *connp, · 20 unmodified lines
711714 spin_unlock(&conn->lock);
712715 return NULL;
713716 }
717+EXPORT_SYMBOL_GPL(fsnotify_find_mark);
714718
715719 /* Clear any marks in a group with given type mask */
716720 void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
@@ -809,6 +813,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark, · 92 unmodified lines
809813 mark->group = group;
810814 WRITE_ONCE(mark->connector, NULL);
811815 }
816+EXPORT_SYMBOL_GPL(fsnotify_init_mark);
812817
813818 /*
814819 * Destroy all marks in destroy_list, waits for SRCU period to finish before
@@ -837,3 +842,4 @@ void fsnotify_wait_marks_destroyed(void) · 22 unmodified lines
837842 {
838843 flush_delayed_work(&reaper_work);
839844 }
845+EXPORT_SYMBOL_GPL(fsnotify_wait_marks_destroyed);
include/linux/fs.h+5−0
@@ -1168,6 +1168,11 @@ extern void lease_get_mtime(struct inode *, struct timespec64 *time); · 1167 unmodified lines
11681168 extern int generic_setlease(struct file *, long, struct file_lock **, void **priv);
11691169 extern int vfs_setlease(struct file *, long, struct file_lock **, void **);
11701170 extern int lease_modify(struct file_lock *, int, struct list_head *);
1171+
1172+struct notifier_block;
1173+extern int lease_register_notifier(struct notifier_block *);
1174+extern void lease_unregister_notifier(struct notifier_block *);
1175+
11711176 struct files_struct;
11721177 extern void show_fd_locks(struct seq_file *f,
11731178 struct file *filp, struct files_struct *files);
include/linux/fsnotify_backend.h+2−0
@@ -475,6 +475,8 @@ extern void fsnotify_destroy_mark(struct fsnotify_mark *mark, · 474 unmodified lines
475475 extern void fsnotify_detach_mark(struct fsnotify_mark *mark);
476476 /* free mark */
477477 extern void fsnotify_free_mark(struct fsnotify_mark *mark);
478+/* Wait until all marks queued for destruction are destroyed */
479+extern void fsnotify_wait_marks_destroyed(void);
478480 /* run all the marks in a group, and clear all of the marks attached to given object type */
479481 extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group, unsigned int type);
480482 /* run all the marks in a group, and clear all of the vfsmount marks */
include/linux/sunrpc/cache.h+4−3
@@ -87,6 +87,7 @@ struct cache_detail { · 86 unmodified lines
8787 int has_died);
8888
8989 struct cache_head * (*alloc)(void);
90+ void (*flush)(void);
9091 int (*match)(struct cache_head *orig, struct cache_head *new);
9192 void (*init)(struct cache_head *orig, struct cache_head *new);
9293 void (*update)(struct cache_head *orig, struct cache_head *new);
@@ -107,9 +108,9 @@ struct cache_detail { · 14 unmodified lines
107108 /* fields for communication over channel */
108109 struct list_head queue;
109110
110− atomic_t readers; /* how many time is /chennel open */
111− time_t last_close; /* if no readers, when did last close */
112− time_t last_warn; /* when we last warned about no readers */
111+ atomic_t writers; /* how many time is /channel open */
112+ time_t last_close; /* if no writers, when did last close */
113+ time_t last_warn; /* when we last warned about no writers */
113114
114115 union {
115116 struct proc_dir_entry *procfs;
include/linux/sunrpc/svc_rdma.h+3−3
@@ -42,6 +42,7 @@ · 41 unmodified lines
4242
4343 #ifndef SVC_RDMA_H
4444 #define SVC_RDMA_H
45+#include <linux/llist.h>
4546 #include <linux/sunrpc/xdr.h>
4647 #include <linux/sunrpc/svcsock.h>
4748 #include <linux/sunrpc/rpc_rdma.h>
@@ -107,8 +108,7 @@ struct svcxprt_rdma { · 59 unmodified lines
107108 struct list_head sc_read_complete_q;
108109 struct work_struct sc_work;
109110
110− spinlock_t sc_recv_lock;
111− struct list_head sc_recv_ctxts;
111+ struct llist_head sc_recv_ctxts;
112112 };
113113 /* sc_flags */
114114 #define RDMAXPRT_CONN_PENDING 3
@@ -125,6 +125,7 @@ enum { · 10 unmodified lines
125125 #define RPCSVC_MAXPAYLOAD_RDMA RPCSVC_MAXPAYLOAD
126126
127127 struct svc_rdma_recv_ctxt {
128+ struct llist_node rc_node;
128129 struct list_head rc_list;
129130 struct ib_recv_wr rc_recv_wr;
130131 struct ib_cqe rc_cqe;
@@ -200,7 +201,6 @@ extern struct svc_xprt_class svc_rdma_bc_class; · 69 unmodified lines
200201 #endif
201202
202203 /* svc_rdma.c */
203−extern struct workqueue_struct *svc_rdma_wq;
204204 extern int svc_rdma_init(void);
205205 extern void svc_rdma_cleanup(void);
206206
include/uapi/linux/nfsd/cld.h+39−2
@@ -26,17 +26,22 @@ · 25 unmodified lines
2626 #include <linux/types.h>
2727
2828 /* latest upcall version available */
29−#define CLD_UPCALL_VERSION 1
29+#define CLD_UPCALL_VERSION 2
3030
3131 /* defined by RFC3530 */
3232 #define NFS4_OPAQUE_LIMIT 1024
3333
34+#ifndef SHA256_DIGEST_SIZE
35+#define SHA256_DIGEST_SIZE 32
36+#endif
37+
3438 enum cld_command {
3539 Cld_Create, /* create a record for this cm_id */
3640 Cld_Remove, /* remove record of this cm_id */
3741 Cld_Check, /* is this cm_id allowed? */
3842 Cld_GraceDone, /* grace period is complete */
39− Cld_GraceStart,
43+ Cld_GraceStart, /* grace start (upload client records) */
44+ Cld_GetVersion, /* query max supported upcall version */
4045 };
4146
4247 /* representation of long-form NFSv4 client ID */
@@ -45,6 +50,17 @@ struct cld_name { · 2 unmodified lines
4550 unsigned char cn_id[NFS4_OPAQUE_LIMIT]; /* client-provided */
4651 } __attribute__((packed));
4752
53+/* sha256 hash of the kerberos principal */
54+struct cld_princhash {
55+ __u8 cp_len; /* length of cp_data */
56+ unsigned char cp_data[SHA256_DIGEST_SIZE]; /* hash of principal */
57+} __attribute__((packed));
58+
59+struct cld_clntinfo {
60+ struct cld_name cc_name;
61+ struct cld_princhash cc_princhash;
62+} __attribute__((packed));
63+
4864 /* message struct for communication with userspace */
4965 struct cld_msg {
5066 __u8 cm_vers; /* upcall version */
@@ -54,7 +70,28 @@ struct cld_msg { · 3 unmodified lines
5470 union {
5571 __s64 cm_gracetime; /* grace period start time */
5672 struct cld_name cm_name;
73+ __u8 cm_version; /* for getting max version */
74+ } __attribute__((packed)) cm_u;
75+} __attribute__((packed));
76+
77+/* version 2 message can include hash of kerberos principal */
78+struct cld_msg_v2 {
79+ __u8 cm_vers; /* upcall version */
80+ __u8 cm_cmd; /* upcall command */
81+ __s16 cm_status; /* return code */
82+ __u32 cm_xid; /* transaction id */
83+ union {
84+ struct cld_name cm_name;
85+ __u8 cm_version; /* for getting max version */
86+ struct cld_clntinfo cm_clntinfo; /* name & princ hash */
5787 } __attribute__((packed)) cm_u;
5888 } __attribute__((packed));
5989
90+struct cld_msg_hdr {
91+ __u8 cm_vers; /* upcall version */
92+ __u8 cm_cmd; /* upcall command */
93+ __s16 cm_status; /* return code */
94+ __u32 cm_xid; /* transaction id */
95+} __attribute__((packed));
96+
6097 #endif /* !_NFSD_CLD_H */
net/sunrpc/cache.c+11−4
@@ -373,7 +373,7 @@ void sunrpc_init_cache_detail(struct cache_detail *cd) · 372 unmodified lines
373373 spin_lock(&cache_list_lock);
374374 cd->nextcheck = 0;
375375 cd->entries = 0;
376− atomic_set(&cd->readers, 0);
376+ atomic_set(&cd->writers, 0);
377377 cd->last_close = 0;
378378 cd->last_warn = -1;
379379 list_add(&cd->others, &cache_list);
@@ -1029,11 +1029,13 @@ static int cache_open(struct inode *inode, struct file *filp, · 649 unmodified lines
10291029 }
10301030 rp->offset = 0;
10311031 rp->q.reader = 1;
1032− atomic_inc(&cd->readers);
1032+
10331033 spin_lock(&queue_lock);
10341034 list_add(&rp->q.list, &cd->queue);
10351035 spin_unlock(&queue_lock);
10361036 }
1037+ if (filp->f_mode & FMODE_WRITE)
1038+ atomic_inc(&cd->writers);
10371039 filp->private_data = rp;
10381040 return 0;
10391041 }
@@ -1062,8 +1064,10 @@ static int cache_release(struct inode *inode, struct file *filp, · 22 unmodified lines
10621064 filp->private_data = NULL;
10631065 kfree(rp);
10641066
1067+ }
1068+ if (filp->f_mode & FMODE_WRITE) {
1069+ atomic_dec(&cd->writers);
10651070 cd->last_close = seconds_since_boot();
1066− atomic_dec(&cd->readers);
10671071 }
10681072 module_put(cd->owner);
10691073 return 0;
@@ -1171,7 +1175,7 @@ static void warn_no_listener(struct cache_detail *detail) · 101 unmodified lines
11711175
11721176 static bool cache_listeners_exist(struct cache_detail *detail)
11731177 {
1174− if (atomic_read(&detail->readers))
1178+ if (atomic_read(&detail->writers))
11751179 return true;
11761180 if (detail->last_close == 0)
11771181 /* This cache was never opened */
@@ -1520,6 +1524,9 @@ static ssize_t write_flush(struct file *file, const char __user *buf, · 342 unmodified lines
15201524 cd->nextcheck = now;
15211525 cache_flush();
15221526
1527+ if (cd->flush)
1528+ cd->flush();
1529+
15231530 *ppos += count;
15241531 return count;
15251532 }
net/sunrpc/svc.c+2−2
@@ -1233,8 +1233,8 @@ svc_generic_init_request(struct svc_rqst *rqstp, · 1232 unmodified lines
12331233
12341234 if (rqstp->rq_vers >= progp->pg_nvers )
12351235 goto err_bad_vers;
1236− versp = progp->pg_vers[rqstp->rq_vers];
1237− if (!versp)
1236+ versp = progp->pg_vers[rqstp->rq_vers];
1237+ if (!versp)
12381238 goto err_bad_vers;
12391239
12401240 /*
net/sunrpc/xprtrdma/svc_rdma.c+0−7
@@ -73,8 +73,6 @@ atomic_t rdma_stat_rq_prod; · 72 unmodified lines
7373 atomic_t rdma_stat_sq_poll;
7474 atomic_t rdma_stat_sq_prod;
7575
76−struct workqueue_struct *svc_rdma_wq;
77−
7876 /*
7977 * This function implements reading and resetting an atomic_t stat
8078 * variable through read/write to a proc file. Any write to the file
@@ -230,7 +228,6 @@ static struct ctl_table svcrdma_root_table[] = { · 149 unmodified lines
230228 void svc_rdma_cleanup(void)
231229 {
232230 dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n");
233− destroy_workqueue(svc_rdma_wq);
234231 if (svcrdma_table_header) {
235232 unregister_sysctl_table(svcrdma_table_header);
236233 svcrdma_table_header = NULL;
@@ -246,10 +243,6 @@ int svc_rdma_init(void) · 9 unmodified lines
246243 dprintk("\tmax_bc_requests : %u\n", svcrdma_max_bc_requests);
247244 dprintk("\tmax_inline : %d\n", svcrdma_max_req_size);
248245
249− svc_rdma_wq = alloc_workqueue("svc_rdma", 0, 0);
250− if (!svc_rdma_wq)
251− return -ENOMEM;
252−
253246 if (!svcrdma_table_header)
254247 svcrdma_table_header =
255248 register_sysctl_table(svcrdma_root_table);
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c+10−14
@@ -172,9 +172,10 @@ static void svc_rdma_recv_ctxt_destroy(struct svcxprt_rdma *rdma, · 171 unmodified lines
172172 void svc_rdma_recv_ctxts_destroy(struct svcxprt_rdma *rdma)
173173 {
174174 struct svc_rdma_recv_ctxt *ctxt;
175+ struct llist_node *node;
175176
176− while ((ctxt = svc_rdma_next_recv_ctxt(&rdma->sc_recv_ctxts))) {
177− list_del(&ctxt->rc_list);
177+ while ((node = llist_del_first(&rdma->sc_recv_ctxts))) {
178+ ctxt = llist_entry(node, struct svc_rdma_recv_ctxt, rc_node);
178179 svc_rdma_recv_ctxt_destroy(rdma, ctxt);
179180 }
180181 }
@@ -183,21 +184,18 @@ static struct svc_rdma_recv_ctxt * · 2 unmodified lines
183184 svc_rdma_recv_ctxt_get(struct svcxprt_rdma *rdma)
184185 {
185186 struct svc_rdma_recv_ctxt *ctxt;
187+ struct llist_node *node;
186188
187− spin_lock(&rdma->sc_recv_lock);
188− ctxt = svc_rdma_next_recv_ctxt(&rdma->sc_recv_ctxts);
189− if (!ctxt)
189+ node = llist_del_first(&rdma->sc_recv_ctxts);
190+ if (!node)
190191 goto out_empty;
191− list_del(&ctxt->rc_list);
192− spin_unlock(&rdma->sc_recv_lock);
192+ ctxt = llist_entry(node, struct svc_rdma_recv_ctxt, rc_node);
193193
194194 out:
195195 ctxt->rc_page_count = 0;
196196 return ctxt;
197197
198198 out_empty:
199− spin_unlock(&rdma->sc_recv_lock);
200−
201199 ctxt = svc_rdma_recv_ctxt_alloc(rdma);
202200 if (!ctxt)
203201 return NULL;
@@ -218,11 +216,9 @@ void svc_rdma_recv_ctxt_put(struct svcxprt_rdma *rdma, · 14 unmodified lines
218216 for (i = 0; i < ctxt->rc_page_count; i++)
219217 put_page(ctxt->rc_pages[i]);
220218
221− if (!ctxt->rc_temp) {
222− spin_lock(&rdma->sc_recv_lock);
223− list_add(&ctxt->rc_list, &rdma->sc_recv_ctxts);
224− spin_unlock(&rdma->sc_recv_lock);
225− } else
219+ if (!ctxt->rc_temp)
220+ llist_add(&ctxt->rc_node, &rdma->sc_recv_ctxts);
221+ else
226222 svc_rdma_recv_ctxt_destroy(rdma, ctxt);
227223 }
228224
net/sunrpc/xprtrdma/svc_rdma_transport.c+3−3
@@ -140,14 +140,13 @@ static struct svcxprt_rdma *svc_rdma_create_xprt(struct svc_serv *serv, · 139 unmodified lines
140140 INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q);
141141 INIT_LIST_HEAD(&cma_xprt->sc_read_complete_q);
142142 INIT_LIST_HEAD(&cma_xprt->sc_send_ctxts);
143− INIT_LIST_HEAD(&cma_xprt->sc_recv_ctxts);
143+ init_llist_head(&cma_xprt->sc_recv_ctxts);
144144 INIT_LIST_HEAD(&cma_xprt->sc_rw_ctxts);
145145 init_waitqueue_head(&cma_xprt->sc_send_wait);
146146
147147 spin_lock_init(&cma_xprt->sc_lock);
148148 spin_lock_init(&cma_xprt->sc_rq_dto_lock);
149149 spin_lock_init(&cma_xprt->sc_send_lock);
150− spin_lock_init(&cma_xprt->sc_recv_lock);
151150 spin_lock_init(&cma_xprt->sc_rw_ctxt_lock);
152151
153152 /*
@@ -630,8 +629,9 @@ static void svc_rdma_free(struct svc_xprt *xprt) · 476 unmodified lines
630629 {
631630 struct svcxprt_rdma *rdma =
632631 container_of(xprt, struct svcxprt_rdma, sc_xprt);
632+
633633 INIT_WORK(&rdma->sc_work, __svc_rdma_free);
634− queue_work(svc_rdma_wq, &rdma->sc_work);
634+ schedule_work(&rdma->sc_work);
635635 }
636636
637637 static int svc_rdma_has_wspace(struct svc_xprt *xprt)