• 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_KERNEL, 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()
1382 static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state) in nfs4_state_mark_reclaim_reboot() argument
1385 if (!nfs4_valid_open_stateid(state)) in nfs4_state_mark_reclaim_reboot()
1387 set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_reboot()
1389 if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) { in nfs4_state_mark_reclaim_reboot()
1390 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_reboot()
1393 set_bit(NFS_OWNER_RECLAIM_REBOOT, &state->owner->so_flags); in nfs4_state_mark_reclaim_reboot()
1398 int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state) in nfs4_state_mark_reclaim_nograce() argument
1400 if (!nfs4_valid_open_stateid(state)) in nfs4_state_mark_reclaim_nograce()
1402 set_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags); in nfs4_state_mark_reclaim_nograce()
1403 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_nograce()
1404 set_bit(NFS_OWNER_RECLAIM_NOGRACE, &state->owner->so_flags); in nfs4_state_mark_reclaim_nograce()
1409 int nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_state *state) in nfs4_schedule_stateid_recovery() argument
1413 if (!nfs4_state_mark_reclaim_nograce(clp, state)) in nfs4_schedule_stateid_recovery()
1415 nfs_inode_find_delegation_state_and_recover(state->inode, in nfs4_schedule_stateid_recovery()
1416 &state->stateid); in nfs4_schedule_stateid_recovery()
1425 nfs_state_find_lock_state_by_stateid(struct nfs4_state *state, in nfs_state_find_lock_state_by_stateid() argument
1430 list_for_each_entry(pos, &state->lock_states, ls_locks) { in nfs_state_find_lock_state_by_stateid()
1439 static bool nfs_state_lock_state_matches_stateid(struct nfs4_state *state, in nfs_state_lock_state_matches_stateid() argument
1444 if (test_bit(LK_STATE_IN_USE, &state->flags)) { in nfs_state_lock_state_matches_stateid()
1445 spin_lock(&state->state_lock); in nfs_state_lock_state_matches_stateid()
1446 if (nfs_state_find_lock_state_by_stateid(state, stateid)) in nfs_state_lock_state_matches_stateid()
1448 spin_unlock(&state->state_lock); in nfs_state_lock_state_matches_stateid()
1459 struct nfs4_state *state; in nfs_inode_find_state_and_recover() local
1464 state = ctx->state; in nfs_inode_find_state_and_recover()
1465 if (state == NULL) in nfs_inode_find_state_and_recover()
1467 if (nfs4_stateid_match_or_older(&state->stateid, stateid) && in nfs_inode_find_state_and_recover()
1468 nfs4_state_mark_reclaim_nograce(clp, state)) { in nfs_inode_find_state_and_recover()
1472 if (test_bit(NFS_OPEN_STATE, &state->flags) && in nfs_inode_find_state_and_recover()
1473 nfs4_stateid_match_or_older(&state->open_stateid, stateid) && in nfs_inode_find_state_and_recover()
1474 nfs4_state_mark_reclaim_nograce(clp, state)) { in nfs_inode_find_state_and_recover()
1478 if (nfs_state_lock_state_matches_stateid(state, stateid) && in nfs_inode_find_state_and_recover()
1479 nfs4_state_mark_reclaim_nograce(clp, state)) in nfs_inode_find_state_and_recover()
1489 static void nfs4_state_mark_open_context_bad(struct nfs4_state *state, int err) in nfs4_state_mark_open_context_bad() argument
1491 struct inode *inode = state->inode; in nfs4_state_mark_open_context_bad()
1497 if (ctx->state != state) in nfs4_state_mark_open_context_bad()
1506 static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error) in nfs4_state_mark_recovery_failed() argument
1508 set_bit(NFS_STATE_RECOVERY_FAILED, &state->flags); in nfs4_state_mark_recovery_failed()
1509 nfs4_state_mark_open_context_bad(state, error); in nfs4_state_mark_recovery_failed()
1513 static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops) in nfs4_reclaim_locks() argument
1515 struct inode *inode = state->inode; in nfs4_reclaim_locks()
1533 if (nfs_file_open_context(fl->fl_file)->state != state) in nfs4_reclaim_locks()
1536 status = ops->recover_lock(state, fl); in nfs4_reclaim_locks()
1579 static void nfs42_complete_copies(struct nfs4_state_owner *sp, struct nfs4_state *state) in nfs42_complete_copies() argument
1583 if (!test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) && in nfs42_complete_copies()
1584 !test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags)) in nfs42_complete_copies()
1589 if ((test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) && in nfs42_complete_copies()
1590 !nfs4_stateid_match_other(&state->stateid, in nfs42_complete_copies()
1595 &state->flags)) { in nfs42_complete_copies()
1596 clear_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags); in nfs42_complete_copies()
1601 if ((test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags) && in nfs42_complete_copies()
1602 !nfs4_stateid_match_other(&state->stateid, in nfs42_complete_copies()
1607 &state->flags)) in nfs42_complete_copies()
1614 struct nfs4_state *state) in nfs42_complete_copies() argument
1619 static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_state *state, in __nfs4_reclaim_open_state() argument
1625 status = ops->recover_open(sp, state); in __nfs4_reclaim_open_state()
1629 status = nfs4_reclaim_locks(state, ops); in __nfs4_reclaim_open_state()
1633 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) { in __nfs4_reclaim_open_state()
1634 spin_lock(&state->state_lock); in __nfs4_reclaim_open_state()
1635 list_for_each_entry(lock, &state->lock_states, ls_locks) { in __nfs4_reclaim_open_state()
1636 trace_nfs4_state_lock_reclaim(state, lock); in __nfs4_reclaim_open_state()
1640 spin_unlock(&state->state_lock); in __nfs4_reclaim_open_state()
1643 nfs42_complete_copies(sp, state); in __nfs4_reclaim_open_state()
1644 clear_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags); in __nfs4_reclaim_open_state()
1650 struct nfs4_state *state; in nfs4_reclaim_open_state() local
1668 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_reclaim_open_state()
1669 if (!test_and_clear_bit(ops->state_flag_bit, &state->flags)) in nfs4_reclaim_open_state()
1671 if (!nfs4_valid_open_stateid(state)) in nfs4_reclaim_open_state()
1673 if (state->state == 0) in nfs4_reclaim_open_state()
1676 if (test_bit(NFS_SRV_SSC_COPY_STATE, &state->flags)) { in nfs4_reclaim_open_state()
1677 nfs4_state_mark_recovery_failed(state, -EIO); in nfs4_reclaim_open_state()
1682 refcount_inc(&state->count); in nfs4_reclaim_open_state()
1684 status = __nfs4_reclaim_open_state(sp, state, ops); in nfs4_reclaim_open_state()
1701 nfs4_state_mark_recovery_failed(state, status); in nfs4_reclaim_open_state()
1706 set_bit(ops->state_flag_bit, &state->flags); in nfs4_reclaim_open_state()
1716 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); in nfs4_reclaim_open_state()
1720 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); in nfs4_reclaim_open_state()
1730 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1742 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1749 static void nfs4_clear_open_state(struct nfs4_state *state) in nfs4_clear_open_state() argument
1753 clear_bit(NFS_DELEGATED_STATE, &state->flags); in nfs4_clear_open_state()
1754 clear_bit(NFS_O_RDONLY_STATE, &state->flags); in nfs4_clear_open_state()
1755 clear_bit(NFS_O_WRONLY_STATE, &state->flags); in nfs4_clear_open_state()
1756 clear_bit(NFS_O_RDWR_STATE, &state->flags); in nfs4_clear_open_state()
1757 spin_lock(&state->state_lock); in nfs4_clear_open_state()
1758 list_for_each_entry(lock, &state->lock_states, ls_locks) { in nfs4_clear_open_state()
1762 spin_unlock(&state->state_lock); in nfs4_clear_open_state()
1766 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) in nfs4_reset_seqids() argument
1771 struct nfs4_state *state; in nfs4_reset_seqids() local
1780 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_reset_seqids()
1781 if (mark_reclaim(clp, state)) in nfs4_reset_seqids()
1782 nfs4_clear_open_state(state); in nfs4_reset_seqids()
1790 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) in nfs4_state_mark_reclaim_helper() argument
1823 struct nfs4_state *state; in nfs4_clear_reclaim_server() local
1831 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_clear_reclaim_server()
1833 &state->flags)) in nfs4_clear_reclaim_server()
1835 nfs4_state_mark_reclaim_nograce(clp, state); in nfs4_clear_reclaim_server()