]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/journal.h
Update bcachefs sources to f9c612bbf82d bcachefs: Fixes for building in userspace
[bcachefs-tools-debian] / libbcachefs / journal.h
index 008a2e25a4fac93df681233b679c9fc6eaca95d0..491133cc52f3bf38f9c80cf94daf7d0d5b0cc6c1 100644 (file)
@@ -252,9 +252,10 @@ static inline bool journal_entry_empty(struct jset *j)
        return true;
 }
 
-void __bch2_journal_buf_put(struct journal *);
-
-static inline void bch2_journal_buf_put(struct journal *j, unsigned idx)
+/*
+ * Drop reference on a buffer index and return true if the count has hit zero.
+ */
+static inline union journal_res_state journal_state_buf_put(struct journal *j, unsigned idx)
 {
        union journal_res_state s;
 
@@ -264,9 +265,30 @@ static inline void bch2_journal_buf_put(struct journal *j, unsigned idx)
                                    .buf2_count = idx == 2,
                                    .buf3_count = idx == 3,
                                    }).v, &j->reservations.counter);
+       return s;
+}
+
+void bch2_journal_buf_put_final(struct journal *, u64, bool);
+
+static inline void __bch2_journal_buf_put(struct journal *j, unsigned idx, u64 seq)
+{
+       union journal_res_state s;
+
+       s = journal_state_buf_put(j, idx);
+       if (!journal_state_count(s, idx))
+               bch2_journal_buf_put_final(j, seq, idx == s.unwritten_idx);
+}
 
-       if (!journal_state_count(s, idx) && idx == s.unwritten_idx)
-               __bch2_journal_buf_put(j);
+static inline void bch2_journal_buf_put(struct journal *j, unsigned idx, u64 seq)
+{
+       union journal_res_state s;
+
+       s = journal_state_buf_put(j, idx);
+       if (!journal_state_count(s, idx)) {
+               spin_lock(&j->lock);
+               bch2_journal_buf_put_final(j, seq, idx == s.unwritten_idx);
+               spin_unlock(&j->lock);
+       }
 }
 
 /*
@@ -286,7 +308,7 @@ static inline void bch2_journal_res_put(struct journal *j,
                                       BCH_JSET_ENTRY_btree_keys,
                                       0, 0, 0);
 
-       bch2_journal_buf_put(j, res->idx);
+       bch2_journal_buf_put(j, res->idx, res->seq);
 
        res->ref = 0;
 }