diff options
author | 2025-07-25 16:51:49 +0100 | |
---|---|---|
committer | 2025-08-22 00:58:25 +0200 | |
commit | 2b3979624c3e34dcdd77d910c6490939727d91b2 (patch) | |
tree | 62c0073c85512aeedbf23457733a043c3b2e4820 | |
parent | btrfs: fix printing of mount info messages for NODATACOW/NODATASUM (diff) | |
download | wireguard-linux-2b3979624c3e34dcdd77d910c6490939727d91b2.tar.xz wireguard-linux-2b3979624c3e34dcdd77d910c6490939727d91b2.zip |
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 <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | fs/btrfs/inode.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9e4aec7330cb..af2f9b2c8c85 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -6852,16 +6852,20 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *parent = dentry->d_parent; ret = btrfs_update_inode(trans, BTRFS_I(inode)); - if (ret) + if (ret) { + btrfs_abort_transaction(trans, ret); goto fail; + } if (inode->i_nlink == 1) { /* * If new hard link count is 1, it's a file created * with open(2) O_TMPFILE flag. */ ret = btrfs_orphan_del(trans, BTRFS_I(inode)); - if (ret) + if (ret) { + btrfs_abort_transaction(trans, ret); goto fail; + } } d_instantiate(dentry, inode); btrfs_log_new_name(trans, old_dentry, NULL, 0, parent); |