linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* splice(-> FIFO) never wakes up inotify IN_MODIFY?
@ 2023-06-26  3:04 Ahelenia Ziemiańska
  2023-06-26  6:11 ` Amir Goldstein
  0 siblings, 1 reply; 55+ messages in thread
From: Ahelenia Ziemiańska @ 2023-06-26  3:04 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, linux-fsdevel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2173 bytes --]

Hi!

Consider the following programs:
-- >8 --
==> ino.c <==
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/inotify.h>
#include <unistd.h>
int main() {
  int ino = inotify_init1(IN_CLOEXEC);
  inotify_add_watch(ino, "/dev/fd/0", IN_MODIFY);

  char buf[64 * 1024];
  struct inotify_event ev;
  while (read(ino, &ev, sizeof(ev)) > 0) {
    fprintf(stderr, "%d: mask=%x, cook=%x, len=%x, name=%.*s\n", ev.wd, ev.mask,
            ev.cookie, ev.len, (int)ev.len, ev.name);
    fprintf(stderr, "rd=%zd\n", read(0, buf, sizeof(buf)));
  }
}

==> se.c <==
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/sendfile.h>
int main() {
  ssize_t rd, acc = 0;
  while ((rd = sendfile(1, 0, 0, 128 * 1024 * 1024)) > 0)
    acc += rd;
  fprintf(stderr, "se=%zd: %m\n", acc);
}

==> sp.c <==
#define _GNU_SOURCE
#include <fcntl.h>
#include <stdio.h>
int main() {
  ssize_t rd, acc = 0;
  while ((rd = splice(0, 0, 1, 0, 128 * 1024 * 1024, 0)) > 0)
    acc += rd;
  fprintf(stderr, "sp=%zd: %m\n", acc);
}
-- >8 --

By all means, ./sp | ./ino and ./se | ./ino should be equivalent,
right?

-- >8 --
$ make se sp ino
$ mkfifo fifo
$ ./ino < fifo &
[1] 230
$ echo a > fifo
$ echo a > fifo
1: mask=2, cook=0, len=0, name=
rd=4
$ echo c > fifo
1: mask=2, cook=0, len=0, name=
rd=2
$ ./se > fifo
abcdef
1: mask=2, cook=0, len=0, name=
asd
^D
se=11: Success
rd=11
1: mask=2, cook=0, len=0, name=
rd=0
$ ./sp > fifo
abcdefg
asd
dsasdadadad
sp=24: Success
$ < sp ./sp > fifo
sp=25856: Success
$ < sp ./sp > fifo
^C
$ echo sp > fifo
^C
-- >8 --

Note how in all ./sp > fifo cases, ./ino doesn't wake up!
Note also how, thus, we've managed to fill the pipe buffer with ./sp
(when it transferred 25856), and now we can't /ever/ write there again
(both splicing and normal writes block, since there's no space left in
 the pipe; ./ino hasn't seen this and will never wake up or service the
 pipe):
so we've effectively "denied service" by slickily using a different
syscall to do the write, right?

I consider this to be unexpected behaviour because (a) obviously and
(b) sendfile() sends the inotify event.

Happens on my linus checkout (v6.4-rc7-234-g547cc9be86f4) and bookworm (6.1.27-1).

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2023-06-30 11:04 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).