| .. | .. |
|---|
| 49 | 49 | #include <linux/workqueue.h> |
|---|
| 50 | 50 | #include <linux/bitops.h> |
|---|
| 51 | 51 | #include <linux/jiffies.h> |
|---|
| 52 | +#include <linux/sched/mm.h> |
|---|
| 52 | 53 | |
|---|
| 53 | 54 | #include <linux/sunrpc/clnt.h> |
|---|
| 54 | 55 | |
|---|
| .. | .. |
|---|
| 60 | 61 | #include "nfs4session.h" |
|---|
| 61 | 62 | #include "pnfs.h" |
|---|
| 62 | 63 | #include "netns.h" |
|---|
| 64 | +#include "nfs4trace.h" |
|---|
| 63 | 65 | |
|---|
| 64 | 66 | #define NFSDBG_FACILITY NFSDBG_STATE |
|---|
| 65 | 67 | |
|---|
| .. | .. |
|---|
| 87 | 89 | |
|---|
| 88 | 90 | static DEFINE_MUTEX(nfs_clid_init_mutex); |
|---|
| 89 | 91 | |
|---|
| 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) |
|---|
| 91 | 112 | { |
|---|
| 92 | 113 | struct nfs4_setclientid_res clid = { |
|---|
| 93 | 114 | .clientid = clp->cl_clientid, |
|---|
| .. | .. |
|---|
| 114 | 135 | if (status != 0) |
|---|
| 115 | 136 | goto out; |
|---|
| 116 | 137 | clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state); |
|---|
| 117 | | - nfs4_schedule_state_renewal(clp); |
|---|
| 138 | + nfs4_setup_state_renewal(clp); |
|---|
| 118 | 139 | out: |
|---|
| 119 | 140 | return status; |
|---|
| 120 | 141 | } |
|---|
| .. | .. |
|---|
| 134 | 155 | */ |
|---|
| 135 | 156 | int nfs40_discover_server_trunking(struct nfs_client *clp, |
|---|
| 136 | 157 | struct nfs_client **result, |
|---|
| 137 | | - struct rpc_cred *cred) |
|---|
| 158 | + const struct cred *cred) |
|---|
| 138 | 159 | { |
|---|
| 139 | 160 | struct nfs4_setclientid_res clid = { |
|---|
| 140 | 161 | .clientid = clp->cl_clientid, |
|---|
| .. | .. |
|---|
| 168 | 189 | return status; |
|---|
| 169 | 190 | } |
|---|
| 170 | 191 | |
|---|
| 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) |
|---|
| 172 | 193 | { |
|---|
| 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()); |
|---|
| 178 | 195 | } |
|---|
| 179 | 196 | |
|---|
| 180 | 197 | static void nfs4_root_machine_cred(struct nfs_client *clp) |
|---|
| 181 | 198 | { |
|---|
| 182 | | - struct rpc_cred *cred, *new; |
|---|
| 183 | 199 | |
|---|
| 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; |
|---|
| 191 | 203 | } |
|---|
| 192 | 204 | |
|---|
| 193 | | -static struct rpc_cred * |
|---|
| 205 | +static const struct cred * |
|---|
| 194 | 206 | nfs4_get_renew_cred_server_locked(struct nfs_server *server) |
|---|
| 195 | 207 | { |
|---|
| 196 | | - struct rpc_cred *cred = NULL; |
|---|
| 208 | + const struct cred *cred = NULL; |
|---|
| 197 | 209 | struct nfs4_state_owner *sp; |
|---|
| 198 | 210 | struct rb_node *pos; |
|---|
| 199 | 211 | |
|---|
| .. | .. |
|---|
| 203 | 215 | sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); |
|---|
| 204 | 216 | if (list_empty(&sp->so_states)) |
|---|
| 205 | 217 | continue; |
|---|
| 206 | | - cred = get_rpccred(sp->so_cred); |
|---|
| 218 | + cred = get_cred(sp->so_cred); |
|---|
| 207 | 219 | break; |
|---|
| 208 | 220 | } |
|---|
| 209 | 221 | return cred; |
|---|
| 210 | 222 | } |
|---|
| 211 | 223 | |
|---|
| 212 | 224 | /** |
|---|
| 213 | | - * nfs4_get_renew_cred_locked - Acquire credential for a renew operation |
|---|
| 225 | + * nfs4_get_renew_cred - Acquire credential for a renew operation |
|---|
| 214 | 226 | * @clp: client state handle |
|---|
| 215 | 227 | * |
|---|
| 216 | 228 | * Returns an rpc_cred with reference count bumped, or NULL. |
|---|
| 217 | 229 | * Caller must hold clp->cl_lock. |
|---|
| 218 | 230 | */ |
|---|
| 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) |
|---|
| 220 | 232 | { |
|---|
| 221 | | - struct rpc_cred *cred = NULL; |
|---|
| 233 | + const struct cred *cred = NULL; |
|---|
| 222 | 234 | struct nfs_server *server; |
|---|
| 223 | 235 | |
|---|
| 224 | 236 | /* Use machine credentials if available */ |
|---|
| 225 | | - cred = nfs4_get_machine_cred_locked(clp); |
|---|
| 237 | + cred = nfs4_get_machine_cred(clp); |
|---|
| 226 | 238 | if (cred != NULL) |
|---|
| 227 | 239 | goto out; |
|---|
| 228 | 240 | |
|---|
| 241 | + spin_lock(&clp->cl_lock); |
|---|
| 229 | 242 | rcu_read_lock(); |
|---|
| 230 | 243 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { |
|---|
| 231 | 244 | cred = nfs4_get_renew_cred_server_locked(server); |
|---|
| .. | .. |
|---|
| 233 | 246 | break; |
|---|
| 234 | 247 | } |
|---|
| 235 | 248 | rcu_read_unlock(); |
|---|
| 249 | + spin_unlock(&clp->cl_lock); |
|---|
| 236 | 250 | |
|---|
| 237 | 251 | out: |
|---|
| 238 | 252 | return cred; |
|---|
| .. | .. |
|---|
| 293 | 307 | |
|---|
| 294 | 308 | #if defined(CONFIG_NFS_V4_1) |
|---|
| 295 | 309 | |
|---|
| 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 | | - |
|---|
| 317 | 310 | static void nfs41_finish_session_reset(struct nfs_client *clp) |
|---|
| 318 | 311 | { |
|---|
| 319 | 312 | clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state); |
|---|
| 320 | 313 | clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); |
|---|
| 321 | 314 | /* create_session negotiated new slot table */ |
|---|
| 322 | 315 | clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state); |
|---|
| 323 | | - nfs41_setup_state_renewal(clp); |
|---|
| 316 | + nfs4_setup_state_renewal(clp); |
|---|
| 324 | 317 | } |
|---|
| 325 | 318 | |
|---|
| 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) |
|---|
| 327 | 320 | { |
|---|
| 328 | 321 | int status; |
|---|
| 329 | 322 | |
|---|
| .. | .. |
|---|
| 358 | 351 | */ |
|---|
| 359 | 352 | int nfs41_discover_server_trunking(struct nfs_client *clp, |
|---|
| 360 | 353 | struct nfs_client **result, |
|---|
| 361 | | - struct rpc_cred *cred) |
|---|
| 354 | + const struct cred *cred) |
|---|
| 362 | 355 | { |
|---|
| 363 | 356 | int status; |
|---|
| 364 | 357 | |
|---|
| .. | .. |
|---|
| 396 | 389 | * nfs4_get_clid_cred - Acquire credential for a setclientid operation |
|---|
| 397 | 390 | * @clp: client state handle |
|---|
| 398 | 391 | * |
|---|
| 399 | | - * Returns an rpc_cred with reference count bumped, or NULL. |
|---|
| 392 | + * Returns a cred with reference count bumped, or NULL. |
|---|
| 400 | 393 | */ |
|---|
| 401 | | -struct rpc_cred *nfs4_get_clid_cred(struct nfs_client *clp) |
|---|
| 394 | +const struct cred *nfs4_get_clid_cred(struct nfs_client *clp) |
|---|
| 402 | 395 | { |
|---|
| 403 | | - struct rpc_cred *cred; |
|---|
| 396 | + const struct cred *cred; |
|---|
| 404 | 397 | |
|---|
| 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); |
|---|
| 408 | 399 | return cred; |
|---|
| 409 | 400 | } |
|---|
| 410 | 401 | |
|---|
| 411 | 402 | 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) |
|---|
| 413 | 404 | { |
|---|
| 414 | 405 | struct rb_node **p = &server->state_owners.rb_node, |
|---|
| 415 | 406 | *parent = NULL; |
|---|
| 416 | 407 | struct nfs4_state_owner *sp; |
|---|
| 408 | + int cmp; |
|---|
| 417 | 409 | |
|---|
| 418 | 410 | while (*p != NULL) { |
|---|
| 419 | 411 | parent = *p; |
|---|
| 420 | 412 | sp = rb_entry(parent, struct nfs4_state_owner, so_server_node); |
|---|
| 413 | + cmp = cred_fscmp(cred, sp->so_cred); |
|---|
| 421 | 414 | |
|---|
| 422 | | - if (cred < sp->so_cred) |
|---|
| 415 | + if (cmp < 0) |
|---|
| 423 | 416 | p = &parent->rb_left; |
|---|
| 424 | | - else if (cred > sp->so_cred) |
|---|
| 417 | + else if (cmp > 0) |
|---|
| 425 | 418 | p = &parent->rb_right; |
|---|
| 426 | 419 | else { |
|---|
| 427 | 420 | if (!list_empty(&sp->so_lru)) |
|---|
| .. | .. |
|---|
| 440 | 433 | struct rb_node **p = &server->state_owners.rb_node, |
|---|
| 441 | 434 | *parent = NULL; |
|---|
| 442 | 435 | struct nfs4_state_owner *sp; |
|---|
| 436 | + int cmp; |
|---|
| 443 | 437 | |
|---|
| 444 | 438 | while (*p != NULL) { |
|---|
| 445 | 439 | parent = *p; |
|---|
| 446 | 440 | sp = rb_entry(parent, struct nfs4_state_owner, so_server_node); |
|---|
| 441 | + cmp = cred_fscmp(new->so_cred, sp->so_cred); |
|---|
| 447 | 442 | |
|---|
| 448 | | - if (new->so_cred < sp->so_cred) |
|---|
| 443 | + if (cmp < 0) |
|---|
| 449 | 444 | p = &parent->rb_left; |
|---|
| 450 | | - else if (new->so_cred > sp->so_cred) |
|---|
| 445 | + else if (cmp > 0) |
|---|
| 451 | 446 | p = &parent->rb_right; |
|---|
| 452 | 447 | else { |
|---|
| 453 | 448 | if (!list_empty(&sp->so_lru)) |
|---|
| .. | .. |
|---|
| 494 | 489 | */ |
|---|
| 495 | 490 | static struct nfs4_state_owner * |
|---|
| 496 | 491 | nfs4_alloc_state_owner(struct nfs_server *server, |
|---|
| 497 | | - struct rpc_cred *cred, |
|---|
| 492 | + const struct cred *cred, |
|---|
| 498 | 493 | gfp_t gfp_flags) |
|---|
| 499 | 494 | { |
|---|
| 500 | 495 | struct nfs4_state_owner *sp; |
|---|
| .. | .. |
|---|
| 509 | 504 | return NULL; |
|---|
| 510 | 505 | } |
|---|
| 511 | 506 | sp->so_server = server; |
|---|
| 512 | | - sp->so_cred = get_rpccred(cred); |
|---|
| 507 | + sp->so_cred = get_cred(cred); |
|---|
| 513 | 508 | spin_lock_init(&sp->so_lock); |
|---|
| 514 | 509 | INIT_LIST_HEAD(&sp->so_states); |
|---|
| 515 | 510 | nfs4_init_seqid_counter(&sp->so_seqid); |
|---|
| 516 | 511 | atomic_set(&sp->so_count, 1); |
|---|
| 517 | 512 | INIT_LIST_HEAD(&sp->so_lru); |
|---|
| 518 | | - seqlock_init(&sp->so_reclaim_seqlock); |
|---|
| 513 | + seqcount_spinlock_init(&sp->so_reclaim_seqcount, &sp->so_lock); |
|---|
| 519 | 514 | mutex_init(&sp->so_delegreturn_mutex); |
|---|
| 520 | 515 | return sp; |
|---|
| 521 | 516 | } |
|---|
| .. | .. |
|---|
| 538 | 533 | static void nfs4_free_state_owner(struct nfs4_state_owner *sp) |
|---|
| 539 | 534 | { |
|---|
| 540 | 535 | nfs4_destroy_seqid_counter(&sp->so_seqid); |
|---|
| 541 | | - put_rpccred(sp->so_cred); |
|---|
| 536 | + put_cred(sp->so_cred); |
|---|
| 542 | 537 | ida_simple_remove(&sp->so_server->openowner_id, sp->so_seqid.owner_id); |
|---|
| 543 | 538 | kfree(sp); |
|---|
| 544 | 539 | } |
|---|
| .. | .. |
|---|
| 572 | 567 | * nfs4_get_state_owner - Look up a state owner given a credential |
|---|
| 573 | 568 | * @server: nfs_server to search |
|---|
| 574 | 569 | * @cred: RPC credential to match |
|---|
| 570 | + * @gfp_flags: allocation mode |
|---|
| 575 | 571 | * |
|---|
| 576 | 572 | * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL. |
|---|
| 577 | 573 | */ |
|---|
| 578 | 574 | struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, |
|---|
| 579 | | - struct rpc_cred *cred, |
|---|
| 575 | + const struct cred *cred, |
|---|
| 580 | 576 | gfp_t gfp_flags) |
|---|
| 581 | 577 | { |
|---|
| 582 | 578 | struct nfs_client *clp = server->nfs_client; |
|---|
| .. | .. |
|---|
| 674 | 670 | state = kzalloc(sizeof(*state), GFP_NOFS); |
|---|
| 675 | 671 | if (!state) |
|---|
| 676 | 672 | return NULL; |
|---|
| 677 | | - atomic_set(&state->count, 1); |
|---|
| 673 | + refcount_set(&state->count, 1); |
|---|
| 678 | 674 | INIT_LIST_HEAD(&state->lock_states); |
|---|
| 679 | 675 | spin_lock_init(&state->state_lock); |
|---|
| 680 | 676 | seqlock_init(&state->seqlock); |
|---|
| .. | .. |
|---|
| 703 | 699 | struct nfs_inode *nfsi = NFS_I(inode); |
|---|
| 704 | 700 | struct nfs4_state *state; |
|---|
| 705 | 701 | |
|---|
| 706 | | - list_for_each_entry(state, &nfsi->open_states, inode_states) { |
|---|
| 702 | + list_for_each_entry_rcu(state, &nfsi->open_states, inode_states) { |
|---|
| 707 | 703 | if (state->owner != owner) |
|---|
| 708 | 704 | continue; |
|---|
| 709 | 705 | if (!nfs4_valid_open_stateid(state)) |
|---|
| 710 | 706 | continue; |
|---|
| 711 | | - if (atomic_inc_not_zero(&state->count)) |
|---|
| 707 | + if (refcount_inc_not_zero(&state->count)) |
|---|
| 712 | 708 | return state; |
|---|
| 713 | 709 | } |
|---|
| 714 | 710 | return NULL; |
|---|
| .. | .. |
|---|
| 717 | 713 | static void |
|---|
| 718 | 714 | nfs4_free_open_state(struct nfs4_state *state) |
|---|
| 719 | 715 | { |
|---|
| 720 | | - kfree(state); |
|---|
| 716 | + kfree_rcu(state, rcu_head); |
|---|
| 721 | 717 | } |
|---|
| 722 | 718 | |
|---|
| 723 | 719 | struct nfs4_state * |
|---|
| .. | .. |
|---|
| 726 | 722 | struct nfs4_state *state, *new; |
|---|
| 727 | 723 | struct nfs_inode *nfsi = NFS_I(inode); |
|---|
| 728 | 724 | |
|---|
| 729 | | - spin_lock(&inode->i_lock); |
|---|
| 725 | + rcu_read_lock(); |
|---|
| 730 | 726 | state = __nfs4_find_state_byowner(inode, owner); |
|---|
| 731 | | - spin_unlock(&inode->i_lock); |
|---|
| 727 | + rcu_read_unlock(); |
|---|
| 732 | 728 | if (state) |
|---|
| 733 | 729 | goto out; |
|---|
| 734 | 730 | new = nfs4_alloc_open_state(); |
|---|
| .. | .. |
|---|
| 739 | 735 | state = new; |
|---|
| 740 | 736 | state->owner = owner; |
|---|
| 741 | 737 | atomic_inc(&owner->so_count); |
|---|
| 742 | | - list_add(&state->inode_states, &nfsi->open_states); |
|---|
| 743 | 738 | ihold(inode); |
|---|
| 744 | 739 | state->inode = inode; |
|---|
| 740 | + list_add_rcu(&state->inode_states, &nfsi->open_states); |
|---|
| 745 | 741 | spin_unlock(&inode->i_lock); |
|---|
| 746 | 742 | /* Note: The reclaim code dictates that we add stateless |
|---|
| 747 | 743 | * and read-only stateids to the end of the list */ |
|---|
| .. | .. |
|---|
| 762 | 758 | struct inode *inode = state->inode; |
|---|
| 763 | 759 | struct nfs4_state_owner *owner = state->owner; |
|---|
| 764 | 760 | |
|---|
| 765 | | - if (!atomic_dec_and_lock(&state->count, &owner->so_lock)) |
|---|
| 761 | + if (!refcount_dec_and_lock(&state->count, &owner->so_lock)) |
|---|
| 766 | 762 | return; |
|---|
| 767 | 763 | spin_lock(&inode->i_lock); |
|---|
| 768 | | - list_del(&state->inode_states); |
|---|
| 764 | + list_del_rcu(&state->inode_states); |
|---|
| 769 | 765 | list_del(&state->open_states); |
|---|
| 770 | 766 | spin_unlock(&inode->i_lock); |
|---|
| 771 | 767 | spin_unlock(&owner->so_lock); |
|---|
| 768 | + nfs4_inode_return_delegation_on_close(inode); |
|---|
| 772 | 769 | iput(inode); |
|---|
| 773 | 770 | nfs4_free_open_state(state); |
|---|
| 774 | 771 | nfs4_put_state_owner(owner); |
|---|
| .. | .. |
|---|
| 1019 | 1016 | return ret; |
|---|
| 1020 | 1017 | } |
|---|
| 1021 | 1018 | |
|---|
| 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 | | - |
|---|
| 1038 | 1019 | bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) |
|---|
| 1039 | 1020 | { |
|---|
| 1040 | 1021 | bool ret; |
|---|
| .. | .. |
|---|
| 1060 | 1041 | */ |
|---|
| 1061 | 1042 | int nfs4_select_rw_stateid(struct nfs4_state *state, |
|---|
| 1062 | 1043 | 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) |
|---|
| 1064 | 1045 | { |
|---|
| 1065 | 1046 | int ret; |
|---|
| 1066 | 1047 | |
|---|
| .. | .. |
|---|
| 1083 | 1064 | * choose to use. |
|---|
| 1084 | 1065 | */ |
|---|
| 1085 | 1066 | goto out; |
|---|
| 1086 | | - nfs4_copy_open_stateid(dst, state); |
|---|
| 1087 | | - ret = 0; |
|---|
| 1067 | + ret = nfs4_copy_open_stateid(dst, state) ? 0 : -EAGAIN; |
|---|
| 1088 | 1068 | out: |
|---|
| 1089 | 1069 | if (nfs_server_capable(state->inode, NFS_CAP_STATEID_NFSV41)) |
|---|
| 1090 | 1070 | dst->seqid = 0; |
|---|
| .. | .. |
|---|
| 1155 | 1135 | case -NFS4ERR_MOVED: |
|---|
| 1156 | 1136 | /* Non-seqid mutating errors */ |
|---|
| 1157 | 1137 | return; |
|---|
| 1158 | | - }; |
|---|
| 1138 | + } |
|---|
| 1159 | 1139 | /* |
|---|
| 1160 | 1140 | * Note: no locking needed as we are guaranteed to be first |
|---|
| 1161 | 1141 | * on the sequence list |
|---|
| .. | .. |
|---|
| 1428 | 1408 | list_for_each_entry(pos, &state->lock_states, ls_locks) { |
|---|
| 1429 | 1409 | if (!test_bit(NFS_LOCK_INITIALIZED, &pos->ls_flags)) |
|---|
| 1430 | 1410 | continue; |
|---|
| 1431 | | - if (nfs4_stateid_match_other(&pos->ls_stateid, stateid)) |
|---|
| 1411 | + if (nfs4_stateid_match_or_older(&pos->ls_stateid, stateid)) |
|---|
| 1432 | 1412 | return pos; |
|---|
| 1433 | 1413 | } |
|---|
| 1434 | 1414 | return NULL; |
|---|
| .. | .. |
|---|
| 1457 | 1437 | struct nfs4_state *state; |
|---|
| 1458 | 1438 | bool found = false; |
|---|
| 1459 | 1439 | |
|---|
| 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) { |
|---|
| 1462 | 1442 | state = ctx->state; |
|---|
| 1463 | 1443 | if (state == NULL) |
|---|
| 1464 | 1444 | continue; |
|---|
| 1465 | | - if (nfs4_stateid_match_other(&state->stateid, stateid) && |
|---|
| 1445 | + if (nfs4_stateid_match_or_older(&state->stateid, stateid) && |
|---|
| 1466 | 1446 | nfs4_state_mark_reclaim_nograce(clp, state)) { |
|---|
| 1467 | 1447 | found = true; |
|---|
| 1468 | 1448 | continue; |
|---|
| 1469 | 1449 | } |
|---|
| 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) && |
|---|
| 1471 | 1452 | nfs4_state_mark_reclaim_nograce(clp, state)) { |
|---|
| 1472 | 1453 | found = true; |
|---|
| 1473 | 1454 | continue; |
|---|
| .. | .. |
|---|
| 1476 | 1457 | nfs4_state_mark_reclaim_nograce(clp, state)) |
|---|
| 1477 | 1458 | found = true; |
|---|
| 1478 | 1459 | } |
|---|
| 1479 | | - spin_unlock(&inode->i_lock); |
|---|
| 1460 | + rcu_read_unlock(); |
|---|
| 1480 | 1461 | |
|---|
| 1481 | 1462 | nfs_inode_find_delegation_state_and_recover(inode, stateid); |
|---|
| 1482 | 1463 | if (found) |
|---|
| 1483 | 1464 | nfs4_schedule_state_manager(clp); |
|---|
| 1484 | 1465 | } |
|---|
| 1485 | 1466 | |
|---|
| 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) |
|---|
| 1487 | 1468 | { |
|---|
| 1488 | 1469 | struct inode *inode = state->inode; |
|---|
| 1489 | 1470 | struct nfs_inode *nfsi = NFS_I(inode); |
|---|
| 1490 | 1471 | struct nfs_open_context *ctx; |
|---|
| 1491 | 1472 | |
|---|
| 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) { |
|---|
| 1494 | 1475 | if (ctx->state != state) |
|---|
| 1495 | 1476 | continue; |
|---|
| 1496 | 1477 | 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); |
|---|
| 1497 | 1480 | } |
|---|
| 1498 | | - spin_unlock(&inode->i_lock); |
|---|
| 1481 | + rcu_read_unlock(); |
|---|
| 1499 | 1482 | } |
|---|
| 1500 | 1483 | |
|---|
| 1501 | 1484 | static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error) |
|---|
| 1502 | 1485 | { |
|---|
| 1503 | 1486 | 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); |
|---|
| 1505 | 1488 | } |
|---|
| 1506 | 1489 | |
|---|
| 1507 | 1490 | |
|---|
| .. | .. |
|---|
| 1532 | 1515 | switch (status) { |
|---|
| 1533 | 1516 | case 0: |
|---|
| 1534 | 1517 | break; |
|---|
| 1518 | + case -ETIMEDOUT: |
|---|
| 1535 | 1519 | case -ESTALE: |
|---|
| 1536 | 1520 | case -NFS4ERR_ADMIN_REVOKED: |
|---|
| 1537 | 1521 | case -NFS4ERR_STALE_STATEID: |
|---|
| .. | .. |
|---|
| 1547 | 1531 | default: |
|---|
| 1548 | 1532 | pr_err("NFS: %s: unhandled error %d\n", |
|---|
| 1549 | 1533 | __func__, status); |
|---|
| 1550 | | - /* Fall through */ |
|---|
| 1534 | + fallthrough; |
|---|
| 1551 | 1535 | case -ENOMEM: |
|---|
| 1552 | 1536 | case -NFS4ERR_DENIED: |
|---|
| 1553 | 1537 | case -NFS4ERR_RECLAIM_BAD: |
|---|
| .. | .. |
|---|
| 1569 | 1553 | return status; |
|---|
| 1570 | 1554 | } |
|---|
| 1571 | 1555 | |
|---|
| 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 | + ©->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(©->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 | + ©->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(©->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 | + |
|---|
| 1572 | 1626 | static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs4_state_recovery_ops *ops) |
|---|
| 1573 | 1627 | { |
|---|
| 1574 | 1628 | struct nfs4_state *state; |
|---|
| 1575 | | - struct nfs4_lock_state *lock; |
|---|
| 1629 | + unsigned int loop = 0; |
|---|
| 1576 | 1630 | int status = 0; |
|---|
| 1631 | +#ifdef CONFIG_NFS_V4_2 |
|---|
| 1632 | + bool found_ssc_copy_state = false; |
|---|
| 1633 | +#endif /* CONFIG_NFS_V4_2 */ |
|---|
| 1577 | 1634 | |
|---|
| 1578 | 1635 | /* Note: we rely on the sp->so_states list being ordered |
|---|
| 1579 | 1636 | * so that we always reclaim open(O_RDWR) and/or open(O_WRITE) |
|---|
| .. | .. |
|---|
| 1583 | 1640 | * recovering after a network partition or a reboot from a |
|---|
| 1584 | 1641 | * server that doesn't support a grace period. |
|---|
| 1585 | 1642 | */ |
|---|
| 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 |
|---|
| 1591 | 1643 | spin_lock(&sp->so_lock); |
|---|
| 1644 | + raw_write_seqcount_begin(&sp->so_reclaim_seqcount); |
|---|
| 1592 | 1645 | restart: |
|---|
| 1593 | 1646 | list_for_each_entry(state, &sp->so_states, open_states) { |
|---|
| 1594 | 1647 | if (!test_and_clear_bit(ops->state_flag_bit, &state->flags)) |
|---|
| .. | .. |
|---|
| 1597 | 1650 | continue; |
|---|
| 1598 | 1651 | if (state->state == 0) |
|---|
| 1599 | 1652 | 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); |
|---|
| 1618 | 1653 | #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, ©->parent_state->stateid.other, NFS4_STATEID_SIZE)) |
|---|
| 1625 | | - continue; |
|---|
| 1626 | | - copy->flags = 1; |
|---|
| 1627 | | - complete(©->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; |
|---|
| 1638 | 1658 | } |
|---|
| 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 | + |
|---|
| 1639 | 1664 | 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; |
|---|
| 1652 | 1668 | 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); |
|---|
| 1663 | 1685 | 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; |
|---|
| 1673 | 1707 | } |
|---|
| 1674 | 1708 | nfs4_put_open_state(state); |
|---|
| 1675 | 1709 | spin_lock(&sp->so_lock); |
|---|
| 1676 | 1710 | goto restart; |
|---|
| 1677 | 1711 | } |
|---|
| 1712 | + raw_write_seqcount_end(&sp->so_reclaim_seqcount); |
|---|
| 1678 | 1713 | 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 */ |
|---|
| 1684 | 1718 | return 0; |
|---|
| 1685 | 1719 | out_err: |
|---|
| 1686 | 1720 | 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); |
|---|
| 1692 | 1724 | return status; |
|---|
| 1693 | 1725 | } |
|---|
| 1694 | 1726 | |
|---|
| .. | .. |
|---|
| 1745 | 1777 | |
|---|
| 1746 | 1778 | static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp) |
|---|
| 1747 | 1779 | { |
|---|
| 1780 | + set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state); |
|---|
| 1748 | 1781 | /* Mark all delegations for reclaim */ |
|---|
| 1749 | 1782 | nfs_delegation_mark_reclaim(clp); |
|---|
| 1750 | 1783 | nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_reboot); |
|---|
| .. | .. |
|---|
| 1752 | 1785 | |
|---|
| 1753 | 1786 | static int nfs4_reclaim_complete(struct nfs_client *clp, |
|---|
| 1754 | 1787 | const struct nfs4_state_recovery_ops *ops, |
|---|
| 1755 | | - struct rpc_cred *cred) |
|---|
| 1788 | + const struct cred *cred) |
|---|
| 1756 | 1789 | { |
|---|
| 1757 | 1790 | /* Notify the server we're done reclaiming our state */ |
|---|
| 1758 | 1791 | if (ops->reclaim_complete) |
|---|
| .. | .. |
|---|
| 1803 | 1836 | static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp) |
|---|
| 1804 | 1837 | { |
|---|
| 1805 | 1838 | const struct nfs4_state_recovery_ops *ops; |
|---|
| 1806 | | - struct rpc_cred *cred; |
|---|
| 1839 | + const struct cred *cred; |
|---|
| 1807 | 1840 | int err; |
|---|
| 1808 | 1841 | |
|---|
| 1809 | 1842 | if (!nfs4_state_clear_reclaim_reboot(clp)) |
|---|
| .. | .. |
|---|
| 1811 | 1844 | ops = clp->cl_mvops->reboot_recovery_ops; |
|---|
| 1812 | 1845 | cred = nfs4_get_clid_cred(clp); |
|---|
| 1813 | 1846 | err = nfs4_reclaim_complete(clp, ops, cred); |
|---|
| 1814 | | - put_rpccred(cred); |
|---|
| 1847 | + put_cred(cred); |
|---|
| 1815 | 1848 | if (err == -NFS4ERR_CONN_NOT_BOUND_TO_SESSION) |
|---|
| 1816 | 1849 | set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state); |
|---|
| 1817 | 1850 | } |
|---|
| .. | .. |
|---|
| 1825 | 1858 | static int nfs4_recovery_handle_error(struct nfs_client *clp, int error) |
|---|
| 1826 | 1859 | { |
|---|
| 1827 | 1860 | 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; |
|---|
| 1860 | 1893 | } |
|---|
| 1861 | 1894 | dprintk("%s: handled error %d for server %s\n", __func__, error, |
|---|
| 1862 | 1895 | clp->cl_hostname); |
|---|
| .. | .. |
|---|
| 1909 | 1942 | |
|---|
| 1910 | 1943 | static int nfs4_check_lease(struct nfs_client *clp) |
|---|
| 1911 | 1944 | { |
|---|
| 1912 | | - struct rpc_cred *cred; |
|---|
| 1945 | + const struct cred *cred; |
|---|
| 1913 | 1946 | const struct nfs4_state_maintenance_ops *ops = |
|---|
| 1914 | 1947 | clp->cl_mvops->state_renewal_ops; |
|---|
| 1915 | 1948 | int status; |
|---|
| .. | .. |
|---|
| 1917 | 1950 | /* Is the client already known to have an expired lease? */ |
|---|
| 1918 | 1951 | if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state)) |
|---|
| 1919 | 1952 | 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); |
|---|
| 1923 | 1954 | if (cred == NULL) { |
|---|
| 1924 | 1955 | cred = nfs4_get_clid_cred(clp); |
|---|
| 1925 | 1956 | status = -ENOKEY; |
|---|
| .. | .. |
|---|
| 1927 | 1958 | goto out; |
|---|
| 1928 | 1959 | } |
|---|
| 1929 | 1960 | status = ops->renew_lease(clp, cred); |
|---|
| 1930 | | - put_rpccred(cred); |
|---|
| 1961 | + put_cred(cred); |
|---|
| 1931 | 1962 | if (status == -ETIMEDOUT) { |
|---|
| 1932 | 1963 | set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state); |
|---|
| 1933 | 1964 | return 0; |
|---|
| .. | .. |
|---|
| 1961 | 1992 | return -EPERM; |
|---|
| 1962 | 1993 | case -EACCES: |
|---|
| 1963 | 1994 | case -NFS4ERR_DELAY: |
|---|
| 1964 | | - case -ETIMEDOUT: |
|---|
| 1965 | 1995 | case -EAGAIN: |
|---|
| 1966 | 1996 | ssleep(1); |
|---|
| 1967 | 1997 | break; |
|---|
| .. | .. |
|---|
| 1987 | 2017 | |
|---|
| 1988 | 2018 | static int nfs4_establish_lease(struct nfs_client *clp) |
|---|
| 1989 | 2019 | { |
|---|
| 1990 | | - struct rpc_cred *cred; |
|---|
| 2020 | + const struct cred *cred; |
|---|
| 1991 | 2021 | const struct nfs4_state_recovery_ops *ops = |
|---|
| 1992 | 2022 | clp->cl_mvops->reboot_recovery_ops; |
|---|
| 1993 | 2023 | int status; |
|---|
| .. | .. |
|---|
| 1999 | 2029 | if (cred == NULL) |
|---|
| 2000 | 2030 | return -ENOENT; |
|---|
| 2001 | 2031 | status = ops->establish_clid(clp, cred); |
|---|
| 2002 | | - put_rpccred(cred); |
|---|
| 2032 | + put_cred(cred); |
|---|
| 2003 | 2033 | if (status != 0) |
|---|
| 2004 | 2034 | return status; |
|---|
| 2005 | 2035 | pnfs_destroy_all_layouts(clp); |
|---|
| .. | .. |
|---|
| 2046 | 2076 | * |
|---|
| 2047 | 2077 | * Returns zero or a negative NFS4ERR status code. |
|---|
| 2048 | 2078 | */ |
|---|
| 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) |
|---|
| 2050 | 2080 | { |
|---|
| 2051 | 2081 | struct nfs_client *clp = server->nfs_client; |
|---|
| 2052 | 2082 | struct nfs4_fs_locations *locations = NULL; |
|---|
| .. | .. |
|---|
| 2086 | 2116 | } |
|---|
| 2087 | 2117 | |
|---|
| 2088 | 2118 | status = nfs4_begin_drain_session(clp); |
|---|
| 2089 | | - if (status != 0) |
|---|
| 2090 | | - return status; |
|---|
| 2119 | + if (status != 0) { |
|---|
| 2120 | + result = status; |
|---|
| 2121 | + goto out; |
|---|
| 2122 | + } |
|---|
| 2091 | 2123 | |
|---|
| 2092 | 2124 | status = nfs4_replace_transport(server, locations); |
|---|
| 2093 | 2125 | if (status != 0) { |
|---|
| .. | .. |
|---|
| 2119 | 2151 | const struct nfs4_state_maintenance_ops *ops = |
|---|
| 2120 | 2152 | clp->cl_mvops->state_renewal_ops; |
|---|
| 2121 | 2153 | struct nfs_server *server; |
|---|
| 2122 | | - struct rpc_cred *cred; |
|---|
| 2154 | + const struct cred *cred; |
|---|
| 2123 | 2155 | |
|---|
| 2124 | 2156 | dprintk("%s: migration reported on \"%s\"\n", __func__, |
|---|
| 2125 | 2157 | clp->cl_hostname); |
|---|
| 2126 | 2158 | |
|---|
| 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); |
|---|
| 2130 | 2160 | if (cred == NULL) |
|---|
| 2131 | 2161 | return -NFS4ERR_NOENT; |
|---|
| 2132 | 2162 | |
|---|
| .. | .. |
|---|
| 2147 | 2177 | rcu_read_unlock(); |
|---|
| 2148 | 2178 | status = nfs4_try_migration(server, cred); |
|---|
| 2149 | 2179 | if (status < 0) { |
|---|
| 2150 | | - put_rpccred(cred); |
|---|
| 2180 | + put_cred(cred); |
|---|
| 2151 | 2181 | return status; |
|---|
| 2152 | 2182 | } |
|---|
| 2153 | 2183 | goto restart; |
|---|
| 2154 | 2184 | } |
|---|
| 2155 | 2185 | rcu_read_unlock(); |
|---|
| 2156 | | - put_rpccred(cred); |
|---|
| 2186 | + put_cred(cred); |
|---|
| 2157 | 2187 | return 0; |
|---|
| 2158 | 2188 | } |
|---|
| 2159 | 2189 | |
|---|
| .. | .. |
|---|
| 2167 | 2197 | const struct nfs4_state_maintenance_ops *ops = |
|---|
| 2168 | 2198 | clp->cl_mvops->state_renewal_ops; |
|---|
| 2169 | 2199 | struct nfs_server *server; |
|---|
| 2170 | | - struct rpc_cred *cred; |
|---|
| 2200 | + const struct cred *cred; |
|---|
| 2171 | 2201 | |
|---|
| 2172 | 2202 | dprintk("%s: lease moved reported on \"%s\"\n", __func__, |
|---|
| 2173 | 2203 | clp->cl_hostname); |
|---|
| 2174 | 2204 | |
|---|
| 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); |
|---|
| 2178 | 2206 | if (cred == NULL) |
|---|
| 2179 | 2207 | return -NFS4ERR_NOENT; |
|---|
| 2180 | 2208 | |
|---|
| .. | .. |
|---|
| 2202 | 2230 | rcu_read_unlock(); |
|---|
| 2203 | 2231 | |
|---|
| 2204 | 2232 | out: |
|---|
| 2205 | | - put_rpccred(cred); |
|---|
| 2233 | + put_cred(cred); |
|---|
| 2206 | 2234 | return 0; |
|---|
| 2207 | 2235 | } |
|---|
| 2208 | 2236 | |
|---|
| .. | .. |
|---|
| 2225 | 2253 | const struct nfs4_state_recovery_ops *ops = |
|---|
| 2226 | 2254 | clp->cl_mvops->reboot_recovery_ops; |
|---|
| 2227 | 2255 | struct rpc_clnt *clnt; |
|---|
| 2228 | | - struct rpc_cred *cred; |
|---|
| 2256 | + const struct cred *cred; |
|---|
| 2229 | 2257 | int i, status; |
|---|
| 2230 | 2258 | |
|---|
| 2231 | 2259 | dprintk("NFS: %s: testing '%s'\n", __func__, clp->cl_hostname); |
|---|
| .. | .. |
|---|
| 2241 | 2269 | goto out_unlock; |
|---|
| 2242 | 2270 | |
|---|
| 2243 | 2271 | status = ops->detect_trunking(clp, result, cred); |
|---|
| 2244 | | - put_rpccred(cred); |
|---|
| 2272 | + put_cred(cred); |
|---|
| 2245 | 2273 | switch (status) { |
|---|
| 2246 | 2274 | case 0: |
|---|
| 2247 | 2275 | case -EINTR: |
|---|
| .. | .. |
|---|
| 2250 | 2278 | case -ETIMEDOUT: |
|---|
| 2251 | 2279 | if (clnt->cl_softrtry) |
|---|
| 2252 | 2280 | break; |
|---|
| 2253 | | - /* Fall through */ |
|---|
| 2281 | + fallthrough; |
|---|
| 2254 | 2282 | case -NFS4ERR_DELAY: |
|---|
| 2255 | 2283 | case -EAGAIN: |
|---|
| 2256 | 2284 | ssleep(1); |
|---|
| 2257 | | - /* Fall through */ |
|---|
| 2285 | + fallthrough; |
|---|
| 2258 | 2286 | case -NFS4ERR_STALE_CLIENTID: |
|---|
| 2259 | 2287 | dprintk("NFS: %s after status %d, retrying\n", |
|---|
| 2260 | 2288 | __func__, status); |
|---|
| .. | .. |
|---|
| 2266 | 2294 | } |
|---|
| 2267 | 2295 | if (clnt->cl_auth->au_flavor == RPC_AUTH_UNIX) |
|---|
| 2268 | 2296 | break; |
|---|
| 2269 | | - /* Fall through */ |
|---|
| 2297 | + fallthrough; |
|---|
| 2270 | 2298 | case -NFS4ERR_CLID_INUSE: |
|---|
| 2271 | 2299 | case -NFS4ERR_WRONGSEC: |
|---|
| 2272 | 2300 | /* No point in retrying if we already used RPC_AUTH_UNIX */ |
|---|
| .. | .. |
|---|
| 2372 | 2400 | { |
|---|
| 2373 | 2401 | /* FIXME: For now, we destroy all layouts. */ |
|---|
| 2374 | 2402 | 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); |
|---|
| 2377 | 2404 | dprintk("%s: Recallable state revoked on server %s!\n", __func__, |
|---|
| 2378 | 2405 | clp->cl_hostname); |
|---|
| 2379 | 2406 | } |
|---|
| .. | .. |
|---|
| 2432 | 2459 | |
|---|
| 2433 | 2460 | static int nfs4_reset_session(struct nfs_client *clp) |
|---|
| 2434 | 2461 | { |
|---|
| 2435 | | - struct rpc_cred *cred; |
|---|
| 2462 | + const struct cred *cred; |
|---|
| 2436 | 2463 | int status; |
|---|
| 2437 | 2464 | |
|---|
| 2438 | 2465 | if (!nfs4_has_session(clp)) |
|---|
| .. | .. |
|---|
| 2470 | 2497 | dprintk("%s: session reset was successful for server %s!\n", |
|---|
| 2471 | 2498 | __func__, clp->cl_hostname); |
|---|
| 2472 | 2499 | out: |
|---|
| 2473 | | - if (cred) |
|---|
| 2474 | | - put_rpccred(cred); |
|---|
| 2500 | + put_cred(cred); |
|---|
| 2475 | 2501 | return status; |
|---|
| 2476 | 2502 | } |
|---|
| 2477 | 2503 | |
|---|
| 2478 | 2504 | static int nfs4_bind_conn_to_session(struct nfs_client *clp) |
|---|
| 2479 | 2505 | { |
|---|
| 2480 | | - struct rpc_cred *cred; |
|---|
| 2506 | + const struct cred *cred; |
|---|
| 2481 | 2507 | int ret; |
|---|
| 2482 | 2508 | |
|---|
| 2483 | 2509 | if (!nfs4_has_session(clp)) |
|---|
| .. | .. |
|---|
| 2487 | 2513 | return ret; |
|---|
| 2488 | 2514 | cred = nfs4_get_clid_cred(clp); |
|---|
| 2489 | 2515 | ret = nfs4_proc_bind_conn_to_session(clp, cred); |
|---|
| 2490 | | - if (cred) |
|---|
| 2491 | | - put_rpccred(cred); |
|---|
| 2516 | + put_cred(cred); |
|---|
| 2492 | 2517 | clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state); |
|---|
| 2493 | 2518 | switch (ret) { |
|---|
| 2494 | 2519 | case 0: |
|---|
| .. | .. |
|---|
| 2504 | 2529 | } |
|---|
| 2505 | 2530 | return 0; |
|---|
| 2506 | 2531 | } |
|---|
| 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 | +} |
|---|
| 2507 | 2547 | #else /* CONFIG_NFS_V4_1 */ |
|---|
| 2508 | 2548 | static int nfs4_reset_session(struct nfs_client *clp) { return 0; } |
|---|
| 2509 | 2549 | |
|---|
| .. | .. |
|---|
| 2511 | 2551 | { |
|---|
| 2512 | 2552 | return 0; |
|---|
| 2513 | 2553 | } |
|---|
| 2554 | + |
|---|
| 2555 | +static void nfs4_layoutreturn_any_run(struct nfs_client *clp) |
|---|
| 2556 | +{ |
|---|
| 2557 | +} |
|---|
| 2514 | 2558 | #endif /* CONFIG_NFS_V4_1 */ |
|---|
| 2515 | 2559 | |
|---|
| 2516 | 2560 | static void nfs4_state_manager(struct nfs_client *clp) |
|---|
| 2517 | 2561 | { |
|---|
| 2562 | + unsigned int memflags; |
|---|
| 2518 | 2563 | int status = 0; |
|---|
| 2519 | 2564 | const char *section = "", *section_sep = ""; |
|---|
| 2520 | 2565 | |
|---|
| 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 | + |
|---|
| 2521 | 2573 | /* Ensure exclusive access to NFSv4 state */ |
|---|
| 2522 | 2574 | do { |
|---|
| 2575 | + trace_nfs4_state_mgr(clp); |
|---|
| 2523 | 2576 | clear_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state); |
|---|
| 2524 | 2577 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
|---|
| 2525 | 2578 | section = "purge state"; |
|---|
| .. | .. |
|---|
| 2590 | 2643 | if (status < 0) |
|---|
| 2591 | 2644 | goto out_error; |
|---|
| 2592 | 2645 | nfs4_state_end_reclaim_reboot(clp); |
|---|
| 2646 | + continue; |
|---|
| 2593 | 2647 | } |
|---|
| 2594 | 2648 | |
|---|
| 2595 | 2649 | /* Detect expired delegations... */ |
|---|
| .. | .. |
|---|
| 2600 | 2654 | } |
|---|
| 2601 | 2655 | |
|---|
| 2602 | 2656 | /* 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)) { |
|---|
| 2604 | 2658 | section = "reclaim nograce"; |
|---|
| 2605 | 2659 | status = nfs4_do_reclaim(clp, |
|---|
| 2606 | 2660 | clp->cl_mvops->nograce_recovery_ops); |
|---|
| .. | .. |
|---|
| 2608 | 2662 | continue; |
|---|
| 2609 | 2663 | if (status < 0) |
|---|
| 2610 | 2664 | goto out_error; |
|---|
| 2665 | + clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state); |
|---|
| 2611 | 2666 | } |
|---|
| 2612 | 2667 | |
|---|
| 2668 | + memalloc_nofs_restore(memflags); |
|---|
| 2613 | 2669 | nfs4_end_drain_session(clp); |
|---|
| 2614 | 2670 | nfs4_clear_state_manager_bit(clp); |
|---|
| 2615 | 2671 | |
|---|
| 2616 | | - if (!test_and_set_bit(NFS4CLNT_DELEGRETURN_RUNNING, &clp->cl_state)) { |
|---|
| 2672 | + if (!test_and_set_bit(NFS4CLNT_RECALL_RUNNING, &clp->cl_state)) { |
|---|
| 2617 | 2673 | if (test_and_clear_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) { |
|---|
| 2618 | 2674 | nfs_client_return_marked_delegations(clp); |
|---|
| 2619 | 2675 | set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state); |
|---|
| 2620 | 2676 | } |
|---|
| 2621 | | - clear_bit(NFS4CLNT_DELEGRETURN_RUNNING, &clp->cl_state); |
|---|
| 2677 | + nfs4_layoutreturn_any_run(clp); |
|---|
| 2678 | + clear_bit(NFS4CLNT_RECALL_RUNNING, &clp->cl_state); |
|---|
| 2622 | 2679 | } |
|---|
| 2623 | 2680 | |
|---|
| 2624 | 2681 | /* Did we race with an attempt to give us more work? */ |
|---|
| .. | .. |
|---|
| 2626 | 2683 | return; |
|---|
| 2627 | 2684 | if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0) |
|---|
| 2628 | 2685 | return; |
|---|
| 2686 | + memflags = memalloc_nofs_save(); |
|---|
| 2629 | 2687 | } while (refcount_read(&clp->cl_count) > 1 && !signalled()); |
|---|
| 2630 | 2688 | goto out_drain; |
|---|
| 2631 | 2689 | |
|---|
| 2632 | 2690 | out_error: |
|---|
| 2633 | 2691 | if (strlen(section)) |
|---|
| 2634 | 2692 | section_sep = ": "; |
|---|
| 2693 | + trace_nfs4_state_mgr_failed(clp, section, status); |
|---|
| 2635 | 2694 | pr_warn_ratelimited("NFS: state manager%s%s failed on NFSv4 server %s" |
|---|
| 2636 | 2695 | " with error %d\n", section_sep, section, |
|---|
| 2637 | 2696 | clp->cl_hostname, -status); |
|---|
| 2638 | 2697 | ssleep(1); |
|---|
| 2639 | 2698 | out_drain: |
|---|
| 2699 | + memalloc_nofs_restore(memflags); |
|---|
| 2640 | 2700 | nfs4_end_drain_session(clp); |
|---|
| 2641 | 2701 | nfs4_clear_state_manager_bit(clp); |
|---|
| 2642 | 2702 | } |
|---|