Lines Matching refs:state
668 struct nfs4_state *state; in nfs4_alloc_open_state() local
670 state = kzalloc(sizeof(*state), GFP_NOFS); in nfs4_alloc_open_state()
671 if (!state) in nfs4_alloc_open_state()
673 refcount_set(&state->count, 1); in nfs4_alloc_open_state()
674 INIT_LIST_HEAD(&state->lock_states); in nfs4_alloc_open_state()
675 spin_lock_init(&state->state_lock); in nfs4_alloc_open_state()
676 seqlock_init(&state->seqlock); in nfs4_alloc_open_state()
677 init_waitqueue_head(&state->waitq); in nfs4_alloc_open_state()
678 return state; in nfs4_alloc_open_state()
682 nfs4_state_set_mode_locked(struct nfs4_state *state, fmode_t fmode) in nfs4_state_set_mode_locked() argument
684 if (state->state == fmode) in nfs4_state_set_mode_locked()
687 if ((fmode & FMODE_WRITE) != (state->state & FMODE_WRITE)) { in nfs4_state_set_mode_locked()
689 list_move(&state->open_states, &state->owner->so_states); in nfs4_state_set_mode_locked()
691 list_move_tail(&state->open_states, &state->owner->so_states); in nfs4_state_set_mode_locked()
693 state->state = fmode; in nfs4_state_set_mode_locked()
700 struct nfs4_state *state; in __nfs4_find_state_byowner() local
702 list_for_each_entry_rcu(state, &nfsi->open_states, inode_states) { in __nfs4_find_state_byowner()
703 if (state->owner != owner) in __nfs4_find_state_byowner()
705 if (!nfs4_valid_open_stateid(state)) in __nfs4_find_state_byowner()
707 if (refcount_inc_not_zero(&state->count)) in __nfs4_find_state_byowner()
708 return state; in __nfs4_find_state_byowner()
714 nfs4_free_open_state(struct nfs4_state *state) in nfs4_free_open_state() argument
716 kfree_rcu(state, rcu_head); in nfs4_free_open_state()
722 struct nfs4_state *state, *new; in nfs4_get_open_state() local
726 state = __nfs4_find_state_byowner(inode, owner); in nfs4_get_open_state()
728 if (state) in nfs4_get_open_state()
733 state = __nfs4_find_state_byowner(inode, owner); in nfs4_get_open_state()
734 if (state == NULL && new != NULL) { in nfs4_get_open_state()
735 state = new; in nfs4_get_open_state()
736 state->owner = owner; in nfs4_get_open_state()
738 list_add_rcu(&state->inode_states, &nfsi->open_states); in nfs4_get_open_state()
740 state->inode = inode; in nfs4_get_open_state()
744 list_add_tail(&state->open_states, &owner->so_states); in nfs4_get_open_state()
753 return state; in nfs4_get_open_state()
756 void nfs4_put_open_state(struct nfs4_state *state) in nfs4_put_open_state() argument
758 struct inode *inode = state->inode; in nfs4_put_open_state()
759 struct nfs4_state_owner *owner = state->owner; in nfs4_put_open_state()
761 if (!refcount_dec_and_lock(&state->count, &owner->so_lock)) in nfs4_put_open_state()
764 list_del_rcu(&state->inode_states); in nfs4_put_open_state()
765 list_del(&state->open_states); in nfs4_put_open_state()
769 nfs4_free_open_state(state); in nfs4_put_open_state()
776 static void __nfs4_close(struct nfs4_state *state, in __nfs4_close() argument
779 struct nfs4_state_owner *owner = state->owner; in __nfs4_close()
788 state->n_rdonly--; in __nfs4_close()
791 state->n_wronly--; in __nfs4_close()
794 state->n_rdwr--; in __nfs4_close()
797 if (state->n_rdwr == 0) { in __nfs4_close()
798 if (state->n_rdonly == 0) { in __nfs4_close()
800 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); in __nfs4_close()
801 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); in __nfs4_close()
803 if (state->n_wronly == 0) { in __nfs4_close()
805 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); in __nfs4_close()
806 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); in __nfs4_close()
809 clear_bit(NFS_DELEGATED_STATE, &state->flags); in __nfs4_close()
811 nfs4_state_set_mode_locked(state, newstate); in __nfs4_close()
815 nfs4_put_open_state(state); in __nfs4_close()
818 nfs4_do_close(state, gfp_mask, wait); in __nfs4_close()
821 void nfs4_close_state(struct nfs4_state *state, fmode_t fmode) in nfs4_close_state() argument
823 __nfs4_close(state, fmode, GFP_NOFS, 0); in nfs4_close_state()
826 void nfs4_close_sync(struct nfs4_state *state, fmode_t fmode) in nfs4_close_sync() argument
828 __nfs4_close(state, fmode, GFP_KERNEL, 1); in nfs4_close_sync()
845 __nfs4_find_lock_state(struct nfs4_state *state, in __nfs4_find_lock_state() argument
849 list_for_each_entry(pos, &state->lock_states, ls_locks) { in __nfs4_find_lock_state()
867 static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) in nfs4_alloc_lock_state() argument
870 struct nfs_server *server = state->owner->so_server; in nfs4_alloc_lock_state()
877 lsp->ls_state = state; in nfs4_alloc_lock_state()
901 static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner) in nfs4_get_lock_state() argument
906 spin_lock(&state->state_lock); in nfs4_get_lock_state()
907 lsp = __nfs4_find_lock_state(state, owner, NULL); in nfs4_get_lock_state()
911 list_add(&new->ls_locks, &state->lock_states); in nfs4_get_lock_state()
912 set_bit(LK_STATE_IN_USE, &state->flags); in nfs4_get_lock_state()
917 spin_unlock(&state->state_lock); in nfs4_get_lock_state()
918 new = nfs4_alloc_lock_state(state, owner); in nfs4_get_lock_state()
922 spin_unlock(&state->state_lock); in nfs4_get_lock_state()
924 nfs4_free_lock_state(state->owner->so_server, new); in nfs4_get_lock_state()
935 struct nfs4_state *state; in nfs4_put_lock_state() local
939 state = lsp->ls_state; in nfs4_put_lock_state()
940 if (!refcount_dec_and_lock(&lsp->ls_count, &state->state_lock)) in nfs4_put_lock_state()
943 if (list_empty(&state->lock_states)) in nfs4_put_lock_state()
944 clear_bit(LK_STATE_IN_USE, &state->flags); in nfs4_put_lock_state()
945 spin_unlock(&state->state_lock); in nfs4_put_lock_state()
946 server = state->owner->so_server; in nfs4_put_lock_state()
973 int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl) in nfs4_set_lock_state() argument
979 lsp = nfs4_get_lock_state(state, fl->fl_owner); in nfs4_set_lock_state()
988 struct nfs4_state *state, in nfs4_copy_lock_stateid() argument
998 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) in nfs4_copy_lock_stateid()
1004 spin_lock(&state->state_lock); in nfs4_copy_lock_stateid()
1005 lsp = __nfs4_find_lock_state(state, fl_owner, fl_flock_owner); in nfs4_copy_lock_stateid()
1012 spin_unlock(&state->state_lock); in nfs4_copy_lock_stateid()
1018 bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) in nfs4_copy_open_stateid() argument
1027 seq = read_seqbegin(&state->seqlock); in nfs4_copy_open_stateid()
1028 if (test_bit(NFS_OPEN_STATE, &state->flags)) { in nfs4_copy_open_stateid()
1029 src = &state->open_stateid; in nfs4_copy_open_stateid()
1033 } while (read_seqretry(&state->seqlock, seq)); in nfs4_copy_open_stateid()
1041 int nfs4_select_rw_stateid(struct nfs4_state *state, in nfs4_select_rw_stateid() argument
1047 if (!nfs4_valid_open_stateid(state)) in nfs4_select_rw_stateid()
1051 ret = nfs4_copy_lock_stateid(dst, state, l_ctx); in nfs4_select_rw_stateid()
1056 if (nfs4_copy_delegation_stateid(state->inode, fmode, dst, cred)) { in nfs4_select_rw_stateid()
1066 ret = nfs4_copy_open_stateid(dst, state) ? 0 : -EAGAIN; in nfs4_select_rw_stateid()
1068 if (nfs_server_capable(state->inode, NFS_CAP_STATEID_NFSV41)) in nfs4_select_rw_stateid()
1359 static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state) in nfs4_state_mark_reclaim_reboot() argument
1362 if (!nfs4_valid_open_stateid(state)) in nfs4_state_mark_reclaim_reboot()
1364 set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_reboot()
1366 if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) { in nfs4_state_mark_reclaim_reboot()
1367 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_reboot()
1370 set_bit(NFS_OWNER_RECLAIM_REBOOT, &state->owner->so_flags); in nfs4_state_mark_reclaim_reboot()
1375 int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state) in nfs4_state_mark_reclaim_nograce() argument
1377 if (!nfs4_valid_open_stateid(state)) in nfs4_state_mark_reclaim_nograce()
1379 set_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags); in nfs4_state_mark_reclaim_nograce()
1380 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_nograce()
1381 set_bit(NFS_OWNER_RECLAIM_NOGRACE, &state->owner->so_flags); in nfs4_state_mark_reclaim_nograce()
1386 int nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_state *state) in nfs4_schedule_stateid_recovery() argument
1390 if (!nfs4_state_mark_reclaim_nograce(clp, state)) in nfs4_schedule_stateid_recovery()
1392 nfs_inode_find_delegation_state_and_recover(state->inode, in nfs4_schedule_stateid_recovery()
1393 &state->stateid); in nfs4_schedule_stateid_recovery()
1402 nfs_state_find_lock_state_by_stateid(struct nfs4_state *state, in nfs_state_find_lock_state_by_stateid() argument
1407 list_for_each_entry(pos, &state->lock_states, ls_locks) { in nfs_state_find_lock_state_by_stateid()
1416 static bool nfs_state_lock_state_matches_stateid(struct nfs4_state *state, in nfs_state_lock_state_matches_stateid() argument
1421 if (test_bit(LK_STATE_IN_USE, &state->flags)) { in nfs_state_lock_state_matches_stateid()
1422 spin_lock(&state->state_lock); in nfs_state_lock_state_matches_stateid()
1423 if (nfs_state_find_lock_state_by_stateid(state, stateid)) in nfs_state_lock_state_matches_stateid()
1425 spin_unlock(&state->state_lock); in nfs_state_lock_state_matches_stateid()
1436 struct nfs4_state *state; in nfs_inode_find_state_and_recover() local
1441 state = ctx->state; in nfs_inode_find_state_and_recover()
1442 if (state == NULL) in nfs_inode_find_state_and_recover()
1444 if (nfs4_stateid_match_other(&state->stateid, stateid) && in nfs_inode_find_state_and_recover()
1445 nfs4_state_mark_reclaim_nograce(clp, state)) { in nfs_inode_find_state_and_recover()
1449 if (nfs4_stateid_match_other(&state->open_stateid, stateid) && in nfs_inode_find_state_and_recover()
1450 nfs4_state_mark_reclaim_nograce(clp, state)) { in nfs_inode_find_state_and_recover()
1454 if (nfs_state_lock_state_matches_stateid(state, stateid) && in nfs_inode_find_state_and_recover()
1455 nfs4_state_mark_reclaim_nograce(clp, state)) in nfs_inode_find_state_and_recover()
1465 static void nfs4_state_mark_open_context_bad(struct nfs4_state *state, int err) in nfs4_state_mark_open_context_bad() argument
1467 struct inode *inode = state->inode; in nfs4_state_mark_open_context_bad()
1473 if (ctx->state != state) in nfs4_state_mark_open_context_bad()
1482 static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error) in nfs4_state_mark_recovery_failed() argument
1484 set_bit(NFS_STATE_RECOVERY_FAILED, &state->flags); in nfs4_state_mark_recovery_failed()
1485 nfs4_state_mark_open_context_bad(state, error); in nfs4_state_mark_recovery_failed()
1489 static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops) in nfs4_reclaim_locks() argument
1491 struct inode *inode = state->inode; in nfs4_reclaim_locks()
1509 if (nfs_file_open_context(fl->fl_file)->state != state) in nfs4_reclaim_locks()
1512 status = ops->recover_lock(state, fl); in nfs4_reclaim_locks()
1555 static void nfs42_complete_copies(struct nfs4_state_owner *sp, struct nfs4_state *state) in nfs42_complete_copies() argument
1559 if (!test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags)) in nfs42_complete_copies()
1564 if (!nfs4_stateid_match_other(&state->stateid, ©->parent_state->stateid)) in nfs42_complete_copies()
1574 struct nfs4_state *state) in nfs42_complete_copies() argument
1579 static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_state *state, in __nfs4_reclaim_open_state() argument
1585 status = ops->recover_open(sp, state); in __nfs4_reclaim_open_state()
1589 status = nfs4_reclaim_locks(state, ops); in __nfs4_reclaim_open_state()
1593 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) { in __nfs4_reclaim_open_state()
1594 spin_lock(&state->state_lock); in __nfs4_reclaim_open_state()
1595 list_for_each_entry(lock, &state->lock_states, ls_locks) { in __nfs4_reclaim_open_state()
1599 spin_unlock(&state->state_lock); in __nfs4_reclaim_open_state()
1602 nfs42_complete_copies(sp, state); in __nfs4_reclaim_open_state()
1603 clear_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags); in __nfs4_reclaim_open_state()
1609 struct nfs4_state *state; in nfs4_reclaim_open_state() local
1624 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_reclaim_open_state()
1625 if (!test_and_clear_bit(ops->state_flag_bit, &state->flags)) in nfs4_reclaim_open_state()
1627 if (!nfs4_valid_open_stateid(state)) in nfs4_reclaim_open_state()
1629 if (state->state == 0) in nfs4_reclaim_open_state()
1631 refcount_inc(&state->count); in nfs4_reclaim_open_state()
1633 status = __nfs4_reclaim_open_state(sp, state, ops); in nfs4_reclaim_open_state()
1650 nfs4_state_mark_recovery_failed(state, status); in nfs4_reclaim_open_state()
1655 set_bit(ops->state_flag_bit, &state->flags); in nfs4_reclaim_open_state()
1665 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); in nfs4_reclaim_open_state()
1669 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); in nfs4_reclaim_open_state()
1679 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1687 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1694 static void nfs4_clear_open_state(struct nfs4_state *state) in nfs4_clear_open_state() argument
1698 clear_bit(NFS_DELEGATED_STATE, &state->flags); in nfs4_clear_open_state()
1699 clear_bit(NFS_O_RDONLY_STATE, &state->flags); in nfs4_clear_open_state()
1700 clear_bit(NFS_O_WRONLY_STATE, &state->flags); in nfs4_clear_open_state()
1701 clear_bit(NFS_O_RDWR_STATE, &state->flags); in nfs4_clear_open_state()
1702 spin_lock(&state->state_lock); in nfs4_clear_open_state()
1703 list_for_each_entry(lock, &state->lock_states, ls_locks) { in nfs4_clear_open_state()
1707 spin_unlock(&state->state_lock); in nfs4_clear_open_state()
1711 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) in nfs4_reset_seqids() argument
1716 struct nfs4_state *state; in nfs4_reset_seqids() local
1725 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_reset_seqids()
1726 if (mark_reclaim(clp, state)) in nfs4_reset_seqids()
1727 nfs4_clear_open_state(state); in nfs4_reset_seqids()
1735 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) in nfs4_state_mark_reclaim_helper() argument
1767 struct nfs4_state *state; in nfs4_clear_reclaim_server() local
1775 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_clear_reclaim_server()
1777 &state->flags)) in nfs4_clear_reclaim_server()
1779 nfs4_state_mark_reclaim_nograce(clp, state); in nfs4_clear_reclaim_server()