--- /dev/null
+From c6a68b51d5351bf61a4eab61120b56c903205368 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Mon, 2 Aug 2021 09:31:37 -0500
+Subject: btrfs: mark compressed range uptodate only if all bio succeed
+
+From: Goldwyn Rodrigues <rgoldwyn@suse.de>
+
+[ Upstream commit 240246f6b913b0c23733cfd2def1d283f8cc9bbe ]
+
+In compression write endio sequence, the range which the compressed_bio
+writes is marked as uptodate if the last bio of the compressed (sub)bios
+is completed successfully. There could be previous bio which may
+have failed which is recorded in cb->errors.
+
+Set the writeback range as uptodate only if cb->errors is zero, as opposed
+to checking only the last bio's status.
+
+Backporting notes: in all versions up to 4.4 the last argument is always
+replaced by "!cb->errors".
+
+CC: stable@vger.kernel.org # 4.4+
+Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
+Reviewed-by: David Sterba <dsterba@suse.com>
+Signed-off-by: David Sterba <dsterba@suse.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ fs/btrfs/compression.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
+index ccd9c709375e..24341c97c13f 100644
+--- a/fs/btrfs/compression.c
++++ b/fs/btrfs/compression.c
+@@ -286,7 +286,7 @@ static void end_compressed_bio_write(struct bio *bio)
+ cb->start,
+ cb->start + cb->len - 1,
+ NULL,
+- bio->bi_status ? 0 : 1);
++ !cb->errors);
+ cb->compressed_pages[0]->mapping = NULL;
+
+ end_compressed_writeback(inode, cb);
+--
+2.30.2
+