public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] btrfs: propagate error from function unpin_extent_cache()
@ 2023-07-20 13:41 Luís Henriques
  2023-07-20 16:15 ` Filipe Manana
  0 siblings, 1 reply; 3+ messages in thread
From: Luís Henriques @ 2023-07-20 13:41 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Johannes Thumshirn
  Cc: linux-btrfs, linux-kernel, Luís Henriques

Function unpin_extent_cache() doesn't propagate an error if the call to
lookup_extent_mapping() fails.  This patch adds an error return (EINVAL)
and simply logs it in the only caller.

Signed-off-by: Luís Henriques <lhenriques@suse.de>
---
Hi!

As per David and Johannes reviews, I'm now proposing a different approach.
Note that I kept the WARN_ON() instead of replacing it by an ASSERT().  In
fact, I considered removing the WARN_ON() completely and simply return the
error if em->start != start.  But I guess it may useful for debug.

Changes since v1:
Instead of changing unpin_extent_cache() into a void function, make it
propage an error code instead.

 fs/btrfs/extent_map.c | 4 +++-
 fs/btrfs/inode.c      | 8 ++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index 0cdb3e86f29b..f4e7956edc05 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -304,8 +304,10 @@ int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len,
 
 	WARN_ON(!em || em->start != start);
 
-	if (!em)
+	if (!em) {
+		ret = -EINVAL;
 		goto out;
+	}
 
 	em->generation = gen;
 	clear_bit(EXTENT_FLAG_PINNED, &em->flags);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index dbbb67293e34..21eb66fcc0df 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3273,8 +3273,12 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
 						ordered_extent->disk_num_bytes);
 		}
 	}
-	unpin_extent_cache(&inode->extent_tree, ordered_extent->file_offset,
-			   ordered_extent->num_bytes, trans->transid);
+
+	/* Proceed even if we fail to unpin extent from cache */
+	if (unpin_extent_cache(&inode->extent_tree, ordered_extent->file_offset,
+			       ordered_extent->num_bytes, trans->transid) < 0)
+		btrfs_warn(fs_info, "failed to unpin extent from cache");
+
 	if (ret < 0) {
 		btrfs_abort_transaction(trans, ret);
 		goto out;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-21  9:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-20 13:41 [PATCH v2] btrfs: propagate error from function unpin_extent_cache() Luís Henriques
2023-07-20 16:15 ` Filipe Manana
2023-07-21  9:02   ` Luís Henriques

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox