Deleted Added
full compact
nfs_lock.c (83366) nfs_lock.c (83651)
1/*-
2 * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 12 unchanged lines hidden (view full) ---

21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * from BSDI nfs_lock.c,v 2.4 1998/12/14 23:49:56 jch Exp
1/*-
2 * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 12 unchanged lines hidden (view full) ---

21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * from BSDI nfs_lock.c,v 2.4 1998/12/14 23:49:56 jch Exp
29 * $FreeBSD: head/sys/nfsclient/nfs_lock.c 83366 2001-09-12 08:38:13Z julian $
30 */
31
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/nfsclient/nfs_lock.c 83651 2001-09-18 23:32:09Z peter $");
33
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/fcntl.h>
35#include <sys/kernel.h> /* for hz */
36#include <sys/lock.h>
37#include <sys/malloc.h>
38#include <sys/lockf.h> /* for hz */ /* Must come after sys/malloc.h */
39#include <sys/mbuf.h>

--- 7 unchanged lines hidden (view full) ---

47#include <sys/vnode.h>
48
49#include <machine/limits.h>
50
51#include <net/if.h>
52
53#include <nfs/rpcv2.h>
54#include <nfs/nfsproto.h>
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/fcntl.h>
37#include <sys/kernel.h> /* for hz */
38#include <sys/lock.h>
39#include <sys/malloc.h>
40#include <sys/lockf.h> /* for hz */ /* Must come after sys/malloc.h */
41#include <sys/mbuf.h>

--- 7 unchanged lines hidden (view full) ---

