Skip to content

Commit 8feecbe

Browse files
author
Kent Overstreet
committed
bcachefs: extent_ptr_invalid() -> bch2_dev_rcu()
Signed-off-by: Kent Overstreet <[email protected]>
1 parent 3858aa4 commit 8feecbe

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

fs/bcachefs/extents.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,6 @@ static int extent_ptr_invalid(struct bch_fs *c,
10831083
struct printbuf *err)
10841084
{
10851085
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
1086-
u64 bucket;
1087-
u32 bucket_offset;
1088-
struct bch_dev *ca;
10891086
int ret = 0;
10901087

10911088
if (!bch2_dev_exists(c, ptr->dev)) {
@@ -1101,24 +1098,35 @@ static int extent_ptr_invalid(struct bch_fs *c,
11011098
"pointer to invalid device (%u)", ptr->dev);
11021099
}
11031100

1104-
ca = bch2_dev_bkey_exists(c, ptr->dev);
1101+
rcu_read_lock();
1102+
struct bch_dev *ca = bch2_dev_rcu(c, ptr->dev);
1103+
if (!ca) {
1104+
rcu_read_unlock();
1105+
return 0;
1106+
}
1107+
u32 bucket_offset;
1108+
u64 bucket = sector_to_bucket_and_offset(ca, ptr->offset, &bucket_offset);
1109+
unsigned first_bucket = ca->mi.first_bucket;
1110+
u64 nbuckets = ca->mi.nbuckets;
1111+
unsigned bucket_size = ca->mi.bucket_size;
1112+
rcu_read_unlock();
1113+
11051114
bkey_for_each_ptr(ptrs, ptr2)
11061115
bkey_fsck_err_on(ptr != ptr2 && ptr->dev == ptr2->dev, c, err,
11071116
ptr_to_duplicate_device,
11081117
"multiple pointers to same device (%u)", ptr->dev);
11091118

1110-
bucket = sector_to_bucket_and_offset(ca, ptr->offset, &bucket_offset);
11111119

1112-
bkey_fsck_err_on(bucket >= ca->mi.nbuckets, c, err,
1120+
bkey_fsck_err_on(bucket >= nbuckets, c, err,
11131121
ptr_after_last_bucket,
1114-
"pointer past last bucket (%llu > %llu)", bucket, ca->mi.nbuckets);
1115-
bkey_fsck_err_on(ptr->offset < bucket_to_sector(ca, ca->mi.first_bucket), c, err,
1122+
"pointer past last bucket (%llu > %llu)", bucket, nbuckets);
1123+
bkey_fsck_err_on(bucket < first_bucket, c, err,
11161124
ptr_before_first_bucket,
1117-
"pointer before first bucket (%llu < %u)", bucket, ca->mi.first_bucket);
1118-
bkey_fsck_err_on(bucket_offset + size_ondisk > ca->mi.bucket_size, c, err,
1125+
"pointer before first bucket (%llu < %u)", bucket, first_bucket);
1126+
bkey_fsck_err_on(bucket_offset + size_ondisk > bucket_size, c, err,
11191127
ptr_spans_multiple_buckets,
11201128
"pointer spans multiple buckets (%u + %u > %u)",
1121-
bucket_offset, size_ondisk, ca->mi.bucket_size);
1129+
bucket_offset, size_ondisk, bucket_size);
11221130
fsck_err:
11231131
return ret;
11241132
}

0 commit comments

Comments
 (0)