--- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1406,8 +1406,10 @@ int btrfs_defrag_root(struct btrfs_root while (1) { trans = btrfs_start_transaction(root, 0); - if (IS_ERR(trans)) - return PTR_ERR(trans); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + break; + } ret = btrfs_defrag_leaves(trans, root);