linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: "Ahelenia Ziemiańska" <nabijaczleweli@nabijaczleweli.xyz>
Cc: Jan Kara <jack@suse.cz>, Amir Goldstein <amir73il@gmail.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: splice(-> FIFO) never wakes up inotify IN_MODIFY?
Date: Mon, 26 Jun 2023 17:00:01 +0200	[thread overview]
Message-ID: <20230626150001.rl7m7ngjsus4hzcs@quack3> (raw)
In-Reply-To: <bngangrplbxesizu5kbi442fw2et5dzh723nzxsqj2b2p5ikze@dtnajlktfc2g>

On Mon 26-06-23 16:25:41, Ahelenia Ziemiańska wrote:
> On Mon, Jun 26, 2023 at 03:51:59PM +0200, Jan Kara wrote:
> > On Mon 26-06-23 14:57:55, Ahelenia Ziemiańska wrote:
> > > On Mon, Jun 26, 2023 at 02:19:42PM +0200, Ahelenia Ziemiańska wrote:
> > > > > splice(2) differentiates three different cases:
> > > > >         if (ipipe && opipe) {
> > > > > ...
> > > > >         if (ipipe) {
> > > > > ...
> > > > >         if (opipe) {
> > > > > ...
> > > > > 
> > > > > IN_ACCESS will only be generated for non-pipe input
> > > > > IN_MODIFY will only be generated for non-pipe output
> > > > >
> > > > > Similarly FAN_ACCESS_PERM fanotify permission events
> > > > > will only be generated for non-pipe input.
> > > Sorry, I must've misunderstood this as "splicing to a pipe generates
> > > *ACCESS". Testing reveals this is not the case. So is it really true
> > > that the only way to poll a pipe is a sleep()/read(O_NONBLOCK) loop?
> > So why doesn't poll(3) work? AFAIK it should...
> poll returns instantly with revents=POLLHUP for pipes that were closed
> by the last writer.
> 
> Thus, you're either in a hot loop or you have to explicitly detect this
> and fall back to sleeping, which defeats the point of polling:

I see. There are two ways around this:

a) open the file descriptor with O_RDWR (so there's always at least one
writer).

b) when you get POLLHUP, just close the fd and open it again.

In these cases poll(3) will behave as you need (tested)...

								Honza

> -- >8 --
> #define _GNU_SOURCE
> #include <errno.h>
> #include <fcntl.h>
> #include <poll.h>
> #include <stdio.h>
> #include <unistd.h>
> int main() {
>   char buf[64 * 1024];
>   struct pollfd pf = {.fd = 0, .events = POLLIN};
>   size_t consec = 0;
>   for (ssize_t rd;;) {
>     while (poll(&pf, 1, -1) <= 0)
>       ;
>     if (pf.revents & POLLIN) {
>       while ((rd = read(0, buf, sizeof(buf))) == -1 && errno == EINTR)
>         ;
>       fprintf(stderr, "\nrd=%zd: %m\n", rd);
>     }
>     if (pf.revents & POLLHUP) {
>       if (!consec++)
>         fprintf(stderr, "\n\tPOLLHUPs");
>       fprintf(stderr, "\r%zu", consec);
>     } else
>       consec = 0;
>   }
> }
> -- >8 --
> 
> And
> -- >8 --
> $ ./rdr < fifo
> 
> rd=12: Success
> 
> 1779532 POLLHUPs
> rd=5: Success
> 
> 945087  POLLHUPs
> rd=12: Success
> ^C
> -- >8 --
> corresponding to
> -- >8 --
> $ cat > fifo
> abc
> def
> ghi
> ^D
> $ echo zupa > fifo
> $ cat > fifo
> as
> dsaa
> asd
> ^C
> -- >8 --


-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2023-06-26 15:00 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-26  3:04 splice(-> FIFO) never wakes up inotify IN_MODIFY? Ahelenia Ziemiańska
2023-06-26  6:11 ` Amir Goldstein
2023-06-26 12:19   ` Ahelenia Ziemiańska
2023-06-26 12:57     ` Ahelenia Ziemiańska
2023-06-26 13:51       ` Jan Kara
2023-06-26 14:25         ` Ahelenia Ziemiańska
2023-06-26 15:00           ` Jan Kara [this message]
2023-06-26 15:15             ` Ahelenia Ziemiańska
2023-06-26 16:52               ` Jan Kara
2023-06-26 14:53     ` Amir Goldstein
2023-06-26 15:12       ` Ahelenia Ziemiańska
2023-06-26 16:21         ` Amir Goldstein
2023-06-26 17:14           ` Ahelenia Ziemiańska
2023-06-26 18:57             ` Amir Goldstein
2023-06-26 23:08               ` [PATCH v2 0/3] fanotify accounting for fs/splice.c наб
2023-06-27  6:14                 ` Amir Goldstein
2023-06-27 16:55                   ` [PATCH v3 0/3+1] " Ahelenia Ziemiańska
2023-06-27 16:55                     ` [PATCH v3 1/3] splice: always fsnotify_access(in), fsnotify_modify(out) on success Ahelenia Ziemiańska
2023-06-27 18:10                       ` Amir Goldstein
2023-06-27 20:13                         ` Ahelenia Ziemiańska
2023-06-27 16:55                     ` [PATCH v3 2/3] splice: fsnotify_access(fd)/fsnotify_modify(fd) in vmsplice Ahelenia Ziemiańska
2023-06-27 18:11                       ` Amir Goldstein
2023-06-27 16:55                     ` [PATCH v3 3/3] splice: fsnotify_access(in), fsnotify_modify(out) on success in tee Ahelenia Ziemiańska
2023-06-27 16:57                     ` [LTP PATCH] inotify13: new test for fs/splice.c functions vs pipes vs inotify Ahelenia Ziemiańska
2023-06-27 18:31                       ` Amir Goldstein
2023-06-27 20:59                         ` [LTP RFC PATCH v2] " Ahelenia Ziemiańska
2023-06-28  0:21                           ` [LTP RFC PATCH v3] " Ahelenia Ziemiańska
2023-06-28  5:30                             ` Amir Goldstein
2023-06-28 16:03                               ` Ahelenia Ziemiańska
2023-06-27 22:57                         ` [LTP PATCH] " Petr Vorel
2023-06-27 18:03                     ` [PATCH v3 0/3+1] fanotify accounting for fs/splice.c Amir Goldstein
2023-06-27 20:34                       ` Ahelenia Ziemiańska
2023-06-27 20:50                         ` [PATCH v4 0/3] " Ahelenia Ziemiańska
2023-06-27 20:50                           ` [PATCH v4 1/3] splice: always fsnotify_access(in), fsnotify_modify(out) on success Ahelenia Ziemiańska
2023-06-28  6:33                             ` Amir Goldstein
2023-06-28 10:11                               ` Jan Kara
2023-06-28 17:09                               ` Ahelenia Ziemiańska
2023-06-28 18:38                                 ` Amir Goldstein
2023-06-28 20:18                                   ` Ahelenia Ziemiańska
2023-06-30 11:03                                     ` Amir Goldstein
2023-06-27 20:50                           ` [PATCH v4 2/3] splice: fsnotify_access(fd)/fsnotify_modify(fd) in vmsplice Ahelenia Ziemiańska
2023-06-27 20:51                           ` [PATCH v4 3/3] splice: fsnotify_access(in), fsnotify_modify(out) on success in tee Ahelenia Ziemiańska
2023-06-28  6:02                           ` [PATCH v4 0/3] fanotify accounting for fs/splice.c Amir Goldstein
2023-06-28 11:38                           ` Jan Kara
2023-06-28 13:41                             ` Amir Goldstein
2023-06-28 18:54                             ` Ahelenia Ziemiańska
2023-06-29  8:45                               ` Jan Kara
2023-06-28  4:51                     ` [PATCH v3 0/3+1] " Christoph Hellwig
2023-06-28 10:38                       ` Jan Kara
2023-06-26 23:09               ` [PATCH v2 1/3] splice: always fsnotify_access(in), fsnotify_modify(out) on success Ahelenia Ziemiańska
2023-06-27  6:02                 ` Amir Goldstein
2023-06-26 23:09               ` [PATCH v2 2/3] splice: fsnotify_modify(fd) in vmsplice Ahelenia Ziemiańska
2023-06-27  6:27                 ` Amir Goldstein
2023-06-26 23:09               ` [PATCH v2 3/3] splice: fsnotify_access(in), fsnotify_modify(out) on success in tee Ahelenia Ziemiańska
2023-06-27  6:20                 ` Amir Goldstein

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=20230626150001.rl7m7ngjsus4hzcs@quack3 \
    --to=jack@suse.cz \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nabijaczleweli@nabijaczleweli.xyz \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).