]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Fix failure to allocate journal write on discard retry
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 4 Dec 2024 23:16:25 +0000 (18:16 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:22 +0000 (01:36 -0500)
When allocating a journal write fails, then retries after doing
discards, we were failing to count already allocated replicas.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/journal_io.c

index e5fce5e497f2181b776cc96336f0f7fa7023fb10..d7dfea5f0181c7abce8bcc3ce605835aaaf02b99 100644 (file)
@@ -1498,6 +1498,15 @@ static int journal_write_alloc(struct journal *j, struct journal_buf *w)
                                       READ_ONCE(c->opts.metadata_replicas_required));
 
        rcu_read_lock();
+
+       /* We might run more than once if we have to stop and do discards: */
+       struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(&w->key));
+       bkey_for_each_ptr(ptrs, p) {
+               struct bch_dev *ca = bch2_dev_rcu_noerror(c, p->dev);
+               if (ca)
+                       replicas += ca->mi.durability;
+       }
+
 retry:
        devs = target_rw_devs(c, BCH_DATA_journal, target);