Skip to content

Commit 2c91ab7

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_dev_get_ioref() checks for device not present
Signed-off-by: Kent Overstreet <[email protected]>
1 parent 465bf6f commit 2c91ab7

File tree

9 files changed

+23
-37
lines changed

9 files changed

+23
-37
lines changed

fs/bcachefs/alloc_background.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ static int bch2_discard_one_bucket(struct btree_trans *trans,
16791679

16801680
struct bch_dev *ca = s->ca && s->ca->dev_idx == pos.inode
16811681
? s->ca
1682-
: bch2_dev_get_ioref2(c, pos.inode, WRITE);
1682+
: bch2_dev_get_ioref(c, pos.inode, WRITE);
16831683
if (!ca) {
16841684
bch2_btree_iter_set_pos(need_discard_iter, POS(pos.inode + 1, 0));
16851685
return 0;
@@ -1860,7 +1860,7 @@ static void bch2_do_discards_fast_work(struct work_struct *work)
18601860
if (i->snapshot)
18611861
continue;
18621862

1863-
ca = bch2_dev_get_ioref2(c, i->inode, WRITE);
1863+
ca = bch2_dev_get_ioref(c, i->inode, WRITE);
18641864
if (!ca) {
18651865
darray_remove_item(&c->discard_buckets_in_flight, i);
18661866
continue;

fs/bcachefs/backpointers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static int check_extent_checksum(struct btree_trans *trans,
486486

487487
bytes = p.crc.compressed_size << 9;
488488

489-
struct bch_dev *ca = bch2_dev_get_ioref2(c, dev, READ);
489+
struct bch_dev *ca = bch2_dev_get_ioref(c, dev, READ);
490490
if (!ca)
491491
return false;
492492

fs/bcachefs/btree_io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ static void btree_node_read_work(struct work_struct *work)
13081308
while (1) {
13091309
retry = true;
13101310
bch_info(c, "retrying read");
1311-
ca = bch2_dev_get_ioref2(c, rb->pick.ptr.dev, READ);
1311+
ca = bch2_dev_get_ioref(c, rb->pick.ptr.dev, READ);
13121312
rb->have_ioref = ca != NULL;
13131313
bio_reset(bio, NULL, REQ_OP_READ|REQ_SYNC|REQ_META);
13141314
bio->bi_iter.bi_sector = rb->pick.ptr.offset;
@@ -1618,7 +1618,7 @@ static int btree_node_read_all_replicas(struct bch_fs *c, struct btree *b, bool
16181618

16191619
i = 0;
16201620
bkey_for_each_ptr_decode(k.k, ptrs, pick, entry) {
1621-
struct bch_dev *ca = bch2_dev_get_ioref2(c, pick.ptr.dev, READ);
1621+
struct bch_dev *ca = bch2_dev_get_ioref(c, pick.ptr.dev, READ);
16221622
struct btree_read_bio *rb =
16231623
container_of(ra->bio[i], struct btree_read_bio, bio);
16241624
rb->c = c;
@@ -1695,7 +1695,7 @@ void bch2_btree_node_read(struct btree_trans *trans, struct btree *b,
16951695
return;
16961696
}
16971697

1698-
ca = bch2_dev_get_ioref2(c, pick.ptr.dev, READ);
1698+
ca = bch2_dev_get_ioref(c, pick.ptr.dev, READ);
16991699

17001700
bio = bio_alloc_bioset(NULL,
17011701
buf_pages(b->data, btree_buf_bytes(b)),

fs/bcachefs/debug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static bool bch2_btree_verify_replica(struct bch_fs *c, struct btree *b,
4040
struct bio *bio;
4141
bool failed = false, saw_error = false;
4242

43-
struct bch_dev *ca = bch2_dev_get_ioref2(c, pick.ptr.dev, READ);
43+
struct bch_dev *ca = bch2_dev_get_ioref(c, pick.ptr.dev, READ);
4444
if (!ca)
4545
return false;
4646

@@ -194,7 +194,7 @@ void bch2_btree_node_ondisk_to_text(struct printbuf *out, struct bch_fs *c,
194194
return;
195195
}
196196

197-
ca = bch2_dev_get_ioref2(c, pick.ptr.dev, READ);
197+
ca = bch2_dev_get_ioref(c, pick.ptr.dev, READ);
198198
if (!ca) {
199199
prt_printf(out, "error getting device to read from: not online\n");
200200
return;

fs/bcachefs/ec.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,17 @@ static void ec_block_io(struct bch_fs *c, struct ec_stripe_buf *buf,
732732
struct bch_stripe *v = &bkey_i_to_stripe(&buf->key)->v;
733733
unsigned offset = 0, bytes = buf->size << 9;
734734
struct bch_extent_ptr *ptr = &v->ptrs[idx];
735-
struct bch_dev *ca = bch2_dev_bkey_exists(c, ptr->dev);
736735
enum bch_data_type data_type = idx < v->nr_blocks - v->nr_redundant
737736
? BCH_DATA_user
738737
: BCH_DATA_parity;
739738
int rw = op_is_write(opf);
740739

740+
struct bch_dev *ca = bch2_dev_get_ioref(c, ptr->dev, rw);
741+
if (!ca) {
742+
clear_bit(idx, buf->valid);
743+
return;
744+
}
745+
741746
if (dev_ptr_stale(ca, ptr)) {
742747
bch_err_ratelimited(c,
743748
"error %s stripe: stale pointer",
@@ -746,10 +751,6 @@ static void ec_block_io(struct bch_fs *c, struct ec_stripe_buf *buf,
746751
return;
747752
}
748753

749-
if (!bch2_dev_get_ioref(ca, rw)) {
750-
clear_bit(idx, buf->valid);
751-
return;
752-
}
753754

754755
this_cpu_add(ca->io_done->sectors[rw][data_type], buf->size);
755756

@@ -1354,20 +1355,18 @@ static void zero_out_rest_of_ec_bucket(struct bch_fs *c,
13541355
unsigned block,
13551356
struct open_bucket *ob)
13561357
{
1357-
struct bch_dev *ca = bch2_dev_bkey_exists(c, ob->dev);
1358-
unsigned offset = ca->mi.bucket_size - ob->sectors_free;
1359-
int ret;
1360-
1361-
if (!bch2_dev_get_ioref(ca, WRITE)) {
1358+
struct bch_dev *ca = bch2_dev_get_ioref(c, ob->dev, WRITE);
1359+
if (!ca) {
13621360
s->err = -BCH_ERR_erofs_no_writes;
13631361
return;
13641362
}
13651363

1364+
unsigned offset = ca->mi.bucket_size - ob->sectors_free;
13661365
memset(s->new_stripe.data[block] + (offset << 9),
13671366
0,
13681367
ob->sectors_free << 9);
13691368

1370-
ret = blkdev_issue_zeroout(ca->disk_sb.bdev,
1369+
int ret = blkdev_issue_zeroout(ca->disk_sb.bdev,
13711370
ob->bucket * ca->mi.bucket_size + offset,
13721371
ob->sectors_free,
13731372
GFP_KERNEL, 0);

fs/bcachefs/io_read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ int __bch2_read_extent(struct btree_trans *trans, struct bch_read_bio *orig,
830830
goto err;
831831
}
832832

833-
struct bch_dev *ca = bch2_dev_get_ioref2(c, pick.ptr.dev, READ);
833+
struct bch_dev *ca = bch2_dev_get_ioref(c, pick.ptr.dev, READ);
834834

835835
/*
836836
* Stale dirty pointers are treated as IO errors, but @failed isn't

fs/bcachefs/io_write.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void bch2_submit_wbio_replicas(struct bch_write_bio *wbio, struct bch_fs *c,
409409
bkey_for_each_ptr(ptrs, ptr) {
410410
struct bch_dev *ca = nocow
411411
? bch2_dev_have_ref(c, ptr->dev)
412-
: bch2_dev_get_ioref2(c, ptr->dev, type == BCH_DATA_btree ? READ : WRITE);
412+
: bch2_dev_get_ioref(c, ptr->dev, type == BCH_DATA_btree ? READ : WRITE);
413413

414414
if (to_entry(ptr + 1) < ptrs.end) {
415415
n = to_wbio(bio_alloc_clone(NULL, &wbio->bio, GFP_NOFS, &c->replica_set));
@@ -1265,7 +1265,7 @@ static void bch2_nocow_write(struct bch_write_op *op)
12651265
/* Get iorefs before dropping btree locks: */
12661266
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
12671267
bkey_for_each_ptr(ptrs, ptr) {
1268-
struct bch_dev *ca = bch2_dev_get_ioref2(c, ptr->dev, WRITE);
1268+
struct bch_dev *ca = bch2_dev_get_ioref(c, ptr->dev, WRITE);
12691269
if (unlikely(!ca))
12701270
goto err_get_ioref;
12711271

fs/bcachefs/journal_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ static CLOSURE_CALLBACK(journal_write_submit)
17221722
unsigned sectors = vstruct_sectors(w->data, c->block_bits);
17231723

17241724
extent_for_each_ptr(bkey_i_to_s_extent(&w->key), ptr) {
1725-
struct bch_dev *ca = bch2_dev_get_ioref2(c, ptr->dev, WRITE);
1725+
struct bch_dev *ca = bch2_dev_get_ioref(c, ptr->dev, WRITE);
17261726
if (!ca) {
17271727
/* XXX: fix this */
17281728
bch_err(c, "missing device for journal write\n");

fs/bcachefs/sb-members.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,6 @@ static inline bool bch2_dev_is_readable(struct bch_dev *ca)
2929
ca->mi.state != BCH_MEMBER_STATE_failed;
3030
}
3131

32-
static inline bool bch2_dev_get_ioref(struct bch_dev *ca, int rw)
33-
{
34-
if (!percpu_ref_tryget(&ca->io_ref))
35-
return false;
36-
37-
if (ca->mi.state == BCH_MEMBER_STATE_rw ||
38-
(ca->mi.state == BCH_MEMBER_STATE_ro && rw == READ))
39-
return true;
40-
41-
percpu_ref_put(&ca->io_ref);
42-
return false;
43-
}
44-
4532
static inline unsigned dev_mask_nr(const struct bch_devs_mask *devs)
4633
{
4734
return bitmap_weight(devs->d, BCH_SB_MEMBERS_MAX);
@@ -285,7 +272,7 @@ static inline struct bch_dev *bch2_dev_iterate(struct bch_fs *c, struct bch_dev
285272
return bch2_dev_tryget(c, dev_idx);
286273
}
287274

288-
static inline struct bch_dev *bch2_dev_get_ioref2(struct bch_fs *c, unsigned dev, int rw)
275+
static inline struct bch_dev *bch2_dev_get_ioref(struct bch_fs *c, unsigned dev, int rw)
289276
{
290277
rcu_read_lock();
291278
struct bch_dev *ca = bch2_dev_rcu(c, dev);

0 commit comments

Comments
 (0)