]> git.saurik.com Git - apple/xnu.git/blame - bsd/nfs/nfs_lock.h
xnu-4570.20.62.tar.gz
[apple/xnu.git] / bsd / nfs / nfs_lock.h
CommitLineData
91447636 1/*
6d2010ae 2 * Copyright (c) 2002-2010 Apple Inc. All rights reserved.
91447636 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
91447636 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
91447636 27 */
55e303ae
A
28/*-
29 * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
32 * are met:
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. Berkeley Software Design Inc's name may not be used to endorse or
39 * promote products derived from this software without specific prior
40 * written permission.
41 *
42 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE.
53 *
54 * from nfs_lock.h,v 2.2 1998/04/28 19:38:41 don Exp
55 * $FreeBSD$
56 */
57
58#include <sys/appleapiopts.h>
59
60#ifdef __APPLE_API_PRIVATE
61
62/*
63 * lockd uses the nfsclnt system call for the unique kernel services it needs.
64 * It passes in a request structure with a version number at the start.
65 * This prevents libc from needing to change if the information passed
66 * between lockd and the kernel needs to change.
67 *
68 * If a structure changes, you must bump the version number.
69 */
70
2d21ac55 71#include <sys/mount.h>
55e303ae
A
72
73/*
e5568f75 74 * The structure that the kernel hands lockd for each lock request.
55e303ae 75 */
e5568f75
A
76#define LOCKD_MSG_VERSION 3
77typedef struct nfs_lock_msg {
78 int lm_version; /* LOCKD_MSG version */
79 int lm_flags; /* request flags */
80 u_int64_t lm_xid; /* unique message transaction ID */
81 struct flock lm_fl; /* The lock request. */
55e303ae 82 struct sockaddr_storage lm_addr; /* The address. */
91447636 83 int lm_fh_len; /* The file handle length. */
55e303ae 84 struct xucred lm_cred; /* user cred for lock req */
2d21ac55 85 u_int8_t lm_fh[NFSV3_MAX_FH_SIZE]; /* The file handle. */
55e303ae
A
86} LOCKD_MSG;
87
e5568f75
A
88/* lm_flags */
89#define LOCKD_MSG_BLOCK 0x0001 /* a blocking request */
90#define LOCKD_MSG_TEST 0x0002 /* just a lock test */
91#define LOCKD_MSG_NFSV3 0x0004 /* NFSv3 request */
92#define LOCKD_MSG_CANCEL 0x0008 /* cancelling blocked request */
b0d623f7 93#define LOCKD_MSG_DENIED_GRACE 0x0010 /* lock denied due to grace period */
6d2010ae
A
94#define LOCKD_MSG_RECLAIM 0x0020 /* lock reclaim request */
95#define LOCKD_MSG_TCP 0x0040 /* (try to) use TCP for request */
e5568f75
A
96
97/* The structure used to maintain the pending request queue */
98typedef struct nfs_lock_msg_request {
99 TAILQ_ENTRY(nfs_lock_msg_request) lmr_next; /* in-kernel pending request list */
100 int lmr_answered; /* received an answer? */
101 int lmr_errno; /* return status */
102 int lmr_saved_errno; /* original return status */
103 LOCKD_MSG lmr_msg; /* the message */
104} LOCKD_MSG_REQUEST;
55e303ae 105
e5568f75
A
106TAILQ_HEAD(nfs_lock_msg_queue, nfs_lock_msg_request);
107typedef struct nfs_lock_msg_queue LOCKD_MSG_QUEUE;
108
109
110/*
111 * The structure that lockd hands the kernel for each lock answer.
112 */
113#define LOCKD_ANS_VERSION 2
55e303ae 114struct lockd_ans {
e5568f75
A
115 int la_version; /* lockd_ans version */
116 int la_errno; /* return status */
117 u_int64_t la_xid; /* unique message transaction ID */
118 int la_flags; /* answer flags */
119 pid_t la_pid; /* pid of lock requester/owner */
120 off_t la_start; /* lock starting offset */
121 off_t la_len; /* lock length */
91447636 122 int la_fh_len; /* The file handle length. */
2d21ac55 123 u_int8_t la_fh[NFSV3_MAX_FH_SIZE];/* The file handle. */
55e303ae
A
124};
125
e5568f75
A
126/* la_flags */
127#define LOCKD_ANS_GRANTED 0x0001 /* NLM_GRANTED request */
128#define LOCKD_ANS_LOCK_INFO 0x0002 /* lock info valid */
129#define LOCKD_ANS_LOCK_EXCL 0x0004 /* lock is exclusive */
b0d623f7 130#define LOCKD_ANS_DENIED_GRACE 0x0008 /* lock denied due to grace period */
e5568f75
A
131
132
6d2010ae
A
133/*
134 * The structure that lockd hands the kernel for each notify.
135 */
136#define LOCKD_NOTIFY_VERSION 1
137struct lockd_notify {
138 int ln_version; /* lockd_notify version */
139 int ln_flags; /* notify flags */
140 int ln_pad; /* (for alignment) */
141 int ln_addrcount; /* # of addresss */
142 struct sockaddr_storage ln_addr[1]; /* List of addresses. */
143};
144
145
55e303ae 146#ifdef KERNEL
e5568f75 147void nfs_lockinit(void);
6d2010ae
A
148void nfs_lockd_mount_register(struct nfsmount *);
149void nfs_lockd_mount_unregister(struct nfsmount *);
150int nfs3_lockd_request(nfsnode_t, int, LOCKD_MSG_REQUEST *, int, thread_t);
91447636 151int nfslockdans(proc_t p, struct lockd_ans *ansp);
6d2010ae 152int nfslockdnotify(proc_t p, user_addr_t argp);
91447636 153
55e303ae
A
154#endif
155#endif /* __APPLE_API_PRIVATE */