* This implements the pipe buffer write mechanism. Note that only * a direct write OR a normal pipe write can be pending at any given time. * If there are any characters in the pipe buffer, the direct write will * be deferred until the receiving process grabs all of the bytes from * the pipe buffer. Then the direct mapping write is set-up. */
| 975 | * the pipe buffer. Then the direct mapping write is set-up. |
| 976 | */ |
| 977 | static int |
| 978 | pipe_direct_write(struct pipe *wpipe, struct uio *uio) |
| 979 | { |
| 980 | int error; |
| 981 | |
| 982 | retry: |
| 983 | PIPE_LOCK_ASSERT(wpipe, MA_OWNED); |
| 984 | if ((wpipe->pipe_state & PIPE_EOF) != 0) { |
| 985 | error = EPIPE; |
| 986 | goto error1; |
| 987 | } |
| 988 | if (wpipe->pipe_state & PIPE_DIRECTW) { |
| 989 | if (wpipe->pipe_state & PIPE_WANTR) { |
| 990 | wpipe->pipe_state &= ~PIPE_WANTR; |
| 991 | wakeup(wpipe); |
| 992 | } |
| 993 | pipeselwakeup(wpipe); |
| 994 | wpipe->pipe_state |= PIPE_WANTW; |
| 995 | pipeunlock(wpipe); |
| 996 | error = msleep(wpipe, PIPE_MTX(wpipe), |
| 997 | PRIBIO | PCATCH, "pipdww", 0); |
| 998 | pipelock(wpipe, 0); |
| 999 | if (error != 0) |
| 1000 | goto error1; |
| 1001 | goto retry; |
| 1002 | } |
| 1003 | if (wpipe->pipe_buffer.cnt > 0) { |
| 1004 | if (wpipe->pipe_state & PIPE_WANTR) { |
| 1005 | wpipe->pipe_state &= ~PIPE_WANTR; |
| 1006 | wakeup(wpipe); |
| 1007 | } |
| 1008 | pipeselwakeup(wpipe); |
| 1009 | wpipe->pipe_state |= PIPE_WANTW; |
| 1010 | pipeunlock(wpipe); |
| 1011 | error = msleep(wpipe, PIPE_MTX(wpipe), |
| 1012 | PRIBIO | PCATCH, "pipdwc", 0); |
| 1013 | pipelock(wpipe, 0); |
| 1014 | if (error != 0) |
| 1015 | goto error1; |
| 1016 | goto retry; |
| 1017 | } |
| 1018 | |
| 1019 | error = pipe_build_write_buffer(wpipe, uio); |
| 1020 | if (error) { |
| 1021 | goto error1; |
| 1022 | } |
| 1023 | |
| 1024 | while (wpipe->pipe_pages.cnt != 0 && |
| 1025 | (wpipe->pipe_state & PIPE_EOF) == 0) { |
| 1026 | if (wpipe->pipe_state & PIPE_WANTR) { |
| 1027 | wpipe->pipe_state &= ~PIPE_WANTR; |
| 1028 | wakeup(wpipe); |
| 1029 | } |
| 1030 | pipeselwakeup(wpipe); |
| 1031 | wpipe->pipe_state |= PIPE_WANTW; |
| 1032 | pipeunlock(wpipe); |
| 1033 | error = msleep(wpipe, PIPE_MTX(wpipe), PRIBIO | PCATCH, |
| 1034 | "pipdwt", 0); |
no test coverage detected