@@ -1732,103 +1732,6 @@ int __bch2_key_has_snapshot_overwrites(struct btree_trans *trans,
17321732 return ret ;
17331733}
17341734
1735- static u32 bch2_snapshot_smallest_child (struct bch_fs * c , u32 id )
1736- {
1737- const struct snapshot_t * s = snapshot_t (c , id );
1738-
1739- return s -> children [1 ] ?: s -> children [0 ];
1740- }
1741-
1742- static u32 bch2_snapshot_smallest_descendent (struct bch_fs * c , u32 id )
1743- {
1744- u32 child ;
1745-
1746- while ((child = bch2_snapshot_smallest_child (c , id )))
1747- id = child ;
1748- return id ;
1749- }
1750-
1751- static int bch2_propagate_key_to_snapshot_leaf (struct btree_trans * trans ,
1752- enum btree_id btree ,
1753- struct bkey_s_c interior_k ,
1754- u32 leaf_id , struct bpos * new_min_pos )
1755- {
1756- struct btree_iter iter ;
1757- struct bpos pos = interior_k .k -> p ;
1758- struct bkey_s_c k ;
1759- struct bkey_i * new ;
1760- int ret ;
1761-
1762- pos .snapshot = leaf_id ;
1763-
1764- bch2_trans_iter_init (trans , & iter , btree , pos , BTREE_ITER_intent );
1765- k = bch2_btree_iter_peek_slot (& iter );
1766- ret = bkey_err (k );
1767- if (ret )
1768- goto out ;
1769-
1770- /* key already overwritten in this snapshot? */
1771- if (k .k -> p .snapshot != interior_k .k -> p .snapshot )
1772- goto out ;
1773-
1774- if (bpos_eq (* new_min_pos , POS_MIN )) {
1775- * new_min_pos = k .k -> p ;
1776- new_min_pos -> snapshot = leaf_id ;
1777- }
1778-
1779- new = bch2_bkey_make_mut_noupdate (trans , interior_k );
1780- ret = PTR_ERR_OR_ZERO (new );
1781- if (ret )
1782- goto out ;
1783-
1784- new -> k .p .snapshot = leaf_id ;
1785- ret = bch2_trans_update (trans , & iter , new , 0 );
1786- out :
1787- bch2_set_btree_iter_dontneed (& iter );
1788- bch2_trans_iter_exit (trans , & iter );
1789- return ret ;
1790- }
1791-
1792- int bch2_propagate_key_to_snapshot_leaves (struct btree_trans * trans ,
1793- enum btree_id btree ,
1794- struct bkey_s_c k ,
1795- struct bpos * new_min_pos )
1796- {
1797- struct bch_fs * c = trans -> c ;
1798- struct bkey_buf sk ;
1799- u32 restart_count = trans -> restart_count ;
1800- int ret = 0 ;
1801-
1802- bch2_bkey_buf_init (& sk );
1803- bch2_bkey_buf_reassemble (& sk , c , k );
1804- k = bkey_i_to_s_c (sk .k );
1805-
1806- * new_min_pos = POS_MIN ;
1807-
1808- for (u32 id = bch2_snapshot_smallest_descendent (c , k .k -> p .snapshot );
1809- id < k .k -> p .snapshot ;
1810- id ++ ) {
1811- if (!bch2_snapshot_is_ancestor (c , id , k .k -> p .snapshot ) ||
1812- !bch2_snapshot_is_leaf (c , id ))
1813- continue ;
1814- again :
1815- ret = btree_trans_too_many_iters (trans ) ?:
1816- bch2_propagate_key_to_snapshot_leaf (trans , btree , k , id , new_min_pos ) ?:
1817- bch2_trans_commit (trans , NULL , NULL , 0 );
1818- if (ret && bch2_err_matches (ret , BCH_ERR_transaction_restart )) {
1819- bch2_trans_begin (trans );
1820- goto again ;
1821- }
1822-
1823- if (ret )
1824- break ;
1825- }
1826-
1827- bch2_bkey_buf_exit (& sk , c );
1828-
1829- return ret ?: trans_was_restarted (trans , restart_count );
1830- }
1831-
18321735static int bch2_check_snapshot_needs_deletion (struct btree_trans * trans , struct bkey_s_c k )
18331736{
18341737 struct bch_fs * c = trans -> c ;
0 commit comments