]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: tracepoints: add trace event for btrfs_log_inode()
authorFilipe Manana <fdmanana@suse.com>
Thu, 30 Apr 2026 15:05:56 +0000 (16:05 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 8 Jun 2026 13:53:34 +0000 (15:53 +0200)
btrfs_log_inode() is one of the most important steps 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>
fs/btrfs/super.c
fs/btrfs/tree-log.c
include/trace/events/btrfs.h

index fb15decb0861895b78068716ec023bc942ab735c..9de67276a8edd67f25a1c067f52eae246e44eebe 100644 (file)
@@ -60,6 +60,7 @@
 #include "verity.h"
 #include "super.h"
 #include "extent-tree.h"
+#include "tree-log.h"
 #define CREATE_TRACE_POINTS
 #include <trace/events/btrfs.h>
 
index 70795cd76d6f375b7dbb7df1920a6a491e8e947e..22066635f75f3863b463d69bacda4b4f20f89ad1 100644 (file)
@@ -6884,7 +6884,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
                           struct btrfs_log_ctx *ctx)
 {
        struct btrfs_path *path;
-       struct btrfs_path *dst_path;
+       struct btrfs_path *dst_path = NULL;
        struct btrfs_key min_key;
        struct btrfs_key max_key;
        struct btrfs_root *log = inode->root->log_root;
@@ -6900,13 +6900,17 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
        LIST_HEAD(delayed_ins_list);
        LIST_HEAD(delayed_del_list);
 
+       trace_btrfs_log_inode_enter(trans, inode, ctx, log_mode);
+
        path = btrfs_alloc_path();
-       if (!path)
-               return -ENOMEM;
+       if (!path) {
+               ret = -ENOMEM;
+               goto out;
+       }
        dst_path = btrfs_alloc_path();
        if (!dst_path) {
-               btrfs_free_path(path);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto out;
        }
 
        min_key.objectid = ino;
@@ -7221,6 +7225,8 @@ out:
                                            &delayed_del_list);
        }
 
+       trace_btrfs_log_inode_exit(trans, inode, ret);
+
        return ret;
 }
 
index cd127c79a535268eec4cd15217c2397f6b3785df..9f195d0d5378a5a382e106ddb24a8c853e625e0b 100644 (file)
@@ -33,6 +33,7 @@ struct raid56_bio_trace_info;
 struct find_free_extent_ctl;
 struct btrfs_trans_handle;
 struct btrfs_transaction;
+struct btrfs_log_ctx;
 
 #define show_inode_type(mode)                                  \
        __print_symbolic((mode) & S_IFMT,                       \
@@ -124,6 +125,9 @@ struct btrfs_transaction;
        EM( TRANS_STATE_SUPER_COMMITTED,        "TRANS_STATE_SUPER_COMMITTED")  \
        EMe(TRANS_STATE_COMPLETED,              "TRANS_STATE_COMPLETED")
 
+#define LOG_MODES                                                      \
+       EM( LOG_INODE_ALL,              "LOG_INODE_ALL")                \
+       EMe(LOG_INODE_EXISTS,           "LOG_INODE_EXISTS")
 /*
  * First define the enums in the above macros to be exported to userspace via
  * TRACE_DEFINE_ENUM().
@@ -140,6 +144,7 @@ QGROUP_RSV_TYPES
 IO_TREE_OWNER
 FLUSH_STATES
 TRANSACTION_STATES
+LOG_MODES
 
 /*
  * Now redefine the EM and EMe macros to map the enums to the strings that will
@@ -951,6 +956,117 @@ TRACE_EVENT(btrfs_log_inode_parent_exit,
                        __entry->transid, __entry->ret)
 );
 
+TRACE_EVENT(btrfs_log_inode_enter,
+
+       TP_PROTO(const struct btrfs_trans_handle *trans, struct btrfs_inode *inode,
+                const struct btrfs_log_ctx *ctx, int log_mode),
+
+       TP_ARGS(trans, inode, ctx, log_mode),
+
+       TP_STRUCT__entry_btrfs(
+               __field(        u64,                    root_objectid                   )
+               __field(        u64,                    ino                             )
+               __field(        umode_t,                mode                            )
+               __field(        u64,                    transid                         )
+               __field(        u64,                    generation                      )
+               __field(        u64,                    logged_trans                    )
+               __field(        u64,                    last_unlink_trans               )
+               __field(        u64,                    last_reflink_trans              )
+               __field(        int,                    last_sub_trans                  )
+               __field(        int,                    last_log_commit                 )
+               __field(        bool,                   logging_new_name                )
+               __field(        bool,                   logging_new_delayed_dentries    )
+               __field(        bool,                   is_conflict_inode               )
+               __field(        bool,                   full_sync                       )
+               __field(        bool,                   copy_everything                 )
+               __field(        bool,                   no_xattrs                       )
+               __field(        int,                    log_mode                        )
+       ),
+
+       TP_fast_assign(
+               TP_fast_assign_fsid(inode->root->fs_info);
+               __entry->root_objectid                  = btrfs_root_id(inode->root);
+               __entry->ino                            = btrfs_ino(inode);
+               __entry->mode                           = inode->vfs_inode.i_mode;
+               __entry->transid                        = trans->transid;
+               __entry->generation                     = inode->generation;
+               spin_lock(&inode->lock);
+               __entry->logged_trans                   = inode->logged_trans;
+               __entry->last_unlink_trans              = inode->last_unlink_trans;
+               __entry->last_reflink_trans             = inode->last_reflink_trans;
+               __entry->last_sub_trans                 = inode->last_sub_trans;
+               __entry->last_log_commit                = inode->last_log_commit;
+               spin_unlock(&inode->lock);
+               __entry->logging_new_name               = ctx->logging_new_name;
+               __entry->logging_new_delayed_dentries   = ctx->logging_new_delayed_dentries;
+               __entry->is_conflict_inode              = ctx->logging_conflict_inodes;
+               __entry->full_sync                      =
+                       test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags);
+               __entry->copy_everything                =
+                       test_bit(BTRFS_INODE_COPY_EVERYTHING, &inode->runtime_flags);
+               __entry->no_xattrs                      =
+                       test_bit(BTRFS_INODE_NO_XATTRS, &inode->runtime_flags);
+               __entry->log_mode                       = log_mode;
+       ),
+
+       TP_printk_btrfs("root=%llu(%s) ino=%llu type=%s transid=%llu gen=%llu"
+                       " logged_trans=%llu last_unlink_trans=%llu"
+                       " last_reflink_trans=%llu last_sub_trans=%d last_log_commit=%d"
+                       " logging_new_name=%d logging_new_delayed_dentries=%d"
+                       " is_conflict_inode=%d full_sync=%d copy_everything=%d"
+                       " no_xattrs=%d log_mode=%d(%s)",
+                       show_root_type(__entry->root_objectid), __entry->ino,
+                       show_inode_type(__entry->mode), __entry->transid,
+                       __entry->generation, __entry->logged_trans,
+                       __entry->last_unlink_trans, __entry->last_reflink_trans,
+                       __entry->last_sub_trans, __entry->last_log_commit,
+                       __entry->logging_new_name, __entry->logging_new_delayed_dentries,
+                       __entry->is_conflict_inode, __entry->log_mode,
+                       __entry->full_sync, __entry->copy_everything, __entry->no_xattrs,
+                       __print_symbolic(__entry->log_mode, LOG_MODES))
+);
+
+TRACE_EVENT(btrfs_log_inode_exit,
+
+       TP_PROTO(const struct btrfs_trans_handle *trans, struct btrfs_inode *inode,
+                int ret),
+
+       TP_ARGS(trans, inode, ret),
+
+       TP_STRUCT__entry_btrfs(
+               __field(        u64,            root_objectid           )
+               __field(        u64,            ino                     )
+               __field(        u64,            transid                 )
+               __field(        u64,            logged_trans            )
+               __field(        u64,            last_reflink_trans      )
+               __field(        int,            last_sub_trans          )
+               __field(        int,            last_log_commit         )
+               __field(        int,            ret                     )
+       ),
+
+       TP_fast_assign(
+               TP_fast_assign_fsid(inode->root->fs_info);
+               __entry->root_objectid                  = btrfs_root_id(inode->root);
+               __entry->ino                            = btrfs_ino(inode);
+               __entry->transid                        = trans->transid;
+               spin_lock(&inode->lock);
+               __entry->logged_trans                   = inode->logged_trans;
+               __entry->last_reflink_trans             = inode->last_reflink_trans;
+               __entry->last_sub_trans                 = inode->last_sub_trans;
+               __entry->last_log_commit                = inode->last_log_commit;
+               spin_unlock(&inode->lock);
+               __entry->ret                            = ret;
+       ),
+
+       TP_printk_btrfs("root=%llu(%s) ino=%llu transid=%llu logged_trans=%llu"
+                       " last_reflink_trans=%llu last_sub_trans=%d"
+                       " last_log_commit=%d ret=%d",
+                       show_root_type(__entry->root_objectid), __entry->ino,
+                       __entry->transid, __entry->logged_trans,
+                       __entry->last_reflink_trans, __entry->last_sub_trans,
+                       __entry->last_log_commit, __entry->ret)
+);
+
 TRACE_EVENT(btrfs_sync_fs,
 
        TP_PROTO(const struct btrfs_fs_info *fs_info, int wait),