Lines Matching +full:embedded +full:- +full:trace +full:- +full:extension
58 #include "trace.h"
106 * A waitqueue for all in-progress 4.0 CLOSE operations that are waiting for
139 rc = -ENOMEM; in nfsd4_create_laundry_wq()
150 return ses->se_flags & NFS4_SESSION_DEAD; in is_session_dead()
155 if (atomic_read(&ses->se_ref) > ref_held_by_me) in mark_session_dead_locked()
157 ses->se_flags |= NFS4_SESSION_DEAD; in mark_session_dead_locked()
163 return clp->cl_time == 0; in is_client_expired()
169 if (clp->cl_state != NFSD4_ACTIVE) in nfsd4_dec_courtesy_client_count()
170 atomic_add_unless(&nn->nfsd_courtesy_clients, -1, 0); in nfsd4_dec_courtesy_client_count()
175 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in get_client_locked()
177 lockdep_assert_held(&nn->client_lock); in get_client_locked()
181 atomic_inc(&clp->cl_rpc_users); in get_client_locked()
183 clp->cl_state = NFSD4_ACTIVE; in get_client_locked()
191 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in renew_client_locked()
197 clp->cl_clientid.cl_boot, in renew_client_locked()
198 clp->cl_clientid.cl_id); in renew_client_locked()
202 list_move_tail(&clp->cl_lru, &nn->client_lru); in renew_client_locked()
203 clp->cl_time = ktime_get_boottime_seconds(); in renew_client_locked()
205 clp->cl_state = NFSD4_ACTIVE; in renew_client_locked()
210 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in put_client_renew_locked()
212 lockdep_assert_held(&nn->client_lock); in put_client_renew_locked()
214 if (!atomic_dec_and_test(&clp->cl_rpc_users)) in put_client_renew_locked()
224 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in put_client_renew()
226 if (!atomic_dec_and_lock(&clp->cl_rpc_users, &nn->client_lock)) in put_client_renew()
232 spin_unlock(&nn->client_lock); in put_client_renew()
241 status = get_client_locked(ses->se_client); in nfsd4_get_session_locked()
244 atomic_inc(&ses->se_ref); in nfsd4_get_session_locked()
250 struct nfs4_client *clp = ses->se_client; in nfsd4_put_session_locked()
251 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in nfsd4_put_session_locked()
253 lockdep_assert_held(&nn->client_lock); in nfsd4_put_session_locked()
255 if (atomic_dec_and_test(&ses->se_ref) && is_session_dead(ses)) in nfsd4_put_session_locked()
262 struct nfs4_client *clp = ses->se_client; in nfsd4_put_session()
263 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in nfsd4_put_session()
265 spin_lock(&nn->client_lock); in nfsd4_put_session()
267 spin_unlock(&nn->client_lock); in nfsd4_put_session()
276 spin_lock(&nn->blocked_locks_lock); in find_blocked_lock()
277 list_for_each_entry(cur, &lo->lo_blocked, nbl_list) { in find_blocked_lock()
278 if (fh_match(fh, &cur->nbl_fh)) { in find_blocked_lock()
279 list_del_init(&cur->nbl_list); in find_blocked_lock()
280 WARN_ON(list_empty(&cur->nbl_lru)); in find_blocked_lock()
281 list_del_init(&cur->nbl_lru); in find_blocked_lock()
286 spin_unlock(&nn->blocked_locks_lock); in find_blocked_lock()
288 locks_delete_block(&found->nbl_lock); in find_blocked_lock()
302 INIT_LIST_HEAD(&nbl->nbl_list); in find_or_allocate_block()
303 INIT_LIST_HEAD(&nbl->nbl_lru); in find_or_allocate_block()
304 fh_copy_shallow(&nbl->nbl_fh, fh); in find_or_allocate_block()
305 locks_init_lock(&nbl->nbl_lock); in find_or_allocate_block()
306 kref_init(&nbl->nbl_kref); in find_or_allocate_block()
307 nfsd4_init_cb(&nbl->nbl_cb, lo->lo_owner.so_client, in find_or_allocate_block()
327 locks_delete_block(&nbl->nbl_lock); in free_blocked_lock()
328 locks_release_private(&nbl->nbl_lock); in free_blocked_lock()
329 kref_put(&nbl->nbl_kref, free_nbl); in free_blocked_lock()
335 struct nfs4_client *clp = lo->lo_owner.so_client; in remove_blocked_locks()
336 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in remove_blocked_locks()
341 spin_lock(&nn->blocked_locks_lock); in remove_blocked_locks()
342 while (!list_empty(&lo->lo_blocked)) { in remove_blocked_locks()
343 nbl = list_first_entry(&lo->lo_blocked, in remove_blocked_locks()
346 list_del_init(&nbl->nbl_list); in remove_blocked_locks()
347 WARN_ON(list_empty(&nbl->nbl_lru)); in remove_blocked_locks()
348 list_move(&nbl->nbl_lru, &reaplist); in remove_blocked_locks()
350 spin_unlock(&nn->blocked_locks_lock); in remove_blocked_locks()
356 list_del_init(&nbl->nbl_lru); in remove_blocked_locks()
366 locks_delete_block(&nbl->nbl_lock); in nfsd4_cb_notify_lock_prepare()
379 switch (task->tk_status) { in nfsd4_cb_notify_lock_done()
380 case -NFS4ERR_DELAY: in nfsd4_cb_notify_lock_done()
409 * https://datatracker.ietf.org/doc/html/rfc7530#section-16.19.4 that
447 stp->st_access_bmap |= mask; in set_access()
457 stp->st_access_bmap &= ~mask; in clear_access()
466 return (bool)(stp->st_access_bmap & mask); in test_access()
476 stp->st_deny_bmap |= mask; in set_deny()
486 stp->st_deny_bmap &= ~mask; in clear_deny()
495 return (bool)(stp->st_deny_bmap & mask); in test_deny()
530 atomic_inc(&sop->so_count); in nfs4_get_stateowner()
537 return (sop->so_owner.len == owner->len) && in same_owner_str()
538 0 == memcmp(sop->so_owner.data, owner->data, owner->len); in same_owner_str()
547 lockdep_assert_held(&clp->cl_lock); in find_openstateowner_str_locked()
549 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[hashval], in find_openstateowner_str_locked()
551 if (!so->so_is_open_owner) in find_openstateowner_str_locked()
553 if (same_owner_str(so, &open->op_owner)) in find_openstateowner_str_locked()
565 spin_lock(&clp->cl_lock); in find_openstateowner_str()
567 spin_unlock(&clp->cl_lock); in find_openstateowner_str()
577 while (nbytes--) { in opaque_hashval()
594 if (refcount_dec_and_test(&fi->fi_ref)) { in put_nfs4_file()
596 WARN_ON_ONCE(!list_empty(&fi->fi_clnt_odstate)); in put_nfs4_file()
597 WARN_ON_ONCE(!list_empty(&fi->fi_delegations)); in put_nfs4_file()
598 call_rcu(&fi->fi_rcu, nfsd4_free_file_rcu); in put_nfs4_file()
607 lockdep_assert_held(&f->fi_lock); in find_writeable_file_locked()
609 ret = nfsd_file_get(f->fi_fds[O_WRONLY]); in find_writeable_file_locked()
611 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_writeable_file_locked()
620 spin_lock(&f->fi_lock); in find_writeable_file()
622 spin_unlock(&f->fi_lock); in find_writeable_file()
632 lockdep_assert_held(&f->fi_lock); in find_readable_file_locked()
634 ret = nfsd_file_get(f->fi_fds[O_RDONLY]); in find_readable_file_locked()
636 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_readable_file_locked()
645 spin_lock(&f->fi_lock); in find_readable_file()
647 spin_unlock(&f->fi_lock); in find_readable_file()
657 spin_lock(&f->fi_lock); in find_rw_file()
658 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_rw_file()
659 spin_unlock(&f->fi_lock); in find_rw_file()
671 spin_lock(&f->fi_lock); in find_any_file()
672 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_any_file()
674 ret = nfsd_file_get(f->fi_fds[O_WRONLY]); in find_any_file()
676 ret = nfsd_file_get(f->fi_fds[O_RDONLY]); in find_any_file()
678 spin_unlock(&f->fi_lock); in find_any_file()
684 lockdep_assert_held(&f->fi_lock); in find_any_file_locked()
686 if (f->fi_fds[O_RDWR]) in find_any_file_locked()
687 return f->fi_fds[O_RDWR]; in find_any_file_locked()
688 if (f->fi_fds[O_WRONLY]) in find_any_file_locked()
689 return f->fi_fds[O_WRONLY]; in find_any_file_locked()
690 if (f->fi_fds[O_RDONLY]) in find_any_file_locked()
691 return f->fi_fds[O_RDONLY]; in find_any_file_locked()
705 #define OWNER_HASH_MASK (OWNER_HASH_SIZE - 1)
711 ret = opaque_hashval(ownername->data, ownername->len); in ownerstr_hashval()
743 * false - access/deny mode conflict with normal client.
744 * true - no conflict or conflict with courtesy client(s) is resolved.
756 lockdep_assert_held(&fp->fi_lock); in nfs4_resolve_deny_conflicts_locked()
757 list_for_each_entry(st, &fp->fi_stateids, st_perfile) { in nfs4_resolve_deny_conflicts_locked()
759 if (st->st_openstp) in nfs4_resolve_deny_conflicts_locked()
764 bmap = share_access ? st->st_deny_bmap : st->st_access_bmap; in nfs4_resolve_deny_conflicts_locked()
767 clp = st->st_stid.sc_client; in nfs4_resolve_deny_conflicts_locked()
774 clp = stp->st_stid.sc_client; in nfs4_resolve_deny_conflicts_locked()
775 nn = net_generic(clp->net, nfsd_net_id); in nfs4_resolve_deny_conflicts_locked()
776 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in nfs4_resolve_deny_conflicts_locked()
784 lockdep_assert_held(&fp->fi_lock); in __nfs4_file_get_access()
787 atomic_inc(&fp->fi_access[O_WRONLY]); in __nfs4_file_get_access()
789 atomic_inc(&fp->fi_access[O_RDONLY]); in __nfs4_file_get_access()
795 lockdep_assert_held(&fp->fi_lock); in nfs4_file_get_access()
802 if ((access & fp->fi_share_deny) != 0) in nfs4_file_get_access()
818 atomic_read(&fp->fi_access[O_RDONLY])) in nfs4_file_check_deny()
822 atomic_read(&fp->fi_access[O_WRONLY])) in nfs4_file_check_deny()
830 might_lock(&fp->fi_lock); in __nfs4_file_put_access()
832 if (atomic_dec_and_lock(&fp->fi_access[oflag], &fp->fi_lock)) { in __nfs4_file_put_access()
836 swap(f1, fp->fi_fds[oflag]); in __nfs4_file_put_access()
837 if (atomic_read(&fp->fi_access[1 - oflag]) == 0) in __nfs4_file_put_access()
838 swap(f2, fp->fi_fds[O_RDWR]); in __nfs4_file_put_access()
839 spin_unlock(&fp->fi_lock); in __nfs4_file_put_access()
861 * Note that we only allocate it for pNFS-enabled exports, otherwise
871 co->co_client = clp; in alloc_clnt_odstate()
872 refcount_set(&co->co_odcount, 1); in alloc_clnt_odstate()
880 struct nfs4_file *fp = co->co_file; in hash_clnt_odstate_locked()
882 lockdep_assert_held(&fp->fi_lock); in hash_clnt_odstate_locked()
883 list_add(&co->co_perfile, &fp->fi_clnt_odstate); in hash_clnt_odstate_locked()
890 refcount_inc(&co->co_odcount); in get_clnt_odstate()
901 fp = co->co_file; in put_clnt_odstate()
902 if (refcount_dec_and_lock(&co->co_odcount, &fp->fi_lock)) { in put_clnt_odstate()
903 list_del(&co->co_perfile); in put_clnt_odstate()
904 spin_unlock(&fp->fi_lock); in put_clnt_odstate()
906 nfsd4_return_all_file_layouts(co->co_client, fp); in put_clnt_odstate()
920 cl = new->co_client; in find_or_hash_clnt_odstate()
922 spin_lock(&fp->fi_lock); in find_or_hash_clnt_odstate()
923 list_for_each_entry(co, &fp->fi_clnt_odstate, co_perfile) { in find_or_hash_clnt_odstate()
924 if (co->co_client == cl) { in find_or_hash_clnt_odstate()
930 co->co_file = fp; in find_or_hash_clnt_odstate()
933 spin_unlock(&fp->fi_lock); in find_or_hash_clnt_odstate()
948 spin_lock(&cl->cl_lock); in nfs4_alloc_stid()
950 new_id = idr_alloc_cyclic(&cl->cl_stateids, stid, 1, 0, GFP_NOWAIT); in nfs4_alloc_stid()
951 spin_unlock(&cl->cl_lock); in nfs4_alloc_stid()
956 stid->sc_free = sc_free; in nfs4_alloc_stid()
957 stid->sc_client = cl; in nfs4_alloc_stid()
958 stid->sc_stateid.si_opaque.so_id = new_id; in nfs4_alloc_stid()
959 stid->sc_stateid.si_opaque.so_clid = cl->cl_clientid; in nfs4_alloc_stid()
961 refcount_set(&stid->sc_count, 1); in nfs4_alloc_stid()
962 spin_lock_init(&stid->sc_lock); in nfs4_alloc_stid()
963 INIT_LIST_HEAD(&stid->sc_cp_list); in nfs4_alloc_stid()
988 stid->cs_stid.si_opaque.so_clid.cl_boot = (u32)nn->boot_time; in nfs4_init_cp_state()
989 stid->cs_stid.si_opaque.so_clid.cl_id = nn->s2s_cp_cl_id; in nfs4_init_cp_state()
992 spin_lock(&nn->s2s_cp_lock); in nfs4_init_cp_state()
993 new_id = idr_alloc_cyclic(&nn->s2s_cp_stateids, stid, 0, 0, GFP_NOWAIT); in nfs4_init_cp_state()
994 stid->cs_stid.si_opaque.so_id = new_id; in nfs4_init_cp_state()
995 stid->cs_stid.si_generation = 1; in nfs4_init_cp_state()
996 spin_unlock(&nn->s2s_cp_lock); in nfs4_init_cp_state()
1000 stid->cs_type = cs_type; in nfs4_init_cp_state()
1006 return nfs4_init_cp_state(nn, ©->cp_stateid, NFS4_COPY_STID); in nfs4_init_copy_state()
1017 cps->cpntf_time = ktime_get_boottime_seconds(); in nfs4_alloc_init_cpntf_state()
1018 refcount_set(&cps->cp_stateid.cs_count, 1); in nfs4_alloc_init_cpntf_state()
1019 if (!nfs4_init_cp_state(nn, &cps->cp_stateid, NFS4_COPYNOTIFY_STID)) in nfs4_alloc_init_cpntf_state()
1021 spin_lock(&nn->s2s_cp_lock); in nfs4_alloc_init_cpntf_state()
1022 list_add(&cps->cp_list, &p_stid->sc_cp_list); in nfs4_alloc_init_cpntf_state()
1023 spin_unlock(&nn->s2s_cp_lock); in nfs4_alloc_init_cpntf_state()
1034 if (copy->cp_stateid.cs_type != NFS4_COPY_STID) in nfs4_free_copy_state()
1036 nn = net_generic(copy->cp_clp->net, nfsd_net_id); in nfs4_free_copy_state()
1037 spin_lock(&nn->s2s_cp_lock); in nfs4_free_copy_state()
1038 idr_remove(&nn->s2s_cp_stateids, in nfs4_free_copy_state()
1039 copy->cp_stateid.cs_stid.si_opaque.so_id); in nfs4_free_copy_state()
1040 spin_unlock(&nn->s2s_cp_lock); in nfs4_free_copy_state()
1049 spin_lock(&nn->s2s_cp_lock); in nfs4_free_cpntf_statelist()
1050 while (!list_empty(&stid->sc_cp_list)) { in nfs4_free_cpntf_statelist()
1051 cps = list_first_entry(&stid->sc_cp_list, in nfs4_free_cpntf_statelist()
1055 spin_unlock(&nn->s2s_cp_lock); in nfs4_free_cpntf_statelist()
1073 WARN_ON_ONCE(!list_empty(&stid->sc_cp_list)); in nfs4_free_deleg()
1074 WARN_ON_ONCE(!list_empty(&dp->dl_perfile)); in nfs4_free_deleg()
1075 WARN_ON_ONCE(!list_empty(&dp->dl_perclnt)); in nfs4_free_deleg()
1076 WARN_ON_ONCE(!list_empty(&dp->dl_recall_lru)); in nfs4_free_deleg()
1093 * low 3 bytes as hash-table indices.
1112 if (bd->entries == 0) in delegation_blocked()
1114 if (ktime_get_seconds() - bd->swap_time > 30) { in delegation_blocked()
1116 if (ktime_get_seconds() - bd->swap_time > 30) { in delegation_blocked()
1117 bd->entries -= bd->old_entries; in delegation_blocked()
1118 bd->old_entries = bd->entries; in delegation_blocked()
1119 memset(bd->set[bd->new], 0, in delegation_blocked()
1120 sizeof(bd->set[0])); in delegation_blocked()
1121 bd->new = 1-bd->new; in delegation_blocked()
1122 bd->swap_time = ktime_get_seconds(); in delegation_blocked()
1126 hash = jhash(&fh->fh_raw, fh->fh_size, 0); in delegation_blocked()
1127 if (test_bit(hash&255, bd->set[0]) && in delegation_blocked()
1128 test_bit((hash>>8)&255, bd->set[0]) && in delegation_blocked()
1129 test_bit((hash>>16)&255, bd->set[0])) in delegation_blocked()
1132 if (test_bit(hash&255, bd->set[1]) && in delegation_blocked()
1133 test_bit((hash>>8)&255, bd->set[1]) && in delegation_blocked()
1134 test_bit((hash>>16)&255, bd->set[1])) in delegation_blocked()
1145 hash = jhash(&fh->fh_raw, fh->fh_size, 0); in block_delegations()
1148 __set_bit(hash&255, bd->set[bd->new]); in block_delegations()
1149 __set_bit((hash>>8)&255, bd->set[bd->new]); in block_delegations()
1150 __set_bit((hash>>16)&255, bd->set[bd->new]); in block_delegations()
1151 if (bd->entries == 0) in block_delegations()
1152 bd->swap_time = ktime_get_seconds(); in block_delegations()
1153 bd->entries += 1; in block_delegations()
1168 if (delegation_blocked(&fp->fi_fhandle)) in alloc_init_deleg()
1179 dp->dl_stid.sc_stateid.si_generation = 1; in alloc_init_deleg()
1180 INIT_LIST_HEAD(&dp->dl_perfile); in alloc_init_deleg()
1181 INIT_LIST_HEAD(&dp->dl_perclnt); in alloc_init_deleg()
1182 INIT_LIST_HEAD(&dp->dl_recall_lru); in alloc_init_deleg()
1183 dp->dl_clnt_odstate = odstate; in alloc_init_deleg()
1185 dp->dl_type = dl_type; in alloc_init_deleg()
1186 dp->dl_retries = 1; in alloc_init_deleg()
1187 dp->dl_recalled = false; in alloc_init_deleg()
1188 nfsd4_init_cb(&dp->dl_recall, dp->dl_stid.sc_client, in alloc_init_deleg()
1191 dp->dl_stid.sc_file = fp; in alloc_init_deleg()
1201 struct nfs4_file *fp = s->sc_file; in nfs4_put_stid()
1202 struct nfs4_client *clp = s->sc_client; in nfs4_put_stid()
1204 might_lock(&clp->cl_lock); in nfs4_put_stid()
1206 if (!refcount_dec_and_lock(&s->sc_count, &clp->cl_lock)) { in nfs4_put_stid()
1210 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); in nfs4_put_stid()
1211 nfs4_free_cpntf_statelist(clp->net, s); in nfs4_put_stid()
1212 spin_unlock(&clp->cl_lock); in nfs4_put_stid()
1213 s->sc_free(s); in nfs4_put_stid()
1221 stateid_t *src = &stid->sc_stateid; in nfs4_inc_and_copy_stateid()
1223 spin_lock(&stid->sc_lock); in nfs4_inc_and_copy_stateid()
1224 if (unlikely(++src->si_generation == 0)) in nfs4_inc_and_copy_stateid()
1225 src->si_generation = 1; in nfs4_inc_and_copy_stateid()
1227 spin_unlock(&stid->sc_lock); in nfs4_inc_and_copy_stateid()
1234 spin_lock(&fp->fi_lock); in put_deleg_file()
1235 if (--fp->fi_delegees == 0) in put_deleg_file()
1236 swap(nf, fp->fi_deleg_file); in put_deleg_file()
1237 spin_unlock(&fp->fi_lock); in put_deleg_file()
1245 struct nfs4_file *fp = dp->dl_stid.sc_file; in nfs4_unlock_deleg_lease()
1246 struct nfsd_file *nf = fp->fi_deleg_file; in nfs4_unlock_deleg_lease()
1248 WARN_ON_ONCE(!fp->fi_delegees); in nfs4_unlock_deleg_lease()
1250 vfs_setlease(nf->nf_file, F_UNLCK, NULL, (void **)&dp); in nfs4_unlock_deleg_lease()
1256 put_clnt_odstate(dp->dl_clnt_odstate); in destroy_unhashed_deleg()
1258 nfs4_put_stid(&dp->dl_stid); in destroy_unhashed_deleg()
1263 s->sc_type = 0; in nfs4_unhash_stid()
1267 * nfs4_delegation_exists - Discover if this delegation already exists
1282 lockdep_assert_held(&fp->fi_lock); in nfs4_delegation_exists()
1284 list_for_each_entry(searchdp, &fp->fi_delegations, dl_perfile) { in nfs4_delegation_exists()
1285 searchclp = searchdp->dl_stid.sc_client; in nfs4_delegation_exists()
1294 * hash_delegation_locked - Add a delegation to the appropriate lists
1301 * On error: -EAGAIN if one was previously granted to this
1309 struct nfs4_client *clp = dp->dl_stid.sc_client; in hash_delegation_locked()
1312 lockdep_assert_held(&fp->fi_lock); in hash_delegation_locked()
1315 return -EAGAIN; in hash_delegation_locked()
1316 refcount_inc(&dp->dl_stid.sc_count); in hash_delegation_locked()
1317 dp->dl_stid.sc_type = NFS4_DELEG_STID; in hash_delegation_locked()
1318 list_add(&dp->dl_perfile, &fp->fi_delegations); in hash_delegation_locked()
1319 list_add(&dp->dl_perclnt, &clp->cl_delegations); in hash_delegation_locked()
1325 return !(list_empty(&dp->dl_perfile)); in delegation_hashed()
1331 struct nfs4_file *fp = dp->dl_stid.sc_file; in unhash_delegation_locked()
1338 dp->dl_stid.sc_type = NFS4_CLOSED_DELEG_STID; in unhash_delegation_locked()
1340 ++dp->dl_time; in unhash_delegation_locked()
1341 spin_lock(&fp->fi_lock); in unhash_delegation_locked()
1342 list_del_init(&dp->dl_perclnt); in unhash_delegation_locked()
1343 list_del_init(&dp->dl_recall_lru); in unhash_delegation_locked()
1344 list_del_init(&dp->dl_perfile); in unhash_delegation_locked()
1345 spin_unlock(&fp->fi_lock); in unhash_delegation_locked()
1362 struct nfs4_client *clp = dp->dl_stid.sc_client; in revoke_delegation()
1364 WARN_ON(!list_empty(&dp->dl_recall_lru)); in revoke_delegation()
1366 trace_nfsd_stid_revoke(&dp->dl_stid); in revoke_delegation()
1368 if (clp->cl_minorversion) { in revoke_delegation()
1369 spin_lock(&clp->cl_lock); in revoke_delegation()
1370 dp->dl_stid.sc_type = NFS4_REVOKED_DELEG_STID; in revoke_delegation()
1371 refcount_inc(&dp->dl_stid.sc_count); in revoke_delegation()
1372 list_add(&dp->dl_recall_lru, &clp->cl_revoked); in revoke_delegation()
1373 spin_unlock(&clp->cl_lock); in revoke_delegation()
1401 spin_lock(&fp->fi_lock); in recalculate_deny_mode()
1402 fp->fi_share_deny = 0; in recalculate_deny_mode()
1403 list_for_each_entry(stp, &fp->fi_stateids, st_perfile) in recalculate_deny_mode()
1404 fp->fi_share_deny |= bmap_to_share_mode(stp->st_deny_bmap); in recalculate_deny_mode()
1405 spin_unlock(&fp->fi_lock); in recalculate_deny_mode()
1421 /* Recalculate per-file deny mode if there was a change */ in reset_union_bmap_deny()
1423 recalculate_deny_mode(stp->st_stid.sc_file); in reset_union_bmap_deny()
1431 struct nfs4_file *fp = stp->st_stid.sc_file; in release_all_access()
1433 if (fp && stp->st_deny_bmap != 0) in release_all_access()
1438 nfs4_file_put_access(stp->st_stid.sc_file, i); in release_all_access()
1445 kfree(sop->so_owner.data); in nfs4_free_stateowner()
1446 sop->so_ops->so_free(sop); in nfs4_free_stateowner()
1451 struct nfs4_client *clp = sop->so_client; in nfs4_put_stateowner()
1453 might_lock(&clp->cl_lock); in nfs4_put_stateowner()
1455 if (!atomic_dec_and_lock(&sop->so_count, &clp->cl_lock)) in nfs4_put_stateowner()
1457 sop->so_ops->so_unhash(sop); in nfs4_put_stateowner()
1458 spin_unlock(&clp->cl_lock); in nfs4_put_stateowner()
1465 return list_empty(&stp->st_perfile); in nfs4_ol_stateid_unhashed()
1470 struct nfs4_file *fp = stp->st_stid.sc_file; in unhash_ol_stateid()
1472 lockdep_assert_held(&stp->st_stateowner->so_client->cl_lock); in unhash_ol_stateid()
1474 if (list_empty(&stp->st_perfile)) in unhash_ol_stateid()
1477 spin_lock(&fp->fi_lock); in unhash_ol_stateid()
1478 list_del_init(&stp->st_perfile); in unhash_ol_stateid()
1479 spin_unlock(&fp->fi_lock); in unhash_ol_stateid()
1480 list_del(&stp->st_perstateowner); in unhash_ol_stateid()
1488 put_clnt_odstate(stp->st_clnt_odstate); in nfs4_free_ol_stateid()
1490 if (stp->st_stateowner) in nfs4_free_ol_stateid()
1491 nfs4_put_stateowner(stp->st_stateowner); in nfs4_free_ol_stateid()
1492 WARN_ON(!list_empty(&stid->sc_cp_list)); in nfs4_free_ol_stateid()
1499 struct nfs4_lockowner *lo = lockowner(stp->st_stateowner); in nfs4_free_lock_stateid()
1502 nf = find_any_file(stp->st_stid.sc_file); in nfs4_free_lock_stateid()
1504 get_file(nf->nf_file); in nfs4_free_lock_stateid()
1505 filp_close(nf->nf_file, (fl_owner_t)lo); in nfs4_free_lock_stateid()
1519 struct nfs4_stid *s = &stp->st_stid; in put_ol_stateid_locked()
1520 struct nfs4_client *clp = s->sc_client; in put_ol_stateid_locked()
1522 lockdep_assert_held(&clp->cl_lock); in put_ol_stateid_locked()
1524 WARN_ON_ONCE(!list_empty(&stp->st_locks)); in put_ol_stateid_locked()
1526 if (!refcount_dec_and_test(&s->sc_count)) { in put_ol_stateid_locked()
1531 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); in put_ol_stateid_locked()
1532 list_add(&stp->st_locks, reaplist); in put_ol_stateid_locked()
1537 lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); in unhash_lock_stateid()
1541 list_del_init(&stp->st_locks); in unhash_lock_stateid()
1542 nfs4_unhash_stid(&stp->st_stid); in unhash_lock_stateid()
1548 struct nfs4_client *clp = stp->st_stid.sc_client; in release_lock_stateid()
1551 spin_lock(&clp->cl_lock); in release_lock_stateid()
1553 spin_unlock(&clp->cl_lock); in release_lock_stateid()
1555 nfs4_put_stid(&stp->st_stid); in release_lock_stateid()
1560 struct nfs4_client *clp = lo->lo_owner.so_client; in unhash_lockowner_locked()
1562 lockdep_assert_held(&clp->cl_lock); in unhash_lockowner_locked()
1564 list_del_init(&lo->lo_owner.so_strhash); in unhash_lockowner_locked()
1582 list_del(&stp->st_locks); in free_ol_stateid_reaplist()
1583 fp = stp->st_stid.sc_file; in free_ol_stateid_reaplist()
1584 stp->st_stid.sc_free(&stp->st_stid); in free_ol_stateid_reaplist()
1595 lockdep_assert_held(&open_stp->st_stid.sc_client->cl_lock); in release_open_stateid_locks()
1597 while (!list_empty(&open_stp->st_locks)) { in release_open_stateid_locks()
1598 stp = list_entry(open_stp->st_locks.next, in release_open_stateid_locks()
1608 lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); in unhash_open_stateid()
1620 spin_lock(&stp->st_stid.sc_client->cl_lock); in release_open_stateid()
1623 spin_unlock(&stp->st_stid.sc_client->cl_lock); in release_open_stateid()
1629 struct nfs4_client *clp = oo->oo_owner.so_client; in unhash_openowner_locked()
1631 lockdep_assert_held(&clp->cl_lock); in unhash_openowner_locked()
1633 list_del_init(&oo->oo_owner.so_strhash); in unhash_openowner_locked()
1634 list_del_init(&oo->oo_perclient); in unhash_openowner_locked()
1639 struct nfsd_net *nn = net_generic(oo->oo_owner.so_client->net, in release_last_closed_stateid()
1643 spin_lock(&nn->client_lock); in release_last_closed_stateid()
1644 s = oo->oo_last_closed_stid; in release_last_closed_stateid()
1646 list_del_init(&oo->oo_close_lru); in release_last_closed_stateid()
1647 oo->oo_last_closed_stid = NULL; in release_last_closed_stateid()
1649 spin_unlock(&nn->client_lock); in release_last_closed_stateid()
1651 nfs4_put_stid(&s->st_stid); in release_last_closed_stateid()
1657 struct nfs4_client *clp = oo->oo_owner.so_client; in release_openowner()
1662 spin_lock(&clp->cl_lock); in release_openowner()
1664 while (!list_empty(&oo->oo_owner.so_stateids)) { in release_openowner()
1665 stp = list_first_entry(&oo->oo_owner.so_stateids, in release_openowner()
1670 spin_unlock(&clp->cl_lock); in release_openowner()
1673 nfs4_put_stateowner(&oo->oo_owner); in release_openowner()
1681 return sid->sequence % SESSION_HASH_SIZE; in hash_sessionid()
1688 u32 *ptr = (u32 *)(&sessionid->data[0]); in dump_sessionid()
1699 * Bump the seqid on cstate->replay_owner, and clear replay_owner if it
1704 struct nfs4_stateowner *so = cstate->replay_owner; in nfsd4_bump_seqid()
1715 if (so->so_is_open_owner) in nfsd4_bump_seqid()
1717 so->so_seqid++; in nfsd4_bump_seqid()
1724 struct nfs4_client *clp = ses->se_client; in gen_sessionid()
1727 sid = (struct nfsd4_sessionid *)ses->se_sessionid.data; in gen_sessionid()
1728 sid->clientid = clp->cl_clientid; in gen_sessionid()
1729 sid->sequence = current_sessionid++; in gen_sessionid()
1730 sid->reserved = 0; in gen_sessionid()
1736 * the end of the initial SEQUENCE operation--the rest we regenerate
1742 * verifier), 12 for the compound header (with zero-length tag), and 44
1752 for (i = 0; i < ses->se_fchannel.maxreqs; i++) { in free_session_slots()
1753 free_svc_cred(&ses->se_slots[i]->sl_cred); in free_session_slots()
1754 kfree(ses->se_slots[i]); in free_session_slots()
1766 if (ca->maxresp_cached < NFSD_MIN_HDR_SEQ_SZ) in slot_bytes()
1769 size = ca->maxresp_cached - NFSD_MIN_HDR_SEQ_SZ; in slot_bytes()
1775 * re-negotiate active sessions and reduce their slot usage to make
1781 u32 num = ca->maxreqs; in nfsd4_get_drc_mem()
1787 total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used; in nfsd4_get_drc_mem()
1803 * over-allocation--it is better than failure. in nfsd4_get_drc_mem()
1805 scale_factor = max_t(unsigned int, 8, nn->nfsd_serv->sv_nrthreads); in nfsd4_get_drc_mem()
1822 nfsd_drc_mem_used -= slotsize * ca->maxreqs; in nfsd4_put_drc_mem()
1829 int numslots = fattrs->maxreqs; in alloc_session()
1842 new->se_slots[i] = kzalloc(slotsize, GFP_KERNEL); in alloc_session()
1843 if (!new->se_slots[i]) in alloc_session()
1847 memcpy(&new->se_fchannel, fattrs, sizeof(struct nfsd4_channel_attrs)); in alloc_session()
1848 memcpy(&new->se_bchannel, battrs, sizeof(struct nfsd4_channel_attrs)); in alloc_session()
1852 while (i--) in alloc_session()
1853 kfree(new->se_slots[i]); in alloc_session()
1860 svc_xprt_put(c->cn_xprt); in free_conn()
1867 struct nfs4_client *clp = c->cn_session->se_client; in nfsd4_conn_lost()
1871 spin_lock(&clp->cl_lock); in nfsd4_conn_lost()
1872 if (!list_empty(&c->cn_persession)) { in nfsd4_conn_lost()
1873 list_del(&c->cn_persession); in nfsd4_conn_lost()
1877 spin_unlock(&clp->cl_lock); in nfsd4_conn_lost()
1887 svc_xprt_get(rqstp->rq_xprt); in alloc_conn()
1888 conn->cn_xprt = rqstp->rq_xprt; in alloc_conn()
1889 conn->cn_flags = flags; in alloc_conn()
1890 INIT_LIST_HEAD(&conn->cn_xpt_user.list); in alloc_conn()
1896 conn->cn_session = ses; in __nfsd4_hash_conn()
1897 list_add(&conn->cn_persession, &ses->se_conns); in __nfsd4_hash_conn()
1902 struct nfs4_client *clp = ses->se_client; in nfsd4_hash_conn()
1904 spin_lock(&clp->cl_lock); in nfsd4_hash_conn()
1906 spin_unlock(&clp->cl_lock); in nfsd4_hash_conn()
1911 conn->cn_xpt_user.callback = nfsd4_conn_lost; in nfsd4_register_conn()
1912 return register_xpt_user(conn->cn_xprt, &conn->cn_xpt_user); in nfsd4_register_conn()
1923 nfsd4_conn_lost(&conn->cn_xpt_user); in nfsd4_init_conn()
1925 nfsd4_probe_callback_sync(ses->se_client); in nfsd4_init_conn()
1932 if (cses->flags & SESSION4_BACK_CHAN) in alloc_conn_from_crses()
1940 struct nfs4_client *clp = s->se_client; in nfsd4_del_conns()
1943 spin_lock(&clp->cl_lock); in nfsd4_del_conns()
1944 while (!list_empty(&s->se_conns)) { in nfsd4_del_conns()
1945 c = list_first_entry(&s->se_conns, struct nfsd4_conn, cn_persession); in nfsd4_del_conns()
1946 list_del_init(&c->cn_persession); in nfsd4_del_conns()
1947 spin_unlock(&clp->cl_lock); in nfsd4_del_conns()
1949 unregister_xpt_user(c->cn_xprt, &c->cn_xpt_user); in nfsd4_del_conns()
1952 spin_lock(&clp->cl_lock); in nfsd4_del_conns()
1954 spin_unlock(&clp->cl_lock); in nfsd4_del_conns()
1966 nfsd4_put_drc_mem(&ses->se_fchannel); in free_session()
1975 new->se_client = clp; in init_session()
1978 INIT_LIST_HEAD(&new->se_conns); in init_session()
1980 new->se_cb_seq_nr = 1; in init_session()
1981 new->se_flags = cses->flags; in init_session()
1982 new->se_cb_prog = cses->callback_prog; in init_session()
1983 new->se_cb_sec = cses->cb_sec; in init_session()
1984 atomic_set(&new->se_ref, 0); in init_session()
1985 idx = hash_sessionid(&new->se_sessionid); in init_session()
1986 list_add(&new->se_hash, &nn->sessionid_hashtbl[idx]); in init_session()
1987 spin_lock(&clp->cl_lock); in init_session()
1988 list_add(&new->se_perclnt, &clp->cl_sessions); in init_session()
1989 spin_unlock(&clp->cl_lock); in init_session()
2000 rpc_copy_addr((struct sockaddr *)&clp->cl_cb_conn.cb_addr, sa); in init_session()
2001 clp->cl_cb_conn.cb_addrlen = svc_addr_len(sa); in init_session()
2013 lockdep_assert_held(&nn->client_lock); in __find_in_sessionid_hashtbl()
2018 list_for_each_entry(elem, &nn->sessionid_hashtbl[idx], se_hash) { in __find_in_sessionid_hashtbl()
2019 if (!memcmp(elem->se_sessionid.data, sessionid->data, in __find_in_sessionid_hashtbl()
2051 struct nfs4_client *clp = ses->se_client; in unhash_session()
2052 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_session()
2054 lockdep_assert_held(&nn->client_lock); in unhash_session()
2056 list_del(&ses->se_hash); in unhash_session()
2057 spin_lock(&ses->se_client->cl_lock); in unhash_session()
2058 list_del(&ses->se_perclnt); in unhash_session()
2059 spin_unlock(&ses->se_client->cl_lock); in unhash_session()
2071 if (clid->cl_boot == (u32)nn->boot_time) in STALE_CLIENTID()
2088 if (atomic_read(&nn->nfs4_client_count) >= nn->nfs4_max_clients) { in alloc_client()
2089 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in alloc_client()
2095 xdr_netobj_dup(&clp->cl_name, &name, GFP_KERNEL); in alloc_client()
2096 if (clp->cl_name.data == NULL) in alloc_client()
2098 clp->cl_ownerstr_hashtbl = kmalloc_array(OWNER_HASH_SIZE, in alloc_client()
2101 if (!clp->cl_ownerstr_hashtbl) in alloc_client()
2104 INIT_LIST_HEAD(&clp->cl_ownerstr_hashtbl[i]); in alloc_client()
2105 INIT_LIST_HEAD(&clp->cl_sessions); in alloc_client()
2106 idr_init(&clp->cl_stateids); in alloc_client()
2107 atomic_set(&clp->cl_rpc_users, 0); in alloc_client()
2108 clp->cl_cb_state = NFSD4_CB_UNKNOWN; in alloc_client()
2109 clp->cl_state = NFSD4_ACTIVE; in alloc_client()
2110 atomic_inc(&nn->nfs4_client_count); in alloc_client()
2111 atomic_set(&clp->cl_delegs_in_recall, 0); in alloc_client()
2112 INIT_LIST_HEAD(&clp->cl_idhash); in alloc_client()
2113 INIT_LIST_HEAD(&clp->cl_openowners); in alloc_client()
2114 INIT_LIST_HEAD(&clp->cl_delegations); in alloc_client()
2115 INIT_LIST_HEAD(&clp->cl_lru); in alloc_client()
2116 INIT_LIST_HEAD(&clp->cl_revoked); in alloc_client()
2118 INIT_LIST_HEAD(&clp->cl_lo_states); in alloc_client()
2120 INIT_LIST_HEAD(&clp->async_copies); in alloc_client()
2121 spin_lock_init(&clp->async_lock); in alloc_client()
2122 spin_lock_init(&clp->cl_lock); in alloc_client()
2123 rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table"); in alloc_client()
2126 kfree(clp->cl_name.data); in alloc_client()
2137 free_svc_cred(&clp->cl_cred); in __free_client()
2138 kfree(clp->cl_ownerstr_hashtbl); in __free_client()
2139 kfree(clp->cl_name.data); in __free_client()
2140 kfree(clp->cl_nii_domain.data); in __free_client()
2141 kfree(clp->cl_nii_name.data); in __free_client()
2142 idr_destroy(&clp->cl_stateids); in __free_client()
2143 kfree(clp->cl_ra); in __free_client()
2149 kref_put(&clp->cl_nfsdfs.cl_ref, __free_client); in drop_client()
2155 while (!list_empty(&clp->cl_sessions)) { in free_client()
2157 ses = list_entry(clp->cl_sessions.next, struct nfsd4_session, in free_client()
2159 list_del(&ses->se_perclnt); in free_client()
2160 WARN_ON_ONCE(atomic_read(&ses->se_ref)); in free_client()
2163 rpc_destroy_wait_queue(&clp->cl_cb_waitq); in free_client()
2164 if (clp->cl_nfsd_dentry) { in free_client()
2165 nfsd_client_rmdir(clp->cl_nfsd_dentry); in free_client()
2166 clp->cl_nfsd_dentry = NULL; in free_client()
2176 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_client_locked()
2179 lockdep_assert_held(&nn->client_lock); in unhash_client_locked()
2182 clp->cl_time = 0; in unhash_client_locked()
2184 if (!list_empty(&clp->cl_idhash)) { in unhash_client_locked()
2185 list_del_init(&clp->cl_idhash); in unhash_client_locked()
2186 if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) in unhash_client_locked()
2187 rb_erase(&clp->cl_namenode, &nn->conf_name_tree); in unhash_client_locked()
2189 rb_erase(&clp->cl_namenode, &nn->unconf_name_tree); in unhash_client_locked()
2191 list_del_init(&clp->cl_lru); in unhash_client_locked()
2192 spin_lock(&clp->cl_lock); in unhash_client_locked()
2193 list_for_each_entry(ses, &clp->cl_sessions, se_perclnt) in unhash_client_locked()
2194 list_del_init(&ses->se_hash); in unhash_client_locked()
2195 spin_unlock(&clp->cl_lock); in unhash_client_locked()
2201 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_client()
2203 spin_lock(&nn->client_lock); in unhash_client()
2205 spin_unlock(&nn->client_lock); in unhash_client()
2210 if (atomic_read(&clp->cl_rpc_users)) in mark_client_expired_locked()
2219 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in __destroy_client()
2227 while (!list_empty(&clp->cl_delegations)) { in __destroy_client()
2228 dp = list_entry(clp->cl_delegations.next, struct nfs4_delegation, dl_perclnt); in __destroy_client()
2230 list_add(&dp->dl_recall_lru, &reaplist); in __destroy_client()
2235 list_del_init(&dp->dl_recall_lru); in __destroy_client()
2238 while (!list_empty(&clp->cl_revoked)) { in __destroy_client()
2239 dp = list_entry(clp->cl_revoked.next, struct nfs4_delegation, dl_recall_lru); in __destroy_client()
2240 list_del_init(&dp->dl_recall_lru); in __destroy_client()
2241 nfs4_put_stid(&dp->dl_stid); in __destroy_client()
2243 while (!list_empty(&clp->cl_openowners)) { in __destroy_client()
2244 oo = list_entry(clp->cl_openowners.next, struct nfs4_openowner, oo_perclient); in __destroy_client()
2245 nfs4_get_stateowner(&oo->oo_owner); in __destroy_client()
2251 list_for_each_entry_safe(so, tmp, &clp->cl_ownerstr_hashtbl[i], in __destroy_client()
2254 WARN_ON_ONCE(so->so_is_open_owner); in __destroy_client()
2261 if (clp->cl_cb_conn.cb_xprt) in __destroy_client()
2262 svc_xprt_put(clp->cl_cb_conn.cb_xprt); in __destroy_client()
2263 atomic_add_unless(&nn->nfs4_client_count, -1, 0); in __destroy_client()
2278 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in inc_reclaim_complete()
2280 if (!nn->track_reclaim_completes) in inc_reclaim_complete()
2282 if (!nfsd4_find_reclaim_client(clp->cl_name, nn)) in inc_reclaim_complete()
2284 if (atomic_inc_return(&nn->nr_reclaim_complete) == in inc_reclaim_complete()
2285 nn->reclaim_str_hashtbl_size) { in inc_reclaim_complete()
2287 clp->net->ns.inum); in inc_reclaim_complete()
2301 memcpy(target->cl_verifier.data, source->data, in copy_verf()
2302 sizeof(target->cl_verifier.data)); in copy_verf()
2307 target->cl_clientid.cl_boot = source->cl_clientid.cl_boot; in copy_clid()
2308 target->cl_clientid.cl_id = source->cl_clientid.cl_id; in copy_clid()
2313 target->cr_principal = kstrdup(source->cr_principal, GFP_KERNEL); in copy_cred()
2314 target->cr_raw_principal = kstrdup(source->cr_raw_principal, in copy_cred()
2316 target->cr_targ_princ = kstrdup(source->cr_targ_princ, GFP_KERNEL); in copy_cred()
2317 if ((source->cr_principal && !target->cr_principal) || in copy_cred()
2318 (source->cr_raw_principal && !target->cr_raw_principal) || in copy_cred()
2319 (source->cr_targ_princ && !target->cr_targ_princ)) in copy_cred()
2320 return -ENOMEM; in copy_cred()
2322 target->cr_flavor = source->cr_flavor; in copy_cred()
2323 target->cr_uid = source->cr_uid; in copy_cred()
2324 target->cr_gid = source->cr_gid; in copy_cred()
2325 target->cr_group_info = source->cr_group_info; in copy_cred()
2326 get_group_info(target->cr_group_info); in copy_cred()
2327 target->cr_gss_mech = source->cr_gss_mech; in copy_cred()
2328 if (source->cr_gss_mech) in copy_cred()
2329 gss_mech_get(source->cr_gss_mech); in copy_cred()
2336 if (o1->len < o2->len) in compare_blob()
2337 return -1; in compare_blob()
2338 if (o1->len > o2->len) in compare_blob()
2340 return memcmp(o1->data, o2->data, o1->len); in compare_blob()
2346 return 0 == memcmp(v1->data, v2->data, sizeof(v1->data)); in same_verf()
2352 return (cl1->cl_boot == cl2->cl_boot) && (cl1->cl_id == cl2->cl_id); in same_clid()
2359 if (g1->ngroups != g2->ngroups) in groups_equal()
2361 for (i=0; i<g1->ngroups; i++) in groups_equal()
2362 if (!gid_eq(g1->gid[i], g2->gid[i])) in groups_equal()
2371 * approximation. We also don't want to allow non-gss use of a client
2379 return (cr->cr_flavor > RPC_AUTH_MAXFLAVOR); in is_gss_cred()
2387 || (!uid_eq(cr1->cr_uid, cr2->cr_uid)) in same_creds()
2388 || (!gid_eq(cr1->cr_gid, cr2->cr_gid)) in same_creds()
2389 || !groups_equal(cr1->cr_group_info, cr2->cr_group_info)) in same_creds()
2392 if (cr1->cr_principal == cr2->cr_principal) in same_creds()
2394 if (!cr1->cr_principal || !cr2->cr_principal) in same_creds()
2396 return 0 == strcmp(cr1->cr_principal, cr2->cr_principal); in same_creds()
2401 struct svc_cred *cr = &rqstp->rq_cred; in svc_rqst_integrity_protected()
2404 if (!cr->cr_gss_mech) in svc_rqst_integrity_protected()
2406 service = gss_pseudoflavor_to_service(cr->cr_gss_mech, cr->cr_flavor); in svc_rqst_integrity_protected()
2413 struct svc_cred *cr = &rqstp->rq_cred; in nfsd4_mach_creds_match()
2415 if (!cl->cl_mach_cred) in nfsd4_mach_creds_match()
2417 if (cl->cl_cred.cr_gss_mech != cr->cr_gss_mech) in nfsd4_mach_creds_match()
2421 if (cl->cl_cred.cr_raw_principal) in nfsd4_mach_creds_match()
2422 return 0 == strcmp(cl->cl_cred.cr_raw_principal, in nfsd4_mach_creds_match()
2423 cr->cr_raw_principal); in nfsd4_mach_creds_match()
2424 if (!cr->cr_principal) in nfsd4_mach_creds_match()
2426 return 0 == strcmp(cl->cl_cred.cr_principal, cr->cr_principal); in nfsd4_mach_creds_match()
2434 * This is opaque to client, so no need to byte-swap. Use in gen_confirm()
2438 verf[1] = (__force __be32)nn->clverifier_counter++; in gen_confirm()
2439 memcpy(clp->cl_confirm.data, verf, sizeof(clp->cl_confirm.data)); in gen_confirm()
2444 clp->cl_clientid.cl_boot = (u32)nn->boot_time; in gen_clid()
2445 clp->cl_clientid.cl_id = nn->clientid_counter++; in gen_clid()
2454 ret = idr_find(&cl->cl_stateids, t->si_opaque.so_id); in find_stateid_locked()
2455 if (!ret || !ret->sc_type) in find_stateid_locked()
2465 spin_lock(&cl->cl_lock); in find_stateid_by_type()
2468 if (typemask & s->sc_type) in find_stateid_by_type()
2469 refcount_inc(&s->sc_count); in find_stateid_by_type()
2473 spin_unlock(&cl->cl_lock); in find_stateid_by_type()
2510 struct inode *inode = file_inode(m->file); in client_info_show()
2516 return -ENXIO; in client_info_show()
2517 memcpy(&clid, &clp->cl_clientid, sizeof(clid)); in client_info_show()
2519 seq_printf(m, "address: \"%pISpc\"\n", (struct sockaddr *)&clp->cl_addr); in client_info_show()
2521 if (clp->cl_state == NFSD4_COURTESY) in client_info_show()
2523 else if (clp->cl_state == NFSD4_EXPIRABLE) in client_info_show()
2525 else if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) in client_info_show()
2530 ktime_get_boottime_seconds() - clp->cl_time); in client_info_show()
2532 seq_quote_mem(m, clp->cl_name.data, clp->cl_name.len); in client_info_show()
2533 seq_printf(m, "\nminor version: %d\n", clp->cl_minorversion); in client_info_show()
2534 if (clp->cl_nii_domain.data) { in client_info_show()
2536 seq_quote_mem(m, clp->cl_nii_domain.data, in client_info_show()
2537 clp->cl_nii_domain.len); in client_info_show()
2539 seq_quote_mem(m, clp->cl_nii_name.data, clp->cl_nii_name.len); in client_info_show()
2541 clp->cl_nii_time.tv_sec, clp->cl_nii_time.tv_nsec); in client_info_show()
2543 seq_printf(m, "callback state: %s\n", cb_state2str(clp->cl_cb_state)); in client_info_show()
2544 seq_printf(m, "callback address: %pISpc\n", &clp->cl_cb_conn.cb_addr); in client_info_show()
2553 __acquires(&clp->cl_lock) in states_start()
2555 struct nfs4_client *clp = s->private; in states_start()
2559 spin_lock(&clp->cl_lock); in states_start()
2560 ret = idr_get_next_ul(&clp->cl_stateids, &id); in states_start()
2567 struct nfs4_client *clp = s->private; in states_next()
2573 ret = idr_get_next_ul(&clp->cl_stateids, &id); in states_next()
2579 __releases(&clp->cl_lock) in states_stop()
2581 struct nfs4_client *clp = s->private; in states_stop()
2583 spin_unlock(&clp->cl_lock); in states_stop()
2588 seq_printf(s, "filename: \"%pD2\"", f->nf_file); in nfs4_show_fname()
2593 struct inode *inode = file_inode(f->nf_file); in nfs4_show_superblock()
2596 MAJOR(inode->i_sb->s_dev), in nfs4_show_superblock()
2597 MINOR(inode->i_sb->s_dev), in nfs4_show_superblock()
2598 inode->i_ino); in nfs4_show_superblock()
2604 seq_quote_mem(s, oo->so_owner.data, oo->so_owner.len); in nfs4_show_owner()
2609 seq_printf(s, "0x%.8x", stid->si_generation); in nfs4_show_stateid()
2610 seq_printf(s, "%12phN", &stid->si_opaque); in nfs4_show_stateid()
2621 if (st->sc_type != NFS4_OPEN_STID && st->sc_type != NFS4_LOCK_STID) in nfs4_show_open()
2624 oo = ols->st_stateowner; in nfs4_show_open()
2625 nf = st->sc_file; in nfs4_show_open()
2627 spin_lock(&nf->fi_lock); in nfs4_show_open()
2632 seq_printf(s, "- "); in nfs4_show_open()
2633 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_open()
2636 access = bmap_to_share_mode(ols->st_access_bmap); in nfs4_show_open()
2637 deny = bmap_to_share_mode(ols->st_deny_bmap); in nfs4_show_open()
2640 access & NFS4_SHARE_ACCESS_READ ? "r" : "-", in nfs4_show_open()
2641 access & NFS4_SHARE_ACCESS_WRITE ? "w" : "-"); in nfs4_show_open()
2643 deny & NFS4_SHARE_ACCESS_READ ? "r" : "-", in nfs4_show_open()
2644 deny & NFS4_SHARE_ACCESS_WRITE ? "w" : "-"); in nfs4_show_open()
2653 spin_unlock(&nf->fi_lock); in nfs4_show_open()
2665 oo = ols->st_stateowner; in nfs4_show_lock()
2666 nf = st->sc_file; in nfs4_show_lock()
2667 spin_lock(&nf->fi_lock); in nfs4_show_lock()
2672 seq_printf(s, "- "); in nfs4_show_lock()
2673 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_lock()
2691 spin_unlock(&nf->fi_lock); in nfs4_show_lock()
2702 nf = st->sc_file; in nfs4_show_deleg()
2703 spin_lock(&nf->fi_lock); in nfs4_show_deleg()
2704 file = nf->fi_deleg_file; in nfs4_show_deleg()
2708 seq_printf(s, "- "); in nfs4_show_deleg()
2709 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_deleg()
2714 ds->dl_type == NFS4_OPEN_DELEGATE_READ ? "r" : "w"); in nfs4_show_deleg()
2723 spin_unlock(&nf->fi_lock); in nfs4_show_deleg()
2733 file = ls->ls_file; in nfs4_show_layout()
2735 seq_printf(s, "- "); in nfs4_show_layout()
2736 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_layout()
2753 switch (st->sc_type) { in states_show()
2783 return -ENXIO; in client_states_open()
2788 s = file->private_data; in client_states_open()
2789 s->private = clp; in client_states_open()
2795 struct seq_file *m = file->private_data; in client_opens_release()
2796 struct nfs4_client *clp = m->private; in client_opens_release()
2818 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in force_expire_client()
2821 trace_nfsd_clid_admin_expired(&clp->cl_clientid); in force_expire_client()
2823 spin_lock(&nn->client_lock); in force_expire_client()
2824 clp->cl_time = 0; in force_expire_client()
2825 spin_unlock(&nn->client_lock); in force_expire_client()
2827 wait_event(expiry_wq, atomic_read(&clp->cl_rpc_users) == 0); in force_expire_client()
2828 spin_lock(&nn->client_lock); in force_expire_client()
2829 already_expired = list_empty(&clp->cl_lru); in force_expire_client()
2832 spin_unlock(&nn->client_lock); in force_expire_client()
2837 wait_event(expiry_wq, clp->cl_nfsd_dentry == NULL); in force_expire_client()
2850 return -EINVAL; in client_ctl_write()
2853 return -ENXIO; in client_ctl_write()
2876 switch (task->tk_status) { in nfsd4_cb_recall_any_done()
2877 case -NFS4ERR_DELAY: in nfsd4_cb_recall_any_done()
2888 struct nfs4_client *clp = cb->cb_clp; in nfsd4_cb_recall_any_release()
2889 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in nfsd4_cb_recall_any_release()
2891 spin_lock(&nn->client_lock); in nfsd4_cb_recall_any_release()
2892 clear_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags); in nfsd4_cb_recall_any_release()
2894 spin_unlock(&nn->client_lock); in nfsd4_cb_recall_any_release()
2916 ret = copy_cred(&clp->cl_cred, &rqstp->rq_cred); in create_client()
2922 kref_init(&clp->cl_nfsdfs.cl_ref); in create_client()
2923 nfsd4_init_cb(&clp->cl_cb_null, clp, NULL, NFSPROC4_CLNT_CB_NULL); in create_client()
2924 clp->cl_time = ktime_get_boottime_seconds(); in create_client()
2925 clear_bit(0, &clp->cl_cb_slot_busy); in create_client()
2927 memcpy(&clp->cl_addr, sa, sizeof(struct sockaddr_storage)); in create_client()
2928 clp->cl_cb_session = NULL; in create_client()
2929 clp->net = net; in create_client()
2930 clp->cl_nfsd_dentry = nfsd_client_mkdir( in create_client()
2931 nn, &clp->cl_nfsdfs, in create_client()
2932 clp->cl_clientid.cl_id - nn->clientid_base, in create_client()
2934 clp->cl_nfsd_info_dentry = dentries[0]; in create_client()
2935 if (!clp->cl_nfsd_dentry) { in create_client()
2939 clp->cl_ra = kzalloc(sizeof(*clp->cl_ra), GFP_KERNEL); in create_client()
2940 if (!clp->cl_ra) { in create_client()
2944 clp->cl_ra_time = 0; in create_client()
2945 nfsd4_init_cb(&clp->cl_ra->ra_cb, clp, &nfsd4_cb_recall_any_ops, in create_client()
2953 struct rb_node **new = &(root->rb_node), *parent = NULL; in add_clp_to_name_tree()
2960 if (compare_blob(&clp->cl_name, &new_clp->cl_name) > 0) in add_clp_to_name_tree()
2961 new = &((*new)->rb_left); in add_clp_to_name_tree()
2963 new = &((*new)->rb_right); in add_clp_to_name_tree()
2966 rb_link_node(&new_clp->cl_namenode, parent, new); in add_clp_to_name_tree()
2967 rb_insert_color(&new_clp->cl_namenode, root); in add_clp_to_name_tree()
2974 struct rb_node *node = root->rb_node; in find_clp_in_name_tree()
2979 cmp = compare_blob(&clp->cl_name, name); in find_clp_in_name_tree()
2981 node = node->rb_left; in find_clp_in_name_tree()
2983 node = node->rb_right; in find_clp_in_name_tree()
2994 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in add_to_unconfirmed()
2996 lockdep_assert_held(&nn->client_lock); in add_to_unconfirmed()
2998 clear_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags); in add_to_unconfirmed()
2999 add_clp_to_name_tree(clp, &nn->unconf_name_tree); in add_to_unconfirmed()
3000 idhashval = clientid_hashval(clp->cl_clientid.cl_id); in add_to_unconfirmed()
3001 list_add(&clp->cl_idhash, &nn->unconf_id_hashtbl[idhashval]); in add_to_unconfirmed()
3008 unsigned int idhashval = clientid_hashval(clp->cl_clientid.cl_id); in move_to_confirmed()
3009 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in move_to_confirmed()
3011 lockdep_assert_held(&nn->client_lock); in move_to_confirmed()
3013 list_move(&clp->cl_idhash, &nn->conf_id_hashtbl[idhashval]); in move_to_confirmed()
3014 rb_erase(&clp->cl_namenode, &nn->unconf_name_tree); in move_to_confirmed()
3015 add_clp_to_name_tree(clp, &nn->conf_name_tree); in move_to_confirmed()
3016 set_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags); in move_to_confirmed()
3017 trace_nfsd_clid_confirmed(&clp->cl_clientid); in move_to_confirmed()
3025 unsigned int idhashval = clientid_hashval(clid->cl_id); in find_client_in_id_table()
3028 if (same_clid(&clp->cl_clientid, clid)) { in find_client_in_id_table()
3029 if ((bool)clp->cl_minorversion != sessions) in find_client_in_id_table()
3041 struct list_head *tbl = nn->conf_id_hashtbl; in find_confirmed_client()
3043 lockdep_assert_held(&nn->client_lock); in find_confirmed_client()
3050 struct list_head *tbl = nn->unconf_id_hashtbl; in find_unconfirmed_client()
3052 lockdep_assert_held(&nn->client_lock); in find_unconfirmed_client()
3058 return clp->cl_exchange_flags != 0; in clp_used_exchangeid()
3064 lockdep_assert_held(&nn->client_lock); in find_confirmed_client_by_name()
3065 return find_clp_in_name_tree(name, &nn->conf_name_tree); in find_confirmed_client_by_name()
3071 lockdep_assert_held(&nn->client_lock); in find_unconfirmed_client_by_name()
3072 return find_clp_in_name_tree(name, &nn->unconf_name_tree); in find_unconfirmed_client_by_name()
3078 struct nfs4_cb_conn *conn = &clp->cl_cb_conn; in gen_callback()
3084 if (se->se_callback_netid_len == 3 && in gen_callback()
3085 !memcmp(se->se_callback_netid_val, "tcp", 3)) in gen_callback()
3087 else if (se->se_callback_netid_len == 4 && in gen_callback()
3088 !memcmp(se->se_callback_netid_val, "tcp6", 4)) in gen_callback()
3093 conn->cb_addrlen = rpc_uaddr2sockaddr(clp->net, se->se_callback_addr_val, in gen_callback()
3094 se->se_callback_addr_len, in gen_callback()
3095 (struct sockaddr *)&conn->cb_addr, in gen_callback()
3096 sizeof(conn->cb_addr)); in gen_callback()
3098 if (!conn->cb_addrlen || conn->cb_addr.ss_family != expected_family) in gen_callback()
3101 if (conn->cb_addr.ss_family == AF_INET6) in gen_callback()
3102 ((struct sockaddr_in6 *)&conn->cb_addr)->sin6_scope_id = scopeid; in gen_callback()
3104 conn->cb_prog = se->se_callback_prog; in gen_callback()
3105 conn->cb_ident = se->se_callback_ident; in gen_callback()
3106 memcpy(&conn->cb_saddr, &rqstp->rq_daddr, rqstp->rq_daddrlen); in gen_callback()
3110 conn->cb_addr.ss_family = AF_UNSPEC; in gen_callback()
3111 conn->cb_addrlen = 0; in gen_callback()
3122 struct xdr_buf *buf = resp->xdr->buf; in nfsd4_store_cache_entry()
3123 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_store_cache_entry()
3126 dprintk("--> %s slot %p\n", __func__, slot); in nfsd4_store_cache_entry()
3128 slot->sl_flags |= NFSD4_SLOT_INITIALIZED; in nfsd4_store_cache_entry()
3129 slot->sl_opcnt = resp->opcnt; in nfsd4_store_cache_entry()
3130 slot->sl_status = resp->cstate.status; in nfsd4_store_cache_entry()
3131 free_svc_cred(&slot->sl_cred); in nfsd4_store_cache_entry()
3132 copy_cred(&slot->sl_cred, &resp->rqstp->rq_cred); in nfsd4_store_cache_entry()
3135 slot->sl_flags &= ~NFSD4_SLOT_CACHED; in nfsd4_store_cache_entry()
3138 slot->sl_flags |= NFSD4_SLOT_CACHED; in nfsd4_store_cache_entry()
3140 base = resp->cstate.data_offset; in nfsd4_store_cache_entry()
3141 slot->sl_datalen = buf->len - base; in nfsd4_store_cache_entry()
3142 if (read_bytes_from_xdr_buf(buf, base, slot->sl_data, slot->sl_datalen)) in nfsd4_store_cache_entry()
3151 * operation which sets resp->p and increments resp->opcnt for
3160 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_enc_sequence_replay()
3163 op = &args->ops[resp->opcnt - 1]; in nfsd4_enc_sequence_replay()
3166 if (slot->sl_flags & NFSD4_SLOT_CACHED) in nfsd4_enc_sequence_replay()
3167 return op->status; in nfsd4_enc_sequence_replay()
3168 if (args->opcnt == 1) { in nfsd4_enc_sequence_replay()
3170 * The original operation wasn't a solo sequence--we in nfsd4_enc_sequence_replay()
3171 * always cache those--so this retry must not match the in nfsd4_enc_sequence_replay()
3174 op->status = nfserr_seq_false_retry; in nfsd4_enc_sequence_replay()
3176 op = &args->ops[resp->opcnt++]; in nfsd4_enc_sequence_replay()
3177 op->status = nfserr_retry_uncached_rep; in nfsd4_enc_sequence_replay()
3180 return op->status; in nfsd4_enc_sequence_replay()
3191 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_replay_cache_entry()
3192 struct xdr_stream *xdr = resp->xdr; in nfsd4_replay_cache_entry()
3196 dprintk("--> %s slot %p\n", __func__, slot); in nfsd4_replay_cache_entry()
3198 status = nfsd4_enc_sequence_replay(resp->rqstp->rq_argp, resp); in nfsd4_replay_cache_entry()
3202 p = xdr_reserve_space(xdr, slot->sl_datalen); in nfsd4_replay_cache_entry()
3207 xdr_encode_opaque_fixed(p, slot->sl_data, slot->sl_datalen); in nfsd4_replay_cache_entry()
3210 resp->opcnt = slot->sl_opcnt; in nfsd4_replay_cache_entry()
3211 return slot->sl_status; in nfsd4_replay_cache_entry()
3221 new->cl_exchange_flags |= EXCHGID4_FLAG_USE_PNFS_MDS; in nfsd4_set_ex_flags()
3223 new->cl_exchange_flags |= EXCHGID4_FLAG_USE_NON_PNFS; in nfsd4_set_ex_flags()
3227 new->cl_exchange_flags |= EXCHGID4_FLAG_SUPP_MOVED_REFER; in nfsd4_set_ex_flags()
3230 clid->flags = new->cl_exchange_flags; in nfsd4_set_ex_flags()
3237 list_for_each_entry(oo, &clp->cl_openowners, oo_perclient) { in client_has_openowners()
3238 if (!list_empty(&oo->oo_owner.so_stateids)) in client_has_openowners()
3248 || !list_empty(&clp->cl_lo_states) in client_has_state()
3250 || !list_empty(&clp->cl_delegations) in client_has_state()
3251 || !list_empty(&clp->cl_sessions) in client_has_state()
3252 || !list_empty(&clp->async_copies); in client_has_state()
3258 if (!exid->nii_domain.data) in copy_impl_id()
3260 xdr_netobj_dup(&clp->cl_nii_domain, &exid->nii_domain, GFP_KERNEL); in copy_impl_id()
3261 if (!clp->cl_nii_domain.data) in copy_impl_id()
3263 xdr_netobj_dup(&clp->cl_nii_name, &exid->nii_name, GFP_KERNEL); in copy_impl_id()
3264 if (!clp->cl_nii_name.data) in copy_impl_id()
3266 clp->cl_nii_time = exid->nii_time; in copy_impl_id()
3274 struct nfsd4_exchange_id *exid = &u->exchange_id; in nfsd4_exchange_id()
3279 nfs4_verifier verf = exid->verifier; in nfsd4_exchange_id()
3281 bool update = exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A; in nfsd4_exchange_id()
3287 __func__, rqstp, exid, exid->clname.len, exid->clname.data, in nfsd4_exchange_id()
3288 addr_str, exid->flags, exid->spa_how); in nfsd4_exchange_id()
3290 if (exid->flags & ~EXCHGID4_FLAG_MASK_A) in nfsd4_exchange_id()
3293 new = create_client(exid->clname, rqstp, &verf); in nfsd4_exchange_id()
3300 switch (exid->spa_how) { in nfsd4_exchange_id()
3302 exid->spo_must_enforce[0] = 0; in nfsd4_exchange_id()
3303 exid->spo_must_enforce[1] = ( in nfsd4_exchange_id()
3304 1 << (OP_BIND_CONN_TO_SESSION - 32) | in nfsd4_exchange_id()
3305 1 << (OP_EXCHANGE_ID - 32) | in nfsd4_exchange_id()
3306 1 << (OP_CREATE_SESSION - 32) | in nfsd4_exchange_id()
3307 1 << (OP_DESTROY_SESSION - 32) | in nfsd4_exchange_id()
3308 1 << (OP_DESTROY_CLIENTID - 32)); in nfsd4_exchange_id()
3310 exid->spo_must_allow[0] &= (1 << (OP_CLOSE) | in nfsd4_exchange_id()
3315 exid->spo_must_allow[1] &= ( in nfsd4_exchange_id()
3316 1 << (OP_TEST_STATEID - 32) | in nfsd4_exchange_id()
3317 1 << (OP_FREE_STATEID - 32)); in nfsd4_exchange_id()
3327 if (!new->cl_cred.cr_principal && in nfsd4_exchange_id()
3328 !new->cl_cred.cr_raw_principal) { in nfsd4_exchange_id()
3332 new->cl_mach_cred = true; in nfsd4_exchange_id()
3345 spin_lock(&nn->client_lock); in nfsd4_exchange_id()
3346 conf = find_confirmed_client_by_name(&exid->clname, nn); in nfsd4_exchange_id()
3348 bool creds_match = same_creds(&conf->cl_cred, &rqstp->rq_cred); in nfsd4_exchange_id()
3349 bool verfs_match = same_verf(&verf, &conf->cl_verifier); in nfsd4_exchange_id()
3369 exid->flags |= EXCHGID4_FLAG_CONFIRMED_R; in nfsd4_exchange_id()
3382 conf->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; in nfsd4_exchange_id()
3397 unconf = find_unconfirmed_client_by_name(&exid->clname, nn); in nfsd4_exchange_id()
3409 trace_nfsd_clid_replaced(&conf->cl_clientid); in nfsd4_exchange_id()
3411 new->cl_minorversion = cstate->minorversion; in nfsd4_exchange_id()
3412 new->cl_spo_must_allow.u.words[0] = exid->spo_must_allow[0]; in nfsd4_exchange_id()
3413 new->cl_spo_must_allow.u.words[1] = exid->spo_must_allow[1]; in nfsd4_exchange_id()
3418 exid->clientid.cl_boot = conf->cl_clientid.cl_boot; in nfsd4_exchange_id()
3419 exid->clientid.cl_id = conf->cl_clientid.cl_id; in nfsd4_exchange_id()
3421 exid->seqid = conf->cl_cs_slot.sl_seqid + 1; in nfsd4_exchange_id()
3425 conf->cl_cs_slot.sl_seqid, conf->cl_exchange_flags); in nfsd4_exchange_id()
3429 spin_unlock(&nn->client_lock); in nfsd4_exchange_id()
3434 trace_nfsd_clid_expire_unconf(&unconf->cl_clientid); in nfsd4_exchange_id()
3453 /* Note unsigned 32-bit arithmetic handles wraparound: */ in check_slot_seqid()
3464 * Do this for solo or embedded create session operations.
3470 slot->sl_status = nfserr; in nfsd4_cache_create_session()
3471 memcpy(&slot->sl_cr_ses, cr_ses, sizeof(*cr_ses)); in nfsd4_cache_create_session()
3478 memcpy(cr_ses, &slot->sl_cr_ses, sizeof(*cr_ses)); in nfsd4_replay_create_session()
3479 return slot->sl_status; in nfsd4_replay_create_session()
3501 u32 maxrpc = nn->nfsd_serv->sv_max_mesg; in check_forechannel_attrs()
3503 if (ca->maxreq_sz < NFSD_MIN_REQ_HDR_SEQ_SZ) in check_forechannel_attrs()
3505 if (ca->maxresp_sz < NFSD_MIN_RESP_HDR_SEQ_SZ) in check_forechannel_attrs()
3507 ca->headerpadsz = 0; in check_forechannel_attrs()
3508 ca->maxreq_sz = min_t(u32, ca->maxreq_sz, maxrpc); in check_forechannel_attrs()
3509 ca->maxresp_sz = min_t(u32, ca->maxresp_sz, maxrpc); in check_forechannel_attrs()
3510 ca->maxops = min_t(u32, ca->maxops, NFSD_MAX_OPS_PER_COMPOUND); in check_forechannel_attrs()
3511 ca->maxresp_cached = min_t(u32, ca->maxresp_cached, in check_forechannel_attrs()
3513 ca->maxreqs = min_t(u32, ca->maxreqs, NFSD_MAX_SLOTS_PER_SESSION); in check_forechannel_attrs()
3524 ca->maxreqs = nfsd4_get_drc_mem(ca, nn); in check_forechannel_attrs()
3530 * Server's NFSv4.1 backchannel support is AUTH_SYS-only for now.
3547 ca->headerpadsz = 0; in check_backchannel_attrs()
3549 if (ca->maxreq_sz < NFSD_CB_MAX_REQ_SZ) in check_backchannel_attrs()
3551 if (ca->maxresp_sz < NFSD_CB_MAX_RESP_SZ) in check_backchannel_attrs()
3553 ca->maxresp_cached = 0; in check_backchannel_attrs()
3554 if (ca->maxops < 2) in check_backchannel_attrs()
3562 switch (cbs->flavor) { in nfsd4_check_cb_sec()
3582 struct nfsd4_create_session *cr_ses = &u->create_session; in nfsd4_create_session()
3592 if (cr_ses->flags & ~SESSION4_FLAG_MASK_A) in nfsd4_create_session()
3594 status = nfsd4_check_cb_sec(&cr_ses->cb_sec); in nfsd4_create_session()
3597 status = check_forechannel_attrs(&cr_ses->fore_channel, nn); in nfsd4_create_session()
3600 status = check_backchannel_attrs(&cr_ses->back_channel); in nfsd4_create_session()
3604 new = alloc_session(&cr_ses->fore_channel, &cr_ses->back_channel); in nfsd4_create_session()
3611 spin_lock(&nn->client_lock); in nfsd4_create_session()
3612 unconf = find_unconfirmed_client(&cr_ses->clientid, true, nn); in nfsd4_create_session()
3613 conf = find_confirmed_client(&cr_ses->clientid, true, nn); in nfsd4_create_session()
3620 cs_slot = &conf->cl_cs_slot; in nfsd4_create_session()
3621 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); in nfsd4_create_session()
3629 if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred) || in nfsd4_create_session()
3630 !rpc_cmp_addr(sa, (struct sockaddr *) &unconf->cl_addr)) { in nfsd4_create_session()
3637 cs_slot = &unconf->cl_cs_slot; in nfsd4_create_session()
3638 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); in nfsd4_create_session()
3644 old = find_confirmed_client_by_name(&unconf->cl_name, nn); in nfsd4_create_session()
3651 trace_nfsd_clid_replaced(&old->cl_clientid); in nfsd4_create_session()
3661 cr_ses->flags &= ~SESSION4_PERSIST; in nfsd4_create_session()
3663 cr_ses->flags &= ~SESSION4_RDMA; in nfsd4_create_session()
3668 memcpy(cr_ses->sessionid.data, new->se_sessionid.data, in nfsd4_create_session()
3670 cs_slot->sl_seqid++; in nfsd4_create_session()
3671 cr_ses->seqid = cs_slot->sl_seqid; in nfsd4_create_session()
3673 /* cache solo and embedded create sessions under the client_lock */ in nfsd4_create_session()
3675 spin_unlock(&nn->client_lock); in nfsd4_create_session()
3677 fsnotify_dentry(conf->cl_nfsd_info_dentry, FS_MODIFY); in nfsd4_create_session()
3685 spin_unlock(&nn->client_lock); in nfsd4_create_session()
3692 nfsd4_put_drc_mem(&cr_ses->fore_channel); in nfsd4_create_session()
3714 struct nfsd4_backchannel_ctl *bc = &u->backchannel_ctl; in nfsd4_backchannel_ctl()
3715 struct nfsd4_session *session = cstate->session; in nfsd4_backchannel_ctl()
3719 status = nfsd4_check_cb_sec(&bc->bc_cb_sec); in nfsd4_backchannel_ctl()
3722 spin_lock(&nn->client_lock); in nfsd4_backchannel_ctl()
3723 session->se_cb_prog = bc->bc_cb_program; in nfsd4_backchannel_ctl()
3724 session->se_cb_sec = bc->bc_cb_sec; in nfsd4_backchannel_ctl()
3725 spin_unlock(&nn->client_lock); in nfsd4_backchannel_ctl()
3727 nfsd4_probe_callback(session->se_client); in nfsd4_backchannel_ctl()
3736 list_for_each_entry(c, &s->se_conns, cn_persession) { in __nfsd4_find_conn()
3737 if (c->cn_xprt == xpt) { in __nfsd4_find_conn()
3747 struct nfs4_client *clp = session->se_client; in nfsd4_match_existing_connection()
3748 struct svc_xprt *xpt = rqst->rq_xprt; in nfsd4_match_existing_connection()
3753 spin_lock(&clp->cl_lock); in nfsd4_match_existing_connection()
3757 else if (req == c->cn_flags) in nfsd4_match_existing_connection()
3760 c->cn_flags != NFS4_CDFC4_BACK) in nfsd4_match_existing_connection()
3763 c->cn_flags != NFS4_CDFC4_FORE) in nfsd4_match_existing_connection()
3767 spin_unlock(&clp->cl_lock); in nfsd4_match_existing_connection()
3777 struct nfsd4_bind_conn_to_session *bcts = &u->bind_conn_to_session; in nfsd4_bind_conn_to_session()
3786 spin_lock(&nn->client_lock); in nfsd4_bind_conn_to_session()
3787 session = find_in_sessionid_hashtbl(&bcts->sessionid, net, &status); in nfsd4_bind_conn_to_session()
3788 spin_unlock(&nn->client_lock); in nfsd4_bind_conn_to_session()
3792 if (!nfsd4_mach_creds_match(session->se_client, rqstp)) in nfsd4_bind_conn_to_session()
3795 bcts->dir, &conn); in nfsd4_bind_conn_to_session()
3797 if (bcts->dir == NFS4_CDFC4_FORE_OR_BOTH || in nfsd4_bind_conn_to_session()
3798 bcts->dir == NFS4_CDFC4_BACK) in nfsd4_bind_conn_to_session()
3799 conn->cn_flags |= NFS4_CDFC4_BACK; in nfsd4_bind_conn_to_session()
3800 nfsd4_probe_callback(session->se_client); in nfsd4_bind_conn_to_session()
3805 status = nfsd4_map_bcts_dir(&bcts->dir); in nfsd4_bind_conn_to_session()
3808 conn = alloc_conn(rqstp, bcts->dir); in nfsd4_bind_conn_to_session()
3822 if (!cstate->session) in nfsd4_compound_in_session()
3824 return !memcmp(sid, &cstate->session->se_sessionid, sizeof(*sid)); in nfsd4_compound_in_session()
3831 struct nfs4_sessionid *sessionid = &u->destroy_session.sessionid; in nfsd4_destroy_session()
3845 spin_lock(&nn->client_lock); in nfsd4_destroy_session()
3850 if (!nfsd4_mach_creds_match(ses->se_client, r)) in nfsd4_destroy_session()
3856 spin_unlock(&nn->client_lock); in nfsd4_destroy_session()
3858 nfsd4_probe_callback_sync(ses->se_client); in nfsd4_destroy_session()
3860 spin_lock(&nn->client_lock); in nfsd4_destroy_session()
3865 spin_unlock(&nn->client_lock); in nfsd4_destroy_session()
3872 struct nfs4_client *clp = ses->se_client; in nfsd4_sequence_check_conn()
3877 spin_lock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3878 c = __nfsd4_find_conn(new->cn_xprt, ses); in nfsd4_sequence_check_conn()
3882 if (clp->cl_mach_cred) in nfsd4_sequence_check_conn()
3885 spin_unlock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3889 nfsd4_conn_lost(&new->cn_xpt_user); in nfsd4_sequence_check_conn()
3892 spin_unlock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3899 struct nfsd4_compoundargs *args = rqstp->rq_argp; in nfsd4_session_too_many_ops()
3901 return args->opcnt > session->se_fchannel.maxops; in nfsd4_session_too_many_ops()
3907 struct xdr_buf *xb = &rqstp->rq_arg; in nfsd4_request_too_big()
3909 return xb->len > session->se_fchannel.maxreq_sz; in nfsd4_request_too_big()
3915 struct nfsd4_compoundargs *argp = rqstp->rq_argp; in replay_matches_cache()
3917 if ((bool)(slot->sl_flags & NFSD4_SLOT_CACHETHIS) != in replay_matches_cache()
3918 (bool)seq->cachethis) in replay_matches_cache()
3924 if (slot->sl_opcnt < argp->opcnt && !slot->sl_status) in replay_matches_cache()
3931 if (slot->sl_opcnt > argp->opcnt) in replay_matches_cache()
3934 if (!same_creds(&rqstp->rq_cred, &slot->sl_cred)) in replay_matches_cache()
3949 struct nfsd4_sequence *seq = &u->sequence; in nfsd4_sequence()
3950 struct nfsd4_compoundres *resp = rqstp->rq_resp; in nfsd4_sequence()
3951 struct xdr_stream *xdr = resp->xdr; in nfsd4_sequence()
3961 if (resp->opcnt != 1) in nfsd4_sequence()
3972 spin_lock(&nn->client_lock); in nfsd4_sequence()
3973 session = find_in_sessionid_hashtbl(&seq->sessionid, net, &status); in nfsd4_sequence()
3976 clp = session->se_client; in nfsd4_sequence()
3987 if (seq->slotid >= session->se_fchannel.maxreqs) in nfsd4_sequence()
3990 slot = session->se_slots[seq->slotid]; in nfsd4_sequence()
3991 dprintk("%s: slotid %d\n", __func__, seq->slotid); in nfsd4_sequence()
3996 seq->maxslots = session->se_fchannel.maxreqs; in nfsd4_sequence()
3998 status = check_slot_seqid(seq->seqid, slot->sl_seqid, in nfsd4_sequence()
3999 slot->sl_flags & NFSD4_SLOT_INUSE); in nfsd4_sequence()
4002 if (!(slot->sl_flags & NFSD4_SLOT_INITIALIZED)) in nfsd4_sequence()
4007 cstate->slot = slot; in nfsd4_sequence()
4008 cstate->session = session; in nfsd4_sequence()
4009 cstate->clp = clp; in nfsd4_sequence()
4010 /* Return the cached reply status and set cstate->status in nfsd4_sequence()
4013 cstate->status = nfserr_replay_cache; in nfsd4_sequence()
4024 buflen = (seq->cachethis) ? in nfsd4_sequence()
4025 session->se_fchannel.maxresp_cached : in nfsd4_sequence()
4026 session->se_fchannel.maxresp_sz; in nfsd4_sequence()
4027 status = (seq->cachethis) ? nfserr_rep_too_big_to_cache : in nfsd4_sequence()
4029 if (xdr_restrict_buflen(xdr, buflen - rqstp->rq_auth_slack)) in nfsd4_sequence()
4035 slot->sl_seqid = seq->seqid; in nfsd4_sequence()
4036 slot->sl_flags |= NFSD4_SLOT_INUSE; in nfsd4_sequence()
4037 if (seq->cachethis) in nfsd4_sequence()
4038 slot->sl_flags |= NFSD4_SLOT_CACHETHIS; in nfsd4_sequence()
4040 slot->sl_flags &= ~NFSD4_SLOT_CACHETHIS; in nfsd4_sequence()
4042 cstate->slot = slot; in nfsd4_sequence()
4043 cstate->session = session; in nfsd4_sequence()
4044 cstate->clp = clp; in nfsd4_sequence()
4047 switch (clp->cl_cb_state) { in nfsd4_sequence()
4049 seq->status_flags = SEQ4_STATUS_CB_PATH_DOWN; in nfsd4_sequence()
4052 seq->status_flags = SEQ4_STATUS_BACKCHANNEL_FAULT; in nfsd4_sequence()
4055 seq->status_flags = 0; in nfsd4_sequence()
4057 if (!list_empty(&clp->cl_revoked)) in nfsd4_sequence()
4058 seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED; in nfsd4_sequence()
4062 spin_unlock(&nn->client_lock); in nfsd4_sequence()
4072 struct nfsd4_compound_state *cs = &resp->cstate; in nfsd4_sequence_done()
4075 if (cs->status != nfserr_replay_cache) { in nfsd4_sequence_done()
4077 cs->slot->sl_flags &= ~NFSD4_SLOT_INUSE; in nfsd4_sequence_done()
4080 nfsd4_put_session(cs->session); in nfsd4_sequence_done()
4081 } else if (cs->clp) in nfsd4_sequence_done()
4082 put_client_renew(cs->clp); in nfsd4_sequence_done()
4090 struct nfsd4_destroy_clientid *dc = &u->destroy_clientid; in nfsd4_destroy_clientid()
4096 spin_lock(&nn->client_lock); in nfsd4_destroy_clientid()
4097 unconf = find_unconfirmed_client(&dc->clientid, true, nn); in nfsd4_destroy_clientid()
4098 conf = find_confirmed_client(&dc->clientid, true, nn); in nfsd4_destroy_clientid()
4121 trace_nfsd_clid_destroyed(&clp->cl_clientid); in nfsd4_destroy_clientid()
4124 spin_unlock(&nn->client_lock); in nfsd4_destroy_clientid()
4134 struct nfsd4_reclaim_complete *rc = &u->reclaim_complete; in nfsd4_reclaim_complete()
4135 struct nfs4_client *clp = cstate->clp; in nfsd4_reclaim_complete()
4138 if (rc->rca_one_fs) { in nfsd4_reclaim_complete()
4139 if (!cstate->current_fh.fh_dentry) in nfsd4_reclaim_complete()
4149 if (test_and_set_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &clp->cl_flags)) in nfsd4_reclaim_complete()
4164 trace_nfsd_clid_reclaim_complete(&clp->cl_clientid); in nfsd4_reclaim_complete()
4175 struct nfsd4_setclientid *setclid = &u->setclientid; in nfsd4_setclientid()
4176 struct xdr_netobj clname = setclid->se_name; in nfsd4_setclientid()
4177 nfs4_verifier clverifier = setclid->se_verf; in nfsd4_setclientid()
4186 spin_lock(&nn->client_lock); in nfsd4_setclientid()
4192 if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid()
4201 if (same_verf(&conf->cl_verifier, &clverifier)) { in nfsd4_setclientid()
4209 new->cl_minorversion = 0; in nfsd4_setclientid()
4212 setclid->se_clientid.cl_boot = new->cl_clientid.cl_boot; in nfsd4_setclientid()
4213 setclid->se_clientid.cl_id = new->cl_clientid.cl_id; in nfsd4_setclientid()
4214 memcpy(setclid->se_confirm.data, new->cl_confirm.data, sizeof(setclid->se_confirm.data)); in nfsd4_setclientid()
4218 spin_unlock(&nn->client_lock); in nfsd4_setclientid()
4222 trace_nfsd_clid_expire_unconf(&unconf->cl_clientid); in nfsd4_setclientid()
4234 &u->setclientid_confirm; in nfsd4_setclientid_confirm()
4237 nfs4_verifier confirm = setclientid_confirm->sc_confirm; in nfsd4_setclientid_confirm()
4238 clientid_t * clid = &setclientid_confirm->sc_clientid; in nfsd4_setclientid_confirm()
4245 spin_lock(&nn->client_lock); in nfsd4_setclientid_confirm()
4256 if (unconf && !same_creds(&unconf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid_confirm()
4260 if (conf && !same_creds(&conf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid_confirm()
4264 if (!unconf || !same_verf(&confirm, &unconf->cl_confirm)) { in nfsd4_setclientid_confirm()
4265 if (conf && same_verf(&confirm, &conf->cl_confirm)) { in nfsd4_setclientid_confirm()
4275 nfsd4_change_callback(conf, &unconf->cl_cb_conn); in nfsd4_setclientid_confirm()
4277 old = find_confirmed_client_by_name(&unconf->cl_name, nn); in nfsd4_setclientid_confirm()
4281 && !same_creds(&unconf->cl_cred, in nfsd4_setclientid_confirm()
4282 &old->cl_cred)) { in nfsd4_setclientid_confirm()
4291 trace_nfsd_clid_replaced(&old->cl_clientid); in nfsd4_setclientid_confirm()
4297 spin_unlock(&nn->client_lock); in nfsd4_setclientid_confirm()
4299 fsnotify_dentry(conf->cl_nfsd_info_dentry, FS_MODIFY); in nfsd4_setclientid_confirm()
4301 spin_lock(&nn->client_lock); in nfsd4_setclientid_confirm()
4304 spin_unlock(&nn->client_lock); in nfsd4_setclientid_confirm()
4319 refcount_set(&fp->fi_ref, 1); in nfsd4_file_init()
4320 spin_lock_init(&fp->fi_lock); in nfsd4_file_init()
4321 INIT_LIST_HEAD(&fp->fi_stateids); in nfsd4_file_init()
4322 INIT_LIST_HEAD(&fp->fi_delegations); in nfsd4_file_init()
4323 INIT_LIST_HEAD(&fp->fi_clnt_odstate); in nfsd4_file_init()
4324 fh_copy_shallow(&fp->fi_fhandle, &fh->fh_handle); in nfsd4_file_init()
4325 fp->fi_deleg_file = NULL; in nfsd4_file_init()
4326 fp->fi_had_conflict = false; in nfsd4_file_init()
4327 fp->fi_share_deny = 0; in nfsd4_file_init()
4328 memset(fp->fi_fds, 0, sizeof(fp->fi_fds)); in nfsd4_file_init()
4329 memset(fp->fi_access, 0, sizeof(fp->fi_access)); in nfsd4_file_init()
4330 fp->fi_aliased = false; in nfsd4_file_init()
4331 fp->fi_inode = d_inode(fh->fh_dentry); in nfsd4_file_init()
4333 INIT_LIST_HEAD(&fp->fi_lo_states); in nfsd4_file_init()
4334 atomic_set(&fp->fi_lo_recalls, 0); in nfsd4_file_init()
4396 return -ENOMEM; in nfsd4_init_slabs()
4406 count = atomic_read(&nn->nfsd_courtesy_clients); in nfsd4_state_shrinker_count()
4410 queue_work(laundry_wq, &nn->nfsd_shrinker_work); in nfsd4_state_shrinker_count()
4426 nn->nfsd4_lease = 90; /* default lease time */ in nfsd4_init_leases_net()
4427 nn->nfsd4_grace = 90; in nfsd4_init_leases_net()
4428 nn->somebody_reclaimed = false; in nfsd4_init_leases_net()
4429 nn->track_reclaim_completes = false; in nfsd4_init_leases_net()
4430 nn->clverifier_counter = get_random_u32(); in nfsd4_init_leases_net()
4431 nn->clientid_base = get_random_u32(); in nfsd4_init_leases_net()
4432 nn->clientid_counter = nn->clientid_base + 1; in nfsd4_init_leases_net()
4433 nn->s2s_cp_cl_id = nn->clientid_counter++; in nfsd4_init_leases_net()
4435 atomic_set(&nn->nfs4_client_count, 0); in nfsd4_init_leases_net()
4439 nn->nfs4_max_clients = max_t(int, max_clients, NFS4_CLIENTS_PER_GB); in nfsd4_init_leases_net()
4441 atomic_set(&nn->nfsd_courtesy_clients, 0); in nfsd4_init_leases_net()
4446 rp->rp_status = nfserr_serverfault; in init_nfs4_replay()
4447 rp->rp_buflen = 0; in init_nfs4_replay()
4448 rp->rp_buf = rp->rp_ibuf; in init_nfs4_replay()
4449 mutex_init(&rp->rp_mutex); in init_nfs4_replay()
4456 mutex_lock(&so->so_replay.rp_mutex); in nfsd4_cstate_assign_replay()
4457 cstate->replay_owner = nfs4_get_stateowner(so); in nfsd4_cstate_assign_replay()
4463 struct nfs4_stateowner *so = cstate->replay_owner; in nfsd4_cstate_clear_replay()
4466 cstate->replay_owner = NULL; in nfsd4_cstate_clear_replay()
4467 mutex_unlock(&so->so_replay.rp_mutex); in nfsd4_cstate_clear_replay()
4480 xdr_netobj_dup(&sop->so_owner, owner, GFP_KERNEL); in alloc_stateowner()
4481 if (!sop->so_owner.data) { in alloc_stateowner()
4486 INIT_LIST_HEAD(&sop->so_stateids); in alloc_stateowner()
4487 sop->so_client = clp; in alloc_stateowner()
4488 init_nfs4_replay(&sop->so_replay); in alloc_stateowner()
4489 atomic_set(&sop->so_count, 1); in alloc_stateowner()
4495 lockdep_assert_held(&clp->cl_lock); in hash_openowner()
4497 list_add(&oo->oo_owner.so_strhash, in hash_openowner()
4498 &clp->cl_ownerstr_hashtbl[strhashval]); in hash_openowner()
4499 list_add(&oo->oo_perclient, &clp->cl_openowners); in hash_openowner()
4523 struct nfs4_openowner *oo = open->op_openowner; in nfsd4_find_existing_open()
4525 lockdep_assert_held(&fp->fi_lock); in nfsd4_find_existing_open()
4527 list_for_each_entry(local, &fp->fi_stateids, st_perfile) { in nfsd4_find_existing_open()
4529 if (local->st_stateowner->so_is_open_owner == 0) in nfsd4_find_existing_open()
4531 if (local->st_stateowner != &oo->oo_owner) in nfsd4_find_existing_open()
4533 if (local->st_stid.sc_type == NFS4_OPEN_STID) { in nfsd4_find_existing_open()
4535 refcount_inc(&ret->st_stid.sc_count); in nfsd4_find_existing_open()
4547 switch (s->sc_type) { in nfsd4_verify_open_stid()
4567 mutex_lock_nested(&stp->st_mutex, LOCK_STATEID_MUTEX); in nfsd4_lock_ol_stateid()
4568 ret = nfsd4_verify_open_stid(&stp->st_stid); in nfsd4_lock_ol_stateid()
4570 mutex_unlock(&stp->st_mutex); in nfsd4_lock_ol_stateid()
4579 spin_lock(&fp->fi_lock); in nfsd4_find_and_lock_existing_open()
4581 spin_unlock(&fp->fi_lock); in nfsd4_find_and_lock_existing_open()
4584 nfs4_put_stid(&stp->st_stid); in nfsd4_find_and_lock_existing_open()
4593 struct nfs4_client *clp = cstate->clp; in alloc_init_open_stateowner()
4596 oo = alloc_stateowner(openowner_slab, &open->op_owner, clp); in alloc_init_open_stateowner()
4599 oo->oo_owner.so_ops = &openowner_ops; in alloc_init_open_stateowner()
4600 oo->oo_owner.so_is_open_owner = 1; in alloc_init_open_stateowner()
4601 oo->oo_owner.so_seqid = open->op_seqid; in alloc_init_open_stateowner()
4602 oo->oo_flags = 0; in alloc_init_open_stateowner()
4604 oo->oo_flags |= NFS4_OO_CONFIRMED; in alloc_init_open_stateowner()
4605 oo->oo_time = 0; in alloc_init_open_stateowner()
4606 oo->oo_last_closed_stid = NULL; in alloc_init_open_stateowner()
4607 INIT_LIST_HEAD(&oo->oo_close_lru); in alloc_init_open_stateowner()
4608 spin_lock(&clp->cl_lock); in alloc_init_open_stateowner()
4614 nfs4_free_stateowner(&oo->oo_owner); in alloc_init_open_stateowner()
4616 spin_unlock(&clp->cl_lock); in alloc_init_open_stateowner()
4624 struct nfs4_openowner *oo = open->op_openowner; in init_open_stateid()
4628 stp = open->op_stp; in init_open_stateid()
4630 mutex_init(&stp->st_mutex); in init_open_stateid()
4631 mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX); in init_open_stateid()
4634 spin_lock(&oo->oo_owner.so_client->cl_lock); in init_open_stateid()
4635 spin_lock(&fp->fi_lock); in init_open_stateid()
4641 open->op_stp = NULL; in init_open_stateid()
4642 refcount_inc(&stp->st_stid.sc_count); in init_open_stateid()
4643 stp->st_stid.sc_type = NFS4_OPEN_STID; in init_open_stateid()
4644 INIT_LIST_HEAD(&stp->st_locks); in init_open_stateid()
4645 stp->st_stateowner = nfs4_get_stateowner(&oo->oo_owner); in init_open_stateid()
4647 stp->st_stid.sc_file = fp; in init_open_stateid()
4648 stp->st_access_bmap = 0; in init_open_stateid()
4649 stp->st_deny_bmap = 0; in init_open_stateid()
4650 stp->st_openstp = NULL; in init_open_stateid()
4651 list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids); in init_open_stateid()
4652 list_add(&stp->st_perfile, &fp->fi_stateids); in init_open_stateid()
4655 spin_unlock(&fp->fi_lock); in init_open_stateid()
4656 spin_unlock(&oo->oo_owner.so_client->cl_lock); in init_open_stateid()
4660 nfs4_put_stid(&retstp->st_stid); in init_open_stateid()
4664 mutex_unlock(&stp->st_mutex); in init_open_stateid()
4679 struct nfs4_openowner *oo = openowner(s->st_stateowner); in move_to_close_lru()
4680 struct nfsd_net *nn = net_generic(s->st_stid.sc_client->net, in move_to_close_lru()
4694 wait_event(close_wq, refcount_read(&s->st_stid.sc_count) == 2); in move_to_close_lru()
4697 if (s->st_stid.sc_file) { in move_to_close_lru()
4698 put_nfs4_file(s->st_stid.sc_file); in move_to_close_lru()
4699 s->st_stid.sc_file = NULL; in move_to_close_lru()
4702 spin_lock(&nn->client_lock); in move_to_close_lru()
4703 last = oo->oo_last_closed_stid; in move_to_close_lru()
4704 oo->oo_last_closed_stid = s; in move_to_close_lru()
4705 list_move_tail(&oo->oo_close_lru, &nn->close_lru); in move_to_close_lru()
4706 oo->oo_time = ktime_get_boottime_seconds(); in move_to_close_lru()
4707 spin_unlock(&nn->client_lock); in move_to_close_lru()
4709 nfs4_put_stid(&last->st_stid); in move_to_close_lru()
4715 struct inode *inode = d_inode(fhp->fh_dentry); in nfsd4_file_hash_lookup()
4723 if (fh_match(&fi->fi_fhandle, &fhp->fh_handle)) { in nfsd4_file_hash_lookup()
4724 if (refcount_inc_not_zero(&fi->fi_ref)) { in nfsd4_file_hash_lookup()
4739 * inode->i_lock prevents racing insertions from adding an entry
4745 struct inode *inode = d_inode(fhp->fh_dentry); in nfsd4_file_hash_insert()
4753 spin_lock(&inode->i_lock); in nfsd4_file_hash_insert()
4758 if (fh_match(&fi->fi_fhandle, &fhp->fh_handle)) { in nfsd4_file_hash_insert()
4759 if (refcount_inc_not_zero(&fi->fi_ref)) in nfsd4_file_hash_insert()
4762 fi->fi_aliased = alias_found = true; in nfsd4_file_hash_insert()
4768 err = rhltable_insert(&nfs4_file_rhltable, &new->fi_rlist, in nfsd4_file_hash_insert()
4773 new->fi_aliased = alias_found; in nfsd4_file_hash_insert()
4777 spin_unlock(&inode->i_lock); in nfsd4_file_hash_insert()
4784 rhltable_remove(&nfs4_file_rhltable, &fi->fi_rlist, in nfsd4_file_hash_remove()
4803 spin_lock(&fp->fi_lock); in nfs4_share_conflict()
4804 if (fp->fi_share_deny & deny_type) in nfs4_share_conflict()
4806 spin_unlock(&fp->fi_lock); in nfs4_share_conflict()
4815 return ctx && !list_empty_careful(&ctx->flc_lease); in nfsd4_deleg_present()
4819 * nfsd_wait_for_delegreturn - wait for delegations to be returned
4821 * @inode: in-core inode of the file being waited for
4843 struct nfsd_net *nn = net_generic(dp->dl_stid.sc_client->net, in nfsd4_cb_recall_prepare()
4846 block_delegations(&dp->dl_stid.sc_file->fi_fhandle); in nfsd4_cb_recall_prepare()
4850 * already holding inode->i_lock. in nfsd4_cb_recall_prepare()
4856 if (delegation_hashed(dp) && dp->dl_time == 0) { in nfsd4_cb_recall_prepare()
4857 dp->dl_time = ktime_get_boottime_seconds(); in nfsd4_cb_recall_prepare()
4858 list_add_tail(&dp->dl_recall_lru, &nn->del_recall_lru); in nfsd4_cb_recall_prepare()
4868 trace_nfsd_cb_recall_done(&dp->dl_stid.sc_stateid, task); in nfsd4_cb_recall_done()
4870 if (dp->dl_stid.sc_type == NFS4_CLOSED_DELEG_STID || in nfsd4_cb_recall_done()
4871 dp->dl_stid.sc_type == NFS4_REVOKED_DELEG_STID) in nfsd4_cb_recall_done()
4874 switch (task->tk_status) { in nfsd4_cb_recall_done()
4877 case -NFS4ERR_DELAY: in nfsd4_cb_recall_done()
4880 case -EBADHANDLE: in nfsd4_cb_recall_done()
4881 case -NFS4ERR_BAD_STATEID: in nfsd4_cb_recall_done()
4886 if (dp->dl_retries--) { in nfsd4_cb_recall_done()
4900 nfs4_put_stid(&dp->dl_stid); in nfsd4_cb_recall_release()
4918 refcount_inc(&dp->dl_stid.sc_count); in nfsd_break_one_deleg()
4919 WARN_ON_ONCE(!nfsd4_run_cb(&dp->dl_recall)); in nfsd_break_one_deleg()
4926 struct nfs4_delegation *dp = (struct nfs4_delegation *)fl->fl_owner; in nfsd_break_deleg_cb()
4927 struct nfs4_file *fp = dp->dl_stid.sc_file; in nfsd_break_deleg_cb()
4928 struct nfs4_client *clp = dp->dl_stid.sc_client; in nfsd_break_deleg_cb()
4931 trace_nfsd_cb_recall(&dp->dl_stid); in nfsd_break_deleg_cb()
4933 dp->dl_recalled = true; in nfsd_break_deleg_cb()
4934 atomic_inc(&clp->cl_delegs_in_recall); in nfsd_break_deleg_cb()
4936 nn = net_generic(clp->net, nfsd_net_id); in nfsd_break_deleg_cb()
4937 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in nfsd_break_deleg_cb()
4945 fl->fl_break_time = 0; in nfsd_break_deleg_cb()
4947 fp->fi_had_conflict = true; in nfsd_break_deleg_cb()
4953 * nfsd_breaker_owns_lease - Check if lease conflict was resolved
4962 struct nfs4_delegation *dl = fl->fl_owner; in nfsd_breaker_owns_lease()
4970 if (rqst->rq_prog != NFS_PROGRAM || rqst->rq_vers < 4) in nfsd_breaker_owns_lease()
4972 clp = *(rqst->rq_lease_breaker); in nfsd_breaker_owns_lease()
4973 return dl->dl_stid.sc_client == clp; in nfsd_breaker_owns_lease()
4980 struct nfs4_delegation *dp = (struct nfs4_delegation *)onlist->fl_owner; in nfsd_change_deleg_cb()
4981 struct nfs4_client *clp = dp->dl_stid.sc_client; in nfsd_change_deleg_cb()
4984 if (dp->dl_recalled) in nfsd_change_deleg_cb()
4985 atomic_dec(&clp->cl_delegs_in_recall); in nfsd_change_deleg_cb()
4988 return -EAGAIN; in nfsd_change_deleg_cb()
5001 if (seqid == so->so_seqid - 1) in nfsd4_check_seqid()
5003 if (seqid == so->so_seqid) in nfsd4_check_seqid()
5013 spin_lock(&nn->client_lock); in lookup_clientid()
5016 atomic_inc(&found->cl_rpc_users); in lookup_clientid()
5017 spin_unlock(&nn->client_lock); in lookup_clientid()
5025 if (cstate->clp) { in set_client()
5026 if (!same_clid(&cstate->clp->cl_clientid, clid)) in set_client()
5034 * set cstate->clp), so session = false: in set_client()
5036 cstate->clp = lookup_clientid(clid, false, nn); in set_client()
5037 if (!cstate->clp) in set_client()
5046 clientid_t *clientid = &open->op_clientid; in nfsd4_process_open1()
5056 open->op_file = nfsd4_alloc_file(); in nfsd4_process_open1()
5057 if (open->op_file == NULL) in nfsd4_process_open1()
5063 clp = cstate->clp; in nfsd4_process_open1()
5065 strhashval = ownerstr_hashval(&open->op_owner); in nfsd4_process_open1()
5067 open->op_openowner = oo; in nfsd4_process_open1()
5071 if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { in nfsd4_process_open1()
5074 open->op_openowner = NULL; in nfsd4_process_open1()
5077 status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid); in nfsd4_process_open1()
5085 open->op_openowner = oo; in nfsd4_process_open1()
5087 open->op_stp = nfs4_alloc_open_stateid(clp); in nfsd4_process_open1()
5088 if (!open->op_stp) in nfsd4_process_open1()
5092 (cstate->current_fh.fh_export->ex_flags & NFSEXP_PNFS)) { in nfsd4_process_open1()
5093 open->op_odstate = alloc_clnt_odstate(clp); in nfsd4_process_open1()
5094 if (!open->op_odstate) in nfsd4_process_open1()
5104 if ((flags & WR_STATE) && (dp->dl_type == NFS4_OPEN_DELEGATE_READ)) in nfs4_check_delegmode()
5128 return open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR || in nfsd4_is_deleg_cur()
5129 open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH; in nfsd4_is_deleg_cur()
5140 deleg = find_deleg_stateid(cl, &open->op_delegate_stateid); in nfs4_check_deleg()
5143 if (deleg->dl_stid.sc_type == NFS4_REVOKED_DELEG_STID) { in nfs4_check_deleg()
5144 nfs4_put_stid(&deleg->dl_stid); in nfs4_check_deleg()
5145 if (cl->cl_minorversion) in nfs4_check_deleg()
5149 flags = share_access_to_flags(open->op_share_access); in nfs4_check_deleg()
5152 nfs4_put_stid(&deleg->dl_stid); in nfs4_check_deleg()
5161 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; in nfs4_check_deleg()
5187 if (!open->op_truncate) in nfsd4_truncate()
5189 if (!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) in nfsd4_truncate()
5200 int oflag = nfs4_access_to_omode(open->op_share_access); in nfs4_get_vfs_file()
5201 int access = nfs4_access_to_access(open->op_share_access); in nfs4_get_vfs_file()
5204 spin_lock(&fp->fi_lock); in nfs4_get_vfs_file()
5210 status = nfs4_file_check_deny(fp, open->op_share_deny); in nfs4_get_vfs_file()
5213 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5217 stp, open->op_share_deny, false)) in nfs4_get_vfs_file()
5219 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5224 status = nfs4_file_get_access(fp, open->op_share_access); in nfs4_get_vfs_file()
5227 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5231 stp, open->op_share_access, true)) in nfs4_get_vfs_file()
5233 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5238 old_access_bmap = stp->st_access_bmap; in nfs4_get_vfs_file()
5239 set_access(open->op_share_access, stp); in nfs4_get_vfs_file()
5242 old_deny_bmap = stp->st_deny_bmap; in nfs4_get_vfs_file()
5243 set_deny(open->op_share_deny, stp); in nfs4_get_vfs_file()
5244 fp->fi_share_deny |= (open->op_share_deny & NFS4_SHARE_DENY_BOTH); in nfs4_get_vfs_file()
5246 if (!fp->fi_fds[oflag]) { in nfs4_get_vfs_file()
5247 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5250 open->op_filp, &nf); in nfs4_get_vfs_file()
5254 spin_lock(&fp->fi_lock); in nfs4_get_vfs_file()
5255 if (!fp->fi_fds[oflag]) { in nfs4_get_vfs_file()
5256 fp->fi_fds[oflag] = nf; in nfs4_get_vfs_file()
5260 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5264 status = nfserrno(nfsd_open_break_lease(cur_fh->fh_dentry->d_inode, in nfs4_get_vfs_file()
5275 stp->st_access_bmap = old_access_bmap; in nfs4_get_vfs_file()
5276 nfs4_file_put_access(fp, open->op_share_access); in nfs4_get_vfs_file()
5287 unsigned char old_deny_bmap = stp->st_deny_bmap; in nfs4_upgrade_open()
5289 if (!test_access(open->op_share_access, stp)) in nfs4_upgrade_open()
5293 spin_lock(&fp->fi_lock); in nfs4_upgrade_open()
5294 status = nfs4_file_check_deny(fp, open->op_share_deny); in nfs4_upgrade_open()
5297 set_deny(open->op_share_deny, stp); in nfs4_upgrade_open()
5298 fp->fi_share_deny |= in nfs4_upgrade_open()
5299 (open->op_share_deny & NFS4_SHARE_DENY_BOTH); in nfs4_upgrade_open()
5303 stp, open->op_share_deny, false)) in nfs4_upgrade_open()
5307 spin_unlock(&fp->fi_lock); in nfs4_upgrade_open()
5321 if (clp->cl_cb_state == NFSD4_CB_UP) in nfsd4_cb_channel_good()
5328 return clp->cl_minorversion && clp->cl_cb_state == NFSD4_CB_UNKNOWN; in nfsd4_cb_channel_good()
5339 fl->fl_lmops = &nfsd_lease_mng_ops; in nfs4_alloc_init_lease()
5340 fl->fl_flags = FL_DELEG; in nfs4_alloc_init_lease()
5341 fl->fl_type = flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK; in nfs4_alloc_init_lease()
5342 fl->fl_end = OFFSET_MAX; in nfs4_alloc_init_lease()
5343 fl->fl_owner = (fl_owner_t)dp; in nfs4_alloc_init_lease()
5344 fl->fl_pid = current->tgid; in nfs4_alloc_init_lease()
5345 fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file; in nfs4_alloc_init_lease()
5353 struct file *f = fp->fi_deleg_file->nf_file; in nfsd4_check_conflicting_opens()
5357 writes = atomic_read(&ino->i_writecount); in nfsd4_check_conflicting_opens()
5367 if (fp->fi_aliased) in nfsd4_check_conflicting_opens()
5368 return -EAGAIN; in nfsd4_check_conflicting_opens()
5376 if (fp->fi_fds[O_WRONLY]) in nfsd4_check_conflicting_opens()
5377 writes--; in nfsd4_check_conflicting_opens()
5378 if (fp->fi_fds[O_RDWR]) in nfsd4_check_conflicting_opens()
5379 writes--; in nfsd4_check_conflicting_opens()
5381 return -EAGAIN; /* There may be non-NFSv4 writers */ in nfsd4_check_conflicting_opens()
5383 * It's possible there are non-NFSv4 write opens in progress, in nfsd4_check_conflicting_opens()
5389 spin_lock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5390 list_for_each_entry(st, &fp->fi_stateids, st_perfile) { in nfsd4_check_conflicting_opens()
5391 if (st->st_openstp == NULL /* it's an open */ && in nfsd4_check_conflicting_opens()
5393 st->st_stid.sc_client != clp) { in nfsd4_check_conflicting_opens()
5394 spin_unlock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5395 return -EAGAIN; in nfsd4_check_conflicting_opens()
5398 spin_unlock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5421 err = nfsd_lookup_dentry(open->op_rqstp, parent, in nfsd4_verify_deleg_dentry()
5422 open->op_fname, open->op_fnamelen, in nfsd4_verify_deleg_dentry()
5426 return -EAGAIN; in nfsd4_verify_deleg_dentry()
5430 if (child != file_dentry(fp->fi_deleg_file->nf_file)) in nfsd4_verify_deleg_dentry()
5431 return -EAGAIN; in nfsd4_verify_deleg_dentry()
5445 struct inode *inode = file_inode(nf->nf_file); in nfsd4_verify_setuid_write()
5447 if ((open->op_share_access & NFS4_SHARE_ACCESS_WRITE) && in nfsd4_verify_setuid_write()
5448 (inode->i_mode & (S_ISUID|S_ISGID))) in nfsd4_verify_setuid_write()
5449 return -EAGAIN; in nfsd4_verify_setuid_write()
5458 struct nfs4_client *clp = stp->st_stid.sc_client; in nfs4_set_delegation()
5459 struct nfs4_file *fp = stp->st_stid.sc_file; in nfs4_set_delegation()
5460 struct nfs4_clnt_odstate *odstate = stp->st_clnt_odstate; in nfs4_set_delegation()
5471 if (fp->fi_had_conflict) in nfs4_set_delegation()
5472 return ERR_PTR(-EAGAIN); in nfs4_set_delegation()
5486 if ((open->op_share_access & NFS4_SHARE_ACCESS_BOTH) == NFS4_SHARE_ACCESS_BOTH) { in nfs4_set_delegation()
5495 if (!nf && (open->op_share_access & NFS4_SHARE_ACCESS_READ)) { in nfs4_set_delegation()
5501 return ERR_PTR(-EAGAIN); in nfs4_set_delegation()
5504 spin_lock(&fp->fi_lock); in nfs4_set_delegation()
5506 status = -EAGAIN; in nfs4_set_delegation()
5508 status = -EAGAIN; in nfs4_set_delegation()
5509 else if (!fp->fi_deleg_file) { in nfs4_set_delegation()
5510 fp->fi_deleg_file = nf; in nfs4_set_delegation()
5513 fp->fi_delegees = 1; in nfs4_set_delegation()
5516 fp->fi_delegees++; in nfs4_set_delegation()
5517 spin_unlock(&fp->fi_lock); in nfs4_set_delegation()
5524 status = -ENOMEM; in nfs4_set_delegation()
5533 status = vfs_setlease(fp->fi_deleg_file->nf_file, fl->fl_type, &fl, NULL); in nfs4_set_delegation()
5553 status = nfsd4_verify_setuid_write(open, fp->fi_deleg_file); in nfs4_set_delegation()
5557 status = -EAGAIN; in nfs4_set_delegation()
5558 if (fp->fi_had_conflict) in nfs4_set_delegation()
5562 spin_lock(&fp->fi_lock); in nfs4_set_delegation()
5564 spin_unlock(&fp->fi_lock); in nfs4_set_delegation()
5572 vfs_setlease(fp->fi_deleg_file->nf_file, F_UNLCK, NULL, (void **)&dp); in nfs4_set_delegation()
5574 put_clnt_odstate(dp->dl_clnt_odstate); in nfs4_set_delegation()
5575 nfs4_put_stid(&dp->dl_stid); in nfs4_set_delegation()
5583 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_open_deleg_none_ext()
5584 if (status == -EAGAIN) in nfsd4_open_deleg_none_ext()
5585 open->op_why_no_deleg = WND4_CONTENTION; in nfsd4_open_deleg_none_ext()
5587 open->op_why_no_deleg = WND4_RESOURCE; in nfsd4_open_deleg_none_ext()
5588 switch (open->op_deleg_want) { in nfsd4_open_deleg_none_ext()
5594 open->op_why_no_deleg = WND4_CANCELLED; in nfsd4_open_deleg_none_ext()
5631 struct nfs4_openowner *oo = openowner(stp->st_stateowner); in nfs4_open_delegation()
5632 struct nfs4_client *clp = stp->st_stid.sc_client; in nfs4_open_delegation()
5637 cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client); in nfs4_open_delegation()
5638 open->op_recall = 0; in nfs4_open_delegation()
5639 switch (open->op_claim_type) { in nfs4_open_delegation()
5642 open->op_recall = 1; in nfs4_open_delegation()
5653 if (locks_in_grace(clp->net)) in nfs4_open_delegation()
5655 if (!cb_up || !(oo->oo_flags & NFS4_OO_CONFIRMED)) in nfs4_open_delegation()
5657 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE && in nfs4_open_delegation()
5658 !clp->cl_minorversion) in nfs4_open_delegation()
5668 memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid)); in nfs4_open_delegation()
5670 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) { in nfs4_open_delegation()
5671 open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE; in nfs4_open_delegation()
5672 trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); in nfs4_open_delegation()
5674 open->op_delegate_type = NFS4_OPEN_DELEGATE_READ; in nfs4_open_delegation()
5675 trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid); in nfs4_open_delegation()
5677 nfs4_put_stid(&dp->dl_stid); in nfs4_open_delegation()
5680 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE; in nfs4_open_delegation()
5681 if (open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS && in nfs4_open_delegation()
5682 open->op_delegate_type != NFS4_OPEN_DELEGATE_NONE) { in nfs4_open_delegation()
5684 open->op_recall = 1; in nfs4_open_delegation()
5688 if (open->op_deleg_want) in nfs4_open_delegation()
5696 if (open->op_deleg_want == NFS4_SHARE_WANT_READ_DELEG && in nfsd4_deleg_xgrade_none_ext()
5697 dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) { in nfsd4_deleg_xgrade_none_ext()
5698 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_deleg_xgrade_none_ext()
5699 open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE; in nfsd4_deleg_xgrade_none_ext()
5700 } else if (open->op_deleg_want == NFS4_SHARE_WANT_WRITE_DELEG && in nfsd4_deleg_xgrade_none_ext()
5701 dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) { in nfsd4_deleg_xgrade_none_ext()
5702 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_deleg_xgrade_none_ext()
5703 open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE; in nfsd4_deleg_xgrade_none_ext()
5712 * nfsd4_process_open2 - finish open processing
5717 * If successful, (1) truncate the file if open->op_truncate was
5718 * set, (2) set open->op_stateid, (3) set open->op_delegation.
5726 struct nfsd4_compoundres *resp = rqstp->rq_resp; in nfsd4_process_open2()
5727 struct nfs4_client *cl = open->op_openowner->oo_owner.so_client; in nfsd4_process_open2()
5739 fp = nfsd4_file_hash_insert(open->op_file, current_fh); in nfsd4_process_open2()
5742 if (fp != open->op_file) { in nfsd4_process_open2()
5748 open->op_file = NULL; in nfsd4_process_open2()
5756 if (!open->op_stp) in nfsd4_process_open2()
5770 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5776 stp->st_stid.sc_type = NFS4_CLOSED_STID; in nfsd4_process_open2()
5778 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5782 stp->st_clnt_odstate = find_or_hash_clnt_odstate(fp, in nfsd4_process_open2()
5783 open->op_odstate); in nfsd4_process_open2()
5784 if (stp->st_clnt_odstate == open->op_odstate) in nfsd4_process_open2()
5785 open->op_odstate = NULL; in nfsd4_process_open2()
5788 nfs4_inc_and_copy_stateid(&open->op_stateid, &stp->st_stid); in nfsd4_process_open2()
5789 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5791 if (nfsd4_has_session(&resp->cstate)) { in nfsd4_process_open2()
5792 if (open->op_deleg_want & NFS4_SHARE_WANT_NO_DELEG) { in nfsd4_process_open2()
5793 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_process_open2()
5794 open->op_why_no_deleg = WND4_NOT_WANTED; in nfsd4_process_open2()
5803 nfs4_open_delegation(open, stp, &resp->cstate.current_fh); in nfsd4_process_open2()
5806 trace_nfsd_open(&stp->st_stid.sc_stateid); in nfsd4_process_open2()
5809 if (open->op_delegate_type == NFS4_OPEN_DELEGATE_NONE && dp && in nfsd4_process_open2()
5810 open->op_deleg_want) in nfsd4_process_open2()
5815 if (status == 0 && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) in nfsd4_process_open2()
5816 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; in nfsd4_process_open2()
5820 open->op_rflags = NFS4_OPEN_RESULT_LOCKTYPE_POSIX; in nfsd4_process_open2()
5821 if (nfsd4_has_session(&resp->cstate)) in nfsd4_process_open2()
5822 open->op_rflags |= NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK; in nfsd4_process_open2()
5823 else if (!(open->op_openowner->oo_flags & NFS4_OO_CONFIRMED)) in nfsd4_process_open2()
5824 open->op_rflags |= NFS4_OPEN_RESULT_CONFIRM; in nfsd4_process_open2()
5827 nfs4_put_stid(&dp->dl_stid); in nfsd4_process_open2()
5829 nfs4_put_stid(&stp->st_stid); in nfsd4_process_open2()
5837 if (open->op_openowner) { in nfsd4_cleanup_open_state()
5838 struct nfs4_stateowner *so = &open->op_openowner->oo_owner; in nfsd4_cleanup_open_state()
5843 if (open->op_file) in nfsd4_cleanup_open_state()
5844 kmem_cache_free(file_slab, open->op_file); in nfsd4_cleanup_open_state()
5845 if (open->op_stp) in nfsd4_cleanup_open_state()
5846 nfs4_put_stid(&open->op_stp->st_stid); in nfsd4_cleanup_open_state()
5847 if (open->op_odstate) in nfsd4_cleanup_open_state()
5848 kmem_cache_free(odstate_slab, open->op_odstate); in nfsd4_cleanup_open_state()
5855 clientid_t *clid = &u->renew; in nfsd4_renew()
5864 clp = cstate->clp; in nfsd4_renew()
5865 if (!list_empty(&clp->cl_delegations) in nfsd4_renew()
5866 && clp->cl_cb_state != NFSD4_CB_UP) in nfsd4_renew()
5875 if (nn->grace_ended) in nfsd4_end_grace()
5879 nn->grace_ended = true; in nfsd4_end_grace()
5896 locks_end_grace(&nn->nfsd4_manager); in nfsd4_end_grace()
5910 time64_t double_grace_period_end = nn->boot_time + in clients_still_reclaiming()
5911 2 * nn->nfsd4_lease; in clients_still_reclaiming()
5913 if (nn->track_reclaim_completes && in clients_still_reclaiming()
5914 atomic_read(&nn->nr_reclaim_complete) == in clients_still_reclaiming()
5915 nn->reclaim_str_hashtbl_size) in clients_still_reclaiming()
5917 if (!nn->somebody_reclaimed) in clients_still_reclaiming()
5919 nn->somebody_reclaimed = false; in clients_still_reclaiming()
5938 if (last_refresh < lt->cutoff) in state_expired()
5940 time_remaining = last_refresh - lt->cutoff; in state_expired()
5941 lt->new_timeo = min(lt->new_timeo, time_remaining); in state_expired()
5948 spin_lock_init(&nn->nfsd_ssc_lock); in nfsd4_ssc_init_umount_work()
5949 INIT_LIST_HEAD(&nn->nfsd_ssc_mount_list); in nfsd4_ssc_init_umount_work()
5950 init_waitqueue_head(&nn->nfsd_ssc_waitq); in nfsd4_ssc_init_umount_work()
5963 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5964 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { in nfsd4_ssc_shutdown_umount()
5965 list_del(&ni->nsui_list); in nfsd4_ssc_shutdown_umount()
5966 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5967 mntput(ni->nsui_vfsmount); in nfsd4_ssc_shutdown_umount()
5969 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5971 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5980 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
5981 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { in nfsd4_ssc_expire_umount()
5982 if (time_after(jiffies, ni->nsui_expire)) { in nfsd4_ssc_expire_umount()
5983 if (refcount_read(&ni->nsui_refcnt) > 1) in nfsd4_ssc_expire_umount()
5987 ni->nsui_busy = true; in nfsd4_ssc_expire_umount()
5988 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
5989 mntput(ni->nsui_vfsmount); in nfsd4_ssc_expire_umount()
5990 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
5993 list_del(&ni->nsui_list); in nfsd4_ssc_expire_umount()
6003 wake_up_all(&nn->nfsd_ssc_waitq); in nfsd4_ssc_expire_umount()
6004 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
6016 list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) { in nfs4_lockowner_has_blockers()
6017 nf = stp->st_stid.sc_file; in nfs4_lockowner_has_blockers()
6018 ctx = locks_inode_context(nf->fi_inode); in nfs4_lockowner_has_blockers()
6034 if (atomic_read(&clp->cl_delegs_in_recall)) in nfs4_anylock_blockers()
6036 spin_lock(&clp->cl_lock); in nfs4_anylock_blockers()
6038 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[i], in nfs4_anylock_blockers()
6040 if (so->so_is_open_owner) in nfs4_anylock_blockers()
6044 spin_unlock(&clp->cl_lock); in nfs4_anylock_blockers()
6049 spin_unlock(&clp->cl_lock); in nfs4_anylock_blockers()
6061 maxreap = (atomic_read(&nn->nfs4_client_count) >= nn->nfs4_max_clients) ? in nfs4_get_client_reaplist()
6064 spin_lock(&nn->client_lock); in nfs4_get_client_reaplist()
6065 list_for_each_safe(pos, next, &nn->client_lru) { in nfs4_get_client_reaplist()
6067 if (clp->cl_state == NFSD4_EXPIRABLE) in nfs4_get_client_reaplist()
6069 if (!state_expired(lt, clp->cl_time)) in nfs4_get_client_reaplist()
6071 if (!atomic_read(&clp->cl_rpc_users)) { in nfs4_get_client_reaplist()
6072 if (clp->cl_state == NFSD4_ACTIVE) in nfs4_get_client_reaplist()
6073 atomic_inc(&nn->nfsd_courtesy_clients); in nfs4_get_client_reaplist()
6074 clp->cl_state = NFSD4_COURTESY; in nfs4_get_client_reaplist()
6083 list_add(&clp->cl_lru, reaplist); in nfs4_get_client_reaplist()
6087 spin_unlock(&nn->client_lock); in nfs4_get_client_reaplist()
6101 spin_lock(&nn->client_lock); in nfs4_get_courtesy_client_reaplist()
6102 list_for_each_safe(pos, next, &nn->client_lru) { in nfs4_get_courtesy_client_reaplist()
6104 if (clp->cl_state == NFSD4_ACTIVE) in nfs4_get_courtesy_client_reaplist()
6109 list_add(&clp->cl_lru, reaplist); in nfs4_get_courtesy_client_reaplist()
6113 spin_unlock(&nn->client_lock); in nfs4_get_courtesy_client_reaplist()
6124 trace_nfsd_clid_purged(&clp->cl_clientid); in nfs4_process_client_reaplist()
6125 list_del_init(&clp->cl_lru); in nfs4_process_client_reaplist()
6139 .cutoff = ktime_get_boottime_seconds() - nn->nfsd4_lease, in nfs4_laundromat()
6140 .new_timeo = nn->nfsd4_lease in nfs4_laundromat()
6152 spin_lock(&nn->s2s_cp_lock); in nfs4_laundromat()
6153 idr_for_each_entry(&nn->s2s_cp_stateids, cps_t, i) { in nfs4_laundromat()
6155 if (cps->cp_stateid.cs_type == NFS4_COPYNOTIFY_STID && in nfs4_laundromat()
6156 state_expired(<, cps->cpntf_time)) in nfs4_laundromat()
6159 spin_unlock(&nn->s2s_cp_lock); in nfs4_laundromat()
6164 list_for_each_safe(pos, next, &nn->del_recall_lru) { in nfs4_laundromat()
6166 if (!state_expired(<, dp->dl_time)) in nfs4_laundromat()
6169 list_add(&dp->dl_recall_lru, &reaplist); in nfs4_laundromat()
6175 list_del_init(&dp->dl_recall_lru); in nfs4_laundromat()
6179 spin_lock(&nn->client_lock); in nfs4_laundromat()
6180 while (!list_empty(&nn->close_lru)) { in nfs4_laundromat()
6181 oo = list_first_entry(&nn->close_lru, struct nfs4_openowner, in nfs4_laundromat()
6183 if (!state_expired(<, oo->oo_time)) in nfs4_laundromat()
6185 list_del_init(&oo->oo_close_lru); in nfs4_laundromat()
6186 stp = oo->oo_last_closed_stid; in nfs4_laundromat()
6187 oo->oo_last_closed_stid = NULL; in nfs4_laundromat()
6188 spin_unlock(&nn->client_lock); in nfs4_laundromat()
6189 nfs4_put_stid(&stp->st_stid); in nfs4_laundromat()
6190 spin_lock(&nn->client_lock); in nfs4_laundromat()
6192 spin_unlock(&nn->client_lock); in nfs4_laundromat()
6197 * So, we clean out any un-revisited request after a lease period in nfs4_laundromat()
6206 spin_lock(&nn->blocked_locks_lock); in nfs4_laundromat()
6207 while (!list_empty(&nn->blocked_locks_lru)) { in nfs4_laundromat()
6208 nbl = list_first_entry(&nn->blocked_locks_lru, in nfs4_laundromat()
6210 if (!state_expired(<, nbl->nbl_time)) in nfs4_laundromat()
6212 list_move(&nbl->nbl_lru, &reaplist); in nfs4_laundromat()
6213 list_del_init(&nbl->nbl_list); in nfs4_laundromat()
6215 spin_unlock(&nn->blocked_locks_lock); in nfs4_laundromat()
6220 list_del_init(&nbl->nbl_lru); in nfs4_laundromat()
6224 /* service the server-to-server copy delayed unmount list */ in nfs4_laundromat()
6242 queue_delayed_work(laundry_wq, &nn->laundromat_work, t*HZ); in laundromat_main()
6262 spin_lock(&nn->client_lock); in deleg_reaper()
6263 list_for_each_safe(pos, next, &nn->client_lru) { in deleg_reaper()
6265 if (clp->cl_state != NFSD4_ACTIVE || in deleg_reaper()
6266 list_empty(&clp->cl_delegations) || in deleg_reaper()
6267 atomic_read(&clp->cl_delegs_in_recall) || in deleg_reaper()
6268 test_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags) || in deleg_reaper()
6269 (ktime_get_boottime_seconds() - in deleg_reaper()
6270 clp->cl_ra_time < 5)) { in deleg_reaper()
6273 list_add(&clp->cl_ra_cblist, &cblist); in deleg_reaper()
6276 atomic_inc(&clp->cl_rpc_users); in deleg_reaper()
6277 set_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags); in deleg_reaper()
6278 clp->cl_ra_time = ktime_get_boottime_seconds(); in deleg_reaper()
6280 spin_unlock(&nn->client_lock); in deleg_reaper()
6285 list_del_init(&clp->cl_ra_cblist); in deleg_reaper()
6286 clp->cl_ra->ra_keep = 0; in deleg_reaper()
6287 clp->cl_ra->ra_bmval[0] = BIT(RCA4_TYPE_MASK_RDATA_DLG); in deleg_reaper()
6288 trace_nfsd_cb_recall_any(clp->cl_ra); in deleg_reaper()
6289 nfsd4_run_cb(&clp->cl_ra->ra_cb); in deleg_reaper()
6305 if (!fh_match(&fhp->fh_handle, &stp->sc_file->fi_fhandle)) in nfs4_check_fh()
6316 if (stp->st_openstp) in nfs4_check_openmode()
6317 stp = stp->st_openstp; in nfs4_check_openmode()
6350 if (has_session && in->si_generation == 0) in check_stateid_generation()
6353 if (in->si_generation == ref->si_generation) in check_stateid_generation()
6361 * non-buggy client. For example, if the client sends a lock in check_stateid_generation()
6376 spin_lock(&s->sc_lock); in nfsd4_stid_check_stateid_generation()
6379 ret = check_stateid_generation(in, &s->sc_stateid, has_session); in nfsd4_stid_check_stateid_generation()
6380 spin_unlock(&s->sc_lock); in nfsd4_stid_check_stateid_generation()
6386 if (ols->st_stateowner->so_is_open_owner && in nfsd4_check_openowner_confirmed()
6387 !(openowner(ols->st_stateowner)->oo_flags & NFS4_OO_CONFIRMED)) in nfsd4_check_openowner_confirmed()
6400 spin_lock(&cl->cl_lock); in nfsd4_validate_stateid()
6407 switch (s->sc_type) { in nfsd4_validate_stateid()
6419 printk("unknown stateid type %x\n", s->sc_type); in nfsd4_validate_stateid()
6426 spin_unlock(&cl->cl_lock); in nfsd4_validate_stateid()
6451 status = set_client(&stateid->si_opaque.so_clid, cstate, nn); in nfsd4_lookup_stateid()
6453 if (cstate->session) in nfsd4_lookup_stateid()
6459 stid = find_stateid_by_type(cstate->clp, stateid, typemask); in nfsd4_lookup_stateid()
6462 if ((stid->sc_type == NFS4_REVOKED_DELEG_STID) && !return_revoked) { in nfsd4_lookup_stateid()
6464 if (cstate->minorversion) in nfsd4_lookup_stateid()
6480 switch (s->sc_type) { in nfs4_find_file()
6482 spin_lock(&s->sc_file->fi_lock); in nfs4_find_file()
6483 ret = nfsd_file_get(s->sc_file->fi_deleg_file); in nfs4_find_file()
6484 spin_unlock(&s->sc_file->fi_lock); in nfs4_find_file()
6489 ret = find_readable_file(s->sc_file); in nfs4_find_file()
6491 ret = find_writeable_file(s->sc_file); in nfs4_find_file()
6518 status = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry, in nfs4_check_file()
6536 WARN_ON_ONCE(cps->cp_stateid.cs_type != NFS4_COPYNOTIFY_STID); in _free_cpntf_state_locked()
6537 if (!refcount_dec_and_test(&cps->cp_stateid.cs_count)) in _free_cpntf_state_locked()
6539 list_del(&cps->cp_list); in _free_cpntf_state_locked()
6540 idr_remove(&nn->s2s_cp_stateids, in _free_cpntf_state_locked()
6541 cps->cp_stateid.cs_stid.si_opaque.so_id); in _free_cpntf_state_locked()
6556 if (st->si_opaque.so_clid.cl_id != nn->s2s_cp_cl_id) in manage_cpntf_state()
6558 spin_lock(&nn->s2s_cp_lock); in manage_cpntf_state()
6559 cps_t = idr_find(&nn->s2s_cp_stateids, st->si_opaque.so_id); in manage_cpntf_state()
6563 if (state->cp_stateid.cs_type != NFS4_COPYNOTIFY_STID) { in manage_cpntf_state()
6568 refcount_inc(&state->cp_stateid.cs_count); in manage_cpntf_state()
6573 spin_unlock(&nn->s2s_cp_lock); in manage_cpntf_state()
6592 cps->cpntf_time = ktime_get_boottime_seconds(); in find_cpntf_state()
6595 found = lookup_clientid(&cps->cp_p_clid, true, nn); in find_cpntf_state()
6599 *stid = find_stateid_by_type(found, &cps->cp_p_stateid, in find_cpntf_state()
6614 spin_lock(&nn->s2s_cp_lock); in nfs4_put_cpntf_state()
6616 spin_unlock(&nn->s2s_cp_lock); in nfs4_put_cpntf_state()
6620 * nfs4_preprocess_stateid_op - find and prep stateid for an operation
6668 switch (s->sc_type) { in nfs4_preprocess_stateid_op()
6704 struct nfsd4_test_stateid *test_stateid = &u->test_stateid; in nfsd4_test_stateid()
6706 struct nfs4_client *cl = cstate->clp; in nfsd4_test_stateid()
6708 list_for_each_entry(stateid, &test_stateid->ts_stateid_list, ts_id_list) in nfsd4_test_stateid()
6709 stateid->ts_id_status = in nfsd4_test_stateid()
6710 nfsd4_validate_stateid(cl, &stateid->ts_id_stateid); in nfsd4_test_stateid()
6725 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); in nfsd4_free_lock_stateid()
6730 if (check_for_locks(stp->st_stid.sc_file, in nfsd4_free_lock_stateid()
6731 lockowner(stp->st_stateowner))) in nfsd4_free_lock_stateid()
6738 mutex_unlock(&stp->st_mutex); in nfsd4_free_lock_stateid()
6748 struct nfsd4_free_stateid *free_stateid = &u->free_stateid; in nfsd4_free_stateid()
6749 stateid_t *stateid = &free_stateid->fr_stateid; in nfsd4_free_stateid()
6752 struct nfs4_client *cl = cstate->clp; in nfsd4_free_stateid()
6755 spin_lock(&cl->cl_lock); in nfsd4_free_stateid()
6759 spin_lock(&s->sc_lock); in nfsd4_free_stateid()
6760 switch (s->sc_type) { in nfsd4_free_stateid()
6765 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); in nfsd4_free_stateid()
6771 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6772 refcount_inc(&s->sc_count); in nfsd4_free_stateid()
6773 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6777 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6779 list_del_init(&dp->dl_recall_lru); in nfsd4_free_stateid()
6780 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6786 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6788 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6802 struct svc_fh *current_fh = &cstate->current_fh; in nfs4_seqid_op_checks()
6803 struct nfs4_stateowner *sop = stp->st_stateowner; in nfs4_seqid_op_checks()
6812 status = check_stateid_generation(stateid, &stp->st_stid.sc_stateid, nfsd4_has_session(cstate)); in nfs4_seqid_op_checks()
6814 status = nfs4_check_fh(current_fh, &stp->st_stid); in nfs4_seqid_op_checks()
6816 mutex_unlock(&stp->st_mutex); in nfs4_seqid_op_checks()
6821 * nfs4_preprocess_seqid_op - find and prep an ol_stateid for a seqid-morphing op
6850 nfsd4_cstate_assign_replay(cstate, stp->st_stateowner); in nfs4_preprocess_seqid_op()
6856 nfs4_put_stid(&stp->st_stid); in nfs4_preprocess_seqid_op()
6871 oo = openowner(stp->st_stateowner); in nfs4_preprocess_confirmed_seqid_op()
6872 if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { in nfs4_preprocess_confirmed_seqid_op()
6873 mutex_unlock(&stp->st_mutex); in nfs4_preprocess_confirmed_seqid_op()
6874 nfs4_put_stid(&stp->st_stid); in nfs4_preprocess_confirmed_seqid_op()
6885 struct nfsd4_open_confirm *oc = &u->open_confirm; in nfsd4_open_confirm()
6892 cstate->current_fh.fh_dentry); in nfsd4_open_confirm()
6894 status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0); in nfsd4_open_confirm()
6899 oc->oc_seqid, &oc->oc_req_stateid, in nfsd4_open_confirm()
6903 oo = openowner(stp->st_stateowner); in nfsd4_open_confirm()
6905 if (oo->oo_flags & NFS4_OO_CONFIRMED) { in nfsd4_open_confirm()
6906 mutex_unlock(&stp->st_mutex); in nfsd4_open_confirm()
6909 oo->oo_flags |= NFS4_OO_CONFIRMED; in nfsd4_open_confirm()
6910 nfs4_inc_and_copy_stateid(&oc->oc_resp_stateid, &stp->st_stid); in nfsd4_open_confirm()
6911 mutex_unlock(&stp->st_mutex); in nfsd4_open_confirm()
6912 trace_nfsd_open_confirm(oc->oc_seqid, &stp->st_stid.sc_stateid); in nfsd4_open_confirm()
6913 nfsd4_client_record_create(oo->oo_owner.so_client); in nfsd4_open_confirm()
6916 nfs4_put_stid(&stp->st_stid); in nfsd4_open_confirm()
6926 nfs4_file_put_access(stp->st_stid.sc_file, access); in nfs4_stateid_downgrade_bit()
6952 struct nfsd4_open_downgrade *od = &u->open_downgrade; in nfsd4_open_downgrade()
6958 cstate->current_fh.fh_dentry); in nfsd4_open_downgrade()
6961 if (od->od_deleg_want) in nfsd4_open_downgrade()
6963 od->od_deleg_want); in nfsd4_open_downgrade()
6965 status = nfs4_preprocess_confirmed_seqid_op(cstate, od->od_seqid, in nfsd4_open_downgrade()
6966 &od->od_stateid, &stp, nn); in nfsd4_open_downgrade()
6970 if (!test_access(od->od_share_access, stp)) { in nfsd4_open_downgrade()
6972 stp->st_access_bmap, od->od_share_access); in nfsd4_open_downgrade()
6975 if (!test_deny(od->od_share_deny, stp)) { in nfsd4_open_downgrade()
6977 stp->st_deny_bmap, od->od_share_deny); in nfsd4_open_downgrade()
6980 nfs4_stateid_downgrade(stp, od->od_share_access); in nfsd4_open_downgrade()
6981 reset_union_bmap_deny(od->od_share_deny, stp); in nfsd4_open_downgrade()
6982 nfs4_inc_and_copy_stateid(&od->od_stateid, &stp->st_stid); in nfsd4_open_downgrade()
6985 mutex_unlock(&stp->st_mutex); in nfsd4_open_downgrade()
6986 nfs4_put_stid(&stp->st_stid); in nfsd4_open_downgrade()
6994 struct nfs4_client *clp = s->st_stid.sc_client; in nfsd4_close_open_stateid()
6999 spin_lock(&clp->cl_lock); in nfsd4_close_open_stateid()
7002 if (clp->cl_minorversion) { in nfsd4_close_open_stateid()
7005 spin_unlock(&clp->cl_lock); in nfsd4_close_open_stateid()
7007 nfs4_free_cpntf_statelist(clp->net, &stp->st_stid); in nfsd4_close_open_stateid()
7010 spin_unlock(&clp->cl_lock); in nfsd4_close_open_stateid()
7013 move_to_close_lru(s, clp->net); in nfsd4_close_open_stateid()
7024 struct nfsd4_close *close = &u->close; in nfsd4_close()
7031 cstate->current_fh.fh_dentry); in nfsd4_close()
7033 status = nfs4_preprocess_seqid_op(cstate, close->cl_seqid, in nfsd4_close()
7034 &close->cl_stateid, in nfsd4_close()
7041 stp->st_stid.sc_type = NFS4_CLOSED_STID; in nfsd4_close()
7049 nfs4_inc_and_copy_stateid(&close->cl_stateid, &stp->st_stid); in nfsd4_close()
7052 mutex_unlock(&stp->st_mutex); in nfsd4_close()
7061 memcpy(&close->cl_stateid, &close_stateid, sizeof(close->cl_stateid)); in nfsd4_close()
7064 nfs4_put_stid(&stp->st_stid); in nfsd4_close()
7073 struct nfsd4_delegreturn *dr = &u->delegreturn; in nfsd4_delegreturn()
7075 stateid_t *stateid = &dr->dr_stateid; in nfsd4_delegreturn()
7080 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) in nfsd4_delegreturn()
7087 status = nfsd4_stid_check_stateid_generation(stateid, &dp->dl_stid, nfsd4_has_session(cstate)); in nfsd4_delegreturn()
7092 wake_up_var(d_inode(cstate->current_fh.fh_dentry)); in nfsd4_delegreturn()
7095 nfs4_put_stid(&dp->dl_stid); in nfsd4_delegreturn()
7108 return end > start ? end - 1: NFS4_MAX_UINT64; in last_byte_offset()
7112 * TODO: Linux file offsets are _signed_ 64-bit quantities, which means that
7113 * we can't properly handle lock requests that go beyond the (2^63 - 1)-th
7114 * byte, because of sign extension problems. Since NFSv4 calls for 64-bit
7115 * locking, this prevents us from being completely protocol-compliant. The
7122 if (lock->fl_start < 0) in nfs4_transform_lock_offset()
7123 lock->fl_start = OFFSET_MAX; in nfs4_transform_lock_offset()
7124 if (lock->fl_end < 0) in nfs4_transform_lock_offset()
7125 lock->fl_end = OFFSET_MAX; in nfs4_transform_lock_offset()
7133 nfs4_get_stateowner(&lo->lo_owner); in nfsd4_lm_get_owner()
7143 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_lm_put_owner()
7150 struct nfs4_lockowner *lo = (struct nfs4_lockowner *)cfl->fl_owner; in nfsd4_lm_lock_expirable()
7151 struct nfs4_client *clp = lo->lo_owner.so_client; in nfsd4_lm_lock_expirable()
7155 nn = net_generic(clp->net, nfsd_net_id); in nfsd4_lm_lock_expirable()
7156 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in nfsd4_lm_lock_expirable()
7172 struct nfs4_lockowner *lo = (struct nfs4_lockowner *)fl->fl_owner; in nfsd4_lm_notify()
7173 struct net *net = lo->lo_owner.so_client->net; in nfsd4_lm_notify()
7180 spin_lock(&nn->blocked_locks_lock); in nfsd4_lm_notify()
7181 if (!list_empty(&nbl->nbl_list)) { in nfsd4_lm_notify()
7182 list_del_init(&nbl->nbl_list); in nfsd4_lm_notify()
7183 list_del_init(&nbl->nbl_lru); in nfsd4_lm_notify()
7186 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lm_notify()
7190 nfsd4_run_cb(&nbl->nbl_cb); in nfsd4_lm_notify()
7208 if (fl->fl_lmops == &nfsd_posix_mng_ops) { in nfs4_set_lock_denied()
7209 lo = (struct nfs4_lockowner *) fl->fl_owner; in nfs4_set_lock_denied()
7210 xdr_netobj_dup(&deny->ld_owner, &lo->lo_owner.so_owner, in nfs4_set_lock_denied()
7212 if (!deny->ld_owner.data) in nfs4_set_lock_denied()
7215 deny->ld_clientid = lo->lo_owner.so_client->cl_clientid; in nfs4_set_lock_denied()
7218 deny->ld_owner.len = 0; in nfs4_set_lock_denied()
7219 deny->ld_owner.data = NULL; in nfs4_set_lock_denied()
7220 deny->ld_clientid.cl_boot = 0; in nfs4_set_lock_denied()
7221 deny->ld_clientid.cl_id = 0; in nfs4_set_lock_denied()
7223 deny->ld_start = fl->fl_start; in nfs4_set_lock_denied()
7224 deny->ld_length = NFS4_MAX_UINT64; in nfs4_set_lock_denied()
7225 if (fl->fl_end != NFS4_MAX_UINT64) in nfs4_set_lock_denied()
7226 deny->ld_length = fl->fl_end - fl->fl_start + 1; in nfs4_set_lock_denied()
7227 deny->ld_type = NFS4_READ_LT; in nfs4_set_lock_denied()
7228 if (fl->fl_type != F_RDLCK) in nfs4_set_lock_denied()
7229 deny->ld_type = NFS4_WRITE_LT; in nfs4_set_lock_denied()
7238 lockdep_assert_held(&clp->cl_lock); in find_lockowner_str_locked()
7240 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[strhashval], in find_lockowner_str_locked()
7242 if (so->so_is_open_owner) in find_lockowner_str_locked()
7255 spin_lock(&clp->cl_lock); in find_lockowner_str()
7257 spin_unlock(&clp->cl_lock); in find_lockowner_str()
7280 * Called in nfsd4_lock - therefore, OPEN and OPEN_CONFIRM (if needed) has
7292 lo = alloc_stateowner(lockowner_slab, &lock->lk_new_owner, clp); in alloc_init_lock_stateowner()
7295 INIT_LIST_HEAD(&lo->lo_blocked); in alloc_init_lock_stateowner()
7296 INIT_LIST_HEAD(&lo->lo_owner.so_stateids); in alloc_init_lock_stateowner()
7297 lo->lo_owner.so_is_open_owner = 0; in alloc_init_lock_stateowner()
7298 lo->lo_owner.so_seqid = lock->lk_new_lock_seqid; in alloc_init_lock_stateowner()
7299 lo->lo_owner.so_ops = &lockowner_ops; in alloc_init_lock_stateowner()
7300 spin_lock(&clp->cl_lock); in alloc_init_lock_stateowner()
7301 ret = find_lockowner_str_locked(clp, &lock->lk_new_owner); in alloc_init_lock_stateowner()
7303 list_add(&lo->lo_owner.so_strhash, in alloc_init_lock_stateowner()
7304 &clp->cl_ownerstr_hashtbl[strhashval]); in alloc_init_lock_stateowner()
7307 nfs4_free_stateowner(&lo->lo_owner); in alloc_init_lock_stateowner()
7309 spin_unlock(&clp->cl_lock); in alloc_init_lock_stateowner()
7319 lockdep_assert_held(&ost->st_stid.sc_client->cl_lock); in find_lock_stateid()
7321 /* If ost is not hashed, ost->st_locks will not be valid */ in find_lock_stateid()
7323 list_for_each_entry(lst, &ost->st_locks, st_locks) { in find_lock_stateid()
7324 if (lst->st_stateowner == &lo->lo_owner) { in find_lock_stateid()
7325 refcount_inc(&lst->st_stid.sc_count); in find_lock_stateid()
7337 struct nfs4_client *clp = lo->lo_owner.so_client; in init_lock_stateid()
7340 mutex_init(&stp->st_mutex); in init_lock_stateid()
7341 mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX); in init_lock_stateid()
7343 spin_lock(&clp->cl_lock); in init_lock_stateid()
7349 refcount_inc(&stp->st_stid.sc_count); in init_lock_stateid()
7350 stp->st_stid.sc_type = NFS4_LOCK_STID; in init_lock_stateid()
7351 stp->st_stateowner = nfs4_get_stateowner(&lo->lo_owner); in init_lock_stateid()
7353 stp->st_stid.sc_file = fp; in init_lock_stateid()
7354 stp->st_access_bmap = 0; in init_lock_stateid()
7355 stp->st_deny_bmap = open_stp->st_deny_bmap; in init_lock_stateid()
7356 stp->st_openstp = open_stp; in init_lock_stateid()
7357 spin_lock(&fp->fi_lock); in init_lock_stateid()
7358 list_add(&stp->st_locks, &open_stp->st_locks); in init_lock_stateid()
7359 list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids); in init_lock_stateid()
7360 list_add(&stp->st_perfile, &fp->fi_stateids); in init_lock_stateid()
7361 spin_unlock(&fp->fi_lock); in init_lock_stateid()
7362 spin_unlock(&clp->cl_lock); in init_lock_stateid()
7365 spin_unlock(&clp->cl_lock); in init_lock_stateid()
7367 nfs4_put_stid(&retstp->st_stid); in init_lock_stateid()
7371 mutex_unlock(&stp->st_mutex); in init_lock_stateid()
7374 spin_unlock(&clp->cl_lock); in init_lock_stateid()
7375 mutex_unlock(&stp->st_mutex); in init_lock_stateid()
7386 struct nfs4_openowner *oo = openowner(ost->st_stateowner); in find_or_create_lock_stateid()
7387 struct nfs4_client *clp = oo->oo_owner.so_client; in find_or_create_lock_stateid()
7390 spin_lock(&clp->cl_lock); in find_or_create_lock_stateid()
7392 spin_unlock(&clp->cl_lock); in find_or_create_lock_stateid()
7396 nfs4_put_stid(&lst->st_stid); in find_or_create_lock_stateid()
7420 struct nfs4_file *fp = lock_stp->st_stid.sc_file; in get_lock_access()
7422 lockdep_assert_held(&fp->fi_lock); in get_lock_access()
7437 struct nfs4_file *fi = ost->st_stid.sc_file; in lookup_or_create_lock_state()
7438 struct nfs4_openowner *oo = openowner(ost->st_stateowner); in lookup_or_create_lock_state()
7439 struct nfs4_client *cl = oo->oo_owner.so_client; in lookup_or_create_lock_state()
7440 struct inode *inode = d_inode(cstate->current_fh.fh_dentry); in lookup_or_create_lock_state()
7445 lo = find_lockowner_str(cl, &lock->lk_new_owner); in lookup_or_create_lock_state()
7447 strhashval = ownerstr_hashval(&lock->lk_new_owner); in lookup_or_create_lock_state()
7454 if (!cstate->minorversion && in lookup_or_create_lock_state()
7455 lock->lk_new_lock_seqid != lo->lo_owner.so_seqid) in lookup_or_create_lock_state()
7468 nfs4_put_stateowner(&lo->lo_owner); in lookup_or_create_lock_state()
7479 struct nfsd4_lock *lock = &u->lock; in nfsd4_lock()
7499 (long long) lock->lk_offset, in nfsd4_lock()
7500 (long long) lock->lk_length); in nfsd4_lock()
7502 if (check_lock_length(lock->lk_offset, lock->lk_length)) in nfsd4_lock()
7505 if ((status = fh_verify(rqstp, &cstate->current_fh, in nfsd4_lock()
7511 if (lock->lk_is_new) { in nfsd4_lock()
7514 memcpy(&lock->lk_new_clientid, in nfsd4_lock()
7515 &cstate->clp->cl_clientid, in nfsd4_lock()
7520 lock->lk_new_open_seqid, in nfsd4_lock()
7521 &lock->lk_new_open_stateid, in nfsd4_lock()
7525 mutex_unlock(&open_stp->st_mutex); in nfsd4_lock()
7526 open_sop = openowner(open_stp->st_stateowner); in nfsd4_lock()
7528 if (!same_clid(&open_sop->oo_owner.so_client->cl_clientid, in nfsd4_lock()
7529 &lock->lk_new_clientid)) in nfsd4_lock()
7535 lock->lk_old_lock_seqid, in nfsd4_lock()
7536 &lock->lk_old_lock_stateid, in nfsd4_lock()
7541 lock_sop = lockowner(lock_stp->st_stateowner); in nfsd4_lock()
7543 lkflg = setlkflg(lock->lk_type); in nfsd4_lock()
7549 if (locks_in_grace(net) && !lock->lk_reclaim) in nfsd4_lock()
7552 if (!locks_in_grace(net) && lock->lk_reclaim) in nfsd4_lock()
7555 if (lock->lk_reclaim) in nfsd4_lock()
7558 fp = lock_stp->st_stid.sc_file; in nfsd4_lock()
7559 switch (lock->lk_type) { in nfsd4_lock()
7565 spin_lock(&fp->fi_lock); in nfsd4_lock()
7569 spin_unlock(&fp->fi_lock); in nfsd4_lock()
7577 spin_lock(&fp->fi_lock); in nfsd4_lock()
7581 spin_unlock(&fp->fi_lock); in nfsd4_lock()
7595 * Most filesystems with their own ->lock operations will block in nfsd4_lock()
7601 if (nf->nf_file->f_op->lock) in nfsd4_lock()
7604 nbl = find_or_allocate_block(lock_sop, &fp->fi_fhandle, nn); in nfsd4_lock()
7611 file_lock = &nbl->nbl_lock; in nfsd4_lock()
7612 file_lock->fl_type = fl_type; in nfsd4_lock()
7613 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(&lock_sop->lo_owner)); in nfsd4_lock()
7614 file_lock->fl_pid = current->tgid; in nfsd4_lock()
7615 file_lock->fl_file = nf->nf_file; in nfsd4_lock()
7616 file_lock->fl_flags = fl_flags; in nfsd4_lock()
7617 file_lock->fl_lmops = &nfsd_posix_mng_ops; in nfsd4_lock()
7618 file_lock->fl_start = lock->lk_offset; in nfsd4_lock()
7619 file_lock->fl_end = last_byte_offset(lock->lk_offset, lock->lk_length); in nfsd4_lock()
7630 nbl->nbl_time = ktime_get_boottime_seconds(); in nfsd4_lock()
7631 spin_lock(&nn->blocked_locks_lock); in nfsd4_lock()
7632 list_add_tail(&nbl->nbl_list, &lock_sop->lo_blocked); in nfsd4_lock()
7633 list_add_tail(&nbl->nbl_lru, &nn->blocked_locks_lru); in nfsd4_lock()
7634 kref_get(&nbl->nbl_kref); in nfsd4_lock()
7635 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lock()
7638 err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, conflock); in nfsd4_lock()
7641 nfs4_inc_and_copy_stateid(&lock->lk_resp_stateid, &lock_stp->st_stid); in nfsd4_lock()
7643 if (lock->lk_reclaim) in nfsd4_lock()
7644 nn->somebody_reclaimed = true; in nfsd4_lock()
7647 kref_put(&nbl->nbl_kref, free_nbl); in nfsd4_lock()
7650 case -EAGAIN: /* conflock holds conflicting lock */ in nfsd4_lock()
7653 nfs4_set_lock_denied(conflock, &lock->lk_denied); in nfsd4_lock()
7655 case -EDEADLK: in nfsd4_lock()
7667 spin_lock(&nn->blocked_locks_lock); in nfsd4_lock()
7668 if (!list_empty(&nbl->nbl_list) && in nfsd4_lock()
7669 !list_empty(&nbl->nbl_lru)) { in nfsd4_lock()
7670 list_del_init(&nbl->nbl_list); in nfsd4_lock()
7671 list_del_init(&nbl->nbl_lru); in nfsd4_lock()
7672 kref_put(&nbl->nbl_kref, free_nbl); in nfsd4_lock()
7675 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lock()
7683 if (cstate->replay_owner && in nfsd4_lock()
7684 cstate->replay_owner != &lock_sop->lo_owner && in nfsd4_lock()
7686 lock_sop->lo_owner.so_seqid++; in nfsd4_lock()
7689 * If this is a new, never-before-used stateid, and we are in nfsd4_lock()
7695 mutex_unlock(&lock_stp->st_mutex); in nfsd4_lock()
7697 nfs4_put_stid(&lock_stp->st_stid); in nfsd4_lock()
7700 nfs4_put_stid(&open_stp->st_stid); in nfsd4_lock()
7721 inode = fhp->fh_dentry->d_inode; in nfsd_test_lock()
7726 lock->fl_file = nf->nf_file; in nfsd_test_lock()
7727 err = nfserrno(vfs_test_lock(nf->nf_file, lock)); in nfsd_test_lock()
7728 lock->fl_file = NULL; in nfsd_test_lock()
7742 struct nfsd4_lockt *lockt = &u->lockt; in nfsd4_lockt()
7751 if (check_lock_length(lockt->lt_offset, lockt->lt_length)) in nfsd4_lockt()
7755 status = set_client(&lockt->lt_clientid, cstate, nn); in nfsd4_lockt()
7760 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) in nfsd4_lockt()
7770 switch (lockt->lt_type) { in nfsd4_lockt()
7773 file_lock->fl_type = F_RDLCK; in nfsd4_lockt()
7777 file_lock->fl_type = F_WRLCK; in nfsd4_lockt()
7785 lo = find_lockowner_str(cstate->clp, &lockt->lt_owner); in nfsd4_lockt()
7787 file_lock->fl_owner = (fl_owner_t)lo; in nfsd4_lockt()
7788 file_lock->fl_pid = current->tgid; in nfsd4_lockt()
7789 file_lock->fl_flags = FL_POSIX; in nfsd4_lockt()
7791 file_lock->fl_start = lockt->lt_offset; in nfsd4_lockt()
7792 file_lock->fl_end = last_byte_offset(lockt->lt_offset, lockt->lt_length); in nfsd4_lockt()
7796 status = nfsd_test_lock(rqstp, &cstate->current_fh, file_lock); in nfsd4_lockt()
7800 if (file_lock->fl_type != F_UNLCK) { in nfsd4_lockt()
7802 nfs4_set_lock_denied(file_lock, &lockt->lt_denied); in nfsd4_lockt()
7806 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_lockt()
7816 struct nfsd4_locku *locku = &u->locku; in nfsd4_locku()
7825 (long long) locku->lu_offset, in nfsd4_locku()
7826 (long long) locku->lu_length); in nfsd4_locku()
7828 if (check_lock_length(locku->lu_offset, locku->lu_length)) in nfsd4_locku()
7831 status = nfs4_preprocess_seqid_op(cstate, locku->lu_seqid, in nfsd4_locku()
7832 &locku->lu_stateid, NFS4_LOCK_STID, in nfsd4_locku()
7836 nf = find_any_file(stp->st_stid.sc_file); in nfsd4_locku()
7848 file_lock->fl_type = F_UNLCK; in nfsd4_locku()
7849 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(stp->st_stateowner)); in nfsd4_locku()
7850 file_lock->fl_pid = current->tgid; in nfsd4_locku()
7851 file_lock->fl_file = nf->nf_file; in nfsd4_locku()
7852 file_lock->fl_flags = FL_POSIX; in nfsd4_locku()
7853 file_lock->fl_lmops = &nfsd_posix_mng_ops; in nfsd4_locku()
7854 file_lock->fl_start = locku->lu_offset; in nfsd4_locku()
7856 file_lock->fl_end = last_byte_offset(locku->lu_offset, in nfsd4_locku()
7857 locku->lu_length); in nfsd4_locku()
7860 err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, NULL); in nfsd4_locku()
7865 nfs4_inc_and_copy_stateid(&locku->lu_stateid, &stp->st_stid); in nfsd4_locku()
7869 mutex_unlock(&stp->st_mutex); in nfsd4_locku()
7870 nfs4_put_stid(&stp->st_stid); in nfsd4_locku()
7896 spin_lock(&fp->fi_lock); in check_for_locks()
7904 inode = file_inode(nf->nf_file); in check_for_locks()
7907 if (flctx && !list_empty_careful(&flctx->flc_posix)) { in check_for_locks()
7908 spin_lock(&flctx->flc_lock); in check_for_locks()
7909 list_for_each_entry(fl, &flctx->flc_posix, fl_list) { in check_for_locks()
7910 if (fl->fl_owner == (fl_owner_t)lowner) { in check_for_locks()
7915 spin_unlock(&flctx->flc_lock); in check_for_locks()
7918 spin_unlock(&fp->fi_lock); in check_for_locks()
7923 * nfsd4_release_lockowner - process NFSv4.0 RELEASE_LOCKOWNER operations
7928 * Check if theree are any locks still held and if not - free the lockowner
7942 struct nfsd4_release_lockowner *rlockowner = &u->release_lockowner; in nfsd4_release_lockowner()
7944 clientid_t *clid = &rlockowner->rl_clientid; in nfsd4_release_lockowner()
7952 clid->cl_boot, clid->cl_id); in nfsd4_release_lockowner()
7957 clp = cstate->clp; in nfsd4_release_lockowner()
7959 spin_lock(&clp->cl_lock); in nfsd4_release_lockowner()
7960 lo = find_lockowner_str_locked(clp, &rlockowner->rl_owner); in nfsd4_release_lockowner()
7962 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
7966 list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) { in nfsd4_release_lockowner()
7967 if (check_for_locks(stp->st_stid.sc_file, lo)) { in nfsd4_release_lockowner()
7968 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
7969 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_release_lockowner()
7974 while (!list_empty(&lo->lo_owner.so_stateids)) { in nfsd4_release_lockowner()
7975 stp = list_first_entry(&lo->lo_owner.so_stateids, in nfsd4_release_lockowner()
7981 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
7985 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_release_lockowner()
8001 return (crp && crp->cr_clp); in nfs4_has_reclaimed_state()
8020 INIT_LIST_HEAD(&crp->cr_strhash); in nfs4_client_to_reclaim()
8021 list_add(&crp->cr_strhash, &nn->reclaim_str_hashtbl[strhashval]); in nfs4_client_to_reclaim()
8022 crp->cr_name.data = name.data; in nfs4_client_to_reclaim()
8023 crp->cr_name.len = name.len; in nfs4_client_to_reclaim()
8024 crp->cr_princhash.data = princhash.data; in nfs4_client_to_reclaim()
8025 crp->cr_princhash.len = princhash.len; in nfs4_client_to_reclaim()
8026 crp->cr_clp = NULL; in nfs4_client_to_reclaim()
8027 nn->reclaim_str_hashtbl_size++; in nfs4_client_to_reclaim()
8035 list_del(&crp->cr_strhash); in nfs4_remove_reclaim_record()
8036 kfree(crp->cr_name.data); in nfs4_remove_reclaim_record()
8037 kfree(crp->cr_princhash.data); in nfs4_remove_reclaim_record()
8039 nn->reclaim_str_hashtbl_size--; in nfs4_remove_reclaim_record()
8049 while (!list_empty(&nn->reclaim_str_hashtbl[i])) { in nfs4_release_reclaim()
8050 crp = list_entry(nn->reclaim_str_hashtbl[i].next, in nfs4_release_reclaim()
8055 WARN_ON_ONCE(nn->reclaim_str_hashtbl_size); in nfs4_release_reclaim()
8067 list_for_each_entry(crp, &nn->reclaim_str_hashtbl[strhashval], cr_strhash) { in nfsd4_find_reclaim_client()
8068 if (compare_blob(&crp->cr_name, &name) == 0) { in nfsd4_find_reclaim_client()
8078 if (test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &clp->cl_flags)) in nfs4_check_open_reclaim()
8105 max_delegations = nr_free_buffer_pages() >> (20 - 2 - PAGE_SHIFT); in set_max_delegations()
8113 nn->conf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE, in nfs4_state_create_net()
8116 if (!nn->conf_id_hashtbl) in nfs4_state_create_net()
8118 nn->unconf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE, in nfs4_state_create_net()
8121 if (!nn->unconf_id_hashtbl) in nfs4_state_create_net()
8123 nn->sessionid_hashtbl = kmalloc_array(SESSION_HASH_SIZE, in nfs4_state_create_net()
8126 if (!nn->sessionid_hashtbl) in nfs4_state_create_net()
8130 INIT_LIST_HEAD(&nn->conf_id_hashtbl[i]); in nfs4_state_create_net()
8131 INIT_LIST_HEAD(&nn->unconf_id_hashtbl[i]); in nfs4_state_create_net()
8134 INIT_LIST_HEAD(&nn->sessionid_hashtbl[i]); in nfs4_state_create_net()
8135 nn->conf_name_tree = RB_ROOT; in nfs4_state_create_net()
8136 nn->unconf_name_tree = RB_ROOT; in nfs4_state_create_net()
8137 nn->boot_time = ktime_get_real_seconds(); in nfs4_state_create_net()
8138 nn->grace_ended = false; in nfs4_state_create_net()
8139 nn->nfsd4_manager.block_opens = true; in nfs4_state_create_net()
8140 INIT_LIST_HEAD(&nn->nfsd4_manager.list); in nfs4_state_create_net()
8141 INIT_LIST_HEAD(&nn->client_lru); in nfs4_state_create_net()
8142 INIT_LIST_HEAD(&nn->close_lru); in nfs4_state_create_net()
8143 INIT_LIST_HEAD(&nn->del_recall_lru); in nfs4_state_create_net()
8144 spin_lock_init(&nn->client_lock); in nfs4_state_create_net()
8145 spin_lock_init(&nn->s2s_cp_lock); in nfs4_state_create_net()
8146 idr_init(&nn->s2s_cp_stateids); in nfs4_state_create_net()
8148 spin_lock_init(&nn->blocked_locks_lock); in nfs4_state_create_net()
8149 INIT_LIST_HEAD(&nn->blocked_locks_lru); in nfs4_state_create_net()
8151 INIT_DELAYED_WORK(&nn->laundromat_work, laundromat_main); in nfs4_state_create_net()
8152 INIT_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker); in nfs4_state_create_net()
8155 nn->nfsd_client_shrinker.scan_objects = nfsd4_state_shrinker_scan; in nfs4_state_create_net()
8156 nn->nfsd_client_shrinker.count_objects = nfsd4_state_shrinker_count; in nfs4_state_create_net()
8157 nn->nfsd_client_shrinker.seeks = DEFAULT_SEEKS; in nfs4_state_create_net()
8159 if (register_shrinker(&nn->nfsd_client_shrinker, "nfsd-client")) in nfs4_state_create_net()
8165 kfree(nn->sessionid_hashtbl); in nfs4_state_create_net()
8167 kfree(nn->unconf_id_hashtbl); in nfs4_state_create_net()
8169 kfree(nn->conf_id_hashtbl); in nfs4_state_create_net()
8171 return -ENOMEM; in nfs4_state_create_net()
8182 while (!list_empty(&nn->conf_id_hashtbl[i])) { in nfs4_state_destroy_net()
8183 clp = list_entry(nn->conf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); in nfs4_state_destroy_net()
8188 WARN_ON(!list_empty(&nn->blocked_locks_lru)); in nfs4_state_destroy_net()
8191 while (!list_empty(&nn->unconf_id_hashtbl[i])) { in nfs4_state_destroy_net()
8192 clp = list_entry(nn->unconf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); in nfs4_state_destroy_net()
8197 kfree(nn->sessionid_hashtbl); in nfs4_state_destroy_net()
8198 kfree(nn->unconf_id_hashtbl); in nfs4_state_destroy_net()
8199 kfree(nn->conf_id_hashtbl); in nfs4_state_destroy_net()
8212 locks_start_grace(net, &nn->nfsd4_manager); in nfs4_state_start_net()
8214 if (nn->track_reclaim_completes && nn->reclaim_str_hashtbl_size == 0) in nfs4_state_start_net()
8216 printk(KERN_INFO "NFSD: starting %lld-second grace period (net %x)\n", in nfs4_state_start_net()
8217 nn->nfsd4_grace, net->ns.inum); in nfs4_state_start_net()
8219 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_grace * HZ); in nfs4_state_start_net()
8224 net->ns.inum); in nfs4_state_start_net()
8225 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_lease * HZ); in nfs4_state_start_net()
8258 unregister_shrinker(&nn->nfsd_client_shrinker); in nfs4_state_shutdown_net()
8259 cancel_work(&nn->nfsd_shrinker_work); in nfs4_state_shutdown_net()
8260 cancel_delayed_work_sync(&nn->laundromat_work); in nfs4_state_shutdown_net()
8261 locks_end_grace(&nn->nfsd4_manager); in nfs4_state_shutdown_net()
8265 list_for_each_safe(pos, next, &nn->del_recall_lru) { in nfs4_state_shutdown_net()
8268 list_add(&dp->dl_recall_lru, &reaplist); in nfs4_state_shutdown_net()
8273 list_del_init(&dp->dl_recall_lru); in nfs4_state_shutdown_net()
8296 memcpy(stateid, &cstate->current_stateid, sizeof(stateid_t)); in get_stateid()
8302 if (cstate->minorversion) { in put_stateid()
8303 memcpy(&cstate->current_stateid, stateid, sizeof(stateid_t)); in put_stateid()
8321 put_stateid(cstate, &u->open_downgrade.od_stateid); in nfsd4_set_opendowngradestateid()
8328 put_stateid(cstate, &u->open.op_stateid); in nfsd4_set_openstateid()
8335 put_stateid(cstate, &u->close.cl_stateid); in nfsd4_set_closestateid()
8342 put_stateid(cstate, &u->lock.lk_resp_stateid); in nfsd4_set_lockstateid()
8353 get_stateid(cstate, &u->open_downgrade.od_stateid); in nfsd4_get_opendowngradestateid()
8360 get_stateid(cstate, &u->delegreturn.dr_stateid); in nfsd4_get_delegreturnstateid()
8367 get_stateid(cstate, &u->free_stateid.fr_stateid); in nfsd4_get_freestateid()
8374 get_stateid(cstate, &u->setattr.sa_stateid); in nfsd4_get_setattrstateid()
8381 get_stateid(cstate, &u->close.cl_stateid); in nfsd4_get_closestateid()
8388 get_stateid(cstate, &u->locku.lu_stateid); in nfsd4_get_lockustateid()
8395 get_stateid(cstate, &u->read.rd_stateid); in nfsd4_get_readstateid()
8402 get_stateid(cstate, &u->write.wr_stateid); in nfsd4_get_writestateid()
8406 * nfsd4_deleg_getattr_conflict - Recall if GETATTR causes conflict
8435 spin_lock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
8436 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in nfsd4_deleg_getattr_conflict()
8437 if (fl->fl_flags == FL_LAYOUT) in nfsd4_deleg_getattr_conflict()
8439 if (fl->fl_lmops != &nfsd_lease_mng_ops) { in nfsd4_deleg_getattr_conflict()
8441 * non-nfs lease, if it's a lease with F_RDLCK then in nfsd4_deleg_getattr_conflict()
8445 if (fl->fl_type == F_RDLCK) in nfsd4_deleg_getattr_conflict()
8449 if (fl->fl_type == F_WRLCK) { in nfsd4_deleg_getattr_conflict()
8450 dp = fl->fl_owner; in nfsd4_deleg_getattr_conflict()
8451 if (dp->dl_recall.cb_clp == *(rqstp->rq_lease_breaker)) { in nfsd4_deleg_getattr_conflict()
8452 spin_unlock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
8456 spin_unlock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
8466 spin_unlock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()