Lines Matching refs:state
636 struct nfs4_state *state; in nfs4_alloc_open_state() local
638 state = kzalloc(sizeof(*state), GFP_NOFS); in nfs4_alloc_open_state()
639 if (!state) in nfs4_alloc_open_state()
641 atomic_set(&state->count, 1); in nfs4_alloc_open_state()
642 INIT_LIST_HEAD(&state->lock_states); in nfs4_alloc_open_state()
643 spin_lock_init(&state->state_lock); in nfs4_alloc_open_state()
644 seqlock_init(&state->seqlock); in nfs4_alloc_open_state()
645 return state; in nfs4_alloc_open_state()
649 nfs4_state_set_mode_locked(struct nfs4_state *state, fmode_t fmode) in nfs4_state_set_mode_locked() argument
651 if (state->state == fmode) in nfs4_state_set_mode_locked()
654 if ((fmode & FMODE_WRITE) != (state->state & FMODE_WRITE)) { in nfs4_state_set_mode_locked()
656 list_move(&state->open_states, &state->owner->so_states); in nfs4_state_set_mode_locked()
658 list_move_tail(&state->open_states, &state->owner->so_states); in nfs4_state_set_mode_locked()
660 state->state = fmode; in nfs4_state_set_mode_locked()
667 struct nfs4_state *state; in __nfs4_find_state_byowner() local
669 list_for_each_entry(state, &nfsi->open_states, inode_states) { in __nfs4_find_state_byowner()
670 if (state->owner != owner) in __nfs4_find_state_byowner()
672 if (!nfs4_valid_open_stateid(state)) in __nfs4_find_state_byowner()
674 if (atomic_inc_not_zero(&state->count)) in __nfs4_find_state_byowner()
675 return state; in __nfs4_find_state_byowner()
681 nfs4_free_open_state(struct nfs4_state *state) in nfs4_free_open_state() argument
683 kfree(state); in nfs4_free_open_state()
689 struct nfs4_state *state, *new; in nfs4_get_open_state() local
693 state = __nfs4_find_state_byowner(inode, owner); in nfs4_get_open_state()
695 if (state) in nfs4_get_open_state()
700 state = __nfs4_find_state_byowner(inode, owner); in nfs4_get_open_state()
701 if (state == NULL && new != NULL) { in nfs4_get_open_state()
702 state = new; in nfs4_get_open_state()
703 state->owner = owner; in nfs4_get_open_state()
705 list_add(&state->inode_states, &nfsi->open_states); in nfs4_get_open_state()
707 state->inode = inode; in nfs4_get_open_state()
711 list_add_tail(&state->open_states, &owner->so_states); in nfs4_get_open_state()
720 return state; in nfs4_get_open_state()
723 void nfs4_put_open_state(struct nfs4_state *state) in nfs4_put_open_state() argument
725 struct inode *inode = state->inode; in nfs4_put_open_state()
726 struct nfs4_state_owner *owner = state->owner; in nfs4_put_open_state()
728 if (!atomic_dec_and_lock(&state->count, &owner->so_lock)) in nfs4_put_open_state()
731 list_del(&state->inode_states); in nfs4_put_open_state()
732 list_del(&state->open_states); in nfs4_put_open_state()
736 nfs4_free_open_state(state); in nfs4_put_open_state()
743 static void __nfs4_close(struct nfs4_state *state, in __nfs4_close() argument
746 struct nfs4_state_owner *owner = state->owner; in __nfs4_close()
755 state->n_rdonly--; in __nfs4_close()
758 state->n_wronly--; in __nfs4_close()
761 state->n_rdwr--; in __nfs4_close()
764 if (state->n_rdwr == 0) { in __nfs4_close()
765 if (state->n_rdonly == 0) { in __nfs4_close()
767 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); in __nfs4_close()
768 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); in __nfs4_close()
770 if (state->n_wronly == 0) { in __nfs4_close()
772 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); in __nfs4_close()
773 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); in __nfs4_close()
776 clear_bit(NFS_DELEGATED_STATE, &state->flags); in __nfs4_close()
778 nfs4_state_set_mode_locked(state, newstate); in __nfs4_close()
782 nfs4_put_open_state(state); in __nfs4_close()
785 nfs4_do_close(state, gfp_mask, wait); in __nfs4_close()
788 void nfs4_close_state(struct nfs4_state *state, fmode_t fmode) in nfs4_close_state() argument
790 __nfs4_close(state, fmode, GFP_NOFS, 0); in nfs4_close_state()
793 void nfs4_close_sync(struct nfs4_state *state, fmode_t fmode) in nfs4_close_sync() argument
795 __nfs4_close(state, fmode, GFP_KERNEL, 1); in nfs4_close_sync()
803 __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) in __nfs4_find_lock_state() argument
806 list_for_each_entry(pos, &state->lock_states, ls_locks) { in __nfs4_find_lock_state()
820 static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) in nfs4_alloc_lock_state() argument
823 struct nfs_server *server = state->owner->so_server; in nfs4_alloc_lock_state()
830 lsp->ls_state = state; in nfs4_alloc_lock_state()
854 static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner) in nfs4_get_lock_state() argument
859 spin_lock(&state->state_lock); in nfs4_get_lock_state()
860 lsp = __nfs4_find_lock_state(state, owner); in nfs4_get_lock_state()
864 list_add(&new->ls_locks, &state->lock_states); in nfs4_get_lock_state()
865 set_bit(LK_STATE_IN_USE, &state->flags); in nfs4_get_lock_state()
870 spin_unlock(&state->state_lock); in nfs4_get_lock_state()
871 new = nfs4_alloc_lock_state(state, owner); in nfs4_get_lock_state()
875 spin_unlock(&state->state_lock); in nfs4_get_lock_state()
877 nfs4_free_lock_state(state->owner->so_server, new); in nfs4_get_lock_state()
888 struct nfs4_state *state; in nfs4_put_lock_state() local
892 state = lsp->ls_state; in nfs4_put_lock_state()
893 if (!atomic_dec_and_lock(&lsp->ls_count, &state->state_lock)) in nfs4_put_lock_state()
896 if (list_empty(&state->lock_states)) in nfs4_put_lock_state()
897 clear_bit(LK_STATE_IN_USE, &state->flags); in nfs4_put_lock_state()
898 spin_unlock(&state->state_lock); in nfs4_put_lock_state()
899 server = state->owner->so_server; in nfs4_put_lock_state()
926 int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl) in nfs4_set_lock_state() argument
932 lsp = nfs4_get_lock_state(state, fl->fl_owner); in nfs4_set_lock_state()
941 struct nfs4_state *state, in nfs4_copy_lock_stateid() argument
952 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) in nfs4_copy_lock_stateid()
956 spin_lock(&state->state_lock); in nfs4_copy_lock_stateid()
957 lsp = __nfs4_find_lock_state(state, fl_owner); in nfs4_copy_lock_stateid()
964 spin_unlock(&state->state_lock); in nfs4_copy_lock_stateid()
970 static void nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) in nfs4_copy_open_stateid() argument
977 seq = read_seqbegin(&state->seqlock); in nfs4_copy_open_stateid()
978 if (test_bit(NFS_OPEN_STATE, &state->flags)) in nfs4_copy_open_stateid()
979 src = &state->open_stateid; in nfs4_copy_open_stateid()
981 } while (read_seqretry(&state->seqlock, seq)); in nfs4_copy_open_stateid()
988 int nfs4_select_rw_stateid(nfs4_stateid *dst, struct nfs4_state *state, in nfs4_select_rw_stateid() argument
991 int ret = nfs4_copy_lock_stateid(dst, state, lockowner); in nfs4_select_rw_stateid()
996 if (nfs4_copy_delegation_stateid(dst, state->inode, fmode)) { in nfs4_select_rw_stateid()
1006 nfs4_copy_open_stateid(dst, state); in nfs4_select_rw_stateid()
1009 if (nfs_server_capable(state->inode, NFS_CAP_STATEID_NFSV41)) in nfs4_select_rw_stateid()
1298 static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state) in nfs4_state_mark_reclaim_reboot() argument
1301 set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_reboot()
1303 if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) { in nfs4_state_mark_reclaim_reboot()
1304 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_reboot()
1307 set_bit(NFS_OWNER_RECLAIM_REBOOT, &state->owner->so_flags); in nfs4_state_mark_reclaim_reboot()
1312 int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state) in nfs4_state_mark_reclaim_nograce() argument
1314 set_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags); in nfs4_state_mark_reclaim_nograce()
1315 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_nograce()
1316 set_bit(NFS_OWNER_RECLAIM_NOGRACE, &state->owner->so_flags); in nfs4_state_mark_reclaim_nograce()
1321 int nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_state *state) in nfs4_schedule_stateid_recovery() argument
1325 if (!nfs4_valid_open_stateid(state)) in nfs4_schedule_stateid_recovery()
1327 nfs4_state_mark_reclaim_nograce(clp, state); in nfs4_schedule_stateid_recovery()
1341 struct nfs4_state *state; in nfs_inode_find_state_and_recover() local
1346 state = ctx->state; in nfs_inode_find_state_and_recover()
1347 if (state == NULL) in nfs_inode_find_state_and_recover()
1349 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) in nfs_inode_find_state_and_recover()
1351 if (!nfs4_stateid_match(&state->stateid, stateid)) in nfs_inode_find_state_and_recover()
1353 nfs4_state_mark_reclaim_nograce(clp, state); in nfs_inode_find_state_and_recover()
1361 static void nfs4_state_mark_open_context_bad(struct nfs4_state *state) in nfs4_state_mark_open_context_bad() argument
1363 struct inode *inode = state->inode; in nfs4_state_mark_open_context_bad()
1369 if (ctx->state != state) in nfs4_state_mark_open_context_bad()
1376 static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error) in nfs4_state_mark_recovery_failed() argument
1378 set_bit(NFS_STATE_RECOVERY_FAILED, &state->flags); in nfs4_state_mark_recovery_failed()
1379 nfs4_state_mark_open_context_bad(state); in nfs4_state_mark_recovery_failed()
1383 static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops) in nfs4_reclaim_locks() argument
1385 struct inode *inode = state->inode; in nfs4_reclaim_locks()
1402 if (nfs_file_open_context(fl->fl_file)->state != state) in nfs4_reclaim_locks()
1405 status = ops->recover_lock(state, fl); in nfs4_reclaim_locks()
1445 struct nfs4_state *state; in nfs4_reclaim_open_state() local
1460 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_reclaim_open_state()
1461 if (!test_and_clear_bit(ops->state_flag_bit, &state->flags)) in nfs4_reclaim_open_state()
1463 if (!nfs4_valid_open_stateid(state)) in nfs4_reclaim_open_state()
1465 if (state->state == 0) in nfs4_reclaim_open_state()
1467 atomic_inc(&state->count); in nfs4_reclaim_open_state()
1469 status = ops->recover_open(sp, state); in nfs4_reclaim_open_state()
1471 status = nfs4_reclaim_locks(state, ops); in nfs4_reclaim_open_state()
1473 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) { in nfs4_reclaim_open_state()
1474 spin_lock(&state->state_lock); in nfs4_reclaim_open_state()
1475 list_for_each_entry(lock, &state->lock_states, ls_locks) { in nfs4_reclaim_open_state()
1481 spin_unlock(&state->state_lock); in nfs4_reclaim_open_state()
1483 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1485 &state->flags); in nfs4_reclaim_open_state()
1498 nfs4_state_mark_recovery_failed(state, status); in nfs4_reclaim_open_state()
1507 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); in nfs4_reclaim_open_state()
1511 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); in nfs4_reclaim_open_state()
1519 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1527 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1534 static void nfs4_clear_open_state(struct nfs4_state *state) in nfs4_clear_open_state() argument
1538 clear_bit(NFS_DELEGATED_STATE, &state->flags); in nfs4_clear_open_state()
1539 clear_bit(NFS_O_RDONLY_STATE, &state->flags); in nfs4_clear_open_state()
1540 clear_bit(NFS_O_WRONLY_STATE, &state->flags); in nfs4_clear_open_state()
1541 clear_bit(NFS_O_RDWR_STATE, &state->flags); in nfs4_clear_open_state()
1542 spin_lock(&state->state_lock); in nfs4_clear_open_state()
1543 list_for_each_entry(lock, &state->lock_states, ls_locks) { in nfs4_clear_open_state()
1547 spin_unlock(&state->state_lock); in nfs4_clear_open_state()
1551 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) in nfs4_reset_seqids() argument
1556 struct nfs4_state *state; in nfs4_reset_seqids() local
1565 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_reset_seqids()
1566 if (mark_reclaim(clp, state)) in nfs4_reset_seqids()
1567 nfs4_clear_open_state(state); in nfs4_reset_seqids()
1575 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) in nfs4_state_mark_reclaim_helper() argument
1606 struct nfs4_state *state; in nfs4_clear_reclaim_server() local
1614 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_clear_reclaim_server()
1616 &state->flags)) in nfs4_clear_reclaim_server()
1618 nfs4_state_mark_reclaim_nograce(clp, state); in nfs4_clear_reclaim_server()