Lines Matching refs:state
475 struct nfs4_state *state = exception->state; in nfs4_do_handle_exception() local
485 if (stateid == NULL && state != NULL) in nfs4_do_handle_exception()
486 stateid = nfs4_recoverable_stateid(&state->stateid); in nfs4_do_handle_exception()
520 if (state == NULL) in nfs4_do_handle_exception()
522 ret = nfs4_schedule_stateid_recovery(server, state); in nfs4_do_handle_exception()
659 struct nfs4_state *state, long *timeout) in nfs4_async_handle_error() argument
662 .state = state, in nfs4_async_handle_error()
1472 if (p->state != NULL) in nfs4_opendata_free()
1473 nfs4_put_open_state(p->state); in nfs4_opendata_free()
1493 static bool nfs4_mode_match_open_stateid(struct nfs4_state *state, in nfs4_mode_match_open_stateid() argument
1498 return state->n_rdwr != 0; in nfs4_mode_match_open_stateid()
1500 return state->n_wronly != 0; in nfs4_mode_match_open_stateid()
1502 return state->n_rdonly != 0; in nfs4_mode_match_open_stateid()
1508 static int can_open_cached(struct nfs4_state *state, fmode_t mode, in can_open_cached() argument
1524 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 in can_open_cached()
1525 && state->n_rdonly != 0; in can_open_cached()
1528 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 in can_open_cached()
1529 && state->n_wronly != 0; in can_open_cached()
1532 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 in can_open_cached()
1533 && state->n_rdwr != 0; in can_open_cached()
1561 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) in update_open_stateflags() argument
1565 state->n_wronly++; in update_open_stateflags()
1568 state->n_rdonly++; in update_open_stateflags()
1571 state->n_rdwr++; in update_open_stateflags()
1573 nfs4_state_set_mode_locked(state, state->state | fmode); in update_open_stateflags()
1577 static bool nfs_open_stateid_recover_openmode(struct nfs4_state *state) in nfs_open_stateid_recover_openmode() argument
1579 if (state->n_rdonly && !test_bit(NFS_O_RDONLY_STATE, &state->flags)) in nfs_open_stateid_recover_openmode()
1581 if (state->n_wronly && !test_bit(NFS_O_WRONLY_STATE, &state->flags)) in nfs_open_stateid_recover_openmode()
1583 if (state->n_rdwr && !test_bit(NFS_O_RDWR_STATE, &state->flags)) in nfs_open_stateid_recover_openmode()
1589 static void nfs_state_log_update_open_stateid(struct nfs4_state *state) in nfs_state_log_update_open_stateid() argument
1591 if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) in nfs_state_log_update_open_stateid()
1592 wake_up_all(&state->waitq); in nfs_state_log_update_open_stateid()
1595 static void nfs_test_and_clear_all_open_stateid(struct nfs4_state *state) in nfs_test_and_clear_all_open_stateid() argument
1597 struct nfs_client *clp = state->owner->so_server->nfs_client; in nfs_test_and_clear_all_open_stateid()
1600 if (test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags) && state->n_rdonly) in nfs_test_and_clear_all_open_stateid()
1602 if (test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags) && state->n_wronly) in nfs_test_and_clear_all_open_stateid()
1604 if (test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags) && state->n_rdwr) in nfs_test_and_clear_all_open_stateid()
1607 nfs4_state_mark_reclaim_nograce(clp, state); in nfs_test_and_clear_all_open_stateid()
1620 static bool nfs_stateid_is_sequential(struct nfs4_state *state, in nfs_stateid_is_sequential() argument
1623 if (test_bit(NFS_OPEN_STATE, &state->flags)) { in nfs_stateid_is_sequential()
1625 if (nfs4_stateid_match_other(stateid, &state->open_stateid)) { in nfs_stateid_is_sequential()
1626 if (nfs4_stateid_is_next(&state->open_stateid, stateid)) in nfs_stateid_is_sequential()
1638 static void nfs_resync_open_stateid_locked(struct nfs4_state *state) in nfs_resync_open_stateid_locked() argument
1640 if (!(state->n_wronly || state->n_rdonly || state->n_rdwr)) in nfs_resync_open_stateid_locked()
1642 if (state->n_wronly) in nfs_resync_open_stateid_locked()
1643 set_bit(NFS_O_WRONLY_STATE, &state->flags); in nfs_resync_open_stateid_locked()
1644 if (state->n_rdonly) in nfs_resync_open_stateid_locked()
1645 set_bit(NFS_O_RDONLY_STATE, &state->flags); in nfs_resync_open_stateid_locked()
1646 if (state->n_rdwr) in nfs_resync_open_stateid_locked()
1647 set_bit(NFS_O_RDWR_STATE, &state->flags); in nfs_resync_open_stateid_locked()
1648 set_bit(NFS_OPEN_STATE, &state->flags); in nfs_resync_open_stateid_locked()
1651 static void nfs_clear_open_stateid_locked(struct nfs4_state *state, in nfs_clear_open_stateid_locked() argument
1654 clear_bit(NFS_O_RDWR_STATE, &state->flags); in nfs_clear_open_stateid_locked()
1657 clear_bit(NFS_O_RDONLY_STATE, &state->flags); in nfs_clear_open_stateid_locked()
1660 clear_bit(NFS_O_WRONLY_STATE, &state->flags); in nfs_clear_open_stateid_locked()
1663 clear_bit(NFS_O_RDONLY_STATE, &state->flags); in nfs_clear_open_stateid_locked()
1664 clear_bit(NFS_O_WRONLY_STATE, &state->flags); in nfs_clear_open_stateid_locked()
1665 clear_bit(NFS_OPEN_STATE, &state->flags); in nfs_clear_open_stateid_locked()
1670 if (nfs4_stateid_match_other(stateid, &state->open_stateid) && in nfs_clear_open_stateid_locked()
1671 !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { in nfs_clear_open_stateid_locked()
1672 nfs_resync_open_stateid_locked(state); in nfs_clear_open_stateid_locked()
1675 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) in nfs_clear_open_stateid_locked()
1676 nfs4_stateid_copy(&state->stateid, stateid); in nfs_clear_open_stateid_locked()
1677 nfs4_stateid_copy(&state->open_stateid, stateid); in nfs_clear_open_stateid_locked()
1678 trace_nfs4_open_stateid_update(state->inode, stateid, 0); in nfs_clear_open_stateid_locked()
1680 nfs_state_log_update_open_stateid(state); in nfs_clear_open_stateid_locked()
1683 static void nfs_clear_open_stateid(struct nfs4_state *state, in nfs_clear_open_stateid() argument
1687 write_seqlock(&state->seqlock); in nfs_clear_open_stateid()
1689 if (nfs4_state_match_open_stateid_other(state, arg_stateid)) in nfs_clear_open_stateid()
1690 nfs_clear_open_stateid_locked(state, stateid, fmode); in nfs_clear_open_stateid()
1691 write_sequnlock(&state->seqlock); in nfs_clear_open_stateid()
1692 if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) in nfs_clear_open_stateid()
1693 nfs4_schedule_state_manager(state->owner->so_server->nfs_client); in nfs_clear_open_stateid()
1696 static void nfs_set_open_stateid_locked(struct nfs4_state *state, in nfs_set_open_stateid_locked() argument
1698 __must_hold(&state->owner->so_lock) in nfs_set_open_stateid_locked()
1699 __must_hold(&state->seqlock) in nfs_set_open_stateid_locked()
1707 if (nfs_stateid_is_sequential(state, stateid)) in nfs_set_open_stateid_locked()
1713 if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) in nfs_set_open_stateid_locked()
1716 set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); in nfs_set_open_stateid_locked()
1717 prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); in nfs_set_open_stateid_locked()
1723 write_sequnlock(&state->seqlock); in nfs_set_open_stateid_locked()
1724 spin_unlock(&state->owner->so_lock); in nfs_set_open_stateid_locked()
1726 trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); in nfs_set_open_stateid_locked()
1735 finish_wait(&state->waitq, &wait); in nfs_set_open_stateid_locked()
1737 spin_lock(&state->owner->so_lock); in nfs_set_open_stateid_locked()
1738 write_seqlock(&state->seqlock); in nfs_set_open_stateid_locked()
1741 if (test_bit(NFS_OPEN_STATE, &state->flags) && in nfs_set_open_stateid_locked()
1742 !nfs4_stateid_match_other(stateid, &state->open_stateid)) { in nfs_set_open_stateid_locked()
1743 nfs4_stateid_copy(freeme, &state->open_stateid); in nfs_set_open_stateid_locked()
1744 nfs_test_and_clear_all_open_stateid(state); in nfs_set_open_stateid_locked()
1747 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) in nfs_set_open_stateid_locked()
1748 nfs4_stateid_copy(&state->stateid, stateid); in nfs_set_open_stateid_locked()
1749 nfs4_stateid_copy(&state->open_stateid, stateid); in nfs_set_open_stateid_locked()
1750 trace_nfs4_open_stateid_update(state->inode, stateid, status); in nfs_set_open_stateid_locked()
1751 nfs_state_log_update_open_stateid(state); in nfs_set_open_stateid_locked()
1754 static void nfs_state_set_open_stateid(struct nfs4_state *state, in nfs_state_set_open_stateid() argument
1763 write_seqlock(&state->seqlock); in nfs_state_set_open_stateid()
1764 nfs_set_open_stateid_locked(state, open_stateid, freeme); in nfs_state_set_open_stateid()
1767 set_bit(NFS_O_RDONLY_STATE, &state->flags); in nfs_state_set_open_stateid()
1770 set_bit(NFS_O_WRONLY_STATE, &state->flags); in nfs_state_set_open_stateid()
1773 set_bit(NFS_O_RDWR_STATE, &state->flags); in nfs_state_set_open_stateid()
1775 set_bit(NFS_OPEN_STATE, &state->flags); in nfs_state_set_open_stateid()
1776 write_sequnlock(&state->seqlock); in nfs_state_set_open_stateid()
1779 static void nfs_state_clear_open_state_flags(struct nfs4_state *state) in nfs_state_clear_open_state_flags() argument
1781 clear_bit(NFS_O_RDWR_STATE, &state->flags); in nfs_state_clear_open_state_flags()
1782 clear_bit(NFS_O_WRONLY_STATE, &state->flags); in nfs_state_clear_open_state_flags()
1783 clear_bit(NFS_O_RDONLY_STATE, &state->flags); in nfs_state_clear_open_state_flags()
1784 clear_bit(NFS_OPEN_STATE, &state->flags); in nfs_state_clear_open_state_flags()
1787 static void nfs_state_set_delegation(struct nfs4_state *state, in nfs_state_set_delegation() argument
1795 write_seqlock(&state->seqlock); in nfs_state_set_delegation()
1796 nfs4_stateid_copy(&state->stateid, deleg_stateid); in nfs_state_set_delegation()
1797 set_bit(NFS_DELEGATED_STATE, &state->flags); in nfs_state_set_delegation()
1798 write_sequnlock(&state->seqlock); in nfs_state_set_delegation()
1801 static void nfs_state_clear_delegation(struct nfs4_state *state) in nfs_state_clear_delegation() argument
1803 write_seqlock(&state->seqlock); in nfs_state_clear_delegation()
1804 nfs4_stateid_copy(&state->stateid, &state->open_stateid); in nfs_state_clear_delegation()
1805 clear_bit(NFS_DELEGATED_STATE, &state->flags); in nfs_state_clear_delegation()
1806 write_sequnlock(&state->seqlock); in nfs_state_clear_delegation()
1809 int update_open_stateid(struct nfs4_state *state, in update_open_stateid() argument
1814 struct nfs_server *server = NFS_SERVER(state->inode); in update_open_stateid()
1816 struct nfs_inode *nfsi = NFS_I(state->inode); in update_open_stateid()
1824 spin_lock(&state->owner->so_lock); in update_open_stateid()
1826 nfs_state_set_open_stateid(state, open_stateid, fmode, &freeme); in update_open_stateid()
1830 deleg_cur = nfs4_get_valid_delegation(state->inode); in update_open_stateid()
1846 nfs_state_set_delegation(state, &deleg_cur->stateid, fmode); in update_open_stateid()
1852 update_open_stateflags(state, fmode); in update_open_stateid()
1853 spin_unlock(&state->owner->so_lock); in update_open_stateid()
1856 if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) in update_open_stateid()
1860 state->owner->so_cred); in update_open_stateid()
1868 struct nfs4_state *state = lsp->ls_state; in nfs4_update_lock_stateid() local
1871 spin_lock(&state->state_lock); in nfs4_update_lock_stateid()
1879 spin_unlock(&state->state_lock); in nfs4_update_lock_stateid()
1900 struct nfs4_state *state = opendata->state; in nfs4_try_open_cached() local
1909 spin_lock(&state->owner->so_lock); in nfs4_try_open_cached()
1910 if (can_open_cached(state, fmode, open_mode, claim)) { in nfs4_try_open_cached()
1911 update_open_stateflags(state, fmode); in nfs4_try_open_cached()
1912 spin_unlock(&state->owner->so_lock); in nfs4_try_open_cached()
1915 spin_unlock(&state->owner->so_lock); in nfs4_try_open_cached()
1917 delegation = nfs4_get_valid_delegation(state->inode); in nfs4_try_open_cached()
1927 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); in nfs4_try_open_cached()
1934 if (update_open_stateid(state, NULL, &stateid, fmode)) in nfs4_try_open_cached()
1940 refcount_inc(&state->count); in nfs4_try_open_cached()
1941 return state; in nfs4_try_open_cached()
1945 nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) in nfs4_opendata_check_deleg() argument
1947 struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; in nfs4_opendata_check_deleg()
1952 delegation = rcu_dereference(NFS_I(state->inode)->delegation); in nfs4_opendata_check_deleg()
1968 nfs_inode_set_delegation(state->inode, in nfs4_opendata_check_deleg()
1974 nfs_inode_reclaim_delegation(state->inode, in nfs4_opendata_check_deleg()
1981 nfs_async_inode_return_delegation(state->inode, in nfs4_opendata_check_deleg()
1992 struct inode *inode = data->state->inode; in _nfs4_opendata_reclaim_to_nfs4_state()
1993 struct nfs4_state *state = data->state; in _nfs4_opendata_reclaim_to_nfs4_state() local
2007 nfs4_opendata_check_deleg(data, state); in _nfs4_opendata_reclaim_to_nfs4_state()
2009 if (!update_open_stateid(state, &data->o_res.stateid, in _nfs4_opendata_reclaim_to_nfs4_state()
2012 refcount_inc(&state->count); in _nfs4_opendata_reclaim_to_nfs4_state()
2014 return state; in _nfs4_opendata_reclaim_to_nfs4_state()
2042 struct nfs4_state *state; in nfs4_opendata_find_nfs4_state() local
2048 if (data->state != NULL && data->state->inode == inode) { in nfs4_opendata_find_nfs4_state()
2049 state = data->state; in nfs4_opendata_find_nfs4_state()
2050 refcount_inc(&state->count); in nfs4_opendata_find_nfs4_state()
2052 state = nfs4_get_open_state(inode, data->owner); in nfs4_opendata_find_nfs4_state()
2054 if (state == NULL) in nfs4_opendata_find_nfs4_state()
2055 state = ERR_PTR(-ENOMEM); in nfs4_opendata_find_nfs4_state()
2056 return state; in nfs4_opendata_find_nfs4_state()
2062 struct nfs4_state *state; in _nfs4_opendata_to_nfs4_state() local
2065 state = nfs4_try_open_cached(data); in _nfs4_opendata_to_nfs4_state()
2066 trace_nfs4_cached_open(data->state); in _nfs4_opendata_to_nfs4_state()
2070 state = nfs4_opendata_find_nfs4_state(data); in _nfs4_opendata_to_nfs4_state()
2071 if (IS_ERR(state)) in _nfs4_opendata_to_nfs4_state()
2075 nfs4_opendata_check_deleg(data, state); in _nfs4_opendata_to_nfs4_state()
2076 if (!update_open_stateid(state, &data->o_res.stateid, in _nfs4_opendata_to_nfs4_state()
2078 nfs4_put_open_state(state); in _nfs4_opendata_to_nfs4_state()
2079 state = ERR_PTR(-EAGAIN); in _nfs4_opendata_to_nfs4_state()
2083 return state; in _nfs4_opendata_to_nfs4_state()
2100 nfs4_state_find_open_context_mode(struct nfs4_state *state, fmode_t mode) in nfs4_state_find_open_context_mode() argument
2102 struct nfs_inode *nfsi = NFS_I(state->inode); in nfs4_state_find_open_context_mode()
2107 if (ctx->state != state) in nfs4_state_find_open_context_mode()
2121 nfs4_state_find_open_context(struct nfs4_state *state) in nfs4_state_find_open_context() argument
2125 ctx = nfs4_state_find_open_context_mode(state, FMODE_READ|FMODE_WRITE); in nfs4_state_find_open_context()
2128 ctx = nfs4_state_find_open_context_mode(state, FMODE_WRITE); in nfs4_state_find_open_context()
2131 return nfs4_state_find_open_context_mode(state, FMODE_READ); in nfs4_state_find_open_context()
2135 struct nfs4_state *state, enum open_claim_type4 claim) in nfs4_open_recoverdata_alloc() argument
2139 opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, in nfs4_open_recoverdata_alloc()
2143 opendata->state = state; in nfs4_open_recoverdata_alloc()
2144 refcount_inc(&state->count); in nfs4_open_recoverdata_alloc()
2156 if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) in nfs4_open_recover_helper()
2170 if (newstate != opendata->state) in nfs4_open_recover_helper()
2176 static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) in nfs4_open_recover() argument
2195 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && in nfs4_open_recover()
2196 !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { in nfs4_open_recover()
2197 write_seqlock(&state->seqlock); in nfs4_open_recover()
2198 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) in nfs4_open_recover()
2199 nfs4_stateid_copy(&state->stateid, &state->open_stateid); in nfs4_open_recover()
2200 write_sequnlock(&state->seqlock); in nfs4_open_recover()
2209 static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) in _nfs4_do_open_reclaim() argument
2216 opendata = nfs4_open_recoverdata_alloc(ctx, state, in _nfs4_do_open_reclaim()
2221 delegation = rcu_dereference(NFS_I(state->inode)->delegation); in _nfs4_do_open_reclaim()
2226 status = nfs4_open_recover(opendata, state); in _nfs4_do_open_reclaim()
2231 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) in nfs4_do_open_reclaim() argument
2233 struct nfs_server *server = NFS_SERVER(state->inode); in nfs4_do_open_reclaim()
2237 err = _nfs4_do_open_reclaim(ctx, state); in nfs4_do_open_reclaim()
2248 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) in nfs4_open_reclaim() argument
2253 ctx = nfs4_state_find_open_context(state); in nfs4_open_reclaim()
2256 clear_bit(NFS_DELEGATED_STATE, &state->flags); in nfs4_open_reclaim()
2257 nfs_state_clear_open_state_flags(state); in nfs4_open_reclaim()
2258 ret = nfs4_do_open_reclaim(ctx, state); in nfs4_open_reclaim()
2263 static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct nfs4_state *state,… in nfs4_handle_delegation_recall_error() argument
2298 nfs_inode_find_state_and_recover(state->inode, in nfs4_handle_delegation_recall_error()
2300 nfs4_schedule_stateid_recovery(server, state); in nfs4_handle_delegation_recall_error()
2319 struct nfs4_state *state, const nfs4_stateid *stateid) in nfs4_open_delegation_recall() argument
2321 struct nfs_server *server = NFS_SERVER(state->inode); in nfs4_open_delegation_recall()
2325 opendata = nfs4_open_recoverdata_alloc(ctx, state, in nfs4_open_delegation_recall()
2330 if (!test_bit(NFS_O_RDWR_STATE, &state->flags)) { in nfs4_open_delegation_recall()
2335 if (!test_bit(NFS_O_WRONLY_STATE, &state->flags)) { in nfs4_open_delegation_recall()
2340 if (!test_bit(NFS_O_RDONLY_STATE, &state->flags)) { in nfs4_open_delegation_recall()
2345 nfs_state_clear_delegation(state); in nfs4_open_delegation_recall()
2348 return nfs4_handle_delegation_recall_error(server, state, stateid, NULL, err); in nfs4_open_delegation_recall()
2377 struct nfs4_state *state = NULL; in nfs4_open_confirm_release() local
2385 state = nfs4_opendata_to_nfs4_state(data); in nfs4_open_confirm_release()
2386 if (!IS_ERR(state)) in nfs4_open_confirm_release()
2387 nfs4_close_state(state, data->o_arg.fmode); in nfs4_open_confirm_release()
2453 if (data->state != NULL) { in nfs4_open_prepare()
2456 if (can_open_cached(data->state, data->o_arg.fmode, in nfs4_open_prepare()
2460 delegation = nfs4_get_valid_delegation(data->state->inode); in nfs4_open_prepare()
2496 trace_nfs4_cached_open(data->state); in nfs4_open_prepare()
2538 struct nfs4_state *state = NULL; in nfs4_open_release() local
2549 state = nfs4_opendata_to_nfs4_state(data); in nfs4_open_release()
2550 if (!IS_ERR(state)) in nfs4_open_release()
2551 nfs4_close_state(state, data->o_arg.fmode); in nfs4_open_release()
2644 struct nfs4_state *state, fmode_t fmode, in nfs4_opendata_access() argument
2662 if (S_ISDIR(state->inode->i_mode)) in nfs4_opendata_access()
2671 nfs_access_add_cache(state->inode, &cache); in nfs4_opendata_access()
2735 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) in _nfs4_open_expired() argument
2740 opendata = nfs4_open_recoverdata_alloc(ctx, state, NFS4_OPEN_CLAIM_FH); in _nfs4_open_expired()
2749 ret = nfs4_open_recover(opendata, state); in _nfs4_open_expired()
2756 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) in nfs4_do_open_expired() argument
2758 struct nfs_server *server = NFS_SERVER(state->inode); in nfs4_do_open_expired()
2763 err = _nfs4_open_expired(ctx, state); in nfs4_do_open_expired()
2780 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) in nfs4_open_expired() argument
2785 ctx = nfs4_state_find_open_context(state); in nfs4_open_expired()
2788 ret = nfs4_do_open_expired(ctx, state); in nfs4_open_expired()
2793 static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state, in nfs_finish_clear_delegation_stateid() argument
2796 nfs_remove_bad_delegation(state->inode, stateid); in nfs_finish_clear_delegation_stateid()
2797 nfs_state_clear_delegation(state); in nfs_finish_clear_delegation_stateid()
2800 static void nfs40_clear_delegation_stateid(struct nfs4_state *state) in nfs40_clear_delegation_stateid() argument
2802 if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL) in nfs40_clear_delegation_stateid()
2803 nfs_finish_clear_delegation_stateid(state, NULL); in nfs40_clear_delegation_stateid()
2806 static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) in nfs40_open_expired() argument
2809 nfs40_clear_delegation_stateid(state); in nfs40_open_expired()
2810 nfs_state_clear_open_state_flags(state); in nfs40_open_expired()
2811 return nfs4_open_expired(sp, state); in nfs40_open_expired()
2853 static int nfs41_check_delegation_stateid(struct nfs4_state *state) in nfs41_check_delegation_stateid() argument
2855 struct nfs_server *server = NFS_SERVER(state->inode); in nfs41_check_delegation_stateid()
2863 delegation = rcu_dereference(NFS_I(state->inode)->delegation); in nfs41_check_delegation_stateid()
2866 nfs_state_clear_delegation(state); in nfs41_check_delegation_stateid()
2885 trace_nfs4_test_delegation_stateid(state, NULL, status); in nfs41_check_delegation_stateid()
2887 nfs_finish_clear_delegation_stateid(state, &stateid); in nfs41_check_delegation_stateid()
2895 static void nfs41_delegation_recover_stateid(struct nfs4_state *state) in nfs41_delegation_recover_stateid() argument
2899 if (test_bit(NFS_DELEGATED_STATE, &state->flags) && in nfs41_delegation_recover_stateid()
2900 nfs4_copy_delegation_stateid(state->inode, state->state, in nfs41_delegation_recover_stateid()
2902 nfs4_stateid_match_other(&state->stateid, &tmp)) in nfs41_delegation_recover_stateid()
2903 nfs_state_set_delegation(state, &tmp, state->state); in nfs41_delegation_recover_stateid()
2905 nfs_state_clear_delegation(state); in nfs41_delegation_recover_stateid()
2916 static int nfs41_check_expired_locks(struct nfs4_state *state) in nfs41_check_expired_locks() argument
2920 struct nfs_server *server = NFS_SERVER(state->inode); in nfs41_check_expired_locks()
2922 if (!test_bit(LK_STATE_IN_USE, &state->flags)) in nfs41_check_expired_locks()
2925 spin_lock(&state->state_lock); in nfs41_check_expired_locks()
2926 list_for_each_entry(lsp, &state->lock_states, ls_locks) { in nfs41_check_expired_locks()
2931 spin_unlock(&state->state_lock); in nfs41_check_expired_locks()
2939 trace_nfs4_test_lock_stateid(state, lsp, status); in nfs41_check_expired_locks()
2951 spin_lock(&state->state_lock); in nfs41_check_expired_locks()
2954 spin_unlock(&state->state_lock); in nfs41_check_expired_locks()
2968 static int nfs41_check_open_stateid(struct nfs4_state *state) in nfs41_check_open_stateid() argument
2970 struct nfs_server *server = NFS_SERVER(state->inode); in nfs41_check_open_stateid()
2971 nfs4_stateid *stateid = &state->open_stateid; in nfs41_check_open_stateid()
2972 const struct cred *cred = state->owner->so_cred; in nfs41_check_open_stateid()
2975 if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) in nfs41_check_open_stateid()
2978 trace_nfs4_test_open_stateid(state, NULL, status); in nfs41_check_open_stateid()
2980 nfs_state_clear_open_state_flags(state); in nfs41_check_open_stateid()
2984 if (nfs_open_stateid_recover_openmode(state)) in nfs41_check_open_stateid()
2989 static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) in nfs41_open_expired() argument
2993 status = nfs41_check_delegation_stateid(state); in nfs41_open_expired()
2996 nfs41_delegation_recover_stateid(state); in nfs41_open_expired()
2998 status = nfs41_check_expired_locks(state); in nfs41_open_expired()
3001 status = nfs41_check_open_stateid(state); in nfs41_open_expired()
3003 status = nfs4_open_expired(sp, state); in nfs41_open_expired()
3055 struct nfs4_state *state; in _nfs4_open_and_get_state() local
3069 state = _nfs4_opendata_to_nfs4_state(opendata); in _nfs4_open_and_get_state()
3070 ret = PTR_ERR(state); in _nfs4_open_and_get_state()
3071 if (IS_ERR(state)) in _nfs4_open_and_get_state()
3073 ctx->state = state; in _nfs4_open_and_get_state()
3075 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); in _nfs4_open_and_get_state()
3077 set_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags); in _nfs4_open_and_get_state()
3083 alias = d_exact_alias(dentry, state->inode); in _nfs4_open_and_get_state()
3085 alias = d_splice_alias(igrab(state->inode), dentry); in _nfs4_open_and_get_state()
3107 pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); in _nfs4_open_and_get_state()
3109 ret = nfs4_opendata_access(sp->so_cred, opendata, state, in _nfs4_open_and_get_state()
3114 if (d_inode(dentry) == state->inode) { in _nfs4_open_and_get_state()
3117 nfs4_schedule_stateid_recovery(server, state); in _nfs4_open_and_get_state()
3141 struct nfs4_state *state = NULL; in _nfs4_do_open() local
3191 opendata->state = nfs4_get_open_state(d_inode(dentry), sp); in _nfs4_do_open()
3196 state = ctx->state; in _nfs4_do_open()
3210 status = nfs4_do_setattr(state->inode, cred, in _nfs4_do_open()
3214 nfs_setattr_update_inode(state->inode, sattr, in _nfs4_do_open()
3216 nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); in _nfs4_do_open()
3269 res = ctx->state; in nfs4_do_open()
3348 } else if (ctx != NULL && ctx->state) { in _nfs4_do_setattr()
3350 if (!nfs4_valid_open_stateid(ctx->state)) in _nfs4_do_setattr()
3355 status = nfs4_select_rw_stateid(ctx->state, FMODE_WRITE, l_ctx, in _nfs4_do_setattr()
3385 struct nfs4_state *state = ctx ? ctx->state : NULL; in nfs4_do_setattr() local
3399 .state = state, in nfs4_do_setattr()
3425 if (state && !(state->state & FMODE_WRITE)) { in nfs4_do_setattr()
3451 struct nfs4_state *state) in nfs4_sync_open_stateid() argument
3458 if (!nfs4_valid_open_stateid(state)) in nfs4_sync_open_stateid()
3460 seq = read_seqbegin(&state->seqlock); in nfs4_sync_open_stateid()
3461 if (!nfs4_state_match_open_stateid_other(state, dst)) { in nfs4_sync_open_stateid()
3462 nfs4_stateid_copy(dst, &state->open_stateid); in nfs4_sync_open_stateid()
3463 if (read_seqretry(&state->seqlock, seq)) in nfs4_sync_open_stateid()
3467 seqid_open = state->open_stateid.seqid; in nfs4_sync_open_stateid()
3468 if (read_seqretry(&state->seqlock, seq)) in nfs4_sync_open_stateid()
3483 struct nfs4_state *state) in nfs4_refresh_open_old_stateid() argument
3493 if (!nfs4_valid_open_stateid(state)) in nfs4_refresh_open_old_stateid()
3495 seq = read_seqbegin(&state->seqlock); in nfs4_refresh_open_old_stateid()
3496 if (!nfs4_state_match_open_stateid_other(state, dst)) { in nfs4_refresh_open_old_stateid()
3497 if (read_seqretry(&state->seqlock, seq)) in nfs4_refresh_open_old_stateid()
3502 write_seqlock(&state->seqlock); in nfs4_refresh_open_old_stateid()
3503 seqid_open = state->open_stateid.seqid; in nfs4_refresh_open_old_stateid()
3510 write_sequnlock(&state->seqlock); in nfs4_refresh_open_old_stateid()
3516 set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); in nfs4_refresh_open_old_stateid()
3517 prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); in nfs4_refresh_open_old_stateid()
3518 write_sequnlock(&state->seqlock); in nfs4_refresh_open_old_stateid()
3519 trace_nfs4_close_stateid_update_wait(state->inode, dst, 0); in nfs4_refresh_open_old_stateid()
3527 finish_wait(&state->waitq, &wait); in nfs4_refresh_open_old_stateid()
3545 struct nfs4_state *state; member
3562 struct nfs4_state_owner *sp = calldata->state->owner; in nfs4_free_closedata()
3563 struct super_block *sb = calldata->state->inode->i_sb; in nfs4_free_closedata()
3568 nfs4_put_open_state(calldata->state); in nfs4_free_closedata()
3578 struct nfs4_state *state = calldata->state; in nfs4_close_done() local
3582 .state = state, in nfs4_close_done()
3590 trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); in nfs4_close_done()
3616 state)) in nfs4_close_done()
3636 nfs_clear_open_stateid(state, &calldata->arg.stateid, in nfs4_close_done()
3653 struct nfs4_state *state = calldata->state; in nfs4_close_prepare() local
3665 spin_lock(&state->owner->so_lock); in nfs4_close_prepare()
3666 is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); in nfs4_close_prepare()
3667 is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); in nfs4_close_prepare()
3668 is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); in nfs4_close_prepare()
3671 if (state->n_rdwr == 0) { in nfs4_close_prepare()
3672 if (state->n_rdonly == 0) in nfs4_close_prepare()
3676 if (state->n_wronly == 0) in nfs4_close_prepare()
3685 nfs4_sync_open_stateid(&calldata->arg.stateid, state); in nfs4_close_prepare()
3686 if (!nfs4_valid_open_stateid(state)) in nfs4_close_prepare()
3688 spin_unlock(&state->owner->so_lock); in nfs4_close_prepare()
3759 int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait) in nfs4_do_close() argument
3761 struct nfs_server *server = NFS_SERVER(state->inode); in nfs4_do_close()
3764 struct nfs4_state_owner *sp = state->owner; in nfs4_do_close()
3768 .rpc_cred = state->owner->so_cred, in nfs4_do_close()
3779 if (nfs_server_capable(state->inode, NFS_CAP_MOVEABLE)) in nfs4_do_close()
3789 calldata->inode = state->inode; in nfs4_do_close()
3790 calldata->state = state; in nfs4_do_close()
3791 calldata->arg.fh = NFS_FH(state->inode); in nfs4_do_close()
3792 if (!nfs4_copy_open_stateid(&calldata->arg.stateid, state)) in nfs4_do_close()
3796 calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); in nfs4_do_close()
3806 calldata->lr.roc = pnfs_roc(state->inode, in nfs4_do_close()
3828 nfs4_put_open_state(state); in nfs4_do_close()
3837 struct nfs4_state *state; in nfs4_atomic_open() local
3843 state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened); in nfs4_atomic_open()
3847 if (IS_ERR(state)) in nfs4_atomic_open()
3848 return ERR_CAST(state); in nfs4_atomic_open()
3849 return state->inode; in nfs4_atomic_open()
3854 if (ctx->state == NULL) in nfs4_close_context()
3857 nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); in nfs4_close_context()
3859 nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); in nfs4_close_context()
4676 struct nfs4_state *state; in nfs4_proc_create() local
4687 state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, NULL); in nfs4_proc_create()
4688 if (IS_ERR(state)) { in nfs4_proc_create()
4689 status = PTR_ERR(state); in nfs4_proc_create()
5347 return nfs4_select_rw_stateid(ctx->state, fmode, l_ctx, stateid, NULL); in nfs4_set_rw_stateid()
5387 .state = hdr->args.context->state, in nfs4_read_done_cb()
5501 .state = hdr->args.context->state, in nfs4_write_done_cb()
6723 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) in _nfs4_proc_getlk() argument
6725 struct inode *inode = state->inode; in _nfs4_proc_getlk()
6739 .rpc_cred = state->owner->so_cred, in _nfs4_proc_getlk()
6745 status = nfs4_set_lock_state(state, request); in _nfs4_proc_getlk()
6765 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) in nfs4_proc_getlk() argument
6773 err = _nfs4_proc_getlk(state, cmd, request); in nfs4_proc_getlk()
6774 trace_nfs4_get_lock(request, state, cmd, err); in nfs4_proc_getlk()
6775 err = nfs4_handle_exception(NFS_SERVER(state->inode), err, in nfs4_proc_getlk()
6788 struct nfs4_state *state = lsp->ls_state; in nfs4_refresh_lock_old_stateid() local
6791 spin_lock(&state->state_lock); in nfs4_refresh_lock_old_stateid()
6800 spin_unlock(&state->state_lock); in nfs4_refresh_lock_old_stateid()
6807 struct nfs4_state *state = lsp->ls_state; in nfs4_sync_lock_stateid() local
6810 spin_lock(&state->state_lock); in nfs4_sync_lock_stateid()
6813 spin_unlock(&state->state_lock); in nfs4_sync_lock_stateid()
6834 struct nfs4_state *state = lsp->ls_state; in nfs4_alloc_unlockdata() local
6835 struct inode *inode = state->inode; in nfs4_alloc_unlockdata()
6851 spin_lock(&state->state_lock); in nfs4_alloc_unlockdata()
6853 spin_unlock(&state->state_lock); in nfs4_alloc_unlockdata()
6989 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) in nfs4_proc_unlck() argument
6991 struct inode *inode = state->inode; in nfs4_proc_unlck()
6992 struct nfs4_state_owner *sp = state->owner; in nfs4_proc_unlck()
7001 status = nfs4_set_lock_state(state, request); in nfs4_proc_unlck()
7034 trace_nfs4_unlock(request, state, F_SETLK, status); in nfs4_proc_unlck()
7092 struct nfs4_state *state = data->lsp->ls_state; in nfs4_lock_prepare() local
7103 &state->open_stateid); in nfs4_lock_prepare()
7111 if (!nfs4_valid_open_stateid(state)) { in nfs4_lock_prepare()
7232 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_typ… in _nfs4_do_setlk() argument
7238 .rpc_cred = state->owner->so_cred, in _nfs4_do_setlk()
7241 .rpc_client = NFS_CLIENT(state->inode), in _nfs4_do_setlk()
7249 if (nfs_server_capable(state->inode, NFS_CAP_MOVEABLE)) in _nfs4_do_setlk()
7280 trace_nfs4_set_lock(fl, state, &data->res.stateid, cmd, ret); in _nfs4_do_setlk()
7286 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) in nfs4_lock_reclaim() argument
7288 struct nfs_server *server = NFS_SERVER(state->inode); in nfs4_lock_reclaim()
7290 .inode = state->inode, in nfs4_lock_reclaim()
7296 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) in nfs4_lock_reclaim()
7298 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); in nfs4_lock_reclaim()
7306 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) in nfs4_lock_expired() argument
7308 struct nfs_server *server = NFS_SERVER(state->inode); in nfs4_lock_expired()
7310 .inode = state->inode, in nfs4_lock_expired()
7314 err = nfs4_set_lock_state(state, request); in nfs4_lock_expired()
7322 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) in nfs4_lock_expired()
7324 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); in nfs4_lock_expired()
7339 static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) in nfs41_lock_expired() argument
7344 status = nfs4_set_lock_state(state, request); in nfs41_lock_expired()
7351 return nfs4_lock_expired(state, request); in nfs41_lock_expired()
7355 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) in _nfs4_proc_setlk() argument
7357 struct nfs_inode *nfsi = NFS_I(state->inode); in _nfs4_proc_setlk()
7358 struct nfs4_state_owner *sp = state->owner; in _nfs4_proc_setlk()
7363 status = locks_lock_inode_wait(state->inode, request); in _nfs4_proc_setlk()
7368 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { in _nfs4_proc_setlk()
7372 status = locks_lock_inode_wait(state->inode, request); in _nfs4_proc_setlk()
7379 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); in _nfs4_proc_setlk()
7385 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) in nfs4_proc_setlk() argument
7388 .state = state, in nfs4_proc_setlk()
7389 .inode = state->inode, in nfs4_proc_setlk()
7395 err = _nfs4_proc_setlk(state, cmd, request); in nfs4_proc_setlk()
7398 err = nfs4_handle_exception(NFS_SERVER(state->inode), in nfs4_proc_setlk()
7408 nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd, in nfs4_retry_setlk_simple() argument
7415 status = nfs4_proc_setlk(state, cmd, request); in nfs4_retry_setlk_simple()
7458 nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) in nfs4_retry_setlk() argument
7461 struct nfs_server *server = NFS_SERVER(state->inode); in nfs4_retry_setlk()
7465 .inode = state->inode, in nfs4_retry_setlk()
7473 if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) in nfs4_retry_setlk()
7474 return nfs4_retry_setlk_simple(state, cmd, request); in nfs4_retry_setlk()
7481 status = nfs4_proc_setlk(state, cmd, request); in nfs4_retry_setlk()
7498 nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) in nfs4_retry_setlk() argument
7500 return nfs4_retry_setlk_simple(state, cmd, request); in nfs4_retry_setlk()
7508 struct nfs4_state *state; in nfs4_proc_lock() local
7513 state = ctx->state; in nfs4_proc_lock()
7516 if (state != NULL) in nfs4_proc_lock()
7517 return nfs4_proc_getlk(state, F_GETLK, request); in nfs4_proc_lock()
7525 if (state != NULL) in nfs4_proc_lock()
7526 return nfs4_proc_unlck(state, cmd, request); in nfs4_proc_lock()
7530 if (state == NULL) in nfs4_proc_lock()
7534 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) in nfs4_proc_lock()
7551 status = nfs4_set_lock_state(state, request); in nfs4_proc_lock()
7555 return nfs4_retry_setlk(state, cmd, request); in nfs4_proc_lock()
7595 int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid … in nfs4_lock_delegation_recall() argument
7597 struct nfs_server *server = NFS_SERVER(state->inode); in nfs4_lock_delegation_recall()
7600 err = nfs4_set_lock_state(state, fl); in nfs4_lock_delegation_recall()
7604 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); in nfs4_lock_delegation_recall()
7609 return nfs4_handle_delegation_recall_error(server, state, stateid, fl, err); in nfs4_lock_delegation_recall()
9606 exception->state = lgp->args.ctx->state; in nfs4_layoutget_handle_exception()