2011-03-19 2 views
4

안녕하세요. Inotify가 IN_UNMOUNT 이벤트를 발생 시키려고했지만 그와 전혀 협력하지 않으므로 inotifywait을 사용하여 간단한 실험을했는데 이것이 아래의 결과입니다.Inotify에서 IN_UNMOUNT 이벤트를 적절하게 내 보냅니다.

[email protected] ~ $ 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 

는 기본적으로 무슨 일이는 등, 생성, 개방과 같은 다른 모든 이벤트를 선택할 것입니다 ....하지만 난 /저장/테스트/을 마운트 해제 할 때 그것은 무시 방출합니다 모든 시계를 만들었지 만 UNMOUNT 이벤트를 내 보내지는 않습니다 ...

그래서 IN_UNMOUNT 이벤트를 얻을 수 없지만 읽은 모든 inotify 문서는 모니터링되는 파일/디렉토리 백업 저장소가 마운트 해제되었을 때 커널이 이벤트에 IN_UNMOUNT 비트 플래그를 추가한다고 말합니다 ...

여기에서 간단한 C 코드입니다 - 어쨌든 Inotify 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; 
} 

내가 다음 단계 않았다가 방출하는 것을 마침내 여기

gcc -oinotify inotify.c 
mkdir mnt 
sudo mount -ttmpfs none mnt 
mkdir mnt/d 
./inotify mnt/d/ 

# Different shell 
sudo umount mnt 

하고

read 16 bytes 
event mask: 8000 

이 시점에서 문제가 코드에 있는지 또는 다른 것이 있는지 확실하지 않습니다.

답변

4

이것은 LKML으로 수정 된 커널 버그 인 것 같습니다. 커널 2.6.31 이후 inode가 마운트 해제 될 때 IN_UNMOUNT 이벤트가 전송되지 않았습니다 ...이 패치는 "2.6-longterm", 즉 커널 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 

등 샘플 C 코드는 다음과 같습니다.

read 32 bytes 
event mask: 2000 

그리고 inotify.h 헤더를 보면 올바른 것입니다 IN_UNMOUNT 플래그에 대한 이벤트 마스크는 결국 ~ 2.6.35 또는 그 이후의 고정을 의미합니다 ...