Re: [PATCH v7 03/14] fs: provide accessors for ->i_state
From: Jan Kara
Date: Fri Oct 10 2025 - 10:45:41 EST
On Thu 09-10-25 09:59:17, Mateusz Guzik wrote:
> +static inline void inode_state_set_raw(struct inode *inode,
> + enum inode_state_flags_enum flags)
> +{
> + WRITE_ONCE(inode->i_state, inode->i_state | flags);
> +}
I think this shouldn't really exist as it is dangerous to use and if we
deal with XFS, nobody will actually need this function.
> +static inline void inode_state_set(struct inode *inode,
> + enum inode_state_flags_enum flags)
> +{
> + lockdep_assert_held(&inode->i_lock);
> + inode_state_set_raw(inode, flags);
> +}
> +
> +static inline void inode_state_clear_raw(struct inode *inode,
> + enum inode_state_flags_enum flags)
> +{
> + WRITE_ONCE(inode->i_state, inode->i_state & ~flags);
> +}
Ditto here.
> +static inline void inode_state_clear(struct inode *inode,
> + enum inode_state_flags_enum flags)
> +{
> + lockdep_assert_held(&inode->i_lock);
> + inode_state_clear_raw(inode, flags);
> +}
> +
> +static inline void inode_state_assign_raw(struct inode *inode,
> + enum inode_state_flags_enum flags)
> +{
> + WRITE_ONCE(inode->i_state, flags);
> +}
> +
> +static inline void inode_state_assign(struct inode *inode,
> + enum inode_state_flags_enum flags)
> +{
> + lockdep_assert_held(&inode->i_lock);
> + inode_state_assign_raw(inode, flags);
> +}
> +
> +static inline void inode_state_replace_raw(struct inode *inode,
> + enum inode_state_flags_enum clearflags,
> + enum inode_state_flags_enum setflags)
> +{
> + enum inode_state_flags_enum flags;
> + flags = inode->i_state;
> + flags &= ~clearflags;
> + flags |= setflags;
> + inode_state_assign_raw(inode, flags);
> +}
Nobody needs this so I'd just provide inode_state_replace().
> +static inline void inode_state_replace(struct inode *inode,
> + enum inode_state_flags_enum clearflags,
> + enum inode_state_flags_enum setflags)
> +{
> + lockdep_assert_held(&inode->i_lock);
> + inode_state_replace_raw(inode, clearflags, setflags);
> +}
> +
> static inline void inode_set_cached_link(struct inode *inode, char *link, int linklen)
> {
> VFS_WARN_ON_INODE(strlen(link) != linklen, inode);
Honza
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR