Lines Matching refs:state
637 struct nfs4_state *state; in nfs4_alloc_open_state() local
639 state = kzalloc(sizeof(*state), GFP_NOFS); in nfs4_alloc_open_state()
640 if (!state) in nfs4_alloc_open_state()
642 atomic_set(&state->count, 1); in nfs4_alloc_open_state()
643 INIT_LIST_HEAD(&state->lock_states); in nfs4_alloc_open_state()
644 spin_lock_init(&state->state_lock); in nfs4_alloc_open_state()
645 seqlock_init(&state->seqlock); in nfs4_alloc_open_state()
646 return state; in nfs4_alloc_open_state()
650 nfs4_state_set_mode_locked(struct nfs4_state *state, fmode_t fmode) in nfs4_state_set_mode_locked() argument
652 if (state->state == fmode) in nfs4_state_set_mode_locked()
655 if ((fmode & FMODE_WRITE) != (state->state & FMODE_WRITE)) { in nfs4_state_set_mode_locked()
657 list_move(&state->open_states, &state->owner->so_states); in nfs4_state_set_mode_locked()
659 list_move_tail(&state->open_states, &state->owner->so_states); in nfs4_state_set_mode_locked()
661 state->state = fmode; in nfs4_state_set_mode_locked()
668 struct nfs4_state *state; in __nfs4_find_state_byowner() local
670 list_for_each_entry(state, &nfsi->open_states, inode_states) { in __nfs4_find_state_byowner()
671 if (state->owner != owner) in __nfs4_find_state_byowner()
673 if (!nfs4_valid_open_stateid(state)) in __nfs4_find_state_byowner()
675 if (atomic_inc_not_zero(&state->count)) in __nfs4_find_state_byowner()
676 return state; in __nfs4_find_state_byowner()
682 nfs4_free_open_state(struct nfs4_state *state) in nfs4_free_open_state() argument
684 kfree(state); in nfs4_free_open_state()
690 struct nfs4_state *state, *new; in nfs4_get_open_state() local
694 state = __nfs4_find_state_byowner(inode, owner); in nfs4_get_open_state()
696 if (state) in nfs4_get_open_state()
701 state = __nfs4_find_state_byowner(inode, owner); in nfs4_get_open_state()
702 if (state == NULL && new != NULL) { in nfs4_get_open_state()
703 state = new; in nfs4_get_open_state()
704 state->owner = owner; in nfs4_get_open_state()
706 list_add(&state->inode_states, &nfsi->open_states); in nfs4_get_open_state()
708 state->inode = inode; in nfs4_get_open_state()
712 list_add_tail(&state->open_states, &owner->so_states); in nfs4_get_open_state()
721 return state; in nfs4_get_open_state()
724 void nfs4_put_open_state(struct nfs4_state *state) in nfs4_put_open_state() argument
726 struct inode *inode = state->inode; in nfs4_put_open_state()
727 struct nfs4_state_owner *owner = state->owner; in nfs4_put_open_state()
729 if (!atomic_dec_and_lock(&state->count, &owner->so_lock)) in nfs4_put_open_state()
732 list_del(&state->inode_states); in nfs4_put_open_state()
733 list_del(&state->open_states); in nfs4_put_open_state()
737 nfs4_free_open_state(state); in nfs4_put_open_state()
744 static void __nfs4_close(struct nfs4_state *state, in __nfs4_close() argument
747 struct nfs4_state_owner *owner = state->owner; in __nfs4_close()
756 state->n_rdonly--; in __nfs4_close()
759 state->n_wronly--; in __nfs4_close()
762 state->n_rdwr--; in __nfs4_close()
765 if (state->n_rdwr == 0) { in __nfs4_close()
766 if (state->n_rdonly == 0) { in __nfs4_close()
768 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); in __nfs4_close()
769 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); in __nfs4_close()
771 if (state->n_wronly == 0) { in __nfs4_close()
773 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); in __nfs4_close()
774 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); in __nfs4_close()
777 clear_bit(NFS_DELEGATED_STATE, &state->flags); in __nfs4_close()
779 nfs4_state_set_mode_locked(state, newstate); in __nfs4_close()
783 nfs4_put_open_state(state); in __nfs4_close()
786 nfs4_do_close(state, gfp_mask, wait); in __nfs4_close()
789 void nfs4_close_state(struct nfs4_state *state, fmode_t fmode) in nfs4_close_state() argument
791 __nfs4_close(state, fmode, GFP_NOFS, 0); in nfs4_close_state()
794 void nfs4_close_sync(struct nfs4_state *state, fmode_t fmode) in nfs4_close_sync() argument
796 __nfs4_close(state, fmode, GFP_KERNEL, 1); in nfs4_close_sync()
804 __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) in __nfs4_find_lock_state() argument
807 list_for_each_entry(pos, &state->lock_states, ls_locks) { in __nfs4_find_lock_state()
821 static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) in nfs4_alloc_lock_state() argument
824 struct nfs_server *server = state->owner->so_server; in nfs4_alloc_lock_state()
831 lsp->ls_state = state; in nfs4_alloc_lock_state()
855 static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner) in nfs4_get_lock_state() argument
860 spin_lock(&state->state_lock); in nfs4_get_lock_state()
861 lsp = __nfs4_find_lock_state(state, owner); in nfs4_get_lock_state()
865 list_add(&new->ls_locks, &state->lock_states); in nfs4_get_lock_state()
866 set_bit(LK_STATE_IN_USE, &state->flags); in nfs4_get_lock_state()
871 spin_unlock(&state->state_lock); in nfs4_get_lock_state()
872 new = nfs4_alloc_lock_state(state, owner); in nfs4_get_lock_state()
876 spin_unlock(&state->state_lock); in nfs4_get_lock_state()
878 nfs4_free_lock_state(state->owner->so_server, new); in nfs4_get_lock_state()
889 struct nfs4_state *state; in nfs4_put_lock_state() local
893 state = lsp->ls_state; in nfs4_put_lock_state()
894 if (!atomic_dec_and_lock(&lsp->ls_count, &state->state_lock)) in nfs4_put_lock_state()
897 if (list_empty(&state->lock_states)) in nfs4_put_lock_state()
898 clear_bit(LK_STATE_IN_USE, &state->flags); in nfs4_put_lock_state()
899 spin_unlock(&state->state_lock); in nfs4_put_lock_state()
900 server = state->owner->so_server; in nfs4_put_lock_state()
927 int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl) in nfs4_set_lock_state() argument
933 lsp = nfs4_get_lock_state(state, fl->fl_owner); in nfs4_set_lock_state()
942 struct nfs4_state *state, in nfs4_copy_lock_stateid() argument
953 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) in nfs4_copy_lock_stateid()
957 spin_lock(&state->state_lock); in nfs4_copy_lock_stateid()
958 lsp = __nfs4_find_lock_state(state, fl_owner); in nfs4_copy_lock_stateid()
965 spin_unlock(&state->state_lock); in nfs4_copy_lock_stateid()
971 static void nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) in nfs4_copy_open_stateid() argument
978 seq = read_seqbegin(&state->seqlock); in nfs4_copy_open_stateid()
979 if (test_bit(NFS_OPEN_STATE, &state->flags)) in nfs4_copy_open_stateid()
980 src = &state->open_stateid; in nfs4_copy_open_stateid()
982 } while (read_seqretry(&state->seqlock, seq)); in nfs4_copy_open_stateid()
989 int nfs4_select_rw_stateid(nfs4_stateid *dst, struct nfs4_state *state, in nfs4_select_rw_stateid() argument
992 int ret = nfs4_copy_lock_stateid(dst, state, lockowner); in nfs4_select_rw_stateid()
997 if (nfs4_copy_delegation_stateid(dst, state->inode, fmode)) { in nfs4_select_rw_stateid()
1007 nfs4_copy_open_stateid(dst, state); in nfs4_select_rw_stateid()
1010 if (nfs_server_capable(state->inode, NFS_CAP_STATEID_NFSV41)) in nfs4_select_rw_stateid()
1299 static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state) in nfs4_state_mark_reclaim_reboot() argument
1302 set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_reboot()
1304 if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) { in nfs4_state_mark_reclaim_reboot()
1305 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_reboot()
1308 set_bit(NFS_OWNER_RECLAIM_REBOOT, &state->owner->so_flags); in nfs4_state_mark_reclaim_reboot()
1313 int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state) in nfs4_state_mark_reclaim_nograce() argument
1315 set_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags); in nfs4_state_mark_reclaim_nograce()
1316 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags); in nfs4_state_mark_reclaim_nograce()
1317 set_bit(NFS_OWNER_RECLAIM_NOGRACE, &state->owner->so_flags); in nfs4_state_mark_reclaim_nograce()
1322 int nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_state *state) in nfs4_schedule_stateid_recovery() argument
1326 if (!nfs4_valid_open_stateid(state)) in nfs4_schedule_stateid_recovery()
1328 nfs4_state_mark_reclaim_nograce(clp, state); in nfs4_schedule_stateid_recovery()
1342 struct nfs4_state *state; in nfs_inode_find_state_and_recover() local
1347 state = ctx->state; in nfs_inode_find_state_and_recover()
1348 if (state == NULL) in nfs_inode_find_state_and_recover()
1350 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) in nfs_inode_find_state_and_recover()
1352 if (!nfs4_stateid_match(&state->stateid, stateid)) in nfs_inode_find_state_and_recover()
1354 nfs4_state_mark_reclaim_nograce(clp, state); in nfs_inode_find_state_and_recover()
1362 static void nfs4_state_mark_open_context_bad(struct nfs4_state *state) in nfs4_state_mark_open_context_bad() argument
1364 struct inode *inode = state->inode; in nfs4_state_mark_open_context_bad()
1370 if (ctx->state != state) in nfs4_state_mark_open_context_bad()
1377 static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error) in nfs4_state_mark_recovery_failed() argument
1379 set_bit(NFS_STATE_RECOVERY_FAILED, &state->flags); in nfs4_state_mark_recovery_failed()
1380 nfs4_state_mark_open_context_bad(state); in nfs4_state_mark_recovery_failed()
1384 static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops) in nfs4_reclaim_locks() argument
1386 struct inode *inode = state->inode; in nfs4_reclaim_locks()
1403 if (nfs_file_open_context(fl->fl_file)->state != state) in nfs4_reclaim_locks()
1406 status = ops->recover_lock(state, fl); in nfs4_reclaim_locks()
1446 struct nfs4_state *state; in nfs4_reclaim_open_state() local
1461 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_reclaim_open_state()
1462 if (!test_and_clear_bit(ops->state_flag_bit, &state->flags)) in nfs4_reclaim_open_state()
1464 if (!nfs4_valid_open_stateid(state)) in nfs4_reclaim_open_state()
1466 if (state->state == 0) in nfs4_reclaim_open_state()
1468 atomic_inc(&state->count); in nfs4_reclaim_open_state()
1470 status = ops->recover_open(sp, state); in nfs4_reclaim_open_state()
1472 status = nfs4_reclaim_locks(state, ops); in nfs4_reclaim_open_state()
1474 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) { in nfs4_reclaim_open_state()
1475 spin_lock(&state->state_lock); in nfs4_reclaim_open_state()
1476 list_for_each_entry(lock, &state->lock_states, ls_locks) { in nfs4_reclaim_open_state()
1482 spin_unlock(&state->state_lock); in nfs4_reclaim_open_state()
1484 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1486 &state->flags); in nfs4_reclaim_open_state()
1499 nfs4_state_mark_recovery_failed(state, status); in nfs4_reclaim_open_state()
1508 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); in nfs4_reclaim_open_state()
1512 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state); in nfs4_reclaim_open_state()
1520 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1528 nfs4_put_open_state(state); in nfs4_reclaim_open_state()
1535 static void nfs4_clear_open_state(struct nfs4_state *state) in nfs4_clear_open_state() argument
1539 clear_bit(NFS_DELEGATED_STATE, &state->flags); in nfs4_clear_open_state()
1540 clear_bit(NFS_O_RDONLY_STATE, &state->flags); in nfs4_clear_open_state()
1541 clear_bit(NFS_O_WRONLY_STATE, &state->flags); in nfs4_clear_open_state()
1542 clear_bit(NFS_O_RDWR_STATE, &state->flags); in nfs4_clear_open_state()
1543 spin_lock(&state->state_lock); in nfs4_clear_open_state()
1544 list_for_each_entry(lock, &state->lock_states, ls_locks) { in nfs4_clear_open_state()
1548 spin_unlock(&state->state_lock); in nfs4_clear_open_state()
1552 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) in nfs4_reset_seqids() argument
1557 struct nfs4_state *state; in nfs4_reset_seqids() local
1566 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_reset_seqids()
1567 if (mark_reclaim(clp, state)) in nfs4_reset_seqids()
1568 nfs4_clear_open_state(state); in nfs4_reset_seqids()
1576 int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) in nfs4_state_mark_reclaim_helper() argument
1607 struct nfs4_state *state; in nfs4_clear_reclaim_server() local
1615 list_for_each_entry(state, &sp->so_states, open_states) { in nfs4_clear_reclaim_server()
1617 &state->flags)) in nfs4_clear_reclaim_server()
1619 nfs4_state_mark_reclaim_nograce(clp, state); in nfs4_clear_reclaim_server()