inotify for 2.6.11-rc3-mm1
Subsystems (5)
PATCH 1/1 inotify for 2.6.11-rc3-mm1
Andrew,
Attached patch is an updated inotify for 2.6-mm. It replaces inotify.patch and inotify-fix_find_inode.patch.
A bunch of improvements over the current patch:
- Implements a generic notification layer, simple wrappers to keep the dnotify and inotify hooks in fs/ clean. In response to hch request.
- Merge Mike's fix for the unmount race Viro spotted.
- dget_parent optimization
- SPARC64 configure entry
- Cleanup, bug fixes, etc.
Please, apply.
Best,
Robert Love
inotify, an awesome file change notification thing!
inotify is intended to correct the deficiencies of dnotify, particularly its inability to scale and its terrible user interface:
* dnotify requires the opening of one fd per each directory that you intend to watch. This quickly results in too many open files and pins removable media, preventing unmount.
* dnotify is directory-based. You only learn about changes to directories. Sure, a change to a file in a directory affects the directory, but you are then forced to keep a cache of stat structures.
* dnotify's interface to user-space is awful. Signals?
inotify provides a more usable, simple, powerful solution to file change notification:
* inotify's interface is a device node, not SIGIO. You open a single fd to the device node, which is select()-able.
* inotify has an event that says "the filesystem that the item you were watching is on was unmounted."
* inotify can watch directories or files.
Inotify is currently used by Beagle (a desktop search infrastructure) and Gamin (a FAM replacement).
arch/sparc64/Kconfig | 13 drivers/char/Kconfig | 13 drivers/char/Makefile | 2 drivers/char/inotify.c | 1072 +++++++++++++++++++++++++++++++++++++++++++++ fs/attr.c | 32 - fs/compat.c | 14 fs/file_table.c | 4 fs/inode.c | 3 fs/namei.c | 38 - fs/open.c | 9 fs/read_write.c | 24 - fs/super.c | 3 include/linux/fs.h | 7 include/linux/fsnotify.h | 235 +++++++++ include/linux/inotify.h | 119 ++++ include/linux/miscdevice.h | 1 include/linux/sched.h | 2 kernel/user.c | 2 18 files changed, 1530 insertions(+), 63 deletions(-)
arch/sparc64/Kconfig +13 -0
@@ -88,6 +88,19 @@ bool default y +config INOTIFY + bool "Inotify file change notification support" + default y + ---help--- + Say Y here to enable inotify support and the /dev/inotify character + device. Inotify is a file change notification system and a + replacement for dnotify. Inotify fixes numerous shortcomings in + dnotify and introduces several new features. It allows monitoring + of both files and directories via a single open fd. Multiple file + events are supported. + + If unsure, say Y. + config SMP bool "Symmetric multi-processing support" ---help---
drivers/char/inotify.c +1072 -0
1,072 lines not on this page · raw message
drivers/char/Kconfig +13 -0
@@ -62,6 +62,19 @@ depends on VT && !S390 && !USERMODE default y +config INOTIFY + bool "Inotify file change notification support" + default y + ---help--- + Say Y here to enable inotify support and the /dev/inotify character + device. Inotify is a file change notification system and a + replacement for dnotify. Inotify fixes numerous shortcomings in + dnotify and introduces several new features. It allows monitoring + of both files and directories via a single open fd. Multiple file + events are supported. + + If unsure, say Y. + config SERIAL_NONSTANDARD bool "Non-standard serial port support" ---help---
drivers/char/Makefile +2 -0
@@ -9,6 +9,8 @@ obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o + +obj-$(CONFIG_INOTIFY) += inotify.o obj-$(CONFIG_LEGACY_PTYS) += pty.o obj-$(CONFIG_UNIX98_PTYS) += pty.o obj-y += misc.o
fs/attr.c +3 -29
@@ -10,7 +10,7 @@#include <linux/mm.h> #include <linux/string.h> #include <linux/smp_lock.h> -#include <linux/dnotify.h> +#include <linux/fsnotify.h> #include <linux/fcntl.h> #include <linux/quotaops.h> #include <linux/security.h>
@@ -107,31 +107,8 @@ out:return error; } -EXPORT_SYMBOL (inode_setattr); -int setattr_mask (unsigned int ia_valid) -{ -unsigned long dn_mask =0 ; - -if (ia_valid &ATTR_UID ) - dn_mask |=DN_ATTRIB ; -if (ia_valid &ATTR_GID ) - dn_mask |=DN_ATTRIB ; -if (ia_valid &ATTR_SIZE ) - dn_mask |=DN_MODIFY ; -/* both times implies a utime(s) call */ -if ((ia_valid & (ATTR_ATIME |ATTR_MTIME )) == (ATTR_ATIME |ATTR_MTIME )) - dn_mask |=DN_ATTRIB ; -else if (ia_valid &ATTR_ATIME ) - dn_mask |=DN_ACCESS ; -else if (ia_valid &ATTR_MTIME ) - dn_mask |=DN_MODIFY ; -if (ia_valid &ATTR_MODE ) - dn_mask |=DN_ATTRIB ; -return dn_mask; -} -int notify_change (struct dentry * dentry,struct iattr * attr) {struct inode *inode = dentry->d_inode;
@@ -194,11 +171,8 @@if (ia_valid &ATTR_SIZE )up_write (&dentry->d_inode->i_alloc_sem); -if (!error) { -unsigned long dn_mask =setattr_mask (ia_valid); -if (dn_mask) -dnotify_parent (dentry, dn_mask); - } +if (!error) +fsnotify_change (dentry, ia_valid);return error; }
fs/compat.c +10 -4
@@ -36,7 +36,7 @@#include <linux/ctype.h> #include <linux/module.h> #include <linux/dirent.h> -#include <linux/dnotify.h> +#include <linux/fsnotify.h> #include <linux/highuid.h> #include <linux/sunrpc/svc.h> #include <linux/nfsd/nfsd.h>
@@ -1233,9 +1233,15 @@ out:if (iov != iovstack)kfree (iov); -if ((ret + (type ==READ )) >0 ) -dnotify_parent (file->f_dentry, - (type ==READ ) ?DN_ACCESS :DN_MODIFY ); +if ((ret + (type ==READ )) >0 ) { +struct dentry *dentry = file->f_dentry; +if (type ==READ ) +fsnotify_access (dentry, dentry->d_inode, + dentry->d_name.name); +else +fsnotify_modify (dentry, dentry->d_inode, + dentry->d_name.name); + }return ret; }
fs/file_table.c +4 -0
@@ -16,6 +16,7 @@#include <linux/eventpoll.h> #include <linux/mount.h> #include <linux/cdev.h> +#include <linux/fsnotify.h> /* sysctl tunables... */ struct files_stat_struct files_stat = {
@@ -122,6 +123,9 @@struct vfsmount *mnt = file->f_vfsmnt;struct inode *inode = dentry->d_inode; + +fsnotify_close (dentry, inode, file->f_mode, dentry->d_name.name); +might_sleep ();/* * The function eventpoll_release() should be the first called
fs/inode.c +3 -0
@@ -132,6 +132,9 @@#ifdef CONFIG_QUOTA memset (&inode->i_dquot,0 ,sizeof (inode->i_dquot));#endif +#ifdef CONFIG_INOTIFY + inode->inotify_data =NULL ; +#endif inode->i_pipe =NULL ; inode->i_bdev =NULL ; inode->i_cdev =NULL ;
fs/namei.c +18 -20
@@ -21,7 +21,7 @@#include <linux/namei.h> #include <linux/quotaops.h> #include <linux/pagemap.h> -#include <linux/dnotify.h> +#include <linux/fsnotify.h> #include <linux/smp_lock.h> #include <linux/personality.h> #include <linux/security.h>
@@ -1252,7 +1252,7 @@DQUOT_INIT (dir); error = dir->i_op->create (dir, dentry, mode, nd);if (!error) { -inode_dir_notify (dir,DN_CREATE ); +fsnotify_create (dir, dentry->d_name.name);security_inode_post_create (dir, dentry, mode); }return error;
@@ -1557,7 +1557,7 @@DQUOT_INIT (dir); error = dir->i_op->mknod (dir, dentry, mode, dev);if (!error) { -inode_dir_notify (dir,DN_CREATE ); +fsnotify_create (dir, dentry->d_name.name);security_inode_post_mknod (dir, dentry, mode, dev); }return error;
@@ -1630,7 +1630,7 @@DQUOT_INIT (dir); error = dir->i_op->mkdir (dir, dentry, mode);if (!error) { -inode_dir_notify (dir,DN_CREATE ); +fsnotify_mkdir (dir, dentry->d_name.name);security_inode_post_mkdir (dir,dentry, mode); }return error;
@@ -1720,10 +1720,8 @@ } }up (&dentry->d_inode->i_sem); -if (!error) { -inode_dir_notify (dir,DN_DELETE ); -d_delete (dentry); - } +if (!error) +fsnotify_rmdir (dentry, dentry->d_inode, dir);dput (dentry);return error;
@@ -1793,10 +1791,9 @@up (&dentry->d_inode->i_sem);/* We don't d_delete() NFS sillyrenamed files--they still exist. */ -if (!error && !(dentry->d_flags &DCACHE_NFSFS_RENAMED )) { -d_delete (dentry); -inode_dir_notify (dir,DN_DELETE ); - } +if (!error && !(dentry->d_flags &DCACHE_NFSFS_RENAMED )) +fsnotify_unlink (dentry->d_inode, dir, dentry); +return error; }
@@ -1870,7 +1867,7 @@DQUOT_INIT (dir); error = dir->i_op->symlink (dir, dentry, oldname);if (!error) { -inode_dir_notify (dir,DN_CREATE ); +fsnotify_create (dir, dentry->d_name.name);security_inode_post_symlink (dir, dentry, oldname); }return error;
@@ -1943,7 +1940,7 @@ error = dir->i_op->link (old_dentry, dir, new_dentry);up (&old_dentry->d_inode->i_sem);if (!error) { -inode_dir_notify (dir,DN_CREATE ); +fsnotify_create (dir, new_dentry->d_name.name);security_inode_post_link (old_dentry, dir, new_dentry); }return error;
@@ -2107,6 +2104,7 @@ {int error;int is_dir =S_ISDIR (old_dentry->d_inode->i_mode); +char *old_name;if (old_dentry->d_inode == new_dentry->d_inode)return 0 ;
@@ -2128,18 +2126,18 @@DQUOT_INIT (old_dir);DQUOT_INIT (new_dir); + old_name =fsnotify_oldname_init (old_dentry); +if (is_dir) error =vfs_rename_dir (old_dir,old_dentry,new_dir,new_dentry);else error =vfs_rename_other (old_dir,old_dentry,new_dir,new_dentry);if (!error) { -if (old_dir == new_dir) -inode_dir_notify (old_dir,DN_RENAME ); -else { -inode_dir_notify (old_dir,DN_DELETE ); -inode_dir_notify (new_dir,DN_CREATE ); - } +const char *new_name = old_dentry->d_name.name; +fsnotify_move (old_dir, new_dir, old_name, new_name); } +fsnotify_oldname_free (old_name); +return error; }
fs/open.c +7 -2
@@ -10,7 +10,7 @@#include <linux/file.h> #include <linux/smp_lock.h> #include <linux/quotaops.h> -#include <linux/dnotify.h> +#include <linux/fsnotify.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/tty.h>
@@ -944,9 +944,14 @@ fd =get_unused_fd ();if (fd >=0 ) {struct file *f =filp_open (tmp, flags, mode); +struct dentry *dentry; + error =PTR_ERR (f);if (IS_ERR (f)) goto out_error; + dentry = f->f_dentry; +fsnotify_open (dentry, dentry->d_inode, + dentry->d_name.name);fd_install (fd, f); } out:
@@ -998,7 +1003,7 @@ retval = err; } -dnotify_flush (filp, id); +fsnotify_flush (filp, id);locks_remove_posix (filp, id);fput (filp);return retval;
fs/read_write.c +18 -6
@@ -10,7 +10,7 @@#include <linux/file.h> #include <linux/uio.h> #include <linux/smp_lock.h> -#include <linux/dnotify.h> +#include <linux/fsnotify.h> #include <linux/security.h> #include <linux/module.h> #include <linux/syscalls.h>
@@ -239,7 +239,10 @@else ret =do_sync_read (file, buf, count, pos);if (ret >0 ) { -dnotify_parent (file->f_dentry,DN_ACCESS ); +struct inode *inode = file->f_dentry->d_inode; +struct dentry *dentry = file->f_dentry; +fsnotify_access (dentry, inode, + dentry->d_name.name); current->rchar += ret; } current->syscr++;
@@ -287,7 +290,10 @@else ret =do_sync_write (file, buf, count, pos);if (ret >0 ) { -dnotify_parent (file->f_dentry,DN_MODIFY ); +struct inode *inode = file->f_dentry->d_inode; +struct dentry *dentry = file->f_dentry; +fsnotify_modify (dentry, inode, + dentry->d_name.name); current->wchar += ret; } current->syscw++;
@@ -523,9 +529,15 @@ out:if (iov != iovstack)kfree (iov); -if ((ret + (type ==READ )) >0 ) -dnotify_parent (file->f_dentry, - (type ==READ ) ?DN_ACCESS :DN_MODIFY ); +if ((ret + (type ==READ )) >0 ) { +struct dentry *dentry = file->f_dentry; +struct inode *inode = dentry->d_inode; + +if (type ==READ ) +fsnotify_access (dentry, inode, dentry->d_name.name); +else +fsnotify_modify (dentry, inode, dentry->d_name.name); + }return ret; Efault: ret = -EFAULT ;
fs/super.c +2 -1
@@ -37,9 +37,9 @@#include <linux/writeback.h> /* for the emergency remount stuff */ #include <linux/idr.h> #include <linux/kobject.h> +#include <linux/fsnotify.h> #include <asm/uaccess.h> -void get_filesystem (struct file_system_type *fs);void put_filesystem (struct file_system_type *fs);struct file_system_type *get_fs_type (const char *name);
@@ -229,6 +229,7 @@if (root) { sb->s_root =NULL ; +fsnotify_sb_umount (sb);shrink_dcache_parent (root);shrink_dcache_anon (&sb->s_anon);dput (root);
include/linux/fs.h +6 -1
@@ -26,6 +26,7 @@struct kstatfs ;struct vm_area_struct ;struct vfsmount ; +struct inotify_inode_data ;/* * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
@@ -474,6 +475,10 @@struct dnotify_struct *i_dnotify;/* for directory notifications */ #endif +#ifdef CONFIG_INOTIFY +struct inotify_inode_data *inotify_data; +#endif +unsigned long i_state;unsigned long dirtied_when;/* jiffies of first dirtying */
@@ -1372,7 +1377,7 @@extern int do_remount_sb (struct super_block *sb,int flags,void *data,int force);extern sector_t bmap (struct inode *,sector_t ); -extern int setattr_mask (unsigned int ); +extern void setattr_mask (unsigned int ,int *,u32 *);extern int notify_change (struct dentry *,struct iattr *);extern int permission (struct inode *,int ,struct nameidata *); extern int generic_permission(struct inode *, int,
include/linux/fsnotify.h +235 -0
235 lines not on this page · raw message
include/linux/inotify.h +119 -0
119 lines not on this page · raw message
include/linux/miscdevice.h +1 -0
@@ -2,6 +2,7 @@#define _LINUX_MISCDEVICE_H#include <linux/module.h> #include <linux/major.h> +#include <linux/device.h> #define PSMOUSE_MINOR 1#define MS_BUSMOUSE_MINOR 2
include/linux/sched.h +2 -0
@@ -400,6 +400,8 @@atomic_t processes;/* How many processes does this user have? */ atomic_t files;/* How many open files does this user have? */ atomic_t sigpending;/* How many pending signals does this user have? */ +atomic_t inotify_watches;/* How many inotify watches does this user have? */ +atomic_t inotify_devs;/* How many inotify devs does this user have opened? */ /* protected by mq_lock */ unsigned long mq_bytes;/* How many bytes can be allocated to mqueue? */ unsigned long locked_shm;/* How many pages of mlocked shm ? */
kernel/user.c +2 -0
@@ -120,6 +120,8 @@atomic_set (&new->processes,0 );atomic_set (&new->files,0 );atomic_set (&new->sigpending,0 ); +atomic_set (&new->inotify_watches,0 ); +atomic_set (&new->inotify_devs,0 ); new->mq_bytes =0 ; new->locked_shm =0 ;