Lines Matching +full:embedded +full:- +full:trace +full:- +full:extension
58 #include "trace.h"
106 * A waitqueue for all in-progress 4.0 CLOSE operations that are waiting for
139 rc = -ENOMEM; in nfsd4_create_laundry_wq()
150 return ses->se_flags & NFS4_SESSION_DEAD; in is_session_dead()
155 if (atomic_read(&ses->se_ref) > ref_held_by_me) in mark_session_dead_locked()
157 ses->se_flags |= NFS4_SESSION_DEAD; in mark_session_dead_locked()
163 return clp->cl_time == 0; in is_client_expired()
169 if (clp->cl_state != NFSD4_ACTIVE) in nfsd4_dec_courtesy_client_count()
170 atomic_add_unless(&nn->nfsd_courtesy_clients, -1, 0); in nfsd4_dec_courtesy_client_count()
175 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in get_client_locked()
177 lockdep_assert_held(&nn->client_lock); in get_client_locked()
181 atomic_inc(&clp->cl_rpc_users); in get_client_locked()
183 clp->cl_state = NFSD4_ACTIVE; in get_client_locked()
191 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in renew_client_locked()
197 clp->cl_clientid.cl_boot, in renew_client_locked()
198 clp->cl_clientid.cl_id); in renew_client_locked()
202 list_move_tail(&clp->cl_lru, &nn->client_lru); in renew_client_locked()
203 clp->cl_time = ktime_get_boottime_seconds(); in renew_client_locked()
205 clp->cl_state = NFSD4_ACTIVE; in renew_client_locked()
210 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in put_client_renew_locked()
212 lockdep_assert_held(&nn->client_lock); in put_client_renew_locked()
214 if (!atomic_dec_and_test(&clp->cl_rpc_users)) in put_client_renew_locked()
224 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in put_client_renew()
226 if (!atomic_dec_and_lock(&clp->cl_rpc_users, &nn->client_lock)) in put_client_renew()
232 spin_unlock(&nn->client_lock); in put_client_renew()
241 status = get_client_locked(ses->se_client); in nfsd4_get_session_locked()
244 atomic_inc(&ses->se_ref); in nfsd4_get_session_locked()
250 struct nfs4_client *clp = ses->se_client; in nfsd4_put_session_locked()
251 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in nfsd4_put_session_locked()
253 lockdep_assert_held(&nn->client_lock); in nfsd4_put_session_locked()
255 if (atomic_dec_and_test(&ses->se_ref) && is_session_dead(ses)) in nfsd4_put_session_locked()
262 struct nfs4_client *clp = ses->se_client; in nfsd4_put_session()
263 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in nfsd4_put_session()
265 spin_lock(&nn->client_lock); in nfsd4_put_session()
267 spin_unlock(&nn->client_lock); in nfsd4_put_session()
276 spin_lock(&nn->blocked_locks_lock); in find_blocked_lock()
277 list_for_each_entry(cur, &lo->lo_blocked, nbl_list) { in find_blocked_lock()
278 if (fh_match(fh, &cur->nbl_fh)) { in find_blocked_lock()
279 list_del_init(&cur->nbl_list); in find_blocked_lock()
280 WARN_ON(list_empty(&cur->nbl_lru)); in find_blocked_lock()
281 list_del_init(&cur->nbl_lru); in find_blocked_lock()
286 spin_unlock(&nn->blocked_locks_lock); in find_blocked_lock()
288 locks_delete_block(&found->nbl_lock); in find_blocked_lock()
302 INIT_LIST_HEAD(&nbl->nbl_list); in find_or_allocate_block()
303 INIT_LIST_HEAD(&nbl->nbl_lru); in find_or_allocate_block()
304 fh_copy_shallow(&nbl->nbl_fh, fh); in find_or_allocate_block()
305 locks_init_lock(&nbl->nbl_lock); in find_or_allocate_block()
306 kref_init(&nbl->nbl_kref); in find_or_allocate_block()
307 nfsd4_init_cb(&nbl->nbl_cb, lo->lo_owner.so_client, in find_or_allocate_block()
327 locks_delete_block(&nbl->nbl_lock); in free_blocked_lock()
328 locks_release_private(&nbl->nbl_lock); in free_blocked_lock()
329 kref_put(&nbl->nbl_kref, free_nbl); in free_blocked_lock()
335 struct nfs4_client *clp = lo->lo_owner.so_client; in remove_blocked_locks()
336 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in remove_blocked_locks()
341 spin_lock(&nn->blocked_locks_lock); in remove_blocked_locks()
342 while (!list_empty(&lo->lo_blocked)) { in remove_blocked_locks()
343 nbl = list_first_entry(&lo->lo_blocked, in remove_blocked_locks()
346 list_del_init(&nbl->nbl_list); in remove_blocked_locks()
347 WARN_ON(list_empty(&nbl->nbl_lru)); in remove_blocked_locks()
348 list_move(&nbl->nbl_lru, &reaplist); in remove_blocked_locks()
350 spin_unlock(&nn->blocked_locks_lock); in remove_blocked_locks()
356 list_del_init(&nbl->nbl_lru); in remove_blocked_locks()
366 locks_delete_block(&nbl->nbl_lock); in nfsd4_cb_notify_lock_prepare()
379 switch (task->tk_status) { in nfsd4_cb_notify_lock_done()
380 case -NFS4ERR_DELAY: in nfsd4_cb_notify_lock_done()
409 * https://datatracker.ietf.org/doc/html/rfc7530#section-16.19.4 that
447 stp->st_access_bmap |= mask; in set_access()
457 stp->st_access_bmap &= ~mask; in clear_access()
466 return (bool)(stp->st_access_bmap & mask); in test_access()
476 stp->st_deny_bmap |= mask; in set_deny()
486 stp->st_deny_bmap &= ~mask; in clear_deny()
495 return (bool)(stp->st_deny_bmap & mask); in test_deny()
530 atomic_inc(&sop->so_count); in nfs4_get_stateowner()
537 return (sop->so_owner.len == owner->len) && in same_owner_str()
538 0 == memcmp(sop->so_owner.data, owner->data, owner->len); in same_owner_str()
547 lockdep_assert_held(&clp->cl_lock); in find_openstateowner_str_locked()
549 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[hashval], in find_openstateowner_str_locked()
551 if (!so->so_is_open_owner) in find_openstateowner_str_locked()
553 if (same_owner_str(so, &open->op_owner)) in find_openstateowner_str_locked()
565 spin_lock(&clp->cl_lock); in find_openstateowner_str()
567 spin_unlock(&clp->cl_lock); in find_openstateowner_str()
577 while (nbytes--) { in opaque_hashval()
594 if (refcount_dec_and_test(&fi->fi_ref)) { in put_nfs4_file()
596 WARN_ON_ONCE(!list_empty(&fi->fi_clnt_odstate)); in put_nfs4_file()
597 WARN_ON_ONCE(!list_empty(&fi->fi_delegations)); in put_nfs4_file()
598 call_rcu(&fi->fi_rcu, nfsd4_free_file_rcu); in put_nfs4_file()
607 lockdep_assert_held(&f->fi_lock); in find_writeable_file_locked()
609 ret = nfsd_file_get(f->fi_fds[O_WRONLY]); in find_writeable_file_locked()
611 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_writeable_file_locked()
620 spin_lock(&f->fi_lock); in find_writeable_file()
622 spin_unlock(&f->fi_lock); in find_writeable_file()
632 lockdep_assert_held(&f->fi_lock); in find_readable_file_locked()
634 ret = nfsd_file_get(f->fi_fds[O_RDONLY]); in find_readable_file_locked()
636 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_readable_file_locked()
645 spin_lock(&f->fi_lock); in find_readable_file()
647 spin_unlock(&f->fi_lock); in find_readable_file()
657 spin_lock(&f->fi_lock); in find_rw_file()
658 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_rw_file()
659 spin_unlock(&f->fi_lock); in find_rw_file()
671 spin_lock(&f->fi_lock); in find_any_file()
672 ret = nfsd_file_get(f->fi_fds[O_RDWR]); in find_any_file()
674 ret = nfsd_file_get(f->fi_fds[O_WRONLY]); in find_any_file()
676 ret = nfsd_file_get(f->fi_fds[O_RDONLY]); in find_any_file()
678 spin_unlock(&f->fi_lock); in find_any_file()
684 lockdep_assert_held(&f->fi_lock); in find_any_file_locked()
686 if (f->fi_fds[O_RDWR]) in find_any_file_locked()
687 return f->fi_fds[O_RDWR]; in find_any_file_locked()
688 if (f->fi_fds[O_WRONLY]) in find_any_file_locked()
689 return f->fi_fds[O_WRONLY]; in find_any_file_locked()
690 if (f->fi_fds[O_RDONLY]) in find_any_file_locked()
691 return f->fi_fds[O_RDONLY]; in find_any_file_locked()
705 #define OWNER_HASH_MASK (OWNER_HASH_SIZE - 1)
711 ret = opaque_hashval(ownername->data, ownername->len); in ownerstr_hashval()
743 * false - access/deny mode conflict with normal client.
744 * true - no conflict or conflict with courtesy client(s) is resolved.
756 lockdep_assert_held(&fp->fi_lock); in nfs4_resolve_deny_conflicts_locked()
757 list_for_each_entry(st, &fp->fi_stateids, st_perfile) { in nfs4_resolve_deny_conflicts_locked()
759 if (st->st_openstp) in nfs4_resolve_deny_conflicts_locked()
764 bmap = share_access ? st->st_deny_bmap : st->st_access_bmap; in nfs4_resolve_deny_conflicts_locked()
767 clp = st->st_stid.sc_client; in nfs4_resolve_deny_conflicts_locked()
774 clp = stp->st_stid.sc_client; in nfs4_resolve_deny_conflicts_locked()
775 nn = net_generic(clp->net, nfsd_net_id); in nfs4_resolve_deny_conflicts_locked()
776 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in nfs4_resolve_deny_conflicts_locked()
784 lockdep_assert_held(&fp->fi_lock); in __nfs4_file_get_access()
787 atomic_inc(&fp->fi_access[O_WRONLY]); in __nfs4_file_get_access()
789 atomic_inc(&fp->fi_access[O_RDONLY]); in __nfs4_file_get_access()
795 lockdep_assert_held(&fp->fi_lock); in nfs4_file_get_access()
802 if ((access & fp->fi_share_deny) != 0) in nfs4_file_get_access()
818 atomic_read(&fp->fi_access[O_RDONLY])) in nfs4_file_check_deny()
822 atomic_read(&fp->fi_access[O_WRONLY])) in nfs4_file_check_deny()
830 might_lock(&fp->fi_lock); in __nfs4_file_put_access()
832 if (atomic_dec_and_lock(&fp->fi_access[oflag], &fp->fi_lock)) { in __nfs4_file_put_access()
836 swap(f1, fp->fi_fds[oflag]); in __nfs4_file_put_access()
837 if (atomic_read(&fp->fi_access[1 - oflag]) == 0) in __nfs4_file_put_access()
838 swap(f2, fp->fi_fds[O_RDWR]); in __nfs4_file_put_access()
839 spin_unlock(&fp->fi_lock); in __nfs4_file_put_access()
861 * Note that we only allocate it for pNFS-enabled exports, otherwise
871 co->co_client = clp; in alloc_clnt_odstate()
872 refcount_set(&co->co_odcount, 1); in alloc_clnt_odstate()
880 struct nfs4_file *fp = co->co_file; in hash_clnt_odstate_locked()
882 lockdep_assert_held(&fp->fi_lock); in hash_clnt_odstate_locked()
883 list_add(&co->co_perfile, &fp->fi_clnt_odstate); in hash_clnt_odstate_locked()
890 refcount_inc(&co->co_odcount); in get_clnt_odstate()
901 fp = co->co_file; in put_clnt_odstate()
902 if (refcount_dec_and_lock(&co->co_odcount, &fp->fi_lock)) { in put_clnt_odstate()
903 list_del(&co->co_perfile); in put_clnt_odstate()
904 spin_unlock(&fp->fi_lock); in put_clnt_odstate()
906 nfsd4_return_all_file_layouts(co->co_client, fp); in put_clnt_odstate()
920 cl = new->co_client; in find_or_hash_clnt_odstate()
922 spin_lock(&fp->fi_lock); in find_or_hash_clnt_odstate()
923 list_for_each_entry(co, &fp->fi_clnt_odstate, co_perfile) { in find_or_hash_clnt_odstate()
924 if (co->co_client == cl) { in find_or_hash_clnt_odstate()
930 co->co_file = fp; in find_or_hash_clnt_odstate()
933 spin_unlock(&fp->fi_lock); in find_or_hash_clnt_odstate()
948 spin_lock(&cl->cl_lock); in nfs4_alloc_stid()
950 new_id = idr_alloc_cyclic(&cl->cl_stateids, stid, 1, 0, GFP_NOWAIT); in nfs4_alloc_stid()
951 spin_unlock(&cl->cl_lock); in nfs4_alloc_stid()
956 stid->sc_free = sc_free; in nfs4_alloc_stid()
957 stid->sc_client = cl; in nfs4_alloc_stid()
958 stid->sc_stateid.si_opaque.so_id = new_id; in nfs4_alloc_stid()
959 stid->sc_stateid.si_opaque.so_clid = cl->cl_clientid; in nfs4_alloc_stid()
961 refcount_set(&stid->sc_count, 1); in nfs4_alloc_stid()
962 spin_lock_init(&stid->sc_lock); in nfs4_alloc_stid()
963 INIT_LIST_HEAD(&stid->sc_cp_list); in nfs4_alloc_stid()
988 stid->cs_stid.si_opaque.so_clid.cl_boot = (u32)nn->boot_time; in nfs4_init_cp_state()
989 stid->cs_stid.si_opaque.so_clid.cl_id = nn->s2s_cp_cl_id; in nfs4_init_cp_state()
992 spin_lock(&nn->s2s_cp_lock); in nfs4_init_cp_state()
993 new_id = idr_alloc_cyclic(&nn->s2s_cp_stateids, stid, 0, 0, GFP_NOWAIT); in nfs4_init_cp_state()
994 stid->cs_stid.si_opaque.so_id = new_id; in nfs4_init_cp_state()
995 stid->cs_stid.si_generation = 1; in nfs4_init_cp_state()
996 spin_unlock(&nn->s2s_cp_lock); in nfs4_init_cp_state()
1000 stid->cs_type = cs_type; in nfs4_init_cp_state()
1006 return nfs4_init_cp_state(nn, ©->cp_stateid, NFS4_COPY_STID); in nfs4_init_copy_state()
1017 cps->cpntf_time = ktime_get_boottime_seconds(); in nfs4_alloc_init_cpntf_state()
1018 refcount_set(&cps->cp_stateid.cs_count, 1); in nfs4_alloc_init_cpntf_state()
1019 if (!nfs4_init_cp_state(nn, &cps->cp_stateid, NFS4_COPYNOTIFY_STID)) in nfs4_alloc_init_cpntf_state()
1021 spin_lock(&nn->s2s_cp_lock); in nfs4_alloc_init_cpntf_state()
1022 list_add(&cps->cp_list, &p_stid->sc_cp_list); in nfs4_alloc_init_cpntf_state()
1023 spin_unlock(&nn->s2s_cp_lock); in nfs4_alloc_init_cpntf_state()
1034 if (copy->cp_stateid.cs_type != NFS4_COPY_STID) in nfs4_free_copy_state()
1036 nn = net_generic(copy->cp_clp->net, nfsd_net_id); in nfs4_free_copy_state()
1037 spin_lock(&nn->s2s_cp_lock); in nfs4_free_copy_state()
1038 idr_remove(&nn->s2s_cp_stateids, in nfs4_free_copy_state()
1039 copy->cp_stateid.cs_stid.si_opaque.so_id); in nfs4_free_copy_state()
1040 spin_unlock(&nn->s2s_cp_lock); in nfs4_free_copy_state()
1049 spin_lock(&nn->s2s_cp_lock); in nfs4_free_cpntf_statelist()
1050 while (!list_empty(&stid->sc_cp_list)) { in nfs4_free_cpntf_statelist()
1051 cps = list_first_entry(&stid->sc_cp_list, in nfs4_free_cpntf_statelist()
1055 spin_unlock(&nn->s2s_cp_lock); in nfs4_free_cpntf_statelist()
1073 WARN_ON_ONCE(!list_empty(&stid->sc_cp_list)); in nfs4_free_deleg()
1074 WARN_ON_ONCE(!list_empty(&dp->dl_perfile)); in nfs4_free_deleg()
1075 WARN_ON_ONCE(!list_empty(&dp->dl_perclnt)); in nfs4_free_deleg()
1076 WARN_ON_ONCE(!list_empty(&dp->dl_recall_lru)); in nfs4_free_deleg()
1093 * low 3 bytes as hash-table indices.
1112 if (bd->entries == 0) in delegation_blocked()
1114 if (ktime_get_seconds() - bd->swap_time > 30) { in delegation_blocked()
1116 if (ktime_get_seconds() - bd->swap_time > 30) { in delegation_blocked()
1117 bd->entries -= bd->old_entries; in delegation_blocked()
1118 bd->old_entries = bd->entries; in delegation_blocked()
1119 memset(bd->set[bd->new], 0, in delegation_blocked()
1120 sizeof(bd->set[0])); in delegation_blocked()
1121 bd->new = 1-bd->new; in delegation_blocked()
1122 bd->swap_time = ktime_get_seconds(); in delegation_blocked()
1126 hash = jhash(&fh->fh_raw, fh->fh_size, 0); in delegation_blocked()
1127 if (test_bit(hash&255, bd->set[0]) && in delegation_blocked()
1128 test_bit((hash>>8)&255, bd->set[0]) && in delegation_blocked()
1129 test_bit((hash>>16)&255, bd->set[0])) in delegation_blocked()
1132 if (test_bit(hash&255, bd->set[1]) && in delegation_blocked()
1133 test_bit((hash>>8)&255, bd->set[1]) && in delegation_blocked()
1134 test_bit((hash>>16)&255, bd->set[1])) in delegation_blocked()
1145 hash = jhash(&fh->fh_raw, fh->fh_size, 0); in block_delegations()
1148 __set_bit(hash&255, bd->set[bd->new]); in block_delegations()
1149 __set_bit((hash>>8)&255, bd->set[bd->new]); in block_delegations()
1150 __set_bit((hash>>16)&255, bd->set[bd->new]); in block_delegations()
1151 if (bd->entries == 0) in block_delegations()
1152 bd->swap_time = ktime_get_seconds(); in block_delegations()
1153 bd->entries += 1; in block_delegations()
1169 if (delegation_blocked(&fp->fi_fhandle)) in alloc_init_deleg()
1181 dp->dl_stid.sc_stateid.si_generation = 1; in alloc_init_deleg()
1182 INIT_LIST_HEAD(&dp->dl_perfile); in alloc_init_deleg()
1183 INIT_LIST_HEAD(&dp->dl_perclnt); in alloc_init_deleg()
1184 INIT_LIST_HEAD(&dp->dl_recall_lru); in alloc_init_deleg()
1185 dp->dl_clnt_odstate = odstate; in alloc_init_deleg()
1187 dp->dl_type = dl_type; in alloc_init_deleg()
1188 dp->dl_retries = 1; in alloc_init_deleg()
1189 dp->dl_recalled = false; in alloc_init_deleg()
1190 nfsd4_init_cb(&dp->dl_recall, dp->dl_stid.sc_client, in alloc_init_deleg()
1193 dp->dl_stid.sc_file = fp; in alloc_init_deleg()
1203 struct nfs4_file *fp = s->sc_file; in nfs4_put_stid()
1204 struct nfs4_client *clp = s->sc_client; in nfs4_put_stid()
1206 might_lock(&clp->cl_lock); in nfs4_put_stid()
1208 if (!refcount_dec_and_lock(&s->sc_count, &clp->cl_lock)) { in nfs4_put_stid()
1212 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); in nfs4_put_stid()
1213 nfs4_free_cpntf_statelist(clp->net, s); in nfs4_put_stid()
1214 spin_unlock(&clp->cl_lock); in nfs4_put_stid()
1215 s->sc_free(s); in nfs4_put_stid()
1223 stateid_t *src = &stid->sc_stateid; in nfs4_inc_and_copy_stateid()
1225 spin_lock(&stid->sc_lock); in nfs4_inc_and_copy_stateid()
1226 if (unlikely(++src->si_generation == 0)) in nfs4_inc_and_copy_stateid()
1227 src->si_generation = 1; in nfs4_inc_and_copy_stateid()
1229 spin_unlock(&stid->sc_lock); in nfs4_inc_and_copy_stateid()
1236 spin_lock(&fp->fi_lock); in put_deleg_file()
1237 if (--fp->fi_delegees == 0) in put_deleg_file()
1238 swap(nf, fp->fi_deleg_file); in put_deleg_file()
1239 spin_unlock(&fp->fi_lock); in put_deleg_file()
1247 struct nfs4_file *fp = dp->dl_stid.sc_file; in nfs4_unlock_deleg_lease()
1248 struct nfsd_file *nf = fp->fi_deleg_file; in nfs4_unlock_deleg_lease()
1250 WARN_ON_ONCE(!fp->fi_delegees); in nfs4_unlock_deleg_lease()
1252 vfs_setlease(nf->nf_file, F_UNLCK, NULL, (void **)&dp); in nfs4_unlock_deleg_lease()
1258 put_clnt_odstate(dp->dl_clnt_odstate); in destroy_unhashed_deleg()
1260 nfs4_put_stid(&dp->dl_stid); in destroy_unhashed_deleg()
1265 s->sc_type = 0; in nfs4_unhash_stid()
1269 * nfs4_delegation_exists - Discover if this delegation already exists
1284 lockdep_assert_held(&fp->fi_lock); in nfs4_delegation_exists()
1286 list_for_each_entry(searchdp, &fp->fi_delegations, dl_perfile) { in nfs4_delegation_exists()
1287 searchclp = searchdp->dl_stid.sc_client; in nfs4_delegation_exists()
1296 * hash_delegation_locked - Add a delegation to the appropriate lists
1303 * On error: -EAGAIN if one was previously granted to this
1311 struct nfs4_client *clp = dp->dl_stid.sc_client; in hash_delegation_locked()
1314 lockdep_assert_held(&fp->fi_lock); in hash_delegation_locked()
1317 return -EAGAIN; in hash_delegation_locked()
1318 refcount_inc(&dp->dl_stid.sc_count); in hash_delegation_locked()
1319 dp->dl_stid.sc_type = NFS4_DELEG_STID; in hash_delegation_locked()
1320 list_add(&dp->dl_perfile, &fp->fi_delegations); in hash_delegation_locked()
1321 list_add(&dp->dl_perclnt, &clp->cl_delegations); in hash_delegation_locked()
1327 return !(list_empty(&dp->dl_perfile)); in delegation_hashed()
1333 struct nfs4_file *fp = dp->dl_stid.sc_file; in unhash_delegation_locked()
1340 dp->dl_stid.sc_type = NFS4_CLOSED_DELEG_STID; in unhash_delegation_locked()
1342 ++dp->dl_time; in unhash_delegation_locked()
1343 spin_lock(&fp->fi_lock); in unhash_delegation_locked()
1344 list_del_init(&dp->dl_perclnt); in unhash_delegation_locked()
1345 list_del_init(&dp->dl_recall_lru); in unhash_delegation_locked()
1346 list_del_init(&dp->dl_perfile); in unhash_delegation_locked()
1347 spin_unlock(&fp->fi_lock); in unhash_delegation_locked()
1364 struct nfs4_client *clp = dp->dl_stid.sc_client; in revoke_delegation()
1366 WARN_ON(!list_empty(&dp->dl_recall_lru)); in revoke_delegation()
1368 trace_nfsd_stid_revoke(&dp->dl_stid); in revoke_delegation()
1370 if (clp->cl_minorversion) { in revoke_delegation()
1371 spin_lock(&clp->cl_lock); in revoke_delegation()
1372 dp->dl_stid.sc_type = NFS4_REVOKED_DELEG_STID; in revoke_delegation()
1373 refcount_inc(&dp->dl_stid.sc_count); in revoke_delegation()
1374 list_add(&dp->dl_recall_lru, &clp->cl_revoked); in revoke_delegation()
1375 spin_unlock(&clp->cl_lock); in revoke_delegation()
1403 spin_lock(&fp->fi_lock); in recalculate_deny_mode()
1404 fp->fi_share_deny = 0; in recalculate_deny_mode()
1405 list_for_each_entry(stp, &fp->fi_stateids, st_perfile) in recalculate_deny_mode()
1406 fp->fi_share_deny |= bmap_to_share_mode(stp->st_deny_bmap); in recalculate_deny_mode()
1407 spin_unlock(&fp->fi_lock); in recalculate_deny_mode()
1423 /* Recalculate per-file deny mode if there was a change */ in reset_union_bmap_deny()
1425 recalculate_deny_mode(stp->st_stid.sc_file); in reset_union_bmap_deny()
1433 struct nfs4_file *fp = stp->st_stid.sc_file; in release_all_access()
1435 if (fp && stp->st_deny_bmap != 0) in release_all_access()
1440 nfs4_file_put_access(stp->st_stid.sc_file, i); in release_all_access()
1447 kfree(sop->so_owner.data); in nfs4_free_stateowner()
1448 sop->so_ops->so_free(sop); in nfs4_free_stateowner()
1453 struct nfs4_client *clp = sop->so_client; in nfs4_put_stateowner()
1455 might_lock(&clp->cl_lock); in nfs4_put_stateowner()
1457 if (!atomic_dec_and_lock(&sop->so_count, &clp->cl_lock)) in nfs4_put_stateowner()
1459 sop->so_ops->so_unhash(sop); in nfs4_put_stateowner()
1460 spin_unlock(&clp->cl_lock); in nfs4_put_stateowner()
1467 return list_empty(&stp->st_perfile); in nfs4_ol_stateid_unhashed()
1472 struct nfs4_file *fp = stp->st_stid.sc_file; in unhash_ol_stateid()
1474 lockdep_assert_held(&stp->st_stateowner->so_client->cl_lock); in unhash_ol_stateid()
1476 if (list_empty(&stp->st_perfile)) in unhash_ol_stateid()
1479 spin_lock(&fp->fi_lock); in unhash_ol_stateid()
1480 list_del_init(&stp->st_perfile); in unhash_ol_stateid()
1481 spin_unlock(&fp->fi_lock); in unhash_ol_stateid()
1482 list_del(&stp->st_perstateowner); in unhash_ol_stateid()
1490 put_clnt_odstate(stp->st_clnt_odstate); in nfs4_free_ol_stateid()
1492 if (stp->st_stateowner) in nfs4_free_ol_stateid()
1493 nfs4_put_stateowner(stp->st_stateowner); in nfs4_free_ol_stateid()
1494 WARN_ON(!list_empty(&stid->sc_cp_list)); in nfs4_free_ol_stateid()
1501 struct nfs4_lockowner *lo = lockowner(stp->st_stateowner); in nfs4_free_lock_stateid()
1504 nf = find_any_file(stp->st_stid.sc_file); in nfs4_free_lock_stateid()
1506 get_file(nf->nf_file); in nfs4_free_lock_stateid()
1507 filp_close(nf->nf_file, (fl_owner_t)lo); in nfs4_free_lock_stateid()
1521 struct nfs4_stid *s = &stp->st_stid; in put_ol_stateid_locked()
1522 struct nfs4_client *clp = s->sc_client; in put_ol_stateid_locked()
1524 lockdep_assert_held(&clp->cl_lock); in put_ol_stateid_locked()
1526 WARN_ON_ONCE(!list_empty(&stp->st_locks)); in put_ol_stateid_locked()
1528 if (!refcount_dec_and_test(&s->sc_count)) { in put_ol_stateid_locked()
1533 idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); in put_ol_stateid_locked()
1534 list_add(&stp->st_locks, reaplist); in put_ol_stateid_locked()
1539 lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); in unhash_lock_stateid()
1543 list_del_init(&stp->st_locks); in unhash_lock_stateid()
1544 nfs4_unhash_stid(&stp->st_stid); in unhash_lock_stateid()
1550 struct nfs4_client *clp = stp->st_stid.sc_client; in release_lock_stateid()
1553 spin_lock(&clp->cl_lock); in release_lock_stateid()
1555 spin_unlock(&clp->cl_lock); in release_lock_stateid()
1557 nfs4_put_stid(&stp->st_stid); in release_lock_stateid()
1562 struct nfs4_client *clp = lo->lo_owner.so_client; in unhash_lockowner_locked()
1564 lockdep_assert_held(&clp->cl_lock); in unhash_lockowner_locked()
1566 list_del_init(&lo->lo_owner.so_strhash); in unhash_lockowner_locked()
1584 list_del(&stp->st_locks); in free_ol_stateid_reaplist()
1585 fp = stp->st_stid.sc_file; in free_ol_stateid_reaplist()
1586 stp->st_stid.sc_free(&stp->st_stid); in free_ol_stateid_reaplist()
1597 lockdep_assert_held(&open_stp->st_stid.sc_client->cl_lock); in release_open_stateid_locks()
1599 while (!list_empty(&open_stp->st_locks)) { in release_open_stateid_locks()
1600 stp = list_entry(open_stp->st_locks.next, in release_open_stateid_locks()
1610 lockdep_assert_held(&stp->st_stid.sc_client->cl_lock); in unhash_open_stateid()
1622 spin_lock(&stp->st_stid.sc_client->cl_lock); in release_open_stateid()
1625 spin_unlock(&stp->st_stid.sc_client->cl_lock); in release_open_stateid()
1631 struct nfs4_client *clp = oo->oo_owner.so_client; in unhash_openowner_locked()
1633 lockdep_assert_held(&clp->cl_lock); in unhash_openowner_locked()
1635 list_del_init(&oo->oo_owner.so_strhash); in unhash_openowner_locked()
1636 list_del_init(&oo->oo_perclient); in unhash_openowner_locked()
1641 struct nfsd_net *nn = net_generic(oo->oo_owner.so_client->net, in release_last_closed_stateid()
1645 spin_lock(&nn->client_lock); in release_last_closed_stateid()
1646 s = oo->oo_last_closed_stid; in release_last_closed_stateid()
1648 list_del_init(&oo->oo_close_lru); in release_last_closed_stateid()
1649 oo->oo_last_closed_stid = NULL; in release_last_closed_stateid()
1651 spin_unlock(&nn->client_lock); in release_last_closed_stateid()
1653 nfs4_put_stid(&s->st_stid); in release_last_closed_stateid()
1659 struct nfs4_client *clp = oo->oo_owner.so_client; in release_openowner()
1664 spin_lock(&clp->cl_lock); in release_openowner()
1666 while (!list_empty(&oo->oo_owner.so_stateids)) { in release_openowner()
1667 stp = list_first_entry(&oo->oo_owner.so_stateids, in release_openowner()
1672 spin_unlock(&clp->cl_lock); in release_openowner()
1675 nfs4_put_stateowner(&oo->oo_owner); in release_openowner()
1683 return sid->sequence % SESSION_HASH_SIZE; in hash_sessionid()
1690 u32 *ptr = (u32 *)(&sessionid->data[0]); in dump_sessionid()
1701 * Bump the seqid on cstate->replay_owner, and clear replay_owner if it
1706 struct nfs4_stateowner *so = cstate->replay_owner; in nfsd4_bump_seqid()
1717 if (so->so_is_open_owner) in nfsd4_bump_seqid()
1719 so->so_seqid++; in nfsd4_bump_seqid()
1726 struct nfs4_client *clp = ses->se_client; in gen_sessionid()
1729 sid = (struct nfsd4_sessionid *)ses->se_sessionid.data; in gen_sessionid()
1730 sid->clientid = clp->cl_clientid; in gen_sessionid()
1731 sid->sequence = current_sessionid++; in gen_sessionid()
1732 sid->reserved = 0; in gen_sessionid()
1738 * the end of the initial SEQUENCE operation--the rest we regenerate
1744 * verifier), 12 for the compound header (with zero-length tag), and 44
1754 for (i = 0; i < ses->se_fchannel.maxreqs; i++) { in free_session_slots()
1755 free_svc_cred(&ses->se_slots[i]->sl_cred); in free_session_slots()
1756 kfree(ses->se_slots[i]); in free_session_slots()
1768 if (ca->maxresp_cached < NFSD_MIN_HDR_SEQ_SZ) in slot_bytes()
1771 size = ca->maxresp_cached - NFSD_MIN_HDR_SEQ_SZ; in slot_bytes()
1777 * re-negotiate active sessions and reduce their slot usage to make
1783 u32 num = ca->maxreqs; in nfsd4_get_drc_mem()
1789 total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used; in nfsd4_get_drc_mem()
1805 * over-allocation--it is better than failure. in nfsd4_get_drc_mem()
1807 scale_factor = max_t(unsigned int, 8, nn->nfsd_serv->sv_nrthreads); in nfsd4_get_drc_mem()
1824 nfsd_drc_mem_used -= slotsize * ca->maxreqs; in nfsd4_put_drc_mem()
1831 int numslots = fattrs->maxreqs; in alloc_session()
1844 new->se_slots[i] = kzalloc(slotsize, GFP_KERNEL); in alloc_session()
1845 if (!new->se_slots[i]) in alloc_session()
1849 memcpy(&new->se_fchannel, fattrs, sizeof(struct nfsd4_channel_attrs)); in alloc_session()
1850 memcpy(&new->se_bchannel, battrs, sizeof(struct nfsd4_channel_attrs)); in alloc_session()
1854 while (i--) in alloc_session()
1855 kfree(new->se_slots[i]); in alloc_session()
1862 svc_xprt_put(c->cn_xprt); in free_conn()
1869 struct nfs4_client *clp = c->cn_session->se_client; in nfsd4_conn_lost()
1873 spin_lock(&clp->cl_lock); in nfsd4_conn_lost()
1874 if (!list_empty(&c->cn_persession)) { in nfsd4_conn_lost()
1875 list_del(&c->cn_persession); in nfsd4_conn_lost()
1879 spin_unlock(&clp->cl_lock); in nfsd4_conn_lost()
1889 svc_xprt_get(rqstp->rq_xprt); in alloc_conn()
1890 conn->cn_xprt = rqstp->rq_xprt; in alloc_conn()
1891 conn->cn_flags = flags; in alloc_conn()
1892 INIT_LIST_HEAD(&conn->cn_xpt_user.list); in alloc_conn()
1898 conn->cn_session = ses; in __nfsd4_hash_conn()
1899 list_add(&conn->cn_persession, &ses->se_conns); in __nfsd4_hash_conn()
1904 struct nfs4_client *clp = ses->se_client; in nfsd4_hash_conn()
1906 spin_lock(&clp->cl_lock); in nfsd4_hash_conn()
1908 spin_unlock(&clp->cl_lock); in nfsd4_hash_conn()
1913 conn->cn_xpt_user.callback = nfsd4_conn_lost; in nfsd4_register_conn()
1914 return register_xpt_user(conn->cn_xprt, &conn->cn_xpt_user); in nfsd4_register_conn()
1925 nfsd4_conn_lost(&conn->cn_xpt_user); in nfsd4_init_conn()
1927 nfsd4_probe_callback_sync(ses->se_client); in nfsd4_init_conn()
1934 if (cses->flags & SESSION4_BACK_CHAN) in alloc_conn_from_crses()
1942 struct nfs4_client *clp = s->se_client; in nfsd4_del_conns()
1945 spin_lock(&clp->cl_lock); in nfsd4_del_conns()
1946 while (!list_empty(&s->se_conns)) { in nfsd4_del_conns()
1947 c = list_first_entry(&s->se_conns, struct nfsd4_conn, cn_persession); in nfsd4_del_conns()
1948 list_del_init(&c->cn_persession); in nfsd4_del_conns()
1949 spin_unlock(&clp->cl_lock); in nfsd4_del_conns()
1951 unregister_xpt_user(c->cn_xprt, &c->cn_xpt_user); in nfsd4_del_conns()
1954 spin_lock(&clp->cl_lock); in nfsd4_del_conns()
1956 spin_unlock(&clp->cl_lock); in nfsd4_del_conns()
1968 nfsd4_put_drc_mem(&ses->se_fchannel); in free_session()
1977 new->se_client = clp; in init_session()
1980 INIT_LIST_HEAD(&new->se_conns); in init_session()
1982 new->se_cb_seq_nr = 1; in init_session()
1983 new->se_flags = cses->flags; in init_session()
1984 new->se_cb_prog = cses->callback_prog; in init_session()
1985 new->se_cb_sec = cses->cb_sec; in init_session()
1986 atomic_set(&new->se_ref, 0); in init_session()
1987 idx = hash_sessionid(&new->se_sessionid); in init_session()
1988 list_add(&new->se_hash, &nn->sessionid_hashtbl[idx]); in init_session()
1989 spin_lock(&clp->cl_lock); in init_session()
1990 list_add(&new->se_perclnt, &clp->cl_sessions); in init_session()
1991 spin_unlock(&clp->cl_lock); in init_session()
2002 rpc_copy_addr((struct sockaddr *)&clp->cl_cb_conn.cb_addr, sa); in init_session()
2003 clp->cl_cb_conn.cb_addrlen = svc_addr_len(sa); in init_session()
2015 lockdep_assert_held(&nn->client_lock); in __find_in_sessionid_hashtbl()
2020 list_for_each_entry(elem, &nn->sessionid_hashtbl[idx], se_hash) { in __find_in_sessionid_hashtbl()
2021 if (!memcmp(elem->se_sessionid.data, sessionid->data, in __find_in_sessionid_hashtbl()
2053 struct nfs4_client *clp = ses->se_client; in unhash_session()
2054 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_session()
2056 lockdep_assert_held(&nn->client_lock); in unhash_session()
2058 list_del(&ses->se_hash); in unhash_session()
2059 spin_lock(&ses->se_client->cl_lock); in unhash_session()
2060 list_del(&ses->se_perclnt); in unhash_session()
2061 spin_unlock(&ses->se_client->cl_lock); in unhash_session()
2073 if (clid->cl_boot == (u32)nn->boot_time) in STALE_CLIENTID()
2090 if (atomic_read(&nn->nfs4_client_count) >= nn->nfs4_max_clients) { in alloc_client()
2091 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in alloc_client()
2097 xdr_netobj_dup(&clp->cl_name, &name, GFP_KERNEL); in alloc_client()
2098 if (clp->cl_name.data == NULL) in alloc_client()
2100 clp->cl_ownerstr_hashtbl = kmalloc_array(OWNER_HASH_SIZE, in alloc_client()
2103 if (!clp->cl_ownerstr_hashtbl) in alloc_client()
2106 INIT_LIST_HEAD(&clp->cl_ownerstr_hashtbl[i]); in alloc_client()
2107 INIT_LIST_HEAD(&clp->cl_sessions); in alloc_client()
2108 idr_init(&clp->cl_stateids); in alloc_client()
2109 atomic_set(&clp->cl_rpc_users, 0); in alloc_client()
2110 clp->cl_cb_state = NFSD4_CB_UNKNOWN; in alloc_client()
2111 clp->cl_state = NFSD4_ACTIVE; in alloc_client()
2112 atomic_inc(&nn->nfs4_client_count); in alloc_client()
2113 atomic_set(&clp->cl_delegs_in_recall, 0); in alloc_client()
2114 INIT_LIST_HEAD(&clp->cl_idhash); in alloc_client()
2115 INIT_LIST_HEAD(&clp->cl_openowners); in alloc_client()
2116 INIT_LIST_HEAD(&clp->cl_delegations); in alloc_client()
2117 INIT_LIST_HEAD(&clp->cl_lru); in alloc_client()
2118 INIT_LIST_HEAD(&clp->cl_revoked); in alloc_client()
2120 INIT_LIST_HEAD(&clp->cl_lo_states); in alloc_client()
2122 INIT_LIST_HEAD(&clp->async_copies); in alloc_client()
2123 spin_lock_init(&clp->async_lock); in alloc_client()
2124 spin_lock_init(&clp->cl_lock); in alloc_client()
2125 rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table"); in alloc_client()
2128 kfree(clp->cl_name.data); in alloc_client()
2139 free_svc_cred(&clp->cl_cred); in __free_client()
2140 kfree(clp->cl_ownerstr_hashtbl); in __free_client()
2141 kfree(clp->cl_name.data); in __free_client()
2142 kfree(clp->cl_nii_domain.data); in __free_client()
2143 kfree(clp->cl_nii_name.data); in __free_client()
2144 idr_destroy(&clp->cl_stateids); in __free_client()
2145 kfree(clp->cl_ra); in __free_client()
2151 kref_put(&clp->cl_nfsdfs.cl_ref, __free_client); in drop_client()
2157 while (!list_empty(&clp->cl_sessions)) { in free_client()
2159 ses = list_entry(clp->cl_sessions.next, struct nfsd4_session, in free_client()
2161 list_del(&ses->se_perclnt); in free_client()
2162 WARN_ON_ONCE(atomic_read(&ses->se_ref)); in free_client()
2165 rpc_destroy_wait_queue(&clp->cl_cb_waitq); in free_client()
2166 if (clp->cl_nfsd_dentry) { in free_client()
2167 nfsd_client_rmdir(clp->cl_nfsd_dentry); in free_client()
2168 clp->cl_nfsd_dentry = NULL; in free_client()
2178 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_client_locked()
2181 lockdep_assert_held(&nn->client_lock); in unhash_client_locked()
2184 clp->cl_time = 0; in unhash_client_locked()
2186 if (!list_empty(&clp->cl_idhash)) { in unhash_client_locked()
2187 list_del_init(&clp->cl_idhash); in unhash_client_locked()
2188 if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) in unhash_client_locked()
2189 rb_erase(&clp->cl_namenode, &nn->conf_name_tree); in unhash_client_locked()
2191 rb_erase(&clp->cl_namenode, &nn->unconf_name_tree); in unhash_client_locked()
2193 list_del_init(&clp->cl_lru); in unhash_client_locked()
2194 spin_lock(&clp->cl_lock); in unhash_client_locked()
2195 list_for_each_entry(ses, &clp->cl_sessions, se_perclnt) in unhash_client_locked()
2196 list_del_init(&ses->se_hash); in unhash_client_locked()
2197 spin_unlock(&clp->cl_lock); in unhash_client_locked()
2203 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in unhash_client()
2205 spin_lock(&nn->client_lock); in unhash_client()
2207 spin_unlock(&nn->client_lock); in unhash_client()
2212 if (atomic_read(&clp->cl_rpc_users)) in mark_client_expired_locked()
2221 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in __destroy_client()
2229 while (!list_empty(&clp->cl_delegations)) { in __destroy_client()
2230 dp = list_entry(clp->cl_delegations.next, struct nfs4_delegation, dl_perclnt); in __destroy_client()
2232 list_add(&dp->dl_recall_lru, &reaplist); in __destroy_client()
2237 list_del_init(&dp->dl_recall_lru); in __destroy_client()
2240 while (!list_empty(&clp->cl_revoked)) { in __destroy_client()
2241 dp = list_entry(clp->cl_revoked.next, struct nfs4_delegation, dl_recall_lru); in __destroy_client()
2242 list_del_init(&dp->dl_recall_lru); in __destroy_client()
2243 nfs4_put_stid(&dp->dl_stid); in __destroy_client()
2245 while (!list_empty(&clp->cl_openowners)) { in __destroy_client()
2246 oo = list_entry(clp->cl_openowners.next, struct nfs4_openowner, oo_perclient); in __destroy_client()
2247 nfs4_get_stateowner(&oo->oo_owner); in __destroy_client()
2253 list_for_each_entry_safe(so, tmp, &clp->cl_ownerstr_hashtbl[i], in __destroy_client()
2256 WARN_ON_ONCE(so->so_is_open_owner); in __destroy_client()
2263 if (clp->cl_cb_conn.cb_xprt) in __destroy_client()
2264 svc_xprt_put(clp->cl_cb_conn.cb_xprt); in __destroy_client()
2265 atomic_add_unless(&nn->nfs4_client_count, -1, 0); in __destroy_client()
2280 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in inc_reclaim_complete()
2282 if (!nn->track_reclaim_completes) in inc_reclaim_complete()
2284 if (!nfsd4_find_reclaim_client(clp->cl_name, nn)) in inc_reclaim_complete()
2286 if (atomic_inc_return(&nn->nr_reclaim_complete) == in inc_reclaim_complete()
2287 nn->reclaim_str_hashtbl_size) { in inc_reclaim_complete()
2289 clp->net->ns.inum); in inc_reclaim_complete()
2303 memcpy(target->cl_verifier.data, source->data, in copy_verf()
2304 sizeof(target->cl_verifier.data)); in copy_verf()
2309 target->cl_clientid.cl_boot = source->cl_clientid.cl_boot; in copy_clid()
2310 target->cl_clientid.cl_id = source->cl_clientid.cl_id; in copy_clid()
2315 target->cr_principal = kstrdup(source->cr_principal, GFP_KERNEL); in copy_cred()
2316 target->cr_raw_principal = kstrdup(source->cr_raw_principal, in copy_cred()
2318 target->cr_targ_princ = kstrdup(source->cr_targ_princ, GFP_KERNEL); in copy_cred()
2319 if ((source->cr_principal && !target->cr_principal) || in copy_cred()
2320 (source->cr_raw_principal && !target->cr_raw_principal) || in copy_cred()
2321 (source->cr_targ_princ && !target->cr_targ_princ)) in copy_cred()
2322 return -ENOMEM; in copy_cred()
2324 target->cr_flavor = source->cr_flavor; in copy_cred()
2325 target->cr_uid = source->cr_uid; in copy_cred()
2326 target->cr_gid = source->cr_gid; in copy_cred()
2327 target->cr_group_info = source->cr_group_info; in copy_cred()
2328 get_group_info(target->cr_group_info); in copy_cred()
2329 target->cr_gss_mech = source->cr_gss_mech; in copy_cred()
2330 if (source->cr_gss_mech) in copy_cred()
2331 gss_mech_get(source->cr_gss_mech); in copy_cred()
2338 if (o1->len < o2->len) in compare_blob()
2339 return -1; in compare_blob()
2340 if (o1->len > o2->len) in compare_blob()
2342 return memcmp(o1->data, o2->data, o1->len); in compare_blob()
2348 return 0 == memcmp(v1->data, v2->data, sizeof(v1->data)); in same_verf()
2354 return (cl1->cl_boot == cl2->cl_boot) && (cl1->cl_id == cl2->cl_id); in same_clid()
2361 if (g1->ngroups != g2->ngroups) in groups_equal()
2363 for (i=0; i<g1->ngroups; i++) in groups_equal()
2364 if (!gid_eq(g1->gid[i], g2->gid[i])) in groups_equal()
2373 * approximation. We also don't want to allow non-gss use of a client
2381 return (cr->cr_flavor > RPC_AUTH_MAXFLAVOR); in is_gss_cred()
2389 || (!uid_eq(cr1->cr_uid, cr2->cr_uid)) in same_creds()
2390 || (!gid_eq(cr1->cr_gid, cr2->cr_gid)) in same_creds()
2391 || !groups_equal(cr1->cr_group_info, cr2->cr_group_info)) in same_creds()
2394 if (cr1->cr_principal == cr2->cr_principal) in same_creds()
2396 if (!cr1->cr_principal || !cr2->cr_principal) in same_creds()
2398 return 0 == strcmp(cr1->cr_principal, cr2->cr_principal); in same_creds()
2403 struct svc_cred *cr = &rqstp->rq_cred; in svc_rqst_integrity_protected()
2406 if (!cr->cr_gss_mech) in svc_rqst_integrity_protected()
2408 service = gss_pseudoflavor_to_service(cr->cr_gss_mech, cr->cr_flavor); in svc_rqst_integrity_protected()
2415 struct svc_cred *cr = &rqstp->rq_cred; in nfsd4_mach_creds_match()
2417 if (!cl->cl_mach_cred) in nfsd4_mach_creds_match()
2419 if (cl->cl_cred.cr_gss_mech != cr->cr_gss_mech) in nfsd4_mach_creds_match()
2423 if (cl->cl_cred.cr_raw_principal) in nfsd4_mach_creds_match()
2424 return 0 == strcmp(cl->cl_cred.cr_raw_principal, in nfsd4_mach_creds_match()
2425 cr->cr_raw_principal); in nfsd4_mach_creds_match()
2426 if (!cr->cr_principal) in nfsd4_mach_creds_match()
2428 return 0 == strcmp(cl->cl_cred.cr_principal, cr->cr_principal); in nfsd4_mach_creds_match()
2436 * This is opaque to client, so no need to byte-swap. Use in gen_confirm()
2440 verf[1] = (__force __be32)nn->clverifier_counter++; in gen_confirm()
2441 memcpy(clp->cl_confirm.data, verf, sizeof(clp->cl_confirm.data)); in gen_confirm()
2446 clp->cl_clientid.cl_boot = (u32)nn->boot_time; in gen_clid()
2447 clp->cl_clientid.cl_id = nn->clientid_counter++; in gen_clid()
2456 ret = idr_find(&cl->cl_stateids, t->si_opaque.so_id); in find_stateid_locked()
2457 if (!ret || !ret->sc_type) in find_stateid_locked()
2467 spin_lock(&cl->cl_lock); in find_stateid_by_type()
2470 if (typemask & s->sc_type) in find_stateid_by_type()
2471 refcount_inc(&s->sc_count); in find_stateid_by_type()
2475 spin_unlock(&cl->cl_lock); in find_stateid_by_type()
2512 struct inode *inode = file_inode(m->file); in client_info_show()
2518 return -ENXIO; in client_info_show()
2519 memcpy(&clid, &clp->cl_clientid, sizeof(clid)); in client_info_show()
2521 seq_printf(m, "address: \"%pISpc\"\n", (struct sockaddr *)&clp->cl_addr); in client_info_show()
2523 if (clp->cl_state == NFSD4_COURTESY) in client_info_show()
2525 else if (clp->cl_state == NFSD4_EXPIRABLE) in client_info_show()
2527 else if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) in client_info_show()
2532 ktime_get_boottime_seconds() - clp->cl_time); in client_info_show()
2534 seq_quote_mem(m, clp->cl_name.data, clp->cl_name.len); in client_info_show()
2535 seq_printf(m, "\nminor version: %d\n", clp->cl_minorversion); in client_info_show()
2536 if (clp->cl_nii_domain.data) { in client_info_show()
2538 seq_quote_mem(m, clp->cl_nii_domain.data, in client_info_show()
2539 clp->cl_nii_domain.len); in client_info_show()
2541 seq_quote_mem(m, clp->cl_nii_name.data, clp->cl_nii_name.len); in client_info_show()
2543 clp->cl_nii_time.tv_sec, clp->cl_nii_time.tv_nsec); in client_info_show()
2545 seq_printf(m, "callback state: %s\n", cb_state2str(clp->cl_cb_state)); in client_info_show()
2546 seq_printf(m, "callback address: %pISpc\n", &clp->cl_cb_conn.cb_addr); in client_info_show()
2555 __acquires(&clp->cl_lock) in states_start()
2557 struct nfs4_client *clp = s->private; in states_start()
2561 spin_lock(&clp->cl_lock); in states_start()
2562 ret = idr_get_next_ul(&clp->cl_stateids, &id); in states_start()
2569 struct nfs4_client *clp = s->private; in states_next()
2575 ret = idr_get_next_ul(&clp->cl_stateids, &id); in states_next()
2581 __releases(&clp->cl_lock) in states_stop()
2583 struct nfs4_client *clp = s->private; in states_stop()
2585 spin_unlock(&clp->cl_lock); in states_stop()
2590 seq_printf(s, "filename: \"%pD2\"", f->nf_file); in nfs4_show_fname()
2595 struct inode *inode = file_inode(f->nf_file); in nfs4_show_superblock()
2598 MAJOR(inode->i_sb->s_dev), in nfs4_show_superblock()
2599 MINOR(inode->i_sb->s_dev), in nfs4_show_superblock()
2600 inode->i_ino); in nfs4_show_superblock()
2606 seq_quote_mem(s, oo->so_owner.data, oo->so_owner.len); in nfs4_show_owner()
2611 seq_printf(s, "0x%.8x", stid->si_generation); in nfs4_show_stateid()
2612 seq_printf(s, "%12phN", &stid->si_opaque); in nfs4_show_stateid()
2623 if (st->sc_type != NFS4_OPEN_STID && st->sc_type != NFS4_LOCK_STID) in nfs4_show_open()
2626 oo = ols->st_stateowner; in nfs4_show_open()
2627 nf = st->sc_file; in nfs4_show_open()
2629 spin_lock(&nf->fi_lock); in nfs4_show_open()
2634 seq_printf(s, "- "); in nfs4_show_open()
2635 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_open()
2638 access = bmap_to_share_mode(ols->st_access_bmap); in nfs4_show_open()
2639 deny = bmap_to_share_mode(ols->st_deny_bmap); in nfs4_show_open()
2642 access & NFS4_SHARE_ACCESS_READ ? "r" : "-", in nfs4_show_open()
2643 access & NFS4_SHARE_ACCESS_WRITE ? "w" : "-"); in nfs4_show_open()
2645 deny & NFS4_SHARE_ACCESS_READ ? "r" : "-", in nfs4_show_open()
2646 deny & NFS4_SHARE_ACCESS_WRITE ? "w" : "-"); in nfs4_show_open()
2655 spin_unlock(&nf->fi_lock); in nfs4_show_open()
2667 oo = ols->st_stateowner; in nfs4_show_lock()
2668 nf = st->sc_file; in nfs4_show_lock()
2669 spin_lock(&nf->fi_lock); in nfs4_show_lock()
2674 seq_printf(s, "- "); in nfs4_show_lock()
2675 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_lock()
2693 spin_unlock(&nf->fi_lock); in nfs4_show_lock()
2704 nf = st->sc_file; in nfs4_show_deleg()
2705 spin_lock(&nf->fi_lock); in nfs4_show_deleg()
2706 file = nf->fi_deleg_file; in nfs4_show_deleg()
2710 seq_printf(s, "- "); in nfs4_show_deleg()
2711 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_deleg()
2716 ds->dl_type == NFS4_OPEN_DELEGATE_READ ? "r" : "w"); in nfs4_show_deleg()
2725 spin_unlock(&nf->fi_lock); in nfs4_show_deleg()
2735 file = ls->ls_file; in nfs4_show_layout()
2737 seq_printf(s, "- "); in nfs4_show_layout()
2738 nfs4_show_stateid(s, &st->sc_stateid); in nfs4_show_layout()
2755 switch (st->sc_type) { in states_show()
2785 return -ENXIO; in client_states_open()
2790 s = file->private_data; in client_states_open()
2791 s->private = clp; in client_states_open()
2797 struct seq_file *m = file->private_data; in client_opens_release()
2798 struct nfs4_client *clp = m->private; in client_opens_release()
2820 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in force_expire_client()
2823 trace_nfsd_clid_admin_expired(&clp->cl_clientid); in force_expire_client()
2825 spin_lock(&nn->client_lock); in force_expire_client()
2826 clp->cl_time = 0; in force_expire_client()
2827 spin_unlock(&nn->client_lock); in force_expire_client()
2829 wait_event(expiry_wq, atomic_read(&clp->cl_rpc_users) == 0); in force_expire_client()
2830 spin_lock(&nn->client_lock); in force_expire_client()
2831 already_expired = list_empty(&clp->cl_lru); in force_expire_client()
2834 spin_unlock(&nn->client_lock); in force_expire_client()
2839 wait_event(expiry_wq, clp->cl_nfsd_dentry == NULL); in force_expire_client()
2852 return -EINVAL; in client_ctl_write()
2855 return -ENXIO; in client_ctl_write()
2878 switch (task->tk_status) { in nfsd4_cb_recall_any_done()
2879 case -NFS4ERR_DELAY: in nfsd4_cb_recall_any_done()
2890 struct nfs4_client *clp = cb->cb_clp; in nfsd4_cb_recall_any_release()
2891 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in nfsd4_cb_recall_any_release()
2893 spin_lock(&nn->client_lock); in nfsd4_cb_recall_any_release()
2894 clear_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags); in nfsd4_cb_recall_any_release()
2896 spin_unlock(&nn->client_lock); in nfsd4_cb_recall_any_release()
2918 ret = copy_cred(&clp->cl_cred, &rqstp->rq_cred); in create_client()
2924 kref_init(&clp->cl_nfsdfs.cl_ref); in create_client()
2925 nfsd4_init_cb(&clp->cl_cb_null, clp, NULL, NFSPROC4_CLNT_CB_NULL); in create_client()
2926 clp->cl_time = ktime_get_boottime_seconds(); in create_client()
2927 clear_bit(0, &clp->cl_cb_slot_busy); in create_client()
2929 memcpy(&clp->cl_addr, sa, sizeof(struct sockaddr_storage)); in create_client()
2930 clp->cl_cb_session = NULL; in create_client()
2931 clp->net = net; in create_client()
2932 clp->cl_nfsd_dentry = nfsd_client_mkdir( in create_client()
2933 nn, &clp->cl_nfsdfs, in create_client()
2934 clp->cl_clientid.cl_id - nn->clientid_base, in create_client()
2936 clp->cl_nfsd_info_dentry = dentries[0]; in create_client()
2937 if (!clp->cl_nfsd_dentry) { in create_client()
2941 clp->cl_ra = kzalloc(sizeof(*clp->cl_ra), GFP_KERNEL); in create_client()
2942 if (!clp->cl_ra) { in create_client()
2946 clp->cl_ra_time = 0; in create_client()
2947 nfsd4_init_cb(&clp->cl_ra->ra_cb, clp, &nfsd4_cb_recall_any_ops, in create_client()
2955 struct rb_node **new = &(root->rb_node), *parent = NULL; in add_clp_to_name_tree()
2962 if (compare_blob(&clp->cl_name, &new_clp->cl_name) > 0) in add_clp_to_name_tree()
2963 new = &((*new)->rb_left); in add_clp_to_name_tree()
2965 new = &((*new)->rb_right); in add_clp_to_name_tree()
2968 rb_link_node(&new_clp->cl_namenode, parent, new); in add_clp_to_name_tree()
2969 rb_insert_color(&new_clp->cl_namenode, root); in add_clp_to_name_tree()
2976 struct rb_node *node = root->rb_node; in find_clp_in_name_tree()
2981 cmp = compare_blob(&clp->cl_name, name); in find_clp_in_name_tree()
2983 node = node->rb_left; in find_clp_in_name_tree()
2985 node = node->rb_right; in find_clp_in_name_tree()
2996 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in add_to_unconfirmed()
2998 lockdep_assert_held(&nn->client_lock); in add_to_unconfirmed()
3000 clear_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags); in add_to_unconfirmed()
3001 add_clp_to_name_tree(clp, &nn->unconf_name_tree); in add_to_unconfirmed()
3002 idhashval = clientid_hashval(clp->cl_clientid.cl_id); in add_to_unconfirmed()
3003 list_add(&clp->cl_idhash, &nn->unconf_id_hashtbl[idhashval]); in add_to_unconfirmed()
3010 unsigned int idhashval = clientid_hashval(clp->cl_clientid.cl_id); in move_to_confirmed()
3011 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); in move_to_confirmed()
3013 lockdep_assert_held(&nn->client_lock); in move_to_confirmed()
3015 list_move(&clp->cl_idhash, &nn->conf_id_hashtbl[idhashval]); in move_to_confirmed()
3016 rb_erase(&clp->cl_namenode, &nn->unconf_name_tree); in move_to_confirmed()
3017 add_clp_to_name_tree(clp, &nn->conf_name_tree); in move_to_confirmed()
3018 set_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags); in move_to_confirmed()
3019 trace_nfsd_clid_confirmed(&clp->cl_clientid); in move_to_confirmed()
3027 unsigned int idhashval = clientid_hashval(clid->cl_id); in find_client_in_id_table()
3030 if (same_clid(&clp->cl_clientid, clid)) { in find_client_in_id_table()
3031 if ((bool)clp->cl_minorversion != sessions) in find_client_in_id_table()
3043 struct list_head *tbl = nn->conf_id_hashtbl; in find_confirmed_client()
3045 lockdep_assert_held(&nn->client_lock); in find_confirmed_client()
3052 struct list_head *tbl = nn->unconf_id_hashtbl; in find_unconfirmed_client()
3054 lockdep_assert_held(&nn->client_lock); in find_unconfirmed_client()
3060 return clp->cl_exchange_flags != 0; in clp_used_exchangeid()
3066 lockdep_assert_held(&nn->client_lock); in find_confirmed_client_by_name()
3067 return find_clp_in_name_tree(name, &nn->conf_name_tree); in find_confirmed_client_by_name()
3073 lockdep_assert_held(&nn->client_lock); in find_unconfirmed_client_by_name()
3074 return find_clp_in_name_tree(name, &nn->unconf_name_tree); in find_unconfirmed_client_by_name()
3080 struct nfs4_cb_conn *conn = &clp->cl_cb_conn; in gen_callback()
3086 if (se->se_callback_netid_len == 3 && in gen_callback()
3087 !memcmp(se->se_callback_netid_val, "tcp", 3)) in gen_callback()
3089 else if (se->se_callback_netid_len == 4 && in gen_callback()
3090 !memcmp(se->se_callback_netid_val, "tcp6", 4)) in gen_callback()
3095 conn->cb_addrlen = rpc_uaddr2sockaddr(clp->net, se->se_callback_addr_val, in gen_callback()
3096 se->se_callback_addr_len, in gen_callback()
3097 (struct sockaddr *)&conn->cb_addr, in gen_callback()
3098 sizeof(conn->cb_addr)); in gen_callback()
3100 if (!conn->cb_addrlen || conn->cb_addr.ss_family != expected_family) in gen_callback()
3103 if (conn->cb_addr.ss_family == AF_INET6) in gen_callback()
3104 ((struct sockaddr_in6 *)&conn->cb_addr)->sin6_scope_id = scopeid; in gen_callback()
3106 conn->cb_prog = se->se_callback_prog; in gen_callback()
3107 conn->cb_ident = se->se_callback_ident; in gen_callback()
3108 memcpy(&conn->cb_saddr, &rqstp->rq_daddr, rqstp->rq_daddrlen); in gen_callback()
3112 conn->cb_addr.ss_family = AF_UNSPEC; in gen_callback()
3113 conn->cb_addrlen = 0; in gen_callback()
3124 struct xdr_buf *buf = resp->xdr->buf; in nfsd4_store_cache_entry()
3125 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_store_cache_entry()
3128 dprintk("--> %s slot %p\n", __func__, slot); in nfsd4_store_cache_entry()
3130 slot->sl_flags |= NFSD4_SLOT_INITIALIZED; in nfsd4_store_cache_entry()
3131 slot->sl_opcnt = resp->opcnt; in nfsd4_store_cache_entry()
3132 slot->sl_status = resp->cstate.status; in nfsd4_store_cache_entry()
3133 free_svc_cred(&slot->sl_cred); in nfsd4_store_cache_entry()
3134 copy_cred(&slot->sl_cred, &resp->rqstp->rq_cred); in nfsd4_store_cache_entry()
3137 slot->sl_flags &= ~NFSD4_SLOT_CACHED; in nfsd4_store_cache_entry()
3140 slot->sl_flags |= NFSD4_SLOT_CACHED; in nfsd4_store_cache_entry()
3142 base = resp->cstate.data_offset; in nfsd4_store_cache_entry()
3143 slot->sl_datalen = buf->len - base; in nfsd4_store_cache_entry()
3144 if (read_bytes_from_xdr_buf(buf, base, slot->sl_data, slot->sl_datalen)) in nfsd4_store_cache_entry()
3153 * operation which sets resp->p and increments resp->opcnt for
3162 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_enc_sequence_replay()
3165 op = &args->ops[resp->opcnt - 1]; in nfsd4_enc_sequence_replay()
3168 if (slot->sl_flags & NFSD4_SLOT_CACHED) in nfsd4_enc_sequence_replay()
3169 return op->status; in nfsd4_enc_sequence_replay()
3170 if (args->opcnt == 1) { in nfsd4_enc_sequence_replay()
3172 * The original operation wasn't a solo sequence--we in nfsd4_enc_sequence_replay()
3173 * always cache those--so this retry must not match the in nfsd4_enc_sequence_replay()
3176 op->status = nfserr_seq_false_retry; in nfsd4_enc_sequence_replay()
3178 op = &args->ops[resp->opcnt++]; in nfsd4_enc_sequence_replay()
3179 op->status = nfserr_retry_uncached_rep; in nfsd4_enc_sequence_replay()
3182 return op->status; in nfsd4_enc_sequence_replay()
3193 struct nfsd4_slot *slot = resp->cstate.slot; in nfsd4_replay_cache_entry()
3194 struct xdr_stream *xdr = resp->xdr; in nfsd4_replay_cache_entry()
3198 dprintk("--> %s slot %p\n", __func__, slot); in nfsd4_replay_cache_entry()
3200 status = nfsd4_enc_sequence_replay(resp->rqstp->rq_argp, resp); in nfsd4_replay_cache_entry()
3204 p = xdr_reserve_space(xdr, slot->sl_datalen); in nfsd4_replay_cache_entry()
3209 xdr_encode_opaque_fixed(p, slot->sl_data, slot->sl_datalen); in nfsd4_replay_cache_entry()
3212 resp->opcnt = slot->sl_opcnt; in nfsd4_replay_cache_entry()
3213 return slot->sl_status; in nfsd4_replay_cache_entry()
3223 new->cl_exchange_flags |= EXCHGID4_FLAG_USE_PNFS_MDS; in nfsd4_set_ex_flags()
3225 new->cl_exchange_flags |= EXCHGID4_FLAG_USE_NON_PNFS; in nfsd4_set_ex_flags()
3229 new->cl_exchange_flags |= EXCHGID4_FLAG_SUPP_MOVED_REFER; in nfsd4_set_ex_flags()
3232 clid->flags = new->cl_exchange_flags; in nfsd4_set_ex_flags()
3239 list_for_each_entry(oo, &clp->cl_openowners, oo_perclient) { in client_has_openowners()
3240 if (!list_empty(&oo->oo_owner.so_stateids)) in client_has_openowners()
3250 || !list_empty(&clp->cl_lo_states) in client_has_state()
3252 || !list_empty(&clp->cl_delegations) in client_has_state()
3253 || !list_empty(&clp->cl_sessions) in client_has_state()
3254 || !list_empty(&clp->async_copies); in client_has_state()
3260 if (!exid->nii_domain.data) in copy_impl_id()
3262 xdr_netobj_dup(&clp->cl_nii_domain, &exid->nii_domain, GFP_KERNEL); in copy_impl_id()
3263 if (!clp->cl_nii_domain.data) in copy_impl_id()
3265 xdr_netobj_dup(&clp->cl_nii_name, &exid->nii_name, GFP_KERNEL); in copy_impl_id()
3266 if (!clp->cl_nii_name.data) in copy_impl_id()
3268 clp->cl_nii_time = exid->nii_time; in copy_impl_id()
3276 struct nfsd4_exchange_id *exid = &u->exchange_id; in nfsd4_exchange_id()
3281 nfs4_verifier verf = exid->verifier; in nfsd4_exchange_id()
3283 bool update = exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A; in nfsd4_exchange_id()
3289 __func__, rqstp, exid, exid->clname.len, exid->clname.data, in nfsd4_exchange_id()
3290 addr_str, exid->flags, exid->spa_how); in nfsd4_exchange_id()
3292 if (exid->flags & ~EXCHGID4_FLAG_MASK_A) in nfsd4_exchange_id()
3295 new = create_client(exid->clname, rqstp, &verf); in nfsd4_exchange_id()
3302 switch (exid->spa_how) { in nfsd4_exchange_id()
3304 exid->spo_must_enforce[0] = 0; in nfsd4_exchange_id()
3305 exid->spo_must_enforce[1] = ( in nfsd4_exchange_id()
3306 1 << (OP_BIND_CONN_TO_SESSION - 32) | in nfsd4_exchange_id()
3307 1 << (OP_EXCHANGE_ID - 32) | in nfsd4_exchange_id()
3308 1 << (OP_CREATE_SESSION - 32) | in nfsd4_exchange_id()
3309 1 << (OP_DESTROY_SESSION - 32) | in nfsd4_exchange_id()
3310 1 << (OP_DESTROY_CLIENTID - 32)); in nfsd4_exchange_id()
3312 exid->spo_must_allow[0] &= (1 << (OP_CLOSE) | in nfsd4_exchange_id()
3317 exid->spo_must_allow[1] &= ( in nfsd4_exchange_id()
3318 1 << (OP_TEST_STATEID - 32) | in nfsd4_exchange_id()
3319 1 << (OP_FREE_STATEID - 32)); in nfsd4_exchange_id()
3329 if (!new->cl_cred.cr_principal && in nfsd4_exchange_id()
3330 !new->cl_cred.cr_raw_principal) { in nfsd4_exchange_id()
3334 new->cl_mach_cred = true; in nfsd4_exchange_id()
3347 spin_lock(&nn->client_lock); in nfsd4_exchange_id()
3348 conf = find_confirmed_client_by_name(&exid->clname, nn); in nfsd4_exchange_id()
3350 bool creds_match = same_creds(&conf->cl_cred, &rqstp->rq_cred); in nfsd4_exchange_id()
3351 bool verfs_match = same_verf(&verf, &conf->cl_verifier); in nfsd4_exchange_id()
3371 exid->flags |= EXCHGID4_FLAG_CONFIRMED_R; in nfsd4_exchange_id()
3384 conf->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R; in nfsd4_exchange_id()
3399 unconf = find_unconfirmed_client_by_name(&exid->clname, nn); in nfsd4_exchange_id()
3411 trace_nfsd_clid_replaced(&conf->cl_clientid); in nfsd4_exchange_id()
3413 new->cl_minorversion = cstate->minorversion; in nfsd4_exchange_id()
3414 new->cl_spo_must_allow.u.words[0] = exid->spo_must_allow[0]; in nfsd4_exchange_id()
3415 new->cl_spo_must_allow.u.words[1] = exid->spo_must_allow[1]; in nfsd4_exchange_id()
3420 exid->clientid.cl_boot = conf->cl_clientid.cl_boot; in nfsd4_exchange_id()
3421 exid->clientid.cl_id = conf->cl_clientid.cl_id; in nfsd4_exchange_id()
3423 exid->seqid = conf->cl_cs_slot.sl_seqid + 1; in nfsd4_exchange_id()
3427 conf->cl_cs_slot.sl_seqid, conf->cl_exchange_flags); in nfsd4_exchange_id()
3431 spin_unlock(&nn->client_lock); in nfsd4_exchange_id()
3436 trace_nfsd_clid_expire_unconf(&unconf->cl_clientid); in nfsd4_exchange_id()
3455 /* Note unsigned 32-bit arithmetic handles wraparound: */ in check_slot_seqid()
3466 * Do this for solo or embedded create session operations.
3472 slot->sl_status = nfserr; in nfsd4_cache_create_session()
3473 memcpy(&slot->sl_cr_ses, cr_ses, sizeof(*cr_ses)); in nfsd4_cache_create_session()
3480 memcpy(cr_ses, &slot->sl_cr_ses, sizeof(*cr_ses)); in nfsd4_replay_create_session()
3481 return slot->sl_status; in nfsd4_replay_create_session()
3503 u32 maxrpc = nn->nfsd_serv->sv_max_mesg; in check_forechannel_attrs()
3505 if (ca->maxreq_sz < NFSD_MIN_REQ_HDR_SEQ_SZ) in check_forechannel_attrs()
3507 if (ca->maxresp_sz < NFSD_MIN_RESP_HDR_SEQ_SZ) in check_forechannel_attrs()
3509 ca->headerpadsz = 0; in check_forechannel_attrs()
3510 ca->maxreq_sz = min_t(u32, ca->maxreq_sz, maxrpc); in check_forechannel_attrs()
3511 ca->maxresp_sz = min_t(u32, ca->maxresp_sz, maxrpc); in check_forechannel_attrs()
3512 ca->maxops = min_t(u32, ca->maxops, NFSD_MAX_OPS_PER_COMPOUND); in check_forechannel_attrs()
3513 ca->maxresp_cached = min_t(u32, ca->maxresp_cached, in check_forechannel_attrs()
3515 ca->maxreqs = min_t(u32, ca->maxreqs, NFSD_MAX_SLOTS_PER_SESSION); in check_forechannel_attrs()
3526 ca->maxreqs = nfsd4_get_drc_mem(ca, nn); in check_forechannel_attrs()
3532 * Server's NFSv4.1 backchannel support is AUTH_SYS-only for now.
3549 ca->headerpadsz = 0; in check_backchannel_attrs()
3551 if (ca->maxreq_sz < NFSD_CB_MAX_REQ_SZ) in check_backchannel_attrs()
3553 if (ca->maxresp_sz < NFSD_CB_MAX_RESP_SZ) in check_backchannel_attrs()
3555 ca->maxresp_cached = 0; in check_backchannel_attrs()
3556 if (ca->maxops < 2) in check_backchannel_attrs()
3564 switch (cbs->flavor) { in nfsd4_check_cb_sec()
3584 struct nfsd4_create_session *cr_ses = &u->create_session; in nfsd4_create_session()
3594 if (cr_ses->flags & ~SESSION4_FLAG_MASK_A) in nfsd4_create_session()
3596 status = nfsd4_check_cb_sec(&cr_ses->cb_sec); in nfsd4_create_session()
3599 status = check_forechannel_attrs(&cr_ses->fore_channel, nn); in nfsd4_create_session()
3602 status = check_backchannel_attrs(&cr_ses->back_channel); in nfsd4_create_session()
3606 new = alloc_session(&cr_ses->fore_channel, &cr_ses->back_channel); in nfsd4_create_session()
3613 spin_lock(&nn->client_lock); in nfsd4_create_session()
3614 unconf = find_unconfirmed_client(&cr_ses->clientid, true, nn); in nfsd4_create_session()
3615 conf = find_confirmed_client(&cr_ses->clientid, true, nn); in nfsd4_create_session()
3622 cs_slot = &conf->cl_cs_slot; in nfsd4_create_session()
3623 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); in nfsd4_create_session()
3631 if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred) || in nfsd4_create_session()
3632 !rpc_cmp_addr(sa, (struct sockaddr *) &unconf->cl_addr)) { in nfsd4_create_session()
3639 cs_slot = &unconf->cl_cs_slot; in nfsd4_create_session()
3640 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); in nfsd4_create_session()
3646 old = find_confirmed_client_by_name(&unconf->cl_name, nn); in nfsd4_create_session()
3653 trace_nfsd_clid_replaced(&old->cl_clientid); in nfsd4_create_session()
3663 cr_ses->flags &= ~SESSION4_PERSIST; in nfsd4_create_session()
3665 cr_ses->flags &= ~SESSION4_RDMA; in nfsd4_create_session()
3670 memcpy(cr_ses->sessionid.data, new->se_sessionid.data, in nfsd4_create_session()
3672 cs_slot->sl_seqid++; in nfsd4_create_session()
3673 cr_ses->seqid = cs_slot->sl_seqid; in nfsd4_create_session()
3675 /* cache solo and embedded create sessions under the client_lock */ in nfsd4_create_session()
3677 spin_unlock(&nn->client_lock); in nfsd4_create_session()
3679 fsnotify_dentry(conf->cl_nfsd_info_dentry, FS_MODIFY); in nfsd4_create_session()
3687 spin_unlock(&nn->client_lock); in nfsd4_create_session()
3694 nfsd4_put_drc_mem(&cr_ses->fore_channel); in nfsd4_create_session()
3716 struct nfsd4_backchannel_ctl *bc = &u->backchannel_ctl; in nfsd4_backchannel_ctl()
3717 struct nfsd4_session *session = cstate->session; in nfsd4_backchannel_ctl()
3721 status = nfsd4_check_cb_sec(&bc->bc_cb_sec); in nfsd4_backchannel_ctl()
3724 spin_lock(&nn->client_lock); in nfsd4_backchannel_ctl()
3725 session->se_cb_prog = bc->bc_cb_program; in nfsd4_backchannel_ctl()
3726 session->se_cb_sec = bc->bc_cb_sec; in nfsd4_backchannel_ctl()
3727 spin_unlock(&nn->client_lock); in nfsd4_backchannel_ctl()
3729 nfsd4_probe_callback(session->se_client); in nfsd4_backchannel_ctl()
3738 list_for_each_entry(c, &s->se_conns, cn_persession) { in __nfsd4_find_conn()
3739 if (c->cn_xprt == xpt) { in __nfsd4_find_conn()
3749 struct nfs4_client *clp = session->se_client; in nfsd4_match_existing_connection()
3750 struct svc_xprt *xpt = rqst->rq_xprt; in nfsd4_match_existing_connection()
3755 spin_lock(&clp->cl_lock); in nfsd4_match_existing_connection()
3759 else if (req == c->cn_flags) in nfsd4_match_existing_connection()
3762 c->cn_flags != NFS4_CDFC4_BACK) in nfsd4_match_existing_connection()
3765 c->cn_flags != NFS4_CDFC4_FORE) in nfsd4_match_existing_connection()
3769 spin_unlock(&clp->cl_lock); in nfsd4_match_existing_connection()
3779 struct nfsd4_bind_conn_to_session *bcts = &u->bind_conn_to_session; in nfsd4_bind_conn_to_session()
3788 spin_lock(&nn->client_lock); in nfsd4_bind_conn_to_session()
3789 session = find_in_sessionid_hashtbl(&bcts->sessionid, net, &status); in nfsd4_bind_conn_to_session()
3790 spin_unlock(&nn->client_lock); in nfsd4_bind_conn_to_session()
3794 if (!nfsd4_mach_creds_match(session->se_client, rqstp)) in nfsd4_bind_conn_to_session()
3797 bcts->dir, &conn); in nfsd4_bind_conn_to_session()
3799 if (bcts->dir == NFS4_CDFC4_FORE_OR_BOTH || in nfsd4_bind_conn_to_session()
3800 bcts->dir == NFS4_CDFC4_BACK) in nfsd4_bind_conn_to_session()
3801 conn->cn_flags |= NFS4_CDFC4_BACK; in nfsd4_bind_conn_to_session()
3802 nfsd4_probe_callback(session->se_client); in nfsd4_bind_conn_to_session()
3807 status = nfsd4_map_bcts_dir(&bcts->dir); in nfsd4_bind_conn_to_session()
3810 conn = alloc_conn(rqstp, bcts->dir); in nfsd4_bind_conn_to_session()
3824 if (!cstate->session) in nfsd4_compound_in_session()
3826 return !memcmp(sid, &cstate->session->se_sessionid, sizeof(*sid)); in nfsd4_compound_in_session()
3833 struct nfs4_sessionid *sessionid = &u->destroy_session.sessionid; in nfsd4_destroy_session()
3847 spin_lock(&nn->client_lock); in nfsd4_destroy_session()
3852 if (!nfsd4_mach_creds_match(ses->se_client, r)) in nfsd4_destroy_session()
3858 spin_unlock(&nn->client_lock); in nfsd4_destroy_session()
3860 nfsd4_probe_callback_sync(ses->se_client); in nfsd4_destroy_session()
3862 spin_lock(&nn->client_lock); in nfsd4_destroy_session()
3867 spin_unlock(&nn->client_lock); in nfsd4_destroy_session()
3874 struct nfs4_client *clp = ses->se_client; in nfsd4_sequence_check_conn()
3879 spin_lock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3880 c = __nfsd4_find_conn(new->cn_xprt, ses); in nfsd4_sequence_check_conn()
3884 if (clp->cl_mach_cred) in nfsd4_sequence_check_conn()
3887 spin_unlock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3891 nfsd4_conn_lost(&new->cn_xpt_user); in nfsd4_sequence_check_conn()
3894 spin_unlock(&clp->cl_lock); in nfsd4_sequence_check_conn()
3901 struct nfsd4_compoundargs *args = rqstp->rq_argp; in nfsd4_session_too_many_ops()
3903 return args->opcnt > session->se_fchannel.maxops; in nfsd4_session_too_many_ops()
3909 struct xdr_buf *xb = &rqstp->rq_arg; in nfsd4_request_too_big()
3911 return xb->len > session->se_fchannel.maxreq_sz; in nfsd4_request_too_big()
3917 struct nfsd4_compoundargs *argp = rqstp->rq_argp; in replay_matches_cache()
3919 if ((bool)(slot->sl_flags & NFSD4_SLOT_CACHETHIS) != in replay_matches_cache()
3920 (bool)seq->cachethis) in replay_matches_cache()
3926 if (slot->sl_opcnt < argp->opcnt && !slot->sl_status) in replay_matches_cache()
3933 if (slot->sl_opcnt > argp->opcnt) in replay_matches_cache()
3936 if (!same_creds(&rqstp->rq_cred, &slot->sl_cred)) in replay_matches_cache()
3951 struct nfsd4_sequence *seq = &u->sequence; in nfsd4_sequence()
3952 struct nfsd4_compoundres *resp = rqstp->rq_resp; in nfsd4_sequence()
3953 struct xdr_stream *xdr = resp->xdr; in nfsd4_sequence()
3963 if (resp->opcnt != 1) in nfsd4_sequence()
3974 spin_lock(&nn->client_lock); in nfsd4_sequence()
3975 session = find_in_sessionid_hashtbl(&seq->sessionid, net, &status); in nfsd4_sequence()
3978 clp = session->se_client; in nfsd4_sequence()
3989 if (seq->slotid >= session->se_fchannel.maxreqs) in nfsd4_sequence()
3992 slot = session->se_slots[seq->slotid]; in nfsd4_sequence()
3993 dprintk("%s: slotid %d\n", __func__, seq->slotid); in nfsd4_sequence()
3998 seq->maxslots = session->se_fchannel.maxreqs; in nfsd4_sequence()
4000 status = check_slot_seqid(seq->seqid, slot->sl_seqid, in nfsd4_sequence()
4001 slot->sl_flags & NFSD4_SLOT_INUSE); in nfsd4_sequence()
4004 if (!(slot->sl_flags & NFSD4_SLOT_INITIALIZED)) in nfsd4_sequence()
4009 cstate->slot = slot; in nfsd4_sequence()
4010 cstate->session = session; in nfsd4_sequence()
4011 cstate->clp = clp; in nfsd4_sequence()
4012 /* Return the cached reply status and set cstate->status in nfsd4_sequence()
4015 cstate->status = nfserr_replay_cache; in nfsd4_sequence()
4026 buflen = (seq->cachethis) ? in nfsd4_sequence()
4027 session->se_fchannel.maxresp_cached : in nfsd4_sequence()
4028 session->se_fchannel.maxresp_sz; in nfsd4_sequence()
4029 status = (seq->cachethis) ? nfserr_rep_too_big_to_cache : in nfsd4_sequence()
4031 if (xdr_restrict_buflen(xdr, buflen - rqstp->rq_auth_slack)) in nfsd4_sequence()
4037 slot->sl_seqid = seq->seqid; in nfsd4_sequence()
4038 slot->sl_flags |= NFSD4_SLOT_INUSE; in nfsd4_sequence()
4039 if (seq->cachethis) in nfsd4_sequence()
4040 slot->sl_flags |= NFSD4_SLOT_CACHETHIS; in nfsd4_sequence()
4042 slot->sl_flags &= ~NFSD4_SLOT_CACHETHIS; in nfsd4_sequence()
4044 cstate->slot = slot; in nfsd4_sequence()
4045 cstate->session = session; in nfsd4_sequence()
4046 cstate->clp = clp; in nfsd4_sequence()
4049 switch (clp->cl_cb_state) { in nfsd4_sequence()
4051 seq->status_flags = SEQ4_STATUS_CB_PATH_DOWN; in nfsd4_sequence()
4054 seq->status_flags = SEQ4_STATUS_BACKCHANNEL_FAULT; in nfsd4_sequence()
4057 seq->status_flags = 0; in nfsd4_sequence()
4059 if (!list_empty(&clp->cl_revoked)) in nfsd4_sequence()
4060 seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED; in nfsd4_sequence()
4064 spin_unlock(&nn->client_lock); in nfsd4_sequence()
4074 struct nfsd4_compound_state *cs = &resp->cstate; in nfsd4_sequence_done()
4077 if (cs->status != nfserr_replay_cache) { in nfsd4_sequence_done()
4079 cs->slot->sl_flags &= ~NFSD4_SLOT_INUSE; in nfsd4_sequence_done()
4082 nfsd4_put_session(cs->session); in nfsd4_sequence_done()
4083 } else if (cs->clp) in nfsd4_sequence_done()
4084 put_client_renew(cs->clp); in nfsd4_sequence_done()
4092 struct nfsd4_destroy_clientid *dc = &u->destroy_clientid; in nfsd4_destroy_clientid()
4098 spin_lock(&nn->client_lock); in nfsd4_destroy_clientid()
4099 unconf = find_unconfirmed_client(&dc->clientid, true, nn); in nfsd4_destroy_clientid()
4100 conf = find_confirmed_client(&dc->clientid, true, nn); in nfsd4_destroy_clientid()
4123 trace_nfsd_clid_destroyed(&clp->cl_clientid); in nfsd4_destroy_clientid()
4126 spin_unlock(&nn->client_lock); in nfsd4_destroy_clientid()
4136 struct nfsd4_reclaim_complete *rc = &u->reclaim_complete; in nfsd4_reclaim_complete()
4137 struct nfs4_client *clp = cstate->clp; in nfsd4_reclaim_complete()
4140 if (rc->rca_one_fs) { in nfsd4_reclaim_complete()
4141 if (!cstate->current_fh.fh_dentry) in nfsd4_reclaim_complete()
4151 if (test_and_set_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &clp->cl_flags)) in nfsd4_reclaim_complete()
4166 trace_nfsd_clid_reclaim_complete(&clp->cl_clientid); in nfsd4_reclaim_complete()
4177 struct nfsd4_setclientid *setclid = &u->setclientid; in nfsd4_setclientid()
4178 struct xdr_netobj clname = setclid->se_name; in nfsd4_setclientid()
4179 nfs4_verifier clverifier = setclid->se_verf; in nfsd4_setclientid()
4188 spin_lock(&nn->client_lock); in nfsd4_setclientid()
4194 if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid()
4203 if (same_verf(&conf->cl_verifier, &clverifier)) { in nfsd4_setclientid()
4211 new->cl_minorversion = 0; in nfsd4_setclientid()
4214 setclid->se_clientid.cl_boot = new->cl_clientid.cl_boot; in nfsd4_setclientid()
4215 setclid->se_clientid.cl_id = new->cl_clientid.cl_id; in nfsd4_setclientid()
4216 memcpy(setclid->se_confirm.data, new->cl_confirm.data, sizeof(setclid->se_confirm.data)); in nfsd4_setclientid()
4220 spin_unlock(&nn->client_lock); in nfsd4_setclientid()
4224 trace_nfsd_clid_expire_unconf(&unconf->cl_clientid); in nfsd4_setclientid()
4236 &u->setclientid_confirm; in nfsd4_setclientid_confirm()
4239 nfs4_verifier confirm = setclientid_confirm->sc_confirm; in nfsd4_setclientid_confirm()
4240 clientid_t * clid = &setclientid_confirm->sc_clientid; in nfsd4_setclientid_confirm()
4247 spin_lock(&nn->client_lock); in nfsd4_setclientid_confirm()
4258 if (unconf && !same_creds(&unconf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid_confirm()
4262 if (conf && !same_creds(&conf->cl_cred, &rqstp->rq_cred)) { in nfsd4_setclientid_confirm()
4266 if (!unconf || !same_verf(&confirm, &unconf->cl_confirm)) { in nfsd4_setclientid_confirm()
4267 if (conf && same_verf(&confirm, &conf->cl_confirm)) { in nfsd4_setclientid_confirm()
4277 nfsd4_change_callback(conf, &unconf->cl_cb_conn); in nfsd4_setclientid_confirm()
4279 old = find_confirmed_client_by_name(&unconf->cl_name, nn); in nfsd4_setclientid_confirm()
4283 && !same_creds(&unconf->cl_cred, in nfsd4_setclientid_confirm()
4284 &old->cl_cred)) { in nfsd4_setclientid_confirm()
4293 trace_nfsd_clid_replaced(&old->cl_clientid); in nfsd4_setclientid_confirm()
4299 spin_unlock(&nn->client_lock); in nfsd4_setclientid_confirm()
4301 fsnotify_dentry(conf->cl_nfsd_info_dentry, FS_MODIFY); in nfsd4_setclientid_confirm()
4303 spin_lock(&nn->client_lock); in nfsd4_setclientid_confirm()
4306 spin_unlock(&nn->client_lock); in nfsd4_setclientid_confirm()
4321 refcount_set(&fp->fi_ref, 1); in nfsd4_file_init()
4322 spin_lock_init(&fp->fi_lock); in nfsd4_file_init()
4323 INIT_LIST_HEAD(&fp->fi_stateids); in nfsd4_file_init()
4324 INIT_LIST_HEAD(&fp->fi_delegations); in nfsd4_file_init()
4325 INIT_LIST_HEAD(&fp->fi_clnt_odstate); in nfsd4_file_init()
4326 fh_copy_shallow(&fp->fi_fhandle, &fh->fh_handle); in nfsd4_file_init()
4327 fp->fi_deleg_file = NULL; in nfsd4_file_init()
4328 fp->fi_had_conflict = false; in nfsd4_file_init()
4329 fp->fi_share_deny = 0; in nfsd4_file_init()
4330 memset(fp->fi_fds, 0, sizeof(fp->fi_fds)); in nfsd4_file_init()
4331 memset(fp->fi_access, 0, sizeof(fp->fi_access)); in nfsd4_file_init()
4332 fp->fi_aliased = false; in nfsd4_file_init()
4333 fp->fi_inode = d_inode(fh->fh_dentry); in nfsd4_file_init()
4335 INIT_LIST_HEAD(&fp->fi_lo_states); in nfsd4_file_init()
4336 atomic_set(&fp->fi_lo_recalls, 0); in nfsd4_file_init()
4398 return -ENOMEM; in nfsd4_init_slabs()
4405 struct nfsd_net *nn = shrink->private_data; in nfsd4_state_shrinker_count()
4407 count = atomic_read(&nn->nfsd_courtesy_clients); in nfsd4_state_shrinker_count()
4411 queue_work(laundry_wq, &nn->nfsd_shrinker_work); in nfsd4_state_shrinker_count()
4427 nn->nfsd4_lease = 90; /* default lease time */ in nfsd4_init_leases_net()
4428 nn->nfsd4_grace = 90; in nfsd4_init_leases_net()
4429 nn->somebody_reclaimed = false; in nfsd4_init_leases_net()
4430 nn->track_reclaim_completes = false; in nfsd4_init_leases_net()
4431 nn->clverifier_counter = get_random_u32(); in nfsd4_init_leases_net()
4432 nn->clientid_base = get_random_u32(); in nfsd4_init_leases_net()
4433 nn->clientid_counter = nn->clientid_base + 1; in nfsd4_init_leases_net()
4434 nn->s2s_cp_cl_id = nn->clientid_counter++; in nfsd4_init_leases_net()
4436 atomic_set(&nn->nfs4_client_count, 0); in nfsd4_init_leases_net()
4440 nn->nfs4_max_clients = max_t(int, max_clients, NFS4_CLIENTS_PER_GB); in nfsd4_init_leases_net()
4442 atomic_set(&nn->nfsd_courtesy_clients, 0); in nfsd4_init_leases_net()
4447 rp->rp_status = nfserr_serverfault; in init_nfs4_replay()
4448 rp->rp_buflen = 0; in init_nfs4_replay()
4449 rp->rp_buf = rp->rp_ibuf; in init_nfs4_replay()
4450 mutex_init(&rp->rp_mutex); in init_nfs4_replay()
4457 mutex_lock(&so->so_replay.rp_mutex); in nfsd4_cstate_assign_replay()
4458 cstate->replay_owner = nfs4_get_stateowner(so); in nfsd4_cstate_assign_replay()
4464 struct nfs4_stateowner *so = cstate->replay_owner; in nfsd4_cstate_clear_replay()
4467 cstate->replay_owner = NULL; in nfsd4_cstate_clear_replay()
4468 mutex_unlock(&so->so_replay.rp_mutex); in nfsd4_cstate_clear_replay()
4481 xdr_netobj_dup(&sop->so_owner, owner, GFP_KERNEL); in alloc_stateowner()
4482 if (!sop->so_owner.data) { in alloc_stateowner()
4487 INIT_LIST_HEAD(&sop->so_stateids); in alloc_stateowner()
4488 sop->so_client = clp; in alloc_stateowner()
4489 init_nfs4_replay(&sop->so_replay); in alloc_stateowner()
4490 atomic_set(&sop->so_count, 1); in alloc_stateowner()
4496 lockdep_assert_held(&clp->cl_lock); in hash_openowner()
4498 list_add(&oo->oo_owner.so_strhash, in hash_openowner()
4499 &clp->cl_ownerstr_hashtbl[strhashval]); in hash_openowner()
4500 list_add(&oo->oo_perclient, &clp->cl_openowners); in hash_openowner()
4524 struct nfs4_openowner *oo = open->op_openowner; in nfsd4_find_existing_open()
4526 lockdep_assert_held(&fp->fi_lock); in nfsd4_find_existing_open()
4528 list_for_each_entry(local, &fp->fi_stateids, st_perfile) { in nfsd4_find_existing_open()
4530 if (local->st_stateowner->so_is_open_owner == 0) in nfsd4_find_existing_open()
4532 if (local->st_stateowner != &oo->oo_owner) in nfsd4_find_existing_open()
4534 if (local->st_stid.sc_type == NFS4_OPEN_STID) { in nfsd4_find_existing_open()
4536 refcount_inc(&ret->st_stid.sc_count); in nfsd4_find_existing_open()
4548 switch (s->sc_type) { in nfsd4_verify_open_stid()
4568 mutex_lock_nested(&stp->st_mutex, LOCK_STATEID_MUTEX); in nfsd4_lock_ol_stateid()
4569 ret = nfsd4_verify_open_stid(&stp->st_stid); in nfsd4_lock_ol_stateid()
4571 mutex_unlock(&stp->st_mutex); in nfsd4_lock_ol_stateid()
4580 spin_lock(&fp->fi_lock); in nfsd4_find_and_lock_existing_open()
4582 spin_unlock(&fp->fi_lock); in nfsd4_find_and_lock_existing_open()
4585 nfs4_put_stid(&stp->st_stid); in nfsd4_find_and_lock_existing_open()
4594 struct nfs4_client *clp = cstate->clp; in alloc_init_open_stateowner()
4597 oo = alloc_stateowner(openowner_slab, &open->op_owner, clp); in alloc_init_open_stateowner()
4600 oo->oo_owner.so_ops = &openowner_ops; in alloc_init_open_stateowner()
4601 oo->oo_owner.so_is_open_owner = 1; in alloc_init_open_stateowner()
4602 oo->oo_owner.so_seqid = open->op_seqid; in alloc_init_open_stateowner()
4603 oo->oo_flags = 0; in alloc_init_open_stateowner()
4605 oo->oo_flags |= NFS4_OO_CONFIRMED; in alloc_init_open_stateowner()
4606 oo->oo_time = 0; in alloc_init_open_stateowner()
4607 oo->oo_last_closed_stid = NULL; in alloc_init_open_stateowner()
4608 INIT_LIST_HEAD(&oo->oo_close_lru); in alloc_init_open_stateowner()
4609 spin_lock(&clp->cl_lock); in alloc_init_open_stateowner()
4615 nfs4_free_stateowner(&oo->oo_owner); in alloc_init_open_stateowner()
4617 spin_unlock(&clp->cl_lock); in alloc_init_open_stateowner()
4625 struct nfs4_openowner *oo = open->op_openowner; in init_open_stateid()
4629 stp = open->op_stp; in init_open_stateid()
4631 mutex_init(&stp->st_mutex); in init_open_stateid()
4632 mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX); in init_open_stateid()
4635 spin_lock(&oo->oo_owner.so_client->cl_lock); in init_open_stateid()
4636 spin_lock(&fp->fi_lock); in init_open_stateid()
4642 open->op_stp = NULL; in init_open_stateid()
4643 refcount_inc(&stp->st_stid.sc_count); in init_open_stateid()
4644 stp->st_stid.sc_type = NFS4_OPEN_STID; in init_open_stateid()
4645 INIT_LIST_HEAD(&stp->st_locks); in init_open_stateid()
4646 stp->st_stateowner = nfs4_get_stateowner(&oo->oo_owner); in init_open_stateid()
4648 stp->st_stid.sc_file = fp; in init_open_stateid()
4649 stp->st_access_bmap = 0; in init_open_stateid()
4650 stp->st_deny_bmap = 0; in init_open_stateid()
4651 stp->st_openstp = NULL; in init_open_stateid()
4652 list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids); in init_open_stateid()
4653 list_add(&stp->st_perfile, &fp->fi_stateids); in init_open_stateid()
4656 spin_unlock(&fp->fi_lock); in init_open_stateid()
4657 spin_unlock(&oo->oo_owner.so_client->cl_lock); in init_open_stateid()
4661 nfs4_put_stid(&retstp->st_stid); in init_open_stateid()
4665 mutex_unlock(&stp->st_mutex); in init_open_stateid()
4680 struct nfs4_openowner *oo = openowner(s->st_stateowner); in move_to_close_lru()
4681 struct nfsd_net *nn = net_generic(s->st_stid.sc_client->net, in move_to_close_lru()
4695 wait_event(close_wq, refcount_read(&s->st_stid.sc_count) == 2); in move_to_close_lru()
4698 if (s->st_stid.sc_file) { in move_to_close_lru()
4699 put_nfs4_file(s->st_stid.sc_file); in move_to_close_lru()
4700 s->st_stid.sc_file = NULL; in move_to_close_lru()
4703 spin_lock(&nn->client_lock); in move_to_close_lru()
4704 last = oo->oo_last_closed_stid; in move_to_close_lru()
4705 oo->oo_last_closed_stid = s; in move_to_close_lru()
4706 list_move_tail(&oo->oo_close_lru, &nn->close_lru); in move_to_close_lru()
4707 oo->oo_time = ktime_get_boottime_seconds(); in move_to_close_lru()
4708 spin_unlock(&nn->client_lock); in move_to_close_lru()
4710 nfs4_put_stid(&last->st_stid); in move_to_close_lru()
4716 struct inode *inode = d_inode(fhp->fh_dentry); in nfsd4_file_hash_lookup()
4724 if (fh_match(&fi->fi_fhandle, &fhp->fh_handle)) { in nfsd4_file_hash_lookup()
4725 if (refcount_inc_not_zero(&fi->fi_ref)) { in nfsd4_file_hash_lookup()
4740 * inode->i_lock prevents racing insertions from adding an entry
4746 struct inode *inode = d_inode(fhp->fh_dentry); in nfsd4_file_hash_insert()
4754 spin_lock(&inode->i_lock); in nfsd4_file_hash_insert()
4759 if (fh_match(&fi->fi_fhandle, &fhp->fh_handle)) { in nfsd4_file_hash_insert()
4760 if (refcount_inc_not_zero(&fi->fi_ref)) in nfsd4_file_hash_insert()
4763 fi->fi_aliased = alias_found = true; in nfsd4_file_hash_insert()
4769 err = rhltable_insert(&nfs4_file_rhltable, &new->fi_rlist, in nfsd4_file_hash_insert()
4774 new->fi_aliased = alias_found; in nfsd4_file_hash_insert()
4778 spin_unlock(&inode->i_lock); in nfsd4_file_hash_insert()
4785 rhltable_remove(&nfs4_file_rhltable, &fi->fi_rlist, in nfsd4_file_hash_remove()
4804 spin_lock(&fp->fi_lock); in nfs4_share_conflict()
4805 if (fp->fi_share_deny & deny_type) in nfs4_share_conflict()
4807 spin_unlock(&fp->fi_lock); in nfs4_share_conflict()
4816 return ctx && !list_empty_careful(&ctx->flc_lease); in nfsd4_deleg_present()
4820 * nfsd_wait_for_delegreturn - wait for delegations to be returned
4822 * @inode: in-core inode of the file being waited for
4844 struct nfsd_net *nn = net_generic(dp->dl_stid.sc_client->net, in nfsd4_cb_recall_prepare()
4847 block_delegations(&dp->dl_stid.sc_file->fi_fhandle); in nfsd4_cb_recall_prepare()
4851 * already holding inode->i_lock. in nfsd4_cb_recall_prepare()
4857 if (delegation_hashed(dp) && dp->dl_time == 0) { in nfsd4_cb_recall_prepare()
4858 dp->dl_time = ktime_get_boottime_seconds(); in nfsd4_cb_recall_prepare()
4859 list_add_tail(&dp->dl_recall_lru, &nn->del_recall_lru); in nfsd4_cb_recall_prepare()
4869 trace_nfsd_cb_recall_done(&dp->dl_stid.sc_stateid, task); in nfsd4_cb_recall_done()
4871 if (dp->dl_stid.sc_type == NFS4_CLOSED_DELEG_STID || in nfsd4_cb_recall_done()
4872 dp->dl_stid.sc_type == NFS4_REVOKED_DELEG_STID) in nfsd4_cb_recall_done()
4875 switch (task->tk_status) { in nfsd4_cb_recall_done()
4878 case -NFS4ERR_DELAY: in nfsd4_cb_recall_done()
4881 case -EBADHANDLE: in nfsd4_cb_recall_done()
4882 case -NFS4ERR_BAD_STATEID: in nfsd4_cb_recall_done()
4887 if (dp->dl_retries--) { in nfsd4_cb_recall_done()
4901 nfs4_put_stid(&dp->dl_stid); in nfsd4_cb_recall_release()
4919 refcount_inc(&dp->dl_stid.sc_count); in nfsd_break_one_deleg()
4920 WARN_ON_ONCE(!nfsd4_run_cb(&dp->dl_recall)); in nfsd_break_one_deleg()
4927 struct nfs4_delegation *dp = (struct nfs4_delegation *)fl->fl_owner; in nfsd_break_deleg_cb()
4928 struct nfs4_file *fp = dp->dl_stid.sc_file; in nfsd_break_deleg_cb()
4929 struct nfs4_client *clp = dp->dl_stid.sc_client; in nfsd_break_deleg_cb()
4932 trace_nfsd_cb_recall(&dp->dl_stid); in nfsd_break_deleg_cb()
4934 dp->dl_recalled = true; in nfsd_break_deleg_cb()
4935 atomic_inc(&clp->cl_delegs_in_recall); in nfsd_break_deleg_cb()
4937 nn = net_generic(clp->net, nfsd_net_id); in nfsd_break_deleg_cb()
4938 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in nfsd_break_deleg_cb()
4946 fl->fl_break_time = 0; in nfsd_break_deleg_cb()
4948 fp->fi_had_conflict = true; in nfsd_break_deleg_cb()
4954 * nfsd_breaker_owns_lease - Check if lease conflict was resolved
4963 struct nfs4_delegation *dl = fl->fl_owner; in nfsd_breaker_owns_lease()
4971 if (rqst->rq_prog != NFS_PROGRAM || rqst->rq_vers < 4) in nfsd_breaker_owns_lease()
4973 clp = *(rqst->rq_lease_breaker); in nfsd_breaker_owns_lease()
4974 return dl->dl_stid.sc_client == clp; in nfsd_breaker_owns_lease()
4981 struct nfs4_delegation *dp = (struct nfs4_delegation *)onlist->fl_owner; in nfsd_change_deleg_cb()
4982 struct nfs4_client *clp = dp->dl_stid.sc_client; in nfsd_change_deleg_cb()
4985 if (dp->dl_recalled) in nfsd_change_deleg_cb()
4986 atomic_dec(&clp->cl_delegs_in_recall); in nfsd_change_deleg_cb()
4989 return -EAGAIN; in nfsd_change_deleg_cb()
5002 if (seqid == so->so_seqid - 1) in nfsd4_check_seqid()
5004 if (seqid == so->so_seqid) in nfsd4_check_seqid()
5014 spin_lock(&nn->client_lock); in lookup_clientid()
5017 atomic_inc(&found->cl_rpc_users); in lookup_clientid()
5018 spin_unlock(&nn->client_lock); in lookup_clientid()
5026 if (cstate->clp) { in set_client()
5027 if (!same_clid(&cstate->clp->cl_clientid, clid)) in set_client()
5035 * set cstate->clp), so session = false: in set_client()
5037 cstate->clp = lookup_clientid(clid, false, nn); in set_client()
5038 if (!cstate->clp) in set_client()
5047 clientid_t *clientid = &open->op_clientid; in nfsd4_process_open1()
5057 open->op_file = nfsd4_alloc_file(); in nfsd4_process_open1()
5058 if (open->op_file == NULL) in nfsd4_process_open1()
5064 clp = cstate->clp; in nfsd4_process_open1()
5066 strhashval = ownerstr_hashval(&open->op_owner); in nfsd4_process_open1()
5068 open->op_openowner = oo; in nfsd4_process_open1()
5072 if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { in nfsd4_process_open1()
5075 open->op_openowner = NULL; in nfsd4_process_open1()
5078 status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid); in nfsd4_process_open1()
5086 open->op_openowner = oo; in nfsd4_process_open1()
5088 open->op_stp = nfs4_alloc_open_stateid(clp); in nfsd4_process_open1()
5089 if (!open->op_stp) in nfsd4_process_open1()
5093 (cstate->current_fh.fh_export->ex_flags & NFSEXP_PNFS)) { in nfsd4_process_open1()
5094 open->op_odstate = alloc_clnt_odstate(clp); in nfsd4_process_open1()
5095 if (!open->op_odstate) in nfsd4_process_open1()
5105 if ((flags & WR_STATE) && (dp->dl_type == NFS4_OPEN_DELEGATE_READ)) in nfs4_check_delegmode()
5129 return open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR || in nfsd4_is_deleg_cur()
5130 open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH; in nfsd4_is_deleg_cur()
5141 deleg = find_deleg_stateid(cl, &open->op_delegate_stateid); in nfs4_check_deleg()
5144 if (deleg->dl_stid.sc_type == NFS4_REVOKED_DELEG_STID) { in nfs4_check_deleg()
5145 nfs4_put_stid(&deleg->dl_stid); in nfs4_check_deleg()
5146 if (cl->cl_minorversion) in nfs4_check_deleg()
5150 flags = share_access_to_flags(open->op_share_access); in nfs4_check_deleg()
5153 nfs4_put_stid(&deleg->dl_stid); in nfs4_check_deleg()
5162 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; in nfs4_check_deleg()
5188 if (!open->op_truncate) in nfsd4_truncate()
5190 if (!(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) in nfsd4_truncate()
5201 int oflag = nfs4_access_to_omode(open->op_share_access); in nfs4_get_vfs_file()
5202 int access = nfs4_access_to_access(open->op_share_access); in nfs4_get_vfs_file()
5205 spin_lock(&fp->fi_lock); in nfs4_get_vfs_file()
5211 status = nfs4_file_check_deny(fp, open->op_share_deny); in nfs4_get_vfs_file()
5214 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5218 stp, open->op_share_deny, false)) in nfs4_get_vfs_file()
5220 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5225 status = nfs4_file_get_access(fp, open->op_share_access); in nfs4_get_vfs_file()
5228 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5232 stp, open->op_share_access, true)) in nfs4_get_vfs_file()
5234 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5239 old_access_bmap = stp->st_access_bmap; in nfs4_get_vfs_file()
5240 set_access(open->op_share_access, stp); in nfs4_get_vfs_file()
5243 old_deny_bmap = stp->st_deny_bmap; in nfs4_get_vfs_file()
5244 set_deny(open->op_share_deny, stp); in nfs4_get_vfs_file()
5245 fp->fi_share_deny |= (open->op_share_deny & NFS4_SHARE_DENY_BOTH); in nfs4_get_vfs_file()
5247 if (!fp->fi_fds[oflag]) { in nfs4_get_vfs_file()
5248 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5251 open->op_filp, &nf); in nfs4_get_vfs_file()
5255 spin_lock(&fp->fi_lock); in nfs4_get_vfs_file()
5256 if (!fp->fi_fds[oflag]) { in nfs4_get_vfs_file()
5257 fp->fi_fds[oflag] = nf; in nfs4_get_vfs_file()
5261 spin_unlock(&fp->fi_lock); in nfs4_get_vfs_file()
5265 status = nfserrno(nfsd_open_break_lease(cur_fh->fh_dentry->d_inode, in nfs4_get_vfs_file()
5276 stp->st_access_bmap = old_access_bmap; in nfs4_get_vfs_file()
5277 nfs4_file_put_access(fp, open->op_share_access); in nfs4_get_vfs_file()
5288 unsigned char old_deny_bmap = stp->st_deny_bmap; in nfs4_upgrade_open()
5290 if (!test_access(open->op_share_access, stp)) in nfs4_upgrade_open()
5294 spin_lock(&fp->fi_lock); in nfs4_upgrade_open()
5295 status = nfs4_file_check_deny(fp, open->op_share_deny); in nfs4_upgrade_open()
5298 set_deny(open->op_share_deny, stp); in nfs4_upgrade_open()
5299 fp->fi_share_deny |= in nfs4_upgrade_open()
5300 (open->op_share_deny & NFS4_SHARE_DENY_BOTH); in nfs4_upgrade_open()
5304 stp, open->op_share_deny, false)) in nfs4_upgrade_open()
5308 spin_unlock(&fp->fi_lock); in nfs4_upgrade_open()
5322 if (clp->cl_cb_state == NFSD4_CB_UP) in nfsd4_cb_channel_good()
5329 return clp->cl_minorversion && clp->cl_cb_state == NFSD4_CB_UNKNOWN; in nfsd4_cb_channel_good()
5340 fl->fl_lmops = &nfsd_lease_mng_ops; in nfs4_alloc_init_lease()
5341 fl->fl_flags = FL_DELEG; in nfs4_alloc_init_lease()
5342 fl->fl_type = flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK; in nfs4_alloc_init_lease()
5343 fl->fl_end = OFFSET_MAX; in nfs4_alloc_init_lease()
5344 fl->fl_owner = (fl_owner_t)dp; in nfs4_alloc_init_lease()
5345 fl->fl_pid = current->tgid; in nfs4_alloc_init_lease()
5346 fl->fl_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file; in nfs4_alloc_init_lease()
5354 struct file *f = fp->fi_deleg_file->nf_file; in nfsd4_check_conflicting_opens()
5358 writes = atomic_read(&ino->i_writecount); in nfsd4_check_conflicting_opens()
5368 if (fp->fi_aliased) in nfsd4_check_conflicting_opens()
5369 return -EAGAIN; in nfsd4_check_conflicting_opens()
5377 if (fp->fi_fds[O_WRONLY]) in nfsd4_check_conflicting_opens()
5378 writes--; in nfsd4_check_conflicting_opens()
5379 if (fp->fi_fds[O_RDWR]) in nfsd4_check_conflicting_opens()
5380 writes--; in nfsd4_check_conflicting_opens()
5382 return -EAGAIN; /* There may be non-NFSv4 writers */ in nfsd4_check_conflicting_opens()
5384 * It's possible there are non-NFSv4 write opens in progress, in nfsd4_check_conflicting_opens()
5390 spin_lock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5391 list_for_each_entry(st, &fp->fi_stateids, st_perfile) { in nfsd4_check_conflicting_opens()
5392 if (st->st_openstp == NULL /* it's an open */ && in nfsd4_check_conflicting_opens()
5394 st->st_stid.sc_client != clp) { in nfsd4_check_conflicting_opens()
5395 spin_unlock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5396 return -EAGAIN; in nfsd4_check_conflicting_opens()
5399 spin_unlock(&fp->fi_lock); in nfsd4_check_conflicting_opens()
5422 err = nfsd_lookup_dentry(open->op_rqstp, parent, in nfsd4_verify_deleg_dentry()
5423 open->op_fname, open->op_fnamelen, in nfsd4_verify_deleg_dentry()
5427 return -EAGAIN; in nfsd4_verify_deleg_dentry()
5431 if (child != file_dentry(fp->fi_deleg_file->nf_file)) in nfsd4_verify_deleg_dentry()
5432 return -EAGAIN; in nfsd4_verify_deleg_dentry()
5446 struct inode *inode = file_inode(nf->nf_file); in nfsd4_verify_setuid_write()
5448 if ((open->op_share_access & NFS4_SHARE_ACCESS_WRITE) && in nfsd4_verify_setuid_write()
5449 (inode->i_mode & (S_ISUID|S_ISGID))) in nfsd4_verify_setuid_write()
5450 return -EAGAIN; in nfsd4_verify_setuid_write()
5459 struct nfs4_client *clp = stp->st_stid.sc_client; in nfs4_set_delegation()
5460 struct nfs4_file *fp = stp->st_stid.sc_file; in nfs4_set_delegation()
5461 struct nfs4_clnt_odstate *odstate = stp->st_clnt_odstate; in nfs4_set_delegation()
5472 if (fp->fi_had_conflict) in nfs4_set_delegation()
5473 return ERR_PTR(-EAGAIN); in nfs4_set_delegation()
5487 if ((open->op_share_access & NFS4_SHARE_ACCESS_BOTH) == NFS4_SHARE_ACCESS_BOTH) { in nfs4_set_delegation()
5496 if (!nf && (open->op_share_access & NFS4_SHARE_ACCESS_READ)) { in nfs4_set_delegation()
5502 return ERR_PTR(-EAGAIN); in nfs4_set_delegation()
5505 spin_lock(&fp->fi_lock); in nfs4_set_delegation()
5507 status = -EAGAIN; in nfs4_set_delegation()
5509 status = -EAGAIN; in nfs4_set_delegation()
5510 else if (!fp->fi_deleg_file) { in nfs4_set_delegation()
5511 fp->fi_deleg_file = nf; in nfs4_set_delegation()
5514 fp->fi_delegees = 1; in nfs4_set_delegation()
5517 fp->fi_delegees++; in nfs4_set_delegation()
5518 spin_unlock(&fp->fi_lock); in nfs4_set_delegation()
5525 status = -ENOMEM; in nfs4_set_delegation()
5534 status = vfs_setlease(fp->fi_deleg_file->nf_file, fl->fl_type, &fl, NULL); in nfs4_set_delegation()
5554 status = nfsd4_verify_setuid_write(open, fp->fi_deleg_file); in nfs4_set_delegation()
5558 status = -EAGAIN; in nfs4_set_delegation()
5559 if (fp->fi_had_conflict) in nfs4_set_delegation()
5563 spin_lock(&fp->fi_lock); in nfs4_set_delegation()
5565 spin_unlock(&fp->fi_lock); in nfs4_set_delegation()
5573 vfs_setlease(fp->fi_deleg_file->nf_file, F_UNLCK, NULL, (void **)&dp); in nfs4_set_delegation()
5575 put_clnt_odstate(dp->dl_clnt_odstate); in nfs4_set_delegation()
5576 nfs4_put_stid(&dp->dl_stid); in nfs4_set_delegation()
5584 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_open_deleg_none_ext()
5585 if (status == -EAGAIN) in nfsd4_open_deleg_none_ext()
5586 open->op_why_no_deleg = WND4_CONTENTION; in nfsd4_open_deleg_none_ext()
5588 open->op_why_no_deleg = WND4_RESOURCE; in nfsd4_open_deleg_none_ext()
5589 switch (open->op_deleg_want) { in nfsd4_open_deleg_none_ext()
5595 open->op_why_no_deleg = WND4_CANCELLED; in nfsd4_open_deleg_none_ext()
5632 struct nfs4_openowner *oo = openowner(stp->st_stateowner); in nfs4_open_delegation()
5633 struct nfs4_client *clp = stp->st_stid.sc_client; in nfs4_open_delegation()
5638 cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client); in nfs4_open_delegation()
5639 open->op_recall = false; in nfs4_open_delegation()
5640 switch (open->op_claim_type) { in nfs4_open_delegation()
5643 open->op_recall = true; in nfs4_open_delegation()
5654 if (locks_in_grace(clp->net)) in nfs4_open_delegation()
5656 if (!cb_up || !(oo->oo_flags & NFS4_OO_CONFIRMED)) in nfs4_open_delegation()
5658 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE && in nfs4_open_delegation()
5659 !clp->cl_minorversion) in nfs4_open_delegation()
5669 memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid)); in nfs4_open_delegation()
5671 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) { in nfs4_open_delegation()
5672 open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE; in nfs4_open_delegation()
5673 trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); in nfs4_open_delegation()
5675 open->op_delegate_type = NFS4_OPEN_DELEGATE_READ; in nfs4_open_delegation()
5676 trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid); in nfs4_open_delegation()
5678 nfs4_put_stid(&dp->dl_stid); in nfs4_open_delegation()
5681 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE; in nfs4_open_delegation()
5682 if (open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS && in nfs4_open_delegation()
5683 open->op_delegate_type != NFS4_OPEN_DELEGATE_NONE) { in nfs4_open_delegation()
5685 open->op_recall = true; in nfs4_open_delegation()
5689 if (open->op_deleg_want) in nfs4_open_delegation()
5697 if (open->op_deleg_want == NFS4_SHARE_WANT_READ_DELEG && in nfsd4_deleg_xgrade_none_ext()
5698 dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) { in nfsd4_deleg_xgrade_none_ext()
5699 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_deleg_xgrade_none_ext()
5700 open->op_why_no_deleg = WND4_NOT_SUPP_DOWNGRADE; in nfsd4_deleg_xgrade_none_ext()
5701 } else if (open->op_deleg_want == NFS4_SHARE_WANT_WRITE_DELEG && in nfsd4_deleg_xgrade_none_ext()
5702 dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) { in nfsd4_deleg_xgrade_none_ext()
5703 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_deleg_xgrade_none_ext()
5704 open->op_why_no_deleg = WND4_NOT_SUPP_UPGRADE; in nfsd4_deleg_xgrade_none_ext()
5713 * nfsd4_process_open2 - finish open processing
5718 * If successful, (1) truncate the file if open->op_truncate was
5719 * set, (2) set open->op_stateid, (3) set open->op_delegation.
5727 struct nfsd4_compoundres *resp = rqstp->rq_resp; in nfsd4_process_open2()
5728 struct nfs4_client *cl = open->op_openowner->oo_owner.so_client; in nfsd4_process_open2()
5740 fp = nfsd4_file_hash_insert(open->op_file, current_fh); in nfsd4_process_open2()
5743 if (fp != open->op_file) { in nfsd4_process_open2()
5749 open->op_file = NULL; in nfsd4_process_open2()
5757 if (!open->op_stp) in nfsd4_process_open2()
5771 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5777 stp->st_stid.sc_type = NFS4_CLOSED_STID; in nfsd4_process_open2()
5779 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5783 stp->st_clnt_odstate = find_or_hash_clnt_odstate(fp, in nfsd4_process_open2()
5784 open->op_odstate); in nfsd4_process_open2()
5785 if (stp->st_clnt_odstate == open->op_odstate) in nfsd4_process_open2()
5786 open->op_odstate = NULL; in nfsd4_process_open2()
5789 nfs4_inc_and_copy_stateid(&open->op_stateid, &stp->st_stid); in nfsd4_process_open2()
5790 mutex_unlock(&stp->st_mutex); in nfsd4_process_open2()
5792 if (nfsd4_has_session(&resp->cstate)) { in nfsd4_process_open2()
5793 if (open->op_deleg_want & NFS4_SHARE_WANT_NO_DELEG) { in nfsd4_process_open2()
5794 open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; in nfsd4_process_open2()
5795 open->op_why_no_deleg = WND4_NOT_WANTED; in nfsd4_process_open2()
5804 nfs4_open_delegation(open, stp, &resp->cstate.current_fh); in nfsd4_process_open2()
5807 trace_nfsd_open(&stp->st_stid.sc_stateid); in nfsd4_process_open2()
5810 if (open->op_delegate_type == NFS4_OPEN_DELEGATE_NONE && dp && in nfsd4_process_open2()
5811 open->op_deleg_want) in nfsd4_process_open2()
5816 if (status == 0 && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) in nfsd4_process_open2()
5817 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; in nfsd4_process_open2()
5821 open->op_rflags = NFS4_OPEN_RESULT_LOCKTYPE_POSIX; in nfsd4_process_open2()
5822 if (nfsd4_has_session(&resp->cstate)) in nfsd4_process_open2()
5823 open->op_rflags |= NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK; in nfsd4_process_open2()
5824 else if (!(open->op_openowner->oo_flags & NFS4_OO_CONFIRMED)) in nfsd4_process_open2()
5825 open->op_rflags |= NFS4_OPEN_RESULT_CONFIRM; in nfsd4_process_open2()
5828 nfs4_put_stid(&dp->dl_stid); in nfsd4_process_open2()
5830 nfs4_put_stid(&stp->st_stid); in nfsd4_process_open2()
5838 if (open->op_openowner) { in nfsd4_cleanup_open_state()
5839 struct nfs4_stateowner *so = &open->op_openowner->oo_owner; in nfsd4_cleanup_open_state()
5844 if (open->op_file) in nfsd4_cleanup_open_state()
5845 kmem_cache_free(file_slab, open->op_file); in nfsd4_cleanup_open_state()
5846 if (open->op_stp) in nfsd4_cleanup_open_state()
5847 nfs4_put_stid(&open->op_stp->st_stid); in nfsd4_cleanup_open_state()
5848 if (open->op_odstate) in nfsd4_cleanup_open_state()
5849 kmem_cache_free(odstate_slab, open->op_odstate); in nfsd4_cleanup_open_state()
5856 clientid_t *clid = &u->renew; in nfsd4_renew()
5865 clp = cstate->clp; in nfsd4_renew()
5866 if (!list_empty(&clp->cl_delegations) in nfsd4_renew()
5867 && clp->cl_cb_state != NFSD4_CB_UP) in nfsd4_renew()
5876 if (nn->grace_ended) in nfsd4_end_grace()
5880 nn->grace_ended = true; in nfsd4_end_grace()
5897 locks_end_grace(&nn->nfsd4_manager); in nfsd4_end_grace()
5911 time64_t double_grace_period_end = nn->boot_time + in clients_still_reclaiming()
5912 2 * nn->nfsd4_lease; in clients_still_reclaiming()
5914 if (nn->track_reclaim_completes && in clients_still_reclaiming()
5915 atomic_read(&nn->nr_reclaim_complete) == in clients_still_reclaiming()
5916 nn->reclaim_str_hashtbl_size) in clients_still_reclaiming()
5918 if (!nn->somebody_reclaimed) in clients_still_reclaiming()
5920 nn->somebody_reclaimed = false; in clients_still_reclaiming()
5939 if (last_refresh < lt->cutoff) in state_expired()
5941 time_remaining = last_refresh - lt->cutoff; in state_expired()
5942 lt->new_timeo = min(lt->new_timeo, time_remaining); in state_expired()
5949 spin_lock_init(&nn->nfsd_ssc_lock); in nfsd4_ssc_init_umount_work()
5950 INIT_LIST_HEAD(&nn->nfsd_ssc_mount_list); in nfsd4_ssc_init_umount_work()
5951 init_waitqueue_head(&nn->nfsd_ssc_waitq); in nfsd4_ssc_init_umount_work()
5964 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5965 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { in nfsd4_ssc_shutdown_umount()
5966 list_del(&ni->nsui_list); in nfsd4_ssc_shutdown_umount()
5967 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5968 mntput(ni->nsui_vfsmount); in nfsd4_ssc_shutdown_umount()
5970 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5972 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_shutdown_umount()
5981 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
5982 list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { in nfsd4_ssc_expire_umount()
5983 if (time_after(jiffies, ni->nsui_expire)) { in nfsd4_ssc_expire_umount()
5984 if (refcount_read(&ni->nsui_refcnt) > 1) in nfsd4_ssc_expire_umount()
5988 ni->nsui_busy = true; in nfsd4_ssc_expire_umount()
5989 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
5990 mntput(ni->nsui_vfsmount); in nfsd4_ssc_expire_umount()
5991 spin_lock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
5994 list_del(&ni->nsui_list); in nfsd4_ssc_expire_umount()
6004 wake_up_all(&nn->nfsd_ssc_waitq); in nfsd4_ssc_expire_umount()
6005 spin_unlock(&nn->nfsd_ssc_lock); in nfsd4_ssc_expire_umount()
6017 list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) { in nfs4_lockowner_has_blockers()
6018 nf = stp->st_stid.sc_file; in nfs4_lockowner_has_blockers()
6019 ctx = locks_inode_context(nf->fi_inode); in nfs4_lockowner_has_blockers()
6035 if (atomic_read(&clp->cl_delegs_in_recall)) in nfs4_anylock_blockers()
6037 spin_lock(&clp->cl_lock); in nfs4_anylock_blockers()
6039 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[i], in nfs4_anylock_blockers()
6041 if (so->so_is_open_owner) in nfs4_anylock_blockers()
6045 spin_unlock(&clp->cl_lock); in nfs4_anylock_blockers()
6050 spin_unlock(&clp->cl_lock); in nfs4_anylock_blockers()
6062 maxreap = (atomic_read(&nn->nfs4_client_count) >= nn->nfs4_max_clients) ? in nfs4_get_client_reaplist()
6065 spin_lock(&nn->client_lock); in nfs4_get_client_reaplist()
6066 list_for_each_safe(pos, next, &nn->client_lru) { in nfs4_get_client_reaplist()
6068 if (clp->cl_state == NFSD4_EXPIRABLE) in nfs4_get_client_reaplist()
6070 if (!state_expired(lt, clp->cl_time)) in nfs4_get_client_reaplist()
6072 if (!atomic_read(&clp->cl_rpc_users)) { in nfs4_get_client_reaplist()
6073 if (clp->cl_state == NFSD4_ACTIVE) in nfs4_get_client_reaplist()
6074 atomic_inc(&nn->nfsd_courtesy_clients); in nfs4_get_client_reaplist()
6075 clp->cl_state = NFSD4_COURTESY; in nfs4_get_client_reaplist()
6084 list_add(&clp->cl_lru, reaplist); in nfs4_get_client_reaplist()
6088 spin_unlock(&nn->client_lock); in nfs4_get_client_reaplist()
6102 spin_lock(&nn->client_lock); in nfs4_get_courtesy_client_reaplist()
6103 list_for_each_safe(pos, next, &nn->client_lru) { in nfs4_get_courtesy_client_reaplist()
6105 if (clp->cl_state == NFSD4_ACTIVE) in nfs4_get_courtesy_client_reaplist()
6110 list_add(&clp->cl_lru, reaplist); in nfs4_get_courtesy_client_reaplist()
6114 spin_unlock(&nn->client_lock); in nfs4_get_courtesy_client_reaplist()
6125 trace_nfsd_clid_purged(&clp->cl_clientid); in nfs4_process_client_reaplist()
6126 list_del_init(&clp->cl_lru); in nfs4_process_client_reaplist()
6140 .cutoff = ktime_get_boottime_seconds() - nn->nfsd4_lease, in nfs4_laundromat()
6141 .new_timeo = nn->nfsd4_lease in nfs4_laundromat()
6153 spin_lock(&nn->s2s_cp_lock); in nfs4_laundromat()
6154 idr_for_each_entry(&nn->s2s_cp_stateids, cps_t, i) { in nfs4_laundromat()
6156 if (cps->cp_stateid.cs_type == NFS4_COPYNOTIFY_STID && in nfs4_laundromat()
6157 state_expired(<, cps->cpntf_time)) in nfs4_laundromat()
6160 spin_unlock(&nn->s2s_cp_lock); in nfs4_laundromat()
6165 list_for_each_safe(pos, next, &nn->del_recall_lru) { in nfs4_laundromat()
6167 if (!state_expired(<, dp->dl_time)) in nfs4_laundromat()
6170 list_add(&dp->dl_recall_lru, &reaplist); in nfs4_laundromat()
6176 list_del_init(&dp->dl_recall_lru); in nfs4_laundromat()
6180 spin_lock(&nn->client_lock); in nfs4_laundromat()
6181 while (!list_empty(&nn->close_lru)) { in nfs4_laundromat()
6182 oo = list_first_entry(&nn->close_lru, struct nfs4_openowner, in nfs4_laundromat()
6184 if (!state_expired(<, oo->oo_time)) in nfs4_laundromat()
6186 list_del_init(&oo->oo_close_lru); in nfs4_laundromat()
6187 stp = oo->oo_last_closed_stid; in nfs4_laundromat()
6188 oo->oo_last_closed_stid = NULL; in nfs4_laundromat()
6189 spin_unlock(&nn->client_lock); in nfs4_laundromat()
6190 nfs4_put_stid(&stp->st_stid); in nfs4_laundromat()
6191 spin_lock(&nn->client_lock); in nfs4_laundromat()
6193 spin_unlock(&nn->client_lock); in nfs4_laundromat()
6198 * So, we clean out any un-revisited request after a lease period in nfs4_laundromat()
6207 spin_lock(&nn->blocked_locks_lock); in nfs4_laundromat()
6208 while (!list_empty(&nn->blocked_locks_lru)) { in nfs4_laundromat()
6209 nbl = list_first_entry(&nn->blocked_locks_lru, in nfs4_laundromat()
6211 if (!state_expired(<, nbl->nbl_time)) in nfs4_laundromat()
6213 list_move(&nbl->nbl_lru, &reaplist); in nfs4_laundromat()
6214 list_del_init(&nbl->nbl_list); in nfs4_laundromat()
6216 spin_unlock(&nn->blocked_locks_lock); in nfs4_laundromat()
6221 list_del_init(&nbl->nbl_lru); in nfs4_laundromat()
6225 /* service the server-to-server copy delayed unmount list */ in nfs4_laundromat()
6243 queue_delayed_work(laundry_wq, &nn->laundromat_work, t*HZ); in laundromat_main()
6263 spin_lock(&nn->client_lock); in deleg_reaper()
6264 list_for_each_safe(pos, next, &nn->client_lru) { in deleg_reaper()
6266 if (clp->cl_state != NFSD4_ACTIVE || in deleg_reaper()
6267 list_empty(&clp->cl_delegations) || in deleg_reaper()
6268 atomic_read(&clp->cl_delegs_in_recall) || in deleg_reaper()
6269 test_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags) || in deleg_reaper()
6270 (ktime_get_boottime_seconds() - in deleg_reaper()
6271 clp->cl_ra_time < 5)) { in deleg_reaper()
6274 list_add(&clp->cl_ra_cblist, &cblist); in deleg_reaper()
6277 atomic_inc(&clp->cl_rpc_users); in deleg_reaper()
6278 set_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags); in deleg_reaper()
6279 clp->cl_ra_time = ktime_get_boottime_seconds(); in deleg_reaper()
6281 spin_unlock(&nn->client_lock); in deleg_reaper()
6286 list_del_init(&clp->cl_ra_cblist); in deleg_reaper()
6287 clp->cl_ra->ra_keep = 0; in deleg_reaper()
6288 clp->cl_ra->ra_bmval[0] = BIT(RCA4_TYPE_MASK_RDATA_DLG); in deleg_reaper()
6289 trace_nfsd_cb_recall_any(clp->cl_ra); in deleg_reaper()
6290 nfsd4_run_cb(&clp->cl_ra->ra_cb); in deleg_reaper()
6306 if (!fh_match(&fhp->fh_handle, &stp->sc_file->fi_fhandle)) in nfs4_check_fh()
6317 if (stp->st_openstp) in nfs4_check_openmode()
6318 stp = stp->st_openstp; in nfs4_check_openmode()
6351 if (has_session && in->si_generation == 0) in check_stateid_generation()
6354 if (in->si_generation == ref->si_generation) in check_stateid_generation()
6362 * non-buggy client. For example, if the client sends a lock in check_stateid_generation()
6377 spin_lock(&s->sc_lock); in nfsd4_stid_check_stateid_generation()
6380 ret = check_stateid_generation(in, &s->sc_stateid, has_session); in nfsd4_stid_check_stateid_generation()
6381 spin_unlock(&s->sc_lock); in nfsd4_stid_check_stateid_generation()
6387 if (ols->st_stateowner->so_is_open_owner && in nfsd4_check_openowner_confirmed()
6388 !(openowner(ols->st_stateowner)->oo_flags & NFS4_OO_CONFIRMED)) in nfsd4_check_openowner_confirmed()
6401 spin_lock(&cl->cl_lock); in nfsd4_validate_stateid()
6408 switch (s->sc_type) { in nfsd4_validate_stateid()
6420 printk("unknown stateid type %x\n", s->sc_type); in nfsd4_validate_stateid()
6427 spin_unlock(&cl->cl_lock); in nfsd4_validate_stateid()
6452 status = set_client(&stateid->si_opaque.so_clid, cstate, nn); in nfsd4_lookup_stateid()
6454 if (cstate->session) in nfsd4_lookup_stateid()
6460 stid = find_stateid_by_type(cstate->clp, stateid, typemask); in nfsd4_lookup_stateid()
6463 if ((stid->sc_type == NFS4_REVOKED_DELEG_STID) && !return_revoked) { in nfsd4_lookup_stateid()
6465 if (cstate->minorversion) in nfsd4_lookup_stateid()
6481 switch (s->sc_type) { in nfs4_find_file()
6483 spin_lock(&s->sc_file->fi_lock); in nfs4_find_file()
6484 ret = nfsd_file_get(s->sc_file->fi_deleg_file); in nfs4_find_file()
6485 spin_unlock(&s->sc_file->fi_lock); in nfs4_find_file()
6490 ret = find_readable_file(s->sc_file); in nfs4_find_file()
6492 ret = find_writeable_file(s->sc_file); in nfs4_find_file()
6519 status = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry, in nfs4_check_file()
6537 WARN_ON_ONCE(cps->cp_stateid.cs_type != NFS4_COPYNOTIFY_STID); in _free_cpntf_state_locked()
6538 if (!refcount_dec_and_test(&cps->cp_stateid.cs_count)) in _free_cpntf_state_locked()
6540 list_del(&cps->cp_list); in _free_cpntf_state_locked()
6541 idr_remove(&nn->s2s_cp_stateids, in _free_cpntf_state_locked()
6542 cps->cp_stateid.cs_stid.si_opaque.so_id); in _free_cpntf_state_locked()
6557 if (st->si_opaque.so_clid.cl_id != nn->s2s_cp_cl_id) in manage_cpntf_state()
6559 spin_lock(&nn->s2s_cp_lock); in manage_cpntf_state()
6560 cps_t = idr_find(&nn->s2s_cp_stateids, st->si_opaque.so_id); in manage_cpntf_state()
6564 if (state->cp_stateid.cs_type != NFS4_COPYNOTIFY_STID) { in manage_cpntf_state()
6569 refcount_inc(&state->cp_stateid.cs_count); in manage_cpntf_state()
6574 spin_unlock(&nn->s2s_cp_lock); in manage_cpntf_state()
6593 cps->cpntf_time = ktime_get_boottime_seconds(); in find_cpntf_state()
6596 found = lookup_clientid(&cps->cp_p_clid, true, nn); in find_cpntf_state()
6600 *stid = find_stateid_by_type(found, &cps->cp_p_stateid, in find_cpntf_state()
6615 spin_lock(&nn->s2s_cp_lock); in nfs4_put_cpntf_state()
6617 spin_unlock(&nn->s2s_cp_lock); in nfs4_put_cpntf_state()
6621 * nfs4_preprocess_stateid_op - find and prep stateid for an operation
6669 switch (s->sc_type) { in nfs4_preprocess_stateid_op()
6705 struct nfsd4_test_stateid *test_stateid = &u->test_stateid; in nfsd4_test_stateid()
6707 struct nfs4_client *cl = cstate->clp; in nfsd4_test_stateid()
6709 list_for_each_entry(stateid, &test_stateid->ts_stateid_list, ts_id_list) in nfsd4_test_stateid()
6710 stateid->ts_id_status = in nfsd4_test_stateid()
6711 nfsd4_validate_stateid(cl, &stateid->ts_id_stateid); in nfsd4_test_stateid()
6726 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); in nfsd4_free_lock_stateid()
6731 if (check_for_locks(stp->st_stid.sc_file, in nfsd4_free_lock_stateid()
6732 lockowner(stp->st_stateowner))) in nfsd4_free_lock_stateid()
6739 mutex_unlock(&stp->st_mutex); in nfsd4_free_lock_stateid()
6749 struct nfsd4_free_stateid *free_stateid = &u->free_stateid; in nfsd4_free_stateid()
6750 stateid_t *stateid = &free_stateid->fr_stateid; in nfsd4_free_stateid()
6753 struct nfs4_client *cl = cstate->clp; in nfsd4_free_stateid()
6756 spin_lock(&cl->cl_lock); in nfsd4_free_stateid()
6760 spin_lock(&s->sc_lock); in nfsd4_free_stateid()
6761 switch (s->sc_type) { in nfsd4_free_stateid()
6766 ret = check_stateid_generation(stateid, &s->sc_stateid, 1); in nfsd4_free_stateid()
6772 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6773 refcount_inc(&s->sc_count); in nfsd4_free_stateid()
6774 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6778 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6780 list_del_init(&dp->dl_recall_lru); in nfsd4_free_stateid()
6781 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6787 spin_unlock(&s->sc_lock); in nfsd4_free_stateid()
6789 spin_unlock(&cl->cl_lock); in nfsd4_free_stateid()
6803 struct svc_fh *current_fh = &cstate->current_fh; in nfs4_seqid_op_checks()
6804 struct nfs4_stateowner *sop = stp->st_stateowner; in nfs4_seqid_op_checks()
6813 status = check_stateid_generation(stateid, &stp->st_stid.sc_stateid, nfsd4_has_session(cstate)); in nfs4_seqid_op_checks()
6815 status = nfs4_check_fh(current_fh, &stp->st_stid); in nfs4_seqid_op_checks()
6817 mutex_unlock(&stp->st_mutex); in nfs4_seqid_op_checks()
6822 * nfs4_preprocess_seqid_op - find and prep an ol_stateid for a seqid-morphing op
6851 nfsd4_cstate_assign_replay(cstate, stp->st_stateowner); in nfs4_preprocess_seqid_op()
6857 nfs4_put_stid(&stp->st_stid); in nfs4_preprocess_seqid_op()
6872 oo = openowner(stp->st_stateowner); in nfs4_preprocess_confirmed_seqid_op()
6873 if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { in nfs4_preprocess_confirmed_seqid_op()
6874 mutex_unlock(&stp->st_mutex); in nfs4_preprocess_confirmed_seqid_op()
6875 nfs4_put_stid(&stp->st_stid); in nfs4_preprocess_confirmed_seqid_op()
6886 struct nfsd4_open_confirm *oc = &u->open_confirm; in nfsd4_open_confirm()
6893 cstate->current_fh.fh_dentry); in nfsd4_open_confirm()
6895 status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0); in nfsd4_open_confirm()
6900 oc->oc_seqid, &oc->oc_req_stateid, in nfsd4_open_confirm()
6904 oo = openowner(stp->st_stateowner); in nfsd4_open_confirm()
6906 if (oo->oo_flags & NFS4_OO_CONFIRMED) { in nfsd4_open_confirm()
6907 mutex_unlock(&stp->st_mutex); in nfsd4_open_confirm()
6910 oo->oo_flags |= NFS4_OO_CONFIRMED; in nfsd4_open_confirm()
6911 nfs4_inc_and_copy_stateid(&oc->oc_resp_stateid, &stp->st_stid); in nfsd4_open_confirm()
6912 mutex_unlock(&stp->st_mutex); in nfsd4_open_confirm()
6913 trace_nfsd_open_confirm(oc->oc_seqid, &stp->st_stid.sc_stateid); in nfsd4_open_confirm()
6914 nfsd4_client_record_create(oo->oo_owner.so_client); in nfsd4_open_confirm()
6917 nfs4_put_stid(&stp->st_stid); in nfsd4_open_confirm()
6927 nfs4_file_put_access(stp->st_stid.sc_file, access); in nfs4_stateid_downgrade_bit()
6953 struct nfsd4_open_downgrade *od = &u->open_downgrade; in nfsd4_open_downgrade()
6959 cstate->current_fh.fh_dentry); in nfsd4_open_downgrade()
6962 if (od->od_deleg_want) in nfsd4_open_downgrade()
6964 od->od_deleg_want); in nfsd4_open_downgrade()
6966 status = nfs4_preprocess_confirmed_seqid_op(cstate, od->od_seqid, in nfsd4_open_downgrade()
6967 &od->od_stateid, &stp, nn); in nfsd4_open_downgrade()
6971 if (!test_access(od->od_share_access, stp)) { in nfsd4_open_downgrade()
6973 stp->st_access_bmap, od->od_share_access); in nfsd4_open_downgrade()
6976 if (!test_deny(od->od_share_deny, stp)) { in nfsd4_open_downgrade()
6978 stp->st_deny_bmap, od->od_share_deny); in nfsd4_open_downgrade()
6981 nfs4_stateid_downgrade(stp, od->od_share_access); in nfsd4_open_downgrade()
6982 reset_union_bmap_deny(od->od_share_deny, stp); in nfsd4_open_downgrade()
6983 nfs4_inc_and_copy_stateid(&od->od_stateid, &stp->st_stid); in nfsd4_open_downgrade()
6986 mutex_unlock(&stp->st_mutex); in nfsd4_open_downgrade()
6987 nfs4_put_stid(&stp->st_stid); in nfsd4_open_downgrade()
6995 struct nfs4_client *clp = s->st_stid.sc_client; in nfsd4_close_open_stateid()
7000 spin_lock(&clp->cl_lock); in nfsd4_close_open_stateid()
7003 if (clp->cl_minorversion) { in nfsd4_close_open_stateid()
7006 spin_unlock(&clp->cl_lock); in nfsd4_close_open_stateid()
7008 nfs4_free_cpntf_statelist(clp->net, &stp->st_stid); in nfsd4_close_open_stateid()
7011 spin_unlock(&clp->cl_lock); in nfsd4_close_open_stateid()
7014 move_to_close_lru(s, clp->net); in nfsd4_close_open_stateid()
7025 struct nfsd4_close *close = &u->close; in nfsd4_close()
7032 cstate->current_fh.fh_dentry); in nfsd4_close()
7034 status = nfs4_preprocess_seqid_op(cstate, close->cl_seqid, in nfsd4_close()
7035 &close->cl_stateid, in nfsd4_close()
7042 stp->st_stid.sc_type = NFS4_CLOSED_STID; in nfsd4_close()
7050 nfs4_inc_and_copy_stateid(&close->cl_stateid, &stp->st_stid); in nfsd4_close()
7053 mutex_unlock(&stp->st_mutex); in nfsd4_close()
7062 memcpy(&close->cl_stateid, &close_stateid, sizeof(close->cl_stateid)); in nfsd4_close()
7065 nfs4_put_stid(&stp->st_stid); in nfsd4_close()
7074 struct nfsd4_delegreturn *dr = &u->delegreturn; in nfsd4_delegreturn()
7076 stateid_t *stateid = &dr->dr_stateid; in nfsd4_delegreturn()
7081 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) in nfsd4_delegreturn()
7088 status = nfsd4_stid_check_stateid_generation(stateid, &dp->dl_stid, nfsd4_has_session(cstate)); in nfsd4_delegreturn()
7093 wake_up_var(d_inode(cstate->current_fh.fh_dentry)); in nfsd4_delegreturn()
7096 nfs4_put_stid(&dp->dl_stid); in nfsd4_delegreturn()
7109 return end > start ? end - 1: NFS4_MAX_UINT64; in last_byte_offset()
7113 * TODO: Linux file offsets are _signed_ 64-bit quantities, which means that
7114 * we can't properly handle lock requests that go beyond the (2^63 - 1)-th
7115 * byte, because of sign extension problems. Since NFSv4 calls for 64-bit
7116 * locking, this prevents us from being completely protocol-compliant. The
7123 if (lock->fl_start < 0) in nfs4_transform_lock_offset()
7124 lock->fl_start = OFFSET_MAX; in nfs4_transform_lock_offset()
7125 if (lock->fl_end < 0) in nfs4_transform_lock_offset()
7126 lock->fl_end = OFFSET_MAX; in nfs4_transform_lock_offset()
7134 nfs4_get_stateowner(&lo->lo_owner); in nfsd4_lm_get_owner()
7144 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_lm_put_owner()
7151 struct nfs4_lockowner *lo = (struct nfs4_lockowner *)cfl->fl_owner; in nfsd4_lm_lock_expirable()
7152 struct nfs4_client *clp = lo->lo_owner.so_client; in nfsd4_lm_lock_expirable()
7156 nn = net_generic(clp->net, nfsd_net_id); in nfsd4_lm_lock_expirable()
7157 mod_delayed_work(laundry_wq, &nn->laundromat_work, 0); in nfsd4_lm_lock_expirable()
7173 struct nfs4_lockowner *lo = (struct nfs4_lockowner *)fl->fl_owner; in nfsd4_lm_notify()
7174 struct net *net = lo->lo_owner.so_client->net; in nfsd4_lm_notify()
7181 spin_lock(&nn->blocked_locks_lock); in nfsd4_lm_notify()
7182 if (!list_empty(&nbl->nbl_list)) { in nfsd4_lm_notify()
7183 list_del_init(&nbl->nbl_list); in nfsd4_lm_notify()
7184 list_del_init(&nbl->nbl_lru); in nfsd4_lm_notify()
7187 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lm_notify()
7191 nfsd4_run_cb(&nbl->nbl_cb); in nfsd4_lm_notify()
7209 if (fl->fl_lmops == &nfsd_posix_mng_ops) { in nfs4_set_lock_denied()
7210 lo = (struct nfs4_lockowner *) fl->fl_owner; in nfs4_set_lock_denied()
7211 xdr_netobj_dup(&deny->ld_owner, &lo->lo_owner.so_owner, in nfs4_set_lock_denied()
7213 if (!deny->ld_owner.data) in nfs4_set_lock_denied()
7216 deny->ld_clientid = lo->lo_owner.so_client->cl_clientid; in nfs4_set_lock_denied()
7219 deny->ld_owner.len = 0; in nfs4_set_lock_denied()
7220 deny->ld_owner.data = NULL; in nfs4_set_lock_denied()
7221 deny->ld_clientid.cl_boot = 0; in nfs4_set_lock_denied()
7222 deny->ld_clientid.cl_id = 0; in nfs4_set_lock_denied()
7224 deny->ld_start = fl->fl_start; in nfs4_set_lock_denied()
7225 deny->ld_length = NFS4_MAX_UINT64; in nfs4_set_lock_denied()
7226 if (fl->fl_end != NFS4_MAX_UINT64) in nfs4_set_lock_denied()
7227 deny->ld_length = fl->fl_end - fl->fl_start + 1; in nfs4_set_lock_denied()
7228 deny->ld_type = NFS4_READ_LT; in nfs4_set_lock_denied()
7229 if (fl->fl_type != F_RDLCK) in nfs4_set_lock_denied()
7230 deny->ld_type = NFS4_WRITE_LT; in nfs4_set_lock_denied()
7239 lockdep_assert_held(&clp->cl_lock); in find_lockowner_str_locked()
7241 list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[strhashval], in find_lockowner_str_locked()
7243 if (so->so_is_open_owner) in find_lockowner_str_locked()
7256 spin_lock(&clp->cl_lock); in find_lockowner_str()
7258 spin_unlock(&clp->cl_lock); in find_lockowner_str()
7281 * Called in nfsd4_lock - therefore, OPEN and OPEN_CONFIRM (if needed) has
7293 lo = alloc_stateowner(lockowner_slab, &lock->lk_new_owner, clp); in alloc_init_lock_stateowner()
7296 INIT_LIST_HEAD(&lo->lo_blocked); in alloc_init_lock_stateowner()
7297 INIT_LIST_HEAD(&lo->lo_owner.so_stateids); in alloc_init_lock_stateowner()
7298 lo->lo_owner.so_is_open_owner = 0; in alloc_init_lock_stateowner()
7299 lo->lo_owner.so_seqid = lock->lk_new_lock_seqid; in alloc_init_lock_stateowner()
7300 lo->lo_owner.so_ops = &lockowner_ops; in alloc_init_lock_stateowner()
7301 spin_lock(&clp->cl_lock); in alloc_init_lock_stateowner()
7302 ret = find_lockowner_str_locked(clp, &lock->lk_new_owner); in alloc_init_lock_stateowner()
7304 list_add(&lo->lo_owner.so_strhash, in alloc_init_lock_stateowner()
7305 &clp->cl_ownerstr_hashtbl[strhashval]); in alloc_init_lock_stateowner()
7308 nfs4_free_stateowner(&lo->lo_owner); in alloc_init_lock_stateowner()
7310 spin_unlock(&clp->cl_lock); in alloc_init_lock_stateowner()
7320 lockdep_assert_held(&ost->st_stid.sc_client->cl_lock); in find_lock_stateid()
7322 /* If ost is not hashed, ost->st_locks will not be valid */ in find_lock_stateid()
7324 list_for_each_entry(lst, &ost->st_locks, st_locks) { in find_lock_stateid()
7325 if (lst->st_stateowner == &lo->lo_owner) { in find_lock_stateid()
7326 refcount_inc(&lst->st_stid.sc_count); in find_lock_stateid()
7338 struct nfs4_client *clp = lo->lo_owner.so_client; in init_lock_stateid()
7341 mutex_init(&stp->st_mutex); in init_lock_stateid()
7342 mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX); in init_lock_stateid()
7344 spin_lock(&clp->cl_lock); in init_lock_stateid()
7350 refcount_inc(&stp->st_stid.sc_count); in init_lock_stateid()
7351 stp->st_stid.sc_type = NFS4_LOCK_STID; in init_lock_stateid()
7352 stp->st_stateowner = nfs4_get_stateowner(&lo->lo_owner); in init_lock_stateid()
7354 stp->st_stid.sc_file = fp; in init_lock_stateid()
7355 stp->st_access_bmap = 0; in init_lock_stateid()
7356 stp->st_deny_bmap = open_stp->st_deny_bmap; in init_lock_stateid()
7357 stp->st_openstp = open_stp; in init_lock_stateid()
7358 spin_lock(&fp->fi_lock); in init_lock_stateid()
7359 list_add(&stp->st_locks, &open_stp->st_locks); in init_lock_stateid()
7360 list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids); in init_lock_stateid()
7361 list_add(&stp->st_perfile, &fp->fi_stateids); in init_lock_stateid()
7362 spin_unlock(&fp->fi_lock); in init_lock_stateid()
7363 spin_unlock(&clp->cl_lock); in init_lock_stateid()
7366 spin_unlock(&clp->cl_lock); in init_lock_stateid()
7368 nfs4_put_stid(&retstp->st_stid); in init_lock_stateid()
7372 mutex_unlock(&stp->st_mutex); in init_lock_stateid()
7375 spin_unlock(&clp->cl_lock); in init_lock_stateid()
7376 mutex_unlock(&stp->st_mutex); in init_lock_stateid()
7387 struct nfs4_openowner *oo = openowner(ost->st_stateowner); in find_or_create_lock_stateid()
7388 struct nfs4_client *clp = oo->oo_owner.so_client; in find_or_create_lock_stateid()
7391 spin_lock(&clp->cl_lock); in find_or_create_lock_stateid()
7393 spin_unlock(&clp->cl_lock); in find_or_create_lock_stateid()
7397 nfs4_put_stid(&lst->st_stid); in find_or_create_lock_stateid()
7421 struct nfs4_file *fp = lock_stp->st_stid.sc_file; in get_lock_access()
7423 lockdep_assert_held(&fp->fi_lock); in get_lock_access()
7438 struct nfs4_file *fi = ost->st_stid.sc_file; in lookup_or_create_lock_state()
7439 struct nfs4_openowner *oo = openowner(ost->st_stateowner); in lookup_or_create_lock_state()
7440 struct nfs4_client *cl = oo->oo_owner.so_client; in lookup_or_create_lock_state()
7441 struct inode *inode = d_inode(cstate->current_fh.fh_dentry); in lookup_or_create_lock_state()
7446 lo = find_lockowner_str(cl, &lock->lk_new_owner); in lookup_or_create_lock_state()
7448 strhashval = ownerstr_hashval(&lock->lk_new_owner); in lookup_or_create_lock_state()
7455 if (!cstate->minorversion && in lookup_or_create_lock_state()
7456 lock->lk_new_lock_seqid != lo->lo_owner.so_seqid) in lookup_or_create_lock_state()
7469 nfs4_put_stateowner(&lo->lo_owner); in lookup_or_create_lock_state()
7480 struct nfsd4_lock *lock = &u->lock; in nfsd4_lock()
7501 (long long) lock->lk_offset, in nfsd4_lock()
7502 (long long) lock->lk_length); in nfsd4_lock()
7504 if (check_lock_length(lock->lk_offset, lock->lk_length)) in nfsd4_lock()
7507 if ((status = fh_verify(rqstp, &cstate->current_fh, in nfsd4_lock()
7512 sb = cstate->current_fh.fh_dentry->d_sb; in nfsd4_lock()
7514 if (lock->lk_is_new) { in nfsd4_lock()
7517 memcpy(&lock->lk_new_clientid, in nfsd4_lock()
7518 &cstate->clp->cl_clientid, in nfsd4_lock()
7523 lock->lk_new_open_seqid, in nfsd4_lock()
7524 &lock->lk_new_open_stateid, in nfsd4_lock()
7528 mutex_unlock(&open_stp->st_mutex); in nfsd4_lock()
7529 open_sop = openowner(open_stp->st_stateowner); in nfsd4_lock()
7531 if (!same_clid(&open_sop->oo_owner.so_client->cl_clientid, in nfsd4_lock()
7532 &lock->lk_new_clientid)) in nfsd4_lock()
7538 lock->lk_old_lock_seqid, in nfsd4_lock()
7539 &lock->lk_old_lock_stateid, in nfsd4_lock()
7544 lock_sop = lockowner(lock_stp->st_stateowner); in nfsd4_lock()
7546 lkflg = setlkflg(lock->lk_type); in nfsd4_lock()
7552 if (locks_in_grace(net) && !lock->lk_reclaim) in nfsd4_lock()
7555 if (!locks_in_grace(net) && lock->lk_reclaim) in nfsd4_lock()
7558 if (lock->lk_reclaim) in nfsd4_lock()
7561 fp = lock_stp->st_stid.sc_file; in nfsd4_lock()
7562 switch (lock->lk_type) { in nfsd4_lock()
7565 exportfs_lock_op_is_async(sb->s_export_op)) in nfsd4_lock()
7569 spin_lock(&fp->fi_lock); in nfsd4_lock()
7573 spin_unlock(&fp->fi_lock); in nfsd4_lock()
7578 exportfs_lock_op_is_async(sb->s_export_op)) in nfsd4_lock()
7582 spin_lock(&fp->fi_lock); in nfsd4_lock()
7586 spin_unlock(&fp->fi_lock); in nfsd4_lock()
7600 * Most filesystems with their own ->lock operations will block in nfsd4_lock()
7606 if (!exportfs_lock_op_is_async(sb->s_export_op)) in nfsd4_lock()
7609 nbl = find_or_allocate_block(lock_sop, &fp->fi_fhandle, nn); in nfsd4_lock()
7616 file_lock = &nbl->nbl_lock; in nfsd4_lock()
7617 file_lock->fl_type = fl_type; in nfsd4_lock()
7618 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(&lock_sop->lo_owner)); in nfsd4_lock()
7619 file_lock->fl_pid = current->tgid; in nfsd4_lock()
7620 file_lock->fl_file = nf->nf_file; in nfsd4_lock()
7621 file_lock->fl_flags = fl_flags; in nfsd4_lock()
7622 file_lock->fl_lmops = &nfsd_posix_mng_ops; in nfsd4_lock()
7623 file_lock->fl_start = lock->lk_offset; in nfsd4_lock()
7624 file_lock->fl_end = last_byte_offset(lock->lk_offset, lock->lk_length); in nfsd4_lock()
7635 nbl->nbl_time = ktime_get_boottime_seconds(); in nfsd4_lock()
7636 spin_lock(&nn->blocked_locks_lock); in nfsd4_lock()
7637 list_add_tail(&nbl->nbl_list, &lock_sop->lo_blocked); in nfsd4_lock()
7638 list_add_tail(&nbl->nbl_lru, &nn->blocked_locks_lru); in nfsd4_lock()
7639 kref_get(&nbl->nbl_kref); in nfsd4_lock()
7640 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lock()
7643 err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, conflock); in nfsd4_lock()
7646 nfs4_inc_and_copy_stateid(&lock->lk_resp_stateid, &lock_stp->st_stid); in nfsd4_lock()
7648 if (lock->lk_reclaim) in nfsd4_lock()
7649 nn->somebody_reclaimed = true; in nfsd4_lock()
7652 kref_put(&nbl->nbl_kref, free_nbl); in nfsd4_lock()
7655 case -EAGAIN: /* conflock holds conflicting lock */ in nfsd4_lock()
7658 nfs4_set_lock_denied(conflock, &lock->lk_denied); in nfsd4_lock()
7660 case -EDEADLK: in nfsd4_lock()
7672 spin_lock(&nn->blocked_locks_lock); in nfsd4_lock()
7673 if (!list_empty(&nbl->nbl_list) && in nfsd4_lock()
7674 !list_empty(&nbl->nbl_lru)) { in nfsd4_lock()
7675 list_del_init(&nbl->nbl_list); in nfsd4_lock()
7676 list_del_init(&nbl->nbl_lru); in nfsd4_lock()
7677 kref_put(&nbl->nbl_kref, free_nbl); in nfsd4_lock()
7680 spin_unlock(&nn->blocked_locks_lock); in nfsd4_lock()
7688 if (cstate->replay_owner && in nfsd4_lock()
7689 cstate->replay_owner != &lock_sop->lo_owner && in nfsd4_lock()
7691 lock_sop->lo_owner.so_seqid++; in nfsd4_lock()
7694 * If this is a new, never-before-used stateid, and we are in nfsd4_lock()
7700 mutex_unlock(&lock_stp->st_mutex); in nfsd4_lock()
7702 nfs4_put_stid(&lock_stp->st_stid); in nfsd4_lock()
7705 nfs4_put_stid(&open_stp->st_stid); in nfsd4_lock()
7714 struct nfsd4_lock *lock = &u->lock; in nfsd4_lock_release()
7715 struct nfsd4_lock_denied *deny = &lock->lk_denied; in nfsd4_lock_release()
7717 kfree(deny->ld_owner.data); in nfsd4_lock_release()
7734 inode = fhp->fh_dentry->d_inode; in nfsd_test_lock()
7739 lock->fl_file = nf->nf_file; in nfsd_test_lock()
7740 err = nfserrno(vfs_test_lock(nf->nf_file, lock)); in nfsd_test_lock()
7741 lock->fl_file = NULL; in nfsd_test_lock()
7755 struct nfsd4_lockt *lockt = &u->lockt; in nfsd4_lockt()
7764 if (check_lock_length(lockt->lt_offset, lockt->lt_length)) in nfsd4_lockt()
7768 status = set_client(&lockt->lt_clientid, cstate, nn); in nfsd4_lockt()
7773 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) in nfsd4_lockt()
7783 switch (lockt->lt_type) { in nfsd4_lockt()
7786 file_lock->fl_type = F_RDLCK; in nfsd4_lockt()
7790 file_lock->fl_type = F_WRLCK; in nfsd4_lockt()
7798 lo = find_lockowner_str(cstate->clp, &lockt->lt_owner); in nfsd4_lockt()
7800 file_lock->fl_owner = (fl_owner_t)lo; in nfsd4_lockt()
7801 file_lock->fl_pid = current->tgid; in nfsd4_lockt()
7802 file_lock->fl_flags = FL_POSIX; in nfsd4_lockt()
7804 file_lock->fl_start = lockt->lt_offset; in nfsd4_lockt()
7805 file_lock->fl_end = last_byte_offset(lockt->lt_offset, lockt->lt_length); in nfsd4_lockt()
7809 status = nfsd_test_lock(rqstp, &cstate->current_fh, file_lock); in nfsd4_lockt()
7813 if (file_lock->fl_type != F_UNLCK) { in nfsd4_lockt()
7815 nfs4_set_lock_denied(file_lock, &lockt->lt_denied); in nfsd4_lockt()
7819 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_lockt()
7827 struct nfsd4_lockt *lockt = &u->lockt; in nfsd4_lockt_release()
7828 struct nfsd4_lock_denied *deny = &lockt->lt_denied; in nfsd4_lockt_release()
7830 kfree(deny->ld_owner.data); in nfsd4_lockt_release()
7837 struct nfsd4_locku *locku = &u->locku; in nfsd4_locku()
7846 (long long) locku->lu_offset, in nfsd4_locku()
7847 (long long) locku->lu_length); in nfsd4_locku()
7849 if (check_lock_length(locku->lu_offset, locku->lu_length)) in nfsd4_locku()
7852 status = nfs4_preprocess_seqid_op(cstate, locku->lu_seqid, in nfsd4_locku()
7853 &locku->lu_stateid, NFS4_LOCK_STID, in nfsd4_locku()
7857 nf = find_any_file(stp->st_stid.sc_file); in nfsd4_locku()
7869 file_lock->fl_type = F_UNLCK; in nfsd4_locku()
7870 file_lock->fl_owner = (fl_owner_t)lockowner(nfs4_get_stateowner(stp->st_stateowner)); in nfsd4_locku()
7871 file_lock->fl_pid = current->tgid; in nfsd4_locku()
7872 file_lock->fl_file = nf->nf_file; in nfsd4_locku()
7873 file_lock->fl_flags = FL_POSIX; in nfsd4_locku()
7874 file_lock->fl_lmops = &nfsd_posix_mng_ops; in nfsd4_locku()
7875 file_lock->fl_start = locku->lu_offset; in nfsd4_locku()
7877 file_lock->fl_end = last_byte_offset(locku->lu_offset, in nfsd4_locku()
7878 locku->lu_length); in nfsd4_locku()
7881 err = vfs_lock_file(nf->nf_file, F_SETLK, file_lock, NULL); in nfsd4_locku()
7886 nfs4_inc_and_copy_stateid(&locku->lu_stateid, &stp->st_stid); in nfsd4_locku()
7890 mutex_unlock(&stp->st_mutex); in nfsd4_locku()
7891 nfs4_put_stid(&stp->st_stid); in nfsd4_locku()
7917 spin_lock(&fp->fi_lock); in check_for_locks()
7925 inode = file_inode(nf->nf_file); in check_for_locks()
7928 if (flctx && !list_empty_careful(&flctx->flc_posix)) { in check_for_locks()
7929 spin_lock(&flctx->flc_lock); in check_for_locks()
7930 list_for_each_entry(fl, &flctx->flc_posix, fl_list) { in check_for_locks()
7931 if (fl->fl_owner == (fl_owner_t)lowner) { in check_for_locks()
7936 spin_unlock(&flctx->flc_lock); in check_for_locks()
7939 spin_unlock(&fp->fi_lock); in check_for_locks()
7944 * nfsd4_release_lockowner - process NFSv4.0 RELEASE_LOCKOWNER operations
7949 * Check if theree are any locks still held and if not - free the lockowner
7963 struct nfsd4_release_lockowner *rlockowner = &u->release_lockowner; in nfsd4_release_lockowner()
7965 clientid_t *clid = &rlockowner->rl_clientid; in nfsd4_release_lockowner()
7973 clid->cl_boot, clid->cl_id); in nfsd4_release_lockowner()
7978 clp = cstate->clp; in nfsd4_release_lockowner()
7980 spin_lock(&clp->cl_lock); in nfsd4_release_lockowner()
7981 lo = find_lockowner_str_locked(clp, &rlockowner->rl_owner); in nfsd4_release_lockowner()
7983 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
7987 list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) { in nfsd4_release_lockowner()
7988 if (check_for_locks(stp->st_stid.sc_file, lo)) { in nfsd4_release_lockowner()
7989 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
7990 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_release_lockowner()
7995 while (!list_empty(&lo->lo_owner.so_stateids)) { in nfsd4_release_lockowner()
7996 stp = list_first_entry(&lo->lo_owner.so_stateids, in nfsd4_release_lockowner()
8002 spin_unlock(&clp->cl_lock); in nfsd4_release_lockowner()
8006 nfs4_put_stateowner(&lo->lo_owner); in nfsd4_release_lockowner()
8022 return (crp && crp->cr_clp); in nfs4_has_reclaimed_state()
8041 INIT_LIST_HEAD(&crp->cr_strhash); in nfs4_client_to_reclaim()
8042 list_add(&crp->cr_strhash, &nn->reclaim_str_hashtbl[strhashval]); in nfs4_client_to_reclaim()
8043 crp->cr_name.data = name.data; in nfs4_client_to_reclaim()
8044 crp->cr_name.len = name.len; in nfs4_client_to_reclaim()
8045 crp->cr_princhash.data = princhash.data; in nfs4_client_to_reclaim()
8046 crp->cr_princhash.len = princhash.len; in nfs4_client_to_reclaim()
8047 crp->cr_clp = NULL; in nfs4_client_to_reclaim()
8048 nn->reclaim_str_hashtbl_size++; in nfs4_client_to_reclaim()
8056 list_del(&crp->cr_strhash); in nfs4_remove_reclaim_record()
8057 kfree(crp->cr_name.data); in nfs4_remove_reclaim_record()
8058 kfree(crp->cr_princhash.data); in nfs4_remove_reclaim_record()
8060 nn->reclaim_str_hashtbl_size--; in nfs4_remove_reclaim_record()
8070 while (!list_empty(&nn->reclaim_str_hashtbl[i])) { in nfs4_release_reclaim()
8071 crp = list_entry(nn->reclaim_str_hashtbl[i].next, in nfs4_release_reclaim()
8076 WARN_ON_ONCE(nn->reclaim_str_hashtbl_size); in nfs4_release_reclaim()
8088 list_for_each_entry(crp, &nn->reclaim_str_hashtbl[strhashval], cr_strhash) { in nfsd4_find_reclaim_client()
8089 if (compare_blob(&crp->cr_name, &name) == 0) { in nfsd4_find_reclaim_client()
8099 if (test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &clp->cl_flags)) in nfs4_check_open_reclaim()
8126 max_delegations = nr_free_buffer_pages() >> (20 - 2 - PAGE_SHIFT); in set_max_delegations()
8134 nn->conf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE, in nfs4_state_create_net()
8137 if (!nn->conf_id_hashtbl) in nfs4_state_create_net()
8139 nn->unconf_id_hashtbl = kmalloc_array(CLIENT_HASH_SIZE, in nfs4_state_create_net()
8142 if (!nn->unconf_id_hashtbl) in nfs4_state_create_net()
8144 nn->sessionid_hashtbl = kmalloc_array(SESSION_HASH_SIZE, in nfs4_state_create_net()
8147 if (!nn->sessionid_hashtbl) in nfs4_state_create_net()
8151 INIT_LIST_HEAD(&nn->conf_id_hashtbl[i]); in nfs4_state_create_net()
8152 INIT_LIST_HEAD(&nn->unconf_id_hashtbl[i]); in nfs4_state_create_net()
8155 INIT_LIST_HEAD(&nn->sessionid_hashtbl[i]); in nfs4_state_create_net()
8156 nn->conf_name_tree = RB_ROOT; in nfs4_state_create_net()
8157 nn->unconf_name_tree = RB_ROOT; in nfs4_state_create_net()
8158 nn->boot_time = ktime_get_real_seconds(); in nfs4_state_create_net()
8159 nn->grace_ended = false; in nfs4_state_create_net()
8160 nn->nfsd4_manager.block_opens = true; in nfs4_state_create_net()
8161 INIT_LIST_HEAD(&nn->nfsd4_manager.list); in nfs4_state_create_net()
8162 INIT_LIST_HEAD(&nn->client_lru); in nfs4_state_create_net()
8163 INIT_LIST_HEAD(&nn->close_lru); in nfs4_state_create_net()
8164 INIT_LIST_HEAD(&nn->del_recall_lru); in nfs4_state_create_net()
8165 spin_lock_init(&nn->client_lock); in nfs4_state_create_net()
8166 spin_lock_init(&nn->s2s_cp_lock); in nfs4_state_create_net()
8167 idr_init(&nn->s2s_cp_stateids); in nfs4_state_create_net()
8169 spin_lock_init(&nn->blocked_locks_lock); in nfs4_state_create_net()
8170 INIT_LIST_HEAD(&nn->blocked_locks_lru); in nfs4_state_create_net()
8172 INIT_DELAYED_WORK(&nn->laundromat_work, laundromat_main); in nfs4_state_create_net()
8173 INIT_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker); in nfs4_state_create_net()
8176 nn->nfsd_client_shrinker = shrinker_alloc(0, "nfsd-client"); in nfs4_state_create_net()
8177 if (!nn->nfsd_client_shrinker) in nfs4_state_create_net()
8180 nn->nfsd_client_shrinker->scan_objects = nfsd4_state_shrinker_scan; in nfs4_state_create_net()
8181 nn->nfsd_client_shrinker->count_objects = nfsd4_state_shrinker_count; in nfs4_state_create_net()
8182 nn->nfsd_client_shrinker->private_data = nn; in nfs4_state_create_net()
8184 shrinker_register(nn->nfsd_client_shrinker); in nfs4_state_create_net()
8190 kfree(nn->sessionid_hashtbl); in nfs4_state_create_net()
8192 kfree(nn->unconf_id_hashtbl); in nfs4_state_create_net()
8194 kfree(nn->conf_id_hashtbl); in nfs4_state_create_net()
8196 return -ENOMEM; in nfs4_state_create_net()
8207 while (!list_empty(&nn->conf_id_hashtbl[i])) { in nfs4_state_destroy_net()
8208 clp = list_entry(nn->conf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); in nfs4_state_destroy_net()
8213 WARN_ON(!list_empty(&nn->blocked_locks_lru)); in nfs4_state_destroy_net()
8216 while (!list_empty(&nn->unconf_id_hashtbl[i])) { in nfs4_state_destroy_net()
8217 clp = list_entry(nn->unconf_id_hashtbl[i].next, struct nfs4_client, cl_idhash); in nfs4_state_destroy_net()
8222 kfree(nn->sessionid_hashtbl); in nfs4_state_destroy_net()
8223 kfree(nn->unconf_id_hashtbl); in nfs4_state_destroy_net()
8224 kfree(nn->conf_id_hashtbl); in nfs4_state_destroy_net()
8237 locks_start_grace(net, &nn->nfsd4_manager); in nfs4_state_start_net()
8239 if (nn->track_reclaim_completes && nn->reclaim_str_hashtbl_size == 0) in nfs4_state_start_net()
8241 printk(KERN_INFO "NFSD: starting %lld-second grace period (net %x)\n", in nfs4_state_start_net()
8242 nn->nfsd4_grace, net->ns.inum); in nfs4_state_start_net()
8244 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_grace * HZ); in nfs4_state_start_net()
8249 net->ns.inum); in nfs4_state_start_net()
8250 queue_delayed_work(laundry_wq, &nn->laundromat_work, nn->nfsd4_lease * HZ); in nfs4_state_start_net()
8283 shrinker_free(nn->nfsd_client_shrinker); in nfs4_state_shutdown_net()
8284 cancel_work(&nn->nfsd_shrinker_work); in nfs4_state_shutdown_net()
8285 cancel_delayed_work_sync(&nn->laundromat_work); in nfs4_state_shutdown_net()
8286 locks_end_grace(&nn->nfsd4_manager); in nfs4_state_shutdown_net()
8290 list_for_each_safe(pos, next, &nn->del_recall_lru) { in nfs4_state_shutdown_net()
8293 list_add(&dp->dl_recall_lru, &reaplist); in nfs4_state_shutdown_net()
8298 list_del_init(&dp->dl_recall_lru); in nfs4_state_shutdown_net()
8321 memcpy(stateid, &cstate->current_stateid, sizeof(stateid_t)); in get_stateid()
8327 if (cstate->minorversion) { in put_stateid()
8328 memcpy(&cstate->current_stateid, stateid, sizeof(stateid_t)); in put_stateid()
8346 put_stateid(cstate, &u->open_downgrade.od_stateid); in nfsd4_set_opendowngradestateid()
8353 put_stateid(cstate, &u->open.op_stateid); in nfsd4_set_openstateid()
8360 put_stateid(cstate, &u->close.cl_stateid); in nfsd4_set_closestateid()
8367 put_stateid(cstate, &u->lock.lk_resp_stateid); in nfsd4_set_lockstateid()
8378 get_stateid(cstate, &u->open_downgrade.od_stateid); in nfsd4_get_opendowngradestateid()
8385 get_stateid(cstate, &u->delegreturn.dr_stateid); in nfsd4_get_delegreturnstateid()
8392 get_stateid(cstate, &u->free_stateid.fr_stateid); in nfsd4_get_freestateid()
8399 get_stateid(cstate, &u->setattr.sa_stateid); in nfsd4_get_setattrstateid()
8406 get_stateid(cstate, &u->close.cl_stateid); in nfsd4_get_closestateid()
8413 get_stateid(cstate, &u->locku.lu_stateid); in nfsd4_get_lockustateid()
8420 get_stateid(cstate, &u->read.rd_stateid); in nfsd4_get_readstateid()
8427 get_stateid(cstate, &u->write.wr_stateid); in nfsd4_get_writestateid()
8431 * nfsd4_deleg_getattr_conflict - Recall if GETATTR causes conflict
8460 spin_lock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
8461 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in nfsd4_deleg_getattr_conflict()
8462 if (fl->fl_flags == FL_LAYOUT) in nfsd4_deleg_getattr_conflict()
8464 if (fl->fl_lmops != &nfsd_lease_mng_ops) { in nfsd4_deleg_getattr_conflict()
8466 * non-nfs lease, if it's a lease with F_RDLCK then in nfsd4_deleg_getattr_conflict()
8470 if (fl->fl_type == F_RDLCK) in nfsd4_deleg_getattr_conflict()
8474 if (fl->fl_type == F_WRLCK) { in nfsd4_deleg_getattr_conflict()
8475 dp = fl->fl_owner; in nfsd4_deleg_getattr_conflict()
8476 if (dp->dl_recall.cb_clp == *(rqstp->rq_lease_breaker)) { in nfsd4_deleg_getattr_conflict()
8477 spin_unlock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
8481 spin_unlock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()
8491 spin_unlock(&ctx->flc_lock); in nfsd4_deleg_getattr_conflict()