49#include <sys/vnode.h>
50
51#include <machine/limits.h>
52
53#include <net/if.h>
54
55#include <nfs/rpcv2.h>
56#include <nfs/nfsproto.h>
55#include
56#include
57#include
58#include
59#include
57#include <nfsclient/nfs.h>
58#include <nfsclient/nfsmount.h>
59#include <nfsclient/nfsnode.h>
60#include <nfsclient/nfs_lock.h>
61#include <nfsclient/nlminfo.h>
60
61#define NFSOWNER_1ST_LEVEL_START 1 /* initial entries */
62#define NFSOWNER_2ND_LEVEL 256 /* some power of 2 */
63
64#define NFSOWNER(tbl, i) \
65 (tbl)[(i) / NFSOWNER_2ND_LEVEL][(i) % NFSOWNER_2ND_LEVEL]
66
67/*
68 * XXX
69 * We have to let the process know if the call succeeded. I'm using an extra
62
63#define NFSOWNER_1ST_LEVEL_START 1 /* initial entries */
64#define NFSOWNER_2ND_LEVEL 256 /* some power of 2 */
65
66#define NFSOWNER(tbl, i) \
67 (tbl)[(i) / NFSOWNER_2ND_LEVEL][(i) % NFSOWNER_2ND_LEVEL]
68
69/*
70 * XXX
71 * We have to let the process know if the call succeeded. I'm using an extra
70 * field in the p_nlminfo field in the proc structure, as it is already for
72 * field in the p_nlminfo field in the proc structure, as it is already for
71 * lockd stuff.
72 */
73
74/*
75 * nfs_advlock --
76 * NFS advisory byte-level locks.
77 */
78int
73 * lockd stuff.
74 */
75
76/*
77 * nfs_advlock --
78 * NFS advisory byte-level locks.
79 */
80int
79nfs_dolock(ap)
80 struct vop_advlock_args /* {
81 struct vnode *a_vp;
82 caddr_t a_id;
83 int a_op;
84 struct flock *a_fl;
85 int a_flags;
86 } */ *ap;
81nfs_dolock(struct vop_advlock_args *ap)
87{
88 LOCKD_MSG msg;
89 struct nameidata nd;
90 struct thread *td;
91 uid_t saved_uid;
92 struct vnode *vp, *wvp;
93 int error, error1;
94 struct flock *fl;

--- 98 unchanged lines hidden (view full) ---

193 * it gets a responce back.
194 */
195 break;
196
197 /*
198 * retry after 20 seconds if we haven't gotten a responce yet.
199 * This number was picked out of thin air... but is longer
200 * then even a reasonably loaded system should take (at least
82{
83 LOCKD_MSG msg;
84 struct nameidata nd;
85 struct thread *td;
86 uid_t saved_uid;
87 struct vnode *vp, *wvp;
88 int error, error1;
89 struct flock *fl;

--- 98 unchanged lines hidden (view full) ---

188 * it gets a responce back.
189 */
190 break;
191
192 /*
193 * retry after 20 seconds if we haven't gotten a responce yet.
194 * This number was picked out of thin air... but is longer
195 * then even a reasonably loaded system should take (at least
201 * on a local network). XXX Probably should use a back-off
196 * on a local network). XXX Probably should use a back-off
202 * scheme.
203 */
197 * scheme.
198 */
204 if ((error = tsleep((void *)p->p_nlminfo,
199 if ((error = tsleep((void *)p->p_nlminfo,
205 PCATCH | PUSER, "lockd", 20*hz)) != 0) {
206 if (error == EWOULDBLOCK) {
207 /*
208 * We timed out, so we rewrite the request
209 * to the fifo, but only if it isn't already
210 * full.
211 */
212 ioflg |= IO_NDELAY;

--- 20 unchanged lines hidden (view full) ---

233 return (error);
234}
235
236/*
237 * nfslockdans --
238 * NFS advisory byte-level locks answer from the lock daemon.
239 */
240int
200 PCATCH | PUSER, "lockd", 20*hz)) != 0) {
201 if (error == EWOULDBLOCK) {
202 /*
203 * We timed out, so we rewrite the request
204 * to the fifo, but only if it isn't already
205 * full.
206 */
207 ioflg |= IO_NDELAY;

--- 20 unchanged lines hidden (view full) ---

228 return (error);
229}
230
231/*
232 * nfslockdans --
233 * NFS advisory byte-level locks answer from the lock daemon.
234 */
235int
241nfslockdans(p, ansp)
242 struct proc *p;
243 struct lockd_ans *ansp;
236nfslockdans(struct proc *p, struct lockd_ans *ansp)
244{
245 int error;
246
247 /* Let root, or someone who once was root (lockd generally
237{
238 int error;
239
240 /* Let root, or someone who once was root (lockd generally
248 * switches to the daemon uid once it is done setting up) make
241 * switches to the daemon uid once it is done setting up) make
249 * this call.
250 *
251 * XXX This authorization check is probably not right.
252 */
253 if ((error = suser(p)) != 0 && p->p_ucred->cr_svuid != 0)
254 return (error);
255
256 /* the version should match, or we're out of sync */
257 if (ansp->la_vers != LOCKD_ANS_VERSION)
258 return (EINVAL);
259
260 /* Find the process, set its return errno and wake it up. */
261 if ((p = pfind(ansp->la_msg_ident.pid)) == NULL)
262 return (ESRCH);
263
242 * this call.
243 *
244 * XXX This authorization check is probably not right.
245 */
246 if ((error = suser(p)) != 0 && p->p_ucred->cr_svuid != 0)
247 return (error);
248
249 /* the version should match, or we're out of sync */
250 if (ansp->la_vers != LOCKD_ANS_VERSION)
251 return (EINVAL);
252
253 /* Find the process, set its return errno and wake it up. */
254 if ((p = pfind(ansp->la_msg_ident.pid)) == NULL)
255 return (ESRCH);
256
264 /* verify the pid hasn't been reused (if we can), and it isn't waiting
257 /* verify the pid hasn't been reused (if we can), and it isn't waiting
265 * for an answer from a more recent request. We return an EPIPE if
266 * the match fails, because we've already used ESRCH above, and this
267 * is sort of like writing on a pipe after the reader has closed it.
268 */
269 if (p->p_nlminfo == NULL ||
270 ((ansp->la_msg_ident.msg_seq != -1) &&
271 (timevalcmp(&p->p_nlminfo->pid_start,
272 &ansp->la_msg_ident.pid_start, !=) ||

--- 14 unchanged lines hidden ---
258 * for an answer from a more recent request. We return an EPIPE if
259 * the match fails, because we've already used ESRCH above, and this
260 * is sort of like writing on a pipe after the reader has closed it.
261 */
262 if (p->p_nlminfo == NULL ||
263 ((ansp->la_msg_ident.msg_seq != -1) &&
264 (timevalcmp(&p->p_nlminfo->pid_start,
265 &ansp->la_msg_ident.pid_start, !=) ||

--- 14 unchanged lines hidden ---