]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: tracepoints: add trace event for log_all_new_ancestors()
authorFilipe Manana <fdmanana@suse.com>
Tue, 5 May 2026 14:31:16 +0000 (15:31 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 8 Jun 2026 13:53:34 +0000 (15:53 +0200)
log_all_new_ancestors() 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>
fs/btrfs/tree-log.c
include/trace/events/btrfs.h

index 90f5d1c830e4a30cbd0fe12eab72a6f4fb8cb816..f34dc9771dab91a434d3413cfbfd3573e854b098 100644 (file)
@@ -7462,16 +7462,22 @@ static int log_all_new_ancestors(struct btrfs_trans_handle *trans,
        struct btrfs_key search_key;
        int ret;
 
+       trace_btrfs_log_all_new_ancestors_enter(trans, inode);
+
        /*
         * For a single hard link case, go through a fast path that does not
         * need to iterate the fs/subvolume tree.
         */
-       if (inode->vfs_inode.i_nlink < 2)
-               return log_new_ancestors_fast(trans, inode, parent, ctx);
+       if (inode->vfs_inode.i_nlink < 2) {
+               ret = log_new_ancestors_fast(trans, inode, parent, ctx);
+               goto out;
+       }
 
        path = btrfs_alloc_path();
-       if (!path)
-               return -ENOMEM;
+       if (!path) {
+               ret = -ENOMEM;
+               goto out;
+       }
 
        search_key.objectid = ino;
        search_key.type = BTRFS_INODE_REF_KEY;
@@ -7479,7 +7485,7 @@ static int log_all_new_ancestors(struct btrfs_trans_handle *trans,
 again:
        ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
        if (ret < 0)
-               return ret;
+               goto out;
        if (ret == 0)
                path->slots[0]++;
 
@@ -7491,9 +7497,11 @@ again:
                if (slot >= btrfs_header_nritems(leaf)) {
                        ret = btrfs_next_leaf(root, path);
                        if (ret < 0)
-                               return ret;
-                       if (ret > 0)
+                               goto out;
+                       if (ret > 0) {
+                               ret = 0;
                                break;
+                       }
                        continue;
                }
 
@@ -7509,8 +7517,10 @@ again:
                 * this loop, etc). So just return some error to fallback to
                 * a transaction commit.
                 */
-               if (found_key.type == BTRFS_INODE_EXTREF_KEY)
-                       return -EMLINK;
+               if (found_key.type == BTRFS_INODE_EXTREF_KEY) {
+                       ret = -EMLINK;
+                       goto out;
+               }
 
                /*
                 * Logging ancestors needs to do more searches on the fs/subvol
@@ -7522,11 +7532,13 @@ again:
 
                ret = log_new_ancestors(trans, root, path, ctx);
                if (ret)
-                       return ret;
+                       goto out;
                btrfs_release_path(path);
                goto again;
        }
-       return 0;
+out:
+       trace_btrfs_log_all_new_ancestors_exit(trans, inode, ret);
+       return ret;
 }
 
 /*
index 2c145240d80979f128954f01b10102af82727637..d16de652a815a19e8eb744475d762f495241d397 100644 (file)
@@ -1120,6 +1120,61 @@ TRACE_EVENT(btrfs_log_all_parents_exit,
                        __entry->transid, __entry->ret)
 );
 
+TRACE_EVENT(btrfs_log_all_new_ancestors_enter,
+
+       TP_PROTO(const struct btrfs_trans_handle *trans,
+                const struct btrfs_inode *inode),
+
+       TP_ARGS(trans, inode),
+
+       TP_STRUCT__entry_btrfs(
+               __field(        u64,            root_objectid           )
+               __field(        u64,            ino                     )
+               __field(        u64,            transid                 )
+               __field(        unsigned int,   nlink                   )
+       ),
+
+       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;
+               __entry->nlink                  = inode->vfs_inode.i_nlink;
+       ),
+
+       TP_printk_btrfs("root=%llu(%s) ino=%llu transid=%llu nlink=%u",
+                       show_root_type(__entry->root_objectid), __entry->ino,
+                       __entry->transid, __entry->nlink)
+);
+
+TRACE_EVENT(btrfs_log_all_new_ancestors_exit,
+
+       TP_PROTO(const struct btrfs_trans_handle *trans,
+                const 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(        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;
+               __entry->ret            = ret;
+       ),
+
+       TP_printk_btrfs("root=%llu(%s) ino=%llu transid=%llu ret=%d",
+                       show_root_type(__entry->root_objectid), __entry->ino,
+                       __entry->transid, __entry->ret)
+);
+
 TRACE_EVENT(btrfs_sync_fs,
 
        TP_PROTO(const struct btrfs_fs_info *fs_info, int wait),