bcachefs: Journal pin refactoring
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 1 Dec 2020 16:48:08 +0000 (11:48 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:48 +0000 (17:08 -0400)
This deletes some duplicated code.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/journal_reclaim.c
fs/bcachefs/journal_reclaim.h

index c20f6de347305fd3f10f5afcc482862e06692d63..1dabad61887024374e1be57de95fa7c40a4cfe9d 100644 (file)
@@ -320,11 +320,14 @@ void bch2_journal_pin_drop(struct journal *j,
        spin_unlock(&j->lock);
 }
 
-static void bch2_journal_pin_add_locked(struct journal *j, u64 seq,
-                           struct journal_entry_pin *pin,
-                           journal_pin_flush_fn flush_fn)
+void bch2_journal_pin_set(struct journal *j, u64 seq,
+                         struct journal_entry_pin *pin,
+                         journal_pin_flush_fn flush_fn)
 {
-       struct journal_entry_pin_list *pin_list = journal_seq_pin(j, seq);
+       struct journal_entry_pin_list *pin_list;
+
+       spin_lock(&j->lock);
+       pin_list = journal_seq_pin(j, seq);
 
        __journal_pin_drop(j, pin);
 
@@ -335,45 +338,6 @@ static void bch2_journal_pin_add_locked(struct journal *j, u64 seq,
        pin->flush      = flush_fn;
 
        list_add(&pin->list, flush_fn ? &pin_list->list : &pin_list->flushed);
-}
-
-void __bch2_journal_pin_add(struct journal *j, u64 seq,
-                           struct journal_entry_pin *pin,
-                           journal_pin_flush_fn flush_fn)
-{
-       spin_lock(&j->lock);
-       bch2_journal_pin_add_locked(j, seq, pin, flush_fn);
-       spin_unlock(&j->lock);
-
-       /*
-        * If the journal is currently full,  we might want to call flush_fn
-        * immediately:
-        */
-       journal_wake(j);
-}
-
-void bch2_journal_pin_update(struct journal *j, u64 seq,
-                            struct journal_entry_pin *pin,
-                            journal_pin_flush_fn flush_fn)
-{
-       if (journal_pin_active(pin) && pin->seq < seq)
-               return;
-
-       spin_lock(&j->lock);
-
-       if (pin->seq != seq) {
-               bch2_journal_pin_add_locked(j, seq, pin, flush_fn);
-       } else {
-               struct journal_entry_pin_list *pin_list =
-                       journal_seq_pin(j, seq);
-
-               /*
-                * If the pin is already pinning the right sequence number, it
-                * still might've already been flushed:
-                */
-               list_move(&pin->list, &pin_list->list);
-       }
-
        spin_unlock(&j->lock);
 
        /*
@@ -383,20 +347,6 @@ void bch2_journal_pin_update(struct journal *j, u64 seq,
        journal_wake(j);
 }
 
-void bch2_journal_pin_copy(struct journal *j,
-                          struct journal_entry_pin *dst,
-                          struct journal_entry_pin *src,
-                          journal_pin_flush_fn flush_fn)
-{
-       spin_lock(&j->lock);
-
-       if (journal_pin_active(src) &&
-           (!journal_pin_active(dst) || src->seq < dst->seq))
-               bch2_journal_pin_add_locked(j, src->seq, dst, flush_fn);
-
-       spin_unlock(&j->lock);
-}
-
 /**
  * bch2_journal_pin_flush: ensure journal pin callback is no longer running
  */
index bae2c9210db8612ffb0cd47e731d5143c2b7a1e0..e25355042e6e4c7a6d821fbbecd026eac753276b 100644 (file)
@@ -42,25 +42,33 @@ journal_seq_pin(struct journal *j, u64 seq)
 void bch2_journal_pin_put(struct journal *, u64);
 void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *);
 
-void __bch2_journal_pin_add(struct journal *, u64, struct journal_entry_pin *,
-                           journal_pin_flush_fn);
+void bch2_journal_pin_set(struct journal *, u64, struct journal_entry_pin *,
+                         journal_pin_flush_fn);
 
 static inline void bch2_journal_pin_add(struct journal *j, u64 seq,
                                        struct journal_entry_pin *pin,
                                        journal_pin_flush_fn flush_fn)
 {
        if (unlikely(!journal_pin_active(pin) || pin->seq > seq))
-               __bch2_journal_pin_add(j, seq, pin, flush_fn);
+               bch2_journal_pin_set(j, seq, pin, flush_fn);
 }
 
-void bch2_journal_pin_update(struct journal *, u64,
-                            struct journal_entry_pin *,
-                            journal_pin_flush_fn);
+static inline void bch2_journal_pin_copy(struct journal *j,
+                                        struct journal_entry_pin *dst,
+                                        struct journal_entry_pin *src,
+                                        journal_pin_flush_fn flush_fn)
+{
+       if (journal_pin_active(src))
+               bch2_journal_pin_add(j, src->seq, dst, flush_fn);
+}
 
-void bch2_journal_pin_copy(struct journal *,
-                          struct journal_entry_pin *,
-                          struct journal_entry_pin *,
-                          journal_pin_flush_fn);
+static inline void bch2_journal_pin_update(struct journal *j, u64 seq,
+                                          struct journal_entry_pin *pin,
+                                          journal_pin_flush_fn flush_fn)
+{
+       if (unlikely(!journal_pin_active(pin) || pin->seq < seq))
+               bch2_journal_pin_set(j, seq, pin, flush_fn);
+}
 
 void bch2_journal_pin_flush(struct journal *, struct journal_entry_pin *);