]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fsnotify: pass dentry instead of inode data
authorAmir Goldstein <amir73il@gmail.com>
Mon, 25 Oct 2021 19:27:17 +0000 (16:27 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:18:49 +0000 (16:18 +0200)
[ Upstream commit fd5a3ff49a19aa69e2bc1e26e98037c2d778e61a ]

Define a new data type to pass for event - FSNOTIFY_EVENT_DENTRY.
Use it to pass the dentry instead of it's ->d_inode where available.

This is needed in preparation to the refactor to retrieve the super
block from the data field.  In some cases (i.e. mkdir in kernfs), the
data inode comes from a negative dentry, such that no super block
information would be available. By receiving the dentry itself, instead
of the inode, fsnotify can derive the super block even on these cases.

Link: https://lore.kernel.org/r/20211025192746.66445-3-krisman@collabora.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
[Expand explanation in commit message]
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
include/linux/fsnotify.h
include/linux/fsnotify_backend.h

index 298fd2bc29e4965a9672bed98a3b30e70fdd1243..70e6b147a76ad804ab08c1c056f57e3bb45fc7ea 100644 (file)
@@ -39,8 +39,7 @@ static inline int fsnotify_name(__u32 mask, const void *data, int data_type,
 static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry,
                                   __u32 mask)
 {
-       fsnotify_name(mask, d_inode(dentry), FSNOTIFY_EVENT_INODE,
-                     dir, &dentry->d_name, 0);
+       fsnotify_name(mask, dentry, FSNOTIFY_EVENT_DENTRY, dir, &dentry->d_name, 0);
 }
 
 static inline void fsnotify_inode(struct inode *inode, __u32 mask)
@@ -87,7 +86,7 @@ notify_child:
  */
 static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask)
 {
-       fsnotify_parent(dentry, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE);
+       fsnotify_parent(dentry, mask, dentry, FSNOTIFY_EVENT_DENTRY);
 }
 
 static inline int fsnotify_file(struct file *file, __u32 mask)
index 1ce66748a2d299dbfac1b3438ed7f1ac48f48527..a2db821e8a8f232a2824f2f732ee032621433a1b 100644 (file)
@@ -248,6 +248,7 @@ enum fsnotify_data_type {
        FSNOTIFY_EVENT_NONE,
        FSNOTIFY_EVENT_PATH,
        FSNOTIFY_EVENT_INODE,
+       FSNOTIFY_EVENT_DENTRY,
 };
 
 static inline struct inode *fsnotify_data_inode(const void *data, int data_type)
@@ -255,6 +256,8 @@ static inline struct inode *fsnotify_data_inode(const void *data, int data_type)
        switch (data_type) {
        case FSNOTIFY_EVENT_INODE:
                return (struct inode *)data;
+       case FSNOTIFY_EVENT_DENTRY:
+               return d_inode(data);
        case FSNOTIFY_EVENT_PATH:
                return d_inode(((const struct path *)data)->dentry);
        default:
@@ -262,6 +265,19 @@ static inline struct inode *fsnotify_data_inode(const void *data, int data_type)
        }
 }
 
+static inline struct dentry *fsnotify_data_dentry(const void *data, int data_type)
+{
+       switch (data_type) {
+       case FSNOTIFY_EVENT_DENTRY:
+               /* Non const is needed for dget() */
+               return (struct dentry *)data;
+       case FSNOTIFY_EVENT_PATH:
+               return ((const struct path *)data)->dentry;
+       default:
+               return NULL;
+       }
+}
+
 static inline const struct path *fsnotify_data_path(const void *data,
                                                    int data_type)
 {