• Home
  • Raw
  • Download

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, &copy->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()
1094 * low 3 bytes as hash-table indices.
1113 if (bd->entries == 0) in delegation_blocked()
1115 if (ktime_get_seconds() - bd->swap_time > 30) { in delegation_blocked()
1117 if (ktime_get_seconds() - bd->swap_time > 30) { in delegation_blocked()
1118 bd->entries -= bd->old_entries; in delegation_blocked()
1119 bd->old_entries = bd->entries; in delegation_blocked()
1120 bd->new = 1-bd->new; in delegation_blocked()
1121 memset(bd->set[bd->new], 0, in delegation_blocked()
1122 sizeof(bd->set[0])); in delegation_blocked()
1123 bd->swap_time = ktime_get_seconds(); in delegation_blocked()
1127 hash = jhash(&fh->fh_raw, fh->fh_size, 0); in delegation_blocked()
1128 if (test_bit(hash&255, bd->set[0]) && in delegation_blocked()
1129 test_bit((hash>>8)&255, bd->set[0]) && in delegation_blocked()
1130 test_bit((hash>>16)&255, bd->set[0])) in delegation_blocked()
1133 if (test_bit(hash&255, bd->set[1]) && in delegation_blocked()
1134 test_bit((hash>>8)&255, bd->set[1]) && in delegation_blocked()
1135 test_bit((hash>>16)&255, bd->set[1])) in delegation_blocked()
1146 hash = jhash(&fh->fh_raw, fh->fh_size, 0); in block_delegations()
1149 __set_bit(hash&255, bd->set[bd->new]); in block_delegations()
1150 __set_bit((hash>>8)&255, bd->set[bd->new]); in block_delegations()
1151 __set_bit((hash>>16)&255, bd->set[bd->new]); in block_delegations()
1152 if (bd->entries == 0) in block_delegations()
1153 bd->swap_time = ktime_get_seconds(); in block_delegations()
1154 bd->entries += 1; in block_delegations()
1169 if (delegation_blocked(&fp->fi_fhandle)) in alloc_init_deleg()
1180 dp->dl_stid.sc_stateid.si_generation = 1; in alloc_init_deleg()
1181 INIT_LIST_HEAD(&dp->dl_perfile); in alloc_init_deleg()
1182 INIT_LIST_HEAD(&dp->dl_perclnt); in alloc_init_deleg()
1183 INIT_LIST_HEAD(&dp->dl_recall_lru); in alloc_init_deleg()
1184 dp->dl_clnt_odstate = odstate; in alloc_init_deleg()
1186 dp->dl_type = dl_type; in alloc_init_deleg()
1187 dp->dl_retries = 1; in alloc_init_deleg()
1188 dp->dl_recalled = false; in alloc_init_deleg()
1189 nfsd4_init_cb(&dp->dl_recall, dp->dl_stid.sc_client, in alloc_init_deleg()
1192 dp->dl_stid.sc_file = fp; in alloc_init_deleg()
1202 struct nfs4_file *fp = s->sc_file; in nfs4_put_stid()
1203 struct nfs4_client *clp = s->sc_client; in nfs4_put_stid()
1205 might_lock(&clp->cl_lock); in nfs4_put_stid()
1207 if (!refcount_dec_and_lock(&s->sc_count, &clp->cl_lock)) { in nfs4_put_stid()
1211 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); in nfs4_put_stid()
1212 nfs4_free_cpntf_statelist(clp->net, s); in nfs4_put_stid()
1213 spin_unlock(&clp->cl_lock); in nfs4_put_stid()
1214 s->sc_free(s); in nfs4_put_stid()
1222 stateid_t *src = &stid->sc_stateid; in nfs4_inc_and_copy_stateid()
1224 spin_lock(&stid->sc_lock); in nfs4_inc_and_copy_stateid()
1225 if (unlikely(++src->si_generation == 0)) in nfs4_inc_and_copy_stateid()
1226 src->si_generation = 1; in nfs4_inc_and_copy_stateid()
1228 spin_unlock(&stid->sc_lock); in nfs4_inc_and_copy_stateid()
1235 spin_lock(&fp->fi_lock); in put_deleg_file()
1236 if (--fp->fi_delegees == 0) in put_deleg_file()
1237 swap(nf, fp->fi_deleg_file); in put_deleg_file()
1238 spin_unlock(&fp->fi_lock); in put_deleg_file()
1246 struct nfs4_file *fp = dp->dl_stid.sc_file; in nfs4_unlock_deleg_lease()
1247 struct nfsd_file *nf = fp->fi_deleg_file; in nfs4_unlock_deleg_lease()
1249 WARN_ON_ONCE(!fp->fi_delegees); in nfs4_unlock_deleg_lease()
1251 vfs_setlease(nf->nf_file, F_UNLCK, NULL, (void **)&dp); in nfs4_unlock_deleg_lease()
1257 put_clnt_odstate(dp->dl_clnt_odstate); in destroy_unhashed_deleg()
1259 nfs4_put_stid(&dp->dl_stid); in destroy_unhashed_deleg()
1264 s->sc_type = 0; in nfs4_unhash_stid()
1268 * nfs4_delegation_exists - Discover if this delegation already exists
1283 lockdep_assert_held(&fp->fi_lock); in nfs4_delegation_exists()
1285 list_for_each_entry(searchdp, &fp->fi_delegations, dl_perfile) { in nfs4_delegation_exists()
1286 searchclp = searchdp->dl_stid.sc_client; in nfs4_delegation_exists()
1295 * hash_delegation_locked - Add a delegation to the appropriate lists
1302 * On error: -EAGAIN if one was previously granted to this
1310 struct nfs4_client *clp = dp->dl_stid.sc_client; in hash_delegation_locked()
1313 lockdep_assert_held(&fp->fi_lock); in hash_delegation_locked()
1316 return -EAGAIN; in hash_delegation_locked()
1317 refcount_inc(&dp->dl_stid.sc_count); in hash_delegation_locked()
1318 dp->dl_stid.sc_type = NFS4_DELEG_STID; in hash_delegation_locked()
1319 list_add(&dp->dl_perfile, &fp->fi_delegations); in hash_delegation_locked()
1320 list_add(&dp->dl_perclnt, &clp->cl_delegations); in hash_delegation_locked()
1326 return !(list_empty(&dp->dl_perfile)); in delegation_hashed()
1332 struct nfs4_file *fp = dp->dl_stid.sc_file; in unhash_delegation_locked()
1339 dp->dl_stid.sc_type = NFS4_CLOSED_DELEG_STID; in unhash_delegation_locked()
1341 ++dp->dl_time; in unhash_delegation_locked()
1342 spin_lock(&fp->fi_lock); in unhash_delegation_locked()
1343 list_del_init(&dp->dl_perclnt); in unhash_delegation_locked()
1344 list_del_init(&dp->dl_recall_lru); in unhash_delegation_locked()
1345 list_del_init(&dp->dl_perfile); in unhash_delegation_locked()
1346 spin_unlock(&fp->fi_lock); in unhash_delegation_locked()
1363 struct nfs4_client *clp = dp->dl_stid.sc_client; in revoke_delegation()
1365 WARN_ON(!list_empty(&dp->dl_recall_lru)); in revoke_delegation()
1367 trace_nfsd_stid_revoke(&dp->dl_stid); in revoke_delegation()
1369 if (clp->cl_minorversion) { in revoke_delegation()
1370 spin_lock(&clp->cl_lock); in revoke_delegation()
1371 dp->dl_stid.sc_type = NFS4_REVOKED_DELEG_STID; in revoke_delegation()
1372 refcount_inc(&dp->dl_stid.sc_count); in revoke_delegation()
1373 list_add(&dp->dl_recall_lru, &clp->cl_revoked); in revoke_delegation()
1374 spin_unlock(&clp->cl_lock); in revoke_delegation()
1402 spin_lock(&fp->fi_lock); in recalculate_deny_mode()
1403 fp->fi_share_deny = 0; in recalculate_deny_mode()
1404 list_for_each_entry(stp, &fp->fi_stateids, st_perfile) in recalculate_deny_mode()
1405 fp->fi_share_deny |= bmap_to_share_mode(stp->st_deny_bmap); in recalculate_deny_mode()
1406 spin_unlock(&fp->fi_lock); in recalculate_deny_mode()
1422 /* Recalculate per-file deny mode if there was a change */ in reset_union_bmap_deny()
1424 recalculate_deny_mode(stp->st_stid.sc_file); in reset_union_bmap_deny()
1432 struct nfs4_file *fp = stp->st_stid.sc_file; in release_all_access()
1434 if (fp && stp->st_deny_bmap != 0) in release_all_access()
1439 nfs4_file_put_access(stp->st_stid.sc_file, i); in release_all_access()
1446 kfree(sop->so_owner.data); in nfs4_free_stateowner()
1447 sop->so_ops->so_free(sop); in nfs4_free_stateowner()
1452 struct nfs4_client *clp = sop->so_client; in nfs4_put_stateowner()
1454 might_lock(&clp->cl_lock); in nfs4_put_stateowner()
1456 if (!atomic_dec_and_lock(&sop->so_count, &clp->cl_lock)) in nfs4_put_stateowner()
1458 sop->so_ops->so_unhash(sop); in nfs4_put_stateowner()
1459 spin_unlock(&clp->cl_lock); in nfs4_put_stateowner()
1466 return list_empty(&stp->st_perfile); in nfs4_ol_stateid_unhashed()
1471 struct nfs4_file *fp = stp->st_stid.sc_file; in unhash_ol_stateid()
1473 lockdep_assert_held(&stp->st_stateowner->so_client->cl_lock); in unhash_ol_stateid()
1475 if (list_empty(&stp->st_perfile)) in unhash_ol_stateid()
1478 spin_lock(&fp->fi_lock); in unhash_ol_stateid()
1479 list_del_init(&stp->st_perfile); in unhash_ol_stateid()
1480 spin_unlock(&fp->fi_lock); in unhash_ol_stateid()
1481 list_del(&stp->st_perstateowner); in unhash_ol_stateid()
1489 put_clnt_odstate(stp->st_clnt_odstate); in nfs4_free_ol_stateid()
1491 if (stp->st_stateowner) in nfs4_free_ol_stateid()
1492 nfs4_put_stateowner(stp->st_stateowner); in nfs4_free_ol_stateid()
1493 WARN_ON(!list_empty(&stid->sc_cp_list)); in nfs4_free_ol_stateid()
1500 struct nfs4_lockowner *lo = lockowner(stp->st_stateowner); in nfs4_free_lock_stateid()
1503 nf = find_any_file(stp->st_stid.sc_file); in nfs4_free_lock_stateid()
1505 get_file(nf->nf_file); in nfs4_free_lock_stateid()
1506 filp_close(nf->nf_file, (fl_owner_t)lo); in nfs4_free_lock_stateid()
1520 struct nfs4_stid *s = &stp->st_stid; in put_ol_stateid_locked()
1521 struct nfs4_client *clp = s->sc_client; in put_ol_stateid_locked()
1523 lockdep_assert_held(&clp->cl_lock); in put_ol_stateid_locked()
1525 WARN_ON_ONCE(!list_empty(&stp->st_locks)); in put_ol_stateid_locked()
1527 if (!refcount_dec_and_test(&s->sc_count)) { in put_ol_stateid_locked()
1532 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); in put_ol_stateid_locked()
1533 list_add(&stp->st_locks, reaplist); in put_ol_stateid_locked()
1538 lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); in unhash_lock_stateid()
1542 list_del_init(&stp->st_locks); in unhash_lock_stateid()
1543 nfs4_unhash_stid(&stp->st_stid); in unhash_lock_stateid()
1549 struct nfs4_client *clp = stp->st_stid.sc_client; in release_lock_stateid()
1552 spin_lock(&clp->cl_lock); in release_lock_stateid()
1554 spin_unlock(&clp->cl_lock); in release_lock_stateid()
1556 nfs4_put_stid(&stp->st_stid); in release_lock_stateid()
1561 struct nfs4_client *clp = lo->lo_owner.so_client; in unhash_lockowner_locked()
1563 lockdep_assert_held(&clp->cl_lock); in unhash_lockowner_locked()
1565 list_del_init(&lo->lo_owner.so_strhash); in unhash_lockowner_locked()
1583 list_del(&stp->st_locks); in free_ol_stateid_reaplist()
1584 fp = stp->st_stid.sc_file; in free_ol_stateid_reaplist()
1585 stp->st_stid.sc_free(&stp->st_stid); in free_ol_stateid_reaplist()
1596 lockdep_assert_held(&open_stp->st_stid.sc_client->cl_lock); in release_open_stateid_locks()
1598 while (!list_empty(&open_stp->st_locks)) { in release_open_stateid_locks()
1599 stp = list_entry(open_stp->st_locks.next, in release_open_stateid_locks()
1609 lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); in unhash_open_stateid()
1621 spin_lock(&stp->st_stid.sc_client->cl_lock); in release_open_stateid()
1624 spin_unlock(&stp->st_stid.sc_client->cl_lock); in release_open_stateid()
1630 lockdep_assert_held(&oo->oo_owner.so_client->cl_lock); in nfs4_openowner_unhashed()
1632 return list_empty(&oo->oo_owner.so_strhash) && in nfs4_openowner_unhashed()
1633 list_empty(&oo->oo_perclient); in nfs4_openowner_unhashed()
1638 struct nfs4_client *clp = oo->oo_owner.so_client; in unhash_openowner_locked()
1640 lockdep_assert_held(&clp->cl_lock); in unhash_openowner_locked()
1642 list_del_init(&oo->oo_owner.so_strhash); in unhash_openowner_locked()
1643 list_del_init(&oo->oo_perclient); in unhash_openowner_locked()
1648 struct nfsd_net *nn = net_generic(oo->oo_owner.so_client->net, in release_last_closed_stateid()
1652 spin_lock(&nn->client_lock); in release_last_closed_stateid()
1653 s = oo->oo_last_closed_stid; in release_last_closed_stateid()
1655 list_del_init(&oo->oo_close_lru); in release_last_closed_stateid()
1656 oo->oo_last_closed_stid = NULL; in release_last_closed_stateid()
1658 spin_unlock(&nn->client_lock); in release_last_closed_stateid()
1660 nfs4_put_stid(&s->st_stid); in release_last_closed_stateid()
1666 struct nfs4_client *clp = oo->oo_owner.so_client; in release_openowner()
1671 spin_lock(&clp->cl_lock); in release_openowner()
1673 while (!list_empty(&oo->oo_owner.so_stateids)) { in release_openowner()
1674 stp = list_first_entry(&oo->oo_owner.so_stateids, in release_openowner()
1679 spin_unlock(&clp->cl_lock); in release_openowner()
1682 nfs4_put_stateowner(&oo->oo_owner); in release_openowner()
1690 return sid->sequence % SESSION_HASH_SIZE; in hash_sessionid()
1697 u32 *ptr = (u32 *)(&sessionid->data[0]); in dump_sessionid()
1708 * Bump the seqid on cstate->replay_owner, and clear replay_owner if it
1713 struct nfs4_stateowner *so = cstate->replay_owner; in nfsd4_bump_seqid()
1724 if (so->so_is_open_owner) in nfsd4_bump_seqid()
1726 so->so_seqid++; in nfsd4_bump_seqid()
1733 struct nfs4_client *clp = ses->se_client; in gen_sessionid()
1736 sid = (struct nfsd4_sessionid *)ses->se_sessionid.data; in gen_sessionid()
1737 sid->clientid = clp->cl_clientid; in gen_sessionid()
1738 sid->sequence = current_sessionid++; in gen_sessionid()
1739 sid->reserved = 0; in gen_sessionid()
1745 * the end of the initial SEQUENCE operation--the rest we regenerate
1751 * verifier), 12 for the compound header (with zero-length tag), and 44
1761 for (i = 0; i < ses->se_fchannel.maxreqs; i++) { in free_session_slots()
1762 free_svc_cred(&ses->se_slots[i]->sl_cred); in free_session_slots()
1763 kfree(ses->se_slots[i]); in free_session_slots()
1775 if (ca->maxresp_cached < NFSD_MIN_HDR_SEQ_SZ) in slot_bytes()
1778 size = ca->maxresp_cached - NFSD_MIN_HDR_SEQ_SZ; in slot_bytes()
1784 * re-negotiate active sessions and reduce their slot usage to make
1790 u32 num = ca->maxreqs; in nfsd4_get_drc_mem()
1796 total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used; in nfsd4_get_drc_mem()
1812 * over-allocation--it is better than failure. in nfsd4_get_drc_mem()
1814 scale_factor = max_t(unsigned int, 8, nn->nfsd_serv->sv_nrthreads); in nfsd4_get_drc_mem()
1831 nfsd_drc_mem_used -= slotsize * ca->maxreqs; in nfsd4_put_drc_mem()
1838 int numslots = fattrs->maxreqs; in alloc_session()
1851 new->se_slots[i] = kzalloc(slotsize, GFP_KERNEL); in alloc_session()
1852 if (!new->se_slots[i]) in alloc_session()
1856 memcpy(&new->se_fchannel, fattrs, sizeof(struct nfsd4_channel_attrs)); in alloc_session()
1857 memcpy(&new->se_bchannel, battrs, sizeof(struct nfsd4_channel_attrs)); in alloc_session()
1861 while (i--) in alloc_session()
1862 kfree(new->se_slots[i]); in alloc_session()
1869 svc_xprt_put(c->cn_xprt); in free_conn()
1876 struct nfs4_client *clp = c->cn_session->se_client; in nfsd4_conn_lost()
1880 spin_lock(&clp->cl_lock); in nfsd4_conn_lost()
1881 if (!list_empty(&c->cn_persession)) { in nfsd4_conn_lost()
1882 list_del(&c->cn_persession); in nfsd4_conn_lost()
1886 spin_unlock(&clp->cl_lock); in nfsd4_conn_lost()
1896 svc_xprt_get(rqstp->rq_xprt); in alloc_conn()
1897 conn->cn_xprt = rqstp->rq_xprt; in alloc_conn()
1898 conn->cn_flags = flags; in alloc_conn()
1899 INIT_LIST_HEAD(&conn->cn_xpt_user.list); in alloc_conn()
1905 conn->cn_session = ses; in __nfsd4_hash_conn()
1906 list_add(&conn->cn_persession, &ses->se_conns); in __nfsd4_hash_conn()
1911 struct nfs4_client *clp = ses->se_client; in nfsd4_hash_conn()
1913 spin_lock(&clp->cl_lock); in nfsd4_hash_conn()
1915 spin_unlock(&clp->cl_lock); in nfsd4_hash_conn()
1920 conn->cn_xpt_user.callback = nfsd4_conn_lost; in nfsd4_register_conn()
1921 return register_xpt_user(conn->cn_xprt, &conn->cn_xpt_user); in nfsd4_register_conn()
1932 nfsd4_conn_lost(&conn->cn_xpt_user); in nfsd4_init_conn()
1934 nfsd4_probe_callback_sync(ses->se_client); in nfsd4_init_conn()
1941 if (cses->flags & SESSION4_BACK_CHAN) in alloc_conn_from_crses()
1949 struct nfs4_client *clp = s->se_client; in nfsd4_del_conns()
1952 spin_lock(&clp->cl_lock); in nfsd4_del_conns()
1953 while (!list_empty(&s->se_conns)) { in nfsd4_del_conns()
1954 c = list_first_entry(&s->se_conns, struct nfsd4_conn, cn_persession); in nfsd4_del_conns()
1955 list_del_init(&c->cn_persession); in nfsd4_del_conns()
1956 spin_unlock(&clp->cl_lock); in nfsd4_del_conns()
1958 unregister_xpt_user(c->cn_xprt, &c->cn_xpt_user); in nfsd4_del_conns()
1961 spin_lock(&clp->cl_lock); in nfsd4_del_conns()
1963 spin_unlock(&clp->cl_lock); in nfsd4_del_conns()
1975 nfsd4_put_drc_mem(&ses->se_fchannel); in free_session()
1984 new->se_client = clp; in init_session()
1987 INIT_LIST_HEAD(&new->se_conns); in init_session()
1989 new->se_cb_seq_nr = 1; in init_session()
1990 new->se_flags = cses->flags; in init_session()
1991 new->se_cb_prog = cses->callback_prog; in init_session()
1992 new->se_cb_sec = cses->cb_sec; in init_session()
1993 atomic_set(&new->se_ref, 0); in init_session()
1994 idx = hash_sessionid(&new->se_sessionid); in init_session()
1995 list_add(&new->se_hash, &nn->sessionid_hashtbl[idx]); in init_session()
1996 spin_lock(&clp->cl_lock); in init_session()
1997 list_add(&new->se_perclnt, &clp->cl_sessions); in init_session()
1998 spin_unlock(&clp->cl_lock); in init_session()
2009 rpc_copy_addr((struct sockaddr *)&clp->cl_cb_conn.cb_addr, sa); in init_session()
2010 clp->cl_cb_conn.cb_addrlen = svc_addr_len(sa); in init_session()
2022 lockdep_assert_held(&nn->client_lock); in __find_in_sessionid_hashtbl()
2027 list_for_each_entry(elem, &nn->sessionid_hashtbl[idx], se_hash) { in __find_in_sessionid_hashtbl()
2028 if (!memcmp(elem->se_sessionid.data, sessionid->data, in __find_in_sessionid_hashtbl()
2060 struct nfs4_client *clp = ses->se_client; in unhash_session()
2061 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_session()
2063 lockdep_assert_held(&nn->client_lock); in unhash_session()
2065 list_del(&ses->se_hash); in unhash_session()
2066 spin_lock(&ses->se_client->cl_lock); in unhash_session()
2067 list_del(&ses->se_perclnt); in unhash_session()
2068 spin_unlock(&ses->se_client->cl_lock); in unhash_session()
2080 if (clid->cl_boot == (u32)nn->boot_time) in STALE_CLIENTID()
2097 if (atomic_read(&nn->nfs4_client_count) >= nn->nfs4_max_clients) { in alloc_client()
2098 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in alloc_client()
2104 xdr_netobj_dup(&clp->cl_name, &name, GFP_KERNEL); in alloc_client()
2105 if (clp->cl_name.data == NULL) in alloc_client()
2107 clp->cl_ownerstr_hashtbl = kmalloc_array(OWNER_HASH_SIZE, in alloc_client()
2110 if (!clp->cl_ownerstr_hashtbl) in alloc_client()
2113 INIT_LIST_HEAD(&clp->cl_ownerstr_hashtbl[i]); in alloc_client()
2114 INIT_LIST_HEAD(&clp->cl_sessions); in alloc_client()
2115 idr_init(&clp->cl_stateids); in alloc_client()
2116 atomic_set(&clp->cl_rpc_users, 0); in alloc_client()
2117 clp->cl_cb_state = NFSD4_CB_UNKNOWN; in alloc_client()
2118 clp->cl_state = NFSD4_ACTIVE; in alloc_client()
2119 atomic_inc(&nn->nfs4_client_count); in alloc_client()
2120 atomic_set(&clp->cl_delegs_in_recall, 0); in alloc_client()
2121 INIT_LIST_HEAD(&clp->cl_idhash); in alloc_client()
2122 INIT_LIST_HEAD(&clp->cl_openowners); in alloc_client()
2123 INIT_LIST_HEAD(&clp->cl_delegations); in alloc_client()
2124 INIT_LIST_HEAD(&clp->cl_lru); in alloc_client()
2125 INIT_LIST_HEAD(&clp->cl_revoked); in alloc_client()
2127 INIT_LIST_HEAD(&clp->cl_lo_states); in alloc_client()
2129 INIT_LIST_HEAD(&clp->async_copies); in alloc_client()
2130 spin_lock_init(&clp->async_lock); in alloc_client()
2131 spin_lock_init(&clp->cl_lock); in alloc_client()
2132 rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table"); in alloc_client()
2135 kfree(clp->cl_name.data); in alloc_client()
2146 free_svc_cred(&clp->cl_cred); in __free_client()
2147 kfree(clp->cl_ownerstr_hashtbl); in __free_client()
2148 kfree(clp->cl_name.data); in __free_client()
2149 kfree(clp->cl_nii_domain.data); in __free_client()
2150 kfree(clp->cl_nii_name.data); in __free_client()
2151 idr_destroy(&clp->cl_stateids); in __free_client()
2152 kfree(clp->cl_ra); in __free_client()
2158 kref_put(&clp->cl_nfsdfs.cl_ref, __free_client); in drop_client()
2164 while (!list_empty(&clp->cl_sessions)) { in free_client()
2166 ses = list_entry(clp->cl_sessions.next, struct nfsd4_session, in free_client()
2168 list_del(&ses->se_perclnt); in free_client()
2169 WARN_ON_ONCE(atomic_read(&ses->se_ref)); in free_client()
2172 rpc_destroy_wait_queue(&clp->cl_cb_waitq); in free_client()
2173 if (clp->cl_nfsd_dentry) { in free_client()
2174 nfsd_client_rmdir(clp->cl_nfsd_dentry); in free_client()
2175 clp->cl_nfsd_dentry = NULL; in free_client()
2185 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_client_locked()
2188 lockdep_assert_held(&nn->client_lock); in unhash_client_locked()
2191 clp->cl_time = 0; in unhash_client_locked()
2193 if (!list_empty(&clp->cl_idhash)) { in unhash_client_locked()
2194 list_del_init(&clp->cl_idhash); in unhash_client_locked()
2195 if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) in unhash_client_locked()
2196 rb_erase(&clp->cl_namenode, &nn->conf_name_tree); in unhash_client_locked()
2198 rb_erase(&clp->cl_namenode, &nn->unconf_name_tree); in unhash_client_locked()
2200 list_del_init(&clp->cl_lru); in unhash_client_locked()
2201 spin_lock(&clp->cl_lock); in unhash_client_locked()
2202 list_for_each_entry(ses, &clp->cl_sessions, se_perclnt) in unhash_client_locked()
2203 list_del_init(&ses->se_hash); in unhash_client_locked()
2204 spin_unlock(&clp->cl_lock); in unhash_client_locked()
2210 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_client()
2212 spin_lock(&nn->client_lock); in unhash_client()
2214 spin_unlock(&nn->client_lock); in unhash_client()
2219 if (atomic_read(&clp->cl_rpc_users)) in mark_client_expired_locked()
2228 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in __destroy_client()
2236 while (!list_empty(&clp->cl_delegations)) { in __destroy_client()
2237 dp = list_entry(clp->cl_delegations.next, struct nfs4_delegation, dl_perclnt); in __destroy_client()
2239 list_add(&dp->dl_recall_lru, &reaplist); in __destroy_client()
2244 list_del_init(&dp->dl_recall_lru); in __destroy_client()
2247 while (!list_empty(&clp->cl_revoked)) { in __destroy_client()
2248 dp = list_entry(clp->cl_revoked.next, struct nfs4_delegation, dl_recall_lru); in __destroy_client()
2249 list_del_init(&dp->dl_recall_lru); in __destroy_client()
2250 nfs4_put_stid(&dp->dl_stid); in __destroy_client()
2252 while (!list_empty(&clp->cl_openowners)) { in __destroy_client()
2253 oo = list_entry(clp->cl_openowners.next, struct nfs4_openowner, oo_perclient); in __destroy_client()
2254 nfs4_get_stateowner(&oo->oo_owner); in __destroy_client()
2260 list_for_each_entry_safe(so, tmp, &clp->cl_ownerstr_hashtbl[i], in __destroy_client()
2263 WARN_ON_ONCE(so->so_is_open_owner); in __destroy_client()
2270 if (clp->cl_cb_conn.cb_xprt) in __destroy_client()
2271 svc_xprt_put(clp->cl_cb_conn.cb_xprt); in __destroy_client()
2272 atomic_add_unless(&nn->nfs4_client_count, -1, 0); in __destroy_client()
2287 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in inc_reclaim_complete()
2289 if (!nn->track_reclaim_completes) in inc_reclaim_complete()
2291 if (!nfsd4_find_reclaim_client(clp->cl_name, nn)) in inc_reclaim_complete()
2293 if (atomic_inc_return(&nn->nr_reclaim_complete) == in inc_reclaim_complete()
2294 nn->reclaim_str_hashtbl_size) { in inc_reclaim_complete()
2296 clp->net->ns.inum); in inc_reclaim_complete()
2310 memcpy(target->cl_verifier.data, source->data, in copy_verf()
2311 sizeof(target->cl_verifier.data)); in copy_verf()
2316 target->cl_clientid.cl_boot = source->cl_clientid.cl_boot; in copy_clid()
2317 target->cl_clientid.cl_id = source->cl_clientid.cl_id; in copy_clid()
2322 target->cr_principal = kstrdup(source->cr_principal, GFP_KERNEL); in copy_cred()
2323 target->cr_raw_principal = kstrdup(source->cr_raw_principal, in copy_cred()
2325 target->cr_targ_princ = kstrdup(source->cr_targ_princ, GFP_KERNEL); in copy_cred()
2326 if ((source->cr_principal && !target->cr_principal) || in copy_cred()
2327 (source->cr_raw_principal && !target->cr_raw_principal) || in copy_cred()
2328 (source->cr_targ_princ && !target->cr_targ_princ)) in copy_cred()
2329 return -ENOMEM; in copy_cred()
2331 target->cr_flavor = source->cr_flavor; in copy_cred()
2332 target->cr_uid = source->cr_uid; in copy_cred()
2333 target->cr_gid = source->cr_gid; in copy_cred()
2334 target->cr_group_info = source->cr_group_info; in copy_cred()
2335 get_group_info(target->cr_group_info); in copy_cred()
2336 target->cr_gss_mech = source->cr_gss_mech; in copy_cred()
2337 if (source->cr_gss_mech) in copy_cred()
2338 gss_mech_get(source->cr_gss_mech); in copy_cred()
2345 if (o1->len < o2->len) in compare_blob()
2346 return -1; in compare_blob()
2347 if (o1->len > o2->len) in compare_blob()
2349 return memcmp(o1->data, o2->data, o1->len); in compare_blob()
2355 return 0 == memcmp(v1->data, v2->data, sizeof(v1->data)); in same_verf()
2361 return (cl1->cl_boot == cl2->cl_boot) && (cl1->cl_id == cl2->cl_id); in same_clid()
2368 if (g1->ngroups != g2->ngroups) in groups_equal()
2370 for (i=0; i<g1->ngroups; i++) in groups_equal()
2371 if (!gid_eq(g1->gid[i], g2->gid[i])) in groups_equal()
2380 * approximation. We also don't want to allow non-gss use of a client
2388 return (cr->cr_flavor > RPC_AUTH_MAXFLAVOR); in is_gss_cred()
2396 || (!uid_eq(cr1->cr_uid, cr2->cr_uid)) in same_creds()
2397 || (!gid_eq(cr1->cr_gid, cr2->cr_gid)) in same_creds()
2398 || !groups_equal(cr1->cr_group_info, cr2->cr_group_info)) in same_creds()
2401 if (cr1->cr_principal == cr2->cr_principal) in same_creds()
2403 if (!cr1->cr_principal || !cr2->cr_principal) in same_creds()
2405 return 0 == strcmp(cr1->cr_principal, cr2->cr_principal); in same_creds()
2410 struct svc_cred *cr = &rqstp->rq_cred; in svc_rqst_integrity_protected()
2413 if (!cr->cr_gss_mech) in svc_rqst_integrity_protected()
2415 service = gss_pseudoflavor_to_service(cr->cr_gss_mech, cr->cr_flavor); in svc_rqst_integrity_protected()
2422 struct svc_cred *cr = &rqstp->rq_cred; in nfsd4_mach_creds_match()
2424 if (!cl->cl_mach_cred) in nfsd4_mach_creds_match()
2426 if (cl->cl_cred.cr_gss_mech != cr->cr_gss_mech) in nfsd4_mach_creds_match()
2430 if (cl->cl_cred.cr_raw_principal) in nfsd4_mach_creds_match()
2431 return 0 == strcmp(cl->cl_cred.cr_raw_principal, in nfsd4_mach_creds_match()
2432 cr->cr_raw_principal); in nfsd4_mach_creds_match()
2433 if (!cr->cr_principal) in nfsd4_mach_creds_match()
2435 return 0 == strcmp(cl->cl_cred.cr_principal, cr->cr_principal); in nfsd4_mach_creds_match()
2443 * This is opaque to client, so no need to byte-swap. Use in gen_confirm()
2447 verf[1] = (__force __be32)nn->clverifier_counter++; in gen_confirm()
2448 memcpy(clp->cl_confirm.data, verf, sizeof(clp->cl_confirm.data)); in gen_confirm()
2453 clp->cl_clientid.cl_boot = (u32)nn->boot_time; in gen_clid()
2454 clp->cl_clientid.cl_id = nn->clientid_counter++; in gen_clid()
2463 ret = idr_find(&cl->cl_stateids, t->si_opaque.so_id); in find_stateid_locked()
2464 if (!ret || !ret->sc_type) in find_stateid_locked()
2474 spin_lock(&cl->cl_lock); in find_stateid_by_type()
2477 if (typemask & s->sc_type) in find_stateid_by_type()
2478 refcount_inc(&s->sc_count); in find_stateid_by_type()
2482 spin_unlock(&cl->cl_lock); in find_stateid_by_type()
2519 struct inode *inode = file_inode(m->file); in client_info_show()
2525 return -ENXIO; in client_info_show()
2526 memcpy(&clid, &clp->cl_clientid, sizeof(clid)); in client_info_show()
2528 seq_printf(m, "address: \"%pISpc\"\n", (struct sockaddr *)&clp->cl_addr); in client_info_show()
2530 if (clp->cl_state == NFSD4_COURTESY) in client_info_show()
2532 else if (clp->cl_state == NFSD4_EXPIRABLE) in client_info_show()
2534 else if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) in client_info_show()
2539 ktime_get_boottime_seconds() - clp->cl_time); in client_info_show()
2541 seq_quote_mem(m, clp->cl_name.data, clp->cl_name.len); in client_info_show()
2542 seq_printf(m, "\nminor version: %d\n", clp->cl_minorversion); in client_info_show()
2543 if (clp->cl_nii_domain.data) { in client_info_show()
2545 seq_quote_mem(m, clp->cl_nii_domain.data, in client_info_show()
2546 clp->cl_nii_domain.len); in client_info_show()
2548 seq_quote_mem(m, clp->cl_nii_name.data, clp->cl_nii_name.len); in client_info_show()
2550 clp->cl_nii_time.tv_sec, clp->cl_nii_time.tv_nsec); in client_info_show()
2552 seq_printf(m, "callback state: %s\n", cb_state2str(clp->cl_cb_state)); in client_info_show()
2553 seq_printf(m, "callback address: %pISpc\n", &clp->cl_cb_conn.cb_addr); in client_info_show()
2562 __acquires(&clp->cl_lock) in states_start()
2564 struct nfs4_client *clp = s->private; in states_start()
2568 spin_lock(&clp->cl_lock); in states_start()
2569 ret = idr_get_next_ul(&clp->cl_stateids, &id); in states_start()
2576 struct nfs4_client *clp = s->private; in states_next()
2582 ret = idr_get_next_ul(&clp->cl_stateids, &id); in states_next()
2588 __releases(&clp->cl_lock) in states_stop()
2590 struct nfs4_client *clp = s->private; in states_stop()
2592 spin_unlock(&clp->cl_lock); in states_stop()
2597 seq_printf(s, "filename: \"%pD2\"", f->nf_file); in nfs4_show_fname()
2602 struct inode *inode = file_inode(f->nf_file); in nfs4_show_superblock()
2605 MAJOR(inode->i_sb->s_dev), in nfs4_show_superblock()
2606 MINOR(inode->i_sb->s_dev), in nfs4_show_superblock()
2607 inode->i_ino); in nfs4_show_superblock()
2613 seq_quote_mem(s, oo->so_owner.data, oo->so_owner.len); in nfs4_show_owner()
2618 seq_printf(s, "0x%.8x", stid->si_generation); in nfs4_show_stateid()
2619 seq_printf(s, "%12phN", &stid->si_opaque); in nfs4_show_stateid()
2630 if (st->sc_type != NFS4_OPEN_STID && st->sc_type != NFS4_LOCK_STID) in nfs4_show_open()
2633 oo = ols->st_stateowner; in nfs4_show_open()
2634 nf = st->sc_file; in nfs4_show_open()
2636 spin_lock(&nf->fi_lock); in nfs4_show_open()
2641 seq_printf(s, "- "); in nfs4_show_open()
2642 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_open()
2645 access = bmap_to_share_mode(ols->st_access_bmap); in nfs4_show_open()
2646 deny = bmap_to_share_mode(ols->st_deny_bmap); in nfs4_show_open()
2649 access & NFS4_SHARE_ACCESS_READ ? "r" : "-", in nfs4_show_open()
2650 access & NFS4_SHARE_ACCESS_WRITE ? "w" : "-"); in nfs4_show_open()
2652 deny & NFS4_SHARE_ACCESS_READ ? "r" : "-", in nfs4_show_open()
2653 deny & NFS4_SHARE_ACCESS_WRITE ? "w" : "-"); in nfs4_show_open()
2662 spin_unlock(&nf->fi_lock); in nfs4_show_open()
2674 oo = ols->st_stateowner; in nfs4_show_lock()
2675 nf = st->sc_file; in nfs4_show_lock()
2676 spin_lock(&nf->fi_lock); in nfs4_show_lock()
2681 seq_printf(s, "- "); in nfs4_show_lock()
2682 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_lock()
2700 spin_unlock(&nf->fi_lock); in nfs4_show_lock()
2711 nf = st->sc_file; in nfs4_show_deleg()
2712 spin_lock(&nf->fi_lock); in nfs4_show_deleg()
2713 file = nf->fi_deleg_file; in nfs4_show_deleg()
2717 seq_printf(s, "- "); in nfs4_show_deleg()
2718 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_deleg()
2723 ds->dl_type == NFS4_OPEN_DELEGATE_READ ? "r" : "w"); in nfs4_show_deleg()
2732 spin_unlock(&nf->fi_lock); in nfs4_show_deleg()
2742 file = ls->ls_file; in nfs4_show_layout()
2744 seq_printf(s, "- "); in nfs4_show_layout()
2745 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_layout()
2762 switch (st->sc_type) { in states_show()
2792 return -ENXIO; in client_states_open()
2797 s = file->private_data; in client_states_open()
2798 s->private = clp; in client_states_open()
2804 struct seq_file *m = file->private_data; in client_opens_release()
2805 struct nfs4_client *clp = m->private; in client_opens_release()
2827 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in force_expire_client()
2830 trace_nfsd_clid_admin_expired(&clp->cl_clientid); in force_expire_client()
2832 spin_lock(&nn->client_lock); in force_expire_client()
2833 clp->cl_time = 0; in force_expire_client()
2834 spin_unlock(&nn->client_lock); in force_expire_client()
2836 wait_event(expiry_wq, atomic_read(&clp->cl_rpc_users) == 0); in force_expire_client()
2837 spin_lock(&nn->client_lock); in force_expire_client()
2838 already_expired = list_empty(&clp->cl_lru); in force_expire_client()
2841 spin_unlock(&nn->client_lock); in force_expire_client()
2846 wait_event(expiry_wq, clp->cl_nfsd_dentry == NULL); in force_expire_client()
2859 return -EINVAL; in client_ctl_write()
2862 return -ENXIO; in client_ctl_write()
2885 switch (task->tk_status) { in nfsd4_cb_recall_any_done()
2886 case -NFS4ERR_DELAY: in nfsd4_cb_recall_any_done()
2897 struct nfs4_client *clp = cb->cb_clp; in nfsd4_cb_recall_any_release()
2899 clear_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags); in nfsd4_cb_recall_any_release()
2922 ret = copy_cred(&clp->cl_cred, &rqstp->rq_cred); in create_client()
2928 kref_init(&clp->cl_nfsdfs.cl_ref); in create_client()
2929 nfsd4_init_cb(&clp->cl_cb_null, clp, NULL, NFSPROC4_CLNT_CB_NULL); in create_client()
2930 clp->cl_time = ktime_get_boottime_seconds(); in create_client()
2931 clear_bit(0, &clp->cl_cb_slot_busy); in create_client()
2933 memcpy(&clp->cl_addr, sa, sizeof(struct sockaddr_storage)); in create_client()
2934 clp->cl_cb_session = NULL; in create_client()
2935 clp->net = net; in create_client()
2936 clp->cl_nfsd_dentry = nfsd_client_mkdir( in create_client()
2937 nn, &clp->cl_nfsdfs, in create_client()
2938 clp->cl_clientid.cl_id - nn->clientid_base, in create_client()
2940 clp->cl_nfsd_info_dentry = dentries[0]; in create_client()
2941 if (!clp->cl_nfsd_dentry) { in create_client()
2945 clp->cl_ra = kzalloc(sizeof(*clp->cl_ra), GFP_KERNEL); in create_client()
2946 if (!clp->cl_ra) { in create_client()
2950 clp->cl_ra_time = 0; in create_client()
2951 nfsd4_init_cb(&clp->cl_ra->ra_cb, clp, &nfsd4_cb_recall_any_ops, in create_client()
2959 struct rb_node **new = &(root->rb_node), *parent = NULL; in add_clp_to_name_tree()
2966 if (compare_blob(&clp->cl_name, &new_clp->cl_name) > 0) in add_clp_to_name_tree()
2967 new = &((*new)->rb_left); in add_clp_to_name_tree()
2969 new = &((*new)->rb_right); in add_clp_to_name_tree()
2972 rb_link_node(&new_clp->cl_namenode, parent, new); in add_clp_to_name_tree()
2973 rb_insert_color(&new_clp->cl_namenode, root); in add_clp_to_name_tree()
2980 struct rb_node *node = root->rb_node; in find_clp_in_name_tree()
2985 cmp = compare_blob(&clp->cl_name, name); in find_clp_in_name_tree()
2987 node = node->rb_left; in find_clp_in_name_tree()
2989 node = node->rb_right; in find_clp_in_name_tree()
3000 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in add_to_unconfirmed()
3002 lockdep_assert_held(&nn->client_lock); in add_to_unconfirmed()
3004 clear_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags); in add_to_unconfirmed()
3005 add_clp_to_name_tree(clp, &nn->unconf_name_tree); in add_to_unconfirmed()
3006 idhashval = clientid_hashval(clp->cl_clientid.cl_id); in add_to_unconfirmed()
3007 list_add(&clp->cl_idhash, &nn->unconf_id_hashtbl[idhashval]); in add_to_unconfirmed()
3014 unsigned int idhashval = clientid_hashval(clp->cl_clientid.cl_id); in move_to_confirmed()
3015 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in move_to_confirmed()
3017 lockdep_assert_held(&nn->client_lock); in move_to_confirmed()
3019 list_move(&clp->cl_idhash, &nn->conf_id_hashtbl[idhashval]); in move_to_confirmed()
3020 rb_erase(&clp->cl_namenode, &nn->unconf_name_tree); in move_to_confirmed()
3021 add_clp_to_name_tree(clp, &nn->conf_name_tree); in move_to_confirmed()
3022 set_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags); in move_to_confirmed()
3023 trace_nfsd_clid_confirmed(&clp->cl_clientid); in move_to_confirmed()
3031 unsigned int idhashval = clientid_hashval(clid->cl_id); in find_client_in_id_table()
3034 if (same_clid(&clp->cl_clientid, clid)) { in find_client_in_id_table()
3035 if ((bool)clp->cl_minorversion != sessions) in find_client_in_id_table()
3047 struct list_head *tbl = nn->conf_id_hashtbl; in find_confirmed_client()
3049 lockdep_assert_held(&nn->client_lock); in find_confirmed_client()
3056 struct list_head *tbl = nn->unconf_id_hashtbl; in find_unconfirmed_client()
3058 lockdep_assert_held(&nn->client_lock); in find_unconfirmed_client()
3064 return clp->cl_exchange_flags != 0; in clp_used_exchangeid()
3070 lockdep_assert_held(&nn->client_lock); in find_confirmed_client_by_name()
3071 return find_clp_in_name_tree(name, &nn->conf_name_tree); in find_confirmed_client_by_name()
3077 lockdep_assert_held(&nn->client_lock); in find_unconfirmed_client_by_name()
3078 return find_clp_in_name_tree(name, &nn->unconf_name_tree); in find_unconfirmed_client_by_name()
3084 struct nfs4_cb_conn *conn = &clp->cl_cb_conn; in gen_callback()
3090 if (se->se_callback_netid_len == 3 && in gen_callback()
3091 !memcmp(se->se_callback_netid_val, "tcp", 3)) in gen_callback()
3093 else if (se->se_callback_netid_len == 4 && in gen_callback()
3094 !memcmp(se->se_callback_netid_val, "tcp6", 4)) in gen_callback()
3099 conn->cb_addrlen = rpc_uaddr2sockaddr(clp->net, se->se_callback_addr_val, in gen_callback()
3100 se->se_callback_addr_len, in gen_callback()
3101 (struct sockaddr *)&conn->cb_addr, in gen_callback()
3102 sizeof(conn->cb_addr)); in gen_callback()
3104 if (!conn->cb_addrlen || conn->cb_addr.ss_family != expected_family) in gen_callback()
3107 if (conn->cb_addr.ss_family == AF_INET6) in gen_callback()
3108 ((struct sockaddr_in6 *)&conn->cb_addr)->sin6_scope_id = scopeid; in gen_callback()
3110 conn->cb_prog = se->se_callback_prog; in gen_callback()
3111 conn->cb_ident = se->se_callback_ident; in gen_callback()
3112 memcpy(&conn->cb_saddr, &rqstp->rq_daddr, rqstp->rq_daddrlen); in gen_callback()
3116 conn->cb_addr.ss_family = AF_UNSPEC; in gen_callback()
3117 conn->cb_addrlen = 0; in gen_callback()
3128 struct xdr_buf *buf = resp->xdr->buf; in nfsd4_store_cache_entry()
3129 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_store_cache_entry()
3132 dprintk("--> %s slot %p\n", __func__, slot); in nfsd4_store_cache_entry()
3134 slot->sl_flags |= NFSD4_SLOT_INITIALIZED; in nfsd4_store_cache_entry()
3135 slot->sl_opcnt = resp->opcnt; in nfsd4_store_cache_entry()
3136 slot->sl_status = resp->cstate.status; in nfsd4_store_cache_entry()
3137 free_svc_cred(&slot->sl_cred); in nfsd4_store_cache_entry()
3138 copy_cred(&slot->sl_cred, &resp->rqstp->rq_cred); in nfsd4_store_cache_entry()
3141 slot->sl_flags &= ~NFSD4_SLOT_CACHED; in nfsd4_store_cache_entry()
3144 slot->sl_flags |= NFSD4_SLOT_CACHED; in nfsd4_store_cache_entry()
3146 base = resp->cstate.data_offset; in nfsd4_store_cache_entry()
3147 slot->sl_datalen = buf->len - base; in nfsd4_store_cache_entry()
3148 if (read_bytes_from_xdr_buf(buf, base, slot->sl_data, slot->sl_datalen)) in nfsd4_store_cache_entry()
3157 * operation which sets resp->p and increments resp->opcnt for
3166 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_enc_sequence_replay()
3169 op = &args->ops[resp->opcnt - 1]; in nfsd4_enc_sequence_replay()
3172 if (slot->sl_flags & NFSD4_SLOT_CACHED) in nfsd4_enc_sequence_replay()
3173 return op->status; in nfsd4_enc_sequence_replay()
3174 if (args->opcnt == 1) { in nfsd4_enc_sequence_replay()
3176 * The original operation wasn't a solo sequence--we in nfsd4_enc_sequence_replay()
3177 * always cache those--so this retry must not match the in nfsd4_enc_sequence_replay()
3180 op->status = nfserr_seq_false_retry; in nfsd4_enc_sequence_replay()
3182 op = &args->ops[resp->opcnt++]; in nfsd4_enc_sequence_replay()
3183 op->status = nfserr_retry_uncached_rep; in nfsd4_enc_sequence_replay()
3186 return op->status; in nfsd4_enc_sequence_replay()
3197 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_replay_cache_entry()
3198 struct xdr_stream *xdr = resp->xdr; in nfsd4_replay_cache_entry()
3202 dprintk("--> %s slot %p\n", __func__, slot); in nfsd4_replay_cache_entry()
3204 status = nfsd4_enc_sequence_replay(resp->rqstp->rq_argp, resp); in nfsd4_replay_cache_entry()
3208 p = xdr_reserve_space(xdr, slot->sl_datalen); in nfsd4_replay_cache_entry()
3213 xdr_encode_opaque_fixed(p, slot->sl_data, slot->sl_datalen); in nfsd4_replay_cache_entry()
3216 resp->opcnt = slot->sl_opcnt; in nfsd4_replay_cache_entry()
3217 return slot->sl_status; in nfsd4_replay_cache_entry()
3227 new->cl_exchange_flags |= EXCHGID4_FLAG_USE_PNFS_MDS; in nfsd4_set_ex_flags()
3229 new->cl_exchange_flags |= EXCHGID4_FLAG_USE_NON_PNFS; in nfsd4_set_ex_flags()
3233 new->cl_exchange_flags |= EXCHGID4_FLAG_SUPP_MOVED_REFER; in nfsd4_set_ex_flags()
3236 clid->flags = new->cl_exchange_flags; in nfsd4_set_ex_flags()
3243 list_for_each_entry(oo, &clp->cl_openowners, oo_perclient) { in client_has_openowners()
3244 if (!list_empty(&oo->oo_owner.so_stateids)) in client_has_openowners()
3254 || !list_empty(&clp->cl_lo_states) in client_has_state()
3256 || !list_empty(&clp->cl_delegations) in client_has_state()
3257 || !list_empty(&clp->cl_sessions) in client_has_state()
3258 || !list_empty(&clp->async_copies); in client_has_state()
3264 if (!exid->nii_domain.data) in copy_impl_id()
3266 xdr_netobj_dup(&clp->cl_nii_domain, &exid->nii_domain, GFP_KERNEL); in copy_impl_id()
3267 if (!clp->cl_nii_domain.data) in copy_impl_id()
3269 xdr_netobj_dup(&clp->cl_nii_name, &exid->nii_name, GFP_KERNEL); in copy_impl_id()
3270 if (!clp->cl_nii_name.data) in copy_impl_id()
3272 clp->cl_nii_time = exid->nii_time; in copy_impl_id()
3280 struct nfsd4_exchange_id *exid = &u->exchange_id; in nfsd4_exchange_id()
3285 nfs4_verifier verf = exid->verifier; in nfsd4_exchange_id()
3287 bool update = exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A; in nfsd4_exchange_id()
3293 __func__, rqstp, exid, exid->clname.len, exid->clname.data, in nfsd4_exchange_id()
3294 addr_str, exid->flags, exid->spa_how); in nfsd4_exchange_id()
3296 if (exid->flags & ~EXCHGID4_FLAG_MASK_A) in nfsd4_exchange_id()
3299 new = create_client(exid->clname, rqstp, &verf); in nfsd4_exchange_id()
3306 switch (exid->spa_how) { in nfsd4_exchange_id()
3308 exid->spo_must_enforce[0] = 0; in nfsd4_exchange_id()
3309 exid->spo_must_enforce[1] = ( in nfsd4_exchange_id()
3310 1 << (OP_BIND_CONN_TO_SESSION - 32) | in nfsd4_exchange_id()
3311 1 << (OP_EXCHANGE_ID - 32) | in nfsd4_exchange_id()
3312 1 << (OP_CREATE_SESSION - 32) | in nfsd4_exchange_id()
3313 1 << (OP_DESTROY_SESSION - 32) | in nfsd4_exchange_id()
3314 1 << (OP_DESTROY_CLIENTID - 32)); in nfsd4_exchange_id()
3316 exid->spo_must_allow[0] &= (1 << (OP_CLOSE) | in nfsd4_exchange_id()
3321 exid->spo_must_allow[1] &= ( in nfsd4_exchange_id()
3322 1 << (OP_TEST_STATEID - 32) | in nfsd4_exchange_id()
3323 1 << (OP_FREE_STATEID - 32)); in nfsd4_exchange_id()
3333 if (!new->cl_cred.cr_principal && in nfsd4_exchange_id()
3334 !new->cl_cred.cr_raw_principal) { in nfsd4_exchange_id()
3338 new->cl_mach_cred = true; in nfsd4_exchange_id()
3351 spin_lock(&nn->client_lock); in nfsd4_exchange_id()
3352 conf = find_confirmed_client_by_name(&exid->clname, nn); in nfsd4_exchange_id()
3354 bool creds_match = same_creds(&conf->cl_cred, &rqstp->rq_cred); in nfsd4_exchange_id()
3355 bool verfs_match = same_verf(&verf, &conf->cl_verifier); in nfsd4_exchange_id()
3375 exid->flags |= EXCHGID4_FLAG_CONFIRMED_R; in nfsd4_exchange_id()
3388 conf->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; in nfsd4_exchange_id()
3403 unconf = find_unconfirmed_client_by_name(&exid->clname, nn); in nfsd4_exchange_id()
3415 trace_nfsd_clid_replaced(&conf->cl_clientid); in nfsd4_exchange_id()
3417 new->cl_minorversion = cstate->minorversion; in nfsd4_exchange_id()
3418 new->cl_spo_must_allow.u.words[0] = exid->spo_must_allow[0]; in nfsd4_exchange_id()
3419 new->cl_spo_must_allow.u.words[1] = exid->spo_must_allow[1]; in nfsd4_exchange_id()
3424 exid->clientid.cl_boot = conf->cl_clientid.cl_boot; in nfsd4_exchange_id()
3425 exid->clientid.cl_id = conf->cl_clientid.cl_id; in nfsd4_exchange_id()
3427 exid->seqid = conf->cl_cs_slot.sl_seqid + 1; in nfsd4_exchange_id()
3431 conf->cl_cs_slot.sl_seqid, conf->cl_exchange_flags); in nfsd4_exchange_id()
3435 spin_unlock(&nn->client_lock); in nfsd4_exchange_id()
3440 trace_nfsd_clid_expire_unconf(&unconf->cl_clientid); in nfsd4_exchange_id()
3459 /* Note unsigned 32-bit arithmetic handles wraparound: */ in check_slot_seqid()
3470 * Do this for solo or embedded create session operations.
3476 slot->sl_status = nfserr; in nfsd4_cache_create_session()
3477 memcpy(&slot->sl_cr_ses, cr_ses, sizeof(*cr_ses)); in nfsd4_cache_create_session()
3484 memcpy(cr_ses, &slot->sl_cr_ses, sizeof(*cr_ses)); in nfsd4_replay_create_session()
3485 return slot->sl_status; in nfsd4_replay_create_session()
3507 u32 maxrpc = nn->nfsd_serv->sv_max_mesg; in check_forechannel_attrs()
3509 if (ca->maxreq_sz < NFSD_MIN_REQ_HDR_SEQ_SZ) in check_forechannel_attrs()
3511 if (ca->maxresp_sz < NFSD_MIN_RESP_HDR_SEQ_SZ) in check_forechannel_attrs()
3513 ca->headerpadsz = 0; in check_forechannel_attrs()
3514 ca->maxreq_sz = min_t(u32, ca->maxreq_sz, maxrpc); in check_forechannel_attrs()
3515 ca->maxresp_sz = min_t(u32, ca->maxresp_sz, maxrpc); in check_forechannel_attrs()
3516 ca->maxops = min_t(u32, ca->maxops, NFSD_MAX_OPS_PER_COMPOUND); in check_forechannel_attrs()
3517 ca->maxresp_cached = min_t(u32, ca->maxresp_cached, in check_forechannel_attrs()
3519 ca->maxreqs = min_t(u32, ca->maxreqs, NFSD_MAX_SLOTS_PER_SESSION); in check_forechannel_attrs()
3530 ca->maxreqs = nfsd4_get_drc_mem(ca, nn); in check_forechannel_attrs()
3536 * Server's NFSv4.1 backchannel support is AUTH_SYS-only for now.
3553 ca->headerpadsz = 0; in check_backchannel_attrs()
3555 if (ca->maxreq_sz < NFSD_CB_MAX_REQ_SZ) in check_backchannel_attrs()
3557 if (ca->maxresp_sz < NFSD_CB_MAX_RESP_SZ) in check_backchannel_attrs()
3559 ca->maxresp_cached = 0; in check_backchannel_attrs()
3560 if (ca->maxops < 2) in check_backchannel_attrs()
3568 switch (cbs->flavor) { in nfsd4_check_cb_sec()
3588 struct nfsd4_create_session *cr_ses = &u->create_session; in nfsd4_create_session()
3598 if (cr_ses->flags & ~SESSION4_FLAG_MASK_A) in nfsd4_create_session()
3600 status = nfsd4_check_cb_sec(&cr_ses->cb_sec); in nfsd4_create_session()
3603 status = check_forechannel_attrs(&cr_ses->fore_channel, nn); in nfsd4_create_session()
3606 status = check_backchannel_attrs(&cr_ses->back_channel); in nfsd4_create_session()
3610 new = alloc_session(&cr_ses->fore_channel, &cr_ses->back_channel); in nfsd4_create_session()
3617 spin_lock(&nn->client_lock); in nfsd4_create_session()
3618 unconf = find_unconfirmed_client(&cr_ses->clientid, true, nn); in nfsd4_create_session()
3619 conf = find_confirmed_client(&cr_ses->clientid, true, nn); in nfsd4_create_session()
3626 cs_slot = &conf->cl_cs_slot; in nfsd4_create_session()
3627 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); in nfsd4_create_session()
3635 if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred) || in nfsd4_create_session()
3636 !rpc_cmp_addr(sa, (struct sockaddr *) &unconf->cl_addr)) { in nfsd4_create_session()
3643 cs_slot = &unconf->cl_cs_slot; in nfsd4_create_session()
3644 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); in nfsd4_create_session()
3650 old = find_confirmed_client_by_name(&unconf->cl_name, nn); in nfsd4_create_session()
3657 trace_nfsd_clid_replaced(&old->cl_clientid); in nfsd4_create_session()
3667 cr_ses->flags &= ~SESSION4_PERSIST; in nfsd4_create_session()
3669 cr_ses->flags &= ~SESSION4_RDMA; in nfsd4_create_session()
3674 memcpy(cr_ses->sessionid.data, new->se_sessionid.data, in nfsd4_create_session()
3676 cs_slot->sl_seqid++; in nfsd4_create_session()
3677 cr_ses->seqid = cs_slot->sl_seqid; in nfsd4_create_session()
3679 /* cache solo and embedded create sessions under the client_lock */ in nfsd4_create_session()
3681 spin_unlock(&nn->client_lock); in nfsd4_create_session()
3683 fsnotify_dentry(conf->cl_nfsd_info_dentry, FS_MODIFY); in nfsd4_create_session()
3691 spin_unlock(&nn->client_lock); in nfsd4_create_session()
3698 nfsd4_put_drc_mem(&cr_ses->fore_channel); in nfsd4_create_session()
3720 struct nfsd4_backchannel_ctl *bc = &u->backchannel_ctl; in nfsd4_backchannel_ctl()
3721 struct nfsd4_session *session = cstate->session; in nfsd4_backchannel_ctl()
3725 status = nfsd4_check_cb_sec(&bc->bc_cb_sec); in nfsd4_backchannel_ctl()
3728 spin_lock(&nn->client_lock); in nfsd4_backchannel_ctl()
3729 session->se_cb_prog = bc->bc_cb_program; in nfsd4_backchannel_ctl()
3730 session->se_cb_sec = bc->bc_cb_sec; in nfsd4_backchannel_ctl()
3731 spin_unlock(&nn->client_lock); in nfsd4_backchannel_ctl()
3733 nfsd4_probe_callback(session->se_client); in nfsd4_backchannel_ctl()
3742 list_for_each_entry(c, &s->se_conns, cn_persession) { in __nfsd4_find_conn()
3743 if (c->cn_xprt == xpt) { in __nfsd4_find_conn()
3753 struct nfs4_client *clp = session->se_client; in nfsd4_match_existing_connection()
3754 struct svc_xprt *xpt = rqst->rq_xprt; in nfsd4_match_existing_connection()
3759 spin_lock(&clp->cl_lock); in nfsd4_match_existing_connection()
3763 else if (req == c->cn_flags) in nfsd4_match_existing_connection()
3766 c->cn_flags != NFS4_CDFC4_BACK) in nfsd4_match_existing_connection()
3769 c->cn_flags != NFS4_CDFC4_FORE) in nfsd4_match_existing_connection()
3773 spin_unlock(&clp->cl_lock); in nfsd4_match_existing_connection()
3783 struct nfsd4_bind_conn_to_session *bcts = &u->bind_conn_to_session; in nfsd4_bind_conn_to_session()
3792 spin_lock(&nn->client_lock); in nfsd4_bind_conn_to_session()
3793 session = find_in_sessionid_hashtbl(&bcts->sessionid, net, &status); in nfsd4_bind_conn_to_session()
3794 spin_unlock(&nn->client_lock); in nfsd4_bind_conn_to_session()
3798 if (!nfsd4_mach_creds_match(session->se_client, rqstp)) in nfsd4_bind_conn_to_session()
3801 bcts->dir, &conn); in nfsd4_bind_conn_to_session()
3803 if (bcts->dir == NFS4_CDFC4_FORE_OR_BOTH || in nfsd4_bind_conn_to_session()
3804 bcts->dir == NFS4_CDFC4_BACK) in nfsd4_bind_conn_to_session()
3805 conn->cn_flags |= NFS4_CDFC4_BACK; in nfsd4_bind_conn_to_session()
3806 nfsd4_probe_callback(session->se_client); in nfsd4_bind_conn_to_session()
3811 status = nfsd4_map_bcts_dir(&bcts->dir); in nfsd4_bind_conn_to_session()
3814 conn = alloc_conn(rqstp, bcts->dir); in nfsd4_bind_conn_to_session()
3828 if (!cstate->session) in nfsd4_compound_in_session()
3830 return !memcmp(sid, &cstate->session->se_sessionid, sizeof(*sid)); in nfsd4_compound_in_session()
3837 struct nfs4_sessionid *sessionid = &u->destroy_session.sessionid; in nfsd4_destroy_session()
3851 spin_lock(&nn->client_lock); in nfsd4_destroy_session()
3856 if (!nfsd4_mach_creds_match(ses->se_client, r)) in nfsd4_destroy_session()
3862 spin_unlock(&nn->client_lock); in nfsd4_destroy_session()
3864 nfsd4_probe_callback_sync(ses->se_client); in nfsd4_destroy_session()
3866 spin_lock(&nn->client_lock); in nfsd4_destroy_session()
3871 spin_unlock(&nn->client_lock); in nfsd4_destroy_session()
3878 struct nfs4_client *clp = ses->se_client; in nfsd4_sequence_check_conn()
3883 spin_lock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3884 c = __nfsd4_find_conn(new->cn_xprt, ses); in nfsd4_sequence_check_conn()
3888 if (clp->cl_mach_cred) in nfsd4_sequence_check_conn()
3891 spin_unlock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3895 nfsd4_conn_lost(&new->cn_xpt_user); in nfsd4_sequence_check_conn()
3898 spin_unlock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3905 struct nfsd4_compoundargs *args = rqstp->rq_argp; in nfsd4_session_too_many_ops()
3907 return args->opcnt > session->se_fchannel.maxops; in nfsd4_session_too_many_ops()
3913 struct xdr_buf *xb = &rqstp->rq_arg; in nfsd4_request_too_big()
3915 return xb->len > session->se_fchannel.maxreq_sz; in nfsd4_request_too_big()
3921 struct nfsd4_compoundargs *argp = rqstp->rq_argp; in replay_matches_cache()
3923 if ((bool)(slot->sl_flags & NFSD4_SLOT_CACHETHIS) != in replay_matches_cache()
3924 (bool)seq->cachethis) in replay_matches_cache()
3930 if (slot->sl_opcnt < argp->opcnt && !slot->sl_status) in replay_matches_cache()
3937 if (slot->sl_opcnt > argp->opcnt) in replay_matches_cache()
3940 if (!same_creds(&rqstp->rq_cred, &slot->sl_cred)) in replay_matches_cache()
3955 struct nfsd4_sequence *seq = &u->sequence; in nfsd4_sequence()
3956 struct nfsd4_compoundres *resp = rqstp->rq_resp; in nfsd4_sequence()
3957 struct xdr_stream *xdr = resp->xdr; in nfsd4_sequence()
3967 if (resp->opcnt != 1) in nfsd4_sequence()
3978 spin_lock(&nn->client_lock); in nfsd4_sequence()
3979 session = find_in_sessionid_hashtbl(&seq->sessionid, net, &status); in nfsd4_sequence()
3982 clp = session->se_client; in nfsd4_sequence()
3993 if (seq->slotid >= session->se_fchannel.maxreqs) in nfsd4_sequence()
3996 slot = session->se_slots[seq->slotid]; in nfsd4_sequence()
3997 dprintk("%s: slotid %d\n", __func__, seq->slotid); in nfsd4_sequence()
4002 seq->maxslots = session->se_fchannel.maxreqs; in nfsd4_sequence()
4004 status = check_slot_seqid(seq->seqid, slot->sl_seqid, in nfsd4_sequence()
4005 slot->sl_flags & NFSD4_SLOT_INUSE); in nfsd4_sequence()
4008 if (!(slot->sl_flags & NFSD4_SLOT_INITIALIZED)) in nfsd4_sequence()
4013 cstate->slot = slot; in nfsd4_sequence()
4014 cstate->session = session; in nfsd4_sequence()
4015 cstate->clp = clp; in nfsd4_sequence()
4016 /* Return the cached reply status and set cstate->status in nfsd4_sequence()
4019 cstate->status = nfserr_replay_cache; in nfsd4_sequence()
4030 buflen = (seq->cachethis) ? in nfsd4_sequence()
4031 session->se_fchannel.maxresp_cached : in nfsd4_sequence()
4032 session->se_fchannel.maxresp_sz; in nfsd4_sequence()
4033 status = (seq->cachethis) ? nfserr_rep_too_big_to_cache : in nfsd4_sequence()
4035 if (xdr_restrict_buflen(xdr, buflen - rqstp->rq_auth_slack)) in nfsd4_sequence()
4041 slot->sl_seqid = seq->seqid; in nfsd4_sequence()
4042 slot->sl_flags |= NFSD4_SLOT_INUSE; in nfsd4_sequence()
4043 if (seq->cachethis) in nfsd4_sequence()
4044 slot->sl_flags |= NFSD4_SLOT_CACHETHIS; in nfsd4_sequence()
4046 slot->sl_flags &= ~NFSD4_SLOT_CACHETHIS; in nfsd4_sequence()
4048 cstate->slot = slot; in nfsd4_sequence()
4049 cstate->session = session; in nfsd4_sequence()
4050 cstate->clp = clp; in nfsd4_sequence()
4053 switch (clp->cl_cb_state) { in nfsd4_sequence()
4055 seq->status_flags = SEQ4_STATUS_CB_PATH_DOWN; in nfsd4_sequence()
4058 seq->status_flags = SEQ4_STATUS_BACKCHANNEL_FAULT; in nfsd4_sequence()
4061 seq->status_flags = 0; in nfsd4_sequence()
4063 if (!list_empty(&clp->cl_revoked)) in nfsd4_sequence()
4064 seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED; in nfsd4_sequence()
4068 spin_unlock(&nn->client_lock); in nfsd4_sequence()
4078 struct nfsd4_compound_state *cs = &resp->cstate; in nfsd4_sequence_done()
4081 if (cs->status != nfserr_replay_cache) { in nfsd4_sequence_done()
4083 cs->slot->sl_flags &= ~NFSD4_SLOT_INUSE; in nfsd4_sequence_done()
4086 nfsd4_put_session(cs->session); in nfsd4_sequence_done()
4087 } else if (cs->clp) in nfsd4_sequence_done()
4088 put_client_renew(cs->clp); in nfsd4_sequence_done()
4096 struct nfsd4_destroy_clientid *dc = &u->destroy_clientid; in nfsd4_destroy_clientid()
4102 spin_lock(&nn->client_lock); in nfsd4_destroy_clientid()
4103 unconf = find_unconfirmed_client(&dc->clientid, true, nn); in nfsd4_destroy_clientid()
4104 conf = find_confirmed_client(&dc->clientid, true, nn); in nfsd4_destroy_clientid()
4127 trace_nfsd_clid_destroyed(&clp->cl_clientid); in nfsd4_destroy_clientid()
4130 spin_unlock(&nn->client_lock); in nfsd4_destroy_clientid()
4140 struct nfsd4_reclaim_complete *rc = &u->reclaim_complete; in nfsd4_reclaim_complete()
4141 struct nfs4_client *clp = cstate->clp; in nfsd4_reclaim_complete()
4144 if (rc->rca_one_fs) { in nfsd4_reclaim_complete()
4145 if (!cstate->current_fh.fh_dentry) in nfsd4_reclaim_complete()
4155 if (test_and_set_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &clp->cl_flags)) in nfsd4_reclaim_complete()
4170 trace_nfsd_clid_reclaim_complete(&clp->cl_clientid); in nfsd4_reclaim_complete()
4181 struct nfsd4_setclientid *setclid = &u->setclientid; in nfsd4_setclientid()
4182 struct xdr_netobj clname = setclid->se_name; in nfsd4_setclientid()
4183 nfs4_verifier clverifier = setclid->se_verf; in nfsd4_setclientid()
4192 spin_lock(&nn->client_lock); in nfsd4_setclientid()
4198 if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid()
4207 if (same_verf(&conf->cl_verifier, &clverifier)) { in nfsd4_setclientid()
4215 new->cl_minorversion = 0; in nfsd4_setclientid()
4218 setclid->se_clientid.cl_boot = new->cl_clientid.cl_boot; in nfsd4_setclientid()
4219 setclid->se_clientid.cl_id = new->cl_clientid.cl_id; in nfsd4_setclientid()
4220 memcpy(setclid->se_confirm.data, new->cl_confirm.data, sizeof(setclid->se_confirm.data)); in nfsd4_setclientid()
4224 spin_unlock(&nn->client_lock); in nfsd4_setclientid()
4228 trace_nfsd_clid_expire_unconf(&unconf->cl_clientid); in nfsd4_setclientid()
4240 &u->setclientid_confirm; in nfsd4_setclientid_confirm()
4243 nfs4_verifier confirm = setclientid_confirm->sc_confirm; in nfsd4_setclientid_confirm()
4244 clientid_t * clid = &setclientid_confirm->sc_clientid; in nfsd4_setclientid_confirm()
4251 spin_lock(&nn->client_lock); in nfsd4_setclientid_confirm()
4262 if (unconf && !same_creds(&unconf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid_confirm()
4266 if (conf && !same_creds(&conf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid_confirm()
4270 if (!unconf || !same_verf(&confirm, &unconf->cl_confirm)) { in nfsd4_setclientid_confirm()
4271 if (conf && same_verf(&confirm, &conf->cl_confirm)) { in nfsd4_setclientid_confirm()
4281 nfsd4_change_callback(conf, &unconf->cl_cb_conn); in nfsd4_setclientid_confirm()
4283 old = find_confirmed_client_by_name(&unconf->cl_name, nn); in nfsd4_setclientid_confirm()
4287 && !same_creds(&unconf->cl_cred, in nfsd4_setclientid_confirm()
4288 &old->cl_cred)) { in nfsd4_setclientid_confirm()
4297 trace_nfsd_clid_replaced(&old->cl_clientid); in nfsd4_setclientid_confirm()
4303 spin_unlock(&nn->client_lock); in nfsd4_setclientid_confirm()
4305 fsnotify_dentry(conf->cl_nfsd_info_dentry, FS_MODIFY); in nfsd4_setclientid_confirm()
4307 spin_lock(&nn->client_lock); in nfsd4_setclientid_confirm()
4310 spin_unlock(&nn->client_lock); in nfsd4_setclientid_confirm()
4325 refcount_set(&fp->fi_ref, 1); in nfsd4_file_init()
4326 spin_lock_init(&fp->fi_lock); in nfsd4_file_init()
4327 INIT_LIST_HEAD(&fp->fi_stateids); in nfsd4_file_init()
4328 INIT_LIST_HEAD(&fp->fi_delegations); in nfsd4_file_init()
4329 INIT_LIST_HEAD(&fp->fi_clnt_odstate); in nfsd4_file_init()
4330 fh_copy_shallow(&fp->fi_fhandle, &fh->fh_handle); in nfsd4_file_init()
4331 fp->fi_deleg_file = NULL; in nfsd4_file_init()
4332 fp->fi_had_conflict = false; in nfsd4_file_init()
4333 fp->fi_share_deny = 0; in nfsd4_file_init()
4334 memset(fp->fi_fds, 0, sizeof(fp->fi_fds)); in nfsd4_file_init()
4335 memset(fp->fi_access, 0, sizeof(fp->fi_access)); in nfsd4_file_init()
4336 fp->fi_aliased = false; in nfsd4_file_init()
4337 fp->fi_inode = d_inode(fh->fh_dentry); in nfsd4_file_init()
4339 INIT_LIST_HEAD(&fp->fi_lo_states); in nfsd4_file_init()
4340 atomic_set(&fp->fi_lo_recalls, 0); in nfsd4_file_init()
4402 return -ENOMEM; in nfsd4_init_slabs()
4412 count = atomic_read(&nn->nfsd_courtesy_clients); in nfsd4_state_shrinker_count()
4416 queue_work(laundry_wq, &nn->nfsd_shrinker_work); in nfsd4_state_shrinker_count()
4432 nn->nfsd4_lease = 90; /* default lease time */ in nfsd4_init_leases_net()
4433 nn->nfsd4_grace = 90; in nfsd4_init_leases_net()
4434 nn->somebody_reclaimed = false; in nfsd4_init_leases_net()
4435 nn->track_reclaim_completes = false; in nfsd4_init_leases_net()
4436 nn->clverifier_counter = get_random_u32(); in nfsd4_init_leases_net()
4437 nn->clientid_base = get_random_u32(); in nfsd4_init_leases_net()
4438 nn->clientid_counter = nn->clientid_base + 1; in nfsd4_init_leases_net()
4439 nn->s2s_cp_cl_id = nn->clientid_counter++; in nfsd4_init_leases_net()
4441 atomic_set(&nn->nfs4_client_count, 0); in nfsd4_init_leases_net()
4445 nn->nfs4_max_clients = max_t(int, max_clients, NFS4_CLIENTS_PER_GB); in nfsd4_init_leases_net()
4447 atomic_set(&nn->nfsd_courtesy_clients, 0); in nfsd4_init_leases_net()
4452 rp->rp_status = nfserr_serverfault; in init_nfs4_replay()
4453 rp->rp_buflen = 0; in init_nfs4_replay()
4454 rp->rp_buf = rp->rp_ibuf; in init_nfs4_replay()
4455 mutex_init(&rp->rp_mutex); in init_nfs4_replay()
4462 mutex_lock(&so->so_replay.rp_mutex); in nfsd4_cstate_assign_replay()
4463 cstate->replay_owner = nfs4_get_stateowner(so); in nfsd4_cstate_assign_replay()
4469 struct nfs4_stateowner *so = cstate->replay_owner; in nfsd4_cstate_clear_replay()
4472 cstate->replay_owner = NULL; in nfsd4_cstate_clear_replay()
4473 mutex_unlock(&so->so_replay.rp_mutex); in nfsd4_cstate_clear_replay()
4486 xdr_netobj_dup(&sop->so_owner, owner, GFP_KERNEL); in alloc_stateowner()
4487 if (!sop->so_owner.data) { in alloc_stateowner()
4492 INIT_LIST_HEAD(&sop->so_stateids); in alloc_stateowner()
4493 sop->so_client = clp; in alloc_stateowner()
4494 init_nfs4_replay(&sop->so_replay); in alloc_stateowner()
4495 atomic_set(&sop->so_count, 1); in alloc_stateowner()
4501 lockdep_assert_held(&clp->cl_lock); in hash_openowner()
4503 list_add(&oo->oo_owner.so_strhash, in hash_openowner()
4504 &clp->cl_ownerstr_hashtbl[strhashval]); in hash_openowner()
4505 list_add(&oo->oo_perclient, &clp->cl_openowners); in hash_openowner()
4529 struct nfs4_openowner *oo = open->op_openowner; in nfsd4_find_existing_open()
4531 lockdep_assert_held(&fp->fi_lock); in nfsd4_find_existing_open()
4533 list_for_each_entry(local, &fp->fi_stateids, st_perfile) { in nfsd4_find_existing_open()
4535 if (local->st_stateowner->so_is_open_owner == 0) in nfsd4_find_existing_open()
4537 if (local->st_stateowner != &oo->oo_owner) in nfsd4_find_existing_open()
4539 if (local->st_stid.sc_type == NFS4_OPEN_STID) { in nfsd4_find_existing_open()
4541 refcount_inc(&ret->st_stid.sc_count); in nfsd4_find_existing_open()
4553 switch (s->sc_type) { in nfsd4_verify_open_stid()
4573 mutex_lock_nested(&stp->st_mutex, LOCK_STATEID_MUTEX); in nfsd4_lock_ol_stateid()
4574 ret = nfsd4_verify_open_stid(&stp->st_stid); in nfsd4_lock_ol_stateid()
4576 mutex_unlock(&stp->st_mutex); in nfsd4_lock_ol_stateid()
4585 spin_lock(&fp->fi_lock); in nfsd4_find_and_lock_existing_open()
4587 spin_unlock(&fp->fi_lock); in nfsd4_find_and_lock_existing_open()
4590 nfs4_put_stid(&stp->st_stid); in nfsd4_find_and_lock_existing_open()
4599 struct nfs4_client *clp = cstate->clp; in alloc_init_open_stateowner()
4602 oo = alloc_stateowner(openowner_slab, &open->op_owner, clp); in alloc_init_open_stateowner()
4605 oo->oo_owner.so_ops = &openowner_ops; in alloc_init_open_stateowner()
4606 oo->oo_owner.so_is_open_owner = 1; in alloc_init_open_stateowner()
4607 oo->oo_owner.so_seqid = open->op_seqid; in alloc_init_open_stateowner()
4608 oo->oo_flags = 0; in alloc_init_open_stateowner()
4610 oo->oo_flags |= NFS4_OO_CONFIRMED; in alloc_init_open_stateowner()
4611 oo->oo_time = 0; in alloc_init_open_stateowner()
4612 oo->oo_last_closed_stid = NULL; in alloc_init_open_stateowner()
4613 INIT_LIST_HEAD(&oo->oo_close_lru); in alloc_init_open_stateowner()
4614 spin_lock(&clp->cl_lock); in alloc_init_open_stateowner()
4620 nfs4_free_stateowner(&oo->oo_owner); in alloc_init_open_stateowner()
4622 spin_unlock(&clp->cl_lock); in alloc_init_open_stateowner()
4630 struct nfs4_openowner *oo = open->op_openowner; in init_open_stateid()
4634 stp = open->op_stp; in init_open_stateid()
4636 mutex_init(&stp->st_mutex); in init_open_stateid()
4637 mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX); in init_open_stateid()
4640 spin_lock(&oo->oo_owner.so_client->cl_lock); in init_open_stateid()
4641 spin_lock(&fp->fi_lock); in init_open_stateid()
4644 mutex_unlock(&stp->st_mutex); in init_open_stateid()
4653 open->op_stp = NULL; in init_open_stateid()
4654 refcount_inc(&stp->st_stid.sc_count); in init_open_stateid()
4655 stp->st_stid.sc_type = NFS4_OPEN_STID; in init_open_stateid()
4656 INIT_LIST_HEAD(&stp->st_locks); in init_open_stateid()
4657 stp->st_stateowner = nfs4_get_stateowner(&oo->oo_owner); in init_open_stateid()
4659 stp->st_stid.sc_file = fp; in init_open_stateid()
4660 stp->st_access_bmap = 0; in init_open_stateid()
4661 stp->st_deny_bmap = 0; in init_open_stateid()
4662 stp->st_openstp = NULL; in init_open_stateid()
4663 list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids); in init_open_stateid()
4664 list_add(&stp->st_perfile, &fp->fi_stateids); in init_open_stateid()
4667 spin_unlock(&fp->fi_lock); in init_open_stateid()
4668 spin_unlock(&oo->oo_owner.so_client->cl_lock); in init_open_stateid()
4672 nfs4_put_stid(&retstp->st_stid); in init_open_stateid()
4676 mutex_unlock(&stp->st_mutex); in init_open_stateid()
4691 struct nfs4_openowner *oo = openowner(s->st_stateowner); in move_to_close_lru()
4692 struct nfsd_net *nn = net_generic(s->st_stid.sc_client->net, in move_to_close_lru()
4706 wait_event(close_wq, refcount_read(&s->st_stid.sc_count) == 2); in move_to_close_lru()
4709 if (s->st_stid.sc_file) { in move_to_close_lru()
4710 put_nfs4_file(s->st_stid.sc_file); in move_to_close_lru()
4711 s->st_stid.sc_file = NULL; in move_to_close_lru()
4714 spin_lock(&nn->client_lock); in move_to_close_lru()
4715 last = oo->oo_last_closed_stid; in move_to_close_lru()
4716 oo->oo_last_closed_stid = s; in move_to_close_lru()
4717 list_move_tail(&oo->oo_close_lru, &nn->close_lru); in move_to_close_lru()
4718 oo->oo_time = ktime_get_boottime_seconds(); in move_to_close_lru()
4719 spin_unlock(&nn->client_lock); in move_to_close_lru()
4721 nfs4_put_stid(&last->st_stid); in move_to_close_lru()
4727 struct inode *inode = d_inode(fhp->fh_dentry); in nfsd4_file_hash_lookup()
4735 if (fh_match(&fi->fi_fhandle, &fhp->fh_handle)) { in nfsd4_file_hash_lookup()
4736 if (refcount_inc_not_zero(&fi->fi_ref)) { in nfsd4_file_hash_lookup()
4751 * inode->i_lock prevents racing insertions from adding an entry
4757 struct inode *inode = d_inode(fhp->fh_dentry); in nfsd4_file_hash_insert()
4765 spin_lock(&inode->i_lock); in nfsd4_file_hash_insert()
4770 if (fh_match(&fi->fi_fhandle, &fhp->fh_handle)) { in nfsd4_file_hash_insert()
4771 if (refcount_inc_not_zero(&fi->fi_ref)) in nfsd4_file_hash_insert()
4774 fi->fi_aliased = alias_found = true; in nfsd4_file_hash_insert()
4780 err = rhltable_insert(&nfs4_file_rhltable, &new->fi_rlist, in nfsd4_file_hash_insert()
4785 new->fi_aliased = alias_found; in nfsd4_file_hash_insert()
4789 spin_unlock(&inode->i_lock); in nfsd4_file_hash_insert()
4796 rhltable_remove(&nfs4_file_rhltable, &fi->fi_rlist, in nfsd4_file_hash_remove()
4815 spin_lock(&fp->fi_lock); in nfs4_share_conflict()
4816 if (fp->fi_share_deny & deny_type) in nfs4_share_conflict()
4818 spin_unlock(&fp->fi_lock); in nfs4_share_conflict()
4827 return ctx && !list_empty_careful(&ctx->flc_lease); in nfsd4_deleg_present()
4831 * nfsd_wait_for_delegreturn - wait for delegations to be returned
4833 * @inode: in-core inode of the file being waited for
4855 struct nfsd_net *nn = net_generic(dp->dl_stid.sc_client->net, in nfsd4_cb_recall_prepare()
4858 block_delegations(&dp->dl_stid.sc_file->fi_fhandle); in nfsd4_cb_recall_prepare()
4862 * already holding inode->i_lock. in nfsd4_cb_recall_prepare()
4868 if (delegation_hashed(dp) && dp->dl_time == 0) { in nfsd4_cb_recall_prepare()
4869 dp->dl_time = ktime_get_boottime_seconds(); in nfsd4_cb_recall_prepare()
4870 list_add_tail(&dp->dl_recall_lru, &nn->del_recall_lru); in nfsd4_cb_recall_prepare()
4880 trace_nfsd_cb_recall_done(&dp->dl_stid.sc_stateid, task); in nfsd4_cb_recall_done()
4882 if (dp->dl_stid.sc_type == NFS4_CLOSED_DELEG_STID || in nfsd4_cb_recall_done()
4883 dp->dl_stid.sc_type == NFS4_REVOKED_DELEG_STID) in nfsd4_cb_recall_done()
4886 switch (task->tk_status) { in nfsd4_cb_recall_done()
4889 case -NFS4ERR_DELAY: in nfsd4_cb_recall_done()
4892 case -EBADHANDLE: in nfsd4_cb_recall_done()
4893 case -NFS4ERR_BAD_STATEID: in nfsd4_cb_recall_done()
4898 if (dp->dl_retries--) { in nfsd4_cb_recall_done()
4912 nfs4_put_stid(&dp->dl_stid); in nfsd4_cb_recall_release()
4930 refcount_inc(&dp->dl_stid.sc_count); in nfsd_break_one_deleg()
4931 WARN_ON_ONCE(!nfsd4_run_cb(&dp->dl_recall)); in nfsd_break_one_deleg()
4938 struct nfs4_delegation *dp = (struct nfs4_delegation *)fl->fl_owner; in nfsd_break_deleg_cb()
4939 struct nfs4_file *fp = dp->dl_stid.sc_file; in nfsd_break_deleg_cb()
4940 struct nfs4_client *clp = dp->dl_stid.sc_client; in nfsd_break_deleg_cb()
4943 trace_nfsd_cb_recall(&dp->dl_stid); in nfsd_break_deleg_cb()
4945 dp->dl_recalled = true; in nfsd_break_deleg_cb()
4946 atomic_inc(&clp->cl_delegs_in_recall); in nfsd_break_deleg_cb()
4948 nn = net_generic(clp->net, nfsd_net_id); in nfsd_break_deleg_cb()
4949 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in nfsd_break_deleg_cb()
4957 fl->fl_break_time = 0; in nfsd_break_deleg_cb()
4959 fp->fi_had_conflict = true; in nfsd_break_deleg_cb()
4965 * nfsd_breaker_owns_lease - Check if lease conflict was resolved
4974 struct nfs4_delegation *dl = fl->fl_owner; in nfsd_breaker_owns_lease()
4982 if (rqst->rq_prog != NFS_PROGRAM || rqst->rq_vers < 4) in nfsd_breaker_owns_lease()
4984 clp = *(rqst->rq_lease_breaker); in nfsd_breaker_owns_lease()
4985 return dl->dl_stid.sc_client == clp; in nfsd_breaker_owns_lease()
4992 struct nfs4_delegation *dp = (struct nfs4_delegation *)onlist->fl_owner; in nfsd_change_deleg_cb()
4993 struct nfs4_client *clp = dp->dl_stid.sc_client; in nfsd_change_deleg_cb()
4996 if (dp->dl_recalled) in nfsd_change_deleg_cb()
4997 atomic_dec(&clp->cl_delegs_in_recall); in nfsd_change_deleg_cb()
5000 return -EAGAIN; in nfsd_change_deleg_cb()
5013 if (seqid == so->so_seqid - 1) in nfsd4_check_seqid()
5015 if (seqid == so->so_seqid) in nfsd4_check_seqid()
5025 spin_lock(&nn->client_lock); in lookup_clientid()
5028 atomic_inc(&found->cl_rpc_users); in lookup_clientid()
5029 spin_unlock(&nn->client_lock); in lookup_clientid()
5037 if (cstate->clp) { in set_client()
5038 if (!same_clid(&cstate->clp->cl_clientid, clid)) in set_client()
5046 * set cstate->clp), so session = false: in set_client()
5048 cstate->clp = lookup_clientid(clid, false, nn); in set_client()
5049 if (!cstate->clp) in set_client()
5058 clientid_t *clientid = &open->op_clientid; in nfsd4_process_open1()
5068 open->op_file = nfsd4_alloc_file(); in nfsd4_process_open1()
5069 if (open->op_file == NULL) in nfsd4_process_open1()
5075 clp = cstate->clp; in nfsd4_process_open1()
5077 strhashval = ownerstr_hashval(&open->op_owner); in nfsd4_process_open1()
5079 open->op_openowner = oo; in nfsd4_process_open1()
5083 if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { in nfsd4_process_open1()
5086 open->op_openowner = NULL; in nfsd4_process_open1()
5089 status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid); in nfsd4_process_open1()
5097 open->op_openowner = oo; in nfsd4_process_open1()
5099 open->op_stp = nfs4_alloc_open_stateid(clp); in nfsd4_process_open1()
5100 if (!open->op_stp) in nfsd4_process_open1()
5104 (cstate->current_fh.fh_export->ex_flags & NFSEXP_PNFS)) { in nfsd4_process_open1()
5105 open->op_odstate = alloc_clnt_odstate(clp); in nfsd4_process_open1()
5106 if (!open->op_odstate) in nfsd4_process_open1()
5116 if ((flags & WR_STATE) && (dp->dl_type == NFS4_OPEN_DELEGATE_READ)) in nfs4_check_delegmode()
5140 return open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR || in nfsd4_is_deleg_cur()
5141 open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH; in nfsd4_is_deleg_cur()
5152 deleg = find_deleg_stateid(cl, &open->op_delegate_stateid); in nfs4_check_deleg()
5155 if (deleg->dl_stid.sc_type == NFS4_REVOKED_DELEG_STID) { in nfs4_check_deleg()
5156 nfs4_put_stid(&deleg->dl_stid); in nfs4_check_deleg()
5157 if (cl->cl_minorversion) in nfs4_check_deleg()
5161 flags = share_access_to_flags(open->op_share_access); in nfs4_check_deleg()
5164 nfs4_put_stid(&deleg->dl_stid); in nfs4_check_deleg()
5173 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; in nfs4_check_deleg()
5199 if (!open->op_truncate) in nfsd4_truncate()
5201 if (!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) in nfsd4_truncate()
5212 int oflag = nfs4_access_to_omode(open->op_share_access); in nfs4_get_vfs_file()
5213 int access = nfs4_access_to_access(open->op_share_access); in nfs4_get_vfs_file()
5216 spin_lock(&fp->fi_lock); in nfs4_get_vfs_file()
5222 status = nfs4_file_check_deny(fp, open->op_share_deny); in nfs4_get_vfs_file()
5225 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5229 stp, open->op_share_deny, false)) in nfs4_get_vfs_file()
5231 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5236 status = nfs4_file_get_access(fp, open->op_share_access); in nfs4_get_vfs_file()
5239 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5243 stp, open->op_share_access, true)) in nfs4_get_vfs_file()
5245 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5250 old_access_bmap = stp->st_access_bmap; in nfs4_get_vfs_file()
5251 set_access(open->op_share_access, stp); in nfs4_get_vfs_file()
5254 old_deny_bmap = stp->st_deny_bmap; in nfs4_get_vfs_file()
5255 set_deny(open->op_share_deny, stp); in nfs4_get_vfs_file()
5256 fp->fi_share_deny |= (open->op_share_deny & NFS4_SHARE_DENY_BOTH); in nfs4_get_vfs_file()
5258 if (!fp->fi_fds[oflag]) { in nfs4_get_vfs_file()
5259 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5262 open->op_filp, &nf); in nfs4_get_vfs_file()
5266 spin_lock(&fp->fi_lock); in nfs4_get_vfs_file()
5267 if (!fp->fi_fds[oflag]) { in nfs4_get_vfs_file()
5268 fp->fi_fds[oflag] = nf; in nfs4_get_vfs_file()
5272 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5276 status = nfserrno(nfsd_open_break_lease(cur_fh->fh_dentry->d_inode, in nfs4_get_vfs_file()
5287 stp->st_access_bmap = old_access_bmap; in nfs4_get_vfs_file()
5288 nfs4_file_put_access(fp, open->op_share_access); in nfs4_get_vfs_file()
5299 unsigned char old_deny_bmap = stp->st_deny_bmap; in nfs4_upgrade_open()
5301 if (!test_access(open->op_share_access, stp)) in nfs4_upgrade_open()
5305 spin_lock(&fp->fi_lock); in nfs4_upgrade_open()
5306 status = nfs4_file_check_deny(fp, open->op_share_deny); in nfs4_upgrade_open()
5309 set_deny(open->op_share_deny, stp); in nfs4_upgrade_open()
5310 fp->fi_share_deny |= in nfs4_upgrade_open()
5311 (open->op_share_deny & NFS4_SHARE_DENY_BOTH); in nfs4_upgrade_open()
5315 stp, open->op_share_deny, false)) in nfs4_upgrade_open()
5319 spin_unlock(&fp->fi_lock); in nfs4_upgrade_open()
5333 if (clp->cl_cb_state == NFSD4_CB_UP) in nfsd4_cb_channel_good()
5340 return clp->cl_minorversion && clp->cl_cb_state == NFSD4_CB_UNKNOWN; in nfsd4_cb_channel_good()
5351 fl->fl_lmops = &nfsd_lease_mng_ops; in nfs4_alloc_init_lease()
5352 fl->fl_flags = FL_DELEG; in nfs4_alloc_init_lease()
5353 fl->fl_type = flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK; in nfs4_alloc_init_lease()
5354 fl->fl_end = OFFSET_MAX; in nfs4_alloc_init_lease()
5355 fl->fl_owner = (fl_owner_t)dp; in nfs4_alloc_init_lease()
5356 fl->fl_pid = current->tgid; in nfs4_alloc_init_lease()
5357 fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file; in nfs4_alloc_init_lease()
5365 struct file *f = fp->fi_deleg_file->nf_file; in nfsd4_check_conflicting_opens()
5369 writes = atomic_read(&ino->i_writecount); in nfsd4_check_conflicting_opens()
5379 if (fp->fi_aliased) in nfsd4_check_conflicting_opens()
5380 return -EAGAIN; in nfsd4_check_conflicting_opens()
5388 if (fp->fi_fds[O_WRONLY]) in nfsd4_check_conflicting_opens()
5389 writes--; in nfsd4_check_conflicting_opens()
5390 if (fp->fi_fds[O_RDWR]) in nfsd4_check_conflicting_opens()
5391 writes--; in nfsd4_check_conflicting_opens()
5393 return -EAGAIN; /* There may be non-NFSv4 writers */ in nfsd4_check_conflicting_opens()
5395 * It's possible there are non-NFSv4 write opens in progress, in nfsd4_check_conflicting_opens()
5401 spin_lock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5402 list_for_each_entry(st, &fp->fi_stateids, st_perfile) { in nfsd4_check_conflicting_opens()
5403 if (st->st_openstp == NULL /* it's an open */ && in nfsd4_check_conflicting_opens()
5405 st->st_stid.sc_client != clp) { in nfsd4_check_conflicting_opens()
5406 spin_unlock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5407 return -EAGAIN; in nfsd4_check_conflicting_opens()
5410 spin_unlock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5433 err = nfsd_lookup_dentry(open->op_rqstp, parent, in nfsd4_verify_deleg_dentry()
5434 open->op_fname, open->op_fnamelen, in nfsd4_verify_deleg_dentry()
5438 return -EAGAIN; in nfsd4_verify_deleg_dentry()
5442 if (child != file_dentry(fp->fi_deleg_file->nf_file)) in nfsd4_verify_deleg_dentry()
5443 return -EAGAIN; in nfsd4_verify_deleg_dentry()
5457 struct inode *inode = file_inode(nf->nf_file); in nfsd4_verify_setuid_write()
5459 if ((open->op_share_access & NFS4_SHARE_ACCESS_WRITE) && in nfsd4_verify_setuid_write()
5460 (inode->i_mode & (S_ISUID|S_ISGID))) in nfsd4_verify_setuid_write()
5461 return -EAGAIN; in nfsd4_verify_setuid_write()
5470 struct nfs4_client *clp = stp->st_stid.sc_client; in nfs4_set_delegation()
5471 struct nfs4_file *fp = stp->st_stid.sc_file; in nfs4_set_delegation()
5472 struct nfs4_clnt_odstate *odstate = stp->st_clnt_odstate; in nfs4_set_delegation()
5483 if (fp->fi_had_conflict) in nfs4_set_delegation()
5484 return ERR_PTR(-EAGAIN); in nfs4_set_delegation()
5498 if ((open->op_share_access & NFS4_SHARE_ACCESS_BOTH) == NFS4_SHARE_ACCESS_BOTH) { in nfs4_set_delegation()
5507 if (!nf && (open->op_share_access & NFS4_SHARE_ACCESS_READ)) { in nfs4_set_delegation()
5513 return ERR_PTR(-EAGAIN); in nfs4_set_delegation()
5516 spin_lock(&fp->fi_lock); in nfs4_set_delegation()
5518 status = -EAGAIN; in nfs4_set_delegation()
5520 status = -EAGAIN; in nfs4_set_delegation()
5521 else if (!fp->fi_deleg_file) { in nfs4_set_delegation()
5522 fp->fi_deleg_file = nf; in nfs4_set_delegation()
5525 fp->fi_delegees = 1; in nfs4_set_delegation()
5528 fp->fi_delegees++; in nfs4_set_delegation()
5529 spin_unlock(&fp->fi_lock); in nfs4_set_delegation()
5536 status = -ENOMEM; in nfs4_set_delegation()
5545 status = vfs_setlease(fp->fi_deleg_file->nf_file, fl->fl_type, &fl, NULL); in nfs4_set_delegation()
5565 status = nfsd4_verify_setuid_write(open, fp->fi_deleg_file); in nfs4_set_delegation()
5569 status = -EAGAIN; in nfs4_set_delegation()
5570 if (fp->fi_had_conflict) in nfs4_set_delegation()
5574 spin_lock(&fp->fi_lock); in nfs4_set_delegation()
5576 spin_unlock(&fp->fi_lock); in nfs4_set_delegation()
5584 vfs_setlease(fp->fi_deleg_file->nf_file, F_UNLCK, NULL, (void **)&dp); in nfs4_set_delegation()
5586 put_clnt_odstate(dp->dl_clnt_odstate); in nfs4_set_delegation()
5587 nfs4_put_stid(&dp->dl_stid); in nfs4_set_delegation()
5595 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_open_deleg_none_ext()
5596 if (status == -EAGAIN) in nfsd4_open_deleg_none_ext()
5597 open->op_why_no_deleg = WND4_CONTENTION; in nfsd4_open_deleg_none_ext()
5599 open->op_why_no_deleg = WND4_RESOURCE; in nfsd4_open_deleg_none_ext()
5600 switch (open->op_deleg_want) { in nfsd4_open_deleg_none_ext()
5606 open->op_why_no_deleg = WND4_CANCELLED; in nfsd4_open_deleg_none_ext()
5643 struct nfs4_openowner *oo = openowner(stp->st_stateowner); in nfs4_open_delegation()
5644 struct nfs4_client *clp = stp->st_stid.sc_client; in nfs4_open_delegation()
5649 cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client); in nfs4_open_delegation()
5650 open->op_recall = 0; in nfs4_open_delegation()
5651 switch (open->op_claim_type) { in nfs4_open_delegation()
5654 open->op_recall = 1; in nfs4_open_delegation()
5665 if (locks_in_grace(clp->net)) in nfs4_open_delegation()
5667 if (!cb_up || !(oo->oo_flags & NFS4_OO_CONFIRMED)) in nfs4_open_delegation()
5669 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE && in nfs4_open_delegation()
5670 !clp->cl_minorversion) in nfs4_open_delegation()
5680 memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid)); in nfs4_open_delegation()
5682 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) { in nfs4_open_delegation()
5683 open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE; in nfs4_open_delegation()
5684 trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); in nfs4_open_delegation()
5686 open->op_delegate_type = NFS4_OPEN_DELEGATE_READ; in nfs4_open_delegation()
5687 trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid); in nfs4_open_delegation()
5689 nfs4_put_stid(&dp->dl_stid); in nfs4_open_delegation()
5692 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE; in nfs4_open_delegation()
5693 if (open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS && in nfs4_open_delegation()
5694 open->op_delegate_type != NFS4_OPEN_DELEGATE_NONE) { in nfs4_open_delegation()
5696 open->op_recall = 1; in nfs4_open_delegation()
5700 if (open->op_deleg_want) in nfs4_open_delegation()
5708 if (open->op_deleg_want == NFS4_SHARE_WANT_READ_DELEG && in nfsd4_deleg_xgrade_none_ext()
5709 dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) { in nfsd4_deleg_xgrade_none_ext()
5710 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_deleg_xgrade_none_ext()
5711 open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE; in nfsd4_deleg_xgrade_none_ext()
5712 } else if (open->op_deleg_want == NFS4_SHARE_WANT_WRITE_DELEG && in nfsd4_deleg_xgrade_none_ext()
5713 dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) { in nfsd4_deleg_xgrade_none_ext()
5714 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_deleg_xgrade_none_ext()
5715 open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE; in nfsd4_deleg_xgrade_none_ext()
5724 * nfsd4_process_open2 - finish open processing
5729 * If successful, (1) truncate the file if open->op_truncate was
5730 * set, (2) set open->op_stateid, (3) set open->op_delegation.
5738 struct nfsd4_compoundres *resp = rqstp->rq_resp; in nfsd4_process_open2()
5739 struct nfs4_client *cl = open->op_openowner->oo_owner.so_client; in nfsd4_process_open2()
5751 fp = nfsd4_file_hash_insert(open->op_file, current_fh); in nfsd4_process_open2()
5754 if (fp != open->op_file) { in nfsd4_process_open2()
5760 open->op_file = NULL; in nfsd4_process_open2()
5773 if (!open->op_stp) in nfsd4_process_open2()
5787 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5793 stp->st_stid.sc_type = NFS4_CLOSED_STID; in nfsd4_process_open2()
5795 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5799 stp->st_clnt_odstate = find_or_hash_clnt_odstate(fp, in nfsd4_process_open2()
5800 open->op_odstate); in nfsd4_process_open2()
5801 if (stp->st_clnt_odstate == open->op_odstate) in nfsd4_process_open2()
5802 open->op_odstate = NULL; in nfsd4_process_open2()
5805 nfs4_inc_and_copy_stateid(&open->op_stateid, &stp->st_stid); in nfsd4_process_open2()
5806 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5808 if (nfsd4_has_session(&resp->cstate)) { in nfsd4_process_open2()
5809 if (open->op_deleg_want & NFS4_SHARE_WANT_NO_DELEG) { in nfsd4_process_open2()
5810 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_process_open2()
5811 open->op_why_no_deleg = WND4_NOT_WANTED; in nfsd4_process_open2()
5820 nfs4_open_delegation(open, stp, &resp->cstate.current_fh); in nfsd4_process_open2()
5823 trace_nfsd_open(&stp->st_stid.sc_stateid); in nfsd4_process_open2()
5826 if (open->op_delegate_type == NFS4_OPEN_DELEGATE_NONE && dp && in nfsd4_process_open2()
5827 open->op_deleg_want) in nfsd4_process_open2()
5832 if (status == 0 && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) in nfsd4_process_open2()
5833 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; in nfsd4_process_open2()
5837 open->op_rflags = NFS4_OPEN_RESULT_LOCKTYPE_POSIX; in nfsd4_process_open2()
5838 if (nfsd4_has_session(&resp->cstate)) in nfsd4_process_open2()
5839 open->op_rflags |= NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK; in nfsd4_process_open2()
5840 else if (!(open->op_openowner->oo_flags & NFS4_OO_CONFIRMED)) in nfsd4_process_open2()
5841 open->op_rflags |= NFS4_OPEN_RESULT_CONFIRM; in nfsd4_process_open2()
5844 nfs4_put_stid(&dp->dl_stid); in nfsd4_process_open2()
5846 nfs4_put_stid(&stp->st_stid); in nfsd4_process_open2()
5854 if (open->op_openowner) { in nfsd4_cleanup_open_state()
5855 struct nfs4_stateowner *so = &open->op_openowner->oo_owner; in nfsd4_cleanup_open_state()
5860 if (open->op_file) in nfsd4_cleanup_open_state()
5861 kmem_cache_free(file_slab, open->op_file); in nfsd4_cleanup_open_state()
5862 if (open->op_stp) in nfsd4_cleanup_open_state()
5863 nfs4_put_stid(&open->op_stp->st_stid); in nfsd4_cleanup_open_state()
5864 if (open->op_odstate) in nfsd4_cleanup_open_state()
5865 kmem_cache_free(odstate_slab, open->op_odstate); in nfsd4_cleanup_open_state()
5872 clientid_t *clid = &u->renew; in nfsd4_renew()
5881 clp = cstate->clp; in nfsd4_renew()
5882 if (!list_empty(&clp->cl_delegations) in nfsd4_renew()
5883 && clp->cl_cb_state != NFSD4_CB_UP) in nfsd4_renew()
5892 if (nn->grace_ended) in nfsd4_end_grace()
5896 nn->grace_ended = true; in nfsd4_end_grace()
5913 locks_end_grace(&nn->nfsd4_manager); in nfsd4_end_grace()
5927 time64_t double_grace_period_end = nn->boot_time + in clients_still_reclaiming()
5928 2 * nn->nfsd4_lease; in clients_still_reclaiming()
5930 if (nn->track_reclaim_completes && in clients_still_reclaiming()
5931 atomic_read(&nn->nr_reclaim_complete) == in clients_still_reclaiming()
5932 nn->reclaim_str_hashtbl_size) in clients_still_reclaiming()
5934 if (!nn->somebody_reclaimed) in clients_still_reclaiming()
5936 nn->somebody_reclaimed = false; in clients_still_reclaiming()
5955 if (last_refresh < lt->cutoff) in state_expired()
5957 time_remaining = last_refresh - lt->cutoff; in state_expired()
5958 lt->new_timeo = min(lt->new_timeo, time_remaining); in state_expired()
5965 spin_lock_init(&nn->nfsd_ssc_lock); in nfsd4_ssc_init_umount_work()
5966 INIT_LIST_HEAD(&nn->nfsd_ssc_mount_list); in nfsd4_ssc_init_umount_work()
5967 init_waitqueue_head(&nn->nfsd_ssc_waitq); in nfsd4_ssc_init_umount_work()
5980 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5981 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { in nfsd4_ssc_shutdown_umount()
5982 list_del(&ni->nsui_list); in nfsd4_ssc_shutdown_umount()
5983 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5984 mntput(ni->nsui_vfsmount); in nfsd4_ssc_shutdown_umount()
5986 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5988 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5997 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
5998 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { in nfsd4_ssc_expire_umount()
5999 if (time_after(jiffies, ni->nsui_expire)) { in nfsd4_ssc_expire_umount()
6000 if (refcount_read(&ni->nsui_refcnt) > 1) in nfsd4_ssc_expire_umount()
6004 ni->nsui_busy = true; in nfsd4_ssc_expire_umount()
6005 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
6006 mntput(ni->nsui_vfsmount); in nfsd4_ssc_expire_umount()
6007 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
6010 list_del(&ni->nsui_list); in nfsd4_ssc_expire_umount()
6020 wake_up_all(&nn->nfsd_ssc_waitq); in nfsd4_ssc_expire_umount()
6021 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
6033 list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) { in nfs4_lockowner_has_blockers()
6034 nf = stp->st_stid.sc_file; in nfs4_lockowner_has_blockers()
6035 ctx = locks_inode_context(nf->fi_inode); in nfs4_lockowner_has_blockers()
6051 if (atomic_read(&clp->cl_delegs_in_recall)) in nfs4_anylock_blockers()
6053 spin_lock(&clp->cl_lock); in nfs4_anylock_blockers()
6055 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[i], in nfs4_anylock_blockers()
6057 if (so->so_is_open_owner) in nfs4_anylock_blockers()
6061 spin_unlock(&clp->cl_lock); in nfs4_anylock_blockers()
6066 spin_unlock(&clp->cl_lock); in nfs4_anylock_blockers()
6078 maxreap = (atomic_read(&nn->nfs4_client_count) >= nn->nfs4_max_clients) ? in nfs4_get_client_reaplist()
6081 spin_lock(&nn->client_lock); in nfs4_get_client_reaplist()
6082 list_for_each_safe(pos, next, &nn->client_lru) { in nfs4_get_client_reaplist()
6084 if (clp->cl_state == NFSD4_EXPIRABLE) in nfs4_get_client_reaplist()
6086 if (!state_expired(lt, clp->cl_time)) in nfs4_get_client_reaplist()
6088 if (!atomic_read(&clp->cl_rpc_users)) { in nfs4_get_client_reaplist()
6089 if (clp->cl_state == NFSD4_ACTIVE) in nfs4_get_client_reaplist()
6090 atomic_inc(&nn->nfsd_courtesy_clients); in nfs4_get_client_reaplist()
6091 clp->cl_state = NFSD4_COURTESY; in nfs4_get_client_reaplist()
6100 list_add(&clp->cl_lru, reaplist); in nfs4_get_client_reaplist()
6104 spin_unlock(&nn->client_lock); in nfs4_get_client_reaplist()
6118 spin_lock(&nn->client_lock); in nfs4_get_courtesy_client_reaplist()
6119 list_for_each_safe(pos, next, &nn->client_lru) { in nfs4_get_courtesy_client_reaplist()
6121 if (clp->cl_state == NFSD4_ACTIVE) in nfs4_get_courtesy_client_reaplist()
6126 list_add(&clp->cl_lru, reaplist); in nfs4_get_courtesy_client_reaplist()
6130 spin_unlock(&nn->client_lock); in nfs4_get_courtesy_client_reaplist()
6141 trace_nfsd_clid_purged(&clp->cl_clientid); in nfs4_process_client_reaplist()
6142 list_del_init(&clp->cl_lru); in nfs4_process_client_reaplist()
6156 .cutoff = ktime_get_boottime_seconds() - nn->nfsd4_lease, in nfs4_laundromat()
6157 .new_timeo = nn->nfsd4_lease in nfs4_laundromat()
6169 spin_lock(&nn->s2s_cp_lock); in nfs4_laundromat()
6170 idr_for_each_entry(&nn->s2s_cp_stateids, cps_t, i) { in nfs4_laundromat()
6172 if (cps->cp_stateid.cs_type == NFS4_COPYNOTIFY_STID && in nfs4_laundromat()
6173 state_expired(&lt, cps->cpntf_time)) in nfs4_laundromat()
6176 spin_unlock(&nn->s2s_cp_lock); in nfs4_laundromat()
6181 list_for_each_safe(pos, next, &nn->del_recall_lru) { in nfs4_laundromat()
6183 if (!state_expired(&lt, dp->dl_time)) in nfs4_laundromat()
6186 list_add(&dp->dl_recall_lru, &reaplist); in nfs4_laundromat()
6192 list_del_init(&dp->dl_recall_lru); in nfs4_laundromat()
6196 spin_lock(&nn->client_lock); in nfs4_laundromat()
6197 while (!list_empty(&nn->close_lru)) { in nfs4_laundromat()
6198 oo = list_first_entry(&nn->close_lru, struct nfs4_openowner, in nfs4_laundromat()
6200 if (!state_expired(&lt, oo->oo_time)) in nfs4_laundromat()
6202 list_del_init(&oo->oo_close_lru); in nfs4_laundromat()
6203 stp = oo->oo_last_closed_stid; in nfs4_laundromat()
6204 oo->oo_last_closed_stid = NULL; in nfs4_laundromat()
6205 spin_unlock(&nn->client_lock); in nfs4_laundromat()
6206 nfs4_put_stid(&stp->st_stid); in nfs4_laundromat()
6207 spin_lock(&nn->client_lock); in nfs4_laundromat()
6209 spin_unlock(&nn->client_lock); in nfs4_laundromat()
6214 * So, we clean out any un-revisited request after a lease period in nfs4_laundromat()
6223 spin_lock(&nn->blocked_locks_lock); in nfs4_laundromat()
6224 while (!list_empty(&nn->blocked_locks_lru)) { in nfs4_laundromat()
6225 nbl = list_first_entry(&nn->blocked_locks_lru, in nfs4_laundromat()
6227 if (!state_expired(&lt, nbl->nbl_time)) in nfs4_laundromat()
6229 list_move(&nbl->nbl_lru, &reaplist); in nfs4_laundromat()
6230 list_del_init(&nbl->nbl_list); in nfs4_laundromat()
6232 spin_unlock(&nn->blocked_locks_lock); in nfs4_laundromat()
6237 list_del_init(&nbl->nbl_lru); in nfs4_laundromat()
6241 /* service the server-to-server copy delayed unmount list */ in nfs4_laundromat()
6259 queue_delayed_work(laundry_wq, &nn->laundromat_work, t*HZ); in laundromat_main()
6279 spin_lock(&nn->client_lock); in deleg_reaper()
6280 list_for_each_safe(pos, next, &nn->client_lru) { in deleg_reaper()
6282 if (clp->cl_state != NFSD4_ACTIVE || in deleg_reaper()
6283 list_empty(&clp->cl_delegations) || in deleg_reaper()
6284 atomic_read(&clp->cl_delegs_in_recall) || in deleg_reaper()
6285 test_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags) || in deleg_reaper()
6286 (ktime_get_boottime_seconds() - in deleg_reaper()
6287 clp->cl_ra_time < 5)) { in deleg_reaper()
6290 list_add(&clp->cl_ra_cblist, &cblist); in deleg_reaper()
6293 kref_get(&clp->cl_nfsdfs.cl_ref); in deleg_reaper()
6294 set_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags); in deleg_reaper()
6295 clp->cl_ra_time = ktime_get_boottime_seconds(); in deleg_reaper()
6297 spin_unlock(&nn->client_lock); in deleg_reaper()
6302 list_del_init(&clp->cl_ra_cblist); in deleg_reaper()
6303 clp->cl_ra->ra_keep = 0; in deleg_reaper()
6304 clp->cl_ra->ra_bmval[0] = BIT(RCA4_TYPE_MASK_RDATA_DLG); in deleg_reaper()
6305 trace_nfsd_cb_recall_any(clp->cl_ra); in deleg_reaper()
6306 nfsd4_run_cb(&clp->cl_ra->ra_cb); in deleg_reaper()
6322 if (!fh_match(&fhp->fh_handle, &stp->sc_file->fi_fhandle)) in nfs4_check_fh()
6333 if (stp->st_openstp) in nfs4_check_openmode()
6334 stp = stp->st_openstp; in nfs4_check_openmode()
6367 if (has_session && in->si_generation == 0) in check_stateid_generation()
6370 if (in->si_generation == ref->si_generation) in check_stateid_generation()
6378 * non-buggy client. For example, if the client sends a lock in check_stateid_generation()
6393 spin_lock(&s->sc_lock); in nfsd4_stid_check_stateid_generation()
6396 ret = check_stateid_generation(in, &s->sc_stateid, has_session); in nfsd4_stid_check_stateid_generation()
6397 spin_unlock(&s->sc_lock); in nfsd4_stid_check_stateid_generation()
6403 if (ols->st_stateowner->so_is_open_owner && in nfsd4_check_openowner_confirmed()
6404 !(openowner(ols->st_stateowner)->oo_flags & NFS4_OO_CONFIRMED)) in nfsd4_check_openowner_confirmed()
6417 spin_lock(&cl->cl_lock); in nfsd4_validate_stateid()
6424 switch (s->sc_type) { in nfsd4_validate_stateid()
6436 printk("unknown stateid type %x\n", s->sc_type); in nfsd4_validate_stateid()
6443 spin_unlock(&cl->cl_lock); in nfsd4_validate_stateid()
6468 status = set_client(&stateid->si_opaque.so_clid, cstate, nn); in nfsd4_lookup_stateid()
6470 if (cstate->session) in nfsd4_lookup_stateid()
6476 stid = find_stateid_by_type(cstate->clp, stateid, typemask); in nfsd4_lookup_stateid()
6479 if ((stid->sc_type == NFS4_REVOKED_DELEG_STID) && !return_revoked) { in nfsd4_lookup_stateid()
6481 if (cstate->minorversion) in nfsd4_lookup_stateid()
6497 switch (s->sc_type) { in nfs4_find_file()
6499 spin_lock(&s->sc_file->fi_lock); in nfs4_find_file()
6500 ret = nfsd_file_get(s->sc_file->fi_deleg_file); in nfs4_find_file()
6501 spin_unlock(&s->sc_file->fi_lock); in nfs4_find_file()
6506 ret = find_readable_file(s->sc_file); in nfs4_find_file()
6508 ret = find_writeable_file(s->sc_file); in nfs4_find_file()
6535 status = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry, in nfs4_check_file()
6553 WARN_ON_ONCE(cps->cp_stateid.cs_type != NFS4_COPYNOTIFY_STID); in _free_cpntf_state_locked()
6554 if (!refcount_dec_and_test(&cps->cp_stateid.cs_count)) in _free_cpntf_state_locked()
6556 list_del(&cps->cp_list); in _free_cpntf_state_locked()
6557 idr_remove(&nn->s2s_cp_stateids, in _free_cpntf_state_locked()
6558 cps->cp_stateid.cs_stid.si_opaque.so_id); in _free_cpntf_state_locked()
6573 if (st->si_opaque.so_clid.cl_id != nn->s2s_cp_cl_id) in manage_cpntf_state()
6575 spin_lock(&nn->s2s_cp_lock); in manage_cpntf_state()
6576 cps_t = idr_find(&nn->s2s_cp_stateids, st->si_opaque.so_id); in manage_cpntf_state()
6580 if (state->cp_stateid.cs_type != NFS4_COPYNOTIFY_STID) { in manage_cpntf_state()
6585 refcount_inc(&state->cp_stateid.cs_count); in manage_cpntf_state()
6590 spin_unlock(&nn->s2s_cp_lock); in manage_cpntf_state()
6609 cps->cpntf_time = ktime_get_boottime_seconds(); in find_cpntf_state()
6612 found = lookup_clientid(&cps->cp_p_clid, true, nn); in find_cpntf_state()
6616 *stid = find_stateid_by_type(found, &cps->cp_p_stateid, in find_cpntf_state()
6631 spin_lock(&nn->s2s_cp_lock); in nfs4_put_cpntf_state()
6633 spin_unlock(&nn->s2s_cp_lock); in nfs4_put_cpntf_state()
6637 * nfs4_preprocess_stateid_op - find and prep stateid for an operation
6685 switch (s->sc_type) { in nfs4_preprocess_stateid_op()
6721 struct nfsd4_test_stateid *test_stateid = &u->test_stateid; in nfsd4_test_stateid()
6723 struct nfs4_client *cl = cstate->clp; in nfsd4_test_stateid()
6725 list_for_each_entry(stateid, &test_stateid->ts_stateid_list, ts_id_list) in nfsd4_test_stateid()
6726 stateid->ts_id_status = in nfsd4_test_stateid()
6727 nfsd4_validate_stateid(cl, &stateid->ts_id_stateid); in nfsd4_test_stateid()
6742 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); in nfsd4_free_lock_stateid()
6747 if (check_for_locks(stp->st_stid.sc_file, in nfsd4_free_lock_stateid()
6748 lockowner(stp->st_stateowner))) in nfsd4_free_lock_stateid()
6755 mutex_unlock(&stp->st_mutex); in nfsd4_free_lock_stateid()
6765 struct nfsd4_free_stateid *free_stateid = &u->free_stateid; in nfsd4_free_stateid()
6766 stateid_t *stateid = &free_stateid->fr_stateid; in nfsd4_free_stateid()
6769 struct nfs4_client *cl = cstate->clp; in nfsd4_free_stateid()
6772 spin_lock(&cl->cl_lock); in nfsd4_free_stateid()
6776 spin_lock(&s->sc_lock); in nfsd4_free_stateid()
6777 switch (s->sc_type) { in nfsd4_free_stateid()
6782 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); in nfsd4_free_stateid()
6788 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6789 refcount_inc(&s->sc_count); in nfsd4_free_stateid()
6790 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6794 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6796 list_del_init(&dp->dl_recall_lru); in nfsd4_free_stateid()
6797 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6803 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6805 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6819 struct svc_fh *current_fh = &cstate->current_fh; in nfs4_seqid_op_checks()
6820 struct nfs4_stateowner *sop = stp->st_stateowner; in nfs4_seqid_op_checks()
6829 status = check_stateid_generation(stateid, &stp->st_stid.sc_stateid, nfsd4_has_session(cstate)); in nfs4_seqid_op_checks()
6831 status = nfs4_check_fh(current_fh, &stp->st_stid); in nfs4_seqid_op_checks()
6833 mutex_unlock(&stp->st_mutex); in nfs4_seqid_op_checks()
6838 * nfs4_preprocess_seqid_op - find and prep an ol_stateid for a seqid-morphing op
6867 nfsd4_cstate_assign_replay(cstate, stp->st_stateowner); in nfs4_preprocess_seqid_op()
6873 nfs4_put_stid(&stp->st_stid); in nfs4_preprocess_seqid_op()
6888 oo = openowner(stp->st_stateowner); in nfs4_preprocess_confirmed_seqid_op()
6889 if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { in nfs4_preprocess_confirmed_seqid_op()
6890 mutex_unlock(&stp->st_mutex); in nfs4_preprocess_confirmed_seqid_op()
6891 nfs4_put_stid(&stp->st_stid); in nfs4_preprocess_confirmed_seqid_op()
6902 struct nfsd4_open_confirm *oc = &u->open_confirm; in nfsd4_open_confirm()
6909 cstate->current_fh.fh_dentry); in nfsd4_open_confirm()
6911 status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0); in nfsd4_open_confirm()
6916 oc->oc_seqid, &oc->oc_req_stateid, in nfsd4_open_confirm()
6920 oo = openowner(stp->st_stateowner); in nfsd4_open_confirm()
6922 if (oo->oo_flags & NFS4_OO_CONFIRMED) { in nfsd4_open_confirm()
6923 mutex_unlock(&stp->st_mutex); in nfsd4_open_confirm()
6926 oo->oo_flags |= NFS4_OO_CONFIRMED; in nfsd4_open_confirm()
6927 nfs4_inc_and_copy_stateid(&oc->oc_resp_stateid, &stp->st_stid); in nfsd4_open_confirm()
6928 mutex_unlock(&stp->st_mutex); in nfsd4_open_confirm()
6929 trace_nfsd_open_confirm(oc->oc_seqid, &stp->st_stid.sc_stateid); in nfsd4_open_confirm()
6930 nfsd4_client_record_create(oo->oo_owner.so_client); in nfsd4_open_confirm()
6933 nfs4_put_stid(&stp->st_stid); in nfsd4_open_confirm()
6943 nfs4_file_put_access(stp->st_stid.sc_file, access); in nfs4_stateid_downgrade_bit()
6969 struct nfsd4_open_downgrade *od = &u->open_downgrade; in nfsd4_open_downgrade()
6975 cstate->current_fh.fh_dentry); in nfsd4_open_downgrade()
6978 if (od->od_deleg_want) in nfsd4_open_downgrade()
6980 od->od_deleg_want); in nfsd4_open_downgrade()
6982 status = nfs4_preprocess_confirmed_seqid_op(cstate, od->od_seqid, in nfsd4_open_downgrade()
6983 &od->od_stateid, &stp, nn); in nfsd4_open_downgrade()
6987 if (!test_access(od->od_share_access, stp)) { in nfsd4_open_downgrade()
6989 stp->st_access_bmap, od->od_share_access); in nfsd4_open_downgrade()
6992 if (!test_deny(od->od_share_deny, stp)) { in nfsd4_open_downgrade()
6994 stp->st_deny_bmap, od->od_share_deny); in nfsd4_open_downgrade()
6997 nfs4_stateid_downgrade(stp, od->od_share_access); in nfsd4_open_downgrade()
6998 reset_union_bmap_deny(od->od_share_deny, stp); in nfsd4_open_downgrade()
6999 nfs4_inc_and_copy_stateid(&od->od_stateid, &stp->st_stid); in nfsd4_open_downgrade()
7002 mutex_unlock(&stp->st_mutex); in nfsd4_open_downgrade()
7003 nfs4_put_stid(&stp->st_stid); in nfsd4_open_downgrade()
7011 struct nfs4_client *clp = s->st_stid.sc_client; in nfsd4_close_open_stateid()
7016 spin_lock(&clp->cl_lock); in nfsd4_close_open_stateid()
7019 if (clp->cl_minorversion) { in nfsd4_close_open_stateid()
7022 spin_unlock(&clp->cl_lock); in nfsd4_close_open_stateid()
7024 nfs4_free_cpntf_statelist(clp->net, &stp->st_stid); in nfsd4_close_open_stateid()
7027 spin_unlock(&clp->cl_lock); in nfsd4_close_open_stateid()
7030 move_to_close_lru(s, clp->net); in nfsd4_close_open_stateid()
7041 struct nfsd4_close *close = &u->close; in nfsd4_close()
7048 cstate->current_fh.fh_dentry); in nfsd4_close()
7050 status = nfs4_preprocess_seqid_op(cstate, close->cl_seqid, in nfsd4_close()
7051 &close->cl_stateid, in nfsd4_close()
7058 stp->st_stid.sc_type = NFS4_CLOSED_STID; in nfsd4_close()
7066 nfs4_inc_and_copy_stateid(&close->cl_stateid, &stp->st_stid); in nfsd4_close()
7069 mutex_unlock(&stp->st_mutex); in nfsd4_close()
7078 memcpy(&close->cl_stateid, &close_stateid, sizeof(close->cl_stateid)); in nfsd4_close()
7081 nfs4_put_stid(&stp->st_stid); in nfsd4_close()
7090 struct nfsd4_delegreturn *dr = &u->delegreturn; in nfsd4_delegreturn()
7092 stateid_t *stateid = &dr->dr_stateid; in nfsd4_delegreturn()
7097 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) in nfsd4_delegreturn()
7104 status = nfsd4_stid_check_stateid_generation(stateid, &dp->dl_stid, nfsd4_has_session(cstate)); in nfsd4_delegreturn()
7109 wake_up_var(d_inode(cstate->current_fh.fh_dentry)); in nfsd4_delegreturn()
7112 nfs4_put_stid(&dp->dl_stid); in nfsd4_delegreturn()
7125 return end > start ? end - 1: NFS4_MAX_UINT64; in last_byte_offset()
7129 * TODO: Linux file offsets are _signed_ 64-bit quantities, which means that
7130 * we can't properly handle lock requests that go beyond the (2^63 - 1)-th
7131 * byte, because of sign extension problems. Since NFSv4 calls for 64-bit
7132 * locking, this prevents us from being completely protocol-compliant. The
7139 if (lock->fl_start < 0) in nfs4_transform_lock_offset()
7140 lock->fl_start = OFFSET_MAX; in nfs4_transform_lock_offset()
7141 if (lock->fl_end < 0) in nfs4_transform_lock_offset()
7142 lock->fl_end = OFFSET_MAX; in nfs4_transform_lock_offset()
7150 nfs4_get_stateowner(&lo->lo_owner); in nfsd4_lm_get_owner()
7160 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_lm_put_owner()
7167 struct nfs4_lockowner *lo = (struct nfs4_lockowner *)cfl->fl_owner; in nfsd4_lm_lock_expirable()
7168 struct nfs4_client *clp = lo->lo_owner.so_client; in nfsd4_lm_lock_expirable()
7172 nn = net_generic(clp->net, nfsd_net_id); in nfsd4_lm_lock_expirable()
7173 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in nfsd4_lm_lock_expirable()
7189 struct nfs4_lockowner *lo = (struct nfs4_lockowner *)fl->fl_owner; in nfsd4_lm_notify()
7190 struct net *net = lo->lo_owner.so_client->net; in nfsd4_lm_notify()
7197 spin_lock(&nn->blocked_locks_lock); in nfsd4_lm_notify()
7198 if (!list_empty(&nbl->nbl_list)) { in nfsd4_lm_notify()
7199 list_del_init(&nbl->nbl_list); in nfsd4_lm_notify()
7200 list_del_init(&nbl->nbl_lru); in nfsd4_lm_notify()
7203 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lm_notify()
7207 nfsd4_run_cb(&nbl->nbl_cb); in nfsd4_lm_notify()
7225 if (fl->fl_lmops == &nfsd_posix_mng_ops) { in nfs4_set_lock_denied()
7226 lo = (struct nfs4_lockowner *) fl->fl_owner; in nfs4_set_lock_denied()
7227 xdr_netobj_dup(&deny->ld_owner, &lo->lo_owner.so_owner, in nfs4_set_lock_denied()
7229 if (!deny->ld_owner.data) in nfs4_set_lock_denied()
7232 deny->ld_clientid = lo->lo_owner.so_client->cl_clientid; in nfs4_set_lock_denied()
7235 deny->ld_owner.len = 0; in nfs4_set_lock_denied()
7236 deny->ld_owner.data = NULL; in nfs4_set_lock_denied()
7237 deny->ld_clientid.cl_boot = 0; in nfs4_set_lock_denied()
7238 deny->ld_clientid.cl_id = 0; in nfs4_set_lock_denied()
7240 deny->ld_start = fl->fl_start; in nfs4_set_lock_denied()
7241 deny->ld_length = NFS4_MAX_UINT64; in nfs4_set_lock_denied()
7242 if (fl->fl_end != NFS4_MAX_UINT64) in nfs4_set_lock_denied()
7243 deny->ld_length = fl->fl_end - fl->fl_start + 1; in nfs4_set_lock_denied()
7244 deny->ld_type = NFS4_READ_LT; in nfs4_set_lock_denied()
7245 if (fl->fl_type != F_RDLCK) in nfs4_set_lock_denied()
7246 deny->ld_type = NFS4_WRITE_LT; in nfs4_set_lock_denied()
7255 lockdep_assert_held(&clp->cl_lock); in find_lockowner_str_locked()
7257 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[strhashval], in find_lockowner_str_locked()
7259 if (so->so_is_open_owner) in find_lockowner_str_locked()
7272 spin_lock(&clp->cl_lock); in find_lockowner_str()
7274 spin_unlock(&clp->cl_lock); in find_lockowner_str()
7297 * Called in nfsd4_lock - therefore, OPEN and OPEN_CONFIRM (if needed) has
7309 lo = alloc_stateowner(lockowner_slab, &lock->lk_new_owner, clp); in alloc_init_lock_stateowner()
7312 INIT_LIST_HEAD(&lo->lo_blocked); in alloc_init_lock_stateowner()
7313 INIT_LIST_HEAD(&lo->lo_owner.so_stateids); in alloc_init_lock_stateowner()
7314 lo->lo_owner.so_is_open_owner = 0; in alloc_init_lock_stateowner()
7315 lo->lo_owner.so_seqid = lock->lk_new_lock_seqid; in alloc_init_lock_stateowner()
7316 lo->lo_owner.so_ops = &lockowner_ops; in alloc_init_lock_stateowner()
7317 spin_lock(&clp->cl_lock); in alloc_init_lock_stateowner()
7318 ret = find_lockowner_str_locked(clp, &lock->lk_new_owner); in alloc_init_lock_stateowner()
7320 list_add(&lo->lo_owner.so_strhash, in alloc_init_lock_stateowner()
7321 &clp->cl_ownerstr_hashtbl[strhashval]); in alloc_init_lock_stateowner()
7324 nfs4_free_stateowner(&lo->lo_owner); in alloc_init_lock_stateowner()
7326 spin_unlock(&clp->cl_lock); in alloc_init_lock_stateowner()
7336 lockdep_assert_held(&ost->st_stid.sc_client->cl_lock); in find_lock_stateid()
7338 /* If ost is not hashed, ost->st_locks will not be valid */ in find_lock_stateid()
7340 list_for_each_entry(lst, &ost->st_locks, st_locks) { in find_lock_stateid()
7341 if (lst->st_stateowner == &lo->lo_owner) { in find_lock_stateid()
7342 refcount_inc(&lst->st_stid.sc_count); in find_lock_stateid()
7354 struct nfs4_client *clp = lo->lo_owner.so_client; in init_lock_stateid()
7357 mutex_init(&stp->st_mutex); in init_lock_stateid()
7358 mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX); in init_lock_stateid()
7360 spin_lock(&clp->cl_lock); in init_lock_stateid()
7366 refcount_inc(&stp->st_stid.sc_count); in init_lock_stateid()
7367 stp->st_stid.sc_type = NFS4_LOCK_STID; in init_lock_stateid()
7368 stp->st_stateowner = nfs4_get_stateowner(&lo->lo_owner); in init_lock_stateid()
7370 stp->st_stid.sc_file = fp; in init_lock_stateid()
7371 stp->st_access_bmap = 0; in init_lock_stateid()
7372 stp->st_deny_bmap = open_stp->st_deny_bmap; in init_lock_stateid()
7373 stp->st_openstp = open_stp; in init_lock_stateid()
7374 spin_lock(&fp->fi_lock); in init_lock_stateid()
7375 list_add(&stp->st_locks, &open_stp->st_locks); in init_lock_stateid()
7376 list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids); in init_lock_stateid()
7377 list_add(&stp->st_perfile, &fp->fi_stateids); in init_lock_stateid()
7378 spin_unlock(&fp->fi_lock); in init_lock_stateid()
7379 spin_unlock(&clp->cl_lock); in init_lock_stateid()
7382 spin_unlock(&clp->cl_lock); in init_lock_stateid()
7384 nfs4_put_stid(&retstp->st_stid); in init_lock_stateid()
7388 mutex_unlock(&stp->st_mutex); in init_lock_stateid()
7391 spin_unlock(&clp->cl_lock); in init_lock_stateid()
7392 mutex_unlock(&stp->st_mutex); in init_lock_stateid()
7403 struct nfs4_openowner *oo = openowner(ost->st_stateowner); in find_or_create_lock_stateid()
7404 struct nfs4_client *clp = oo->oo_owner.so_client; in find_or_create_lock_stateid()
7407 spin_lock(&clp->cl_lock); in find_or_create_lock_stateid()
7409 spin_unlock(&clp->cl_lock); in find_or_create_lock_stateid()
7413 nfs4_put_stid(&lst->st_stid); in find_or_create_lock_stateid()
7437 struct nfs4_file *fp = lock_stp->st_stid.sc_file; in get_lock_access()
7439 lockdep_assert_held(&fp->fi_lock); in get_lock_access()
7454 struct nfs4_file *fi = ost->st_stid.sc_file; in lookup_or_create_lock_state()
7455 struct nfs4_openowner *oo = openowner(ost->st_stateowner); in lookup_or_create_lock_state()
7456 struct nfs4_client *cl = oo->oo_owner.so_client; in lookup_or_create_lock_state()
7457 struct inode *inode = d_inode(cstate->current_fh.fh_dentry); in lookup_or_create_lock_state()
7462 lo = find_lockowner_str(cl, &lock->lk_new_owner); in lookup_or_create_lock_state()
7464 strhashval = ownerstr_hashval(&lock->lk_new_owner); in lookup_or_create_lock_state()
7471 if (!cstate->minorversion && in lookup_or_create_lock_state()
7472 lock->lk_new_lock_seqid != lo->lo_owner.so_seqid) in lookup_or_create_lock_state()
7485 nfs4_put_stateowner(&lo->lo_owner); in lookup_or_create_lock_state()
7496 struct nfsd4_lock *lock = &u->lock; in nfsd4_lock()
7516 (long long) lock->lk_offset, in nfsd4_lock()
7517 (long long) lock->lk_length); in nfsd4_lock()
7519 if (check_lock_length(lock->lk_offset, lock->lk_length)) in nfsd4_lock()
7522 if ((status = fh_verify(rqstp, &cstate->current_fh, in nfsd4_lock()
7528 if (lock->lk_is_new) { in nfsd4_lock()
7531 memcpy(&lock->lk_new_clientid, in nfsd4_lock()
7532 &cstate->clp->cl_clientid, in nfsd4_lock()
7537 lock->lk_new_open_seqid, in nfsd4_lock()
7538 &lock->lk_new_open_stateid, in nfsd4_lock()
7542 mutex_unlock(&open_stp->st_mutex); in nfsd4_lock()
7543 open_sop = openowner(open_stp->st_stateowner); in nfsd4_lock()
7545 if (!same_clid(&open_sop->oo_owner.so_client->cl_clientid, in nfsd4_lock()
7546 &lock->lk_new_clientid)) in nfsd4_lock()
7552 lock->lk_old_lock_seqid, in nfsd4_lock()
7553 &lock->lk_old_lock_stateid, in nfsd4_lock()
7558 lock_sop = lockowner(lock_stp->st_stateowner); in nfsd4_lock()
7560 lkflg = setlkflg(lock->lk_type); in nfsd4_lock()
7566 if (locks_in_grace(net) && !lock->lk_reclaim) in nfsd4_lock()
7569 if (!locks_in_grace(net) && lock->lk_reclaim) in nfsd4_lock()
7572 if (lock->lk_reclaim) in nfsd4_lock()
7575 fp = lock_stp->st_stid.sc_file; in nfsd4_lock()
7576 switch (lock->lk_type) { in nfsd4_lock()
7582 spin_lock(&fp->fi_lock); in nfsd4_lock()
7586 spin_unlock(&fp->fi_lock); in nfsd4_lock()
7594 spin_lock(&fp->fi_lock); in nfsd4_lock()
7598 spin_unlock(&fp->fi_lock); in nfsd4_lock()
7612 * Most filesystems with their own ->lock operations will block in nfsd4_lock()
7618 if (nf->nf_file->f_op->lock) in nfsd4_lock()
7621 nbl = find_or_allocate_block(lock_sop, &fp->fi_fhandle, nn); in nfsd4_lock()
7628 file_lock = &nbl->nbl_lock; in nfsd4_lock()
7629 file_lock->fl_type = fl_type; in nfsd4_lock()
7630 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(&lock_sop->lo_owner)); in nfsd4_lock()
7631 file_lock->fl_pid = current->tgid; in nfsd4_lock()
7632 file_lock->fl_file = nf->nf_file; in nfsd4_lock()
7633 file_lock->fl_flags = fl_flags; in nfsd4_lock()
7634 file_lock->fl_lmops = &nfsd_posix_mng_ops; in nfsd4_lock()
7635 file_lock->fl_start = lock->lk_offset; in nfsd4_lock()
7636 file_lock->fl_end = last_byte_offset(lock->lk_offset, lock->lk_length); in nfsd4_lock()
7647 nbl->nbl_time = ktime_get_boottime_seconds(); in nfsd4_lock()
7648 spin_lock(&nn->blocked_locks_lock); in nfsd4_lock()
7649 list_add_tail(&nbl->nbl_list, &lock_sop->lo_blocked); in nfsd4_lock()
7650 list_add_tail(&nbl->nbl_lru, &nn->blocked_locks_lru); in nfsd4_lock()
7651 kref_get(&nbl->nbl_kref); in nfsd4_lock()
7652 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lock()
7655 err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, conflock); in nfsd4_lock()
7658 nfs4_inc_and_copy_stateid(&lock->lk_resp_stateid, &lock_stp->st_stid); in nfsd4_lock()
7660 if (lock->lk_reclaim) in nfsd4_lock()
7661 nn->somebody_reclaimed = true; in nfsd4_lock()
7664 kref_put(&nbl->nbl_kref, free_nbl); in nfsd4_lock()
7667 case -EAGAIN: /* conflock holds conflicting lock */ in nfsd4_lock()
7670 nfs4_set_lock_denied(conflock, &lock->lk_denied); in nfsd4_lock()
7672 case -EDEADLK: in nfsd4_lock()
7684 spin_lock(&nn->blocked_locks_lock); in nfsd4_lock()
7685 if (!list_empty(&nbl->nbl_list) && in nfsd4_lock()
7686 !list_empty(&nbl->nbl_lru)) { in nfsd4_lock()
7687 list_del_init(&nbl->nbl_list); in nfsd4_lock()
7688 list_del_init(&nbl->nbl_lru); in nfsd4_lock()
7689 kref_put(&nbl->nbl_kref, free_nbl); in nfsd4_lock()
7692 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lock()
7700 if (cstate->replay_owner && in nfsd4_lock()
7701 cstate->replay_owner != &lock_sop->lo_owner && in nfsd4_lock()
7703 lock_sop->lo_owner.so_seqid++; in nfsd4_lock()
7706 * If this is a new, never-before-used stateid, and we are in nfsd4_lock()
7712 mutex_unlock(&lock_stp->st_mutex); in nfsd4_lock()
7714 nfs4_put_stid(&lock_stp->st_stid); in nfsd4_lock()
7717 nfs4_put_stid(&open_stp->st_stid); in nfsd4_lock()
7738 inode = fhp->fh_dentry->d_inode; in nfsd_test_lock()
7743 lock->fl_file = nf->nf_file; in nfsd_test_lock()
7744 err = nfserrno(vfs_test_lock(nf->nf_file, lock)); in nfsd_test_lock()
7745 lock->fl_file = NULL; in nfsd_test_lock()
7759 struct nfsd4_lockt *lockt = &u->lockt; in nfsd4_lockt()
7768 if (check_lock_length(lockt->lt_offset, lockt->lt_length)) in nfsd4_lockt()
7772 status = set_client(&lockt->lt_clientid, cstate, nn); in nfsd4_lockt()
7777 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) in nfsd4_lockt()
7787 switch (lockt->lt_type) { in nfsd4_lockt()
7790 file_lock->fl_type = F_RDLCK; in nfsd4_lockt()
7794 file_lock->fl_type = F_WRLCK; in nfsd4_lockt()
7802 lo = find_lockowner_str(cstate->clp, &lockt->lt_owner); in nfsd4_lockt()
7804 file_lock->fl_owner = (fl_owner_t)lo; in nfsd4_lockt()
7805 file_lock->fl_pid = current->tgid; in nfsd4_lockt()
7806 file_lock->fl_flags = FL_POSIX; in nfsd4_lockt()
7808 file_lock->fl_start = lockt->lt_offset; in nfsd4_lockt()
7809 file_lock->fl_end = last_byte_offset(lockt->lt_offset, lockt->lt_length); in nfsd4_lockt()
7813 status = nfsd_test_lock(rqstp, &cstate->current_fh, file_lock); in nfsd4_lockt()
7817 if (file_lock->fl_type != F_UNLCK) { in nfsd4_lockt()
7819 nfs4_set_lock_denied(file_lock, &lockt->lt_denied); in nfsd4_lockt()
7823 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_lockt()
7833 struct nfsd4_locku *locku = &u->locku; in nfsd4_locku()
7842 (long long) locku->lu_offset, in nfsd4_locku()
7843 (long long) locku->lu_length); in nfsd4_locku()
7845 if (check_lock_length(locku->lu_offset, locku->lu_length)) in nfsd4_locku()
7848 status = nfs4_preprocess_seqid_op(cstate, locku->lu_seqid, in nfsd4_locku()
7849 &locku->lu_stateid, NFS4_LOCK_STID, in nfsd4_locku()
7853 nf = find_any_file(stp->st_stid.sc_file); in nfsd4_locku()
7865 file_lock->fl_type = F_UNLCK; in nfsd4_locku()
7866 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(stp->st_stateowner)); in nfsd4_locku()
7867 file_lock->fl_pid = current->tgid; in nfsd4_locku()
7868 file_lock->fl_file = nf->nf_file; in nfsd4_locku()
7869 file_lock->fl_flags = FL_POSIX; in nfsd4_locku()
7870 file_lock->fl_lmops = &nfsd_posix_mng_ops; in nfsd4_locku()
7871 file_lock->fl_start = locku->lu_offset; in nfsd4_locku()
7873 file_lock->fl_end = last_byte_offset(locku->lu_offset, in nfsd4_locku()
7874 locku->lu_length); in nfsd4_locku()
7877 err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, NULL); in nfsd4_locku()
7882 nfs4_inc_and_copy_stateid(&locku->lu_stateid, &stp->st_stid); in nfsd4_locku()
7886 mutex_unlock(&stp->st_mutex); in nfsd4_locku()
7887 nfs4_put_stid(&stp->st_stid); in nfsd4_locku()
7913 spin_lock(&fp->fi_lock); in check_for_locks()
7921 inode = file_inode(nf->nf_file); in check_for_locks()
7924 if (flctx && !list_empty_careful(&flctx->flc_posix)) { in check_for_locks()
7925 spin_lock(&flctx->flc_lock); in check_for_locks()
7926 list_for_each_entry(fl, &flctx->flc_posix, fl_list) { in check_for_locks()
7927 if (fl->fl_owner == (fl_owner_t)lowner) { in check_for_locks()
7932 spin_unlock(&flctx->flc_lock); in check_for_locks()
7935 spin_unlock(&fp->fi_lock); in check_for_locks()
7940 * nfsd4_release_lockowner - process NFSv4.0 RELEASE_LOCKOWNER operations
7945 * Check if theree are any locks still held and if not - free the lockowner
7959 struct nfsd4_release_lockowner *rlockowner = &u->release_lockowner; in nfsd4_release_lockowner()
7961 clientid_t *clid = &rlockowner->rl_clientid; in nfsd4_release_lockowner()
7969 clid->cl_boot, clid->cl_id); in nfsd4_release_lockowner()
7974 clp = cstate->clp; in nfsd4_release_lockowner()
7976 spin_lock(&clp->cl_lock); in nfsd4_release_lockowner()
7977 lo = find_lockowner_str_locked(clp, &rlockowner->rl_owner); in nfsd4_release_lockowner()
7979 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
7983 list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) { in nfsd4_release_lockowner()
7984 if (check_for_locks(stp->st_stid.sc_file, lo)) { in nfsd4_release_lockowner()
7985 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
7986 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_release_lockowner()
7991 while (!list_empty(&lo->lo_owner.so_stateids)) { in nfsd4_release_lockowner()
7992 stp = list_first_entry(&lo->lo_owner.so_stateids, in nfsd4_release_lockowner()
7998 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
8002 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_release_lockowner()
8018 return (crp && crp->cr_clp); in nfs4_has_reclaimed_state()
8037 INIT_LIST_HEAD(&crp->cr_strhash); in nfs4_client_to_reclaim()
8038 list_add(&crp->cr_strhash, &nn->reclaim_str_hashtbl[strhashval]); in nfs4_client_to_reclaim()
8039 crp->cr_name.data = name.data; in nfs4_client_to_reclaim()
8040 crp->cr_name.len = name.len; in nfs4_client_to_reclaim()
8041 crp->cr_princhash.data = princhash.data; in nfs4_client_to_reclaim()
8042 crp->cr_princhash.len = princhash.len; in nfs4_client_to_reclaim()
8043 crp->cr_clp = NULL; in nfs4_client_to_reclaim()
8044 nn->reclaim_str_hashtbl_size++; in nfs4_client_to_reclaim()
8052 list_del(&crp->cr_strhash); in nfs4_remove_reclaim_record()
8053 kfree(crp->cr_name.data); in nfs4_remove_reclaim_record()
8054 kfree(crp->cr_princhash.data); in nfs4_remove_reclaim_record()
8056 nn->reclaim_str_hashtbl_size--; in nfs4_remove_reclaim_record()
8066 while (!list_empty(&nn->reclaim_str_hashtbl[i])) { in nfs4_release_reclaim()
8067 crp = list_entry(nn->reclaim_str_hashtbl[i].next, in nfs4_release_reclaim()
8072 WARN_ON_ONCE(nn->reclaim_str_hashtbl_size); in nfs4_release_reclaim()
8084 list_for_each_entry(crp, &nn->reclaim_str_hashtbl[strhashval], cr_strhash) { in nfsd4_find_reclaim_client()
8085 if (compare_blob(&crp->cr_name, &name) == 0) { in nfsd4_find_reclaim_client()
8095 if (test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &clp->cl_flags)) in nfs4_check_open_reclaim()
8122 max_delegations = nr_free_buffer_pages() >> (20 - 2 - PAGE_SHIFT); in set_max_delegations()
8130 nn->conf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE, in nfs4_state_create_net()
8133 if (!nn->conf_id_hashtbl) in nfs4_state_create_net()
8135 nn->unconf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE, in nfs4_state_create_net()
8138 if (!nn->unconf_id_hashtbl) in nfs4_state_create_net()
8140 nn->sessionid_hashtbl = kmalloc_array(SESSION_HASH_SIZE, in nfs4_state_create_net()
8143 if (!nn->sessionid_hashtbl) in nfs4_state_create_net()
8147 INIT_LIST_HEAD(&nn->conf_id_hashtbl[i]); in nfs4_state_create_net()
8148 INIT_LIST_HEAD(&nn->unconf_id_hashtbl[i]); in nfs4_state_create_net()
8151 INIT_LIST_HEAD(&nn->sessionid_hashtbl[i]); in nfs4_state_create_net()
8152 nn->conf_name_tree = RB_ROOT; in nfs4_state_create_net()
8153 nn->unconf_name_tree = RB_ROOT; in nfs4_state_create_net()
8154 nn->boot_time = ktime_get_real_seconds(); in nfs4_state_create_net()
8155 nn->grace_ended = false; in nfs4_state_create_net()
8156 nn->nfsd4_manager.block_opens = true; in nfs4_state_create_net()
8157 INIT_LIST_HEAD(&nn->nfsd4_manager.list); in nfs4_state_create_net()
8158 INIT_LIST_HEAD(&nn->client_lru); in nfs4_state_create_net()
8159 INIT_LIST_HEAD(&nn->close_lru); in nfs4_state_create_net()
8160 INIT_LIST_HEAD(&nn->del_recall_lru); in nfs4_state_create_net()
8161 spin_lock_init(&nn->client_lock); in nfs4_state_create_net()
8162 spin_lock_init(&nn->s2s_cp_lock); in nfs4_state_create_net()
8163 idr_init(&nn->s2s_cp_stateids); in nfs4_state_create_net()
8164 atomic_set(&nn->pending_async_copies, 0); in nfs4_state_create_net()
8166 spin_lock_init(&nn->blocked_locks_lock); in nfs4_state_create_net()
8167 INIT_LIST_HEAD(&nn->blocked_locks_lru); in nfs4_state_create_net()
8169 INIT_DELAYED_WORK(&nn->laundromat_work, laundromat_main); in nfs4_state_create_net()
8170 INIT_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker); in nfs4_state_create_net()
8173 nn->nfsd_client_shrinker.scan_objects = nfsd4_state_shrinker_scan; in nfs4_state_create_net()
8174 nn->nfsd_client_shrinker.count_objects = nfsd4_state_shrinker_count; in nfs4_state_create_net()
8175 nn->nfsd_client_shrinker.seeks = DEFAULT_SEEKS; in nfs4_state_create_net()
8177 if (register_shrinker(&nn->nfsd_client_shrinker, "nfsd-client")) in nfs4_state_create_net()
8183 kfree(nn->sessionid_hashtbl); in nfs4_state_create_net()
8185 kfree(nn->unconf_id_hashtbl); in nfs4_state_create_net()
8187 kfree(nn->conf_id_hashtbl); in nfs4_state_create_net()
8189 return -ENOMEM; in nfs4_state_create_net()
8200 while (!list_empty(&nn->conf_id_hashtbl[i])) { in nfs4_state_destroy_net()
8201 clp = list_entry(nn->conf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); in nfs4_state_destroy_net()
8206 WARN_ON(!list_empty(&nn->blocked_locks_lru)); in nfs4_state_destroy_net()
8209 while (!list_empty(&nn->unconf_id_hashtbl[i])) { in nfs4_state_destroy_net()
8210 clp = list_entry(nn->unconf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); in nfs4_state_destroy_net()
8215 kfree(nn->sessionid_hashtbl); in nfs4_state_destroy_net()
8216 kfree(nn->unconf_id_hashtbl); in nfs4_state_destroy_net()
8217 kfree(nn->conf_id_hashtbl); in nfs4_state_destroy_net()
8230 locks_start_grace(net, &nn->nfsd4_manager); in nfs4_state_start_net()
8232 if (nn->track_reclaim_completes && nn->reclaim_str_hashtbl_size == 0) in nfs4_state_start_net()
8234 printk(KERN_INFO "NFSD: starting %lld-second grace period (net %x)\n", in nfs4_state_start_net()
8235 nn->nfsd4_grace, net->ns.inum); in nfs4_state_start_net()
8237 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_grace * HZ); in nfs4_state_start_net()
8242 net->ns.inum); in nfs4_state_start_net()
8243 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_lease * HZ); in nfs4_state_start_net()
8276 unregister_shrinker(&nn->nfsd_client_shrinker); in nfs4_state_shutdown_net()
8277 cancel_work_sync(&nn->nfsd_shrinker_work); in nfs4_state_shutdown_net()
8278 cancel_delayed_work_sync(&nn->laundromat_work); in nfs4_state_shutdown_net()
8279 locks_end_grace(&nn->nfsd4_manager); in nfs4_state_shutdown_net()
8283 list_for_each_safe(pos, next, &nn->del_recall_lru) { in nfs4_state_shutdown_net()
8286 list_add(&dp->dl_recall_lru, &reaplist); in nfs4_state_shutdown_net()
8291 list_del_init(&dp->dl_recall_lru); in nfs4_state_shutdown_net()
8314 memcpy(stateid, &cstate->current_stateid, sizeof(stateid_t)); in get_stateid()
8320 if (cstate->minorversion) { in put_stateid()
8321 memcpy(&cstate->current_stateid, stateid, sizeof(stateid_t)); in put_stateid()
8339 put_stateid(cstate, &u->open_downgrade.od_stateid); in nfsd4_set_opendowngradestateid()
8346 put_stateid(cstate, &u->open.op_stateid); in nfsd4_set_openstateid()
8353 put_stateid(cstate, &u->close.cl_stateid); in nfsd4_set_closestateid()
8360 put_stateid(cstate, &u->lock.lk_resp_stateid); in nfsd4_set_lockstateid()
8371 get_stateid(cstate, &u->open_downgrade.od_stateid); in nfsd4_get_opendowngradestateid()
8378 get_stateid(cstate, &u->delegreturn.dr_stateid); in nfsd4_get_delegreturnstateid()
8385 get_stateid(cstate, &u->free_stateid.fr_stateid); in nfsd4_get_freestateid()
8392 get_stateid(cstate, &u->setattr.sa_stateid); in nfsd4_get_setattrstateid()
8399 get_stateid(cstate, &u->close.cl_stateid); in nfsd4_get_closestateid()
8406 get_stateid(cstate, &u->locku.lu_stateid); in nfsd4_get_lockustateid()
8413 get_stateid(cstate, &u->read.rd_stateid); in nfsd4_get_readstateid()
8420 get_stateid(cstate, &u->write.wr_stateid); in nfsd4_get_writestateid()
8424 * nfsd4_deleg_getattr_conflict - Recall if GETATTR causes conflict
8454 spin_lock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
8455 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in nfsd4_deleg_getattr_conflict()
8456 if (fl->fl_flags == FL_LAYOUT) in nfsd4_deleg_getattr_conflict()
8458 if (fl->fl_lmops != &nfsd_lease_mng_ops) { in nfsd4_deleg_getattr_conflict()
8460 * non-nfs lease, if it's a lease with F_RDLCK then in nfsd4_deleg_getattr_conflict()
8464 if (fl->fl_type == F_RDLCK) in nfsd4_deleg_getattr_conflict()
8468 if (fl->fl_type == F_WRLCK) { in nfsd4_deleg_getattr_conflict()
8469 dp = fl->fl_owner; in nfsd4_deleg_getattr_conflict()
8470 if (dp->dl_recall.cb_clp == *(rqstp->rq_lease_breaker)) { in nfsd4_deleg_getattr_conflict()
8471 spin_unlock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
8475 spin_unlock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
8485 spin_unlock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()