Skip to content

Commit 2b39796

Browse files
fdmananakdave
authored andcommitted
btrfs: abort transaction on failure to add link to inode
If we fail to update the inode or delete the orphan item, we must abort the transaction to prevent persisting an inconsistent state. For example if we fail to update the inode item, we have the inconsistency of having a persisted inode item with a link count of N but we have N + 1 inode ref items and N + 1 directory entries pointing to our inode in case the transaction gets committed. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 74857fd commit 2b39796

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

fs/btrfs/inode.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6852,16 +6852,20 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
68526852
struct dentry *parent = dentry->d_parent;
68536853

68546854
ret = btrfs_update_inode(trans, BTRFS_I(inode));
6855-
if (ret)
6855+
if (ret) {
6856+
btrfs_abort_transaction(trans, ret);
68566857
goto fail;
6858+
}
68576859
if (inode->i_nlink == 1) {
68586860
/*
68596861
* If new hard link count is 1, it's a file created
68606862
* with open(2) O_TMPFILE flag.
68616863
*/
68626864
ret = btrfs_orphan_del(trans, BTRFS_I(inode));
6863-
if (ret)
6865+
if (ret) {
6866+
btrfs_abort_transaction(trans, ret);
68646867
goto fail;
6868+
}
68656869
}
68666870
d_instantiate(dentry, inode);
68676871
btrfs_log_new_name(trans, old_dentry, NULL, 0, parent);

0 commit comments

Comments
 (0)