]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/journal.h
Update bcachefs sources to 7bf1ac0d46 bcachefs: Correctly initialize new buckets...
[bcachefs-tools-debian] / libbcachefs / journal.h
index d3caa7ea7ce9446b2b9994f41af0782abaa79b08..491133cc52f3bf38f9c80cf94daf7d0d5b0cc6c1 100644 (file)
@@ -29,8 +29,8 @@
  *
  * Synchronous updates are specified by passing a closure (@flush_cl) to
  * bch2_btree_insert() or bch_btree_insert_node(), which then pass that parameter
- * down to the journalling code. That closure will will wait on the journal
- * write to complete (via closure_wait()).
+ * down to the journalling code. That closure will wait on the journal write to
+ * complete (via closure_wait()).
  *
  * If the index update wasn't synchronous, the journal entry will be
  * written out after 10 ms have elapsed, by default (the delay_ms field
@@ -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;
 
-       if (!journal_state_count(s, idx) && idx == s.unwritten_idx)
-               __bch2_journal_buf_put(j);
+       s = journal_state_buf_put(j, idx);
+       if (!journal_state_count(s, idx))
+               bch2_journal_buf_put_final(j, seq, idx == s.unwritten_idx);
+}
+
+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;
 }
@@ -294,9 +316,14 @@ static inline void bch2_journal_res_put(struct journal *j,
 int bch2_journal_res_get_slowpath(struct journal *, struct journal_res *,
                                  unsigned);
 
-/* First two bits for JOURNAL_WATERMARK: */
-#define JOURNAL_RES_GET_NONBLOCK       (1 << 2)
-#define JOURNAL_RES_GET_CHECK          (1 << 3)
+/* First bits for BCH_WATERMARK: */
+enum journal_res_flags {
+       __JOURNAL_RES_GET_NONBLOCK      = BCH_WATERMARK_BITS,
+       __JOURNAL_RES_GET_CHECK,
+};
+
+#define JOURNAL_RES_GET_NONBLOCK       (1 << __JOURNAL_RES_GET_NONBLOCK)
+#define JOURNAL_RES_GET_CHECK          (1 << __JOURNAL_RES_GET_CHECK)
 
 static inline int journal_res_get_fast(struct journal *j,
                                       struct journal_res *res,
@@ -317,7 +344,7 @@ static inline int journal_res_get_fast(struct journal *j,
 
                EBUG_ON(!journal_state_count(new, new.idx));
 
-               if ((flags & JOURNAL_WATERMARK_MASK) < j->watermark)
+               if ((flags & BCH_WATERMARK_MASK) < j->watermark)
                        return 0;
 
                new.cur_entry_offset += res->u64s;
@@ -373,17 +400,17 @@ out:
 static inline void journal_set_watermark(struct journal *j)
 {
        union journal_preres_state s = READ_ONCE(j->prereserved);
-       unsigned watermark = JOURNAL_WATERMARK_any;
+       unsigned watermark = BCH_WATERMARK_stripe;
 
        if (fifo_free(&j->pin) < j->pin.size / 4)
-               watermark = max_t(unsigned, watermark, JOURNAL_WATERMARK_copygc);
+               watermark = max_t(unsigned, watermark, BCH_WATERMARK_copygc);
        if (fifo_free(&j->pin) < j->pin.size / 8)
-               watermark = max_t(unsigned, watermark, JOURNAL_WATERMARK_reserved);
+               watermark = max_t(unsigned, watermark, BCH_WATERMARK_reclaim);
 
        if (s.reserved > s.remaining)
-               watermark = max_t(unsigned, watermark, JOURNAL_WATERMARK_copygc);
+               watermark = max_t(unsigned, watermark, BCH_WATERMARK_copygc);
        if (!s.remaining)
-               watermark = max_t(unsigned, watermark, JOURNAL_WATERMARK_reserved);
+               watermark = max_t(unsigned, watermark, BCH_WATERMARK_reclaim);
 
        if (watermark == j->watermark)
                return;
@@ -426,13 +453,14 @@ static inline int bch2_journal_preres_get_fast(struct journal *j,
        int d = new_u64s - res->u64s;
        union journal_preres_state old, new;
        u64 v = atomic64_read(&j->prereserved.counter);
+       enum bch_watermark watermark = flags & BCH_WATERMARK_MASK;
        int ret;
 
        do {
                old.v = new.v = v;
                ret = 0;
 
-               if ((flags & JOURNAL_WATERMARK_reserved) ||
+               if (watermark == BCH_WATERMARK_reclaim ||
                    new.reserved + d < new.remaining) {
                        new.reserved += d;
                        ret = 1;
@@ -460,7 +488,7 @@ static inline int bch2_journal_preres_get(struct journal *j,
                return 0;
 
        if (flags & JOURNAL_RES_GET_NONBLOCK)
-               return -EAGAIN;
+               return -BCH_ERR_journal_preres_get_blocked;
 
        return __bch2_journal_preres_get(j, res, new_u64s, flags);
 }
@@ -478,7 +506,6 @@ int bch2_journal_flush_seq(struct journal *, u64);
 int bch2_journal_flush(struct journal *);
 bool bch2_journal_noflush_seq(struct journal *, u64);
 int bch2_journal_meta(struct journal *);
-int bch2_journal_log_msg(struct journal *, const char *, ...);
 
 void bch2_journal_halt(struct journal *);