@@ -800,7 +800,6 @@ int __bch2_read_extent(struct btree_trans *trans, struct bch_read_bio *orig,
800800 struct bch_fs * c = trans -> c ;
801801 struct extent_ptr_decoded pick ;
802802 struct bch_read_bio * rbio = NULL ;
803- struct bch_dev * ca = NULL ;
804803 struct promote_op * promote = NULL ;
805804 bool bounce = false, read_full = false, narrow_crcs = false;
806805 struct bpos data_pos = bkey_start_pos (k .k );
@@ -831,7 +830,7 @@ int __bch2_read_extent(struct btree_trans *trans, struct bch_read_bio *orig,
831830 goto err ;
832831 }
833832
834- ca = bch2_dev_bkey_exists (c , pick .ptr .dev );
833+ struct bch_dev * ca = bch2_dev_get_ioref2 (c , pick .ptr .dev , READ );
835834
836835 /*
837836 * Stale dirty pointers are treated as IO errors, but @failed isn't
@@ -841,9 +840,11 @@ int __bch2_read_extent(struct btree_trans *trans, struct bch_read_bio *orig,
841840 */
842841 if ((flags & BCH_READ_IN_RETRY ) &&
843842 !pick .ptr .cached &&
843+ ca &&
844844 unlikely (dev_ptr_stale (ca , & pick .ptr ))) {
845845 read_from_stale_dirty_pointer (trans , ca , k , pick .ptr );
846846 bch2_mark_io_failure (failed , & pick );
847+ percpu_ref_put (& ca -> io_ref );
847848 goto retry_pick ;
848849 }
849850
@@ -858,8 +859,11 @@ int __bch2_read_extent(struct btree_trans *trans, struct bch_read_bio *orig,
858859 * can happen if we retry, and the extent we were going to read
859860 * has been merged in the meantime:
860861 */
861- if (pick .crc .compressed_size > orig -> bio .bi_vcnt * PAGE_SECTORS )
862+ if (pick .crc .compressed_size > orig -> bio .bi_vcnt * PAGE_SECTORS ) {
863+ if (ca )
864+ percpu_ref_put (& ca -> io_ref );
862865 goto hole ;
866+ }
863867
864868 iter .bi_size = pick .crc .compressed_size << 9 ;
865869 goto get_bio ;
@@ -964,7 +968,7 @@ int __bch2_read_extent(struct btree_trans *trans, struct bch_read_bio *orig,
964968 rbio -> bvec_iter = iter ;
965969 rbio -> offset_into_extent = offset_into_extent ;
966970 rbio -> flags = flags ;
967- rbio -> have_ioref = pick_ret > 0 && bch2_dev_get_ioref ( ca , READ ) ;
971+ rbio -> have_ioref = ca != NULL ;
968972 rbio -> narrow_crcs = narrow_crcs ;
969973 rbio -> hole = 0 ;
970974 rbio -> retry = 0 ;
@@ -994,7 +998,7 @@ int __bch2_read_extent(struct btree_trans *trans, struct bch_read_bio *orig,
994998 * If it's being moved internally, we don't want to flag it as a cache
995999 * hit:
9961000 */
997- if (pick .ptr .cached && !(flags & BCH_READ_NODECODE ))
1001+ if (ca && pick .ptr .cached && !(flags & BCH_READ_NODECODE ))
9981002 bch2_bucket_io_time_reset (trans , pick .ptr .dev ,
9991003 PTR_BUCKET_NR (ca , & pick .ptr ), READ );
10001004
0 commit comments