mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 05:04:02 +02:00
fs: add iput_if_not_last() helper
Add a helper that drops an inode reference only if the caller does not hold the last one. Returns true if the reference was dropped, false otherwise. This is useful for filesystems that need to release inode references in contexts where triggering final iput (and thus eviction) would be unsafe due to lock ordering constraints. The caller can check the return value and defer the final iput to a safe context. Unlike iput_not_last() which BUG_ON's if called with the last ref, this variant is designed to be called speculatively. Signed-off-by: Yun Zhou <yun.zhou@windriver.com> Suggested-by: Jan Kara <jack@suse.cz> Suggested-by: Mateusz Guzik <mjguzik@gmail.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Christian Brauner (Amutable) <brauner@kernel.org> Tested-by: syzbot@syzkaller.appspotmail.com Link: https://patch.msgid.link/20260710030851.2791589-2-yun.zhou@windriver.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
parent
3a00c9bc8e
commit
2a4c637d6f
|
|
@ -2413,6 +2413,21 @@ static inline void super_set_sysfs_name_generic(struct super_block *sb, const ch
|
|||
extern void ihold(struct inode * inode);
|
||||
extern void iput(struct inode *);
|
||||
void iput_not_last(struct inode *);
|
||||
|
||||
/**
|
||||
* iput_if_not_last - drop an inode reference only if it is not the last one
|
||||
* @inode: inode to put
|
||||
*
|
||||
* Returns true if the reference was dropped, false if this was the last
|
||||
* reference and the caller must arrange for final iput() in a safe context.
|
||||
*/
|
||||
static inline bool __must_check iput_if_not_last(struct inode *inode)
|
||||
{
|
||||
VFS_BUG_ON_INODE(inode_state_read_once(inode) & (I_FREEING | I_CLEAR), inode);
|
||||
VFS_BUG_ON_INODE(icount_read_once(inode) < 1, inode);
|
||||
return atomic_add_unless(&inode->i_count, -1, 1);
|
||||
}
|
||||
|
||||
int inode_update_time(struct inode *inode, enum fs_update_time type,
|
||||
unsigned int flags);
|
||||
int generic_update_time(struct inode *inode, enum fs_update_time type,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user