Lines Matching +full:embedded +full:- +full:trace +full:- +full:extension
56 #include "trace.h"
103 * A waitqueue for all in-progress 4.0 CLOSE operations that are waiting for
130 return ses->se_flags & NFS4_SESSION_DEAD; in is_session_dead()
135 if (atomic_read(&ses->se_ref) > ref_held_by_me) in mark_session_dead_locked()
137 ses->se_flags |= NFS4_SESSION_DEAD; in mark_session_dead_locked()
143 return clp->cl_time == 0; in is_client_expired()
148 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in get_client_locked()
150 lockdep_assert_held(&nn->client_lock); in get_client_locked()
154 atomic_inc(&clp->cl_rpc_users); in get_client_locked()
162 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in renew_client_locked()
168 clp->cl_clientid.cl_boot, in renew_client_locked()
169 clp->cl_clientid.cl_id); in renew_client_locked()
173 list_move_tail(&clp->cl_lru, &nn->client_lru); in renew_client_locked()
174 clp->cl_time = ktime_get_boottime_seconds(); in renew_client_locked()
179 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in put_client_renew_locked()
181 lockdep_assert_held(&nn->client_lock); in put_client_renew_locked()
183 if (!atomic_dec_and_test(&clp->cl_rpc_users)) in put_client_renew_locked()
193 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in put_client_renew()
195 if (!atomic_dec_and_lock(&clp->cl_rpc_users, &nn->client_lock)) in put_client_renew()
201 spin_unlock(&nn->client_lock); in put_client_renew()
210 status = get_client_locked(ses->se_client); in nfsd4_get_session_locked()
213 atomic_inc(&ses->se_ref); in nfsd4_get_session_locked()
219 struct nfs4_client *clp = ses->se_client; in nfsd4_put_session_locked()
220 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in nfsd4_put_session_locked()
222 lockdep_assert_held(&nn->client_lock); in nfsd4_put_session_locked()
224 if (atomic_dec_and_test(&ses->se_ref) && is_session_dead(ses)) in nfsd4_put_session_locked()
231 struct nfs4_client *clp = ses->se_client; in nfsd4_put_session()
232 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in nfsd4_put_session()
234 spin_lock(&nn->client_lock); in nfsd4_put_session()
236 spin_unlock(&nn->client_lock); in nfsd4_put_session()
245 spin_lock(&nn->blocked_locks_lock); in find_blocked_lock()
246 list_for_each_entry(cur, &lo->lo_blocked, nbl_list) { in find_blocked_lock()
247 if (fh_match(fh, &cur->nbl_fh)) { in find_blocked_lock()
248 list_del_init(&cur->nbl_list); in find_blocked_lock()
249 list_del_init(&cur->nbl_lru); in find_blocked_lock()
254 spin_unlock(&nn->blocked_locks_lock); in find_blocked_lock()
256 locks_delete_block(&found->nbl_lock); in find_blocked_lock()
270 INIT_LIST_HEAD(&nbl->nbl_list); in find_or_allocate_block()
271 INIT_LIST_HEAD(&nbl->nbl_lru); in find_or_allocate_block()
272 fh_copy_shallow(&nbl->nbl_fh, fh); in find_or_allocate_block()
273 locks_init_lock(&nbl->nbl_lock); in find_or_allocate_block()
274 nfsd4_init_cb(&nbl->nbl_cb, lo->lo_owner.so_client, in find_or_allocate_block()
285 locks_delete_block(&nbl->nbl_lock); in free_blocked_lock()
286 locks_release_private(&nbl->nbl_lock); in free_blocked_lock()
293 struct nfs4_client *clp = lo->lo_owner.so_client; in remove_blocked_locks()
294 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in remove_blocked_locks()
299 spin_lock(&nn->blocked_locks_lock); in remove_blocked_locks()
300 while (!list_empty(&lo->lo_blocked)) { in remove_blocked_locks()
301 nbl = list_first_entry(&lo->lo_blocked, in remove_blocked_locks()
304 list_del_init(&nbl->nbl_list); in remove_blocked_locks()
305 list_move(&nbl->nbl_lru, &reaplist); in remove_blocked_locks()
307 spin_unlock(&nn->blocked_locks_lock); in remove_blocked_locks()
313 list_del_init(&nbl->nbl_lru); in remove_blocked_locks()
323 locks_delete_block(&nbl->nbl_lock); in nfsd4_cb_notify_lock_prepare()
334 switch (task->tk_status) { in nfsd4_cb_notify_lock_done()
335 case -NFS4ERR_DELAY: in nfsd4_cb_notify_lock_done()
396 stp->st_access_bmap |= mask; in set_access()
406 stp->st_access_bmap &= ~mask; in clear_access()
415 return (bool)(stp->st_access_bmap & mask); in test_access()
425 stp->st_deny_bmap |= mask; in set_deny()
435 stp->st_deny_bmap &= ~mask; in clear_deny()
444 return (bool)(stp->st_deny_bmap & mask); in test_deny()
479 atomic_inc(&sop->so_count); in nfs4_get_stateowner()
486 return (sop->so_owner.len == owner->len) && in same_owner_str()
487 0 == memcmp(sop->so_owner.data, owner->data, owner->len); in same_owner_str()
496 lockdep_assert_held(&clp->cl_lock); in find_openstateowner_str_locked()
498 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[hashval], in find_openstateowner_str_locked()
500 if (!so->so_is_open_owner) in find_openstateowner_str_locked()
502 if (same_owner_str(so, &open->op_owner)) in find_openstateowner_str_locked()
514 spin_lock(&clp->cl_lock); in find_openstateowner_str()
516 spin_unlock(&clp->cl_lock); in find_openstateowner_str()
526 while (nbytes--) { in opaque_hashval()
545 if (refcount_dec_and_lock(&fi->fi_ref, &state_lock)) { in put_nfs4_file()
546 hlist_del_rcu(&fi->fi_hash); in put_nfs4_file()
548 WARN_ON_ONCE(!list_empty(&fi->fi_clnt_odstate)); in put_nfs4_file()
549 WARN_ON_ONCE(!list_empty(&fi->fi_delegations)); in put_nfs4_file()
550 call_rcu(&fi->fi_rcu, nfsd4_free_file_rcu); in put_nfs4_file()
557 if (f->fi_fds[oflag]) in __nfs4_get_fd()
558 return nfsd_file_get(f->fi_fds[oflag]); in __nfs4_get_fd()
567 lockdep_assert_held(&f->fi_lock); in find_writeable_file_locked()
580 spin_lock(&f->fi_lock); in find_writeable_file()
582 spin_unlock(&f->fi_lock); in find_writeable_file()
592 lockdep_assert_held(&f->fi_lock); in find_readable_file_locked()
605 spin_lock(&f->fi_lock); in find_readable_file()
607 spin_unlock(&f->fi_lock); in find_readable_file()
619 spin_lock(&f->fi_lock); in find_any_file()
626 spin_unlock(&f->fi_lock); in find_any_file()
634 spin_lock(&f->fi_lock); in find_deleg_file()
635 if (f->fi_deleg_file) in find_deleg_file()
636 ret = nfsd_file_get(f->fi_deleg_file); in find_deleg_file()
637 spin_unlock(&f->fi_lock); in find_deleg_file()
651 #define OWNER_HASH_MASK (OWNER_HASH_SIZE - 1)
657 ret = opaque_hashval(ownername->data, ownername->len); in ownerstr_hashval()
667 struct inode *inode = d_inode(fh->fh_dentry); in file_hashval()
670 return (unsigned int)hash_long(inode->i_ino, FILE_HASH_BITS); in file_hashval()
678 lockdep_assert_held(&fp->fi_lock); in __nfs4_file_get_access()
681 atomic_inc(&fp->fi_access[O_WRONLY]); in __nfs4_file_get_access()
683 atomic_inc(&fp->fi_access[O_RDONLY]); in __nfs4_file_get_access()
689 lockdep_assert_held(&fp->fi_lock); in nfs4_file_get_access()
696 if ((access & fp->fi_share_deny) != 0) in nfs4_file_get_access()
712 atomic_read(&fp->fi_access[O_RDONLY])) in nfs4_file_check_deny()
716 atomic_read(&fp->fi_access[O_WRONLY])) in nfs4_file_check_deny()
724 might_lock(&fp->fi_lock); in __nfs4_file_put_access()
726 if (atomic_dec_and_lock(&fp->fi_access[oflag], &fp->fi_lock)) { in __nfs4_file_put_access()
730 swap(f1, fp->fi_fds[oflag]); in __nfs4_file_put_access()
731 if (atomic_read(&fp->fi_access[1 - oflag]) == 0) in __nfs4_file_put_access()
732 swap(f2, fp->fi_fds[O_RDWR]); in __nfs4_file_put_access()
733 spin_unlock(&fp->fi_lock); in __nfs4_file_put_access()
755 * Note that we only allocate it for pNFS-enabled exports, otherwise
765 co->co_client = clp; in alloc_clnt_odstate()
766 refcount_set(&co->co_odcount, 1); in alloc_clnt_odstate()
774 struct nfs4_file *fp = co->co_file; in hash_clnt_odstate_locked()
776 lockdep_assert_held(&fp->fi_lock); in hash_clnt_odstate_locked()
777 list_add(&co->co_perfile, &fp->fi_clnt_odstate); in hash_clnt_odstate_locked()
784 refcount_inc(&co->co_odcount); in get_clnt_odstate()
795 fp = co->co_file; in put_clnt_odstate()
796 if (refcount_dec_and_lock(&co->co_odcount, &fp->fi_lock)) { in put_clnt_odstate()
797 list_del(&co->co_perfile); in put_clnt_odstate()
798 spin_unlock(&fp->fi_lock); in put_clnt_odstate()
800 nfsd4_return_all_file_layouts(co->co_client, fp); in put_clnt_odstate()
814 cl = new->co_client; in find_or_hash_clnt_odstate()
816 spin_lock(&fp->fi_lock); in find_or_hash_clnt_odstate()
817 list_for_each_entry(co, &fp->fi_clnt_odstate, co_perfile) { in find_or_hash_clnt_odstate()
818 if (co->co_client == cl) { in find_or_hash_clnt_odstate()
824 co->co_file = fp; in find_or_hash_clnt_odstate()
827 spin_unlock(&fp->fi_lock); in find_or_hash_clnt_odstate()
842 spin_lock(&cl->cl_lock); in nfs4_alloc_stid()
844 new_id = idr_alloc_cyclic(&cl->cl_stateids, stid, 1, 0, GFP_NOWAIT); in nfs4_alloc_stid()
845 spin_unlock(&cl->cl_lock); in nfs4_alloc_stid()
850 stid->sc_free = sc_free; in nfs4_alloc_stid()
851 stid->sc_client = cl; in nfs4_alloc_stid()
852 stid->sc_stateid.si_opaque.so_id = new_id; in nfs4_alloc_stid()
853 stid->sc_stateid.si_opaque.so_clid = cl->cl_clientid; in nfs4_alloc_stid()
855 refcount_set(&stid->sc_count, 1); in nfs4_alloc_stid()
856 spin_lock_init(&stid->sc_lock); in nfs4_alloc_stid()
857 INIT_LIST_HEAD(&stid->sc_cp_list); in nfs4_alloc_stid()
882 stid->stid.si_opaque.so_clid.cl_boot = (u32)nn->boot_time; in nfs4_init_cp_state()
883 stid->stid.si_opaque.so_clid.cl_id = nn->s2s_cp_cl_id; in nfs4_init_cp_state()
884 stid->sc_type = sc_type; in nfs4_init_cp_state()
887 spin_lock(&nn->s2s_cp_lock); in nfs4_init_cp_state()
888 new_id = idr_alloc_cyclic(&nn->s2s_cp_stateids, stid, 0, 0, GFP_NOWAIT); in nfs4_init_cp_state()
889 stid->stid.si_opaque.so_id = new_id; in nfs4_init_cp_state()
890 stid->stid.si_generation = 1; in nfs4_init_cp_state()
891 spin_unlock(&nn->s2s_cp_lock); in nfs4_init_cp_state()
900 return nfs4_init_cp_state(nn, ©->cp_stateid, NFS4_COPY_STID); in nfs4_init_copy_state()
911 cps->cpntf_time = ktime_get_boottime_seconds(); in nfs4_alloc_init_cpntf_state()
912 refcount_set(&cps->cp_stateid.sc_count, 1); in nfs4_alloc_init_cpntf_state()
913 if (!nfs4_init_cp_state(nn, &cps->cp_stateid, NFS4_COPYNOTIFY_STID)) in nfs4_alloc_init_cpntf_state()
915 spin_lock(&nn->s2s_cp_lock); in nfs4_alloc_init_cpntf_state()
916 list_add(&cps->cp_list, &p_stid->sc_cp_list); in nfs4_alloc_init_cpntf_state()
917 spin_unlock(&nn->s2s_cp_lock); in nfs4_alloc_init_cpntf_state()
928 WARN_ON_ONCE(copy->cp_stateid.sc_type != NFS4_COPY_STID); in nfs4_free_copy_state()
929 nn = net_generic(copy->cp_clp->net, nfsd_net_id); in nfs4_free_copy_state()
930 spin_lock(&nn->s2s_cp_lock); in nfs4_free_copy_state()
931 idr_remove(&nn->s2s_cp_stateids, in nfs4_free_copy_state()
932 copy->cp_stateid.stid.si_opaque.so_id); in nfs4_free_copy_state()
933 spin_unlock(&nn->s2s_cp_lock); in nfs4_free_copy_state()
942 spin_lock(&nn->s2s_cp_lock); in nfs4_free_cpntf_statelist()
943 while (!list_empty(&stid->sc_cp_list)) { in nfs4_free_cpntf_statelist()
944 cps = list_first_entry(&stid->sc_cp_list, in nfs4_free_cpntf_statelist()
948 spin_unlock(&nn->s2s_cp_lock); in nfs4_free_cpntf_statelist()
980 * low 3 bytes as hash-table indices.
999 if (bd->entries == 0) in delegation_blocked()
1001 if (ktime_get_seconds() - bd->swap_time > 30) { in delegation_blocked()
1003 if (ktime_get_seconds() - bd->swap_time > 30) { in delegation_blocked()
1004 bd->entries -= bd->old_entries; in delegation_blocked()
1005 bd->old_entries = bd->entries; in delegation_blocked()
1006 memset(bd->set[bd->new], 0, in delegation_blocked()
1007 sizeof(bd->set[0])); in delegation_blocked()
1008 bd->new = 1-bd->new; in delegation_blocked()
1009 bd->swap_time = ktime_get_seconds(); in delegation_blocked()
1013 hash = jhash(&fh->fh_base, fh->fh_size, 0); in delegation_blocked()
1014 if (test_bit(hash&255, bd->set[0]) && in delegation_blocked()
1015 test_bit((hash>>8)&255, bd->set[0]) && in delegation_blocked()
1016 test_bit((hash>>16)&255, bd->set[0])) in delegation_blocked()
1019 if (test_bit(hash&255, bd->set[1]) && in delegation_blocked()
1020 test_bit((hash>>8)&255, bd->set[1]) && in delegation_blocked()
1021 test_bit((hash>>16)&255, bd->set[1])) in delegation_blocked()
1032 hash = jhash(&fh->fh_base, fh->fh_size, 0); in block_delegations()
1035 __set_bit(hash&255, bd->set[bd->new]); in block_delegations()
1036 __set_bit((hash>>8)&255, bd->set[bd->new]); in block_delegations()
1037 __set_bit((hash>>16)&255, bd->set[bd->new]); in block_delegations()
1038 if (bd->entries == 0) in block_delegations()
1039 bd->swap_time = ktime_get_seconds(); in block_delegations()
1040 bd->entries += 1; in block_delegations()
1056 if (delegation_blocked(¤t_fh->fh_handle)) in alloc_init_deleg()
1067 dp->dl_stid.sc_stateid.si_generation = 1; in alloc_init_deleg()
1068 INIT_LIST_HEAD(&dp->dl_perfile); in alloc_init_deleg()
1069 INIT_LIST_HEAD(&dp->dl_perclnt); in alloc_init_deleg()
1070 INIT_LIST_HEAD(&dp->dl_recall_lru); in alloc_init_deleg()
1071 dp->dl_clnt_odstate = odstate; in alloc_init_deleg()
1073 dp->dl_type = NFS4_OPEN_DELEGATE_READ; in alloc_init_deleg()
1074 dp->dl_retries = 1; in alloc_init_deleg()
1075 nfsd4_init_cb(&dp->dl_recall, dp->dl_stid.sc_client, in alloc_init_deleg()
1078 dp->dl_stid.sc_file = fp; in alloc_init_deleg()
1088 struct nfs4_file *fp = s->sc_file; in nfs4_put_stid()
1089 struct nfs4_client *clp = s->sc_client; in nfs4_put_stid()
1091 might_lock(&clp->cl_lock); in nfs4_put_stid()
1093 if (!refcount_dec_and_lock(&s->sc_count, &clp->cl_lock)) { in nfs4_put_stid()
1097 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); in nfs4_put_stid()
1098 nfs4_free_cpntf_statelist(clp->net, s); in nfs4_put_stid()
1099 spin_unlock(&clp->cl_lock); in nfs4_put_stid()
1100 s->sc_free(s); in nfs4_put_stid()
1108 stateid_t *src = &stid->sc_stateid; in nfs4_inc_and_copy_stateid()
1110 spin_lock(&stid->sc_lock); in nfs4_inc_and_copy_stateid()
1111 if (unlikely(++src->si_generation == 0)) in nfs4_inc_and_copy_stateid()
1112 src->si_generation = 1; in nfs4_inc_and_copy_stateid()
1114 spin_unlock(&stid->sc_lock); in nfs4_inc_and_copy_stateid()
1121 spin_lock(&fp->fi_lock); in put_deleg_file()
1122 if (--fp->fi_delegees == 0) in put_deleg_file()
1123 swap(nf, fp->fi_deleg_file); in put_deleg_file()
1124 spin_unlock(&fp->fi_lock); in put_deleg_file()
1132 struct nfs4_file *fp = dp->dl_stid.sc_file; in nfs4_unlock_deleg_lease()
1133 struct nfsd_file *nf = fp->fi_deleg_file; in nfs4_unlock_deleg_lease()
1135 WARN_ON_ONCE(!fp->fi_delegees); in nfs4_unlock_deleg_lease()
1137 vfs_setlease(nf->nf_file, F_UNLCK, NULL, (void **)&dp); in nfs4_unlock_deleg_lease()
1143 put_clnt_odstate(dp->dl_clnt_odstate); in destroy_unhashed_deleg()
1145 nfs4_put_stid(&dp->dl_stid); in destroy_unhashed_deleg()
1150 s->sc_type = 0; in nfs4_unhash_stid()
1154 * nfs4_delegation_exists - Discover if this delegation already exists
1169 lockdep_assert_held(&fp->fi_lock); in nfs4_delegation_exists()
1171 list_for_each_entry(searchdp, &fp->fi_delegations, dl_perfile) { in nfs4_delegation_exists()
1172 searchclp = searchdp->dl_stid.sc_client; in nfs4_delegation_exists()
1181 * hash_delegation_locked - Add a delegation to the appropriate lists
1188 * On error: -EAGAIN if one was previously granted to this
1196 struct nfs4_client *clp = dp->dl_stid.sc_client; in hash_delegation_locked()
1199 lockdep_assert_held(&fp->fi_lock); in hash_delegation_locked()
1202 return -EAGAIN; in hash_delegation_locked()
1203 refcount_inc(&dp->dl_stid.sc_count); in hash_delegation_locked()
1204 dp->dl_stid.sc_type = NFS4_DELEG_STID; in hash_delegation_locked()
1205 list_add(&dp->dl_perfile, &fp->fi_delegations); in hash_delegation_locked()
1206 list_add(&dp->dl_perclnt, &clp->cl_delegations); in hash_delegation_locked()
1213 struct nfs4_file *fp = dp->dl_stid.sc_file; in unhash_delegation_locked()
1217 if (list_empty(&dp->dl_perfile)) in unhash_delegation_locked()
1220 dp->dl_stid.sc_type = NFS4_CLOSED_DELEG_STID; in unhash_delegation_locked()
1222 ++dp->dl_time; in unhash_delegation_locked()
1223 spin_lock(&fp->fi_lock); in unhash_delegation_locked()
1224 list_del_init(&dp->dl_perclnt); in unhash_delegation_locked()
1225 list_del_init(&dp->dl_recall_lru); in unhash_delegation_locked()
1226 list_del_init(&dp->dl_perfile); in unhash_delegation_locked()
1227 spin_unlock(&fp->fi_lock); in unhash_delegation_locked()
1244 struct nfs4_client *clp = dp->dl_stid.sc_client; in revoke_delegation()
1246 WARN_ON(!list_empty(&dp->dl_recall_lru)); in revoke_delegation()
1248 if (clp->cl_minorversion) { in revoke_delegation()
1249 dp->dl_stid.sc_type = NFS4_REVOKED_DELEG_STID; in revoke_delegation()
1250 refcount_inc(&dp->dl_stid.sc_count); in revoke_delegation()
1251 spin_lock(&clp->cl_lock); in revoke_delegation()
1252 list_add(&dp->dl_recall_lru, &clp->cl_revoked); in revoke_delegation()
1253 spin_unlock(&clp->cl_lock); in revoke_delegation()
1281 spin_lock(&fp->fi_lock); in recalculate_deny_mode()
1282 fp->fi_share_deny = 0; in recalculate_deny_mode()
1283 list_for_each_entry(stp, &fp->fi_stateids, st_perfile) in recalculate_deny_mode()
1284 fp->fi_share_deny |= bmap_to_share_mode(stp->st_deny_bmap); in recalculate_deny_mode()
1285 spin_unlock(&fp->fi_lock); in recalculate_deny_mode()
1301 /* Recalculate per-file deny mode if there was a change */ in reset_union_bmap_deny()
1303 recalculate_deny_mode(stp->st_stid.sc_file); in reset_union_bmap_deny()
1311 struct nfs4_file *fp = stp->st_stid.sc_file; in release_all_access()
1313 if (fp && stp->st_deny_bmap != 0) in release_all_access()
1318 nfs4_file_put_access(stp->st_stid.sc_file, i); in release_all_access()
1325 kfree(sop->so_owner.data); in nfs4_free_stateowner()
1326 sop->so_ops->so_free(sop); in nfs4_free_stateowner()
1331 struct nfs4_client *clp = sop->so_client; in nfs4_put_stateowner()
1333 might_lock(&clp->cl_lock); in nfs4_put_stateowner()
1335 if (!atomic_dec_and_lock(&sop->so_count, &clp->cl_lock)) in nfs4_put_stateowner()
1337 sop->so_ops->so_unhash(sop); in nfs4_put_stateowner()
1338 spin_unlock(&clp->cl_lock); in nfs4_put_stateowner()
1345 return list_empty(&stp->st_perfile); in nfs4_ol_stateid_unhashed()
1350 struct nfs4_file *fp = stp->st_stid.sc_file; in unhash_ol_stateid()
1352 lockdep_assert_held(&stp->st_stateowner->so_client->cl_lock); in unhash_ol_stateid()
1354 if (list_empty(&stp->st_perfile)) in unhash_ol_stateid()
1357 spin_lock(&fp->fi_lock); in unhash_ol_stateid()
1358 list_del_init(&stp->st_perfile); in unhash_ol_stateid()
1359 spin_unlock(&fp->fi_lock); in unhash_ol_stateid()
1360 list_del(&stp->st_perstateowner); in unhash_ol_stateid()
1368 put_clnt_odstate(stp->st_clnt_odstate); in nfs4_free_ol_stateid()
1370 if (stp->st_stateowner) in nfs4_free_ol_stateid()
1371 nfs4_put_stateowner(stp->st_stateowner); in nfs4_free_ol_stateid()
1378 struct nfs4_lockowner *lo = lockowner(stp->st_stateowner); in nfs4_free_lock_stateid()
1381 nf = find_any_file(stp->st_stid.sc_file); in nfs4_free_lock_stateid()
1383 get_file(nf->nf_file); in nfs4_free_lock_stateid()
1384 filp_close(nf->nf_file, (fl_owner_t)lo); in nfs4_free_lock_stateid()
1398 struct nfs4_stid *s = &stp->st_stid; in put_ol_stateid_locked()
1399 struct nfs4_client *clp = s->sc_client; in put_ol_stateid_locked()
1401 lockdep_assert_held(&clp->cl_lock); in put_ol_stateid_locked()
1403 WARN_ON_ONCE(!list_empty(&stp->st_locks)); in put_ol_stateid_locked()
1405 if (!refcount_dec_and_test(&s->sc_count)) { in put_ol_stateid_locked()
1410 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); in put_ol_stateid_locked()
1411 list_add(&stp->st_locks, reaplist); in put_ol_stateid_locked()
1416 lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); in unhash_lock_stateid()
1420 list_del_init(&stp->st_locks); in unhash_lock_stateid()
1421 nfs4_unhash_stid(&stp->st_stid); in unhash_lock_stateid()
1427 struct nfs4_client *clp = stp->st_stid.sc_client; in release_lock_stateid()
1430 spin_lock(&clp->cl_lock); in release_lock_stateid()
1432 spin_unlock(&clp->cl_lock); in release_lock_stateid()
1434 nfs4_put_stid(&stp->st_stid); in release_lock_stateid()
1439 struct nfs4_client *clp = lo->lo_owner.so_client; in unhash_lockowner_locked()
1441 lockdep_assert_held(&clp->cl_lock); in unhash_lockowner_locked()
1443 list_del_init(&lo->lo_owner.so_strhash); in unhash_lockowner_locked()
1461 list_del(&stp->st_locks); in free_ol_stateid_reaplist()
1462 fp = stp->st_stid.sc_file; in free_ol_stateid_reaplist()
1463 stp->st_stid.sc_free(&stp->st_stid); in free_ol_stateid_reaplist()
1474 lockdep_assert_held(&open_stp->st_stid.sc_client->cl_lock); in release_open_stateid_locks()
1476 while (!list_empty(&open_stp->st_locks)) { in release_open_stateid_locks()
1477 stp = list_entry(open_stp->st_locks.next, in release_open_stateid_locks()
1487 lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); in unhash_open_stateid()
1499 spin_lock(&stp->st_stid.sc_client->cl_lock); in release_open_stateid()
1502 spin_unlock(&stp->st_stid.sc_client->cl_lock); in release_open_stateid()
1508 struct nfs4_client *clp = oo->oo_owner.so_client; in unhash_openowner_locked()
1510 lockdep_assert_held(&clp->cl_lock); in unhash_openowner_locked()
1512 list_del_init(&oo->oo_owner.so_strhash); in unhash_openowner_locked()
1513 list_del_init(&oo->oo_perclient); in unhash_openowner_locked()
1518 struct nfsd_net *nn = net_generic(oo->oo_owner.so_client->net, in release_last_closed_stateid()
1522 spin_lock(&nn->client_lock); in release_last_closed_stateid()
1523 s = oo->oo_last_closed_stid; in release_last_closed_stateid()
1525 list_del_init(&oo->oo_close_lru); in release_last_closed_stateid()
1526 oo->oo_last_closed_stid = NULL; in release_last_closed_stateid()
1528 spin_unlock(&nn->client_lock); in release_last_closed_stateid()
1530 nfs4_put_stid(&s->st_stid); in release_last_closed_stateid()
1536 struct nfs4_client *clp = oo->oo_owner.so_client; in release_openowner()
1541 spin_lock(&clp->cl_lock); in release_openowner()
1543 while (!list_empty(&oo->oo_owner.so_stateids)) { in release_openowner()
1544 stp = list_first_entry(&oo->oo_owner.so_stateids, in release_openowner()
1549 spin_unlock(&clp->cl_lock); in release_openowner()
1552 nfs4_put_stateowner(&oo->oo_owner); in release_openowner()
1560 return sid->sequence % SESSION_HASH_SIZE; in hash_sessionid()
1567 u32 *ptr = (u32 *)(&sessionid->data[0]); in dump_sessionid()
1578 * Bump the seqid on cstate->replay_owner, and clear replay_owner if it
1583 struct nfs4_stateowner *so = cstate->replay_owner; in nfsd4_bump_seqid()
1594 if (so->so_is_open_owner) in nfsd4_bump_seqid()
1596 so->so_seqid++; in nfsd4_bump_seqid()
1603 struct nfs4_client *clp = ses->se_client; in gen_sessionid()
1606 sid = (struct nfsd4_sessionid *)ses->se_sessionid.data; in gen_sessionid()
1607 sid->clientid = clp->cl_clientid; in gen_sessionid()
1608 sid->sequence = current_sessionid++; in gen_sessionid()
1609 sid->reserved = 0; in gen_sessionid()
1615 * the end of the initial SEQUENCE operation--the rest we regenerate
1621 * verifier), 12 for the compound header (with zero-length tag), and 44
1631 for (i = 0; i < ses->se_fchannel.maxreqs; i++) { in free_session_slots()
1632 free_svc_cred(&ses->se_slots[i]->sl_cred); in free_session_slots()
1633 kfree(ses->se_slots[i]); in free_session_slots()
1645 if (ca->maxresp_cached < NFSD_MIN_HDR_SEQ_SZ) in slot_bytes()
1648 size = ca->maxresp_cached - NFSD_MIN_HDR_SEQ_SZ; in slot_bytes()
1654 * re-negotiate active sessions and reduce their slot usage to make
1660 u32 num = ca->maxreqs; in nfsd4_get_drc_mem()
1666 total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used; in nfsd4_get_drc_mem()
1682 * over-allocation--it is better than failure. in nfsd4_get_drc_mem()
1684 scale_factor = max_t(unsigned int, 8, nn->nfsd_serv->sv_nrthreads); in nfsd4_get_drc_mem()
1701 nfsd_drc_mem_used -= slotsize * ca->maxreqs; in nfsd4_put_drc_mem()
1708 int numslots = fattrs->maxreqs; in alloc_session()
1722 new->se_slots[i] = kzalloc(slotsize, GFP_KERNEL); in alloc_session()
1723 if (!new->se_slots[i]) in alloc_session()
1727 memcpy(&new->se_fchannel, fattrs, sizeof(struct nfsd4_channel_attrs)); in alloc_session()
1728 memcpy(&new->se_bchannel, battrs, sizeof(struct nfsd4_channel_attrs)); in alloc_session()
1732 while (i--) in alloc_session()
1733 kfree(new->se_slots[i]); in alloc_session()
1740 svc_xprt_put(c->cn_xprt); in free_conn()
1747 struct nfs4_client *clp = c->cn_session->se_client; in nfsd4_conn_lost()
1751 spin_lock(&clp->cl_lock); in nfsd4_conn_lost()
1752 if (!list_empty(&c->cn_persession)) { in nfsd4_conn_lost()
1753 list_del(&c->cn_persession); in nfsd4_conn_lost()
1757 spin_unlock(&clp->cl_lock); in nfsd4_conn_lost()
1767 svc_xprt_get(rqstp->rq_xprt); in alloc_conn()
1768 conn->cn_xprt = rqstp->rq_xprt; in alloc_conn()
1769 conn->cn_flags = flags; in alloc_conn()
1770 INIT_LIST_HEAD(&conn->cn_xpt_user.list); in alloc_conn()
1776 conn->cn_session = ses; in __nfsd4_hash_conn()
1777 list_add(&conn->cn_persession, &ses->se_conns); in __nfsd4_hash_conn()
1782 struct nfs4_client *clp = ses->se_client; in nfsd4_hash_conn()
1784 spin_lock(&clp->cl_lock); in nfsd4_hash_conn()
1786 spin_unlock(&clp->cl_lock); in nfsd4_hash_conn()
1791 conn->cn_xpt_user.callback = nfsd4_conn_lost; in nfsd4_register_conn()
1792 return register_xpt_user(conn->cn_xprt, &conn->cn_xpt_user); in nfsd4_register_conn()
1803 nfsd4_conn_lost(&conn->cn_xpt_user); in nfsd4_init_conn()
1805 nfsd4_probe_callback_sync(ses->se_client); in nfsd4_init_conn()
1812 if (cses->flags & SESSION4_BACK_CHAN) in alloc_conn_from_crses()
1820 struct nfs4_client *clp = s->se_client; in nfsd4_del_conns()
1823 spin_lock(&clp->cl_lock); in nfsd4_del_conns()
1824 while (!list_empty(&s->se_conns)) { in nfsd4_del_conns()
1825 c = list_first_entry(&s->se_conns, struct nfsd4_conn, cn_persession); in nfsd4_del_conns()
1826 list_del_init(&c->cn_persession); in nfsd4_del_conns()
1827 spin_unlock(&clp->cl_lock); in nfsd4_del_conns()
1829 unregister_xpt_user(c->cn_xprt, &c->cn_xpt_user); in nfsd4_del_conns()
1832 spin_lock(&clp->cl_lock); in nfsd4_del_conns()
1834 spin_unlock(&clp->cl_lock); in nfsd4_del_conns()
1846 nfsd4_put_drc_mem(&ses->se_fchannel); in free_session()
1855 new->se_client = clp; in init_session()
1858 INIT_LIST_HEAD(&new->se_conns); in init_session()
1860 new->se_cb_seq_nr = 1; in init_session()
1861 new->se_flags = cses->flags; in init_session()
1862 new->se_cb_prog = cses->callback_prog; in init_session()
1863 new->se_cb_sec = cses->cb_sec; in init_session()
1864 atomic_set(&new->se_ref, 0); in init_session()
1865 idx = hash_sessionid(&new->se_sessionid); in init_session()
1866 list_add(&new->se_hash, &nn->sessionid_hashtbl[idx]); in init_session()
1867 spin_lock(&clp->cl_lock); in init_session()
1868 list_add(&new->se_perclnt, &clp->cl_sessions); in init_session()
1869 spin_unlock(&clp->cl_lock); in init_session()
1880 rpc_copy_addr((struct sockaddr *)&clp->cl_cb_conn.cb_addr, sa); in init_session()
1881 clp->cl_cb_conn.cb_addrlen = svc_addr_len(sa); in init_session()
1893 lockdep_assert_held(&nn->client_lock); in __find_in_sessionid_hashtbl()
1898 list_for_each_entry(elem, &nn->sessionid_hashtbl[idx], se_hash) { in __find_in_sessionid_hashtbl()
1899 if (!memcmp(elem->se_sessionid.data, sessionid->data, in __find_in_sessionid_hashtbl()
1931 struct nfs4_client *clp = ses->se_client; in unhash_session()
1932 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_session()
1934 lockdep_assert_held(&nn->client_lock); in unhash_session()
1936 list_del(&ses->se_hash); in unhash_session()
1937 spin_lock(&ses->se_client->cl_lock); in unhash_session()
1938 list_del(&ses->se_perclnt); in unhash_session()
1939 spin_unlock(&ses->se_client->cl_lock); in unhash_session()
1951 if (clid->cl_boot == (u32)nn->boot_time) in STALE_CLIENTID()
1970 xdr_netobj_dup(&clp->cl_name, &name, GFP_KERNEL); in alloc_client()
1971 if (clp->cl_name.data == NULL) in alloc_client()
1973 clp->cl_ownerstr_hashtbl = kmalloc_array(OWNER_HASH_SIZE, in alloc_client()
1976 if (!clp->cl_ownerstr_hashtbl) in alloc_client()
1979 INIT_LIST_HEAD(&clp->cl_ownerstr_hashtbl[i]); in alloc_client()
1980 INIT_LIST_HEAD(&clp->cl_sessions); in alloc_client()
1981 idr_init(&clp->cl_stateids); in alloc_client()
1982 atomic_set(&clp->cl_rpc_users, 0); in alloc_client()
1983 clp->cl_cb_state = NFSD4_CB_UNKNOWN; in alloc_client()
1984 INIT_LIST_HEAD(&clp->cl_idhash); in alloc_client()
1985 INIT_LIST_HEAD(&clp->cl_openowners); in alloc_client()
1986 INIT_LIST_HEAD(&clp->cl_delegations); in alloc_client()
1987 INIT_LIST_HEAD(&clp->cl_lru); in alloc_client()
1988 INIT_LIST_HEAD(&clp->cl_revoked); in alloc_client()
1990 INIT_LIST_HEAD(&clp->cl_lo_states); in alloc_client()
1992 INIT_LIST_HEAD(&clp->async_copies); in alloc_client()
1993 spin_lock_init(&clp->async_lock); in alloc_client()
1994 spin_lock_init(&clp->cl_lock); in alloc_client()
1995 rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table"); in alloc_client()
1998 kfree(clp->cl_name.data); in alloc_client()
2009 free_svc_cred(&clp->cl_cred); in __free_client()
2010 kfree(clp->cl_ownerstr_hashtbl); in __free_client()
2011 kfree(clp->cl_name.data); in __free_client()
2012 kfree(clp->cl_nii_domain.data); in __free_client()
2013 kfree(clp->cl_nii_name.data); in __free_client()
2014 idr_destroy(&clp->cl_stateids); in __free_client()
2020 kref_put(&clp->cl_nfsdfs.cl_ref, __free_client); in drop_client()
2026 while (!list_empty(&clp->cl_sessions)) { in free_client()
2028 ses = list_entry(clp->cl_sessions.next, struct nfsd4_session, in free_client()
2030 list_del(&ses->se_perclnt); in free_client()
2031 WARN_ON_ONCE(atomic_read(&ses->se_ref)); in free_client()
2034 rpc_destroy_wait_queue(&clp->cl_cb_waitq); in free_client()
2035 if (clp->cl_nfsd_dentry) { in free_client()
2036 nfsd_client_rmdir(clp->cl_nfsd_dentry); in free_client()
2037 clp->cl_nfsd_dentry = NULL; in free_client()
2047 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_client_locked()
2050 lockdep_assert_held(&nn->client_lock); in unhash_client_locked()
2053 clp->cl_time = 0; in unhash_client_locked()
2055 if (!list_empty(&clp->cl_idhash)) { in unhash_client_locked()
2056 list_del_init(&clp->cl_idhash); in unhash_client_locked()
2057 if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) in unhash_client_locked()
2058 rb_erase(&clp->cl_namenode, &nn->conf_name_tree); in unhash_client_locked()
2060 rb_erase(&clp->cl_namenode, &nn->unconf_name_tree); in unhash_client_locked()
2062 list_del_init(&clp->cl_lru); in unhash_client_locked()
2063 spin_lock(&clp->cl_lock); in unhash_client_locked()
2064 list_for_each_entry(ses, &clp->cl_sessions, se_perclnt) in unhash_client_locked()
2065 list_del_init(&ses->se_hash); in unhash_client_locked()
2066 spin_unlock(&clp->cl_lock); in unhash_client_locked()
2072 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_client()
2074 spin_lock(&nn->client_lock); in unhash_client()
2076 spin_unlock(&nn->client_lock); in unhash_client()
2081 if (atomic_read(&clp->cl_rpc_users)) in mark_client_expired_locked()
2097 while (!list_empty(&clp->cl_delegations)) { in __destroy_client()
2098 dp = list_entry(clp->cl_delegations.next, struct nfs4_delegation, dl_perclnt); in __destroy_client()
2100 list_add(&dp->dl_recall_lru, &reaplist); in __destroy_client()
2105 list_del_init(&dp->dl_recall_lru); in __destroy_client()
2108 while (!list_empty(&clp->cl_revoked)) { in __destroy_client()
2109 dp = list_entry(clp->cl_revoked.next, struct nfs4_delegation, dl_recall_lru); in __destroy_client()
2110 list_del_init(&dp->dl_recall_lru); in __destroy_client()
2111 nfs4_put_stid(&dp->dl_stid); in __destroy_client()
2113 while (!list_empty(&clp->cl_openowners)) { in __destroy_client()
2114 oo = list_entry(clp->cl_openowners.next, struct nfs4_openowner, oo_perclient); in __destroy_client()
2115 nfs4_get_stateowner(&oo->oo_owner); in __destroy_client()
2121 list_for_each_entry_safe(so, tmp, &clp->cl_ownerstr_hashtbl[i], in __destroy_client()
2124 WARN_ON_ONCE(so->so_is_open_owner); in __destroy_client()
2131 if (clp->cl_cb_conn.cb_xprt) in __destroy_client()
2132 svc_xprt_put(clp->cl_cb_conn.cb_xprt); in __destroy_client()
2146 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in inc_reclaim_complete()
2148 if (!nn->track_reclaim_completes) in inc_reclaim_complete()
2150 if (!nfsd4_find_reclaim_client(clp->cl_name, nn)) in inc_reclaim_complete()
2152 if (atomic_inc_return(&nn->nr_reclaim_complete) == in inc_reclaim_complete()
2153 nn->reclaim_str_hashtbl_size) { in inc_reclaim_complete()
2155 clp->net->ns.inum); in inc_reclaim_complete()
2169 memcpy(target->cl_verifier.data, source->data, in copy_verf()
2170 sizeof(target->cl_verifier.data)); in copy_verf()
2175 target->cl_clientid.cl_boot = source->cl_clientid.cl_boot; in copy_clid()
2176 target->cl_clientid.cl_id = source->cl_clientid.cl_id; in copy_clid()
2181 target->cr_principal = kstrdup(source->cr_principal, GFP_KERNEL); in copy_cred()
2182 target->cr_raw_principal = kstrdup(source->cr_raw_principal, in copy_cred()
2184 target->cr_targ_princ = kstrdup(source->cr_targ_princ, GFP_KERNEL); in copy_cred()
2185 if ((source->cr_principal && !target->cr_principal) || in copy_cred()
2186 (source->cr_raw_principal && !target->cr_raw_principal) || in copy_cred()
2187 (source->cr_targ_princ && !target->cr_targ_princ)) in copy_cred()
2188 return -ENOMEM; in copy_cred()
2190 target->cr_flavor = source->cr_flavor; in copy_cred()
2191 target->cr_uid = source->cr_uid; in copy_cred()
2192 target->cr_gid = source->cr_gid; in copy_cred()
2193 target->cr_group_info = source->cr_group_info; in copy_cred()
2194 get_group_info(target->cr_group_info); in copy_cred()
2195 target->cr_gss_mech = source->cr_gss_mech; in copy_cred()
2196 if (source->cr_gss_mech) in copy_cred()
2197 gss_mech_get(source->cr_gss_mech); in copy_cred()
2204 if (o1->len < o2->len) in compare_blob()
2205 return -1; in compare_blob()
2206 if (o1->len > o2->len) in compare_blob()
2208 return memcmp(o1->data, o2->data, o1->len); in compare_blob()
2214 return 0 == memcmp(v1->data, v2->data, sizeof(v1->data)); in same_verf()
2220 return (cl1->cl_boot == cl2->cl_boot) && (cl1->cl_id == cl2->cl_id); in same_clid()
2227 if (g1->ngroups != g2->ngroups) in groups_equal()
2229 for (i=0; i<g1->ngroups; i++) in groups_equal()
2230 if (!gid_eq(g1->gid[i], g2->gid[i])) in groups_equal()
2239 * approximation. We also don't want to allow non-gss use of a client
2247 return (cr->cr_flavor > RPC_AUTH_MAXFLAVOR); in is_gss_cred()
2255 || (!uid_eq(cr1->cr_uid, cr2->cr_uid)) in same_creds()
2256 || (!gid_eq(cr1->cr_gid, cr2->cr_gid)) in same_creds()
2257 || !groups_equal(cr1->cr_group_info, cr2->cr_group_info)) in same_creds()
2260 if (cr1->cr_principal == cr2->cr_principal) in same_creds()
2262 if (!cr1->cr_principal || !cr2->cr_principal) in same_creds()
2264 return 0 == strcmp(cr1->cr_principal, cr2->cr_principal); in same_creds()
2269 struct svc_cred *cr = &rqstp->rq_cred; in svc_rqst_integrity_protected()
2272 if (!cr->cr_gss_mech) in svc_rqst_integrity_protected()
2274 service = gss_pseudoflavor_to_service(cr->cr_gss_mech, cr->cr_flavor); in svc_rqst_integrity_protected()
2281 struct svc_cred *cr = &rqstp->rq_cred; in nfsd4_mach_creds_match()
2283 if (!cl->cl_mach_cred) in nfsd4_mach_creds_match()
2285 if (cl->cl_cred.cr_gss_mech != cr->cr_gss_mech) in nfsd4_mach_creds_match()
2289 if (cl->cl_cred.cr_raw_principal) in nfsd4_mach_creds_match()
2290 return 0 == strcmp(cl->cl_cred.cr_raw_principal, in nfsd4_mach_creds_match()
2291 cr->cr_raw_principal); in nfsd4_mach_creds_match()
2292 if (!cr->cr_principal) in nfsd4_mach_creds_match()
2294 return 0 == strcmp(cl->cl_cred.cr_principal, cr->cr_principal); in nfsd4_mach_creds_match()
2302 * This is opaque to client, so no need to byte-swap. Use in gen_confirm()
2306 verf[1] = (__force __be32)nn->clverifier_counter++; in gen_confirm()
2307 memcpy(clp->cl_confirm.data, verf, sizeof(clp->cl_confirm.data)); in gen_confirm()
2312 clp->cl_clientid.cl_boot = (u32)nn->boot_time; in gen_clid()
2313 clp->cl_clientid.cl_id = nn->clientid_counter++; in gen_clid()
2322 ret = idr_find(&cl->cl_stateids, t->si_opaque.so_id); in find_stateid_locked()
2323 if (!ret || !ret->sc_type) in find_stateid_locked()
2333 spin_lock(&cl->cl_lock); in find_stateid_by_type()
2336 if (typemask & s->sc_type) in find_stateid_by_type()
2337 refcount_inc(&s->sc_count); in find_stateid_by_type()
2341 spin_unlock(&cl->cl_lock); in find_stateid_by_type()
2378 struct inode *inode = m->private; in client_info_show()
2384 return -ENXIO; in client_info_show()
2385 memcpy(&clid, &clp->cl_clientid, sizeof(clid)); in client_info_show()
2387 seq_printf(m, "address: \"%pISpc\"\n", (struct sockaddr *)&clp->cl_addr); in client_info_show()
2388 if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) in client_info_show()
2393 seq_quote_mem(m, clp->cl_name.data, clp->cl_name.len); in client_info_show()
2394 seq_printf(m, "\nminor version: %d\n", clp->cl_minorversion); in client_info_show()
2395 if (clp->cl_nii_domain.data) { in client_info_show()
2397 seq_quote_mem(m, clp->cl_nii_domain.data, in client_info_show()
2398 clp->cl_nii_domain.len); in client_info_show()
2400 seq_quote_mem(m, clp->cl_nii_name.data, clp->cl_nii_name.len); in client_info_show()
2402 clp->cl_nii_time.tv_sec, clp->cl_nii_time.tv_nsec); in client_info_show()
2404 seq_printf(m, "callback state: %s\n", cb_state2str(clp->cl_cb_state)); in client_info_show()
2405 seq_printf(m, "callback address: %pISpc\n", &clp->cl_cb_conn.cb_addr); in client_info_show()
2424 __acquires(&clp->cl_lock) in states_start()
2426 struct nfs4_client *clp = s->private; in states_start()
2430 spin_lock(&clp->cl_lock); in states_start()
2431 ret = idr_get_next_ul(&clp->cl_stateids, &id); in states_start()
2438 struct nfs4_client *clp = s->private; in states_next()
2444 ret = idr_get_next_ul(&clp->cl_stateids, &id); in states_next()
2450 __releases(&clp->cl_lock) in states_stop()
2452 struct nfs4_client *clp = s->private; in states_stop()
2454 spin_unlock(&clp->cl_lock); in states_stop()
2459 seq_printf(s, "filename: \"%pD2\"", f->nf_file); in nfs4_show_fname()
2464 struct inode *inode = f->nf_inode; in nfs4_show_superblock()
2467 MAJOR(inode->i_sb->s_dev), in nfs4_show_superblock()
2468 MINOR(inode->i_sb->s_dev), in nfs4_show_superblock()
2469 inode->i_ino); in nfs4_show_superblock()
2475 seq_quote_mem(s, oo->so_owner.data, oo->so_owner.len); in nfs4_show_owner()
2480 seq_printf(s, "0x%.8x", stid->si_generation); in nfs4_show_stateid()
2481 seq_printf(s, "%12phN", &stid->si_opaque); in nfs4_show_stateid()
2492 if (st->sc_type != NFS4_OPEN_STID && st->sc_type != NFS4_LOCK_STID) in nfs4_show_open()
2495 oo = ols->st_stateowner; in nfs4_show_open()
2496 nf = st->sc_file; in nfs4_show_open()
2501 seq_printf(s, "- "); in nfs4_show_open()
2502 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_open()
2505 access = bmap_to_share_mode(ols->st_access_bmap); in nfs4_show_open()
2506 deny = bmap_to_share_mode(ols->st_deny_bmap); in nfs4_show_open()
2509 access & NFS4_SHARE_ACCESS_READ ? "r" : "-", in nfs4_show_open()
2510 access & NFS4_SHARE_ACCESS_WRITE ? "w" : "-"); in nfs4_show_open()
2512 deny & NFS4_SHARE_ACCESS_READ ? "r" : "-", in nfs4_show_open()
2513 deny & NFS4_SHARE_ACCESS_WRITE ? "w" : "-"); in nfs4_show_open()
2534 oo = ols->st_stateowner; in nfs4_show_lock()
2535 nf = st->sc_file; in nfs4_show_lock()
2540 seq_printf(s, "- "); in nfs4_show_lock()
2541 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_lock()
2570 nf = st->sc_file; in nfs4_show_deleg()
2575 seq_printf(s, "- "); in nfs4_show_deleg()
2576 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_deleg()
2581 ds->dl_type == NFS4_OPEN_DELEGATE_READ ? "r" : "w"); in nfs4_show_deleg()
2600 file = ls->ls_file; in nfs4_show_layout()
2602 seq_printf(s, "- "); in nfs4_show_layout()
2603 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_layout()
2620 switch (st->sc_type) { in states_show()
2650 return -ENXIO; in client_states_open()
2655 s = file->private_data; in client_states_open()
2656 s->private = clp; in client_states_open()
2662 struct seq_file *m = file->private_data; in client_opens_release()
2663 struct nfs4_client *clp = m->private; in client_opens_release()
2685 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in force_expire_client()
2688 trace_nfsd_clid_admin_expired(&clp->cl_clientid); in force_expire_client()
2690 spin_lock(&nn->client_lock); in force_expire_client()
2691 clp->cl_time = 0; in force_expire_client()
2692 spin_unlock(&nn->client_lock); in force_expire_client()
2694 wait_event(expiry_wq, atomic_read(&clp->cl_rpc_users) == 0); in force_expire_client()
2695 spin_lock(&nn->client_lock); in force_expire_client()
2696 already_expired = list_empty(&clp->cl_lru); in force_expire_client()
2699 spin_unlock(&nn->client_lock); in force_expire_client()
2704 wait_event(expiry_wq, clp->cl_nfsd_dentry == NULL); in force_expire_client()
2717 return -EINVAL; in client_ctl_write()
2720 return -ENXIO; in client_ctl_write()
2752 ret = copy_cred(&clp->cl_cred, &rqstp->rq_cred); in create_client()
2758 kref_init(&clp->cl_nfsdfs.cl_ref); in create_client()
2759 nfsd4_init_cb(&clp->cl_cb_null, clp, NULL, NFSPROC4_CLNT_CB_NULL); in create_client()
2760 clp->cl_time = ktime_get_boottime_seconds(); in create_client()
2761 clear_bit(0, &clp->cl_cb_slot_busy); in create_client()
2763 memcpy(&clp->cl_addr, sa, sizeof(struct sockaddr_storage)); in create_client()
2764 clp->cl_cb_session = NULL; in create_client()
2765 clp->net = net; in create_client()
2766 clp->cl_nfsd_dentry = nfsd_client_mkdir( in create_client()
2767 nn, &clp->cl_nfsdfs, in create_client()
2768 clp->cl_clientid.cl_id - nn->clientid_base, in create_client()
2770 clp->cl_nfsd_info_dentry = dentries[0]; in create_client()
2771 if (!clp->cl_nfsd_dentry) { in create_client()
2781 struct rb_node **new = &(root->rb_node), *parent = NULL; in add_clp_to_name_tree()
2788 if (compare_blob(&clp->cl_name, &new_clp->cl_name) > 0) in add_clp_to_name_tree()
2789 new = &((*new)->rb_left); in add_clp_to_name_tree()
2791 new = &((*new)->rb_right); in add_clp_to_name_tree()
2794 rb_link_node(&new_clp->cl_namenode, parent, new); in add_clp_to_name_tree()
2795 rb_insert_color(&new_clp->cl_namenode, root); in add_clp_to_name_tree()
2802 struct rb_node *node = root->rb_node; in find_clp_in_name_tree()
2807 cmp = compare_blob(&clp->cl_name, name); in find_clp_in_name_tree()
2809 node = node->rb_left; in find_clp_in_name_tree()
2811 node = node->rb_right; in find_clp_in_name_tree()
2822 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in add_to_unconfirmed()
2824 lockdep_assert_held(&nn->client_lock); in add_to_unconfirmed()
2826 clear_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags); in add_to_unconfirmed()
2827 add_clp_to_name_tree(clp, &nn->unconf_name_tree); in add_to_unconfirmed()
2828 idhashval = clientid_hashval(clp->cl_clientid.cl_id); in add_to_unconfirmed()
2829 list_add(&clp->cl_idhash, &nn->unconf_id_hashtbl[idhashval]); in add_to_unconfirmed()
2836 unsigned int idhashval = clientid_hashval(clp->cl_clientid.cl_id); in move_to_confirmed()
2837 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in move_to_confirmed()
2839 lockdep_assert_held(&nn->client_lock); in move_to_confirmed()
2841 list_move(&clp->cl_idhash, &nn->conf_id_hashtbl[idhashval]); in move_to_confirmed()
2842 rb_erase(&clp->cl_namenode, &nn->unconf_name_tree); in move_to_confirmed()
2843 add_clp_to_name_tree(clp, &nn->conf_name_tree); in move_to_confirmed()
2844 set_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags); in move_to_confirmed()
2845 trace_nfsd_clid_confirmed(&clp->cl_clientid); in move_to_confirmed()
2853 unsigned int idhashval = clientid_hashval(clid->cl_id); in find_client_in_id_table()
2856 if (same_clid(&clp->cl_clientid, clid)) { in find_client_in_id_table()
2857 if ((bool)clp->cl_minorversion != sessions) in find_client_in_id_table()
2869 struct list_head *tbl = nn->conf_id_hashtbl; in find_confirmed_client()
2871 lockdep_assert_held(&nn->client_lock); in find_confirmed_client()
2878 struct list_head *tbl = nn->unconf_id_hashtbl; in find_unconfirmed_client()
2880 lockdep_assert_held(&nn->client_lock); in find_unconfirmed_client()
2886 return clp->cl_exchange_flags != 0; in clp_used_exchangeid()
2892 lockdep_assert_held(&nn->client_lock); in find_confirmed_client_by_name()
2893 return find_clp_in_name_tree(name, &nn->conf_name_tree); in find_confirmed_client_by_name()
2899 lockdep_assert_held(&nn->client_lock); in find_unconfirmed_client_by_name()
2900 return find_clp_in_name_tree(name, &nn->unconf_name_tree); in find_unconfirmed_client_by_name()
2906 struct nfs4_cb_conn *conn = &clp->cl_cb_conn; in gen_callback()
2912 if (se->se_callback_netid_len == 3 && in gen_callback()
2913 !memcmp(se->se_callback_netid_val, "tcp", 3)) in gen_callback()
2915 else if (se->se_callback_netid_len == 4 && in gen_callback()
2916 !memcmp(se->se_callback_netid_val, "tcp6", 4)) in gen_callback()
2921 conn->cb_addrlen = rpc_uaddr2sockaddr(clp->net, se->se_callback_addr_val, in gen_callback()
2922 se->se_callback_addr_len, in gen_callback()
2923 (struct sockaddr *)&conn->cb_addr, in gen_callback()
2924 sizeof(conn->cb_addr)); in gen_callback()
2926 if (!conn->cb_addrlen || conn->cb_addr.ss_family != expected_family) in gen_callback()
2929 if (conn->cb_addr.ss_family == AF_INET6) in gen_callback()
2930 ((struct sockaddr_in6 *)&conn->cb_addr)->sin6_scope_id = scopeid; in gen_callback()
2932 conn->cb_prog = se->se_callback_prog; in gen_callback()
2933 conn->cb_ident = se->se_callback_ident; in gen_callback()
2934 memcpy(&conn->cb_saddr, &rqstp->rq_daddr, rqstp->rq_daddrlen); in gen_callback()
2938 conn->cb_addr.ss_family = AF_UNSPEC; in gen_callback()
2939 conn->cb_addrlen = 0; in gen_callback()
2950 struct xdr_buf *buf = resp->xdr->buf; in nfsd4_store_cache_entry()
2951 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_store_cache_entry()
2954 dprintk("--> %s slot %p\n", __func__, slot); in nfsd4_store_cache_entry()
2956 slot->sl_flags |= NFSD4_SLOT_INITIALIZED; in nfsd4_store_cache_entry()
2957 slot->sl_opcnt = resp->opcnt; in nfsd4_store_cache_entry()
2958 slot->sl_status = resp->cstate.status; in nfsd4_store_cache_entry()
2959 free_svc_cred(&slot->sl_cred); in nfsd4_store_cache_entry()
2960 copy_cred(&slot->sl_cred, &resp->rqstp->rq_cred); in nfsd4_store_cache_entry()
2963 slot->sl_flags &= ~NFSD4_SLOT_CACHED; in nfsd4_store_cache_entry()
2966 slot->sl_flags |= NFSD4_SLOT_CACHED; in nfsd4_store_cache_entry()
2968 base = resp->cstate.data_offset; in nfsd4_store_cache_entry()
2969 slot->sl_datalen = buf->len - base; in nfsd4_store_cache_entry()
2970 if (read_bytes_from_xdr_buf(buf, base, slot->sl_data, slot->sl_datalen)) in nfsd4_store_cache_entry()
2979 * operation which sets resp->p and increments resp->opcnt for
2988 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_enc_sequence_replay()
2991 op = &args->ops[resp->opcnt - 1]; in nfsd4_enc_sequence_replay()
2994 if (slot->sl_flags & NFSD4_SLOT_CACHED) in nfsd4_enc_sequence_replay()
2995 return op->status; in nfsd4_enc_sequence_replay()
2996 if (args->opcnt == 1) { in nfsd4_enc_sequence_replay()
2998 * The original operation wasn't a solo sequence--we in nfsd4_enc_sequence_replay()
2999 * always cache those--so this retry must not match the in nfsd4_enc_sequence_replay()
3002 op->status = nfserr_seq_false_retry; in nfsd4_enc_sequence_replay()
3004 op = &args->ops[resp->opcnt++]; in nfsd4_enc_sequence_replay()
3005 op->status = nfserr_retry_uncached_rep; in nfsd4_enc_sequence_replay()
3008 return op->status; in nfsd4_enc_sequence_replay()
3019 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_replay_cache_entry()
3020 struct xdr_stream *xdr = resp->xdr; in nfsd4_replay_cache_entry()
3024 dprintk("--> %s slot %p\n", __func__, slot); in nfsd4_replay_cache_entry()
3026 status = nfsd4_enc_sequence_replay(resp->rqstp->rq_argp, resp); in nfsd4_replay_cache_entry()
3030 p = xdr_reserve_space(xdr, slot->sl_datalen); in nfsd4_replay_cache_entry()
3035 xdr_encode_opaque_fixed(p, slot->sl_data, slot->sl_datalen); in nfsd4_replay_cache_entry()
3038 resp->opcnt = slot->sl_opcnt; in nfsd4_replay_cache_entry()
3039 return slot->sl_status; in nfsd4_replay_cache_entry()
3049 new->cl_exchange_flags |= EXCHGID4_FLAG_USE_PNFS_MDS; in nfsd4_set_ex_flags()
3051 new->cl_exchange_flags |= EXCHGID4_FLAG_USE_NON_PNFS; in nfsd4_set_ex_flags()
3055 new->cl_exchange_flags |= EXCHGID4_FLAG_SUPP_MOVED_REFER; in nfsd4_set_ex_flags()
3058 clid->flags = new->cl_exchange_flags; in nfsd4_set_ex_flags()
3065 list_for_each_entry(oo, &clp->cl_openowners, oo_perclient) { in client_has_openowners()
3066 if (!list_empty(&oo->oo_owner.so_stateids)) in client_has_openowners()
3076 || !list_empty(&clp->cl_lo_states) in client_has_state()
3078 || !list_empty(&clp->cl_delegations) in client_has_state()
3079 || !list_empty(&clp->cl_sessions) in client_has_state()
3080 || !list_empty(&clp->async_copies); in client_has_state()
3086 if (!exid->nii_domain.data) in copy_impl_id()
3088 xdr_netobj_dup(&clp->cl_nii_domain, &exid->nii_domain, GFP_KERNEL); in copy_impl_id()
3089 if (!clp->cl_nii_domain.data) in copy_impl_id()
3091 xdr_netobj_dup(&clp->cl_nii_name, &exid->nii_name, GFP_KERNEL); in copy_impl_id()
3092 if (!clp->cl_nii_name.data) in copy_impl_id()
3094 clp->cl_nii_time = exid->nii_time; in copy_impl_id()
3102 struct nfsd4_exchange_id *exid = &u->exchange_id; in nfsd4_exchange_id()
3107 nfs4_verifier verf = exid->verifier; in nfsd4_exchange_id()
3109 bool update = exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A; in nfsd4_exchange_id()
3115 __func__, rqstp, exid, exid->clname.len, exid->clname.data, in nfsd4_exchange_id()
3116 addr_str, exid->flags, exid->spa_how); in nfsd4_exchange_id()
3118 if (exid->flags & ~EXCHGID4_FLAG_MASK_A) in nfsd4_exchange_id()
3121 new = create_client(exid->clname, rqstp, &verf); in nfsd4_exchange_id()
3128 switch (exid->spa_how) { in nfsd4_exchange_id()
3130 exid->spo_must_enforce[0] = 0; in nfsd4_exchange_id()
3131 exid->spo_must_enforce[1] = ( in nfsd4_exchange_id()
3132 1 << (OP_BIND_CONN_TO_SESSION - 32) | in nfsd4_exchange_id()
3133 1 << (OP_EXCHANGE_ID - 32) | in nfsd4_exchange_id()
3134 1 << (OP_CREATE_SESSION - 32) | in nfsd4_exchange_id()
3135 1 << (OP_DESTROY_SESSION - 32) | in nfsd4_exchange_id()
3136 1 << (OP_DESTROY_CLIENTID - 32)); in nfsd4_exchange_id()
3138 exid->spo_must_allow[0] &= (1 << (OP_CLOSE) | in nfsd4_exchange_id()
3143 exid->spo_must_allow[1] &= ( in nfsd4_exchange_id()
3144 1 << (OP_TEST_STATEID - 32) | in nfsd4_exchange_id()
3145 1 << (OP_FREE_STATEID - 32)); in nfsd4_exchange_id()
3155 if (!new->cl_cred.cr_principal && in nfsd4_exchange_id()
3156 !new->cl_cred.cr_raw_principal) { in nfsd4_exchange_id()
3160 new->cl_mach_cred = true; in nfsd4_exchange_id()
3173 spin_lock(&nn->client_lock); in nfsd4_exchange_id()
3174 conf = find_confirmed_client_by_name(&exid->clname, nn); in nfsd4_exchange_id()
3176 bool creds_match = same_creds(&conf->cl_cred, &rqstp->rq_cred); in nfsd4_exchange_id()
3177 bool verfs_match = same_verf(&verf, &conf->cl_verifier); in nfsd4_exchange_id()
3197 exid->flags |= EXCHGID4_FLAG_CONFIRMED_R; in nfsd4_exchange_id()
3210 conf->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; in nfsd4_exchange_id()
3225 unconf = find_unconfirmed_client_by_name(&exid->clname, nn); in nfsd4_exchange_id()
3237 trace_nfsd_clid_replaced(&conf->cl_clientid); in nfsd4_exchange_id()
3239 new->cl_minorversion = cstate->minorversion; in nfsd4_exchange_id()
3240 new->cl_spo_must_allow.u.words[0] = exid->spo_must_allow[0]; in nfsd4_exchange_id()
3241 new->cl_spo_must_allow.u.words[1] = exid->spo_must_allow[1]; in nfsd4_exchange_id()
3246 exid->clientid.cl_boot = conf->cl_clientid.cl_boot; in nfsd4_exchange_id()
3247 exid->clientid.cl_id = conf->cl_clientid.cl_id; in nfsd4_exchange_id()
3249 exid->seqid = conf->cl_cs_slot.sl_seqid + 1; in nfsd4_exchange_id()
3253 conf->cl_cs_slot.sl_seqid, conf->cl_exchange_flags); in nfsd4_exchange_id()
3257 spin_unlock(&nn->client_lock); in nfsd4_exchange_id()
3262 trace_nfsd_clid_expire_unconf(&unconf->cl_clientid); in nfsd4_exchange_id()
3281 /* Note unsigned 32-bit arithmetic handles wraparound: */ in check_slot_seqid()
3292 * Do this for solo or embedded create session operations.
3298 slot->sl_status = nfserr; in nfsd4_cache_create_session()
3299 memcpy(&slot->sl_cr_ses, cr_ses, sizeof(*cr_ses)); in nfsd4_cache_create_session()
3306 memcpy(cr_ses, &slot->sl_cr_ses, sizeof(*cr_ses)); in nfsd4_replay_create_session()
3307 return slot->sl_status; in nfsd4_replay_create_session()
3329 u32 maxrpc = nn->nfsd_serv->sv_max_mesg; in check_forechannel_attrs()
3331 if (ca->maxreq_sz < NFSD_MIN_REQ_HDR_SEQ_SZ) in check_forechannel_attrs()
3333 if (ca->maxresp_sz < NFSD_MIN_RESP_HDR_SEQ_SZ) in check_forechannel_attrs()
3335 ca->headerpadsz = 0; in check_forechannel_attrs()
3336 ca->maxreq_sz = min_t(u32, ca->maxreq_sz, maxrpc); in check_forechannel_attrs()
3337 ca->maxresp_sz = min_t(u32, ca->maxresp_sz, maxrpc); in check_forechannel_attrs()
3338 ca->maxops = min_t(u32, ca->maxops, NFSD_MAX_OPS_PER_COMPOUND); in check_forechannel_attrs()
3339 ca->maxresp_cached = min_t(u32, ca->maxresp_cached, in check_forechannel_attrs()
3341 ca->maxreqs = min_t(u32, ca->maxreqs, NFSD_MAX_SLOTS_PER_SESSION); in check_forechannel_attrs()
3352 ca->maxreqs = nfsd4_get_drc_mem(ca, nn); in check_forechannel_attrs()
3358 * Server's NFSv4.1 backchannel support is AUTH_SYS-only for now.
3375 ca->headerpadsz = 0; in check_backchannel_attrs()
3377 if (ca->maxreq_sz < NFSD_CB_MAX_REQ_SZ) in check_backchannel_attrs()
3379 if (ca->maxresp_sz < NFSD_CB_MAX_RESP_SZ) in check_backchannel_attrs()
3381 ca->maxresp_cached = 0; in check_backchannel_attrs()
3382 if (ca->maxops < 2) in check_backchannel_attrs()
3390 switch (cbs->flavor) { in nfsd4_check_cb_sec()
3410 struct nfsd4_create_session *cr_ses = &u->create_session; in nfsd4_create_session()
3420 if (cr_ses->flags & ~SESSION4_FLAG_MASK_A) in nfsd4_create_session()
3422 status = nfsd4_check_cb_sec(&cr_ses->cb_sec); in nfsd4_create_session()
3425 status = check_forechannel_attrs(&cr_ses->fore_channel, nn); in nfsd4_create_session()
3428 status = check_backchannel_attrs(&cr_ses->back_channel); in nfsd4_create_session()
3432 new = alloc_session(&cr_ses->fore_channel, &cr_ses->back_channel); in nfsd4_create_session()
3439 spin_lock(&nn->client_lock); in nfsd4_create_session()
3440 unconf = find_unconfirmed_client(&cr_ses->clientid, true, nn); in nfsd4_create_session()
3441 conf = find_confirmed_client(&cr_ses->clientid, true, nn); in nfsd4_create_session()
3448 cs_slot = &conf->cl_cs_slot; in nfsd4_create_session()
3449 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); in nfsd4_create_session()
3457 if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred) || in nfsd4_create_session()
3458 !rpc_cmp_addr(sa, (struct sockaddr *) &unconf->cl_addr)) { in nfsd4_create_session()
3465 cs_slot = &unconf->cl_cs_slot; in nfsd4_create_session()
3466 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); in nfsd4_create_session()
3472 old = find_confirmed_client_by_name(&unconf->cl_name, nn); in nfsd4_create_session()
3479 trace_nfsd_clid_replaced(&old->cl_clientid); in nfsd4_create_session()
3489 cr_ses->flags &= ~SESSION4_PERSIST; in nfsd4_create_session()
3491 cr_ses->flags &= ~SESSION4_RDMA; in nfsd4_create_session()
3496 memcpy(cr_ses->sessionid.data, new->se_sessionid.data, in nfsd4_create_session()
3498 cs_slot->sl_seqid++; in nfsd4_create_session()
3499 cr_ses->seqid = cs_slot->sl_seqid; in nfsd4_create_session()
3501 /* cache solo and embedded create sessions under the client_lock */ in nfsd4_create_session()
3503 spin_unlock(&nn->client_lock); in nfsd4_create_session()
3505 fsnotify_dentry(conf->cl_nfsd_info_dentry, FS_MODIFY); in nfsd4_create_session()
3513 spin_unlock(&nn->client_lock); in nfsd4_create_session()
3520 nfsd4_put_drc_mem(&cr_ses->fore_channel); in nfsd4_create_session()
3542 struct nfsd4_backchannel_ctl *bc = &u->backchannel_ctl; in nfsd4_backchannel_ctl()
3543 struct nfsd4_session *session = cstate->session; in nfsd4_backchannel_ctl()
3547 status = nfsd4_check_cb_sec(&bc->bc_cb_sec); in nfsd4_backchannel_ctl()
3550 spin_lock(&nn->client_lock); in nfsd4_backchannel_ctl()
3551 session->se_cb_prog = bc->bc_cb_program; in nfsd4_backchannel_ctl()
3552 session->se_cb_sec = bc->bc_cb_sec; in nfsd4_backchannel_ctl()
3553 spin_unlock(&nn->client_lock); in nfsd4_backchannel_ctl()
3555 nfsd4_probe_callback(session->se_client); in nfsd4_backchannel_ctl()
3564 list_for_each_entry(c, &s->se_conns, cn_persession) { in __nfsd4_find_conn()
3565 if (c->cn_xprt == xpt) { in __nfsd4_find_conn()
3575 struct nfs4_client *clp = session->se_client; in nfsd4_match_existing_connection()
3576 struct svc_xprt *xpt = rqst->rq_xprt; in nfsd4_match_existing_connection()
3581 spin_lock(&clp->cl_lock); in nfsd4_match_existing_connection()
3585 else if (req == c->cn_flags) in nfsd4_match_existing_connection()
3588 c->cn_flags != NFS4_CDFC4_BACK) in nfsd4_match_existing_connection()
3591 c->cn_flags != NFS4_CDFC4_FORE) in nfsd4_match_existing_connection()
3595 spin_unlock(&clp->cl_lock); in nfsd4_match_existing_connection()
3605 struct nfsd4_bind_conn_to_session *bcts = &u->bind_conn_to_session; in nfsd4_bind_conn_to_session()
3614 spin_lock(&nn->client_lock); in nfsd4_bind_conn_to_session()
3615 session = find_in_sessionid_hashtbl(&bcts->sessionid, net, &status); in nfsd4_bind_conn_to_session()
3616 spin_unlock(&nn->client_lock); in nfsd4_bind_conn_to_session()
3620 if (!nfsd4_mach_creds_match(session->se_client, rqstp)) in nfsd4_bind_conn_to_session()
3623 bcts->dir, &conn); in nfsd4_bind_conn_to_session()
3625 if (bcts->dir == NFS4_CDFC4_FORE_OR_BOTH || in nfsd4_bind_conn_to_session()
3626 bcts->dir == NFS4_CDFC4_BACK) in nfsd4_bind_conn_to_session()
3627 conn->cn_flags |= NFS4_CDFC4_BACK; in nfsd4_bind_conn_to_session()
3628 nfsd4_probe_callback(session->se_client); in nfsd4_bind_conn_to_session()
3633 status = nfsd4_map_bcts_dir(&bcts->dir); in nfsd4_bind_conn_to_session()
3636 conn = alloc_conn(rqstp, bcts->dir); in nfsd4_bind_conn_to_session()
3650 if (!cstate->session) in nfsd4_compound_in_session()
3652 return !memcmp(sid, &cstate->session->se_sessionid, sizeof(*sid)); in nfsd4_compound_in_session()
3659 struct nfs4_sessionid *sessionid = &u->destroy_session.sessionid; in nfsd4_destroy_session()
3673 spin_lock(&nn->client_lock); in nfsd4_destroy_session()
3678 if (!nfsd4_mach_creds_match(ses->se_client, r)) in nfsd4_destroy_session()
3684 spin_unlock(&nn->client_lock); in nfsd4_destroy_session()
3686 nfsd4_probe_callback_sync(ses->se_client); in nfsd4_destroy_session()
3688 spin_lock(&nn->client_lock); in nfsd4_destroy_session()
3693 spin_unlock(&nn->client_lock); in nfsd4_destroy_session()
3700 struct nfs4_client *clp = ses->se_client; in nfsd4_sequence_check_conn()
3705 spin_lock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3706 c = __nfsd4_find_conn(new->cn_xprt, ses); in nfsd4_sequence_check_conn()
3710 if (clp->cl_mach_cred) in nfsd4_sequence_check_conn()
3713 spin_unlock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3717 nfsd4_conn_lost(&new->cn_xpt_user); in nfsd4_sequence_check_conn()
3720 spin_unlock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3727 struct nfsd4_compoundargs *args = rqstp->rq_argp; in nfsd4_session_too_many_ops()
3729 return args->opcnt > session->se_fchannel.maxops; in nfsd4_session_too_many_ops()
3735 struct xdr_buf *xb = &rqstp->rq_arg; in nfsd4_request_too_big()
3737 return xb->len > session->se_fchannel.maxreq_sz; in nfsd4_request_too_big()
3743 struct nfsd4_compoundargs *argp = rqstp->rq_argp; in replay_matches_cache()
3745 if ((bool)(slot->sl_flags & NFSD4_SLOT_CACHETHIS) != in replay_matches_cache()
3746 (bool)seq->cachethis) in replay_matches_cache()
3752 if (slot->sl_opcnt < argp->opcnt && !slot->sl_status) in replay_matches_cache()
3759 if (slot->sl_opcnt > argp->opcnt) in replay_matches_cache()
3762 if (!same_creds(&rqstp->rq_cred, &slot->sl_cred)) in replay_matches_cache()
3777 struct nfsd4_sequence *seq = &u->sequence; in nfsd4_sequence()
3778 struct nfsd4_compoundres *resp = rqstp->rq_resp; in nfsd4_sequence()
3779 struct xdr_stream *xdr = resp->xdr; in nfsd4_sequence()
3789 if (resp->opcnt != 1) in nfsd4_sequence()
3800 spin_lock(&nn->client_lock); in nfsd4_sequence()
3801 session = find_in_sessionid_hashtbl(&seq->sessionid, net, &status); in nfsd4_sequence()
3804 clp = session->se_client; in nfsd4_sequence()
3815 if (seq->slotid >= session->se_fchannel.maxreqs) in nfsd4_sequence()
3818 slot = session->se_slots[seq->slotid]; in nfsd4_sequence()
3819 dprintk("%s: slotid %d\n", __func__, seq->slotid); in nfsd4_sequence()
3824 seq->maxslots = session->se_fchannel.maxreqs; in nfsd4_sequence()
3826 status = check_slot_seqid(seq->seqid, slot->sl_seqid, in nfsd4_sequence()
3827 slot->sl_flags & NFSD4_SLOT_INUSE); in nfsd4_sequence()
3830 if (!(slot->sl_flags & NFSD4_SLOT_INITIALIZED)) in nfsd4_sequence()
3835 cstate->slot = slot; in nfsd4_sequence()
3836 cstate->session = session; in nfsd4_sequence()
3837 cstate->clp = clp; in nfsd4_sequence()
3838 /* Return the cached reply status and set cstate->status in nfsd4_sequence()
3841 cstate->status = nfserr_replay_cache; in nfsd4_sequence()
3852 buflen = (seq->cachethis) ? in nfsd4_sequence()
3853 session->se_fchannel.maxresp_cached : in nfsd4_sequence()
3854 session->se_fchannel.maxresp_sz; in nfsd4_sequence()
3855 status = (seq->cachethis) ? nfserr_rep_too_big_to_cache : in nfsd4_sequence()
3857 if (xdr_restrict_buflen(xdr, buflen - rqstp->rq_auth_slack)) in nfsd4_sequence()
3863 slot->sl_seqid = seq->seqid; in nfsd4_sequence()
3864 slot->sl_flags |= NFSD4_SLOT_INUSE; in nfsd4_sequence()
3865 if (seq->cachethis) in nfsd4_sequence()
3866 slot->sl_flags |= NFSD4_SLOT_CACHETHIS; in nfsd4_sequence()
3868 slot->sl_flags &= ~NFSD4_SLOT_CACHETHIS; in nfsd4_sequence()
3870 cstate->slot = slot; in nfsd4_sequence()
3871 cstate->session = session; in nfsd4_sequence()
3872 cstate->clp = clp; in nfsd4_sequence()
3875 switch (clp->cl_cb_state) { in nfsd4_sequence()
3877 seq->status_flags = SEQ4_STATUS_CB_PATH_DOWN; in nfsd4_sequence()
3880 seq->status_flags = SEQ4_STATUS_BACKCHANNEL_FAULT; in nfsd4_sequence()
3883 seq->status_flags = 0; in nfsd4_sequence()
3885 if (!list_empty(&clp->cl_revoked)) in nfsd4_sequence()
3886 seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED; in nfsd4_sequence()
3890 spin_unlock(&nn->client_lock); in nfsd4_sequence()
3900 struct nfsd4_compound_state *cs = &resp->cstate; in nfsd4_sequence_done()
3903 if (cs->status != nfserr_replay_cache) { in nfsd4_sequence_done()
3905 cs->slot->sl_flags &= ~NFSD4_SLOT_INUSE; in nfsd4_sequence_done()
3908 nfsd4_put_session(cs->session); in nfsd4_sequence_done()
3909 } else if (cs->clp) in nfsd4_sequence_done()
3910 put_client_renew(cs->clp); in nfsd4_sequence_done()
3918 struct nfsd4_destroy_clientid *dc = &u->destroy_clientid; in nfsd4_destroy_clientid()
3924 spin_lock(&nn->client_lock); in nfsd4_destroy_clientid()
3925 unconf = find_unconfirmed_client(&dc->clientid, true, nn); in nfsd4_destroy_clientid()
3926 conf = find_confirmed_client(&dc->clientid, true, nn); in nfsd4_destroy_clientid()
3949 trace_nfsd_clid_destroyed(&clp->cl_clientid); in nfsd4_destroy_clientid()
3952 spin_unlock(&nn->client_lock); in nfsd4_destroy_clientid()
3962 struct nfsd4_reclaim_complete *rc = &u->reclaim_complete; in nfsd4_reclaim_complete()
3963 struct nfs4_client *clp = cstate->clp; in nfsd4_reclaim_complete()
3966 if (rc->rca_one_fs) { in nfsd4_reclaim_complete()
3967 if (!cstate->current_fh.fh_dentry) in nfsd4_reclaim_complete()
3977 if (test_and_set_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &clp->cl_flags)) in nfsd4_reclaim_complete()
3992 trace_nfsd_clid_reclaim_complete(&clp->cl_clientid); in nfsd4_reclaim_complete()
4003 struct nfsd4_setclientid *setclid = &u->setclientid; in nfsd4_setclientid()
4004 struct xdr_netobj clname = setclid->se_name; in nfsd4_setclientid()
4005 nfs4_verifier clverifier = setclid->se_verf; in nfsd4_setclientid()
4014 spin_lock(&nn->client_lock); in nfsd4_setclientid()
4020 if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid()
4029 if (same_verf(&conf->cl_verifier, &clverifier)) { in nfsd4_setclientid()
4037 new->cl_minorversion = 0; in nfsd4_setclientid()
4040 setclid->se_clientid.cl_boot = new->cl_clientid.cl_boot; in nfsd4_setclientid()
4041 setclid->se_clientid.cl_id = new->cl_clientid.cl_id; in nfsd4_setclientid()
4042 memcpy(setclid->se_confirm.data, new->cl_confirm.data, sizeof(setclid->se_confirm.data)); in nfsd4_setclientid()
4046 spin_unlock(&nn->client_lock); in nfsd4_setclientid()
4050 trace_nfsd_clid_expire_unconf(&unconf->cl_clientid); in nfsd4_setclientid()
4062 &u->setclientid_confirm; in nfsd4_setclientid_confirm()
4065 nfs4_verifier confirm = setclientid_confirm->sc_confirm; in nfsd4_setclientid_confirm()
4066 clientid_t * clid = &setclientid_confirm->sc_clientid; in nfsd4_setclientid_confirm()
4073 spin_lock(&nn->client_lock); in nfsd4_setclientid_confirm()
4084 if (unconf && !same_creds(&unconf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid_confirm()
4088 if (conf && !same_creds(&conf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid_confirm()
4092 if (!unconf || !same_verf(&confirm, &unconf->cl_confirm)) { in nfsd4_setclientid_confirm()
4093 if (conf && same_verf(&confirm, &conf->cl_confirm)) { in nfsd4_setclientid_confirm()
4103 nfsd4_change_callback(conf, &unconf->cl_cb_conn); in nfsd4_setclientid_confirm()
4105 old = find_confirmed_client_by_name(&unconf->cl_name, nn); in nfsd4_setclientid_confirm()
4109 && !same_creds(&unconf->cl_cred, in nfsd4_setclientid_confirm()
4110 &old->cl_cred)) in nfsd4_setclientid_confirm()
4117 trace_nfsd_clid_replaced(&old->cl_clientid); in nfsd4_setclientid_confirm()
4123 spin_unlock(&nn->client_lock); in nfsd4_setclientid_confirm()
4125 fsnotify_dentry(conf->cl_nfsd_info_dentry, FS_MODIFY); in nfsd4_setclientid_confirm()
4127 spin_lock(&nn->client_lock); in nfsd4_setclientid_confirm()
4130 spin_unlock(&nn->client_lock); in nfsd4_setclientid_confirm()
4147 refcount_set(&fp->fi_ref, 1); in nfsd4_init_file()
4148 spin_lock_init(&fp->fi_lock); in nfsd4_init_file()
4149 INIT_LIST_HEAD(&fp->fi_stateids); in nfsd4_init_file()
4150 INIT_LIST_HEAD(&fp->fi_delegations); in nfsd4_init_file()
4151 INIT_LIST_HEAD(&fp->fi_clnt_odstate); in nfsd4_init_file()
4152 fh_copy_shallow(&fp->fi_fhandle, &fh->fh_handle); in nfsd4_init_file()
4153 fp->fi_deleg_file = NULL; in nfsd4_init_file()
4154 fp->fi_had_conflict = false; in nfsd4_init_file()
4155 fp->fi_share_deny = 0; in nfsd4_init_file()
4156 memset(fp->fi_fds, 0, sizeof(fp->fi_fds)); in nfsd4_init_file()
4157 memset(fp->fi_access, 0, sizeof(fp->fi_access)); in nfsd4_init_file()
4158 fp->fi_aliased = false; in nfsd4_init_file()
4159 fp->fi_inode = d_inode(fh->fh_dentry); in nfsd4_init_file()
4161 INIT_LIST_HEAD(&fp->fi_lo_states); in nfsd4_init_file()
4162 atomic_set(&fp->fi_lo_recalls, 0); in nfsd4_init_file()
4164 hlist_add_head_rcu(&fp->fi_hash, &file_hashtbl[hashval]); in nfsd4_init_file()
4225 return -ENOMEM; in nfsd4_init_slabs()
4230 rp->rp_status = nfserr_serverfault; in init_nfs4_replay()
4231 rp->rp_buflen = 0; in init_nfs4_replay()
4232 rp->rp_buf = rp->rp_ibuf; in init_nfs4_replay()
4233 mutex_init(&rp->rp_mutex); in init_nfs4_replay()
4240 mutex_lock(&so->so_replay.rp_mutex); in nfsd4_cstate_assign_replay()
4241 cstate->replay_owner = nfs4_get_stateowner(so); in nfsd4_cstate_assign_replay()
4247 struct nfs4_stateowner *so = cstate->replay_owner; in nfsd4_cstate_clear_replay()
4250 cstate->replay_owner = NULL; in nfsd4_cstate_clear_replay()
4251 mutex_unlock(&so->so_replay.rp_mutex); in nfsd4_cstate_clear_replay()
4264 xdr_netobj_dup(&sop->so_owner, owner, GFP_KERNEL); in alloc_stateowner()
4265 if (!sop->so_owner.data) { in alloc_stateowner()
4270 INIT_LIST_HEAD(&sop->so_stateids); in alloc_stateowner()
4271 sop->so_client = clp; in alloc_stateowner()
4272 init_nfs4_replay(&sop->so_replay); in alloc_stateowner()
4273 atomic_set(&sop->so_count, 1); in alloc_stateowner()
4279 lockdep_assert_held(&clp->cl_lock); in hash_openowner()
4281 list_add(&oo->oo_owner.so_strhash, in hash_openowner()
4282 &clp->cl_ownerstr_hashtbl[strhashval]); in hash_openowner()
4283 list_add(&oo->oo_perclient, &clp->cl_openowners); in hash_openowner()
4307 struct nfs4_openowner *oo = open->op_openowner; in nfsd4_find_existing_open()
4309 lockdep_assert_held(&fp->fi_lock); in nfsd4_find_existing_open()
4311 list_for_each_entry(local, &fp->fi_stateids, st_perfile) { in nfsd4_find_existing_open()
4313 if (local->st_stateowner->so_is_open_owner == 0) in nfsd4_find_existing_open()
4315 if (local->st_stateowner != &oo->oo_owner) in nfsd4_find_existing_open()
4317 if (local->st_stid.sc_type == NFS4_OPEN_STID) { in nfsd4_find_existing_open()
4319 refcount_inc(&ret->st_stid.sc_count); in nfsd4_find_existing_open()
4331 switch (s->sc_type) { in nfsd4_verify_open_stid()
4351 mutex_lock_nested(&stp->st_mutex, LOCK_STATEID_MUTEX); in nfsd4_lock_ol_stateid()
4352 ret = nfsd4_verify_open_stid(&stp->st_stid); in nfsd4_lock_ol_stateid()
4354 mutex_unlock(&stp->st_mutex); in nfsd4_lock_ol_stateid()
4363 spin_lock(&fp->fi_lock); in nfsd4_find_and_lock_existing_open()
4365 spin_unlock(&fp->fi_lock); in nfsd4_find_and_lock_existing_open()
4368 nfs4_put_stid(&stp->st_stid); in nfsd4_find_and_lock_existing_open()
4377 struct nfs4_client *clp = cstate->clp; in alloc_init_open_stateowner()
4380 oo = alloc_stateowner(openowner_slab, &open->op_owner, clp); in alloc_init_open_stateowner()
4383 oo->oo_owner.so_ops = &openowner_ops; in alloc_init_open_stateowner()
4384 oo->oo_owner.so_is_open_owner = 1; in alloc_init_open_stateowner()
4385 oo->oo_owner.so_seqid = open->op_seqid; in alloc_init_open_stateowner()
4386 oo->oo_flags = 0; in alloc_init_open_stateowner()
4388 oo->oo_flags |= NFS4_OO_CONFIRMED; in alloc_init_open_stateowner()
4389 oo->oo_time = 0; in alloc_init_open_stateowner()
4390 oo->oo_last_closed_stid = NULL; in alloc_init_open_stateowner()
4391 INIT_LIST_HEAD(&oo->oo_close_lru); in alloc_init_open_stateowner()
4392 spin_lock(&clp->cl_lock); in alloc_init_open_stateowner()
4398 nfs4_free_stateowner(&oo->oo_owner); in alloc_init_open_stateowner()
4400 spin_unlock(&clp->cl_lock); in alloc_init_open_stateowner()
4408 struct nfs4_openowner *oo = open->op_openowner; in init_open_stateid()
4412 stp = open->op_stp; in init_open_stateid()
4414 mutex_init(&stp->st_mutex); in init_open_stateid()
4415 mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX); in init_open_stateid()
4418 spin_lock(&oo->oo_owner.so_client->cl_lock); in init_open_stateid()
4419 spin_lock(&fp->fi_lock); in init_open_stateid()
4425 open->op_stp = NULL; in init_open_stateid()
4426 refcount_inc(&stp->st_stid.sc_count); in init_open_stateid()
4427 stp->st_stid.sc_type = NFS4_OPEN_STID; in init_open_stateid()
4428 INIT_LIST_HEAD(&stp->st_locks); in init_open_stateid()
4429 stp->st_stateowner = nfs4_get_stateowner(&oo->oo_owner); in init_open_stateid()
4431 stp->st_stid.sc_file = fp; in init_open_stateid()
4432 stp->st_access_bmap = 0; in init_open_stateid()
4433 stp->st_deny_bmap = 0; in init_open_stateid()
4434 stp->st_openstp = NULL; in init_open_stateid()
4435 list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids); in init_open_stateid()
4436 list_add(&stp->st_perfile, &fp->fi_stateids); in init_open_stateid()
4439 spin_unlock(&fp->fi_lock); in init_open_stateid()
4440 spin_unlock(&oo->oo_owner.so_client->cl_lock); in init_open_stateid()
4444 nfs4_put_stid(&retstp->st_stid); in init_open_stateid()
4448 mutex_unlock(&stp->st_mutex); in init_open_stateid()
4463 struct nfs4_openowner *oo = openowner(s->st_stateowner); in move_to_close_lru()
4464 struct nfsd_net *nn = net_generic(s->st_stid.sc_client->net, in move_to_close_lru()
4478 wait_event(close_wq, refcount_read(&s->st_stid.sc_count) == 2); in move_to_close_lru()
4481 if (s->st_stid.sc_file) { in move_to_close_lru()
4482 put_nfs4_file(s->st_stid.sc_file); in move_to_close_lru()
4483 s->st_stid.sc_file = NULL; in move_to_close_lru()
4486 spin_lock(&nn->client_lock); in move_to_close_lru()
4487 last = oo->oo_last_closed_stid; in move_to_close_lru()
4488 oo->oo_last_closed_stid = s; in move_to_close_lru()
4489 list_move_tail(&oo->oo_close_lru, &nn->close_lru); in move_to_close_lru()
4490 oo->oo_time = ktime_get_boottime_seconds(); in move_to_close_lru()
4491 spin_unlock(&nn->client_lock); in move_to_close_lru()
4493 nfs4_put_stid(&last->st_stid); in move_to_close_lru()
4504 if (fh_match(&fp->fi_fhandle, &fh->fh_handle)) { in find_file_locked()
4505 if (refcount_inc_not_zero(&fp->fi_ref)) in find_file_locked()
4522 if (fh_match(&fp->fi_fhandle, &fh->fh_handle)) { in insert_file()
4523 if (refcount_inc_not_zero(&fp->fi_ref)) in insert_file()
4525 } else if (d_inode(fh->fh_dentry) == fp->fi_inode) in insert_file()
4526 fp->fi_aliased = alias_found = true; in insert_file()
4530 new->fi_aliased = alias_found; in insert_file()
4577 spin_lock(&fp->fi_lock); in nfs4_share_conflict()
4578 if (fp->fi_share_deny & deny_type) in nfs4_share_conflict()
4580 spin_unlock(&fp->fi_lock); in nfs4_share_conflict()
4588 struct nfsd_net *nn = net_generic(dp->dl_stid.sc_client->net, in nfsd4_cb_recall_prepare()
4591 block_delegations(&dp->dl_stid.sc_file->fi_fhandle); in nfsd4_cb_recall_prepare()
4595 * already holding inode->i_lock. in nfsd4_cb_recall_prepare()
4601 if (dp->dl_time == 0) { in nfsd4_cb_recall_prepare()
4602 dp->dl_time = ktime_get_boottime_seconds(); in nfsd4_cb_recall_prepare()
4603 list_add_tail(&dp->dl_recall_lru, &nn->del_recall_lru); in nfsd4_cb_recall_prepare()
4613 if (dp->dl_stid.sc_type == NFS4_CLOSED_DELEG_STID || in nfsd4_cb_recall_done()
4614 dp->dl_stid.sc_type == NFS4_REVOKED_DELEG_STID) in nfsd4_cb_recall_done()
4617 switch (task->tk_status) { in nfsd4_cb_recall_done()
4620 case -NFS4ERR_DELAY: in nfsd4_cb_recall_done()
4623 case -EBADHANDLE: in nfsd4_cb_recall_done()
4624 case -NFS4ERR_BAD_STATEID: in nfsd4_cb_recall_done()
4629 if (dp->dl_retries--) { in nfsd4_cb_recall_done()
4643 nfs4_put_stid(&dp->dl_stid); in nfsd4_cb_recall_release()
4661 refcount_inc(&dp->dl_stid.sc_count); in nfsd_break_one_deleg()
4662 nfsd4_run_cb(&dp->dl_recall); in nfsd_break_one_deleg()
4670 struct nfs4_delegation *dp = (struct nfs4_delegation *)fl->fl_owner; in nfsd_break_deleg_cb()
4671 struct nfs4_file *fp = dp->dl_stid.sc_file; in nfsd_break_deleg_cb()
4673 trace_nfsd_cb_recall(&dp->dl_stid); in nfsd_break_deleg_cb()
4680 fl->fl_break_time = 0; in nfsd_break_deleg_cb()
4682 spin_lock(&fp->fi_lock); in nfsd_break_deleg_cb()
4683 fp->fi_had_conflict = true; in nfsd_break_deleg_cb()
4685 spin_unlock(&fp->fi_lock); in nfsd_break_deleg_cb()
4691 struct nfs4_delegation *dl = fl->fl_owner; in nfsd_breaker_owns_lease()
4699 if (rqst->rq_prog != NFS_PROGRAM || rqst->rq_vers < 4) in nfsd_breaker_owns_lease()
4701 clp = *(rqst->rq_lease_breaker); in nfsd_breaker_owns_lease()
4702 return dl->dl_stid.sc_client == clp; in nfsd_breaker_owns_lease()
4712 return -EAGAIN; in nfsd_change_deleg_cb()
4725 if (seqid == so->so_seqid - 1) in nfsd4_check_seqid()
4727 if (seqid == so->so_seqid) in nfsd4_check_seqid()
4737 spin_lock(&nn->client_lock); in lookup_clientid()
4740 atomic_inc(&found->cl_rpc_users); in lookup_clientid()
4741 spin_unlock(&nn->client_lock); in lookup_clientid()
4749 if (cstate->clp) { in set_client()
4750 if (!same_clid(&cstate->clp->cl_clientid, clid)) in set_client()
4758 * set cstate->clp), so session = false: in set_client()
4760 cstate->clp = lookup_clientid(clid, false, nn); in set_client()
4761 if (!cstate->clp) in set_client()
4770 clientid_t *clientid = &open->op_clientid; in nfsd4_process_open1()
4780 open->op_file = nfsd4_alloc_file(); in nfsd4_process_open1()
4781 if (open->op_file == NULL) in nfsd4_process_open1()
4787 clp = cstate->clp; in nfsd4_process_open1()
4789 strhashval = ownerstr_hashval(&open->op_owner); in nfsd4_process_open1()
4791 open->op_openowner = oo; in nfsd4_process_open1()
4795 if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { in nfsd4_process_open1()
4798 open->op_openowner = NULL; in nfsd4_process_open1()
4801 status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid); in nfsd4_process_open1()
4809 open->op_openowner = oo; in nfsd4_process_open1()
4811 open->op_stp = nfs4_alloc_open_stateid(clp); in nfsd4_process_open1()
4812 if (!open->op_stp) in nfsd4_process_open1()
4816 (cstate->current_fh.fh_export->ex_flags & NFSEXP_PNFS)) { in nfsd4_process_open1()
4817 open->op_odstate = alloc_clnt_odstate(clp); in nfsd4_process_open1()
4818 if (!open->op_odstate) in nfsd4_process_open1()
4828 if ((flags & WR_STATE) && (dp->dl_type == NFS4_OPEN_DELEGATE_READ)) in nfs4_check_delegmode()
4852 return open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR || in nfsd4_is_deleg_cur()
4853 open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH; in nfsd4_is_deleg_cur()
4864 deleg = find_deleg_stateid(cl, &open->op_delegate_stateid); in nfs4_check_deleg()
4867 if (deleg->dl_stid.sc_type == NFS4_REVOKED_DELEG_STID) { in nfs4_check_deleg()
4868 nfs4_put_stid(&deleg->dl_stid); in nfs4_check_deleg()
4869 if (cl->cl_minorversion) in nfs4_check_deleg()
4873 flags = share_access_to_flags(open->op_share_access); in nfs4_check_deleg()
4876 nfs4_put_stid(&deleg->dl_stid); in nfs4_check_deleg()
4885 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; in nfs4_check_deleg()
4908 if (!open->op_truncate) in nfsd4_truncate()
4910 if (!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) in nfsd4_truncate()
4921 int oflag = nfs4_access_to_omode(open->op_share_access); in nfs4_get_vfs_file()
4922 int access = nfs4_access_to_access(open->op_share_access); in nfs4_get_vfs_file()
4925 spin_lock(&fp->fi_lock); in nfs4_get_vfs_file()
4931 status = nfs4_file_check_deny(fp, open->op_share_deny); in nfs4_get_vfs_file()
4933 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
4938 status = nfs4_file_get_access(fp, open->op_share_access); in nfs4_get_vfs_file()
4940 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
4945 old_access_bmap = stp->st_access_bmap; in nfs4_get_vfs_file()
4946 set_access(open->op_share_access, stp); in nfs4_get_vfs_file()
4949 old_deny_bmap = stp->st_deny_bmap; in nfs4_get_vfs_file()
4950 set_deny(open->op_share_deny, stp); in nfs4_get_vfs_file()
4951 fp->fi_share_deny |= (open->op_share_deny & NFS4_SHARE_DENY_BOTH); in nfs4_get_vfs_file()
4953 if (!fp->fi_fds[oflag]) { in nfs4_get_vfs_file()
4954 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
4958 spin_lock(&fp->fi_lock); in nfs4_get_vfs_file()
4959 if (!fp->fi_fds[oflag]) { in nfs4_get_vfs_file()
4960 fp->fi_fds[oflag] = nf; in nfs4_get_vfs_file()
4964 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
4968 status = nfserrno(nfsd_open_break_lease(cur_fh->fh_dentry->d_inode, in nfs4_get_vfs_file()
4979 stp->st_access_bmap = old_access_bmap; in nfs4_get_vfs_file()
4980 nfs4_file_put_access(fp, open->op_share_access); in nfs4_get_vfs_file()
4989 unsigned char old_deny_bmap = stp->st_deny_bmap; in nfs4_upgrade_open()
4991 if (!test_access(open->op_share_access, stp)) in nfs4_upgrade_open()
4995 spin_lock(&fp->fi_lock); in nfs4_upgrade_open()
4996 status = nfs4_file_check_deny(fp, open->op_share_deny); in nfs4_upgrade_open()
4998 set_deny(open->op_share_deny, stp); in nfs4_upgrade_open()
4999 fp->fi_share_deny |= in nfs4_upgrade_open()
5000 (open->op_share_deny & NFS4_SHARE_DENY_BOTH); in nfs4_upgrade_open()
5002 spin_unlock(&fp->fi_lock); in nfs4_upgrade_open()
5016 if (clp->cl_cb_state == NFSD4_CB_UP) in nfsd4_cb_channel_good()
5023 return clp->cl_minorversion && clp->cl_cb_state == NFSD4_CB_UNKNOWN; in nfsd4_cb_channel_good()
5034 fl->fl_lmops = &nfsd_lease_mng_ops; in nfs4_alloc_init_lease()
5035 fl->fl_flags = FL_DELEG; in nfs4_alloc_init_lease()
5036 fl->fl_type = flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK; in nfs4_alloc_init_lease()
5037 fl->fl_end = OFFSET_MAX; in nfs4_alloc_init_lease()
5038 fl->fl_owner = (fl_owner_t)dp; in nfs4_alloc_init_lease()
5039 fl->fl_pid = current->tgid; in nfs4_alloc_init_lease()
5040 fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file; in nfs4_alloc_init_lease()
5048 struct file *f = fp->fi_deleg_file->nf_file; in nfsd4_check_conflicting_opens()
5052 writes = atomic_read(&ino->i_writecount); in nfsd4_check_conflicting_opens()
5062 if (fp->fi_aliased) in nfsd4_check_conflicting_opens()
5063 return -EAGAIN; in nfsd4_check_conflicting_opens()
5071 if (fp->fi_fds[O_WRONLY]) in nfsd4_check_conflicting_opens()
5072 writes--; in nfsd4_check_conflicting_opens()
5073 if (fp->fi_fds[O_RDWR]) in nfsd4_check_conflicting_opens()
5074 writes--; in nfsd4_check_conflicting_opens()
5076 return -EAGAIN; /* There may be non-NFSv4 writers */ in nfsd4_check_conflicting_opens()
5078 * It's possible there are non-NFSv4 write opens in progress, in nfsd4_check_conflicting_opens()
5084 spin_lock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5085 list_for_each_entry(st, &fp->fi_stateids, st_perfile) { in nfsd4_check_conflicting_opens()
5086 if (st->st_openstp == NULL /* it's an open */ && in nfsd4_check_conflicting_opens()
5088 st->st_stid.sc_client != clp) { in nfsd4_check_conflicting_opens()
5089 spin_unlock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5090 return -EAGAIN; in nfsd4_check_conflicting_opens()
5093 spin_unlock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5117 if (fp->fi_had_conflict) in nfs4_set_delegation()
5118 return ERR_PTR(-EAGAIN); in nfs4_set_delegation()
5127 return ERR_PTR(-EAGAIN); in nfs4_set_delegation()
5130 spin_lock(&fp->fi_lock); in nfs4_set_delegation()
5132 status = -EAGAIN; in nfs4_set_delegation()
5133 else if (!fp->fi_deleg_file) { in nfs4_set_delegation()
5134 fp->fi_deleg_file = nf; in nfs4_set_delegation()
5137 fp->fi_delegees = 1; in nfs4_set_delegation()
5140 fp->fi_delegees++; in nfs4_set_delegation()
5141 spin_unlock(&fp->fi_lock); in nfs4_set_delegation()
5148 status = -ENOMEM; in nfs4_set_delegation()
5157 status = vfs_setlease(fp->fi_deleg_file->nf_file, fl->fl_type, &fl, NULL); in nfs4_set_delegation()
5167 spin_lock(&fp->fi_lock); in nfs4_set_delegation()
5168 if (fp->fi_had_conflict) in nfs4_set_delegation()
5169 status = -EAGAIN; in nfs4_set_delegation()
5172 spin_unlock(&fp->fi_lock); in nfs4_set_delegation()
5180 vfs_setlease(fp->fi_deleg_file->nf_file, F_UNLCK, NULL, (void **)&dp); in nfs4_set_delegation()
5182 put_clnt_odstate(dp->dl_clnt_odstate); in nfs4_set_delegation()
5183 nfs4_put_stid(&dp->dl_stid); in nfs4_set_delegation()
5191 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_open_deleg_none_ext()
5192 if (status == -EAGAIN) in nfsd4_open_deleg_none_ext()
5193 open->op_why_no_deleg = WND4_CONTENTION; in nfsd4_open_deleg_none_ext()
5195 open->op_why_no_deleg = WND4_RESOURCE; in nfsd4_open_deleg_none_ext()
5196 switch (open->op_deleg_want) { in nfsd4_open_deleg_none_ext()
5202 open->op_why_no_deleg = WND4_CANCELLED; in nfsd4_open_deleg_none_ext()
5221 struct nfs4_openowner *oo = openowner(stp->st_stateowner); in nfs4_open_delegation()
5222 struct nfs4_client *clp = stp->st_stid.sc_client; in nfs4_open_delegation()
5226 cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client); in nfs4_open_delegation()
5227 open->op_recall = 0; in nfs4_open_delegation()
5228 switch (open->op_claim_type) { in nfs4_open_delegation()
5231 open->op_recall = 1; in nfs4_open_delegation()
5232 if (open->op_delegate_type != NFS4_OPEN_DELEGATE_READ) in nfs4_open_delegation()
5242 if (locks_in_grace(clp->net)) in nfs4_open_delegation()
5244 if (!cb_up || !(oo->oo_flags & NFS4_OO_CONFIRMED)) in nfs4_open_delegation()
5250 dp = nfs4_set_delegation(clp, fh, stp->st_stid.sc_file, stp->st_clnt_odstate); in nfs4_open_delegation()
5254 memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid)); in nfs4_open_delegation()
5256 trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid); in nfs4_open_delegation()
5257 open->op_delegate_type = NFS4_OPEN_DELEGATE_READ; in nfs4_open_delegation()
5258 nfs4_put_stid(&dp->dl_stid); in nfs4_open_delegation()
5261 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE; in nfs4_open_delegation()
5262 if (open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS && in nfs4_open_delegation()
5263 open->op_delegate_type != NFS4_OPEN_DELEGATE_NONE) { in nfs4_open_delegation()
5265 open->op_recall = 1; in nfs4_open_delegation()
5269 if (open->op_deleg_want) in nfs4_open_delegation()
5277 if (open->op_deleg_want == NFS4_SHARE_WANT_READ_DELEG && in nfsd4_deleg_xgrade_none_ext()
5278 dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) { in nfsd4_deleg_xgrade_none_ext()
5279 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_deleg_xgrade_none_ext()
5280 open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE; in nfsd4_deleg_xgrade_none_ext()
5281 } else if (open->op_deleg_want == NFS4_SHARE_WANT_WRITE_DELEG && in nfsd4_deleg_xgrade_none_ext()
5282 dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) { in nfsd4_deleg_xgrade_none_ext()
5283 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_deleg_xgrade_none_ext()
5284 open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE; in nfsd4_deleg_xgrade_none_ext()
5295 struct nfsd4_compoundres *resp = rqstp->rq_resp; in nfsd4_process_open2()
5296 struct nfs4_client *cl = open->op_openowner->oo_owner.so_client; in nfsd4_process_open2()
5308 fp = find_or_add_file(open->op_file, current_fh); in nfsd4_process_open2()
5309 if (fp != open->op_file) { in nfsd4_process_open2()
5315 open->op_file = NULL; in nfsd4_process_open2()
5323 if (!open->op_stp) in nfsd4_process_open2()
5337 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5343 stp->st_stid.sc_type = NFS4_CLOSED_STID; in nfsd4_process_open2()
5345 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5349 stp->st_clnt_odstate = find_or_hash_clnt_odstate(fp, in nfsd4_process_open2()
5350 open->op_odstate); in nfsd4_process_open2()
5351 if (stp->st_clnt_odstate == open->op_odstate) in nfsd4_process_open2()
5352 open->op_odstate = NULL; in nfsd4_process_open2()
5355 nfs4_inc_and_copy_stateid(&open->op_stateid, &stp->st_stid); in nfsd4_process_open2()
5356 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5358 if (nfsd4_has_session(&resp->cstate)) { in nfsd4_process_open2()
5359 if (open->op_deleg_want & NFS4_SHARE_WANT_NO_DELEG) { in nfsd4_process_open2()
5360 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_process_open2()
5361 open->op_why_no_deleg = WND4_NOT_WANTED; in nfsd4_process_open2()
5373 trace_nfsd_open(&stp->st_stid.sc_stateid); in nfsd4_process_open2()
5376 if (open->op_delegate_type == NFS4_OPEN_DELEGATE_NONE && dp && in nfsd4_process_open2()
5377 open->op_deleg_want) in nfsd4_process_open2()
5382 if (status == 0 && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) in nfsd4_process_open2()
5383 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; in nfsd4_process_open2()
5387 open->op_rflags = NFS4_OPEN_RESULT_LOCKTYPE_POSIX; in nfsd4_process_open2()
5388 if (nfsd4_has_session(&resp->cstate)) in nfsd4_process_open2()
5389 open->op_rflags |= NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK; in nfsd4_process_open2()
5390 else if (!(open->op_openowner->oo_flags & NFS4_OO_CONFIRMED)) in nfsd4_process_open2()
5391 open->op_rflags |= NFS4_OPEN_RESULT_CONFIRM; in nfsd4_process_open2()
5394 nfs4_put_stid(&dp->dl_stid); in nfsd4_process_open2()
5396 nfs4_put_stid(&stp->st_stid); in nfsd4_process_open2()
5404 if (open->op_openowner) { in nfsd4_cleanup_open_state()
5405 struct nfs4_stateowner *so = &open->op_openowner->oo_owner; in nfsd4_cleanup_open_state()
5410 if (open->op_file) in nfsd4_cleanup_open_state()
5411 kmem_cache_free(file_slab, open->op_file); in nfsd4_cleanup_open_state()
5412 if (open->op_stp) in nfsd4_cleanup_open_state()
5413 nfs4_put_stid(&open->op_stp->st_stid); in nfsd4_cleanup_open_state()
5414 if (open->op_odstate) in nfsd4_cleanup_open_state()
5415 kmem_cache_free(odstate_slab, open->op_odstate); in nfsd4_cleanup_open_state()
5422 clientid_t *clid = &u->renew; in nfsd4_renew()
5431 clp = cstate->clp; in nfsd4_renew()
5432 if (!list_empty(&clp->cl_delegations) in nfsd4_renew()
5433 && clp->cl_cb_state != NFSD4_CB_UP) in nfsd4_renew()
5442 if (nn->grace_ended) in nfsd4_end_grace()
5446 nn->grace_ended = true; in nfsd4_end_grace()
5463 locks_end_grace(&nn->nfsd4_manager); in nfsd4_end_grace()
5477 time64_t double_grace_period_end = nn->boot_time + in clients_still_reclaiming()
5478 2 * nn->nfsd4_lease; in clients_still_reclaiming()
5480 if (nn->track_reclaim_completes && in clients_still_reclaiming()
5481 atomic_read(&nn->nr_reclaim_complete) == in clients_still_reclaiming()
5482 nn->reclaim_str_hashtbl_size) in clients_still_reclaiming()
5484 if (!nn->somebody_reclaimed) in clients_still_reclaiming()
5486 nn->somebody_reclaimed = false; in clients_still_reclaiming()
5505 if (last_refresh < lt->cutoff) in state_expired()
5507 time_remaining = last_refresh - lt->cutoff; in state_expired()
5508 lt->new_timeo = min(lt->new_timeo, time_remaining); in state_expired()
5515 spin_lock_init(&nn->nfsd_ssc_lock); in nfsd4_ssc_init_umount_work()
5516 INIT_LIST_HEAD(&nn->nfsd_ssc_mount_list); in nfsd4_ssc_init_umount_work()
5517 init_waitqueue_head(&nn->nfsd_ssc_waitq); in nfsd4_ssc_init_umount_work()
5530 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5531 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { in nfsd4_ssc_shutdown_umount()
5532 list_del(&ni->nsui_list); in nfsd4_ssc_shutdown_umount()
5533 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5534 mntput(ni->nsui_vfsmount); in nfsd4_ssc_shutdown_umount()
5536 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5538 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5547 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
5548 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { in nfsd4_ssc_expire_umount()
5549 if (time_after(jiffies, ni->nsui_expire)) { in nfsd4_ssc_expire_umount()
5550 if (refcount_read(&ni->nsui_refcnt) > 1) in nfsd4_ssc_expire_umount()
5554 ni->nsui_busy = true; in nfsd4_ssc_expire_umount()
5555 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
5556 mntput(ni->nsui_vfsmount); in nfsd4_ssc_expire_umount()
5557 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
5560 list_del(&ni->nsui_list); in nfsd4_ssc_expire_umount()
5570 wake_up_all(&nn->nfsd_ssc_waitq); in nfsd4_ssc_expire_umount()
5571 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
5585 .cutoff = ktime_get_boottime_seconds() - nn->nfsd4_lease, in nfs4_laundromat()
5586 .new_timeo = nn->nfsd4_lease in nfs4_laundromat()
5599 spin_lock(&nn->s2s_cp_lock); in nfs4_laundromat()
5600 idr_for_each_entry(&nn->s2s_cp_stateids, cps_t, i) { in nfs4_laundromat()
5602 if (cps->cp_stateid.sc_type == NFS4_COPYNOTIFY_STID && in nfs4_laundromat()
5603 state_expired(<, cps->cpntf_time)) in nfs4_laundromat()
5606 spin_unlock(&nn->s2s_cp_lock); in nfs4_laundromat()
5608 spin_lock(&nn->client_lock); in nfs4_laundromat()
5609 list_for_each_safe(pos, next, &nn->client_lru) { in nfs4_laundromat()
5611 if (!state_expired(<, clp->cl_time)) in nfs4_laundromat()
5615 list_add(&clp->cl_lru, &reaplist); in nfs4_laundromat()
5617 spin_unlock(&nn->client_lock); in nfs4_laundromat()
5620 trace_nfsd_clid_purged(&clp->cl_clientid); in nfs4_laundromat()
5621 list_del_init(&clp->cl_lru); in nfs4_laundromat()
5625 list_for_each_safe(pos, next, &nn->del_recall_lru) { in nfs4_laundromat()
5627 if (!state_expired(<, dp->dl_time)) in nfs4_laundromat()
5630 list_add(&dp->dl_recall_lru, &reaplist); in nfs4_laundromat()
5636 list_del_init(&dp->dl_recall_lru); in nfs4_laundromat()
5640 spin_lock(&nn->client_lock); in nfs4_laundromat()
5641 while (!list_empty(&nn->close_lru)) { in nfs4_laundromat()
5642 oo = list_first_entry(&nn->close_lru, struct nfs4_openowner, in nfs4_laundromat()
5644 if (!state_expired(<, oo->oo_time)) in nfs4_laundromat()
5646 list_del_init(&oo->oo_close_lru); in nfs4_laundromat()
5647 stp = oo->oo_last_closed_stid; in nfs4_laundromat()
5648 oo->oo_last_closed_stid = NULL; in nfs4_laundromat()
5649 spin_unlock(&nn->client_lock); in nfs4_laundromat()
5650 nfs4_put_stid(&stp->st_stid); in nfs4_laundromat()
5651 spin_lock(&nn->client_lock); in nfs4_laundromat()
5653 spin_unlock(&nn->client_lock); in nfs4_laundromat()
5658 * So, we clean out any un-revisited request after a lease period in nfs4_laundromat()
5667 spin_lock(&nn->blocked_locks_lock); in nfs4_laundromat()
5668 while (!list_empty(&nn->blocked_locks_lru)) { in nfs4_laundromat()
5669 nbl = list_first_entry(&nn->blocked_locks_lru, in nfs4_laundromat()
5671 if (!state_expired(<, nbl->nbl_time)) in nfs4_laundromat()
5673 list_move(&nbl->nbl_lru, &reaplist); in nfs4_laundromat()
5674 list_del_init(&nbl->nbl_list); in nfs4_laundromat()
5676 spin_unlock(&nn->blocked_locks_lock); in nfs4_laundromat()
5681 list_del_init(&nbl->nbl_lru); in nfs4_laundromat()
5685 /* service the server-to-server copy delayed unmount list */ in nfs4_laundromat()
5704 queue_delayed_work(laundry_wq, &nn->laundromat_work, t*HZ); in laundromat_main()
5709 if (!fh_match(&fhp->fh_handle, &stp->sc_file->fi_fhandle)) in nfs4_check_fh()
5720 if (stp->st_openstp) in nfs4_check_openmode()
5721 stp = stp->st_openstp; in nfs4_check_openmode()
5754 if (has_session && in->si_generation == 0) in check_stateid_generation()
5757 if (in->si_generation == ref->si_generation) in check_stateid_generation()
5765 * non-buggy client. For example, if the client sends a lock in check_stateid_generation()
5780 spin_lock(&s->sc_lock); in nfsd4_stid_check_stateid_generation()
5783 ret = check_stateid_generation(in, &s->sc_stateid, has_session); in nfsd4_stid_check_stateid_generation()
5784 spin_unlock(&s->sc_lock); in nfsd4_stid_check_stateid_generation()
5790 if (ols->st_stateowner->so_is_open_owner && in nfsd4_check_openowner_confirmed()
5791 !(openowner(ols->st_stateowner)->oo_flags & NFS4_OO_CONFIRMED)) in nfsd4_check_openowner_confirmed()
5804 if (!same_clid(&stateid->si_opaque.so_clid, &cl->cl_clientid)) in nfsd4_validate_stateid()
5806 spin_lock(&cl->cl_lock); in nfsd4_validate_stateid()
5813 switch (s->sc_type) { in nfsd4_validate_stateid()
5825 printk("unknown stateid type %x\n", s->sc_type); in nfsd4_validate_stateid()
5832 spin_unlock(&cl->cl_lock); in nfsd4_validate_stateid()
5856 status = set_client(&stateid->si_opaque.so_clid, cstate, nn); in nfsd4_lookup_stateid()
5858 if (cstate->session) in nfsd4_lookup_stateid()
5864 *s = find_stateid_by_type(cstate->clp, stateid, typemask); in nfsd4_lookup_stateid()
5867 if (((*s)->sc_type == NFS4_REVOKED_DELEG_STID) && !return_revoked) { in nfsd4_lookup_stateid()
5869 if (cstate->minorversion) in nfsd4_lookup_stateid()
5882 switch (s->sc_type) { in nfs4_find_file()
5884 if (WARN_ON_ONCE(!s->sc_file->fi_deleg_file)) in nfs4_find_file()
5886 return nfsd_file_get(s->sc_file->fi_deleg_file); in nfs4_find_file()
5890 return find_readable_file(s->sc_file); in nfs4_find_file()
5892 return find_writeable_file(s->sc_file); in nfs4_find_file()
5919 status = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry, in nfs4_check_file()
5937 WARN_ON_ONCE(cps->cp_stateid.sc_type != NFS4_COPYNOTIFY_STID); in _free_cpntf_state_locked()
5938 if (!refcount_dec_and_test(&cps->cp_stateid.sc_count)) in _free_cpntf_state_locked()
5940 list_del(&cps->cp_list); in _free_cpntf_state_locked()
5941 idr_remove(&nn->s2s_cp_stateids, in _free_cpntf_state_locked()
5942 cps->cp_stateid.stid.si_opaque.so_id); in _free_cpntf_state_locked()
5957 if (st->si_opaque.so_clid.cl_id != nn->s2s_cp_cl_id) in manage_cpntf_state()
5959 spin_lock(&nn->s2s_cp_lock); in manage_cpntf_state()
5960 cps_t = idr_find(&nn->s2s_cp_stateids, st->si_opaque.so_id); in manage_cpntf_state()
5964 if (state->cp_stateid.sc_type != NFS4_COPYNOTIFY_STID) { in manage_cpntf_state()
5969 refcount_inc(&state->cp_stateid.sc_count); in manage_cpntf_state()
5974 spin_unlock(&nn->s2s_cp_lock); in manage_cpntf_state()
5993 cps->cpntf_time = ktime_get_boottime_seconds(); in find_cpntf_state()
5996 found = lookup_clientid(&cps->cp_p_clid, true, nn); in find_cpntf_state()
6000 *stid = find_stateid_by_type(found, &cps->cp_p_stateid, in find_cpntf_state()
6015 spin_lock(&nn->s2s_cp_lock); in nfs4_put_cpntf_state()
6017 spin_unlock(&nn->s2s_cp_lock); in nfs4_put_cpntf_state()
6054 switch (s->sc_type) { in nfs4_preprocess_stateid_op()
6090 struct nfsd4_test_stateid *test_stateid = &u->test_stateid; in nfsd4_test_stateid()
6092 struct nfs4_client *cl = cstate->clp; in nfsd4_test_stateid()
6094 list_for_each_entry(stateid, &test_stateid->ts_stateid_list, ts_id_list) in nfsd4_test_stateid()
6095 stateid->ts_id_status = in nfsd4_test_stateid()
6096 nfsd4_validate_stateid(cl, &stateid->ts_id_stateid); in nfsd4_test_stateid()
6111 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); in nfsd4_free_lock_stateid()
6116 if (check_for_locks(stp->st_stid.sc_file, in nfsd4_free_lock_stateid()
6117 lockowner(stp->st_stateowner))) in nfsd4_free_lock_stateid()
6124 mutex_unlock(&stp->st_mutex); in nfsd4_free_lock_stateid()
6134 struct nfsd4_free_stateid *free_stateid = &u->free_stateid; in nfsd4_free_stateid()
6135 stateid_t *stateid = &free_stateid->fr_stateid; in nfsd4_free_stateid()
6138 struct nfs4_client *cl = cstate->clp; in nfsd4_free_stateid()
6141 spin_lock(&cl->cl_lock); in nfsd4_free_stateid()
6145 spin_lock(&s->sc_lock); in nfsd4_free_stateid()
6146 switch (s->sc_type) { in nfsd4_free_stateid()
6151 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); in nfsd4_free_stateid()
6157 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6158 refcount_inc(&s->sc_count); in nfsd4_free_stateid()
6159 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6163 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6165 list_del_init(&dp->dl_recall_lru); in nfsd4_free_stateid()
6166 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6172 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6174 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6188 struct svc_fh *current_fh = &cstate->current_fh; in nfs4_seqid_op_checks()
6189 struct nfs4_stateowner *sop = stp->st_stateowner; in nfs4_seqid_op_checks()
6198 status = check_stateid_generation(stateid, &stp->st_stid.sc_stateid, nfsd4_has_session(cstate)); in nfs4_seqid_op_checks()
6200 status = nfs4_check_fh(current_fh, &stp->st_stid); in nfs4_seqid_op_checks()
6202 mutex_unlock(&stp->st_mutex); in nfs4_seqid_op_checks()
6226 nfsd4_cstate_assign_replay(cstate, stp->st_stateowner); in nfs4_preprocess_seqid_op()
6232 nfs4_put_stid(&stp->st_stid); in nfs4_preprocess_seqid_op()
6247 oo = openowner(stp->st_stateowner); in nfs4_preprocess_confirmed_seqid_op()
6248 if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { in nfs4_preprocess_confirmed_seqid_op()
6249 mutex_unlock(&stp->st_mutex); in nfs4_preprocess_confirmed_seqid_op()
6250 nfs4_put_stid(&stp->st_stid); in nfs4_preprocess_confirmed_seqid_op()
6261 struct nfsd4_open_confirm *oc = &u->open_confirm; in nfsd4_open_confirm()
6268 cstate->current_fh.fh_dentry); in nfsd4_open_confirm()
6270 status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0); in nfsd4_open_confirm()
6275 oc->oc_seqid, &oc->oc_req_stateid, in nfsd4_open_confirm()
6279 oo = openowner(stp->st_stateowner); in nfsd4_open_confirm()
6281 if (oo->oo_flags & NFS4_OO_CONFIRMED) { in nfsd4_open_confirm()
6282 mutex_unlock(&stp->st_mutex); in nfsd4_open_confirm()
6285 oo->oo_flags |= NFS4_OO_CONFIRMED; in nfsd4_open_confirm()
6286 nfs4_inc_and_copy_stateid(&oc->oc_resp_stateid, &stp->st_stid); in nfsd4_open_confirm()
6287 mutex_unlock(&stp->st_mutex); in nfsd4_open_confirm()
6288 trace_nfsd_open_confirm(oc->oc_seqid, &stp->st_stid.sc_stateid); in nfsd4_open_confirm()
6289 nfsd4_client_record_create(oo->oo_owner.so_client); in nfsd4_open_confirm()
6292 nfs4_put_stid(&stp->st_stid); in nfsd4_open_confirm()
6302 nfs4_file_put_access(stp->st_stid.sc_file, access); in nfs4_stateid_downgrade_bit()
6328 struct nfsd4_open_downgrade *od = &u->open_downgrade; in nfsd4_open_downgrade()
6334 cstate->current_fh.fh_dentry); in nfsd4_open_downgrade()
6337 if (od->od_deleg_want) in nfsd4_open_downgrade()
6339 od->od_deleg_want); in nfsd4_open_downgrade()
6341 status = nfs4_preprocess_confirmed_seqid_op(cstate, od->od_seqid, in nfsd4_open_downgrade()
6342 &od->od_stateid, &stp, nn); in nfsd4_open_downgrade()
6346 if (!test_access(od->od_share_access, stp)) { in nfsd4_open_downgrade()
6348 stp->st_access_bmap, od->od_share_access); in nfsd4_open_downgrade()
6351 if (!test_deny(od->od_share_deny, stp)) { in nfsd4_open_downgrade()
6353 stp->st_deny_bmap, od->od_share_deny); in nfsd4_open_downgrade()
6356 nfs4_stateid_downgrade(stp, od->od_share_access); in nfsd4_open_downgrade()
6357 reset_union_bmap_deny(od->od_share_deny, stp); in nfsd4_open_downgrade()
6358 nfs4_inc_and_copy_stateid(&od->od_stateid, &stp->st_stid); in nfsd4_open_downgrade()
6361 mutex_unlock(&stp->st_mutex); in nfsd4_open_downgrade()
6362 nfs4_put_stid(&stp->st_stid); in nfsd4_open_downgrade()
6370 struct nfs4_client *clp = s->st_stid.sc_client; in nfsd4_close_open_stateid()
6374 spin_lock(&clp->cl_lock); in nfsd4_close_open_stateid()
6377 if (clp->cl_minorversion) { in nfsd4_close_open_stateid()
6380 spin_unlock(&clp->cl_lock); in nfsd4_close_open_stateid()
6383 spin_unlock(&clp->cl_lock); in nfsd4_close_open_stateid()
6386 move_to_close_lru(s, clp->net); in nfsd4_close_open_stateid()
6397 struct nfsd4_close *close = &u->close; in nfsd4_close()
6404 cstate->current_fh.fh_dentry); in nfsd4_close()
6406 status = nfs4_preprocess_seqid_op(cstate, close->cl_seqid, in nfsd4_close()
6407 &close->cl_stateid, in nfsd4_close()
6414 stp->st_stid.sc_type = NFS4_CLOSED_STID; in nfsd4_close()
6422 nfs4_inc_and_copy_stateid(&close->cl_stateid, &stp->st_stid); in nfsd4_close()
6425 mutex_unlock(&stp->st_mutex); in nfsd4_close()
6434 memcpy(&close->cl_stateid, &close_stateid, sizeof(close->cl_stateid)); in nfsd4_close()
6437 nfs4_put_stid(&stp->st_stid); in nfsd4_close()
6446 struct nfsd4_delegreturn *dr = &u->delegreturn; in nfsd4_delegreturn()
6448 stateid_t *stateid = &dr->dr_stateid; in nfsd4_delegreturn()
6453 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) in nfsd4_delegreturn()
6460 status = nfsd4_stid_check_stateid_generation(stateid, &dp->dl_stid, nfsd4_has_session(cstate)); in nfsd4_delegreturn()
6466 nfs4_put_stid(&dp->dl_stid); in nfsd4_delegreturn()
6479 return end > start ? end - 1: NFS4_MAX_UINT64; in last_byte_offset()
6483 * TODO: Linux file offsets are _signed_ 64-bit quantities, which means that
6484 * we can't properly handle lock requests that go beyond the (2^63 - 1)-th
6485 * byte, because of sign extension problems. Since NFSv4 calls for 64-bit
6486 * locking, this prevents us from being completely protocol-compliant. The
6493 if (lock->fl_start < 0) in nfs4_transform_lock_offset()
6494 lock->fl_start = OFFSET_MAX; in nfs4_transform_lock_offset()
6495 if (lock->fl_end < 0) in nfs4_transform_lock_offset()
6496 lock->fl_end = OFFSET_MAX; in nfs4_transform_lock_offset()
6504 nfs4_get_stateowner(&lo->lo_owner); in nfsd4_fl_get_owner()
6514 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_fl_put_owner()
6520 struct nfs4_lockowner *lo = (struct nfs4_lockowner *)fl->fl_owner; in nfsd4_lm_notify()
6521 struct net *net = lo->lo_owner.so_client->net; in nfsd4_lm_notify()
6528 spin_lock(&nn->blocked_locks_lock); in nfsd4_lm_notify()
6529 if (!list_empty(&nbl->nbl_list)) { in nfsd4_lm_notify()
6530 list_del_init(&nbl->nbl_list); in nfsd4_lm_notify()
6531 list_del_init(&nbl->nbl_lru); in nfsd4_lm_notify()
6534 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lm_notify()
6538 nfsd4_run_cb(&nbl->nbl_cb); in nfsd4_lm_notify()
6553 if (fl->fl_lmops == &nfsd_posix_mng_ops) { in nfs4_set_lock_denied()
6554 lo = (struct nfs4_lockowner *) fl->fl_owner; in nfs4_set_lock_denied()
6555 xdr_netobj_dup(&deny->ld_owner, &lo->lo_owner.so_owner, in nfs4_set_lock_denied()
6557 if (!deny->ld_owner.data) in nfs4_set_lock_denied()
6560 deny->ld_clientid = lo->lo_owner.so_client->cl_clientid; in nfs4_set_lock_denied()
6563 deny->ld_owner.len = 0; in nfs4_set_lock_denied()
6564 deny->ld_owner.data = NULL; in nfs4_set_lock_denied()
6565 deny->ld_clientid.cl_boot = 0; in nfs4_set_lock_denied()
6566 deny->ld_clientid.cl_id = 0; in nfs4_set_lock_denied()
6568 deny->ld_start = fl->fl_start; in nfs4_set_lock_denied()
6569 deny->ld_length = NFS4_MAX_UINT64; in nfs4_set_lock_denied()
6570 if (fl->fl_end != NFS4_MAX_UINT64) in nfs4_set_lock_denied()
6571 deny->ld_length = fl->fl_end - fl->fl_start + 1; in nfs4_set_lock_denied()
6572 deny->ld_type = NFS4_READ_LT; in nfs4_set_lock_denied()
6573 if (fl->fl_type != F_RDLCK) in nfs4_set_lock_denied()
6574 deny->ld_type = NFS4_WRITE_LT; in nfs4_set_lock_denied()
6583 lockdep_assert_held(&clp->cl_lock); in find_lockowner_str_locked()
6585 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[strhashval], in find_lockowner_str_locked()
6587 if (so->so_is_open_owner) in find_lockowner_str_locked()
6600 spin_lock(&clp->cl_lock); in find_lockowner_str()
6602 spin_unlock(&clp->cl_lock); in find_lockowner_str()
6625 * Called in nfsd4_lock - therefore, OPEN and OPEN_CONFIRM (if needed) has
6637 lo = alloc_stateowner(lockowner_slab, &lock->lk_new_owner, clp); in alloc_init_lock_stateowner()
6640 INIT_LIST_HEAD(&lo->lo_blocked); in alloc_init_lock_stateowner()
6641 INIT_LIST_HEAD(&lo->lo_owner.so_stateids); in alloc_init_lock_stateowner()
6642 lo->lo_owner.so_is_open_owner = 0; in alloc_init_lock_stateowner()
6643 lo->lo_owner.so_seqid = lock->lk_new_lock_seqid; in alloc_init_lock_stateowner()
6644 lo->lo_owner.so_ops = &lockowner_ops; in alloc_init_lock_stateowner()
6645 spin_lock(&clp->cl_lock); in alloc_init_lock_stateowner()
6646 ret = find_lockowner_str_locked(clp, &lock->lk_new_owner); in alloc_init_lock_stateowner()
6648 list_add(&lo->lo_owner.so_strhash, in alloc_init_lock_stateowner()
6649 &clp->cl_ownerstr_hashtbl[strhashval]); in alloc_init_lock_stateowner()
6652 nfs4_free_stateowner(&lo->lo_owner); in alloc_init_lock_stateowner()
6654 spin_unlock(&clp->cl_lock); in alloc_init_lock_stateowner()
6664 lockdep_assert_held(&ost->st_stid.sc_client->cl_lock); in find_lock_stateid()
6666 /* If ost is not hashed, ost->st_locks will not be valid */ in find_lock_stateid()
6668 list_for_each_entry(lst, &ost->st_locks, st_locks) { in find_lock_stateid()
6669 if (lst->st_stateowner == &lo->lo_owner) { in find_lock_stateid()
6670 refcount_inc(&lst->st_stid.sc_count); in find_lock_stateid()
6682 struct nfs4_client *clp = lo->lo_owner.so_client; in init_lock_stateid()
6685 mutex_init(&stp->st_mutex); in init_lock_stateid()
6686 mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX); in init_lock_stateid()
6688 spin_lock(&clp->cl_lock); in init_lock_stateid()
6694 refcount_inc(&stp->st_stid.sc_count); in init_lock_stateid()
6695 stp->st_stid.sc_type = NFS4_LOCK_STID; in init_lock_stateid()
6696 stp->st_stateowner = nfs4_get_stateowner(&lo->lo_owner); in init_lock_stateid()
6698 stp->st_stid.sc_file = fp; in init_lock_stateid()
6699 stp->st_access_bmap = 0; in init_lock_stateid()
6700 stp->st_deny_bmap = open_stp->st_deny_bmap; in init_lock_stateid()
6701 stp->st_openstp = open_stp; in init_lock_stateid()
6702 spin_lock(&fp->fi_lock); in init_lock_stateid()
6703 list_add(&stp->st_locks, &open_stp->st_locks); in init_lock_stateid()
6704 list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids); in init_lock_stateid()
6705 list_add(&stp->st_perfile, &fp->fi_stateids); in init_lock_stateid()
6706 spin_unlock(&fp->fi_lock); in init_lock_stateid()
6707 spin_unlock(&clp->cl_lock); in init_lock_stateid()
6710 spin_unlock(&clp->cl_lock); in init_lock_stateid()
6712 nfs4_put_stid(&retstp->st_stid); in init_lock_stateid()
6716 mutex_unlock(&stp->st_mutex); in init_lock_stateid()
6719 spin_unlock(&clp->cl_lock); in init_lock_stateid()
6720 mutex_unlock(&stp->st_mutex); in init_lock_stateid()
6731 struct nfs4_openowner *oo = openowner(ost->st_stateowner); in find_or_create_lock_stateid()
6732 struct nfs4_client *clp = oo->oo_owner.so_client; in find_or_create_lock_stateid()
6735 spin_lock(&clp->cl_lock); in find_or_create_lock_stateid()
6737 spin_unlock(&clp->cl_lock); in find_or_create_lock_stateid()
6741 nfs4_put_stid(&lst->st_stid); in find_or_create_lock_stateid()
6765 struct nfs4_file *fp = lock_stp->st_stid.sc_file; in get_lock_access()
6767 lockdep_assert_held(&fp->fi_lock); in get_lock_access()
6782 struct nfs4_file *fi = ost->st_stid.sc_file; in lookup_or_create_lock_state()
6783 struct nfs4_openowner *oo = openowner(ost->st_stateowner); in lookup_or_create_lock_state()
6784 struct nfs4_client *cl = oo->oo_owner.so_client; in lookup_or_create_lock_state()
6785 struct inode *inode = d_inode(cstate->current_fh.fh_dentry); in lookup_or_create_lock_state()
6790 lo = find_lockowner_str(cl, &lock->lk_new_owner); in lookup_or_create_lock_state()
6792 strhashval = ownerstr_hashval(&lock->lk_new_owner); in lookup_or_create_lock_state()
6799 if (!cstate->minorversion && in lookup_or_create_lock_state()
6800 lock->lk_new_lock_seqid != lo->lo_owner.so_seqid) in lookup_or_create_lock_state()
6813 nfs4_put_stateowner(&lo->lo_owner); in lookup_or_create_lock_state()
6824 struct nfsd4_lock *lock = &u->lock; in nfsd4_lock()
6845 (long long) lock->lk_offset, in nfsd4_lock()
6846 (long long) lock->lk_length); in nfsd4_lock()
6848 if (check_lock_length(lock->lk_offset, lock->lk_length)) in nfsd4_lock()
6851 if ((status = fh_verify(rqstp, &cstate->current_fh, in nfsd4_lock()
6856 sb = cstate->current_fh.fh_dentry->d_sb; in nfsd4_lock()
6858 if (lock->lk_is_new) { in nfsd4_lock()
6861 memcpy(&lock->lk_new_clientid, in nfsd4_lock()
6862 &cstate->clp->cl_clientid, in nfsd4_lock()
6867 lock->lk_new_open_seqid, in nfsd4_lock()
6868 &lock->lk_new_open_stateid, in nfsd4_lock()
6872 mutex_unlock(&open_stp->st_mutex); in nfsd4_lock()
6873 open_sop = openowner(open_stp->st_stateowner); in nfsd4_lock()
6875 if (!same_clid(&open_sop->oo_owner.so_client->cl_clientid, in nfsd4_lock()
6876 &lock->lk_new_clientid)) in nfsd4_lock()
6882 lock->lk_old_lock_seqid, in nfsd4_lock()
6883 &lock->lk_old_lock_stateid, in nfsd4_lock()
6888 lock_sop = lockowner(lock_stp->st_stateowner); in nfsd4_lock()
6890 lkflg = setlkflg(lock->lk_type); in nfsd4_lock()
6896 if (locks_in_grace(net) && !lock->lk_reclaim) in nfsd4_lock()
6899 if (!locks_in_grace(net) && lock->lk_reclaim) in nfsd4_lock()
6902 if (lock->lk_reclaim) in nfsd4_lock()
6905 fp = lock_stp->st_stid.sc_file; in nfsd4_lock()
6906 switch (lock->lk_type) { in nfsd4_lock()
6909 !(sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS)) in nfsd4_lock()
6913 spin_lock(&fp->fi_lock); in nfsd4_lock()
6917 spin_unlock(&fp->fi_lock); in nfsd4_lock()
6922 !(sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS)) in nfsd4_lock()
6926 spin_lock(&fp->fi_lock); in nfsd4_lock()
6930 spin_unlock(&fp->fi_lock); in nfsd4_lock()
6943 nbl = find_or_allocate_block(lock_sop, &fp->fi_fhandle, nn); in nfsd4_lock()
6950 file_lock = &nbl->nbl_lock; in nfsd4_lock()
6951 file_lock->fl_type = fl_type; in nfsd4_lock()
6952 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(&lock_sop->lo_owner)); in nfsd4_lock()
6953 file_lock->fl_pid = current->tgid; in nfsd4_lock()
6954 file_lock->fl_file = nf->nf_file; in nfsd4_lock()
6955 file_lock->fl_flags = fl_flags; in nfsd4_lock()
6956 file_lock->fl_lmops = &nfsd_posix_mng_ops; in nfsd4_lock()
6957 file_lock->fl_start = lock->lk_offset; in nfsd4_lock()
6958 file_lock->fl_end = last_byte_offset(lock->lk_offset, lock->lk_length); in nfsd4_lock()
6969 nbl->nbl_time = ktime_get_boottime_seconds(); in nfsd4_lock()
6970 spin_lock(&nn->blocked_locks_lock); in nfsd4_lock()
6971 list_add_tail(&nbl->nbl_list, &lock_sop->lo_blocked); in nfsd4_lock()
6972 list_add_tail(&nbl->nbl_lru, &nn->blocked_locks_lru); in nfsd4_lock()
6973 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lock()
6976 err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, conflock); in nfsd4_lock()
6979 nfs4_inc_and_copy_stateid(&lock->lk_resp_stateid, &lock_stp->st_stid); in nfsd4_lock()
6981 if (lock->lk_reclaim) in nfsd4_lock()
6982 nn->somebody_reclaimed = true; in nfsd4_lock()
6987 case -EAGAIN: /* conflock holds conflicting lock */ in nfsd4_lock()
6990 nfs4_set_lock_denied(conflock, &lock->lk_denied); in nfsd4_lock()
6992 case -EDEADLK: in nfsd4_lock()
7004 spin_lock(&nn->blocked_locks_lock); in nfsd4_lock()
7005 list_del_init(&nbl->nbl_list); in nfsd4_lock()
7006 list_del_init(&nbl->nbl_lru); in nfsd4_lock()
7007 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lock()
7015 if (cstate->replay_owner && in nfsd4_lock()
7016 cstate->replay_owner != &lock_sop->lo_owner && in nfsd4_lock()
7018 lock_sop->lo_owner.so_seqid++; in nfsd4_lock()
7021 * If this is a new, never-before-used stateid, and we are in nfsd4_lock()
7027 mutex_unlock(&lock_stp->st_mutex); in nfsd4_lock()
7029 nfs4_put_stid(&lock_stp->st_stid); in nfsd4_lock()
7032 nfs4_put_stid(&open_stp->st_stid); in nfsd4_lock()
7053 err = nfserrno(nfsd_open_break_lease(fhp->fh_dentry->d_inode, in nfsd_test_lock()
7057 lock->fl_file = nf->nf_file; in nfsd_test_lock()
7058 err = nfserrno(vfs_test_lock(nf->nf_file, lock)); in nfsd_test_lock()
7059 lock->fl_file = NULL; in nfsd_test_lock()
7073 struct nfsd4_lockt *lockt = &u->lockt; in nfsd4_lockt()
7082 if (check_lock_length(lockt->lt_offset, lockt->lt_length)) in nfsd4_lockt()
7086 status = set_client(&lockt->lt_clientid, cstate, nn); in nfsd4_lockt()
7091 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) in nfsd4_lockt()
7101 switch (lockt->lt_type) { in nfsd4_lockt()
7104 file_lock->fl_type = F_RDLCK; in nfsd4_lockt()
7108 file_lock->fl_type = F_WRLCK; in nfsd4_lockt()
7116 lo = find_lockowner_str(cstate->clp, &lockt->lt_owner); in nfsd4_lockt()
7118 file_lock->fl_owner = (fl_owner_t)lo; in nfsd4_lockt()
7119 file_lock->fl_pid = current->tgid; in nfsd4_lockt()
7120 file_lock->fl_flags = FL_POSIX; in nfsd4_lockt()
7122 file_lock->fl_start = lockt->lt_offset; in nfsd4_lockt()
7123 file_lock->fl_end = last_byte_offset(lockt->lt_offset, lockt->lt_length); in nfsd4_lockt()
7127 status = nfsd_test_lock(rqstp, &cstate->current_fh, file_lock); in nfsd4_lockt()
7131 if (file_lock->fl_type != F_UNLCK) { in nfsd4_lockt()
7133 nfs4_set_lock_denied(file_lock, &lockt->lt_denied); in nfsd4_lockt()
7137 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_lockt()
7147 struct nfsd4_locku *locku = &u->locku; in nfsd4_locku()
7156 (long long) locku->lu_offset, in nfsd4_locku()
7157 (long long) locku->lu_length); in nfsd4_locku()
7159 if (check_lock_length(locku->lu_offset, locku->lu_length)) in nfsd4_locku()
7162 status = nfs4_preprocess_seqid_op(cstate, locku->lu_seqid, in nfsd4_locku()
7163 &locku->lu_stateid, NFS4_LOCK_STID, in nfsd4_locku()
7167 nf = find_any_file(stp->st_stid.sc_file); in nfsd4_locku()
7179 file_lock->fl_type = F_UNLCK; in nfsd4_locku()
7180 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(stp->st_stateowner)); in nfsd4_locku()
7181 file_lock->fl_pid = current->tgid; in nfsd4_locku()
7182 file_lock->fl_file = nf->nf_file; in nfsd4_locku()
7183 file_lock->fl_flags = FL_POSIX; in nfsd4_locku()
7184 file_lock->fl_lmops = &nfsd_posix_mng_ops; in nfsd4_locku()
7185 file_lock->fl_start = locku->lu_offset; in nfsd4_locku()
7187 file_lock->fl_end = last_byte_offset(locku->lu_offset, in nfsd4_locku()
7188 locku->lu_length); in nfsd4_locku()
7191 err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, NULL); in nfsd4_locku()
7196 nfs4_inc_and_copy_stateid(&locku->lu_stateid, &stp->st_stid); in nfsd4_locku()
7200 mutex_unlock(&stp->st_mutex); in nfsd4_locku()
7201 nfs4_put_stid(&stp->st_stid); in nfsd4_locku()
7233 inode = locks_inode(nf->nf_file); in check_for_locks()
7234 flctx = inode->i_flctx; in check_for_locks()
7236 if (flctx && !list_empty_careful(&flctx->flc_posix)) { in check_for_locks()
7237 spin_lock(&flctx->flc_lock); in check_for_locks()
7238 list_for_each_entry(fl, &flctx->flc_posix, fl_list) { in check_for_locks()
7239 if (fl->fl_owner == (fl_owner_t)lowner) { in check_for_locks()
7244 spin_unlock(&flctx->flc_lock); in check_for_locks()
7255 struct nfsd4_release_lockowner *rlockowner = &u->release_lockowner; in nfsd4_release_lockowner()
7256 clientid_t *clid = &rlockowner->rl_clientid; in nfsd4_release_lockowner()
7260 struct xdr_netobj *owner = &rlockowner->rl_owner; in nfsd4_release_lockowner()
7268 clid->cl_boot, clid->cl_id); in nfsd4_release_lockowner()
7274 clp = cstate->clp; in nfsd4_release_lockowner()
7276 spin_lock(&clp->cl_lock); in nfsd4_release_lockowner()
7277 list_for_each_entry(sop, &clp->cl_ownerstr_hashtbl[hashval], in nfsd4_release_lockowner()
7280 if (sop->so_is_open_owner || !same_owner_str(sop, owner)) in nfsd4_release_lockowner()
7285 list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) { in nfsd4_release_lockowner()
7286 if (check_for_locks(stp->st_stid.sc_file, lo)) { in nfsd4_release_lockowner()
7288 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
7297 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
7302 while (!list_empty(&lo->lo_owner.so_stateids)) { in nfsd4_release_lockowner()
7303 stp = list_first_entry(&lo->lo_owner.so_stateids, in nfsd4_release_lockowner()
7309 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
7312 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_release_lockowner()
7329 return (crp && crp->cr_clp); in nfs4_has_reclaimed_state()
7348 INIT_LIST_HEAD(&crp->cr_strhash); in nfs4_client_to_reclaim()
7349 list_add(&crp->cr_strhash, &nn->reclaim_str_hashtbl[strhashval]); in nfs4_client_to_reclaim()
7350 crp->cr_name.data = name.data; in nfs4_client_to_reclaim()
7351 crp->cr_name.len = name.len; in nfs4_client_to_reclaim()
7352 crp->cr_princhash.data = princhash.data; in nfs4_client_to_reclaim()
7353 crp->cr_princhash.len = princhash.len; in nfs4_client_to_reclaim()
7354 crp->cr_clp = NULL; in nfs4_client_to_reclaim()
7355 nn->reclaim_str_hashtbl_size++; in nfs4_client_to_reclaim()
7363 list_del(&crp->cr_strhash); in nfs4_remove_reclaim_record()
7364 kfree(crp->cr_name.data); in nfs4_remove_reclaim_record()
7365 kfree(crp->cr_princhash.data); in nfs4_remove_reclaim_record()
7367 nn->reclaim_str_hashtbl_size--; in nfs4_remove_reclaim_record()
7377 while (!list_empty(&nn->reclaim_str_hashtbl[i])) { in nfs4_release_reclaim()
7378 crp = list_entry(nn->reclaim_str_hashtbl[i].next, in nfs4_release_reclaim()
7383 WARN_ON_ONCE(nn->reclaim_str_hashtbl_size); in nfs4_release_reclaim()
7395 list_for_each_entry(crp, &nn->reclaim_str_hashtbl[strhashval], cr_strhash) { in nfsd4_find_reclaim_client()
7396 if (compare_blob(&crp->cr_name, &name) == 0) { in nfsd4_find_reclaim_client()
7406 if (test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &clp->cl_flags)) in nfs4_check_open_reclaim()
7433 max_delegations = nr_free_buffer_pages() >> (20 - 2 - PAGE_SHIFT); in set_max_delegations()
7441 nn->conf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE, in nfs4_state_create_net()
7444 if (!nn->conf_id_hashtbl) in nfs4_state_create_net()
7446 nn->unconf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE, in nfs4_state_create_net()
7449 if (!nn->unconf_id_hashtbl) in nfs4_state_create_net()
7451 nn->sessionid_hashtbl = kmalloc_array(SESSION_HASH_SIZE, in nfs4_state_create_net()
7454 if (!nn->sessionid_hashtbl) in nfs4_state_create_net()
7458 INIT_LIST_HEAD(&nn->conf_id_hashtbl[i]); in nfs4_state_create_net()
7459 INIT_LIST_HEAD(&nn->unconf_id_hashtbl[i]); in nfs4_state_create_net()
7462 INIT_LIST_HEAD(&nn->sessionid_hashtbl[i]); in nfs4_state_create_net()
7463 nn->conf_name_tree = RB_ROOT; in nfs4_state_create_net()
7464 nn->unconf_name_tree = RB_ROOT; in nfs4_state_create_net()
7465 nn->boot_time = ktime_get_real_seconds(); in nfs4_state_create_net()
7466 nn->grace_ended = false; in nfs4_state_create_net()
7467 nn->nfsd4_manager.block_opens = true; in nfs4_state_create_net()
7468 INIT_LIST_HEAD(&nn->nfsd4_manager.list); in nfs4_state_create_net()
7469 INIT_LIST_HEAD(&nn->client_lru); in nfs4_state_create_net()
7470 INIT_LIST_HEAD(&nn->close_lru); in nfs4_state_create_net()
7471 INIT_LIST_HEAD(&nn->del_recall_lru); in nfs4_state_create_net()
7472 spin_lock_init(&nn->client_lock); in nfs4_state_create_net()
7473 spin_lock_init(&nn->s2s_cp_lock); in nfs4_state_create_net()
7474 idr_init(&nn->s2s_cp_stateids); in nfs4_state_create_net()
7476 spin_lock_init(&nn->blocked_locks_lock); in nfs4_state_create_net()
7477 INIT_LIST_HEAD(&nn->blocked_locks_lru); in nfs4_state_create_net()
7479 INIT_DELAYED_WORK(&nn->laundromat_work, laundromat_main); in nfs4_state_create_net()
7485 kfree(nn->unconf_id_hashtbl); in nfs4_state_create_net()
7487 kfree(nn->conf_id_hashtbl); in nfs4_state_create_net()
7489 return -ENOMEM; in nfs4_state_create_net()
7500 while (!list_empty(&nn->conf_id_hashtbl[i])) { in nfs4_state_destroy_net()
7501 clp = list_entry(nn->conf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); in nfs4_state_destroy_net()
7506 WARN_ON(!list_empty(&nn->blocked_locks_lru)); in nfs4_state_destroy_net()
7509 while (!list_empty(&nn->unconf_id_hashtbl[i])) { in nfs4_state_destroy_net()
7510 clp = list_entry(nn->unconf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); in nfs4_state_destroy_net()
7515 kfree(nn->sessionid_hashtbl); in nfs4_state_destroy_net()
7516 kfree(nn->unconf_id_hashtbl); in nfs4_state_destroy_net()
7517 kfree(nn->conf_id_hashtbl); in nfs4_state_destroy_net()
7530 locks_start_grace(net, &nn->nfsd4_manager); in nfs4_state_start_net()
7532 if (nn->track_reclaim_completes && nn->reclaim_str_hashtbl_size == 0) in nfs4_state_start_net()
7534 printk(KERN_INFO "NFSD: starting %lld-second grace period (net %x)\n", in nfs4_state_start_net()
7535 nn->nfsd4_grace, net->ns.inum); in nfs4_state_start_net()
7537 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_grace * HZ); in nfs4_state_start_net()
7542 net->ns.inum); in nfs4_state_start_net()
7543 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_lease * HZ); in nfs4_state_start_net()
7557 ret = -ENOMEM; in nfs4_state_start()
7580 cancel_delayed_work_sync(&nn->laundromat_work); in nfs4_state_shutdown_net()
7581 locks_end_grace(&nn->nfsd4_manager); in nfs4_state_shutdown_net()
7585 list_for_each_safe(pos, next, &nn->del_recall_lru) { in nfs4_state_shutdown_net()
7588 list_add(&dp->dl_recall_lru, &reaplist); in nfs4_state_shutdown_net()
7593 list_del_init(&dp->dl_recall_lru); in nfs4_state_shutdown_net()
7616 memcpy(stateid, &cstate->current_stateid, sizeof(stateid_t)); in get_stateid()
7622 if (cstate->minorversion) { in put_stateid()
7623 memcpy(&cstate->current_stateid, stateid, sizeof(stateid_t)); in put_stateid()
7641 put_stateid(cstate, &u->open_downgrade.od_stateid); in nfsd4_set_opendowngradestateid()
7648 put_stateid(cstate, &u->open.op_stateid); in nfsd4_set_openstateid()
7655 put_stateid(cstate, &u->close.cl_stateid); in nfsd4_set_closestateid()
7662 put_stateid(cstate, &u->lock.lk_resp_stateid); in nfsd4_set_lockstateid()
7673 get_stateid(cstate, &u->open_downgrade.od_stateid); in nfsd4_get_opendowngradestateid()
7680 get_stateid(cstate, &u->delegreturn.dr_stateid); in nfsd4_get_delegreturnstateid()
7687 get_stateid(cstate, &u->free_stateid.fr_stateid); in nfsd4_get_freestateid()
7694 get_stateid(cstate, &u->setattr.sa_stateid); in nfsd4_get_setattrstateid()
7701 get_stateid(cstate, &u->close.cl_stateid); in nfsd4_get_closestateid()
7708 get_stateid(cstate, &u->locku.lu_stateid); in nfsd4_get_lockustateid()
7715 get_stateid(cstate, &u->read.rd_stateid); in nfsd4_get_readstateid()
7722 get_stateid(cstate, &u->write.wr_stateid); in nfsd4_get_writestateid()