@@ -1678,9 +1678,15 @@ static void do_journal_write(struct closure *cl)
16781678 continue_at (cl , journal_write_done , c -> io_complete_wq );
16791679}
16801680
1681- static void bch2_journal_entries_postprocess (struct bch_fs * c , struct jset * jset )
1681+ static int bch2_journal_write_prep (struct journal * j , struct journal_buf * w )
16821682{
1683- struct jset_entry * i , * next , * prev = NULL ;
1683+ struct bch_fs * c = container_of (j , struct bch_fs , journal );
1684+ struct jset_entry * start , * end , * i , * next , * prev = NULL ;
1685+ struct jset * jset = w -> data ;
1686+ unsigned sectors , bytes , u64s ;
1687+ bool validate_before_checksum = false;
1688+ unsigned long btree_roots_have = 0 ;
1689+ int ret ;
16841690
16851691 /*
16861692 * Simple compaction, dropping empty jset_entries (from journal
@@ -1697,8 +1703,20 @@ static void bch2_journal_entries_postprocess(struct bch_fs *c, struct jset *jset
16971703 if (!u64s )
16981704 continue ;
16991705
1700- if (i -> type == BCH_JSET_ENTRY_btree_root )
1706+ /*
1707+ * New btree roots are set by journalling them; when the journal
1708+ * entry gets written we have to propagate them to
1709+ * c->btree_roots
1710+ *
1711+ * But, every journal entry we write has to contain all the
1712+ * btree roots (at least for now); so after we copy btree roots
1713+ * to c->btree_roots we have to get any missing btree roots and
1714+ * add them to this journal entry:
1715+ */
1716+ if (i -> type == BCH_JSET_ENTRY_btree_root ) {
17011717 bch2_journal_entry_to_btree_root (c , i );
1718+ __set_bit (i -> btree_id , & btree_roots_have );
1719+ }
17021720
17031721 /* Can we merge with previous entry? */
17041722 if (prev &&
@@ -1722,35 +1740,10 @@ static void bch2_journal_entries_postprocess(struct bch_fs *c, struct jset *jset
17221740
17231741 prev = prev ? vstruct_next (prev ) : jset -> start ;
17241742 jset -> u64s = cpu_to_le32 ((u64 * ) prev - jset -> _data );
1725- }
1726-
1727- static int bch2_journal_write_prep (struct journal * j , struct journal_buf * w )
1728- {
1729- struct bch_fs * c = container_of (j , struct bch_fs , journal );
1730- struct jset_entry * start , * end ;
1731- struct jset * jset ;
1732- unsigned sectors , bytes , u64s ;
1733- bool validate_before_checksum = false;
1734- int ret ;
1735-
1736- journal_buf_realloc (j , w );
1737- jset = w -> data ;
1738-
1739- /*
1740- * New btree roots are set by journalling them; when the journal entry
1741- * gets written we have to propagate them to c->btree_roots
1742- *
1743- * But, every journal entry we write has to contain all the btree roots
1744- * (at least for now); so after we copy btree roots to c->btree_roots we
1745- * have to get any missing btree roots and add them to this journal
1746- * entry:
1747- */
1748-
1749- bch2_journal_entries_postprocess (c , jset );
17501743
17511744 start = end = vstruct_last (jset );
17521745
1753- end = bch2_btree_roots_to_journal_entries (c , jset -> start , end );
1746+ end = bch2_btree_roots_to_journal_entries (c , end , btree_roots_have );
17541747
17551748 bch2_journal_super_entries_add_common (c , & end ,
17561749 le64_to_cpu (jset -> seq ));
@@ -1872,6 +1865,8 @@ void bch2_journal_write(struct closure *cl)
18721865 if (ret )
18731866 goto err ;
18741867
1868+ journal_buf_realloc (j , w );
1869+
18751870 ret = bch2_journal_write_prep (j , w );
18761871 if (ret )
18771872 goto err ;
0 commit comments