Linux 获取Inotify以正确发出IN_UNMOUNT事件
您好,我一直试图让Inotify放弃IN_UNMOUNT事件,但它根本不配合我,因此我用inotifywait做了一个简单的实验,结果如下:Linux 获取Inotify以正确发出IN_UNMOUNT事件,linux,inotify,Linux,Inotify,您好,我一直试图让Inotify放弃IN_UNMOUNT事件,但它根本不配合我,因此我用inotifywait做了一个简单的实验,结果如下: 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 /stora
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
基本上,它将接收所有其他事件,如创建、打开等。。。。但当我卸载/storage/test/时,它将为它创建的所有手表发出一个IGNORED,但它从不发出卸载事件
因此,似乎我无法获得IN_UNMOUNT事件,但我阅读的所有inotify文档都表示,当卸载受监视的文件/目录备份存储时,内核将向事件添加IN_UNMOUNT位标志
下面是一个简单的C代码,来自-
最后,这里是它所散发的
read 16 bytes
event mask: 8000
因此,此时此刻,我不确定问题是在代码中还是在其他地方?这似乎是一个内核错误,已根据修复。大约从内核2.6.31开始,在安装inode时,未发送IN_UNMOUNT事件。。。这个补丁是为“34长期”aka内核2.6.35(?) 无论如何,我能够升级到内核2.6.37并重新运行上述测试,结果如下:
mkdir mnt
sudo mount -ttmpfs none mnt
mkdir mnt/d
inotifywait -r mnt/d/ -m
# Different shell
sudo umount mnt
以下是输出:
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
read 32 bytes
event mask: 2000
根据示例C代码,以下是输出:
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
read 32 bytes
event mask: 2000
查看inotify.h头,这是IN_UNMOUNT标志的正确事件掩码,这意味着它最终修复了~2.6.35或更高版本