forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
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;
....@@ -480,6 +503,17 @@
480503 if (!ret)
481504 ret = __nfs4_get_fd(f, O_RDONLY);
482505 }
506
+ spin_unlock(&f->fi_lock);
507
+ return ret;
508
+}
509
+
510
+static struct nfsd_file *find_deleg_file(struct nfs4_file *f)
511
+{
512
+ struct nfsd_file *ret = NULL;
513
+
514
+ spin_lock(&f->fi_lock);
515
+ if (f->fi_deleg_file)
516
+ ret = nfsd_file_get(f->fi_deleg_file);
483517 spin_unlock(&f->fi_lock);
484518 return ret;
485519 }
....@@ -572,17 +606,17 @@
572606 might_lock(&fp->fi_lock);
573607
574608 if (atomic_dec_and_lock(&fp->fi_access[oflag], &fp->fi_lock)) {
575
- struct file *f1 = NULL;
576
- struct file *f2 = NULL;
609
+ struct nfsd_file *f1 = NULL;
610
+ struct nfsd_file *f2 = NULL;
577611
578612 swap(f1, fp->fi_fds[oflag]);
579613 if (atomic_read(&fp->fi_access[1 - oflag]) == 0)
580614 swap(f2, fp->fi_fds[O_RDWR]);
581615 spin_unlock(&fp->fi_lock);
582616 if (f1)
583
- fput(f1);
617
+ nfsd_file_put(f1);
584618 if (f2)
585
- fput(f2);
619
+ nfsd_file_put(f2);
586620 }
587621 }
588622
....@@ -688,7 +722,8 @@
688722
689723 idr_preload(GFP_KERNEL);
690724 spin_lock(&cl->cl_lock);
691
- new_id = idr_alloc_cyclic(&cl->cl_stateids, stid, 0, 0, GFP_NOWAIT);
725
+ /* Reserving 0 for start of file in nfsdfs "states" file: */
726
+ new_id = idr_alloc_cyclic(&cl->cl_stateids, stid, 1, 0, GFP_NOWAIT);
692727 spin_unlock(&cl->cl_lock);
693728 idr_preload_end();
694729 if (new_id < 0)
....@@ -701,6 +736,7 @@
701736 /* Will be incremented before return to client: */
702737 refcount_set(&stid->sc_count, 1);
703738 spin_lock_init(&stid->sc_lock);
739
+ INIT_LIST_HEAD(&stid->sc_cp_list);
704740
705741 /*
706742 * It shouldn't be a problem to reuse an opaque stateid value.
....@@ -717,6 +753,83 @@
717753 return NULL;
718754 }
719755
756
+/*
757
+ * Create a unique stateid_t to represent each COPY.
758
+ */
759
+static int nfs4_init_cp_state(struct nfsd_net *nn, copy_stateid_t *stid,
760
+ unsigned char sc_type)
761
+{
762
+ int new_id;
763
+
764
+ stid->stid.si_opaque.so_clid.cl_boot = (u32)nn->boot_time;
765
+ stid->stid.si_opaque.so_clid.cl_id = nn->s2s_cp_cl_id;
766
+ stid->sc_type = sc_type;
767
+
768
+ idr_preload(GFP_KERNEL);
769
+ spin_lock(&nn->s2s_cp_lock);
770
+ new_id = idr_alloc_cyclic(&nn->s2s_cp_stateids, stid, 0, 0, GFP_NOWAIT);
771
+ stid->stid.si_opaque.so_id = new_id;
772
+ stid->stid.si_generation = 1;
773
+ spin_unlock(&nn->s2s_cp_lock);
774
+ idr_preload_end();
775
+ if (new_id < 0)
776
+ return 0;
777
+ return 1;
778
+}
779
+
780
+int nfs4_init_copy_state(struct nfsd_net *nn, struct nfsd4_copy *copy)
781
+{
782
+ return nfs4_init_cp_state(nn, &copy->cp_stateid, NFS4_COPY_STID);
783
+}
784
+
785
+struct nfs4_cpntf_state *nfs4_alloc_init_cpntf_state(struct nfsd_net *nn,
786
+ struct nfs4_stid *p_stid)
787
+{
788
+ struct nfs4_cpntf_state *cps;
789
+
790
+ cps = kzalloc(sizeof(struct nfs4_cpntf_state), GFP_KERNEL);
791
+ if (!cps)
792
+ return NULL;
793
+ cps->cpntf_time = ktime_get_boottime_seconds();
794
+ refcount_set(&cps->cp_stateid.sc_count, 1);
795
+ if (!nfs4_init_cp_state(nn, &cps->cp_stateid, NFS4_COPYNOTIFY_STID))
796
+ goto out_free;
797
+ spin_lock(&nn->s2s_cp_lock);
798
+ list_add(&cps->cp_list, &p_stid->sc_cp_list);
799
+ spin_unlock(&nn->s2s_cp_lock);
800
+ return cps;
801
+out_free:
802
+ kfree(cps);
803
+ return NULL;
804
+}
805
+
806
+void nfs4_free_copy_state(struct nfsd4_copy *copy)
807
+{
808
+ struct nfsd_net *nn;
809
+
810
+ WARN_ON_ONCE(copy->cp_stateid.sc_type != NFS4_COPY_STID);
811
+ nn = net_generic(copy->cp_clp->net, nfsd_net_id);
812
+ spin_lock(&nn->s2s_cp_lock);
813
+ idr_remove(&nn->s2s_cp_stateids,
814
+ copy->cp_stateid.stid.si_opaque.so_id);
815
+ spin_unlock(&nn->s2s_cp_lock);
816
+}
817
+
818
+static void nfs4_free_cpntf_statelist(struct net *net, struct nfs4_stid *stid)
819
+{
820
+ struct nfs4_cpntf_state *cps;
821
+ struct nfsd_net *nn;
822
+
823
+ nn = net_generic(net, nfsd_net_id);
824
+ spin_lock(&nn->s2s_cp_lock);
825
+ while (!list_empty(&stid->sc_cp_list)) {
826
+ cps = list_first_entry(&stid->sc_cp_list,
827
+ struct nfs4_cpntf_state, cp_list);
828
+ _free_cpntf_state_locked(nn, cps);
829
+ }
830
+ spin_unlock(&nn->s2s_cp_lock);
831
+}
832
+
720833 static struct nfs4_ol_stateid * nfs4_alloc_open_stateid(struct nfs4_client *clp)
721834 {
722835 struct nfs4_stid *stid;
....@@ -730,6 +843,7 @@
730843
731844 static void nfs4_free_deleg(struct nfs4_stid *stid)
732845 {
846
+ WARN_ON(!list_empty(&stid->sc_cp_list));
733847 kmem_cache_free(deleg_slab, stid);
734848 atomic_long_dec(&num_delegations);
735849 }
....@@ -755,7 +869,7 @@
755869 static DEFINE_SPINLOCK(blocked_delegations_lock);
756870 static struct bloom_pair {
757871 int entries, old_entries;
758
- time_t swap_time;
872
+ time64_t swap_time;
759873 int new; /* index into 'set' */
760874 DECLARE_BITMAP(set[2], 256);
761875 } blocked_delegations;
....@@ -767,15 +881,15 @@
767881
768882 if (bd->entries == 0)
769883 return 0;
770
- if (seconds_since_boot() - bd->swap_time > 30) {
884
+ if (ktime_get_seconds() - bd->swap_time > 30) {
771885 spin_lock(&blocked_delegations_lock);
772
- if (seconds_since_boot() - bd->swap_time > 30) {
886
+ if (ktime_get_seconds() - bd->swap_time > 30) {
773887 bd->entries -= bd->old_entries;
774888 bd->old_entries = bd->entries;
775889 memset(bd->set[bd->new], 0,
776890 sizeof(bd->set[0]));
777891 bd->new = 1-bd->new;
778
- bd->swap_time = seconds_since_boot();
892
+ bd->swap_time = ktime_get_seconds();
779893 }
780894 spin_unlock(&blocked_delegations_lock);
781895 }
....@@ -805,7 +919,7 @@
805919 __set_bit((hash>>8)&255, bd->set[bd->new]);
806920 __set_bit((hash>>16)&255, bd->set[bd->new]);
807921 if (bd->entries == 0)
808
- bd->swap_time = seconds_since_boot();
922
+ bd->swap_time = ktime_get_seconds();
809923 bd->entries += 1;
810924 spin_unlock(&blocked_delegations_lock);
811925 }
....@@ -864,6 +978,7 @@
864978 return;
865979 }
866980 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id);
981
+ nfs4_free_cpntf_statelist(clp->net, s);
867982 spin_unlock(&clp->cl_lock);
868983 s->sc_free(s);
869984 if (fp)
....@@ -884,25 +999,25 @@
884999
8851000 static void put_deleg_file(struct nfs4_file *fp)
8861001 {
887
- struct file *filp = NULL;
1002
+ struct nfsd_file *nf = NULL;
8881003
8891004 spin_lock(&fp->fi_lock);
8901005 if (--fp->fi_delegees == 0)
891
- swap(filp, fp->fi_deleg_file);
1006
+ swap(nf, fp->fi_deleg_file);
8921007 spin_unlock(&fp->fi_lock);
8931008
894
- if (filp)
895
- fput(filp);
1009
+ if (nf)
1010
+ nfsd_file_put(nf);
8961011 }
8971012
8981013 static void nfs4_unlock_deleg_lease(struct nfs4_delegation *dp)
8991014 {
9001015 struct nfs4_file *fp = dp->dl_stid.sc_file;
901
- struct file *filp = fp->fi_deleg_file;
1016
+ struct nfsd_file *nf = fp->fi_deleg_file;
9021017
9031018 WARN_ON_ONCE(!fp->fi_delegees);
9041019
905
- vfs_setlease(filp, F_UNLCK, NULL, (void **)&dp);
1020
+ vfs_setlease(nf->nf_file, F_UNLCK, NULL, (void **)&dp);
9061021 put_deleg_file(fp);
9071022 }
9081023
....@@ -1037,9 +1152,9 @@
10371152 return id & CLIENT_HASH_MASK;
10381153 }
10391154
1040
-static unsigned int clientstr_hashval(const char *name)
1155
+static unsigned int clientstr_hashval(struct xdr_netobj name)
10411156 {
1042
- return opaque_hashval(name, 8) & CLIENT_HASH_MASK;
1157
+ return opaque_hashval(name.data, 8) & CLIENT_HASH_MASK;
10431158 }
10441159
10451160 /*
....@@ -1244,6 +1359,7 @@
12441359 release_all_access(stp);
12451360 if (stp->st_stateowner)
12461361 nfs4_put_stateowner(stp->st_stateowner);
1362
+ WARN_ON(!list_empty(&stid->sc_cp_list));
12471363 kmem_cache_free(stateid_slab, stid);
12481364 }
12491365
....@@ -1251,11 +1367,14 @@
12511367 {
12521368 struct nfs4_ol_stateid *stp = openlockstateid(stid);
12531369 struct nfs4_lockowner *lo = lockowner(stp->st_stateowner);
1254
- struct file *file;
1370
+ struct nfsd_file *nf;
12551371
1256
- file = find_any_file(stp->st_stid.sc_file);
1257
- if (file)
1258
- filp_close(file, (fl_owner_t)lo);
1372
+ nf = find_any_file(stp->st_stid.sc_file);
1373
+ if (nf) {
1374
+ get_file(nf->nf_file);
1375
+ filp_close(nf->nf_file, (fl_owner_t)lo);
1376
+ nfsd_file_put(nf);
1377
+ }
12591378 nfs4_free_ol_stateid(stid);
12601379 }
12611380
....@@ -1526,21 +1645,39 @@
15261645 * re-negotiate active sessions and reduce their slot usage to make
15271646 * room for new connections. For now we just fail the create session.
15281647 */
1529
-static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca)
1648
+static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca, struct nfsd_net *nn)
15301649 {
15311650 u32 slotsize = slot_bytes(ca);
15321651 u32 num = ca->maxreqs;
15331652 unsigned long avail, total_avail;
1653
+ unsigned int scale_factor;
15341654
15351655 spin_lock(&nfsd_drc_lock);
1536
- total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used;
1656
+ if (nfsd_drc_max_mem > nfsd_drc_mem_used)
1657
+ total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used;
1658
+ else
1659
+ /* We have handed out more space than we chose in
1660
+ * set_max_drc() to allow. That isn't really a
1661
+ * problem as long as that doesn't make us think we
1662
+ * have lots more due to integer overflow.
1663
+ */
1664
+ total_avail = 0;
15371665 avail = min((unsigned long)NFSD_MAX_MEM_PER_SESSION, total_avail);
15381666 /*
1539
- * Never use more than a third of the remaining memory,
1540
- * unless it's the only way to give this client a slot:
1667
+ * Never use more than a fraction of the remaining memory,
1668
+ * unless it's the only way to give this client a slot.
1669
+ * The chosen fraction is either 1/8 or 1/number of threads,
1670
+ * whichever is smaller. This ensures there are adequate
1671
+ * slots to support multiple clients per thread.
1672
+ * Give the client one slot even if that would require
1673
+ * over-allocation--it is better than failure.
15411674 */
1542
- avail = clamp_t(unsigned long, avail, slotsize, total_avail/3);
1675
+ scale_factor = max_t(unsigned int, 8, nn->nfsd_serv->sv_nrthreads);
1676
+
1677
+ avail = clamp_t(unsigned long, avail, slotsize,
1678
+ total_avail/scale_factor);
15431679 num = min_t(int, num, avail / slotsize);
1680
+ num = max_t(int, num, 1);
15441681 nfsd_drc_mem_used += num * slotsize;
15451682 spin_unlock(&nfsd_drc_lock);
15461683
....@@ -1802,8 +1939,7 @@
18021939 */
18031940 if (clid->cl_boot == (u32)nn->boot_time)
18041941 return 0;
1805
- dprintk("NFSD stale clientid (%08x/%08x) boot_time %08lx\n",
1806
- clid->cl_boot, clid->cl_id, nn->boot_time);
1942
+ trace_nfsd_clid_stale(clid);
18071943 return 1;
18081944 }
18091945
....@@ -1820,7 +1956,7 @@
18201956 clp = kmem_cache_zalloc(client_slab, GFP_KERNEL);
18211957 if (clp == NULL)
18221958 return NULL;
1823
- clp->cl_name.data = kmemdup(name.data, name.len, GFP_KERNEL);
1959
+ xdr_netobj_dup(&clp->cl_name, &name, GFP_KERNEL);
18241960 if (clp->cl_name.data == NULL)
18251961 goto err_no_name;
18261962 clp->cl_ownerstr_hashtbl = kmalloc_array(OWNER_HASH_SIZE,
....@@ -1830,10 +1966,9 @@
18301966 goto err_no_hashtbl;
18311967 for (i = 0; i < OWNER_HASH_SIZE; i++)
18321968 INIT_LIST_HEAD(&clp->cl_ownerstr_hashtbl[i]);
1833
- clp->cl_name.len = name.len;
18341969 INIT_LIST_HEAD(&clp->cl_sessions);
18351970 idr_init(&clp->cl_stateids);
1836
- atomic_set(&clp->cl_refcount, 0);
1971
+ atomic_set(&clp->cl_rpc_users, 0);
18371972 clp->cl_cb_state = NFSD4_CB_UNKNOWN;
18381973 INIT_LIST_HEAD(&clp->cl_idhash);
18391974 INIT_LIST_HEAD(&clp->cl_openowners);
....@@ -1843,6 +1978,8 @@
18431978 #ifdef CONFIG_NFSD_PNFS
18441979 INIT_LIST_HEAD(&clp->cl_lo_states);
18451980 #endif
1981
+ INIT_LIST_HEAD(&clp->async_copies);
1982
+ spin_lock_init(&clp->async_lock);
18461983 spin_lock_init(&clp->cl_lock);
18471984 rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
18481985 return clp;
....@@ -1851,6 +1988,25 @@
18511988 err_no_name:
18521989 kmem_cache_free(client_slab, clp);
18531990 return NULL;
1991
+}
1992
+
1993
+static void __free_client(struct kref *k)
1994
+{
1995
+ struct nfsdfs_client *c = container_of(k, struct nfsdfs_client, cl_ref);
1996
+ struct nfs4_client *clp = container_of(c, struct nfs4_client, cl_nfsdfs);
1997
+
1998
+ free_svc_cred(&clp->cl_cred);
1999
+ kfree(clp->cl_ownerstr_hashtbl);
2000
+ kfree(clp->cl_name.data);
2001
+ kfree(clp->cl_nii_domain.data);
2002
+ kfree(clp->cl_nii_name.data);
2003
+ idr_destroy(&clp->cl_stateids);
2004
+ kmem_cache_free(client_slab, clp);
2005
+}
2006
+
2007
+static void drop_client(struct nfs4_client *clp)
2008
+{
2009
+ kref_put(&clp->cl_nfsdfs.cl_ref, __free_client);
18542010 }
18552011
18562012 static void
....@@ -1865,11 +2021,12 @@
18652021 free_session(ses);
18662022 }
18672023 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);
2024
+ if (clp->cl_nfsd_dentry) {
2025
+ nfsd_client_rmdir(clp->cl_nfsd_dentry);
2026
+ clp->cl_nfsd_dentry = NULL;
2027
+ wake_up_all(&expiry_wq);
2028
+ }
2029
+ drop_client(clp);
18732030 }
18742031
18752032 /* must be called under the client_lock */
....@@ -1910,7 +2067,7 @@
19102067
19112068 static __be32 mark_client_expired_locked(struct nfs4_client *clp)
19122069 {
1913
- if (atomic_read(&clp->cl_refcount))
2070
+ if (atomic_read(&clp->cl_rpc_users))
19142071 return nfserr_jukebox;
19152072 unhash_client_locked(clp);
19162073 return nfs_ok;
....@@ -1958,10 +2115,12 @@
19582115 }
19592116 }
19602117 nfsd4_return_all_client_layouts(clp);
2118
+ nfsd4_shutdown_copy(clp);
19612119 nfsd4_shutdown_callback(clp);
19622120 if (clp->cl_cb_conn.cb_xprt)
19632121 svc_xprt_put(clp->cl_cb_conn.cb_xprt);
19642122 free_client(clp);
2123
+ wake_up_all(&expiry_wq);
19652124 }
19662125
19672126 static void
....@@ -1969,6 +2128,22 @@
19692128 {
19702129 unhash_client(clp);
19712130 __destroy_client(clp);
2131
+}
2132
+
2133
+static void inc_reclaim_complete(struct nfs4_client *clp)
2134
+{
2135
+ struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
2136
+
2137
+ if (!nn->track_reclaim_completes)
2138
+ return;
2139
+ if (!nfsd4_find_reclaim_client(clp->cl_name, nn))
2140
+ return;
2141
+ if (atomic_inc_return(&nn->nr_reclaim_complete) ==
2142
+ nn->reclaim_str_hashtbl_size) {
2143
+ printk(KERN_INFO "NFSD: all clients done reclaiming, ending NFSv4 grace period (net %x)\n",
2144
+ clp->net->ns.inum);
2145
+ nfsd4_end_grace(nn);
2146
+ }
19722147 }
19732148
19742149 static void expire_client(struct nfs4_client *clp)
....@@ -2020,11 +2195,6 @@
20202195 if (o1->len > o2->len)
20212196 return 1;
20222197 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);
20282198 }
20292199
20302200 static int
....@@ -2121,14 +2291,14 @@
21212291 * This is opaque to client, so no need to byte-swap. Use
21222292 * __force to keep sparse happy
21232293 */
2124
- verf[0] = (__force __be32)get_seconds();
2294
+ verf[0] = (__force __be32)(u32)ktime_get_real_seconds();
21252295 verf[1] = (__force __be32)nn->clverifier_counter++;
21262296 memcpy(clp->cl_confirm.data, verf, sizeof(clp->cl_confirm.data));
21272297 }
21282298
21292299 static void gen_clid(struct nfs4_client *clp, struct nfsd_net *nn)
21302300 {
2131
- clp->cl_clientid.cl_boot = nn->boot_time;
2301
+ clp->cl_clientid.cl_boot = (u32)nn->boot_time;
21322302 clp->cl_clientid.cl_id = nn->clientid_counter++;
21332303 gen_confirm(clp, nn);
21342304 }
....@@ -2161,6 +2331,376 @@
21612331 return s;
21622332 }
21632333
2334
+static struct nfs4_client *get_nfsdfs_clp(struct inode *inode)
2335
+{
2336
+ struct nfsdfs_client *nc;
2337
+ nc = get_nfsdfs_client(inode);
2338
+ if (!nc)
2339
+ return NULL;
2340
+ return container_of(nc, struct nfs4_client, cl_nfsdfs);
2341
+}
2342
+
2343
+static void seq_quote_mem(struct seq_file *m, char *data, int len)
2344
+{
2345
+ seq_printf(m, "\"");
2346
+ seq_escape_mem_ascii(m, data, len);
2347
+ seq_printf(m, "\"");
2348
+}
2349
+
2350
+static int client_info_show(struct seq_file *m, void *v)
2351
+{
2352
+ struct inode *inode = m->private;
2353
+ struct nfs4_client *clp;
2354
+ u64 clid;
2355
+
2356
+ clp = get_nfsdfs_clp(inode);
2357
+ if (!clp)
2358
+ return -ENXIO;
2359
+ memcpy(&clid, &clp->cl_clientid, sizeof(clid));
2360
+ seq_printf(m, "clientid: 0x%llx\n", clid);
2361
+ seq_printf(m, "address: \"%pISpc\"\n", (struct sockaddr *)&clp->cl_addr);
2362
+ seq_printf(m, "name: ");
2363
+ seq_quote_mem(m, clp->cl_name.data, clp->cl_name.len);
2364
+ seq_printf(m, "\nminor version: %d\n", clp->cl_minorversion);
2365
+ if (clp->cl_nii_domain.data) {
2366
+ seq_printf(m, "Implementation domain: ");
2367
+ seq_quote_mem(m, clp->cl_nii_domain.data,
2368
+ clp->cl_nii_domain.len);
2369
+ seq_printf(m, "\nImplementation name: ");
2370
+ seq_quote_mem(m, clp->cl_nii_name.data, clp->cl_nii_name.len);
2371
+ seq_printf(m, "\nImplementation time: [%lld, %ld]\n",
2372
+ clp->cl_nii_time.tv_sec, clp->cl_nii_time.tv_nsec);
2373
+ }
2374
+ drop_client(clp);
2375
+
2376
+ return 0;
2377
+}
2378
+
2379
+static int client_info_open(struct inode *inode, struct file *file)
2380
+{
2381
+ return single_open(file, client_info_show, inode);
2382
+}
2383
+
2384
+static const struct file_operations client_info_fops = {
2385
+ .open = client_info_open,
2386
+ .read = seq_read,
2387
+ .llseek = seq_lseek,
2388
+ .release = single_release,
2389
+};
2390
+
2391
+static void *states_start(struct seq_file *s, loff_t *pos)
2392
+ __acquires(&clp->cl_lock)
2393
+{
2394
+ struct nfs4_client *clp = s->private;
2395
+ unsigned long id = *pos;
2396
+ void *ret;
2397
+
2398
+ spin_lock(&clp->cl_lock);
2399
+ ret = idr_get_next_ul(&clp->cl_stateids, &id);
2400
+ *pos = id;
2401
+ return ret;
2402
+}
2403
+
2404
+static void *states_next(struct seq_file *s, void *v, loff_t *pos)
2405
+{
2406
+ struct nfs4_client *clp = s->private;
2407
+ unsigned long id = *pos;
2408
+ void *ret;
2409
+
2410
+ id = *pos;
2411
+ id++;
2412
+ ret = idr_get_next_ul(&clp->cl_stateids, &id);
2413
+ *pos = id;
2414
+ return ret;
2415
+}
2416
+
2417
+static void states_stop(struct seq_file *s, void *v)
2418
+ __releases(&clp->cl_lock)
2419
+{
2420
+ struct nfs4_client *clp = s->private;
2421
+
2422
+ spin_unlock(&clp->cl_lock);
2423
+}
2424
+
2425
+static void nfs4_show_fname(struct seq_file *s, struct nfsd_file *f)
2426
+{
2427
+ seq_printf(s, "filename: \"%pD2\"", f->nf_file);
2428
+}
2429
+
2430
+static void nfs4_show_superblock(struct seq_file *s, struct nfsd_file *f)
2431
+{
2432
+ struct inode *inode = f->nf_inode;
2433
+
2434
+ seq_printf(s, "superblock: \"%02x:%02x:%ld\"",
2435
+ MAJOR(inode->i_sb->s_dev),
2436
+ MINOR(inode->i_sb->s_dev),
2437
+ inode->i_ino);
2438
+}
2439
+
2440
+static void nfs4_show_owner(struct seq_file *s, struct nfs4_stateowner *oo)
2441
+{
2442
+ seq_printf(s, "owner: ");
2443
+ seq_quote_mem(s, oo->so_owner.data, oo->so_owner.len);
2444
+}
2445
+
2446
+static void nfs4_show_stateid(struct seq_file *s, stateid_t *stid)
2447
+{
2448
+ seq_printf(s, "0x%.8x", stid->si_generation);
2449
+ seq_printf(s, "%12phN", &stid->si_opaque);
2450
+}
2451
+
2452
+static int nfs4_show_open(struct seq_file *s, struct nfs4_stid *st)
2453
+{
2454
+ struct nfs4_ol_stateid *ols;
2455
+ struct nfs4_file *nf;
2456
+ struct nfsd_file *file;
2457
+ struct nfs4_stateowner *oo;
2458
+ unsigned int access, deny;
2459
+
2460
+ if (st->sc_type != NFS4_OPEN_STID && st->sc_type != NFS4_LOCK_STID)
2461
+ return 0; /* XXX: or SEQ_SKIP? */
2462
+ ols = openlockstateid(st);
2463
+ oo = ols->st_stateowner;
2464
+ nf = st->sc_file;
2465
+ file = find_any_file(nf);
2466
+ if (!file)
2467
+ return 0;
2468
+
2469
+ seq_printf(s, "- ");
2470
+ nfs4_show_stateid(s, &st->sc_stateid);
2471
+ seq_printf(s, ": { type: open, ");
2472
+
2473
+ access = bmap_to_share_mode(ols->st_access_bmap);
2474
+ deny = bmap_to_share_mode(ols->st_deny_bmap);
2475
+
2476
+ seq_printf(s, "access: %s%s, ",
2477
+ access & NFS4_SHARE_ACCESS_READ ? "r" : "-",
2478
+ access & NFS4_SHARE_ACCESS_WRITE ? "w" : "-");
2479
+ seq_printf(s, "deny: %s%s, ",
2480
+ deny & NFS4_SHARE_ACCESS_READ ? "r" : "-",
2481
+ deny & NFS4_SHARE_ACCESS_WRITE ? "w" : "-");
2482
+
2483
+ nfs4_show_superblock(s, file);
2484
+ seq_printf(s, ", ");
2485
+ nfs4_show_fname(s, file);
2486
+ seq_printf(s, ", ");
2487
+ nfs4_show_owner(s, oo);
2488
+ seq_printf(s, " }\n");
2489
+ nfsd_file_put(file);
2490
+
2491
+ return 0;
2492
+}
2493
+
2494
+static int nfs4_show_lock(struct seq_file *s, struct nfs4_stid *st)
2495
+{
2496
+ struct nfs4_ol_stateid *ols;
2497
+ struct nfs4_file *nf;
2498
+ struct nfsd_file *file;
2499
+ struct nfs4_stateowner *oo;
2500
+
2501
+ ols = openlockstateid(st);
2502
+ oo = ols->st_stateowner;
2503
+ nf = st->sc_file;
2504
+ file = find_any_file(nf);
2505
+ if (!file)
2506
+ return 0;
2507
+
2508
+ seq_printf(s, "- ");
2509
+ nfs4_show_stateid(s, &st->sc_stateid);
2510
+ seq_printf(s, ": { type: lock, ");
2511
+
2512
+ /*
2513
+ * Note: a lock stateid isn't really the same thing as a lock,
2514
+ * it's the locking state held by one owner on a file, and there
2515
+ * may be multiple (or no) lock ranges associated with it.
2516
+ * (Same for the matter is true of open stateids.)
2517
+ */
2518
+
2519
+ nfs4_show_superblock(s, file);
2520
+ /* XXX: open stateid? */
2521
+ seq_printf(s, ", ");
2522
+ nfs4_show_fname(s, file);
2523
+ seq_printf(s, ", ");
2524
+ nfs4_show_owner(s, oo);
2525
+ seq_printf(s, " }\n");
2526
+ nfsd_file_put(file);
2527
+
2528
+ return 0;
2529
+}
2530
+
2531
+static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st)
2532
+{
2533
+ struct nfs4_delegation *ds;
2534
+ struct nfs4_file *nf;
2535
+ struct nfsd_file *file;
2536
+
2537
+ ds = delegstateid(st);
2538
+ nf = st->sc_file;
2539
+ file = find_deleg_file(nf);
2540
+ if (!file)
2541
+ return 0;
2542
+
2543
+ seq_printf(s, "- ");
2544
+ nfs4_show_stateid(s, &st->sc_stateid);
2545
+ seq_printf(s, ": { type: deleg, ");
2546
+
2547
+ /* Kinda dead code as long as we only support read delegs: */
2548
+ seq_printf(s, "access: %s, ",
2549
+ ds->dl_type == NFS4_OPEN_DELEGATE_READ ? "r" : "w");
2550
+
2551
+ /* XXX: lease time, whether it's being recalled. */
2552
+
2553
+ nfs4_show_superblock(s, file);
2554
+ seq_printf(s, ", ");
2555
+ nfs4_show_fname(s, file);
2556
+ seq_printf(s, " }\n");
2557
+ nfsd_file_put(file);
2558
+
2559
+ return 0;
2560
+}
2561
+
2562
+static int nfs4_show_layout(struct seq_file *s, struct nfs4_stid *st)
2563
+{
2564
+ struct nfs4_layout_stateid *ls;
2565
+ struct nfsd_file *file;
2566
+
2567
+ ls = container_of(st, struct nfs4_layout_stateid, ls_stid);
2568
+ file = ls->ls_file;
2569
+
2570
+ seq_printf(s, "- ");
2571
+ nfs4_show_stateid(s, &st->sc_stateid);
2572
+ seq_printf(s, ": { type: layout, ");
2573
+
2574
+ /* XXX: What else would be useful? */
2575
+
2576
+ nfs4_show_superblock(s, file);
2577
+ seq_printf(s, ", ");
2578
+ nfs4_show_fname(s, file);
2579
+ seq_printf(s, " }\n");
2580
+
2581
+ return 0;
2582
+}
2583
+
2584
+static int states_show(struct seq_file *s, void *v)
2585
+{
2586
+ struct nfs4_stid *st = v;
2587
+
2588
+ switch (st->sc_type) {
2589
+ case NFS4_OPEN_STID:
2590
+ return nfs4_show_open(s, st);
2591
+ case NFS4_LOCK_STID:
2592
+ return nfs4_show_lock(s, st);
2593
+ case NFS4_DELEG_STID:
2594
+ return nfs4_show_deleg(s, st);
2595
+ case NFS4_LAYOUT_STID:
2596
+ return nfs4_show_layout(s, st);
2597
+ default:
2598
+ return 0; /* XXX: or SEQ_SKIP? */
2599
+ }
2600
+ /* XXX: copy stateids? */
2601
+}
2602
+
2603
+static struct seq_operations states_seq_ops = {
2604
+ .start = states_start,
2605
+ .next = states_next,
2606
+ .stop = states_stop,
2607
+ .show = states_show
2608
+};
2609
+
2610
+static int client_states_open(struct inode *inode, struct file *file)
2611
+{
2612
+ struct seq_file *s;
2613
+ struct nfs4_client *clp;
2614
+ int ret;
2615
+
2616
+ clp = get_nfsdfs_clp(inode);
2617
+ if (!clp)
2618
+ return -ENXIO;
2619
+
2620
+ ret = seq_open(file, &states_seq_ops);
2621
+ if (ret)
2622
+ return ret;
2623
+ s = file->private_data;
2624
+ s->private = clp;
2625
+ return 0;
2626
+}
2627
+
2628
+static int client_opens_release(struct inode *inode, struct file *file)
2629
+{
2630
+ struct seq_file *m = file->private_data;
2631
+ struct nfs4_client *clp = m->private;
2632
+
2633
+ /* XXX: alternatively, we could get/drop in seq start/stop */
2634
+ drop_client(clp);
2635
+ return 0;
2636
+}
2637
+
2638
+static const struct file_operations client_states_fops = {
2639
+ .open = client_states_open,
2640
+ .read = seq_read,
2641
+ .llseek = seq_lseek,
2642
+ .release = client_opens_release,
2643
+};
2644
+
2645
+/*
2646
+ * Normally we refuse to destroy clients that are in use, but here the
2647
+ * administrator is telling us to just do it. We also want to wait
2648
+ * so the caller has a guarantee that the client's locks are gone by
2649
+ * the time the write returns:
2650
+ */
2651
+static void force_expire_client(struct nfs4_client *clp)
2652
+{
2653
+ struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
2654
+ bool already_expired;
2655
+
2656
+ spin_lock(&nn->client_lock);
2657
+ clp->cl_time = 0;
2658
+ spin_unlock(&nn->client_lock);
2659
+
2660
+ wait_event(expiry_wq, atomic_read(&clp->cl_rpc_users) == 0);
2661
+ spin_lock(&nn->client_lock);
2662
+ already_expired = list_empty(&clp->cl_lru);
2663
+ if (!already_expired)
2664
+ unhash_client_locked(clp);
2665
+ spin_unlock(&nn->client_lock);
2666
+
2667
+ if (!already_expired)
2668
+ expire_client(clp);
2669
+ else
2670
+ wait_event(expiry_wq, clp->cl_nfsd_dentry == NULL);
2671
+}
2672
+
2673
+static ssize_t client_ctl_write(struct file *file, const char __user *buf,
2674
+ size_t size, loff_t *pos)
2675
+{
2676
+ char *data;
2677
+ struct nfs4_client *clp;
2678
+
2679
+ data = simple_transaction_get(file, buf, size);
2680
+ if (IS_ERR(data))
2681
+ return PTR_ERR(data);
2682
+ if (size != 7 || 0 != memcmp(data, "expire\n", 7))
2683
+ return -EINVAL;
2684
+ clp = get_nfsdfs_clp(file_inode(file));
2685
+ if (!clp)
2686
+ return -ENXIO;
2687
+ force_expire_client(clp);
2688
+ drop_client(clp);
2689
+ return 7;
2690
+}
2691
+
2692
+static const struct file_operations client_ctl_fops = {
2693
+ .write = client_ctl_write,
2694
+ .release = simple_transaction_release,
2695
+};
2696
+
2697
+static const struct tree_descr client_files[] = {
2698
+ [0] = {"info", &client_info_fops, S_IRUSR},
2699
+ [1] = {"states", &client_states_fops, S_IRUSR},
2700
+ [2] = {"ctl", &client_ctl_fops, S_IWUSR},
2701
+ [3] = {""},
2702
+};
2703
+
21642704 static struct nfs4_client *create_client(struct xdr_netobj name,
21652705 struct svc_rqst *rqstp, nfs4_verifier *verf)
21662706 {
....@@ -2168,6 +2708,7 @@
21682708 struct sockaddr *sa = svc_addr(rqstp);
21692709 int ret;
21702710 struct net *net = SVC_NET(rqstp);
2711
+ struct nfsd_net *nn = net_generic(net, nfsd_net_id);
21712712
21722713 clp = alloc_client(name);
21732714 if (clp == NULL)
....@@ -2178,13 +2719,22 @@
21782719 free_client(clp);
21792720 return NULL;
21802721 }
2722
+ gen_clid(clp, nn);
2723
+ kref_init(&clp->cl_nfsdfs.cl_ref);
21812724 nfsd4_init_cb(&clp->cl_cb_null, clp, NULL, NFSPROC4_CLNT_CB_NULL);
2182
- clp->cl_time = get_seconds();
2725
+ clp->cl_time = ktime_get_boottime_seconds();
21832726 clear_bit(0, &clp->cl_cb_slot_busy);
21842727 copy_verf(clp, verf);
2185
- rpc_copy_addr((struct sockaddr *) &clp->cl_addr, sa);
2728
+ memcpy(&clp->cl_addr, sa, sizeof(struct sockaddr_storage));
21862729 clp->cl_cb_session = NULL;
21872730 clp->net = net;
2731
+ clp->cl_nfsd_dentry = nfsd_client_mkdir(nn, &clp->cl_nfsdfs,
2732
+ clp->cl_clientid.cl_id - nn->clientid_base,
2733
+ client_files);
2734
+ if (!clp->cl_nfsd_dentry) {
2735
+ free_client(clp);
2736
+ return NULL;
2737
+ }
21882738 return clp;
21892739 }
21902740
....@@ -2345,14 +2895,12 @@
23452895 conn->cb_prog = se->se_callback_prog;
23462896 conn->cb_ident = se->se_callback_ident;
23472897 memcpy(&conn->cb_saddr, &rqstp->rq_daddr, rqstp->rq_daddrlen);
2898
+ trace_nfsd_cb_args(clp, conn);
23482899 return;
23492900 out_err:
23502901 conn->cb_addr.ss_family = AF_UNSPEC;
23512902 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
-
2903
+ trace_nfsd_cb_nodelegs(clp);
23562904 return;
23572905 }
23582906
....@@ -2491,7 +3039,23 @@
24913039 || !list_empty(&clp->cl_lo_states)
24923040 #endif
24933041 || !list_empty(&clp->cl_delegations)
2494
- || !list_empty(&clp->cl_sessions);
3042
+ || !list_empty(&clp->cl_sessions)
3043
+ || !list_empty(&clp->async_copies);
3044
+}
3045
+
3046
+static __be32 copy_impl_id(struct nfs4_client *clp,
3047
+ struct nfsd4_exchange_id *exid)
3048
+{
3049
+ if (!exid->nii_domain.data)
3050
+ return 0;
3051
+ xdr_netobj_dup(&clp->cl_nii_domain, &exid->nii_domain, GFP_KERNEL);
3052
+ if (!clp->cl_nii_domain.data)
3053
+ return nfserr_jukebox;
3054
+ xdr_netobj_dup(&clp->cl_nii_name, &exid->nii_name, GFP_KERNEL);
3055
+ if (!clp->cl_nii_name.data)
3056
+ return nfserr_jukebox;
3057
+ clp->cl_nii_time = exid->nii_time;
3058
+ return 0;
24953059 }
24963060
24973061 __be32
....@@ -2520,6 +3084,9 @@
25203084 new = create_client(exid->clname, rqstp, &verf);
25213085 if (new == NULL)
25223086 return nfserr_jukebox;
3087
+ status = copy_impl_id(new, exid);
3088
+ if (status)
3089
+ goto out_nolock;
25233090
25243091 switch (exid->spa_how) {
25253092 case SP4_MACH_CRED:
....@@ -2558,6 +3125,7 @@
25583125 break;
25593126 default: /* checked by xdr code */
25603127 WARN_ON_ONCE(1);
3128
+ fallthrough;
25613129 case SP4_SSV:
25623130 status = nfserr_encr_alg_unsupp;
25633131 goto out_nolock;
....@@ -2627,7 +3195,6 @@
26273195 new->cl_spo_must_allow.u.words[0] = exid->spo_must_allow[0];
26283196 new->cl_spo_must_allow.u.words[1] = exid->spo_must_allow[1];
26293197
2630
- gen_clid(new, nn);
26313198 add_to_unconfirmed(new);
26323199 swap(new, conf);
26333200 out_copy:
....@@ -2732,10 +3299,10 @@
27323299 * performance. When short on memory we therefore prefer to
27333300 * decrease number of slots instead of their size. Clients that
27343301 * request larger slots than they need will get poor results:
3302
+ * Note that we always allow at least one slot, because our
3303
+ * accounting is soft and provides no guarantees either way.
27353304 */
2736
- ca->maxreqs = nfsd4_get_drc_mem(ca);
2737
- if (!ca->maxreqs)
2738
- return nfserr_jukebox;
3305
+ ca->maxreqs = nfsd4_get_drc_mem(ca, nn);
27393306
27403307 return nfs_ok;
27413308 }
....@@ -2913,7 +3480,7 @@
29133480 case NFS4_CDFC4_BACK_OR_BOTH:
29143481 *dir = NFS4_CDFC4_BOTH;
29153482 return nfs_ok;
2916
- };
3483
+ }
29173484 return nfserr_inval;
29183485 }
29193486
....@@ -2939,6 +3506,47 @@
29393506 return nfs_ok;
29403507 }
29413508
3509
+static struct nfsd4_conn *__nfsd4_find_conn(struct svc_xprt *xpt, struct nfsd4_session *s)
3510
+{
3511
+ struct nfsd4_conn *c;
3512
+
3513
+ list_for_each_entry(c, &s->se_conns, cn_persession) {
3514
+ if (c->cn_xprt == xpt) {
3515
+ return c;
3516
+ }
3517
+ }
3518
+ return NULL;
3519
+}
3520
+
3521
+static __be32 nfsd4_match_existing_connection(struct svc_rqst *rqst,
3522
+ struct nfsd4_session *session, u32 req, struct nfsd4_conn **conn)
3523
+{
3524
+ struct nfs4_client *clp = session->se_client;
3525
+ struct svc_xprt *xpt = rqst->rq_xprt;
3526
+ struct nfsd4_conn *c;
3527
+ __be32 status;
3528
+
3529
+ /* Following the last paragraph of RFC 5661 Section 18.34.3: */
3530
+ spin_lock(&clp->cl_lock);
3531
+ c = __nfsd4_find_conn(xpt, session);
3532
+ if (!c)
3533
+ status = nfserr_noent;
3534
+ else if (req == c->cn_flags)
3535
+ status = nfs_ok;
3536
+ else if (req == NFS4_CDFC4_FORE_OR_BOTH &&
3537
+ c->cn_flags != NFS4_CDFC4_BACK)
3538
+ status = nfs_ok;
3539
+ else if (req == NFS4_CDFC4_BACK_OR_BOTH &&
3540
+ c->cn_flags != NFS4_CDFC4_FORE)
3541
+ status = nfs_ok;
3542
+ else
3543
+ status = nfserr_inval;
3544
+ spin_unlock(&clp->cl_lock);
3545
+ if (status == nfs_ok && conn)
3546
+ *conn = c;
3547
+ return status;
3548
+}
3549
+
29423550 __be32 nfsd4_bind_conn_to_session(struct svc_rqst *rqstp,
29433551 struct nfsd4_compound_state *cstate,
29443552 union nfsd4_op_u *u)
....@@ -2959,6 +3567,17 @@
29593567 goto out_no_session;
29603568 status = nfserr_wrong_cred;
29613569 if (!nfsd4_mach_creds_match(session->se_client, rqstp))
3570
+ goto out;
3571
+ status = nfsd4_match_existing_connection(rqstp, session,
3572
+ bcts->dir, &conn);
3573
+ if (status == nfs_ok) {
3574
+ if (bcts->dir == NFS4_CDFC4_FORE_OR_BOTH ||
3575
+ bcts->dir == NFS4_CDFC4_BACK)
3576
+ conn->cn_flags |= NFS4_CDFC4_BACK;
3577
+ nfsd4_probe_callback(session->se_client);
3578
+ goto out;
3579
+ }
3580
+ if (status == nfserr_inval)
29623581 goto out;
29633582 status = nfsd4_map_bcts_dir(&bcts->dir);
29643583 if (status)
....@@ -3023,18 +3642,6 @@
30233642 spin_unlock(&nn->client_lock);
30243643 out:
30253644 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;
30383645 }
30393646
30403647 static __be32 nfsd4_sequence_check_conn(struct nfsd4_conn *new, struct nfsd4_session *ses)
....@@ -3331,6 +3938,7 @@
33313938
33323939 status = nfs_ok;
33333940 nfsd4_client_record_create(cstate->session->se_client);
3941
+ inc_reclaim_complete(cstate->session->se_client);
33343942 out:
33353943 return status;
33363944 }
....@@ -3359,23 +3967,18 @@
33593967 if (clp_used_exchangeid(conf))
33603968 goto out;
33613969 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);
3970
+ trace_nfsd_clid_inuse_err(conf);
33673971 goto out;
33683972 }
33693973 }
33703974 unconf = find_unconfirmed_client_by_name(&clname, nn);
33713975 if (unconf)
33723976 unhash_client_locked(unconf);
3977
+ /* We need to handle only case 1: probable callback update */
33733978 if (conf && same_verf(&conf->cl_verifier, &clverifier)) {
3374
- /* case 1: probable callback update */
33753979 copy_clid(new, conf);
33763980 gen_confirm(new, nn);
3377
- } else /* case 4 (new client) or cases 2, 3 (client reboot): */
3378
- gen_clid(new, nn);
3981
+ }
33793982 new->cl_minorversion = 0;
33803983 gen_callback(new, setclid, rqstp);
33813984 add_to_unconfirmed(new);
....@@ -3558,7 +4161,6 @@
35584161 out_free_client_slab:
35594162 kmem_cache_destroy(client_slab);
35604163 out:
3561
- dprintk("nfsd4: out of memory while initializing nfsv4\n");
35624164 return -ENOMEM;
35634165 }
35644166
....@@ -3598,12 +4200,11 @@
35984200 if (!sop)
35994201 return NULL;
36004202
3601
- sop->so_owner.data = kmemdup(owner->data, owner->len, GFP_KERNEL);
4203
+ xdr_netobj_dup(&sop->so_owner, owner, GFP_KERNEL);
36024204 if (!sop->so_owner.data) {
36034205 kmem_cache_free(slab, sop);
36044206 return NULL;
36054207 }
3606
- sop->so_owner.len = owner->len;
36074208
36084209 INIT_LIST_HEAD(&sop->so_stateids);
36094210 sop->so_client = clp;
....@@ -3825,7 +4426,7 @@
38254426 last = oo->oo_last_closed_stid;
38264427 oo->oo_last_closed_stid = s;
38274428 list_move_tail(&oo->oo_close_lru, &nn->close_lru);
3828
- oo->oo_time = get_seconds();
4429
+ oo->oo_time = ktime_get_boottime_seconds();
38294430 spin_unlock(&nn->client_lock);
38304431 if (last)
38314432 nfs4_put_stid(&last->st_stid);
....@@ -3837,7 +4438,8 @@
38374438 {
38384439 struct nfs4_file *fp;
38394440
3840
- hlist_for_each_entry_rcu(fp, &file_hashtbl[hashval], fi_hash) {
4441
+ hlist_for_each_entry_rcu(fp, &file_hashtbl[hashval], fi_hash,
4442
+ lockdep_is_held(&state_lock)) {
38414443 if (fh_match(&fp->fi_fhandle, fh)) {
38424444 if (refcount_inc_not_zero(&fp->fi_ref))
38434445 return fp;
....@@ -3920,7 +4522,7 @@
39204522 */
39214523 spin_lock(&state_lock);
39224524 if (delegation_hashed(dp) && dp->dl_time == 0) {
3923
- dp->dl_time = get_seconds();
4525
+ dp->dl_time = ktime_get_boottime_seconds();
39244526 list_add_tail(&dp->dl_recall_lru, &nn->del_recall_lru);
39254527 }
39264528 spin_unlock(&state_lock);
....@@ -3931,12 +4533,16 @@
39314533 {
39324534 struct nfs4_delegation *dp = cb_to_delegation(cb);
39334535
3934
- if (dp->dl_stid.sc_type == NFS4_CLOSED_DELEG_STID)
4536
+ if (dp->dl_stid.sc_type == NFS4_CLOSED_DELEG_STID ||
4537
+ dp->dl_stid.sc_type == NFS4_REVOKED_DELEG_STID)
39354538 return 1;
39364539
39374540 switch (task->tk_status) {
39384541 case 0:
39394542 return 1;
4543
+ case -NFS4ERR_DELAY:
4544
+ rpc_delay(task, 2 * HZ);
4545
+ return 0;
39404546 case -EBADHANDLE:
39414547 case -NFS4ERR_BAD_STATEID:
39424548 /*
....@@ -3947,9 +4553,9 @@
39474553 rpc_delay(task, 2 * HZ);
39484554 return 0;
39494555 }
3950
- /*FALLTHRU*/
4556
+ fallthrough;
39514557 default:
3952
- return -1;
4558
+ return 1;
39534559 }
39544560 }
39554561
....@@ -3987,6 +4593,8 @@
39874593 struct nfs4_delegation *dp = (struct nfs4_delegation *)fl->fl_owner;
39884594 struct nfs4_file *fp = dp->dl_stid.sc_file;
39894595
4596
+ trace_nfsd_deleg_break(&dp->dl_stid.sc_stateid);
4597
+
39904598 /*
39914599 * We don't want the locks code to timeout the lease for us;
39924600 * we'll remove it ourself if a delegation isn't returned
....@@ -4001,6 +4609,30 @@
40014609 return ret;
40024610 }
40034611
4612
+/**
4613
+ * nfsd_breaker_owns_lease - Check if lease conflict was resolved
4614
+ * @fl: Lock state to check
4615
+ *
4616
+ * Return values:
4617
+ * %true: Lease conflict was resolved
4618
+ * %false: Lease conflict was not resolved.
4619
+ */
4620
+static bool nfsd_breaker_owns_lease(struct file_lock *fl)
4621
+{
4622
+ struct nfs4_delegation *dl = fl->fl_owner;
4623
+ struct svc_rqst *rqst;
4624
+ struct nfs4_client *clp;
4625
+
4626
+ if (!i_am_nfsd())
4627
+ return false;
4628
+ rqst = kthread_data(current);
4629
+ /* Note rq_prog == NFS_ACL_PROGRAM is also possible: */
4630
+ if (rqst->rq_prog != NFS_PROGRAM || rqst->rq_vers < 4)
4631
+ return false;
4632
+ clp = *(rqst->rq_lease_breaker);
4633
+ return dl->dl_stid.sc_client == clp;
4634
+}
4635
+
40044636 static int
40054637 nfsd_change_deleg_cb(struct file_lock *onlist, int arg,
40064638 struct list_head *dispose)
....@@ -4012,6 +4644,7 @@
40124644 }
40134645
40144646 static const struct lock_manager_operations nfsd_lease_mng_ops = {
4647
+ .lm_breaker_owns_lease = nfsd_breaker_owns_lease,
40154648 .lm_break = nfsd_break_deleg_cb,
40164649 .lm_change = nfsd_change_deleg_cb,
40174650 };
....@@ -4029,7 +4662,8 @@
40294662
40304663 static __be32 lookup_clientid(clientid_t *clid,
40314664 struct nfsd4_compound_state *cstate,
4032
- struct nfsd_net *nn)
4665
+ struct nfsd_net *nn,
4666
+ bool sessions)
40334667 {
40344668 struct nfs4_client *found;
40354669
....@@ -4050,12 +4684,12 @@
40504684 */
40514685 WARN_ON_ONCE(cstate->session);
40524686 spin_lock(&nn->client_lock);
4053
- found = find_confirmed_client(clid, false, nn);
4687
+ found = find_confirmed_client(clid, sessions, nn);
40544688 if (!found) {
40554689 spin_unlock(&nn->client_lock);
40564690 return nfserr_expired;
40574691 }
4058
- atomic_inc(&found->cl_refcount);
4692
+ atomic_inc(&found->cl_rpc_users);
40594693 spin_unlock(&nn->client_lock);
40604694
40614695 /* Cache the nfs4_client in cstate! */
....@@ -4083,7 +4717,7 @@
40834717 if (open->op_file == NULL)
40844718 return nfserr_jukebox;
40854719
4086
- status = lookup_clientid(clientid, cstate, nn);
4720
+ status = lookup_clientid(clientid, cstate, nn, false);
40874721 if (status)
40884722 return status;
40894723 clp = cstate->clp;
....@@ -4211,14 +4845,14 @@
42114845 return 0;
42124846 if (!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
42134847 return nfserr_inval;
4214
- return nfsd_setattr(rqstp, fh, &iattr, 0, (time_t)0);
4848
+ return nfsd_setattr(rqstp, fh, &iattr, 0, (time64_t)0);
42154849 }
42164850
42174851 static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
42184852 struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp,
42194853 struct nfsd4_open *open)
42204854 {
4221
- struct file *filp = NULL;
4855
+ struct nfsd_file *nf = NULL;
42224856 __be32 status;
42234857 int oflag = nfs4_access_to_omode(open->op_share_access);
42244858 int access = nfs4_access_to_access(open->op_share_access);
....@@ -4254,18 +4888,23 @@
42544888
42554889 if (!fp->fi_fds[oflag]) {
42564890 spin_unlock(&fp->fi_lock);
4257
- status = nfsd_open(rqstp, cur_fh, S_IFREG, access, &filp);
4891
+ status = nfsd_file_acquire(rqstp, cur_fh, access, &nf);
42584892 if (status)
42594893 goto out_put_access;
42604894 spin_lock(&fp->fi_lock);
42614895 if (!fp->fi_fds[oflag]) {
4262
- fp->fi_fds[oflag] = filp;
4263
- filp = NULL;
4896
+ fp->fi_fds[oflag] = nf;
4897
+ nf = NULL;
42644898 }
42654899 }
42664900 spin_unlock(&fp->fi_lock);
4267
- if (filp)
4268
- fput(filp);
4901
+ if (nf)
4902
+ nfsd_file_put(nf);
4903
+
4904
+ status = nfserrno(nfsd_open_break_lease(cur_fh->fh_dentry->d_inode,
4905
+ access));
4906
+ if (status)
4907
+ goto out_put_access;
42694908
42704909 status = nfsd4_truncate(rqstp, cur_fh, open);
42714910 if (status)
....@@ -4334,7 +4973,7 @@
43344973 fl->fl_end = OFFSET_MAX;
43354974 fl->fl_owner = (fl_owner_t)dp;
43364975 fl->fl_pid = current->tgid;
4337
- fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file;
4976
+ fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file;
43384977 return fl;
43394978 }
43404979
....@@ -4344,7 +4983,7 @@
43444983 {
43454984 int status = 0;
43464985 struct nfs4_delegation *dp;
4347
- struct file *filp;
4986
+ struct nfsd_file *nf;
43484987 struct file_lock *fl;
43494988
43504989 /*
....@@ -4355,8 +4994,8 @@
43554994 if (fp->fi_had_conflict)
43564995 return ERR_PTR(-EAGAIN);
43574996
4358
- filp = find_readable_file(fp);
4359
- if (!filp) {
4997
+ nf = find_readable_file(fp);
4998
+ if (!nf) {
43604999 /* We should always have a readable file here */
43615000 WARN_ON_ONCE(1);
43625001 return ERR_PTR(-EBADF);
....@@ -4366,17 +5005,17 @@
43665005 if (nfs4_delegation_exists(clp, fp))
43675006 status = -EAGAIN;
43685007 else if (!fp->fi_deleg_file) {
4369
- fp->fi_deleg_file = filp;
5008
+ fp->fi_deleg_file = nf;
43705009 /* increment early to prevent fi_deleg_file from being
43715010 * cleared */
43725011 fp->fi_delegees = 1;
4373
- filp = NULL;
5012
+ nf = NULL;
43745013 } else
43755014 fp->fi_delegees++;
43765015 spin_unlock(&fp->fi_lock);
43775016 spin_unlock(&state_lock);
4378
- if (filp)
4379
- fput(filp);
5017
+ if (nf)
5018
+ nfsd_file_put(nf);
43805019 if (status)
43815020 return ERR_PTR(status);
43825021
....@@ -4389,7 +5028,7 @@
43895028 if (!fl)
43905029 goto out_clnt_odstate;
43915030
4392
- status = vfs_setlease(fp->fi_deleg_file, fl->fl_type, &fl, NULL);
5031
+ status = vfs_setlease(fp->fi_deleg_file->nf_file, fl->fl_type, &fl, NULL);
43935032 if (fl)
43945033 locks_free_lock(fl);
43955034 if (status)
....@@ -4409,7 +5048,7 @@
44095048
44105049 return dp;
44115050 out_unlock:
4412
- vfs_setlease(fp->fi_deleg_file, F_UNLCK, NULL, (void **)&dp);
5051
+ vfs_setlease(fp->fi_deleg_file->nf_file, F_UNLCK, NULL, (void **)&dp);
44135052 out_clnt_odstate:
44145053 put_clnt_odstate(dp->dl_clnt_odstate);
44155054 nfs4_put_stid(&dp->dl_stid);
....@@ -4496,8 +5135,7 @@
44965135
44975136 memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid));
44985137
4499
- dprintk("NFSD: delegation stateid=" STATEID_FMT "\n",
4500
- STATEID_VAL(&dp->dl_stid.sc_stateid));
5138
+ trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid);
45015139 open->op_delegate_type = NFS4_OPEN_DELEGATE_READ;
45025140 nfs4_put_stid(&dp->dl_stid);
45035141 return;
....@@ -4614,9 +5252,7 @@
46145252 nfs4_open_delegation(current_fh, open, stp);
46155253 nodeleg:
46165254 status = nfs_ok;
4617
-
4618
- dprintk("%s: stateid=" STATEID_FMT "\n", __func__,
4619
- STATEID_VAL(&stp->st_stid.sc_stateid));
5255
+ trace_nfsd_open(&stp->st_stid.sc_stateid);
46205256 out:
46215257 /* 4.1 client trying to upgrade/downgrade delegation? */
46225258 if (open->op_delegate_type == NFS4_OPEN_DELEGATE_NONE && dp &&
....@@ -4670,9 +5306,8 @@
46705306 __be32 status;
46715307 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
46725308
4673
- dprintk("process_renew(%08x/%08x): starting\n",
4674
- clid->cl_boot, clid->cl_id);
4675
- status = lookup_clientid(clid, cstate, nn);
5309
+ trace_nfsd_clid_renew(clid);
5310
+ status = lookup_clientid(clid, cstate, nn, false);
46765311 if (status)
46775312 goto out;
46785313 clp = cstate->clp;
....@@ -4692,7 +5327,7 @@
46925327 if (nn->grace_ended)
46935328 return;
46945329
4695
- dprintk("NFSD: end of grace period\n");
5330
+ trace_nfsd_grace_complete(nn);
46965331 nn->grace_ended = true;
46975332 /*
46985333 * If the server goes down again right now, an NFSv4
....@@ -4724,10 +5359,13 @@
47245359 */
47255360 static bool clients_still_reclaiming(struct nfsd_net *nn)
47265361 {
4727
- unsigned long now = get_seconds();
4728
- unsigned long double_grace_period_end = nn->boot_time +
4729
- 2 * nn->nfsd4_lease;
5362
+ time64_t double_grace_period_end = nn->boot_time +
5363
+ 2 * nn->nfsd4_lease;
47305364
5365
+ if (nn->track_reclaim_completes &&
5366
+ atomic_read(&nn->nr_reclaim_complete) ==
5367
+ nn->reclaim_str_hashtbl_size)
5368
+ return false;
47315369 if (!nn->somebody_reclaimed)
47325370 return false;
47335371 nn->somebody_reclaimed = false;
....@@ -4735,12 +5373,12 @@
47355373 * If we've given them *two* lease times to reclaim, and they're
47365374 * still not done, give up:
47375375 */
4738
- if (time_after(now, double_grace_period_end))
5376
+ if (ktime_get_boottime_seconds() > double_grace_period_end)
47395377 return false;
47405378 return true;
47415379 }
47425380
4743
-static time_t
5381
+static time64_t
47445382 nfs4_laundromat(struct nfsd_net *nn)
47455383 {
47465384 struct nfs4_client *clp;
....@@ -4749,10 +5387,11 @@
47495387 struct nfs4_ol_stateid *stp;
47505388 struct nfsd4_blocked_lock *nbl;
47515389 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");
5390
+ time64_t cutoff = ktime_get_boottime_seconds() - nn->nfsd4_lease;
5391
+ time64_t t, new_timeo = nn->nfsd4_lease;
5392
+ struct nfs4_cpntf_state *cps;
5393
+ copy_stateid_t *cps_t;
5394
+ int i;
47565395
47575396 if (clients_still_reclaiming(nn)) {
47585397 new_timeo = 0;
....@@ -4760,17 +5399,26 @@
47605399 }
47615400 nfsd4_end_grace(nn);
47625401 INIT_LIST_HEAD(&reaplist);
5402
+
5403
+ spin_lock(&nn->s2s_cp_lock);
5404
+ idr_for_each_entry(&nn->s2s_cp_stateids, cps_t, i) {
5405
+ cps = container_of(cps_t, struct nfs4_cpntf_state, cp_stateid);
5406
+ if (cps->cp_stateid.sc_type == NFS4_COPYNOTIFY_STID &&
5407
+ cps->cpntf_time < cutoff)
5408
+ _free_cpntf_state_locked(nn, cps);
5409
+ }
5410
+ spin_unlock(&nn->s2s_cp_lock);
5411
+
47635412 spin_lock(&nn->client_lock);
47645413 list_for_each_safe(pos, next, &nn->client_lru) {
47655414 clp = list_entry(pos, struct nfs4_client, cl_lru);
4766
- if (time_after((unsigned long)clp->cl_time, (unsigned long)cutoff)) {
5415
+ if (clp->cl_time > cutoff) {
47675416 t = clp->cl_time - cutoff;
47685417 new_timeo = min(new_timeo, t);
47695418 break;
47705419 }
47715420 if (mark_client_expired_locked(clp)) {
4772
- dprintk("NFSD: client in use (clientid %08x)\n",
4773
- clp->cl_clientid.cl_id);
5421
+ trace_nfsd_clid_expired(&clp->cl_clientid);
47745422 continue;
47755423 }
47765424 list_add(&clp->cl_lru, &reaplist);
....@@ -4778,15 +5426,14 @@
47785426 spin_unlock(&nn->client_lock);
47795427 list_for_each_safe(pos, next, &reaplist) {
47805428 clp = list_entry(pos, struct nfs4_client, cl_lru);
4781
- dprintk("NFSD: purging unused client (clientid %08x)\n",
4782
- clp->cl_clientid.cl_id);
5429
+ trace_nfsd_clid_purged(&clp->cl_clientid);
47835430 list_del_init(&clp->cl_lru);
47845431 expire_client(clp);
47855432 }
47865433 spin_lock(&state_lock);
47875434 list_for_each_safe(pos, next, &nn->del_recall_lru) {
47885435 dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);
4789
- if (time_after((unsigned long)dp->dl_time, (unsigned long)cutoff)) {
5436
+ if (dp->dl_time > cutoff) {
47905437 t = dp->dl_time - cutoff;
47915438 new_timeo = min(new_timeo, t);
47925439 break;
....@@ -4806,8 +5453,7 @@
48065453 while (!list_empty(&nn->close_lru)) {
48075454 oo = list_first_entry(&nn->close_lru, struct nfs4_openowner,
48085455 oo_close_lru);
4809
- if (time_after((unsigned long)oo->oo_time,
4810
- (unsigned long)cutoff)) {
5456
+ if (oo->oo_time > cutoff) {
48115457 t = oo->oo_time - cutoff;
48125458 new_timeo = min(new_timeo, t);
48135459 break;
....@@ -4837,8 +5483,7 @@
48375483 while (!list_empty(&nn->blocked_locks_lru)) {
48385484 nbl = list_first_entry(&nn->blocked_locks_lru,
48395485 struct nfsd4_blocked_lock, nbl_lru);
4840
- if (time_after((unsigned long)nbl->nbl_time,
4841
- (unsigned long)cutoff)) {
5486
+ if (nbl->nbl_time > cutoff) {
48425487 t = nbl->nbl_time - cutoff;
48435488 new_timeo = min(new_timeo, t);
48445489 break;
....@@ -4852,11 +5497,10 @@
48525497 nbl = list_first_entry(&reaplist,
48535498 struct nfsd4_blocked_lock, nbl_lru);
48545499 list_del_init(&nbl->nbl_lru);
4855
- posix_unblock_lock(&nbl->nbl_lock);
48565500 free_blocked_lock(nbl);
48575501 }
48585502 out:
4859
- new_timeo = max_t(time_t, new_timeo, NFSD_LAUNDROMAT_MINTIMEOUT);
5503
+ new_timeo = max_t(time64_t, new_timeo, NFSD_LAUNDROMAT_MINTIMEOUT);
48605504 return new_timeo;
48615505 }
48625506
....@@ -4866,13 +5510,12 @@
48665510 static void
48675511 laundromat_main(struct work_struct *laundry)
48685512 {
4869
- time_t t;
5513
+ time64_t t;
48705514 struct delayed_work *dwork = to_delayed_work(laundry);
48715515 struct nfsd_net *nn = container_of(dwork, struct nfsd_net,
48725516 laundromat_work);
48735517
48745518 t = nfs4_laundromat(nn);
4875
- dprintk("NFSD: laundromat_main - sleeping for %ld seconds\n", t);
48765519 queue_delayed_work(laundry_wq, &nn->laundromat_work, t*HZ);
48775520 }
48785521
....@@ -4998,15 +5641,8 @@
49985641 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid) ||
49995642 CLOSE_STATEID(stateid))
50005643 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);
5644
+ if (!same_clid(&stateid->si_opaque.so_clid, &cl->cl_clientid))
50085645 return status;
5009
- }
50105646 spin_lock(&cl->cl_lock);
50115647 s = find_stateid_locked(cl, stateid);
50125648 if (!s)
....@@ -5027,7 +5663,7 @@
50275663 break;
50285664 default:
50295665 printk("unknown stateid type %x\n", s->sc_type);
5030
- /* Fallthrough */
5666
+ fallthrough;
50315667 case NFS4_CLOSED_STID:
50325668 case NFS4_CLOSED_DELEG_STID:
50335669 status = nfserr_bad_stateid;
....@@ -5057,7 +5693,8 @@
50575693 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid) ||
50585694 CLOSE_STATEID(stateid))
50595695 return nfserr_bad_stateid;
5060
- status = lookup_clientid(&stateid->si_opaque.so_clid, cstate, nn);
5696
+ status = lookup_clientid(&stateid->si_opaque.so_clid, cstate, nn,
5697
+ false);
50615698 if (status == nfserr_stale_clientid) {
50625699 if (cstate->session)
50635700 return nfserr_bad_stateid;
....@@ -5077,7 +5714,7 @@
50775714 return nfs_ok;
50785715 }
50795716
5080
-static struct file *
5717
+static struct nfsd_file *
50815718 nfs4_find_file(struct nfs4_stid *s, int flags)
50825719 {
50835720 if (!s)
....@@ -5087,21 +5724,20 @@
50875724 case NFS4_DELEG_STID:
50885725 if (WARN_ON_ONCE(!s->sc_file->fi_deleg_file))
50895726 return NULL;
5090
- return get_file(s->sc_file->fi_deleg_file);
5727
+ return nfsd_file_get(s->sc_file->fi_deleg_file);
50915728 case NFS4_OPEN_STID:
50925729 case NFS4_LOCK_STID:
50935730 if (flags & RD_STATE)
50945731 return find_readable_file(s->sc_file);
50955732 else
50965733 return find_writeable_file(s->sc_file);
5097
- break;
50985734 }
50995735
51005736 return NULL;
51015737 }
51025738
51035739 static __be32
5104
-nfs4_check_olstateid(struct svc_fh *fhp, struct nfs4_ol_stateid *ols, int flags)
5740
+nfs4_check_olstateid(struct nfs4_ol_stateid *ols, int flags)
51055741 {
51065742 __be32 status;
51075743
....@@ -5113,32 +5749,107 @@
51135749
51145750 static __be32
51155751 nfs4_check_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfs4_stid *s,
5116
- struct file **filpp, bool *tmp_file, int flags)
5752
+ struct nfsd_file **nfp, int flags)
51175753 {
51185754 int acc = (flags & RD_STATE) ? NFSD_MAY_READ : NFSD_MAY_WRITE;
5119
- struct file *file;
5755
+ struct nfsd_file *nf;
51205756 __be32 status;
51215757
5122
- file = nfs4_find_file(s, flags);
5123
- if (file) {
5758
+ nf = nfs4_find_file(s, flags);
5759
+ if (nf) {
51245760 status = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry,
51255761 acc | NFSD_MAY_OWNER_OVERRIDE);
51265762 if (status) {
5127
- fput(file);
5128
- return status;
5763
+ nfsd_file_put(nf);
5764
+ goto out;
51295765 }
5130
-
5131
- *filpp = file;
51325766 } else {
5133
- status = nfsd_open(rqstp, fhp, S_IFREG, acc, filpp);
5767
+ status = nfsd_file_acquire(rqstp, fhp, acc, &nf);
51345768 if (status)
51355769 return status;
5136
-
5137
- if (tmp_file)
5138
- *tmp_file = true;
51395770 }
5771
+ *nfp = nf;
5772
+out:
5773
+ return status;
5774
+}
5775
+static void
5776
+_free_cpntf_state_locked(struct nfsd_net *nn, struct nfs4_cpntf_state *cps)
5777
+{
5778
+ WARN_ON_ONCE(cps->cp_stateid.sc_type != NFS4_COPYNOTIFY_STID);
5779
+ if (!refcount_dec_and_test(&cps->cp_stateid.sc_count))
5780
+ return;
5781
+ list_del(&cps->cp_list);
5782
+ idr_remove(&nn->s2s_cp_stateids,
5783
+ cps->cp_stateid.stid.si_opaque.so_id);
5784
+ kfree(cps);
5785
+}
5786
+/*
5787
+ * A READ from an inter server to server COPY will have a
5788
+ * copy stateid. Look up the copy notify stateid from the
5789
+ * idr structure and take a reference on it.
5790
+ */
5791
+__be32 manage_cpntf_state(struct nfsd_net *nn, stateid_t *st,
5792
+ struct nfs4_client *clp,
5793
+ struct nfs4_cpntf_state **cps)
5794
+{
5795
+ copy_stateid_t *cps_t;
5796
+ struct nfs4_cpntf_state *state = NULL;
51405797
5798
+ if (st->si_opaque.so_clid.cl_id != nn->s2s_cp_cl_id)
5799
+ return nfserr_bad_stateid;
5800
+ spin_lock(&nn->s2s_cp_lock);
5801
+ cps_t = idr_find(&nn->s2s_cp_stateids, st->si_opaque.so_id);
5802
+ if (cps_t) {
5803
+ state = container_of(cps_t, struct nfs4_cpntf_state,
5804
+ cp_stateid);
5805
+ if (state->cp_stateid.sc_type != NFS4_COPYNOTIFY_STID) {
5806
+ state = NULL;
5807
+ goto unlock;
5808
+ }
5809
+ if (!clp)
5810
+ refcount_inc(&state->cp_stateid.sc_count);
5811
+ else
5812
+ _free_cpntf_state_locked(nn, state);
5813
+ }
5814
+unlock:
5815
+ spin_unlock(&nn->s2s_cp_lock);
5816
+ if (!state)
5817
+ return nfserr_bad_stateid;
5818
+ if (!clp && state)
5819
+ *cps = state;
51415820 return 0;
5821
+}
5822
+
5823
+static __be32 find_cpntf_state(struct nfsd_net *nn, stateid_t *st,
5824
+ struct nfs4_stid **stid)
5825
+{
5826
+ __be32 status;
5827
+ struct nfs4_cpntf_state *cps = NULL;
5828
+ struct nfsd4_compound_state cstate;
5829
+
5830
+ status = manage_cpntf_state(nn, st, NULL, &cps);
5831
+ if (status)
5832
+ return status;
5833
+
5834
+ cps->cpntf_time = ktime_get_boottime_seconds();
5835
+ memset(&cstate, 0, sizeof(cstate));
5836
+ status = lookup_clientid(&cps->cp_p_clid, &cstate, nn, true);
5837
+ if (status)
5838
+ goto out;
5839
+ status = nfsd4_lookup_stateid(&cstate, &cps->cp_p_stateid,
5840
+ NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID,
5841
+ stid, nn);
5842
+ put_client_renew(cstate.clp);
5843
+out:
5844
+ nfs4_put_cpntf_state(nn, cps);
5845
+ return status;
5846
+}
5847
+
5848
+void nfs4_put_cpntf_state(struct nfsd_net *nn, struct nfs4_cpntf_state *cps)
5849
+{
5850
+ spin_lock(&nn->s2s_cp_lock);
5851
+ _free_cpntf_state_locked(nn, cps);
5852
+ spin_unlock(&nn->s2s_cp_lock);
51425853 }
51435854
51445855 /*
....@@ -5147,7 +5858,8 @@
51475858 __be32
51485859 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
51495860 struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
5150
- stateid_t *stateid, int flags, struct file **filpp, bool *tmp_file)
5861
+ stateid_t *stateid, int flags, struct nfsd_file **nfp,
5862
+ struct nfs4_stid **cstid)
51515863 {
51525864 struct inode *ino = d_inode(fhp->fh_dentry);
51535865 struct net *net = SVC_NET(rqstp);
....@@ -5155,10 +5867,8 @@
51555867 struct nfs4_stid *s = NULL;
51565868 __be32 status;
51575869
5158
- if (filpp)
5159
- *filpp = NULL;
5160
- if (tmp_file)
5161
- *tmp_file = false;
5870
+ if (nfp)
5871
+ *nfp = NULL;
51625872
51635873 if (grace_disallows_io(net, ino))
51645874 return nfserr_grace;
....@@ -5171,6 +5881,8 @@
51715881 status = nfsd4_lookup_stateid(cstate, stateid,
51725882 NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID,
51735883 &s, nn);
5884
+ if (status == nfserr_bad_stateid)
5885
+ status = find_cpntf_state(nn, stateid, &s);
51745886 if (status)
51755887 return status;
51765888 status = nfsd4_stid_check_stateid_generation(stateid, s,
....@@ -5184,7 +5896,7 @@
51845896 break;
51855897 case NFS4_OPEN_STID:
51865898 case NFS4_LOCK_STID:
5187
- status = nfs4_check_olstateid(fhp, openlockstateid(s), flags);
5899
+ status = nfs4_check_olstateid(openlockstateid(s), flags);
51885900 break;
51895901 default:
51905902 status = nfserr_bad_stateid;
....@@ -5195,11 +5907,15 @@
51955907 status = nfs4_check_fh(fhp, s);
51965908
51975909 done:
5198
- if (!status && filpp)
5199
- status = nfs4_check_file(rqstp, fhp, s, filpp, tmp_file, flags);
5910
+ if (status == nfs_ok && nfp)
5911
+ status = nfs4_check_file(rqstp, fhp, s, nfp, flags);
52005912 out:
5201
- if (s)
5202
- nfs4_put_stid(s);
5913
+ if (s) {
5914
+ if (!status && cstid)
5915
+ *cstid = s;
5916
+ else
5917
+ nfs4_put_stid(s);
5918
+ }
52035919 return status;
52045920 }
52055921
....@@ -5339,8 +6055,7 @@
53396055 struct nfs4_stid *s;
53406056 struct nfs4_ol_stateid *stp = NULL;
53416057
5342
- dprintk("NFSD: %s: seqid=%d stateid = " STATEID_FMT "\n", __func__,
5343
- seqid, STATEID_VAL(stateid));
6058
+ trace_nfsd_preprocess(seqid, stateid);
53446059
53456060 *stpp = NULL;
53466061 status = nfsd4_lookup_stateid(cstate, stateid, typemask, &s, nn);
....@@ -5409,9 +6124,7 @@
54096124 oo->oo_flags |= NFS4_OO_CONFIRMED;
54106125 nfs4_inc_and_copy_stateid(&oc->oc_resp_stateid, &stp->st_stid);
54116126 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
-
6127
+ trace_nfsd_open_confirm(oc->oc_seqid, &stp->st_stid.sc_stateid);
54156128 nfsd4_client_record_create(oo->oo_owner.so_client);
54166129 status = nfs_ok;
54176130 put_stateid:
....@@ -5496,6 +6209,7 @@
54966209 struct nfs4_client *clp = s->st_stid.sc_client;
54976210 bool unhashed;
54986211 LIST_HEAD(reaplist);
6212
+ struct nfs4_ol_stateid *stp;
54996213
55006214 spin_lock(&clp->cl_lock);
55016215 unhashed = unhash_open_stateid(s, &reaplist);
....@@ -5504,6 +6218,8 @@
55046218 if (unhashed)
55056219 put_ol_stateid_locked(s, &reaplist);
55066220 spin_unlock(&clp->cl_lock);
6221
+ list_for_each_entry(stp, &reaplist, st_locks)
6222
+ nfs4_free_cpntf_statelist(clp->net, &stp->st_stid);
55076223 free_ol_stateid_reaplist(&reaplist);
55086224 } else {
55096225 spin_unlock(&clp->cl_lock);
....@@ -5685,12 +6401,11 @@
56856401
56866402 if (fl->fl_lmops == &nfsd_posix_mng_ops) {
56876403 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);
6404
+ xdr_netobj_dup(&deny->ld_owner, &lo->lo_owner.so_owner,
6405
+ GFP_KERNEL);
56906406 if (!deny->ld_owner.data)
56916407 /* We just don't care that much */
56926408 goto nevermind;
5693
- deny->ld_owner.len = lo->lo_owner.so_owner.len;
56946409 deny->ld_clientid = lo->lo_owner.so_client->cl_clientid;
56956410 } else {
56966411 nevermind:
....@@ -5961,7 +6676,7 @@
59616676 struct nfs4_ol_stateid *lock_stp = NULL;
59626677 struct nfs4_ol_stateid *open_stp = NULL;
59636678 struct nfs4_file *fp;
5964
- struct file *filp = NULL;
6679
+ struct nfsd_file *nf = NULL;
59656680 struct nfsd4_blocked_lock *nbl = NULL;
59666681 struct file_lock *file_lock = NULL;
59676682 struct file_lock *conflock = NULL;
....@@ -6040,11 +6755,11 @@
60406755 case NFS4_READW_LT:
60416756 if (nfsd4_has_session(cstate))
60426757 fl_flags |= FL_SLEEP;
6043
- /* Fallthrough */
6758
+ fallthrough;
60446759 case NFS4_READ_LT:
60456760 spin_lock(&fp->fi_lock);
6046
- filp = find_readable_file_locked(fp);
6047
- if (filp)
6761
+ nf = find_readable_file_locked(fp);
6762
+ if (nf)
60486763 get_lock_access(lock_stp, NFS4_SHARE_ACCESS_READ);
60496764 spin_unlock(&fp->fi_lock);
60506765 fl_type = F_RDLCK;
....@@ -6052,11 +6767,11 @@
60526767 case NFS4_WRITEW_LT:
60536768 if (nfsd4_has_session(cstate))
60546769 fl_flags |= FL_SLEEP;
6055
- /* Fallthrough */
6770
+ fallthrough;
60566771 case NFS4_WRITE_LT:
60576772 spin_lock(&fp->fi_lock);
6058
- filp = find_writeable_file_locked(fp);
6059
- if (filp)
6773
+ nf = find_writeable_file_locked(fp);
6774
+ if (nf)
60606775 get_lock_access(lock_stp, NFS4_SHARE_ACCESS_WRITE);
60616776 spin_unlock(&fp->fi_lock);
60626777 fl_type = F_WRLCK;
....@@ -6066,7 +6781,7 @@
60666781 goto out;
60676782 }
60686783
6069
- if (!filp) {
6784
+ if (!nf) {
60706785 status = nfserr_openmode;
60716786 goto out;
60726787 }
....@@ -6082,7 +6797,7 @@
60826797 file_lock->fl_type = fl_type;
60836798 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(&lock_sop->lo_owner));
60846799 file_lock->fl_pid = current->tgid;
6085
- file_lock->fl_file = filp;
6800
+ file_lock->fl_file = nf->nf_file;
60866801 file_lock->fl_flags = fl_flags;
60876802 file_lock->fl_lmops = &nfsd_posix_mng_ops;
60886803 file_lock->fl_start = lock->lk_offset;
....@@ -6097,14 +6812,14 @@
60976812 }
60986813
60996814 if (fl_flags & FL_SLEEP) {
6100
- nbl->nbl_time = get_seconds();
6815
+ nbl->nbl_time = ktime_get_boottime_seconds();
61016816 spin_lock(&nn->blocked_locks_lock);
61026817 list_add_tail(&nbl->nbl_list, &lock_sop->lo_blocked);
61036818 list_add_tail(&nbl->nbl_lru, &nn->blocked_locks_lru);
61046819 spin_unlock(&nn->blocked_locks_lock);
61056820 }
61066821
6107
- err = vfs_lock_file(filp, F_SETLK, file_lock, conflock);
6822
+ err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, conflock);
61086823 switch (err) {
61096824 case 0: /* success! */
61106825 nfs4_inc_and_copy_stateid(&lock->lk_resp_stateid, &lock_stp->st_stid);
....@@ -6114,7 +6829,7 @@
61146829 break;
61156830 case FILE_LOCK_DEFERRED:
61166831 nbl = NULL;
6117
- /* Fallthrough */
6832
+ fallthrough;
61186833 case -EAGAIN: /* conflock holds conflicting lock */
61196834 status = nfserr_denied;
61206835 dprintk("NFSD: nfsd4_lock: conflicting lock found!\n");
....@@ -6139,8 +6854,8 @@
61396854 }
61406855 free_blocked_lock(nbl);
61416856 }
6142
- if (filp)
6143
- fput(filp);
6857
+ if (nf)
6858
+ nfsd_file_put(nf);
61446859 if (lock_stp) {
61456860 /* Bump seqid manually if the 4.0 replay owner is openowner */
61466861 if (cstate->replay_owner &&
....@@ -6170,17 +6885,27 @@
61706885 /*
61716886 * The NFSv4 spec allows a client to do a LOCKT without holding an OPEN,
61726887 * 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.)
6888
+ * vfs_test_lock.
61756889 */
61766890 static __be32 nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file_lock *lock)
61776891 {
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
- }
6892
+ struct nfsd_file *nf;
6893
+ __be32 err;
6894
+
6895
+ err = nfsd_file_acquire(rqstp, fhp, NFSD_MAY_READ, &nf);
6896
+ if (err)
6897
+ return err;
6898
+ fh_lock(fhp); /* to block new leases till after test_lock: */
6899
+ err = nfserrno(nfsd_open_break_lease(fhp->fh_dentry->d_inode,
6900
+ NFSD_MAY_READ));
6901
+ if (err)
6902
+ goto out;
6903
+ lock->fl_file = nf->nf_file;
6904
+ err = nfserrno(vfs_test_lock(nf->nf_file, lock));
6905
+ lock->fl_file = NULL;
6906
+out:
6907
+ fh_unlock(fhp);
6908
+ nfsd_file_put(nf);
61846909 return err;
61856910 }
61866911
....@@ -6204,7 +6929,8 @@
62046929 return nfserr_inval;
62056930
62066931 if (!nfsd4_has_session(cstate)) {
6207
- status = lookup_clientid(&lockt->lt_clientid, cstate, nn);
6932
+ status = lookup_clientid(&lockt->lt_clientid, cstate, nn,
6933
+ false);
62086934 if (status)
62096935 goto out;
62106936 }
....@@ -6223,15 +6949,15 @@
62236949 case NFS4_READ_LT:
62246950 case NFS4_READW_LT:
62256951 file_lock->fl_type = F_RDLCK;
6226
- break;
6952
+ break;
62276953 case NFS4_WRITE_LT:
62286954 case NFS4_WRITEW_LT:
62296955 file_lock->fl_type = F_WRLCK;
6230
- break;
6956
+ break;
62316957 default:
62326958 dprintk("NFSD: nfs4_lockt: bad lock type!\n");
62336959 status = nfserr_inval;
6234
- goto out;
6960
+ goto out;
62356961 }
62366962
62376963 lo = find_lockowner_str(cstate->clp, &lockt->lt_owner);
....@@ -6267,7 +6993,7 @@
62676993 {
62686994 struct nfsd4_locku *locku = &u->locku;
62696995 struct nfs4_ol_stateid *stp;
6270
- struct file *filp = NULL;
6996
+ struct nfsd_file *nf = NULL;
62716997 struct file_lock *file_lock = NULL;
62726998 __be32 status;
62736999 int err;
....@@ -6285,8 +7011,8 @@
62857011 &stp, nn);
62867012 if (status)
62877013 goto out;
6288
- filp = find_any_file(stp->st_stid.sc_file);
6289
- if (!filp) {
7014
+ nf = find_any_file(stp->st_stid.sc_file);
7015
+ if (!nf) {
62907016 status = nfserr_lock_range;
62917017 goto put_stateid;
62927018 }
....@@ -6294,13 +7020,13 @@
62947020 if (!file_lock) {
62957021 dprintk("NFSD: %s: unable to allocate lock!\n", __func__);
62967022 status = nfserr_jukebox;
6297
- goto fput;
7023
+ goto put_file;
62987024 }
62997025
63007026 file_lock->fl_type = F_UNLCK;
63017027 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(stp->st_stateowner));
63027028 file_lock->fl_pid = current->tgid;
6303
- file_lock->fl_file = filp;
7029
+ file_lock->fl_file = nf->nf_file;
63047030 file_lock->fl_flags = FL_POSIX;
63057031 file_lock->fl_lmops = &nfsd_posix_mng_ops;
63067032 file_lock->fl_start = locku->lu_offset;
....@@ -6309,14 +7035,14 @@
63097035 locku->lu_length);
63107036 nfs4_transform_lock_offset(file_lock);
63117037
6312
- err = vfs_lock_file(filp, F_SETLK, file_lock, NULL);
7038
+ err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, NULL);
63137039 if (err) {
63147040 dprintk("NFSD: nfs4_locku: vfs_lock_file failed!\n");
63157041 goto out_nfserr;
63167042 }
63177043 nfs4_inc_and_copy_stateid(&locku->lu_stateid, &stp->st_stid);
6318
-fput:
6319
- fput(filp);
7044
+put_file:
7045
+ nfsd_file_put(nf);
63207046 put_stateid:
63217047 mutex_unlock(&stp->st_mutex);
63227048 nfs4_put_stid(&stp->st_stid);
....@@ -6328,7 +7054,7 @@
63287054
63297055 out_nfserr:
63307056 status = nfserrno(err);
6331
- goto fput;
7057
+ goto put_file;
63327058 }
63337059
63347060 /*
....@@ -6341,17 +7067,17 @@
63417067 {
63427068 struct file_lock *fl;
63437069 int status = false;
6344
- struct file *filp = find_any_file(fp);
7070
+ struct nfsd_file *nf = find_any_file(fp);
63457071 struct inode *inode;
63467072 struct file_lock_context *flctx;
63477073
6348
- if (!filp) {
7074
+ if (!nf) {
63497075 /* Any valid lock stateid should have some sort of access */
63507076 WARN_ON_ONCE(1);
63517077 return status;
63527078 }
63537079
6354
- inode = locks_inode(filp);
7080
+ inode = locks_inode(nf->nf_file);
63557081 flctx = inode->i_flctx;
63567082
63577083 if (flctx && !list_empty_careful(&flctx->flc_posix)) {
....@@ -6364,7 +7090,7 @@
63647090 }
63657091 spin_unlock(&flctx->flc_lock);
63667092 }
6367
- fput(filp);
7093
+ nfsd_file_put(nf);
63687094 return status;
63697095 }
63707096
....@@ -6388,7 +7114,7 @@
63887114 dprintk("nfsd4_release_lockowner clientid: (%08x/%08x):\n",
63897115 clid->cl_boot, clid->cl_id);
63907116
6391
- status = lookup_clientid(clid, cstate, nn);
7117
+ status = lookup_clientid(clid, cstate, nn, false);
63927118 if (status)
63937119 return status;
63947120
....@@ -6401,16 +7127,12 @@
64017127 if (sop->so_is_open_owner || !same_owner_str(sop, owner))
64027128 continue;
64037129
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
- }
7130
+ if (atomic_read(&sop->so_count) != 1) {
7131
+ spin_unlock(&clp->cl_lock);
7132
+ return nfserr_locks_held;
64127133 }
64137134
7135
+ lo = lockowner(sop);
64147136 nfs4_get_stateowner(sop);
64157137 break;
64167138 }
....@@ -6442,7 +7164,7 @@
64427164 }
64437165
64447166 bool
6445
-nfs4_has_reclaimed_state(const char *name, struct nfsd_net *nn)
7167
+nfs4_has_reclaimed_state(struct xdr_netobj name, struct nfsd_net *nn)
64467168 {
64477169 struct nfs4_client_reclaim *crp;
64487170
....@@ -6452,20 +7174,26 @@
64527174
64537175 /*
64547176 * failure => all reset bets are off, nfserr_no_grace...
7177
+ *
7178
+ * The caller is responsible for freeing name.data if NULL is returned (it
7179
+ * will be freed in nfs4_remove_reclaim_record in the normal case).
64557180 */
64567181 struct nfs4_client_reclaim *
6457
-nfs4_client_to_reclaim(const char *name, struct nfsd_net *nn)
7182
+nfs4_client_to_reclaim(struct xdr_netobj name, struct xdr_netobj princhash,
7183
+ struct nfsd_net *nn)
64587184 {
64597185 unsigned int strhashval;
64607186 struct nfs4_client_reclaim *crp;
64617187
6462
- dprintk("NFSD nfs4_client_to_reclaim NAME: %.*s\n", HEXDIR_LEN, name);
64637188 crp = alloc_reclaim();
64647189 if (crp) {
64657190 strhashval = clientstr_hashval(name);
64667191 INIT_LIST_HEAD(&crp->cr_strhash);
64677192 list_add(&crp->cr_strhash, &nn->reclaim_str_hashtbl[strhashval]);
6468
- memcpy(crp->cr_recdir, name, HEXDIR_LEN);
7193
+ crp->cr_name.data = name.data;
7194
+ crp->cr_name.len = name.len;
7195
+ crp->cr_princhash.data = princhash.data;
7196
+ crp->cr_princhash.len = princhash.len;
64697197 crp->cr_clp = NULL;
64707198 nn->reclaim_str_hashtbl_size++;
64717199 }
....@@ -6476,6 +7204,8 @@
64767204 nfs4_remove_reclaim_record(struct nfs4_client_reclaim *crp, struct nfsd_net *nn)
64777205 {
64787206 list_del(&crp->cr_strhash);
7207
+ kfree(crp->cr_name.data);
7208
+ kfree(crp->cr_princhash.data);
64797209 kfree(crp);
64807210 nn->reclaim_str_hashtbl_size--;
64817211 }
....@@ -6499,16 +7229,14 @@
64997229 /*
65007230 * called from OPEN, CLAIM_PREVIOUS with a new clientid. */
65017231 struct nfs4_client_reclaim *
6502
-nfsd4_find_reclaim_client(const char *recdir, struct nfsd_net *nn)
7232
+nfsd4_find_reclaim_client(struct xdr_netobj name, struct nfsd_net *nn)
65037233 {
65047234 unsigned int strhashval;
65057235 struct nfs4_client_reclaim *crp = NULL;
65067236
6507
- dprintk("NFSD: nfs4_find_reclaim_client for recdir %s\n", recdir);
6508
-
6509
- strhashval = clientstr_hashval(recdir);
7237
+ strhashval = clientstr_hashval(name);
65107238 list_for_each_entry(crp, &nn->reclaim_str_hashtbl[strhashval], cr_strhash) {
6511
- if (same_name(crp->cr_recdir, recdir)) {
7239
+ if (compare_blob(&crp->cr_name, &name) == 0) {
65127240 return crp;
65137241 }
65147242 }
....@@ -6526,7 +7254,7 @@
65267254 __be32 status;
65277255
65287256 /* find clientid in conf_id_hashtbl */
6529
- status = lookup_clientid(clid, cstate, nn);
7257
+ status = lookup_clientid(clid, cstate, nn, false);
65307258 if (status)
65317259 return nfserr_reclaim_bad;
65327260
....@@ -6538,596 +7266,6 @@
65387266
65397267 return nfs_ok;
65407268 }
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 */
71317269
71327270 /*
71337271 * Since the lifetime of a delegation isn't limited to that of an open, a
....@@ -7179,7 +7317,7 @@
71797317 INIT_LIST_HEAD(&nn->sessionid_hashtbl[i]);
71807318 nn->conf_name_tree = RB_ROOT;
71817319 nn->unconf_name_tree = RB_ROOT;
7182
- nn->boot_time = get_seconds();
7320
+ nn->boot_time = ktime_get_real_seconds();
71837321 nn->grace_ended = false;
71847322 nn->nfsd4_manager.block_opens = true;
71857323 INIT_LIST_HEAD(&nn->nfsd4_manager.list);
....@@ -7187,6 +7325,8 @@
71877325 INIT_LIST_HEAD(&nn->close_lru);
71887326 INIT_LIST_HEAD(&nn->del_recall_lru);
71897327 spin_lock_init(&nn->client_lock);
7328
+ spin_lock_init(&nn->s2s_cp_lock);
7329
+ idr_init(&nn->s2s_cp_stateids);
71907330
71917331 spin_lock_init(&nn->blocked_locks_lock);
71927332 INIT_LIST_HEAD(&nn->blocked_locks_lru);
....@@ -7239,14 +7379,29 @@
72397379 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
72407380 int ret;
72417381
7242
- ret = nfs4_state_create_net(net);
7382
+ ret = get_nfsdfs(net);
72437383 if (ret)
72447384 return ret;
7385
+ ret = nfs4_state_create_net(net);
7386
+ if (ret) {
7387
+ mntput(nn->nfsd_mnt);
7388
+ return ret;
7389
+ }
72457390 locks_start_grace(net, &nn->nfsd4_manager);
72467391 nfsd4_client_tracking_init(net);
7247
- printk(KERN_INFO "NFSD: starting %ld-second grace period (net %x)\n",
7392
+ if (nn->track_reclaim_completes && nn->reclaim_str_hashtbl_size == 0)
7393
+ goto skip_grace;
7394
+ printk(KERN_INFO "NFSD: starting %lld-second grace period (net %x)\n",
72487395 nn->nfsd4_grace, net->ns.inum);
7396
+ trace_nfsd_grace_start(nn);
72497397 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_grace * HZ);
7398
+ return 0;
7399
+
7400
+skip_grace:
7401
+ printk(KERN_INFO "NFSD: no clients to reclaim, skipping NFSv4 grace period (net %x)\n",
7402
+ net->ns.inum);
7403
+ queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_lease * HZ);
7404
+ nfsd4_end_grace(nn);
72507405 return 0;
72517406 }
72527407
....@@ -7301,6 +7456,7 @@
73017456
73027457 nfsd4_client_tracking_exit(net);
73037458 nfs4_state_destroy_net(net);
7459
+ mntput(nn->nfsd_mnt);
73047460 }
73057461
73067462 void
....@@ -7313,7 +7469,8 @@
73137469 static void
73147470 get_stateid(struct nfsd4_compound_state *cstate, stateid_t *stateid)
73157471 {
7316
- if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG) && CURRENT_STATEID(stateid))
7472
+ if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG) &&
7473
+ CURRENT_STATEID(stateid))
73177474 memcpy(stateid, &cstate->current_stateid, sizeof(stateid_t));
73187475 }
73197476
....@@ -7322,14 +7479,14 @@
73227479 {
73237480 if (cstate->minorversion) {
73247481 memcpy(&cstate->current_stateid, stateid, sizeof(stateid_t));
7325
- SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG);
7482
+ SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG);
73267483 }
73277484 }
73287485
73297486 void
73307487 clear_current_stateid(struct nfsd4_compound_state *cstate)
73317488 {
7332
- CLEAR_STATE_ID(cstate, CURRENT_STATE_ID_FLAG);
7489
+ CLEAR_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG);
73337490 }
73347491
73357492 /*