Print this page
3484 enhance and document tail follow support
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/port_impl.h
+++ new/usr/src/uts/common/sys/port_impl.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 (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 +/*
28 + * Copyright (c) 2013, Joyent, Inc. All rights reserved.
29 + */
30 +
27 31 #ifndef _SYS_PORT_IMPL_H
28 32 #define _SYS_PORT_IMPL_H
29 33
30 34
31 35 #ifdef __cplusplus
32 36 extern "C" {
33 37 #endif
34 38
35 39 /*
36 40 * Note:
37 41 * The contents of this file are private to the implementation of the
38 42 * Solaris system and event ports subsystem and are subject to change
39 43 * at any time without notice.
40 44 */
41 45
42 46 #include <sys/poll_impl.h>
43 47 #include <sys/port.h>
44 48 #include <sys/port_kernel.h>
45 49 #include <sys/vnode.h>
46 50 #include <sys/fem.h>
47 51
48 52 /*
49 53 * port system call codes
50 54 */
51 55 #define PORT_CREATE 0 /* create a port */
52 56 #define PORT_ASSOCIATE 1 /* register object or object list */
53 57 #define PORT_DISSOCIATE 2 /* remove object association */
54 58 #define PORT_SEND 3 /* send user-defined event to a port */
55 59 #define PORT_SENDN 4 /* send user-defined event to a list of ports */
56 60 #define PORT_GET 5 /* receive object with events */
57 61 #define PORT_GETN 6 /* receive list of objects with events */
58 62 #define PORT_ALERT 7 /* set port in alert mode */
59 63 #define PORT_DISPATCH 8 /* dispatch object with events */
60 64
61 65 #define PORT_SYS_NOPORT 0x100 /* system call without port-id */
62 66 #define PORT_SYS_NOSHARE 0x200 /* non shareable event */
63 67 #define PORT_CODE_MASK 0xff
64 68
65 69 /* port_dispatch() flags */
66 70 #define PORT_SHARE_EVENT 0x01 /* event can be shared between procs */
67 71
68 72 /* port limits */
69 73 #define PORT_MAX_LIST 8192 /* max. # of list ent. per syscall */
70 74
71 75 #ifdef _KERNEL
72 76
73 77 #define PORT_SCACHE_SIZE 16 /* start source cache size */
74 78 #define PORT_SHASH(cookie) (cookie & (PORT_SCACHE_SIZE-1))
75 79
76 80 /* portkev_flags masks */
77 81 #define PORT_CLEANUP_DONE (PORT_KEV_FREE|PORT_KEV_DONEQ)
78 82 #define PORT_KEV_CACHE (PORT_KEV_CACHED|PORT_KEV_SCACHED)
79 83 #define PORT_KEV_WIRED (PORT_KEV_PRIVATE|PORT_KEV_CACHE)
80 84
81 85 #define PORT_FREE_EVENT(pev) (((pev)->portkev_flags & PORT_KEV_CACHE) == 0)
82 86
83 87 typedef struct port_alert {
84 88 int portal_events; /* passed to alert event */
85 89 pid_t portal_pid; /* owner of the alert mode */
86 90 uintptr_t portal_object; /* passed to alert event */
87 91 void *portal_user; /* passed to alert event */
88 92 } port_alert_t;
89 93
90 94 /*
91 95 * The port_queue_t structure is responsible for the management of all
92 96 * event activities within a port.
93 97 */
94 98 typedef struct port_queue {
95 99 kmutex_t portq_mutex;
96 100 kcondvar_t portq_closecv;
97 101 kcondvar_t portq_block_cv;
98 102 int portq_flags;
99 103 uint_t portq_nent; /* number of events in the queue */
100 104 uint_t portq_nget; /* events required for waiting thread */
101 105 uint_t portq_tnent; /* number of events in the temp queue */
102 106 int portq_thrcnt; /* # of threads waiting for events */
103 107 int portq_getn; /* # of threads retrieving events */
104 108 struct portget *portq_thread; /* queue of waiting threads */
105 109 struct port_fdcache *portq_pcp; /* fd cache */
106 110 list_t portq_list; /* port event list */
107 111 list_t portq_get_list; /* port event list for port_get(n) */
108 112 kmutex_t portq_source_mutex;
109 113 port_source_t **portq_scache;
110 114 port_alert_t portq_alert; /* alert event data */
111 115 } port_queue_t;
112 116
113 117 /* defines for portq_flags */
114 118 #define PORTQ_ALERT 0x01 /* port in alert state */
115 119 #define PORTQ_CLOSE 0x02 /* closing port */
116 120 #define PORTQ_WAIT_EVENTS 0x04 /* waiting for new events */
117 121 #define PORTQ_POLLIN 0x08 /* events available in the event queue */
118 122 #define PORTQ_POLLOUT 0x10 /* space available for new events */
119 123 #define PORTQ_BLOCKED 0x20 /* port is blocked by port_getn() */
120 124 #define PORTQ_POLLWK_PEND 0x40 /* pollwakeup is pending, blocks port close */
121 125
122 126 #define VTOEP(v) ((struct port *)(v->v_data))
123 127 #define EPTOV(ep) ((struct vnode *)(ep)->port_vnode)
124 128
125 129
126 130 typedef struct port {
127 131 vnode_t *port_vnode;
128 132 kmutex_t port_mutex;
129 133 kcondvar_t port_cv; /* resource control */
130 134 uint_t port_flags;
131 135 pid_t port_pid;
132 136 int port_fd;
133 137 uint_t port_max_events; /* max. number of event per port */
134 138 uint_t port_max_list; /* max. number of list structs */
135 139 uint_t port_curr; /* current number of event structs */
136 140 pollhead_t port_pollhd;
137 141 timespec_t port_ctime;
138 142 uid_t port_uid;
139 143 gid_t port_gid;
140 144 port_queue_t port_queue; /* global queue */
141 145 } port_t;
142 146
143 147 /* defines for port_flags */
144 148 #define PORT_INIT 0x01 /* port initialized */
145 149 #define PORT_CLOSED 0x02 /* owner closed the port */
146 150 #define PORT_EVENTS 0x04 /* waiting for event resources */
147 151
148 152 /*
149 153 * global control structure of port framework
150 154 */
151 155 typedef struct port_control {
152 156 kmutex_t pc_mutex;
153 157 uint_t pc_nents; /* ports currently allocated */
154 158 struct kmem_cache *pc_cache; /* port event structures */
155 159 } port_control_t;
156 160
157 161
158 162 /*
159 163 * Every thread waiting on an object will use this structure to store
160 164 * all dependencies (flags, counters, events) before it awakes with
161 165 * some events/transactions completed
162 166 */
163 167 typedef struct portget {
164 168 int portget_state;
165 169 uint_t portget_nget; /* number of expected events */
166 170 pid_t portget_pid;
167 171 kcondvar_t portget_cv;
168 172 port_alert_t portget_alert;
169 173 struct portget *portget_next;
170 174 struct portget *portget_prev;
171 175 } portget_t;
172 176
173 177 /* defines for portget_state */
174 178 #define PORTGET_ALERT 0x01 /* wake up and return alert event */
175 179
176 180 extern port_control_t port_control;
177 181 extern uint_t port_max_list;
178 182
179 183 /*
180 184 * port_getn() needs this structure to manage inter-process event delivery.
181 185 */
182 186 typedef struct port_gettimer {
183 187 ushort_t pgt_flags;
184 188 ushort_t pgt_loop;
185 189 int pgt_timecheck;
186 190 timespec_t pgt_rqtime;
187 191 timespec_t *pgt_rqtp;
188 192 struct timespec *pgt_timeout;
189 193 } port_gettimer_t;
190 194
191 195 /* pgt_flags */
192 196 #define PORTGET_ONE 0x01 /* return only 1 object */
193 197 #define PORTGET_WAIT_EVENTS 0x02 /* thread is waiting for new events */
194 198
195 199 /*
196 200 * portfd_t is required to synchronize the association of fds with a port
197 201 * and the per-process list of open files.
198 202 * There is a pointer to a portfd structure in uf_entry_t.
199 203 * If a fd is closed then closeandsetf() is able to detect the association of
200 204 * the fd with a port or with a list of ports. closeandsetf() will dissociate
201 205 * the fd from the port(s).
202 206 */
203 207 typedef struct portfd {
204 208 struct polldat pfd_pd;
205 209 struct portfd *pfd_next;
206 210 struct portfd *pfd_prev;
207 211 kthread_t *pfd_thread;
208 212 } portfd_t;
209 213
210 214 #define PFTOD(pfd) (&(pfd)->pfd_pd)
211 215 #define PDTOF(pdp) ((struct portfd *)(pdp))
212 216 #define PORT_FD_BUCKET(pcp, fd) \
213 217 (&(pcp)->pc_hash[((fd) % (pcp)->pc_hashsize)])
214 218
215 219 /*
216 220 * PORT_SOURCE_FILE -- File Events Notification sources
217 221 */
218 222 #define PORT_FOP_BUCKET(pcp, id) \
219 223 (portfop_t **)(&(pcp)->pfc_hash[(((ulong_t)id >> 8) & \
220 224 (PORTFOP_HASHSIZE - 1))])
221 225
222 226 /*
223 227 * This structure is used to register a file object to be watched.
224 228 *
225 229 * The pfop_flags are protected by the vnode's pvp_mutex lock.
226 230 * The pfop list (vnode's list) is protected by the pvp_mutex when it is on
227 231 * the vnode's list.
228 232 *
229 233 * All the rest of the fields are protected by the port's source cache lock
230 234 * pfcp_lock.
231 235 */
232 236 typedef struct portfop {
233 237 int pfop_events;
234 238 int pfop_flags; /* above flags. */
235 239 uintptr_t pfop_object; /* object address */
236 240 vnode_t *pfop_vp;
237 241 vnode_t *pfop_dvp;
238 242 port_t *pfop_pp;
239 243 fem_t *pfop_fem;
240 244 list_node_t pfop_node; /* list of pfop's per vnode */
241 245 struct portfop *pfop_hashnext; /* hash list */
242 246 pid_t pfop_pid; /* owner of portfop */
243 247 struct portfop_cache *pfop_pcache;
244 248 port_kevent_t *pfop_pev; /* event pointers */
245 249 char *pfop_cname; /* file component name */
246 250 int pfop_clen;
247 251 kthread_t *pfop_callrid; /* thread doing the associate */
248 252 } portfop_t;
249 253
250 254 /*
251 255 * pfop_flags
252 256 */
253 257 #define PORT_FOP_ACTIVE 0x1
254 258 #define PORT_FOP_REMOVING 0x2
255 259 #define PORT_FOP_KEV_ONQ 0x4
256 260
257 261 typedef struct portfop_vfs {
258 262 vfs_t *pvfs;
259 263 int pvfs_unmount; /* 1 if unmount in progress */
260 264 list_t pvfs_pvplist; /* list of vnodes from */
261 265 fsem_t *pvfs_fsemp;
262 266 struct portfop_vfs *pvfs_next; /* hash list */
263 267 } portfop_vfs_t;
264 268
265 269 typedef struct portfop_vfs_hash {
266 270 kmutex_t pvfshash_mutex;
267 271 struct portfop_vfs *pvfshash_pvfsp;
268 272 } portfop_vfs_hash_t;
269 273
270 274 typedef struct portfop_vp {
271 275 vnode_t *pvp_vp;
272 276 kmutex_t pvp_mutex;
273 277 int pvp_cnt; /* number of watches */
274 278 list_t pvp_pfoplist;
275 279 list_node_t pvp_pvfsnode;
276 280 struct portfop *pvp_lpfop; /* oldest pfop */
277 281 fem_t *pvp_femp;
278 282 struct portfop_vfs *pvp_pvfsp;
279 283 } portfop_vp_t;
280 284
281 285 #define PORTFOP_PVFSHASH_SZ 256
282 286 #define PORTFOP_PVFSHASH(vfsp) (((uintptr_t)(vfsp) >> 4) % PORTFOP_PVFSHASH_SZ)
283 287
284 288 /*
285 289 * file operations flag.
286 290 */
287 291
288 292 /*
289 293 * PORT_SOURCE_FILE - vnode operations
290 294 */
291 295
292 296 #define FOP_FILE_OPEN 0x00000001
293 297 #define FOP_FILE_READ 0x00000002
294 298 #define FOP_FILE_WRITE 0x00000004
295 299 #define FOP_FILE_MAP 0x00000008
296 300 #define FOP_FILE_IOCTL 0x00000010
297 301 #define FOP_FILE_CREATE 0x00000020
298 302 #define FOP_FILE_MKDIR 0x00000040
299 303 #define FOP_FILE_SYMLINK 0x00000080
300 304 #define FOP_FILE_LINK 0x00000100
301 305 #define FOP_FILE_RENAME 0x00000200
302 306 #define FOP_FILE_REMOVE 0x00000400
303 307 #define FOP_FILE_RMDIR 0x00000800
↓ open down ↓ |
267 lines elided |
↑ open up ↑ |
304 308 #define FOP_FILE_READDIR 0x00001000
305 309 #define FOP_FILE_RENAMESRC 0x00002000
306 310 #define FOP_FILE_RENAMEDST 0x00004000
307 311 #define FOP_FILE_REMOVEFILE 0x00008000
308 312 #define FOP_FILE_REMOVEDIR 0x00010000
309 313 #define FOP_FILE_SETSECATTR 0x00020000
310 314 #define FOP_FILE_SETATTR_ATIME 0x00040000
311 315 #define FOP_FILE_SETATTR_MTIME 0x00080000
312 316 #define FOP_FILE_SETATTR_CTIME 0x00100000
313 317 #define FOP_FILE_LINK_SRC 0x00200000
318 +#define FOP_FILE_TRUNC 0x00400000
314 319
315 320 /*
316 321 * File modification event.
317 322 */
318 323 #define FOP_MODIFIED_MASK (FOP_FILE_WRITE|FOP_FILE_CREATE \
319 324 |FOP_FILE_REMOVE|FOP_FILE_LINK \
320 325 |FOP_FILE_RENAMESRC|FOP_FILE_RENAMEDST \
321 326 |FOP_FILE_MKDIR|FOP_FILE_RMDIR \
322 327 |FOP_FILE_SYMLINK|FOP_FILE_SETATTR_MTIME)
323 328
324 329 /*
325 330 * File access event
326 331 */
327 332 #define FOP_ACCESS_MASK (FOP_FILE_READ|FOP_FILE_READDIR \
328 333 |FOP_FILE_MAP|FOP_FILE_SETATTR_ATIME)
329 334
330 335 /*
331 336 * File attrib event
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
332 337 */
333 338 #define FOP_ATTRIB_MASK (FOP_FILE_WRITE|FOP_FILE_CREATE \
334 339 |FOP_FILE_REMOVE|FOP_FILE_LINK \
335 340 |FOP_FILE_RENAMESRC|FOP_FILE_RENAMEDST \
336 341 |FOP_FILE_MKDIR|FOP_FILE_RMDIR \
337 342 |FOP_FILE_SYMLINK|FOP_FILE_SETATTR_CTIME \
338 343 |FOP_FILE_LINK_SRC|FOP_FILE_SETSECATTR)
339 344
340 345
341 346 /*
347 + * File trunc event
348 + */
349 +#define FOP_TRUNC_MASK (FOP_FILE_TRUNC|FOP_FILE_CREATE)
350 +
351 +/*
342 352 * valid watchable events
343 353 */
344 354 #define FILE_EVENTS_MASK (FILE_ACCESS|FILE_MODIFIED|FILE_ATTRIB \
345 - |FILE_NOFOLLOW)
355 + |FILE_NOFOLLOW|FILE_TRUNC)
346 356 /* --- End file events --- */
347 357
348 358 /*
349 359 * port_kstat_t contains the event port kernel values which are
350 360 * exported to kstat.
351 361 * Currently only the number of active ports is exported.
352 362 */
353 363 typedef struct port_kstat {
354 364 kstat_named_t pks_ports;
355 365 } port_kstat_t;
356 366
357 367 /* misc functions */
358 368 int port_alloc_event_block(port_t *, int, int, struct port_kevent **);
359 369 void port_push_eventq(port_queue_t *);
360 370 int port_remove_done_event(struct port_kevent *);
361 371 struct port_kevent *port_get_kevent(list_t *, struct port_kevent *);
362 372 void port_block(port_queue_t *);
363 373 void port_unblock(port_queue_t *);
364 374
365 375 /* PORT_SOURCE_FD cache management */
366 376 void port_pcache_remove_fd(port_fdcache_t *, portfd_t *);
367 377 int port_remove_fd_object(portfd_t *, struct port *, port_fdcache_t *);
368 378
369 379 /* file close management */
370 380 extern void addfd_port(int, portfd_t *);
371 381 extern void delfd_port(int, portfd_t *);
372 382
373 383 #endif /* _KERNEL */
374 384
375 385 #ifdef __cplusplus
376 386 }
377 387 #endif
378 388
379 389 #endif /* _SYS_PORT_IMPL_H */
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX