btrfs: tracepoints: add trace event for add_conflicting_inode()

add_conflicting_inode() is an important step called during a fsync, as
well as during rename and link operations on inodes that were previously
logged. Add trace events for when entering and exiting that function.

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-05-07 11:17:55 +01:00
parent bb10bfba75
commit aa0487b003
2 changed files with 93 additions and 15 deletions

View File

@@ -6121,6 +6121,9 @@ static int add_conflicting_inode(struct btrfs_trans_handle *trans,
{
struct btrfs_ino_list *ino_elem;
struct btrfs_inode *inode;
int ret = 0;
trace_btrfs_add_conflicting_inode_enter(trans, ctx, ino, parent);
/*
* It's rare to have a lot of conflicting inodes, in practice it is not
@@ -6129,8 +6132,10 @@ static int add_conflicting_inode(struct btrfs_trans_handle *trans,
* LOG_INODE_EXISTS mode) and slow down other fsyncs or transaction
* commits.
*/
if (ctx->num_conflict_inodes >= MAX_CONFLICT_INODES)
return BTRFS_LOG_FORCE_COMMIT;
if (ctx->num_conflict_inodes >= MAX_CONFLICT_INODES) {
ret = BTRFS_LOG_FORCE_COMMIT;
goto out;
}
inode = btrfs_iget_logging(ino, root);
/*
@@ -6154,26 +6159,27 @@ static int add_conflicting_inode(struct btrfs_trans_handle *trans,
* some inode from it to some other directory).
*/
if (IS_ERR(inode)) {
int ret = PTR_ERR(inode);
ret = PTR_ERR(inode);
if (ret != -ENOENT)
return ret;
goto out;
ret = conflicting_inode_is_dir(root, ino, path);
/* Not a directory or we got an error. */
if (ret <= 0)
return ret;
goto out;
/* Conflicting inode is a directory, so we'll log its parent. */
ino_elem = kmalloc_obj(*ino_elem, GFP_NOFS);
if (!ino_elem)
return -ENOMEM;
if (!ino_elem) {
ret = -ENOMEM;
goto out;
}
ino_elem->ino = ino;
ino_elem->parent = parent;
list_add_tail(&ino_elem->list, &ctx->conflict_inodes);
ctx->num_conflict_inodes++;
return 0;
ret = 0;
goto out;
}
/*
@@ -6213,25 +6219,31 @@ static int add_conflicting_inode(struct btrfs_trans_handle *trans,
*/
if (!need_log_inode(trans, inode)) {
btrfs_add_delayed_iput(inode);
return 0;
goto out;
}
if (!can_log_conflicting_inode(trans, inode)) {
btrfs_add_delayed_iput(inode);
return BTRFS_LOG_FORCE_COMMIT;
ret = BTRFS_LOG_FORCE_COMMIT;
goto out;
}
btrfs_add_delayed_iput(inode);
ino_elem = kmalloc_obj(*ino_elem, GFP_NOFS);
if (!ino_elem)
return -ENOMEM;
if (!ino_elem) {
ret = -ENOMEM;
goto out;
}
ino_elem->ino = ino;
ino_elem->parent = parent;
list_add_tail(&ino_elem->list, &ctx->conflict_inodes);
ctx->num_conflict_inodes++;
return 0;
out:
trace_btrfs_add_conflicting_inode_exit(trans, ctx, ino, parent, ret);
return ret;
}
static int log_conflicting_inodes(struct btrfs_trans_handle *trans,

View File

@@ -1228,6 +1228,72 @@ TRACE_EVENT(btrfs_log_new_dir_dentries_exit,
__entry->transid, __entry->ret)
);
TRACE_EVENT(btrfs_add_conflicting_inode_enter,
TP_PROTO(const struct btrfs_trans_handle *trans,
const struct btrfs_log_ctx *ctx,
u64 ino, u64 parent),
TP_ARGS(trans, ctx, ino, parent),
TP_STRUCT__entry_btrfs(
__field( u64, root_objectid )
__field( u64, transid )
__field( u64, ctx_ino )
__field( u64, conflict_ino )
__field( u64, conflict_ino_parent )
),
TP_fast_assign(
TP_fast_assign_fsid(trans->fs_info);
__entry->root_objectid = btrfs_root_id(ctx->inode->root);
__entry->transid = trans->transid;
__entry->ctx_ino = btrfs_ino(ctx->inode);
__entry->conflict_ino = ino;
__entry->conflict_ino_parent = parent;
),
TP_printk_btrfs("root=%llu(%s) transid=%llu ctx_ino=%llu conflict_ino=%llu"
" conflict_ino_parent=%llu",
show_root_type(__entry->root_objectid), __entry->transid,
__entry->ctx_ino, __entry->conflict_ino,
__entry->conflict_ino_parent)
);
TRACE_EVENT(btrfs_add_conflicting_inode_exit,
TP_PROTO(const struct btrfs_trans_handle *trans,
const struct btrfs_log_ctx *ctx,
u64 ino, u64 parent, int ret),
TP_ARGS(trans, ctx, ino, parent, ret),
TP_STRUCT__entry_btrfs(
__field( u64, root_objectid )
__field( u64, transid )
__field( u64, ctx_ino )
__field( u64, conflict_ino )
__field( u64, conflict_ino_parent )
__field( int, ret )
),
TP_fast_assign(
TP_fast_assign_fsid(trans->fs_info);
__entry->root_objectid = btrfs_root_id(ctx->inode->root);
__entry->transid = trans->transid;
__entry->ctx_ino = btrfs_ino(ctx->inode);
__entry->conflict_ino = ino;
__entry->conflict_ino_parent = parent;
__entry->ret = ret;
),
TP_printk_btrfs("root=%llu(%s) transid=%llu ctx_ino=%llu conflict_ino=%llu"
" conflict_ino_parent=%llu ret=%d",
show_root_type(__entry->root_objectid), __entry->transid,
__entry->ctx_ino, __entry->conflict_ino,
__entry->conflict_ino_parent, __entry->ret)
);
TRACE_EVENT(btrfs_sync_fs,
TP_PROTO(const struct btrfs_fs_info *fs_info, int wait),