Skip to content

Commit 690f7cd

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_dev_get_ioref2(); btree_io.c
Signed-off-by: Kent Overstreet <[email protected]>
1 parent 466298e commit 690f7cd

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

fs/bcachefs/btree_io.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
11091109
nonce = btree_nonce(i, b->written << 9);
11101110
struct bch_csum csum = csum_vstruct(c, BSET_CSUM_TYPE(i), nonce, bne);
11111111
csum_bad = bch2_crc_cmp(bne->csum, csum);
1112-
if (csum_bad)
1112+
if (ca && csum_bad)
11131113
bch2_io_error(ca, BCH_MEMBER_ERROR_checksum);
11141114

11151115
btree_err_on(csum_bad,
@@ -1263,12 +1263,14 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
12631263

12641264
btree_node_reset_sib_u64s(b);
12651265

1266+
rcu_read_lock();
12661267
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);
12681269

1269-
if (ca2->mi.state != BCH_MEMBER_STATE_rw)
1270+
if (!ca2 || ca2->mi.state != BCH_MEMBER_STATE_rw)
12701271
set_btree_node_need_rewrite(b);
12711272
}
1273+
rcu_read_unlock();
12721274

12731275
if (!ptr_written)
12741276
set_btree_node_need_rewrite(b);
@@ -1293,8 +1295,8 @@ static void btree_node_read_work(struct work_struct *work)
12931295
struct btree_read_bio *rb =
12941296
container_of(work, struct btree_read_bio, work);
12951297
struct bch_fs *c = rb->c;
1298+
struct bch_dev *ca = rb->have_ioref ? bch2_dev_have_ref(c, rb->pick.ptr.dev) : NULL;
12961299
struct btree *b = rb->b;
1297-
struct bch_dev *ca = bch2_dev_bkey_exists(c, rb->pick.ptr.dev);
12981300
struct bio *bio = &rb->bio;
12991301
struct bch_io_failures failed = { .nr = 0 };
13001302
struct printbuf buf = PRINTBUF;
@@ -1306,8 +1308,8 @@ static void btree_node_read_work(struct work_struct *work)
13061308
while (1) {
13071309
retry = true;
13081310
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;
13111313
bio_reset(bio, NULL, REQ_OP_READ|REQ_SYNC|REQ_META);
13121314
bio->bi_iter.bi_sector = rb->pick.ptr.offset;
13131315
bio->bi_iter.bi_size = btree_buf_bytes(b);
@@ -1321,7 +1323,7 @@ static void btree_node_read_work(struct work_struct *work)
13211323
start:
13221324
printbuf_reset(&buf);
13231325
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,
13251327
"btree read error %s for %s",
13261328
bch2_blk_status_to_str(bio->bi_status), buf.buf);
13271329
if (rb->have_ioref)
@@ -1377,7 +1379,7 @@ static void btree_node_read_endio(struct bio *bio)
13771379
struct bch_fs *c = rb->c;
13781380

13791381
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);
13811383

13821384
bch2_latency_acct(ca, rb->start_time, READ);
13831385
}
@@ -1574,7 +1576,7 @@ static void btree_node_read_all_replicas_endio(struct bio *bio)
15741576
struct btree_node_read_all *ra = rb->ra;
15751577

15761578
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);
15781580

15791581
bch2_latency_acct(ca, rb->start_time, READ);
15801582
}
@@ -1616,14 +1618,14 @@ static int btree_node_read_all_replicas(struct bch_fs *c, struct btree *b, bool
16161618

16171619
i = 0;
16181620
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);
16201622
struct btree_read_bio *rb =
16211623
container_of(ra->bio[i], struct btree_read_bio, bio);
16221624
rb->c = c;
16231625
rb->b = b;
16241626
rb->ra = ra;
16251627
rb->start_time = local_clock();
1626-
rb->have_ioref = bch2_dev_get_ioref(ca, READ);
1628+
rb->have_ioref = ca != NULL;
16271629
rb->idx = i;
16281630
rb->pick = pick;
16291631
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,
16931695
return;
16941696
}
16951697

1696-
ca = bch2_dev_bkey_exists(c, pick.ptr.dev);
1698+
ca = bch2_dev_get_ioref2(c, pick.ptr.dev, READ);
16971699

16981700
bio = bio_alloc_bioset(NULL,
16991701
buf_pages(b->data, btree_buf_bytes(b)),
@@ -1705,7 +1707,7 @@ void bch2_btree_node_read(struct btree_trans *trans, struct btree *b,
17051707
rb->b = b;
17061708
rb->ra = NULL;
17071709
rb->start_time = local_clock();
1708-
rb->have_ioref = bch2_dev_get_ioref(ca, READ);
1710+
rb->have_ioref = ca != NULL;
17091711
rb->pick = pick;
17101712
INIT_WORK(&rb->work, btree_node_read_work);
17111713
bio->bi_iter.bi_sector = pick.ptr.offset;
@@ -1909,13 +1911,14 @@ static void btree_node_write_endio(struct bio *bio)
19091911
struct btree_write_bio *wb = container_of(orig, struct btree_write_bio, wbio);
19101912
struct bch_fs *c = wbio->c;
19111913
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;
19131915
unsigned long flags;
19141916

19151917
if (wbio->have_ioref)
19161918
bch2_latency_acct(ca, wbio->submit_time, WRITE);
19171919

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,
19191922
"btree write error: %s",
19201923
bch2_blk_status_to_str(bio->bi_status)) ||
19211924
bch2_meta_write_fault("btree")) {

0 commit comments

Comments
 (0)