From: Kent Overstreet <kent.overstreet@linux.dev>
Date: Sun, 18 Feb 2024 01:38:47 +0000 (-0500)
Subject: bcachefs: Fix bch2_journal_flush_device_pins()
X-Git-Tag: v6.8-rc6~1^2~2
X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=097471f9e458dbbe41e25394c1fb1ccd751f0bee;p=users%2Fdwmw2%2Flinux.git

bcachefs: Fix bch2_journal_flush_device_pins()

If a journal write errored, the list of devices it was written to could
be empty - we're not supposed to mark an empty replicas list.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---

diff --git a/fs/bcachefs/journal_reclaim.c b/fs/bcachefs/journal_reclaim.c
index 2cf626315652c..c33dca641575d 100644
--- a/fs/bcachefs/journal_reclaim.c
+++ b/fs/bcachefs/journal_reclaim.c
@@ -892,9 +892,11 @@ int bch2_journal_flush_device_pins(struct journal *j, int dev_idx)
 					 journal_seq_pin(j, seq)->devs);
 		seq++;
 
-		spin_unlock(&j->lock);
-		ret = bch2_mark_replicas(c, &replicas.e);
-		spin_lock(&j->lock);
+		if (replicas.e.nr_devs) {
+			spin_unlock(&j->lock);
+			ret = bch2_mark_replicas(c, &replicas.e);
+			spin_lock(&j->lock);
+		}
 	}
 	spin_unlock(&j->lock);
 err: