| 337 | } |
| 338 | |
| 339 | static int |
| 340 | pipe_paircreate(struct thread *td, struct pipepair **p_pp) |
| 341 | { |
| 342 | struct pipepair *pp; |
| 343 | struct pipe *rpipe, *wpipe; |
| 344 | int error; |
| 345 | |
| 346 | *p_pp = pp = uma_zalloc(pipe_zone, M_WAITOK); |
| 347 | #ifdef MAC |
| 348 | /* |
| 349 | * The MAC label is shared between the connected endpoints. As a |
| 350 | * result mac_pipe_init() and mac_pipe_create() are called once |
| 351 | * for the pair, and not on the endpoints. |
| 352 | */ |
| 353 | mac_pipe_init(pp); |
| 354 | mac_pipe_create(td->td_ucred, pp); |
| 355 | #endif |
| 356 | rpipe = &pp->pp_rpipe; |
| 357 | wpipe = &pp->pp_wpipe; |
| 358 | |
| 359 | knlist_init_mtx(&rpipe->pipe_sel.si_note, PIPE_MTX(rpipe)); |
| 360 | knlist_init_mtx(&wpipe->pipe_sel.si_note, PIPE_MTX(wpipe)); |
| 361 | |
| 362 | /* |
| 363 | * Only the forward direction pipe is backed by big buffer by |
| 364 | * default. |
| 365 | */ |
| 366 | error = pipe_create(rpipe, true); |
| 367 | if (error != 0) |
| 368 | goto fail; |
| 369 | error = pipe_create(wpipe, false); |
| 370 | if (error != 0) { |
| 371 | /* |
| 372 | * This cleanup leaves the pipe inode number for rpipe |
| 373 | * still allocated, but never used. We do not free |
| 374 | * inode numbers for opened pipes, which is required |
| 375 | * for correctness because numbers must be unique. |
| 376 | * But also it avoids any memory use by the unr |
| 377 | * allocator, so stashing away the transient inode |
| 378 | * number is reasonable. |
| 379 | */ |
| 380 | pipe_free_kmem(rpipe); |
| 381 | goto fail; |
| 382 | } |
| 383 | |
| 384 | rpipe->pipe_state |= PIPE_DIRECTOK; |
| 385 | wpipe->pipe_state |= PIPE_DIRECTOK; |
| 386 | return (0); |
| 387 | |
| 388 | fail: |
| 389 | knlist_destroy(&rpipe->pipe_sel.si_note); |
| 390 | knlist_destroy(&wpipe->pipe_sel.si_note); |
| 391 | #ifdef MAC |
| 392 | mac_pipe_destroy(pp); |
| 393 | #endif |
| 394 | return (error); |
| 395 | } |
| 396 |
no test coverage detected