@@ -1678,9 +1678,15 @@ static void do_journal_write(struct closure *cl)
1678
1678
continue_at (cl , journal_write_done , c -> io_complete_wq );
1679
1679
}
1680
1680
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 )
1682
1682
{
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 ;
1684
1690
1685
1691
/*
1686
1692
* 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
1697
1703
if (!u64s )
1698
1704
continue ;
1699
1705
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 ) {
1701
1717
bch2_journal_entry_to_btree_root (c , i );
1718
+ __set_bit (i -> btree_id , & btree_roots_have );
1719
+ }
1702
1720
1703
1721
/* Can we merge with previous entry? */
1704
1722
if (prev &&
@@ -1722,35 +1740,10 @@ static void bch2_journal_entries_postprocess(struct bch_fs *c, struct jset *jset
1722
1740
1723
1741
prev = prev ? vstruct_next (prev ) : jset -> start ;
1724
1742
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 );
1750
1743
1751
1744
start = end = vstruct_last (jset );
1752
1745
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 );
1754
1747
1755
1748
bch2_journal_super_entries_add_common (c , & end ,
1756
1749
le64_to_cpu (jset -> seq ));
@@ -1872,6 +1865,8 @@ void bch2_journal_write(struct closure *cl)
1872
1865
if (ret )
1873
1866
goto err ;
1874
1867
1868
+ journal_buf_realloc (j , w );
1869
+
1875
1870
ret = bch2_journal_write_prep (j , w );
1876
1871
if (ret )
1877
1872
goto err ;
0 commit comments