hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/fs/nfsd/nfs4state.c
....@@ -42,6 +42,7 @@
4242 #include <linux/sunrpc/svcauth_gss.h>
4343 #include <linux/sunrpc/addr.h>
4444 #include <linux/jhash.h>
45
+#include <linux/string_helpers.h>
4546 #include "xdr4.h"
4647 #include "xdr4cb.h"
4748 #include "vfs.h"
....@@ -49,6 +50,8 @@
4950
5051 #include "netns.h"
5152 #include "pnfs.h"
53
+#include "filecache.h"
54
+#include "trace.h"
5255
5356 #define NFSDDBG_FACILITY NFSDDBG_PROC
5457
....@@ -77,6 +80,8 @@
7780 /* forward declarations */
7881 static bool check_for_locks(struct nfs4_file *fp, struct nfs4_lockowner *lowner);
7982 static void nfs4_free_ol_stateid(struct nfs4_stid *stid);
83
+void nfsd4_end_grace(struct nfsd_net *nn);
84
+static void _free_cpntf_state_locked(struct nfsd_net *nn, struct nfs4_cpntf_state *cps);
8085
8186 /* Locking: */
8287
....@@ -97,6 +102,13 @@
97102 * the refcount on the open stateid to drop.
98103 */
99104 static DECLARE_WAIT_QUEUE_HEAD(close_wq);
105
+
106
+/*
107
+ * A waitqueue where a writer to clients/#/ctl destroying a client can
108
+ * wait for cl_rpc_users to drop to 0 and then for the client to be
109
+ * unhashed.
110
+ */
111
+static DECLARE_WAIT_QUEUE_HEAD(expiry_wq);
100112
101113 static struct kmem_cache *client_slab;
102114 static struct kmem_cache *openowner_slab;
....@@ -137,7 +149,7 @@
137149
138150 if (is_client_expired(clp))
139151 return nfserr_expired;
140
- atomic_inc(&clp->cl_refcount);
152
+ atomic_inc(&clp->cl_rpc_users);
141153 return nfs_ok;
142154 }
143155
....@@ -156,11 +168,8 @@
156168 return;
157169 }
158170
159
- dprintk("renewing client (clientid %08x/%08x)\n",
160
- clp->cl_clientid.cl_boot,
161
- clp->cl_clientid.cl_id);
162171 list_move_tail(&clp->cl_lru, &nn->client_lru);
163
- clp->cl_time = get_seconds();
172
+ clp->cl_time = ktime_get_boottime_seconds();
164173 }
165174
166175 static void put_client_renew_locked(struct nfs4_client *clp)
....@@ -169,20 +178,24 @@
169178
170179 lockdep_assert_held(&nn->client_lock);
171180
172
- if (!atomic_dec_and_test(&clp->cl_refcount))
181
+ if (!atomic_dec_and_test(&clp->cl_rpc_users))
173182 return;
174183 if (!is_client_expired(clp))
175184 renew_client_locked(clp);
185
+ else
186
+ wake_up_all(&expiry_wq);
176187 }
177188
178189 static void put_client_renew(struct nfs4_client *clp)
179190 {
180191 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
181192
182
- if (!atomic_dec_and_lock(&clp->cl_refcount, &nn->client_lock))
193
+ if (!atomic_dec_and_lock(&clp->cl_rpc_users, &nn->client_lock))
183194 return;
184195 if (!is_client_expired(clp))
185196 renew_client_locked(clp);
197
+ else
198
+ wake_up_all(&expiry_wq);
186199 spin_unlock(&nn->client_lock);
187200 }
188201
....@@ -238,7 +251,7 @@
238251 }
239252 spin_unlock(&nn->blocked_locks_lock);
240253 if (found)
241
- posix_unblock_lock(&found->nbl_lock);
254
+ locks_delete_block(&found->nbl_lock);
242255 return found;
243256 }
244257
....@@ -267,6 +280,7 @@
267280 static void
268281 free_blocked_lock(struct nfsd4_blocked_lock *nbl)
269282 {
283
+ locks_delete_block(&nbl->nbl_lock);
270284 locks_release_private(&nbl->nbl_lock);
271285 kfree(nbl);
272286 }
....@@ -295,9 +309,16 @@
295309 nbl = list_first_entry(&reaplist, struct nfsd4_blocked_lock,
296310 nbl_lru);
297311 list_del_init(&nbl->nbl_lru);
298
- posix_unblock_lock(&nbl->nbl_lock);
299312 free_blocked_lock(nbl);
300313 }
314
+}
315
+
316
+static void
317
+nfsd4_cb_notify_lock_prepare(struct nfsd4_callback *cb)
318
+{
319
+ struct nfsd4_blocked_lock *nbl = container_of(cb,
320
+ struct nfsd4_blocked_lock, nbl_cb);
321
+ locks_delete_block(&nbl->nbl_lock);
301322 }
302323
303324 static int
....@@ -327,6 +348,7 @@
327348 }
328349
329350 static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops = {
351
+ .prepare = nfsd4_cb_notify_lock_prepare,
330352 .done = nfsd4_cb_notify_lock_done,
331353 .release = nfsd4_cb_notify_lock_release,
332354 };
....@@ -409,18 +431,18 @@
409431 }
410432 }
411433
412
-static struct file *
434
+static struct nfsd_file *
413435 __nfs4_get_fd(struct nfs4_file *f, int oflag)
414436 {
415437 if (f->fi_fds[oflag])
416
- return get_file(f->fi_fds[oflag]);
438
+ return nfsd_file_get(f->fi_fds[oflag]);
417439 return NULL;
418440 }
419441
420
-static struct file *
442
+static struct nfsd_file *
421443 find_writeable_file_locked(struct nfs4_file *f)
422444 {
423
- struct file *ret;
445
+ struct nfsd_file *ret;
424446
425447 lockdep_assert_held(&f->fi_lock);
426448
....@@ -430,10 +452,10 @@
430452 return ret;
431453 }
432454
433
-static struct file *
455
+static struct nfsd_file *
434456 find_writeable_file(struct nfs4_file *f)
435457 {
436
- struct file *ret;
458
+ struct nfsd_file *ret;
437459
438460 spin_lock(&f->fi_lock);
439461 ret = find_writeable_file_locked(f);
....@@ -442,9 +464,10 @@
442464 return ret;
443465 }
444466
445
-static struct file *find_readable_file_locked(struct nfs4_file *f)
467
+static struct nfsd_file *
468
+find_readable_file_locked(struct nfs4_file *f)
446469 {
447
- struct file *ret;
470
+ struct nfsd_file *ret;
448471
449472 lockdep_assert_held(&f->fi_lock);
450473
....@@ -454,10 +477,10 @@
454477 return ret;
455478 }
456479
457
-static struct file *
480
+static struct nfsd_file *
458481 find_readable_file(struct nfs4_file *f)
459482 {
460
- struct file *ret;
483
+ struct nfsd_file *ret;
461484
462485 spin_lock(&f->fi_lock);
463486 ret = find_readable_file_locked(f);
....@@ -466,10 +489,10 @@
466489 return ret;
467490 }
468491
469
-struct file *
492
+struct nfsd_file *
470493 find_any_file(struct nfs4_file *f)
471494 {
472
- struct file *ret;
495
+ struct nfsd_file *ret;
473496
474497 if (!f)
475498 return NULL;
....@@ -482,6 +505,28 @@
482505 }
483506 spin_unlock(&f->fi_lock);
484507 return ret;
508
+}
509
+
510
+static struct nfsd_file *find_any_file_locked(struct nfs4_file *f)
511
+{
512
+ lockdep_assert_held(&f->fi_lock);
513
+
514
+ if (f->fi_fds[O_RDWR])
515
+ return f->fi_fds[O_RDWR];
516
+ if (f->fi_fds[O_WRONLY])
517
+ return f->fi_fds[O_WRONLY];
518
+ if (f->fi_fds[O_RDONLY])
519
+ return f->fi_fds[O_RDONLY];
520
+ return NULL;
521
+}
522
+
523
+static struct nfsd_file *find_deleg_file_locked(struct nfs4_file *f)
524
+{
525
+ lockdep_assert_held(&f->fi_lock);
526
+
527
+ if (f->fi_deleg_file)
528
+ return f->fi_deleg_file;
529
+ return NULL;
485530 }
486531
487532 static atomic_long_t num_delegations;
....@@ -572,17 +617,17 @@
572617 might_lock(&fp->fi_lock);
573618
574619 if (atomic_dec_and_lock(&fp->fi_access[oflag], &fp->fi_lock)) {
575
- struct file *f1 = NULL;
576
- struct file *f2 = NULL;
620
+ struct nfsd_file *f1 = NULL;
621
+ struct nfsd_file *f2 = NULL;
577622
578623 swap(f1, fp->fi_fds[oflag]);
579624 if (atomic_read(&fp->fi_access[1 - oflag]) == 0)
580625 swap(f2, fp->fi_fds[O_RDWR]);
581626 spin_unlock(&fp->fi_lock);
582627 if (f1)
583
- fput(f1);
628
+ nfsd_file_put(f1);
584629 if (f2)
585
- fput(f2);
630
+ nfsd_file_put(f2);
586631 }
587632 }
588633
....@@ -688,7 +733,8 @@
688733
689734 idr_preload(GFP_KERNEL);
690735 spin_lock(&cl->cl_lock);
691
- new_id = idr_alloc_cyclic(&cl->cl_stateids, stid, 0, 0, GFP_NOWAIT);
736
+ /* Reserving 0 for start of file in nfsdfs "states" file: */
737
+ new_id = idr_alloc_cyclic(&cl->cl_stateids, stid, 1, 0, GFP_NOWAIT);
692738 spin_unlock(&cl->cl_lock);
693739 idr_preload_end();
694740 if (new_id < 0)
....@@ -701,6 +747,7 @@
701747 /* Will be incremented before return to client: */
702748 refcount_set(&stid->sc_count, 1);
703749 spin_lock_init(&stid->sc_lock);
750
+ INIT_LIST_HEAD(&stid->sc_cp_list);
704751
705752 /*
706753 * It shouldn't be a problem to reuse an opaque stateid value.
....@@ -717,6 +764,83 @@
717764 return NULL;
718765 }
719766
767
+/*
768
+ * Create a unique stateid_t to represent each COPY.
769
+ */
770
+static int nfs4_init_cp_state(struct nfsd_net *nn, copy_stateid_t *stid,
771
+ unsigned char sc_type)
772
+{
773
+ int new_id;
774
+
775
+ stid->stid.si_opaque.so_clid.cl_boot = (u32)nn->boot_time;
776
+ stid->stid.si_opaque.so_clid.cl_id = nn->s2s_cp_cl_id;
777
+ stid->sc_type = sc_type;
778
+
779
+ idr_preload(GFP_KERNEL);
780
+ spin_lock(&nn->s2s_cp_lock);
781
+ new_id = idr_alloc_cyclic(&nn->s2s_cp_stateids, stid, 0, 0, GFP_NOWAIT);
782
+ stid->stid.si_opaque.so_id = new_id;
783
+ stid->stid.si_generation = 1;
784
+ spin_unlock(&nn->s2s_cp_lock);
785
+ idr_preload_end();
786
+ if (new_id < 0)
787
+ return 0;
788
+ return 1;
789
+}
790
+
791
+int nfs4_init_copy_state(struct nfsd_net *nn, struct nfsd4_copy *copy)
792
+{
793
+ return nfs4_init_cp_state(nn, &copy->cp_stateid, NFS4_COPY_STID);
794
+}
795
+
796
+struct nfs4_cpntf_state *nfs4_alloc_init_cpntf_state(struct nfsd_net *nn,
797
+ struct nfs4_stid *p_stid)
798
+{
799
+ struct nfs4_cpntf_state *cps;
800
+
801
+ cps = kzalloc(sizeof(struct nfs4_cpntf_state), GFP_KERNEL);
802
+ if (!cps)
803
+ return NULL;
804
+ cps->cpntf_time = ktime_get_boottime_seconds();
805
+ refcount_set(&cps->cp_stateid.sc_count, 1);
806
+ if (!nfs4_init_cp_state(nn, &cps->cp_stateid, NFS4_COPYNOTIFY_STID))
807
+ goto out_free;
808
+ spin_lock(&nn->s2s_cp_lock);
809
+ list_add(&cps->cp_list, &p_stid->sc_cp_list);
810
+ spin_unlock(&nn->s2s_cp_lock);
811
+ return cps;
812
+out_free:
813
+ kfree(cps);
814
+ return NULL;
815
+}
816
+
817
+void nfs4_free_copy_state(struct nfsd4_copy *copy)
818
+{
819
+ struct nfsd_net *nn;
820
+
821
+ WARN_ON_ONCE(copy->cp_stateid.sc_type != NFS4_COPY_STID);
822
+ nn = net_generic(copy->cp_clp->net, nfsd_net_id);
823
+ spin_lock(&nn->s2s_cp_lock);
824
+ idr_remove(&nn->s2s_cp_stateids,
825
+ copy->cp_stateid.stid.si_opaque.so_id);
826
+ spin_unlock(&nn->s2s_cp_lock);
827
+}
828
+
829
+static void nfs4_free_cpntf_statelist(struct net *net, struct nfs4_stid *stid)
830
+{
831
+ struct nfs4_cpntf_state *cps;
832
+ struct nfsd_net *nn;
833
+
834
+ nn = net_generic(net, nfsd_net_id);
835
+ spin_lock(&nn->s2s_cp_lock);
836
+ while (!list_empty(&stid->sc_cp_list)) {
837
+ cps = list_first_entry(&stid->sc_cp_list,
838
+ struct nfs4_cpntf_state, cp_list);
839
+ _free_cpntf_state_locked(nn, cps);
840
+ }
841
+ spin_unlock(&nn->s2s_cp_lock);
842
+}
843
+
720844 static struct nfs4_ol_stateid * nfs4_alloc_open_stateid(struct nfs4_client *clp)
721845 {
722846 struct nfs4_stid *stid;
....@@ -730,6 +854,7 @@
730854
731855 static void nfs4_free_deleg(struct nfs4_stid *stid)
732856 {
857
+ WARN_ON(!list_empty(&stid->sc_cp_list));
733858 kmem_cache_free(deleg_slab, stid);
734859 atomic_long_dec(&num_delegations);
735860 }
....@@ -755,7 +880,7 @@
755880 static DEFINE_SPINLOCK(blocked_delegations_lock);
756881 static struct bloom_pair {
757882 int entries, old_entries;
758
- time_t swap_time;
883
+ time64_t swap_time;
759884 int new; /* index into 'set' */
760885 DECLARE_BITMAP(set[2], 256);
761886 } blocked_delegations;
....@@ -767,15 +892,15 @@
767892
768893 if (bd->entries == 0)
769894 return 0;
770
- if (seconds_since_boot() - bd->swap_time > 30) {
895
+ if (ktime_get_seconds() - bd->swap_time > 30) {
771896 spin_lock(&blocked_delegations_lock);
772
- if (seconds_since_boot() - bd->swap_time > 30) {
897
+ if (ktime_get_seconds() - bd->swap_time > 30) {
773898 bd->entries -= bd->old_entries;
774899 bd->old_entries = bd->entries;
775900 memset(bd->set[bd->new], 0,
776901 sizeof(bd->set[0]));
777902 bd->new = 1-bd->new;
778
- bd->swap_time = seconds_since_boot();
903
+ bd->swap_time = ktime_get_seconds();
779904 }
780905 spin_unlock(&blocked_delegations_lock);
781906 }
....@@ -805,7 +930,7 @@
805930 __set_bit((hash>>8)&255, bd->set[bd->new]);
806931 __set_bit((hash>>16)&255, bd->set[bd->new]);
807932 if (bd->entries == 0)
808
- bd->swap_time = seconds_since_boot();
933
+ bd->swap_time = ktime_get_seconds();
809934 bd->entries += 1;
810935 spin_unlock(&blocked_delegations_lock);
811936 }
....@@ -864,6 +989,7 @@
864989 return;
865990 }
866991 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id);
992
+ nfs4_free_cpntf_statelist(clp->net, s);
867993 spin_unlock(&clp->cl_lock);
868994 s->sc_free(s);
869995 if (fp)
....@@ -884,25 +1010,25 @@
8841010
8851011 static void put_deleg_file(struct nfs4_file *fp)
8861012 {
887
- struct file *filp = NULL;
1013
+ struct nfsd_file *nf = NULL;
8881014
8891015 spin_lock(&fp->fi_lock);
8901016 if (--fp->fi_delegees == 0)
891
- swap(filp, fp->fi_deleg_file);
1017
+ swap(nf, fp->fi_deleg_file);
8921018 spin_unlock(&fp->fi_lock);
8931019
894
- if (filp)
895
- fput(filp);
1020
+ if (nf)
1021
+ nfsd_file_put(nf);
8961022 }
8971023
8981024 static void nfs4_unlock_deleg_lease(struct nfs4_delegation *dp)
8991025 {
9001026 struct nfs4_file *fp = dp->dl_stid.sc_file;
901
- struct file *filp = fp->fi_deleg_file;
1027
+ struct nfsd_file *nf = fp->fi_deleg_file;
9021028
9031029 WARN_ON_ONCE(!fp->fi_delegees);
9041030
905
- vfs_setlease(filp, F_UNLCK, NULL, (void **)&dp);
1031
+ vfs_setlease(nf->nf_file, F_UNLCK, NULL, (void **)&dp);
9061032 put_deleg_file(fp);
9071033 }
9081034
....@@ -1019,9 +1145,9 @@
10191145 WARN_ON(!list_empty(&dp->dl_recall_lru));
10201146
10211147 if (clp->cl_minorversion) {
1148
+ spin_lock(&clp->cl_lock);
10221149 dp->dl_stid.sc_type = NFS4_REVOKED_DELEG_STID;
10231150 refcount_inc(&dp->dl_stid.sc_count);
1024
- spin_lock(&clp->cl_lock);
10251151 list_add(&dp->dl_recall_lru, &clp->cl_revoked);
10261152 spin_unlock(&clp->cl_lock);
10271153 }
....@@ -1037,9 +1163,9 @@
10371163 return id & CLIENT_HASH_MASK;
10381164 }
10391165
1040
-static unsigned int clientstr_hashval(const char *name)
1166
+static unsigned int clientstr_hashval(struct xdr_netobj name)
10411167 {
1042
- return opaque_hashval(name, 8) & CLIENT_HASH_MASK;
1168
+ return opaque_hashval(name.data, 8) & CLIENT_HASH_MASK;
10431169 }
10441170
10451171 /*
....@@ -1244,6 +1370,7 @@
12441370 release_all_access(stp);
12451371 if (stp->st_stateowner)
12461372 nfs4_put_stateowner(stp->st_stateowner);
1373
+ WARN_ON(!list_empty(&stid->sc_cp_list));
12471374 kmem_cache_free(stateid_slab, stid);
12481375 }
12491376
....@@ -1251,11 +1378,14 @@
12511378 {
12521379 struct nfs4_ol_stateid *stp = openlockstateid(stid);
12531380 struct nfs4_lockowner *lo = lockowner(stp->st_stateowner);
1254
- struct file *file;
1381
+ struct nfsd_file *nf;
12551382
1256
- file = find_any_file(stp->st_stid.sc_file);
1257
- if (file)
1258
- filp_close(file, (fl_owner_t)lo);
1383
+ nf = find_any_file(stp->st_stid.sc_file);
1384
+ if (nf) {
1385
+ get_file(nf->nf_file);
1386
+ filp_close(nf->nf_file, (fl_owner_t)lo);
1387
+ nfsd_file_put(nf);
1388
+ }
12591389 nfs4_free_ol_stateid(stid);
12601390 }
12611391
....@@ -1526,21 +1656,39 @@
15261656 * re-negotiate active sessions and reduce their slot usage to make
15271657 * room for new connections. For now we just fail the create session.
15281658 */
1529
-static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca)
1659
+static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca, struct nfsd_net *nn)
15301660 {
15311661 u32 slotsize = slot_bytes(ca);
15321662 u32 num = ca->maxreqs;
15331663 unsigned long avail, total_avail;
1664
+ unsigned int scale_factor;
15341665
15351666 spin_lock(&nfsd_drc_lock);
1536
- total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used;
1667
+ if (nfsd_drc_max_mem > nfsd_drc_mem_used)
1668
+ total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used;
1669
+ else
1670
+ /* We have handed out more space than we chose in
1671
+ * set_max_drc() to allow. That isn't really a
1672
+ * problem as long as that doesn't make us think we
1673
+ * have lots more due to integer overflow.
1674
+ */
1675
+ total_avail = 0;
15371676 avail = min((unsigned long)NFSD_MAX_MEM_PER_SESSION, total_avail);
15381677 /*
1539
- * Never use more than a third of the remaining memory,
1540
- * unless it's the only way to give this client a slot:
1678
+ * Never use more than a fraction of the remaining memory,
1679
+ * unless it's the only way to give this client a slot.
1680
+ * The chosen fraction is either 1/8 or 1/number of threads,
1681
+ * whichever is smaller. This ensures there are adequate
1682
+ * slots to support multiple clients per thread.
1683
+ * Give the client one slot even if that would require
1684
+ * over-allocation--it is better than failure.
15411685 */
1542
- avail = clamp_t(unsigned long, avail, slotsize, total_avail/3);
1686
+ scale_factor = max_t(unsigned int, 8, nn->nfsd_serv->sv_nrthreads);
1687
+
1688
+ avail = clamp_t(unsigned long, avail, slotsize,
1689
+ total_avail/scale_factor);
15431690 num = min_t(int, num, avail / slotsize);
1691
+ num = max_t(int, num, 1);
15441692 nfsd_drc_mem_used += num * slotsize;
15451693 spin_unlock(&nfsd_drc_lock);
15461694
....@@ -1802,8 +1950,7 @@
18021950 */
18031951 if (clid->cl_boot == (u32)nn->boot_time)
18041952 return 0;
1805
- dprintk("NFSD stale clientid (%08x/%08x) boot_time %08lx\n",
1806
- clid->cl_boot, clid->cl_id, nn->boot_time);
1953
+ trace_nfsd_clid_stale(clid);
18071954 return 1;
18081955 }
18091956
....@@ -1820,7 +1967,7 @@
18201967 clp = kmem_cache_zalloc(client_slab, GFP_KERNEL);
18211968 if (clp == NULL)
18221969 return NULL;
1823
- clp->cl_name.data = kmemdup(name.data, name.len, GFP_KERNEL);
1970
+ xdr_netobj_dup(&clp->cl_name, &name, GFP_KERNEL);
18241971 if (clp->cl_name.data == NULL)
18251972 goto err_no_name;
18261973 clp->cl_ownerstr_hashtbl = kmalloc_array(OWNER_HASH_SIZE,
....@@ -1830,10 +1977,9 @@
18301977 goto err_no_hashtbl;
18311978 for (i = 0; i < OWNER_HASH_SIZE; i++)
18321979 INIT_LIST_HEAD(&clp->cl_ownerstr_hashtbl[i]);
1833
- clp->cl_name.len = name.len;
18341980 INIT_LIST_HEAD(&clp->cl_sessions);
18351981 idr_init(&clp->cl_stateids);
1836
- atomic_set(&clp->cl_refcount, 0);
1982
+ atomic_set(&clp->cl_rpc_users, 0);
18371983 clp->cl_cb_state = NFSD4_CB_UNKNOWN;
18381984 INIT_LIST_HEAD(&clp->cl_idhash);
18391985 INIT_LIST_HEAD(&clp->cl_openowners);
....@@ -1843,6 +1989,8 @@
18431989 #ifdef CONFIG_NFSD_PNFS
18441990 INIT_LIST_HEAD(&clp->cl_lo_states);
18451991 #endif
1992
+ INIT_LIST_HEAD(&clp->async_copies);
1993
+ spin_lock_init(&clp->async_lock);
18461994 spin_lock_init(&clp->cl_lock);
18471995 rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
18481996 return clp;
....@@ -1851,6 +1999,25 @@
18511999 err_no_name:
18522000 kmem_cache_free(client_slab, clp);
18532001 return NULL;
2002
+}
2003
+
2004
+static void __free_client(struct kref *k)
2005
+{
2006
+ struct nfsdfs_client *c = container_of(k, struct nfsdfs_client, cl_ref);
2007
+ struct nfs4_client *clp = container_of(c, struct nfs4_client, cl_nfsdfs);
2008
+
2009
+ free_svc_cred(&clp->cl_cred);
2010
+ kfree(clp->cl_ownerstr_hashtbl);
2011
+ kfree(clp->cl_name.data);
2012
+ kfree(clp->cl_nii_domain.data);
2013
+ kfree(clp->cl_nii_name.data);
2014
+ idr_destroy(&clp->cl_stateids);
2015
+ kmem_cache_free(client_slab, clp);
2016
+}
2017
+
2018
+static void drop_client(struct nfs4_client *clp)
2019
+{
2020
+ kref_put(&clp->cl_nfsdfs.cl_ref, __free_client);
18542021 }
18552022
18562023 static void
....@@ -1865,11 +2032,12 @@
18652032 free_session(ses);
18662033 }
18672034 rpc_destroy_wait_queue(&clp->cl_cb_waitq);
1868
- free_svc_cred(&clp->cl_cred);
1869
- kfree(clp->cl_ownerstr_hashtbl);
1870
- kfree(clp->cl_name.data);
1871
- idr_destroy(&clp->cl_stateids);
1872
- kmem_cache_free(client_slab, clp);
2035
+ if (clp->cl_nfsd_dentry) {
2036
+ nfsd_client_rmdir(clp->cl_nfsd_dentry);
2037
+ clp->cl_nfsd_dentry = NULL;
2038
+ wake_up_all(&expiry_wq);
2039
+ }
2040
+ drop_client(clp);
18732041 }
18742042
18752043 /* must be called under the client_lock */
....@@ -1910,7 +2078,7 @@
19102078
19112079 static __be32 mark_client_expired_locked(struct nfs4_client *clp)
19122080 {
1913
- if (atomic_read(&clp->cl_refcount))
2081
+ if (atomic_read(&clp->cl_rpc_users))
19142082 return nfserr_jukebox;
19152083 unhash_client_locked(clp);
19162084 return nfs_ok;
....@@ -1958,10 +2126,12 @@
19582126 }
19592127 }
19602128 nfsd4_return_all_client_layouts(clp);
2129
+ nfsd4_shutdown_copy(clp);
19612130 nfsd4_shutdown_callback(clp);
19622131 if (clp->cl_cb_conn.cb_xprt)
19632132 svc_xprt_put(clp->cl_cb_conn.cb_xprt);
19642133 free_client(clp);
2134
+ wake_up_all(&expiry_wq);
19652135 }
19662136
19672137 static void
....@@ -1969,6 +2139,22 @@
19692139 {
19702140 unhash_client(clp);
19712141 __destroy_client(clp);
2142
+}
2143
+
2144
+static void inc_reclaim_complete(struct nfs4_client *clp)
2145
+{
2146
+ struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
2147
+
2148
+ if (!nn->track_reclaim_completes)
2149
+ return;
2150
+ if (!nfsd4_find_reclaim_client(clp->cl_name, nn))
2151
+ return;
2152
+ if (atomic_inc_return(&nn->nr_reclaim_complete) ==
2153
+ nn->reclaim_str_hashtbl_size) {
2154
+ printk(KERN_INFO "NFSD: all clients done reclaiming, ending NFSv4 grace period (net %x)\n",
2155
+ clp->net->ns.inum);
2156
+ nfsd4_end_grace(nn);
2157
+ }
19722158 }
19732159
19742160 static void expire_client(struct nfs4_client *clp)
....@@ -2020,11 +2206,6 @@
20202206 if (o1->len > o2->len)
20212207 return 1;
20222208 return memcmp(o1->data, o2->data, o1->len);
2023
-}
2024
-
2025
-static int same_name(const char *n1, const char *n2)
2026
-{
2027
- return 0 == memcmp(n1, n2, HEXDIR_LEN);
20282209 }
20292210
20302211 static int
....@@ -2121,14 +2302,14 @@
21212302 * This is opaque to client, so no need to byte-swap. Use
21222303 * __force to keep sparse happy
21232304 */
2124
- verf[0] = (__force __be32)get_seconds();
2305
+ verf[0] = (__force __be32)(u32)ktime_get_real_seconds();
21252306 verf[1] = (__force __be32)nn->clverifier_counter++;
21262307 memcpy(clp->cl_confirm.data, verf, sizeof(clp->cl_confirm.data));
21272308 }
21282309
21292310 static void gen_clid(struct nfs4_client *clp, struct nfsd_net *nn)
21302311 {
2131
- clp->cl_clientid.cl_boot = nn->boot_time;
2312
+ clp->cl_clientid.cl_boot = (u32)nn->boot_time;
21322313 clp->cl_clientid.cl_id = nn->clientid_counter++;
21332314 gen_confirm(clp, nn);
21342315 }
....@@ -2161,6 +2342,380 @@
21612342 return s;
21622343 }
21632344
2345
+static struct nfs4_client *get_nfsdfs_clp(struct inode *inode)
2346
+{
2347
+ struct nfsdfs_client *nc;
2348
+ nc = get_nfsdfs_client(inode);
2349
+ if (!nc)
2350
+ return NULL;
2351
+ return container_of(nc, struct nfs4_client, cl_nfsdfs);
2352
+}
2353
+
2354
+static void seq_quote_mem(struct seq_file *m, char *data, int len)
2355
+{
2356
+ seq_printf(m, "\"");
2357
+ seq_escape_mem_ascii(m, data, len);
2358
+ seq_printf(m, "\"");
2359
+}
2360
+
2361
+static int client_info_show(struct seq_file *m, void *v)
2362
+{
2363
+ struct inode *inode = m->private;
2364
+ struct nfs4_client *clp;
2365
+ u64 clid;
2366
+
2367
+ clp = get_nfsdfs_clp(inode);
2368
+ if (!clp)
2369
+ return -ENXIO;
2370
+ memcpy(&clid, &clp->cl_clientid, sizeof(clid));
2371
+ seq_printf(m, "clientid: 0x%llx\n", clid);
2372
+ seq_printf(m, "address: \"%pISpc\"\n", (struct sockaddr *)&clp->cl_addr);
2373
+ seq_printf(m, "name: ");
2374
+ seq_quote_mem(m, clp->cl_name.data, clp->cl_name.len);
2375
+ seq_printf(m, "\nminor version: %d\n", clp->cl_minorversion);
2376
+ if (clp->cl_nii_domain.data) {
2377
+ seq_printf(m, "Implementation domain: ");
2378
+ seq_quote_mem(m, clp->cl_nii_domain.data,
2379
+ clp->cl_nii_domain.len);
2380
+ seq_printf(m, "\nImplementation name: ");
2381
+ seq_quote_mem(m, clp->cl_nii_name.data, clp->cl_nii_name.len);
2382
+ seq_printf(m, "\nImplementation time: [%lld, %ld]\n",
2383
+ clp->cl_nii_time.tv_sec, clp->cl_nii_time.tv_nsec);
2384
+ }
2385
+ drop_client(clp);
2386
+
2387
+ return 0;
2388
+}
2389
+
2390
+static int client_info_open(struct inode *inode, struct file *file)
2391
+{
2392
+ return single_open(file, client_info_show, inode);
2393
+}
2394
+
2395
+static const struct file_operations client_info_fops = {
2396
+ .open = client_info_open,
2397
+ .read = seq_read,
2398
+ .llseek = seq_lseek,
2399
+ .release = single_release,
2400
+};
2401
+
2402
+static void *states_start(struct seq_file *s, loff_t *pos)
2403
+ __acquires(&clp->cl_lock)
2404
+{
2405
+ struct nfs4_client *clp = s->private;
2406
+ unsigned long id = *pos;
2407
+ void *ret;
2408
+
2409
+ spin_lock(&clp->cl_lock);
2410
+ ret = idr_get_next_ul(&clp->cl_stateids, &id);
2411
+ *pos = id;
2412
+ return ret;
2413
+}
2414
+
2415
+static void *states_next(struct seq_file *s, void *v, loff_t *pos)
2416
+{
2417
+ struct nfs4_client *clp = s->private;
2418
+ unsigned long id = *pos;
2419
+ void *ret;
2420
+
2421
+ id = *pos;
2422
+ id++;
2423
+ ret = idr_get_next_ul(&clp->cl_stateids, &id);
2424
+ *pos = id;
2425
+ return ret;
2426
+}
2427
+
2428
+static void states_stop(struct seq_file *s, void *v)
2429
+ __releases(&clp->cl_lock)
2430
+{
2431
+ struct nfs4_client *clp = s->private;
2432
+
2433
+ spin_unlock(&clp->cl_lock);
2434
+}
2435
+
2436
+static void nfs4_show_fname(struct seq_file *s, struct nfsd_file *f)
2437
+{
2438
+ seq_printf(s, "filename: \"%pD2\"", f->nf_file);
2439
+}
2440
+
2441
+static void nfs4_show_superblock(struct seq_file *s, struct nfsd_file *f)
2442
+{
2443
+ struct inode *inode = f->nf_inode;
2444
+
2445
+ seq_printf(s, "superblock: \"%02x:%02x:%ld\"",
2446
+ MAJOR(inode->i_sb->s_dev),
2447
+ MINOR(inode->i_sb->s_dev),
2448
+ inode->i_ino);
2449
+}
2450
+
2451
+static void nfs4_show_owner(struct seq_file *s, struct nfs4_stateowner *oo)
2452
+{
2453
+ seq_printf(s, "owner: ");
2454
+ seq_quote_mem(s, oo->so_owner.data, oo->so_owner.len);
2455
+}
2456
+
2457
+static void nfs4_show_stateid(struct seq_file *s, stateid_t *stid)
2458
+{
2459
+ seq_printf(s, "0x%.8x", stid->si_generation);
2460
+ seq_printf(s, "%12phN", &stid->si_opaque);
2461
+}
2462
+
2463
+static int nfs4_show_open(struct seq_file *s, struct nfs4_stid *st)
2464
+{
2465
+ struct nfs4_ol_stateid *ols;
2466
+ struct nfs4_file *nf;
2467
+ struct nfsd_file *file;
2468
+ struct nfs4_stateowner *oo;
2469
+ unsigned int access, deny;
2470
+
2471
+ if (st->sc_type != NFS4_OPEN_STID && st->sc_type != NFS4_LOCK_STID)
2472
+ return 0; /* XXX: or SEQ_SKIP? */
2473
+ ols = openlockstateid(st);
2474
+ oo = ols->st_stateowner;
2475
+ nf = st->sc_file;
2476
+
2477
+ spin_lock(&nf->fi_lock);
2478
+ file = find_any_file_locked(nf);
2479
+ if (!file)
2480
+ goto out;
2481
+
2482
+ seq_printf(s, "- ");
2483
+ nfs4_show_stateid(s, &st->sc_stateid);
2484
+ seq_printf(s, ": { type: open, ");
2485
+
2486
+ access = bmap_to_share_mode(ols->st_access_bmap);
2487
+ deny = bmap_to_share_mode(ols->st_deny_bmap);
2488
+
2489
+ seq_printf(s, "access: %s%s, ",
2490
+ access & NFS4_SHARE_ACCESS_READ ? "r" : "-",
2491
+ access & NFS4_SHARE_ACCESS_WRITE ? "w" : "-");
2492
+ seq_printf(s, "deny: %s%s, ",
2493
+ deny & NFS4_SHARE_ACCESS_READ ? "r" : "-",
2494
+ deny & NFS4_SHARE_ACCESS_WRITE ? "w" : "-");
2495
+
2496
+ nfs4_show_superblock(s, file);
2497
+ seq_printf(s, ", ");
2498
+ nfs4_show_fname(s, file);
2499
+ seq_printf(s, ", ");
2500
+ nfs4_show_owner(s, oo);
2501
+ seq_printf(s, " }\n");
2502
+out:
2503
+ spin_unlock(&nf->fi_lock);
2504
+ return 0;
2505
+}
2506
+
2507
+static int nfs4_show_lock(struct seq_file *s, struct nfs4_stid *st)
2508
+{
2509
+ struct nfs4_ol_stateid *ols;
2510
+ struct nfs4_file *nf;
2511
+ struct nfsd_file *file;
2512
+ struct nfs4_stateowner *oo;
2513
+
2514
+ ols = openlockstateid(st);
2515
+ oo = ols->st_stateowner;
2516
+ nf = st->sc_file;
2517
+ spin_lock(&nf->fi_lock);
2518
+ file = find_any_file_locked(nf);
2519
+ if (!file)
2520
+ goto out;
2521
+
2522
+ seq_printf(s, "- ");
2523
+ nfs4_show_stateid(s, &st->sc_stateid);
2524
+ seq_printf(s, ": { type: lock, ");
2525
+
2526
+ /*
2527
+ * Note: a lock stateid isn't really the same thing as a lock,
2528
+ * it's the locking state held by one owner on a file, and there
2529
+ * may be multiple (or no) lock ranges associated with it.
2530
+ * (Same for the matter is true of open stateids.)
2531
+ */
2532
+
2533
+ nfs4_show_superblock(s, file);
2534
+ /* XXX: open stateid? */
2535
+ seq_printf(s, ", ");
2536
+ nfs4_show_fname(s, file);
2537
+ seq_printf(s, ", ");
2538
+ nfs4_show_owner(s, oo);
2539
+ seq_printf(s, " }\n");
2540
+out:
2541
+ spin_unlock(&nf->fi_lock);
2542
+ return 0;
2543
+}
2544
+
2545
+static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st)
2546
+{
2547
+ struct nfs4_delegation *ds;
2548
+ struct nfs4_file *nf;
2549
+ struct nfsd_file *file;
2550
+
2551
+ ds = delegstateid(st);
2552
+ nf = st->sc_file;
2553
+ spin_lock(&nf->fi_lock);
2554
+ file = find_deleg_file_locked(nf);
2555
+ if (!file)
2556
+ goto out;
2557
+
2558
+ seq_printf(s, "- ");
2559
+ nfs4_show_stateid(s, &st->sc_stateid);
2560
+ seq_printf(s, ": { type: deleg, ");
2561
+
2562
+ /* Kinda dead code as long as we only support read delegs: */
2563
+ seq_printf(s, "access: %s, ",
2564
+ ds->dl_type == NFS4_OPEN_DELEGATE_READ ? "r" : "w");
2565
+
2566
+ /* XXX: lease time, whether it's being recalled. */
2567
+
2568
+ nfs4_show_superblock(s, file);
2569
+ seq_printf(s, ", ");
2570
+ nfs4_show_fname(s, file);
2571
+ seq_printf(s, " }\n");
2572
+out:
2573
+ spin_unlock(&nf->fi_lock);
2574
+ return 0;
2575
+}
2576
+
2577
+static int nfs4_show_layout(struct seq_file *s, struct nfs4_stid *st)
2578
+{
2579
+ struct nfs4_layout_stateid *ls;
2580
+ struct nfsd_file *file;
2581
+
2582
+ ls = container_of(st, struct nfs4_layout_stateid, ls_stid);
2583
+ file = ls->ls_file;
2584
+
2585
+ seq_printf(s, "- ");
2586
+ nfs4_show_stateid(s, &st->sc_stateid);
2587
+ seq_printf(s, ": { type: layout, ");
2588
+
2589
+ /* XXX: What else would be useful? */
2590
+
2591
+ nfs4_show_superblock(s, file);
2592
+ seq_printf(s, ", ");
2593
+ nfs4_show_fname(s, file);
2594
+ seq_printf(s, " }\n");
2595
+
2596
+ return 0;
2597
+}
2598
+
2599
+static int states_show(struct seq_file *s, void *v)
2600
+{
2601
+ struct nfs4_stid *st = v;
2602
+
2603
+ switch (st->sc_type) {
2604
+ case NFS4_OPEN_STID:
2605
+ return nfs4_show_open(s, st);
2606
+ case NFS4_LOCK_STID:
2607
+ return nfs4_show_lock(s, st);
2608
+ case NFS4_DELEG_STID:
2609
+ return nfs4_show_deleg(s, st);
2610
+ case NFS4_LAYOUT_STID:
2611
+ return nfs4_show_layout(s, st);
2612
+ default:
2613
+ return 0; /* XXX: or SEQ_SKIP? */
2614
+ }
2615
+ /* XXX: copy stateids? */
2616
+}
2617
+
2618
+static struct seq_operations states_seq_ops = {
2619
+ .start = states_start,
2620
+ .next = states_next,
2621
+ .stop = states_stop,
2622
+ .show = states_show
2623
+};
2624
+
2625
+static int client_states_open(struct inode *inode, struct file *file)
2626
+{
2627
+ struct seq_file *s;
2628
+ struct nfs4_client *clp;
2629
+ int ret;
2630
+
2631
+ clp = get_nfsdfs_clp(inode);
2632
+ if (!clp)
2633
+ return -ENXIO;
2634
+
2635
+ ret = seq_open(file, &states_seq_ops);
2636
+ if (ret)
2637
+ return ret;
2638
+ s = file->private_data;
2639
+ s->private = clp;
2640
+ return 0;
2641
+}
2642
+
2643
+static int client_opens_release(struct inode *inode, struct file *file)
2644
+{
2645
+ struct seq_file *m = file->private_data;
2646
+ struct nfs4_client *clp = m->private;
2647
+
2648
+ /* XXX: alternatively, we could get/drop in seq start/stop */
2649
+ drop_client(clp);
2650
+ return 0;
2651
+}
2652
+
2653
+static const struct file_operations client_states_fops = {
2654
+ .open = client_states_open,
2655
+ .read = seq_read,
2656
+ .llseek = seq_lseek,
2657
+ .release = client_opens_release,
2658
+};
2659
+
2660
+/*
2661
+ * Normally we refuse to destroy clients that are in use, but here the
2662
+ * administrator is telling us to just do it. We also want to wait
2663
+ * so the caller has a guarantee that the client's locks are gone by
2664
+ * the time the write returns:
2665
+ */
2666
+static void force_expire_client(struct nfs4_client *clp)
2667
+{
2668
+ struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
2669
+ bool already_expired;
2670
+
2671
+ spin_lock(&nn->client_lock);
2672
+ clp->cl_time = 0;
2673
+ spin_unlock(&nn->client_lock);
2674
+
2675
+ wait_event(expiry_wq, atomic_read(&clp->cl_rpc_users) == 0);
2676
+ spin_lock(&nn->client_lock);
2677
+ already_expired = list_empty(&clp->cl_lru);
2678
+ if (!already_expired)
2679
+ unhash_client_locked(clp);
2680
+ spin_unlock(&nn->client_lock);
2681
+
2682
+ if (!already_expired)
2683
+ expire_client(clp);
2684
+ else
2685
+ wait_event(expiry_wq, clp->cl_nfsd_dentry == NULL);
2686
+}
2687
+
2688
+static ssize_t client_ctl_write(struct file *file, const char __user *buf,
2689
+ size_t size, loff_t *pos)
2690
+{
2691
+ char *data;
2692
+ struct nfs4_client *clp;
2693
+
2694
+ data = simple_transaction_get(file, buf, size);
2695
+ if (IS_ERR(data))
2696
+ return PTR_ERR(data);
2697
+ if (size != 7 || 0 != memcmp(data, "expire\n", 7))
2698
+ return -EINVAL;
2699
+ clp = get_nfsdfs_clp(file_inode(file));
2700
+ if (!clp)
2701
+ return -ENXIO;
2702
+ force_expire_client(clp);
2703
+ drop_client(clp);
2704
+ return 7;
2705
+}
2706
+
2707
+static const struct file_operations client_ctl_fops = {
2708
+ .write = client_ctl_write,
2709
+ .release = simple_transaction_release,
2710
+};
2711
+
2712
+static const struct tree_descr client_files[] = {
2713
+ [0] = {"info", &client_info_fops, S_IRUSR},
2714
+ [1] = {"states", &client_states_fops, S_IRUSR},
2715
+ [2] = {"ctl", &client_ctl_fops, S_IWUSR},
2716
+ [3] = {""},
2717
+};
2718
+
21642719 static struct nfs4_client *create_client(struct xdr_netobj name,
21652720 struct svc_rqst *rqstp, nfs4_verifier *verf)
21662721 {
....@@ -2168,6 +2723,7 @@
21682723 struct sockaddr *sa = svc_addr(rqstp);
21692724 int ret;
21702725 struct net *net = SVC_NET(rqstp);
2726
+ struct nfsd_net *nn = net_generic(net, nfsd_net_id);
21712727
21722728 clp = alloc_client(name);
21732729 if (clp == NULL)
....@@ -2178,13 +2734,22 @@
21782734 free_client(clp);
21792735 return NULL;
21802736 }
2737
+ gen_clid(clp, nn);
2738
+ kref_init(&clp->cl_nfsdfs.cl_ref);
21812739 nfsd4_init_cb(&clp->cl_cb_null, clp, NULL, NFSPROC4_CLNT_CB_NULL);
2182
- clp->cl_time = get_seconds();
2740
+ clp->cl_time = ktime_get_boottime_seconds();
21832741 clear_bit(0, &clp->cl_cb_slot_busy);
21842742 copy_verf(clp, verf);
2185
- rpc_copy_addr((struct sockaddr *) &clp->cl_addr, sa);
2743
+ memcpy(&clp->cl_addr, sa, sizeof(struct sockaddr_storage));
21862744 clp->cl_cb_session = NULL;
21872745 clp->net = net;
2746
+ clp->cl_nfsd_dentry = nfsd_client_mkdir(nn, &clp->cl_nfsdfs,
2747
+ clp->cl_clientid.cl_id - nn->clientid_base,
2748
+ client_files);
2749
+ if (!clp->cl_nfsd_dentry) {
2750
+ free_client(clp);
2751
+ return NULL;
2752
+ }
21882753 return clp;
21892754 }
21902755
....@@ -2345,14 +2910,12 @@
23452910 conn->cb_prog = se->se_callback_prog;
23462911 conn->cb_ident = se->se_callback_ident;
23472912 memcpy(&conn->cb_saddr, &rqstp->rq_daddr, rqstp->rq_daddrlen);
2913
+ trace_nfsd_cb_args(clp, conn);
23482914 return;
23492915 out_err:
23502916 conn->cb_addr.ss_family = AF_UNSPEC;
23512917 conn->cb_addrlen = 0;
2352
- dprintk("NFSD: this client (clientid %08x/%08x) "
2353
- "will not receive delegations\n",
2354
- clp->cl_clientid.cl_boot, clp->cl_clientid.cl_id);
2355
-
2918
+ trace_nfsd_cb_nodelegs(clp);
23562919 return;
23572920 }
23582921
....@@ -2491,7 +3054,23 @@
24913054 || !list_empty(&clp->cl_lo_states)
24923055 #endif
24933056 || !list_empty(&clp->cl_delegations)
2494
- || !list_empty(&clp->cl_sessions);
3057
+ || !list_empty(&clp->cl_sessions)
3058
+ || !list_empty(&clp->async_copies);
3059
+}
3060
+
3061
+static __be32 copy_impl_id(struct nfs4_client *clp,
3062
+ struct nfsd4_exchange_id *exid)
3063
+{
3064
+ if (!exid->nii_domain.data)
3065
+ return 0;
3066
+ xdr_netobj_dup(&clp->cl_nii_domain, &exid->nii_domain, GFP_KERNEL);
3067
+ if (!clp->cl_nii_domain.data)
3068
+ return nfserr_jukebox;
3069
+ xdr_netobj_dup(&clp->cl_nii_name, &exid->nii_name, GFP_KERNEL);
3070
+ if (!clp->cl_nii_name.data)
3071
+ return nfserr_jukebox;
3072
+ clp->cl_nii_time = exid->nii_time;
3073
+ return 0;
24953074 }
24963075
24973076 __be32
....@@ -2520,6 +3099,9 @@
25203099 new = create_client(exid->clname, rqstp, &verf);
25213100 if (new == NULL)
25223101 return nfserr_jukebox;
3102
+ status = copy_impl_id(new, exid);
3103
+ if (status)
3104
+ goto out_nolock;
25233105
25243106 switch (exid->spa_how) {
25253107 case SP4_MACH_CRED:
....@@ -2558,6 +3140,7 @@
25583140 break;
25593141 default: /* checked by xdr code */
25603142 WARN_ON_ONCE(1);
3143
+ fallthrough;
25613144 case SP4_SSV:
25623145 status = nfserr_encr_alg_unsupp;
25633146 goto out_nolock;
....@@ -2627,7 +3210,6 @@
26273210 new->cl_spo_must_allow.u.words[0] = exid->spo_must_allow[0];
26283211 new->cl_spo_must_allow.u.words[1] = exid->spo_must_allow[1];
26293212
2630
- gen_clid(new, nn);
26313213 add_to_unconfirmed(new);
26323214 swap(new, conf);
26333215 out_copy:
....@@ -2732,10 +3314,10 @@
27323314 * performance. When short on memory we therefore prefer to
27333315 * decrease number of slots instead of their size. Clients that
27343316 * request larger slots than they need will get poor results:
3317
+ * Note that we always allow at least one slot, because our
3318
+ * accounting is soft and provides no guarantees either way.
27353319 */
2736
- ca->maxreqs = nfsd4_get_drc_mem(ca);
2737
- if (!ca->maxreqs)
2738
- return nfserr_jukebox;
3320
+ ca->maxreqs = nfsd4_get_drc_mem(ca, nn);
27393321
27403322 return nfs_ok;
27413323 }
....@@ -2913,7 +3495,7 @@
29133495 case NFS4_CDFC4_BACK_OR_BOTH:
29143496 *dir = NFS4_CDFC4_BOTH;
29153497 return nfs_ok;
2916
- };
3498
+ }
29173499 return nfserr_inval;
29183500 }
29193501
....@@ -2939,6 +3521,47 @@
29393521 return nfs_ok;
29403522 }
29413523
3524
+static struct nfsd4_conn *__nfsd4_find_conn(struct svc_xprt *xpt, struct nfsd4_session *s)
3525
+{
3526
+ struct nfsd4_conn *c;
3527
+
3528
+ list_for_each_entry(c, &s->se_conns, cn_persession) {
3529
+ if (c->cn_xprt == xpt) {
3530
+ return c;
3531
+ }
3532
+ }
3533
+ return NULL;
3534
+}
3535
+
3536
+static __be32 nfsd4_match_existing_connection(struct svc_rqst *rqst,
3537
+ struct nfsd4_session *session, u32 req, struct nfsd4_conn **conn)
3538
+{
3539
+ struct nfs4_client *clp = session->se_client;
3540
+ struct svc_xprt *xpt = rqst->rq_xprt;
3541
+ struct nfsd4_conn *c;
3542
+ __be32 status;
3543
+
3544
+ /* Following the last paragraph of RFC 5661 Section 18.34.3: */
3545
+ spin_lock(&clp->cl_lock);
3546
+ c = __nfsd4_find_conn(xpt, session);
3547
+ if (!c)
3548
+ status = nfserr_noent;
3549
+ else if (req == c->cn_flags)
3550
+ status = nfs_ok;
3551
+ else if (req == NFS4_CDFC4_FORE_OR_BOTH &&
3552
+ c->cn_flags != NFS4_CDFC4_BACK)
3553
+ status = nfs_ok;
3554
+ else if (req == NFS4_CDFC4_BACK_OR_BOTH &&
3555
+ c->cn_flags != NFS4_CDFC4_FORE)
3556
+ status = nfs_ok;
3557
+ else
3558
+ status = nfserr_inval;
3559
+ spin_unlock(&clp->cl_lock);
3560
+ if (status == nfs_ok && conn)
3561
+ *conn = c;
3562
+ return status;
3563
+}
3564
+
29423565 __be32 nfsd4_bind_conn_to_session(struct svc_rqst *rqstp,
29433566 struct nfsd4_compound_state *cstate,
29443567 union nfsd4_op_u *u)
....@@ -2959,6 +3582,17 @@
29593582 goto out_no_session;
29603583 status = nfserr_wrong_cred;
29613584 if (!nfsd4_mach_creds_match(session->se_client, rqstp))
3585
+ goto out;
3586
+ status = nfsd4_match_existing_connection(rqstp, session,
3587
+ bcts->dir, &conn);
3588
+ if (status == nfs_ok) {
3589
+ if (bcts->dir == NFS4_CDFC4_FORE_OR_BOTH ||
3590
+ bcts->dir == NFS4_CDFC4_BACK)
3591
+ conn->cn_flags |= NFS4_CDFC4_BACK;
3592
+ nfsd4_probe_callback(session->se_client);
3593
+ goto out;
3594
+ }
3595
+ if (status == nfserr_inval)
29623596 goto out;
29633597 status = nfsd4_map_bcts_dir(&bcts->dir);
29643598 if (status)
....@@ -3023,18 +3657,6 @@
30233657 spin_unlock(&nn->client_lock);
30243658 out:
30253659 return status;
3026
-}
3027
-
3028
-static struct nfsd4_conn *__nfsd4_find_conn(struct svc_xprt *xpt, struct nfsd4_session *s)
3029
-{
3030
- struct nfsd4_conn *c;
3031
-
3032
- list_for_each_entry(c, &s->se_conns, cn_persession) {
3033
- if (c->cn_xprt == xpt) {
3034
- return c;
3035
- }
3036
- }
3037
- return NULL;
30383660 }
30393661
30403662 static __be32 nfsd4_sequence_check_conn(struct nfsd4_conn *new, struct nfsd4_session *ses)
....@@ -3331,6 +3953,7 @@
33313953
33323954 status = nfs_ok;
33333955 nfsd4_client_record_create(cstate->session->se_client);
3956
+ inc_reclaim_complete(cstate->session->se_client);
33343957 out:
33353958 return status;
33363959 }
....@@ -3359,23 +3982,18 @@
33593982 if (clp_used_exchangeid(conf))
33603983 goto out;
33613984 if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) {
3362
- char addr_str[INET6_ADDRSTRLEN];
3363
- rpc_ntop((struct sockaddr *) &conf->cl_addr, addr_str,
3364
- sizeof(addr_str));
3365
- dprintk("NFSD: setclientid: string in use by client "
3366
- "at %s\n", addr_str);
3985
+ trace_nfsd_clid_inuse_err(conf);
33673986 goto out;
33683987 }
33693988 }
33703989 unconf = find_unconfirmed_client_by_name(&clname, nn);
33713990 if (unconf)
33723991 unhash_client_locked(unconf);
3992
+ /* We need to handle only case 1: probable callback update */
33733993 if (conf && same_verf(&conf->cl_verifier, &clverifier)) {
3374
- /* case 1: probable callback update */
33753994 copy_clid(new, conf);
33763995 gen_confirm(new, nn);
3377
- } else /* case 4 (new client) or cases 2, 3 (client reboot): */
3378
- gen_clid(new, nn);
3996
+ }
33793997 new->cl_minorversion = 0;
33803998 gen_callback(new, setclid, rqstp);
33813999 add_to_unconfirmed(new);
....@@ -3558,7 +4176,6 @@
35584176 out_free_client_slab:
35594177 kmem_cache_destroy(client_slab);
35604178 out:
3561
- dprintk("nfsd4: out of memory while initializing nfsv4\n");
35624179 return -ENOMEM;
35634180 }
35644181
....@@ -3598,12 +4215,11 @@
35984215 if (!sop)
35994216 return NULL;
36004217
3601
- sop->so_owner.data = kmemdup(owner->data, owner->len, GFP_KERNEL);
4218
+ xdr_netobj_dup(&sop->so_owner, owner, GFP_KERNEL);
36024219 if (!sop->so_owner.data) {
36034220 kmem_cache_free(slab, sop);
36044221 return NULL;
36054222 }
3606
- sop->so_owner.len = owner->len;
36074223
36084224 INIT_LIST_HEAD(&sop->so_stateids);
36094225 sop->so_client = clp;
....@@ -3825,7 +4441,7 @@
38254441 last = oo->oo_last_closed_stid;
38264442 oo->oo_last_closed_stid = s;
38274443 list_move_tail(&oo->oo_close_lru, &nn->close_lru);
3828
- oo->oo_time = get_seconds();
4444
+ oo->oo_time = ktime_get_boottime_seconds();
38294445 spin_unlock(&nn->client_lock);
38304446 if (last)
38314447 nfs4_put_stid(&last->st_stid);
....@@ -3837,7 +4453,8 @@
38374453 {
38384454 struct nfs4_file *fp;
38394455
3840
- hlist_for_each_entry_rcu(fp, &file_hashtbl[hashval], fi_hash) {
4456
+ hlist_for_each_entry_rcu(fp, &file_hashtbl[hashval], fi_hash,
4457
+ lockdep_is_held(&state_lock)) {
38414458 if (fh_match(&fp->fi_fhandle, fh)) {
38424459 if (refcount_inc_not_zero(&fp->fi_ref))
38434460 return fp;
....@@ -3920,7 +4537,7 @@
39204537 */
39214538 spin_lock(&state_lock);
39224539 if (delegation_hashed(dp) && dp->dl_time == 0) {
3923
- dp->dl_time = get_seconds();
4540
+ dp->dl_time = ktime_get_boottime_seconds();
39244541 list_add_tail(&dp->dl_recall_lru, &nn->del_recall_lru);
39254542 }
39264543 spin_unlock(&state_lock);
....@@ -3931,12 +4548,16 @@
39314548 {
39324549 struct nfs4_delegation *dp = cb_to_delegation(cb);
39334550
3934
- if (dp->dl_stid.sc_type == NFS4_CLOSED_DELEG_STID)
4551
+ if (dp->dl_stid.sc_type == NFS4_CLOSED_DELEG_STID ||
4552
+ dp->dl_stid.sc_type == NFS4_REVOKED_DELEG_STID)
39354553 return 1;
39364554
39374555 switch (task->tk_status) {
39384556 case 0:
39394557 return 1;
4558
+ case -NFS4ERR_DELAY:
4559
+ rpc_delay(task, 2 * HZ);
4560
+ return 0;
39404561 case -EBADHANDLE:
39414562 case -NFS4ERR_BAD_STATEID:
39424563 /*
....@@ -3947,9 +4568,9 @@
39474568 rpc_delay(task, 2 * HZ);
39484569 return 0;
39494570 }
3950
- /*FALLTHRU*/
4571
+ fallthrough;
39514572 default:
3952
- return -1;
4573
+ return 1;
39534574 }
39544575 }
39554576
....@@ -3987,6 +4608,8 @@
39874608 struct nfs4_delegation *dp = (struct nfs4_delegation *)fl->fl_owner;
39884609 struct nfs4_file *fp = dp->dl_stid.sc_file;
39894610
4611
+ trace_nfsd_deleg_break(&dp->dl_stid.sc_stateid);
4612
+
39904613 /*
39914614 * We don't want the locks code to timeout the lease for us;
39924615 * we'll remove it ourself if a delegation isn't returned
....@@ -4001,6 +4624,30 @@
40014624 return ret;
40024625 }
40034626
4627
+/**
4628
+ * nfsd_breaker_owns_lease - Check if lease conflict was resolved
4629
+ * @fl: Lock state to check
4630
+ *
4631
+ * Return values:
4632
+ * %true: Lease conflict was resolved
4633
+ * %false: Lease conflict was not resolved.
4634
+ */
4635
+static bool nfsd_breaker_owns_lease(struct file_lock *fl)
4636
+{
4637
+ struct nfs4_delegation *dl = fl->fl_owner;
4638
+ struct svc_rqst *rqst;
4639
+ struct nfs4_client *clp;
4640
+
4641
+ if (!i_am_nfsd())
4642
+ return false;
4643
+ rqst = kthread_data(current);
4644
+ /* Note rq_prog == NFS_ACL_PROGRAM is also possible: */
4645
+ if (rqst->rq_prog != NFS_PROGRAM || rqst->rq_vers < 4)
4646
+ return false;
4647
+ clp = *(rqst->rq_lease_breaker);
4648
+ return dl->dl_stid.sc_client == clp;
4649
+}
4650
+
40044651 static int
40054652 nfsd_change_deleg_cb(struct file_lock *onlist, int arg,
40064653 struct list_head *dispose)
....@@ -4012,6 +4659,7 @@
40124659 }
40134660
40144661 static const struct lock_manager_operations nfsd_lease_mng_ops = {
4662
+ .lm_breaker_owns_lease = nfsd_breaker_owns_lease,
40154663 .lm_break = nfsd_break_deleg_cb,
40164664 .lm_change = nfsd_change_deleg_cb,
40174665 };
....@@ -4029,7 +4677,8 @@
40294677
40304678 static __be32 lookup_clientid(clientid_t *clid,
40314679 struct nfsd4_compound_state *cstate,
4032
- struct nfsd_net *nn)
4680
+ struct nfsd_net *nn,
4681
+ bool sessions)
40334682 {
40344683 struct nfs4_client *found;
40354684
....@@ -4050,12 +4699,12 @@
40504699 */
40514700 WARN_ON_ONCE(cstate->session);
40524701 spin_lock(&nn->client_lock);
4053
- found = find_confirmed_client(clid, false, nn);
4702
+ found = find_confirmed_client(clid, sessions, nn);
40544703 if (!found) {
40554704 spin_unlock(&nn->client_lock);
40564705 return nfserr_expired;
40574706 }
4058
- atomic_inc(&found->cl_refcount);
4707
+ atomic_inc(&found->cl_rpc_users);
40594708 spin_unlock(&nn->client_lock);
40604709
40614710 /* Cache the nfs4_client in cstate! */
....@@ -4083,7 +4732,7 @@
40834732 if (open->op_file == NULL)
40844733 return nfserr_jukebox;
40854734
4086
- status = lookup_clientid(clientid, cstate, nn);
4735
+ status = lookup_clientid(clientid, cstate, nn, false);
40874736 if (status)
40884737 return status;
40894738 clp = cstate->clp;
....@@ -4211,14 +4860,14 @@
42114860 return 0;
42124861 if (!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
42134862 return nfserr_inval;
4214
- return nfsd_setattr(rqstp, fh, &iattr, 0, (time_t)0);
4863
+ return nfsd_setattr(rqstp, fh, &iattr, 0, (time64_t)0);
42154864 }
42164865
42174866 static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
42184867 struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp,
42194868 struct nfsd4_open *open)
42204869 {
4221
- struct file *filp = NULL;
4870
+ struct nfsd_file *nf = NULL;
42224871 __be32 status;
42234872 int oflag = nfs4_access_to_omode(open->op_share_access);
42244873 int access = nfs4_access_to_access(open->op_share_access);
....@@ -4254,18 +4903,23 @@
42544903
42554904 if (!fp->fi_fds[oflag]) {
42564905 spin_unlock(&fp->fi_lock);
4257
- status = nfsd_open(rqstp, cur_fh, S_IFREG, access, &filp);
4906
+ status = nfsd_file_acquire(rqstp, cur_fh, access, &nf);
42584907 if (status)
42594908 goto out_put_access;
42604909 spin_lock(&fp->fi_lock);
42614910 if (!fp->fi_fds[oflag]) {
4262
- fp->fi_fds[oflag] = filp;
4263
- filp = NULL;
4911
+ fp->fi_fds[oflag] = nf;
4912
+ nf = NULL;
42644913 }
42654914 }
42664915 spin_unlock(&fp->fi_lock);
4267
- if (filp)
4268
- fput(filp);
4916
+ if (nf)
4917
+ nfsd_file_put(nf);
4918
+
4919
+ status = nfserrno(nfsd_open_break_lease(cur_fh->fh_dentry->d_inode,
4920
+ access));
4921
+ if (status)
4922
+ goto out_put_access;
42694923
42704924 status = nfsd4_truncate(rqstp, cur_fh, open);
42714925 if (status)
....@@ -4334,7 +4988,7 @@
43344988 fl->fl_end = OFFSET_MAX;
43354989 fl->fl_owner = (fl_owner_t)dp;
43364990 fl->fl_pid = current->tgid;
4337
- fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file;
4991
+ fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file;
43384992 return fl;
43394993 }
43404994
....@@ -4344,7 +4998,7 @@
43444998 {
43454999 int status = 0;
43465000 struct nfs4_delegation *dp;
4347
- struct file *filp;
5001
+ struct nfsd_file *nf;
43485002 struct file_lock *fl;
43495003
43505004 /*
....@@ -4355,8 +5009,8 @@
43555009 if (fp->fi_had_conflict)
43565010 return ERR_PTR(-EAGAIN);
43575011
4358
- filp = find_readable_file(fp);
4359
- if (!filp) {
5012
+ nf = find_readable_file(fp);
5013
+ if (!nf) {
43605014 /* We should always have a readable file here */
43615015 WARN_ON_ONCE(1);
43625016 return ERR_PTR(-EBADF);
....@@ -4366,17 +5020,17 @@
43665020 if (nfs4_delegation_exists(clp, fp))
43675021 status = -EAGAIN;
43685022 else if (!fp->fi_deleg_file) {
4369
- fp->fi_deleg_file = filp;
5023
+ fp->fi_deleg_file = nf;
43705024 /* increment early to prevent fi_deleg_file from being
43715025 * cleared */
43725026 fp->fi_delegees = 1;
4373
- filp = NULL;
5027
+ nf = NULL;
43745028 } else
43755029 fp->fi_delegees++;
43765030 spin_unlock(&fp->fi_lock);
43775031 spin_unlock(&state_lock);
4378
- if (filp)
4379
- fput(filp);
5032
+ if (nf)
5033
+ nfsd_file_put(nf);
43805034 if (status)
43815035 return ERR_PTR(status);
43825036
....@@ -4389,7 +5043,7 @@
43895043 if (!fl)
43905044 goto out_clnt_odstate;
43915045
4392
- status = vfs_setlease(fp->fi_deleg_file, fl->fl_type, &fl, NULL);
5046
+ status = vfs_setlease(fp->fi_deleg_file->nf_file, fl->fl_type, &fl, NULL);
43935047 if (fl)
43945048 locks_free_lock(fl);
43955049 if (status)
....@@ -4409,7 +5063,7 @@
44095063
44105064 return dp;
44115065 out_unlock:
4412
- vfs_setlease(fp->fi_deleg_file, F_UNLCK, NULL, (void **)&dp);
5066
+ vfs_setlease(fp->fi_deleg_file->nf_file, F_UNLCK, NULL, (void **)&dp);
44135067 out_clnt_odstate:
44145068 put_clnt_odstate(dp->dl_clnt_odstate);
44155069 nfs4_put_stid(&dp->dl_stid);
....@@ -4496,8 +5150,7 @@
44965150
44975151 memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid));
44985152
4499
- dprintk("NFSD: delegation stateid=" STATEID_FMT "\n",
4500
- STATEID_VAL(&dp->dl_stid.sc_stateid));
5153
+ trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid);
45015154 open->op_delegate_type = NFS4_OPEN_DELEGATE_READ;
45025155 nfs4_put_stid(&dp->dl_stid);
45035156 return;
....@@ -4614,9 +5267,7 @@
46145267 nfs4_open_delegation(current_fh, open, stp);
46155268 nodeleg:
46165269 status = nfs_ok;
4617
-
4618
- dprintk("%s: stateid=" STATEID_FMT "\n", __func__,
4619
- STATEID_VAL(&stp->st_stid.sc_stateid));
5270
+ trace_nfsd_open(&stp->st_stid.sc_stateid);
46205271 out:
46215272 /* 4.1 client trying to upgrade/downgrade delegation? */
46225273 if (open->op_delegate_type == NFS4_OPEN_DELEGATE_NONE && dp &&
....@@ -4670,9 +5321,8 @@
46705321 __be32 status;
46715322 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
46725323
4673
- dprintk("process_renew(%08x/%08x): starting\n",
4674
- clid->cl_boot, clid->cl_id);
4675
- status = lookup_clientid(clid, cstate, nn);
5324
+ trace_nfsd_clid_renew(clid);
5325
+ status = lookup_clientid(clid, cstate, nn, false);
46765326 if (status)
46775327 goto out;
46785328 clp = cstate->clp;
....@@ -4692,7 +5342,7 @@
46925342 if (nn->grace_ended)
46935343 return;
46945344
4695
- dprintk("NFSD: end of grace period\n");
5345
+ trace_nfsd_grace_complete(nn);
46965346 nn->grace_ended = true;
46975347 /*
46985348 * If the server goes down again right now, an NFSv4
....@@ -4724,10 +5374,13 @@
47245374 */
47255375 static bool clients_still_reclaiming(struct nfsd_net *nn)
47265376 {
4727
- unsigned long now = get_seconds();
4728
- unsigned long double_grace_period_end = nn->boot_time +
4729
- 2 * nn->nfsd4_lease;
5377
+ time64_t double_grace_period_end = nn->boot_time +
5378
+ 2 * nn->nfsd4_lease;
47305379
5380
+ if (nn->track_reclaim_completes &&
5381
+ atomic_read(&nn->nr_reclaim_complete) ==
5382
+ nn->reclaim_str_hashtbl_size)
5383
+ return false;
47315384 if (!nn->somebody_reclaimed)
47325385 return false;
47335386 nn->somebody_reclaimed = false;
....@@ -4735,12 +5388,12 @@
47355388 * If we've given them *two* lease times to reclaim, and they're
47365389 * still not done, give up:
47375390 */
4738
- if (time_after(now, double_grace_period_end))
5391
+ if (ktime_get_boottime_seconds() > double_grace_period_end)
47395392 return false;
47405393 return true;
47415394 }
47425395
4743
-static time_t
5396
+static time64_t
47445397 nfs4_laundromat(struct nfsd_net *nn)
47455398 {
47465399 struct nfs4_client *clp;
....@@ -4749,10 +5402,11 @@
47495402 struct nfs4_ol_stateid *stp;
47505403 struct nfsd4_blocked_lock *nbl;
47515404 struct list_head *pos, *next, reaplist;
4752
- time_t cutoff = get_seconds() - nn->nfsd4_lease;
4753
- time_t t, new_timeo = nn->nfsd4_lease;
4754
-
4755
- dprintk("NFSD: laundromat service - starting\n");
5405
+ time64_t cutoff = ktime_get_boottime_seconds() - nn->nfsd4_lease;
5406
+ time64_t t, new_timeo = nn->nfsd4_lease;
5407
+ struct nfs4_cpntf_state *cps;
5408
+ copy_stateid_t *cps_t;
5409
+ int i;
47565410
47575411 if (clients_still_reclaiming(nn)) {
47585412 new_timeo = 0;
....@@ -4760,17 +5414,26 @@
47605414 }
47615415 nfsd4_end_grace(nn);
47625416 INIT_LIST_HEAD(&reaplist);
5417
+
5418
+ spin_lock(&nn->s2s_cp_lock);
5419
+ idr_for_each_entry(&nn->s2s_cp_stateids, cps_t, i) {
5420
+ cps = container_of(cps_t, struct nfs4_cpntf_state, cp_stateid);
5421
+ if (cps->cp_stateid.sc_type == NFS4_COPYNOTIFY_STID &&
5422
+ cps->cpntf_time < cutoff)
5423
+ _free_cpntf_state_locked(nn, cps);
5424
+ }
5425
+ spin_unlock(&nn->s2s_cp_lock);
5426
+
47635427 spin_lock(&nn->client_lock);
47645428 list_for_each_safe(pos, next, &nn->client_lru) {
47655429 clp = list_entry(pos, struct nfs4_client, cl_lru);
4766
- if (time_after((unsigned long)clp->cl_time, (unsigned long)cutoff)) {
5430
+ if (clp->cl_time > cutoff) {
47675431 t = clp->cl_time - cutoff;
47685432 new_timeo = min(new_timeo, t);
47695433 break;
47705434 }
47715435 if (mark_client_expired_locked(clp)) {
4772
- dprintk("NFSD: client in use (clientid %08x)\n",
4773
- clp->cl_clientid.cl_id);
5436
+ trace_nfsd_clid_expired(&clp->cl_clientid);
47745437 continue;
47755438 }
47765439 list_add(&clp->cl_lru, &reaplist);
....@@ -4778,15 +5441,14 @@
47785441 spin_unlock(&nn->client_lock);
47795442 list_for_each_safe(pos, next, &reaplist) {
47805443 clp = list_entry(pos, struct nfs4_client, cl_lru);
4781
- dprintk("NFSD: purging unused client (clientid %08x)\n",
4782
- clp->cl_clientid.cl_id);
5444
+ trace_nfsd_clid_purged(&clp->cl_clientid);
47835445 list_del_init(&clp->cl_lru);
47845446 expire_client(clp);
47855447 }
47865448 spin_lock(&state_lock);
47875449 list_for_each_safe(pos, next, &nn->del_recall_lru) {
47885450 dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);
4789
- if (time_after((unsigned long)dp->dl_time, (unsigned long)cutoff)) {
5451
+ if (dp->dl_time > cutoff) {
47905452 t = dp->dl_time - cutoff;
47915453 new_timeo = min(new_timeo, t);
47925454 break;
....@@ -4806,8 +5468,7 @@
48065468 while (!list_empty(&nn->close_lru)) {
48075469 oo = list_first_entry(&nn->close_lru, struct nfs4_openowner,
48085470 oo_close_lru);
4809
- if (time_after((unsigned long)oo->oo_time,
4810
- (unsigned long)cutoff)) {
5471
+ if (oo->oo_time > cutoff) {
48115472 t = oo->oo_time - cutoff;
48125473 new_timeo = min(new_timeo, t);
48135474 break;
....@@ -4837,8 +5498,7 @@
48375498 while (!list_empty(&nn->blocked_locks_lru)) {
48385499 nbl = list_first_entry(&nn->blocked_locks_lru,
48395500 struct nfsd4_blocked_lock, nbl_lru);
4840
- if (time_after((unsigned long)nbl->nbl_time,
4841
- (unsigned long)cutoff)) {
5501
+ if (nbl->nbl_time > cutoff) {
48425502 t = nbl->nbl_time - cutoff;
48435503 new_timeo = min(new_timeo, t);
48445504 break;
....@@ -4852,11 +5512,10 @@
48525512 nbl = list_first_entry(&reaplist,
48535513 struct nfsd4_blocked_lock, nbl_lru);
48545514 list_del_init(&nbl->nbl_lru);
4855
- posix_unblock_lock(&nbl->nbl_lock);
48565515 free_blocked_lock(nbl);
48575516 }
48585517 out:
4859
- new_timeo = max_t(time_t, new_timeo, NFSD_LAUNDROMAT_MINTIMEOUT);
5518
+ new_timeo = max_t(time64_t, new_timeo, NFSD_LAUNDROMAT_MINTIMEOUT);
48605519 return new_timeo;
48615520 }
48625521
....@@ -4866,13 +5525,12 @@
48665525 static void
48675526 laundromat_main(struct work_struct *laundry)
48685527 {
4869
- time_t t;
5528
+ time64_t t;
48705529 struct delayed_work *dwork = to_delayed_work(laundry);
48715530 struct nfsd_net *nn = container_of(dwork, struct nfsd_net,
48725531 laundromat_work);
48735532
48745533 t = nfs4_laundromat(nn);
4875
- dprintk("NFSD: laundromat_main - sleeping for %ld seconds\n", t);
48765534 queue_delayed_work(laundry_wq, &nn->laundromat_work, t*HZ);
48775535 }
48785536
....@@ -4998,15 +5656,6 @@
49985656 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid) ||
49995657 CLOSE_STATEID(stateid))
50005658 return status;
5001
- /* Client debugging aid. */
5002
- if (!same_clid(&stateid->si_opaque.so_clid, &cl->cl_clientid)) {
5003
- char addr_str[INET6_ADDRSTRLEN];
5004
- rpc_ntop((struct sockaddr *)&cl->cl_addr, addr_str,
5005
- sizeof(addr_str));
5006
- pr_warn_ratelimited("NFSD: client %s testing state ID "
5007
- "with incorrect client ID\n", addr_str);
5008
- return status;
5009
- }
50105659 spin_lock(&cl->cl_lock);
50115660 s = find_stateid_locked(cl, stateid);
50125661 if (!s)
....@@ -5027,7 +5676,7 @@
50275676 break;
50285677 default:
50295678 printk("unknown stateid type %x\n", s->sc_type);
5030
- /* Fallthrough */
5679
+ fallthrough;
50315680 case NFS4_CLOSED_STID:
50325681 case NFS4_CLOSED_DELEG_STID:
50335682 status = nfserr_bad_stateid;
....@@ -5057,7 +5706,8 @@
50575706 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid) ||
50585707 CLOSE_STATEID(stateid))
50595708 return nfserr_bad_stateid;
5060
- status = lookup_clientid(&stateid->si_opaque.so_clid, cstate, nn);
5709
+ status = lookup_clientid(&stateid->si_opaque.so_clid, cstate, nn,
5710
+ false);
50615711 if (status == nfserr_stale_clientid) {
50625712 if (cstate->session)
50635713 return nfserr_bad_stateid;
....@@ -5077,7 +5727,7 @@
50775727 return nfs_ok;
50785728 }
50795729
5080
-static struct file *
5730
+static struct nfsd_file *
50815731 nfs4_find_file(struct nfs4_stid *s, int flags)
50825732 {
50835733 if (!s)
....@@ -5087,21 +5737,20 @@
50875737 case NFS4_DELEG_STID:
50885738 if (WARN_ON_ONCE(!s->sc_file->fi_deleg_file))
50895739 return NULL;
5090
- return get_file(s->sc_file->fi_deleg_file);
5740
+ return nfsd_file_get(s->sc_file->fi_deleg_file);
50915741 case NFS4_OPEN_STID:
50925742 case NFS4_LOCK_STID:
50935743 if (flags & RD_STATE)
50945744 return find_readable_file(s->sc_file);
50955745 else
50965746 return find_writeable_file(s->sc_file);
5097
- break;
50985747 }
50995748
51005749 return NULL;
51015750 }
51025751
51035752 static __be32
5104
-nfs4_check_olstateid(struct svc_fh *fhp, struct nfs4_ol_stateid *ols, int flags)
5753
+nfs4_check_olstateid(struct nfs4_ol_stateid *ols, int flags)
51055754 {
51065755 __be32 status;
51075756
....@@ -5113,32 +5762,107 @@
51135762
51145763 static __be32
51155764 nfs4_check_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfs4_stid *s,
5116
- struct file **filpp, bool *tmp_file, int flags)
5765
+ struct nfsd_file **nfp, int flags)
51175766 {
51185767 int acc = (flags & RD_STATE) ? NFSD_MAY_READ : NFSD_MAY_WRITE;
5119
- struct file *file;
5768
+ struct nfsd_file *nf;
51205769 __be32 status;
51215770
5122
- file = nfs4_find_file(s, flags);
5123
- if (file) {
5771
+ nf = nfs4_find_file(s, flags);
5772
+ if (nf) {
51245773 status = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry,
51255774 acc | NFSD_MAY_OWNER_OVERRIDE);
51265775 if (status) {
5127
- fput(file);
5128
- return status;
5776
+ nfsd_file_put(nf);
5777
+ goto out;
51295778 }
5130
-
5131
- *filpp = file;
51325779 } else {
5133
- status = nfsd_open(rqstp, fhp, S_IFREG, acc, filpp);
5780
+ status = nfsd_file_acquire(rqstp, fhp, acc, &nf);
51345781 if (status)
51355782 return status;
5136
-
5137
- if (tmp_file)
5138
- *tmp_file = true;
51395783 }
5784
+ *nfp = nf;
5785
+out:
5786
+ return status;
5787
+}
5788
+static void
5789
+_free_cpntf_state_locked(struct nfsd_net *nn, struct nfs4_cpntf_state *cps)
5790
+{
5791
+ WARN_ON_ONCE(cps->cp_stateid.sc_type != NFS4_COPYNOTIFY_STID);
5792
+ if (!refcount_dec_and_test(&cps->cp_stateid.sc_count))
5793
+ return;
5794
+ list_del(&cps->cp_list);
5795
+ idr_remove(&nn->s2s_cp_stateids,
5796
+ cps->cp_stateid.stid.si_opaque.so_id);
5797
+ kfree(cps);
5798
+}
5799
+/*
5800
+ * A READ from an inter server to server COPY will have a
5801
+ * copy stateid. Look up the copy notify stateid from the
5802
+ * idr structure and take a reference on it.
5803
+ */
5804
+__be32 manage_cpntf_state(struct nfsd_net *nn, stateid_t *st,
5805
+ struct nfs4_client *clp,
5806
+ struct nfs4_cpntf_state **cps)
5807
+{
5808
+ copy_stateid_t *cps_t;
5809
+ struct nfs4_cpntf_state *state = NULL;
51405810
5811
+ if (st->si_opaque.so_clid.cl_id != nn->s2s_cp_cl_id)
5812
+ return nfserr_bad_stateid;
5813
+ spin_lock(&nn->s2s_cp_lock);
5814
+ cps_t = idr_find(&nn->s2s_cp_stateids, st->si_opaque.so_id);
5815
+ if (cps_t) {
5816
+ state = container_of(cps_t, struct nfs4_cpntf_state,
5817
+ cp_stateid);
5818
+ if (state->cp_stateid.sc_type != NFS4_COPYNOTIFY_STID) {
5819
+ state = NULL;
5820
+ goto unlock;
5821
+ }
5822
+ if (!clp)
5823
+ refcount_inc(&state->cp_stateid.sc_count);
5824
+ else
5825
+ _free_cpntf_state_locked(nn, state);
5826
+ }
5827
+unlock:
5828
+ spin_unlock(&nn->s2s_cp_lock);
5829
+ if (!state)
5830
+ return nfserr_bad_stateid;
5831
+ if (!clp && state)
5832
+ *cps = state;
51415833 return 0;
5834
+}
5835
+
5836
+static __be32 find_cpntf_state(struct nfsd_net *nn, stateid_t *st,
5837
+ struct nfs4_stid **stid)
5838
+{
5839
+ __be32 status;
5840
+ struct nfs4_cpntf_state *cps = NULL;
5841
+ struct nfsd4_compound_state cstate;
5842
+
5843
+ status = manage_cpntf_state(nn, st, NULL, &cps);
5844
+ if (status)
5845
+ return status;
5846
+
5847
+ cps->cpntf_time = ktime_get_boottime_seconds();
5848
+ memset(&cstate, 0, sizeof(cstate));
5849
+ status = lookup_clientid(&cps->cp_p_clid, &cstate, nn, true);
5850
+ if (status)
5851
+ goto out;
5852
+ status = nfsd4_lookup_stateid(&cstate, &cps->cp_p_stateid,
5853
+ NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID,
5854
+ stid, nn);
5855
+ put_client_renew(cstate.clp);
5856
+out:
5857
+ nfs4_put_cpntf_state(nn, cps);
5858
+ return status;
5859
+}
5860
+
5861
+void nfs4_put_cpntf_state(struct nfsd_net *nn, struct nfs4_cpntf_state *cps)
5862
+{
5863
+ spin_lock(&nn->s2s_cp_lock);
5864
+ _free_cpntf_state_locked(nn, cps);
5865
+ spin_unlock(&nn->s2s_cp_lock);
51425866 }
51435867
51445868 /*
....@@ -5147,7 +5871,8 @@
51475871 __be32
51485872 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
51495873 struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
5150
- stateid_t *stateid, int flags, struct file **filpp, bool *tmp_file)
5874
+ stateid_t *stateid, int flags, struct nfsd_file **nfp,
5875
+ struct nfs4_stid **cstid)
51515876 {
51525877 struct inode *ino = d_inode(fhp->fh_dentry);
51535878 struct net *net = SVC_NET(rqstp);
....@@ -5155,10 +5880,8 @@
51555880 struct nfs4_stid *s = NULL;
51565881 __be32 status;
51575882
5158
- if (filpp)
5159
- *filpp = NULL;
5160
- if (tmp_file)
5161
- *tmp_file = false;
5883
+ if (nfp)
5884
+ *nfp = NULL;
51625885
51635886 if (grace_disallows_io(net, ino))
51645887 return nfserr_grace;
....@@ -5171,6 +5894,8 @@
51715894 status = nfsd4_lookup_stateid(cstate, stateid,
51725895 NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID,
51735896 &s, nn);
5897
+ if (status == nfserr_bad_stateid)
5898
+ status = find_cpntf_state(nn, stateid, &s);
51745899 if (status)
51755900 return status;
51765901 status = nfsd4_stid_check_stateid_generation(stateid, s,
....@@ -5184,7 +5909,7 @@
51845909 break;
51855910 case NFS4_OPEN_STID:
51865911 case NFS4_LOCK_STID:
5187
- status = nfs4_check_olstateid(fhp, openlockstateid(s), flags);
5912
+ status = nfs4_check_olstateid(openlockstateid(s), flags);
51885913 break;
51895914 default:
51905915 status = nfserr_bad_stateid;
....@@ -5195,11 +5920,15 @@
51955920 status = nfs4_check_fh(fhp, s);
51965921
51975922 done:
5198
- if (!status && filpp)
5199
- status = nfs4_check_file(rqstp, fhp, s, filpp, tmp_file, flags);
5923
+ if (status == nfs_ok && nfp)
5924
+ status = nfs4_check_file(rqstp, fhp, s, nfp, flags);
52005925 out:
5201
- if (s)
5202
- nfs4_put_stid(s);
5926
+ if (s) {
5927
+ if (!status && cstid)
5928
+ *cstid = s;
5929
+ else
5930
+ nfs4_put_stid(s);
5931
+ }
52035932 return status;
52045933 }
52055934
....@@ -5339,8 +6068,7 @@
53396068 struct nfs4_stid *s;
53406069 struct nfs4_ol_stateid *stp = NULL;
53416070
5342
- dprintk("NFSD: %s: seqid=%d stateid = " STATEID_FMT "\n", __func__,
5343
- seqid, STATEID_VAL(stateid));
6071
+ trace_nfsd_preprocess(seqid, stateid);
53446072
53456073 *stpp = NULL;
53466074 status = nfsd4_lookup_stateid(cstate, stateid, typemask, &s, nn);
....@@ -5409,9 +6137,7 @@
54096137 oo->oo_flags |= NFS4_OO_CONFIRMED;
54106138 nfs4_inc_and_copy_stateid(&oc->oc_resp_stateid, &stp->st_stid);
54116139 mutex_unlock(&stp->st_mutex);
5412
- dprintk("NFSD: %s: success, seqid=%d stateid=" STATEID_FMT "\n",
5413
- __func__, oc->oc_seqid, STATEID_VAL(&stp->st_stid.sc_stateid));
5414
-
6140
+ trace_nfsd_open_confirm(oc->oc_seqid, &stp->st_stid.sc_stateid);
54156141 nfsd4_client_record_create(oo->oo_owner.so_client);
54166142 status = nfs_ok;
54176143 put_stateid:
....@@ -5496,6 +6222,7 @@
54966222 struct nfs4_client *clp = s->st_stid.sc_client;
54976223 bool unhashed;
54986224 LIST_HEAD(reaplist);
6225
+ struct nfs4_ol_stateid *stp;
54996226
55006227 spin_lock(&clp->cl_lock);
55016228 unhashed = unhash_open_stateid(s, &reaplist);
....@@ -5504,6 +6231,8 @@
55046231 if (unhashed)
55056232 put_ol_stateid_locked(s, &reaplist);
55066233 spin_unlock(&clp->cl_lock);
6234
+ list_for_each_entry(stp, &reaplist, st_locks)
6235
+ nfs4_free_cpntf_statelist(clp->net, &stp->st_stid);
55076236 free_ol_stateid_reaplist(&reaplist);
55086237 } else {
55096238 spin_unlock(&clp->cl_lock);
....@@ -5685,12 +6414,11 @@
56856414
56866415 if (fl->fl_lmops == &nfsd_posix_mng_ops) {
56876416 lo = (struct nfs4_lockowner *) fl->fl_owner;
5688
- deny->ld_owner.data = kmemdup(lo->lo_owner.so_owner.data,
5689
- lo->lo_owner.so_owner.len, GFP_KERNEL);
6417
+ xdr_netobj_dup(&deny->ld_owner, &lo->lo_owner.so_owner,
6418
+ GFP_KERNEL);
56906419 if (!deny->ld_owner.data)
56916420 /* We just don't care that much */
56926421 goto nevermind;
5693
- deny->ld_owner.len = lo->lo_owner.so_owner.len;
56946422 deny->ld_clientid = lo->lo_owner.so_client->cl_clientid;
56956423 } else {
56966424 nevermind:
....@@ -5961,7 +6689,7 @@
59616689 struct nfs4_ol_stateid *lock_stp = NULL;
59626690 struct nfs4_ol_stateid *open_stp = NULL;
59636691 struct nfs4_file *fp;
5964
- struct file *filp = NULL;
6692
+ struct nfsd_file *nf = NULL;
59656693 struct nfsd4_blocked_lock *nbl = NULL;
59666694 struct file_lock *file_lock = NULL;
59676695 struct file_lock *conflock = NULL;
....@@ -6040,11 +6768,11 @@
60406768 case NFS4_READW_LT:
60416769 if (nfsd4_has_session(cstate))
60426770 fl_flags |= FL_SLEEP;
6043
- /* Fallthrough */
6771
+ fallthrough;
60446772 case NFS4_READ_LT:
60456773 spin_lock(&fp->fi_lock);
6046
- filp = find_readable_file_locked(fp);
6047
- if (filp)
6774
+ nf = find_readable_file_locked(fp);
6775
+ if (nf)
60486776 get_lock_access(lock_stp, NFS4_SHARE_ACCESS_READ);
60496777 spin_unlock(&fp->fi_lock);
60506778 fl_type = F_RDLCK;
....@@ -6052,11 +6780,11 @@
60526780 case NFS4_WRITEW_LT:
60536781 if (nfsd4_has_session(cstate))
60546782 fl_flags |= FL_SLEEP;
6055
- /* Fallthrough */
6783
+ fallthrough;
60566784 case NFS4_WRITE_LT:
60576785 spin_lock(&fp->fi_lock);
6058
- filp = find_writeable_file_locked(fp);
6059
- if (filp)
6786
+ nf = find_writeable_file_locked(fp);
6787
+ if (nf)
60606788 get_lock_access(lock_stp, NFS4_SHARE_ACCESS_WRITE);
60616789 spin_unlock(&fp->fi_lock);
60626790 fl_type = F_WRLCK;
....@@ -6066,7 +6794,7 @@
60666794 goto out;
60676795 }
60686796
6069
- if (!filp) {
6797
+ if (!nf) {
60706798 status = nfserr_openmode;
60716799 goto out;
60726800 }
....@@ -6082,7 +6810,7 @@
60826810 file_lock->fl_type = fl_type;
60836811 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(&lock_sop->lo_owner));
60846812 file_lock->fl_pid = current->tgid;
6085
- file_lock->fl_file = filp;
6813
+ file_lock->fl_file = nf->nf_file;
60866814 file_lock->fl_flags = fl_flags;
60876815 file_lock->fl_lmops = &nfsd_posix_mng_ops;
60886816 file_lock->fl_start = lock->lk_offset;
....@@ -6097,14 +6825,14 @@
60976825 }
60986826
60996827 if (fl_flags & FL_SLEEP) {
6100
- nbl->nbl_time = get_seconds();
6828
+ nbl->nbl_time = ktime_get_boottime_seconds();
61016829 spin_lock(&nn->blocked_locks_lock);
61026830 list_add_tail(&nbl->nbl_list, &lock_sop->lo_blocked);
61036831 list_add_tail(&nbl->nbl_lru, &nn->blocked_locks_lru);
61046832 spin_unlock(&nn->blocked_locks_lock);
61056833 }
61066834
6107
- err = vfs_lock_file(filp, F_SETLK, file_lock, conflock);
6835
+ err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, conflock);
61086836 switch (err) {
61096837 case 0: /* success! */
61106838 nfs4_inc_and_copy_stateid(&lock->lk_resp_stateid, &lock_stp->st_stid);
....@@ -6114,7 +6842,7 @@
61146842 break;
61156843 case FILE_LOCK_DEFERRED:
61166844 nbl = NULL;
6117
- /* Fallthrough */
6845
+ fallthrough;
61186846 case -EAGAIN: /* conflock holds conflicting lock */
61196847 status = nfserr_denied;
61206848 dprintk("NFSD: nfsd4_lock: conflicting lock found!\n");
....@@ -6139,8 +6867,8 @@
61396867 }
61406868 free_blocked_lock(nbl);
61416869 }
6142
- if (filp)
6143
- fput(filp);
6870
+ if (nf)
6871
+ nfsd_file_put(nf);
61446872 if (lock_stp) {
61456873 /* Bump seqid manually if the 4.0 replay owner is openowner */
61466874 if (cstate->replay_owner &&
....@@ -6170,17 +6898,27 @@
61706898 /*
61716899 * The NFSv4 spec allows a client to do a LOCKT without holding an OPEN,
61726900 * so we do a temporary open here just to get an open file to pass to
6173
- * vfs_test_lock. (Arguably perhaps test_lock should be done with an
6174
- * inode operation.)
6901
+ * vfs_test_lock.
61756902 */
61766903 static __be32 nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file_lock *lock)
61776904 {
6178
- struct file *file;
6179
- __be32 err = nfsd_open(rqstp, fhp, S_IFREG, NFSD_MAY_READ, &file);
6180
- if (!err) {
6181
- err = nfserrno(vfs_test_lock(file, lock));
6182
- fput(file);
6183
- }
6905
+ struct nfsd_file *nf;
6906
+ __be32 err;
6907
+
6908
+ err = nfsd_file_acquire(rqstp, fhp, NFSD_MAY_READ, &nf);
6909
+ if (err)
6910
+ return err;
6911
+ fh_lock(fhp); /* to block new leases till after test_lock: */
6912
+ err = nfserrno(nfsd_open_break_lease(fhp->fh_dentry->d_inode,
6913
+ NFSD_MAY_READ));
6914
+ if (err)
6915
+ goto out;
6916
+ lock->fl_file = nf->nf_file;
6917
+ err = nfserrno(vfs_test_lock(nf->nf_file, lock));
6918
+ lock->fl_file = NULL;
6919
+out:
6920
+ fh_unlock(fhp);
6921
+ nfsd_file_put(nf);
61846922 return err;
61856923 }
61866924
....@@ -6204,7 +6942,8 @@
62046942 return nfserr_inval;
62056943
62066944 if (!nfsd4_has_session(cstate)) {
6207
- status = lookup_clientid(&lockt->lt_clientid, cstate, nn);
6945
+ status = lookup_clientid(&lockt->lt_clientid, cstate, nn,
6946
+ false);
62086947 if (status)
62096948 goto out;
62106949 }
....@@ -6223,15 +6962,15 @@
62236962 case NFS4_READ_LT:
62246963 case NFS4_READW_LT:
62256964 file_lock->fl_type = F_RDLCK;
6226
- break;
6965
+ break;
62276966 case NFS4_WRITE_LT:
62286967 case NFS4_WRITEW_LT:
62296968 file_lock->fl_type = F_WRLCK;
6230
- break;
6969
+ break;
62316970 default:
62326971 dprintk("NFSD: nfs4_lockt: bad lock type!\n");
62336972 status = nfserr_inval;
6234
- goto out;
6973
+ goto out;
62356974 }
62366975
62376976 lo = find_lockowner_str(cstate->clp, &lockt->lt_owner);
....@@ -6267,7 +7006,7 @@
62677006 {
62687007 struct nfsd4_locku *locku = &u->locku;
62697008 struct nfs4_ol_stateid *stp;
6270
- struct file *filp = NULL;
7009
+ struct nfsd_file *nf = NULL;
62717010 struct file_lock *file_lock = NULL;
62727011 __be32 status;
62737012 int err;
....@@ -6285,8 +7024,8 @@
62857024 &stp, nn);
62867025 if (status)
62877026 goto out;
6288
- filp = find_any_file(stp->st_stid.sc_file);
6289
- if (!filp) {
7027
+ nf = find_any_file(stp->st_stid.sc_file);
7028
+ if (!nf) {
62907029 status = nfserr_lock_range;
62917030 goto put_stateid;
62927031 }
....@@ -6294,13 +7033,13 @@
62947033 if (!file_lock) {
62957034 dprintk("NFSD: %s: unable to allocate lock!\n", __func__);
62967035 status = nfserr_jukebox;
6297
- goto fput;
7036
+ goto put_file;
62987037 }
62997038
63007039 file_lock->fl_type = F_UNLCK;
63017040 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(stp->st_stateowner));
63027041 file_lock->fl_pid = current->tgid;
6303
- file_lock->fl_file = filp;
7042
+ file_lock->fl_file = nf->nf_file;
63047043 file_lock->fl_flags = FL_POSIX;
63057044 file_lock->fl_lmops = &nfsd_posix_mng_ops;
63067045 file_lock->fl_start = locku->lu_offset;
....@@ -6309,14 +7048,14 @@
63097048 locku->lu_length);
63107049 nfs4_transform_lock_offset(file_lock);
63117050
6312
- err = vfs_lock_file(filp, F_SETLK, file_lock, NULL);
7051
+ err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, NULL);
63137052 if (err) {
63147053 dprintk("NFSD: nfs4_locku: vfs_lock_file failed!\n");
63157054 goto out_nfserr;
63167055 }
63177056 nfs4_inc_and_copy_stateid(&locku->lu_stateid, &stp->st_stid);
6318
-fput:
6319
- fput(filp);
7057
+put_file:
7058
+ nfsd_file_put(nf);
63207059 put_stateid:
63217060 mutex_unlock(&stp->st_mutex);
63227061 nfs4_put_stid(&stp->st_stid);
....@@ -6328,7 +7067,7 @@
63287067
63297068 out_nfserr:
63307069 status = nfserrno(err);
6331
- goto fput;
7070
+ goto put_file;
63327071 }
63337072
63347073 /*
....@@ -6341,17 +7080,17 @@
63417080 {
63427081 struct file_lock *fl;
63437082 int status = false;
6344
- struct file *filp = find_any_file(fp);
7083
+ struct nfsd_file *nf = find_any_file(fp);
63457084 struct inode *inode;
63467085 struct file_lock_context *flctx;
63477086
6348
- if (!filp) {
7087
+ if (!nf) {
63497088 /* Any valid lock stateid should have some sort of access */
63507089 WARN_ON_ONCE(1);
63517090 return status;
63527091 }
63537092
6354
- inode = locks_inode(filp);
7093
+ inode = locks_inode(nf->nf_file);
63557094 flctx = inode->i_flctx;
63567095
63577096 if (flctx && !list_empty_careful(&flctx->flc_posix)) {
....@@ -6364,7 +7103,7 @@
63647103 }
63657104 spin_unlock(&flctx->flc_lock);
63667105 }
6367
- fput(filp);
7106
+ nfsd_file_put(nf);
63687107 return status;
63697108 }
63707109
....@@ -6388,7 +7127,7 @@
63887127 dprintk("nfsd4_release_lockowner clientid: (%08x/%08x):\n",
63897128 clid->cl_boot, clid->cl_id);
63907129
6391
- status = lookup_clientid(clid, cstate, nn);
7130
+ status = lookup_clientid(clid, cstate, nn, false);
63927131 if (status)
63937132 return status;
63947133
....@@ -6401,16 +7140,12 @@
64017140 if (sop->so_is_open_owner || !same_owner_str(sop, owner))
64027141 continue;
64037142
6404
- /* see if there are still any locks associated with it */
6405
- lo = lockowner(sop);
6406
- list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) {
6407
- if (check_for_locks(stp->st_stid.sc_file, lo)) {
6408
- status = nfserr_locks_held;
6409
- spin_unlock(&clp->cl_lock);
6410
- return status;
6411
- }
7143
+ if (atomic_read(&sop->so_count) != 1) {
7144
+ spin_unlock(&clp->cl_lock);
7145
+ return nfserr_locks_held;
64127146 }
64137147
7148
+ lo = lockowner(sop);
64147149 nfs4_get_stateowner(sop);
64157150 break;
64167151 }
....@@ -6442,7 +7177,7 @@
64427177 }
64437178
64447179 bool
6445
-nfs4_has_reclaimed_state(const char *name, struct nfsd_net *nn)
7180
+nfs4_has_reclaimed_state(struct xdr_netobj name, struct nfsd_net *nn)
64467181 {
64477182 struct nfs4_client_reclaim *crp;
64487183
....@@ -6452,20 +7187,26 @@
64527187
64537188 /*
64547189 * failure => all reset bets are off, nfserr_no_grace...
7190
+ *
7191
+ * The caller is responsible for freeing name.data if NULL is returned (it
7192
+ * will be freed in nfs4_remove_reclaim_record in the normal case).
64557193 */
64567194 struct nfs4_client_reclaim *
6457
-nfs4_client_to_reclaim(const char *name, struct nfsd_net *nn)
7195
+nfs4_client_to_reclaim(struct xdr_netobj name, struct xdr_netobj princhash,
7196
+ struct nfsd_net *nn)
64587197 {
64597198 unsigned int strhashval;
64607199 struct nfs4_client_reclaim *crp;
64617200
6462
- dprintk("NFSD nfs4_client_to_reclaim NAME: %.*s\n", HEXDIR_LEN, name);
64637201 crp = alloc_reclaim();
64647202 if (crp) {
64657203 strhashval = clientstr_hashval(name);
64667204 INIT_LIST_HEAD(&crp->cr_strhash);
64677205 list_add(&crp->cr_strhash, &nn->reclaim_str_hashtbl[strhashval]);
6468
- memcpy(crp->cr_recdir, name, HEXDIR_LEN);
7206
+ crp->cr_name.data = name.data;
7207
+ crp->cr_name.len = name.len;
7208
+ crp->cr_princhash.data = princhash.data;
7209
+ crp->cr_princhash.len = princhash.len;
64697210 crp->cr_clp = NULL;
64707211 nn->reclaim_str_hashtbl_size++;
64717212 }
....@@ -6476,6 +7217,8 @@
64767217 nfs4_remove_reclaim_record(struct nfs4_client_reclaim *crp, struct nfsd_net *nn)
64777218 {
64787219 list_del(&crp->cr_strhash);
7220
+ kfree(crp->cr_name.data);
7221
+ kfree(crp->cr_princhash.data);
64797222 kfree(crp);
64807223 nn->reclaim_str_hashtbl_size--;
64817224 }
....@@ -6499,16 +7242,14 @@
64997242 /*
65007243 * called from OPEN, CLAIM_PREVIOUS with a new clientid. */
65017244 struct nfs4_client_reclaim *
6502
-nfsd4_find_reclaim_client(const char *recdir, struct nfsd_net *nn)
7245
+nfsd4_find_reclaim_client(struct xdr_netobj name, struct nfsd_net *nn)
65037246 {
65047247 unsigned int strhashval;
65057248 struct nfs4_client_reclaim *crp = NULL;
65067249
6507
- dprintk("NFSD: nfs4_find_reclaim_client for recdir %s\n", recdir);
6508
-
6509
- strhashval = clientstr_hashval(recdir);
7250
+ strhashval = clientstr_hashval(name);
65107251 list_for_each_entry(crp, &nn->reclaim_str_hashtbl[strhashval], cr_strhash) {
6511
- if (same_name(crp->cr_recdir, recdir)) {
7252
+ if (compare_blob(&crp->cr_name, &name) == 0) {
65127253 return crp;
65137254 }
65147255 }
....@@ -6526,7 +7267,7 @@
65267267 __be32 status;
65277268
65287269 /* find clientid in conf_id_hashtbl */
6529
- status = lookup_clientid(clid, cstate, nn);
7270
+ status = lookup_clientid(clid, cstate, nn, false);
65307271 if (status)
65317272 return nfserr_reclaim_bad;
65327273
....@@ -6538,596 +7279,6 @@
65387279
65397280 return nfs_ok;
65407281 }
6541
-
6542
-#ifdef CONFIG_NFSD_FAULT_INJECTION
6543
-static inline void
6544
-put_client(struct nfs4_client *clp)
6545
-{
6546
- atomic_dec(&clp->cl_refcount);
6547
-}
6548
-
6549
-static struct nfs4_client *
6550
-nfsd_find_client(struct sockaddr_storage *addr, size_t addr_size)
6551
-{
6552
- struct nfs4_client *clp;
6553
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6554
- nfsd_net_id);
6555
-
6556
- if (!nfsd_netns_ready(nn))
6557
- return NULL;
6558
-
6559
- list_for_each_entry(clp, &nn->client_lru, cl_lru) {
6560
- if (memcmp(&clp->cl_addr, addr, addr_size) == 0)
6561
- return clp;
6562
- }
6563
- return NULL;
6564
-}
6565
-
6566
-u64
6567
-nfsd_inject_print_clients(void)
6568
-{
6569
- struct nfs4_client *clp;
6570
- u64 count = 0;
6571
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6572
- nfsd_net_id);
6573
- char buf[INET6_ADDRSTRLEN];
6574
-
6575
- if (!nfsd_netns_ready(nn))
6576
- return 0;
6577
-
6578
- spin_lock(&nn->client_lock);
6579
- list_for_each_entry(clp, &nn->client_lru, cl_lru) {
6580
- rpc_ntop((struct sockaddr *)&clp->cl_addr, buf, sizeof(buf));
6581
- pr_info("NFS Client: %s\n", buf);
6582
- ++count;
6583
- }
6584
- spin_unlock(&nn->client_lock);
6585
-
6586
- return count;
6587
-}
6588
-
6589
-u64
6590
-nfsd_inject_forget_client(struct sockaddr_storage *addr, size_t addr_size)
6591
-{
6592
- u64 count = 0;
6593
- struct nfs4_client *clp;
6594
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6595
- nfsd_net_id);
6596
-
6597
- if (!nfsd_netns_ready(nn))
6598
- return count;
6599
-
6600
- spin_lock(&nn->client_lock);
6601
- clp = nfsd_find_client(addr, addr_size);
6602
- if (clp) {
6603
- if (mark_client_expired_locked(clp) == nfs_ok)
6604
- ++count;
6605
- else
6606
- clp = NULL;
6607
- }
6608
- spin_unlock(&nn->client_lock);
6609
-
6610
- if (clp)
6611
- expire_client(clp);
6612
-
6613
- return count;
6614
-}
6615
-
6616
-u64
6617
-nfsd_inject_forget_clients(u64 max)
6618
-{
6619
- u64 count = 0;
6620
- struct nfs4_client *clp, *next;
6621
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6622
- nfsd_net_id);
6623
- LIST_HEAD(reaplist);
6624
-
6625
- if (!nfsd_netns_ready(nn))
6626
- return count;
6627
-
6628
- spin_lock(&nn->client_lock);
6629
- list_for_each_entry_safe(clp, next, &nn->client_lru, cl_lru) {
6630
- if (mark_client_expired_locked(clp) == nfs_ok) {
6631
- list_add(&clp->cl_lru, &reaplist);
6632
- if (max != 0 && ++count >= max)
6633
- break;
6634
- }
6635
- }
6636
- spin_unlock(&nn->client_lock);
6637
-
6638
- list_for_each_entry_safe(clp, next, &reaplist, cl_lru)
6639
- expire_client(clp);
6640
-
6641
- return count;
6642
-}
6643
-
6644
-static void nfsd_print_count(struct nfs4_client *clp, unsigned int count,
6645
- const char *type)
6646
-{
6647
- char buf[INET6_ADDRSTRLEN];
6648
- rpc_ntop((struct sockaddr *)&clp->cl_addr, buf, sizeof(buf));
6649
- printk(KERN_INFO "NFS Client: %s has %u %s\n", buf, count, type);
6650
-}
6651
-
6652
-static void
6653
-nfsd_inject_add_lock_to_list(struct nfs4_ol_stateid *lst,
6654
- struct list_head *collect)
6655
-{
6656
- struct nfs4_client *clp = lst->st_stid.sc_client;
6657
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6658
- nfsd_net_id);
6659
-
6660
- if (!collect)
6661
- return;
6662
-
6663
- lockdep_assert_held(&nn->client_lock);
6664
- atomic_inc(&clp->cl_refcount);
6665
- list_add(&lst->st_locks, collect);
6666
-}
6667
-
6668
-static u64 nfsd_foreach_client_lock(struct nfs4_client *clp, u64 max,
6669
- struct list_head *collect,
6670
- bool (*func)(struct nfs4_ol_stateid *))
6671
-{
6672
- struct nfs4_openowner *oop;
6673
- struct nfs4_ol_stateid *stp, *st_next;
6674
- struct nfs4_ol_stateid *lst, *lst_next;
6675
- u64 count = 0;
6676
-
6677
- spin_lock(&clp->cl_lock);
6678
- list_for_each_entry(oop, &clp->cl_openowners, oo_perclient) {
6679
- list_for_each_entry_safe(stp, st_next,
6680
- &oop->oo_owner.so_stateids, st_perstateowner) {
6681
- list_for_each_entry_safe(lst, lst_next,
6682
- &stp->st_locks, st_locks) {
6683
- if (func) {
6684
- if (func(lst))
6685
- nfsd_inject_add_lock_to_list(lst,
6686
- collect);
6687
- }
6688
- ++count;
6689
- /*
6690
- * Despite the fact that these functions deal
6691
- * with 64-bit integers for "count", we must
6692
- * ensure that it doesn't blow up the
6693
- * clp->cl_refcount. Throw a warning if we
6694
- * start to approach INT_MAX here.
6695
- */
6696
- WARN_ON_ONCE(count == (INT_MAX / 2));
6697
- if (count == max)
6698
- goto out;
6699
- }
6700
- }
6701
- }
6702
-out:
6703
- spin_unlock(&clp->cl_lock);
6704
-
6705
- return count;
6706
-}
6707
-
6708
-static u64
6709
-nfsd_collect_client_locks(struct nfs4_client *clp, struct list_head *collect,
6710
- u64 max)
6711
-{
6712
- return nfsd_foreach_client_lock(clp, max, collect, unhash_lock_stateid);
6713
-}
6714
-
6715
-static u64
6716
-nfsd_print_client_locks(struct nfs4_client *clp)
6717
-{
6718
- u64 count = nfsd_foreach_client_lock(clp, 0, NULL, NULL);
6719
- nfsd_print_count(clp, count, "locked files");
6720
- return count;
6721
-}
6722
-
6723
-u64
6724
-nfsd_inject_print_locks(void)
6725
-{
6726
- struct nfs4_client *clp;
6727
- u64 count = 0;
6728
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6729
- nfsd_net_id);
6730
-
6731
- if (!nfsd_netns_ready(nn))
6732
- return 0;
6733
-
6734
- spin_lock(&nn->client_lock);
6735
- list_for_each_entry(clp, &nn->client_lru, cl_lru)
6736
- count += nfsd_print_client_locks(clp);
6737
- spin_unlock(&nn->client_lock);
6738
-
6739
- return count;
6740
-}
6741
-
6742
-static void
6743
-nfsd_reap_locks(struct list_head *reaplist)
6744
-{
6745
- struct nfs4_client *clp;
6746
- struct nfs4_ol_stateid *stp, *next;
6747
-
6748
- list_for_each_entry_safe(stp, next, reaplist, st_locks) {
6749
- list_del_init(&stp->st_locks);
6750
- clp = stp->st_stid.sc_client;
6751
- nfs4_put_stid(&stp->st_stid);
6752
- put_client(clp);
6753
- }
6754
-}
6755
-
6756
-u64
6757
-nfsd_inject_forget_client_locks(struct sockaddr_storage *addr, size_t addr_size)
6758
-{
6759
- unsigned int count = 0;
6760
- struct nfs4_client *clp;
6761
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6762
- nfsd_net_id);
6763
- LIST_HEAD(reaplist);
6764
-
6765
- if (!nfsd_netns_ready(nn))
6766
- return count;
6767
-
6768
- spin_lock(&nn->client_lock);
6769
- clp = nfsd_find_client(addr, addr_size);
6770
- if (clp)
6771
- count = nfsd_collect_client_locks(clp, &reaplist, 0);
6772
- spin_unlock(&nn->client_lock);
6773
- nfsd_reap_locks(&reaplist);
6774
- return count;
6775
-}
6776
-
6777
-u64
6778
-nfsd_inject_forget_locks(u64 max)
6779
-{
6780
- u64 count = 0;
6781
- struct nfs4_client *clp;
6782
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6783
- nfsd_net_id);
6784
- LIST_HEAD(reaplist);
6785
-
6786
- if (!nfsd_netns_ready(nn))
6787
- return count;
6788
-
6789
- spin_lock(&nn->client_lock);
6790
- list_for_each_entry(clp, &nn->client_lru, cl_lru) {
6791
- count += nfsd_collect_client_locks(clp, &reaplist, max - count);
6792
- if (max != 0 && count >= max)
6793
- break;
6794
- }
6795
- spin_unlock(&nn->client_lock);
6796
- nfsd_reap_locks(&reaplist);
6797
- return count;
6798
-}
6799
-
6800
-static u64
6801
-nfsd_foreach_client_openowner(struct nfs4_client *clp, u64 max,
6802
- struct list_head *collect,
6803
- void (*func)(struct nfs4_openowner *))
6804
-{
6805
- struct nfs4_openowner *oop, *next;
6806
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6807
- nfsd_net_id);
6808
- u64 count = 0;
6809
-
6810
- lockdep_assert_held(&nn->client_lock);
6811
-
6812
- spin_lock(&clp->cl_lock);
6813
- list_for_each_entry_safe(oop, next, &clp->cl_openowners, oo_perclient) {
6814
- if (func) {
6815
- func(oop);
6816
- if (collect) {
6817
- atomic_inc(&clp->cl_refcount);
6818
- list_add(&oop->oo_perclient, collect);
6819
- }
6820
- }
6821
- ++count;
6822
- /*
6823
- * Despite the fact that these functions deal with
6824
- * 64-bit integers for "count", we must ensure that
6825
- * it doesn't blow up the clp->cl_refcount. Throw a
6826
- * warning if we start to approach INT_MAX here.
6827
- */
6828
- WARN_ON_ONCE(count == (INT_MAX / 2));
6829
- if (count == max)
6830
- break;
6831
- }
6832
- spin_unlock(&clp->cl_lock);
6833
-
6834
- return count;
6835
-}
6836
-
6837
-static u64
6838
-nfsd_print_client_openowners(struct nfs4_client *clp)
6839
-{
6840
- u64 count = nfsd_foreach_client_openowner(clp, 0, NULL, NULL);
6841
-
6842
- nfsd_print_count(clp, count, "openowners");
6843
- return count;
6844
-}
6845
-
6846
-static u64
6847
-nfsd_collect_client_openowners(struct nfs4_client *clp,
6848
- struct list_head *collect, u64 max)
6849
-{
6850
- return nfsd_foreach_client_openowner(clp, max, collect,
6851
- unhash_openowner_locked);
6852
-}
6853
-
6854
-u64
6855
-nfsd_inject_print_openowners(void)
6856
-{
6857
- struct nfs4_client *clp;
6858
- u64 count = 0;
6859
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6860
- nfsd_net_id);
6861
-
6862
- if (!nfsd_netns_ready(nn))
6863
- return 0;
6864
-
6865
- spin_lock(&nn->client_lock);
6866
- list_for_each_entry(clp, &nn->client_lru, cl_lru)
6867
- count += nfsd_print_client_openowners(clp);
6868
- spin_unlock(&nn->client_lock);
6869
-
6870
- return count;
6871
-}
6872
-
6873
-static void
6874
-nfsd_reap_openowners(struct list_head *reaplist)
6875
-{
6876
- struct nfs4_client *clp;
6877
- struct nfs4_openowner *oop, *next;
6878
-
6879
- list_for_each_entry_safe(oop, next, reaplist, oo_perclient) {
6880
- list_del_init(&oop->oo_perclient);
6881
- clp = oop->oo_owner.so_client;
6882
- release_openowner(oop);
6883
- put_client(clp);
6884
- }
6885
-}
6886
-
6887
-u64
6888
-nfsd_inject_forget_client_openowners(struct sockaddr_storage *addr,
6889
- size_t addr_size)
6890
-{
6891
- unsigned int count = 0;
6892
- struct nfs4_client *clp;
6893
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6894
- nfsd_net_id);
6895
- LIST_HEAD(reaplist);
6896
-
6897
- if (!nfsd_netns_ready(nn))
6898
- return count;
6899
-
6900
- spin_lock(&nn->client_lock);
6901
- clp = nfsd_find_client(addr, addr_size);
6902
- if (clp)
6903
- count = nfsd_collect_client_openowners(clp, &reaplist, 0);
6904
- spin_unlock(&nn->client_lock);
6905
- nfsd_reap_openowners(&reaplist);
6906
- return count;
6907
-}
6908
-
6909
-u64
6910
-nfsd_inject_forget_openowners(u64 max)
6911
-{
6912
- u64 count = 0;
6913
- struct nfs4_client *clp;
6914
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6915
- nfsd_net_id);
6916
- LIST_HEAD(reaplist);
6917
-
6918
- if (!nfsd_netns_ready(nn))
6919
- return count;
6920
-
6921
- spin_lock(&nn->client_lock);
6922
- list_for_each_entry(clp, &nn->client_lru, cl_lru) {
6923
- count += nfsd_collect_client_openowners(clp, &reaplist,
6924
- max - count);
6925
- if (max != 0 && count >= max)
6926
- break;
6927
- }
6928
- spin_unlock(&nn->client_lock);
6929
- nfsd_reap_openowners(&reaplist);
6930
- return count;
6931
-}
6932
-
6933
-static u64 nfsd_find_all_delegations(struct nfs4_client *clp, u64 max,
6934
- struct list_head *victims)
6935
-{
6936
- struct nfs4_delegation *dp, *next;
6937
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6938
- nfsd_net_id);
6939
- u64 count = 0;
6940
-
6941
- lockdep_assert_held(&nn->client_lock);
6942
-
6943
- spin_lock(&state_lock);
6944
- list_for_each_entry_safe(dp, next, &clp->cl_delegations, dl_perclnt) {
6945
- if (victims) {
6946
- /*
6947
- * It's not safe to mess with delegations that have a
6948
- * non-zero dl_time. They might have already been broken
6949
- * and could be processed by the laundromat outside of
6950
- * the state_lock. Just leave them be.
6951
- */
6952
- if (dp->dl_time != 0)
6953
- continue;
6954
-
6955
- atomic_inc(&clp->cl_refcount);
6956
- WARN_ON(!unhash_delegation_locked(dp));
6957
- list_add(&dp->dl_recall_lru, victims);
6958
- }
6959
- ++count;
6960
- /*
6961
- * Despite the fact that these functions deal with
6962
- * 64-bit integers for "count", we must ensure that
6963
- * it doesn't blow up the clp->cl_refcount. Throw a
6964
- * warning if we start to approach INT_MAX here.
6965
- */
6966
- WARN_ON_ONCE(count == (INT_MAX / 2));
6967
- if (count == max)
6968
- break;
6969
- }
6970
- spin_unlock(&state_lock);
6971
- return count;
6972
-}
6973
-
6974
-static u64
6975
-nfsd_print_client_delegations(struct nfs4_client *clp)
6976
-{
6977
- u64 count = nfsd_find_all_delegations(clp, 0, NULL);
6978
-
6979
- nfsd_print_count(clp, count, "delegations");
6980
- return count;
6981
-}
6982
-
6983
-u64
6984
-nfsd_inject_print_delegations(void)
6985
-{
6986
- struct nfs4_client *clp;
6987
- u64 count = 0;
6988
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
6989
- nfsd_net_id);
6990
-
6991
- if (!nfsd_netns_ready(nn))
6992
- return 0;
6993
-
6994
- spin_lock(&nn->client_lock);
6995
- list_for_each_entry(clp, &nn->client_lru, cl_lru)
6996
- count += nfsd_print_client_delegations(clp);
6997
- spin_unlock(&nn->client_lock);
6998
-
6999
- return count;
7000
-}
7001
-
7002
-static void
7003
-nfsd_forget_delegations(struct list_head *reaplist)
7004
-{
7005
- struct nfs4_client *clp;
7006
- struct nfs4_delegation *dp, *next;
7007
-
7008
- list_for_each_entry_safe(dp, next, reaplist, dl_recall_lru) {
7009
- list_del_init(&dp->dl_recall_lru);
7010
- clp = dp->dl_stid.sc_client;
7011
- revoke_delegation(dp);
7012
- put_client(clp);
7013
- }
7014
-}
7015
-
7016
-u64
7017
-nfsd_inject_forget_client_delegations(struct sockaddr_storage *addr,
7018
- size_t addr_size)
7019
-{
7020
- u64 count = 0;
7021
- struct nfs4_client *clp;
7022
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
7023
- nfsd_net_id);
7024
- LIST_HEAD(reaplist);
7025
-
7026
- if (!nfsd_netns_ready(nn))
7027
- return count;
7028
-
7029
- spin_lock(&nn->client_lock);
7030
- clp = nfsd_find_client(addr, addr_size);
7031
- if (clp)
7032
- count = nfsd_find_all_delegations(clp, 0, &reaplist);
7033
- spin_unlock(&nn->client_lock);
7034
-
7035
- nfsd_forget_delegations(&reaplist);
7036
- return count;
7037
-}
7038
-
7039
-u64
7040
-nfsd_inject_forget_delegations(u64 max)
7041
-{
7042
- u64 count = 0;
7043
- struct nfs4_client *clp;
7044
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
7045
- nfsd_net_id);
7046
- LIST_HEAD(reaplist);
7047
-
7048
- if (!nfsd_netns_ready(nn))
7049
- return count;
7050
-
7051
- spin_lock(&nn->client_lock);
7052
- list_for_each_entry(clp, &nn->client_lru, cl_lru) {
7053
- count += nfsd_find_all_delegations(clp, max - count, &reaplist);
7054
- if (max != 0 && count >= max)
7055
- break;
7056
- }
7057
- spin_unlock(&nn->client_lock);
7058
- nfsd_forget_delegations(&reaplist);
7059
- return count;
7060
-}
7061
-
7062
-static void
7063
-nfsd_recall_delegations(struct list_head *reaplist)
7064
-{
7065
- struct nfs4_client *clp;
7066
- struct nfs4_delegation *dp, *next;
7067
-
7068
- list_for_each_entry_safe(dp, next, reaplist, dl_recall_lru) {
7069
- list_del_init(&dp->dl_recall_lru);
7070
- clp = dp->dl_stid.sc_client;
7071
- /*
7072
- * We skipped all entries that had a zero dl_time before,
7073
- * so we can now reset the dl_time back to 0. If a delegation
7074
- * break comes in now, then it won't make any difference since
7075
- * we're recalling it either way.
7076
- */
7077
- spin_lock(&state_lock);
7078
- dp->dl_time = 0;
7079
- spin_unlock(&state_lock);
7080
- nfsd_break_one_deleg(dp);
7081
- put_client(clp);
7082
- }
7083
-}
7084
-
7085
-u64
7086
-nfsd_inject_recall_client_delegations(struct sockaddr_storage *addr,
7087
- size_t addr_size)
7088
-{
7089
- u64 count = 0;
7090
- struct nfs4_client *clp;
7091
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
7092
- nfsd_net_id);
7093
- LIST_HEAD(reaplist);
7094
-
7095
- if (!nfsd_netns_ready(nn))
7096
- return count;
7097
-
7098
- spin_lock(&nn->client_lock);
7099
- clp = nfsd_find_client(addr, addr_size);
7100
- if (clp)
7101
- count = nfsd_find_all_delegations(clp, 0, &reaplist);
7102
- spin_unlock(&nn->client_lock);
7103
-
7104
- nfsd_recall_delegations(&reaplist);
7105
- return count;
7106
-}
7107
-
7108
-u64
7109
-nfsd_inject_recall_delegations(u64 max)
7110
-{
7111
- u64 count = 0;
7112
- struct nfs4_client *clp, *next;
7113
- struct nfsd_net *nn = net_generic(current->nsproxy->net_ns,
7114
- nfsd_net_id);
7115
- LIST_HEAD(reaplist);
7116
-
7117
- if (!nfsd_netns_ready(nn))
7118
- return count;
7119
-
7120
- spin_lock(&nn->client_lock);
7121
- list_for_each_entry_safe(clp, next, &nn->client_lru, cl_lru) {
7122
- count += nfsd_find_all_delegations(clp, max - count, &reaplist);
7123
- if (max != 0 && ++count >= max)
7124
- break;
7125
- }
7126
- spin_unlock(&nn->client_lock);
7127
- nfsd_recall_delegations(&reaplist);
7128
- return count;
7129
-}
7130
-#endif /* CONFIG_NFSD_FAULT_INJECTION */
71317282
71327283 /*
71337284 * Since the lifetime of a delegation isn't limited to that of an open, a
....@@ -7179,7 +7330,7 @@
71797330 INIT_LIST_HEAD(&nn->sessionid_hashtbl[i]);
71807331 nn->conf_name_tree = RB_ROOT;
71817332 nn->unconf_name_tree = RB_ROOT;
7182
- nn->boot_time = get_seconds();
7333
+ nn->boot_time = ktime_get_real_seconds();
71837334 nn->grace_ended = false;
71847335 nn->nfsd4_manager.block_opens = true;
71857336 INIT_LIST_HEAD(&nn->nfsd4_manager.list);
....@@ -7187,6 +7338,8 @@
71877338 INIT_LIST_HEAD(&nn->close_lru);
71887339 INIT_LIST_HEAD(&nn->del_recall_lru);
71897340 spin_lock_init(&nn->client_lock);
7341
+ spin_lock_init(&nn->s2s_cp_lock);
7342
+ idr_init(&nn->s2s_cp_stateids);
71907343
71917344 spin_lock_init(&nn->blocked_locks_lock);
71927345 INIT_LIST_HEAD(&nn->blocked_locks_lru);
....@@ -7244,9 +7397,19 @@
72447397 return ret;
72457398 locks_start_grace(net, &nn->nfsd4_manager);
72467399 nfsd4_client_tracking_init(net);
7247
- printk(KERN_INFO "NFSD: starting %ld-second grace period (net %x)\n",
7400
+ if (nn->track_reclaim_completes && nn->reclaim_str_hashtbl_size == 0)
7401
+ goto skip_grace;
7402
+ printk(KERN_INFO "NFSD: starting %lld-second grace period (net %x)\n",
72487403 nn->nfsd4_grace, net->ns.inum);
7404
+ trace_nfsd_grace_start(nn);
72497405 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_grace * HZ);
7406
+ return 0;
7407
+
7408
+skip_grace:
7409
+ printk(KERN_INFO "NFSD: no clients to reclaim, skipping NFSv4 grace period (net %x)\n",
7410
+ net->ns.inum);
7411
+ queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_lease * HZ);
7412
+ nfsd4_end_grace(nn);
72507413 return 0;
72517414 }
72527415
....@@ -7313,7 +7476,8 @@
73137476 static void
73147477 get_stateid(struct nfsd4_compound_state *cstate, stateid_t *stateid)
73157478 {
7316
- if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG) && CURRENT_STATEID(stateid))
7479
+ if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG) &&
7480
+ CURRENT_STATEID(stateid))
73177481 memcpy(stateid, &cstate->current_stateid, sizeof(stateid_t));
73187482 }
73197483
....@@ -7322,14 +7486,14 @@
73227486 {
73237487 if (cstate->minorversion) {
73247488 memcpy(&cstate->current_stateid, stateid, sizeof(stateid_t));
7325
- SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG);
7489
+ SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG);
73267490 }
73277491 }
73287492
73297493 void
73307494 clear_current_stateid(struct nfsd4_compound_state *cstate)
73317495 {
7332
- CLEAR_STATE_ID(cstate, CURRENT_STATE_ID_FLAG);
7496
+ CLEAR_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG);
73337497 }
73347498
73357499 /*