forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/fs/nfs/nfs4state.c
....@@ -49,6 +49,7 @@
4949 #include <linux/workqueue.h>
5050 #include <linux/bitops.h>
5151 #include <linux/jiffies.h>
52
+#include <linux/sched/mm.h>
5253
5354 #include <linux/sunrpc/clnt.h>
5455
....@@ -60,6 +61,7 @@
6061 #include "nfs4session.h"
6162 #include "pnfs.h"
6263 #include "netns.h"
64
+#include "nfs4trace.h"
6365
6466 #define NFSDBG_FACILITY NFSDBG_STATE
6567
....@@ -87,7 +89,26 @@
8789
8890 static DEFINE_MUTEX(nfs_clid_init_mutex);
8991
90
-int nfs4_init_clientid(struct nfs_client *clp, struct rpc_cred *cred)
92
+static int nfs4_setup_state_renewal(struct nfs_client *clp)
93
+{
94
+ int status;
95
+ struct nfs_fsinfo fsinfo;
96
+
97
+ if (!test_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state)) {
98
+ nfs4_schedule_state_renewal(clp);
99
+ return 0;
100
+ }
101
+
102
+ status = nfs4_proc_get_lease_time(clp, &fsinfo);
103
+ if (status == 0) {
104
+ nfs4_set_lease_period(clp, fsinfo.lease_time * HZ);
105
+ nfs4_schedule_state_renewal(clp);
106
+ }
107
+
108
+ return status;
109
+}
110
+
111
+int nfs4_init_clientid(struct nfs_client *clp, const struct cred *cred)
91112 {
92113 struct nfs4_setclientid_res clid = {
93114 .clientid = clp->cl_clientid,
....@@ -114,7 +135,7 @@
114135 if (status != 0)
115136 goto out;
116137 clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
117
- nfs4_schedule_state_renewal(clp);
138
+ nfs4_setup_state_renewal(clp);
118139 out:
119140 return status;
120141 }
....@@ -134,7 +155,7 @@
134155 */
135156 int nfs40_discover_server_trunking(struct nfs_client *clp,
136157 struct nfs_client **result,
137
- struct rpc_cred *cred)
158
+ const struct cred *cred)
138159 {
139160 struct nfs4_setclientid_res clid = {
140161 .clientid = clp->cl_clientid,
....@@ -168,32 +189,23 @@
168189 return status;
169190 }
170191
171
-struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp)
192
+const struct cred *nfs4_get_machine_cred(struct nfs_client *clp)
172193 {
173
- struct rpc_cred *cred = NULL;
174
-
175
- if (clp->cl_machine_cred != NULL)
176
- cred = get_rpccred(clp->cl_machine_cred);
177
- return cred;
194
+ return get_cred(rpc_machine_cred());
178195 }
179196
180197 static void nfs4_root_machine_cred(struct nfs_client *clp)
181198 {
182
- struct rpc_cred *cred, *new;
183199
184
- new = rpc_lookup_machine_cred(NULL);
185
- spin_lock(&clp->cl_lock);
186
- cred = clp->cl_machine_cred;
187
- clp->cl_machine_cred = new;
188
- spin_unlock(&clp->cl_lock);
189
- if (cred != NULL)
190
- put_rpccred(cred);
200
+ /* Force root creds instead of machine */
201
+ clp->cl_principal = NULL;
202
+ clp->cl_rpcclient->cl_principal = NULL;
191203 }
192204
193
-static struct rpc_cred *
205
+static const struct cred *
194206 nfs4_get_renew_cred_server_locked(struct nfs_server *server)
195207 {
196
- struct rpc_cred *cred = NULL;
208
+ const struct cred *cred = NULL;
197209 struct nfs4_state_owner *sp;
198210 struct rb_node *pos;
199211
....@@ -203,29 +215,30 @@
203215 sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);
204216 if (list_empty(&sp->so_states))
205217 continue;
206
- cred = get_rpccred(sp->so_cred);
218
+ cred = get_cred(sp->so_cred);
207219 break;
208220 }
209221 return cred;
210222 }
211223
212224 /**
213
- * nfs4_get_renew_cred_locked - Acquire credential for a renew operation
225
+ * nfs4_get_renew_cred - Acquire credential for a renew operation
214226 * @clp: client state handle
215227 *
216228 * Returns an rpc_cred with reference count bumped, or NULL.
217229 * Caller must hold clp->cl_lock.
218230 */
219
-struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)
231
+const struct cred *nfs4_get_renew_cred(struct nfs_client *clp)
220232 {
221
- struct rpc_cred *cred = NULL;
233
+ const struct cred *cred = NULL;
222234 struct nfs_server *server;
223235
224236 /* Use machine credentials if available */
225
- cred = nfs4_get_machine_cred_locked(clp);
237
+ cred = nfs4_get_machine_cred(clp);
226238 if (cred != NULL)
227239 goto out;
228240
241
+ spin_lock(&clp->cl_lock);
229242 rcu_read_lock();
230243 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
231244 cred = nfs4_get_renew_cred_server_locked(server);
....@@ -233,6 +246,7 @@
233246 break;
234247 }
235248 rcu_read_unlock();
249
+ spin_unlock(&clp->cl_lock);
236250
237251 out:
238252 return cred;
....@@ -293,37 +307,16 @@
293307
294308 #if defined(CONFIG_NFS_V4_1)
295309
296
-static int nfs41_setup_state_renewal(struct nfs_client *clp)
297
-{
298
- int status;
299
- struct nfs_fsinfo fsinfo;
300
- unsigned long now;
301
-
302
- if (!test_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state)) {
303
- nfs4_schedule_state_renewal(clp);
304
- return 0;
305
- }
306
-
307
- now = jiffies;
308
- status = nfs4_proc_get_lease_time(clp, &fsinfo);
309
- if (status == 0) {
310
- nfs4_set_lease_period(clp, fsinfo.lease_time * HZ, now);
311
- nfs4_schedule_state_renewal(clp);
312
- }
313
-
314
- return status;
315
-}
316
-
317310 static void nfs41_finish_session_reset(struct nfs_client *clp)
318311 {
319312 clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
320313 clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
321314 /* create_session negotiated new slot table */
322315 clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
323
- nfs41_setup_state_renewal(clp);
316
+ nfs4_setup_state_renewal(clp);
324317 }
325318
326
-int nfs41_init_clientid(struct nfs_client *clp, struct rpc_cred *cred)
319
+int nfs41_init_clientid(struct nfs_client *clp, const struct cred *cred)
327320 {
328321 int status;
329322
....@@ -358,7 +351,7 @@
358351 */
359352 int nfs41_discover_server_trunking(struct nfs_client *clp,
360353 struct nfs_client **result,
361
- struct rpc_cred *cred)
354
+ const struct cred *cred)
362355 {
363356 int status;
364357
....@@ -396,32 +389,32 @@
396389 * nfs4_get_clid_cred - Acquire credential for a setclientid operation
397390 * @clp: client state handle
398391 *
399
- * Returns an rpc_cred with reference count bumped, or NULL.
392
+ * Returns a cred with reference count bumped, or NULL.
400393 */
401
-struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp)
394
+const struct cred *nfs4_get_clid_cred(struct nfs_client *clp)
402395 {
403
- struct rpc_cred *cred;
396
+ const struct cred *cred;
404397
405
- spin_lock(&clp->cl_lock);
406
- cred = nfs4_get_machine_cred_locked(clp);
407
- spin_unlock(&clp->cl_lock);
398
+ cred = nfs4_get_machine_cred(clp);
408399 return cred;
409400 }
410401
411402 static struct nfs4_state_owner *
412
-nfs4_find_state_owner_locked(struct nfs_server *server, struct rpc_cred *cred)
403
+nfs4_find_state_owner_locked(struct nfs_server *server, const struct cred *cred)
413404 {
414405 struct rb_node **p = &server->state_owners.rb_node,
415406 *parent = NULL;
416407 struct nfs4_state_owner *sp;
408
+ int cmp;
417409
418410 while (*p != NULL) {
419411 parent = *p;
420412 sp = rb_entry(parent, struct nfs4_state_owner, so_server_node);
413
+ cmp = cred_fscmp(cred, sp->so_cred);
421414
422
- if (cred < sp->so_cred)
415
+ if (cmp < 0)
423416 p = &parent->rb_left;
424
- else if (cred > sp->so_cred)
417
+ else if (cmp > 0)
425418 p = &parent->rb_right;
426419 else {
427420 if (!list_empty(&sp->so_lru))
....@@ -440,14 +433,16 @@
440433 struct rb_node **p = &server->state_owners.rb_node,
441434 *parent = NULL;
442435 struct nfs4_state_owner *sp;
436
+ int cmp;
443437
444438 while (*p != NULL) {
445439 parent = *p;
446440 sp = rb_entry(parent, struct nfs4_state_owner, so_server_node);
441
+ cmp = cred_fscmp(new->so_cred, sp->so_cred);
447442
448
- if (new->so_cred < sp->so_cred)
443
+ if (cmp < 0)
449444 p = &parent->rb_left;
450
- else if (new->so_cred > sp->so_cred)
445
+ else if (cmp > 0)
451446 p = &parent->rb_right;
452447 else {
453448 if (!list_empty(&sp->so_lru))
....@@ -494,7 +489,7 @@
494489 */
495490 static struct nfs4_state_owner *
496491 nfs4_alloc_state_owner(struct nfs_server *server,
497
- struct rpc_cred *cred,
492
+ const struct cred *cred,
498493 gfp_t gfp_flags)
499494 {
500495 struct nfs4_state_owner *sp;
....@@ -509,13 +504,13 @@
509504 return NULL;
510505 }
511506 sp->so_server = server;
512
- sp->so_cred = get_rpccred(cred);
507
+ sp->so_cred = get_cred(cred);
513508 spin_lock_init(&sp->so_lock);
514509 INIT_LIST_HEAD(&sp->so_states);
515510 nfs4_init_seqid_counter(&sp->so_seqid);
516511 atomic_set(&sp->so_count, 1);
517512 INIT_LIST_HEAD(&sp->so_lru);
518
- seqlock_init(&sp->so_reclaim_seqlock);
513
+ seqcount_spinlock_init(&sp->so_reclaim_seqcount, &sp->so_lock);
519514 mutex_init(&sp->so_delegreturn_mutex);
520515 return sp;
521516 }
....@@ -538,7 +533,7 @@
538533 static void nfs4_free_state_owner(struct nfs4_state_owner *sp)
539534 {
540535 nfs4_destroy_seqid_counter(&sp->so_seqid);
541
- put_rpccred(sp->so_cred);
536
+ put_cred(sp->so_cred);
542537 ida_simple_remove(&sp->so_server->openowner_id, sp->so_seqid.owner_id);
543538 kfree(sp);
544539 }
....@@ -572,11 +567,12 @@
572567 * nfs4_get_state_owner - Look up a state owner given a credential
573568 * @server: nfs_server to search
574569 * @cred: RPC credential to match
570
+ * @gfp_flags: allocation mode
575571 *
576572 * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL.
577573 */
578574 struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server,
579
- struct rpc_cred *cred,
575
+ const struct cred *cred,
580576 gfp_t gfp_flags)
581577 {
582578 struct nfs_client *clp = server->nfs_client;
....@@ -674,7 +670,7 @@
674670 state = kzalloc(sizeof(*state), GFP_NOFS);
675671 if (!state)
676672 return NULL;
677
- atomic_set(&state->count, 1);
673
+ refcount_set(&state->count, 1);
678674 INIT_LIST_HEAD(&state->lock_states);
679675 spin_lock_init(&state->state_lock);
680676 seqlock_init(&state->seqlock);
....@@ -703,12 +699,12 @@
703699 struct nfs_inode *nfsi = NFS_I(inode);
704700 struct nfs4_state *state;
705701
706
- list_for_each_entry(state, &nfsi->open_states, inode_states) {
702
+ list_for_each_entry_rcu(state, &nfsi->open_states, inode_states) {
707703 if (state->owner != owner)
708704 continue;
709705 if (!nfs4_valid_open_stateid(state))
710706 continue;
711
- if (atomic_inc_not_zero(&state->count))
707
+ if (refcount_inc_not_zero(&state->count))
712708 return state;
713709 }
714710 return NULL;
....@@ -717,7 +713,7 @@
717713 static void
718714 nfs4_free_open_state(struct nfs4_state *state)
719715 {
720
- kfree(state);
716
+ kfree_rcu(state, rcu_head);
721717 }
722718
723719 struct nfs4_state *
....@@ -726,9 +722,9 @@
726722 struct nfs4_state *state, *new;
727723 struct nfs_inode *nfsi = NFS_I(inode);
728724
729
- spin_lock(&inode->i_lock);
725
+ rcu_read_lock();
730726 state = __nfs4_find_state_byowner(inode, owner);
731
- spin_unlock(&inode->i_lock);
727
+ rcu_read_unlock();
732728 if (state)
733729 goto out;
734730 new = nfs4_alloc_open_state();
....@@ -739,9 +735,9 @@
739735 state = new;
740736 state->owner = owner;
741737 atomic_inc(&owner->so_count);
742
- list_add(&state->inode_states, &nfsi->open_states);
743738 ihold(inode);
744739 state->inode = inode;
740
+ list_add_rcu(&state->inode_states, &nfsi->open_states);
745741 spin_unlock(&inode->i_lock);
746742 /* Note: The reclaim code dictates that we add stateless
747743 * and read-only stateids to the end of the list */
....@@ -762,13 +758,14 @@
762758 struct inode *inode = state->inode;
763759 struct nfs4_state_owner *owner = state->owner;
764760
765
- if (!atomic_dec_and_lock(&state->count, &owner->so_lock))
761
+ if (!refcount_dec_and_lock(&state->count, &owner->so_lock))
766762 return;
767763 spin_lock(&inode->i_lock);
768
- list_del(&state->inode_states);
764
+ list_del_rcu(&state->inode_states);
769765 list_del(&state->open_states);
770766 spin_unlock(&inode->i_lock);
771767 spin_unlock(&owner->so_lock);
768
+ nfs4_inode_return_delegation_on_close(inode);
772769 iput(inode);
773770 nfs4_free_open_state(state);
774771 nfs4_put_state_owner(owner);
....@@ -1019,22 +1016,6 @@
10191016 return ret;
10201017 }
10211018
1022
-bool nfs4_refresh_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
1023
-{
1024
- bool ret;
1025
- int seq;
1026
-
1027
- do {
1028
- ret = false;
1029
- seq = read_seqbegin(&state->seqlock);
1030
- if (nfs4_state_match_open_stateid_other(state, dst)) {
1031
- dst->seqid = state->open_stateid.seqid;
1032
- ret = true;
1033
- }
1034
- } while (read_seqretry(&state->seqlock, seq));
1035
- return ret;
1036
-}
1037
-
10381019 bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
10391020 {
10401021 bool ret;
....@@ -1060,7 +1041,7 @@
10601041 */
10611042 int nfs4_select_rw_stateid(struct nfs4_state *state,
10621043 fmode_t fmode, const struct nfs_lock_context *l_ctx,
1063
- nfs4_stateid *dst, struct rpc_cred **cred)
1044
+ nfs4_stateid *dst, const struct cred **cred)
10641045 {
10651046 int ret;
10661047
....@@ -1083,8 +1064,7 @@
10831064 * choose to use.
10841065 */
10851066 goto out;
1086
- nfs4_copy_open_stateid(dst, state);
1087
- ret = 0;
1067
+ ret = nfs4_copy_open_stateid(dst, state) ? 0 : -EAGAIN;
10881068 out:
10891069 if (nfs_server_capable(state->inode, NFS_CAP_STATEID_NFSV41))
10901070 dst->seqid = 0;
....@@ -1155,7 +1135,7 @@
11551135 case -NFS4ERR_MOVED:
11561136 /* Non-seqid mutating errors */
11571137 return;
1158
- };
1138
+ }
11591139 /*
11601140 * Note: no locking needed as we are guaranteed to be first
11611141 * on the sequence list
....@@ -1428,7 +1408,7 @@
14281408 list_for_each_entry(pos, &state->lock_states, ls_locks) {
14291409 if (!test_bit(NFS_LOCK_INITIALIZED, &pos->ls_flags))
14301410 continue;
1431
- if (nfs4_stateid_match_other(&pos->ls_stateid, stateid))
1411
+ if (nfs4_stateid_match_or_older(&pos->ls_stateid, stateid))
14321412 return pos;
14331413 }
14341414 return NULL;
....@@ -1457,17 +1437,18 @@
14571437 struct nfs4_state *state;
14581438 bool found = false;
14591439
1460
- spin_lock(&inode->i_lock);
1461
- list_for_each_entry(ctx, &nfsi->open_files, list) {
1440
+ rcu_read_lock();
1441
+ list_for_each_entry_rcu(ctx, &nfsi->open_files, list) {
14621442 state = ctx->state;
14631443 if (state == NULL)
14641444 continue;
1465
- if (nfs4_stateid_match_other(&state->stateid, stateid) &&
1445
+ if (nfs4_stateid_match_or_older(&state->stateid, stateid) &&
14661446 nfs4_state_mark_reclaim_nograce(clp, state)) {
14671447 found = true;
14681448 continue;
14691449 }
1470
- if (nfs4_stateid_match_other(&state->open_stateid, stateid) &&
1450
+ if (test_bit(NFS_OPEN_STATE, &state->flags) &&
1451
+ nfs4_stateid_match_or_older(&state->open_stateid, stateid) &&
14711452 nfs4_state_mark_reclaim_nograce(clp, state)) {
14721453 found = true;
14731454 continue;
....@@ -1476,32 +1457,34 @@
14761457 nfs4_state_mark_reclaim_nograce(clp, state))
14771458 found = true;
14781459 }
1479
- spin_unlock(&inode->i_lock);
1460
+ rcu_read_unlock();
14801461
14811462 nfs_inode_find_delegation_state_and_recover(inode, stateid);
14821463 if (found)
14831464 nfs4_schedule_state_manager(clp);
14841465 }
14851466
1486
-static void nfs4_state_mark_open_context_bad(struct nfs4_state *state)
1467
+static void nfs4_state_mark_open_context_bad(struct nfs4_state *state, int err)
14871468 {
14881469 struct inode *inode = state->inode;
14891470 struct nfs_inode *nfsi = NFS_I(inode);
14901471 struct nfs_open_context *ctx;
14911472
1492
- spin_lock(&inode->i_lock);
1493
- list_for_each_entry(ctx, &nfsi->open_files, list) {
1473
+ rcu_read_lock();
1474
+ list_for_each_entry_rcu(ctx, &nfsi->open_files, list) {
14941475 if (ctx->state != state)
14951476 continue;
14961477 set_bit(NFS_CONTEXT_BAD, &ctx->flags);
1478
+ pr_warn("NFSv4: state recovery failed for open file %pd2, "
1479
+ "error = %d\n", ctx->dentry, err);
14971480 }
1498
- spin_unlock(&inode->i_lock);
1481
+ rcu_read_unlock();
14991482 }
15001483
15011484 static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error)
15021485 {
15031486 set_bit(NFS_STATE_RECOVERY_FAILED, &state->flags);
1504
- nfs4_state_mark_open_context_bad(state);
1487
+ nfs4_state_mark_open_context_bad(state, error);
15051488 }
15061489
15071490
....@@ -1532,6 +1515,7 @@
15321515 switch (status) {
15331516 case 0:
15341517 break;
1518
+ case -ETIMEDOUT:
15351519 case -ESTALE:
15361520 case -NFS4ERR_ADMIN_REVOKED:
15371521 case -NFS4ERR_STALE_STATEID:
....@@ -1547,7 +1531,7 @@
15471531 default:
15481532 pr_err("NFS: %s: unhandled error %d\n",
15491533 __func__, status);
1550
- /* Fall through */
1534
+ fallthrough;
15511535 case -ENOMEM:
15521536 case -NFS4ERR_DENIED:
15531537 case -NFS4ERR_RECLAIM_BAD:
....@@ -1569,11 +1553,84 @@
15691553 return status;
15701554 }
15711555
1556
+#ifdef CONFIG_NFS_V4_2
1557
+static void nfs42_complete_copies(struct nfs4_state_owner *sp, struct nfs4_state *state)
1558
+{
1559
+ struct nfs4_copy_state *copy;
1560
+
1561
+ if (!test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) &&
1562
+ !test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags))
1563
+ return;
1564
+
1565
+ spin_lock(&sp->so_server->nfs_client->cl_lock);
1566
+ list_for_each_entry(copy, &sp->so_server->ss_copies, copies) {
1567
+ if ((test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) &&
1568
+ !nfs4_stateid_match_other(&state->stateid,
1569
+ &copy->parent_dst_state->stateid)))
1570
+ continue;
1571
+ copy->flags = 1;
1572
+ if (test_and_clear_bit(NFS_CLNT_DST_SSC_COPY_STATE,
1573
+ &state->flags)) {
1574
+ clear_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags);
1575
+ complete(&copy->completion);
1576
+ }
1577
+ }
1578
+ list_for_each_entry(copy, &sp->so_server->ss_copies, src_copies) {
1579
+ if ((test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags) &&
1580
+ !nfs4_stateid_match_other(&state->stateid,
1581
+ &copy->parent_src_state->stateid)))
1582
+ continue;
1583
+ copy->flags = 1;
1584
+ if (test_and_clear_bit(NFS_CLNT_DST_SSC_COPY_STATE,
1585
+ &state->flags))
1586
+ complete(&copy->completion);
1587
+ }
1588
+ spin_unlock(&sp->so_server->nfs_client->cl_lock);
1589
+}
1590
+#else /* !CONFIG_NFS_V4_2 */
1591
+static inline void nfs42_complete_copies(struct nfs4_state_owner *sp,
1592
+ struct nfs4_state *state)
1593
+{
1594
+}
1595
+#endif /* CONFIG_NFS_V4_2 */
1596
+
1597
+static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_state *state,
1598
+ const struct nfs4_state_recovery_ops *ops)
1599
+{
1600
+ struct nfs4_lock_state *lock;
1601
+ int status;
1602
+
1603
+ status = ops->recover_open(sp, state);
1604
+ if (status < 0)
1605
+ return status;
1606
+
1607
+ status = nfs4_reclaim_locks(state, ops);
1608
+ if (status < 0)
1609
+ return status;
1610
+
1611
+ if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) {
1612
+ spin_lock(&state->state_lock);
1613
+ list_for_each_entry(lock, &state->lock_states, ls_locks) {
1614
+ trace_nfs4_state_lock_reclaim(state, lock);
1615
+ if (!test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags))
1616
+ pr_warn_ratelimited("NFS: %s: Lock reclaim failed!\n", __func__);
1617
+ }
1618
+ spin_unlock(&state->state_lock);
1619
+ }
1620
+
1621
+ nfs42_complete_copies(sp, state);
1622
+ clear_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags);
1623
+ return status;
1624
+}
1625
+
15721626 static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs4_state_recovery_ops *ops)
15731627 {
15741628 struct nfs4_state *state;
1575
- struct nfs4_lock_state *lock;
1629
+ unsigned int loop = 0;
15761630 int status = 0;
1631
+#ifdef CONFIG_NFS_V4_2
1632
+ bool found_ssc_copy_state = false;
1633
+#endif /* CONFIG_NFS_V4_2 */
15771634
15781635 /* Note: we rely on the sp->so_states list being ordered
15791636 * so that we always reclaim open(O_RDWR) and/or open(O_WRITE)
....@@ -1583,12 +1640,8 @@
15831640 * recovering after a network partition or a reboot from a
15841641 * server that doesn't support a grace period.
15851642 */
1586
-#ifdef CONFIG_PREEMPT_RT_FULL
1587
- write_seqlock(&sp->so_reclaim_seqlock);
1588
-#else
1589
- write_seqcount_begin(&sp->so_reclaim_seqlock.seqcount);
1590
-#endif
15911643 spin_lock(&sp->so_lock);
1644
+ raw_write_seqcount_begin(&sp->so_reclaim_seqcount);
15921645 restart:
15931646 list_for_each_entry(state, &sp->so_states, open_states) {
15941647 if (!test_and_clear_bit(ops->state_flag_bit, &state->flags))
....@@ -1597,98 +1650,77 @@
15971650 continue;
15981651 if (state->state == 0)
15991652 continue;
1600
- atomic_inc(&state->count);
1601
- spin_unlock(&sp->so_lock);
1602
- status = ops->recover_open(sp, state);
1603
- if (status >= 0) {
1604
- status = nfs4_reclaim_locks(state, ops);
1605
- if (status >= 0) {
1606
- if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) {
1607
- spin_lock(&state->state_lock);
1608
- list_for_each_entry(lock, &state->lock_states, ls_locks) {
1609
- if (!test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags))
1610
- pr_warn_ratelimited("NFS: "
1611
- "%s: Lock reclaim "
1612
- "failed!\n", __func__);
1613
- }
1614
- spin_unlock(&state->state_lock);
1615
- }
1616
- clear_bit(NFS_STATE_RECLAIM_NOGRACE,
1617
- &state->flags);
16181653 #ifdef CONFIG_NFS_V4_2
1619
- if (test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags)) {
1620
- struct nfs4_copy_state *copy;
1621
-
1622
- spin_lock(&sp->so_server->nfs_client->cl_lock);
1623
- list_for_each_entry(copy, &sp->so_server->ss_copies, copies) {
1624
- if (memcmp(&state->stateid.other, &copy->parent_state->stateid.other, NFS4_STATEID_SIZE))
1625
- continue;
1626
- copy->flags = 1;
1627
- complete(&copy->completion);
1628
- printk("AGLO: server rebooted waking up the copy\n");
1629
- break;
1630
- }
1631
- spin_unlock(&sp->so_server->nfs_client->cl_lock);
1632
- }
1633
-#endif /* CONFIG_NFS_V4_2 */
1634
- nfs4_put_open_state(state);
1635
- spin_lock(&sp->so_lock);
1636
- goto restart;
1637
- }
1654
+ if (test_bit(NFS_SRV_SSC_COPY_STATE, &state->flags)) {
1655
+ nfs4_state_mark_recovery_failed(state, -EIO);
1656
+ found_ssc_copy_state = true;
1657
+ continue;
16381658 }
1659
+#endif /* CONFIG_NFS_V4_2 */
1660
+ refcount_inc(&state->count);
1661
+ spin_unlock(&sp->so_lock);
1662
+ status = __nfs4_reclaim_open_state(sp, state, ops);
1663
+
16391664 switch (status) {
1640
- default:
1641
- printk(KERN_ERR "NFS: %s: unhandled error %d\n",
1642
- __func__, status);
1643
- /* Fall through */
1644
- case -ENOENT:
1645
- case -ENOMEM:
1646
- case -EACCES:
1647
- case -EROFS:
1648
- case -EIO:
1649
- case -ESTALE:
1650
- /* Open state on this file cannot be recovered */
1651
- nfs4_state_mark_recovery_failed(state, status);
1665
+ default:
1666
+ if (status >= 0) {
1667
+ loop = 0;
16521668 break;
1653
- case -EAGAIN:
1654
- ssleep(1);
1655
- /* Fall through */
1656
- case -NFS4ERR_ADMIN_REVOKED:
1657
- case -NFS4ERR_STALE_STATEID:
1658
- case -NFS4ERR_OLD_STATEID:
1659
- case -NFS4ERR_BAD_STATEID:
1660
- case -NFS4ERR_RECLAIM_BAD:
1661
- case -NFS4ERR_RECLAIM_CONFLICT:
1662
- nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
1669
+ }
1670
+ printk(KERN_ERR "NFS: %s: unhandled error %d\n", __func__, status);
1671
+ fallthrough;
1672
+ case -ENOENT:
1673
+ case -ENOMEM:
1674
+ case -EACCES:
1675
+ case -EROFS:
1676
+ case -EIO:
1677
+ case -ESTALE:
1678
+ /* Open state on this file cannot be recovered */
1679
+ nfs4_state_mark_recovery_failed(state, status);
1680
+ break;
1681
+ case -EAGAIN:
1682
+ ssleep(1);
1683
+ if (loop++ < 10) {
1684
+ set_bit(ops->state_flag_bit, &state->flags);
16631685 break;
1664
- case -NFS4ERR_EXPIRED:
1665
- case -NFS4ERR_NO_GRACE:
1666
- nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
1667
- case -NFS4ERR_STALE_CLIENTID:
1668
- case -NFS4ERR_BADSESSION:
1669
- case -NFS4ERR_BADSLOT:
1670
- case -NFS4ERR_BAD_HIGH_SLOT:
1671
- case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1672
- goto out_err;
1686
+ }
1687
+ fallthrough;
1688
+ case -NFS4ERR_ADMIN_REVOKED:
1689
+ case -NFS4ERR_STALE_STATEID:
1690
+ case -NFS4ERR_OLD_STATEID:
1691
+ case -NFS4ERR_BAD_STATEID:
1692
+ case -NFS4ERR_RECLAIM_BAD:
1693
+ case -NFS4ERR_RECLAIM_CONFLICT:
1694
+ nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
1695
+ break;
1696
+ case -NFS4ERR_EXPIRED:
1697
+ case -NFS4ERR_NO_GRACE:
1698
+ nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
1699
+ fallthrough;
1700
+ case -NFS4ERR_STALE_CLIENTID:
1701
+ case -NFS4ERR_BADSESSION:
1702
+ case -NFS4ERR_BADSLOT:
1703
+ case -NFS4ERR_BAD_HIGH_SLOT:
1704
+ case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1705
+ case -ETIMEDOUT:
1706
+ goto out_err;
16731707 }
16741708 nfs4_put_open_state(state);
16751709 spin_lock(&sp->so_lock);
16761710 goto restart;
16771711 }
1712
+ raw_write_seqcount_end(&sp->so_reclaim_seqcount);
16781713 spin_unlock(&sp->so_lock);
1679
-#ifdef CONFIG_PREEMPT_RT_FULL
1680
- write_sequnlock(&sp->so_reclaim_seqlock);
1681
-#else
1682
- write_seqcount_end(&sp->so_reclaim_seqlock.seqcount);
1683
-#endif
1714
+#ifdef CONFIG_NFS_V4_2
1715
+ if (found_ssc_copy_state)
1716
+ return -EIO;
1717
+#endif /* CONFIG_NFS_V4_2 */
16841718 return 0;
16851719 out_err:
16861720 nfs4_put_open_state(state);
1687
-#ifdef CONFIG_PREEMPT_RT_FULL
1688
- write_sequnlock(&sp->so_reclaim_seqlock);
1689
-#else
1690
- write_seqcount_end(&sp->so_reclaim_seqlock.seqcount);
1691
-#endif
1721
+ spin_lock(&sp->so_lock);
1722
+ raw_write_seqcount_end(&sp->so_reclaim_seqcount);
1723
+ spin_unlock(&sp->so_lock);
16921724 return status;
16931725 }
16941726
....@@ -1745,6 +1777,7 @@
17451777
17461778 static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp)
17471779 {
1780
+ set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
17481781 /* Mark all delegations for reclaim */
17491782 nfs_delegation_mark_reclaim(clp);
17501783 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_reboot);
....@@ -1752,7 +1785,7 @@
17521785
17531786 static int nfs4_reclaim_complete(struct nfs_client *clp,
17541787 const struct nfs4_state_recovery_ops *ops,
1755
- struct rpc_cred *cred)
1788
+ const struct cred *cred)
17561789 {
17571790 /* Notify the server we're done reclaiming our state */
17581791 if (ops->reclaim_complete)
....@@ -1803,7 +1836,7 @@
18031836 static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
18041837 {
18051838 const struct nfs4_state_recovery_ops *ops;
1806
- struct rpc_cred *cred;
1839
+ const struct cred *cred;
18071840 int err;
18081841
18091842 if (!nfs4_state_clear_reclaim_reboot(clp))
....@@ -1811,7 +1844,7 @@
18111844 ops = clp->cl_mvops->reboot_recovery_ops;
18121845 cred = nfs4_get_clid_cred(clp);
18131846 err = nfs4_reclaim_complete(clp, ops, cred);
1814
- put_rpccred(cred);
1847
+ put_cred(cred);
18151848 if (err == -NFS4ERR_CONN_NOT_BOUND_TO_SESSION)
18161849 set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
18171850 }
....@@ -1825,38 +1858,38 @@
18251858 static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
18261859 {
18271860 switch (error) {
1828
- case 0:
1829
- break;
1830
- case -NFS4ERR_CB_PATH_DOWN:
1831
- nfs40_handle_cb_pathdown(clp);
1832
- break;
1833
- case -NFS4ERR_NO_GRACE:
1834
- nfs4_state_end_reclaim_reboot(clp);
1835
- break;
1836
- case -NFS4ERR_STALE_CLIENTID:
1837
- set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1838
- nfs4_state_start_reclaim_reboot(clp);
1839
- break;
1840
- case -NFS4ERR_EXPIRED:
1841
- set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1842
- nfs4_state_start_reclaim_nograce(clp);
1843
- break;
1844
- case -NFS4ERR_BADSESSION:
1845
- case -NFS4ERR_BADSLOT:
1846
- case -NFS4ERR_BAD_HIGH_SLOT:
1847
- case -NFS4ERR_DEADSESSION:
1848
- case -NFS4ERR_SEQ_FALSE_RETRY:
1849
- case -NFS4ERR_SEQ_MISORDERED:
1850
- set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
1851
- /* Zero session reset errors */
1852
- break;
1853
- case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1854
- set_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
1855
- break;
1856
- default:
1857
- dprintk("%s: failed to handle error %d for server %s\n",
1858
- __func__, error, clp->cl_hostname);
1859
- return error;
1861
+ case 0:
1862
+ break;
1863
+ case -NFS4ERR_CB_PATH_DOWN:
1864
+ nfs40_handle_cb_pathdown(clp);
1865
+ break;
1866
+ case -NFS4ERR_NO_GRACE:
1867
+ nfs4_state_end_reclaim_reboot(clp);
1868
+ break;
1869
+ case -NFS4ERR_STALE_CLIENTID:
1870
+ set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1871
+ nfs4_state_start_reclaim_reboot(clp);
1872
+ break;
1873
+ case -NFS4ERR_EXPIRED:
1874
+ set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1875
+ nfs4_state_start_reclaim_nograce(clp);
1876
+ break;
1877
+ case -NFS4ERR_BADSESSION:
1878
+ case -NFS4ERR_BADSLOT:
1879
+ case -NFS4ERR_BAD_HIGH_SLOT:
1880
+ case -NFS4ERR_DEADSESSION:
1881
+ case -NFS4ERR_SEQ_FALSE_RETRY:
1882
+ case -NFS4ERR_SEQ_MISORDERED:
1883
+ set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
1884
+ /* Zero session reset errors */
1885
+ break;
1886
+ case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1887
+ set_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
1888
+ break;
1889
+ default:
1890
+ dprintk("%s: failed to handle error %d for server %s\n",
1891
+ __func__, error, clp->cl_hostname);
1892
+ return error;
18601893 }
18611894 dprintk("%s: handled error %d for server %s\n", __func__, error,
18621895 clp->cl_hostname);
....@@ -1909,7 +1942,7 @@
19091942
19101943 static int nfs4_check_lease(struct nfs_client *clp)
19111944 {
1912
- struct rpc_cred *cred;
1945
+ const struct cred *cred;
19131946 const struct nfs4_state_maintenance_ops *ops =
19141947 clp->cl_mvops->state_renewal_ops;
19151948 int status;
....@@ -1917,9 +1950,7 @@
19171950 /* Is the client already known to have an expired lease? */
19181951 if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
19191952 return 0;
1920
- spin_lock(&clp->cl_lock);
1921
- cred = ops->get_state_renewal_cred_locked(clp);
1922
- spin_unlock(&clp->cl_lock);
1953
+ cred = ops->get_state_renewal_cred(clp);
19231954 if (cred == NULL) {
19241955 cred = nfs4_get_clid_cred(clp);
19251956 status = -ENOKEY;
....@@ -1927,7 +1958,7 @@
19271958 goto out;
19281959 }
19291960 status = ops->renew_lease(clp, cred);
1930
- put_rpccred(cred);
1961
+ put_cred(cred);
19311962 if (status == -ETIMEDOUT) {
19321963 set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
19331964 return 0;
....@@ -1961,7 +1992,6 @@
19611992 return -EPERM;
19621993 case -EACCES:
19631994 case -NFS4ERR_DELAY:
1964
- case -ETIMEDOUT:
19651995 case -EAGAIN:
19661996 ssleep(1);
19671997 break;
....@@ -1987,7 +2017,7 @@
19872017
19882018 static int nfs4_establish_lease(struct nfs_client *clp)
19892019 {
1990
- struct rpc_cred *cred;
2020
+ const struct cred *cred;
19912021 const struct nfs4_state_recovery_ops *ops =
19922022 clp->cl_mvops->reboot_recovery_ops;
19932023 int status;
....@@ -1999,7 +2029,7 @@
19992029 if (cred == NULL)
20002030 return -ENOENT;
20012031 status = ops->establish_clid(clp, cred);
2002
- put_rpccred(cred);
2032
+ put_cred(cred);
20032033 if (status != 0)
20042034 return status;
20052035 pnfs_destroy_all_layouts(clp);
....@@ -2046,7 +2076,7 @@
20462076 *
20472077 * Returns zero or a negative NFS4ERR status code.
20482078 */
2049
-static int nfs4_try_migration(struct nfs_server *server, struct rpc_cred *cred)
2079
+static int nfs4_try_migration(struct nfs_server *server, const struct cred *cred)
20502080 {
20512081 struct nfs_client *clp = server->nfs_client;
20522082 struct nfs4_fs_locations *locations = NULL;
....@@ -2086,8 +2116,10 @@
20862116 }
20872117
20882118 status = nfs4_begin_drain_session(clp);
2089
- if (status != 0)
2090
- return status;
2119
+ if (status != 0) {
2120
+ result = status;
2121
+ goto out;
2122
+ }
20912123
20922124 status = nfs4_replace_transport(server, locations);
20932125 if (status != 0) {
....@@ -2119,14 +2151,12 @@
21192151 const struct nfs4_state_maintenance_ops *ops =
21202152 clp->cl_mvops->state_renewal_ops;
21212153 struct nfs_server *server;
2122
- struct rpc_cred *cred;
2154
+ const struct cred *cred;
21232155
21242156 dprintk("%s: migration reported on \"%s\"\n", __func__,
21252157 clp->cl_hostname);
21262158
2127
- spin_lock(&clp->cl_lock);
2128
- cred = ops->get_state_renewal_cred_locked(clp);
2129
- spin_unlock(&clp->cl_lock);
2159
+ cred = ops->get_state_renewal_cred(clp);
21302160 if (cred == NULL)
21312161 return -NFS4ERR_NOENT;
21322162
....@@ -2147,13 +2177,13 @@
21472177 rcu_read_unlock();
21482178 status = nfs4_try_migration(server, cred);
21492179 if (status < 0) {
2150
- put_rpccred(cred);
2180
+ put_cred(cred);
21512181 return status;
21522182 }
21532183 goto restart;
21542184 }
21552185 rcu_read_unlock();
2156
- put_rpccred(cred);
2186
+ put_cred(cred);
21572187 return 0;
21582188 }
21592189
....@@ -2167,14 +2197,12 @@
21672197 const struct nfs4_state_maintenance_ops *ops =
21682198 clp->cl_mvops->state_renewal_ops;
21692199 struct nfs_server *server;
2170
- struct rpc_cred *cred;
2200
+ const struct cred *cred;
21712201
21722202 dprintk("%s: lease moved reported on \"%s\"\n", __func__,
21732203 clp->cl_hostname);
21742204
2175
- spin_lock(&clp->cl_lock);
2176
- cred = ops->get_state_renewal_cred_locked(clp);
2177
- spin_unlock(&clp->cl_lock);
2205
+ cred = ops->get_state_renewal_cred(clp);
21782206 if (cred == NULL)
21792207 return -NFS4ERR_NOENT;
21802208
....@@ -2202,7 +2230,7 @@
22022230 rcu_read_unlock();
22032231
22042232 out:
2205
- put_rpccred(cred);
2233
+ put_cred(cred);
22062234 return 0;
22072235 }
22082236
....@@ -2225,7 +2253,7 @@
22252253 const struct nfs4_state_recovery_ops *ops =
22262254 clp->cl_mvops->reboot_recovery_ops;
22272255 struct rpc_clnt *clnt;
2228
- struct rpc_cred *cred;
2256
+ const struct cred *cred;
22292257 int i, status;
22302258
22312259 dprintk("NFS: %s: testing '%s'\n", __func__, clp->cl_hostname);
....@@ -2241,7 +2269,7 @@
22412269 goto out_unlock;
22422270
22432271 status = ops->detect_trunking(clp, result, cred);
2244
- put_rpccred(cred);
2272
+ put_cred(cred);
22452273 switch (status) {
22462274 case 0:
22472275 case -EINTR:
....@@ -2250,11 +2278,11 @@
22502278 case -ETIMEDOUT:
22512279 if (clnt->cl_softrtry)
22522280 break;
2253
- /* Fall through */
2281
+ fallthrough;
22542282 case -NFS4ERR_DELAY:
22552283 case -EAGAIN:
22562284 ssleep(1);
2257
- /* Fall through */
2285
+ fallthrough;
22582286 case -NFS4ERR_STALE_CLIENTID:
22592287 dprintk("NFS: %s after status %d, retrying\n",
22602288 __func__, status);
....@@ -2266,7 +2294,7 @@
22662294 }
22672295 if (clnt->cl_auth->au_flavor == RPC_AUTH_UNIX)
22682296 break;
2269
- /* Fall through */
2297
+ fallthrough;
22702298 case -NFS4ERR_CLID_INUSE:
22712299 case -NFS4ERR_WRONGSEC:
22722300 /* No point in retrying if we already used RPC_AUTH_UNIX */
....@@ -2372,8 +2400,7 @@
23722400 {
23732401 /* FIXME: For now, we destroy all layouts. */
23742402 pnfs_destroy_all_layouts(clp);
2375
- /* FIXME: For now, we test all delegations+open state+locks. */
2376
- nfs41_handle_some_state_revoked(clp);
2403
+ nfs_test_expired_all_delegations(clp);
23772404 dprintk("%s: Recallable state revoked on server %s!\n", __func__,
23782405 clp->cl_hostname);
23792406 }
....@@ -2432,7 +2459,7 @@
24322459
24332460 static int nfs4_reset_session(struct nfs_client *clp)
24342461 {
2435
- struct rpc_cred *cred;
2462
+ const struct cred *cred;
24362463 int status;
24372464
24382465 if (!nfs4_has_session(clp))
....@@ -2470,14 +2497,13 @@
24702497 dprintk("%s: session reset was successful for server %s!\n",
24712498 __func__, clp->cl_hostname);
24722499 out:
2473
- if (cred)
2474
- put_rpccred(cred);
2500
+ put_cred(cred);
24752501 return status;
24762502 }
24772503
24782504 static int nfs4_bind_conn_to_session(struct nfs_client *clp)
24792505 {
2480
- struct rpc_cred *cred;
2506
+ const struct cred *cred;
24812507 int ret;
24822508
24832509 if (!nfs4_has_session(clp))
....@@ -2487,8 +2513,7 @@
24872513 return ret;
24882514 cred = nfs4_get_clid_cred(clp);
24892515 ret = nfs4_proc_bind_conn_to_session(clp, cred);
2490
- if (cred)
2491
- put_rpccred(cred);
2516
+ put_cred(cred);
24922517 clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
24932518 switch (ret) {
24942519 case 0:
....@@ -2504,6 +2529,21 @@
25042529 }
25052530 return 0;
25062531 }
2532
+
2533
+static void nfs4_layoutreturn_any_run(struct nfs_client *clp)
2534
+{
2535
+ int iomode = 0;
2536
+
2537
+ if (test_and_clear_bit(NFS4CLNT_RECALL_ANY_LAYOUT_READ, &clp->cl_state))
2538
+ iomode += IOMODE_READ;
2539
+ if (test_and_clear_bit(NFS4CLNT_RECALL_ANY_LAYOUT_RW, &clp->cl_state))
2540
+ iomode += IOMODE_RW;
2541
+ /* Note: IOMODE_READ + IOMODE_RW == IOMODE_ANY */
2542
+ if (iomode) {
2543
+ pnfs_layout_return_unused_byclid(clp, iomode);
2544
+ set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state);
2545
+ }
2546
+}
25072547 #else /* CONFIG_NFS_V4_1 */
25082548 static int nfs4_reset_session(struct nfs_client *clp) { return 0; }
25092549
....@@ -2511,15 +2551,28 @@
25112551 {
25122552 return 0;
25132553 }
2554
+
2555
+static void nfs4_layoutreturn_any_run(struct nfs_client *clp)
2556
+{
2557
+}
25142558 #endif /* CONFIG_NFS_V4_1 */
25152559
25162560 static void nfs4_state_manager(struct nfs_client *clp)
25172561 {
2562
+ unsigned int memflags;
25182563 int status = 0;
25192564 const char *section = "", *section_sep = "";
25202565
2566
+ /*
2567
+ * State recovery can deadlock if the direct reclaim code tries
2568
+ * start NFS writeback. So ensure memory allocations are all
2569
+ * GFP_NOFS.
2570
+ */
2571
+ memflags = memalloc_nofs_save();
2572
+
25212573 /* Ensure exclusive access to NFSv4 state */
25222574 do {
2575
+ trace_nfs4_state_mgr(clp);
25232576 clear_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state);
25242577 if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) {
25252578 section = "purge state";
....@@ -2590,6 +2643,7 @@
25902643 if (status < 0)
25912644 goto out_error;
25922645 nfs4_state_end_reclaim_reboot(clp);
2646
+ continue;
25932647 }
25942648
25952649 /* Detect expired delegations... */
....@@ -2600,7 +2654,7 @@
26002654 }
26012655
26022656 /* Now recover expired state... */
2603
- if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) {
2657
+ if (test_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) {
26042658 section = "reclaim nograce";
26052659 status = nfs4_do_reclaim(clp,
26062660 clp->cl_mvops->nograce_recovery_ops);
....@@ -2608,17 +2662,20 @@
26082662 continue;
26092663 if (status < 0)
26102664 goto out_error;
2665
+ clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state);
26112666 }
26122667
2668
+ memalloc_nofs_restore(memflags);
26132669 nfs4_end_drain_session(clp);
26142670 nfs4_clear_state_manager_bit(clp);
26152671
2616
- if (!test_and_set_bit(NFS4CLNT_DELEGRETURN_RUNNING, &clp->cl_state)) {
2672
+ if (!test_and_set_bit(NFS4CLNT_RECALL_RUNNING, &clp->cl_state)) {
26172673 if (test_and_clear_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) {
26182674 nfs_client_return_marked_delegations(clp);
26192675 set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state);
26202676 }
2621
- clear_bit(NFS4CLNT_DELEGRETURN_RUNNING, &clp->cl_state);
2677
+ nfs4_layoutreturn_any_run(clp);
2678
+ clear_bit(NFS4CLNT_RECALL_RUNNING, &clp->cl_state);
26222679 }
26232680
26242681 /* Did we race with an attempt to give us more work? */
....@@ -2626,17 +2683,20 @@
26262683 return;
26272684 if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0)
26282685 return;
2686
+ memflags = memalloc_nofs_save();
26292687 } while (refcount_read(&clp->cl_count) > 1 && !signalled());
26302688 goto out_drain;
26312689
26322690 out_error:
26332691 if (strlen(section))
26342692 section_sep = ": ";
2693
+ trace_nfs4_state_mgr_failed(clp, section, status);
26352694 pr_warn_ratelimited("NFS: state manager%s%s failed on NFSv4 server %s"
26362695 " with error %d\n", section_sep, section,
26372696 clp->cl_hostname, -status);
26382697 ssleep(1);
26392698 out_drain:
2699
+ memalloc_nofs_restore(memflags);
26402700 nfs4_end_drain_session(clp);
26412701 nfs4_clear_state_manager_bit(clp);
26422702 }