Print this page
195 Need replacement for nfs/lockd+klm
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/flock.h
+++ new/usr/src/uts/common/sys/flock.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 * CDDL HEADER END
21 21 */
22 22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 23 /* All Rights Reserved */
24 24
25 25
26 26 /*
27 27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 28 * Use is subject to license terms.
29 29 */
30 +/*
31 + * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
32 + */
30 33
31 34 #ifndef _SYS_FLOCK_H
32 35 #define _SYS_FLOCK_H
33 36
34 -#pragma ident "%Z%%M% %I% %E% SMI"
35 -
36 37 #include <sys/types.h>
37 38 #include <sys/fcntl.h>
38 39 #include <sys/vnode.h>
39 40 #include <sys/t_lock.h> /* for <sys/callb.h> */
40 41 #include <sys/callb.h>
41 42 #include <sys/param.h>
42 43 #include <sys/zone.h>
43 44
44 45 #ifdef __cplusplus
45 46 extern "C" {
46 47 #endif
47 48
48 49 /*
49 50 * Private declarations and instrumentation for local locking.
50 51 */
51 52
52 53 /*
53 54 * The flag passed to fs_frlock() may be ORed together with either
54 55 * `F_REMOTELOCK' or `F_PXFSLOCK'. Since this flag is initialized using the
55 56 * `f_flag' field in the `file' structure, and that field is an unsigned short,
56 57 * we do not use the first 2 bytes.
57 58 */
58 59 #define F_REMOTELOCK (0x01 << 16) /* Set if NLM lock */
59 60 #define F_PXFSLOCK (0x02 << 16) /* Clustering: set if PXFS lock */
60 61
61 62 /*
62 63 * The command passed to reclock() is made by ORing together one or more of
63 64 * the following values.
64 65 */
65 66
66 67 #define INOFLCK 0x01 /* Vnode is locked when reclock() is called. */
67 68 #define SETFLCK 0x02 /* Set a file lock. */
68 69 #define SLPFLCK 0x04 /* Wait if blocked. */
69 70 #define RCMDLCK 0x08 /* F_REMOTELOCK specified */
70 71 #define PCMDLCK 0x10 /* Clustering: F_PXFSLOCK specified */
71 72 #define NBMLCK 0x20 /* non-blocking mandatory locking */
72 73
73 74 /*
74 75 * Special pid value that can be passed to cleanlocks(). It means that
75 76 * cleanlocks() should flush all locks for the given sysid, not just the
76 77 * locks owned by a specific process.
77 78 */
78 79
79 80 #define IGN_PID (-1)
80 81
81 82 /* file locking structure (connected to vnode) */
82 83
83 84 #define l_end l_len
84 85
85 86 /*
86 87 * The lock manager is allowed to use unsigned offsets and lengths, though
87 88 * regular Unix processes are still required to use signed offsets and
88 89 * lengths.
89 90 */
90 91 typedef ulong_t u_off_t;
91 92
92 93 #define MAX_U_OFF_T ((u_off_t)~0)
93 94 #define MAX_U_OFFSET_T ((u_offset_t)~0)
94 95
95 96 /*
96 97 * define MAXEND as the largest positive value the signed offset_t will hold.
97 98 */
98 99 #define MAXEND MAXOFFSET_T
99 100
100 101 /*
101 102 * Definitions for accessing the l_pad area of struct flock. The
102 103 * descriminant of the pad_info_t union is the fcntl command used in
103 104 * conjunction with the flock struct.
104 105 */
105 106
106 107 typedef union {
107 108 int pi_pad[4]; /* (original pad area) */
108 109 int pi_has_rmt; /* F_HASREMOTELOCKS */
109 110 } pad_info_t;
110 111
111 112 #define l_has_rmt(flockp) (((pad_info_t *)((flockp)->l_pad))->pi_has_rmt)
112 113
113 114 /*
114 115 * Optional callbacks for blocking lock requests. Each function is called
115 116 * twice.
116 117 * The first call is after the request is put in the "sleeping" list, but
117 118 * before waiting. At most one callback may return a callb_cpr_t object;
118 119 * the others must return NULL. If a callb_cpr_t is returned, the thread
119 120 * will be marked as safe to suspend while waiting for the lock.
120 121 * The second call is after the request wakes up. Note that the request
121 122 * might not have been granted at the second call (e.g., the request was
122 123 * signalled).
123 124 * New callbacks should be added to the head of the list. For the first
124 125 * call the list is walked in order. For the second call the list is
125 126 * walked backwards (in case the callbacks need to reacquire locks).
126 127 */
127 128
128 129 typedef enum {FLK_BEFORE_SLEEP, FLK_AFTER_SLEEP} flk_cb_when_t;
129 130
130 131 struct flk_callback {
131 132 struct flk_callback *cb_next; /* circular linked list */
132 133 struct flk_callback *cb_prev;
133 134 callb_cpr_t *(*cb_callback)(flk_cb_when_t, void *); /* fcn ptr */
134 135 void *cb_data; /* ptr to callback data */
135 136 };
136 137
137 138 typedef struct flk_callback flk_callback_t;
138 139
139 140 /*
140 141 * This structure members are not used any more inside the kernel.
141 142 * The structure is used for casting some pointer assignments only.
142 143 */
143 144
144 145 typedef struct filock {
145 146 kcondvar_t cv;
146 147 struct flock set; /* contains type, start, and end */
147 148 struct {
148 149 int granted_flag; /* granted flag */
149 150 struct filock *blk; /* for sleeping locks only */
150 151 struct attacher *blocking_list;
151 152 struct attacher *my_attacher;
152 153 } stat;
153 154 struct filock *prev;
154 155 struct filock *next;
155 156 } filock_t;
156 157
157 158 #define FLP_DELAYED_FREE -1 /* special value for granted_flag */
158 159
159 160 /* structure that contains list of locks to be granted */
160 161
161 162 #define MAX_GRANT_LOCKS 52
162 163
163 164 typedef struct grant_lock {
164 165 struct filock *grant_lock_list[MAX_GRANT_LOCKS];
165 166 struct grant_lock *next;
166 167 } grant_lock_t;
167 168
168 169 /*
169 170 * Provide a way to cleanly enable and disable Network Lock Manager locking
170 171 * requests (i.e., requests from remote clients):
171 172 * FLK_NLM_SHUTTING_DOWN: Forces all blocked NLM requests to bail out
172 173 * and return ENOLCK.
173 174 * FLK_NLM_DOWN: Clears all granted NLM server locks. Both status
174 175 * codes cause new NLM lock requests to fail immediately with ENOLCK.
175 176 * FLK_NLM_UP: Changes the state of all locks to UP, after a server has
176 177 * shutdown and is restarting on the same node.
177 178 */
178 179
179 180 /*
180 181 * Enumerated type of the four possible states an NLM server can be in.
181 182 */
182 183 typedef enum {
183 184 FLK_NLM_UP,
184 185 FLK_NLM_SHUTTING_DOWN,
185 186 FLK_NLM_DOWN,
186 187 FLK_NLM_UNKNOWN
187 188 } flk_nlm_status_t;
188 189
189 190 /*
190 191 * Provide a way to cleanly enable and disable lock manager locking
191 192 * requests (i.e., requests from remote clients). FLK_WAKEUP_SLEEPERS
192 193 * forces all blocked lock manager requests to bail out and return ENOLCK.
193 194 * FLK_LOCKMGR_DOWN clears all granted lock manager locks. Both status
194 195 * codes cause new lock manager requests to fail immediately with ENOLCK.
195 196 */
196 197
197 198 typedef enum {
198 199 FLK_LOCKMGR_UP,
199 200 FLK_WAKEUP_SLEEPERS,
200 201 FLK_LOCKMGR_DOWN
201 202 } flk_lockmgr_status_t;
202 203
203 204 #if defined(_KERNEL)
204 205
205 206 /*
206 207 * The following structure is used to hold a list of locks returned
207 208 * by the F_ACTIVELIST or F_SLEEPINGLIST commands to fs_frlock.
208 209 *
209 210 * N.B. The lists returned by these commands are dynamically
210 211 * allocated and must be freed by the caller. The vnodes returned
211 212 * in the lists are held and must be released when the caller is done.
212 213 */
213 214
214 215 typedef struct locklist {
215 216 struct vnode *ll_vp;
216 217 struct flock64 ll_flock;
217 218 struct locklist *ll_next;
218 219 } locklist_t;
219 220
220 221 #define FLK_QUERY_ACTIVE 0x1
221 222 #define FLK_QUERY_SLEEPING 0x2
222 223
223 224 int reclock(struct vnode *, struct flock64 *, int, int, u_offset_t,
224 225 flk_callback_t *);
225 226 int chklock(struct vnode *, int, u_offset_t, ssize_t, int,
226 227 caller_context_t *);
227 228 int convoff(struct vnode *, struct flock64 *, int, offset_t);
228 229 void cleanlocks(struct vnode *, pid_t, int);
229 230 locklist_t *flk_get_sleeping_locks(int sysid, pid_t pid);
230 231 locklist_t *flk_get_active_locks(int sysid, pid_t pid);
↓ open down ↓ |
185 lines elided |
↑ open up ↑ |
231 232 locklist_t *flk_active_locks_for_vp(const struct vnode *vp);
232 233 locklist_t *flk_active_nbmand_locks_for_vp(const struct vnode *vp);
233 234 locklist_t *flk_active_nbmand_locks(pid_t pid);
234 235 void flk_free_locklist(locklist_t *);
235 236 int flk_convert_lock_data(struct vnode *, struct flock64 *,
236 237 u_offset_t *, u_offset_t *, offset_t);
237 238 int flk_check_lock_data(u_offset_t, u_offset_t, offset_t);
238 239 int flk_has_remote_locks(struct vnode *vp);
239 240 void flk_set_lockmgr_status(flk_lockmgr_status_t status);
240 241 int flk_sysid_has_locks(int sysid, int chklck);
242 +int flk_has_remote_locks_for_sysid(vnode_t *vp, int);
241 243 void flk_init_callback(flk_callback_t *,
242 244 callb_cpr_t *(*)(flk_cb_when_t, void *), void *);
243 245 void flk_add_callback(flk_callback_t *,
244 246 callb_cpr_t *(*)(flk_cb_when_t, void *), void *,
245 247 flk_callback_t *);
246 248 callb_cpr_t *flk_invoke_callbacks(flk_callback_t *, flk_cb_when_t);
247 249
248 250 /* Zones hooks */
249 251 extern zone_key_t flock_zone_key;
250 252
251 253 void *flk_zone_init(zoneid_t);
252 254 void flk_zone_fini(zoneid_t, void *);
253 255
254 256 /* Clustering hooks */
255 257 void cl_flk_set_nlm_status(int nlmid, flk_nlm_status_t nlm_state);
256 258 void cl_flk_remove_locks_by_sysid(int sysid);
257 259 int cl_flk_has_remote_locks_for_nlmid(struct vnode *vp, int nlmid);
258 260 void cl_flk_change_nlm_state_to_unknown(int nlmid);
259 261 void cl_flk_delete_pxfs_locks(struct vfs *vfsp, int pxfsid);
260 262 #endif /* _KERNEL */
261 263
262 264 #ifdef __cplusplus
263 265 }
264 266 #endif
265 267
266 268 #endif /* _SYS_FLOCK_H */
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX