From: Michael Jeanson <mjeanson@efficios.com>
Date: Mon Jul 12 15:00:26 2021 -0400
Git-commit: 39192dfbea6041eefea1676c554ba73946793c71
Subject: btrfs: pass btrfs_inode to btrfs_writepage_endio_finish_ordered() (v5.14)
References: bsc#1190361
Signed-off-by: Tony Jones <tonyj@suse.de>

    fix: btrfs: pass btrfs_inode to btrfs_writepage_endio_finish_ordered() (v5.14)
    
    See upstream commit:
    
      commit 38a39ac77e089515acbe85c6c70c3df1e728357d
      Author: Qu Wenruo <wqu@suse.com>
      Date:   Thu Apr 8 20:32:27 2021 +0800
    
        btrfs: pass btrfs_inode to btrfs_writepage_endio_finish_ordered()
    
        There is a pretty bad abuse of btrfs_writepage_endio_finish_ordered() in
        end_compressed_bio_write().
    
        It passes compressed pages to btrfs_writepage_endio_finish_ordered(),
        which is only supposed to accept inode pages.
    
        Thankfully the important info here is the inode, so let's pass
        btrfs_inode directly into btrfs_writepage_endio_finish_ordered(), and
        make @page parameter optional.
    
        By this, end_compressed_bio_write() can happily pass page=NULL while
        still getting everything done properly.
    
        Also, to cooperate with such modification, replace @page parameter for
        trace_btrfs_writepage_end_io_hook() with btrfs_inode.
        Although this removes page_index info, the existing start/len should be
        enough for most usage.
    
    Change-Id: If96e99c2d9533d96d9d1aa6460bb7fd3ac9ed7ab
    Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
    Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

diff --git a/instrumentation/events/lttng-module/btrfs.h b/instrumentation/events/lttng-module/btrfs.h
index ca3b58c8..af9b8bed 100644
--- a/instrumentation/events/lttng-module/btrfs.h
+++ b/instrumentation/events/lttng-module/btrfs.h
@@ -578,6 +578,65 @@ LTTNG_TRACEPOINT_EVENT_INSTANCE(btrfs__ordered_extent, btrfs_ordered_extent_put,
 )
 #endif
 
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,14,0))
+LTTNG_TRACEPOINT_EVENT(btrfs_writepage_end_io_hook,
+
+	TP_PROTO(const struct btrfs_inode *inode, u64 start, u64 end, int uptodate),
+
+	TP_ARGS(inode, start, end, uptodate),
+
+	TP_FIELDS(
+		ctf_integer(u64, ino, btrfs_ino(inode))
+		ctf_integer(u64, start, start)
+		ctf_integer(u64, end, end)
+		ctf_integer(int, uptodate, uptodate)
+		ctf_integer(u64, root_objectid, inode->root->root_key.objectid)
+	)
+)
+
+#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,14,0) || \
+	LTTNG_SLE_KERNEL_RANGE(4,4,73,5,0,0, 4,4,73,6,0,0) || \
+	LTTNG_SLE_KERNEL_RANGE(4,4,82,6,0,0, 4,4,82,7,0,0) || \
+	LTTNG_SLE_KERNEL_RANGE(4,4,92,6,0,0, 4,4,92,7,0,0) || \
+	LTTNG_SLE_KERNEL_RANGE(4,4,103,6,0,0, 4,5,0,0,0,0))
+
+LTTNG_TRACEPOINT_EVENT(btrfs_writepage_end_io_hook,
+
+	TP_PROTO(const struct page *page, u64 start, u64 end, int uptodate),
+
+	TP_ARGS(page, start, end, uptodate),
+
+	TP_FIELDS(
+		ctf_integer(ino_t, ino, page->mapping->host->i_ino)
+		ctf_integer(pgoff_t, index, page->index)
+		ctf_integer(u64, start, start)
+		ctf_integer(u64, end, end)
+		ctf_integer(int, uptodate, uptodate)
+		ctf_integer(u64, root_objectid,
+			BTRFS_I(page->mapping->host)->root->root_key.objectid)
+	)
+)
+
+#else
+
+LTTNG_TRACEPOINT_EVENT(btrfs_writepage_end_io_hook,
+
+	TP_PROTO(struct page *page, u64 start, u64 end, int uptodate),
+
+	TP_ARGS(page, start, end, uptodate),
+
+	TP_FIELDS(
+		ctf_integer(ino_t, ino, page->mapping->host->i_ino)
+		ctf_integer(pgoff_t, index, page->index)
+		ctf_integer(u64, start, start)
+		ctf_integer(u64, end, end)
+		ctf_integer(int, uptodate, uptodate)
+		ctf_integer(u64, root_objectid,
+			BTRFS_I(page->mapping->host)->root->root_key.objectid)
+	)
+)
+#endif
+
 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,14,0) || \
 	LTTNG_SLE_KERNEL_RANGE(4,4,73,5,0,0, 4,4,73,6,0,0) || \
 	LTTNG_SLE_KERNEL_RANGE(4,4,82,6,0,0, 4,4,82,7,0,0) || \
@@ -619,23 +678,6 @@ LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(btrfs__writepage,
 	TP_ARGS(page, inode, wbc)
 )
 
-LTTNG_TRACEPOINT_EVENT(btrfs_writepage_end_io_hook,
-
-	TP_PROTO(const struct page *page, u64 start, u64 end, int uptodate),
-
-	TP_ARGS(page, start, end, uptodate),
-
-	TP_FIELDS(
-		ctf_integer(ino_t, ino, page->mapping->host->i_ino)
-		ctf_integer(pgoff_t, index, page->index)
-		ctf_integer(u64, start, start)
-		ctf_integer(u64, end, end)
-		ctf_integer(int, uptodate, uptodate)
-		ctf_integer(u64, root_objectid,
-			BTRFS_I(page->mapping->host)->root->root_key.objectid)
-	)
-)
-
 LTTNG_TRACEPOINT_EVENT(btrfs_sync_file,
 
 	TP_PROTO(const struct file *file, int datasync),
@@ -690,23 +732,6 @@ LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(btrfs__writepage,
 	TP_ARGS(page, inode, wbc)
 )
 
-LTTNG_TRACEPOINT_EVENT(btrfs_writepage_end_io_hook,
-
-	TP_PROTO(struct page *page, u64 start, u64 end, int uptodate),
-
-	TP_ARGS(page, start, end, uptodate),
-
-	TP_FIELDS(
-		ctf_integer(ino_t, ino, page->mapping->host->i_ino)
-		ctf_integer(pgoff_t, index, page->index)
-		ctf_integer(u64, start, start)
-		ctf_integer(u64, end, end)
-		ctf_integer(int, uptodate, uptodate)
-		ctf_integer(u64, root_objectid,
-			BTRFS_I(page->mapping->host)->root->root_key.objectid)
-	)
-)
-
 LTTNG_TRACEPOINT_EVENT(btrfs_sync_file,
 
 	TP_PROTO(struct file *file, int datasync),
