| @@ -1077,68 +1077,58 @@ static CLOSURE_CALLBACK(cached_dev_nodata) · 1076 unmodified lines |
| 1077 | continue_at(cl, cached_dev_bio_complete, NULL); | 1077 | continue_at(cl, cached_dev_bio_complete, NULL); |
| 1078 | } | 1078 | } |
| 1079 | | 1079 | |
| 1080 | struct detached_dev_io_private { | | |
| 1081 | struct bcache_device *d; | | |
| 1082 | unsigned long start_time; | | |
| 1083 | bio_end_io_t *bi_end_io; | | |
| 1084 | void *bi_private; | | |
| 1085 | struct block_device *orig_bdev; | | |
| 1086 | }; | | |
| 1087 | | | |
| 1088 | static void detached_dev_end_io(struct bio *bio) | 1080 | static void detached_dev_end_io(struct bio *bio) |
| 1089 | { | 1081 | { |
| 1090 | struct detached_dev_io_private *ddip; | 1082 | struct detached_dev_io_private *ddip = |
| 1091 | | 1083 | container_of(bio, struct detached_dev_io_private, bio); |
| 1092 | ddip = bio->bi_private; | 1084 | struct bio *orig_bio = ddip->orig_bio; |
| 1093 | bio->bi_end_io = ddip->bi_end_io; | | |
| 1094 | bio->bi_private = ddip->bi_private; | | |
| 1095 | | 1085 | |
| 1096 | /* Count on the bcache device */ | 1086 | /* Count on the bcache device */ |
| 1097 | bio_end_io_acct_remapped(bio, ddip->start_time, ddip->orig_bdev); | 1087 | bio_end_io_acct(orig_bio, ddip->start_time); |
| 1098 | | 1088 | |
| 1099 | if (bio->bi_status) { | 1089 | if (bio->bi_status) { |
| 1100 | struct cached_dev *dc = container_of(ddip->d, | 1090 | struct cached_dev *dc = bio->bi_private; |
| 1101 | struct cached_dev, disk); | 1091 | |
| 1102 | /* should count I/O error for backing device here */ | 1092 | /* should count I/O error for backing device here */ |
| 1103 | bch_count_backing_io_errors(dc, bio); | 1093 | bch_count_backing_io_errors(dc, bio); |
| | 1094 | orig_bio->bi_status = bio->bi_status; |
| 1104 | } | 1095 | } |
| 1105 | | 1096 | |
| 1106 | kfree(ddip); | 1097 | bio_put(bio); |
| 1107 | bio_endio(bio); | 1098 | bio_endio(orig_bio); |
| 1108 | } | 1099 | } |
| 1109 | | 1100 | |
| 1110 | static void detached_dev_do_request(struct bcache_device *d, struct bio *bio, | 1101 | static void detached_dev_do_request(struct bcache_device *d, |
| 1111 | struct block_device *orig_bdev, unsigned long start_time) | 1102 | struct bio *orig_bio, unsigned long start_time) |
| 1112 | { | 1103 | { |
| 1113 | struct detached_dev_io_private *ddip; | 1104 | struct detached_dev_io_private *ddip; |
| 1114 | struct cached_dev *dc = container_of(d, struct cached_dev, disk); | 1105 | struct cached_dev *dc = container_of(d, struct cached_dev, disk); |
| | 1106 | struct bio *clone_bio; |
| 1115 | | 1107 | |
| 1116 | /* | 1108 | if (bio_op(orig_bio) == REQ_OP_DISCARD && |
| 1117 | * no need to call closure_get(&dc->disk.cl), | 1109 | !bdev_max_discard_sectors(dc->bdev)) { |
| 1118 | * because upper layer had already opened bcache device, | 1110 | bio_endio(orig_bio); |
| 1119 | * which would call closure_get(&dc->disk.cl) | | |
| 1120 | */ | | |
| 1121 | ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO); | | |
| 1122 | if (!ddip) { | | |
| 1123 | bio->bi_status = BLK_STS_RESOURCE; | | |
| 1124 | bio_endio(bio); | | |
| 1125 | return; | 1111 | return; |
| 1126 | } | 1112 | } |
| 1127 | | 1113 | |
| 1128 | ddip->d = d; | 1114 | clone_bio = bio_alloc_clone(dc->bdev, orig_bio, GFP_NOIO, |
| | 1115 | &d->bio_detached); |
| | 1116 | if (!clone_bio) { |
| | 1117 | orig_bio->bi_status = BLK_STS_RESOURCE; |
| | 1118 | bio_endio(orig_bio); |
| | 1119 | return; |
| | 1120 | } |
| | 1121 | |
| | 1122 | ddip = container_of(clone_bio, struct detached_dev_io_private, bio); |
| 1129 | /* Count on the bcache device */ | 1123 | /* Count on the bcache device */ |
| 1130 | ddip->orig_bdev = orig_bdev; | 1124 | ddip->d = d; |
| 1131 | ddip->start_time = start_time; | 1125 | ddip->start_time = start_time; |
| 1132 | ddip->bi_end_io = bio->bi_end_io; | 1126 | ddip->orig_bio = orig_bio; |
| 1133 | ddip->bi_private = bio->bi_private; | 1127 | |
| 1134 | bio->bi_end_io = detached_dev_end_io; | 1128 | clone_bio->bi_end_io = detached_dev_end_io; |
| 1135 | bio->bi_private = ddip; | 1129 | clone_bio->bi_private = dc; |
| 1136 | | 1130 | |
| 1137 | if ((bio_op(bio) == REQ_OP_DISCARD) && | 1131 | submit_bio_noacct(clone_bio); |
| 1138 | !bdev_max_discard_sectors(dc->bdev)) | | |
| 1139 | detached_dev_end_io(bio); | | |
| 1140 | else | | |
| 1141 | submit_bio_noacct(bio); | | |
| 1142 | } | 1132 | } |
| 1143 | | 1133 | |
| 1144 | static void quit_max_writeback_rate(struct cache_set *c, | 1134 | static void quit_max_writeback_rate(struct cache_set *c, |
| @@ -1214,10 +1204,10 @@ void cached_dev_submit_bio(struct bio *bio) · 69 unmodified lines |
| 1214 | | 1204 | |
| 1215 | start_time = bio_start_io_acct(bio); | 1205 | start_time = bio_start_io_acct(bio); |
| 1216 | | 1206 | |
| 1217 | bio_set_dev(bio, dc->bdev); | | |
| 1218 | bio->bi_iter.bi_sector += dc->sb.data_offset; | 1207 | bio->bi_iter.bi_sector += dc->sb.data_offset; |
| 1219 | | 1208 | |
| 1220 | if (cached_dev_get(dc)) { | 1209 | if (cached_dev_get(dc)) { |
| | 1210 | bio_set_dev(bio, dc->bdev); |
| 1221 | s = search_alloc(bio, d, orig_bdev, start_time); | 1211 | s = search_alloc(bio, d, orig_bdev, start_time); |
| 1222 | trace_bcache_request_start(s->d, bio); | 1212 | trace_bcache_request_start(s->d, bio); |
| 1223 | | 1213 | |
| @@ -1237,9 +1227,10 @@ void cached_dev_submit_bio(struct bio *bio) · 13 unmodified lines |
| 1237 | else | 1227 | else |
| 1238 | cached_dev_read(dc, s); | 1228 | cached_dev_read(dc, s); |
| 1239 | } | 1229 | } |
| 1240 | } else | 1230 | } else { |
| 1241 | /* I/O request sent to backing device */ | 1231 | /* I/O request sent to backing device */ |
| 1242 | detached_dev_do_request(d, bio, orig_bdev, start_time); | 1232 | detached_dev_do_request(d, bio, start_time); |
| | 1233 | } |
| 1243 | } | 1234 | } |
| 1244 | | 1235 | |
| 1245 | static int cached_dev_ioctl(struct bcache_device *d, blk_mode_t mode, | 1236 | static int cached_dev_ioctl(struct bcache_device *d, blk_mode_t mode, |