Skip to content

Commit

Permalink
btrfs: don't start transaction when joining with TRANS_JOIN_NOSTART
Browse files Browse the repository at this point in the history
commit 4490e80 upstream.

When joining a transaction with TRANS_JOIN_NOSTART, if we don't find a
running transaction we end up creating one. This goes against the purpose
of TRANS_JOIN_NOSTART which is to join a running transaction if its state
is at or below the state TRANS_STATE_COMMIT_START, otherwise return an
-ENOENT error and don't start a new transaction. So fix this to not create
a new transaction if there's no running transaction at or below that
state.

CC: stable@vger.kernel.org # 4.14+
Fixes: a6d155d ("Btrfs: fix deadlock between fiemap and transaction commits")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
fdmanana authored and gregkh committed Sep 19, 2023
1 parent b5cd2c8 commit 70fa3d4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions fs/btrfs/transaction.c
Expand Up @@ -292,10 +292,11 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
spin_unlock(&fs_info->trans_lock);

/*
* If we are ATTACH, we just want to catch the current transaction,
* and commit it. If there is no transaction, just return ENOENT.
* If we are ATTACH or TRANS_JOIN_NOSTART, we just want to catch the
* current transaction, and commit it. If there is no transaction, just
* return ENOENT.
*/
if (type == TRANS_ATTACH)
if (type == TRANS_ATTACH || type == TRANS_JOIN_NOSTART)
return -ENOENT;

/*
Expand Down

0 comments on commit 70fa3d4

Please sign in to comment.