@@ -1280,23 +1280,29 @@ static void bch2_btree_set_root_inmem(struct bch_fs *c, struct btree *b)
1280
1280
bch2_recalc_btree_reserve (c );
1281
1281
}
1282
1282
1283
- static void bch2_btree_set_root (struct btree_update * as ,
1284
- struct btree_trans * trans ,
1285
- struct btree_path * path ,
1286
- struct btree * b )
1283
+ static int bch2_btree_set_root (struct btree_update * as ,
1284
+ struct btree_trans * trans ,
1285
+ struct btree_path * path ,
1286
+ struct btree * b ,
1287
+ bool nofail )
1287
1288
{
1288
1289
struct bch_fs * c = as -> c ;
1289
- struct btree * old ;
1290
1290
1291
1291
trace_and_count (c , btree_node_set_root , trans , b );
1292
1292
1293
- old = btree_node_root (c , b );
1293
+ struct btree * old = btree_node_root (c , b );
1294
1294
1295
1295
/*
1296
1296
* Ensure no one is using the old root while we switch to the
1297
1297
* new root:
1298
1298
*/
1299
- bch2_btree_node_lock_write_nofail (trans , path , & old -> c );
1299
+ if (nofail ) {
1300
+ bch2_btree_node_lock_write_nofail (trans , path , & old -> c );
1301
+ } else {
1302
+ int ret = bch2_btree_node_lock_write (trans , path , & old -> c );
1303
+ if (ret )
1304
+ return ret ;
1305
+ }
1300
1306
1301
1307
bch2_btree_set_root_inmem (c , b );
1302
1308
@@ -1310,6 +1316,7 @@ static void bch2_btree_set_root(struct btree_update *as,
1310
1316
* depend on the new root would have to update the new root.
1311
1317
*/
1312
1318
bch2_btree_node_unlock_write (trans , path , old );
1319
+ return 0 ;
1313
1320
}
1314
1321
1315
1322
/* Interior node updates: */
@@ -1652,15 +1659,16 @@ static int btree_split(struct btree_update *as, struct btree_trans *trans,
1652
1659
if (parent ) {
1653
1660
/* Split a non root node */
1654
1661
ret = bch2_btree_insert_node (as , trans , path , parent , & as -> parent_keys );
1655
- if (ret )
1656
- goto err ;
1657
1662
} else if (n3 ) {
1658
- bch2_btree_set_root (as , trans , trans -> paths + path , n3 );
1663
+ ret = bch2_btree_set_root (as , trans , trans -> paths + path , n3 , false );
1659
1664
} else {
1660
1665
/* Root filled up but didn't need to be split */
1661
- bch2_btree_set_root (as , trans , trans -> paths + path , n1 );
1666
+ ret = bch2_btree_set_root (as , trans , trans -> paths + path , n1 , false );
1662
1667
}
1663
1668
1669
+ if (ret )
1670
+ goto err ;
1671
+
1664
1672
if (n3 ) {
1665
1673
bch2_btree_update_get_open_buckets (as , n3 );
1666
1674
bch2_btree_node_write (c , n3 , SIX_LOCK_intent , 0 );
@@ -1863,7 +1871,9 @@ static void __btree_increase_depth(struct btree_update *as, struct btree_trans *
1863
1871
bch2_keylist_add (& as -> parent_keys , & b -> key );
1864
1872
btree_split_insert_keys (as , trans , path_idx , n , & as -> parent_keys );
1865
1873
1866
- bch2_btree_set_root (as , trans , path , n );
1874
+ int ret = bch2_btree_set_root (as , trans , path , n , true);
1875
+ BUG_ON (ret );
1876
+
1867
1877
bch2_btree_update_get_open_buckets (as , n );
1868
1878
bch2_btree_node_write (c , n , SIX_LOCK_intent , 0 );
1869
1879
bch2_trans_node_add (trans , path , n );
@@ -2106,12 +2116,13 @@ int bch2_btree_node_rewrite(struct btree_trans *trans,
2106
2116
if (parent ) {
2107
2117
bch2_keylist_add (& as -> parent_keys , & n -> key );
2108
2118
ret = bch2_btree_insert_node (as , trans , iter -> path , parent , & as -> parent_keys );
2109
- if (ret )
2110
- goto err ;
2111
2119
} else {
2112
- bch2_btree_set_root (as , trans , btree_iter_path (trans , iter ), n );
2120
+ ret = bch2_btree_set_root (as , trans , btree_iter_path (trans , iter ), n , false );
2113
2121
}
2114
2122
2123
+ if (ret )
2124
+ goto err ;
2125
+
2115
2126
bch2_btree_update_get_open_buckets (as , n );
2116
2127
bch2_btree_node_write (c , n , SIX_LOCK_intent , 0 );
2117
2128
0 commit comments