Skip to content

Commit 47f1e50

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]>
1 parent 3849c80 commit 47f1e50

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
@@ -6846,16 +6846,20 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
68466846
struct dentry *parent = dentry->d_parent;
68476847

68486848
ret = btrfs_update_inode(trans, BTRFS_I(inode));
6849-
if (ret)
6849+
if (ret) {
6850+
btrfs_abort_transaction(trans, ret);
68506851
goto fail;
6852+
}
68516853
if (inode->i_nlink == 1) {
68526854
/*
68536855
* If new hard link count is 1, it's a file created
68546856
* with open(2) O_TMPFILE flag.
68556857
*/
68566858
ret = btrfs_orphan_del(trans, BTRFS_I(inode));
6857-
if (ret)
6859+
if (ret) {
6860+
btrfs_abort_transaction(trans, ret);
68586861
goto fail;
6862+
}
68596863
}
68606864
d_instantiate(dentry, inode);
68616865
btrfs_log_new_name(trans, old_dentry, NULL, 0, parent);

0 commit comments

Comments
 (0)