Get Inotify to properly emit the IN_UNMOUNT event

Hello, I'm trying to get Inotify to give way to the IN_UNMOUNT event, but it didn’t interact with me at all, so I went and did a simple experiment with inotifywait, and this is the result below:

paul@imaskar ~ $ inotifywait -r /storage/test/ -m Setting up watches. Beware: since -r was given, this may take a while! Watches established. /storage/test/ CREATE,ISDIR a /storage/test/ OPEN,ISDIR a /storage/test/ CLOSE_NOWRITE,CLOSE,ISDIR a /storage/test/ DELETE,ISDIR a /storage/test/a/ DELETE_SELF /storage/test/a/ IGNORED /storage/test/ IGNORED 

Basically, what happens is that it will take away all other events, such as create, open, etc., but when I turn off / storage / test /, it gives IGNORED for all the clocks that it created, but it never fires an event UNMOUNT ...

So, it looks like I cannot get the IN_UNMOUNT event, but all the inotify documentation I read says that the kernel will add the IN_UNMOUNT bit flag to the event when the monitored storage of backup files / directories is disabled ...

Here is a simple C code from Fix Patch

 #include <stdio.h> #include <stdlib.h> #include <sys/inotify.h> int main(int argc, char **argv) { char buf[1024]; struct inotify_event *ie; char *p; int i; ssize_t l; p = argv[1]; i = inotify_init(); inotify_add_watch(i, p, ~0); l = read(i, buf, sizeof(buf)); printf("read %d bytes\n", l); ie = (struct inotify_event *) buf; printf("event mask: %x\n", ie->mask); return 0; } 

In any case, I took the following steps:

 gcc -oinotify inotify.c mkdir mnt sudo mount -ttmpfs none mnt mkdir mnt/d ./inotify mnt/d/ # Different shell sudo umount mnt 

And finally, this is what it emits

 read 16 bytes event mask: 8000 

So, at the moment I'm not sure if the problem is in the code or something else?

+4
source share
1 answer

This seems to be a kernel bug that is fixed by LKML . Around the time of tier 2.6.31, the IN_UNMOUNT event was not dispatched when inodes umounted ... This patch was for "34-longterm" aka Kernel 2.6.35 (?).

In any case, I managed to upgrade to the 2.6.37 kernel and repeat the previous tests, and here are the results:

 mkdir mnt sudo mount -ttmpfs none mnt mkdir mnt/d inotifywait -r mnt/d/ -m # Different shell sudo umount mnt 

And here is the conclusion:

 Setting up watches. Beware: since -r was given, this may take a while! Watches established. /tmp/test/d/ UNMOUNT /tmp/test/d/ IGNORED /tmp/test/ UNMOUNT /tmp/test/ IGNORED 

And according to the C code sample, here's the output:

 read 32 bytes event mask: 2000 

And looking at the inotify.h headers, this is the correct event mask for the IN_UNMOUNT flag, so this means that it is finally fixed ~ 2.6.35 or the last ...

+4
source

Source: https://habr.com/ru/post/1344350/


All Articles