Skip to content
Snippets Groups Projects
  • Linus Torvalds's avatar
    00a7d398
    fs/pipe: add simpler helpers for common cases · 00a7d398
    Linus Torvalds authored
    
    The fix to atomically read the pipe head and tail state when not holding
    the pipe mutex has caused a number of headaches due to the size change
    of the involved types.
    
    It turns out that we don't have _that_ many places that access these
    fields directly and were affected, but we have more than we strictly
    should have, because our low-level helper functions have been designed
    to have intimate knowledge of how the pipes work.
    
    And as a result, that random noise of direct 'pipe->head' and
    'pipe->tail' accesses makes it harder to pinpoint any actual potential
    problem spots remaining.
    
    For example, we didn't have a "is the pipe full" helper function, but
    instead had a "given these pipe buffer indexes and this pipe size, is
    the pipe full".  That's because some low-level pipe code does actually
    want that much more complicated interface.
    
    But most other places literally just want a "is the pipe full" helper,
    and not having it meant that those places ended up being unnecessarily
    much too aware of this all.
    
    It would have been much better if only the very core pipe code that
    cared had been the one aware of this all.
    
    So let's fix it - better late than never.  This just introduces the
    trivial wrappers for "is this pipe full or empty" and to get how many
    pipe buffers are used, so that instead of writing
    
            if (pipe_full(pipe->head, pipe->tail, pipe->max_usage))
    
    the places that literally just want to know if a pipe is full can just
    say
    
            if (pipe_is_full(pipe))
    
    instead.  The existing trivial cases were converted with a 'sed' script.
    
    This cuts down on the places that access pipe->head and pipe->tail
    directly outside of the pipe code (and core splice code) quite a lot.
    
    The splice code in particular still revels in doing the direct low-level
    accesses, and the fuse fuse_dev_splice_write() code also seems a bit
    unnecessarily eager to go very low-level, but it's at least a bit better
    than it used to be.
    
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    00a7d398
    History
    fs/pipe: add simpler helpers for common cases
    Linus Torvalds authored
    
    The fix to atomically read the pipe head and tail state when not holding
    the pipe mutex has caused a number of headaches due to the size change
    of the involved types.
    
    It turns out that we don't have _that_ many places that access these
    fields directly and were affected, but we have more than we strictly
    should have, because our low-level helper functions have been designed
    to have intimate knowledge of how the pipes work.
    
    And as a result, that random noise of direct 'pipe->head' and
    'pipe->tail' accesses makes it harder to pinpoint any actual potential
    problem spots remaining.
    
    For example, we didn't have a "is the pipe full" helper function, but
    instead had a "given these pipe buffer indexes and this pipe size, is
    the pipe full".  That's because some low-level pipe code does actually
    want that much more complicated interface.
    
    But most other places literally just want a "is the pipe full" helper,
    and not having it meant that those places ended up being unnecessarily
    much too aware of this all.
    
    It would have been much better if only the very core pipe code that
    cared had been the one aware of this all.
    
    So let's fix it - better late than never.  This just introduces the
    trivial wrappers for "is this pipe full or empty" and to get how many
    pipe buffers are used, so that instead of writing
    
            if (pipe_full(pipe->head, pipe->tail, pipe->max_usage))
    
    the places that literally just want to know if a pipe is full can just
    say
    
            if (pipe_is_full(pipe))
    
    instead.  The existing trivial cases were converted with a 'sed' script.
    
    This cuts down on the places that access pipe->head and pipe->tail
    directly outside of the pipe code (and core splice code) quite a lot.
    
    The splice code in particular still revels in doing the direct low-level
    accesses, and the fuse fuse_dev_splice_write() code also seems a bit
    unnecessarily eager to go very low-level, but it's at least a bit better
    than it used to be.
    
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
virtio_console.c 52.71 KiB