[vhffs-dev] [1911] using different inotify mask for directories and files, in order to lower a lot number of events received from kernel |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
- To: vhffs-dev@xxxxxxxxx
- Subject: [vhffs-dev] [1911] using different inotify mask for directories and files, in order to lower a lot number of events received from kernel
- From: subversion@xxxxxxxxxxxxx
- Date: Sat, 12 Nov 2011 23:35:06 +0100
Revision: 1911
Author: gradator
Date: 2011-11-12 23:35:06 +0100 (Sat, 12 Nov 2011)
Log Message:
-----------
using different inotify mask for directories and files, in order to lower a lot number of events received from kernel
Modified Paths:
--------------
trunk/vhffs-fssync/vhffsfssync_master.c
Modified: trunk/vhffs-fssync/vhffsfssync_master.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_master.c 2011-11-04 21:45:50 UTC (rev 1910)
+++ trunk/vhffs-fssync/vhffsfssync_master.c 2011-11-12 22:35:06 UTC (rev 1911)
@@ -57,10 +57,8 @@
/* -- inotify stuff -- */
#define VHFFSFSSYNC_BUF_LEN 4096
-#define VHFFSFSSYNC_WATCH_MASK IN_ATTRIB|IN_CREATE|IN_DELETE|IN_MODIFY|IN_MOVED_FROM|IN_MOVED_TO|IN_DONT_FOLLOW
-// Not used yet: IN_DELETE_SELF, IN_MOVE_SELF
-// Use to be used: IN_CLOSE_WRITE, IN_ONLYDIR
-// Will never be used: IN_ACCESS, IN_OPEN, IN_CLOSE_NOWRITE
+#define VHFFSFSSYNC_WATCH_MASK_FILE IN_ATTRIB|IN_MODIFY|IN_DONT_FOLLOW
+#define VHFFSFSSYNC_WATCH_MASK_DIR IN_ATTRIB|IN_CREATE|IN_DELETE|IN_MOVED_FROM|IN_MOVED_TO|IN_DONT_FOLLOW|IN_ONLYDIR
// each monitor entry is associated with a path, we need to keep it to compute the path
//char **vhffsfssync_wd_to_watch = NULL;
@@ -93,7 +91,7 @@
char *vhffsfssync_pathname(vhffsfssync_watch *watch, const char *filename);
vhffsfssync_watch *vhffsfssync_add_watch(int inotifyfd, vhffsfssync_watch *parent, const char *dirname, uint32_t mask);
int vhffsfssync_del_watch(int inotifyfd, vhffsfssync_watch *watch);
-vhffsfssync_watch *vhffsfssync_add_watch_recursively(int inotifyfd, vhffsfssync_watch *parent, const char *dirname, uint32_t mask);
+vhffsfssync_watch *vhffsfssync_add_watch_recursively(int inotifyfd, vhffsfssync_watch *parent, const char *dirname);
int vhffsfssync_manage_event_remove(int inotifyfd, vhffsfssync_watch *watch, char *filename);
int vhffsfssync_manage_event_create(int inotifyfd, vhffsfssync_watch *watch, char *filename);
int vhffsfssync_manage_event(int inotifyfd, struct inotify_event *event);
@@ -1333,13 +1331,13 @@
}
-vhffsfssync_watch *vhffsfssync_add_watch_recursively(int inotifyfd, vhffsfssync_watch *parent, const char *dirname, uint32_t mask) {
+vhffsfssync_watch *vhffsfssync_add_watch_recursively(int inotifyfd, vhffsfssync_watch *parent, const char *dirname) {
vhffsfssync_watch *watch;
char *pathname;
DIR *d;
- watch = vhffsfssync_add_watch(inotifyfd, parent, dirname, mask);
+ watch = vhffsfssync_add_watch(inotifyfd, parent, dirname, VHFFSFSSYNC_WATCH_MASK_DIR);
if(!watch) return NULL;
pathname = vhffsfssync_pathname(parent, dirname);
@@ -1358,11 +1356,11 @@
/* If the filesystem supports dirent->d_type */
if(dir->d_type != DT_UNKNOWN) {
if( dir->d_type == DT_REG || dir->d_type == DT_LNK ) {
- if( !vhffsfssync_add_watch(inotifyfd, watch, dir->d_name, mask) )
+ if( !vhffsfssync_add_watch(inotifyfd, watch, dir->d_name, VHFFSFSSYNC_WATCH_MASK_FILE) )
return NULL;
}
else if(dir->d_type == DT_DIR) {
- if( !vhffsfssync_add_watch_recursively(inotifyfd, watch, dir->d_name, mask) )
+ if( !vhffsfssync_add_watch_recursively(inotifyfd, watch, dir->d_name) )
return NULL;
}
/* we don't need other file types (chr, block, fifo, socket, ...) */
@@ -1372,11 +1370,11 @@
struct stat st;
if( !lstat(dir->d_name, &st) ) {
if( S_ISREG(st.st_mode) || S_ISLNK(st.st_mode) ) {
- if( !vhffsfssync_add_watch(inotifyfd, watch, dir->d_name, mask) )
+ if( !vhffsfssync_add_watch(inotifyfd, watch, dir->d_name, VHFFSFSSYNC_WATCH_MASK_FILE) )
return NULL;
}
else if(S_ISDIR(st.st_mode)) {
- if( !vhffsfssync_add_watch_recursively(inotifyfd, watch, dir->d_name, mask) )
+ if( !vhffsfssync_add_watch_recursively(inotifyfd, watch, dir->d_name) )
return NULL;
}
/* we don't need other file types (chr, block, fifo, socket, ...) */
@@ -1428,7 +1426,7 @@
#if DEBUG_INOTIFY
printf("==> CREATE %s\n", pathname);
#endif
- vhffsfssync_add_watch(inotifyfd, watch, filename, VHFFSFSSYNC_WATCH_MASK);
+ vhffsfssync_add_watch(inotifyfd, watch, filename, VHFFSFSSYNC_WATCH_MASK_FILE);
if(!st.st_size) {
vhffsfssync_net_broadcast_event( g_strdup_printf("create%c%s%c%ld%c%d%c%d%c%d%c", '\0', pathname, '\0', st.st_mtime, '\0', st.st_mode&07777, '\0', st.st_uid, '\0', st.st_gid, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
vhffsfssync_net_broadcast_event( vhffsfssync_net_parent_attrib(pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
@@ -1443,7 +1441,7 @@
#if DEBUG_INOTIFY
printf("==> MKDIR %s\n", pathname);
#endif
- newwatch = vhffsfssync_add_watch(inotifyfd, watch, filename, VHFFSFSSYNC_WATCH_MASK);
+ newwatch = vhffsfssync_add_watch(inotifyfd, watch, filename, VHFFSFSSYNC_WATCH_MASK_DIR);
vhffsfssync_net_broadcast_event( g_strdup_printf("mkdir%c%s%c%ld%c%d%c%d%c%d%c", '\0', pathname, '\0', st.st_mtime, '\0', st.st_mode&07777, '\0', st.st_uid, '\0', st.st_gid, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
vhffsfssync_net_broadcast_event( vhffsfssync_net_parent_attrib(pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
/* there is a short delay between the mkdir() and the add_watch(),
@@ -1461,7 +1459,7 @@
#if DEBUG_INOTIFY
printf("==> SYMLINK %s -> %s\n", pathname, linkto);
#endif
- vhffsfssync_add_watch(inotifyfd, watch, filename, VHFFSFSSYNC_WATCH_MASK);
+ vhffsfssync_add_watch(inotifyfd, watch, filename, VHFFSFSSYNC_WATCH_MASK_FILE);
vhffsfssync_net_broadcast_event( g_strdup_printf("symlink%c%s%c%s%c%ld%c%d%c%d%c", '\0', pathname, '\0', linkto, '\0', st.st_mtime, '\0', st.st_uid, '\0', st.st_gid, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
vhffsfssync_net_broadcast_event( vhffsfssync_net_parent_attrib(pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
}
@@ -1509,6 +1507,11 @@
return -1;
}
+ // DROP useless dir events (we are going to receive the same event on the file watch)
+ if( event->len > 0 && event->mask & IN_ATTRIB ) {
+ return 0;
+ }
+
watch = g_hash_table_lookup(vhffsfssync_wd_to_watch, &event->wd);
assert( watch != NULL );
@@ -1596,7 +1599,7 @@
if( vhffsfssync_cookie.isdir ) {
char *frompathname = vhffsfssync_pathname(vhffsfssync_cookie.watch, vhffsfssync_cookie.filename);
- vhffsfssync_add_watch(inotifyfd, watch, event->name, VHFFSFSSYNC_WATCH_MASK);
+ vhffsfssync_add_watch(inotifyfd, watch, event->name, VHFFSFSSYNC_WATCH_MASK_DIR);
vhffsfssync_net_broadcast_event( g_strdup_printf("move%c%s%c%s%c", '\0', frompathname, '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
vhffsfssync_net_broadcast_event( vhffsfssync_net_parent_attrib(frompathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
vhffsfssync_net_broadcast_event( vhffsfssync_net_parent_attrib(pathname) , VHFFSFSSYNC_NET_PRIO_MEDIUM);
@@ -1792,7 +1795,7 @@
fcntl(inotifyfd, F_SETFL, flags);
}
- watch = vhffsfssync_add_watch_recursively(inotifyfd, NULL, root, VHFFSFSSYNC_WATCH_MASK);
+ watch = vhffsfssync_add_watch_recursively(inotifyfd, NULL, root);
if(!watch) {
fprintf(stderr, "Maximum number of watches probably reached, consider adding more or fixing what is being wrong before running me again (strace is your friend)... byebye!\n");
return -1;