175631Salfred/*-
275631Salfred * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved.
375631Salfred * Redistribution and use in source and binary forms, with or without
475631Salfred * modification, are permitted provided that the following conditions
575631Salfred * are met:
675631Salfred * 1. Redistributions of source code must retain the above copyright
775631Salfred *    notice, this list of conditions and the following disclaimer.
875631Salfred * 2. Redistributions in binary form must reproduce the above copyright
975631Salfred *    notice, this list of conditions and the following disclaimer in the
1075631Salfred *    documentation and/or other materials provided with the distribution.
1175631Salfred * 3. Berkeley Software Design Inc's name may not be used to endorse or
1275631Salfred *    promote products derived from this software without specific prior
1375631Salfred *    written permission.
1475631Salfred *
1575631Salfred * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
1675631Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1775631Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1875631Salfred * ARE DISCLAIMED.  IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
1975631Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2075631Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2175631Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2275631Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2375631Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2475631Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2575631Salfred * SUCH DAMAGE.
2675631Salfred *
2775631Salfred *      from nfs_lock.h,v 2.2 1998/04/28 19:38:41 don Exp
2875631Salfred * $FreeBSD$
2975631Salfred */
3075631Salfred
3175631Salfred/*
3275631Salfred * lockd uses the nfssvc system call to get the unique kernel services it needs.
3375631Salfred * It passes in a request structure with a version number at the start.
3483651Speter * This prevents libc from needing to change if the information passed
3575631Salfred * between lockd and the kernel needs to change.
3675631Salfred *
3775631Salfred * If a structure changes, you must bump the version number.
3875631Salfred */
3975631Salfred
4083651Speter/*
4175631Salfred * The fifo where the kernel writes requests for locks on remote NFS files,
4275631Salfred * and where lockd reads these requests.
4375631Salfred *
4475631Salfred */
45138430Sphk#define	_PATH_NFSLCKDEV	"nfslock"
4675631Salfred
4775631Salfred/*
4875631Salfred * This structure is used to uniquely identify the process which originated
4975631Salfred * a particular message to lockd.  A sequence number is used to differentiate
5075631Salfred * multiple messages from the same process.  A process start time is used to
5175631Salfred * detect the unlikely, but possible, event of the recycling of a pid.
5275631Salfred */
5375631Salfredstruct lockd_msg_ident {
5475631Salfred	pid_t		pid;            /* The process ID. */
5575631Salfred	struct timeval	pid_start;	/* Start time of process id */
5675631Salfred	int		msg_seq;	/* Sequence number of message */
5775631Salfred};
5875631Salfred
59138430Sphk#define LOCKD_MSG_VERSION	3
6075631Salfred
6175631Salfred/*
6275631Salfred * The structure that the kernel hands us for each lock request.
6375631Salfred */
6475631Salfredtypedef struct __lock_msg {
65138430Sphk	TAILQ_ENTRY(__lock_msg)	lm_link;	/* internal linkage */
6675631Salfred	int			lm_version;	/* which version is this */
6775631Salfred	struct lockd_msg_ident	lm_msg_ident;	/* originator of the message */
6875631Salfred	struct flock		lm_fl;             /* The lock request. */
6975631Salfred	int			lm_wait;           /* The F_WAIT flag. */
7075631Salfred	int			lm_getlk;		/* is this a F_GETLK request */
71100134Salfred	struct sockaddr_storage lm_addr;		/* The address. */
7275631Salfred	int			lm_nfsv3;		/* If NFS version 3. */
7375631Salfred	size_t			lm_fh_len;		/* The file handle length. */
74101947Salfred	struct xucred		lm_cred;		/* user cred for lock req */
75210455Srmacklem	u_int8_t		lm_fh[NFSX_V3FHMAX];/* The file handle. */
7675631Salfred} LOCKD_MSG;
7775631Salfred
7875631Salfred#define LOCKD_ANS_VERSION	1
7975631Salfred
8075631Salfredstruct lockd_ans {
8175631Salfred	int		la_vers;
8275631Salfred	struct lockd_msg_ident	la_msg_ident;	/* originator of the message */
8375631Salfred	int		la_errno;
8475631Salfred	int		la_set_getlk_pid;		/* use returned pid */
8575631Salfred	int		la_getlk_pid;		/* returned pid for F_GETLK */
8675631Salfred};
8775631Salfred
8875631Salfred#ifdef _KERNEL
8975631Salfredint	nfs_dolock(struct vop_advlock_args *ap);
90214048Srmacklemextern	vop_advlock_t *nfs_advlock_p;
91214048Srmacklemextern	vop_reclaim_t *nfs_reclaim_p;
9275631Salfred#endif
93