diff options
Diffstat (limited to 'drivers/md/raid1.c')
-rw-r--r-- | drivers/md/raid1.c | 360 |
1 files changed, 192 insertions, 168 deletions
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 32323f0afd89..ede2461e79c5 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c | |||
@@ -34,28 +34,31 @@ | |||
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/delay.h> | 35 | #include <linux/delay.h> |
36 | #include <linux/blkdev.h> | 36 | #include <linux/blkdev.h> |
37 | #include <linux/module.h> | ||
37 | #include <linux/seq_file.h> | 38 | #include <linux/seq_file.h> |
38 | #include <linux/ratelimit.h> | 39 | #include <linux/ratelimit.h> |
39 | #include "md.h" | 40 | #include "md.h" |
40 | #include "raid1.h" | 41 | #include "raid1.h" |
41 | #include "bitmap.h" | 42 | #include "bitmap.h" |
42 | 43 | ||
43 | #define DEBUG 0 | ||
44 | #define PRINTK(x...) do { if (DEBUG) printk(x); } while (0) | ||
45 | |||
46 | /* | 44 | /* |
47 | * Number of guaranteed r1bios in case of extreme VM load: | 45 | * Number of guaranteed r1bios in case of extreme VM load: |
48 | */ | 46 | */ |
49 | #define NR_RAID1_BIOS 256 | 47 | #define NR_RAID1_BIOS 256 |
50 | 48 | ||
49 | /* When there are this many requests queue to be written by | ||
50 | * the raid1 thread, we become 'congested' to provide back-pressure | ||
51 | * for writeback. | ||
52 | */ | ||
53 | static int max_queued_requests = 1024; | ||
51 | 54 | ||
52 | static void allow_barrier(conf_t *conf); | 55 | static void allow_barrier(struct r1conf *conf); |
53 | static void lower_barrier(conf_t *conf); | 56 | static void lower_barrier(struct r1conf *conf); |
54 | 57 | ||
55 | static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data) | 58 | static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data) |
56 | { | 59 | { |
57 | struct pool_info *pi = data; | 60 | struct pool_info *pi = data; |
58 | int size = offsetof(r1bio_t, bios[pi->raid_disks]); | 61 | int size = offsetof(struct r1bio, bios[pi->raid_disks]); |
59 | 62 | ||
60 | /* allocate a r1bio with room for raid_disks entries in the bios array */ | 63 | /* allocate a r1bio with room for raid_disks entries in the bios array */ |
61 | return kzalloc(size, gfp_flags); | 64 | return kzalloc(size, gfp_flags); |
@@ -76,7 +79,7 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data) | |||
76 | { | 79 | { |
77 | struct pool_info *pi = data; | 80 | struct pool_info *pi = data; |
78 | struct page *page; | 81 | struct page *page; |
79 | r1bio_t *r1_bio; | 82 | struct r1bio *r1_bio; |
80 | struct bio *bio; | 83 | struct bio *bio; |
81 | int i, j; | 84 | int i, j; |
82 | 85 | ||
@@ -142,7 +145,7 @@ static void r1buf_pool_free(void *__r1_bio, void *data) | |||
142 | { | 145 | { |
143 | struct pool_info *pi = data; | 146 | struct pool_info *pi = data; |
144 | int i,j; | 147 | int i,j; |
145 | r1bio_t *r1bio = __r1_bio; | 148 | struct r1bio *r1bio = __r1_bio; |
146 | 149 | ||
147 | for (i = 0; i < RESYNC_PAGES; i++) | 150 | for (i = 0; i < RESYNC_PAGES; i++) |
148 | for (j = pi->raid_disks; j-- ;) { | 151 | for (j = pi->raid_disks; j-- ;) { |
@@ -157,7 +160,7 @@ static void r1buf_pool_free(void *__r1_bio, void *data) | |||
157 | r1bio_pool_free(r1bio, data); | 160 | r1bio_pool_free(r1bio, data); |
158 | } | 161 | } |
159 | 162 | ||
160 | static void put_all_bios(conf_t *conf, r1bio_t *r1_bio) | 163 | static void put_all_bios(struct r1conf *conf, struct r1bio *r1_bio) |
161 | { | 164 | { |
162 | int i; | 165 | int i; |
163 | 166 | ||
@@ -169,17 +172,17 @@ static void put_all_bios(conf_t *conf, r1bio_t *r1_bio) | |||
169 | } | 172 | } |
170 | } | 173 | } |
171 | 174 | ||
172 | static void free_r1bio(r1bio_t *r1_bio) | 175 | static void free_r1bio(struct r1bio *r1_bio) |
173 | { | 176 | { |
174 | conf_t *conf = r1_bio->mddev->private; | 177 | struct r1conf *conf = r1_bio->mddev->private; |
175 | 178 | ||
176 | put_all_bios(conf, r1_bio); | 179 | put_all_bios(conf, r1_bio); |
177 | mempool_free(r1_bio, conf->r1bio_pool); | 180 | mempool_free(r1_bio, conf->r1bio_pool); |
178 | } | 181 | } |
179 | 182 | ||
180 | static void put_buf(r1bio_t *r1_bio) | 183 | static void put_buf(struct r1bio *r1_bio) |
181 | { | 184 | { |
182 | conf_t *conf = r1_bio->mddev->private; | 185 | struct r1conf *conf = r1_bio->mddev->private; |
183 | int i; | 186 | int i; |
184 | 187 | ||
185 | for (i=0; i<conf->raid_disks; i++) { | 188 | for (i=0; i<conf->raid_disks; i++) { |
@@ -193,11 +196,11 @@ static void put_buf(r1bio_t *r1_bio) | |||
193 | lower_barrier(conf); | 196 | lower_barrier(conf); |
194 | } | 197 | } |
195 | 198 | ||
196 | static void reschedule_retry(r1bio_t *r1_bio) | 199 | static void reschedule_retry(struct r1bio *r1_bio) |
197 | { | 200 | { |
198 | unsigned long flags; | 201 | unsigned long flags; |
199 | mddev_t *mddev = r1_bio->mddev; | 202 | struct mddev *mddev = r1_bio->mddev; |
200 | conf_t *conf = mddev->private; | 203 | struct r1conf *conf = mddev->private; |
201 | 204 | ||
202 | spin_lock_irqsave(&conf->device_lock, flags); | 205 | spin_lock_irqsave(&conf->device_lock, flags); |
203 | list_add(&r1_bio->retry_list, &conf->retry_list); | 206 | list_add(&r1_bio->retry_list, &conf->retry_list); |
@@ -213,11 +216,11 @@ static void reschedule_retry(r1bio_t *r1_bio) | |||
213 | * operation and are ready to return a success/failure code to the buffer | 216 | * operation and are ready to return a success/failure code to the buffer |
214 | * cache layer. | 217 | * cache layer. |
215 | */ | 218 | */ |
216 | static void call_bio_endio(r1bio_t *r1_bio) | 219 | static void call_bio_endio(struct r1bio *r1_bio) |
217 | { | 220 | { |
218 | struct bio *bio = r1_bio->master_bio; | 221 | struct bio *bio = r1_bio->master_bio; |
219 | int done; | 222 | int done; |
220 | conf_t *conf = r1_bio->mddev->private; | 223 | struct r1conf *conf = r1_bio->mddev->private; |
221 | 224 | ||
222 | if (bio->bi_phys_segments) { | 225 | if (bio->bi_phys_segments) { |
223 | unsigned long flags; | 226 | unsigned long flags; |
@@ -240,17 +243,17 @@ static void call_bio_endio(r1bio_t *r1_bio) | |||
240 | } | 243 | } |
241 | } | 244 | } |
242 | 245 | ||
243 | static void raid_end_bio_io(r1bio_t *r1_bio) | 246 | static void raid_end_bio_io(struct r1bio *r1_bio) |
244 | { | 247 | { |
245 | struct bio *bio = r1_bio->master_bio; | 248 | struct bio *bio = r1_bio->master_bio; |
246 | 249 | ||
247 | /* if nobody has done the final endio yet, do it now */ | 250 | /* if nobody has done the final endio yet, do it now */ |
248 | if (!test_and_set_bit(R1BIO_Returned, &r1_bio->state)) { | 251 | if (!test_and_set_bit(R1BIO_Returned, &r1_bio->state)) { |
249 | PRINTK(KERN_DEBUG "raid1: sync end %s on sectors %llu-%llu\n", | 252 | pr_debug("raid1: sync end %s on sectors %llu-%llu\n", |
250 | (bio_data_dir(bio) == WRITE) ? "write" : "read", | 253 | (bio_data_dir(bio) == WRITE) ? "write" : "read", |
251 | (unsigned long long) bio->bi_sector, | 254 | (unsigned long long) bio->bi_sector, |
252 | (unsigned long long) bio->bi_sector + | 255 | (unsigned long long) bio->bi_sector + |
253 | (bio->bi_size >> 9) - 1); | 256 | (bio->bi_size >> 9) - 1); |
254 | 257 | ||
255 | call_bio_endio(r1_bio); | 258 | call_bio_endio(r1_bio); |
256 | } | 259 | } |
@@ -260,20 +263,38 @@ static void raid_end_bio_io(r1bio_t *r1_bio) | |||
260 | /* | 263 | /* |
261 | * Update disk head position estimator based on IRQ completion info. | 264 | * Update disk head position estimator based on IRQ completion info. |
262 | */ | 265 | */ |
263 | static inline void update_head_pos(int disk, r1bio_t *r1_bio) | 266 | static inline void update_head_pos(int disk, struct r1bio *r1_bio) |
264 | { | 267 | { |
265 | conf_t *conf = r1_bio->mddev->private; | 268 | struct r1conf *conf = r1_bio->mddev->private; |
266 | 269 | ||
267 | conf->mirrors[disk].head_position = | 270 | conf->mirrors[disk].head_position = |
268 | r1_bio->sector + (r1_bio->sectors); | 271 | r1_bio->sector + (r1_bio->sectors); |
269 | } | 272 | } |
270 | 273 | ||
274 | /* | ||
275 | * Find the disk number which triggered given bio | ||
276 | */ | ||
277 | static int find_bio_disk(struct r1bio *r1_bio, struct bio *bio) | ||
278 | { | ||
279 | int mirror; | ||
280 | int raid_disks = r1_bio->mddev->raid_disks; | ||
281 | |||
282 | for (mirror = 0; mirror < raid_disks; mirror++) | ||
283 | if (r1_bio->bios[mirror] == bio) | ||
284 | break; | ||
285 | |||
286 | BUG_ON(mirror == raid_disks); | ||
287 | update_head_pos(mirror, r1_bio); | ||
288 | |||
289 | return mirror; | ||
290 | } | ||
291 | |||
271 | static void raid1_end_read_request(struct bio *bio, int error) | 292 | static void raid1_end_read_request(struct bio *bio, int error) |
272 | { | 293 | { |
273 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); | 294 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
274 | r1bio_t *r1_bio = bio->bi_private; | 295 | struct r1bio *r1_bio = bio->bi_private; |
275 | int mirror; | 296 | int mirror; |
276 | conf_t *conf = r1_bio->mddev->private; | 297 | struct r1conf *conf = r1_bio->mddev->private; |
277 | 298 | ||
278 | mirror = r1_bio->read_disk; | 299 | mirror = r1_bio->read_disk; |
279 | /* | 300 | /* |
@@ -318,7 +339,7 @@ static void raid1_end_read_request(struct bio *bio, int error) | |||
318 | rdev_dec_pending(conf->mirrors[mirror].rdev, conf->mddev); | 339 | rdev_dec_pending(conf->mirrors[mirror].rdev, conf->mddev); |
319 | } | 340 | } |
320 | 341 | ||
321 | static void close_write(r1bio_t *r1_bio) | 342 | static void close_write(struct r1bio *r1_bio) |
322 | { | 343 | { |
323 | /* it really is the end of this request */ | 344 | /* it really is the end of this request */ |
324 | if (test_bit(R1BIO_BehindIO, &r1_bio->state)) { | 345 | if (test_bit(R1BIO_BehindIO, &r1_bio->state)) { |
@@ -337,7 +358,7 @@ static void close_write(r1bio_t *r1_bio) | |||
337 | md_write_end(r1_bio->mddev); | 358 | md_write_end(r1_bio->mddev); |
338 | } | 359 | } |
339 | 360 | ||
340 | static void r1_bio_write_done(r1bio_t *r1_bio) | 361 | static void r1_bio_write_done(struct r1bio *r1_bio) |
341 | { | 362 | { |
342 | if (!atomic_dec_and_test(&r1_bio->remaining)) | 363 | if (!atomic_dec_and_test(&r1_bio->remaining)) |
343 | return; | 364 | return; |
@@ -356,15 +377,12 @@ static void r1_bio_write_done(r1bio_t *r1_bio) | |||
356 | static void raid1_end_write_request(struct bio *bio, int error) | 377 | static void raid1_end_write_request(struct bio *bio, int error) |
357 | { | 378 | { |
358 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); | 379 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
359 | r1bio_t *r1_bio = bio->bi_private; | 380 | struct r1bio *r1_bio = bio->bi_private; |
360 | int mirror, behind = test_bit(R1BIO_BehindIO, &r1_bio->state); | 381 | int mirror, behind = test_bit(R1BIO_BehindIO, &r1_bio->state); |
361 | conf_t *conf = r1_bio->mddev->private; | 382 | struct r1conf *conf = r1_bio->mddev->private; |
362 | struct bio *to_put = NULL; | 383 | struct bio *to_put = NULL; |
363 | 384 | ||
364 | 385 | mirror = find_bio_disk(r1_bio, bio); | |
365 | for (mirror = 0; mirror < conf->raid_disks; mirror++) | ||
366 | if (r1_bio->bios[mirror] == bio) | ||
367 | break; | ||
368 | 386 | ||
369 | /* | 387 | /* |
370 | * 'one mirror IO has finished' event handler: | 388 | * 'one mirror IO has finished' event handler: |
@@ -400,8 +418,6 @@ static void raid1_end_write_request(struct bio *bio, int error) | |||
400 | } | 418 | } |
401 | } | 419 | } |
402 | 420 | ||
403 | update_head_pos(mirror, r1_bio); | ||
404 | |||
405 | if (behind) { | 421 | if (behind) { |
406 | if (test_bit(WriteMostly, &conf->mirrors[mirror].rdev->flags)) | 422 | if (test_bit(WriteMostly, &conf->mirrors[mirror].rdev->flags)) |
407 | atomic_dec(&r1_bio->behind_remaining); | 423 | atomic_dec(&r1_bio->behind_remaining); |
@@ -418,10 +434,11 @@ static void raid1_end_write_request(struct bio *bio, int error) | |||
418 | /* Maybe we can return now */ | 434 | /* Maybe we can return now */ |
419 | if (!test_and_set_bit(R1BIO_Returned, &r1_bio->state)) { | 435 | if (!test_and_set_bit(R1BIO_Returned, &r1_bio->state)) { |
420 | struct bio *mbio = r1_bio->master_bio; | 436 | struct bio *mbio = r1_bio->master_bio; |
421 | PRINTK(KERN_DEBUG "raid1: behind end write sectors %llu-%llu\n", | 437 | pr_debug("raid1: behind end write sectors" |
422 | (unsigned long long) mbio->bi_sector, | 438 | " %llu-%llu\n", |
423 | (unsigned long long) mbio->bi_sector + | 439 | (unsigned long long) mbio->bi_sector, |
424 | (mbio->bi_size >> 9) - 1); | 440 | (unsigned long long) mbio->bi_sector + |
441 | (mbio->bi_size >> 9) - 1); | ||
425 | call_bio_endio(r1_bio); | 442 | call_bio_endio(r1_bio); |
426 | } | 443 | } |
427 | } | 444 | } |
@@ -455,7 +472,7 @@ static void raid1_end_write_request(struct bio *bio, int error) | |||
455 | * | 472 | * |
456 | * The rdev for the device selected will have nr_pending incremented. | 473 | * The rdev for the device selected will have nr_pending incremented. |
457 | */ | 474 | */ |
458 | static int read_balance(conf_t *conf, r1bio_t *r1_bio, int *max_sectors) | 475 | static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sectors) |
459 | { | 476 | { |
460 | const sector_t this_sector = r1_bio->sector; | 477 | const sector_t this_sector = r1_bio->sector; |
461 | int sectors; | 478 | int sectors; |
@@ -464,7 +481,7 @@ static int read_balance(conf_t *conf, r1bio_t *r1_bio, int *max_sectors) | |||
464 | int best_disk; | 481 | int best_disk; |
465 | int i; | 482 | int i; |
466 | sector_t best_dist; | 483 | sector_t best_dist; |
467 | mdk_rdev_t *rdev; | 484 | struct md_rdev *rdev; |
468 | int choose_first; | 485 | int choose_first; |
469 | 486 | ||
470 | rcu_read_lock(); | 487 | rcu_read_lock(); |
@@ -582,14 +599,18 @@ static int read_balance(conf_t *conf, r1bio_t *r1_bio, int *max_sectors) | |||
582 | return best_disk; | 599 | return best_disk; |
583 | } | 600 | } |
584 | 601 | ||
585 | int md_raid1_congested(mddev_t *mddev, int bits) | 602 | int md_raid1_congested(struct mddev *mddev, int bits) |
586 | { | 603 | { |
587 | conf_t *conf = mddev->private; | 604 | struct r1conf *conf = mddev->private; |
588 | int i, ret = 0; | 605 | int i, ret = 0; |
589 | 606 | ||
607 | if ((bits & (1 << BDI_async_congested)) && | ||
608 | conf->pending_count >= max_queued_requests) | ||
609 | return 1; | ||
610 | |||
590 | rcu_read_lock(); | 611 | rcu_read_lock(); |
591 | for (i = 0; i < mddev->raid_disks; i++) { | 612 | for (i = 0; i < mddev->raid_disks; i++) { |
592 | mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); | 613 | struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); |
593 | if (rdev && !test_bit(Faulty, &rdev->flags)) { | 614 | if (rdev && !test_bit(Faulty, &rdev->flags)) { |
594 | struct request_queue *q = bdev_get_queue(rdev->bdev); | 615 | struct request_queue *q = bdev_get_queue(rdev->bdev); |
595 | 616 | ||
@@ -611,13 +632,13 @@ EXPORT_SYMBOL_GPL(md_raid1_congested); | |||
611 | 632 | ||
612 | static int raid1_congested(void *data, int bits) | 633 | static int raid1_congested(void *data, int bits) |
613 | { | 634 | { |
614 | mddev_t *mddev = data; | 635 | struct mddev *mddev = data; |
615 | 636 | ||
616 | return mddev_congested(mddev, bits) || | 637 | return mddev_congested(mddev, bits) || |
617 | md_raid1_congested(mddev, bits); | 638 | md_raid1_congested(mddev, bits); |
618 | } | 639 | } |
619 | 640 | ||
620 | static void flush_pending_writes(conf_t *conf) | 641 | static void flush_pending_writes(struct r1conf *conf) |
621 | { | 642 | { |
622 | /* Any writes that have been queued but are awaiting | 643 | /* Any writes that have been queued but are awaiting |
623 | * bitmap updates get flushed here. | 644 | * bitmap updates get flushed here. |
@@ -627,10 +648,12 @@ static void flush_pending_writes(conf_t *conf) | |||
627 | if (conf->pending_bio_list.head) { | 648 | if (conf->pending_bio_list.head) { |
628 | struct bio *bio; | 649 | struct bio *bio; |
629 | bio = bio_list_get(&conf->pending_bio_list); | 650 | bio = bio_list_get(&conf->pending_bio_list); |
651 | conf->pending_count = 0; | ||
630 | spin_unlock_irq(&conf->device_lock); | 652 | spin_unlock_irq(&conf->device_lock); |
631 | /* flush any pending bitmap writes to | 653 | /* flush any pending bitmap writes to |
632 | * disk before proceeding w/ I/O */ | 654 | * disk before proceeding w/ I/O */ |
633 | bitmap_unplug(conf->mddev->bitmap); | 655 | bitmap_unplug(conf->mddev->bitmap); |
656 | wake_up(&conf->wait_barrier); | ||
634 | 657 | ||
635 | while (bio) { /* submit pending writes */ | 658 | while (bio) { /* submit pending writes */ |
636 | struct bio *next = bio->bi_next; | 659 | struct bio *next = bio->bi_next; |
@@ -665,7 +688,7 @@ static void flush_pending_writes(conf_t *conf) | |||
665 | */ | 688 | */ |
666 | #define RESYNC_DEPTH 32 | 689 | #define RESYNC_DEPTH 32 |
667 | 690 | ||
668 | static void raise_barrier(conf_t *conf) | 691 | static void raise_barrier(struct r1conf *conf) |
669 | { | 692 | { |
670 | spin_lock_irq(&conf->resync_lock); | 693 | spin_lock_irq(&conf->resync_lock); |
671 | 694 | ||
@@ -684,7 +707,7 @@ static void raise_barrier(conf_t *conf) | |||
684 | spin_unlock_irq(&conf->resync_lock); | 707 | spin_unlock_irq(&conf->resync_lock); |
685 | } | 708 | } |
686 | 709 | ||
687 | static void lower_barrier(conf_t *conf) | 710 | static void lower_barrier(struct r1conf *conf) |
688 | { | 711 | { |
689 | unsigned long flags; | 712 | unsigned long flags; |
690 | BUG_ON(conf->barrier <= 0); | 713 | BUG_ON(conf->barrier <= 0); |
@@ -694,7 +717,7 @@ static void lower_barrier(conf_t *conf) | |||
694 | wake_up(&conf->wait_barrier); | 717 | wake_up(&conf->wait_barrier); |
695 | } | 718 | } |
696 | 719 | ||
697 | static void wait_barrier(conf_t *conf) | 720 | static void wait_barrier(struct r1conf *conf) |
698 | { | 721 | { |
699 | spin_lock_irq(&conf->resync_lock); | 722 | spin_lock_irq(&conf->resync_lock); |
700 | if (conf->barrier) { | 723 | if (conf->barrier) { |
@@ -708,7 +731,7 @@ static void wait_barrier(conf_t *conf) | |||
708 | spin_unlock_irq(&conf->resync_lock); | 731 | spin_unlock_irq(&conf->resync_lock); |
709 | } | 732 | } |
710 | 733 | ||
711 | static void allow_barrier(conf_t *conf) | 734 | static void allow_barrier(struct r1conf *conf) |
712 | { | 735 | { |
713 | unsigned long flags; | 736 | unsigned long flags; |
714 | spin_lock_irqsave(&conf->resync_lock, flags); | 737 | spin_lock_irqsave(&conf->resync_lock, flags); |
@@ -717,7 +740,7 @@ static void allow_barrier(conf_t *conf) | |||
717 | wake_up(&conf->wait_barrier); | 740 | wake_up(&conf->wait_barrier); |
718 | } | 741 | } |
719 | 742 | ||
720 | static void freeze_array(conf_t *conf) | 743 | static void freeze_array(struct r1conf *conf) |
721 | { | 744 | { |
722 | /* stop syncio and normal IO and wait for everything to | 745 | /* stop syncio and normal IO and wait for everything to |
723 | * go quite. | 746 | * go quite. |
@@ -740,7 +763,7 @@ static void freeze_array(conf_t *conf) | |||
740 | flush_pending_writes(conf)); | 763 | flush_pending_writes(conf)); |
741 | spin_unlock_irq(&conf->resync_lock); | 764 | spin_unlock_irq(&conf->resync_lock); |
742 | } | 765 | } |
743 | static void unfreeze_array(conf_t *conf) | 766 | static void unfreeze_array(struct r1conf *conf) |
744 | { | 767 | { |
745 | /* reverse the effect of the freeze */ | 768 | /* reverse the effect of the freeze */ |
746 | spin_lock_irq(&conf->resync_lock); | 769 | spin_lock_irq(&conf->resync_lock); |
@@ -753,7 +776,7 @@ static void unfreeze_array(conf_t *conf) | |||
753 | 776 | ||
754 | /* duplicate the data pages for behind I/O | 777 | /* duplicate the data pages for behind I/O |
755 | */ | 778 | */ |
756 | static void alloc_behind_pages(struct bio *bio, r1bio_t *r1_bio) | 779 | static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio) |
757 | { | 780 | { |
758 | int i; | 781 | int i; |
759 | struct bio_vec *bvec; | 782 | struct bio_vec *bvec; |
@@ -782,14 +805,14 @@ do_sync_io: | |||
782 | if (bvecs[i].bv_page) | 805 | if (bvecs[i].bv_page) |
783 | put_page(bvecs[i].bv_page); | 806 | put_page(bvecs[i].bv_page); |
784 | kfree(bvecs); | 807 | kfree(bvecs); |
785 | PRINTK("%dB behind alloc failed, doing sync I/O\n", bio->bi_size); | 808 | pr_debug("%dB behind alloc failed, doing sync I/O\n", bio->bi_size); |
786 | } | 809 | } |
787 | 810 | ||
788 | static int make_request(mddev_t *mddev, struct bio * bio) | 811 | static void make_request(struct mddev *mddev, struct bio * bio) |
789 | { | 812 | { |
790 | conf_t *conf = mddev->private; | 813 | struct r1conf *conf = mddev->private; |
791 | mirror_info_t *mirror; | 814 | struct mirror_info *mirror; |
792 | r1bio_t *r1_bio; | 815 | struct r1bio *r1_bio; |
793 | struct bio *read_bio; | 816 | struct bio *read_bio; |
794 | int i, disks; | 817 | int i, disks; |
795 | struct bitmap *bitmap; | 818 | struct bitmap *bitmap; |
@@ -797,7 +820,7 @@ static int make_request(mddev_t *mddev, struct bio * bio) | |||
797 | const int rw = bio_data_dir(bio); | 820 | const int rw = bio_data_dir(bio); |
798 | const unsigned long do_sync = (bio->bi_rw & REQ_SYNC); | 821 | const unsigned long do_sync = (bio->bi_rw & REQ_SYNC); |
799 | const unsigned long do_flush_fua = (bio->bi_rw & (REQ_FLUSH | REQ_FUA)); | 822 | const unsigned long do_flush_fua = (bio->bi_rw & (REQ_FLUSH | REQ_FUA)); |
800 | mdk_rdev_t *blocked_rdev; | 823 | struct md_rdev *blocked_rdev; |
801 | int plugged; | 824 | int plugged; |
802 | int first_clone; | 825 | int first_clone; |
803 | int sectors_handled; | 826 | int sectors_handled; |
@@ -870,7 +893,7 @@ read_again: | |||
870 | if (rdisk < 0) { | 893 | if (rdisk < 0) { |
871 | /* couldn't find anywhere to read from */ | 894 | /* couldn't find anywhere to read from */ |
872 | raid_end_bio_io(r1_bio); | 895 | raid_end_bio_io(r1_bio); |
873 | return 0; | 896 | return; |
874 | } | 897 | } |
875 | mirror = conf->mirrors + rdisk; | 898 | mirror = conf->mirrors + rdisk; |
876 | 899 | ||
@@ -928,12 +951,17 @@ read_again: | |||
928 | goto read_again; | 951 | goto read_again; |
929 | } else | 952 | } else |
930 | generic_make_request(read_bio); | 953 | generic_make_request(read_bio); |
931 | return 0; | 954 | return; |
932 | } | 955 | } |
933 | 956 | ||
934 | /* | 957 | /* |
935 | * WRITE: | 958 | * WRITE: |
936 | */ | 959 | */ |
960 | if (conf->pending_count >= max_queued_requests) { | ||
961 | md_wakeup_thread(mddev->thread); | ||
962 | wait_event(conf->wait_barrier, | ||
963 | conf->pending_count < max_queued_requests); | ||
964 | } | ||
937 | /* first select target devices under rcu_lock and | 965 | /* first select target devices under rcu_lock and |
938 | * inc refcount on their rdev. Record them by setting | 966 | * inc refcount on their rdev. Record them by setting |
939 | * bios[x] to bio | 967 | * bios[x] to bio |
@@ -952,7 +980,7 @@ read_again: | |||
952 | rcu_read_lock(); | 980 | rcu_read_lock(); |
953 | max_sectors = r1_bio->sectors; | 981 | max_sectors = r1_bio->sectors; |
954 | for (i = 0; i < disks; i++) { | 982 | for (i = 0; i < disks; i++) { |
955 | mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); | 983 | struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); |
956 | if (rdev && unlikely(test_bit(Blocked, &rdev->flags))) { | 984 | if (rdev && unlikely(test_bit(Blocked, &rdev->flags))) { |
957 | atomic_inc(&rdev->nr_pending); | 985 | atomic_inc(&rdev->nr_pending); |
958 | blocked_rdev = rdev; | 986 | blocked_rdev = rdev; |
@@ -1097,14 +1125,14 @@ read_again: | |||
1097 | atomic_inc(&r1_bio->remaining); | 1125 | atomic_inc(&r1_bio->remaining); |
1098 | spin_lock_irqsave(&conf->device_lock, flags); | 1126 | spin_lock_irqsave(&conf->device_lock, flags); |
1099 | bio_list_add(&conf->pending_bio_list, mbio); | 1127 | bio_list_add(&conf->pending_bio_list, mbio); |
1128 | conf->pending_count++; | ||
1100 | spin_unlock_irqrestore(&conf->device_lock, flags); | 1129 | spin_unlock_irqrestore(&conf->device_lock, flags); |
1101 | } | 1130 | } |
1102 | r1_bio_write_done(r1_bio); | 1131 | /* Mustn't call r1_bio_write_done before this next test, |
1103 | 1132 | * as it could result in the bio being freed. | |
1104 | /* In case raid1d snuck in to freeze_array */ | 1133 | */ |
1105 | wake_up(&conf->wait_barrier); | ||
1106 | |||
1107 | if (sectors_handled < (bio->bi_size >> 9)) { | 1134 | if (sectors_handled < (bio->bi_size >> 9)) { |
1135 | r1_bio_write_done(r1_bio); | ||
1108 | /* We need another r1_bio. It has already been counted | 1136 | /* We need another r1_bio. It has already been counted |
1109 | * in bio->bi_phys_segments | 1137 | * in bio->bi_phys_segments |
1110 | */ | 1138 | */ |
@@ -1117,22 +1145,25 @@ read_again: | |||
1117 | goto retry_write; | 1145 | goto retry_write; |
1118 | } | 1146 | } |
1119 | 1147 | ||
1148 | r1_bio_write_done(r1_bio); | ||
1149 | |||
1150 | /* In case raid1d snuck in to freeze_array */ | ||
1151 | wake_up(&conf->wait_barrier); | ||
1152 | |||
1120 | if (do_sync || !bitmap || !plugged) | 1153 | if (do_sync || !bitmap || !plugged) |
1121 | md_wakeup_thread(mddev->thread); | 1154 | md_wakeup_thread(mddev->thread); |
1122 | |||
1123 | return 0; | ||
1124 | } | 1155 | } |
1125 | 1156 | ||
1126 | static void status(struct seq_file *seq, mddev_t *mddev) | 1157 | static void status(struct seq_file *seq, struct mddev *mddev) |
1127 | { | 1158 | { |
1128 | conf_t *conf = mddev->private; | 1159 | struct r1conf *conf = mddev->private; |
1129 | int i; | 1160 | int i; |
1130 | 1161 | ||
1131 | seq_printf(seq, " [%d/%d] [", conf->raid_disks, | 1162 | seq_printf(seq, " [%d/%d] [", conf->raid_disks, |
1132 | conf->raid_disks - mddev->degraded); | 1163 | conf->raid_disks - mddev->degraded); |
1133 | rcu_read_lock(); | 1164 | rcu_read_lock(); |
1134 | for (i = 0; i < conf->raid_disks; i++) { | 1165 | for (i = 0; i < conf->raid_disks; i++) { |
1135 | mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); | 1166 | struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); |
1136 | seq_printf(seq, "%s", | 1167 | seq_printf(seq, "%s", |
1137 | rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); | 1168 | rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); |
1138 | } | 1169 | } |
@@ -1141,10 +1172,10 @@ static void status(struct seq_file *seq, mddev_t *mddev) | |||
1141 | } | 1172 | } |
1142 | 1173 | ||
1143 | 1174 | ||
1144 | static void error(mddev_t *mddev, mdk_rdev_t *rdev) | 1175 | static void error(struct mddev *mddev, struct md_rdev *rdev) |
1145 | { | 1176 | { |
1146 | char b[BDEVNAME_SIZE]; | 1177 | char b[BDEVNAME_SIZE]; |
1147 | conf_t *conf = mddev->private; | 1178 | struct r1conf *conf = mddev->private; |
1148 | 1179 | ||
1149 | /* | 1180 | /* |
1150 | * If it is not operational, then we have already marked it as dead | 1181 | * If it is not operational, then we have already marked it as dead |
@@ -1184,7 +1215,7 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev) | |||
1184 | mdname(mddev), conf->raid_disks - mddev->degraded); | 1215 | mdname(mddev), conf->raid_disks - mddev->degraded); |
1185 | } | 1216 | } |
1186 | 1217 | ||
1187 | static void print_conf(conf_t *conf) | 1218 | static void print_conf(struct r1conf *conf) |
1188 | { | 1219 | { |
1189 | int i; | 1220 | int i; |
1190 | 1221 | ||
@@ -1199,7 +1230,7 @@ static void print_conf(conf_t *conf) | |||
1199 | rcu_read_lock(); | 1230 | rcu_read_lock(); |
1200 | for (i = 0; i < conf->raid_disks; i++) { | 1231 | for (i = 0; i < conf->raid_disks; i++) { |
1201 | char b[BDEVNAME_SIZE]; | 1232 | char b[BDEVNAME_SIZE]; |
1202 | mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); | 1233 | struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); |
1203 | if (rdev) | 1234 | if (rdev) |
1204 | printk(KERN_DEBUG " disk %d, wo:%d, o:%d, dev:%s\n", | 1235 | printk(KERN_DEBUG " disk %d, wo:%d, o:%d, dev:%s\n", |
1205 | i, !test_bit(In_sync, &rdev->flags), | 1236 | i, !test_bit(In_sync, &rdev->flags), |
@@ -1209,7 +1240,7 @@ static void print_conf(conf_t *conf) | |||
1209 | rcu_read_unlock(); | 1240 | rcu_read_unlock(); |
1210 | } | 1241 | } |
1211 | 1242 | ||
1212 | static void close_sync(conf_t *conf) | 1243 | static void close_sync(struct r1conf *conf) |
1213 | { | 1244 | { |
1214 | wait_barrier(conf); | 1245 | wait_barrier(conf); |
1215 | allow_barrier(conf); | 1246 | allow_barrier(conf); |
@@ -1218,10 +1249,10 @@ static void close_sync(conf_t *conf) | |||
1218 | conf->r1buf_pool = NULL; | 1249 | conf->r1buf_pool = NULL; |
1219 | } | 1250 | } |
1220 | 1251 | ||
1221 | static int raid1_spare_active(mddev_t *mddev) | 1252 | static int raid1_spare_active(struct mddev *mddev) |
1222 | { | 1253 | { |
1223 | int i; | 1254 | int i; |
1224 | conf_t *conf = mddev->private; | 1255 | struct r1conf *conf = mddev->private; |
1225 | int count = 0; | 1256 | int count = 0; |
1226 | unsigned long flags; | 1257 | unsigned long flags; |
1227 | 1258 | ||
@@ -1231,7 +1262,7 @@ static int raid1_spare_active(mddev_t *mddev) | |||
1231 | * Called under mddev lock, so rcu protection not needed. | 1262 | * Called under mddev lock, so rcu protection not needed. |
1232 | */ | 1263 | */ |
1233 | for (i = 0; i < conf->raid_disks; i++) { | 1264 | for (i = 0; i < conf->raid_disks; i++) { |
1234 | mdk_rdev_t *rdev = conf->mirrors[i].rdev; | 1265 | struct md_rdev *rdev = conf->mirrors[i].rdev; |
1235 | if (rdev | 1266 | if (rdev |
1236 | && !test_bit(Faulty, &rdev->flags) | 1267 | && !test_bit(Faulty, &rdev->flags) |
1237 | && !test_and_set_bit(In_sync, &rdev->flags)) { | 1268 | && !test_and_set_bit(In_sync, &rdev->flags)) { |
@@ -1248,12 +1279,12 @@ static int raid1_spare_active(mddev_t *mddev) | |||
1248 | } | 1279 | } |
1249 | 1280 | ||
1250 | 1281 | ||
1251 | static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) | 1282 | static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev) |
1252 | { | 1283 | { |
1253 | conf_t *conf = mddev->private; | 1284 | struct r1conf *conf = mddev->private; |
1254 | int err = -EEXIST; | 1285 | int err = -EEXIST; |
1255 | int mirror = 0; | 1286 | int mirror = 0; |
1256 | mirror_info_t *p; | 1287 | struct mirror_info *p; |
1257 | int first = 0; | 1288 | int first = 0; |
1258 | int last = mddev->raid_disks - 1; | 1289 | int last = mddev->raid_disks - 1; |
1259 | 1290 | ||
@@ -1296,12 +1327,12 @@ static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) | |||
1296 | return err; | 1327 | return err; |
1297 | } | 1328 | } |
1298 | 1329 | ||
1299 | static int raid1_remove_disk(mddev_t *mddev, int number) | 1330 | static int raid1_remove_disk(struct mddev *mddev, int number) |
1300 | { | 1331 | { |
1301 | conf_t *conf = mddev->private; | 1332 | struct r1conf *conf = mddev->private; |
1302 | int err = 0; | 1333 | int err = 0; |
1303 | mdk_rdev_t *rdev; | 1334 | struct md_rdev *rdev; |
1304 | mirror_info_t *p = conf->mirrors+ number; | 1335 | struct mirror_info *p = conf->mirrors+ number; |
1305 | 1336 | ||
1306 | print_conf(conf); | 1337 | print_conf(conf); |
1307 | rdev = p->rdev; | 1338 | rdev = p->rdev; |
@@ -1339,14 +1370,10 @@ abort: | |||
1339 | 1370 | ||
1340 | static void end_sync_read(struct bio *bio, int error) | 1371 | static void end_sync_read(struct bio *bio, int error) |
1341 | { | 1372 | { |
1342 | r1bio_t *r1_bio = bio->bi_private; | 1373 | struct r1bio *r1_bio = bio->bi_private; |
1343 | int i; | 1374 | |
1375 | update_head_pos(r1_bio->read_disk, r1_bio); | ||
1344 | 1376 | ||
1345 | for (i=r1_bio->mddev->raid_disks; i--; ) | ||
1346 | if (r1_bio->bios[i] == bio) | ||
1347 | break; | ||
1348 | BUG_ON(i < 0); | ||
1349 | update_head_pos(i, r1_bio); | ||
1350 | /* | 1377 | /* |
1351 | * we have read a block, now it needs to be re-written, | 1378 | * we have read a block, now it needs to be re-written, |
1352 | * or re-read if the read failed. | 1379 | * or re-read if the read failed. |
@@ -1362,19 +1389,15 @@ static void end_sync_read(struct bio *bio, int error) | |||
1362 | static void end_sync_write(struct bio *bio, int error) | 1389 | static void end_sync_write(struct bio *bio, int error) |
1363 | { | 1390 | { |
1364 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); | 1391 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
1365 | r1bio_t *r1_bio = bio->bi_private; | 1392 | struct r1bio *r1_bio = bio->bi_private; |
1366 | mddev_t *mddev = r1_bio->mddev; | 1393 | struct mddev *mddev = r1_bio->mddev; |
1367 | conf_t *conf = mddev->private; | 1394 | struct r1conf *conf = mddev->private; |
1368 | int i; | ||
1369 | int mirror=0; | 1395 | int mirror=0; |
1370 | sector_t first_bad; | 1396 | sector_t first_bad; |
1371 | int bad_sectors; | 1397 | int bad_sectors; |
1372 | 1398 | ||
1373 | for (i = 0; i < conf->raid_disks; i++) | 1399 | mirror = find_bio_disk(r1_bio, bio); |
1374 | if (r1_bio->bios[i] == bio) { | 1400 | |
1375 | mirror = i; | ||
1376 | break; | ||
1377 | } | ||
1378 | if (!uptodate) { | 1401 | if (!uptodate) { |
1379 | sector_t sync_blocks = 0; | 1402 | sector_t sync_blocks = 0; |
1380 | sector_t s = r1_bio->sector; | 1403 | sector_t s = r1_bio->sector; |
@@ -1400,8 +1423,6 @@ static void end_sync_write(struct bio *bio, int error) | |||
1400 | ) | 1423 | ) |
1401 | set_bit(R1BIO_MadeGood, &r1_bio->state); | 1424 | set_bit(R1BIO_MadeGood, &r1_bio->state); |
1402 | 1425 | ||
1403 | update_head_pos(mirror, r1_bio); | ||
1404 | |||
1405 | if (atomic_dec_and_test(&r1_bio->remaining)) { | 1426 | if (atomic_dec_and_test(&r1_bio->remaining)) { |
1406 | int s = r1_bio->sectors; | 1427 | int s = r1_bio->sectors; |
1407 | if (test_bit(R1BIO_MadeGood, &r1_bio->state) || | 1428 | if (test_bit(R1BIO_MadeGood, &r1_bio->state) || |
@@ -1414,7 +1435,7 @@ static void end_sync_write(struct bio *bio, int error) | |||
1414 | } | 1435 | } |
1415 | } | 1436 | } |
1416 | 1437 | ||
1417 | static int r1_sync_page_io(mdk_rdev_t *rdev, sector_t sector, | 1438 | static int r1_sync_page_io(struct md_rdev *rdev, sector_t sector, |
1418 | int sectors, struct page *page, int rw) | 1439 | int sectors, struct page *page, int rw) |
1419 | { | 1440 | { |
1420 | if (sync_page_io(rdev, sector, sectors << 9, page, rw, false)) | 1441 | if (sync_page_io(rdev, sector, sectors << 9, page, rw, false)) |
@@ -1428,7 +1449,7 @@ static int r1_sync_page_io(mdk_rdev_t *rdev, sector_t sector, | |||
1428 | return 0; | 1449 | return 0; |
1429 | } | 1450 | } |
1430 | 1451 | ||
1431 | static int fix_sync_read_error(r1bio_t *r1_bio) | 1452 | static int fix_sync_read_error(struct r1bio *r1_bio) |
1432 | { | 1453 | { |
1433 | /* Try some synchronous reads of other devices to get | 1454 | /* Try some synchronous reads of other devices to get |
1434 | * good data, much like with normal read errors. Only | 1455 | * good data, much like with normal read errors. Only |
@@ -1441,8 +1462,8 @@ static int fix_sync_read_error(r1bio_t *r1_bio) | |||
1441 | * made sure that anything with a bad block in range | 1462 | * made sure that anything with a bad block in range |
1442 | * will have bi_end_io clear. | 1463 | * will have bi_end_io clear. |
1443 | */ | 1464 | */ |
1444 | mddev_t *mddev = r1_bio->mddev; | 1465 | struct mddev *mddev = r1_bio->mddev; |
1445 | conf_t *conf = mddev->private; | 1466 | struct r1conf *conf = mddev->private; |
1446 | struct bio *bio = r1_bio->bios[r1_bio->read_disk]; | 1467 | struct bio *bio = r1_bio->bios[r1_bio->read_disk]; |
1447 | sector_t sect = r1_bio->sector; | 1468 | sector_t sect = r1_bio->sector; |
1448 | int sectors = r1_bio->sectors; | 1469 | int sectors = r1_bio->sectors; |
@@ -1452,7 +1473,7 @@ static int fix_sync_read_error(r1bio_t *r1_bio) | |||
1452 | int s = sectors; | 1473 | int s = sectors; |
1453 | int d = r1_bio->read_disk; | 1474 | int d = r1_bio->read_disk; |
1454 | int success = 0; | 1475 | int success = 0; |
1455 | mdk_rdev_t *rdev; | 1476 | struct md_rdev *rdev; |
1456 | int start; | 1477 | int start; |
1457 | 1478 | ||
1458 | if (s > (PAGE_SIZE>>9)) | 1479 | if (s > (PAGE_SIZE>>9)) |
@@ -1497,7 +1518,8 @@ static int fix_sync_read_error(r1bio_t *r1_bio) | |||
1497 | abort = 1; | 1518 | abort = 1; |
1498 | } | 1519 | } |
1499 | if (abort) { | 1520 | if (abort) { |
1500 | mddev->recovery_disabled = 1; | 1521 | conf->recovery_disabled = |
1522 | mddev->recovery_disabled; | ||
1501 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); | 1523 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
1502 | md_done_sync(mddev, r1_bio->sectors, 0); | 1524 | md_done_sync(mddev, r1_bio->sectors, 0); |
1503 | put_buf(r1_bio); | 1525 | put_buf(r1_bio); |
@@ -1548,7 +1570,7 @@ static int fix_sync_read_error(r1bio_t *r1_bio) | |||
1548 | return 1; | 1570 | return 1; |
1549 | } | 1571 | } |
1550 | 1572 | ||
1551 | static int process_checks(r1bio_t *r1_bio) | 1573 | static int process_checks(struct r1bio *r1_bio) |
1552 | { | 1574 | { |
1553 | /* We have read all readable devices. If we haven't | 1575 | /* We have read all readable devices. If we haven't |
1554 | * got the block, then there is no hope left. | 1576 | * got the block, then there is no hope left. |
@@ -1557,8 +1579,8 @@ static int process_checks(r1bio_t *r1_bio) | |||
1557 | * If any blocks failed to read, then we need to | 1579 | * If any blocks failed to read, then we need to |
1558 | * attempt an over-write | 1580 | * attempt an over-write |
1559 | */ | 1581 | */ |
1560 | mddev_t *mddev = r1_bio->mddev; | 1582 | struct mddev *mddev = r1_bio->mddev; |
1561 | conf_t *conf = mddev->private; | 1583 | struct r1conf *conf = mddev->private; |
1562 | int primary; | 1584 | int primary; |
1563 | int i; | 1585 | int i; |
1564 | 1586 | ||
@@ -1630,9 +1652,9 @@ static int process_checks(r1bio_t *r1_bio) | |||
1630 | return 0; | 1652 | return 0; |
1631 | } | 1653 | } |
1632 | 1654 | ||
1633 | static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio) | 1655 | static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio) |
1634 | { | 1656 | { |
1635 | conf_t *conf = mddev->private; | 1657 | struct r1conf *conf = mddev->private; |
1636 | int i; | 1658 | int i; |
1637 | int disks = conf->raid_disks; | 1659 | int disks = conf->raid_disks; |
1638 | struct bio *bio, *wbio; | 1660 | struct bio *bio, *wbio; |
@@ -1682,16 +1704,16 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio) | |||
1682 | * 3. Performs writes following reads for array synchronising. | 1704 | * 3. Performs writes following reads for array synchronising. |
1683 | */ | 1705 | */ |
1684 | 1706 | ||
1685 | static void fix_read_error(conf_t *conf, int read_disk, | 1707 | static void fix_read_error(struct r1conf *conf, int read_disk, |
1686 | sector_t sect, int sectors) | 1708 | sector_t sect, int sectors) |
1687 | { | 1709 | { |
1688 | mddev_t *mddev = conf->mddev; | 1710 | struct mddev *mddev = conf->mddev; |
1689 | while(sectors) { | 1711 | while(sectors) { |
1690 | int s = sectors; | 1712 | int s = sectors; |
1691 | int d = read_disk; | 1713 | int d = read_disk; |
1692 | int success = 0; | 1714 | int success = 0; |
1693 | int start; | 1715 | int start; |
1694 | mdk_rdev_t *rdev; | 1716 | struct md_rdev *rdev; |
1695 | 1717 | ||
1696 | if (s > (PAGE_SIZE>>9)) | 1718 | if (s > (PAGE_SIZE>>9)) |
1697 | s = PAGE_SIZE >> 9; | 1719 | s = PAGE_SIZE >> 9; |
@@ -1722,7 +1744,7 @@ static void fix_read_error(conf_t *conf, int read_disk, | |||
1722 | 1744 | ||
1723 | if (!success) { | 1745 | if (!success) { |
1724 | /* Cannot read from anywhere - mark it bad */ | 1746 | /* Cannot read from anywhere - mark it bad */ |
1725 | mdk_rdev_t *rdev = conf->mirrors[read_disk].rdev; | 1747 | struct md_rdev *rdev = conf->mirrors[read_disk].rdev; |
1726 | if (!rdev_set_badblocks(rdev, sect, s, 0)) | 1748 | if (!rdev_set_badblocks(rdev, sect, s, 0)) |
1727 | md_error(mddev, rdev); | 1749 | md_error(mddev, rdev); |
1728 | break; | 1750 | break; |
@@ -1785,11 +1807,11 @@ static int submit_bio_wait(int rw, struct bio *bio) | |||
1785 | return test_bit(BIO_UPTODATE, &bio->bi_flags); | 1807 | return test_bit(BIO_UPTODATE, &bio->bi_flags); |
1786 | } | 1808 | } |
1787 | 1809 | ||
1788 | static int narrow_write_error(r1bio_t *r1_bio, int i) | 1810 | static int narrow_write_error(struct r1bio *r1_bio, int i) |
1789 | { | 1811 | { |
1790 | mddev_t *mddev = r1_bio->mddev; | 1812 | struct mddev *mddev = r1_bio->mddev; |
1791 | conf_t *conf = mddev->private; | 1813 | struct r1conf *conf = mddev->private; |
1792 | mdk_rdev_t *rdev = conf->mirrors[i].rdev; | 1814 | struct md_rdev *rdev = conf->mirrors[i].rdev; |
1793 | int vcnt, idx; | 1815 | int vcnt, idx; |
1794 | struct bio_vec *vec; | 1816 | struct bio_vec *vec; |
1795 | 1817 | ||
@@ -1861,12 +1883,12 @@ static int narrow_write_error(r1bio_t *r1_bio, int i) | |||
1861 | return ok; | 1883 | return ok; |
1862 | } | 1884 | } |
1863 | 1885 | ||
1864 | static void handle_sync_write_finished(conf_t *conf, r1bio_t *r1_bio) | 1886 | static void handle_sync_write_finished(struct r1conf *conf, struct r1bio *r1_bio) |
1865 | { | 1887 | { |
1866 | int m; | 1888 | int m; |
1867 | int s = r1_bio->sectors; | 1889 | int s = r1_bio->sectors; |
1868 | for (m = 0; m < conf->raid_disks ; m++) { | 1890 | for (m = 0; m < conf->raid_disks ; m++) { |
1869 | mdk_rdev_t *rdev = conf->mirrors[m].rdev; | 1891 | struct md_rdev *rdev = conf->mirrors[m].rdev; |
1870 | struct bio *bio = r1_bio->bios[m]; | 1892 | struct bio *bio = r1_bio->bios[m]; |
1871 | if (bio->bi_end_io == NULL) | 1893 | if (bio->bi_end_io == NULL) |
1872 | continue; | 1894 | continue; |
@@ -1884,12 +1906,12 @@ static void handle_sync_write_finished(conf_t *conf, r1bio_t *r1_bio) | |||
1884 | md_done_sync(conf->mddev, s, 1); | 1906 | md_done_sync(conf->mddev, s, 1); |
1885 | } | 1907 | } |
1886 | 1908 | ||
1887 | static void handle_write_finished(conf_t *conf, r1bio_t *r1_bio) | 1909 | static void handle_write_finished(struct r1conf *conf, struct r1bio *r1_bio) |
1888 | { | 1910 | { |
1889 | int m; | 1911 | int m; |
1890 | for (m = 0; m < conf->raid_disks ; m++) | 1912 | for (m = 0; m < conf->raid_disks ; m++) |
1891 | if (r1_bio->bios[m] == IO_MADE_GOOD) { | 1913 | if (r1_bio->bios[m] == IO_MADE_GOOD) { |
1892 | mdk_rdev_t *rdev = conf->mirrors[m].rdev; | 1914 | struct md_rdev *rdev = conf->mirrors[m].rdev; |
1893 | rdev_clear_badblocks(rdev, | 1915 | rdev_clear_badblocks(rdev, |
1894 | r1_bio->sector, | 1916 | r1_bio->sector, |
1895 | r1_bio->sectors); | 1917 | r1_bio->sectors); |
@@ -1913,14 +1935,14 @@ static void handle_write_finished(conf_t *conf, r1bio_t *r1_bio) | |||
1913 | raid_end_bio_io(r1_bio); | 1935 | raid_end_bio_io(r1_bio); |
1914 | } | 1936 | } |
1915 | 1937 | ||
1916 | static void handle_read_error(conf_t *conf, r1bio_t *r1_bio) | 1938 | static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio) |
1917 | { | 1939 | { |
1918 | int disk; | 1940 | int disk; |
1919 | int max_sectors; | 1941 | int max_sectors; |
1920 | mddev_t *mddev = conf->mddev; | 1942 | struct mddev *mddev = conf->mddev; |
1921 | struct bio *bio; | 1943 | struct bio *bio; |
1922 | char b[BDEVNAME_SIZE]; | 1944 | char b[BDEVNAME_SIZE]; |
1923 | mdk_rdev_t *rdev; | 1945 | struct md_rdev *rdev; |
1924 | 1946 | ||
1925 | clear_bit(R1BIO_ReadError, &r1_bio->state); | 1947 | clear_bit(R1BIO_ReadError, &r1_bio->state); |
1926 | /* we got a read error. Maybe the drive is bad. Maybe just | 1948 | /* we got a read error. Maybe the drive is bad. Maybe just |
@@ -2003,11 +2025,11 @@ read_more: | |||
2003 | } | 2025 | } |
2004 | } | 2026 | } |
2005 | 2027 | ||
2006 | static void raid1d(mddev_t *mddev) | 2028 | static void raid1d(struct mddev *mddev) |
2007 | { | 2029 | { |
2008 | r1bio_t *r1_bio; | 2030 | struct r1bio *r1_bio; |
2009 | unsigned long flags; | 2031 | unsigned long flags; |
2010 | conf_t *conf = mddev->private; | 2032 | struct r1conf *conf = mddev->private; |
2011 | struct list_head *head = &conf->retry_list; | 2033 | struct list_head *head = &conf->retry_list; |
2012 | struct blk_plug plug; | 2034 | struct blk_plug plug; |
2013 | 2035 | ||
@@ -2024,7 +2046,7 @@ static void raid1d(mddev_t *mddev) | |||
2024 | spin_unlock_irqrestore(&conf->device_lock, flags); | 2046 | spin_unlock_irqrestore(&conf->device_lock, flags); |
2025 | break; | 2047 | break; |
2026 | } | 2048 | } |
2027 | r1_bio = list_entry(head->prev, r1bio_t, retry_list); | 2049 | r1_bio = list_entry(head->prev, struct r1bio, retry_list); |
2028 | list_del(head->prev); | 2050 | list_del(head->prev); |
2029 | conf->nr_queued--; | 2051 | conf->nr_queued--; |
2030 | spin_unlock_irqrestore(&conf->device_lock, flags); | 2052 | spin_unlock_irqrestore(&conf->device_lock, flags); |
@@ -2056,7 +2078,7 @@ static void raid1d(mddev_t *mddev) | |||
2056 | } | 2078 | } |
2057 | 2079 | ||
2058 | 2080 | ||
2059 | static int init_resync(conf_t *conf) | 2081 | static int init_resync(struct r1conf *conf) |
2060 | { | 2082 | { |
2061 | int buffs; | 2083 | int buffs; |
2062 | 2084 | ||
@@ -2080,10 +2102,10 @@ static int init_resync(conf_t *conf) | |||
2080 | * that can be installed to exclude normal IO requests. | 2102 | * that can be installed to exclude normal IO requests. |
2081 | */ | 2103 | */ |
2082 | 2104 | ||
2083 | static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster) | 2105 | static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipped, int go_faster) |
2084 | { | 2106 | { |
2085 | conf_t *conf = mddev->private; | 2107 | struct r1conf *conf = mddev->private; |
2086 | r1bio_t *r1_bio; | 2108 | struct r1bio *r1_bio; |
2087 | struct bio *bio; | 2109 | struct bio *bio; |
2088 | sector_t max_sector, nr_sectors; | 2110 | sector_t max_sector, nr_sectors; |
2089 | int disk = -1; | 2111 | int disk = -1; |
@@ -2163,14 +2185,13 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i | |||
2163 | set_bit(R1BIO_IsSync, &r1_bio->state); | 2185 | set_bit(R1BIO_IsSync, &r1_bio->state); |
2164 | 2186 | ||
2165 | for (i=0; i < conf->raid_disks; i++) { | 2187 | for (i=0; i < conf->raid_disks; i++) { |
2166 | mdk_rdev_t *rdev; | 2188 | struct md_rdev *rdev; |
2167 | bio = r1_bio->bios[i]; | 2189 | bio = r1_bio->bios[i]; |
2168 | 2190 | ||
2169 | /* take from bio_init */ | 2191 | /* take from bio_init */ |
2170 | bio->bi_next = NULL; | 2192 | bio->bi_next = NULL; |
2171 | bio->bi_flags &= ~(BIO_POOL_MASK-1); | 2193 | bio->bi_flags &= ~(BIO_POOL_MASK-1); |
2172 | bio->bi_flags |= 1 << BIO_UPTODATE; | 2194 | bio->bi_flags |= 1 << BIO_UPTODATE; |
2173 | bio->bi_comp_cpu = -1; | ||
2174 | bio->bi_rw = READ; | 2195 | bio->bi_rw = READ; |
2175 | bio->bi_vcnt = 0; | 2196 | bio->bi_vcnt = 0; |
2176 | bio->bi_idx = 0; | 2197 | bio->bi_idx = 0; |
@@ -2235,7 +2256,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i | |||
2235 | int ok = 1; | 2256 | int ok = 1; |
2236 | for (i = 0 ; i < conf->raid_disks ; i++) | 2257 | for (i = 0 ; i < conf->raid_disks ; i++) |
2237 | if (r1_bio->bios[i]->bi_end_io == end_sync_write) { | 2258 | if (r1_bio->bios[i]->bi_end_io == end_sync_write) { |
2238 | mdk_rdev_t *rdev = | 2259 | struct md_rdev *rdev = |
2239 | rcu_dereference(conf->mirrors[i].rdev); | 2260 | rcu_dereference(conf->mirrors[i].rdev); |
2240 | ok = rdev_set_badblocks(rdev, sector_nr, | 2261 | ok = rdev_set_badblocks(rdev, sector_nr, |
2241 | min_bad, 0 | 2262 | min_bad, 0 |
@@ -2352,7 +2373,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i | |||
2352 | return nr_sectors; | 2373 | return nr_sectors; |
2353 | } | 2374 | } |
2354 | 2375 | ||
2355 | static sector_t raid1_size(mddev_t *mddev, sector_t sectors, int raid_disks) | 2376 | static sector_t raid1_size(struct mddev *mddev, sector_t sectors, int raid_disks) |
2356 | { | 2377 | { |
2357 | if (sectors) | 2378 | if (sectors) |
2358 | return sectors; | 2379 | return sectors; |
@@ -2360,15 +2381,15 @@ static sector_t raid1_size(mddev_t *mddev, sector_t sectors, int raid_disks) | |||
2360 | return mddev->dev_sectors; | 2381 | return mddev->dev_sectors; |
2361 | } | 2382 | } |
2362 | 2383 | ||
2363 | static conf_t *setup_conf(mddev_t *mddev) | 2384 | static struct r1conf *setup_conf(struct mddev *mddev) |
2364 | { | 2385 | { |
2365 | conf_t *conf; | 2386 | struct r1conf *conf; |
2366 | int i; | 2387 | int i; |
2367 | mirror_info_t *disk; | 2388 | struct mirror_info *disk; |
2368 | mdk_rdev_t *rdev; | 2389 | struct md_rdev *rdev; |
2369 | int err = -ENOMEM; | 2390 | int err = -ENOMEM; |
2370 | 2391 | ||
2371 | conf = kzalloc(sizeof(conf_t), GFP_KERNEL); | 2392 | conf = kzalloc(sizeof(struct r1conf), GFP_KERNEL); |
2372 | if (!conf) | 2393 | if (!conf) |
2373 | goto abort; | 2394 | goto abort; |
2374 | 2395 | ||
@@ -2413,6 +2434,8 @@ static conf_t *setup_conf(mddev_t *mddev) | |||
2413 | init_waitqueue_head(&conf->wait_barrier); | 2434 | init_waitqueue_head(&conf->wait_barrier); |
2414 | 2435 | ||
2415 | bio_list_init(&conf->pending_bio_list); | 2436 | bio_list_init(&conf->pending_bio_list); |
2437 | conf->pending_count = 0; | ||
2438 | conf->recovery_disabled = mddev->recovery_disabled - 1; | ||
2416 | 2439 | ||
2417 | conf->last_used = -1; | 2440 | conf->last_used = -1; |
2418 | for (i = 0; i < conf->raid_disks; i++) { | 2441 | for (i = 0; i < conf->raid_disks; i++) { |
@@ -2461,11 +2484,11 @@ static conf_t *setup_conf(mddev_t *mddev) | |||
2461 | return ERR_PTR(err); | 2484 | return ERR_PTR(err); |
2462 | } | 2485 | } |
2463 | 2486 | ||
2464 | static int run(mddev_t *mddev) | 2487 | static int run(struct mddev *mddev) |
2465 | { | 2488 | { |
2466 | conf_t *conf; | 2489 | struct r1conf *conf; |
2467 | int i; | 2490 | int i; |
2468 | mdk_rdev_t *rdev; | 2491 | struct md_rdev *rdev; |
2469 | 2492 | ||
2470 | if (mddev->level != 1) { | 2493 | if (mddev->level != 1) { |
2471 | printk(KERN_ERR "md/raid1:%s: raid level not set to mirroring (%d)\n", | 2494 | printk(KERN_ERR "md/raid1:%s: raid level not set to mirroring (%d)\n", |
@@ -2541,9 +2564,9 @@ static int run(mddev_t *mddev) | |||
2541 | return md_integrity_register(mddev); | 2564 | return md_integrity_register(mddev); |
2542 | } | 2565 | } |
2543 | 2566 | ||
2544 | static int stop(mddev_t *mddev) | 2567 | static int stop(struct mddev *mddev) |
2545 | { | 2568 | { |
2546 | conf_t *conf = mddev->private; | 2569 | struct r1conf *conf = mddev->private; |
2547 | struct bitmap *bitmap = mddev->bitmap; | 2570 | struct bitmap *bitmap = mddev->bitmap; |
2548 | 2571 | ||
2549 | /* wait for behind writes to complete */ | 2572 | /* wait for behind writes to complete */ |
@@ -2558,8 +2581,7 @@ static int stop(mddev_t *mddev) | |||
2558 | raise_barrier(conf); | 2581 | raise_barrier(conf); |
2559 | lower_barrier(conf); | 2582 | lower_barrier(conf); |
2560 | 2583 | ||
2561 | md_unregister_thread(mddev->thread); | 2584 | md_unregister_thread(&mddev->thread); |
2562 | mddev->thread = NULL; | ||
2563 | if (conf->r1bio_pool) | 2585 | if (conf->r1bio_pool) |
2564 | mempool_destroy(conf->r1bio_pool); | 2586 | mempool_destroy(conf->r1bio_pool); |
2565 | kfree(conf->mirrors); | 2587 | kfree(conf->mirrors); |
@@ -2569,7 +2591,7 @@ static int stop(mddev_t *mddev) | |||
2569 | return 0; | 2591 | return 0; |
2570 | } | 2592 | } |
2571 | 2593 | ||
2572 | static int raid1_resize(mddev_t *mddev, sector_t sectors) | 2594 | static int raid1_resize(struct mddev *mddev, sector_t sectors) |
2573 | { | 2595 | { |
2574 | /* no resync is happening, and there is enough space | 2596 | /* no resync is happening, and there is enough space |
2575 | * on all devices, so we can resize. | 2597 | * on all devices, so we can resize. |
@@ -2593,7 +2615,7 @@ static int raid1_resize(mddev_t *mddev, sector_t sectors) | |||
2593 | return 0; | 2615 | return 0; |
2594 | } | 2616 | } |
2595 | 2617 | ||
2596 | static int raid1_reshape(mddev_t *mddev) | 2618 | static int raid1_reshape(struct mddev *mddev) |
2597 | { | 2619 | { |
2598 | /* We need to: | 2620 | /* We need to: |
2599 | * 1/ resize the r1bio_pool | 2621 | * 1/ resize the r1bio_pool |
@@ -2608,8 +2630,8 @@ static int raid1_reshape(mddev_t *mddev) | |||
2608 | */ | 2630 | */ |
2609 | mempool_t *newpool, *oldpool; | 2631 | mempool_t *newpool, *oldpool; |
2610 | struct pool_info *newpoolinfo; | 2632 | struct pool_info *newpoolinfo; |
2611 | mirror_info_t *newmirrors; | 2633 | struct mirror_info *newmirrors; |
2612 | conf_t *conf = mddev->private; | 2634 | struct r1conf *conf = mddev->private; |
2613 | int cnt, raid_disks; | 2635 | int cnt, raid_disks; |
2614 | unsigned long flags; | 2636 | unsigned long flags; |
2615 | int d, d2, err; | 2637 | int d, d2, err; |
@@ -2665,7 +2687,7 @@ static int raid1_reshape(mddev_t *mddev) | |||
2665 | conf->r1bio_pool = newpool; | 2687 | conf->r1bio_pool = newpool; |
2666 | 2688 | ||
2667 | for (d = d2 = 0; d < conf->raid_disks; d++) { | 2689 | for (d = d2 = 0; d < conf->raid_disks; d++) { |
2668 | mdk_rdev_t *rdev = conf->mirrors[d].rdev; | 2690 | struct md_rdev *rdev = conf->mirrors[d].rdev; |
2669 | if (rdev && rdev->raid_disk != d2) { | 2691 | if (rdev && rdev->raid_disk != d2) { |
2670 | sysfs_unlink_rdev(mddev, rdev); | 2692 | sysfs_unlink_rdev(mddev, rdev); |
2671 | rdev->raid_disk = d2; | 2693 | rdev->raid_disk = d2; |
@@ -2699,9 +2721,9 @@ static int raid1_reshape(mddev_t *mddev) | |||
2699 | return 0; | 2721 | return 0; |
2700 | } | 2722 | } |
2701 | 2723 | ||
2702 | static void raid1_quiesce(mddev_t *mddev, int state) | 2724 | static void raid1_quiesce(struct mddev *mddev, int state) |
2703 | { | 2725 | { |
2704 | conf_t *conf = mddev->private; | 2726 | struct r1conf *conf = mddev->private; |
2705 | 2727 | ||
2706 | switch(state) { | 2728 | switch(state) { |
2707 | case 2: /* wake for suspend */ | 2729 | case 2: /* wake for suspend */ |
@@ -2716,13 +2738,13 @@ static void raid1_quiesce(mddev_t *mddev, int state) | |||
2716 | } | 2738 | } |
2717 | } | 2739 | } |
2718 | 2740 | ||
2719 | static void *raid1_takeover(mddev_t *mddev) | 2741 | static void *raid1_takeover(struct mddev *mddev) |
2720 | { | 2742 | { |
2721 | /* raid1 can take over: | 2743 | /* raid1 can take over: |
2722 | * raid5 with 2 devices, any layout or chunk size | 2744 | * raid5 with 2 devices, any layout or chunk size |
2723 | */ | 2745 | */ |
2724 | if (mddev->level == 5 && mddev->raid_disks == 2) { | 2746 | if (mddev->level == 5 && mddev->raid_disks == 2) { |
2725 | conf_t *conf; | 2747 | struct r1conf *conf; |
2726 | mddev->new_level = 1; | 2748 | mddev->new_level = 1; |
2727 | mddev->new_layout = 0; | 2749 | mddev->new_layout = 0; |
2728 | mddev->new_chunk_sectors = 0; | 2750 | mddev->new_chunk_sectors = 0; |
@@ -2734,7 +2756,7 @@ static void *raid1_takeover(mddev_t *mddev) | |||
2734 | return ERR_PTR(-EINVAL); | 2756 | return ERR_PTR(-EINVAL); |
2735 | } | 2757 | } |
2736 | 2758 | ||
2737 | static struct mdk_personality raid1_personality = | 2759 | static struct md_personality raid1_personality = |
2738 | { | 2760 | { |
2739 | .name = "raid1", | 2761 | .name = "raid1", |
2740 | .level = 1, | 2762 | .level = 1, |
@@ -2772,3 +2794,5 @@ MODULE_DESCRIPTION("RAID1 (mirroring) personality for MD"); | |||
2772 | MODULE_ALIAS("md-personality-3"); /* RAID1 */ | 2794 | MODULE_ALIAS("md-personality-3"); /* RAID1 */ |
2773 | MODULE_ALIAS("md-raid1"); | 2795 | MODULE_ALIAS("md-raid1"); |
2774 | MODULE_ALIAS("md-level-1"); | 2796 | MODULE_ALIAS("md-level-1"); |
2797 | |||
2798 | module_param(max_queued_requests, int, S_IRUGO|S_IWUSR); | ||