linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Regression: File truncate inotify behavior change
@ 2024-02-16 19:53 Paul Lawrence
       [not found] ` <CAOQ4uxgR1Z9LXAiRwgQ6h9avBphYttLeQS2JFWtzQr6ck6AiKw@mail.gmail.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Lawrence @ 2024-02-16 19:53 UTC (permalink / raw)
  To: Linux kernel; +Cc: Amir Goldstein, Miklos Szeredi, linux-fsdevel

The change:

fsnotify: move fsnotify_open() hook into do_dentry_open()

has modified notification behavior on creat. Specifically, calling
creat on an existing file used to emit a modify then an open
notification, presumably from the file being truncated first. After
this change, there is no modify. I wrote the following test program:

#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/inotify.h>

const char *dirname = "test";
const char *filename = "test/file";

int main() {
  char buffer[4096];
  int size;
  char *ptr = buffer;

  mkdir(dirname, 0777);
  int nfd = inotify_init();
  inotify_add_watch(nfd, dirname, IN_ALL_EVENTS);
  int fd = creat(filename, 0600);
  write(fd, "hello", 5);
  close(fd);
  size = read(nfd, buffer, sizeof(buffer));

  while(size > 0) {
    struct inotify_event *ie = (struct inotify_event *) ptr;
    printf("%d %u %u %u %s\n", ie->wd, (unsigned) ie->mask, (unsigned)
ie->cookie, (unsigned) ie->len, ie->name);
    ptr += sizeof(*ie) + ie->len;
    size -= sizeof(*ie) + ie->len;
  }

  return 0;
}

which demonstrates the change - if you run it twice without this patch, you get:

debian@debian:~$ ./test
1 256 0 16 file
1 32 0 16 file
1 2 0 16 file
1 8 0 16 file
debian@debian:~$ ./test
1 2 0 16 file
1 32 0 16 file
1 2 0 16 file
1 8 0 16 file

but with this patch you get:

debian@debian:~$ ./test
1 256 0 16 file
1 32 0 16 file
1 2 0 16 file
1 8 0 16 file
debian@debian:~$ ./test
1 32 0 16 file
1 2 0 16 file
1 8 0 16 file

(Android has a CTS test that detected this change in behavior. I am
not aware of any actual breakages caused by it, but it seemed worth
surfacing this change so we can decide the best course of action.)

Paul

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

* Re: Regression: File truncate inotify behavior change
       [not found] ` <CAOQ4uxgR1Z9LXAiRwgQ6h9avBphYttLeQS2JFWtzQr6ck6AiKw@mail.gmail.com>
@ 2024-02-17 18:53   ` Paul Lawrence
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Lawrence @ 2024-02-17 18:53 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Miklos Szeredi, linux-fsdevel, Jan Kara

OK, that makes sense. I checked that I still get a modify even if I
don't write to the file. It's hard to imagine an actual application
(not a test app) depending on this exact ordering. I will change our
CTS test to be more tolerant.

Thanks for the quick response,
Paul

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

end of thread, other threads:[~2024-02-17 18:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-16 19:53 Regression: File truncate inotify behavior change Paul Lawrence
     [not found] ` <CAOQ4uxgR1Z9LXAiRwgQ6h9avBphYttLeQS2JFWtzQr6ck6AiKw@mail.gmail.com>
2024-02-17 18:53   ` Paul Lawrence

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