Lines Matching +full:we +full:- +full:on +full:- +full:ns

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * We need to keep track of the svid values used for F_FLOCK locks.
60 int ns_svid; /* on-the-wire SVID for this file */
63 bool_t ns_active; /* TRUE if we own a lock */
112 p = td ? td->td_proc : NULL; in nlm_msg()
131 struct nfsmount *nmp = nf->nf_nmp; in nlm_down()
135 mtx_lock(&nmp->nm_mtx); in nlm_down()
136 if (!(nmp->nm_state & NFSSTA_LOCKTIMEO)) { in nlm_down()
137 nmp->nm_state |= NFSSTA_LOCKTIMEO; in nlm_down()
138 mtx_unlock(&nmp->nm_mtx); in nlm_down()
139 vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid, in nlm_down()
142 mtx_unlock(&nmp->nm_mtx); in nlm_down()
145 nf->nf_printed = TRUE; in nlm_down()
146 nlm_msg(td, nmp->nm_mountp->mnt_stat.f_mntfromname, msg, error); in nlm_down()
153 struct nfsmount *nmp = nf->nf_nmp; in nlm_up()
155 if (!nf->nf_printed) in nlm_up()
158 nlm_msg(td, nmp->nm_mountp->mnt_stat.f_mntfromname, msg, 0); in nlm_up()
160 mtx_lock(&nmp->nm_mtx); in nlm_up()
161 if (nmp->nm_state & NFSSTA_LOCKTIMEO) { in nlm_up()
162 nmp->nm_state &= ~NFSSTA_LOCKTIMEO; in nlm_up()
163 mtx_unlock(&nmp->nm_mtx); in nlm_up()
164 vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid, in nlm_up()
167 mtx_unlock(&nmp->nm_mtx); in nlm_up()
190 * nlm_advlock --
191 * NFS advisory byte-level locks.
213 struct nlm_file_svid *ns; in nlm_advlock_internal() local
221 nmp = VFSTONFS(vp->v_mount); in nlm_advlock_internal()
224 * so that if we are contending with another machine for a in nlm_advlock_internal()
225 * file, we get whatever they wrote and vice-versa. in nlm_advlock_internal()
228 nmp->nm_vinvalbuf(vp, V_SAVE, td, 1); in nlm_advlock_internal()
230 strcpy(servername, nmp->nm_hostname); in nlm_advlock_internal()
231 nmp->nm_getinfo(vp, fh.fh_bytes, &fhlen, &ss, &is_v3, &size, &timo); in nlm_advlock_internal()
238 if (nmp->nm_flag & NFSMNT_SOFT) in nlm_advlock_internal()
239 retries = nmp->nm_retry; in nlm_advlock_internal()
244 * We need to switch to mount-point creds so that we can send in nlm_advlock_internal()
249 cred = td->td_ucred; in nlm_advlock_internal()
250 td->td_ucred = vp->v_mount->mnt_cred; in nlm_advlock_internal()
251 crhold(td->td_ucred); in nlm_advlock_internal()
267 ns = NULL; in nlm_advlock_internal()
269 ns = nlm_find_svid(id); in nlm_advlock_internal()
270 KASSERT(fl->l_start == 0 && fl->l_len == 0, in nlm_advlock_internal()
271 ("F_FLOCK lock requests must be whole-file locks")); in nlm_advlock_internal()
272 if (!ns->ns_ucred) { in nlm_advlock_internal()
275 * we need to recover the lock later. in nlm_advlock_internal()
277 ns->ns_ucred = crdup(cred); in nlm_advlock_internal()
279 svid = ns->ns_svid; in nlm_advlock_internal()
282 * If we are recovering after a server restart or in nlm_advlock_internal()
283 * trashing locks on a force unmount, use the same in nlm_advlock_internal()
286 svid = fl->l_pid; in nlm_advlock_internal()
288 svid = ((struct proc *) id)->p_pid; in nlm_advlock_internal()
294 && fl->l_type == F_WRLCK) { in nlm_advlock_internal()
297 * shared lock on the file must be released in nlm_advlock_internal()
300 * unlocking the file before sleeping on a in nlm_advlock_internal()
301 * blocked exclusive lock request. We in nlm_advlock_internal()
303 * non-blocking and if that fails, we unlock in nlm_advlock_internal()
310 fl->l_type = F_UNLCK; in nlm_advlock_internal()
314 fl->l_type = F_WRLCK; in nlm_advlock_internal()
317 if (ns->ns_active) { in nlm_advlock_internal()
318 ns->ns_refs--; in nlm_advlock_internal()
319 ns->ns_active = FALSE; in nlm_advlock_internal()
334 if (!error && ns) { in nlm_advlock_internal()
336 if (!ns->ns_active) { in nlm_advlock_internal()
341 * F_FLOCK only supports whole-file in nlm_advlock_internal()
345 ns->ns_refs++; in nlm_advlock_internal()
346 ns->ns_active = TRUE; in nlm_advlock_internal()
355 if (!error && ns) { in nlm_advlock_internal()
357 if (ns->ns_active) { in nlm_advlock_internal()
358 ns->ns_refs--; in nlm_advlock_internal()
359 ns->ns_active = FALSE; in nlm_advlock_internal()
375 if (ns) in nlm_advlock_internal()
376 nlm_free_svid(ns); in nlm_advlock_internal()
378 cred1 = td->td_ucred; in nlm_advlock_internal()
379 td->td_ucred = cred; in nlm_advlock_internal()
392 return (nlm_advlock_internal(ap->a_vp, ap->a_id, ap->a_op, ap->a_fl, in nlm_advlock()
393 ap->a_flags, FALSE, TRUE)); in nlm_advlock()
405 struct nlm_file_svid *ns; in nlm_set_creds_for_lock() local
410 if (fl->l_pid > PID_MAX) { in nlm_set_creds_for_lock()
412 * If this was originally a F_FLOCK-style lock, we in nlm_set_creds_for_lock()
418 for (ns = LIST_FIRST(&nlm_file_svids[i]); ns; in nlm_set_creds_for_lock()
419 ns = LIST_NEXT(ns, ns_link)) { in nlm_set_creds_for_lock()
420 if (ns->ns_svid == fl->l_pid) { in nlm_set_creds_for_lock()
421 cred = crhold(ns->ns_ucred); in nlm_set_creds_for_lock()
432 p = pfind(fl->l_pid); in nlm_set_creds_for_lock()
434 cred = crhold(p->p_ucred); in nlm_set_creds_for_lock()
440 * If we can't find a cred, fall back on the recovery in nlm_set_creds_for_lock()
444 cred = crhold(td->td_ucred); in nlm_set_creds_for_lock()
447 td->td_ucred = cred; in nlm_set_creds_for_lock()
461 oldcred = td->td_ucred; in nlm_reclaim_free_lock()
467 crfree(td->td_ucred); in nlm_reclaim_free_lock()
468 td->td_ucred = oldcred; in nlm_reclaim_free_lock()
477 nlm_cancel_wait(ap->a_vp); in nlm_reclaim()
478 lf_iteratelocks_vnode(ap->a_vp, nlm_reclaim_free_lock, NULL); in nlm_reclaim()
483 struct nlm_host *nr_host; /* host we are recovering */
497 * must have rebooted a second time. In that case, we must in nlm_client_recover_lock()
500 state = nlm_host_get_state(nr->nr_host); in nlm_client_recover_lock()
501 if (nr->nr_state != state) in nlm_client_recover_lock()
508 oldcred = td->td_ucred; in nlm_client_recover_lock()
514 crfree(td->td_ucred); in nlm_client_recover_lock()
515 td->td_ucred = oldcred; in nlm_client_recover_lock()
539 dst->caller_name = src->caller_name; in nlm_convert_to_nlm_lock()
540 dst->fh = src->fh; in nlm_convert_to_nlm_lock()
541 dst->oh = src->oh; in nlm_convert_to_nlm_lock()
542 dst->svid = src->svid; in nlm_convert_to_nlm_lock()
543 dst->l_offset = src->l_offset; in nlm_convert_to_nlm_lock()
544 dst->l_len = src->l_len; in nlm_convert_to_nlm_lock()
551 dst->exclusive = src->exclusive; in nlm_convert_to_nlm4_holder()
552 dst->svid = src->svid; in nlm_convert_to_nlm4_holder()
553 dst->oh = src->oh; in nlm_convert_to_nlm4_holder()
554 dst->l_offset = src->l_offset; in nlm_convert_to_nlm4_holder()
555 dst->l_len = src->l_len; in nlm_convert_to_nlm4_holder()
561 dst->cookie = src->cookie; in nlm_convert_to_nlm4_res()
562 dst->stat.stat = (enum nlm4_stats) src->stat.stat; in nlm_convert_to_nlm4_res()
576 args1.cookie = args->cookie; in nlm_test_rpc()
577 args1.exclusive = args->exclusive; in nlm_test_rpc()
578 nlm_convert_to_nlm_lock(&args1.alock, &args->alock); in nlm_test_rpc()
584 res->cookie = res1.cookie; in nlm_test_rpc()
585 res->stat.stat = (enum nlm4_stats) res1.stat.stat; in nlm_test_rpc()
588 &res->stat.nlm4_testrply_u.holder, in nlm_test_rpc()
607 args1.cookie = args->cookie; in nlm_lock_rpc()
608 args1.block = args->block; in nlm_lock_rpc()
609 args1.exclusive = args->exclusive; in nlm_lock_rpc()
610 nlm_convert_to_nlm_lock(&args1.alock, &args->alock); in nlm_lock_rpc()
611 args1.reclaim = args->reclaim; in nlm_lock_rpc()
612 args1.state = args->state; in nlm_lock_rpc()
636 args1.cookie = args->cookie; in nlm_cancel_rpc()
637 args1.block = args->block; in nlm_cancel_rpc()
638 args1.exclusive = args->exclusive; in nlm_cancel_rpc()
639 nlm_convert_to_nlm_lock(&args1.alock, &args->alock); in nlm_cancel_rpc()
663 args1.cookie = args->cookie; in nlm_unlock_rpc()
664 nlm_convert_to_nlm_lock(&args1.alock, &args->alock); in nlm_unlock_rpc()
678 * Called after a lock request (set or clear) succeeded. We record the
680 * server has granted the lock, we can be sure that it doesn't
681 * conflict with any other locks we have in the local lock manager.
684 * our NLM server, we use a different sysid value to record our own
689 * many local threads are contending for the same lock), we must use a
691 * We expect that any actual wait will be rare and short hence we
710 newfl.l_start = fl->l_start; in nlm_record_lock()
711 newfl.l_len = fl->l_len; in nlm_record_lock()
712 newfl.l_type = fl->l_type; in nlm_record_lock()
713 newfl.l_whence = fl->l_whence; in nlm_record_lock()
718 error = lf_advlockasync(&a, &vp->v_lockf, size); in nlm_record_lock()
722 * not with threads. Suppose we have two in nlm_record_lock()
728 * advlock manager. The process B owns lock on in nlm_record_lock()
729 * f2 and issued the lock on f1. Remote would in nlm_record_lock()
730 * grant B the request on f1, but local would in nlm_record_lock()
744 * There is no sense in re-trying recording in nlm_record_lock()
754 ("Failed to register NFS lock locally - error=%d", error)); in nlm_record_lock()
777 exclusive = (fl->l_type == F_WRLCK); in nlm_setlock()
809 retries--; in nlm_setlock()
844 * granted messages and server reboots, we in nlm_setlock()
845 * will also re-try every few seconds. in nlm_setlock()
856 * We need to call the server to in nlm_setlock()
883 * We need to cope in nlm_setlock()
888 * we have to keep in nlm_setlock()
906 * to cancel. We are in nlm_setlock()
908 * and assume we got in nlm_setlock()
917 * recently rebooted - in nlm_setlock()
926 * We managed to in nlm_setlock()
934 * implementation - in nlm_setlock()
992 retries--; in nlm_clearlock()
1017 * If we are being called via nlm_reclaim (which will in nlm_clearlock()
1050 exclusive = (fl->l_type == F_WRLCK); in nlm_getlock()
1073 retries--; in nlm_getlock()
1096 fl->l_start = h->l_offset; in nlm_getlock()
1097 fl->l_len = h->l_len; in nlm_getlock()
1098 fl->l_pid = h->svid; in nlm_getlock()
1099 if (h->exclusive) in nlm_getlock()
1100 fl->l_type = F_WRLCK; in nlm_getlock()
1102 fl->l_type = F_RDLCK; in nlm_getlock()
1103 fl->l_whence = SEEK_SET; in nlm_getlock()
1104 fl->l_sysid = 0; in nlm_getlock()
1106 fl->l_type = F_UNLCK; in nlm_getlock()
1151 struct nlm_file_svid *ns, *newns; in nlm_find_svid() local
1157 LIST_FOREACH(ns, &nlm_file_svids[h], ns_link) { in nlm_find_svid()
1158 if (ns->ns_id == id) { in nlm_find_svid()
1159 ns->ns_refs++; in nlm_find_svid()
1164 if (!ns) { in nlm_find_svid()
1168 newns->ns_refs = 1; in nlm_find_svid()
1169 newns->ns_id = id; in nlm_find_svid()
1170 newns->ns_svid = svid; in nlm_find_svid()
1171 newns->ns_ucred = NULL; in nlm_find_svid()
1172 newns->ns_active = FALSE; in nlm_find_svid()
1175 * We need to check for a race with some other in nlm_find_svid()
1179 LIST_FOREACH(ns, &nlm_file_svids[h], ns_link) { in nlm_find_svid()
1180 if (ns->ns_id == id) { in nlm_find_svid()
1181 ns->ns_refs++; in nlm_find_svid()
1185 if (ns) { in nlm_find_svid()
1187 free_unr(nlm_svid_allocator, newns->ns_svid); in nlm_find_svid()
1192 ns = newns; in nlm_find_svid()
1197 return (ns); in nlm_find_svid()
1201 nlm_free_svid(struct nlm_file_svid *ns) in nlm_free_svid() argument
1205 ns->ns_refs--; in nlm_free_svid()
1206 if (!ns->ns_refs) { in nlm_free_svid()
1207 KASSERT(!ns->ns_active, ("Freeing active SVID")); in nlm_free_svid()
1208 LIST_REMOVE(ns, ns_link); in nlm_free_svid()
1210 free_unr(nlm_svid_allocator, ns->ns_svid); in nlm_free_svid()
1211 if (ns->ns_ucred) in nlm_free_svid()
1212 crfree(ns->ns_ucred); in nlm_free_svid()
1213 free(ns, M_NLM); in nlm_free_svid()
1227 if (fl->l_whence == SEEK_END) { in nlm_init_lock()
1229 || (fl->l_start > 0 && size > OFF_MAX - fl->l_start)) in nlm_init_lock()
1231 start = size + fl->l_start; in nlm_init_lock()
1232 } else if (fl->l_whence == SEEK_SET || fl->l_whence == SEEK_CUR) { in nlm_init_lock()
1233 start = fl->l_start; in nlm_init_lock()
1239 if (fl->l_len < 0) { in nlm_init_lock()
1240 len = -fl->l_len; in nlm_init_lock()
1241 start -= len; in nlm_init_lock()
1245 len = fl->l_len; in nlm_init_lock()
1250 * Enforce range limits on V1 locks in nlm_init_lock()
1258 getcredhostname(NULL, oh_space + oh_len, 32 - oh_len); in nlm_init_lock()
1262 lock->caller_name = prison0.pr_hostname; in nlm_init_lock()
1263 lock->fh.n_len = fhlen; in nlm_init_lock()
1264 lock->fh.n_bytes = fh; in nlm_init_lock()
1265 lock->oh.n_len = oh_len; in nlm_init_lock()
1266 lock->oh.n_bytes = oh_space; in nlm_init_lock()
1267 lock->svid = svid; in nlm_init_lock()
1268 lock->l_offset = start; in nlm_init_lock()
1269 lock->l_len = len; in nlm_init_lock()