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
525 * remain in place so that state recovery can find it
570 * nfs4_get_state_owner - Look up a state owner given a credential
604 * @sp: state owner data to release
606 * Note that we keep released state owners on an LRU
608 * This caches valid state owners so that they can be
610 * It also pins the uniquifier of dropped state owners for
611 * a while, to ensure that those state owner names are
628 * nfs4_purge_state_owners - Release all cached state owners
629 * @server: nfs_server with cached state owners to release
630 * @head: resulting list of state owners
632 * Called at umount time. Remaining state owners will be on
634 * Note that the state owners are not freed, but are added
652 * nfs4_free_state_owners - Release all cached state owners
653 * @head: resulting list of state owners
655 * Frees a list of state owners that was generated by
671 struct nfs4_state *state;
673 state = kzalloc(sizeof(*state), GFP_KERNEL_ACCOUNT);
674 if (!state)
676 refcount_set(&state->count, 1);
677 INIT_LIST_HEAD(&state->lock_states);
678 spin_lock_init(&state->state_lock);
679 seqlock_init(&state->seqlock);
680 init_waitqueue_head(&state->waitq);
681 return state;
685 nfs4_state_set_mode_locked(struct nfs4_state *state, fmode_t fmode)
687 if (state->state == fmode)
690 if ((fmode & FMODE_WRITE) != (state->state & FMODE_WRITE)) {
692 list_move(&state->open_states, &state->owner->so_states);
694 list_move_tail(&state->open_states, &state->owner->so_states);
696 state->state = fmode;
703 struct nfs4_state *state;
705 list_for_each_entry_rcu(state, &nfsi->open_states, inode_states) {
706 if (state->owner != owner)
708 if (!nfs4_valid_open_stateid(state))
710 if (refcount_inc_not_zero(&state->count))
711 return state;
717 nfs4_free_open_state(struct nfs4_state *state)
719 kfree_rcu(state, rcu_head);
725 struct nfs4_state *state, *new;
729 state = __nfs4_find_state_byowner(inode, owner);
731 if (state)
736 state = __nfs4_find_state_byowner(inode, owner);
737 if (state == NULL && new != NULL) {
738 state = new;
739 state->owner = owner;
742 state->inode = inode;
743 list_add_rcu(&state->inode_states, &nfsi->open_states);
747 list_add_tail(&state->open_states, &owner->so_states);
756 return state;
759 void nfs4_put_open_state(struct nfs4_state *state)
761 struct inode *inode = state->inode;
762 struct nfs4_state_owner *owner = state->owner;
764 if (!refcount_dec_and_lock(&state->count, &owner->so_lock))
767 list_del_rcu(&state->inode_states);
768 list_del(&state->open_states);
773 nfs4_free_open_state(state);
780 static void __nfs4_close(struct nfs4_state *state,
783 struct nfs4_state_owner *owner = state->owner;
792 state->n_rdonly--;
795 state->n_wronly--;
798 state->n_rdwr--;
801 if (state->n_rdwr == 0) {
802 if (state->n_rdonly == 0) {
804 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
805 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
807 if (state->n_wronly == 0) {
809 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
810 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
813 clear_bit(NFS_DELEGATED_STATE, &state->flags);
815 nfs4_state_set_mode_locked(state, newstate);
819 nfs4_put_open_state(state);
822 nfs4_do_close(state, gfp_mask, wait);
825 void nfs4_close_state(struct nfs4_state *state, fmode_t fmode)
827 __nfs4_close(state, fmode, GFP_KERNEL, 0);
830 void nfs4_close_sync(struct nfs4_state *state, fmode_t fmode)
832 __nfs4_close(state, fmode, GFP_KERNEL, 1);
836 * Search the state->lock_states for an existing lock_owner
849 __nfs4_find_lock_state(struct nfs4_state *state,
853 list_for_each_entry(pos, &state->lock_states, ls_locks) {
871 static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
874 struct nfs_server *server = state->owner->so_server;
881 lsp->ls_state = state;
905 static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner)
910 spin_lock(&state->state_lock);
911 lsp = __nfs4_find_lock_state(state, owner, NULL);
915 list_add(&new->ls_locks, &state->lock_states);
916 set_bit(LK_STATE_IN_USE, &state->flags);
921 spin_unlock(&state->state_lock);
922 new = nfs4_alloc_lock_state(state, owner);
926 spin_unlock(&state->state_lock);
928 nfs4_free_lock_state(state->owner->so_server, new);
939 struct nfs4_state *state;
943 state = lsp->ls_state;
944 if (!refcount_dec_and_lock(&lsp->ls_count, &state->state_lock))
947 if (list_empty(&state->lock_states))
948 clear_bit(LK_STATE_IN_USE, &state->flags);
949 spin_unlock(&state->state_lock);
950 server = state->owner->so_server;
977 int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
983 lsp = nfs4_get_lock_state(state, fl->fl_owner);
992 struct nfs4_state *state,
1002 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0)
1008 spin_lock(&state->state_lock);
1009 lsp = __nfs4_find_lock_state(state, fl_owner, fl_flock_owner);
1016 spin_unlock(&state->state_lock);
1022 bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
1031 seq = read_seqbegin(&state->seqlock);
1032 if (test_bit(NFS_OPEN_STATE, &state->flags)) {
1033 src = &state->open_stateid;
1037 } while (read_seqretry(&state->seqlock, seq));
1045 int nfs4_select_rw_stateid(struct nfs4_state *state,
1051 if (!nfs4_valid_open_stateid(state))
1055 ret = nfs4_copy_lock_stateid(dst, state, l_ctx);
1060 if (nfs4_copy_delegation_stateid(state->inode, fmode, dst, cred)) {
1070 ret = nfs4_copy_open_stateid(dst, state) ? 0 : -EAGAIN;
1072 if (nfs_server_capable(state->inode, NFS_CAP_STATEID_NFSV41))
1206 * Schedule the nfs_client asynchronous state management routine
1235 /* The rcu_read_lock() is not strictly necessary, as the state
1364 * Set the NFS4CLNT_LEASE_EXPIRED state in order to force a
1382 static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state)
1385 if (!nfs4_valid_open_stateid(state))
1387 set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
1388 /* Don't recover state that expired before the reboot */
1389 if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) {
1390 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
1393 set_bit(NFS_OWNER_RECLAIM_REBOOT, &state->owner->so_flags);
1398 int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state)
1400 if (!nfs4_valid_open_stateid(state))
1402 set_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags);
1403 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
1404 set_bit(NFS_OWNER_RECLAIM_NOGRACE, &state->owner->so_flags);
1409 int nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_state *state)
1413 if (!nfs4_state_mark_reclaim_nograce(clp, state))
1415 nfs_inode_find_delegation_state_and_recover(state->inode,
1416 &state->stateid);
1425 nfs_state_find_lock_state_by_stateid(struct nfs4_state *state,
1430 list_for_each_entry(pos, &state->lock_states, ls_locks) {
1439 static bool nfs_state_lock_state_matches_stateid(struct nfs4_state *state,
1444 if (test_bit(LK_STATE_IN_USE, &state->flags)) {
1445 spin_lock(&state->state_lock);
1446 if (nfs_state_find_lock_state_by_stateid(state, stateid))
1448 spin_unlock(&state->state_lock);
1459 struct nfs4_state *state;
1464 state = ctx->state;
1465 if (state == NULL)
1467 if (nfs4_stateid_match_or_older(&state->stateid, stateid) &&
1468 nfs4_state_mark_reclaim_nograce(clp, state)) {
1472 if (test_bit(NFS_OPEN_STATE, &state->flags) &&
1473 nfs4_stateid_match_or_older(&state->open_stateid, stateid) &&
1474 nfs4_state_mark_reclaim_nograce(clp, state)) {
1478 if (nfs_state_lock_state_matches_stateid(state, stateid) &&
1479 nfs4_state_mark_reclaim_nograce(clp, state))
1489 static void nfs4_state_mark_open_context_bad(struct nfs4_state *state, int err)
1491 struct inode *inode = state->inode;
1497 if (ctx->state != state)
1500 pr_warn("NFSv4: state recovery failed for open file %pd2, "
1506 static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error)
1508 set_bit(NFS_STATE_RECOVERY_FAILED, &state->flags);
1509 nfs4_state_mark_open_context_bad(state, error);
1513 static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops)
1515 struct inode *inode = state->inode;
1533 if (nfs_file_open_context(fl->fl_file)->state != state)
1536 status = ops->recover_lock(state, fl);
1579 static void nfs42_complete_copies(struct nfs4_state_owner *sp, struct nfs4_state *state)
1583 if (!test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) &&
1584 !test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags))
1589 if ((test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) &&
1590 !nfs4_stateid_match_other(&state->stateid,
1595 &state->flags)) {
1596 clear_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags);
1601 if ((test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags) &&
1602 !nfs4_stateid_match_other(&state->stateid,
1607 &state->flags))
1614 struct nfs4_state *state)
1619 static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_state *state,
1626 status = ops->recover_open(sp, state);
1630 status = nfs4_reclaim_locks(state, ops);
1634 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) {
1635 spin_lock(&state->state_lock);
1636 list_for_each_entry(lock, &state->lock_states, ls_locks) {
1637 trace_nfs4_state_lock_reclaim(state, lock);
1642 spin_unlock(&state->state_lock);
1645 nfs42_complete_copies(sp, state);
1646 clear_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags);
1654 struct nfs4_state *state;
1672 list_for_each_entry(state, &sp->so_states, open_states) {
1673 if (!test_and_clear_bit(ops->state_flag_bit, &state->flags))
1675 if (!nfs4_valid_open_stateid(state))
1677 if (state->state == 0)
1680 if (test_bit(NFS_SRV_SSC_COPY_STATE, &state->flags)) {
1681 nfs4_state_mark_recovery_failed(state, -EIO);
1686 refcount_inc(&state->count);
1688 status = __nfs4_reclaim_open_state(sp, state, ops, lost_locks);
1704 /* Open state on this file cannot be recovered */
1705 nfs4_state_mark_recovery_failed(state, status);
1710 set_bit(ops->state_flag_bit, &state->flags);
1720 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
1724 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
1734 nfs4_put_open_state(state);
1746 nfs4_put_open_state(state);
1753 static void nfs4_clear_open_state(struct nfs4_state *state)
1757 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1758 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1759 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1760 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1761 spin_lock(&state->state_lock);
1762 list_for_each_entry(lock, &state->lock_states, ls_locks) {
1766 spin_unlock(&state->state_lock);
1770 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state))
1775 struct nfs4_state *state;
1784 list_for_each_entry(state, &sp->so_states, open_states) {
1785 if (mark_reclaim(clp, state))
1786 nfs4_clear_open_state(state);
1794 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state))
1816 /* Notify the server we're done reclaiming our state */
1827 struct nfs4_state *state;
1835 list_for_each_entry(state, &sp->so_states, open_states) {
1837 &state->flags))
1839 nfs4_state_mark_reclaim_nograce(clp, state);
2003 /* Set NFS4CLNT_LEASE_EXPIRED and reclaim reboot state for all v4.0 errors
2292 * not from inside the state manager, we cannot use
2414 dprintk("%s: scheduling reset of all state for server %s!\n",
2433 dprintk("%s: state revoked on server %s\n", __func__, clp->cl_hostname);
2441 dprintk("%s: state revoked on server %s\n", __func__, clp->cl_hostname);
2449 dprintk("%s: Recallable state revoked on server %s!\n", __func__,
2478 * If we're called from the state manager thread, then assume we're
2618 /* Ensure exclusive access to NFSv4 state */
2623 section = "purge state";
2681 /* First recover reboot state... */
2701 /* Now recover expired state... */
2742 pr_warn_ratelimited("NFS: state manager%s%s failed on NFSv4 server %s"