diff options
author | Namhyung Kim <namhyung@gmail.com> | 2011-07-18 03:38:47 -0400 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2011-07-18 03:38:47 -0400 |
commit | 778ca01852e6cc9ff335119b37a1938a978df384 (patch) | |
tree | 845221188a1ffaafddac1041c8ced88ac9e6d8c2 /drivers/md/raid10.c | |
parent | 2c4193df379bb89114ff60d4b0fa66131abe6a75 (diff) |
md/raid10: factor out common bio handling code
When normal-write and sync-read/write bio completes, we should
find out the disk number the bio belongs to. Factor those common
code out to a separate function.
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers/md/raid10.c')
-rw-r--r-- | drivers/md/raid10.c | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index d55ae12b2d8c..e434f1e8d223 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c | |||
@@ -244,6 +244,23 @@ static inline void update_head_pos(int slot, r10bio_t *r10_bio) | |||
244 | r10_bio->devs[slot].addr + (r10_bio->sectors); | 244 | r10_bio->devs[slot].addr + (r10_bio->sectors); |
245 | } | 245 | } |
246 | 246 | ||
247 | /* | ||
248 | * Find the disk number which triggered given bio | ||
249 | */ | ||
250 | static int find_bio_disk(conf_t *conf, r10bio_t *r10_bio, struct bio *bio) | ||
251 | { | ||
252 | int slot; | ||
253 | |||
254 | for (slot = 0; slot < conf->copies; slot++) | ||
255 | if (r10_bio->devs[slot].bio == bio) | ||
256 | break; | ||
257 | |||
258 | BUG_ON(slot == conf->copies); | ||
259 | update_head_pos(slot, r10_bio); | ||
260 | |||
261 | return r10_bio->devs[slot].devnum; | ||
262 | } | ||
263 | |||
247 | static void raid10_end_read_request(struct bio *bio, int error) | 264 | static void raid10_end_read_request(struct bio *bio, int error) |
248 | { | 265 | { |
249 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); | 266 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
@@ -289,13 +306,10 @@ static void raid10_end_write_request(struct bio *bio, int error) | |||
289 | { | 306 | { |
290 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); | 307 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
291 | r10bio_t *r10_bio = bio->bi_private; | 308 | r10bio_t *r10_bio = bio->bi_private; |
292 | int slot, dev; | 309 | int dev; |
293 | conf_t *conf = r10_bio->mddev->private; | 310 | conf_t *conf = r10_bio->mddev->private; |
294 | 311 | ||
295 | for (slot = 0; slot < conf->copies; slot++) | 312 | dev = find_bio_disk(conf, r10_bio, bio); |
296 | if (r10_bio->devs[slot].bio == bio) | ||
297 | break; | ||
298 | dev = r10_bio->devs[slot].devnum; | ||
299 | 313 | ||
300 | /* | 314 | /* |
301 | * this branch is our 'one mirror IO has finished' event handler: | 315 | * this branch is our 'one mirror IO has finished' event handler: |
@@ -316,8 +330,6 @@ static void raid10_end_write_request(struct bio *bio, int error) | |||
316 | */ | 330 | */ |
317 | set_bit(R10BIO_Uptodate, &r10_bio->state); | 331 | set_bit(R10BIO_Uptodate, &r10_bio->state); |
318 | 332 | ||
319 | update_head_pos(slot, r10_bio); | ||
320 | |||
321 | /* | 333 | /* |
322 | * | 334 | * |
323 | * Let's see if all mirrored write operations have finished | 335 | * Let's see if all mirrored write operations have finished |
@@ -1173,14 +1185,9 @@ static void end_sync_read(struct bio *bio, int error) | |||
1173 | { | 1185 | { |
1174 | r10bio_t *r10_bio = bio->bi_private; | 1186 | r10bio_t *r10_bio = bio->bi_private; |
1175 | conf_t *conf = r10_bio->mddev->private; | 1187 | conf_t *conf = r10_bio->mddev->private; |
1176 | int i,d; | 1188 | int d; |
1177 | 1189 | ||
1178 | for (i=0; i<conf->copies; i++) | 1190 | d = find_bio_disk(conf, r10_bio, bio); |
1179 | if (r10_bio->devs[i].bio == bio) | ||
1180 | break; | ||
1181 | BUG_ON(i == conf->copies); | ||
1182 | update_head_pos(i, r10_bio); | ||
1183 | d = r10_bio->devs[i].devnum; | ||
1184 | 1191 | ||
1185 | if (test_bit(BIO_UPTODATE, &bio->bi_flags)) | 1192 | if (test_bit(BIO_UPTODATE, &bio->bi_flags)) |
1186 | set_bit(R10BIO_Uptodate, &r10_bio->state); | 1193 | set_bit(R10BIO_Uptodate, &r10_bio->state); |
@@ -1211,18 +1218,13 @@ static void end_sync_write(struct bio *bio, int error) | |||
1211 | r10bio_t *r10_bio = bio->bi_private; | 1218 | r10bio_t *r10_bio = bio->bi_private; |
1212 | mddev_t *mddev = r10_bio->mddev; | 1219 | mddev_t *mddev = r10_bio->mddev; |
1213 | conf_t *conf = mddev->private; | 1220 | conf_t *conf = mddev->private; |
1214 | int i,d; | 1221 | int d; |
1215 | 1222 | ||
1216 | for (i = 0; i < conf->copies; i++) | 1223 | d = find_bio_disk(conf, r10_bio, bio); |
1217 | if (r10_bio->devs[i].bio == bio) | ||
1218 | break; | ||
1219 | d = r10_bio->devs[i].devnum; | ||
1220 | 1224 | ||
1221 | if (!uptodate) | 1225 | if (!uptodate) |
1222 | md_error(mddev, conf->mirrors[d].rdev); | 1226 | md_error(mddev, conf->mirrors[d].rdev); |
1223 | 1227 | ||
1224 | update_head_pos(i, r10_bio); | ||
1225 | |||
1226 | rdev_dec_pending(conf->mirrors[d].rdev, mddev); | 1228 | rdev_dec_pending(conf->mirrors[d].rdev, mddev); |
1227 | while (atomic_dec_and_test(&r10_bio->remaining)) { | 1229 | while (atomic_dec_and_test(&r10_bio->remaining)) { |
1228 | if (r10_bio->master_bio == NULL) { | 1230 | if (r10_bio->master_bio == NULL) { |