]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs: relocate and tidy up ihold()
authorMateusz Guzik <mjguzik@gmail.com>
Tue, 21 Apr 2026 18:25:37 +0000 (20:25 +0200)
committerChristian Brauner <brauner@kernel.org>
Mon, 11 May 2026 21:12:29 +0000 (23:12 +0200)
The placement was illogical, move it next to igrab().

Take this opportunity to add docs and an assert on the refcount. While
its modification remains gated with a WARN_ON, the new assert will also
dump the inode state which might aid debugging.

No functional changes.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Link: https://patch.msgid.link/20260421182538.1215894-3-mjguzik@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/inode.c

index 3338ef2710999936f0c05c3d4dda8be1fda9baca..ab9573355f3b8858ac94bd9482f6bc2711fa4c12 100644 (file)
@@ -518,15 +518,6 @@ static void init_once(void *foo)
        inode_init_once(inode);
 }
 
-/*
- * get additional reference to inode; caller must already hold one.
- */
-void ihold(struct inode *inode)
-{
-       WARN_ON(atomic_inc_return(&inode->i_count) < 2);
-}
-EXPORT_SYMBOL(ihold);
-
 struct wait_queue_head *inode_bit_waitqueue(struct wait_bit_queue_entry *wqe,
                                            struct inode *inode, u32 bit)
 {
@@ -1572,6 +1563,17 @@ ino_t iunique(struct super_block *sb, ino_t max_reserved)
 }
 EXPORT_SYMBOL(iunique);
 
+/**
+ * ihold - get a reference on the inode, provided you already have one
+ * @inode:     inode to operate on
+ */
+void ihold(struct inode *inode)
+{
+       VFS_BUG_ON_INODE(icount_read_once(inode) < 1, inode);
+       WARN_ON(atomic_inc_return(&inode->i_count) < 2);
+}
+EXPORT_SYMBOL(ihold);
+
 struct inode *igrab(struct inode *inode)
 {
        spin_lock(&inode->i_lock);