Skip to content

Commit 1b58ae0

Browse files
fdmananakdave
authored andcommitted
btrfs: skip transaction commit after failure to create subvolume
At ioctl.c:create_subvol(), when we fail to create a subvolume we always commit the transaction. In most cases this is a no-op, since all the error paths, except for one, abort the transaction - the only exception is when we fail to insert the new root item into the root tree, in that case we don't abort the transaction because we didn't do anything that is irreversible - however we end up committing the transaction which although is not a functional problem, it adds unnecessary rotation of the backup roots in the superblock and unnecessary work. So change that to commit a transaction only when no error happened, otherwise just call btrfs_end_transaction() to release our reference on the transaction. Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 82187d2 commit 1b58ae0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fs/btrfs/ioctl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ static noinline int create_subvol(struct user_namespace *mnt_userns,
544544
struct timespec64 cur_time = current_time(dir);
545545
struct inode *inode;
546546
int ret;
547-
int err;
548547
dev_t anon_dev = 0;
549548
u64 objectid;
550549
u64 index = 0;
@@ -724,9 +723,10 @@ static noinline int create_subvol(struct user_namespace *mnt_userns,
724723
trans->bytes_reserved = 0;
725724
btrfs_subvolume_release_metadata(root, &block_rsv);
726725

727-
err = btrfs_commit_transaction(trans);
728-
if (err && !ret)
729-
ret = err;
726+
if (ret)
727+
btrfs_end_transaction(trans);
728+
else
729+
ret = btrfs_commit_transaction(trans);
730730

731731
if (!ret) {
732732
inode = btrfs_lookup_dentry(dir, dentry);

0 commit comments

Comments
 (0)