Print this page
5914 pipe generates inodes with ino > 4G
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/fifofs/fifosubr.c
+++ new/usr/src/uts/common/fs/fifofs/fifosubr.c
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.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 22
23 23 /*
24 24 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
25 + *
26 + * Copyright 2017 Ivan Richwalski <ivan@seppuku.net>
27 + *
25 28 */
26 29
27 30 /*
28 31 * The routines defined in this file are supporting routines for FIFOFS
29 32 * file system type.
30 33 */
31 34 #include <sys/types.h>
32 35 #include <sys/param.h>
33 36 #include <sys/systm.h>
34 37 #include <sys/debug.h>
35 38 #include <sys/errno.h>
36 39 #include <sys/time.h>
37 40 #include <sys/kmem.h>
38 41 #include <sys/inline.h>
39 42 #include <sys/file.h>
40 43 #include <sys/proc.h>
41 44 #include <sys/stat.h>
42 45 #include <sys/sysmacros.h>
43 46 #include <sys/var.h>
44 47 #include <sys/vfs.h>
45 48 #include <sys/vfs_opreg.h>
46 49 #include <sys/vnode.h>
47 50 #include <sys/mode.h>
48 51 #include <sys/signal.h>
49 52 #include <sys/user.h>
50 53 #include <sys/uio.h>
51 54 #include <sys/flock.h>
52 55 #include <sys/stream.h>
53 56 #include <sys/fs/fifonode.h>
54 57 #include <sys/strsubr.h>
55 58 #include <sys/stropts.h>
56 59 #include <sys/cmn_err.h>
57 60 #include <fs/fs_subr.h>
58 61 #include <sys/ddi.h>
59 62
60 63
61 64 #if FIFODEBUG
62 65 int Fifo_fastmode = 1; /* pipes/fifos will be opened in fast mode */
63 66 int Fifo_verbose = 0; /* msg when switching out of fast mode */
64 67 int Fifohiwat = FIFOHIWAT; /* Modifiable FIFO high water mark */
65 68 #endif
66 69
67 70 /*
68 71 * This is the loadable module wrapper.
69 72 */
70 73 #include <sys/modctl.h>
71 74
72 75 extern struct qinit fifo_strdata;
73 76
74 77 struct vfsops *fifo_vfsops;
75 78
76 79 static vfsdef_t vfw = {
77 80 VFSDEF_VERSION,
78 81 "fifofs",
79 82 fifoinit,
80 83 VSW_ZMOUNT,
81 84 NULL
82 85 };
83 86
84 87 /*
85 88 * Module linkage information for the kernel.
86 89 */
87 90 extern struct mod_ops mod_fsops;
88 91
89 92 static struct modlfs modlfs = {
90 93 &mod_fsops, "filesystem for fifo", &vfw
91 94 };
92 95
93 96 static struct modlinkage modlinkage = {
94 97 MODREV_1, (void *)&modlfs, NULL
95 98 };
96 99
97 100 int
98 101 _init()
99 102 {
100 103 return (mod_install(&modlinkage));
101 104 }
102 105
103 106 int
104 107 _info(struct modinfo *modinfop)
105 108 {
106 109 return (mod_info(&modlinkage, modinfop));
107 110 }
108 111
109 112 /*
110 113 * Define data structures within this file.
111 114 * XXX should the hash size be configurable ?
112 115 */
113 116 #define FIFOSHFT 5
114 117 #define FIFO_HASHSZ 63
115 118
116 119 #if ((FIFO_HASHSZ & (FIFO_HASHSZ - 1)) == 0)
117 120 #define FIFOHASH(vp) (((uintptr_t)(vp) >> FIFOSHFT) & (FIFO_HASHSZ - 1))
118 121 #else
119 122 #define FIFOHASH(vp) (((uintptr_t)(vp) >> FIFOSHFT) % FIFO_HASHSZ)
120 123 #endif
121 124
122 125 fifonode_t *fifoalloc[FIFO_HASHSZ];
123 126 dev_t fifodev;
124 127 struct vfs *fifovfsp;
125 128 int fifofstype;
126 129
127 130 kmutex_t ftable_lock;
128 131 static kmutex_t fino_lock;
129 132 struct kmem_cache *fnode_cache;
130 133 struct kmem_cache *pipe_cache;
131 134
132 135 static void fifoinsert(fifonode_t *);
133 136 static fifonode_t *fifofind(vnode_t *);
134 137 static int fifo_connld(struct vnode **, int, cred_t *);
135 138 static void fifo_fastturnoff(fifonode_t *);
136 139
137 140 static void fifo_reinit_vp(vnode_t *);
138 141
139 142 static void fnode_destructor(void *, void *);
140 143
141 144 /*
142 145 * Constructor/destructor routines for fifos and pipes.
143 146 *
144 147 * In the interest of code sharing, we define a common fifodata structure
145 148 * which consists of a fifolock and one or two fnodes. A fifo contains
146 149 * one fnode; a pipe contains two. The fifolock is shared by the fnodes,
147 150 * each of which points to it:
148 151 *
149 152 * --> --> --------- --- ---
150 153 * | | | lock | | |
151 154 * | | --------- | |
152 155 * | | | | fifo |
153 156 * | --- | fnode | | |
154 157 * | | | | pipe
155 158 * | --------- --- |
156 159 * | | | |
157 160 * ------- | fnode | |
158 161 * | | |
159 162 * --------- ---
160 163 *
161 164 * Since the fifolock is at the beginning of the fifodata structure,
162 165 * the fifolock address is the same as the fifodata address. Thus,
163 166 * we can determine the fifodata address from any of its member fnodes.
164 167 * This is essential for fifo_inactive.
165 168 *
166 169 * The fnode constructor is designed to handle any fifodata structure,
167 170 * deducing the number of fnodes from the total size. Thus, the fnode
168 171 * constructor does most of the work for the pipe constructor.
169 172 */
170 173 static int
171 174 fnode_constructor(void *buf, void *cdrarg, int kmflags)
172 175 {
173 176 fifodata_t *fdp = buf;
174 177 fifolock_t *flp = &fdp->fifo_lock;
175 178 fifonode_t *fnp = &fdp->fifo_fnode[0];
176 179 size_t size = (uintptr_t)cdrarg;
177 180
178 181 mutex_init(&flp->flk_lock, NULL, MUTEX_DEFAULT, NULL);
179 182 cv_init(&flp->flk_wait_cv, NULL, CV_DEFAULT, NULL);
180 183 flp->flk_ocsync = 0;
181 184
182 185 while ((char *)fnp < (char *)buf + size) {
183 186
184 187 vnode_t *vp;
185 188
186 189 vp = vn_alloc(kmflags);
187 190 if (vp == NULL) {
188 191 fnp->fn_vnode = NULL; /* mark for destructor */
189 192 fnode_destructor(buf, cdrarg);
190 193 return (-1);
191 194 }
192 195 fnp->fn_vnode = vp;
193 196
194 197 fnp->fn_lock = flp;
195 198 fnp->fn_open = 0;
196 199 fnp->fn_dest = fnp;
197 200 fnp->fn_mp = NULL;
198 201 fnp->fn_count = 0;
199 202 fnp->fn_rsynccnt = 0;
200 203 fnp->fn_wsynccnt = 0;
201 204 fnp->fn_wwaitcnt = 0;
202 205 fnp->fn_insync = 0;
203 206 fnp->fn_pcredp = NULL;
204 207 fnp->fn_cpid = -1;
205 208 /*
206 209 * 32-bit stat(2) may fail if fn_ino isn't initialized
207 210 */
208 211 fnp->fn_ino = 0;
209 212
210 213 cv_init(&fnp->fn_wait_cv, NULL, CV_DEFAULT, NULL);
211 214
212 215 vn_setops(vp, fifo_vnodeops);
213 216 vp->v_stream = NULL;
214 217 vp->v_type = VFIFO;
215 218 vp->v_data = (caddr_t)fnp;
216 219 vp->v_flag = VNOMAP | VNOSWAP;
217 220 vn_exists(vp);
218 221 fnp++;
219 222 }
220 223 return (0);
221 224 }
222 225
223 226 static void
224 227 fnode_destructor(void *buf, void *cdrarg)
225 228 {
226 229 fifodata_t *fdp = buf;
227 230 fifolock_t *flp = &fdp->fifo_lock;
228 231 fifonode_t *fnp = &fdp->fifo_fnode[0];
229 232 size_t size = (uintptr_t)cdrarg;
230 233
231 234 mutex_destroy(&flp->flk_lock);
232 235 cv_destroy(&flp->flk_wait_cv);
233 236 ASSERT(flp->flk_ocsync == 0);
234 237
235 238 while ((char *)fnp < (char *)buf + size) {
236 239
237 240 vnode_t *vp = FTOV(fnp);
238 241
239 242 if (vp == NULL) {
240 243 return; /* constructor failed here */
241 244 }
242 245
243 246 ASSERT(fnp->fn_mp == NULL);
244 247 ASSERT(fnp->fn_count == 0);
245 248 ASSERT(fnp->fn_lock == flp);
246 249 ASSERT(fnp->fn_open == 0);
247 250 ASSERT(fnp->fn_insync == 0);
248 251 ASSERT(fnp->fn_rsynccnt == 0 && fnp->fn_wsynccnt == 0);
249 252 ASSERT(fnp->fn_wwaitcnt == 0);
250 253 ASSERT(fnp->fn_pcredp == NULL);
251 254 ASSERT(vn_matchops(vp, fifo_vnodeops));
252 255 ASSERT(vp->v_stream == NULL);
253 256 ASSERT(vp->v_type == VFIFO);
254 257 ASSERT(vp->v_data == (caddr_t)fnp);
255 258 ASSERT((vp->v_flag & (VNOMAP|VNOSWAP)) == (VNOMAP|VNOSWAP));
256 259
257 260 cv_destroy(&fnp->fn_wait_cv);
258 261 vn_invalid(vp);
259 262 vn_free(vp);
260 263
261 264 fnp++;
262 265 }
263 266 }
264 267
265 268 static int
266 269 pipe_constructor(void *buf, void *cdrarg, int kmflags)
267 270 {
268 271 fifodata_t *fdp = buf;
269 272 fifonode_t *fnp1 = &fdp->fifo_fnode[0];
270 273 fifonode_t *fnp2 = &fdp->fifo_fnode[1];
271 274 vnode_t *vp1;
272 275 vnode_t *vp2;
273 276
274 277 (void) fnode_constructor(buf, cdrarg, kmflags);
275 278
276 279 vp1 = FTOV(fnp1);
277 280 vp2 = FTOV(fnp2);
278 281
279 282 vp1->v_vfsp = vp2->v_vfsp = fifovfsp;
280 283 vp1->v_rdev = vp2->v_rdev = fifodev;
281 284 fnp1->fn_realvp = fnp2->fn_realvp = NULL;
282 285 fnp1->fn_dest = fnp2;
283 286 fnp2->fn_dest = fnp1;
284 287
285 288 return (0);
286 289 }
287 290
288 291 static void
289 292 pipe_destructor(void *buf, void *cdrarg)
290 293 {
291 294 #ifdef DEBUG
292 295 fifodata_t *fdp = buf;
293 296 fifonode_t *fnp1 = &fdp->fifo_fnode[0];
294 297 fifonode_t *fnp2 = &fdp->fifo_fnode[1];
295 298 vnode_t *vp1 = FTOV(fnp1);
296 299 vnode_t *vp2 = FTOV(fnp2);
297 300
298 301 ASSERT(vp1->v_vfsp == fifovfsp);
299 302 ASSERT(vp2->v_vfsp == fifovfsp);
300 303 ASSERT(vp1->v_rdev == fifodev);
301 304 ASSERT(vp2->v_rdev == fifodev);
302 305 #endif
303 306 fnode_destructor(buf, cdrarg);
304 307 }
305 308
306 309 /*
307 310 * Reinitialize a FIFO vnode (uses normal vnode reinit, but ensures that
308 311 * vnode type and flags are reset).
309 312 */
310 313
311 314 static void fifo_reinit_vp(vnode_t *vp)
312 315 {
313 316 vn_reinit(vp);
314 317 vp->v_type = VFIFO;
315 318 vp->v_flag &= VROOT;
316 319 vp->v_flag |= VNOMAP | VNOSWAP;
317 320 }
318 321
319 322 /*
320 323 * Save file system type/index, initialize vfs operations vector, get
321 324 * unique device number for FIFOFS and initialize the FIFOFS hash.
322 325 * Create and initialize a "generic" vfs pointer that will be placed
323 326 * in the v_vfsp field of each pipe's vnode.
324 327 */
325 328 int
326 329 fifoinit(int fstype, char *name)
327 330 {
328 331 static const fs_operation_def_t fifo_vfsops_template[] = {
329 332 NULL, NULL
330 333 };
331 334 int error;
332 335 major_t dev;
333 336
334 337 fifofstype = fstype;
335 338 error = vfs_setfsops(fstype, fifo_vfsops_template, &fifo_vfsops);
336 339 if (error != 0) {
337 340 cmn_err(CE_WARN, "fifoinit: bad vfs ops template");
338 341 return (error);
339 342 }
340 343
341 344 error = vn_make_ops(name, fifo_vnodeops_template, &fifo_vnodeops);
342 345 if (error != 0) {
343 346 (void) vfs_freevfsops_by_type(fstype);
344 347 cmn_err(CE_WARN, "fifoinit: bad vnode ops template");
345 348 return (error);
346 349 }
347 350
348 351 if ((dev = getudev()) == (major_t)-1) {
349 352 cmn_err(CE_WARN, "fifoinit: can't get unique device number");
350 353 dev = 0;
351 354 }
352 355 fifodev = makedevice(dev, 0);
353 356
354 357 fifovfsp = kmem_zalloc(sizeof (struct vfs), KM_SLEEP);
355 358 fifovfsp->vfs_next = NULL;
356 359 vfs_setops(fifovfsp, fifo_vfsops);
357 360 fifovfsp->vfs_vnodecovered = NULL;
358 361 fifovfsp->vfs_flag = 0;
359 362 fifovfsp->vfs_bsize = 1024;
360 363 fifovfsp->vfs_fstype = fifofstype;
361 364 vfs_make_fsid(&fifovfsp->vfs_fsid, fifodev, fifofstype);
362 365 fifovfsp->vfs_data = NULL;
363 366 fifovfsp->vfs_dev = fifodev;
364 367 fifovfsp->vfs_bcount = 0;
365 368
366 369 /*
367 370 * It is necessary to initialize vfs_count here to 1.
368 371 * This prevents the fifovfsp from getting freed when
369 372 * a thread does a VFS_HOLD followed by a VFS_RELE
370 373 * on the fifovfsp
371 374 *
372 375 * The fifovfsp should never be freed.
373 376 */
374 377 fifovfsp->vfs_count = 1;
375 378
376 379 mutex_init(&ftable_lock, NULL, MUTEX_DEFAULT, NULL);
377 380 mutex_init(&fino_lock, NULL, MUTEX_DEFAULT, NULL);
378 381
379 382 /*
380 383 * vnodes are cached aligned
381 384 */
382 385 fnode_cache = kmem_cache_create("fnode_cache",
383 386 sizeof (fifodata_t) - sizeof (fifonode_t), 32,
384 387 fnode_constructor, fnode_destructor, NULL,
385 388 (void *)(sizeof (fifodata_t) - sizeof (fifonode_t)), NULL, 0);
386 389
387 390 pipe_cache = kmem_cache_create("pipe_cache", sizeof (fifodata_t), 32,
388 391 pipe_constructor, pipe_destructor, NULL,
389 392 (void *)(sizeof (fifodata_t)), NULL, 0);
390 393
391 394 #if FIFODEBUG
392 395 if (Fifohiwat < FIFOHIWAT)
393 396 Fifohiwat = FIFOHIWAT;
394 397 #endif /* FIFODEBUG */
395 398 fifo_strdata.qi_minfo->mi_hiwat = Fifohiwat;
396 399
397 400 return (0);
398 401 }
399 402
400 403 /*
401 404 * Provide a shadow for a vnode. We create a new shadow before checking for an
402 405 * existing one, to minimize the amount of time we need to hold ftable_lock.
403 406 * If a vp already has a shadow in the hash list, return its shadow. If not,
404 407 * we hash the new vnode and return its pointer to the caller.
405 408 */
406 409 vnode_t *
407 410 fifovp(vnode_t *vp, cred_t *crp)
408 411 {
409 412 fifonode_t *fnp;
410 413 fifonode_t *spec_fnp; /* Speculative fnode ptr. */
411 414 fifodata_t *fdp;
412 415 vnode_t *newvp;
413 416 struct vattr va;
414 417 vnode_t *rvp;
415 418
416 419 ASSERT(vp != NULL);
417 420
418 421 fdp = kmem_cache_alloc(fnode_cache, KM_SLEEP);
419 422
420 423 fdp->fifo_lock.flk_ref = 1;
421 424 fnp = &fdp->fifo_fnode[0];
422 425
423 426 /*
424 427 * Its possible that fifo nodes on different lofs mountpoints
425 428 * shadow the same real filesystem fifo node.
426 429 * In this case its necessary to get and store the realvp.
427 430 * This way different fifo nodes sharing the same real vnode
428 431 * can use realvp for communication.
429 432 */
430 433
431 434 if (VOP_REALVP(vp, &rvp, NULL) == 0)
432 435 vp = rvp;
433 436
434 437 fnp->fn_realvp = vp;
435 438 fnp->fn_wcnt = 0;
436 439 fnp->fn_rcnt = 0;
437 440
438 441 #if FIFODEBUG
439 442 if (! Fifo_fastmode) {
440 443 fnp->fn_flag = 0;
441 444 } else {
442 445 fnp->fn_flag = FIFOFAST;
443 446 }
444 447 #else /* FIFODEBUG */
445 448 fnp->fn_flag = FIFOFAST;
446 449 #endif /* FIFODEBUG */
447 450
448 451 /*
449 452 * initialize the times from vp.
450 453 */
451 454 va.va_mask = AT_TIMES;
452 455 if (VOP_GETATTR(vp, &va, 0, crp, NULL) == 0) {
453 456 fnp->fn_atime = va.va_atime.tv_sec;
454 457 fnp->fn_mtime = va.va_mtime.tv_sec;
455 458 fnp->fn_ctime = va.va_ctime.tv_sec;
456 459 } else {
457 460 fnp->fn_atime = 0;
458 461 fnp->fn_mtime = 0;
459 462 fnp->fn_ctime = 0;
460 463 }
461 464
462 465 /*
463 466 * Grab the VP here to avoid holding locks
464 467 * whilst trying to acquire others.
465 468 */
466 469
467 470 VN_HOLD(vp);
468 471
469 472 mutex_enter(&ftable_lock);
470 473
471 474 if ((spec_fnp = fifofind(vp)) != NULL) {
472 475 mutex_exit(&ftable_lock);
473 476
474 477 /*
475 478 * Release the vnode and free up our pre-prepared fnode.
476 479 * Zero the lock reference just to explicitly signal
477 480 * this is unused.
478 481 */
479 482 VN_RELE(vp);
480 483 fdp->fifo_lock.flk_ref = 0;
481 484 kmem_cache_free(fnode_cache, fdp);
482 485
483 486 return (FTOV(spec_fnp));
484 487 }
485 488
486 489 newvp = FTOV(fnp);
487 490 fifo_reinit_vp(newvp);
488 491 /*
489 492 * Since the fifo vnode's v_vfsp needs to point to the
490 493 * underlying filesystem's vfsp we need to bump up the
491 494 * underlying filesystem's vfs reference count.
492 495 * The count is decremented when the fifo node is
493 496 * inactivated.
494 497 */
495 498
496 499 VFS_HOLD(vp->v_vfsp);
497 500 newvp->v_vfsp = vp->v_vfsp;
498 501 newvp->v_rdev = vp->v_rdev;
499 502 newvp->v_flag |= (vp->v_flag & VROOT);
500 503
501 504 fifoinsert(fnp);
502 505 mutex_exit(&ftable_lock);
503 506
504 507 return (newvp);
505 508 }
506 509
507 510 /*
508 511 * Create a pipe end by...
509 512 * allocating a vnode-fifonode pair and initializing the fifonode.
510 513 */
511 514 void
512 515 makepipe(vnode_t **vpp1, vnode_t **vpp2)
513 516 {
514 517 fifonode_t *fnp1;
515 518 fifonode_t *fnp2;
516 519 vnode_t *nvp1;
517 520 vnode_t *nvp2;
518 521 fifodata_t *fdp;
519 522 time_t now;
520 523
521 524 fdp = kmem_cache_alloc(pipe_cache, KM_SLEEP);
522 525 fdp->fifo_lock.flk_ref = 2;
523 526 fnp1 = &fdp->fifo_fnode[0];
524 527 fnp2 = &fdp->fifo_fnode[1];
525 528
526 529 fnp1->fn_wcnt = fnp2->fn_wcnt = 1;
527 530 fnp1->fn_rcnt = fnp2->fn_rcnt = 1;
528 531 #if FIFODEBUG
529 532 if (! Fifo_fastmode) {
530 533 fnp1->fn_flag = fnp2->fn_flag = ISPIPE;
531 534 } else {
532 535 fnp1->fn_flag = fnp2->fn_flag = ISPIPE | FIFOFAST;
533 536 }
534 537 #else /* FIFODEBUG */
535 538 fnp1->fn_flag = fnp2->fn_flag = ISPIPE | FIFOFAST;
536 539 #endif /* FIFODEBUG */
537 540 now = gethrestime_sec();
538 541 fnp1->fn_atime = fnp2->fn_atime = now;
539 542 fnp1->fn_mtime = fnp2->fn_mtime = now;
540 543 fnp1->fn_ctime = fnp2->fn_ctime = now;
541 544
542 545 *vpp1 = nvp1 = FTOV(fnp1);
543 546 *vpp2 = nvp2 = FTOV(fnp2);
544 547
↓ open down ↓ |
510 lines elided |
↑ open up ↑ |
545 548 fifo_reinit_vp(nvp1); /* Reinitialize vnodes for reuse... */
546 549 fifo_reinit_vp(nvp2);
547 550 nvp1->v_vfsp = fifovfsp; /* Need to re-establish VFS & device */
548 551 nvp2->v_vfsp = fifovfsp; /* before we can reuse this vnode. */
549 552 nvp1->v_rdev = fifodev;
550 553 nvp2->v_rdev = fifodev;
551 554 }
552 555
553 556 /*
554 557 * Attempt to establish a unique pipe id. Only un-named pipes use this
555 - * routine.
558 + * routine. Use a 32-bit ino_t so any 32-bit processes that aren't large
559 + * file aware can still stat() a pipe fd and not fail with EOVERFLOW.
556 560 */
557 561 ino_t
558 562 fifogetid(void)
559 563 {
560 - static ino_t fifo_ino = 0;
564 + static ino32_t fifo_ino = 0;
561 565 ino_t fino;
562 566
563 567 mutex_enter(&fino_lock);
564 568 fino = fifo_ino++;
565 569 mutex_exit(&fino_lock);
566 570 return (fino);
567 571 }
568 572
569 573
570 574 /*
571 575 * Stream a pipe/FIFO.
572 576 * The FIFOCONNLD flag is used when CONNLD has been pushed on the stream.
573 577 * If the flag is set, a new vnode is created by calling fifo_connld().
574 578 * Connld logic was moved to fifo_connld() to speed up the open
575 579 * operation, simplify the connld/fifo interaction, and remove inherent
576 580 * race conditions between the connld module and fifos.
577 581 * This routine is single threaded for two reasons.
578 582 * 1) connld requests are synchronous; that is, they must block
579 583 * until the server does an I_RECVFD (oh, well). Single threading is
580 584 * the simplest way to accomplish this.
581 585 * 2) fifo_close() must not send M_HANGUP or M_ERROR while we are
582 586 * in stropen. Stropen() has a tendency to reset things and
583 587 * we would like streams to remember that a hangup occurred.
584 588 */
585 589 int
586 590 fifo_stropen(vnode_t **vpp, int flag, cred_t *crp, int dotwist, int lockheld)
587 591 {
588 592 int error = 0;
589 593 vnode_t *oldvp = *vpp;
590 594 fifonode_t *fnp = VTOF(*vpp);
591 595 dev_t pdev = 0;
592 596 int firstopen = 0;
593 597 fifolock_t *fn_lock;
594 598
595 599 fn_lock = fnp->fn_lock;
596 600 if (!lockheld)
597 601 mutex_enter(&fn_lock->flk_lock);
598 602 ASSERT(MUTEX_HELD(&fnp->fn_lock->flk_lock));
599 603
600 604 /*
601 605 * FIFO is in the process of opening. Wait for it
602 606 * to complete before starting another open on it
603 607 * This prevents races associated with connld open
604 608 */
605 609 while (fnp->fn_flag & FIFOOPEN) {
606 610 if (!cv_wait_sig(&fnp->fn_wait_cv, &fn_lock->flk_lock)) {
607 611 fifo_cleanup(oldvp, flag);
608 612 if (!lockheld)
609 613 mutex_exit(&fn_lock->flk_lock);
610 614 return (EINTR);
611 615 }
612 616 }
613 617
614 618 /*
615 619 * The other end of the pipe is almost closed so
616 620 * reject any other open on this end of the pipe
617 621 * This only happens with a pipe mounted under namefs
618 622 */
619 623 if ((fnp->fn_flag & (FIFOCLOSE|ISPIPE)) == (FIFOCLOSE|ISPIPE)) {
620 624 fifo_cleanup(oldvp, flag);
621 625 cv_broadcast(&fnp->fn_wait_cv);
622 626 if (!lockheld)
623 627 mutex_exit(&fn_lock->flk_lock);
624 628 return (ENXIO);
625 629 }
626 630
627 631 fnp->fn_flag |= FIFOOPEN;
628 632
629 633 /*
630 634 * can't allow close to happen while we are
631 635 * in the middle of stropen().
632 636 * M_HANGUP and M_ERROR could leave the stream in a strange state
633 637 */
634 638 while (fn_lock->flk_ocsync)
635 639 cv_wait(&fn_lock->flk_wait_cv, &fn_lock->flk_lock);
636 640
637 641 fn_lock->flk_ocsync = 1;
638 642
639 643 if (fnp->fn_flag & FIFOCONNLD) {
640 644 /*
641 645 * This is a reopen, so we should release the fifo lock
642 646 * just in case some strange module pushed on connld
643 647 * has some odd side effect.
644 648 * Note: this stropen is on the oldvp. It will
645 649 * have no impact on the connld vp returned and
646 650 * strclose() will only be called when we release
647 651 * flk_ocsync
648 652 */
649 653 mutex_exit(&fn_lock->flk_lock);
650 654 if ((error = stropen(oldvp, &pdev, flag, crp)) != 0) {
651 655 mutex_enter(&fn_lock->flk_lock);
652 656 fifo_cleanup(oldvp, flag);
653 657 fn_lock->flk_ocsync = 0;
654 658 cv_broadcast(&fn_lock->flk_wait_cv);
655 659 goto out;
656 660 }
657 661 /*
658 662 * streams open done, allow close on other end if
659 663 * required. Do this now.. it could
660 664 * be a very long time before fifo_connld returns.
661 665 */
662 666 mutex_enter(&fn_lock->flk_lock);
663 667 /*
664 668 * we need to fake an open here so that if this
665 669 * end of the pipe closes, we don't loose the
666 670 * stream head (kind of like single threading
667 671 * open and close for this end of the pipe)
668 672 * We'll need to call fifo_close() to do clean
669 673 * up in case this end of the pipe was closed
670 674 * down while we were in fifo_connld()
671 675 */
672 676 ASSERT(fnp->fn_open > 0);
673 677 fnp->fn_open++;
674 678 fn_lock->flk_ocsync = 0;
675 679 cv_broadcast(&fn_lock->flk_wait_cv);
676 680 mutex_exit(&fn_lock->flk_lock);
677 681 /*
678 682 * Connld has been pushed onto the pipe
679 683 * Create new pipe on behalf of connld
680 684 */
681 685 if (error = fifo_connld(vpp, flag, crp)) {
682 686 (void) fifo_close(oldvp, flag, 1, 0, crp, NULL);
683 687 mutex_enter(&fn_lock->flk_lock);
684 688 goto out;
685 689 }
686 690 /*
687 691 * undo fake open. We need to call fifo_close
688 692 * because some other thread could have done
689 693 * a close and detach of the named pipe while
690 694 * we were in fifo_connld(), so
691 695 * we want to make sure the close completes (yuk)
692 696 */
693 697 (void) fifo_close(oldvp, flag, 1, 0, crp, NULL);
694 698 /*
695 699 * fifo_connld has changed the vp, so we
696 700 * need to re-initialize locals
697 701 */
698 702 fnp = VTOF(*vpp);
699 703 fn_lock = fnp->fn_lock;
700 704 mutex_enter(&fn_lock->flk_lock);
701 705 } else {
702 706 /*
703 707 * release lock in case there are modules pushed that
704 708 * could have some strange side effect
705 709 */
706 710
707 711 mutex_exit(&fn_lock->flk_lock);
708 712
709 713 /*
710 714 * If this is the first open of a fifo (dotwist
711 715 * will be non-zero) we will need to twist the queues.
712 716 */
713 717 if (oldvp->v_stream == NULL)
714 718 firstopen = 1;
715 719
716 720
717 721 /*
718 722 * normal open of pipe/fifo
719 723 */
720 724
721 725 if ((error = stropen(oldvp, &pdev, flag, crp)) != 0) {
722 726 mutex_enter(&fn_lock->flk_lock);
723 727 fifo_cleanup(oldvp, flag);
724 728 ASSERT(fnp->fn_open != 0 || oldvp->v_stream == NULL);
725 729 fn_lock->flk_ocsync = 0;
726 730 cv_broadcast(&fn_lock->flk_wait_cv);
727 731 goto out;
728 732 }
729 733 mutex_enter(&fn_lock->flk_lock);
730 734
731 735 /*
732 736 * twist the ends of the fifo together
733 737 */
734 738 if (dotwist && firstopen)
735 739 strmate(*vpp, *vpp);
736 740
737 741 /*
738 742 * Show that this open has succeeded
739 743 * and allow closes or other opens to proceed
740 744 */
741 745 fnp->fn_open++;
742 746 fn_lock->flk_ocsync = 0;
743 747 cv_broadcast(&fn_lock->flk_wait_cv);
744 748 }
745 749 out:
746 750 fnp->fn_flag &= ~FIFOOPEN;
747 751 if (error == 0) {
748 752 fnp->fn_flag |= FIFOISOPEN;
749 753 /*
750 754 * If this is a FIFO and has the close flag set
751 755 * and there are now writers, clear the close flag
752 756 * Note: close flag only gets set when last writer
753 757 * on a FIFO goes away.
754 758 */
755 759 if (((fnp->fn_flag & (ISPIPE|FIFOCLOSE)) == FIFOCLOSE) &&
756 760 fnp->fn_wcnt > 0)
757 761 fnp->fn_flag &= ~FIFOCLOSE;
758 762 }
759 763 cv_broadcast(&fnp->fn_wait_cv);
760 764 if (!lockheld)
761 765 mutex_exit(&fn_lock->flk_lock);
762 766 return (error);
763 767 }
764 768
765 769 /*
766 770 * Clean up the state of a FIFO and/or mounted pipe in the
767 771 * event that a fifo_open() was interrupted while the
768 772 * process was blocked.
769 773 */
770 774 void
771 775 fifo_cleanup(vnode_t *vp, int flag)
772 776 {
773 777 fifonode_t *fnp = VTOF(vp);
774 778
775 779 ASSERT(MUTEX_HELD(&fnp->fn_lock->flk_lock));
776 780
777 781 cleanlocks(vp, curproc->p_pid, 0);
778 782 cleanshares(vp, curproc->p_pid);
779 783 if (flag & FREAD) {
780 784 fnp->fn_rcnt--;
781 785 }
782 786 if (flag & FWRITE) {
783 787 fnp->fn_wcnt--;
784 788 }
785 789 cv_broadcast(&fnp->fn_wait_cv);
786 790 }
787 791
788 792
789 793 /*
790 794 * Insert a fifonode-vnode pair onto the fifoalloc hash list.
791 795 */
792 796 static void
793 797 fifoinsert(fifonode_t *fnp)
794 798 {
795 799 int idx = FIFOHASH(fnp->fn_realvp);
796 800
797 801 /*
798 802 * We don't need to hold fn_lock since we're holding ftable_lock and
799 803 * this routine is only called right after we've allocated an fnode.
800 804 * FIFO is inserted at head of NULL terminated doubly linked list.
801 805 */
802 806
803 807 ASSERT(MUTEX_HELD(&ftable_lock));
804 808 fnp->fn_backp = NULL;
805 809 fnp->fn_nextp = fifoalloc[idx];
806 810 fifoalloc[idx] = fnp;
807 811 if (fnp->fn_nextp)
808 812 fnp->fn_nextp->fn_backp = fnp;
809 813 }
810 814
811 815 /*
812 816 * Find a fifonode-vnode pair on the fifoalloc hash list.
813 817 * vp is a vnode to be shadowed. If it's on the hash list,
814 818 * it already has a shadow, therefore return its corresponding
815 819 * fifonode.
816 820 */
817 821 static fifonode_t *
818 822 fifofind(vnode_t *vp)
819 823 {
820 824 fifonode_t *fnode;
821 825
822 826 ASSERT(MUTEX_HELD(&ftable_lock));
823 827 for (fnode = fifoalloc[FIFOHASH(vp)]; fnode; fnode = fnode->fn_nextp) {
824 828 if (fnode->fn_realvp == vp) {
825 829 VN_HOLD(FTOV(fnode));
826 830 return (fnode);
827 831 }
828 832 }
829 833 return (NULL);
830 834 }
831 835
832 836 /*
833 837 * Remove a fifonode-vnode pair from the fifoalloc hash list.
834 838 * This routine is called from the fifo_inactive() routine when a
835 839 * FIFO is being released.
836 840 * If the link to be removed is the only link, set fifoalloc to NULL.
837 841 */
838 842 void
839 843 fiforemove(fifonode_t *fnp)
840 844 {
841 845 int idx = FIFOHASH(fnp->fn_realvp);
842 846 fifonode_t *fnode;
843 847
844 848 ASSERT(MUTEX_HELD(&ftable_lock));
845 849 fnode = fifoalloc[idx];
846 850 /*
847 851 * fast path... only 1 FIFO in this list entry
848 852 */
849 853 if (fnode != NULL && fnode == fnp &&
850 854 !fnode->fn_nextp && !fnode->fn_backp) {
851 855 fifoalloc[idx] = NULL;
852 856 } else {
853 857
854 858 for (; fnode; fnode = fnode->fn_nextp) {
855 859 if (fnode == fnp) {
856 860 /*
857 861 * if we are first entry
858 862 */
859 863 if (fnp == fifoalloc[idx])
860 864 fifoalloc[idx] = fnp->fn_nextp;
861 865 if (fnode->fn_nextp)
862 866 fnode->fn_nextp->fn_backp =
863 867 fnode->fn_backp;
864 868 if (fnode->fn_backp)
865 869 fnode->fn_backp->fn_nextp =
866 870 fnode->fn_nextp;
867 871 break;
868 872 }
869 873 }
870 874 }
871 875 }
872 876
873 877 /*
874 878 * Flush all data from a fifo's message queue
875 879 */
876 880
877 881 void
878 882 fifo_fastflush(fifonode_t *fnp)
879 883 {
880 884 mblk_t *bp;
881 885 ASSERT(MUTEX_HELD(&fnp->fn_lock->flk_lock));
882 886
883 887 if ((bp = fnp->fn_mp) != NULL) {
884 888 fnp->fn_mp = NULL;
885 889 fnp->fn_count = 0;
886 890 freemsg(bp);
887 891 }
888 892 fifo_wakewriter(fnp->fn_dest, fnp->fn_lock);
889 893 }
890 894
891 895 /*
892 896 * Note: This routine is single threaded
893 897 * Protected by FIFOOPEN flag (i.e. flk_lock is not held)
894 898 * Upon successful completion, the original fifo is unlocked
895 899 * and FIFOOPEN is cleared for the original vpp.
896 900 * The new fifo returned has FIFOOPEN set.
897 901 */
898 902 static int
899 903 fifo_connld(struct vnode **vpp, int flag, cred_t *crp)
900 904 {
901 905 struct vnode *vp1;
902 906 struct vnode *vp2;
903 907 struct fifonode *oldfnp;
904 908 struct fifonode *fn_dest;
905 909 int error;
906 910 struct file *filep;
907 911 struct fifolock *fn_lock;
908 912 cred_t *c;
909 913
910 914 /*
911 915 * Get two vnodes that will represent the pipe ends for the new pipe.
912 916 */
913 917 makepipe(&vp1, &vp2);
914 918
915 919 /*
916 920 * Allocate a file descriptor and file pointer for one of the pipe
917 921 * ends. The file descriptor will be used to send that pipe end to
918 922 * the process on the other end of this stream. Note that we get
919 923 * the file structure only, there is no file list entry allocated.
920 924 */
921 925 if (error = falloc(vp1, FWRITE|FREAD, &filep, NULL)) {
922 926 VN_RELE(vp1);
923 927 VN_RELE(vp2);
924 928 return (error);
925 929 }
926 930 mutex_exit(&filep->f_tlock);
927 931 oldfnp = VTOF(*vpp);
928 932 fn_lock = oldfnp->fn_lock;
929 933 fn_dest = oldfnp->fn_dest;
930 934
931 935 /*
932 936 * Create two new stream heads and attach them to the two vnodes for
933 937 * the new pipe.
934 938 */
935 939 if ((error = fifo_stropen(&vp1, FREAD|FWRITE, filep->f_cred, 0, 0)) !=
936 940 0 ||
937 941 (error = fifo_stropen(&vp2, flag, filep->f_cred, 0, 0)) != 0) {
938 942 #if DEBUG
939 943 cmn_err(CE_NOTE, "fifo stropen failed error 0x%x", error);
940 944 #endif
941 945 /*
942 946 * this will call fifo_close and VN_RELE on vp1
943 947 */
944 948 (void) closef(filep);
945 949 VN_RELE(vp2);
946 950 return (error);
947 951 }
948 952
949 953 /*
950 954 * twist the ends of the pipe together
951 955 */
952 956 strmate(vp1, vp2);
953 957
954 958 /*
955 959 * Set our end to busy in open
956 960 * Note: Don't need lock around this because we're the only
957 961 * one who knows about it
958 962 */
959 963 VTOF(vp2)->fn_flag |= FIFOOPEN;
960 964
961 965 mutex_enter(&fn_lock->flk_lock);
962 966
963 967 fn_dest->fn_flag |= FIFOSEND;
964 968 /*
965 969 * check to make sure neither end of pipe has gone away
966 970 */
967 971 if (!(fn_dest->fn_flag & FIFOISOPEN)) {
968 972 error = ENXIO;
969 973 fn_dest->fn_flag &= ~FIFOSEND;
970 974 mutex_exit(&fn_lock->flk_lock);
971 975 /*
972 976 * this will call fifo_close and VN_RELE on vp1
973 977 */
974 978 goto out;
975 979 }
976 980 mutex_exit(&fn_lock->flk_lock);
977 981
978 982 /*
979 983 * Tag the sender's credential on the pipe descriptor.
980 984 */
981 985 crhold(VTOF(vp1)->fn_pcredp = crp);
982 986 VTOF(vp1)->fn_cpid = curproc->p_pid;
983 987
984 988 /*
985 989 * send the file descriptor to other end of pipe
986 990 */
987 991 if (error = do_sendfp((*vpp)->v_stream, filep, crp)) {
988 992 mutex_enter(&fn_lock->flk_lock);
989 993 fn_dest->fn_flag &= ~FIFOSEND;
990 994 mutex_exit(&fn_lock->flk_lock);
991 995 /*
992 996 * this will call fifo_close and VN_RELE on vp1
993 997 */
994 998 goto out;
995 999 }
996 1000
997 1001 mutex_enter(&fn_lock->flk_lock);
998 1002 /*
999 1003 * Wait for other end to receive file descriptor
1000 1004 * FIFOCLOSE indicates that one or both sides of the pipe
1001 1005 * have gone away.
1002 1006 */
1003 1007 while ((fn_dest->fn_flag & (FIFOCLOSE | FIFOSEND)) == FIFOSEND) {
1004 1008 if (!cv_wait_sig(&oldfnp->fn_wait_cv, &fn_lock->flk_lock)) {
1005 1009 error = EINTR;
1006 1010 fn_dest->fn_flag &= ~FIFOSEND;
1007 1011 mutex_exit(&fn_lock->flk_lock);
1008 1012 goto out;
1009 1013 }
1010 1014 }
1011 1015 /*
1012 1016 * If either end of pipe has gone away and the other end did not
1013 1017 * receive pipe, reject the connld open
1014 1018 */
1015 1019 if ((fn_dest->fn_flag & FIFOSEND)) {
1016 1020 error = ENXIO;
1017 1021 fn_dest->fn_flag &= ~FIFOSEND;
1018 1022 mutex_exit(&fn_lock->flk_lock);
1019 1023 goto out;
1020 1024 }
1021 1025
1022 1026 oldfnp->fn_flag &= ~FIFOOPEN;
1023 1027 cv_broadcast(&oldfnp->fn_wait_cv);
1024 1028 mutex_exit(&fn_lock->flk_lock);
1025 1029
1026 1030 VN_RELE(*vpp);
1027 1031 *vpp = vp2;
1028 1032 (void) closef(filep);
1029 1033 return (0);
1030 1034 out:
1031 1035 c = filep->f_cred;
1032 1036 crhold(c);
1033 1037 (void) closef(filep);
1034 1038 VTOF(vp2)->fn_flag &= ~FIFOOPEN;
1035 1039 (void) fifo_close(vp2, flag, 1, (offset_t)0, c, NULL);
1036 1040 crfree(c);
1037 1041 VN_RELE(vp2);
1038 1042 return (error);
1039 1043 }
1040 1044
1041 1045 /*
1042 1046 * Disable fastpath mode.
1043 1047 */
1044 1048 void
1045 1049 fifo_fastoff(fifonode_t *fnp)
1046 1050 {
1047 1051 ASSERT(MUTEX_HELD(&fnp->fn_lock->flk_lock));
1048 1052 ASSERT(FTOV(fnp)->v_stream);
1049 1053
1050 1054 /* FIFOSTAYFAST is set => FIFOFAST is set */
1051 1055 while ((fnp->fn_flag & FIFOSTAYFAST) || ((fnp->fn_flag & ISPIPE) &&
1052 1056 (fnp->fn_dest->fn_flag & FIFOSTAYFAST))) {
1053 1057 ASSERT(fnp->fn_flag & FIFOFAST);
1054 1058 /* indicate someone is waiting to turn into stream mode */
1055 1059 fnp->fn_flag |= FIFOWAITMODE;
1056 1060 cv_wait(&fnp->fn_wait_cv, &fnp->fn_lock->flk_lock);
1057 1061 fnp->fn_flag &= ~FIFOWAITMODE;
1058 1062 }
1059 1063
1060 1064 /* as we may have relased the lock, test the FIFOFAST flag here */
1061 1065 if (!(fnp->fn_flag & FIFOFAST))
1062 1066 return;
1063 1067 #if FIFODEBUG
1064 1068 if (Fifo_verbose)
1065 1069 cmn_err(CE_NOTE, "Fifo reverting to streams mode\n");
1066 1070 #endif
1067 1071
1068 1072 fifo_fastturnoff(fnp);
1069 1073 if (fnp->fn_flag & ISPIPE) {
1070 1074 fifo_fastturnoff(fnp->fn_dest);
1071 1075 }
1072 1076 }
1073 1077
1074 1078
1075 1079 /*
1076 1080 * flk_lock must be held while calling fifo_fastturnoff() to
1077 1081 * preserve data ordering (no reads or writes allowed)
1078 1082 */
1079 1083
1080 1084 static void
1081 1085 fifo_fastturnoff(fifonode_t *fnp)
1082 1086 {
1083 1087 fifonode_t *fn_dest = fnp->fn_dest;
1084 1088 mblk_t *fn_mp;
1085 1089 int fn_flag;
1086 1090
1087 1091 ASSERT(MUTEX_HELD(&fnp->fn_lock->flk_lock));
1088 1092 /*
1089 1093 * Note: This end can't be closed if there
1090 1094 * is stuff in fn_mp
1091 1095 */
1092 1096 if ((fn_mp = fnp->fn_mp) != NULL) {
1093 1097 ASSERT(fnp->fn_flag & FIFOISOPEN);
1094 1098 ASSERT(FTOV(fnp)->v_stream != NULL);
1095 1099 ASSERT(FTOV(fnp)->v_stream->sd_wrq != NULL);
1096 1100 ASSERT(RD(FTOV(fnp)->v_stream->sd_wrq) != NULL);
1097 1101 ASSERT(strvp2wq(FTOV(fnp)) != NULL);
1098 1102 fnp->fn_mp = NULL;
1099 1103 fnp->fn_count = 0;
1100 1104 /*
1101 1105 * Don't need to drop flk_lock across the put()
1102 1106 * since we're just moving the message from the fifo
1103 1107 * node to the STREAM head...
1104 1108 */
1105 1109 put(RD(strvp2wq(FTOV(fnp))), fn_mp);
1106 1110 }
1107 1111
1108 1112 /*
1109 1113 * Need to re-issue any pending poll requests
1110 1114 * so that the STREAMS framework sees them
1111 1115 * Writers would be waiting on fnp and readers on fn_dest
1112 1116 */
1113 1117 if ((fnp->fn_flag & (FIFOISOPEN | FIFOPOLLW)) ==
1114 1118 (FIFOISOPEN | FIFOPOLLW)) {
1115 1119 strpollwakeup(FTOV(fnp), POLLWRNORM);
1116 1120 }
1117 1121 fn_flag = fn_dest->fn_flag;
1118 1122 if ((fn_flag & FIFOISOPEN) == FIFOISOPEN) {
1119 1123 if ((fn_flag & (FIFOPOLLR | FIFOPOLLRBAND))) {
1120 1124 strpollwakeup(FTOV(fn_dest), POLLIN|POLLRDNORM);
1121 1125 }
1122 1126 }
1123 1127 /*
1124 1128 * wake up any sleeping processes so they can notice we went
1125 1129 * to streams mode
1126 1130 */
1127 1131 fnp->fn_flag &= ~(FIFOFAST|FIFOWANTW|FIFOWANTR);
1128 1132 cv_broadcast(&fnp->fn_wait_cv);
1129 1133 }
1130 1134
1131 1135 /*
1132 1136 * Alternative version of fifo_fastoff()
1133 1137 * optimized for putmsg/getmsg.
1134 1138 */
1135 1139 void
1136 1140 fifo_vfastoff(vnode_t *vp)
1137 1141 {
1138 1142 fifonode_t *fnp = VTOF(vp);
1139 1143
1140 1144 mutex_enter(&fnp->fn_lock->flk_lock);
1141 1145 if (!(fnp->fn_flag & FIFOFAST)) {
1142 1146 mutex_exit(&fnp->fn_lock->flk_lock);
1143 1147 return;
1144 1148 }
1145 1149 fifo_fastoff(fnp);
1146 1150 mutex_exit(&fnp->fn_lock->flk_lock);
1147 1151 }
1148 1152
1149 1153 /*
1150 1154 * Wake any sleeping writers, poll and send signals if necessary
1151 1155 * This module is only called when we drop below the hi water mark
1152 1156 * FIFOWANTW indicates that a process is sleeping in fifo_write()
1153 1157 * FIFOHIWATW indicates that we have either attempted a poll or
1154 1158 * non-blocking write and were over the high water mark
1155 1159 * This routine assumes a low water mark of 0.
1156 1160 */
1157 1161
1158 1162 void
1159 1163 fifo_wakewriter(fifonode_t *fn_dest, fifolock_t *fn_lock)
1160 1164 {
1161 1165 int fn_dflag = fn_dest->fn_flag;
1162 1166
1163 1167 ASSERT(MUTEX_HELD(&fn_lock->flk_lock));
1164 1168 ASSERT(fn_dest->fn_dest->fn_count < Fifohiwat);
1165 1169 if ((fn_dflag & FIFOWANTW)) {
1166 1170 cv_broadcast(&fn_dest->fn_wait_cv);
1167 1171 }
1168 1172 if ((fn_dflag & (FIFOHIWATW | FIFOISOPEN)) ==
1169 1173 (FIFOHIWATW | FIFOISOPEN)) {
1170 1174 if (fn_dflag & FIFOPOLLW)
1171 1175 strpollwakeup(FTOV(fn_dest), POLLWRNORM);
1172 1176 if (fn_dflag & FIFOSETSIG)
1173 1177 str_sendsig(FTOV(fn_dest), S_WRNORM, 0, 0);
1174 1178 }
1175 1179 /*
1176 1180 * FIFOPOLLW can't be set without setting FIFOHIWAT
1177 1181 * This allows us to clear both here.
1178 1182 */
1179 1183 fn_dest->fn_flag = fn_dflag & ~(FIFOWANTW | FIFOHIWATW | FIFOPOLLW);
1180 1184 }
1181 1185
1182 1186 /*
1183 1187 * wake up any sleeping readers, poll or send signal if needed
1184 1188 * FIFOWANTR indicates that a process is waiting in fifo_read() for data
1185 1189 * FIFOSETSIG indicates that SIGPOLL should be sent to process
1186 1190 * FIFOPOLLR indicates that a poll request for reading on the fifo was made
1187 1191 */
1188 1192
1189 1193 void
1190 1194 fifo_wakereader(fifonode_t *fn_dest, fifolock_t *fn_lock)
1191 1195 {
1192 1196 int fn_dflag = fn_dest->fn_flag;
1193 1197
1194 1198 ASSERT(MUTEX_HELD(&fn_lock->flk_lock));
1195 1199 if (fn_dflag & FIFOWANTR) {
1196 1200 cv_broadcast(&fn_dest->fn_wait_cv);
1197 1201 }
1198 1202 if (fn_dflag & FIFOISOPEN) {
1199 1203 if (fn_dflag & FIFOPOLLR)
1200 1204 strpollwakeup(FTOV(fn_dest), POLLIN | POLLRDNORM);
1201 1205 if (fn_dflag & FIFOSETSIG)
1202 1206 str_sendsig(FTOV(fn_dest), S_INPUT | S_RDNORM, 0, 0);
1203 1207 }
1204 1208 fn_dest->fn_flag = fn_dflag & ~(FIFOWANTR | FIFOPOLLR);
1205 1209 }
↓ open down ↓ |
635 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX