Lines Matching refs:state
36 * Implementation of the NFSv4 state model. For the time being,
186 /* If the client state need to recover, do it. */
228 * @clp: client state handle
373 * Purge state if the client id was established in a prior
394 * @clp: client state handle
526 * remain in place so that state recovery can find it
571 * nfs4_get_state_owner - Look up a state owner given a credential
605 * @sp: state owner data to release
607 * Note that we keep released state owners on an LRU
609 * This caches valid state owners so that they can be
611 * It also pins the uniquifier of dropped state owners for
612 * a while, to ensure that those state owner names are
629 * nfs4_purge_state_owners - Release all cached state owners
630 * @server: nfs_server with cached state owners to release
631 * @head: resulting list of state owners
633 * Called at umount time. Remaining state owners will be on
635 * Note that the state owners are not freed, but are added
653 * nfs4_purge_state_owners - Release all cached state owners
654 * @head: resulting list of state owners
656 * Frees a list of state owners that was generated by
672 struct nfs4_state *state;
674 state = kzalloc(sizeof(*state), GFP_NOFS);
675 if (!state)
677 refcount_set(&state->count, 1);
678 INIT_LIST_HEAD(&state->lock_states);
679 spin_lock_init(&state->state_lock);
680 seqlock_init(&state->seqlock);
681 init_waitqueue_head(&state->waitq);
682 return state;
686 nfs4_state_set_mode_locked(struct nfs4_state *state, fmode_t fmode)
688 if (state->state == fmode)
691 if ((fmode & FMODE_WRITE) != (state->state & FMODE_WRITE)) {
693 list_move(&state->open_states, &state->owner->so_states);
695 list_move_tail(&state->open_states, &state->owner->so_states);
697 state->state = fmode;
704 struct nfs4_state *state;
706 list_for_each_entry_rcu(state, &nfsi->open_states, inode_states) {
707 if (state->owner != owner)
709 if (!nfs4_valid_open_stateid(state))
711 if (refcount_inc_not_zero(&state->count))
712 return state;
718 nfs4_free_open_state(struct nfs4_state *state)
720 kfree_rcu(state, rcu_head);
726 struct nfs4_state *state, *new;
730 state = __nfs4_find_state_byowner(inode, owner);
732 if (state)
737 state = __nfs4_find_state_byowner(inode, owner);
738 if (state == NULL && new != NULL) {
739 state = new;
740 state->owner = owner;
743 state->inode = inode;
744 list_add_rcu(&state->inode_states, &nfsi->open_states);
748 list_add_tail(&state->open_states, &owner->so_states);
757 return state;
760 void nfs4_put_open_state(struct nfs4_state *state)
762 struct inode *inode = state->inode;
763 struct nfs4_state_owner *owner = state->owner;
765 if (!refcount_dec_and_lock(&state->count, &owner->so_lock))
768 list_del_rcu(&state->inode_states);
769 list_del(&state->open_states);
774 nfs4_free_open_state(state);
781 static void __nfs4_close(struct nfs4_state *state,
784 struct nfs4_state_owner *owner = state->owner;
793 state->n_rdonly--;
796 state->n_wronly--;
799 state->n_rdwr--;
802 if (state->n_rdwr == 0) {
803 if (state->n_rdonly == 0) {
805 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
806 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
808 if (state->n_wronly == 0) {
810 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
811 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
814 clear_bit(NFS_DELEGATED_STATE, &state->flags);
816 nfs4_state_set_mode_locked(state, newstate);
820 nfs4_put_open_state(state);
823 nfs4_do_close(state, gfp_mask, wait);
826 void nfs4_close_state(struct nfs4_state *state, fmode_t fmode)
828 __nfs4_close(state, fmode, GFP_NOFS, 0);
831 void nfs4_close_sync(struct nfs4_state *state, fmode_t fmode)
833 __nfs4_close(state, fmode, GFP_KERNEL, 1);
837 * Search the state->lock_states for an existing lock_owner
850 __nfs4_find_lock_state(struct nfs4_state *state,
854 list_for_each_entry(pos, &state->lock_states, ls_locks) {
872 static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
875 struct nfs_server *server = state->owner->so_server;
882 lsp->ls_state = state;
906 static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner)
911 spin_lock(&state->state_lock);
912 lsp = __nfs4_find_lock_state(state, owner, NULL);
916 list_add(&new->ls_locks, &state->lock_states);
917 set_bit(LK_STATE_IN_USE, &state->flags);
922 spin_unlock(&state->state_lock);
923 new = nfs4_alloc_lock_state(state, owner);
927 spin_unlock(&state->state_lock);
929 nfs4_free_lock_state(state->owner->so_server, new);
940 struct nfs4_state *state;
944 state = lsp->ls_state;
945 if (!refcount_dec_and_lock(&lsp->ls_count, &state->state_lock))
948 if (list_empty(&state->lock_states))
949 clear_bit(LK_STATE_IN_USE, &state->flags);
950 spin_unlock(&state->state_lock);
951 server = state->owner->so_server;
978 int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
984 lsp = nfs4_get_lock_state(state, fl->fl_owner);
993 struct nfs4_state *state,
1003 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0)
1009 spin_lock(&state->state_lock);
1010 lsp = __nfs4_find_lock_state(state, fl_owner, fl_flock_owner);
1017 spin_unlock(&state->state_lock);
1023 bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
1032 seq = read_seqbegin(&state->seqlock);
1033 if (test_bit(NFS_OPEN_STATE, &state->flags)) {
1034 src = &state->open_stateid;
1038 } while (read_seqretry(&state->seqlock, seq));
1046 int nfs4_select_rw_stateid(struct nfs4_state *state,
1052 if (!nfs4_valid_open_stateid(state))
1056 ret = nfs4_copy_lock_stateid(dst, state, l_ctx);
1061 if (nfs4_copy_delegation_stateid(state->inode, fmode, dst, cred)) {
1071 ret = nfs4_copy_open_stateid(dst, state) ? 0 : -EAGAIN;
1073 if (nfs_server_capable(state->inode, NFS_CAP_STATEID_NFSV41))
1209 * Schedule the nfs_client asynchronous state management routine
1235 /* The rcu_read_lock() is not strictly necessary, as the state
1363 * Set the NFS4CLNT_LEASE_EXPIRED state in order to force a
1381 static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state)
1384 if (!nfs4_valid_open_stateid(state))
1386 set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
1387 /* Don't recover state that expired before the reboot */
1388 if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) {
1389 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
1392 set_bit(NFS_OWNER_RECLAIM_REBOOT, &state->owner->so_flags);
1397 int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state)
1399 if (!nfs4_valid_open_stateid(state))
1401 set_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags);
1402 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
1403 set_bit(NFS_OWNER_RECLAIM_NOGRACE, &state->owner->so_flags);
1408 int nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_state *state)
1412 if (!nfs4_state_mark_reclaim_nograce(clp, state))
1414 nfs_inode_find_delegation_state_and_recover(state->inode,
1415 &state->stateid);
1424 nfs_state_find_lock_state_by_stateid(struct nfs4_state *state,
1429 list_for_each_entry(pos, &state->lock_states, ls_locks) {
1438 static bool nfs_state_lock_state_matches_stateid(struct nfs4_state *state,
1443 if (test_bit(LK_STATE_IN_USE, &state->flags)) {
1444 spin_lock(&state->state_lock);
1445 if (nfs_state_find_lock_state_by_stateid(state, stateid))
1447 spin_unlock(&state->state_lock);
1458 struct nfs4_state *state;
1463 state = ctx->state;
1464 if (state == NULL)
1466 if (nfs4_stateid_match_or_older(&state->stateid, stateid) &&
1467 nfs4_state_mark_reclaim_nograce(clp, state)) {
1471 if (test_bit(NFS_OPEN_STATE, &state->flags) &&
1472 nfs4_stateid_match_or_older(&state->open_stateid, stateid) &&
1473 nfs4_state_mark_reclaim_nograce(clp, state)) {
1477 if (nfs_state_lock_state_matches_stateid(state, stateid) &&
1478 nfs4_state_mark_reclaim_nograce(clp, state))
1488 static void nfs4_state_mark_open_context_bad(struct nfs4_state *state, int err)
1490 struct inode *inode = state->inode;
1496 if (ctx->state != state)
1499 pr_warn("NFSv4: state recovery failed for open file %pd2, "
1505 static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error)
1507 set_bit(NFS_STATE_RECOVERY_FAILED, &state->flags);
1508 nfs4_state_mark_open_context_bad(state, error);
1512 static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops)
1514 struct inode *inode = state->inode;
1532 if (nfs_file_open_context(fl->fl_file)->state != state)
1535 status = ops->recover_lock(state, fl);
1578 static void nfs42_complete_copies(struct nfs4_state_owner *sp, struct nfs4_state *state)
1582 if (!test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) &&
1583 !test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags))
1588 if ((test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) &&
1589 !nfs4_stateid_match_other(&state->stateid,
1594 &state->flags)) {
1595 clear_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags);
1600 if ((test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags) &&
1601 !nfs4_stateid_match_other(&state->stateid,
1606 &state->flags))
1613 struct nfs4_state *state)
1618 static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_state *state,
1624 status = ops->recover_open(sp, state);
1628 status = nfs4_reclaim_locks(state, ops);
1632 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) {
1633 spin_lock(&state->state_lock);
1634 list_for_each_entry(lock, &state->lock_states, ls_locks) {
1635 trace_nfs4_state_lock_reclaim(state, lock);
1639 spin_unlock(&state->state_lock);
1642 nfs42_complete_copies(sp, state);
1643 clear_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags);
1649 struct nfs4_state *state;
1667 list_for_each_entry(state, &sp->so_states, open_states) {
1668 if (!test_and_clear_bit(ops->state_flag_bit, &state->flags))
1670 if (!nfs4_valid_open_stateid(state))
1672 if (state->state == 0)
1675 if (test_bit(NFS_SRV_SSC_COPY_STATE, &state->flags)) {
1676 nfs4_state_mark_recovery_failed(state, -EIO);
1681 refcount_inc(&state->count);
1683 status = __nfs4_reclaim_open_state(sp, state, ops);
1699 /* Open state on this file cannot be recovered */
1700 nfs4_state_mark_recovery_failed(state, status);
1705 set_bit(ops->state_flag_bit, &state->flags);
1715 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
1719 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
1729 nfs4_put_open_state(state);
1741 nfs4_put_open_state(state);
1748 static void nfs4_clear_open_state(struct nfs4_state *state)
1752 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1753 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1754 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1755 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1756 spin_lock(&state->state_lock);
1757 list_for_each_entry(lock, &state->lock_states, ls_locks) {
1761 spin_unlock(&state->state_lock);
1765 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state))
1770 struct nfs4_state *state;
1779 list_for_each_entry(state, &sp->so_states, open_states) {
1780 if (mark_reclaim(clp, state))
1781 nfs4_clear_open_state(state);
1789 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state))
1811 /* Notify the server we're done reclaiming our state */
1822 struct nfs4_state *state;
1830 list_for_each_entry(state, &sp->so_states, open_states) {
1832 &state->flags))
1834 nfs4_state_mark_reclaim_nograce(clp, state);
1991 /* Set NFS4CLNT_LEASE_EXPIRED and reclaim reboot state for all v4.0 errors
2268 * not from inside the state manager, we cannot use
2390 dprintk("%s: scheduling reset of all state for server %s!\n",
2409 dprintk("%s: state revoked on server %s\n", __func__, clp->cl_hostname);
2417 dprintk("%s: state revoked on server %s\n", __func__, clp->cl_hostname);
2425 dprintk("%s: Recallable state revoked on server %s!\n", __func__,
2454 * If we're called from the state manager thread, then assume we're
2594 /* Ensure exclusive access to NFSv4 state */
2599 section = "purge state";
2657 /* First recover reboot state... */
2677 /* Now recover expired state... */
2718 pr_warn_ratelimited("NFS: state manager%s%s failed on NFSv4 server %s"