All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>,
	Johannes Berg <johannes@sipsolutions.net>,
	Oliver Giles <ohw.giles@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: Splicing to/from a tty
Date: Wed, 20 Jan 2021 17:04:17 -0800	[thread overview]
Message-ID: <CAHk-=whWGwcZXpqDFv-j2fcChtT1jE0ZMFCmQHp3BrSkp+XZ6A@mail.gmail.com> (raw)
In-Reply-To: <20210121003835.GF740243@zeniv-ca>

On Wed, Jan 20, 2021 at 4:38 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> OK...  I wonder how many debugfs writable files allow pwrite() with
> BS results...

I hope some of them check for "pos == 0" when they start parsing integers.

But honestly, I don't think it's a big deal. We've had these things
that just basically assume that whenever you write, the offset just
doesn't matter at all, and as long as some number comes in one single
write call, we accept it.

Because even if you end up doing something like just

   echo $SOMETHING > /sys/xyz/abc

and that "$SOMETHING" could be done multiple writes, in practice it
all works out just fine and it never really is. You almost have to try
to screw up with something like

  (echo -n 3; echo -n 4) > /sys/xyz/abc

to actually see two writes of "3" and "4" instead of one write with
"34". And honestly, if somebody does something like that, do we really
care? They might get 3, they might get 4, and they might get 34. They
get what they deserve.

> Anyway, possibly more interesting question is why do we care about
> O_APPEND at all - why not treat it the same way we do in write()?

The whole point of O_APPEND is that the position shouldn't matter.

And the whole point of "pwrite()" is that you specify a position.

So the two just do not go together - although we may have legacy
issues, of course.

In contrast, the whole point of just a plain "write()" is that the
position is the "current file position", with O_APPEND is just a
special rule for what the current position for a write is.

Now, splice() is able to do *both* write() and pwrite(), because
unlike pwrite() it doesn't take a "pos" argument, it takes a _pointer_
to pos. So with a NULL pointer, it's like read/write, and with a
non-NULL pointer it is like pread/pwrite.

So I do think that "splice with non-NULL off_out and O_APPEND" should
cause an error in general.

That said, we probabyl have legacy behavior with splice and pipes in
particular, and that legacy behavior would override any "this is
conceptually the sane model".

> So... why do we ban O_APPEND on destination for splice() or for sendfile()?

sendfile() shouldn't be an issue. The offset pointer for sendfile is
for the _source_, not the destination.

For splice(), I do think that O_APPEND and a position pointer don't
make sense as a combination, although if we do allow it for regular
file pwrite() (I didn't check), maybe we could allow it for splice()
too just to be erqually inconsistent.

Honestly, I don't think it's a huge deal. O_APPEND isn't that
interesting, but I do hope that if we allow O_APPEND and a file
position, then O_APPEND always overrides it.

           Linus

  reply	other threads:[~2021-01-21  1:07 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-16  7:35 Splicing to/from a tty Oliver Giles
2021-01-16 16:46 ` Johannes Berg
2021-01-17  6:12   ` Oliver Giles
2021-01-18  8:53   ` Christoph Hellwig
2021-01-18  8:58     ` Johannes Berg
2021-01-18 19:26       ` Linus Torvalds
2021-01-18 19:45         ` Al Viro
2021-01-18 19:49           ` Linus Torvalds
2021-01-18 19:56             ` Al Viro
2021-01-24 19:11           ` Linus Torvalds
2021-01-25  9:16             ` [PATCH] fs/pipe: allow sendfile() to pipe again Johannes Berg
2021-01-25 10:16               ` Christoph Hellwig
2021-01-25 20:34               ` Linus Torvalds
2021-01-26  6:07             ` Splicing to/from a tty Al Viro
2021-01-26  6:08               ` [PATCH 1/3] do_splice_to(): move the logics for limiting the read length in Al Viro
2021-01-26  6:09               ` [PATCH 2/3] take the guts of file-to-pipe splice into a helper function Al Viro
2021-01-26  6:09               ` [PATCH 3/3] teach sendfile(2) to handle send-to-pipe directly Al Viro
2021-01-26 18:57                 ` Linus Torvalds
2021-01-26 19:33                   ` Al Viro
2021-01-26 18:49               ` Splicing to/from a tty Linus Torvalds
2021-01-26 19:42                 ` Al Viro
2021-01-18 19:34     ` Al Viro
2021-01-18 19:46       ` Linus Torvalds
2021-01-18 19:54         ` Al Viro
2021-01-20 16:26           ` Al Viro
2021-01-20 19:11             ` Al Viro
2021-01-20 19:27               ` Linus Torvalds
2021-01-20 22:25                 ` David Laight
2021-01-20 23:02                   ` Al Viro
2021-01-20 23:14                 ` Al Viro
2021-01-20 23:40                   ` Linus Torvalds
2021-01-21  0:38                     ` Al Viro
2021-01-21  1:04                       ` Linus Torvalds [this message]
2021-01-21  1:45                         ` Al Viro
2021-01-21  3:38                           ` Linus Torvalds
2021-01-21  6:05                             ` Willy Tarreau
2021-01-21  8:04                               ` Johannes Berg
2021-01-21 10:08                         ` David Laight
2021-01-18  8:16 ` Christoph Hellwig
2021-01-18 19:36   ` Linus Torvalds
2021-01-18 20:24     ` Linus Torvalds
2021-01-18 21:35       ` Linus Torvalds
2021-01-18 21:54         ` Linus Torvalds
2021-01-18 22:03           ` Linus Torvalds
2021-01-18 22:20             ` Linus Torvalds
2021-01-19  1:38               ` Linus Torvalds
2021-01-19 11:53                 ` Greg Kroah-Hartman
2021-01-19 16:56                   ` Robert Karszniewicz
2021-01-19 17:10                     ` Robert Karszniewicz
2021-01-19 22:09                     ` Oliver Giles
2021-01-19 17:25                   ` Linus Torvalds
2021-01-19 20:24                   ` Linus Torvalds
2021-01-19 20:38                     ` Christoph Hellwig
2021-01-20  1:25                     ` Oliver Giles
2021-01-20  4:44                       ` Linus Torvalds
2021-01-20  8:15                         ` Oliver Giles
2021-01-21  1:18                         ` tty splice branch (was "Re: Splicing to/from a tty") Linus Torvalds
2021-01-21  8:44                           ` Greg Kroah-Hartman
2021-01-21  8:50                           ` Jiri Slaby
2021-01-21  8:58                             ` Jiri Slaby
2021-01-21 17:52                               ` Linus Torvalds
2021-01-21  8:58                             ` Greg Kroah-Hartman
2021-01-21 17:03                         ` Splicing to/from a tty Robert Karszniewicz
2021-01-21 18:43                           ` Linus Torvalds
2021-01-19 11:52         ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHk-=whWGwcZXpqDFv-j2fcChtT1jE0ZMFCmQHp3BrSkp+XZ6A@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ohw.giles@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.