fsnotify: get rid of fsnotify_nameremove() [Linux 5.3]

This Linux kernel change "fsnotify: get rid of fsnotify_nameremove()" is included in the Linux 5.3 release. This change is authored by Amir Goldstein <amir73il [at] gmail.com> on Sun May 26 17:34:11 2019 +0300. The commit for this change in Linux stable tree is 7377f5b (patch).

fsnotify: get rid of fsnotify_nameremove()

For all callers of fsnotify_{unlink,rmdir}(), we made sure that d_parent
and d_name are stable.  Therefore, fsnotify_{unlink,rmdir}() do not need
the safety measures in fsnotify_nameremove() to stabilize parent and name.
We can now simplify those hooks and get rid of fsnotify_nameremove().

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>

There are 51 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/notify/fsnotify.c             | 41 ----------------------------------------
 include/linux/fsnotify.h         |  6 ++----
 include/linux/fsnotify_backend.h |  4 ----
 3 files changed, 2 insertions(+), 49 deletions(-)

diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 4eb2ebf..2ecef61 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -95,47 +95,6 @@ void fsnotify_sb_delete(struct super_block *sb)
 }

 /*
- * fsnotify_nameremove - a filename was removed from a directory
- *
- * This is mostly called under parent vfs inode lock so name and
- * dentry->d_parent should be stable. However there are some corner cases where
- * inode lock is not held. So to be on the safe side and be reselient to future
- * callers and out of tree users of d_delete(), we do not assume that d_parent
- * and d_name are stable and we use dget_parent() and
- * take_dentry_name_snapshot() to grab stable references.
- */
-void fsnotify_nameremove(struct dentry *dentry, int isdir)
-{
-   struct dentry *parent;
-   struct name_snapshot name;
-   __u32 mask = FS_DELETE;
-
-   /* d_delete() of pseudo inode? (e.g. __ns_get_path() playing tricks) */
-   if (IS_ROOT(dentry))
-       return;
-
-   if (isdir)
-       mask |= FS_ISDIR;
-
-   parent = dget_parent(dentry);
-   /* Avoid unneeded take_dentry_name_snapshot() */
-   if (!(d_inode(parent)->i_fsnotify_mask & FS_DELETE) &&
-       !(dentry->d_sb->s_fsnotify_mask & FS_DELETE))
-       goto out_dput;
-
-   take_dentry_name_snapshot(&name, dentry);
-
-   fsnotify(d_inode(parent), mask, d_inode(dentry), FSNOTIFY_EVENT_INODE,
-        &name.name, 0);
-
-   release_dentry_name_snapshot(&name);
-
-out_dput:
-   dput(parent);
-}
-EXPORT_SYMBOL(fsnotify_nameremove);
-
-/*
  * Given an inode, first check if we care what happens to our children.  Inotify
  * and dnotify both tell their parents about events.  If we care about any event
  * on a child we run all of our children and set a dentry flag saying that the
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index 0145073..a2d5d17 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -198,8 +198,7 @@ static inline void fsnotify_unlink(struct inode *dir, struct dentry *dentry)
    /* Expected to be called before d_delete() */
    WARN_ON_ONCE(d_is_negative(dentry));

-   /* TODO: call fsnotify_dirent() */
-   fsnotify_nameremove(dentry, 0);
+   fsnotify_dirent(dir, dentry, FS_DELETE);
 }

 /*
@@ -222,8 +221,7 @@ static inline void fsnotify_rmdir(struct inode *dir, struct dentry *dentry)
    /* Expected to be called before d_delete() */
    WARN_ON_ONCE(d_is_negative(dentry));

-   /* TODO: call fsnotify_dirent() */
-   fsnotify_nameremove(dentry, 1);
+   fsnotify_dirent(dir, dentry, FS_DELETE | FS_ISDIR);
 }

 /*
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index a9f9dcc..c28f6ed 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -355,7 +355,6 @@ extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int dat
 extern void __fsnotify_inode_delete(struct inode *inode);
 extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
 extern void fsnotify_sb_delete(struct super_block *sb);
-extern void fsnotify_nameremove(struct dentry *dentry, int isdir);
 extern u32 fsnotify_get_cookie(void);

 static inline int fsnotify_inode_watches_children(struct inode *inode)
@@ -525,9 +524,6 @@ static inline void __fsnotify_vfsmount_delete(struct vfsmount *mnt)
 static inline void fsnotify_sb_delete(struct super_block *sb)
 {}

-static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
-{}
-
 static inline void fsnotify_update_flags(struct dentry *dentry)
 {}

Leave a Reply

Your email address will not be published. Required fields are marked *