From: Robert Love <rml@novell.com>

- Replace open-coded hook in sysfs with fsnotify
- Replace open-coded hooks in nfsd with fsnotify
- Misc. cleanup

Signed-Off-By: Robert Love <rml@novell.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 fs/inotify.c             |   21 ++++++++++++---------
 fs/nfsd/vfs.c            |    6 +++---
 fs/sysfs/file.c          |    7 ++-----
 include/linux/fsnotify.h |    4 ++--
 4 files changed, 19 insertions(+), 19 deletions(-)

diff -puN fs/inotify.c~inotify-44-update-2 fs/inotify.c
--- 25/fs/inotify.c~inotify-44-update-2	Mon May 16 14:55:57 2005
+++ 25-akpm/fs/inotify.c	Mon May 16 14:55:57 2005
@@ -50,7 +50,7 @@ static unsigned int max_queued_events;
  * Lock ordering:
  *
  * dentry->d_lock (used to keep d_move() away from dentry->d_parent)
- * iprune_sem (synchronize versus shrink_icache_memory())
+ * iprune_sem (synchronize shrink_icache_memory())
  * 	inode_lock (protects the super_block->s_inodes list)
  * 	inode->inotify_sem (protects inode->inotify_watches and watches->i_list)
  * 		inotify_dev->sem (protects inotify_device and watches->d_list)
@@ -251,16 +251,16 @@ static struct inotify_kernel_event * ker
 			if (len % event_size == 0)
 				rem = 0;
 		}
-		len += rem;
 
-		kevent->name = kmalloc(len, GFP_KERNEL);
+		kevent->name = kmalloc(len + rem, GFP_KERNEL);
 		if (unlikely(!kevent->name)) {
 			kmem_cache_free(event_cachep, kevent);
 			return NULL;
 		}
-		memset(kevent->name, 0, len);
-		strncpy(kevent->name, name, strlen(name));
-		kevent->event.len = len;
+		memcpy(kevent->name, name, len);
+		if (rem)
+			memset(kevent->name + len, 0, rem);
+		kevent->event.len = len + rem;
 	} else {
 		kevent->event.len = 0;
 		kevent->name = NULL;
@@ -293,9 +293,8 @@ static void inotify_dev_queue_event(stru
 
 	/* coalescing: drop this event if it is a dupe of the previous */
 	last = inotify_dev_get_event(dev);
-	if (dev->event_count && last->event.mask == mask &&
-			last->event.cookie == cookie &&
-			last->event.wd == watch->wd) {
+	if (last && last->event.mask == mask && last->event.wd == watch->wd &&
+			last->event.cookie == cookie) {
 		const char *lastname = last->name;
 
 		if (!name && !lastname)
@@ -574,6 +573,9 @@ void inotify_unmount_inodes(struct list_
 		struct inotify_watch *watch, *next_w;
 		struct list_head *watches;
 
+		/* In case the remove_watch() drops a reference */
+		__iget(inode);
+
 		/*
 		 * We can safely drop inode_lock here because the per-sb list
 		 * of inodes must not change during unmount and iprune_sem
@@ -592,6 +594,7 @@ void inotify_unmount_inodes(struct list_
 			up(&dev->sem);
 		}
 		up(&inode->inotify_sem);
+		iput(inode);
 
 		spin_lock(&inode_lock);
 	}
diff -puN fs/nfsd/vfs.c~inotify-44-update-2 fs/nfsd/vfs.c
--- 25/fs/nfsd/vfs.c~inotify-44-update-2	Mon May 16 14:55:57 2005
+++ 25-akpm/fs/nfsd/vfs.c	Mon May 16 14:55:57 2005
@@ -45,7 +45,7 @@
 #endif /* CONFIG_NFSD_V3 */
 #include <linux/nfsd/nfsfh.h>
 #include <linux/quotaops.h>
-#include <linux/dnotify.h>
+#include <linux/fsnotify.h>
 #include <linux/xattr_acl.h>
 #include <linux/posix_acl.h>
 #ifdef CONFIG_NFSD_V4
@@ -862,7 +862,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
 		nfsdstats.io_read += err;
 		*count = err;
 		err = 0;
-		dnotify_parent(file->f_dentry, DN_ACCESS);
+		fsnotify_access(file->f_dentry);
 	} else 
 		err = nfserrno(err);
 out:
@@ -918,7 +918,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
 	set_fs(oldfs);
 	if (err >= 0) {
 		nfsdstats.io_write += cnt;
-		dnotify_parent(file->f_dentry, DN_MODIFY);
+		fsnotify_modify(file->f_dentry);
 	}
 
 	/* clear setuid/setgid flag after write */
diff -puN fs/sysfs/file.c~inotify-44-update-2 fs/sysfs/file.c
--- 25/fs/sysfs/file.c~inotify-44-update-2	Mon May 16 14:55:57 2005
+++ 25-akpm/fs/sysfs/file.c	Mon May 16 14:55:57 2005
@@ -3,7 +3,7 @@
  */
 
 #include <linux/module.h>
-#include <linux/dnotify.h>
+#include <linux/fsnotify.h>
 #include <linux/kobject.h>
 #include <linux/namei.h>
 #include <asm/uaccess.h>
@@ -390,9 +390,6 @@ int sysfs_create_file(struct kobject * k
  * sysfs_update_file - update the modified timestamp on an object attribute.
  * @kobj: object we're acting for.
  * @attr: attribute descriptor.
- *
- * Also call dnotify for the dentry, which lots of userspace programs
- * use.
  */
 int sysfs_update_file(struct kobject * kobj, const struct attribute * attr)
 {
@@ -407,7 +404,7 @@ int sysfs_update_file(struct kobject * k
 		if (victim->d_inode && 
 		    (victim->d_parent->d_inode == dir->d_inode)) {
 			victim->d_inode->i_mtime = CURRENT_TIME;
-			dnotify_parent(victim, DN_MODIFY);
+			fsnotify_modify(victim);
 
 			/**
 			 * Drop reference from initial sysfs_get_dentry().
diff -puN include/linux/fsnotify.h~inotify-44-update-2 include/linux/fsnotify.h
--- 25/include/linux/fsnotify.h~inotify-44-update-2	Mon May 16 14:55:57 2005
+++ 25-akpm/include/linux/fsnotify.h	Mon May 16 14:55:57 2005
@@ -219,7 +219,7 @@ static inline void fsnotify_change(struc
  *
  * XXX: This could be kstrdup if only we could add that to lib/string.c
  */
-static inline char *fsnotify_oldname_init(const char *name)
+static inline const char *fsnotify_oldname_init(const char *name)
 {
 	size_t len;
 	char *buf;
@@ -241,7 +241,7 @@ static inline void fsnotify_oldname_free
 
 #else	/* CONFIG_INOTIFY */
 
-static inline char *fsnotify_oldname_init(const char *name)
+static inline const char *fsnotify_oldname_init(const char *name)
 {
 	return NULL;
 }
_