]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/journal.c
Update bcachefs sources to 4837f82ee1 bcachefs: Use cached iterators for alloc btree
[bcachefs-tools-debian] / libbcachefs / journal.c
index 5c3e146e3942ac673735c2fb1bcde80782b6e3ca..b4f7b61ba9acd03ce9ecd8d2deb821b30ccf079e 100644 (file)
@@ -376,7 +376,8 @@ unlock:
                goto retry;
 
        if (ret == -ENOSPC) {
-               BUG_ON(!can_discard && (flags & JOURNAL_RES_GET_RESERVED));
+               WARN_ONCE(!can_discard && (flags & JOURNAL_RES_GET_RESERVED),
+                         "JOURNAL_RES_GET_RESERVED set but journal full");
 
                /*
                 * Journal is full - can't rely on reclaim from work item due to
@@ -427,9 +428,10 @@ int bch2_journal_res_get_slowpath(struct journal *j, struct journal_res *res,
 
 static bool journal_preres_available(struct journal *j,
                                     struct journal_preres *res,
-                                    unsigned new_u64s)
+                                    unsigned new_u64s,
+                                    unsigned flags)
 {
-       bool ret = bch2_journal_preres_get_fast(j, res, new_u64s);
+       bool ret = bch2_journal_preres_get_fast(j, res, new_u64s, flags);
 
        if (!ret)
                bch2_journal_reclaim_work(&j->reclaim_work.work);
@@ -439,13 +441,14 @@ static bool journal_preres_available(struct journal *j,
 
 int __bch2_journal_preres_get(struct journal *j,
                              struct journal_preres *res,
-                             unsigned new_u64s)
+                             unsigned new_u64s,
+                             unsigned flags)
 {
        int ret;
 
        closure_wait_event(&j->preres_wait,
                   (ret = bch2_journal_error(j)) ||
-                  journal_preres_available(j, res, new_u64s));
+                  journal_preres_available(j, res, new_u64s, flags));
        return ret;
 }
 
@@ -945,7 +948,7 @@ static bool bch2_journal_writing_to_device(struct journal *j, unsigned dev_idx)
        w = j->buf + !state.idx;
 
        ret = state.prev_buf_unwritten &&
-               bch2_extent_has_device(bkey_i_to_s_c_extent(&w->key), dev_idx);
+               bch2_bkey_has_device(bkey_i_to_s_c(&w->key), dev_idx);
        spin_unlock(&j->lock);
 
        return ret;
@@ -958,15 +961,12 @@ void bch2_dev_journal_stop(struct journal *j, struct bch_dev *ca)
 
 void bch2_fs_journal_stop(struct journal *j)
 {
-       struct bch_fs *c = container_of(j, struct bch_fs, journal);
-
        bch2_journal_flush_all_pins(j);
 
        wait_event(j->wait, journal_entry_close(j));
 
        /* do we need to write another journal entry? */
-       if (test_bit(JOURNAL_NOT_EMPTY, &j->flags) ||
-           c->btree_roots_dirty)
+       if (test_bit(JOURNAL_NOT_EMPTY, &j->flags))
                bch2_journal_meta(j);
 
        journal_quiesce(j);
@@ -987,9 +987,8 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq,
        u64 last_seq = cur_seq, nr, seq;
 
        if (!list_empty(journal_entries))
-               last_seq = le64_to_cpu(list_first_entry(journal_entries,
-                                                       struct journal_replay,
-                                                       list)->j.seq);
+               last_seq = le64_to_cpu(list_last_entry(journal_entries,
+                               struct journal_replay, list)->j.last_seq);
 
        nr = cur_seq - last_seq;
 
@@ -1018,8 +1017,10 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq,
 
        list_for_each_entry(i, journal_entries, list) {
                seq = le64_to_cpu(i->j.seq);
+               BUG_ON(seq >= cur_seq);
 
-               BUG_ON(seq < last_seq || seq >= cur_seq);
+               if (seq < last_seq)
+                       continue;
 
                journal_seq_pin(j, seq)->devs = i->devs;
        }
@@ -1237,14 +1238,14 @@ ssize_t bch2_journal_print_pins(struct journal *j, char *buf)
                       i, atomic_read(&pin_list->count));
 
                list_for_each_entry(pin, &pin_list->list, list)
-                       pr_buf(&out, "\t%p %pf\n",
+                       pr_buf(&out, "\t%px %ps\n",
                               pin, pin->flush);
 
                if (!list_empty(&pin_list->flushed))
                        pr_buf(&out, "flushed:\n");
 
                list_for_each_entry(pin, &pin_list->flushed, list)
-                       pr_buf(&out, "\t%p %pf\n",
+                       pr_buf(&out, "\t%px %ps\n",
                               pin, pin->flush);
        }
        spin_unlock(&j->lock);