fs: factor out d_mark_tmpfile()
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 10 Jul 2018 03:27:33 +0000 (23:27 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Tue, 12 Sep 2023 03:59:47 +0000 (23:59 -0400)
New helper for bcachefs - bcachefs doesn't want the
inode_dec_link_count() call that d_tmpfile does, it handles i_nlink on
its own atomically with other btree updates

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christian Brauner <brauner@kernel.org>
fs/dcache.c
include/linux/dcache.h

index 25ac74d30bff3b39e6763c4717cee2b403d80139..796e23761ba0505748faf160011f49736ac26522 100644 (file)
@@ -3246,11 +3246,10 @@ void d_genocide(struct dentry *parent)
        d_walk(parent, parent, d_genocide_kill);
 }
 
-void d_tmpfile(struct file *file, struct inode *inode)
+void d_mark_tmpfile(struct file *file, struct inode *inode)
 {
        struct dentry *dentry = file->f_path.dentry;
 
-       inode_dec_link_count(inode);
        BUG_ON(dentry->d_name.name != dentry->d_iname ||
                !hlist_unhashed(&dentry->d_u.d_alias) ||
                !d_unlinked(dentry));
@@ -3260,6 +3259,15 @@ void d_tmpfile(struct file *file, struct inode *inode)
                                (unsigned long long)inode->i_ino);
        spin_unlock(&dentry->d_lock);
        spin_unlock(&dentry->d_parent->d_lock);
+}
+EXPORT_SYMBOL(d_mark_tmpfile);
+
+void d_tmpfile(struct file *file, struct inode *inode)
+{
+       struct dentry *dentry = file->f_path.dentry;
+
+       inode_dec_link_count(inode);
+       d_mark_tmpfile(file, inode);
        d_instantiate(dentry, inode);
 }
 EXPORT_SYMBOL(d_tmpfile);
index 6b351e009f5976db447e8da82e579713d02f20b5..3da2f0545d5d773c032388e80750c700d09b28f2 100644 (file)
@@ -251,6 +251,7 @@ extern struct dentry * d_make_root(struct inode *);
 /* <clickety>-<click> the ramfs-type tree */
 extern void d_genocide(struct dentry *);
 
+extern void d_mark_tmpfile(struct file *, struct inode *);
 extern void d_tmpfile(struct file *, struct inode *);
 
 extern struct dentry *d_find_alias(struct inode *);