@@ -1109,7 +1109,7 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
1109
1109
nonce = btree_nonce (i , b -> written << 9 );
1110
1110
struct bch_csum csum = csum_vstruct (c , BSET_CSUM_TYPE (i ), nonce , bne );
1111
1111
csum_bad = bch2_crc_cmp (bne -> csum , csum );
1112
- if (csum_bad )
1112
+ if (ca && csum_bad )
1113
1113
bch2_io_error (ca , BCH_MEMBER_ERROR_checksum );
1114
1114
1115
1115
btree_err_on (csum_bad ,
@@ -1263,12 +1263,14 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
1263
1263
1264
1264
btree_node_reset_sib_u64s (b );
1265
1265
1266
+ rcu_read_lock ();
1266
1267
bkey_for_each_ptr (bch2_bkey_ptrs (bkey_i_to_s (& b -> key )), ptr ) {
1267
- struct bch_dev * ca2 = bch2_dev_bkey_exists (c , ptr -> dev );
1268
+ struct bch_dev * ca2 = bch2_dev_rcu (c , ptr -> dev );
1268
1269
1269
- if (ca2 -> mi .state != BCH_MEMBER_STATE_rw )
1270
+ if (! ca2 || ca2 -> mi .state != BCH_MEMBER_STATE_rw )
1270
1271
set_btree_node_need_rewrite (b );
1271
1272
}
1273
+ rcu_read_unlock ();
1272
1274
1273
1275
if (!ptr_written )
1274
1276
set_btree_node_need_rewrite (b );
@@ -1293,8 +1295,8 @@ static void btree_node_read_work(struct work_struct *work)
1293
1295
struct btree_read_bio * rb =
1294
1296
container_of (work , struct btree_read_bio , work );
1295
1297
struct bch_fs * c = rb -> c ;
1298
+ struct bch_dev * ca = rb -> have_ioref ? bch2_dev_have_ref (c , rb -> pick .ptr .dev ) : NULL ;
1296
1299
struct btree * b = rb -> b ;
1297
- struct bch_dev * ca = bch2_dev_bkey_exists (c , rb -> pick .ptr .dev );
1298
1300
struct bio * bio = & rb -> bio ;
1299
1301
struct bch_io_failures failed = { .nr = 0 };
1300
1302
struct printbuf buf = PRINTBUF ;
@@ -1306,8 +1308,8 @@ static void btree_node_read_work(struct work_struct *work)
1306
1308
while (1 ) {
1307
1309
retry = true;
1308
1310
bch_info (c , "retrying read" );
1309
- ca = bch2_dev_bkey_exists (c , rb -> pick .ptr .dev );
1310
- rb -> have_ioref = bch2_dev_get_ioref ( ca , READ ) ;
1311
+ ca = bch2_dev_get_ioref2 (c , rb -> pick .ptr .dev , READ );
1312
+ rb -> have_ioref = ca != NULL ;
1311
1313
bio_reset (bio , NULL , REQ_OP_READ |REQ_SYNC |REQ_META );
1312
1314
bio -> bi_iter .bi_sector = rb -> pick .ptr .offset ;
1313
1315
bio -> bi_iter .bi_size = btree_buf_bytes (b );
@@ -1321,7 +1323,7 @@ static void btree_node_read_work(struct work_struct *work)
1321
1323
start :
1322
1324
printbuf_reset (& buf );
1323
1325
bch2_btree_pos_to_text (& buf , c , b );
1324
- bch2_dev_io_err_on (bio -> bi_status , ca , BCH_MEMBER_ERROR_read ,
1326
+ bch2_dev_io_err_on (ca && bio -> bi_status , ca , BCH_MEMBER_ERROR_read ,
1325
1327
"btree read error %s for %s" ,
1326
1328
bch2_blk_status_to_str (bio -> bi_status ), buf .buf );
1327
1329
if (rb -> have_ioref )
@@ -1377,7 +1379,7 @@ static void btree_node_read_endio(struct bio *bio)
1377
1379
struct bch_fs * c = rb -> c ;
1378
1380
1379
1381
if (rb -> have_ioref ) {
1380
- struct bch_dev * ca = bch2_dev_bkey_exists (c , rb -> pick .ptr .dev );
1382
+ struct bch_dev * ca = bch2_dev_have_ref (c , rb -> pick .ptr .dev );
1381
1383
1382
1384
bch2_latency_acct (ca , rb -> start_time , READ );
1383
1385
}
@@ -1574,7 +1576,7 @@ static void btree_node_read_all_replicas_endio(struct bio *bio)
1574
1576
struct btree_node_read_all * ra = rb -> ra ;
1575
1577
1576
1578
if (rb -> have_ioref ) {
1577
- struct bch_dev * ca = bch2_dev_bkey_exists (c , rb -> pick .ptr .dev );
1579
+ struct bch_dev * ca = bch2_dev_have_ref (c , rb -> pick .ptr .dev );
1578
1580
1579
1581
bch2_latency_acct (ca , rb -> start_time , READ );
1580
1582
}
@@ -1616,14 +1618,14 @@ static int btree_node_read_all_replicas(struct bch_fs *c, struct btree *b, bool
1616
1618
1617
1619
i = 0 ;
1618
1620
bkey_for_each_ptr_decode (k .k , ptrs , pick , entry ) {
1619
- struct bch_dev * ca = bch2_dev_bkey_exists (c , pick .ptr .dev );
1621
+ struct bch_dev * ca = bch2_dev_get_ioref2 (c , pick .ptr .dev , READ );
1620
1622
struct btree_read_bio * rb =
1621
1623
container_of (ra -> bio [i ], struct btree_read_bio , bio );
1622
1624
rb -> c = c ;
1623
1625
rb -> b = b ;
1624
1626
rb -> ra = ra ;
1625
1627
rb -> start_time = local_clock ();
1626
- rb -> have_ioref = bch2_dev_get_ioref ( ca , READ ) ;
1628
+ rb -> have_ioref = ca != NULL ;
1627
1629
rb -> idx = i ;
1628
1630
rb -> pick = pick ;
1629
1631
rb -> bio .bi_iter .bi_sector = pick .ptr .offset ;
@@ -1693,7 +1695,7 @@ void bch2_btree_node_read(struct btree_trans *trans, struct btree *b,
1693
1695
return ;
1694
1696
}
1695
1697
1696
- ca = bch2_dev_bkey_exists (c , pick .ptr .dev );
1698
+ ca = bch2_dev_get_ioref2 (c , pick .ptr .dev , READ );
1697
1699
1698
1700
bio = bio_alloc_bioset (NULL ,
1699
1701
buf_pages (b -> data , btree_buf_bytes (b )),
@@ -1705,7 +1707,7 @@ void bch2_btree_node_read(struct btree_trans *trans, struct btree *b,
1705
1707
rb -> b = b ;
1706
1708
rb -> ra = NULL ;
1707
1709
rb -> start_time = local_clock ();
1708
- rb -> have_ioref = bch2_dev_get_ioref ( ca , READ ) ;
1710
+ rb -> have_ioref = ca != NULL ;
1709
1711
rb -> pick = pick ;
1710
1712
INIT_WORK (& rb -> work , btree_node_read_work );
1711
1713
bio -> bi_iter .bi_sector = pick .ptr .offset ;
@@ -1909,13 +1911,14 @@ static void btree_node_write_endio(struct bio *bio)
1909
1911
struct btree_write_bio * wb = container_of (orig , struct btree_write_bio , wbio );
1910
1912
struct bch_fs * c = wbio -> c ;
1911
1913
struct btree * b = wbio -> bio .bi_private ;
1912
- struct bch_dev * ca = bch2_dev_bkey_exists (c , wbio -> dev );
1914
+ struct bch_dev * ca = wbio -> have_ioref ? bch2_dev_have_ref (c , wbio -> dev ) : NULL ;
1913
1915
unsigned long flags ;
1914
1916
1915
1917
if (wbio -> have_ioref )
1916
1918
bch2_latency_acct (ca , wbio -> submit_time , WRITE );
1917
1919
1918
- if (bch2_dev_io_err_on (bio -> bi_status , ca , BCH_MEMBER_ERROR_write ,
1920
+ if (!ca ||
1921
+ bch2_dev_io_err_on (bio -> bi_status , ca , BCH_MEMBER_ERROR_write ,
1919
1922
"btree write error: %s" ,
1920
1923
bch2_blk_status_to_str (bio -> bi_status )) ||
1921
1924
bch2_meta_write_fault ("btree" )) {
0 commit comments