nfs_lock.c revision 1.1.1.1.10.2 1 1.1.1.1.10.2 tls /* $NetBSD: nfs_lock.c,v 1.1.1.1.10.2 2014/08/20 00:04:27 tls Exp $ */
2 1.1.1.1.10.2 tls /*-
3 1.1.1.1.10.2 tls * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
4 1.1.1.1.10.2 tls *
5 1.1.1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
6 1.1.1.1.10.2 tls * modification, are permitted provided that the following conditions
7 1.1.1.1.10.2 tls * are met:
8 1.1.1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
9 1.1.1.1.10.2 tls * notice, this list of conditions and the following disclaimer.
10 1.1.1.1.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
11 1.1.1.1.10.2 tls * notice, this list of conditions and the following disclaimer in the
12 1.1.1.1.10.2 tls * documentation and/or other materials provided with the distribution.
13 1.1.1.1.10.2 tls * 3. Berkeley Software Design Inc's name may not be used to endorse or
14 1.1.1.1.10.2 tls * promote products derived from this software without specific prior
15 1.1.1.1.10.2 tls * written permission.
16 1.1.1.1.10.2 tls *
17 1.1.1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
18 1.1.1.1.10.2 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.1.1.1.10.2 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.1.1.1.10.2 tls * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
21 1.1.1.1.10.2 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.1.1.1.10.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.1.1.1.10.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1.1.1.10.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.1.1.1.10.2 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.1.1.1.10.2 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.1.1.1.10.2 tls * SUCH DAMAGE.
28 1.1.1.1.10.2 tls *
29 1.1.1.1.10.2 tls * from BSDI nfs_lock.c,v 2.4 1998/12/14 23:49:56 jch Exp
30 1.1.1.1.10.2 tls */
31 1.1.1.1.10.2 tls
32 1.1.1.1.10.2 tls #include <sys/cdefs.h>
33 1.1.1.1.10.2 tls /* __FBSDID("FreeBSD: head/sys/nfs/nfs_lock.c 227293 2011-11-07 06:44:47Z ed "); */
34 1.1.1.1.10.2 tls __RCSID("$NetBSD: nfs_lock.c,v 1.1.1.1.10.2 2014/08/20 00:04:27 tls Exp $");
35 1.1.1.1.10.2 tls
36 1.1.1.1.10.2 tls #include <sys/param.h>
37 1.1.1.1.10.2 tls #include <sys/systm.h>
38 1.1.1.1.10.2 tls #include <sys/conf.h>
39 1.1.1.1.10.2 tls #include <sys/fcntl.h>
40 1.1.1.1.10.2 tls #include <sys/kernel.h> /* for hz */
41 1.1.1.1.10.2 tls #include <sys/limits.h>
42 1.1.1.1.10.2 tls #include <sys/lock.h>
43 1.1.1.1.10.2 tls #include <sys/malloc.h>
44 1.1.1.1.10.2 tls #include <sys/lockf.h> /* for hz */ /* Must come after sys/malloc.h */
45 1.1.1.1.10.2 tls #include <sys/mbuf.h>
46 1.1.1.1.10.2 tls #include <sys/mount.h>
47 1.1.1.1.10.2 tls #include <sys/namei.h>
48 1.1.1.1.10.2 tls #include <sys/priv.h>
49 1.1.1.1.10.2 tls #include <sys/proc.h>
50 1.1.1.1.10.2 tls #include <sys/resourcevar.h>
51 1.1.1.1.10.2 tls #include <sys/socket.h>
52 1.1.1.1.10.2 tls #include <sys/socket.h>
53 1.1.1.1.10.2 tls #include <sys/unistd.h>
54 1.1.1.1.10.2 tls #include <sys/vnode.h>
55 1.1.1.1.10.2 tls
56 1.1.1.1.10.2 tls #include <net/if.h>
57 1.1.1.1.10.2 tls
58 1.1.1.1.10.2 tls #include <nfs/nfsproto.h>
59 1.1.1.1.10.2 tls #include <nfs/nfs_lock.h>
60 1.1.1.1.10.2 tls #include <nfsclient/nfs.h>
61 1.1.1.1.10.2 tls #include <nfsclient/nfsmount.h>
62 1.1.1.1.10.2 tls #include <nfsclient/nfsnode.h>
63 1.1.1.1.10.2 tls #include <nfsclient/nlminfo.h>
64 1.1.1.1.10.2 tls
65 1.1.1.1.10.2 tls extern void (*nlminfo_release_p)(struct proc *p);
66 1.1.1.1.10.2 tls
67 1.1.1.1.10.2 tls vop_advlock_t *nfs_advlock_p = nfs_dolock;
68 1.1.1.1.10.2 tls vop_reclaim_t *nfs_reclaim_p = NULL;
69 1.1.1.1.10.2 tls
70 1.1.1.1.10.2 tls static MALLOC_DEFINE(M_NFSLOCK, "nfsclient_lock", "NFS lock request");
71 1.1.1.1.10.2 tls static MALLOC_DEFINE(M_NLMINFO, "nfsclient_nlminfo",
72 1.1.1.1.10.2 tls "NFS lock process structure");
73 1.1.1.1.10.2 tls
74 1.1.1.1.10.2 tls static int nfslockdans(struct thread *td, struct lockd_ans *ansp);
75 1.1.1.1.10.2 tls static void nlminfo_release(struct proc *p);
76 1.1.1.1.10.2 tls /*
77 1.1.1.1.10.2 tls * --------------------------------------------------------------------
78 1.1.1.1.10.2 tls * A miniature device driver which the userland uses to talk to us.
79 1.1.1.1.10.2 tls *
80 1.1.1.1.10.2 tls */
81 1.1.1.1.10.2 tls
82 1.1.1.1.10.2 tls static struct cdev *nfslock_dev;
83 1.1.1.1.10.2 tls static struct mtx nfslock_mtx;
84 1.1.1.1.10.2 tls static int nfslock_isopen;
85 1.1.1.1.10.2 tls static TAILQ_HEAD(,__lock_msg) nfslock_list;
86 1.1.1.1.10.2 tls
87 1.1.1.1.10.2 tls static int
88 1.1.1.1.10.2 tls nfslock_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
89 1.1.1.1.10.2 tls {
90 1.1.1.1.10.2 tls int error;
91 1.1.1.1.10.2 tls
92 1.1.1.1.10.2 tls error = priv_check(td, PRIV_NFS_LOCKD);
93 1.1.1.1.10.2 tls if (error)
94 1.1.1.1.10.2 tls return (error);
95 1.1.1.1.10.2 tls
96 1.1.1.1.10.2 tls mtx_lock(&nfslock_mtx);
97 1.1.1.1.10.2 tls if (!nfslock_isopen) {
98 1.1.1.1.10.2 tls error = 0;
99 1.1.1.1.10.2 tls nfslock_isopen = 1;
100 1.1.1.1.10.2 tls } else {
101 1.1.1.1.10.2 tls error = EOPNOTSUPP;
102 1.1.1.1.10.2 tls }
103 1.1.1.1.10.2 tls mtx_unlock(&nfslock_mtx);
104 1.1.1.1.10.2 tls
105 1.1.1.1.10.2 tls return (error);
106 1.1.1.1.10.2 tls }
107 1.1.1.1.10.2 tls
108 1.1.1.1.10.2 tls static int
109 1.1.1.1.10.2 tls nfslock_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
110 1.1.1.1.10.2 tls {
111 1.1.1.1.10.2 tls struct __lock_msg *lm;
112 1.1.1.1.10.2 tls
113 1.1.1.1.10.2 tls mtx_lock(&nfslock_mtx);
114 1.1.1.1.10.2 tls nfslock_isopen = 0;
115 1.1.1.1.10.2 tls while (!TAILQ_EMPTY(&nfslock_list)) {
116 1.1.1.1.10.2 tls lm = TAILQ_FIRST(&nfslock_list);
117 1.1.1.1.10.2 tls /* XXX: answer request */
118 1.1.1.1.10.2 tls TAILQ_REMOVE(&nfslock_list, lm, lm_link);
119 1.1.1.1.10.2 tls free(lm, M_NFSLOCK);
120 1.1.1.1.10.2 tls }
121 1.1.1.1.10.2 tls mtx_unlock(&nfslock_mtx);
122 1.1.1.1.10.2 tls return (0);
123 1.1.1.1.10.2 tls }
124 1.1.1.1.10.2 tls
125 1.1.1.1.10.2 tls static int
126 1.1.1.1.10.2 tls nfslock_read(struct cdev *dev, struct uio *uio, int ioflag)
127 1.1.1.1.10.2 tls {
128 1.1.1.1.10.2 tls int error;
129 1.1.1.1.10.2 tls struct __lock_msg *lm;
130 1.1.1.1.10.2 tls
131 1.1.1.1.10.2 tls if (uio->uio_resid != sizeof *lm)
132 1.1.1.1.10.2 tls return (EOPNOTSUPP);
133 1.1.1.1.10.2 tls lm = NULL;
134 1.1.1.1.10.2 tls error = 0;
135 1.1.1.1.10.2 tls mtx_lock(&nfslock_mtx);
136 1.1.1.1.10.2 tls while (TAILQ_EMPTY(&nfslock_list)) {
137 1.1.1.1.10.2 tls error = msleep(&nfslock_list, &nfslock_mtx, PSOCK | PCATCH,
138 1.1.1.1.10.2 tls "nfslockd", 0);
139 1.1.1.1.10.2 tls if (error)
140 1.1.1.1.10.2 tls break;
141 1.1.1.1.10.2 tls }
142 1.1.1.1.10.2 tls if (!error) {
143 1.1.1.1.10.2 tls lm = TAILQ_FIRST(&nfslock_list);
144 1.1.1.1.10.2 tls TAILQ_REMOVE(&nfslock_list, lm, lm_link);
145 1.1.1.1.10.2 tls }
146 1.1.1.1.10.2 tls mtx_unlock(&nfslock_mtx);
147 1.1.1.1.10.2 tls if (!error) {
148 1.1.1.1.10.2 tls error = uiomove(lm, sizeof *lm, uio);
149 1.1.1.1.10.2 tls free(lm, M_NFSLOCK);
150 1.1.1.1.10.2 tls }
151 1.1.1.1.10.2 tls return (error);
152 1.1.1.1.10.2 tls }
153 1.1.1.1.10.2 tls
154 1.1.1.1.10.2 tls static int
155 1.1.1.1.10.2 tls nfslock_write(struct cdev *dev, struct uio *uio, int ioflag)
156 1.1.1.1.10.2 tls {
157 1.1.1.1.10.2 tls struct lockd_ans la;
158 1.1.1.1.10.2 tls int error;
159 1.1.1.1.10.2 tls
160 1.1.1.1.10.2 tls if (uio->uio_resid != sizeof la)
161 1.1.1.1.10.2 tls return (EOPNOTSUPP);
162 1.1.1.1.10.2 tls error = uiomove(&la, sizeof la, uio);
163 1.1.1.1.10.2 tls if (!error)
164 1.1.1.1.10.2 tls error = nfslockdans(curthread, &la);
165 1.1.1.1.10.2 tls return (error);
166 1.1.1.1.10.2 tls }
167 1.1.1.1.10.2 tls
168 1.1.1.1.10.2 tls static int
169 1.1.1.1.10.2 tls nfslock_send(struct __lock_msg *lm)
170 1.1.1.1.10.2 tls {
171 1.1.1.1.10.2 tls struct __lock_msg *lm2;
172 1.1.1.1.10.2 tls int error;
173 1.1.1.1.10.2 tls
174 1.1.1.1.10.2 tls error = 0;
175 1.1.1.1.10.2 tls lm2 = malloc(sizeof *lm2, M_NFSLOCK, M_WAITOK);
176 1.1.1.1.10.2 tls mtx_lock(&nfslock_mtx);
177 1.1.1.1.10.2 tls if (nfslock_isopen) {
178 1.1.1.1.10.2 tls memcpy(lm2, lm, sizeof *lm2);
179 1.1.1.1.10.2 tls TAILQ_INSERT_TAIL(&nfslock_list, lm2, lm_link);
180 1.1.1.1.10.2 tls wakeup(&nfslock_list);
181 1.1.1.1.10.2 tls } else {
182 1.1.1.1.10.2 tls error = EOPNOTSUPP;
183 1.1.1.1.10.2 tls }
184 1.1.1.1.10.2 tls mtx_unlock(&nfslock_mtx);
185 1.1.1.1.10.2 tls if (error)
186 1.1.1.1.10.2 tls free(lm2, M_NFSLOCK);
187 1.1.1.1.10.2 tls return (error);
188 1.1.1.1.10.2 tls }
189 1.1.1.1.10.2 tls
190 1.1.1.1.10.2 tls static struct cdevsw nfslock_cdevsw = {
191 1.1.1.1.10.2 tls .d_version = D_VERSION,
192 1.1.1.1.10.2 tls .d_open = nfslock_open,
193 1.1.1.1.10.2 tls .d_close = nfslock_close,
194 1.1.1.1.10.2 tls .d_read = nfslock_read,
195 1.1.1.1.10.2 tls .d_write = nfslock_write,
196 1.1.1.1.10.2 tls .d_name = "nfslock"
197 1.1.1.1.10.2 tls };
198 1.1.1.1.10.2 tls
199 1.1.1.1.10.2 tls static int
200 1.1.1.1.10.2 tls nfslock_modevent(module_t mod __unused, int type, void *data __unused)
201 1.1.1.1.10.2 tls {
202 1.1.1.1.10.2 tls
203 1.1.1.1.10.2 tls switch (type) {
204 1.1.1.1.10.2 tls case MOD_LOAD:
205 1.1.1.1.10.2 tls if (bootverbose)
206 1.1.1.1.10.2 tls printf("nfslock: pseudo-device\n");
207 1.1.1.1.10.2 tls mtx_init(&nfslock_mtx, "nfslock", NULL, MTX_DEF);
208 1.1.1.1.10.2 tls TAILQ_INIT(&nfslock_list);
209 1.1.1.1.10.2 tls nlminfo_release_p = nlminfo_release;
210 1.1.1.1.10.2 tls nfslock_dev = make_dev(&nfslock_cdevsw, 0,
211 1.1.1.1.10.2 tls UID_ROOT, GID_KMEM, 0600, _PATH_NFSLCKDEV);
212 1.1.1.1.10.2 tls return (0);
213 1.1.1.1.10.2 tls default:
214 1.1.1.1.10.2 tls return (EOPNOTSUPP);
215 1.1.1.1.10.2 tls }
216 1.1.1.1.10.2 tls }
217 1.1.1.1.10.2 tls
218 1.1.1.1.10.2 tls DEV_MODULE(nfslock, nfslock_modevent, NULL);
219 1.1.1.1.10.2 tls MODULE_VERSION(nfslock, 1);
220 1.1.1.1.10.2 tls
221 1.1.1.1.10.2 tls
222 1.1.1.1.10.2 tls /*
223 1.1.1.1.10.2 tls * XXX
224 1.1.1.1.10.2 tls * We have to let the process know if the call succeeded. I'm using an extra
225 1.1.1.1.10.2 tls * field in the p_nlminfo field in the proc structure, as it is already for
226 1.1.1.1.10.2 tls * lockd stuff.
227 1.1.1.1.10.2 tls */
228 1.1.1.1.10.2 tls
229 1.1.1.1.10.2 tls /*
230 1.1.1.1.10.2 tls * nfs_advlock --
231 1.1.1.1.10.2 tls * NFS advisory byte-level locks.
232 1.1.1.1.10.2 tls *
233 1.1.1.1.10.2 tls * The vnode shall be (shared) locked on the entry, it is
234 1.1.1.1.10.2 tls * unconditionally unlocked after.
235 1.1.1.1.10.2 tls */
236 1.1.1.1.10.2 tls int
237 1.1.1.1.10.2 tls nfs_dolock(struct vop_advlock_args *ap)
238 1.1.1.1.10.2 tls {
239 1.1.1.1.10.2 tls LOCKD_MSG msg;
240 1.1.1.1.10.2 tls struct thread *td;
241 1.1.1.1.10.2 tls struct vnode *vp;
242 1.1.1.1.10.2 tls int error;
243 1.1.1.1.10.2 tls struct flock *fl;
244 1.1.1.1.10.2 tls struct proc *p;
245 1.1.1.1.10.2 tls struct nfsmount *nmp;
246 1.1.1.1.10.2 tls
247 1.1.1.1.10.2 tls td = curthread;
248 1.1.1.1.10.2 tls p = td->td_proc;
249 1.1.1.1.10.2 tls
250 1.1.1.1.10.2 tls vp = ap->a_vp;
251 1.1.1.1.10.2 tls fl = ap->a_fl;
252 1.1.1.1.10.2 tls nmp = VFSTONFS(vp->v_mount);
253 1.1.1.1.10.2 tls
254 1.1.1.1.10.2 tls ASSERT_VOP_LOCKED(vp, "nfs_dolock");
255 1.1.1.1.10.2 tls
256 1.1.1.1.10.2 tls nmp->nm_getinfo(vp, msg.lm_fh, &msg.lm_fh_len, &msg.lm_addr,
257 1.1.1.1.10.2 tls &msg.lm_nfsv3, NULL, NULL);
258 1.1.1.1.10.2 tls VOP_UNLOCK(vp, 0);
259 1.1.1.1.10.2 tls
260 1.1.1.1.10.2 tls /*
261 1.1.1.1.10.2 tls * the NLM protocol doesn't allow the server to return an error
262 1.1.1.1.10.2 tls * on ranges, so we do it.
263 1.1.1.1.10.2 tls */
264 1.1.1.1.10.2 tls if (fl->l_whence != SEEK_END) {
265 1.1.1.1.10.2 tls if ((fl->l_whence != SEEK_CUR && fl->l_whence != SEEK_SET) ||
266 1.1.1.1.10.2 tls fl->l_start < 0 ||
267 1.1.1.1.10.2 tls (fl->l_len < 0 &&
268 1.1.1.1.10.2 tls (fl->l_start == 0 || fl->l_start + fl->l_len < 0)))
269 1.1.1.1.10.2 tls return (EINVAL);
270 1.1.1.1.10.2 tls if (fl->l_len > 0 &&
271 1.1.1.1.10.2 tls (fl->l_len - 1 > OFF_MAX - fl->l_start))
272 1.1.1.1.10.2 tls return (EOVERFLOW);
273 1.1.1.1.10.2 tls }
274 1.1.1.1.10.2 tls
275 1.1.1.1.10.2 tls /*
276 1.1.1.1.10.2 tls * Fill in the information structure.
277 1.1.1.1.10.2 tls */
278 1.1.1.1.10.2 tls msg.lm_version = LOCKD_MSG_VERSION;
279 1.1.1.1.10.2 tls msg.lm_msg_ident.pid = p->p_pid;
280 1.1.1.1.10.2 tls
281 1.1.1.1.10.2 tls mtx_lock(&Giant);
282 1.1.1.1.10.2 tls /*
283 1.1.1.1.10.2 tls * if there is no nfsowner table yet, allocate one.
284 1.1.1.1.10.2 tls */
285 1.1.1.1.10.2 tls if (p->p_nlminfo == NULL) {
286 1.1.1.1.10.2 tls p->p_nlminfo = malloc(sizeof(struct nlminfo),
287 1.1.1.1.10.2 tls M_NLMINFO, M_WAITOK | M_ZERO);
288 1.1.1.1.10.2 tls p->p_nlminfo->pid_start = p->p_stats->p_start;
289 1.1.1.1.10.2 tls timevaladd(&p->p_nlminfo->pid_start, &boottime);
290 1.1.1.1.10.2 tls }
291 1.1.1.1.10.2 tls msg.lm_msg_ident.pid_start = p->p_nlminfo->pid_start;
292 1.1.1.1.10.2 tls msg.lm_msg_ident.msg_seq = ++(p->p_nlminfo->msg_seq);
293 1.1.1.1.10.2 tls
294 1.1.1.1.10.2 tls msg.lm_fl = *fl;
295 1.1.1.1.10.2 tls msg.lm_wait = ap->a_flags & F_WAIT;
296 1.1.1.1.10.2 tls msg.lm_getlk = ap->a_op == F_GETLK;
297 1.1.1.1.10.2 tls cru2x(td->td_ucred, &msg.lm_cred);
298 1.1.1.1.10.2 tls
299 1.1.1.1.10.2 tls for (;;) {
300 1.1.1.1.10.2 tls error = nfslock_send(&msg);
301 1.1.1.1.10.2 tls if (error)
302 1.1.1.1.10.2 tls goto out;
303 1.1.1.1.10.2 tls
304 1.1.1.1.10.2 tls /* Unlocks succeed immediately. */
305 1.1.1.1.10.2 tls if (fl->l_type == F_UNLCK)
306 1.1.1.1.10.2 tls goto out;
307 1.1.1.1.10.2 tls
308 1.1.1.1.10.2 tls /*
309 1.1.1.1.10.2 tls * Retry after 20 seconds if we haven't gotten a response yet.
310 1.1.1.1.10.2 tls * This number was picked out of thin air... but is longer
311 1.1.1.1.10.2 tls * then even a reasonably loaded system should take (at least
312 1.1.1.1.10.2 tls * on a local network). XXX Probably should use a back-off
313 1.1.1.1.10.2 tls * scheme.
314 1.1.1.1.10.2 tls *
315 1.1.1.1.10.2 tls * XXX: No PCATCH here since we currently have no useful
316 1.1.1.1.10.2 tls * way to signal to the userland rpc.lockd that the request
317 1.1.1.1.10.2 tls * has been aborted. Once the rpc.lockd implementation
318 1.1.1.1.10.2 tls * can handle aborts, and we report them properly,
319 1.1.1.1.10.2 tls * PCATCH can be put back. In the mean time, if we did
320 1.1.1.1.10.2 tls * permit aborting, the lock attempt would "get lost"
321 1.1.1.1.10.2 tls * and the lock would get stuck in the locked state.
322 1.1.1.1.10.2 tls */
323 1.1.1.1.10.2 tls error = tsleep(p->p_nlminfo, PUSER, "lockd", 20*hz);
324 1.1.1.1.10.2 tls if (error != 0) {
325 1.1.1.1.10.2 tls if (error == EWOULDBLOCK) {
326 1.1.1.1.10.2 tls /*
327 1.1.1.1.10.2 tls * We timed out, so we rewrite the request
328 1.1.1.1.10.2 tls * to the fifo.
329 1.1.1.1.10.2 tls */
330 1.1.1.1.10.2 tls continue;
331 1.1.1.1.10.2 tls }
332 1.1.1.1.10.2 tls
333 1.1.1.1.10.2 tls break;
334 1.1.1.1.10.2 tls }
335 1.1.1.1.10.2 tls
336 1.1.1.1.10.2 tls if (msg.lm_getlk && p->p_nlminfo->retcode == 0) {
337 1.1.1.1.10.2 tls if (p->p_nlminfo->set_getlk_pid) {
338 1.1.1.1.10.2 tls fl->l_sysid = 0; /* XXX */
339 1.1.1.1.10.2 tls fl->l_pid = p->p_nlminfo->getlk_pid;
340 1.1.1.1.10.2 tls } else {
341 1.1.1.1.10.2 tls fl->l_type = F_UNLCK;
342 1.1.1.1.10.2 tls }
343 1.1.1.1.10.2 tls }
344 1.1.1.1.10.2 tls error = p->p_nlminfo->retcode;
345 1.1.1.1.10.2 tls break;
346 1.1.1.1.10.2 tls }
347 1.1.1.1.10.2 tls out:
348 1.1.1.1.10.2 tls mtx_unlock(&Giant);
349 1.1.1.1.10.2 tls return (error);
350 1.1.1.1.10.2 tls }
351 1.1.1.1.10.2 tls
352 1.1.1.1.10.2 tls /*
353 1.1.1.1.10.2 tls * nfslockdans --
354 1.1.1.1.10.2 tls * NFS advisory byte-level locks answer from the lock daemon.
355 1.1.1.1.10.2 tls */
356 1.1.1.1.10.2 tls static int
357 1.1.1.1.10.2 tls nfslockdans(struct thread *td, struct lockd_ans *ansp)
358 1.1.1.1.10.2 tls {
359 1.1.1.1.10.2 tls struct proc *targetp;
360 1.1.1.1.10.2 tls
361 1.1.1.1.10.2 tls /* the version should match, or we're out of sync */
362 1.1.1.1.10.2 tls if (ansp->la_vers != LOCKD_ANS_VERSION)
363 1.1.1.1.10.2 tls return (EINVAL);
364 1.1.1.1.10.2 tls
365 1.1.1.1.10.2 tls /* Find the process, set its return errno and wake it up. */
366 1.1.1.1.10.2 tls if ((targetp = pfind(ansp->la_msg_ident.pid)) == NULL)
367 1.1.1.1.10.2 tls return (ESRCH);
368 1.1.1.1.10.2 tls
369 1.1.1.1.10.2 tls /* verify the pid hasn't been reused (if we can), and it isn't waiting
370 1.1.1.1.10.2 tls * for an answer from a more recent request. We return an EPIPE if
371 1.1.1.1.10.2 tls * the match fails, because we've already used ESRCH above, and this
372 1.1.1.1.10.2 tls * is sort of like writing on a pipe after the reader has closed it.
373 1.1.1.1.10.2 tls */
374 1.1.1.1.10.2 tls if (targetp->p_nlminfo == NULL ||
375 1.1.1.1.10.2 tls ((ansp->la_msg_ident.msg_seq != -1) &&
376 1.1.1.1.10.2 tls (timevalcmp(&targetp->p_nlminfo->pid_start,
377 1.1.1.1.10.2 tls &ansp->la_msg_ident.pid_start, !=) ||
378 1.1.1.1.10.2 tls targetp->p_nlminfo->msg_seq != ansp->la_msg_ident.msg_seq))) {
379 1.1.1.1.10.2 tls PROC_UNLOCK(targetp);
380 1.1.1.1.10.2 tls return (EPIPE);
381 1.1.1.1.10.2 tls }
382 1.1.1.1.10.2 tls
383 1.1.1.1.10.2 tls targetp->p_nlminfo->retcode = ansp->la_errno;
384 1.1.1.1.10.2 tls targetp->p_nlminfo->set_getlk_pid = ansp->la_set_getlk_pid;
385 1.1.1.1.10.2 tls targetp->p_nlminfo->getlk_pid = ansp->la_getlk_pid;
386 1.1.1.1.10.2 tls
387 1.1.1.1.10.2 tls wakeup(targetp->p_nlminfo);
388 1.1.1.1.10.2 tls
389 1.1.1.1.10.2 tls PROC_UNLOCK(targetp);
390 1.1.1.1.10.2 tls return (0);
391 1.1.1.1.10.2 tls }
392 1.1.1.1.10.2 tls
393 1.1.1.1.10.2 tls /*
394 1.1.1.1.10.2 tls * Free nlminfo attached to process.
395 1.1.1.1.10.2 tls */
396 1.1.1.1.10.2 tls void
397 1.1.1.1.10.2 tls nlminfo_release(struct proc *p)
398 1.1.1.1.10.2 tls {
399 1.1.1.1.10.2 tls free(p->p_nlminfo, M_NLMINFO);
400 1.1.1.1.10.2 tls p->p_nlminfo = NULL;
401 1.1.1.1.10.2 tls }
402