Commit 1b58ae0e authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

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: default avatarNikolay Borisov <nborisov@suse.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 82187d2e
...@@ -544,7 +544,6 @@ static noinline int create_subvol(struct user_namespace *mnt_userns, ...@@ -544,7 +544,6 @@ static noinline int create_subvol(struct user_namespace *mnt_userns,
struct timespec64 cur_time = current_time(dir); struct timespec64 cur_time = current_time(dir);
struct inode *inode; struct inode *inode;
int ret; int ret;
int err;
dev_t anon_dev = 0; dev_t anon_dev = 0;
u64 objectid; u64 objectid;
u64 index = 0; u64 index = 0;
...@@ -724,9 +723,10 @@ static noinline int create_subvol(struct user_namespace *mnt_userns, ...@@ -724,9 +723,10 @@ static noinline int create_subvol(struct user_namespace *mnt_userns,
trans->bytes_reserved = 0; trans->bytes_reserved = 0;
btrfs_subvolume_release_metadata(root, &block_rsv); btrfs_subvolume_release_metadata(root, &block_rsv);
err = btrfs_commit_transaction(trans); if (ret)
if (err && !ret) btrfs_end_transaction(trans);
ret = err; else
ret = btrfs_commit_transaction(trans);
if (!ret) { if (!ret) {
inode = btrfs_lookup_dentry(dir, dentry); inode = btrfs_lookup_dentry(dir, dentry);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment