]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: bch2_dev_get_ioref() may now sleep
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 1 Mar 2025 22:34:33 +0000 (17:34 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 15 Mar 2025 01:02:16 +0000 (21:02 -0400)
The next patch implementing freezing will change bch2_dev_get_ioref() to
sleep if a device is currently frozen.

Add an annotation and fix the journal code accordingly.

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

index c12d9f9bd5368f08051b6b2167f59b194c76ae87..a510755a8364e45d81f860c2e23d10f88ccd544f 100644 (file)
@@ -1664,6 +1664,7 @@ static CLOSURE_CALLBACK(journal_write_done)
        }
 
        bool completed = false;
+       bool do_discards = false;
 
        for (seq = journal_last_unwritten_seq(j);
             seq <= journal_cur_seq(j);
@@ -1676,7 +1677,6 @@ static CLOSURE_CALLBACK(journal_write_done)
                        j->flushed_seq_ondisk = seq;
                        j->last_seq_ondisk = w->last_seq;
 
-                       bch2_do_discards(c);
                        closure_wake_up(&c->freelist_wait);
                        bch2_reset_alloc_cursors(c);
                }
@@ -1727,6 +1727,9 @@ static CLOSURE_CALLBACK(journal_write_done)
         */
        bch2_journal_do_writes(j);
        spin_unlock(&j->lock);
+
+       if (do_discards)
+               bch2_do_discards(c);
 }
 
 static void journal_write_endio(struct bio *bio)
index b29b6c6c21dd2dc9aa31ac2e923cc347062eac84..df91b02ce57542816a707d9b4c64716ed3cdf8e6 100644 (file)
@@ -283,6 +283,8 @@ static inline struct bch_dev *bch2_dev_iterate(struct bch_fs *c, struct bch_dev
 
 static inline struct bch_dev *bch2_dev_get_ioref(struct bch_fs *c, unsigned dev, int rw)
 {
+       might_sleep();
+
        rcu_read_lock();
        struct bch_dev *ca = bch2_dev_rcu(c, dev);
        if (ca && !percpu_ref_tryget(&ca->io_ref))