| 1 | /*- |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * |
| 4 | * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved. |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. Berkeley Software Design Inc's name may not be used to endorse or |
| 14 | * promote products derived from this software without specific prior |
| 15 | * written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE |
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | * |
| 29 | * from nfs_lock.h,v 2.2 1998/04/28 19:38:41 don Exp |
| 30 | */ |
| 31 | |
| 32 | /* |
| 33 | * lockd uses the nfssvc system call to get the unique kernel services it needs. |
| 34 | * It passes in a request structure with a version number at the start. |
| 35 | * This prevents libc from needing to change if the information passed |
| 36 | * between lockd and the kernel needs to change. |
| 37 | * |
| 38 | * If a structure changes, you must bump the version number. |
| 39 | */ |
| 40 | |
| 41 | /* |
| 42 | * The fifo where the kernel writes requests for locks on remote NFS files, |
| 43 | * and where lockd reads these requests. |
| 44 | * |
| 45 | */ |
| 46 | #define	_PATH_NFSLCKDEV	"nfslock" |
| 47 | |
| 48 | /* |
| 49 | * This structure is used to uniquely identify the process which originated |
| 50 | * a particular message to lockd. A sequence number is used to differentiate |
| 51 | * multiple messages from the same process. A process start time is used to |
| 52 | * detect the unlikely, but possible, event of the recycling of a pid. |
| 53 | */ |
| 54 | struct lockd_msg_ident { |
| 55 | 	pid_t		pid; /* The process ID. */ |
| 56 | 	struct timeval	pid_start;	/* Start time of process id */ |
| 57 | 	int		msg_seq;	/* Sequence number of message */ |
| 58 | }; |
| 59 | |
| 60 | #define LOCKD_MSG_VERSION	3 |
| 61 | |
| 62 | /* |
| 63 | * The structure that the kernel hands us for each lock request. |
| 64 | */ |
| 65 | typedef struct __lock_msg { |
| 66 | 	TAILQ_ENTRY(__lock_msg)	lm_link;	/* internal linkage */ |
| 67 | 	int			lm_version;	/* which version is this */ |
| 68 | 	struct lockd_msg_ident	lm_msg_ident;	/* originator of the message */ |
| 69 | 	struct flock		lm_fl; /* The lock request. */ |
| 70 | 	int			lm_wait; /* The F_WAIT flag. */ |
| 71 | 	int			lm_getlk;		/* is this a F_GETLK request */ |
| 72 | 	struct sockaddr_storage lm_addr;		/* The address. */ |
| 73 | 	int			lm_nfsv3;		/* If NFS version 3. */ |
| 74 | 	size_t			lm_fh_len;		/* The file handle length. */ |
| 75 | 	struct xucred		lm_cred;		/* user cred for lock req */ |
| 76 | 	u_int8_t		lm_fh[NFSX_V3FHMAX];/* The file handle. */ |
| 77 | } LOCKD_MSG; |
| 78 | |
| 79 | #define LOCKD_ANS_VERSION	1 |
| 80 | |
| 81 | struct lockd_ans { |
| 82 | 	int		la_vers; |
| 83 | 	struct lockd_msg_ident	la_msg_ident;	/* originator of the message */ |
| 84 | 	int		la_errno; |
| 85 | 	int		la_set_getlk_pid;		/* use returned pid */ |
| 86 | 	int		la_getlk_pid;		/* returned pid for F_GETLK */ |
| 87 | }; |
| 88 | |
| 89 | #ifdef _KERNEL |
| 90 | int	nfs_dolock(struct vop_advlock_args *ap); |
| 91 | extern	vop_advlock_t *nfs_advlock_p; |
| 92 | extern	vop_reclaim_t *nfs_reclaim_p; |
| 93 | #endif |