btrfs: tracepoints: pass a transaction handle to transaction commit event

The transaction commit tracepoint prints fs_info->generation as if it
were the ID of the committed transaction but this does not always match
that ID. This is because the trace point is called in the transaction
commit path after the transaction is in the TRANS_STATE_COMPLETED state,
which means another transaction may have already started (which can happen
as soon as the transaction state was set to TRANS_STATE_UNBLOCKED), in
which case fs_info->generation was incremented and does not correspond
to the committed transaction anymore.

So fix this by passing a transaction handle to the trace event instead of
fs_info. This will also allow later for the trace event to dump other
useful information about the transaction.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Filipe Manana 2026-04-17 17:43:19 +01:00 committed by David Sterba
parent d5ccc38b75
commit e1ad307c7a
2 changed files with 7 additions and 6 deletions

View File

@ -2114,7 +2114,7 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans, int err)
btrfs_put_transaction(cur_trans);
btrfs_put_transaction(cur_trans);
trace_btrfs_transaction_commit(fs_info);
trace_btrfs_transaction_commit(trans);
if (current->journal_info == trans)
current->journal_info = NULL;
@ -2632,7 +2632,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
if (trans->type & __TRANS_FREEZABLE)
sb_end_intwrite(fs_info->sb);
trace_btrfs_transaction_commit(fs_info);
trace_btrfs_transaction_commit(trans);
btrfs_scrub_continue(fs_info);

View File

@ -31,6 +31,7 @@ struct btrfs_space_info;
struct btrfs_raid_bio;
struct raid56_bio_trace_info;
struct find_free_extent_ctl;
struct btrfs_trans_handle;
#define show_ref_type(type) \
__print_symbolic(type, \
@ -182,16 +183,16 @@ FLUSH_STATES
TRACE_EVENT(btrfs_transaction_commit,
TP_PROTO(const struct btrfs_fs_info *fs_info),
TP_PROTO(const struct btrfs_trans_handle *trans),
TP_ARGS(fs_info),
TP_ARGS(trans),
TP_STRUCT__entry_btrfs(
__field( u64, generation )
),
TP_fast_assign_btrfs(fs_info,
__entry->generation = fs_info->generation;
TP_fast_assign_btrfs(trans->fs_info,
__entry->generation = trans->transid;
),
TP_printk_btrfs("gen=%llu", __entry->generation)