Re: [PATCH v5 2/4] fs: relocate and tidy up ihold()
From: Jan Kara
Date: Wed Apr 01 2026 - 13:34:39 EST
On Tue 31-03-26 18:08:49, Mateusz Guzik wrote:
> 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@xxxxxxxxx>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@xxxxxxx>
Honza
> ---
> fs/inode.c | 20 +++++++++++---------
> 1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/fs/inode.c b/fs/inode.c
> index 1f5a383ccf27..e397a4b56671 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -522,15 +522,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)
> {
> @@ -1578,6 +1569,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);
> --
> 2.48.1
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR