]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hostfs: store inode in dentry after mkdir if possible.
authorNeilBrown <neilb@suse.de>
Thu, 27 Feb 2025 01:32:54 +0000 (12:32 +1100)
committerChristian Brauner <brauner@kernel.org>
Thu, 27 Feb 2025 19:00:17 +0000 (20:00 +0100)
After handling a mkdir, get the inode for the name and use
d_splice_alias() to store the correct dentry in the dcache.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neilb@suse.de>
Link: https://lore.kernel.org/r/20250227013949.536172-3-neilb@suse.de
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/hostfs/hostfs_kern.c

index ccbb48fe830dd5da35ca39baaadd3b1a0606a39b..a2c6b9051c5b157474c3225d10f69a74f0b8c481 100644 (file)
@@ -682,14 +682,22 @@ static int hostfs_symlink(struct mnt_idmap *idmap, struct inode *ino,
 static struct dentry *hostfs_mkdir(struct mnt_idmap *idmap, struct inode *ino,
                                   struct dentry *dentry, umode_t mode)
 {
+       struct inode *inode;
        char *file;
        int err;
 
        if ((file = dentry_name(dentry)) == NULL)
                return ERR_PTR(-ENOMEM);
        err = do_mkdir(file, mode);
+       if (err) {
+               dentry = ERR_PTR(err);
+       } else {
+               inode = hostfs_iget(dentry->d_sb, file);
+               d_drop(dentry);
+               dentry = d_splice_alias(inode, dentry);
+       }
        __putname(file);
-       return ERR_PTR(err);
+       return dentry;
 }
 
 static int hostfs_rmdir(struct inode *ino, struct dentry *dentry)