Lines Matching +full:embedded +full:- +full:trace +full:- +full:extension

58 #include "trace.h"
107 * A waitqueue for all in-progress 4.0 CLOSE operations that are waiting for
141 rc = -ENOMEM; in nfsd4_create_laundry_wq()
152 return ses->se_dead; in is_session_dead()
157 if (atomic_read(&ses->se_ref) > ref_held_by_me) in mark_session_dead_locked()
159 ses->se_dead = true; in mark_session_dead_locked()
165 return clp->cl_time == 0; in is_client_expired()
171 if (clp->cl_state != NFSD4_ACTIVE) in nfsd4_dec_courtesy_client_count()
172 atomic_add_unless(&nn->nfsd_courtesy_clients, -1, 0); in nfsd4_dec_courtesy_client_count()
177 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in get_client_locked()
179 lockdep_assert_held(&nn->client_lock); in get_client_locked()
183 atomic_inc(&clp->cl_rpc_users); in get_client_locked()
185 clp->cl_state = NFSD4_ACTIVE; in get_client_locked()
193 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in renew_client_locked()
199 clp->cl_clientid.cl_boot, in renew_client_locked()
200 clp->cl_clientid.cl_id); in renew_client_locked()
204 list_move_tail(&clp->cl_lru, &nn->client_lru); in renew_client_locked()
205 clp->cl_time = ktime_get_boottime_seconds(); in renew_client_locked()
207 clp->cl_state = NFSD4_ACTIVE; in renew_client_locked()
212 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in put_client_renew_locked()
214 lockdep_assert_held(&nn->client_lock); in put_client_renew_locked()
216 if (!atomic_dec_and_test(&clp->cl_rpc_users)) in put_client_renew_locked()
226 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in put_client_renew()
228 if (!atomic_dec_and_lock(&clp->cl_rpc_users, &nn->client_lock)) in put_client_renew()
234 spin_unlock(&nn->client_lock); in put_client_renew()
243 status = get_client_locked(ses->se_client); in nfsd4_get_session_locked()
246 atomic_inc(&ses->se_ref); in nfsd4_get_session_locked()
252 struct nfs4_client *clp = ses->se_client; in nfsd4_put_session_locked()
253 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in nfsd4_put_session_locked()
255 lockdep_assert_held(&nn->client_lock); in nfsd4_put_session_locked()
257 if (atomic_dec_and_test(&ses->se_ref) && is_session_dead(ses)) in nfsd4_put_session_locked()
264 struct nfs4_client *clp = ses->se_client; in nfsd4_put_session()
265 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in nfsd4_put_session()
267 spin_lock(&nn->client_lock); in nfsd4_put_session()
269 spin_unlock(&nn->client_lock); in nfsd4_put_session()
278 spin_lock(&nn->blocked_locks_lock); in find_blocked_lock()
279 list_for_each_entry(cur, &lo->lo_blocked, nbl_list) { in find_blocked_lock()
280 if (fh_match(fh, &cur->nbl_fh)) { in find_blocked_lock()
281 list_del_init(&cur->nbl_list); in find_blocked_lock()
282 WARN_ON(list_empty(&cur->nbl_lru)); in find_blocked_lock()
283 list_del_init(&cur->nbl_lru); in find_blocked_lock()
288 spin_unlock(&nn->blocked_locks_lock); in find_blocked_lock()
290 locks_delete_block(&found->nbl_lock); in find_blocked_lock()
304 INIT_LIST_HEAD(&nbl->nbl_list); in find_or_allocate_block()
305 INIT_LIST_HEAD(&nbl->nbl_lru); in find_or_allocate_block()
306 fh_copy_shallow(&nbl->nbl_fh, fh); in find_or_allocate_block()
307 locks_init_lock(&nbl->nbl_lock); in find_or_allocate_block()
308 kref_init(&nbl->nbl_kref); in find_or_allocate_block()
309 nfsd4_init_cb(&nbl->nbl_cb, lo->lo_owner.so_client, in find_or_allocate_block()
323 locks_release_private(&nbl->nbl_lock); in free_nbl()
330 locks_delete_block(&nbl->nbl_lock); in free_blocked_lock()
331 kref_put(&nbl->nbl_kref, free_nbl); in free_blocked_lock()
337 struct nfs4_client *clp = lo->lo_owner.so_client; in remove_blocked_locks()
338 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in remove_blocked_locks()
343 spin_lock(&nn->blocked_locks_lock); in remove_blocked_locks()
344 while (!list_empty(&lo->lo_blocked)) { in remove_blocked_locks()
345 nbl = list_first_entry(&lo->lo_blocked, in remove_blocked_locks()
348 list_del_init(&nbl->nbl_list); in remove_blocked_locks()
349 WARN_ON(list_empty(&nbl->nbl_lru)); in remove_blocked_locks()
350 list_move(&nbl->nbl_lru, &reaplist); in remove_blocked_locks()
352 spin_unlock(&nn->blocked_locks_lock); in remove_blocked_locks()
358 list_del_init(&nbl->nbl_lru); in remove_blocked_locks()
368 locks_delete_block(&nbl->nbl_lock); in nfsd4_cb_notify_lock_prepare()
381 switch (task->tk_status) { in nfsd4_cb_notify_lock_done()
382 case -NFS4ERR_DELAY: in nfsd4_cb_notify_lock_done()
412 * https://datatracker.ietf.org/doc/html/rfc7530#section-16.19.4 that
450 stp->st_access_bmap |= mask; in set_access()
460 stp->st_access_bmap &= ~mask; in clear_access()
469 return (bool)(stp->st_access_bmap & mask); in test_access()
479 stp->st_deny_bmap |= mask; in set_deny()
489 stp->st_deny_bmap &= ~mask; in clear_deny()
498 return (bool)(stp->st_deny_bmap & mask); in test_deny()
533 atomic_inc(&sop->so_count); in nfs4_get_stateowner()
540 return (sop->so_owner.len == owner->len) && in same_owner_str()
541 0 == memcmp(sop->so_owner.data, owner->data, owner->len); in same_owner_str()
550 lockdep_assert_held(&clp->cl_lock); in find_openstateowner_str()
552 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[hashval], in find_openstateowner_str()
554 if (!so->so_is_open_owner) in find_openstateowner_str()
556 if (same_owner_str(so, &open->op_owner)) in find_openstateowner_str()
568 while (nbytes--) { in opaque_hashval()
578 if (refcount_dec_and_test(&fi->fi_ref)) { in put_nfs4_file()
580 WARN_ON_ONCE(!list_empty(&fi->fi_clnt_odstate)); in put_nfs4_file()
581 WARN_ON_ONCE(!list_empty(&fi->fi_delegations)); in put_nfs4_file()
591 lockdep_assert_held(&f->fi_lock); in find_writeable_file_locked()
593 ret = nfsd_file_get(f->fi_fds[O_WRONLY]); in find_writeable_file_locked()
595 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_writeable_file_locked()
604 spin_lock(&f->fi_lock); in find_writeable_file()
606 spin_unlock(&f->fi_lock); in find_writeable_file()
616 lockdep_assert_held(&f->fi_lock); in find_readable_file_locked()
618 ret = nfsd_file_get(f->fi_fds[O_RDONLY]); in find_readable_file_locked()
620 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_readable_file_locked()
629 spin_lock(&f->fi_lock); in find_readable_file()
631 spin_unlock(&f->fi_lock); in find_readable_file()
641 spin_lock(&f->fi_lock); in find_rw_file()
642 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_rw_file()
643 spin_unlock(&f->fi_lock); in find_rw_file()
655 spin_lock(&f->fi_lock); in find_any_file()
656 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_any_file()
658 ret = nfsd_file_get(f->fi_fds[O_WRONLY]); in find_any_file()
660 ret = nfsd_file_get(f->fi_fds[O_RDONLY]); in find_any_file()
662 spin_unlock(&f->fi_lock); in find_any_file()
668 lockdep_assert_held(&f->fi_lock); in find_any_file_locked()
670 if (f->fi_fds[O_RDWR]) in find_any_file_locked()
671 return f->fi_fds[O_RDWR]; in find_any_file_locked()
672 if (f->fi_fds[O_WRONLY]) in find_any_file_locked()
673 return f->fi_fds[O_WRONLY]; in find_any_file_locked()
674 if (f->fi_fds[O_RDONLY]) in find_any_file_locked()
675 return f->fi_fds[O_RDONLY]; in find_any_file_locked()
689 #define OWNER_HASH_MASK (OWNER_HASH_SIZE - 1)
695 ret = opaque_hashval(ownername->data, ownername->len); in ownerstr_hashval()
727 * false - access/deny mode conflict with normal client.
728 * true - no conflict or conflict with courtesy client(s) is resolved.
740 lockdep_assert_held(&fp->fi_lock); in nfs4_resolve_deny_conflicts_locked()
741 list_for_each_entry(st, &fp->fi_stateids, st_perfile) { in nfs4_resolve_deny_conflicts_locked()
743 if (st->st_openstp) in nfs4_resolve_deny_conflicts_locked()
748 bmap = share_access ? st->st_deny_bmap : st->st_access_bmap; in nfs4_resolve_deny_conflicts_locked()
751 clp = st->st_stid.sc_client; in nfs4_resolve_deny_conflicts_locked()
758 clp = stp->st_stid.sc_client; in nfs4_resolve_deny_conflicts_locked()
759 nn = net_generic(clp->net, nfsd_net_id); in nfs4_resolve_deny_conflicts_locked()
760 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in nfs4_resolve_deny_conflicts_locked()
768 lockdep_assert_held(&fp->fi_lock); in __nfs4_file_get_access()
771 atomic_inc(&fp->fi_access[O_WRONLY]); in __nfs4_file_get_access()
773 atomic_inc(&fp->fi_access[O_RDONLY]); in __nfs4_file_get_access()
779 lockdep_assert_held(&fp->fi_lock); in nfs4_file_get_access()
786 if ((access & fp->fi_share_deny) != 0) in nfs4_file_get_access()
802 atomic_read(&fp->fi_access[O_RDONLY])) in nfs4_file_check_deny()
806 atomic_read(&fp->fi_access[O_WRONLY])) in nfs4_file_check_deny()
814 might_lock(&fp->fi_lock); in __nfs4_file_put_access()
816 if (atomic_dec_and_lock(&fp->fi_access[oflag], &fp->fi_lock)) { in __nfs4_file_put_access()
820 swap(f1, fp->fi_fds[oflag]); in __nfs4_file_put_access()
821 if (atomic_read(&fp->fi_access[1 - oflag]) == 0) in __nfs4_file_put_access()
822 swap(f2, fp->fi_fds[O_RDWR]); in __nfs4_file_put_access()
823 spin_unlock(&fp->fi_lock); in __nfs4_file_put_access()
845 * Note that we only allocate it for pNFS-enabled exports, otherwise
855 co->co_client = clp; in alloc_clnt_odstate()
856 refcount_set(&co->co_odcount, 1); in alloc_clnt_odstate()
864 struct nfs4_file *fp = co->co_file; in hash_clnt_odstate_locked()
866 lockdep_assert_held(&fp->fi_lock); in hash_clnt_odstate_locked()
867 list_add(&co->co_perfile, &fp->fi_clnt_odstate); in hash_clnt_odstate_locked()
874 refcount_inc(&co->co_odcount); in get_clnt_odstate()
885 fp = co->co_file; in put_clnt_odstate()
886 if (refcount_dec_and_lock(&co->co_odcount, &fp->fi_lock)) { in put_clnt_odstate()
887 list_del(&co->co_perfile); in put_clnt_odstate()
888 spin_unlock(&fp->fi_lock); in put_clnt_odstate()
890 nfsd4_return_all_file_layouts(co->co_client, fp); in put_clnt_odstate()
904 cl = new->co_client; in find_or_hash_clnt_odstate()
906 spin_lock(&fp->fi_lock); in find_or_hash_clnt_odstate()
907 list_for_each_entry(co, &fp->fi_clnt_odstate, co_perfile) { in find_or_hash_clnt_odstate()
908 if (co->co_client == cl) { in find_or_hash_clnt_odstate()
914 co->co_file = fp; in find_or_hash_clnt_odstate()
917 spin_unlock(&fp->fi_lock); in find_or_hash_clnt_odstate()
932 spin_lock(&cl->cl_lock); in nfs4_alloc_stid()
934 new_id = idr_alloc_cyclic(&cl->cl_stateids, stid, 1, 0, GFP_NOWAIT); in nfs4_alloc_stid()
935 spin_unlock(&cl->cl_lock); in nfs4_alloc_stid()
940 stid->sc_free = sc_free; in nfs4_alloc_stid()
941 stid->sc_client = cl; in nfs4_alloc_stid()
942 stid->sc_stateid.si_opaque.so_id = new_id; in nfs4_alloc_stid()
943 stid->sc_stateid.si_opaque.so_clid = cl->cl_clientid; in nfs4_alloc_stid()
945 refcount_set(&stid->sc_count, 1); in nfs4_alloc_stid()
946 spin_lock_init(&stid->sc_lock); in nfs4_alloc_stid()
947 INIT_LIST_HEAD(&stid->sc_cp_list); in nfs4_alloc_stid()
972 stid->cs_stid.si_opaque.so_clid.cl_boot = (u32)nn->boot_time; in nfs4_init_cp_state()
973 stid->cs_stid.si_opaque.so_clid.cl_id = nn->s2s_cp_cl_id; in nfs4_init_cp_state()
976 spin_lock(&nn->s2s_cp_lock); in nfs4_init_cp_state()
977 new_id = idr_alloc_cyclic(&nn->s2s_cp_stateids, stid, 0, 0, GFP_NOWAIT); in nfs4_init_cp_state()
978 stid->cs_stid.si_opaque.so_id = new_id; in nfs4_init_cp_state()
979 stid->cs_stid.si_generation = 1; in nfs4_init_cp_state()
980 spin_unlock(&nn->s2s_cp_lock); in nfs4_init_cp_state()
984 stid->cs_type = cs_type; in nfs4_init_cp_state()
990 return nfs4_init_cp_state(nn, &copy->cp_stateid, NFS4_COPY_STID); in nfs4_init_copy_state()
1001 cps->cpntf_time = ktime_get_boottime_seconds(); in nfs4_alloc_init_cpntf_state()
1002 refcount_set(&cps->cp_stateid.cs_count, 1); in nfs4_alloc_init_cpntf_state()
1003 if (!nfs4_init_cp_state(nn, &cps->cp_stateid, NFS4_COPYNOTIFY_STID)) in nfs4_alloc_init_cpntf_state()
1005 spin_lock(&nn->s2s_cp_lock); in nfs4_alloc_init_cpntf_state()
1006 list_add(&cps->cp_list, &p_stid->sc_cp_list); in nfs4_alloc_init_cpntf_state()
1007 spin_unlock(&nn->s2s_cp_lock); in nfs4_alloc_init_cpntf_state()
1018 if (copy->cp_stateid.cs_type != NFS4_COPY_STID) in nfs4_free_copy_state()
1020 nn = net_generic(copy->cp_clp->net, nfsd_net_id); in nfs4_free_copy_state()
1021 spin_lock(&nn->s2s_cp_lock); in nfs4_free_copy_state()
1022 idr_remove(&nn->s2s_cp_stateids, in nfs4_free_copy_state()
1023 copy->cp_stateid.cs_stid.si_opaque.so_id); in nfs4_free_copy_state()
1024 spin_unlock(&nn->s2s_cp_lock); in nfs4_free_copy_state()
1033 spin_lock(&nn->s2s_cp_lock); in nfs4_free_cpntf_statelist()
1034 while (!list_empty(&stid->sc_cp_list)) { in nfs4_free_cpntf_statelist()
1035 cps = list_first_entry(&stid->sc_cp_list, in nfs4_free_cpntf_statelist()
1039 spin_unlock(&nn->s2s_cp_lock); in nfs4_free_cpntf_statelist()
1056 * Considering nfsd_break_one_deleg is called with the flc->flc_lock held,
1063 WARN_ON_ONCE(!list_empty(&stid->sc_cp_list)); in nfs4_free_deleg()
1064 WARN_ON_ONCE(!list_empty(&dp->dl_perfile)); in nfs4_free_deleg()
1065 WARN_ON_ONCE(!list_empty(&dp->dl_perclnt)); in nfs4_free_deleg()
1066 WARN_ON_ONCE(!list_empty(&dp->dl_recall_lru)); in nfs4_free_deleg()
1084 * low 3 bytes as hash-table indices.
1103 if (bd->entries == 0) in delegation_blocked()
1105 if (ktime_get_seconds() - bd->swap_time > 30) { in delegation_blocked()
1107 if (ktime_get_seconds() - bd->swap_time > 30) { in delegation_blocked()
1108 bd->entries -= bd->old_entries; in delegation_blocked()
1109 bd->old_entries = bd->entries; in delegation_blocked()
1110 bd->new = 1-bd->new; in delegation_blocked()
1111 memset(bd->set[bd->new], 0, in delegation_blocked()
1112 sizeof(bd->set[0])); in delegation_blocked()
1113 bd->swap_time = ktime_get_seconds(); in delegation_blocked()
1117 hash = jhash(&fh->fh_raw, fh->fh_size, 0); in delegation_blocked()
1118 if (test_bit(hash&255, bd->set[0]) && in delegation_blocked()
1119 test_bit((hash>>8)&255, bd->set[0]) && in delegation_blocked()
1120 test_bit((hash>>16)&255, bd->set[0])) in delegation_blocked()
1123 if (test_bit(hash&255, bd->set[1]) && in delegation_blocked()
1124 test_bit((hash>>8)&255, bd->set[1]) && in delegation_blocked()
1125 test_bit((hash>>16)&255, bd->set[1])) in delegation_blocked()
1136 hash = jhash(&fh->fh_raw, fh->fh_size, 0); in block_delegations()
1139 __set_bit(hash&255, bd->set[bd->new]); in block_delegations()
1140 __set_bit((hash>>8)&255, bd->set[bd->new]); in block_delegations()
1141 __set_bit((hash>>16)&255, bd->set[bd->new]); in block_delegations()
1142 if (bd->entries == 0) in block_delegations()
1143 bd->swap_time = ktime_get_seconds(); in block_delegations()
1144 bd->entries += 1; in block_delegations()
1160 if (delegation_blocked(&fp->fi_fhandle)) in alloc_init_deleg()
1172 dp->dl_stid.sc_stateid.si_generation = 1; in alloc_init_deleg()
1173 INIT_LIST_HEAD(&dp->dl_perfile); in alloc_init_deleg()
1174 INIT_LIST_HEAD(&dp->dl_perclnt); in alloc_init_deleg()
1175 INIT_LIST_HEAD(&dp->dl_recall_lru); in alloc_init_deleg()
1176 dp->dl_clnt_odstate = odstate; in alloc_init_deleg()
1178 dp->dl_type = dl_type; in alloc_init_deleg()
1179 dp->dl_retries = 1; in alloc_init_deleg()
1180 dp->dl_recalled = false; in alloc_init_deleg()
1181 nfsd4_init_cb(&dp->dl_recall, dp->dl_stid.sc_client, in alloc_init_deleg()
1183 nfsd4_init_cb(&dp->dl_cb_fattr.ncf_getattr, dp->dl_stid.sc_client, in alloc_init_deleg()
1185 dp->dl_cb_fattr.ncf_file_modified = false; in alloc_init_deleg()
1187 dp->dl_stid.sc_file = fp; in alloc_init_deleg()
1197 struct nfs4_file *fp = s->sc_file; in nfs4_put_stid()
1198 struct nfs4_client *clp = s->sc_client; in nfs4_put_stid()
1200 might_lock(&clp->cl_lock); in nfs4_put_stid()
1202 if (!refcount_dec_and_lock(&s->sc_count, &clp->cl_lock)) { in nfs4_put_stid()
1206 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); in nfs4_put_stid()
1207 if (s->sc_status & SC_STATUS_ADMIN_REVOKED) in nfs4_put_stid()
1208 atomic_dec(&s->sc_client->cl_admin_revoked); in nfs4_put_stid()
1209 nfs4_free_cpntf_statelist(clp->net, s); in nfs4_put_stid()
1210 spin_unlock(&clp->cl_lock); in nfs4_put_stid()
1211 s->sc_free(s); in nfs4_put_stid()
1219 stateid_t *src = &stid->sc_stateid; in nfs4_inc_and_copy_stateid()
1221 spin_lock(&stid->sc_lock); in nfs4_inc_and_copy_stateid()
1222 if (unlikely(++src->si_generation == 0)) in nfs4_inc_and_copy_stateid()
1223 src->si_generation = 1; in nfs4_inc_and_copy_stateid()
1225 spin_unlock(&stid->sc_lock); in nfs4_inc_and_copy_stateid()
1232 spin_lock(&fp->fi_lock); in put_deleg_file()
1233 if (--fp->fi_delegees == 0) in put_deleg_file()
1234 swap(nf, fp->fi_deleg_file); in put_deleg_file()
1235 spin_unlock(&fp->fi_lock); in put_deleg_file()
1243 struct nfs4_file *fp = dp->dl_stid.sc_file; in nfs4_unlock_deleg_lease()
1244 struct nfsd_file *nf = fp->fi_deleg_file; in nfs4_unlock_deleg_lease()
1246 WARN_ON_ONCE(!fp->fi_delegees); in nfs4_unlock_deleg_lease()
1248 kernel_setlease(nf->nf_file, F_UNLCK, NULL, (void **)&dp); in nfs4_unlock_deleg_lease()
1254 put_clnt_odstate(dp->dl_clnt_odstate); in destroy_unhashed_deleg()
1256 nfs4_put_stid(&dp->dl_stid); in destroy_unhashed_deleg()
1260 * nfs4_delegation_exists - Discover if this delegation already exists
1275 lockdep_assert_held(&fp->fi_lock); in nfs4_delegation_exists()
1277 list_for_each_entry(searchdp, &fp->fi_delegations, dl_perfile) { in nfs4_delegation_exists()
1278 searchclp = searchdp->dl_stid.sc_client; in nfs4_delegation_exists()
1287 * hash_delegation_locked - Add a delegation to the appropriate lists
1294 * On error: -EAGAIN if one was previously granted to this
1302 struct nfs4_client *clp = dp->dl_stid.sc_client; in hash_delegation_locked()
1305 lockdep_assert_held(&fp->fi_lock); in hash_delegation_locked()
1306 lockdep_assert_held(&clp->cl_lock); in hash_delegation_locked()
1309 return -EAGAIN; in hash_delegation_locked()
1310 refcount_inc(&dp->dl_stid.sc_count); in hash_delegation_locked()
1311 dp->dl_stid.sc_type = SC_TYPE_DELEG; in hash_delegation_locked()
1312 list_add(&dp->dl_perfile, &fp->fi_delegations); in hash_delegation_locked()
1313 list_add(&dp->dl_perclnt, &clp->cl_delegations); in hash_delegation_locked()
1319 return !(list_empty(&dp->dl_perfile)); in delegation_hashed()
1325 struct nfs4_file *fp = dp->dl_stid.sc_file; in unhash_delegation_locked()
1333 dp->dl_stid.sc_client->cl_minorversion == 0) in unhash_delegation_locked()
1335 dp->dl_stid.sc_status |= statusmask; in unhash_delegation_locked()
1337 atomic_inc(&dp->dl_stid.sc_client->cl_admin_revoked); in unhash_delegation_locked()
1340 ++dp->dl_time; in unhash_delegation_locked()
1341 spin_lock(&fp->fi_lock); in unhash_delegation_locked()
1342 list_del_init(&dp->dl_perclnt); in unhash_delegation_locked()
1343 list_del_init(&dp->dl_recall_lru); in unhash_delegation_locked()
1344 list_del_init(&dp->dl_perfile); in unhash_delegation_locked()
1345 spin_unlock(&fp->fi_lock); in unhash_delegation_locked()
1361 * revoke_delegation - perform nfs4 delegation structure cleanup
1380 * in the revocation process is protected by the clp->cl_lock.
1384 struct nfs4_client *clp = dp->dl_stid.sc_client; in revoke_delegation()
1386 WARN_ON(!list_empty(&dp->dl_recall_lru)); in revoke_delegation()
1387 WARN_ON_ONCE(!(dp->dl_stid.sc_status & in revoke_delegation()
1390 trace_nfsd_stid_revoke(&dp->dl_stid); in revoke_delegation()
1392 spin_lock(&clp->cl_lock); in revoke_delegation()
1393 if (dp->dl_stid.sc_status & SC_STATUS_FREED) { in revoke_delegation()
1394 list_del_init(&dp->dl_recall_lru); in revoke_delegation()
1397 list_add(&dp->dl_recall_lru, &clp->cl_revoked); in revoke_delegation()
1398 dp->dl_stid.sc_status |= SC_STATUS_FREEABLE; in revoke_delegation()
1400 spin_unlock(&clp->cl_lock); in revoke_delegation()
1428 spin_lock(&fp->fi_lock); in recalculate_deny_mode()
1429 old_deny = fp->fi_share_deny; in recalculate_deny_mode()
1430 fp->fi_share_deny = 0; in recalculate_deny_mode()
1431 list_for_each_entry(stp, &fp->fi_stateids, st_perfile) { in recalculate_deny_mode()
1432 fp->fi_share_deny |= bmap_to_share_mode(stp->st_deny_bmap); in recalculate_deny_mode()
1433 if (fp->fi_share_deny == old_deny) in recalculate_deny_mode()
1436 spin_unlock(&fp->fi_lock); in recalculate_deny_mode()
1452 /* Recalculate per-file deny mode if there was a change */ in reset_union_bmap_deny()
1454 recalculate_deny_mode(stp->st_stid.sc_file); in reset_union_bmap_deny()
1462 struct nfs4_file *fp = stp->st_stid.sc_file; in release_all_access()
1464 if (fp && stp->st_deny_bmap != 0) in release_all_access()
1469 nfs4_file_put_access(stp->st_stid.sc_file, i); in release_all_access()
1476 kfree(sop->so_owner.data); in nfs4_free_stateowner()
1477 sop->so_ops->so_free(sop); in nfs4_free_stateowner()
1482 struct nfs4_client *clp = sop->so_client; in nfs4_put_stateowner()
1484 might_lock(&clp->cl_lock); in nfs4_put_stateowner()
1486 if (!atomic_dec_and_lock(&sop->so_count, &clp->cl_lock)) in nfs4_put_stateowner()
1488 sop->so_ops->so_unhash(sop); in nfs4_put_stateowner()
1489 spin_unlock(&clp->cl_lock); in nfs4_put_stateowner()
1496 return list_empty(&stp->st_perfile); in nfs4_ol_stateid_unhashed()
1501 struct nfs4_file *fp = stp->st_stid.sc_file; in unhash_ol_stateid()
1503 lockdep_assert_held(&stp->st_stateowner->so_client->cl_lock); in unhash_ol_stateid()
1505 if (list_empty(&stp->st_perfile)) in unhash_ol_stateid()
1508 spin_lock(&fp->fi_lock); in unhash_ol_stateid()
1509 list_del_init(&stp->st_perfile); in unhash_ol_stateid()
1510 spin_unlock(&fp->fi_lock); in unhash_ol_stateid()
1511 list_del(&stp->st_perstateowner); in unhash_ol_stateid()
1519 put_clnt_odstate(stp->st_clnt_odstate); in nfs4_free_ol_stateid()
1521 if (stp->st_stateowner) in nfs4_free_ol_stateid()
1522 nfs4_put_stateowner(stp->st_stateowner); in nfs4_free_ol_stateid()
1523 WARN_ON(!list_empty(&stid->sc_cp_list)); in nfs4_free_ol_stateid()
1530 struct nfs4_lockowner *lo = lockowner(stp->st_stateowner); in nfs4_free_lock_stateid()
1533 nf = find_any_file(stp->st_stid.sc_file); in nfs4_free_lock_stateid()
1535 get_file(nf->nf_file); in nfs4_free_lock_stateid()
1536 filp_close(nf->nf_file, (fl_owner_t)lo); in nfs4_free_lock_stateid()
1550 struct nfs4_stid *s = &stp->st_stid; in put_ol_stateid_locked()
1551 struct nfs4_client *clp = s->sc_client; in put_ol_stateid_locked()
1553 lockdep_assert_held(&clp->cl_lock); in put_ol_stateid_locked()
1555 WARN_ON_ONCE(!list_empty(&stp->st_locks)); in put_ol_stateid_locked()
1557 if (!refcount_dec_and_test(&s->sc_count)) { in put_ol_stateid_locked()
1562 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); in put_ol_stateid_locked()
1563 if (s->sc_status & SC_STATUS_ADMIN_REVOKED) in put_ol_stateid_locked()
1564 atomic_dec(&s->sc_client->cl_admin_revoked); in put_ol_stateid_locked()
1565 list_add(&stp->st_locks, reaplist); in put_ol_stateid_locked()
1570 lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); in unhash_lock_stateid()
1574 list_del_init(&stp->st_locks); in unhash_lock_stateid()
1575 stp->st_stid.sc_status |= SC_STATUS_CLOSED; in unhash_lock_stateid()
1581 struct nfs4_client *clp = stp->st_stid.sc_client; in release_lock_stateid()
1584 spin_lock(&clp->cl_lock); in release_lock_stateid()
1586 spin_unlock(&clp->cl_lock); in release_lock_stateid()
1588 nfs4_put_stid(&stp->st_stid); in release_lock_stateid()
1593 struct nfs4_client *clp = lo->lo_owner.so_client; in unhash_lockowner_locked()
1595 lockdep_assert_held(&clp->cl_lock); in unhash_lockowner_locked()
1597 list_del_init(&lo->lo_owner.so_strhash); in unhash_lockowner_locked()
1615 list_del(&stp->st_locks); in free_ol_stateid_reaplist()
1616 fp = stp->st_stid.sc_file; in free_ol_stateid_reaplist()
1617 stp->st_stid.sc_free(&stp->st_stid); in free_ol_stateid_reaplist()
1628 lockdep_assert_held(&open_stp->st_stid.sc_client->cl_lock); in release_open_stateid_locks()
1630 while (!list_empty(&open_stp->st_locks)) { in release_open_stateid_locks()
1631 stp = list_entry(open_stp->st_locks.next, in release_open_stateid_locks()
1641 lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); in unhash_open_stateid()
1653 spin_lock(&stp->st_stid.sc_client->cl_lock); in release_open_stateid()
1654 stp->st_stid.sc_status |= SC_STATUS_CLOSED; in release_open_stateid()
1657 spin_unlock(&stp->st_stid.sc_client->cl_lock); in release_open_stateid()
1663 lockdep_assert_held(&oo->oo_owner.so_client->cl_lock); in nfs4_openowner_unhashed()
1665 return list_empty(&oo->oo_owner.so_strhash) && in nfs4_openowner_unhashed()
1666 list_empty(&oo->oo_perclient); in nfs4_openowner_unhashed()
1671 struct nfs4_client *clp = oo->oo_owner.so_client; in unhash_openowner_locked()
1673 lockdep_assert_held(&clp->cl_lock); in unhash_openowner_locked()
1675 list_del_init(&oo->oo_owner.so_strhash); in unhash_openowner_locked()
1676 list_del_init(&oo->oo_perclient); in unhash_openowner_locked()
1681 struct nfsd_net *nn = net_generic(oo->oo_owner.so_client->net, in release_last_closed_stateid()
1685 spin_lock(&nn->client_lock); in release_last_closed_stateid()
1686 s = oo->oo_last_closed_stid; in release_last_closed_stateid()
1688 list_del_init(&oo->oo_close_lru); in release_last_closed_stateid()
1689 oo->oo_last_closed_stid = NULL; in release_last_closed_stateid()
1691 spin_unlock(&nn->client_lock); in release_last_closed_stateid()
1693 nfs4_put_stid(&s->st_stid); in release_last_closed_stateid()
1699 struct nfs4_client *clp = oo->oo_owner.so_client; in release_openowner()
1702 spin_lock(&clp->cl_lock); in release_openowner()
1704 while (!list_empty(&oo->oo_owner.so_stateids)) { in release_openowner()
1705 stp = list_first_entry(&oo->oo_owner.so_stateids, in release_openowner()
1710 spin_unlock(&clp->cl_lock); in release_openowner()
1713 nfs4_put_stateowner(&oo->oo_owner); in release_openowner()
1723 spin_lock(&clp->cl_lock); in find_one_sb_stid()
1724 idr_for_each_entry_ul(&clp->cl_stateids, stid, tmp, id) in find_one_sb_stid()
1725 if ((stid->sc_type & sc_types) && in find_one_sb_stid()
1726 stid->sc_status == 0 && in find_one_sb_stid()
1727 stid->sc_file->fi_inode->i_sb == sb) { in find_one_sb_stid()
1728 refcount_inc(&stid->sc_count); in find_one_sb_stid()
1731 spin_unlock(&clp->cl_lock); in find_one_sb_stid()
1736 * nfsd4_revoke_states - revoke all nfsv4 states associated with given filesystem
1747 * states have been "admin-revoked".
1757 spin_lock(&nn->client_lock); in nfsd4_revoke_states()
1759 struct list_head *head = &nn->conf_id_hashtbl[idhashval]; in nfsd4_revoke_states()
1770 spin_unlock(&nn->client_lock); in nfsd4_revoke_states()
1771 switch (stid->sc_type) { in nfsd4_revoke_states()
1774 mutex_lock_nested(&stp->st_mutex, in nfsd4_revoke_states()
1777 spin_lock(&clp->cl_lock); in nfsd4_revoke_states()
1778 if (stid->sc_status == 0) { in nfsd4_revoke_states()
1779 stid->sc_status |= in nfsd4_revoke_states()
1781 atomic_inc(&clp->cl_admin_revoked); in nfsd4_revoke_states()
1782 spin_unlock(&clp->cl_lock); in nfsd4_revoke_states()
1785 spin_unlock(&clp->cl_lock); in nfsd4_revoke_states()
1786 mutex_unlock(&stp->st_mutex); in nfsd4_revoke_states()
1790 mutex_lock_nested(&stp->st_mutex, in nfsd4_revoke_states()
1792 spin_lock(&clp->cl_lock); in nfsd4_revoke_states()
1793 if (stid->sc_status == 0) { in nfsd4_revoke_states()
1795 lockowner(stp->st_stateowner); in nfsd4_revoke_states()
1798 stid->sc_status |= in nfsd4_revoke_states()
1800 atomic_inc(&clp->cl_admin_revoked); in nfsd4_revoke_states()
1801 spin_unlock(&clp->cl_lock); in nfsd4_revoke_states()
1802 nf = find_any_file(stp->st_stid.sc_file); in nfsd4_revoke_states()
1804 get_file(nf->nf_file); in nfsd4_revoke_states()
1805 filp_close(nf->nf_file, in nfsd4_revoke_states()
1811 spin_unlock(&clp->cl_lock); in nfsd4_revoke_states()
1812 mutex_unlock(&stp->st_mutex); in nfsd4_revoke_states()
1815 refcount_inc(&stid->sc_count); in nfsd4_revoke_states()
1831 spin_lock(&nn->client_lock); in nfsd4_revoke_states()
1832 if (clp->cl_minorversion == 0) in nfsd4_revoke_states()
1838 nn->nfs40_last_revoke = in nfsd4_revoke_states()
1844 spin_unlock(&nn->client_lock); in nfsd4_revoke_states()
1852 return sid->sequence % SESSION_HASH_SIZE; in hash_sessionid()
1859 u32 *ptr = (u32 *)(&sessionid->data[0]); in dump_sessionid()
1870 * Bump the seqid on cstate->replay_owner, and clear replay_owner if it
1875 struct nfs4_stateowner *so = cstate->replay_owner; in nfsd4_bump_seqid()
1886 if (so->so_is_open_owner) in nfsd4_bump_seqid()
1888 so->so_seqid++; in nfsd4_bump_seqid()
1895 struct nfs4_client *clp = ses->se_client; in gen_sessionid()
1898 sid = (struct nfsd4_sessionid *)ses->se_sessionid.data; in gen_sessionid()
1899 sid->clientid = clp->cl_clientid; in gen_sessionid()
1900 sid->sequence = current_sessionid++; in gen_sessionid()
1901 sid->reserved = 0; in gen_sessionid()
1907 * the end of the initial SEQUENCE operation--the rest we regenerate
1913 * verifier), 12 for the compound header (with zero-length tag), and 44
1921 /* The sum of "target_slots-1" on every session. The shrinker can push this
1923 * be freed. The "-1" is because we can never free slot 0 while the
1933 if (from >= ses->se_fchannel.maxreqs) in free_session_slots()
1936 for (i = from; i < ses->se_fchannel.maxreqs; i++) { in free_session_slots()
1937 struct nfsd4_slot *slot = xa_load(&ses->se_slots, i); in free_session_slots()
1944 xa_store(&ses->se_slots, i, xa_mk_value(slot->sl_seqid), 0); in free_session_slots()
1945 free_svc_cred(&slot->sl_cred); in free_session_slots()
1948 ses->se_fchannel.maxreqs = from; in free_session_slots()
1949 if (ses->se_target_maxslots > from) { in free_session_slots()
1951 atomic_sub(ses->se_target_maxslots - new_target, &nfsd_total_target_slots); in free_session_slots()
1952 ses->se_target_maxslots = new_target; in free_session_slots()
1957 * reduce_session_slots - reduce the target max-slots of a session if possible
1961 * This interface can be used by a shrinker to reduce the target max-slots
1965 * best-effort, skiping a session is client_lock is already held has no
1974 struct nfsd_net *nn = net_generic(ses->se_client->net, in reduce_session_slots()
1978 if (ses->se_target_maxslots <= 1) in reduce_session_slots()
1980 if (!spin_trylock(&nn->client_lock)) in reduce_session_slots()
1982 ret = min(dec, ses->se_target_maxslots-1); in reduce_session_slots()
1983 ses->se_target_maxslots -= ret; in reduce_session_slots()
1985 ses->se_slot_gen += 1; in reduce_session_slots()
1986 if (ses->se_slot_gen == 0) { in reduce_session_slots()
1988 ses->se_slot_gen = 1; in reduce_session_slots()
1989 for (i = 0; i < ses->se_fchannel.maxreqs; i++) { in reduce_session_slots()
1990 struct nfsd4_slot *slot = xa_load(&ses->se_slots, i); in reduce_session_slots()
1991 slot->sl_generation = 0; in reduce_session_slots()
1994 spin_unlock(&nn->client_lock); in reduce_session_slots()
2006 if (ca->maxresp_cached < NFSD_MIN_HDR_SEQ_SZ) in slot_bytes()
2009 size = ca->maxresp_cached - NFSD_MIN_HDR_SEQ_SZ; in slot_bytes()
2016 int numslots = fattrs->maxreqs; in alloc_session()
2025 xa_init(&new->se_slots); in alloc_session()
2028 if (!slot || xa_is_err(xa_store(&new->se_slots, 0, slot, GFP_KERNEL))) in alloc_session()
2036 if (xa_is_err(xa_store(&new->se_slots, i, slot, gfp))) { in alloc_session()
2041 fattrs->maxreqs = i; in alloc_session()
2042 memcpy(&new->se_fchannel, fattrs, sizeof(struct nfsd4_channel_attrs)); in alloc_session()
2043 new->se_target_maxslots = i; in alloc_session()
2044 atomic_add(i - 1, &nfsd_total_target_slots); in alloc_session()
2045 new->se_cb_slot_avail = ~0U; in alloc_session()
2046 new->se_cb_highest_slot = min(battrs->maxreqs - 1, in alloc_session()
2047 NFSD_BC_SLOT_TABLE_SIZE - 1); in alloc_session()
2048 spin_lock_init(&new->se_lock); in alloc_session()
2052 xa_destroy(&new->se_slots); in alloc_session()
2059 svc_xprt_put(c->cn_xprt); in free_conn()
2066 struct nfs4_client *clp = c->cn_session->se_client; in nfsd4_conn_lost()
2070 spin_lock(&clp->cl_lock); in nfsd4_conn_lost()
2071 if (!list_empty(&c->cn_persession)) { in nfsd4_conn_lost()
2072 list_del(&c->cn_persession); in nfsd4_conn_lost()
2076 spin_unlock(&clp->cl_lock); in nfsd4_conn_lost()
2086 svc_xprt_get(rqstp->rq_xprt); in alloc_conn()
2087 conn->cn_xprt = rqstp->rq_xprt; in alloc_conn()
2088 conn->cn_flags = flags; in alloc_conn()
2089 INIT_LIST_HEAD(&conn->cn_xpt_user.list); in alloc_conn()
2095 conn->cn_session = ses; in __nfsd4_hash_conn()
2096 list_add(&conn->cn_persession, &ses->se_conns); in __nfsd4_hash_conn()
2101 struct nfs4_client *clp = ses->se_client; in nfsd4_hash_conn()
2103 spin_lock(&clp->cl_lock); in nfsd4_hash_conn()
2105 spin_unlock(&clp->cl_lock); in nfsd4_hash_conn()
2110 conn->cn_xpt_user.callback = nfsd4_conn_lost; in nfsd4_register_conn()
2111 return register_xpt_user(conn->cn_xprt, &conn->cn_xpt_user); in nfsd4_register_conn()
2122 nfsd4_conn_lost(&conn->cn_xpt_user); in nfsd4_init_conn()
2124 nfsd4_probe_callback_sync(ses->se_client); in nfsd4_init_conn()
2131 if (cses->flags & SESSION4_BACK_CHAN) in alloc_conn_from_crses()
2139 struct nfs4_client *clp = s->se_client; in nfsd4_del_conns()
2142 spin_lock(&clp->cl_lock); in nfsd4_del_conns()
2143 while (!list_empty(&s->se_conns)) { in nfsd4_del_conns()
2144 c = list_first_entry(&s->se_conns, struct nfsd4_conn, cn_persession); in nfsd4_del_conns()
2145 list_del_init(&c->cn_persession); in nfsd4_del_conns()
2146 spin_unlock(&clp->cl_lock); in nfsd4_del_conns()
2148 unregister_xpt_user(c->cn_xprt, &c->cn_xpt_user); in nfsd4_del_conns()
2151 spin_lock(&clp->cl_lock); in nfsd4_del_conns()
2153 spin_unlock(&clp->cl_lock); in nfsd4_del_conns()
2159 xa_destroy(&ses->se_slots); in __free_session()
2188 if (scanned >= sc->nr_to_scan) { in nfsd_slot_scan()
2190 list_move(&nfsd_session_list, &ses->se_all_sessions); in nfsd_slot_scan()
2195 sc->nr_scanned = scanned; in nfsd_slot_scan()
2204 new->se_client = clp; in init_session()
2207 INIT_LIST_HEAD(&new->se_conns); in init_session()
2209 atomic_set(&new->se_ref, 0); in init_session()
2210 new->se_dead = false; in init_session()
2211 new->se_cb_prog = cses->callback_prog; in init_session()
2212 new->se_cb_sec = cses->cb_sec; in init_session()
2215 new->se_cb_seq_nr[idx] = 1; in init_session()
2217 idx = hash_sessionid(&new->se_sessionid); in init_session()
2218 list_add(&new->se_hash, &nn->sessionid_hashtbl[idx]); in init_session()
2219 spin_lock(&clp->cl_lock); in init_session()
2220 list_add(&new->se_perclnt, &clp->cl_sessions); in init_session()
2221 spin_unlock(&clp->cl_lock); in init_session()
2224 list_add_tail(&new->se_all_sessions, &nfsd_session_list); in init_session()
2236 rpc_copy_addr((struct sockaddr *)&clp->cl_cb_conn.cb_addr, sa); in init_session()
2237 clp->cl_cb_conn.cb_addrlen = svc_addr_len(sa); in init_session()
2249 lockdep_assert_held(&nn->client_lock); in __find_in_sessionid_hashtbl()
2254 list_for_each_entry(elem, &nn->sessionid_hashtbl[idx], se_hash) { in __find_in_sessionid_hashtbl()
2255 if (!memcmp(elem->se_sessionid.data, sessionid->data, in __find_in_sessionid_hashtbl()
2287 struct nfs4_client *clp = ses->se_client; in unhash_session()
2288 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_session()
2290 lockdep_assert_held(&nn->client_lock); in unhash_session()
2292 list_del(&ses->se_hash); in unhash_session()
2293 spin_lock(&ses->se_client->cl_lock); in unhash_session()
2294 list_del(&ses->se_perclnt); in unhash_session()
2295 spin_unlock(&ses->se_client->cl_lock); in unhash_session()
2297 list_del(&ses->se_all_sessions); in unhash_session()
2310 if (clid->cl_boot == (u32)nn->boot_time) in STALE_CLIENTID()
2322 if (atomic_read(&nn->nfs4_client_count) >= nn->nfs4_max_clients && in alloc_client()
2323 atomic_read(&nn->nfsd_courtesy_clients) > 0) in alloc_client()
2324 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in alloc_client()
2329 xdr_netobj_dup(&clp->cl_name, &name, GFP_KERNEL); in alloc_client()
2330 if (clp->cl_name.data == NULL) in alloc_client()
2332 clp->cl_ownerstr_hashtbl = kmalloc_array(OWNER_HASH_SIZE, in alloc_client()
2335 if (!clp->cl_ownerstr_hashtbl) in alloc_client()
2337 clp->cl_callback_wq = alloc_ordered_workqueue("nfsd4_callbacks", 0); in alloc_client()
2338 if (!clp->cl_callback_wq) in alloc_client()
2342 INIT_LIST_HEAD(&clp->cl_ownerstr_hashtbl[i]); in alloc_client()
2343 INIT_LIST_HEAD(&clp->cl_sessions); in alloc_client()
2344 idr_init(&clp->cl_stateids); in alloc_client()
2345 atomic_set(&clp->cl_rpc_users, 0); in alloc_client()
2346 clp->cl_cb_state = NFSD4_CB_UNKNOWN; in alloc_client()
2347 clp->cl_state = NFSD4_ACTIVE; in alloc_client()
2348 atomic_inc(&nn->nfs4_client_count); in alloc_client()
2349 atomic_set(&clp->cl_delegs_in_recall, 0); in alloc_client()
2350 INIT_LIST_HEAD(&clp->cl_idhash); in alloc_client()
2351 INIT_LIST_HEAD(&clp->cl_openowners); in alloc_client()
2352 INIT_LIST_HEAD(&clp->cl_delegations); in alloc_client()
2353 INIT_LIST_HEAD(&clp->cl_lru); in alloc_client()
2354 INIT_LIST_HEAD(&clp->cl_revoked); in alloc_client()
2356 INIT_LIST_HEAD(&clp->cl_lo_states); in alloc_client()
2358 INIT_LIST_HEAD(&clp->async_copies); in alloc_client()
2359 spin_lock_init(&clp->async_lock); in alloc_client()
2360 spin_lock_init(&clp->cl_lock); in alloc_client()
2361 rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table"); in alloc_client()
2364 kfree(clp->cl_ownerstr_hashtbl); in alloc_client()
2366 kfree(clp->cl_name.data); in alloc_client()
2377 free_svc_cred(&clp->cl_cred); in __free_client()
2378 destroy_workqueue(clp->cl_callback_wq); in __free_client()
2379 kfree(clp->cl_ownerstr_hashtbl); in __free_client()
2380 kfree(clp->cl_name.data); in __free_client()
2381 kfree(clp->cl_nii_domain.data); in __free_client()
2382 kfree(clp->cl_nii_name.data); in __free_client()
2383 idr_destroy(&clp->cl_stateids); in __free_client()
2384 kfree(clp->cl_ra); in __free_client()
2390 kref_put(&clp->cl_nfsdfs.cl_ref, __free_client); in drop_client()
2396 while (!list_empty(&clp->cl_sessions)) { in free_client()
2398 ses = list_entry(clp->cl_sessions.next, struct nfsd4_session, in free_client()
2400 list_del(&ses->se_perclnt); in free_client()
2401 WARN_ON_ONCE(atomic_read(&ses->se_ref)); in free_client()
2404 rpc_destroy_wait_queue(&clp->cl_cb_waitq); in free_client()
2405 if (clp->cl_nfsd_dentry) { in free_client()
2406 nfsd_client_rmdir(clp->cl_nfsd_dentry); in free_client()
2407 clp->cl_nfsd_dentry = NULL; in free_client()
2417 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_client_locked()
2420 lockdep_assert_held(&nn->client_lock); in unhash_client_locked()
2423 clp->cl_time = 0; in unhash_client_locked()
2425 if (!list_empty(&clp->cl_idhash)) { in unhash_client_locked()
2426 list_del_init(&clp->cl_idhash); in unhash_client_locked()
2427 if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) in unhash_client_locked()
2428 rb_erase(&clp->cl_namenode, &nn->conf_name_tree); in unhash_client_locked()
2430 rb_erase(&clp->cl_namenode, &nn->unconf_name_tree); in unhash_client_locked()
2432 list_del_init(&clp->cl_lru); in unhash_client_locked()
2433 spin_lock(&clp->cl_lock); in unhash_client_locked()
2435 list_for_each_entry(ses, &clp->cl_sessions, se_perclnt) { in unhash_client_locked()
2436 list_del_init(&ses->se_hash); in unhash_client_locked()
2437 list_del_init(&ses->se_all_sessions); in unhash_client_locked()
2440 spin_unlock(&clp->cl_lock); in unhash_client_locked()
2446 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_client()
2448 spin_lock(&nn->client_lock); in unhash_client()
2450 spin_unlock(&nn->client_lock); in unhash_client()
2455 int users = atomic_read(&clp->cl_rpc_users); in mark_client_expired_locked()
2468 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in __destroy_client()
2475 while (!list_empty(&clp->cl_delegations)) { in __destroy_client()
2476 dp = list_entry(clp->cl_delegations.next, struct nfs4_delegation, dl_perclnt); in __destroy_client()
2478 list_add(&dp->dl_recall_lru, &reaplist); in __destroy_client()
2483 list_del_init(&dp->dl_recall_lru); in __destroy_client()
2486 while (!list_empty(&clp->cl_revoked)) { in __destroy_client()
2487 dp = list_entry(clp->cl_revoked.next, struct nfs4_delegation, dl_recall_lru); in __destroy_client()
2488 list_del_init(&dp->dl_recall_lru); in __destroy_client()
2489 nfs4_put_stid(&dp->dl_stid); in __destroy_client()
2491 while (!list_empty(&clp->cl_openowners)) { in __destroy_client()
2492 oo = list_entry(clp->cl_openowners.next, struct nfs4_openowner, oo_perclient); in __destroy_client()
2493 nfs4_get_stateowner(&oo->oo_owner); in __destroy_client()
2499 list_for_each_entry_safe(so, tmp, &clp->cl_ownerstr_hashtbl[i], in __destroy_client()
2502 WARN_ON_ONCE(so->so_is_open_owner); in __destroy_client()
2509 if (clp->cl_cb_conn.cb_xprt) in __destroy_client()
2510 svc_xprt_put(clp->cl_cb_conn.cb_xprt); in __destroy_client()
2511 atomic_add_unless(&nn->nfs4_client_count, -1, 0); in __destroy_client()
2526 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in inc_reclaim_complete()
2528 if (!nn->track_reclaim_completes) in inc_reclaim_complete()
2530 if (!nfsd4_find_reclaim_client(clp->cl_name, nn)) in inc_reclaim_complete()
2532 if (atomic_inc_return(&nn->nr_reclaim_complete) == in inc_reclaim_complete()
2533 nn->reclaim_str_hashtbl_size) { in inc_reclaim_complete()
2535 clp->net->ns.inum); in inc_reclaim_complete()
2549 memcpy(target->cl_verifier.data, source->data, in copy_verf()
2550 sizeof(target->cl_verifier.data)); in copy_verf()
2555 target->cl_clientid.cl_boot = source->cl_clientid.cl_boot; in copy_clid()
2556 target->cl_clientid.cl_id = source->cl_clientid.cl_id; in copy_clid()
2561 target->cr_principal = kstrdup(source->cr_principal, GFP_KERNEL); in copy_cred()
2562 target->cr_raw_principal = kstrdup(source->cr_raw_principal, in copy_cred()
2564 target->cr_targ_princ = kstrdup(source->cr_targ_princ, GFP_KERNEL); in copy_cred()
2565 if ((source->cr_principal && !target->cr_principal) || in copy_cred()
2566 (source->cr_raw_principal && !target->cr_raw_principal) || in copy_cred()
2567 (source->cr_targ_princ && !target->cr_targ_princ)) in copy_cred()
2568 return -ENOMEM; in copy_cred()
2570 target->cr_flavor = source->cr_flavor; in copy_cred()
2571 target->cr_uid = source->cr_uid; in copy_cred()
2572 target->cr_gid = source->cr_gid; in copy_cred()
2573 target->cr_group_info = source->cr_group_info; in copy_cred()
2574 get_group_info(target->cr_group_info); in copy_cred()
2575 target->cr_gss_mech = source->cr_gss_mech; in copy_cred()
2576 if (source->cr_gss_mech) in copy_cred()
2577 gss_mech_get(source->cr_gss_mech); in copy_cred()
2584 if (o1->len < o2->len) in compare_blob()
2585 return -1; in compare_blob()
2586 if (o1->len > o2->len) in compare_blob()
2588 return memcmp(o1->data, o2->data, o1->len); in compare_blob()
2594 return 0 == memcmp(v1->data, v2->data, sizeof(v1->data)); in same_verf()
2600 return (cl1->cl_boot == cl2->cl_boot) && (cl1->cl_id == cl2->cl_id); in same_clid()
2607 if (g1->ngroups != g2->ngroups) in groups_equal()
2609 for (i=0; i<g1->ngroups; i++) in groups_equal()
2610 if (!gid_eq(g1->gid[i], g2->gid[i])) in groups_equal()
2619 * approximation. We also don't want to allow non-gss use of a client
2627 return (cr->cr_flavor > RPC_AUTH_MAXFLAVOR); in is_gss_cred()
2635 || (!uid_eq(cr1->cr_uid, cr2->cr_uid)) in same_creds()
2636 || (!gid_eq(cr1->cr_gid, cr2->cr_gid)) in same_creds()
2637 || !groups_equal(cr1->cr_group_info, cr2->cr_group_info)) in same_creds()
2640 if (cr1->cr_principal == cr2->cr_principal) in same_creds()
2642 if (!cr1->cr_principal || !cr2->cr_principal) in same_creds()
2644 return 0 == strcmp(cr1->cr_principal, cr2->cr_principal); in same_creds()
2649 struct svc_cred *cr = &rqstp->rq_cred; in svc_rqst_integrity_protected()
2652 if (!cr->cr_gss_mech) in svc_rqst_integrity_protected()
2654 service = gss_pseudoflavor_to_service(cr->cr_gss_mech, cr->cr_flavor); in svc_rqst_integrity_protected()
2661 struct svc_cred *cr = &rqstp->rq_cred; in nfsd4_mach_creds_match()
2663 if (!cl->cl_mach_cred) in nfsd4_mach_creds_match()
2665 if (cl->cl_cred.cr_gss_mech != cr->cr_gss_mech) in nfsd4_mach_creds_match()
2669 if (cl->cl_cred.cr_raw_principal) in nfsd4_mach_creds_match()
2670 return 0 == strcmp(cl->cl_cred.cr_raw_principal, in nfsd4_mach_creds_match()
2671 cr->cr_raw_principal); in nfsd4_mach_creds_match()
2672 if (!cr->cr_principal) in nfsd4_mach_creds_match()
2674 return 0 == strcmp(cl->cl_cred.cr_principal, cr->cr_principal); in nfsd4_mach_creds_match()
2682 * This is opaque to client, so no need to byte-swap. Use in gen_confirm()
2686 verf[1] = (__force __be32)nn->clverifier_counter++; in gen_confirm()
2687 memcpy(clp->cl_confirm.data, verf, sizeof(clp->cl_confirm.data)); in gen_confirm()
2692 clp->cl_clientid.cl_boot = (u32)nn->boot_time; in gen_clid()
2693 clp->cl_clientid.cl_id = nn->clientid_counter++; in gen_clid()
2702 ret = idr_find(&cl->cl_stateids, t->si_opaque.so_id); in find_stateid_locked()
2703 if (!ret || !ret->sc_type) in find_stateid_locked()
2714 spin_lock(&cl->cl_lock); in find_stateid_by_type()
2717 if ((s->sc_status & ~ok_states) == 0 && in find_stateid_by_type()
2718 (typemask & s->sc_type)) in find_stateid_by_type()
2719 refcount_inc(&s->sc_count); in find_stateid_by_type()
2723 spin_unlock(&cl->cl_lock); in find_stateid_by_type()
2760 struct inode *inode = file_inode(m->file); in client_info_show()
2767 return -ENXIO; in client_info_show()
2768 memcpy(&clid, &clp->cl_clientid, sizeof(clid)); in client_info_show()
2770 seq_printf(m, "address: \"%pISpc\"\n", (struct sockaddr *)&clp->cl_addr); in client_info_show()
2772 if (clp->cl_state == NFSD4_COURTESY) in client_info_show()
2774 else if (clp->cl_state == NFSD4_EXPIRABLE) in client_info_show()
2776 else if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) in client_info_show()
2781 ktime_get_boottime_seconds() - clp->cl_time); in client_info_show()
2783 seq_quote_mem(m, clp->cl_name.data, clp->cl_name.len); in client_info_show()
2784 seq_printf(m, "\nminor version: %d\n", clp->cl_minorversion); in client_info_show()
2785 if (clp->cl_nii_domain.data) { in client_info_show()
2787 seq_quote_mem(m, clp->cl_nii_domain.data, in client_info_show()
2788 clp->cl_nii_domain.len); in client_info_show()
2790 seq_quote_mem(m, clp->cl_nii_name.data, clp->cl_nii_name.len); in client_info_show()
2792 clp->cl_nii_time.tv_sec, clp->cl_nii_time.tv_nsec); in client_info_show()
2794 seq_printf(m, "callback state: %s\n", cb_state2str(clp->cl_cb_state)); in client_info_show()
2795 seq_printf(m, "callback address: \"%pISpc\"\n", &clp->cl_cb_conn.cb_addr); in client_info_show()
2796 seq_printf(m, "admin-revoked states: %d\n", in client_info_show()
2797 atomic_read(&clp->cl_admin_revoked)); in client_info_show()
2798 spin_lock(&clp->cl_lock); in client_info_show()
2800 list_for_each_entry(ses, &clp->cl_sessions, se_perclnt) in client_info_show()
2801 seq_printf(m, " %u", ses->se_fchannel.maxreqs); in client_info_show()
2803 list_for_each_entry(ses, &clp->cl_sessions, se_perclnt) in client_info_show()
2804 seq_printf(m, " %u", ses->se_target_maxslots); in client_info_show()
2805 spin_unlock(&clp->cl_lock); in client_info_show()
2816 __acquires(&clp->cl_lock) in states_start()
2818 struct nfs4_client *clp = s->private; in states_start()
2822 spin_lock(&clp->cl_lock); in states_start()
2823 ret = idr_get_next_ul(&clp->cl_stateids, &id); in states_start()
2830 struct nfs4_client *clp = s->private; in states_next()
2836 ret = idr_get_next_ul(&clp->cl_stateids, &id); in states_next()
2842 __releases(&clp->cl_lock) in states_stop()
2844 struct nfs4_client *clp = s->private; in states_stop()
2846 spin_unlock(&clp->cl_lock); in states_stop()
2851 seq_printf(s, "filename: \"%pD2\"", f->nf_file); in nfs4_show_fname()
2856 struct inode *inode = file_inode(f->nf_file); in nfs4_show_superblock()
2859 MAJOR(inode->i_sb->s_dev), in nfs4_show_superblock()
2860 MINOR(inode->i_sb->s_dev), in nfs4_show_superblock()
2861 inode->i_ino); in nfs4_show_superblock()
2867 seq_quote_mem(s, oo->so_owner.data, oo->so_owner.len); in nfs4_show_owner()
2872 seq_printf(s, "0x%.8x", stid->si_generation); in nfs4_show_stateid()
2873 seq_printf(s, "%12phN", &stid->si_opaque); in nfs4_show_stateid()
2885 oo = ols->st_stateowner; in nfs4_show_open()
2886 nf = st->sc_file; in nfs4_show_open()
2888 seq_puts(s, "- "); in nfs4_show_open()
2889 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_open()
2892 access = bmap_to_share_mode(ols->st_access_bmap); in nfs4_show_open()
2893 deny = bmap_to_share_mode(ols->st_deny_bmap); in nfs4_show_open()
2896 access & NFS4_SHARE_ACCESS_READ ? "r" : "-", in nfs4_show_open()
2897 access & NFS4_SHARE_ACCESS_WRITE ? "w" : "-"); in nfs4_show_open()
2899 deny & NFS4_SHARE_ACCESS_READ ? "r" : "-", in nfs4_show_open()
2900 deny & NFS4_SHARE_ACCESS_WRITE ? "w" : "-"); in nfs4_show_open()
2903 spin_lock(&nf->fi_lock); in nfs4_show_open()
2911 spin_unlock(&nf->fi_lock); in nfs4_show_open()
2915 if (st->sc_status & SC_STATUS_ADMIN_REVOKED) in nfs4_show_open()
2916 seq_puts(s, ", admin-revoked"); in nfs4_show_open()
2929 oo = ols->st_stateowner; in nfs4_show_lock()
2930 nf = st->sc_file; in nfs4_show_lock()
2932 seq_puts(s, "- "); in nfs4_show_lock()
2933 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_lock()
2936 spin_lock(&nf->fi_lock); in nfs4_show_lock()
2953 if (st->sc_status & SC_STATUS_ADMIN_REVOKED) in nfs4_show_lock()
2954 seq_puts(s, ", admin-revoked"); in nfs4_show_lock()
2956 spin_unlock(&nf->fi_lock); in nfs4_show_lock()
2982 nf = st->sc_file; in nfs4_show_deleg()
2984 seq_puts(s, "- "); in nfs4_show_deleg()
2985 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_deleg()
2988 seq_printf(s, "access: %s", nfs4_show_deleg_type(ds->dl_type)); in nfs4_show_deleg()
2992 spin_lock(&nf->fi_lock); in nfs4_show_deleg()
2993 file = nf->fi_deleg_file; in nfs4_show_deleg()
3000 spin_unlock(&nf->fi_lock); in nfs4_show_deleg()
3001 if (st->sc_status & SC_STATUS_ADMIN_REVOKED) in nfs4_show_deleg()
3002 seq_puts(s, ", admin-revoked"); in nfs4_show_deleg()
3014 seq_puts(s, "- "); in nfs4_show_layout()
3015 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_layout()
3020 spin_lock(&ls->ls_stid.sc_file->fi_lock); in nfs4_show_layout()
3021 file = ls->ls_file; in nfs4_show_layout()
3028 spin_unlock(&ls->ls_stid.sc_file->fi_lock); in nfs4_show_layout()
3029 if (st->sc_status & SC_STATUS_ADMIN_REVOKED) in nfs4_show_layout()
3030 seq_puts(s, ", admin-revoked"); in nfs4_show_layout()
3040 switch (st->sc_type) { in states_show()
3070 return -ENXIO; in client_states_open()
3075 s = file->private_data; in client_states_open()
3076 s->private = clp; in client_states_open()
3082 struct seq_file *m = file->private_data; in client_opens_release()
3083 struct nfs4_client *clp = m->private; in client_opens_release()
3105 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in force_expire_client()
3108 trace_nfsd_clid_admin_expired(&clp->cl_clientid); in force_expire_client()
3110 spin_lock(&nn->client_lock); in force_expire_client()
3111 clp->cl_time = 0; in force_expire_client()
3112 spin_unlock(&nn->client_lock); in force_expire_client()
3114 wait_event(expiry_wq, atomic_read(&clp->cl_rpc_users) == 0); in force_expire_client()
3115 spin_lock(&nn->client_lock); in force_expire_client()
3116 already_expired = list_empty(&clp->cl_lru); in force_expire_client()
3119 spin_unlock(&nn->client_lock); in force_expire_client()
3124 wait_event(expiry_wq, clp->cl_nfsd_dentry == NULL); in force_expire_client()
3137 return -EINVAL; in client_ctl_write()
3140 return -ENXIO; in client_ctl_write()
3163 switch (task->tk_status) { in nfsd4_cb_recall_any_done()
3164 case -NFS4ERR_DELAY: in nfsd4_cb_recall_any_done()
3175 struct nfs4_client *clp = cb->cb_clp; in nfsd4_cb_recall_any_release()
3177 clear_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags); in nfsd4_cb_recall_any_release()
3189 trace_nfsd_cb_getattr_done(&dp->dl_stid.sc_stateid, task); in nfsd4_cb_getattr_done()
3190 ncf->ncf_cb_status = task->tk_status; in nfsd4_cb_getattr_done()
3191 switch (task->tk_status) { in nfsd4_cb_getattr_done()
3192 case -NFS4ERR_DELAY: in nfsd4_cb_getattr_done()
3208 clear_and_wake_up_bit(CB_GETATTR_BUSY, &ncf->ncf_cb_flags); in nfsd4_cb_getattr_release()
3209 nfs4_put_stid(&dp->dl_stid); in nfsd4_cb_getattr_release()
3229 if (test_and_set_bit(CB_GETATTR_BUSY, &ncf->ncf_cb_flags)) in nfs4_cb_getattr()
3232 ncf->ncf_cb_status = NFS4ERR_IO; in nfs4_cb_getattr()
3234 refcount_inc(&dp->dl_stid.sc_count); in nfs4_cb_getattr()
3235 nfsd4_run_cb(&ncf->ncf_getattr); in nfs4_cb_getattr()
3252 ret = copy_cred(&clp->cl_cred, &rqstp->rq_cred); in create_client()
3258 kref_init(&clp->cl_nfsdfs.cl_ref); in create_client()
3259 nfsd4_init_cb(&clp->cl_cb_null, clp, NULL, NFSPROC4_CLNT_CB_NULL); in create_client()
3260 clp->cl_time = ktime_get_boottime_seconds(); in create_client()
3262 memcpy(&clp->cl_addr, sa, sizeof(struct sockaddr_storage)); in create_client()
3263 clp->cl_cb_session = NULL; in create_client()
3264 clp->net = net; in create_client()
3265 clp->cl_nfsd_dentry = nfsd_client_mkdir( in create_client()
3266 nn, &clp->cl_nfsdfs, in create_client()
3267 clp->cl_clientid.cl_id - nn->clientid_base, in create_client()
3269 clp->cl_nfsd_info_dentry = dentries[0]; in create_client()
3270 if (!clp->cl_nfsd_dentry) { in create_client()
3274 clp->cl_ra = kzalloc(sizeof(*clp->cl_ra), GFP_KERNEL); in create_client()
3275 if (!clp->cl_ra) { in create_client()
3279 clp->cl_ra_time = 0; in create_client()
3280 nfsd4_init_cb(&clp->cl_ra->ra_cb, clp, &nfsd4_cb_recall_any_ops, in create_client()
3288 struct rb_node **new = &(root->rb_node), *parent = NULL; in add_clp_to_name_tree()
3295 if (compare_blob(&clp->cl_name, &new_clp->cl_name) > 0) in add_clp_to_name_tree()
3296 new = &((*new)->rb_left); in add_clp_to_name_tree()
3298 new = &((*new)->rb_right); in add_clp_to_name_tree()
3301 rb_link_node(&new_clp->cl_namenode, parent, new); in add_clp_to_name_tree()
3302 rb_insert_color(&new_clp->cl_namenode, root); in add_clp_to_name_tree()
3309 struct rb_node *node = root->rb_node; in find_clp_in_name_tree()
3314 cmp = compare_blob(&clp->cl_name, name); in find_clp_in_name_tree()
3316 node = node->rb_left; in find_clp_in_name_tree()
3318 node = node->rb_right; in find_clp_in_name_tree()
3329 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in add_to_unconfirmed()
3331 lockdep_assert_held(&nn->client_lock); in add_to_unconfirmed()
3333 clear_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags); in add_to_unconfirmed()
3334 add_clp_to_name_tree(clp, &nn->unconf_name_tree); in add_to_unconfirmed()
3335 idhashval = clientid_hashval(clp->cl_clientid.cl_id); in add_to_unconfirmed()
3336 list_add(&clp->cl_idhash, &nn->unconf_id_hashtbl[idhashval]); in add_to_unconfirmed()
3343 unsigned int idhashval = clientid_hashval(clp->cl_clientid.cl_id); in move_to_confirmed()
3344 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in move_to_confirmed()
3346 lockdep_assert_held(&nn->client_lock); in move_to_confirmed()
3348 list_move(&clp->cl_idhash, &nn->conf_id_hashtbl[idhashval]); in move_to_confirmed()
3349 rb_erase(&clp->cl_namenode, &nn->unconf_name_tree); in move_to_confirmed()
3350 add_clp_to_name_tree(clp, &nn->conf_name_tree); in move_to_confirmed()
3351 set_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags); in move_to_confirmed()
3352 trace_nfsd_clid_confirmed(&clp->cl_clientid); in move_to_confirmed()
3360 unsigned int idhashval = clientid_hashval(clid->cl_id); in find_client_in_id_table()
3363 if (same_clid(&clp->cl_clientid, clid)) { in find_client_in_id_table()
3364 if ((bool)clp->cl_minorversion != sessions) in find_client_in_id_table()
3376 struct list_head *tbl = nn->conf_id_hashtbl; in find_confirmed_client()
3378 lockdep_assert_held(&nn->client_lock); in find_confirmed_client()
3385 struct list_head *tbl = nn->unconf_id_hashtbl; in find_unconfirmed_client()
3387 lockdep_assert_held(&nn->client_lock); in find_unconfirmed_client()
3393 return clp->cl_exchange_flags != 0; in clp_used_exchangeid()
3399 lockdep_assert_held(&nn->client_lock); in find_confirmed_client_by_name()
3400 return find_clp_in_name_tree(name, &nn->conf_name_tree); in find_confirmed_client_by_name()
3406 lockdep_assert_held(&nn->client_lock); in find_unconfirmed_client_by_name()
3407 return find_clp_in_name_tree(name, &nn->unconf_name_tree); in find_unconfirmed_client_by_name()
3413 struct nfs4_cb_conn *conn = &clp->cl_cb_conn; in gen_callback()
3419 if (se->se_callback_netid_len == 3 && in gen_callback()
3420 !memcmp(se->se_callback_netid_val, "tcp", 3)) in gen_callback()
3422 else if (se->se_callback_netid_len == 4 && in gen_callback()
3423 !memcmp(se->se_callback_netid_val, "tcp6", 4)) in gen_callback()
3428 conn->cb_addrlen = rpc_uaddr2sockaddr(clp->net, se->se_callback_addr_val, in gen_callback()
3429 se->se_callback_addr_len, in gen_callback()
3430 (struct sockaddr *)&conn->cb_addr, in gen_callback()
3431 sizeof(conn->cb_addr)); in gen_callback()
3433 if (!conn->cb_addrlen || conn->cb_addr.ss_family != expected_family) in gen_callback()
3436 if (conn->cb_addr.ss_family == AF_INET6) in gen_callback()
3437 ((struct sockaddr_in6 *)&conn->cb_addr)->sin6_scope_id = scopeid; in gen_callback()
3439 conn->cb_prog = se->se_callback_prog; in gen_callback()
3440 conn->cb_ident = se->se_callback_ident; in gen_callback()
3441 memcpy(&conn->cb_saddr, &rqstp->rq_daddr, rqstp->rq_daddrlen); in gen_callback()
3445 conn->cb_addr.ss_family = AF_UNSPEC; in gen_callback()
3446 conn->cb_addrlen = 0; in gen_callback()
3457 struct xdr_buf *buf = resp->xdr->buf; in nfsd4_store_cache_entry()
3458 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_store_cache_entry()
3461 dprintk("--> %s slot %p\n", __func__, slot); in nfsd4_store_cache_entry()
3463 slot->sl_flags |= NFSD4_SLOT_INITIALIZED; in nfsd4_store_cache_entry()
3464 slot->sl_opcnt = resp->opcnt; in nfsd4_store_cache_entry()
3465 slot->sl_status = resp->cstate.status; in nfsd4_store_cache_entry()
3466 free_svc_cred(&slot->sl_cred); in nfsd4_store_cache_entry()
3467 copy_cred(&slot->sl_cred, &resp->rqstp->rq_cred); in nfsd4_store_cache_entry()
3470 slot->sl_flags &= ~NFSD4_SLOT_CACHED; in nfsd4_store_cache_entry()
3473 slot->sl_flags |= NFSD4_SLOT_CACHED; in nfsd4_store_cache_entry()
3475 base = resp->cstate.data_offset; in nfsd4_store_cache_entry()
3476 slot->sl_datalen = buf->len - base; in nfsd4_store_cache_entry()
3477 if (read_bytes_from_xdr_buf(buf, base, slot->sl_data, slot->sl_datalen)) in nfsd4_store_cache_entry()
3486 * operation which sets resp->p and increments resp->opcnt for
3495 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_enc_sequence_replay()
3498 op = &args->ops[resp->opcnt - 1]; in nfsd4_enc_sequence_replay()
3501 if (slot->sl_flags & NFSD4_SLOT_CACHED) in nfsd4_enc_sequence_replay()
3502 return op->status; in nfsd4_enc_sequence_replay()
3503 if (args->opcnt == 1) { in nfsd4_enc_sequence_replay()
3505 * The original operation wasn't a solo sequence--we in nfsd4_enc_sequence_replay()
3506 * always cache those--so this retry must not match the in nfsd4_enc_sequence_replay()
3509 op->status = nfserr_seq_false_retry; in nfsd4_enc_sequence_replay()
3511 op = &args->ops[resp->opcnt++]; in nfsd4_enc_sequence_replay()
3512 op->status = nfserr_retry_uncached_rep; in nfsd4_enc_sequence_replay()
3515 return op->status; in nfsd4_enc_sequence_replay()
3526 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_replay_cache_entry()
3527 struct xdr_stream *xdr = resp->xdr; in nfsd4_replay_cache_entry()
3531 dprintk("--> %s slot %p\n", __func__, slot); in nfsd4_replay_cache_entry()
3533 status = nfsd4_enc_sequence_replay(resp->rqstp->rq_argp, resp); in nfsd4_replay_cache_entry()
3537 p = xdr_reserve_space(xdr, slot->sl_datalen); in nfsd4_replay_cache_entry()
3542 xdr_encode_opaque_fixed(p, slot->sl_data, slot->sl_datalen); in nfsd4_replay_cache_entry()
3545 resp->opcnt = slot->sl_opcnt; in nfsd4_replay_cache_entry()
3546 return slot->sl_status; in nfsd4_replay_cache_entry()
3556 new->cl_exchange_flags |= EXCHGID4_FLAG_USE_PNFS_MDS; in nfsd4_set_ex_flags()
3558 new->cl_exchange_flags |= EXCHGID4_FLAG_USE_NON_PNFS; in nfsd4_set_ex_flags()
3562 new->cl_exchange_flags |= EXCHGID4_FLAG_SUPP_MOVED_REFER; in nfsd4_set_ex_flags()
3565 clid->flags = new->cl_exchange_flags; in nfsd4_set_ex_flags()
3572 list_for_each_entry(oo, &clp->cl_openowners, oo_perclient) { in client_has_openowners()
3573 if (!list_empty(&oo->oo_owner.so_stateids)) in client_has_openowners()
3583 || !list_empty(&clp->cl_lo_states) in client_has_state()
3585 || !list_empty(&clp->cl_delegations) in client_has_state()
3586 || !list_empty(&clp->cl_sessions) in client_has_state()
3593 if (!exid->nii_domain.data) in copy_impl_id()
3595 xdr_netobj_dup(&clp->cl_nii_domain, &exid->nii_domain, GFP_KERNEL); in copy_impl_id()
3596 if (!clp->cl_nii_domain.data) in copy_impl_id()
3598 xdr_netobj_dup(&clp->cl_nii_name, &exid->nii_name, GFP_KERNEL); in copy_impl_id()
3599 if (!clp->cl_nii_name.data) in copy_impl_id()
3601 clp->cl_nii_time = exid->nii_time; in copy_impl_id()
3609 struct nfsd4_exchange_id *exid = &u->exchange_id; in nfsd4_exchange_id()
3614 nfs4_verifier verf = exid->verifier; in nfsd4_exchange_id()
3616 bool update = exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A; in nfsd4_exchange_id()
3622 __func__, rqstp, exid, exid->clname.len, exid->clname.data, in nfsd4_exchange_id()
3623 addr_str, exid->flags, exid->spa_how); in nfsd4_exchange_id()
3625 exid->server_impl_name = kasprintf(GFP_KERNEL, "%s %s %s %s", in nfsd4_exchange_id()
3626 utsname()->sysname, utsname()->release, in nfsd4_exchange_id()
3627 utsname()->version, utsname()->machine); in nfsd4_exchange_id()
3628 if (!exid->server_impl_name) in nfsd4_exchange_id()
3631 if (exid->flags & ~EXCHGID4_FLAG_MASK_A) in nfsd4_exchange_id()
3634 new = create_client(exid->clname, rqstp, &verf); in nfsd4_exchange_id()
3641 switch (exid->spa_how) { in nfsd4_exchange_id()
3643 exid->spo_must_enforce[0] = 0; in nfsd4_exchange_id()
3644 exid->spo_must_enforce[1] = ( in nfsd4_exchange_id()
3645 1 << (OP_BIND_CONN_TO_SESSION - 32) | in nfsd4_exchange_id()
3646 1 << (OP_EXCHANGE_ID - 32) | in nfsd4_exchange_id()
3647 1 << (OP_CREATE_SESSION - 32) | in nfsd4_exchange_id()
3648 1 << (OP_DESTROY_SESSION - 32) | in nfsd4_exchange_id()
3649 1 << (OP_DESTROY_CLIENTID - 32)); in nfsd4_exchange_id()
3651 exid->spo_must_allow[0] &= (1 << (OP_CLOSE) | in nfsd4_exchange_id()
3656 exid->spo_must_allow[1] &= ( in nfsd4_exchange_id()
3657 1 << (OP_TEST_STATEID - 32) | in nfsd4_exchange_id()
3658 1 << (OP_FREE_STATEID - 32)); in nfsd4_exchange_id()
3668 if (!new->cl_cred.cr_principal && in nfsd4_exchange_id()
3669 !new->cl_cred.cr_raw_principal) { in nfsd4_exchange_id()
3673 new->cl_mach_cred = true; in nfsd4_exchange_id()
3686 spin_lock(&nn->client_lock); in nfsd4_exchange_id()
3687 conf = find_confirmed_client_by_name(&exid->clname, nn); in nfsd4_exchange_id()
3689 bool creds_match = same_creds(&conf->cl_cred, &rqstp->rq_cred); in nfsd4_exchange_id()
3690 bool verfs_match = same_verf(&verf, &conf->cl_verifier); in nfsd4_exchange_id()
3710 exid->flags |= EXCHGID4_FLAG_CONFIRMED_R; in nfsd4_exchange_id()
3723 conf->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; in nfsd4_exchange_id()
3738 unconf = find_unconfirmed_client_by_name(&exid->clname, nn); in nfsd4_exchange_id()
3750 trace_nfsd_clid_replaced(&conf->cl_clientid); in nfsd4_exchange_id()
3752 new->cl_minorversion = cstate->minorversion; in nfsd4_exchange_id()
3753 new->cl_spo_must_allow.u.words[0] = exid->spo_must_allow[0]; in nfsd4_exchange_id()
3754 new->cl_spo_must_allow.u.words[1] = exid->spo_must_allow[1]; in nfsd4_exchange_id()
3757 new->cl_cs_slot.sl_status = nfserr_seq_misordered; in nfsd4_exchange_id()
3762 exid->clientid.cl_boot = conf->cl_clientid.cl_boot; in nfsd4_exchange_id()
3763 exid->clientid.cl_id = conf->cl_clientid.cl_id; in nfsd4_exchange_id()
3765 exid->seqid = conf->cl_cs_slot.sl_seqid + 1; in nfsd4_exchange_id()
3768 exid->nii_domain.len = sizeof("kernel.org") - 1; in nfsd4_exchange_id()
3769 exid->nii_domain.data = "kernel.org"; in nfsd4_exchange_id()
3776 exid->nii_name.len = strlen(exid->server_impl_name); in nfsd4_exchange_id()
3777 if (exid->nii_name.len > NFS4_OPAQUE_LIMIT) in nfsd4_exchange_id()
3778 exid->nii_name.len = NFS4_OPAQUE_LIMIT; in nfsd4_exchange_id()
3779 exid->nii_name.data = exid->server_impl_name; in nfsd4_exchange_id()
3781 /* just send zeros - the date is in nii_name */ in nfsd4_exchange_id()
3782 exid->nii_time.tv_sec = 0; in nfsd4_exchange_id()
3783 exid->nii_time.tv_nsec = 0; in nfsd4_exchange_id()
3786 conf->cl_cs_slot.sl_seqid, conf->cl_exchange_flags); in nfsd4_exchange_id()
3790 spin_unlock(&nn->client_lock); in nfsd4_exchange_id()
3795 trace_nfsd_clid_expire_unconf(&unconf->cl_clientid); in nfsd4_exchange_id()
3804 struct nfsd4_exchange_id *exid = &u->exchange_id; in nfsd4_exchange_id_release()
3806 kfree(exid->server_impl_name); in nfsd4_exchange_id_release()
3818 /* Note unsigned 32-bit arithmetic handles wraparound: */ in check_slot_seqid()
3831 * Do this for solo or embedded create session operations.
3837 slot->sl_status = nfserr; in nfsd4_cache_create_session()
3838 memcpy(&slot->sl_cr_ses, cr_ses, sizeof(*cr_ses)); in nfsd4_cache_create_session()
3845 memcpy(cr_ses, &slot->sl_cr_ses, sizeof(*cr_ses)); in nfsd4_replay_create_session()
3846 return slot->sl_status; in nfsd4_replay_create_session()
3868 u32 maxrpc = nn->nfsd_serv->sv_max_mesg; in check_forechannel_attrs()
3870 if (ca->maxreq_sz < NFSD_MIN_REQ_HDR_SEQ_SZ) in check_forechannel_attrs()
3872 if (ca->maxresp_sz < NFSD_MIN_RESP_HDR_SEQ_SZ) in check_forechannel_attrs()
3874 ca->headerpadsz = 0; in check_forechannel_attrs()
3875 ca->maxreq_sz = min_t(u32, ca->maxreq_sz, maxrpc); in check_forechannel_attrs()
3876 ca->maxresp_sz = min_t(u32, ca->maxresp_sz, maxrpc); in check_forechannel_attrs()
3877 ca->maxops = min_t(u32, ca->maxops, NFSD_MAX_OPS_PER_COMPOUND); in check_forechannel_attrs()
3878 ca->maxresp_cached = min_t(u32, ca->maxresp_cached, in check_forechannel_attrs()
3880 ca->maxreqs = min_t(u32, ca->maxreqs, NFSD_MAX_SLOTS_PER_SESSION); in check_forechannel_attrs()
3886 * Server's NFSv4.1 backchannel support is AUTH_SYS-only for now.
3903 ca->headerpadsz = 0; in check_backchannel_attrs()
3905 if (ca->maxreq_sz < NFSD_CB_MAX_REQ_SZ) in check_backchannel_attrs()
3907 if (ca->maxresp_sz < NFSD_CB_MAX_RESP_SZ) in check_backchannel_attrs()
3909 ca->maxresp_cached = 0; in check_backchannel_attrs()
3910 if (ca->maxops < 2) in check_backchannel_attrs()
3918 switch (cbs->flavor) { in nfsd4_check_cb_sec()
3938 struct nfsd4_create_session *cr_ses = &u->create_session; in nfsd4_create_session()
3948 if (cr_ses->flags & ~SESSION4_FLAG_MASK_A) in nfsd4_create_session()
3950 status = nfsd4_check_cb_sec(&cr_ses->cb_sec); in nfsd4_create_session()
3953 status = check_forechannel_attrs(&cr_ses->fore_channel, nn); in nfsd4_create_session()
3956 status = check_backchannel_attrs(&cr_ses->back_channel); in nfsd4_create_session()
3960 new = alloc_session(&cr_ses->fore_channel, &cr_ses->back_channel); in nfsd4_create_session()
3967 spin_lock(&nn->client_lock); in nfsd4_create_session()
3969 /* RFC 8881 Section 18.36.4 Phase 1: Client record look-up. */ in nfsd4_create_session()
3970 unconf = find_unconfirmed_client(&cr_ses->clientid, true, nn); in nfsd4_create_session()
3971 conf = find_confirmed_client(&cr_ses->clientid, true, nn); in nfsd4_create_session()
3979 cs_slot = &conf->cl_cs_slot; in nfsd4_create_session()
3982 cs_slot = &unconf->cl_cs_slot; in nfsd4_create_session()
3985 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); in nfsd4_create_session()
3988 cs_slot->sl_seqid++; in nfsd4_create_session()
3989 cr_ses->seqid = cs_slot->sl_seqid; in nfsd4_create_session()
4008 if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred) || in nfsd4_create_session()
4009 !rpc_cmp_addr(sa, (struct sockaddr *) &unconf->cl_addr)) { in nfsd4_create_session()
4016 old = find_confirmed_client_by_name(&unconf->cl_name, nn); in nfsd4_create_session()
4021 trace_nfsd_clid_replaced(&old->cl_clientid); in nfsd4_create_session()
4030 cr_ses->flags &= ~SESSION4_PERSIST; in nfsd4_create_session()
4032 cr_ses->flags &= ~SESSION4_RDMA; in nfsd4_create_session()
4034 cr_ses->back_channel.maxreqs = new->se_cb_highest_slot + 1; in nfsd4_create_session()
4039 memcpy(cr_ses->sessionid.data, new->se_sessionid.data, in nfsd4_create_session()
4042 /* cache solo and embedded create sessions under the client_lock */ in nfsd4_create_session()
4044 spin_unlock(&nn->client_lock); in nfsd4_create_session()
4046 fsnotify_dentry(conf->cl_nfsd_info_dentry, FS_MODIFY); in nfsd4_create_session()
4060 cs_slot->sl_seqid--; in nfsd4_create_session()
4061 cr_ses->seqid = cs_slot->sl_seqid; in nfsd4_create_session()
4067 spin_unlock(&nn->client_lock); in nfsd4_create_session()
4093 struct nfsd4_backchannel_ctl *bc = &u->backchannel_ctl; in nfsd4_backchannel_ctl()
4094 struct nfsd4_session *session = cstate->session; in nfsd4_backchannel_ctl()
4098 status = nfsd4_check_cb_sec(&bc->bc_cb_sec); in nfsd4_backchannel_ctl()
4101 spin_lock(&nn->client_lock); in nfsd4_backchannel_ctl()
4102 session->se_cb_prog = bc->bc_cb_program; in nfsd4_backchannel_ctl()
4103 session->se_cb_sec = bc->bc_cb_sec; in nfsd4_backchannel_ctl()
4104 spin_unlock(&nn->client_lock); in nfsd4_backchannel_ctl()
4106 nfsd4_probe_callback(session->se_client); in nfsd4_backchannel_ctl()
4115 list_for_each_entry(c, &s->se_conns, cn_persession) { in __nfsd4_find_conn()
4116 if (c->cn_xprt == xpt) { in __nfsd4_find_conn()
4126 struct nfs4_client *clp = session->se_client; in nfsd4_match_existing_connection()
4127 struct svc_xprt *xpt = rqst->rq_xprt; in nfsd4_match_existing_connection()
4132 spin_lock(&clp->cl_lock); in nfsd4_match_existing_connection()
4136 else if (req == c->cn_flags) in nfsd4_match_existing_connection()
4139 c->cn_flags != NFS4_CDFC4_BACK) in nfsd4_match_existing_connection()
4142 c->cn_flags != NFS4_CDFC4_FORE) in nfsd4_match_existing_connection()
4146 spin_unlock(&clp->cl_lock); in nfsd4_match_existing_connection()
4156 struct nfsd4_bind_conn_to_session *bcts = &u->bind_conn_to_session; in nfsd4_bind_conn_to_session()
4165 spin_lock(&nn->client_lock); in nfsd4_bind_conn_to_session()
4166 session = find_in_sessionid_hashtbl(&bcts->sessionid, net, &status); in nfsd4_bind_conn_to_session()
4167 spin_unlock(&nn->client_lock); in nfsd4_bind_conn_to_session()
4171 if (!nfsd4_mach_creds_match(session->se_client, rqstp)) in nfsd4_bind_conn_to_session()
4174 bcts->dir, &conn); in nfsd4_bind_conn_to_session()
4176 if (bcts->dir == NFS4_CDFC4_FORE_OR_BOTH || in nfsd4_bind_conn_to_session()
4177 bcts->dir == NFS4_CDFC4_BACK) in nfsd4_bind_conn_to_session()
4178 conn->cn_flags |= NFS4_CDFC4_BACK; in nfsd4_bind_conn_to_session()
4179 nfsd4_probe_callback(session->se_client); in nfsd4_bind_conn_to_session()
4184 status = nfsd4_map_bcts_dir(&bcts->dir); in nfsd4_bind_conn_to_session()
4187 conn = alloc_conn(rqstp, bcts->dir); in nfsd4_bind_conn_to_session()
4201 if (!cstate->session) in nfsd4_compound_in_session()
4203 return !memcmp(sid, &cstate->session->se_sessionid, sizeof(*sid)); in nfsd4_compound_in_session()
4210 struct nfs4_sessionid *sessionid = &u->destroy_session.sessionid; in nfsd4_destroy_session()
4224 spin_lock(&nn->client_lock); in nfsd4_destroy_session()
4229 if (!nfsd4_mach_creds_match(ses->se_client, r)) in nfsd4_destroy_session()
4235 spin_unlock(&nn->client_lock); in nfsd4_destroy_session()
4237 nfsd4_probe_callback_sync(ses->se_client); in nfsd4_destroy_session()
4239 spin_lock(&nn->client_lock); in nfsd4_destroy_session()
4244 spin_unlock(&nn->client_lock); in nfsd4_destroy_session()
4251 struct nfs4_client *clp = ses->se_client; in nfsd4_sequence_check_conn()
4256 spin_lock(&clp->cl_lock); in nfsd4_sequence_check_conn()
4257 c = __nfsd4_find_conn(new->cn_xprt, ses); in nfsd4_sequence_check_conn()
4261 if (clp->cl_mach_cred) in nfsd4_sequence_check_conn()
4264 spin_unlock(&clp->cl_lock); in nfsd4_sequence_check_conn()
4268 nfsd4_conn_lost(&new->cn_xpt_user); in nfsd4_sequence_check_conn()
4271 spin_unlock(&clp->cl_lock); in nfsd4_sequence_check_conn()
4278 struct nfsd4_compoundargs *args = rqstp->rq_argp; in nfsd4_session_too_many_ops()
4280 return args->opcnt > session->se_fchannel.maxops; in nfsd4_session_too_many_ops()
4286 struct xdr_buf *xb = &rqstp->rq_arg; in nfsd4_request_too_big()
4288 return xb->len > session->se_fchannel.maxreq_sz; in nfsd4_request_too_big()
4294 struct nfsd4_compoundargs *argp = rqstp->rq_argp; in replay_matches_cache()
4296 if ((bool)(slot->sl_flags & NFSD4_SLOT_CACHETHIS) != in replay_matches_cache()
4297 (bool)seq->cachethis) in replay_matches_cache()
4303 if (slot->sl_opcnt < argp->opcnt && !slot->sl_status) in replay_matches_cache()
4310 if (slot->sl_opcnt > argp->opcnt) in replay_matches_cache()
4313 if (!same_creds(&rqstp->rq_cred, &slot->sl_cred)) in replay_matches_cache()
4328 struct nfsd4_sequence *seq = &u->sequence; in nfsd4_sequence()
4329 struct nfsd4_compoundres *resp = rqstp->rq_resp; in nfsd4_sequence()
4330 struct xdr_stream *xdr = resp->xdr; in nfsd4_sequence()
4340 if (resp->opcnt != 1) in nfsd4_sequence()
4351 spin_lock(&nn->client_lock); in nfsd4_sequence()
4352 session = find_in_sessionid_hashtbl(&seq->sessionid, net, &status); in nfsd4_sequence()
4355 clp = session->se_client; in nfsd4_sequence()
4366 if (seq->slotid >= session->se_fchannel.maxreqs) in nfsd4_sequence()
4369 slot = xa_load(&session->se_slots, seq->slotid); in nfsd4_sequence()
4370 dprintk("%s: slotid %d\n", __func__, seq->slotid); in nfsd4_sequence()
4373 status = check_slot_seqid(seq->seqid, slot->sl_seqid, slot->sl_flags); in nfsd4_sequence()
4376 if (!(slot->sl_flags & NFSD4_SLOT_INITIALIZED)) in nfsd4_sequence()
4381 cstate->slot = slot; in nfsd4_sequence()
4382 cstate->session = session; in nfsd4_sequence()
4383 cstate->clp = clp; in nfsd4_sequence()
4384 /* Return the cached reply status and set cstate->status in nfsd4_sequence()
4387 cstate->status = nfserr_replay_cache; in nfsd4_sequence()
4398 if (session->se_target_maxslots < session->se_fchannel.maxreqs && in nfsd4_sequence()
4399 slot->sl_generation == session->se_slot_gen && in nfsd4_sequence()
4400 seq->maxslots <= session->se_target_maxslots) in nfsd4_sequence()
4402 free_session_slots(session, session->se_target_maxslots); in nfsd4_sequence()
4404 buflen = (seq->cachethis) ? in nfsd4_sequence()
4405 session->se_fchannel.maxresp_cached : in nfsd4_sequence()
4406 session->se_fchannel.maxresp_sz; in nfsd4_sequence()
4407 status = (seq->cachethis) ? nfserr_rep_too_big_to_cache : in nfsd4_sequence()
4409 if (xdr_restrict_buflen(xdr, buflen - rqstp->rq_auth_slack)) in nfsd4_sequence()
4415 slot->sl_seqid = seq->seqid; in nfsd4_sequence()
4416 slot->sl_flags &= ~NFSD4_SLOT_REUSED; in nfsd4_sequence()
4417 slot->sl_flags |= NFSD4_SLOT_INUSE; in nfsd4_sequence()
4418 slot->sl_generation = session->se_slot_gen; in nfsd4_sequence()
4419 if (seq->cachethis) in nfsd4_sequence()
4420 slot->sl_flags |= NFSD4_SLOT_CACHETHIS; in nfsd4_sequence()
4422 slot->sl_flags &= ~NFSD4_SLOT_CACHETHIS; in nfsd4_sequence()
4424 cstate->slot = slot; in nfsd4_sequence()
4425 cstate->session = session; in nfsd4_sequence()
4426 cstate->clp = clp; in nfsd4_sequence()
4431 * fairly quick growth without grossly over-shooting what in nfsd4_sequence()
4434 if (seq->slotid == session->se_fchannel.maxreqs - 1 && in nfsd4_sequence()
4435 session->se_target_maxslots >= session->se_fchannel.maxreqs && in nfsd4_sequence()
4436 session->se_fchannel.maxreqs < NFSD_MAX_SLOTS_PER_SESSION) { in nfsd4_sequence()
4437 int s = session->se_fchannel.maxreqs; in nfsd4_sequence()
4447 slot = kzalloc(slot_bytes(&session->se_fchannel), in nfsd4_sequence()
4449 prev_slot = xa_load(&session->se_slots, s); in nfsd4_sequence()
4451 slot->sl_seqid = xa_to_value(prev_slot); in nfsd4_sequence()
4452 slot->sl_flags |= NFSD4_SLOT_REUSED; in nfsd4_sequence()
4455 !xa_is_err(xa_store(&session->se_slots, s, slot, in nfsd4_sequence()
4458 session->se_fchannel.maxreqs = s; in nfsd4_sequence()
4459 atomic_add(s - session->se_target_maxslots, in nfsd4_sequence()
4461 session->se_target_maxslots = s; in nfsd4_sequence()
4466 } while (slot && --cnt > 0); in nfsd4_sequence()
4470 seq->maxslots = max(session->se_target_maxslots, seq->maxslots); in nfsd4_sequence()
4471 seq->target_maxslots = session->se_target_maxslots; in nfsd4_sequence()
4473 switch (clp->cl_cb_state) { in nfsd4_sequence()
4475 seq->status_flags = SEQ4_STATUS_CB_PATH_DOWN; in nfsd4_sequence()
4478 seq->status_flags = SEQ4_STATUS_BACKCHANNEL_FAULT; in nfsd4_sequence()
4481 seq->status_flags = 0; in nfsd4_sequence()
4483 if (!list_empty(&clp->cl_revoked)) in nfsd4_sequence()
4484 seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED; in nfsd4_sequence()
4485 if (atomic_read(&clp->cl_admin_revoked)) in nfsd4_sequence()
4486 seq->status_flags |= SEQ4_STATUS_ADMIN_STATE_REVOKED; in nfsd4_sequence()
4491 spin_unlock(&nn->client_lock); in nfsd4_sequence()
4501 struct nfsd4_compound_state *cs = &resp->cstate; in nfsd4_sequence_done()
4504 if (cs->status != nfserr_replay_cache) { in nfsd4_sequence_done()
4506 cs->slot->sl_flags &= ~NFSD4_SLOT_INUSE; in nfsd4_sequence_done()
4509 nfsd4_put_session(cs->session); in nfsd4_sequence_done()
4510 } else if (cs->clp) in nfsd4_sequence_done()
4511 put_client_renew(cs->clp); in nfsd4_sequence_done()
4519 struct nfsd4_destroy_clientid *dc = &u->destroy_clientid; in nfsd4_destroy_clientid()
4525 spin_lock(&nn->client_lock); in nfsd4_destroy_clientid()
4526 unconf = find_unconfirmed_client(&dc->clientid, true, nn); in nfsd4_destroy_clientid()
4527 conf = find_confirmed_client(&dc->clientid, true, nn); in nfsd4_destroy_clientid()
4550 trace_nfsd_clid_destroyed(&clp->cl_clientid); in nfsd4_destroy_clientid()
4553 spin_unlock(&nn->client_lock); in nfsd4_destroy_clientid()
4563 struct nfsd4_reclaim_complete *rc = &u->reclaim_complete; in nfsd4_reclaim_complete()
4564 struct nfs4_client *clp = cstate->clp; in nfsd4_reclaim_complete()
4567 if (rc->rca_one_fs) { in nfsd4_reclaim_complete()
4568 if (!cstate->current_fh.fh_dentry) in nfsd4_reclaim_complete()
4578 if (test_and_set_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &clp->cl_flags)) in nfsd4_reclaim_complete()
4593 trace_nfsd_clid_reclaim_complete(&clp->cl_clientid); in nfsd4_reclaim_complete()
4604 struct nfsd4_setclientid *setclid = &u->setclientid; in nfsd4_setclientid()
4605 struct xdr_netobj clname = setclid->se_name; in nfsd4_setclientid()
4606 nfs4_verifier clverifier = setclid->se_verf; in nfsd4_setclientid()
4615 spin_lock(&nn->client_lock); in nfsd4_setclientid()
4621 if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid()
4630 if (same_verf(&conf->cl_verifier, &clverifier)) { in nfsd4_setclientid()
4638 new->cl_minorversion = 0; in nfsd4_setclientid()
4641 setclid->se_clientid.cl_boot = new->cl_clientid.cl_boot; in nfsd4_setclientid()
4642 setclid->se_clientid.cl_id = new->cl_clientid.cl_id; in nfsd4_setclientid()
4643 memcpy(setclid->se_confirm.data, new->cl_confirm.data, sizeof(setclid->se_confirm.data)); in nfsd4_setclientid()
4647 spin_unlock(&nn->client_lock); in nfsd4_setclientid()
4651 trace_nfsd_clid_expire_unconf(&unconf->cl_clientid); in nfsd4_setclientid()
4663 &u->setclientid_confirm; in nfsd4_setclientid_confirm()
4666 nfs4_verifier confirm = setclientid_confirm->sc_confirm; in nfsd4_setclientid_confirm()
4667 clientid_t * clid = &setclientid_confirm->sc_clientid; in nfsd4_setclientid_confirm()
4674 spin_lock(&nn->client_lock); in nfsd4_setclientid_confirm()
4685 if (unconf && !same_creds(&unconf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid_confirm()
4689 if (conf && !same_creds(&conf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid_confirm()
4693 if (!unconf || !same_verf(&confirm, &unconf->cl_confirm)) { in nfsd4_setclientid_confirm()
4694 if (conf && same_verf(&confirm, &conf->cl_confirm)) { in nfsd4_setclientid_confirm()
4704 nfsd4_change_callback(conf, &unconf->cl_cb_conn); in nfsd4_setclientid_confirm()
4706 old = find_confirmed_client_by_name(&unconf->cl_name, nn); in nfsd4_setclientid_confirm()
4710 && !same_creds(&unconf->cl_cred, in nfsd4_setclientid_confirm()
4711 &old->cl_cred)) { in nfsd4_setclientid_confirm()
4720 trace_nfsd_clid_replaced(&old->cl_clientid); in nfsd4_setclientid_confirm()
4726 spin_unlock(&nn->client_lock); in nfsd4_setclientid_confirm()
4728 fsnotify_dentry(conf->cl_nfsd_info_dentry, FS_MODIFY); in nfsd4_setclientid_confirm()
4730 spin_lock(&nn->client_lock); in nfsd4_setclientid_confirm()
4733 spin_unlock(&nn->client_lock); in nfsd4_setclientid_confirm()
4748 refcount_set(&fp->fi_ref, 1); in nfsd4_file_init()
4749 spin_lock_init(&fp->fi_lock); in nfsd4_file_init()
4750 INIT_LIST_HEAD(&fp->fi_stateids); in nfsd4_file_init()
4751 INIT_LIST_HEAD(&fp->fi_delegations); in nfsd4_file_init()
4752 INIT_LIST_HEAD(&fp->fi_clnt_odstate); in nfsd4_file_init()
4753 fh_copy_shallow(&fp->fi_fhandle, &fh->fh_handle); in nfsd4_file_init()
4754 fp->fi_deleg_file = NULL; in nfsd4_file_init()
4755 fp->fi_had_conflict = false; in nfsd4_file_init()
4756 fp->fi_share_deny = 0; in nfsd4_file_init()
4757 memset(fp->fi_fds, 0, sizeof(fp->fi_fds)); in nfsd4_file_init()
4758 memset(fp->fi_access, 0, sizeof(fp->fi_access)); in nfsd4_file_init()
4759 fp->fi_aliased = false; in nfsd4_file_init()
4760 fp->fi_inode = d_inode(fh->fh_dentry); in nfsd4_file_init()
4762 INIT_LIST_HEAD(&fp->fi_lo_states); in nfsd4_file_init()
4763 atomic_set(&fp->fi_lo_recalls, 0); in nfsd4_file_init()
4818 return -ENOMEM; in nfsd4_init_slabs()
4825 struct nfsd_net *nn = shrink->private_data; in nfsd4_state_shrinker_count()
4827 count = atomic_read(&nn->nfsd_courtesy_clients); in nfsd4_state_shrinker_count()
4831 queue_work(laundry_wq, &nn->nfsd_shrinker_work); in nfsd4_state_shrinker_count()
4847 nn->nfsd4_lease = 90; /* default lease time */ in nfsd4_init_leases_net()
4848 nn->nfsd4_grace = 90; in nfsd4_init_leases_net()
4849 nn->somebody_reclaimed = false; in nfsd4_init_leases_net()
4850 nn->track_reclaim_completes = false; in nfsd4_init_leases_net()
4851 nn->clverifier_counter = get_random_u32(); in nfsd4_init_leases_net()
4852 nn->clientid_base = get_random_u32(); in nfsd4_init_leases_net()
4853 nn->clientid_counter = nn->clientid_base + 1; in nfsd4_init_leases_net()
4854 nn->s2s_cp_cl_id = nn->clientid_counter++; in nfsd4_init_leases_net()
4856 atomic_set(&nn->nfs4_client_count, 0); in nfsd4_init_leases_net()
4860 nn->nfs4_max_clients = max_t(int, max_clients, NFS4_CLIENTS_PER_GB); in nfsd4_init_leases_net()
4862 atomic_set(&nn->nfsd_courtesy_clients, 0); in nfsd4_init_leases_net()
4873 rp->rp_status = nfserr_serverfault; in init_nfs4_replay()
4874 rp->rp_buflen = 0; in init_nfs4_replay()
4875 rp->rp_buf = rp->rp_ibuf; in init_nfs4_replay()
4876 rp->rp_locked = RP_UNLOCKED; in init_nfs4_replay()
4883 wait_var_event(&so->so_replay.rp_locked, in nfsd4_cstate_assign_replay()
4884 cmpxchg(&so->so_replay.rp_locked, in nfsd4_cstate_assign_replay()
4886 if (so->so_replay.rp_locked == RP_UNHASHED) in nfsd4_cstate_assign_replay()
4887 return -EAGAIN; in nfsd4_cstate_assign_replay()
4888 cstate->replay_owner = nfs4_get_stateowner(so); in nfsd4_cstate_assign_replay()
4895 struct nfs4_stateowner *so = cstate->replay_owner; in nfsd4_cstate_clear_replay()
4898 cstate->replay_owner = NULL; in nfsd4_cstate_clear_replay()
4899 store_release_wake_up(&so->so_replay.rp_locked, RP_UNLOCKED); in nfsd4_cstate_clear_replay()
4912 xdr_netobj_dup(&sop->so_owner, owner, GFP_KERNEL); in alloc_stateowner()
4913 if (!sop->so_owner.data) { in alloc_stateowner()
4918 INIT_LIST_HEAD(&sop->so_stateids); in alloc_stateowner()
4919 sop->so_client = clp; in alloc_stateowner()
4920 init_nfs4_replay(&sop->so_replay); in alloc_stateowner()
4921 atomic_set(&sop->so_count, 1); in alloc_stateowner()
4927 lockdep_assert_held(&clp->cl_lock); in hash_openowner()
4929 list_add(&oo->oo_owner.so_strhash, in hash_openowner()
4930 &clp->cl_ownerstr_hashtbl[strhashval]); in hash_openowner()
4931 list_add(&oo->oo_perclient, &clp->cl_openowners); in hash_openowner()
4955 struct nfs4_openowner *oo = open->op_openowner; in nfsd4_find_existing_open()
4957 lockdep_assert_held(&fp->fi_lock); in nfsd4_find_existing_open()
4959 list_for_each_entry(local, &fp->fi_stateids, st_perfile) { in nfsd4_find_existing_open()
4961 if (local->st_stateowner->so_is_open_owner == 0) in nfsd4_find_existing_open()
4963 if (local->st_stateowner != &oo->oo_owner) in nfsd4_find_existing_open()
4965 if (local->st_stid.sc_type == SC_TYPE_OPEN && in nfsd4_find_existing_open()
4966 !local->st_stid.sc_status) { in nfsd4_find_existing_open()
4968 refcount_inc(&ret->st_stid.sc_count); in nfsd4_find_existing_open()
4976 __releases(&s->sc_client->cl_lock) in nfsd4_drop_revoked_stid()
4978 struct nfs4_client *cl = s->sc_client; in nfsd4_drop_revoked_stid()
4984 switch (s->sc_type) { in nfsd4_drop_revoked_stid()
4989 spin_unlock(&cl->cl_lock); in nfsd4_drop_revoked_stid()
4995 spin_unlock(&cl->cl_lock); in nfsd4_drop_revoked_stid()
5001 list_del_init(&dp->dl_recall_lru); in nfsd4_drop_revoked_stid()
5002 spin_unlock(&cl->cl_lock); in nfsd4_drop_revoked_stid()
5006 spin_unlock(&cl->cl_lock); in nfsd4_drop_revoked_stid()
5014 * that it can forget an admin-revoked stateid. in nfsd40_drop_revoked_stid()
5021 if (cl->cl_minorversion == 0) { in nfsd40_drop_revoked_stid()
5024 spin_lock(&cl->cl_lock); in nfsd40_drop_revoked_stid()
5029 spin_unlock(&cl->cl_lock); in nfsd40_drop_revoked_stid()
5038 if (s->sc_status & SC_STATUS_ADMIN_REVOKED) in nfsd4_verify_open_stid()
5040 else if (s->sc_status & SC_STATUS_REVOKED) in nfsd4_verify_open_stid()
5042 else if (s->sc_status & SC_STATUS_CLOSED) in nfsd4_verify_open_stid()
5053 mutex_lock_nested(&stp->st_mutex, LOCK_STATEID_MUTEX); in nfsd4_lock_ol_stateid()
5054 ret = nfsd4_verify_open_stid(&stp->st_stid); in nfsd4_lock_ol_stateid()
5056 nfsd40_drop_revoked_stid(stp->st_stid.sc_client, in nfsd4_lock_ol_stateid()
5057 &stp->st_stid.sc_stateid); in nfsd4_lock_ol_stateid()
5060 mutex_unlock(&stp->st_mutex); in nfsd4_lock_ol_stateid()
5069 spin_lock(&fp->fi_lock); in nfsd4_find_and_lock_existing_open()
5071 spin_unlock(&fp->fi_lock); in nfsd4_find_and_lock_existing_open()
5074 nfs4_put_stid(&stp->st_stid); in nfsd4_find_and_lock_existing_open()
5083 struct nfs4_client *clp = cstate->clp; in find_or_alloc_open_stateowner()
5087 spin_lock(&clp->cl_lock); in find_or_alloc_open_stateowner()
5091 spin_unlock(&clp->cl_lock); in find_or_alloc_open_stateowner()
5094 spin_unlock(&clp->cl_lock); in find_or_alloc_open_stateowner()
5096 if (oo && !(oo->oo_flags & NFS4_OO_CONFIRMED)) { in find_or_alloc_open_stateowner()
5103 nfs4_free_stateowner(&new->oo_owner); in find_or_alloc_open_stateowner()
5107 new = alloc_stateowner(openowner_slab, &open->op_owner, clp); in find_or_alloc_open_stateowner()
5110 new->oo_owner.so_ops = &openowner_ops; in find_or_alloc_open_stateowner()
5111 new->oo_owner.so_is_open_owner = 1; in find_or_alloc_open_stateowner()
5112 new->oo_owner.so_seqid = open->op_seqid; in find_or_alloc_open_stateowner()
5113 new->oo_flags = 0; in find_or_alloc_open_stateowner()
5115 new->oo_flags |= NFS4_OO_CONFIRMED; in find_or_alloc_open_stateowner()
5116 new->oo_time = 0; in find_or_alloc_open_stateowner()
5117 new->oo_last_closed_stid = NULL; in find_or_alloc_open_stateowner()
5118 INIT_LIST_HEAD(&new->oo_close_lru); in find_or_alloc_open_stateowner()
5126 struct nfs4_openowner *oo = open->op_openowner; in init_open_stateid()
5130 stp = open->op_stp; in init_open_stateid()
5132 mutex_init(&stp->st_mutex); in init_open_stateid()
5133 mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX); in init_open_stateid()
5136 spin_lock(&oo->oo_owner.so_client->cl_lock); in init_open_stateid()
5137 spin_lock(&fp->fi_lock); in init_open_stateid()
5140 mutex_unlock(&stp->st_mutex); in init_open_stateid()
5149 open->op_stp = NULL; in init_open_stateid()
5150 refcount_inc(&stp->st_stid.sc_count); in init_open_stateid()
5151 stp->st_stid.sc_type = SC_TYPE_OPEN; in init_open_stateid()
5152 INIT_LIST_HEAD(&stp->st_locks); in init_open_stateid()
5153 stp->st_stateowner = nfs4_get_stateowner(&oo->oo_owner); in init_open_stateid()
5155 stp->st_stid.sc_file = fp; in init_open_stateid()
5156 stp->st_access_bmap = 0; in init_open_stateid()
5157 stp->st_deny_bmap = 0; in init_open_stateid()
5158 stp->st_openstp = NULL; in init_open_stateid()
5159 list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids); in init_open_stateid()
5160 list_add(&stp->st_perfile, &fp->fi_stateids); in init_open_stateid()
5163 spin_unlock(&fp->fi_lock); in init_open_stateid()
5164 spin_unlock(&oo->oo_owner.so_client->cl_lock); in init_open_stateid()
5168 nfs4_put_stid(&retstp->st_stid); in init_open_stateid()
5172 mutex_unlock(&stp->st_mutex); in init_open_stateid()
5187 struct nfs4_openowner *oo = openowner(s->st_stateowner); in move_to_close_lru()
5188 struct nfsd_net *nn = net_generic(s->st_stid.sc_client->net, in move_to_close_lru()
5204 store_release_wake_up(&oo->oo_owner.so_replay.rp_locked, RP_UNHASHED); in move_to_close_lru()
5205 wait_event(close_wq, refcount_read(&s->st_stid.sc_count) == 2); in move_to_close_lru()
5208 if (s->st_stid.sc_file) { in move_to_close_lru()
5209 put_nfs4_file(s->st_stid.sc_file); in move_to_close_lru()
5210 s->st_stid.sc_file = NULL; in move_to_close_lru()
5213 spin_lock(&nn->client_lock); in move_to_close_lru()
5214 last = oo->oo_last_closed_stid; in move_to_close_lru()
5215 oo->oo_last_closed_stid = s; in move_to_close_lru()
5216 list_move_tail(&oo->oo_close_lru, &nn->close_lru); in move_to_close_lru()
5217 oo->oo_time = ktime_get_boottime_seconds(); in move_to_close_lru()
5218 spin_unlock(&nn->client_lock); in move_to_close_lru()
5220 nfs4_put_stid(&last->st_stid); in move_to_close_lru()
5226 struct inode *inode = d_inode(fhp->fh_dentry); in nfsd4_file_hash_lookup()
5234 if (fh_match(&fi->fi_fhandle, &fhp->fh_handle)) { in nfsd4_file_hash_lookup()
5235 if (refcount_inc_not_zero(&fi->fi_ref)) { in nfsd4_file_hash_lookup()
5250 * inode->i_lock prevents racing insertions from adding an entry
5256 struct inode *inode = d_inode(fhp->fh_dentry); in nfsd4_file_hash_insert()
5264 spin_lock(&inode->i_lock); in nfsd4_file_hash_insert()
5269 if (fh_match(&fi->fi_fhandle, &fhp->fh_handle)) { in nfsd4_file_hash_insert()
5270 if (refcount_inc_not_zero(&fi->fi_ref)) in nfsd4_file_hash_insert()
5273 fi->fi_aliased = alias_found = true; in nfsd4_file_hash_insert()
5279 err = rhltable_insert(&nfs4_file_rhltable, &new->fi_rlist, in nfsd4_file_hash_insert()
5284 new->fi_aliased = alias_found; in nfsd4_file_hash_insert()
5288 spin_unlock(&inode->i_lock); in nfsd4_file_hash_insert()
5295 rhltable_remove(&nfs4_file_rhltable, &fi->fi_rlist, in nfsd4_file_hash_remove()
5314 spin_lock(&fp->fi_lock); in nfs4_share_conflict()
5315 if (fp->fi_share_deny & deny_type) in nfs4_share_conflict()
5317 spin_unlock(&fp->fi_lock); in nfs4_share_conflict()
5326 return ctx && !list_empty_careful(&ctx->flc_lease); in nfsd4_deleg_present()
5330 * nfsd_wait_for_delegreturn - wait for delegations to be returned
5332 * @inode: in-core inode of the file being waited for
5354 struct nfsd_net *nn = net_generic(dp->dl_stid.sc_client->net, in nfsd4_cb_recall_prepare()
5357 block_delegations(&dp->dl_stid.sc_file->fi_fhandle); in nfsd4_cb_recall_prepare()
5361 * already holding inode->i_lock. in nfsd4_cb_recall_prepare()
5367 if (delegation_hashed(dp) && dp->dl_time == 0) { in nfsd4_cb_recall_prepare()
5368 dp->dl_time = ktime_get_boottime_seconds(); in nfsd4_cb_recall_prepare()
5369 list_add_tail(&dp->dl_recall_lru, &nn->del_recall_lru); in nfsd4_cb_recall_prepare()
5379 trace_nfsd_cb_recall_done(&dp->dl_stid.sc_stateid, task); in nfsd4_cb_recall_done()
5381 if (dp->dl_stid.sc_status) in nfsd4_cb_recall_done()
5385 switch (task->tk_status) { in nfsd4_cb_recall_done()
5388 case -NFS4ERR_DELAY: in nfsd4_cb_recall_done()
5391 case -EBADHANDLE: in nfsd4_cb_recall_done()
5392 case -NFS4ERR_BAD_STATEID: in nfsd4_cb_recall_done()
5397 if (dp->dl_retries--) { in nfsd4_cb_recall_done()
5411 nfs4_put_stid(&dp->dl_stid); in nfsd4_cb_recall_release()
5431 refcount_inc(&dp->dl_stid.sc_count); in nfsd_break_one_deleg()
5432 queued = nfsd4_run_cb(&dp->dl_recall); in nfsd_break_one_deleg()
5435 refcount_dec(&dp->dl_stid.sc_count); in nfsd_break_one_deleg()
5442 struct nfs4_delegation *dp = (struct nfs4_delegation *) fl->c.flc_owner; in nfsd_break_deleg_cb()
5443 struct nfs4_file *fp = dp->dl_stid.sc_file; in nfsd_break_deleg_cb()
5444 struct nfs4_client *clp = dp->dl_stid.sc_client; in nfsd_break_deleg_cb()
5447 trace_nfsd_cb_recall(&dp->dl_stid); in nfsd_break_deleg_cb()
5449 dp->dl_recalled = true; in nfsd_break_deleg_cb()
5450 atomic_inc(&clp->cl_delegs_in_recall); in nfsd_break_deleg_cb()
5452 nn = net_generic(clp->net, nfsd_net_id); in nfsd_break_deleg_cb()
5453 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in nfsd_break_deleg_cb()
5461 fl->fl_break_time = 0; in nfsd_break_deleg_cb()
5463 fp->fi_had_conflict = true; in nfsd_break_deleg_cb()
5469 * nfsd_breaker_owns_lease - Check if lease conflict was resolved
5478 struct nfs4_delegation *dl = fl->c.flc_owner; in nfsd_breaker_owns_lease()
5485 clp = *(rqst->rq_lease_breaker); in nfsd_breaker_owns_lease()
5486 return dl->dl_stid.sc_client == clp; in nfsd_breaker_owns_lease()
5493 struct nfs4_delegation *dp = (struct nfs4_delegation *) onlist->c.flc_owner; in nfsd_change_deleg_cb()
5494 struct nfs4_client *clp = dp->dl_stid.sc_client; in nfsd_change_deleg_cb()
5497 if (dp->dl_recalled) in nfsd_change_deleg_cb()
5498 atomic_dec(&clp->cl_delegs_in_recall); in nfsd_change_deleg_cb()
5501 return -EAGAIN; in nfsd_change_deleg_cb()
5514 if (seqid == so->so_seqid - 1) in nfsd4_check_seqid()
5516 if (seqid == so->so_seqid) in nfsd4_check_seqid()
5526 spin_lock(&nn->client_lock); in lookup_clientid()
5529 atomic_inc(&found->cl_rpc_users); in lookup_clientid()
5530 spin_unlock(&nn->client_lock); in lookup_clientid()
5538 if (cstate->clp) { in set_client()
5539 if (!same_clid(&cstate->clp->cl_clientid, clid)) in set_client()
5547 * set cstate->clp), so session = false: in set_client()
5549 cstate->clp = lookup_clientid(clid, false, nn); in set_client()
5550 if (!cstate->clp) in set_client()
5559 clientid_t *clientid = &open->op_clientid; in nfsd4_process_open1()
5569 open->op_file = nfsd4_alloc_file(); in nfsd4_process_open1()
5570 if (open->op_file == NULL) in nfsd4_process_open1()
5576 clp = cstate->clp; in nfsd4_process_open1()
5578 strhashval = ownerstr_hashval(&open->op_owner); in nfsd4_process_open1()
5581 open->op_openowner = oo; in nfsd4_process_open1()
5584 if (nfsd4_cstate_assign_replay(cstate, &oo->oo_owner) == -EAGAIN) { in nfsd4_process_open1()
5585 nfs4_put_stateowner(&oo->oo_owner); in nfsd4_process_open1()
5588 status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid); in nfsd4_process_open1()
5592 open->op_stp = nfs4_alloc_open_stateid(clp); in nfsd4_process_open1()
5593 if (!open->op_stp) in nfsd4_process_open1()
5597 (cstate->current_fh.fh_export->ex_flags & NFSEXP_PNFS)) { in nfsd4_process_open1()
5598 open->op_odstate = alloc_clnt_odstate(clp); in nfsd4_process_open1()
5599 if (!open->op_odstate) in nfsd4_process_open1()
5609 if (!(flags & RD_STATE) && deleg_is_read(dp->dl_type)) in nfs4_check_delegmode()
5633 return open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR || in nfsd4_is_deleg_cur()
5634 open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH; in nfsd4_is_deleg_cur()
5645 deleg = find_deleg_stateid(cl, &open->op_delegate_stateid); in nfs4_check_deleg()
5648 if (deleg->dl_stid.sc_status & SC_STATUS_ADMIN_REVOKED) { in nfs4_check_deleg()
5649 nfs4_put_stid(&deleg->dl_stid); in nfs4_check_deleg()
5653 if (deleg->dl_stid.sc_status & SC_STATUS_REVOKED) { in nfs4_check_deleg()
5654 nfs4_put_stid(&deleg->dl_stid); in nfs4_check_deleg()
5655 nfsd40_drop_revoked_stid(cl, &open->op_delegate_stateid); in nfs4_check_deleg()
5659 flags = share_access_to_flags(open->op_share_access); in nfs4_check_deleg()
5662 nfs4_put_stid(&deleg->dl_stid); in nfs4_check_deleg()
5671 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; in nfs4_check_deleg()
5697 if (!open->op_truncate) in nfsd4_truncate()
5699 if (!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) in nfsd4_truncate()
5710 int oflag = nfs4_access_to_omode(open->op_share_access); in nfs4_get_vfs_file()
5711 int access = nfs4_access_to_access(open->op_share_access); in nfs4_get_vfs_file()
5714 spin_lock(&fp->fi_lock); in nfs4_get_vfs_file()
5720 status = nfs4_file_check_deny(fp, open->op_share_deny); in nfs4_get_vfs_file()
5723 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5727 stp, open->op_share_deny, false)) in nfs4_get_vfs_file()
5729 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5734 status = nfs4_file_get_access(fp, open->op_share_access); in nfs4_get_vfs_file()
5737 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5741 stp, open->op_share_access, true)) in nfs4_get_vfs_file()
5743 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5748 old_access_bmap = stp->st_access_bmap; in nfs4_get_vfs_file()
5749 set_access(open->op_share_access, stp); in nfs4_get_vfs_file()
5752 old_deny_bmap = stp->st_deny_bmap; in nfs4_get_vfs_file()
5753 set_deny(open->op_share_deny, stp); in nfs4_get_vfs_file()
5754 fp->fi_share_deny |= (open->op_share_deny & NFS4_SHARE_DENY_BOTH); in nfs4_get_vfs_file()
5756 if (!fp->fi_fds[oflag]) { in nfs4_get_vfs_file()
5757 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5760 open->op_filp, &nf); in nfs4_get_vfs_file()
5764 spin_lock(&fp->fi_lock); in nfs4_get_vfs_file()
5765 if (!fp->fi_fds[oflag]) { in nfs4_get_vfs_file()
5766 fp->fi_fds[oflag] = nf; in nfs4_get_vfs_file()
5770 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5774 status = nfserrno(nfsd_open_break_lease(cur_fh->fh_dentry->d_inode, in nfs4_get_vfs_file()
5785 stp->st_access_bmap = old_access_bmap; in nfs4_get_vfs_file()
5786 nfs4_file_put_access(fp, open->op_share_access); in nfs4_get_vfs_file()
5797 unsigned char old_deny_bmap = stp->st_deny_bmap; in nfs4_upgrade_open()
5799 if (!test_access(open->op_share_access, stp)) in nfs4_upgrade_open()
5803 spin_lock(&fp->fi_lock); in nfs4_upgrade_open()
5804 status = nfs4_file_check_deny(fp, open->op_share_deny); in nfs4_upgrade_open()
5807 set_deny(open->op_share_deny, stp); in nfs4_upgrade_open()
5808 fp->fi_share_deny |= in nfs4_upgrade_open()
5809 (open->op_share_deny & NFS4_SHARE_DENY_BOTH); in nfs4_upgrade_open()
5813 stp, open->op_share_deny, false)) in nfs4_upgrade_open()
5817 spin_unlock(&fp->fi_lock); in nfs4_upgrade_open()
5831 if (clp->cl_cb_state == NFSD4_CB_UP) in nfsd4_cb_channel_good()
5838 return clp->cl_minorversion && clp->cl_cb_state == NFSD4_CB_UNKNOWN; in nfsd4_cb_channel_good()
5848 fl->fl_lmops = &nfsd_lease_mng_ops; in nfs4_alloc_init_lease()
5849 fl->c.flc_flags = FL_DELEG; in nfs4_alloc_init_lease()
5850 fl->c.flc_type = deleg_is_read(dp->dl_type) ? F_RDLCK : F_WRLCK; in nfs4_alloc_init_lease()
5851 fl->c.flc_owner = (fl_owner_t)dp; in nfs4_alloc_init_lease()
5852 fl->c.flc_pid = current->tgid; in nfs4_alloc_init_lease()
5853 fl->c.flc_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file; in nfs4_alloc_init_lease()
5861 struct file *f = fp->fi_deleg_file->nf_file; in nfsd4_check_conflicting_opens()
5865 writes = atomic_read(&ino->i_writecount); in nfsd4_check_conflicting_opens()
5875 if (fp->fi_aliased) in nfsd4_check_conflicting_opens()
5876 return -EAGAIN; in nfsd4_check_conflicting_opens()
5884 if (fp->fi_fds[O_WRONLY]) in nfsd4_check_conflicting_opens()
5885 writes--; in nfsd4_check_conflicting_opens()
5886 if (fp->fi_fds[O_RDWR]) in nfsd4_check_conflicting_opens()
5887 writes--; in nfsd4_check_conflicting_opens()
5889 return -EAGAIN; /* There may be non-NFSv4 writers */ in nfsd4_check_conflicting_opens()
5891 * It's possible there are non-NFSv4 write opens in progress, in nfsd4_check_conflicting_opens()
5897 spin_lock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5898 list_for_each_entry(st, &fp->fi_stateids, st_perfile) { in nfsd4_check_conflicting_opens()
5899 if (st->st_openstp == NULL /* it's an open */ && in nfsd4_check_conflicting_opens()
5901 st->st_stid.sc_client != clp) { in nfsd4_check_conflicting_opens()
5902 spin_unlock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5903 return -EAGAIN; in nfsd4_check_conflicting_opens()
5906 spin_unlock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5929 err = nfsd_lookup_dentry(open->op_rqstp, parent, in nfsd4_verify_deleg_dentry()
5930 open->op_fname, open->op_fnamelen, in nfsd4_verify_deleg_dentry()
5934 return -EAGAIN; in nfsd4_verify_deleg_dentry()
5938 if (child != file_dentry(fp->fi_deleg_file->nf_file)) in nfsd4_verify_deleg_dentry()
5939 return -EAGAIN; in nfsd4_verify_deleg_dentry()
5953 struct inode *inode = file_inode(nf->nf_file); in nfsd4_verify_setuid_write()
5955 if ((open->op_share_access & NFS4_SHARE_ACCESS_WRITE) && in nfsd4_verify_setuid_write()
5956 (inode->i_mode & (S_ISUID|S_ISGID))) in nfsd4_verify_setuid_write()
5957 return -EAGAIN; in nfsd4_verify_setuid_write()
5964 return open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS; in nfsd4_want_deleg_timestamps()
5978 struct nfs4_client *clp = stp->st_stid.sc_client; in nfs4_set_delegation()
5979 struct nfs4_file *fp = stp->st_stid.sc_file; in nfs4_set_delegation()
5980 struct nfs4_clnt_odstate *odstate = stp->st_clnt_odstate; in nfs4_set_delegation()
5992 if (fp->fi_had_conflict) in nfs4_set_delegation()
5993 return ERR_PTR(-EAGAIN); in nfs4_set_delegation()
6007 if ((open->op_share_access & NFS4_SHARE_ACCESS_BOTH) == NFS4_SHARE_ACCESS_BOTH) { in nfs4_set_delegation()
6016 if (!nf && (open->op_share_access & NFS4_SHARE_ACCESS_READ)) { in nfs4_set_delegation()
6022 return ERR_PTR(-EAGAIN); in nfs4_set_delegation()
6025 spin_lock(&fp->fi_lock); in nfs4_set_delegation()
6027 status = -EAGAIN; in nfs4_set_delegation()
6029 status = -EAGAIN; in nfs4_set_delegation()
6030 else if (!fp->fi_deleg_file) { in nfs4_set_delegation()
6031 fp->fi_deleg_file = nf; in nfs4_set_delegation()
6034 fp->fi_delegees = 1; in nfs4_set_delegation()
6037 fp->fi_delegees++; in nfs4_set_delegation()
6038 spin_unlock(&fp->fi_lock); in nfs4_set_delegation()
6045 status = -ENOMEM; in nfs4_set_delegation()
6054 status = kernel_setlease(fp->fi_deleg_file->nf_file, in nfs4_set_delegation()
6055 fl->c.flc_type, &fl, NULL); in nfs4_set_delegation()
6075 status = nfsd4_verify_setuid_write(open, fp->fi_deleg_file); in nfs4_set_delegation()
6079 status = -EAGAIN; in nfs4_set_delegation()
6080 if (fp->fi_had_conflict) in nfs4_set_delegation()
6084 spin_lock(&clp->cl_lock); in nfs4_set_delegation()
6085 spin_lock(&fp->fi_lock); in nfs4_set_delegation()
6087 spin_unlock(&fp->fi_lock); in nfs4_set_delegation()
6088 spin_unlock(&clp->cl_lock); in nfs4_set_delegation()
6096 kernel_setlease(fp->fi_deleg_file->nf_file, F_UNLCK, NULL, (void **)&dp); in nfs4_set_delegation()
6098 put_clnt_odstate(dp->dl_clnt_odstate); in nfs4_set_delegation()
6099 nfs4_put_stid(&dp->dl_stid); in nfs4_set_delegation()
6107 open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; in nfsd4_open_deleg_none_ext()
6108 if (status == -EAGAIN) in nfsd4_open_deleg_none_ext()
6109 open->op_why_no_deleg = WND4_CONTENTION; in nfsd4_open_deleg_none_ext()
6111 open->op_why_no_deleg = WND4_RESOURCE; in nfsd4_open_deleg_none_ext()
6112 switch (open->op_deleg_want) { in nfsd4_open_deleg_none_ext()
6118 open->op_why_no_deleg = WND4_CANCELLED; in nfsd4_open_deleg_none_ext()
6130 struct nfsd_file *nf = find_rw_file(dp->dl_stid.sc_file); in nfs4_delegation_stat()
6137 path.mnt = currentfh->fh_export->ex_path.mnt; in nfs4_delegation_stat()
6138 path.dentry = file_dentry(nf->nf_file); in nfs4_delegation_stat()
6176 struct nfs4_openowner *oo = openowner(stp->st_stateowner); in nfs4_open_delegation()
6178 struct nfs4_client *clp = stp->st_stid.sc_client; in nfs4_open_delegation()
6185 cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client); in nfs4_open_delegation()
6186 open->op_recall = false; in nfs4_open_delegation()
6187 switch (open->op_claim_type) { in nfs4_open_delegation()
6190 open->op_recall = true; in nfs4_open_delegation()
6201 if (locks_in_grace(clp->net)) in nfs4_open_delegation()
6203 if (!cb_up || !(oo->oo_flags & NFS4_OO_CONFIRMED)) in nfs4_open_delegation()
6205 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE && in nfs4_open_delegation()
6206 !clp->cl_minorversion) in nfs4_open_delegation()
6216 memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid)); in nfs4_open_delegation()
6218 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) { in nfs4_open_delegation()
6220 nfs4_put_stid(&dp->dl_stid); in nfs4_open_delegation()
6224 open->op_delegate_type = deleg_ts ? OPEN_DELEGATE_WRITE_ATTRS_DELEG : in nfs4_open_delegation()
6226 dp->dl_cb_fattr.ncf_cur_fsize = stat.size; in nfs4_open_delegation()
6227 dp->dl_cb_fattr.ncf_initial_cinfo = nfsd4_change_attribute(&stat); in nfs4_open_delegation()
6228 trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); in nfs4_open_delegation()
6230 open->op_delegate_type = deleg_ts ? OPEN_DELEGATE_READ_ATTRS_DELEG : in nfs4_open_delegation()
6232 trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid); in nfs4_open_delegation()
6234 nfs4_put_stid(&dp->dl_stid); in nfs4_open_delegation()
6237 open->op_delegate_type = OPEN_DELEGATE_NONE; in nfs4_open_delegation()
6238 if (open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS && in nfs4_open_delegation()
6239 open->op_delegate_type != OPEN_DELEGATE_NONE) { in nfs4_open_delegation()
6241 open->op_recall = true; in nfs4_open_delegation()
6245 if (open->op_deleg_want) in nfs4_open_delegation()
6253 if (deleg_is_write(dp->dl_type)) { in nfsd4_deleg_xgrade_none_ext()
6254 if (open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_READ_DELEG) { in nfsd4_deleg_xgrade_none_ext()
6255 open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; in nfsd4_deleg_xgrade_none_ext()
6256 open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE; in nfsd4_deleg_xgrade_none_ext()
6257 } else if (open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_WRITE_DELEG) { in nfsd4_deleg_xgrade_none_ext()
6258 open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; in nfsd4_deleg_xgrade_none_ext()
6259 open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE; in nfsd4_deleg_xgrade_none_ext()
6271 if (!(open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION)) in open_xor_delegation()
6274 if (!deleg_is_read(open->op_delegate_type) && !deleg_is_write(open->op_delegate_type)) in open_xor_delegation()
6280 * nfsd4_process_open2 - finish open processing
6285 * If successful, (1) truncate the file if open->op_truncate was
6286 * set, (2) set open->op_stateid, (3) set open->op_delegation.
6294 struct nfsd4_compoundres *resp = rqstp->rq_resp; in nfsd4_process_open2()
6295 struct nfs4_client *cl = open->op_openowner->oo_owner.so_client; in nfsd4_process_open2()
6307 fp = nfsd4_file_hash_insert(open->op_file, current_fh); in nfsd4_process_open2()
6310 if (fp != open->op_file) { in nfsd4_process_open2()
6316 open->op_file = NULL; in nfsd4_process_open2()
6329 if (!open->op_stp) in nfsd4_process_open2()
6343 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
6350 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
6354 stp->st_clnt_odstate = find_or_hash_clnt_odstate(fp, in nfsd4_process_open2()
6355 open->op_odstate); in nfsd4_process_open2()
6356 if (stp->st_clnt_odstate == open->op_odstate) in nfsd4_process_open2()
6357 open->op_odstate = NULL; in nfsd4_process_open2()
6360 nfs4_inc_and_copy_stateid(&open->op_stateid, &stp->st_stid); in nfsd4_process_open2()
6361 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
6363 if (nfsd4_has_session(&resp->cstate)) { in nfsd4_process_open2()
6364 if (open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_NO_DELEG) { in nfsd4_process_open2()
6365 open->op_delegate_type = OPEN_DELEGATE_NONE_EXT; in nfsd4_process_open2()
6366 open->op_why_no_deleg = WND4_NOT_WANTED; in nfsd4_process_open2()
6375 nfs4_open_delegation(open, stp, &resp->cstate.current_fh); in nfsd4_process_open2()
6383 memcpy(&open->op_stateid, &zero_stateid, sizeof(open->op_stateid)); in nfsd4_process_open2()
6384 open->op_rflags |= OPEN4_RESULT_NO_OPEN_STATEID; in nfsd4_process_open2()
6389 trace_nfsd_open(&stp->st_stid.sc_stateid); in nfsd4_process_open2()
6392 if (open->op_delegate_type == OPEN_DELEGATE_NONE && dp && in nfsd4_process_open2()
6393 open->op_deleg_want) in nfsd4_process_open2()
6398 if (status == 0 && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) in nfsd4_process_open2()
6399 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; in nfsd4_process_open2()
6403 open->op_rflags |= NFS4_OPEN_RESULT_LOCKTYPE_POSIX; in nfsd4_process_open2()
6404 if (nfsd4_has_session(&resp->cstate)) in nfsd4_process_open2()
6405 open->op_rflags |= NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK; in nfsd4_process_open2()
6406 else if (!(open->op_openowner->oo_flags & NFS4_OO_CONFIRMED)) in nfsd4_process_open2()
6407 open->op_rflags |= NFS4_OPEN_RESULT_CONFIRM; in nfsd4_process_open2()
6410 nfs4_put_stid(&dp->dl_stid); in nfsd4_process_open2()
6412 nfs4_put_stid(&stp->st_stid); in nfsd4_process_open2()
6420 if (open->op_openowner) in nfsd4_cleanup_open_state()
6421 nfs4_put_stateowner(&open->op_openowner->oo_owner); in nfsd4_cleanup_open_state()
6422 if (open->op_file) in nfsd4_cleanup_open_state()
6423 kmem_cache_free(file_slab, open->op_file); in nfsd4_cleanup_open_state()
6424 if (open->op_stp) in nfsd4_cleanup_open_state()
6425 nfs4_put_stid(&open->op_stp->st_stid); in nfsd4_cleanup_open_state()
6426 if (open->op_odstate) in nfsd4_cleanup_open_state()
6427 kmem_cache_free(odstate_slab, open->op_odstate); in nfsd4_cleanup_open_state()
6434 clientid_t *clid = &u->renew; in nfsd4_renew()
6443 clp = cstate->clp; in nfsd4_renew()
6444 if (!list_empty(&clp->cl_delegations) in nfsd4_renew()
6445 && clp->cl_cb_state != NFSD4_CB_UP) in nfsd4_renew()
6454 if (nn->grace_ended) in nfsd4_end_grace()
6458 nn->grace_ended = true; in nfsd4_end_grace()
6475 locks_end_grace(&nn->nfsd4_manager); in nfsd4_end_grace()
6489 time64_t double_grace_period_end = nn->boot_time + in clients_still_reclaiming()
6490 2 * nn->nfsd4_lease; in clients_still_reclaiming()
6492 if (nn->track_reclaim_completes && in clients_still_reclaiming()
6493 atomic_read(&nn->nr_reclaim_complete) == in clients_still_reclaiming()
6494 nn->reclaim_str_hashtbl_size) in clients_still_reclaiming()
6496 if (!nn->somebody_reclaimed) in clients_still_reclaiming()
6498 nn->somebody_reclaimed = false; in clients_still_reclaiming()
6517 if (last_refresh < lt->cutoff) in state_expired()
6519 time_remaining = last_refresh - lt->cutoff; in state_expired()
6520 lt->new_timeo = min(lt->new_timeo, time_remaining); in state_expired()
6527 spin_lock_init(&nn->nfsd_ssc_lock); in nfsd4_ssc_init_umount_work()
6528 INIT_LIST_HEAD(&nn->nfsd_ssc_mount_list); in nfsd4_ssc_init_umount_work()
6529 init_waitqueue_head(&nn->nfsd_ssc_waitq); in nfsd4_ssc_init_umount_work()
6541 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
6542 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { in nfsd4_ssc_shutdown_umount()
6543 list_del(&ni->nsui_list); in nfsd4_ssc_shutdown_umount()
6544 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
6545 mntput(ni->nsui_vfsmount); in nfsd4_ssc_shutdown_umount()
6547 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
6549 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
6558 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
6559 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { in nfsd4_ssc_expire_umount()
6560 if (time_after(jiffies, ni->nsui_expire)) { in nfsd4_ssc_expire_umount()
6561 if (refcount_read(&ni->nsui_refcnt) > 1) in nfsd4_ssc_expire_umount()
6565 ni->nsui_busy = true; in nfsd4_ssc_expire_umount()
6566 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
6567 mntput(ni->nsui_vfsmount); in nfsd4_ssc_expire_umount()
6568 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
6571 list_del(&ni->nsui_list); in nfsd4_ssc_expire_umount()
6581 wake_up_all(&nn->nfsd_ssc_waitq); in nfsd4_ssc_expire_umount()
6582 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
6594 list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) { in nfs4_lockowner_has_blockers()
6595 nf = stp->st_stid.sc_file; in nfs4_lockowner_has_blockers()
6596 ctx = locks_inode_context(nf->fi_inode); in nfs4_lockowner_has_blockers()
6612 if (atomic_read(&clp->cl_delegs_in_recall)) in nfs4_anylock_blockers()
6614 spin_lock(&clp->cl_lock); in nfs4_anylock_blockers()
6616 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[i], in nfs4_anylock_blockers()
6618 if (so->so_is_open_owner) in nfs4_anylock_blockers()
6622 spin_unlock(&clp->cl_lock); in nfs4_anylock_blockers()
6627 spin_unlock(&clp->cl_lock); in nfs4_anylock_blockers()
6639 maxreap = (atomic_read(&nn->nfs4_client_count) >= nn->nfs4_max_clients) ? in nfs4_get_client_reaplist()
6642 spin_lock(&nn->client_lock); in nfs4_get_client_reaplist()
6643 list_for_each_safe(pos, next, &nn->client_lru) { in nfs4_get_client_reaplist()
6645 if (clp->cl_state == NFSD4_EXPIRABLE) in nfs4_get_client_reaplist()
6647 if (!state_expired(lt, clp->cl_time)) in nfs4_get_client_reaplist()
6649 if (!atomic_read(&clp->cl_rpc_users)) { in nfs4_get_client_reaplist()
6650 if (clp->cl_state == NFSD4_ACTIVE) in nfs4_get_client_reaplist()
6651 atomic_inc(&nn->nfsd_courtesy_clients); in nfs4_get_client_reaplist()
6652 clp->cl_state = NFSD4_COURTESY; in nfs4_get_client_reaplist()
6661 list_add(&clp->cl_lru, reaplist); in nfs4_get_client_reaplist()
6665 spin_unlock(&nn->client_lock); in nfs4_get_client_reaplist()
6679 spin_lock(&nn->client_lock); in nfs4_get_courtesy_client_reaplist()
6680 list_for_each_safe(pos, next, &nn->client_lru) { in nfs4_get_courtesy_client_reaplist()
6682 if (clp->cl_state == NFSD4_ACTIVE) in nfs4_get_courtesy_client_reaplist()
6687 list_add(&clp->cl_lru, reaplist); in nfs4_get_courtesy_client_reaplist()
6691 spin_unlock(&nn->client_lock); in nfs4_get_courtesy_client_reaplist()
6702 trace_nfsd_clid_purged(&clp->cl_clientid); in nfs4_process_client_reaplist()
6703 list_del_init(&clp->cl_lru); in nfs4_process_client_reaplist()
6713 spin_lock(&nn->client_lock); in nfs40_clean_admin_revoked()
6714 if (nn->nfs40_last_revoke == 0 || in nfs40_clean_admin_revoked()
6715 nn->nfs40_last_revoke > lt->cutoff) { in nfs40_clean_admin_revoked()
6716 spin_unlock(&nn->client_lock); in nfs40_clean_admin_revoked()
6719 nn->nfs40_last_revoke = 0; in nfs40_clean_admin_revoked()
6722 list_for_each_entry(clp, &nn->client_lru, cl_lru) { in nfs40_clean_admin_revoked()
6726 if (atomic_read(&clp->cl_admin_revoked) == 0) in nfs40_clean_admin_revoked()
6729 spin_lock(&clp->cl_lock); in nfs40_clean_admin_revoked()
6730 idr_for_each_entry_ul(&clp->cl_stateids, stid, tmp, id) in nfs40_clean_admin_revoked()
6731 if (stid->sc_status & SC_STATUS_ADMIN_REVOKED) { in nfs40_clean_admin_revoked()
6732 refcount_inc(&stid->sc_count); in nfs40_clean_admin_revoked()
6733 spin_unlock(&nn->client_lock); in nfs40_clean_admin_revoked()
6734 /* this function drops ->cl_lock */ in nfs40_clean_admin_revoked()
6737 spin_lock(&nn->client_lock); in nfs40_clean_admin_revoked()
6740 spin_unlock(&clp->cl_lock); in nfs40_clean_admin_revoked()
6742 spin_unlock(&nn->client_lock); in nfs40_clean_admin_revoked()
6754 .cutoff = ktime_get_boottime_seconds() - nn->nfsd4_lease, in nfs4_laundromat()
6755 .new_timeo = nn->nfsd4_lease in nfs4_laundromat()
6767 spin_lock(&nn->s2s_cp_lock); in nfs4_laundromat()
6768 idr_for_each_entry(&nn->s2s_cp_stateids, cps_t, i) { in nfs4_laundromat()
6770 if (cps->cp_stateid.cs_type == NFS4_COPYNOTIFY_STID && in nfs4_laundromat()
6771 state_expired(&lt, cps->cpntf_time)) in nfs4_laundromat()
6774 spin_unlock(&nn->s2s_cp_lock); in nfs4_laundromat()
6782 list_for_each_safe(pos, next, &nn->del_recall_lru) { in nfs4_laundromat()
6784 if (!state_expired(&lt, dp->dl_time)) in nfs4_laundromat()
6786 refcount_inc(&dp->dl_stid.sc_count); in nfs4_laundromat()
6788 list_add(&dp->dl_recall_lru, &reaplist); in nfs4_laundromat()
6794 list_del_init(&dp->dl_recall_lru); in nfs4_laundromat()
6798 spin_lock(&nn->client_lock); in nfs4_laundromat()
6799 while (!list_empty(&nn->close_lru)) { in nfs4_laundromat()
6800 oo = list_first_entry(&nn->close_lru, struct nfs4_openowner, in nfs4_laundromat()
6802 if (!state_expired(&lt, oo->oo_time)) in nfs4_laundromat()
6804 list_del_init(&oo->oo_close_lru); in nfs4_laundromat()
6805 stp = oo->oo_last_closed_stid; in nfs4_laundromat()
6806 oo->oo_last_closed_stid = NULL; in nfs4_laundromat()
6807 spin_unlock(&nn->client_lock); in nfs4_laundromat()
6808 nfs4_put_stid(&stp->st_stid); in nfs4_laundromat()
6809 spin_lock(&nn->client_lock); in nfs4_laundromat()
6811 spin_unlock(&nn->client_lock); in nfs4_laundromat()
6816 * So, we clean out any un-revisited request after a lease period in nfs4_laundromat()
6825 spin_lock(&nn->blocked_locks_lock); in nfs4_laundromat()
6826 while (!list_empty(&nn->blocked_locks_lru)) { in nfs4_laundromat()
6827 nbl = list_first_entry(&nn->blocked_locks_lru, in nfs4_laundromat()
6829 if (!state_expired(&lt, nbl->nbl_time)) in nfs4_laundromat()
6831 list_move(&nbl->nbl_lru, &reaplist); in nfs4_laundromat()
6832 list_del_init(&nbl->nbl_list); in nfs4_laundromat()
6834 spin_unlock(&nn->blocked_locks_lock); in nfs4_laundromat()
6839 list_del_init(&nbl->nbl_lru); in nfs4_laundromat()
6843 /* service the server-to-server copy delayed unmount list */ in nfs4_laundromat()
6863 queue_delayed_work(laundry_wq, &nn->laundromat_work, t*HZ); in laundromat_main()
6882 spin_lock(&nn->client_lock); in deleg_reaper()
6883 list_for_each_safe(pos, next, &nn->client_lru) { in deleg_reaper()
6886 if (clp->cl_state != NFSD4_ACTIVE) in deleg_reaper()
6888 if (list_empty(&clp->cl_delegations)) in deleg_reaper()
6890 if (atomic_read(&clp->cl_delegs_in_recall)) in deleg_reaper()
6892 if (test_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags)) in deleg_reaper()
6894 if (ktime_get_boottime_seconds() - clp->cl_ra_time < 5) in deleg_reaper()
6896 if (clp->cl_cb_state != NFSD4_CB_UP) in deleg_reaper()
6898 list_add(&clp->cl_ra_cblist, &cblist); in deleg_reaper()
6901 kref_get(&clp->cl_nfsdfs.cl_ref); in deleg_reaper()
6902 set_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags); in deleg_reaper()
6903 clp->cl_ra_time = ktime_get_boottime_seconds(); in deleg_reaper()
6905 spin_unlock(&nn->client_lock); in deleg_reaper()
6910 list_del_init(&clp->cl_ra_cblist); in deleg_reaper()
6911 clp->cl_ra->ra_keep = 0; in deleg_reaper()
6912 clp->cl_ra->ra_bmval[0] = BIT(RCA4_TYPE_MASK_RDATA_DLG) | in deleg_reaper()
6914 trace_nfsd_cb_recall_any(clp->cl_ra); in deleg_reaper()
6915 nfsd4_run_cb(&clp->cl_ra->ra_cb); in deleg_reaper()
6931 if (!fh_match(&fhp->fh_handle, &stp->sc_file->fi_fhandle)) in nfs4_check_fh()
6942 if (stp->st_openstp) in nfs4_check_openmode()
6943 stp = stp->st_openstp; in nfs4_check_openmode()
6976 if (has_session && in->si_generation == 0) in check_stateid_generation()
6979 if (in->si_generation == ref->si_generation) in check_stateid_generation()
6987 * non-buggy client. For example, if the client sends a lock in check_stateid_generation()
7002 spin_lock(&s->sc_lock); in nfsd4_stid_check_stateid_generation()
7005 ret = check_stateid_generation(in, &s->sc_stateid, has_session); in nfsd4_stid_check_stateid_generation()
7006 spin_unlock(&s->sc_lock); in nfsd4_stid_check_stateid_generation()
7008 nfsd40_drop_revoked_stid(s->sc_client, in nfsd4_stid_check_stateid_generation()
7009 &s->sc_stateid); in nfsd4_stid_check_stateid_generation()
7015 if (ols->st_stateowner->so_is_open_owner && in nfsd4_check_openowner_confirmed()
7016 !(openowner(ols->st_stateowner)->oo_flags & NFS4_OO_CONFIRMED)) in nfsd4_check_openowner_confirmed()
7029 spin_lock(&cl->cl_lock); in nfsd4_validate_stateid()
7040 switch (s->sc_type) { in nfsd4_validate_stateid()
7049 printk("unknown stateid type %x\n", s->sc_type); in nfsd4_validate_stateid()
7053 spin_unlock(&cl->cl_lock); in nfsd4_validate_stateid()
7086 status = set_client(&stateid->si_opaque.so_clid, cstate, nn); in nfsd4_lookup_stateid()
7088 if (cstate->session) in nfsd4_lookup_stateid()
7094 stid = find_stateid_by_type(cstate->clp, stateid, typemask, statusmask); in nfsd4_lookup_stateid()
7097 if ((stid->sc_status & SC_STATUS_REVOKED) && !return_revoked) { in nfsd4_lookup_stateid()
7101 if (stid->sc_status & SC_STATUS_ADMIN_REVOKED) { in nfsd4_lookup_stateid()
7102 nfsd40_drop_revoked_stid(cstate->clp, stateid); in nfsd4_lookup_stateid()
7115 if (!s || s->sc_status) in nfs4_find_file()
7118 switch (s->sc_type) { in nfs4_find_file()
7120 spin_lock(&s->sc_file->fi_lock); in nfs4_find_file()
7121 ret = nfsd_file_get(s->sc_file->fi_deleg_file); in nfs4_find_file()
7122 spin_unlock(&s->sc_file->fi_lock); in nfs4_find_file()
7127 ret = find_readable_file(s->sc_file); in nfs4_find_file()
7129 ret = find_writeable_file(s->sc_file); in nfs4_find_file()
7156 status = nfsd_permission(&rqstp->rq_cred, in nfs4_check_file()
7157 fhp->fh_export, fhp->fh_dentry, in nfs4_check_file()
7175 WARN_ON_ONCE(cps->cp_stateid.cs_type != NFS4_COPYNOTIFY_STID); in _free_cpntf_state_locked()
7176 if (!refcount_dec_and_test(&cps->cp_stateid.cs_count)) in _free_cpntf_state_locked()
7178 list_del(&cps->cp_list); in _free_cpntf_state_locked()
7179 idr_remove(&nn->s2s_cp_stateids, in _free_cpntf_state_locked()
7180 cps->cp_stateid.cs_stid.si_opaque.so_id); in _free_cpntf_state_locked()
7195 if (st->si_opaque.so_clid.cl_id != nn->s2s_cp_cl_id) in manage_cpntf_state()
7197 spin_lock(&nn->s2s_cp_lock); in manage_cpntf_state()
7198 cps_t = idr_find(&nn->s2s_cp_stateids, st->si_opaque.so_id); in manage_cpntf_state()
7202 if (state->cp_stateid.cs_type != NFS4_COPYNOTIFY_STID) { in manage_cpntf_state()
7207 refcount_inc(&state->cp_stateid.cs_count); in manage_cpntf_state()
7212 spin_unlock(&nn->s2s_cp_lock); in manage_cpntf_state()
7231 cps->cpntf_time = ktime_get_boottime_seconds(); in find_cpntf_state()
7234 found = lookup_clientid(&cps->cp_p_clid, true, nn); in find_cpntf_state()
7238 *stid = find_stateid_by_type(found, &cps->cp_p_stateid, in find_cpntf_state()
7254 spin_lock(&nn->s2s_cp_lock); in nfs4_put_cpntf_state()
7256 spin_unlock(&nn->s2s_cp_lock); in nfs4_put_cpntf_state()
7260 * nfs4_preprocess_stateid_op - find and prep stateid for an operation
7304 switch (s->sc_type) { in nfs4_preprocess_stateid_op()
7337 struct nfsd4_test_stateid *test_stateid = &u->test_stateid; in nfsd4_test_stateid()
7339 struct nfs4_client *cl = cstate->clp; in nfsd4_test_stateid()
7341 list_for_each_entry(stateid, &test_stateid->ts_stateid_list, ts_id_list) in nfsd4_test_stateid()
7342 stateid->ts_id_status = in nfsd4_test_stateid()
7343 nfsd4_validate_stateid(cl, &stateid->ts_id_stateid); in nfsd4_test_stateid()
7358 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); in nfsd4_free_lock_stateid()
7363 if (check_for_locks(stp->st_stid.sc_file, in nfsd4_free_lock_stateid()
7364 lockowner(stp->st_stateowner))) in nfsd4_free_lock_stateid()
7371 mutex_unlock(&stp->st_mutex); in nfsd4_free_lock_stateid()
7381 struct nfsd4_free_stateid *free_stateid = &u->free_stateid; in nfsd4_free_stateid()
7382 stateid_t *stateid = &free_stateid->fr_stateid; in nfsd4_free_stateid()
7385 struct nfs4_client *cl = cstate->clp; in nfsd4_free_stateid()
7388 spin_lock(&cl->cl_lock); in nfsd4_free_stateid()
7390 if (!s || s->sc_status & SC_STATUS_CLOSED) in nfsd4_free_stateid()
7392 if (s->sc_status & SC_STATUS_ADMIN_REVOKED) { in nfsd4_free_stateid()
7397 spin_lock(&s->sc_lock); in nfsd4_free_stateid()
7398 switch (s->sc_type) { in nfsd4_free_stateid()
7400 if (s->sc_status & SC_STATUS_REVOKED) { in nfsd4_free_stateid()
7401 s->sc_status |= SC_STATUS_CLOSED; in nfsd4_free_stateid()
7402 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
7404 if (s->sc_status & SC_STATUS_FREEABLE) in nfsd4_free_stateid()
7405 list_del_init(&dp->dl_recall_lru); in nfsd4_free_stateid()
7406 s->sc_status |= SC_STATUS_FREED; in nfsd4_free_stateid()
7407 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
7415 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); in nfsd4_free_stateid()
7421 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
7422 refcount_inc(&s->sc_count); in nfsd4_free_stateid()
7423 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
7427 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
7429 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
7443 struct svc_fh *current_fh = &cstate->current_fh; in nfs4_seqid_op_checks()
7444 struct nfs4_stateowner *sop = stp->st_stateowner; in nfs4_seqid_op_checks()
7453 status = check_stateid_generation(stateid, &stp->st_stid.sc_stateid, nfsd4_has_session(cstate)); in nfs4_seqid_op_checks()
7455 status = nfs4_check_fh(current_fh, &stp->st_stid); in nfs4_seqid_op_checks()
7457 mutex_unlock(&stp->st_mutex); in nfs4_seqid_op_checks()
7462 * nfs4_preprocess_seqid_op - find and prep an ol_stateid for a seqid-morphing op
7495 if (nfsd4_cstate_assign_replay(cstate, stp->st_stateowner) == -EAGAIN) { in nfs4_preprocess_seqid_op()
7496 nfs4_put_stateowner(stp->st_stateowner); in nfs4_preprocess_seqid_op()
7504 nfs4_put_stid(&stp->st_stid); in nfs4_preprocess_seqid_op()
7519 oo = openowner(stp->st_stateowner); in nfs4_preprocess_confirmed_seqid_op()
7520 if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { in nfs4_preprocess_confirmed_seqid_op()
7521 mutex_unlock(&stp->st_mutex); in nfs4_preprocess_confirmed_seqid_op()
7522 nfs4_put_stid(&stp->st_stid); in nfs4_preprocess_confirmed_seqid_op()
7533 struct nfsd4_open_confirm *oc = &u->open_confirm; in nfsd4_open_confirm()
7540 cstate->current_fh.fh_dentry); in nfsd4_open_confirm()
7542 status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0); in nfsd4_open_confirm()
7547 oc->oc_seqid, &oc->oc_req_stateid, in nfsd4_open_confirm()
7551 oo = openowner(stp->st_stateowner); in nfsd4_open_confirm()
7553 if (oo->oo_flags & NFS4_OO_CONFIRMED) { in nfsd4_open_confirm()
7554 mutex_unlock(&stp->st_mutex); in nfsd4_open_confirm()
7557 oo->oo_flags |= NFS4_OO_CONFIRMED; in nfsd4_open_confirm()
7558 nfs4_inc_and_copy_stateid(&oc->oc_resp_stateid, &stp->st_stid); in nfsd4_open_confirm()
7559 mutex_unlock(&stp->st_mutex); in nfsd4_open_confirm()
7560 trace_nfsd_open_confirm(oc->oc_seqid, &stp->st_stid.sc_stateid); in nfsd4_open_confirm()
7561 nfsd4_client_record_create(oo->oo_owner.so_client); in nfsd4_open_confirm()
7564 nfs4_put_stid(&stp->st_stid); in nfsd4_open_confirm()
7574 nfs4_file_put_access(stp->st_stid.sc_file, access); in nfs4_stateid_downgrade_bit()
7600 struct nfsd4_open_downgrade *od = &u->open_downgrade; in nfsd4_open_downgrade()
7606 cstate->current_fh.fh_dentry); in nfsd4_open_downgrade()
7609 if (od->od_deleg_want) in nfsd4_open_downgrade()
7611 od->od_deleg_want); in nfsd4_open_downgrade()
7613 status = nfs4_preprocess_confirmed_seqid_op(cstate, od->od_seqid, in nfsd4_open_downgrade()
7614 &od->od_stateid, &stp, nn); in nfsd4_open_downgrade()
7618 if (!test_access(od->od_share_access, stp)) { in nfsd4_open_downgrade()
7620 stp->st_access_bmap, od->od_share_access); in nfsd4_open_downgrade()
7623 if (!test_deny(od->od_share_deny, stp)) { in nfsd4_open_downgrade()
7625 stp->st_deny_bmap, od->od_share_deny); in nfsd4_open_downgrade()
7628 nfs4_stateid_downgrade(stp, od->od_share_access); in nfsd4_open_downgrade()
7629 reset_union_bmap_deny(od->od_share_deny, stp); in nfsd4_open_downgrade()
7630 nfs4_inc_and_copy_stateid(&od->od_stateid, &stp->st_stid); in nfsd4_open_downgrade()
7633 mutex_unlock(&stp->st_mutex); in nfsd4_open_downgrade()
7634 nfs4_put_stid(&stp->st_stid); in nfsd4_open_downgrade()
7642 struct nfs4_client *clp = s->st_stid.sc_client; in nfsd4_close_open_stateid()
7647 spin_lock(&clp->cl_lock); in nfsd4_close_open_stateid()
7650 if (clp->cl_minorversion) { in nfsd4_close_open_stateid()
7653 spin_unlock(&clp->cl_lock); in nfsd4_close_open_stateid()
7655 nfs4_free_cpntf_statelist(clp->net, &stp->st_stid); in nfsd4_close_open_stateid()
7659 spin_unlock(&clp->cl_lock); in nfsd4_close_open_stateid()
7672 struct nfsd4_close *close = &u->close; in nfsd4_close()
7680 cstate->current_fh.fh_dentry); in nfsd4_close()
7682 status = nfs4_preprocess_seqid_op(cstate, close->cl_seqid, in nfsd4_close()
7683 &close->cl_stateid, in nfsd4_close()
7690 spin_lock(&stp->st_stid.sc_client->cl_lock); in nfsd4_close()
7691 stp->st_stid.sc_status |= SC_STATUS_CLOSED; in nfsd4_close()
7692 spin_unlock(&stp->st_stid.sc_client->cl_lock); in nfsd4_close()
7700 nfs4_inc_and_copy_stateid(&close->cl_stateid, &stp->st_stid); in nfsd4_close()
7703 mutex_unlock(&stp->st_mutex); in nfsd4_close()
7714 memcpy(&close->cl_stateid, &close_stateid, sizeof(close->cl_stateid)); in nfsd4_close()
7717 nfs4_put_stid(&stp->st_stid); in nfsd4_close()
7726 struct nfsd4_delegreturn *dr = &u->delegreturn; in nfsd4_delegreturn()
7728 stateid_t *stateid = &dr->dr_stateid; in nfsd4_delegreturn()
7733 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) in nfsd4_delegreturn()
7740 status = nfsd4_stid_check_stateid_generation(stateid, &dp->dl_stid, nfsd4_has_session(cstate)); in nfsd4_delegreturn()
7747 wake_up_var(d_inode(cstate->current_fh.fh_dentry)); in nfsd4_delegreturn()
7749 nfs4_put_stid(&dp->dl_stid); in nfsd4_delegreturn()
7762 return end > start ? end - 1: NFS4_MAX_UINT64; in last_byte_offset()
7766 * TODO: Linux file offsets are _signed_ 64-bit quantities, which means that
7767 * we can't properly handle lock requests that go beyond the (2^63 - 1)-th
7768 * byte, because of sign extension problems. Since NFSv4 calls for 64-bit
7769 * locking, this prevents us from being completely protocol-compliant. The
7776 if (lock->fl_start < 0) in nfs4_transform_lock_offset()
7777 lock->fl_start = OFFSET_MAX; in nfs4_transform_lock_offset()
7778 if (lock->fl_end < 0) in nfs4_transform_lock_offset()
7779 lock->fl_end = OFFSET_MAX; in nfs4_transform_lock_offset()
7787 nfs4_get_stateowner(&lo->lo_owner); in nfsd4_lm_get_owner()
7797 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_lm_put_owner()
7804 struct nfs4_lockowner *lo = (struct nfs4_lockowner *) cfl->c.flc_owner; in nfsd4_lm_lock_expirable()
7805 struct nfs4_client *clp = lo->lo_owner.so_client; in nfsd4_lm_lock_expirable()
7809 nn = net_generic(clp->net, nfsd_net_id); in nfsd4_lm_lock_expirable()
7810 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in nfsd4_lm_lock_expirable()
7826 struct nfs4_lockowner *lo = (struct nfs4_lockowner *) fl->c.flc_owner; in nfsd4_lm_notify()
7827 struct net *net = lo->lo_owner.so_client->net; in nfsd4_lm_notify()
7834 spin_lock(&nn->blocked_locks_lock); in nfsd4_lm_notify()
7835 if (!list_empty(&nbl->nbl_list)) { in nfsd4_lm_notify()
7836 list_del_init(&nbl->nbl_list); in nfsd4_lm_notify()
7837 list_del_init(&nbl->nbl_lru); in nfsd4_lm_notify()
7840 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lm_notify()
7844 nfsd4_run_cb(&nbl->nbl_cb); in nfsd4_lm_notify()
7862 if (fl->fl_lmops == &nfsd_posix_mng_ops) { in nfs4_set_lock_denied()
7863 lo = (struct nfs4_lockowner *) fl->c.flc_owner; in nfs4_set_lock_denied()
7864 xdr_netobj_dup(&deny->ld_owner, &lo->lo_owner.so_owner, in nfs4_set_lock_denied()
7866 if (!deny->ld_owner.data) in nfs4_set_lock_denied()
7869 deny->ld_clientid = lo->lo_owner.so_client->cl_clientid; in nfs4_set_lock_denied()
7872 deny->ld_owner.len = 0; in nfs4_set_lock_denied()
7873 deny->ld_owner.data = NULL; in nfs4_set_lock_denied()
7874 deny->ld_clientid.cl_boot = 0; in nfs4_set_lock_denied()
7875 deny->ld_clientid.cl_id = 0; in nfs4_set_lock_denied()
7877 deny->ld_start = fl->fl_start; in nfs4_set_lock_denied()
7878 deny->ld_length = NFS4_MAX_UINT64; in nfs4_set_lock_denied()
7879 if (fl->fl_end != NFS4_MAX_UINT64) in nfs4_set_lock_denied()
7880 deny->ld_length = fl->fl_end - fl->fl_start + 1; in nfs4_set_lock_denied()
7881 deny->ld_type = NFS4_READ_LT; in nfs4_set_lock_denied()
7882 if (fl->c.flc_type != F_RDLCK) in nfs4_set_lock_denied()
7883 deny->ld_type = NFS4_WRITE_LT; in nfs4_set_lock_denied()
7892 lockdep_assert_held(&clp->cl_lock); in find_lockowner_str_locked()
7894 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[strhashval], in find_lockowner_str_locked()
7896 if (so->so_is_open_owner) in find_lockowner_str_locked()
7909 spin_lock(&clp->cl_lock); in find_lockowner_str()
7911 spin_unlock(&clp->cl_lock); in find_lockowner_str()
7934 * Called in nfsd4_lock - therefore, OPEN and OPEN_CONFIRM (if needed) has
7946 lo = alloc_stateowner(lockowner_slab, &lock->lk_new_owner, clp); in alloc_init_lock_stateowner()
7949 INIT_LIST_HEAD(&lo->lo_blocked); in alloc_init_lock_stateowner()
7950 INIT_LIST_HEAD(&lo->lo_owner.so_stateids); in alloc_init_lock_stateowner()
7951 lo->lo_owner.so_is_open_owner = 0; in alloc_init_lock_stateowner()
7952 lo->lo_owner.so_seqid = lock->lk_new_lock_seqid; in alloc_init_lock_stateowner()
7953 lo->lo_owner.so_ops = &lockowner_ops; in alloc_init_lock_stateowner()
7954 spin_lock(&clp->cl_lock); in alloc_init_lock_stateowner()
7955 ret = find_lockowner_str_locked(clp, &lock->lk_new_owner); in alloc_init_lock_stateowner()
7957 list_add(&lo->lo_owner.so_strhash, in alloc_init_lock_stateowner()
7958 &clp->cl_ownerstr_hashtbl[strhashval]); in alloc_init_lock_stateowner()
7961 nfs4_free_stateowner(&lo->lo_owner); in alloc_init_lock_stateowner()
7963 spin_unlock(&clp->cl_lock); in alloc_init_lock_stateowner()
7973 lockdep_assert_held(&ost->st_stid.sc_client->cl_lock); in find_lock_stateid()
7975 /* If ost is not hashed, ost->st_locks will not be valid */ in find_lock_stateid()
7977 list_for_each_entry(lst, &ost->st_locks, st_locks) { in find_lock_stateid()
7978 if (lst->st_stateowner == &lo->lo_owner) { in find_lock_stateid()
7979 refcount_inc(&lst->st_stid.sc_count); in find_lock_stateid()
7991 struct nfs4_client *clp = lo->lo_owner.so_client; in init_lock_stateid()
7994 mutex_init(&stp->st_mutex); in init_lock_stateid()
7995 mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX); in init_lock_stateid()
7997 spin_lock(&clp->cl_lock); in init_lock_stateid()
8003 refcount_inc(&stp->st_stid.sc_count); in init_lock_stateid()
8004 stp->st_stid.sc_type = SC_TYPE_LOCK; in init_lock_stateid()
8005 stp->st_stateowner = nfs4_get_stateowner(&lo->lo_owner); in init_lock_stateid()
8007 stp->st_stid.sc_file = fp; in init_lock_stateid()
8008 stp->st_access_bmap = 0; in init_lock_stateid()
8009 stp->st_deny_bmap = open_stp->st_deny_bmap; in init_lock_stateid()
8010 stp->st_openstp = open_stp; in init_lock_stateid()
8011 spin_lock(&fp->fi_lock); in init_lock_stateid()
8012 list_add(&stp->st_locks, &open_stp->st_locks); in init_lock_stateid()
8013 list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids); in init_lock_stateid()
8014 list_add(&stp->st_perfile, &fp->fi_stateids); in init_lock_stateid()
8015 spin_unlock(&fp->fi_lock); in init_lock_stateid()
8016 spin_unlock(&clp->cl_lock); in init_lock_stateid()
8019 spin_unlock(&clp->cl_lock); in init_lock_stateid()
8021 nfs4_put_stid(&retstp->st_stid); in init_lock_stateid()
8025 mutex_unlock(&stp->st_mutex); in init_lock_stateid()
8028 spin_unlock(&clp->cl_lock); in init_lock_stateid()
8029 mutex_unlock(&stp->st_mutex); in init_lock_stateid()
8040 struct nfs4_openowner *oo = openowner(ost->st_stateowner); in find_or_create_lock_stateid()
8041 struct nfs4_client *clp = oo->oo_owner.so_client; in find_or_create_lock_stateid()
8044 spin_lock(&clp->cl_lock); in find_or_create_lock_stateid()
8046 spin_unlock(&clp->cl_lock); in find_or_create_lock_stateid()
8050 nfs4_put_stid(&lst->st_stid); in find_or_create_lock_stateid()
8074 struct nfs4_file *fp = lock_stp->st_stid.sc_file; in get_lock_access()
8076 lockdep_assert_held(&fp->fi_lock); in get_lock_access()
8091 struct nfs4_file *fi = ost->st_stid.sc_file; in lookup_or_create_lock_state()
8092 struct nfs4_openowner *oo = openowner(ost->st_stateowner); in lookup_or_create_lock_state()
8093 struct nfs4_client *cl = oo->oo_owner.so_client; in lookup_or_create_lock_state()
8094 struct inode *inode = d_inode(cstate->current_fh.fh_dentry); in lookup_or_create_lock_state()
8099 lo = find_lockowner_str(cl, &lock->lk_new_owner); in lookup_or_create_lock_state()
8101 strhashval = ownerstr_hashval(&lock->lk_new_owner); in lookup_or_create_lock_state()
8108 if (!cstate->minorversion && in lookup_or_create_lock_state()
8109 lock->lk_new_lock_seqid != lo->lo_owner.so_seqid) in lookup_or_create_lock_state()
8122 nfs4_put_stateowner(&lo->lo_owner); in lookup_or_create_lock_state()
8133 struct nfsd4_lock *lock = &u->lock; in nfsd4_lock()
8153 (long long) lock->lk_offset, in nfsd4_lock()
8154 (long long) lock->lk_length); in nfsd4_lock()
8156 if (check_lock_length(lock->lk_offset, lock->lk_length)) in nfsd4_lock()
8159 status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0); in nfsd4_lock()
8163 if (lock->lk_is_new) { in nfsd4_lock()
8166 memcpy(&lock->lk_new_clientid, in nfsd4_lock()
8167 &cstate->clp->cl_clientid, in nfsd4_lock()
8172 lock->lk_new_open_seqid, in nfsd4_lock()
8173 &lock->lk_new_open_stateid, in nfsd4_lock()
8177 mutex_unlock(&open_stp->st_mutex); in nfsd4_lock()
8178 open_sop = openowner(open_stp->st_stateowner); in nfsd4_lock()
8180 if (!same_clid(&open_sop->oo_owner.so_client->cl_clientid, in nfsd4_lock()
8181 &lock->lk_new_clientid)) in nfsd4_lock()
8187 lock->lk_old_lock_seqid, in nfsd4_lock()
8188 &lock->lk_old_lock_stateid, in nfsd4_lock()
8194 lock_sop = lockowner(lock_stp->st_stateowner); in nfsd4_lock()
8196 lkflg = setlkflg(lock->lk_type); in nfsd4_lock()
8202 if (locks_in_grace(net) && !lock->lk_reclaim) in nfsd4_lock()
8205 if (!locks_in_grace(net) && lock->lk_reclaim) in nfsd4_lock()
8208 if (lock->lk_reclaim) in nfsd4_lock()
8211 fp = lock_stp->st_stid.sc_file; in nfsd4_lock()
8212 switch (lock->lk_type) { in nfsd4_lock()
8216 spin_lock(&fp->fi_lock); in nfsd4_lock()
8220 spin_unlock(&fp->fi_lock); in nfsd4_lock()
8226 spin_lock(&fp->fi_lock); in nfsd4_lock()
8230 spin_unlock(&fp->fi_lock); in nfsd4_lock()
8243 if (lock->lk_type & (NFS4_READW_LT | NFS4_WRITEW_LT) && in nfsd4_lock()
8245 locks_can_async_lock(nf->nf_file->f_op)) in nfsd4_lock()
8248 nbl = find_or_allocate_block(lock_sop, &fp->fi_fhandle, nn); in nfsd4_lock()
8255 file_lock = &nbl->nbl_lock; in nfsd4_lock()
8256 file_lock->c.flc_type = type; in nfsd4_lock()
8257 file_lock->c.flc_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(&lock_sop->lo_owner)); in nfsd4_lock()
8258 file_lock->c.flc_pid = current->tgid; in nfsd4_lock()
8259 file_lock->c.flc_file = nf->nf_file; in nfsd4_lock()
8260 file_lock->c.flc_flags = flags; in nfsd4_lock()
8261 file_lock->fl_lmops = &nfsd_posix_mng_ops; in nfsd4_lock()
8262 file_lock->fl_start = lock->lk_offset; in nfsd4_lock()
8263 file_lock->fl_end = last_byte_offset(lock->lk_offset, lock->lk_length); in nfsd4_lock()
8274 nbl->nbl_time = ktime_get_boottime_seconds(); in nfsd4_lock()
8275 spin_lock(&nn->blocked_locks_lock); in nfsd4_lock()
8276 list_add_tail(&nbl->nbl_list, &lock_sop->lo_blocked); in nfsd4_lock()
8277 list_add_tail(&nbl->nbl_lru, &nn->blocked_locks_lru); in nfsd4_lock()
8278 kref_get(&nbl->nbl_kref); in nfsd4_lock()
8279 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lock()
8282 err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, conflock); in nfsd4_lock()
8285 nfs4_inc_and_copy_stateid(&lock->lk_resp_stateid, &lock_stp->st_stid); in nfsd4_lock()
8287 if (lock->lk_reclaim) in nfsd4_lock()
8288 nn->somebody_reclaimed = true; in nfsd4_lock()
8291 kref_put(&nbl->nbl_kref, free_nbl); in nfsd4_lock()
8294 case -EAGAIN: /* conflock holds conflicting lock */ in nfsd4_lock()
8297 nfs4_set_lock_denied(conflock, &lock->lk_denied); in nfsd4_lock()
8299 case -EDEADLK: in nfsd4_lock()
8311 spin_lock(&nn->blocked_locks_lock); in nfsd4_lock()
8312 if (!list_empty(&nbl->nbl_list) && in nfsd4_lock()
8313 !list_empty(&nbl->nbl_lru)) { in nfsd4_lock()
8314 list_del_init(&nbl->nbl_list); in nfsd4_lock()
8315 list_del_init(&nbl->nbl_lru); in nfsd4_lock()
8316 kref_put(&nbl->nbl_kref, free_nbl); in nfsd4_lock()
8319 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lock()
8327 if (cstate->replay_owner && in nfsd4_lock()
8328 cstate->replay_owner != &lock_sop->lo_owner && in nfsd4_lock()
8330 lock_sop->lo_owner.so_seqid++; in nfsd4_lock()
8333 * If this is a new, never-before-used stateid, and we are in nfsd4_lock()
8339 mutex_unlock(&lock_stp->st_mutex); in nfsd4_lock()
8341 nfs4_put_stid(&lock_stp->st_stid); in nfsd4_lock()
8344 nfs4_put_stid(&open_stp->st_stid); in nfsd4_lock()
8353 struct nfsd4_lock *lock = &u->lock; in nfsd4_lock_release()
8354 struct nfsd4_lock_denied *deny = &lock->lk_denied; in nfsd4_lock_release()
8356 kfree(deny->ld_owner.data); in nfsd4_lock_release()
8373 inode = fhp->fh_dentry->d_inode; in nfsd_test_lock()
8378 lock->c.flc_file = nf->nf_file; in nfsd_test_lock()
8379 err = nfserrno(vfs_test_lock(nf->nf_file, lock)); in nfsd_test_lock()
8380 lock->c.flc_file = NULL; in nfsd_test_lock()
8394 struct nfsd4_lockt *lockt = &u->lockt; in nfsd4_lockt()
8403 if (check_lock_length(lockt->lt_offset, lockt->lt_length)) in nfsd4_lockt()
8407 status = set_client(&lockt->lt_clientid, cstate, nn); in nfsd4_lockt()
8412 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) in nfsd4_lockt()
8422 switch (lockt->lt_type) { in nfsd4_lockt()
8425 file_lock->c.flc_type = F_RDLCK; in nfsd4_lockt()
8429 file_lock->c.flc_type = F_WRLCK; in nfsd4_lockt()
8437 lo = find_lockowner_str(cstate->clp, &lockt->lt_owner); in nfsd4_lockt()
8439 file_lock->c.flc_owner = (fl_owner_t)lo; in nfsd4_lockt()
8440 file_lock->c.flc_pid = current->tgid; in nfsd4_lockt()
8441 file_lock->c.flc_flags = FL_POSIX; in nfsd4_lockt()
8443 file_lock->fl_start = lockt->lt_offset; in nfsd4_lockt()
8444 file_lock->fl_end = last_byte_offset(lockt->lt_offset, lockt->lt_length); in nfsd4_lockt()
8448 status = nfsd_test_lock(rqstp, &cstate->current_fh, file_lock); in nfsd4_lockt()
8452 if (file_lock->c.flc_type != F_UNLCK) { in nfsd4_lockt()
8454 nfs4_set_lock_denied(file_lock, &lockt->lt_denied); in nfsd4_lockt()
8458 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_lockt()
8466 struct nfsd4_lockt *lockt = &u->lockt; in nfsd4_lockt_release()
8467 struct nfsd4_lock_denied *deny = &lockt->lt_denied; in nfsd4_lockt_release()
8469 kfree(deny->ld_owner.data); in nfsd4_lockt_release()
8476 struct nfsd4_locku *locku = &u->locku; in nfsd4_locku()
8485 (long long) locku->lu_offset, in nfsd4_locku()
8486 (long long) locku->lu_length); in nfsd4_locku()
8488 if (check_lock_length(locku->lu_offset, locku->lu_length)) in nfsd4_locku()
8491 status = nfs4_preprocess_seqid_op(cstate, locku->lu_seqid, in nfsd4_locku()
8492 &locku->lu_stateid, SC_TYPE_LOCK, 0, in nfsd4_locku()
8496 nf = find_any_file(stp->st_stid.sc_file); in nfsd4_locku()
8508 file_lock->c.flc_type = F_UNLCK; in nfsd4_locku()
8509 file_lock->c.flc_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(stp->st_stateowner)); in nfsd4_locku()
8510 file_lock->c.flc_pid = current->tgid; in nfsd4_locku()
8511 file_lock->c.flc_file = nf->nf_file; in nfsd4_locku()
8512 file_lock->c.flc_flags = FL_POSIX; in nfsd4_locku()
8513 file_lock->fl_lmops = &nfsd_posix_mng_ops; in nfsd4_locku()
8514 file_lock->fl_start = locku->lu_offset; in nfsd4_locku()
8516 file_lock->fl_end = last_byte_offset(locku->lu_offset, in nfsd4_locku()
8517 locku->lu_length); in nfsd4_locku()
8520 err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, NULL); in nfsd4_locku()
8525 nfs4_inc_and_copy_stateid(&locku->lu_stateid, &stp->st_stid); in nfsd4_locku()
8529 mutex_unlock(&stp->st_mutex); in nfsd4_locku()
8530 nfs4_put_stid(&stp->st_stid); in nfsd4_locku()
8556 spin_lock(&fp->fi_lock); in check_for_locks()
8564 inode = file_inode(nf->nf_file); in check_for_locks()
8567 if (flctx && !list_empty_careful(&flctx->flc_posix)) { in check_for_locks()
8568 spin_lock(&flctx->flc_lock); in check_for_locks()
8569 for_each_file_lock(fl, &flctx->flc_posix) { in check_for_locks()
8570 if (fl->c.flc_owner == (fl_owner_t)lowner) { in check_for_locks()
8575 spin_unlock(&flctx->flc_lock); in check_for_locks()
8578 spin_unlock(&fp->fi_lock); in check_for_locks()
8583 * nfsd4_release_lockowner - process NFSv4.0 RELEASE_LOCKOWNER operations
8602 struct nfsd4_release_lockowner *rlockowner = &u->release_lockowner; in nfsd4_release_lockowner()
8604 clientid_t *clid = &rlockowner->rl_clientid; in nfsd4_release_lockowner()
8612 clid->cl_boot, clid->cl_id); in nfsd4_release_lockowner()
8617 clp = cstate->clp; in nfsd4_release_lockowner()
8619 spin_lock(&clp->cl_lock); in nfsd4_release_lockowner()
8620 lo = find_lockowner_str_locked(clp, &rlockowner->rl_owner); in nfsd4_release_lockowner()
8622 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
8626 list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) { in nfsd4_release_lockowner()
8627 if (check_for_locks(stp->st_stid.sc_file, lo)) { in nfsd4_release_lockowner()
8628 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
8629 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_release_lockowner()
8634 while (!list_empty(&lo->lo_owner.so_stateids)) { in nfsd4_release_lockowner()
8635 stp = list_first_entry(&lo->lo_owner.so_stateids, in nfsd4_release_lockowner()
8641 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
8645 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_release_lockowner()
8661 return (crp && crp->cr_clp); in nfs4_has_reclaimed_state()
8680 INIT_LIST_HEAD(&crp->cr_strhash); in nfs4_client_to_reclaim()
8681 list_add(&crp->cr_strhash, &nn->reclaim_str_hashtbl[strhashval]); in nfs4_client_to_reclaim()
8682 crp->cr_name.data = name.data; in nfs4_client_to_reclaim()
8683 crp->cr_name.len = name.len; in nfs4_client_to_reclaim()
8684 crp->cr_princhash.data = princhash.data; in nfs4_client_to_reclaim()
8685 crp->cr_princhash.len = princhash.len; in nfs4_client_to_reclaim()
8686 crp->cr_clp = NULL; in nfs4_client_to_reclaim()
8687 nn->reclaim_str_hashtbl_size++; in nfs4_client_to_reclaim()
8695 list_del(&crp->cr_strhash); in nfs4_remove_reclaim_record()
8696 kfree(crp->cr_name.data); in nfs4_remove_reclaim_record()
8697 kfree(crp->cr_princhash.data); in nfs4_remove_reclaim_record()
8699 nn->reclaim_str_hashtbl_size--; in nfs4_remove_reclaim_record()
8709 while (!list_empty(&nn->reclaim_str_hashtbl[i])) { in nfs4_release_reclaim()
8710 crp = list_entry(nn->reclaim_str_hashtbl[i].next, in nfs4_release_reclaim()
8715 WARN_ON_ONCE(nn->reclaim_str_hashtbl_size); in nfs4_release_reclaim()
8727 list_for_each_entry(crp, &nn->reclaim_str_hashtbl[strhashval], cr_strhash) { in nfsd4_find_reclaim_client()
8728 if (compare_blob(&crp->cr_name, &name) == 0) { in nfsd4_find_reclaim_client()
8738 if (test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &clp->cl_flags)) in nfs4_check_open_reclaim()
8765 max_delegations = nr_free_buffer_pages() >> (20 - 2 - PAGE_SHIFT); in set_max_delegations()
8773 nn->conf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE, in nfs4_state_create_net()
8776 if (!nn->conf_id_hashtbl) in nfs4_state_create_net()
8778 nn->unconf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE, in nfs4_state_create_net()
8781 if (!nn->unconf_id_hashtbl) in nfs4_state_create_net()
8783 nn->sessionid_hashtbl = kmalloc_array(SESSION_HASH_SIZE, in nfs4_state_create_net()
8786 if (!nn->sessionid_hashtbl) in nfs4_state_create_net()
8790 INIT_LIST_HEAD(&nn->conf_id_hashtbl[i]); in nfs4_state_create_net()
8791 INIT_LIST_HEAD(&nn->unconf_id_hashtbl[i]); in nfs4_state_create_net()
8794 INIT_LIST_HEAD(&nn->sessionid_hashtbl[i]); in nfs4_state_create_net()
8795 nn->conf_name_tree = RB_ROOT; in nfs4_state_create_net()
8796 nn->unconf_name_tree = RB_ROOT; in nfs4_state_create_net()
8797 nn->boot_time = ktime_get_real_seconds(); in nfs4_state_create_net()
8798 nn->grace_ended = false; in nfs4_state_create_net()
8799 nn->nfsd4_manager.block_opens = true; in nfs4_state_create_net()
8800 INIT_LIST_HEAD(&nn->nfsd4_manager.list); in nfs4_state_create_net()
8801 INIT_LIST_HEAD(&nn->client_lru); in nfs4_state_create_net()
8802 INIT_LIST_HEAD(&nn->close_lru); in nfs4_state_create_net()
8803 INIT_LIST_HEAD(&nn->del_recall_lru); in nfs4_state_create_net()
8804 spin_lock_init(&nn->client_lock); in nfs4_state_create_net()
8805 spin_lock_init(&nn->s2s_cp_lock); in nfs4_state_create_net()
8806 idr_init(&nn->s2s_cp_stateids); in nfs4_state_create_net()
8807 atomic_set(&nn->pending_async_copies, 0); in nfs4_state_create_net()
8809 spin_lock_init(&nn->blocked_locks_lock); in nfs4_state_create_net()
8810 INIT_LIST_HEAD(&nn->blocked_locks_lru); in nfs4_state_create_net()
8812 INIT_DELAYED_WORK(&nn->laundromat_work, laundromat_main); in nfs4_state_create_net()
8813 INIT_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker); in nfs4_state_create_net()
8816 nn->nfsd_client_shrinker = shrinker_alloc(0, "nfsd-client"); in nfs4_state_create_net()
8817 if (!nn->nfsd_client_shrinker) in nfs4_state_create_net()
8820 nn->nfsd_client_shrinker->scan_objects = nfsd4_state_shrinker_scan; in nfs4_state_create_net()
8821 nn->nfsd_client_shrinker->count_objects = nfsd4_state_shrinker_count; in nfs4_state_create_net()
8822 nn->nfsd_client_shrinker->private_data = nn; in nfs4_state_create_net()
8824 shrinker_register(nn->nfsd_client_shrinker); in nfs4_state_create_net()
8830 kfree(nn->sessionid_hashtbl); in nfs4_state_create_net()
8832 kfree(nn->unconf_id_hashtbl); in nfs4_state_create_net()
8834 kfree(nn->conf_id_hashtbl); in nfs4_state_create_net()
8836 return -ENOMEM; in nfs4_state_create_net()
8847 while (!list_empty(&nn->conf_id_hashtbl[i])) { in nfs4_state_destroy_net()
8848 clp = list_entry(nn->conf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); in nfs4_state_destroy_net()
8853 WARN_ON(!list_empty(&nn->blocked_locks_lru)); in nfs4_state_destroy_net()
8856 while (!list_empty(&nn->unconf_id_hashtbl[i])) { in nfs4_state_destroy_net()
8857 clp = list_entry(nn->unconf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); in nfs4_state_destroy_net()
8862 kfree(nn->sessionid_hashtbl); in nfs4_state_destroy_net()
8863 kfree(nn->unconf_id_hashtbl); in nfs4_state_destroy_net()
8864 kfree(nn->conf_id_hashtbl); in nfs4_state_destroy_net()
8877 locks_start_grace(net, &nn->nfsd4_manager); in nfs4_state_start_net()
8879 if (nn->track_reclaim_completes && nn->reclaim_str_hashtbl_size == 0) in nfs4_state_start_net()
8881 printk(KERN_INFO "NFSD: starting %lld-second grace period (net %x)\n", in nfs4_state_start_net()
8882 nn->nfsd4_grace, net->ns.inum); in nfs4_state_start_net()
8884 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_grace * HZ); in nfs4_state_start_net()
8889 net->ns.inum); in nfs4_state_start_net()
8890 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_lease * HZ); in nfs4_state_start_net()
8905 nfsd_slot_shrinker = shrinker_alloc(0, "nfsd-DRC-slot"); in nfs4_state_start()
8908 return -ENOMEM; in nfs4_state_start()
8910 nfsd_slot_shrinker->count_objects = nfsd_slot_count; in nfs4_state_start()
8911 nfsd_slot_shrinker->scan_objects = nfsd_slot_scan; in nfs4_state_start()
8925 shrinker_free(nn->nfsd_client_shrinker); in nfs4_state_shutdown_net()
8926 cancel_work_sync(&nn->nfsd_shrinker_work); in nfs4_state_shutdown_net()
8927 cancel_delayed_work_sync(&nn->laundromat_work); in nfs4_state_shutdown_net()
8928 locks_end_grace(&nn->nfsd4_manager); in nfs4_state_shutdown_net()
8932 list_for_each_safe(pos, next, &nn->del_recall_lru) { in nfs4_state_shutdown_net()
8935 list_add(&dp->dl_recall_lru, &reaplist); in nfs4_state_shutdown_net()
8940 list_del_init(&dp->dl_recall_lru); in nfs4_state_shutdown_net()
8963 memcpy(stateid, &cstate->current_stateid, sizeof(stateid_t)); in get_stateid()
8969 if (cstate->minorversion) { in put_stateid()
8970 memcpy(&cstate->current_stateid, stateid, sizeof(stateid_t)); in put_stateid()
8988 put_stateid(cstate, &u->open_downgrade.od_stateid); in nfsd4_set_opendowngradestateid()
8995 put_stateid(cstate, &u->open.op_stateid); in nfsd4_set_openstateid()
9002 put_stateid(cstate, &u->close.cl_stateid); in nfsd4_set_closestateid()
9009 put_stateid(cstate, &u->lock.lk_resp_stateid); in nfsd4_set_lockstateid()
9020 get_stateid(cstate, &u->open_downgrade.od_stateid); in nfsd4_get_opendowngradestateid()
9027 get_stateid(cstate, &u->delegreturn.dr_stateid); in nfsd4_get_delegreturnstateid()
9034 get_stateid(cstate, &u->free_stateid.fr_stateid); in nfsd4_get_freestateid()
9041 get_stateid(cstate, &u->setattr.sa_stateid); in nfsd4_get_setattrstateid()
9048 get_stateid(cstate, &u->close.cl_stateid); in nfsd4_get_closestateid()
9055 get_stateid(cstate, &u->locku.lu_stateid); in nfsd4_get_lockustateid()
9062 get_stateid(cstate, &u->read.rd_stateid); in nfsd4_get_readstateid()
9069 get_stateid(cstate, &u->write.wr_stateid); in nfsd4_get_writestateid()
9073 * set_cb_time - vet and set the timespec for a cb_getattr update
9111 struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; in cb_getattr_update_times()
9115 if (deleg_attrs_deleg(dp->dl_type)) { in cb_getattr_update_times()
9119 attrs.ia_atime = ncf->ncf_cb_atime; in cb_getattr_update_times()
9120 attrs.ia_mtime = ncf->ncf_cb_mtime; in cb_getattr_update_times()
9145 * nfsd4_deleg_getattr_conflict - Recall if GETATTR causes conflict
9158 * code is returned. If @pdp is set to a non-NULL value, then the
9179 spin_lock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
9180 for_each_file_lock(fl, &ctx->flc_lease) { in nfsd4_deleg_getattr_conflict()
9181 if (fl->c.flc_flags == FL_LAYOUT) in nfsd4_deleg_getattr_conflict()
9183 if (fl->c.flc_type == F_WRLCK) { in nfsd4_deleg_getattr_conflict()
9184 if (fl->fl_lmops == &nfsd_lease_mng_ops) in nfsd4_deleg_getattr_conflict()
9185 dp = fl->c.flc_owner; in nfsd4_deleg_getattr_conflict()
9192 dp->dl_recall.cb_clp == *(rqstp->rq_lease_breaker)) { in nfsd4_deleg_getattr_conflict()
9193 spin_unlock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
9205 refcount_inc(&dp->dl_stid.sc_count); in nfsd4_deleg_getattr_conflict()
9206 ncf = &dp->dl_cb_fattr; in nfsd4_deleg_getattr_conflict()
9207 nfs4_cb_getattr(&dp->dl_cb_fattr); in nfsd4_deleg_getattr_conflict()
9208 spin_unlock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
9210 wait_on_bit_timeout(&ncf->ncf_cb_flags, CB_GETATTR_BUSY, in nfsd4_deleg_getattr_conflict()
9212 if (ncf->ncf_cb_status) { in nfsd4_deleg_getattr_conflict()
9219 if (!ncf->ncf_file_modified && in nfsd4_deleg_getattr_conflict()
9220 (ncf->ncf_initial_cinfo != ncf->ncf_cb_change || in nfsd4_deleg_getattr_conflict()
9221 ncf->ncf_cur_fsize != ncf->ncf_cb_fsize)) in nfsd4_deleg_getattr_conflict()
9222 ncf->ncf_file_modified = true; in nfsd4_deleg_getattr_conflict()
9223 if (ncf->ncf_file_modified) { in nfsd4_deleg_getattr_conflict()
9236 ncf->ncf_cur_fsize = ncf->ncf_cb_fsize; in nfsd4_deleg_getattr_conflict()
9242 nfs4_put_stid(&dp->dl_stid); in nfsd4_deleg_getattr_conflict()