]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: tracepoints: add trace event for when fsync finishes
authorFilipe Manana <fdmanana@suse.com>
Tue, 28 Apr 2026 14:32:15 +0000 (15:32 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 8 Jun 2026 13:53:34 +0000 (15:53 +0200)
Currently we only have a trace event for when a fsync operation starts,
but this alone is not very helpful. Add a trace event for when fsync
finishes, which reports its return value, so that using tracing we can
see which other trace events happened in between (several will be added
soon for inode logging steps) and even measure execution time.

So rename the existing trace event btrfs_sync_file to
btrfs_sync_file_enter and add the trace event btrfs_sync_file_exit.
The naming is similar to what ext4 does (ext4_sync_file_enter and
ext4_sync_file_exit) and with similar information reported.

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/file.c
include/trace/events/btrfs.h

index f77ccef837b961977db84ac9b0f05a48c9ce85d8..d786b9666755adf7032a72a07f6dfbeeafd728a4 100644 (file)
@@ -1564,7 +1564,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
                btrfs_assert_inode_locked(inode);
        }
 
-       trace_btrfs_sync_file(file, datasync);
+       trace_btrfs_sync_file_enter(file, datasync);
 
        btrfs_init_log_ctx(&ctx, inode);
 
@@ -1810,6 +1810,8 @@ out:
        err = file_check_and_advance_wb_err(file);
        if (!ret)
                ret = err;
+       trace_btrfs_sync_file_exit(file, ret);
+
        return ret;
 
 out_release_extents:
index 801f4793e00265bef6063f5a577082bb6678ec1d..1b19364eabff7f703638ccb459a3da0a09c2421a 100644 (file)
@@ -808,7 +808,7 @@ TRACE_EVENT(btrfs_writepage_end_io_hook,
                  __entry->end, __entry->uptodate)
 );
 
-TRACE_EVENT(btrfs_sync_file,
+TRACE_EVENT(btrfs_sync_file_enter,
 
        TP_PROTO(const struct file *file, int datasync),
 
@@ -840,6 +840,32 @@ TRACE_EVENT(btrfs_sync_file,
                  __entry->datasync)
 );
 
+TRACE_EVENT(btrfs_sync_file_exit,
+
+       TP_PROTO(const struct file *file, int ret),
+
+       TP_ARGS(file, ret),
+
+       TP_STRUCT__entry_btrfs(
+               __field(        u64,    ino             )
+               __field(        int,    ret             )
+               __field(        u64,    root_objectid   )
+       ),
+
+       TP_fast_assign(
+               struct btrfs_inode *inode = BTRFS_I(file_inode(file));
+
+               TP_fast_assign_fsid(inode->root->fs_info);
+               __entry->root_objectid  = btrfs_root_id(inode->root);
+               __entry->ino            = btrfs_ino(inode);
+               __entry->ret            = ret;
+       ),
+
+       TP_printk_btrfs("root=%llu(%s) ino=%llu ret=%d",
+                       show_root_type(__entry->root_objectid),
+                       __entry->ino, __entry->ret)
+);
+
 TRACE_EVENT(btrfs_sync_fs,
 
        TP_PROTO(const struct btrfs_fs_info *fs_info, int wait),