Skip to content

Commit 1274162

Browse files
mjguzikbrauner
authored andcommitted
fs: add iput_not_last()
Signed-off-by: Mateusz Guzik <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 3cd1548 commit 1274162

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

fs/inode.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,18 @@ void iput(struct inode *inode)
19671967
}
19681968
EXPORT_SYMBOL(iput);
19691969

1970+
/**
1971+
* iput_not_last - put an inode assuming this is not the last reference
1972+
* @inode: inode to put
1973+
*/
1974+
void iput_not_last(struct inode *inode)
1975+
{
1976+
VFS_BUG_ON_INODE(atomic_read(&inode->i_count) < 2, inode);
1977+
1978+
WARN_ON(atomic_sub_return(1, &inode->i_count) == 0);
1979+
}
1980+
EXPORT_SYMBOL(iput_not_last);
1981+
19701982
#ifdef CONFIG_BLOCK
19711983
/**
19721984
* bmap - find a block number in a file

include/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,7 @@ extern int current_umask(void);
28242824

28252825
extern void ihold(struct inode * inode);
28262826
extern void iput(struct inode *);
2827+
void iput_not_last(struct inode *);
28272828
int inode_update_timestamps(struct inode *inode, int flags);
28282829
int generic_update_time(struct inode *, int);
28292830

0 commit comments

Comments
 (0)