diff mbox series

[17/21] btrfs: add a btrfs_finish_ordered_extent helper

Message ID 20230508160843.133013-18-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [01/21] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio | expand

Commit Message

Christoph Hellwig May 8, 2023, 4:08 p.m. UTC
Add a helper to complete an ordered_extent without first doing a lookup.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/ordered-data.c      | 20 ++++++++++++++++++++
 fs/btrfs/ordered-data.h      |  3 +++
 include/trace/events/btrfs.h | 29 +++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)

Comments

Johannes Thumshirn May 9, 2023, 12:22 a.m. UTC | #1
On 08.05.23 18:09, Christoph Hellwig wrote:
> diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
> index 8ea9cea9bfeb4d..c0f308ef6f7699 100644
> --- a/include/trace/events/btrfs.h
> +++ b/include/trace/events/btrfs.h
> @@ -661,6 +661,35 @@ DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_mark_finished,
>  	     TP_ARGS(inode, ordered)
>  );
>  
> +TRACE_EVENT(btrfs_finish_ordered_extent,
> +
> +	TP_PROTO(const struct btrfs_inode *inode, u64 start, u64 len,
> +		 int uptodate),
> +
> +	TP_ARGS(inode, start, len, uptodate),
> +
> +	TP_STRUCT__entry_btrfs(
> +		__field(	u64,	 ino		)
> +		__field(	u64,	 start		)
> +		__field(	u64,	 len		)
> +		__field(	int,	 uptodate	)
> +		__field(	u64,	 root_objectid	)
> +	),
> +
> +	TP_fast_assign_btrfs(inode->root->fs_info,
> +		__entry->ino	= btrfs_ino(inode);
> +		__entry->start	= start;
> +		__entry->len	= len;
> +		__entry->uptodate = uptodate;
> +		__entry->root_objectid = inode->root->root_key.objectid;
> +	),
> +
> +	TP_printk_btrfs("root=%llu(%s) ino=%llu start=%llu len=%llu uptodate=%d",
> +		  show_root_type(__entry->root_objectid),
> +		  __entry->ino, __entry->start,
> +		  __entry->len, __entry->uptodate)
> +);

Why can't we use the btrfs__ordered_extent event class here?
Christoph Hellwig May 9, 2023, 1:12 p.m. UTC | #2
On Tue, May 09, 2023 at 12:22:39AM +0000, Johannes Thumshirn wrote:
> > +		  show_root_type(__entry->root_objectid),
> > +		  __entry->ino, __entry->start,
> > +		  __entry->len, __entry->uptodate)
> > +);
> 
> Why can't we use the btrfs__ordered_extent event class here?

We could.  We'd lose the information on the range of the ordered_extent
that actually is being completed.  If the maintainers are ok with not
having that in the trace point we can drop the separate implementation.
David Sterba May 10, 2023, 1:16 p.m. UTC | #3
On Tue, May 09, 2023 at 03:12:44PM +0200, Christoph Hellwig wrote:
> On Tue, May 09, 2023 at 12:22:39AM +0000, Johannes Thumshirn wrote:
> > > +		  show_root_type(__entry->root_objectid),
> > > +		  __entry->ino, __entry->start,
> > > +		  __entry->len, __entry->uptodate)
> > > +);
> > 
> > Why can't we use the btrfs__ordered_extent event class here?
> 
> We could.  We'd lose the information on the range of the ordered_extent
> that actually is being completed.  If the maintainers are ok with not
> having that in the trace point we can drop the separate implementation.

I think it's good to have the range there, the parameters and info for
the trace point do not match the ordered extent class so it needs to be
a separate one.
diff mbox series

Patch

diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index f474585e6234fe..a54bf49bd5c849 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -356,6 +356,26 @@  static void btrfs_queue_ordered_fn(struct btrfs_ordered_extent *ordered)
 	btrfs_queue_work(wq, &ordered->work);
 }
 
+bool btrfs_finish_ordered_extent(struct btrfs_ordered_extent *ordered,
+				 struct page *page, u64 file_offset, u64 len,
+				 bool uptodate)
+{
+	struct btrfs_inode *inode = BTRFS_I(ordered->inode);
+	unsigned long flags;
+	bool ret;
+
+	trace_btrfs_finish_ordered_extent(inode, file_offset, len, uptodate);
+
+	spin_lock_irqsave(&inode->ordered_tree.lock, flags);
+	ret = can_finish_ordered_extent(ordered, page, file_offset, len,
+					uptodate);
+	spin_unlock_irqrestore(&inode->ordered_tree.lock, flags);
+
+	if (ret)
+		btrfs_queue_ordered_fn(ordered);
+	return ret;
+}
+
 /*
  * Mark all ordered extents io inside the specified range finished.
  *
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index 87a61a2bb722fd..16e2e7b91267cb 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -172,6 +172,9 @@  int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent);
 void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry);
 void btrfs_remove_ordered_extent(struct btrfs_inode *btrfs_inode,
 				struct btrfs_ordered_extent *entry);
+bool btrfs_finish_ordered_extent(struct btrfs_ordered_extent *ordered,
+				 struct page *page, u64 file_offset, u64 len,
+				 bool uptodate);
 void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode,
 				struct page *page, u64 file_offset,
 				u64 num_bytes, bool uptodate);
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index 8ea9cea9bfeb4d..c0f308ef6f7699 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -661,6 +661,35 @@  DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_mark_finished,
 	     TP_ARGS(inode, ordered)
 );
 
+TRACE_EVENT(btrfs_finish_ordered_extent,
+
+	TP_PROTO(const struct btrfs_inode *inode, u64 start, u64 len,
+		 int uptodate),
+
+	TP_ARGS(inode, start, len, uptodate),
+
+	TP_STRUCT__entry_btrfs(
+		__field(	u64,	 ino		)
+		__field(	u64,	 start		)
+		__field(	u64,	 len		)
+		__field(	int,	 uptodate	)
+		__field(	u64,	 root_objectid	)
+	),
+
+	TP_fast_assign_btrfs(inode->root->fs_info,
+		__entry->ino	= btrfs_ino(inode);
+		__entry->start	= start;
+		__entry->len	= len;
+		__entry->uptodate = uptodate;
+		__entry->root_objectid = inode->root->root_key.objectid;
+	),
+
+	TP_printk_btrfs("root=%llu(%s) ino=%llu start=%llu len=%llu uptodate=%d",
+		  show_root_type(__entry->root_objectid),
+		  __entry->ino, __entry->start,
+		  __entry->len, __entry->uptodate)
+);
+
 DECLARE_EVENT_CLASS(btrfs__writepage,
 
 	TP_PROTO(const struct page *page, const struct inode *inode,