Commit 231db03c authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Journal pin refactoring

This deletes some duplicated code.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 34c1cd6a
...@@ -320,11 +320,14 @@ void bch2_journal_pin_drop(struct journal *j, ...@@ -320,11 +320,14 @@ void bch2_journal_pin_drop(struct journal *j,
spin_unlock(&j->lock); spin_unlock(&j->lock);
} }
static void bch2_journal_pin_add_locked(struct journal *j, u64 seq, void bch2_journal_pin_set(struct journal *j, u64 seq,
struct journal_entry_pin *pin, struct journal_entry_pin *pin,
journal_pin_flush_fn flush_fn) 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); __journal_pin_drop(j, pin);
...@@ -335,45 +338,6 @@ static void bch2_journal_pin_add_locked(struct journal *j, u64 seq, ...@@ -335,45 +338,6 @@ static void bch2_journal_pin_add_locked(struct journal *j, u64 seq,
pin->flush = flush_fn; pin->flush = flush_fn;
list_add(&pin->list, flush_fn ? &pin_list->list : &pin_list->flushed); 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); spin_unlock(&j->lock);
/* /*
...@@ -383,20 +347,6 @@ void bch2_journal_pin_update(struct journal *j, u64 seq, ...@@ -383,20 +347,6 @@ void bch2_journal_pin_update(struct journal *j, u64 seq,
journal_wake(j); 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 * bch2_journal_pin_flush: ensure journal pin callback is no longer running
*/ */
......
...@@ -42,25 +42,33 @@ journal_seq_pin(struct journal *j, u64 seq) ...@@ -42,25 +42,33 @@ journal_seq_pin(struct journal *j, u64 seq)
void bch2_journal_pin_put(struct journal *, u64); void bch2_journal_pin_put(struct journal *, u64);
void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *); void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *);
void __bch2_journal_pin_add(struct journal *, u64, struct journal_entry_pin *, void bch2_journal_pin_set(struct journal *, u64, struct journal_entry_pin *,
journal_pin_flush_fn); journal_pin_flush_fn);
static inline void bch2_journal_pin_add(struct journal *j, u64 seq, static inline void bch2_journal_pin_add(struct journal *j, u64 seq,
struct journal_entry_pin *pin, struct journal_entry_pin *pin,
journal_pin_flush_fn flush_fn) journal_pin_flush_fn flush_fn)
{ {
if (unlikely(!journal_pin_active(pin) || pin->seq > seq)) 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, static inline void bch2_journal_pin_copy(struct journal *j,
struct journal_entry_pin *, struct journal_entry_pin *dst,
journal_pin_flush_fn); 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 *, static inline void bch2_journal_pin_update(struct journal *j, u64 seq,
struct journal_entry_pin *, struct journal_entry_pin *pin,
struct journal_entry_pin *, journal_pin_flush_fn flush_fn)
journal_pin_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 *); void bch2_journal_pin_flush(struct journal *, struct journal_entry_pin *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment