• Home
  • Raw
  • Download

Lines Matching refs:state

672 	struct nfs4_state *state;  in nfs4_alloc_open_state()  local
674 state = kzalloc(sizeof(*state), GFP_NOFS); in nfs4_alloc_open_state()
675 if (!state) in nfs4_alloc_open_state()
677 refcount_set(&state->count, 1); in nfs4_alloc_open_state()
678 INIT_LIST_HEAD(&state->lock_states); in nfs4_alloc_open_state()
679 spin_lock_init(&state->state_lock); in nfs4_alloc_open_state()
680 seqlock_init(&state->seqlock); in nfs4_alloc_open_state()
681 init_waitqueue_head(&state->waitq); in nfs4_alloc_open_state()
682 return state; in nfs4_alloc_open_state()
686 nfs4_state_set_mode_locked(struct nfs4_state *state, fmode_t fmode) in nfs4_state_set_mode_locked() argument
688 if (state->state == fmode) in nfs4_state_set_mode_locked()
691 if ((fmode & FMODE_WRITE) != (state->state & FMODE_WRITE)) { in nfs4_state_set_mode_locked()
693 list_move(&state->open_states, &state->owner->so_states); in nfs4_state_set_mode_locked()
695 list_move_tail(&state->open_states, &state->owner->so_states); in nfs4_state_set_mode_locked()
697 state->state = fmode; in nfs4_state_set_mode_locked()
704 struct nfs4_state *state; in __nfs4_find_state_byowner() local
706 list_for_each_entry_rcu(state, &nfsi->open_states, inode_states) { in __nfs4_find_state_byowner()
707 if (state->owner != owner) in __nfs4_find_state_byowner()
709 if (!nfs4_valid_open_stateid(state)) in __nfs4_find_state_byowner()
711 if (refcount_inc_not_zero(&state->count)) in __nfs4_find_state_byowner()
712 return state; in __nfs4_find_state_byowner()
718 nfs4_free_open_state(struct nfs4_state *state) in nfs4_free_open_state() argument
720 kfree_rcu(state, rcu_head); in nfs4_free_open_state()
726 struct nfs4_state *state, *new; in nfs4_get_open_state() local
730 state = __nfs4_find_state_byowner(inode, owner); in nfs4_get_open_state()
732 if (state) in nfs4_get_open_state()
737 state = __nfs4_find_state_byowner(inode, owner); in nfs4_get_open_state()
738 if (state == NULL && new != NULL) { in nfs4_get_open_state()
739 state = new; in nfs4_get_open_state()
740 state->owner = owner; in nfs4_get_open_state()
743 state->inode = inode; in nfs4_get_open_state()
744 list_add_rcu(&state->inode_states, &nfsi->open_states); in nfs4_get_open_state()
748 list_add_tail(&state->open_states, &owner->so_states); in nfs4_get_open_state()
757 return state; in nfs4_get_open_state()
760 void nfs4_put_open_state(struct nfs4_state *state) in nfs4_put_open_state() argument
762 struct inode *inode = state->inode; in nfs4_put_open_state()
763 struct nfs4_state_owner *owner = state->owner; in nfs4_put_open_state()
765 if (!refcount_dec_and_lock(&state->count, &owner->so_lock)) in nfs4_put_open_state()
768 list_del_rcu(&state->inode_states); in nfs4_put_open_state()
769 list_del(&state->open_states); in nfs4_put_open_state()
774 nfs4_free_open_state(state); in nfs4_put_open_state()
781 static void __nfs4_close(struct nfs4_state *state, in __nfs4_close() argument
784 struct nfs4_state_owner *owner = state->owner; in __nfs4_close()
793 state->n_rdonly--; in __nfs4_close()
796 state->n_wronly--; in __nfs4_close()
799 state->n_rdwr--; in __nfs4_close()
802 if (state->n_rdwr == 0) { in __nfs4_close()
803 if (state->n_rdonly == 0) { in __nfs4_close()
805 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); in __nfs4_close()
806 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); in __nfs4_close()
808 if (state->n_wronly == 0) { in __nfs4_close()
810 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); in __nfs4_close()
811 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); in __nfs4_close()
814 clear_bit(NFS_DELEGATED_STATE, &state->flags); in __nfs4_close()
816 nfs4_state_set_mode_locked(state, newstate); in __nfs4_close()
820 nfs4_put_open_state(state); in __nfs4_close()
823 nfs4_do_close(state, gfp_mask, wait); in __nfs4_close()
826 void nfs4_close_state(struct nfs4_state *state, fmode_t fmode) in nfs4_close_state() argument
828 __nfs4_close(state, fmode, GFP_NOFS, 0); in nfs4_close_state()
831 void nfs4_close_sync(struct nfs4_state *state, fmode_t fmode) in nfs4_close_sync() argument
833 __nfs4_close(state, fmode, GFP_KERNEL, 1); in nfs4_close_sync()
850 __nfs4_find_lock_state(struct nfs4_state *state, in __nfs4_find_lock_state() argument
854 list_for_each_entry(pos, &state->lock_states, ls_locks) { in __nfs4_find_lock_state()
872 static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) in nfs4_alloc_lock_state() argument
875 struct nfs_server *server = state->owner->so_server; in nfs4_alloc_lock_state()
882 lsp->ls_state = state; in nfs4_alloc_lock_state()
906 static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner) in nfs4_get_lock_state() argument
911 spin_lock(&state->state_lock); in nfs4_get_lock_state()
912 lsp = __nfs4_find_lock_state(state, owner, NULL); in nfs4_get_lock_state()
916 list_add(&new->ls_locks, &state->lock_states); in nfs4_get_lock_state()
917 set_bit(LK_STATE_IN_USE, &state->flags); in nfs4_get_lock_state()
922 spin_unlock(&state->state_lock); in nfs4_get_lock_state()
923 new = nfs4_alloc_lock_state(state, owner); in nfs4_get_lock_state()
927 spin_unlock(&state->state_lock); in nfs4_get_lock_state()
929 nfs4_free_lock_state(state->owner->so_server, new); in nfs4_get_lock_state()
940 struct nfs4_state *state; in nfs4_put_lock_state() local
944 state = lsp->ls_state; in nfs4_put_lock_state()
945 if (!refcount_dec_and_lock(&lsp->ls_count, &state->state_lock)) in nfs4_put_lock_state()
948 if (list_empty(&state->lock_states)) in nfs4_put_lock_state()
949 clear_bit(LK_STATE_IN_USE, &state->flags); in nfs4_put_lock_state()
950 spin_unlock(&state->state_lock); in nfs4_put_lock_state()
951 server = state->owner->so_server; in nfs4_put_lock_state()
978 int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl) in nfs4_set_lock_state() argument
984 lsp = nfs4_get_lock_state(state, fl->fl_owner); in nfs4_set_lock_state()
993 struct nfs4_state *state, in nfs4_copy_lock_stateid() argument
1003 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) in nfs4_copy_lock_stateid()
1009 spin_lock(&state->state_lock); in nfs4_copy_lock_stateid()
1010 lsp = __nfs4_find_lock_state(state, fl_owner, fl_flock_owner); in nfs4_copy_lock_stateid()
1017 spin_unlock(&state->state_lock); in nfs4_copy_lock_stateid()
1023 bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) in nfs4_copy_open_stateid() argument
1032 seq = read_seqbegin(&state->seqlock); in nfs4_copy_open_stateid()
1033 if (test_bit(NFS_OPEN_STATE, &state->flags)) { in nfs4_copy_open_stateid()
1034 src = &state->open_stateid; in nfs4_copy_open_stateid()
1038 } while (read_seqretry(&state->seqlock, seq)); in nfs4_copy_open_stateid()
1046 int nfs4_select_rw_stateid(struct nfs4_state *state, in nfs4_select_rw_stateid() argument
1052 if (!nfs4_valid_open_stateid(state)) in nfs4_select_rw_stateid()
1056 ret = nfs4_copy_lock_stateid(dst, state, l_ctx); in nfs4_select_rw_stateid()
1061 if (nfs4_copy_delegation_stateid(state->inode, fmode, dst, cred)) { in nfs4_select_rw_stateid()
1071 ret = nfs4_copy_open_stateid(dst, state) ? 0 : -EAGAIN; in nfs4_select_rw_stateid()
1073 if (nfs_server_capable(state->inode, NFS_CAP_STATEID_NFSV41)) in nfs4_select_rw_stateid()
1381 static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state) in nfs4_state_mark_reclaim_reboot() argument
1384 if (!nfs4_valid_open_stateid(state)) in nfs4_state_mark_reclaim_reboot()
1386 set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_reboot()
1388 if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) { in nfs4_state_mark_reclaim_reboot()
1389 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_reboot()
1392 set_bit(NFS_OWNER_RECLAIM_REBOOT, &state->owner->so_flags); in nfs4_state_mark_reclaim_reboot()
1397 int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state) in nfs4_state_mark_reclaim_nograce() argument
1399 if (!nfs4_valid_open_stateid(state)) in nfs4_state_mark_reclaim_nograce()
1401 set_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags); in nfs4_state_mark_reclaim_nograce()
1402 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_nograce()
1403 set_bit(NFS_OWNER_RECLAIM_NOGRACE, &state->owner->so_flags); in nfs4_state_mark_reclaim_nograce()
1408 int nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_state *state) in nfs4_schedule_stateid_recovery() argument
1412 if (!nfs4_state_mark_reclaim_nograce(clp, state)) in nfs4_schedule_stateid_recovery()
1414 nfs_inode_find_delegation_state_and_recover(state->inode, in nfs4_schedule_stateid_recovery()
1415 &state->stateid); in nfs4_schedule_stateid_recovery()
1424 nfs_state_find_lock_state_by_stateid(struct nfs4_state *state, in nfs_state_find_lock_state_by_stateid() argument
1429 list_for_each_entry(pos, &state->lock_states, ls_locks) { in nfs_state_find_lock_state_by_stateid()
1438 static bool nfs_state_lock_state_matches_stateid(struct nfs4_state *state, in nfs_state_lock_state_matches_stateid() argument
1443 if (test_bit(LK_STATE_IN_USE, &state->flags)) { in nfs_state_lock_state_matches_stateid()
1444 spin_lock(&state->state_lock); in nfs_state_lock_state_matches_stateid()
1445 if (nfs_state_find_lock_state_by_stateid(state, stateid)) in nfs_state_lock_state_matches_stateid()
1447 spin_unlock(&state->state_lock); in nfs_state_lock_state_matches_stateid()
1458 struct nfs4_state *state; in nfs_inode_find_state_and_recover() local
1463 state = ctx->state; in nfs_inode_find_state_and_recover()
1464 if (state == NULL) in nfs_inode_find_state_and_recover()
1466 if (nfs4_stateid_match_or_older(&state->stateid, stateid) && in nfs_inode_find_state_and_recover()
1467 nfs4_state_mark_reclaim_nograce(clp, state)) { in nfs_inode_find_state_and_recover()
1471 if (test_bit(NFS_OPEN_STATE, &state->flags) && in nfs_inode_find_state_and_recover()
1472 nfs4_stateid_match_or_older(&state->open_stateid, stateid) && in nfs_inode_find_state_and_recover()
1473 nfs4_state_mark_reclaim_nograce(clp, state)) { in nfs_inode_find_state_and_recover()
1477 if (nfs_state_lock_state_matches_stateid(state, stateid) && in nfs_inode_find_state_and_recover()
1478 nfs4_state_mark_reclaim_nograce(clp, state)) in nfs_inode_find_state_and_recover()
1488 static void nfs4_state_mark_open_context_bad(struct nfs4_state *state, int err) in nfs4_state_mark_open_context_bad() argument
1490 struct inode *inode = state->inode; in nfs4_state_mark_open_context_bad()
1496 if (ctx->state != state) in nfs4_state_mark_open_context_bad()
1505 static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error) in nfs4_state_mark_recovery_failed() argument
1507 set_bit(NFS_STATE_RECOVERY_FAILED, &state->flags); in nfs4_state_mark_recovery_failed()
1508 nfs4_state_mark_open_context_bad(state, error); in nfs4_state_mark_recovery_failed()
1512 static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops) in nfs4_reclaim_locks() argument
1514 struct inode *inode = state->inode; in nfs4_reclaim_locks()
1532 if (nfs_file_open_context(fl->fl_file)->state != state) in nfs4_reclaim_locks()
1535 status = ops->recover_lock(state, fl); in nfs4_reclaim_locks()
1578 static void nfs42_complete_copies(struct nfs4_state_owner *sp, struct nfs4_state *state) in nfs42_complete_copies() argument
1582 if (!test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) && in nfs42_complete_copies()
1583 !test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags)) in nfs42_complete_copies()
1588 if ((test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) && in nfs42_complete_copies()
1589 !nfs4_stateid_match_other(&state->stateid, in nfs42_complete_copies()
1594 &state->flags)) { in nfs42_complete_copies()
1595 clear_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags); in nfs42_complete_copies()
1600 if ((test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags) && in nfs42_complete_copies()
1601 !nfs4_stateid_match_other(&state->stateid, in nfs42_complete_copies()
1606 &state->flags)) in nfs42_complete_copies()
1613 struct nfs4_state *state) in nfs42_complete_copies() argument
1618 static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_state *state, in __nfs4_reclaim_open_state() argument
1624 status = ops->recover_open(sp, state); in __nfs4_reclaim_open_state()
1628 status = nfs4_reclaim_locks(state, ops); in __nfs4_reclaim_open_state()
1632 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) { in __nfs4_reclaim_open_state()
1633 spin_lock(&state->state_lock); in __nfs4_reclaim_open_state()
1634 list_for_each_entry(lock, &state->lock_states, ls_locks) { in __nfs4_reclaim_open_state()
1635 trace_nfs4_state_lock_reclaim(state, lock); in __nfs4_reclaim_open_state()
1639 spin_unlock(&state->state_lock); in __nfs4_reclaim_open_state()
1642 nfs42_complete_copies(sp, state); in __nfs4_reclaim_open_state()
1643 clear_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags); in __nfs4_reclaim_open_state()
1649 struct nfs4_state *state; in nfs4_reclaim_open_state() local
1667 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_reclaim_open_state()
1668 if (!test_and_clear_bit(ops->state_flag_bit, &state->flags)) in nfs4_reclaim_open_state()
1670 if (!nfs4_valid_open_stateid(state)) in nfs4_reclaim_open_state()
1672 if (state->state == 0) in nfs4_reclaim_open_state()
1675 if (test_bit(NFS_SRV_SSC_COPY_STATE, &state->flags)) { in nfs4_reclaim_open_state()
1676 nfs4_state_mark_recovery_failed(state, -EIO); in nfs4_reclaim_open_state()
1681 refcount_inc(&state->count); in nfs4_reclaim_open_state()
1683 status = __nfs4_reclaim_open_state(sp, state, ops); in nfs4_reclaim_open_state()
1700 nfs4_state_mark_recovery_failed(state, status); in nfs4_reclaim_open_state()
1705 set_bit(ops->state_flag_bit, &state->flags); in nfs4_reclaim_open_state()
1715 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); in nfs4_reclaim_open_state()
1719 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); in nfs4_reclaim_open_state()
1729 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1741 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1748 static void nfs4_clear_open_state(struct nfs4_state *state) in nfs4_clear_open_state() argument
1752 clear_bit(NFS_DELEGATED_STATE, &state->flags); in nfs4_clear_open_state()
1753 clear_bit(NFS_O_RDONLY_STATE, &state->flags); in nfs4_clear_open_state()
1754 clear_bit(NFS_O_WRONLY_STATE, &state->flags); in nfs4_clear_open_state()
1755 clear_bit(NFS_O_RDWR_STATE, &state->flags); in nfs4_clear_open_state()
1756 spin_lock(&state->state_lock); in nfs4_clear_open_state()
1757 list_for_each_entry(lock, &state->lock_states, ls_locks) { in nfs4_clear_open_state()
1761 spin_unlock(&state->state_lock); in nfs4_clear_open_state()
1765 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) in nfs4_reset_seqids() argument
1770 struct nfs4_state *state; in nfs4_reset_seqids() local
1779 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_reset_seqids()
1780 if (mark_reclaim(clp, state)) in nfs4_reset_seqids()
1781 nfs4_clear_open_state(state); in nfs4_reset_seqids()
1789 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) in nfs4_state_mark_reclaim_helper() argument
1822 struct nfs4_state *state; in nfs4_clear_reclaim_server() local
1830 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_clear_reclaim_server()
1832 &state->flags)) in nfs4_clear_reclaim_server()
1834 nfs4_state_mark_reclaim_nograce(clp, state); in nfs4_clear_reclaim_server()