raid10.c (91de76e661a266731fc2889a398ad1694df9d523) raid10.c (b03e0ccb5ab9df3efbe51c87843a1ffbecbafa1f)
1/*
2 * raid10.c : Multiple Devices driver for Linux
3 *
4 * Copyright (C) 2000-2004 Neil Brown
5 *
6 * RAID-10 support for md.
7 *
8 * Base on code in raid1.c. See raid1.c for further copyright information.

--- 15 unchanged lines hidden (view full) ---

24#include <linux/module.h>
25#include <linux/seq_file.h>
26#include <linux/ratelimit.h>
27#include <linux/kthread.h>
28#include <trace/events/block.h>
29#include "md.h"
30#include "raid10.h"
31#include "raid0.h"
1/*
2 * raid10.c : Multiple Devices driver for Linux
3 *
4 * Copyright (C) 2000-2004 Neil Brown
5 *
6 * RAID-10 support for md.
7 *
8 * Base on code in raid1.c. See raid1.c for further copyright information.

--- 15 unchanged lines hidden (view full) ---

24#include <linux/module.h>
25#include <linux/seq_file.h>
26#include <linux/ratelimit.h>
27#include <linux/kthread.h>
28#include <trace/events/block.h>
29#include "md.h"
30#include "raid10.h"
31#include "raid0.h"
32#include "bitmap.h"
32#include "md-bitmap.h"
33
34/*
35 * RAID10 provides a combination of RAID0 and RAID1 functionality.
36 * The layout of data is defined by
37 * chunk_size
38 * raid_disks
39 * near_copies (stored in low byte of layout)
40 * far_copies (stored in second byte of layout)

--- 337 unchanged lines hidden (view full) ---

378 *replp = repl;
379 return r10_bio->devs[slot].devnum;
380}
381
382static void raid10_end_read_request(struct bio *bio)
383{
384 int uptodate = !bio->bi_status;
385 struct r10bio *r10_bio = bio->bi_private;
33
34/*
35 * RAID10 provides a combination of RAID0 and RAID1 functionality.
36 * The layout of data is defined by
37 * chunk_size
38 * raid_disks
39 * near_copies (stored in low byte of layout)
40 * far_copies (stored in second byte of layout)

--- 337 unchanged lines hidden (view full) ---

378 *replp = repl;
379 return r10_bio->devs[slot].devnum;
380}
381
382static void raid10_end_read_request(struct bio *bio)
383{
384 int uptodate = !bio->bi_status;
385 struct r10bio *r10_bio = bio->bi_private;
386 int slot, dev;
386 int slot;
387 struct md_rdev *rdev;
388 struct r10conf *conf = r10_bio->mddev->private;
389
390 slot = r10_bio->read_slot;
387 struct md_rdev *rdev;
388 struct r10conf *conf = r10_bio->mddev->private;
389
390 slot = r10_bio->read_slot;
391 dev = r10_bio->devs[slot].devnum;
392 rdev = r10_bio->devs[slot].rdev;
393 /*
394 * this branch is our 'one mirror IO has finished' event handler:
395 */
396 update_head_pos(slot, r10_bio);
397
398 if (uptodate) {
399 /*

--- 343 unchanged lines hidden (view full) ---

743 sector_t new_distance, best_dist;
744 struct md_rdev *best_rdev, *rdev = NULL;
745 int do_balance;
746 int best_slot;
747 struct geom *geo = &conf->geo;
748
749 raid10_find_phys(conf, r10_bio);
750 rcu_read_lock();
391 rdev = r10_bio->devs[slot].rdev;
392 /*
393 * this branch is our 'one mirror IO has finished' event handler:
394 */
395 update_head_pos(slot, r10_bio);
396
397 if (uptodate) {
398 /*

--- 343 unchanged lines hidden (view full) ---

742 sector_t new_distance, best_dist;
743 struct md_rdev *best_rdev, *rdev = NULL;
744 int do_balance;
745 int best_slot;
746 struct geom *geo = &conf->geo;
747
748 raid10_find_phys(conf, r10_bio);
749 rcu_read_lock();
751 sectors = r10_bio->sectors;
752 best_slot = -1;
753 best_rdev = NULL;
754 best_dist = MaxSector;
755 best_good_sectors = 0;
756 do_balance = 1;
757 clear_bit(R10BIO_FailFast, &r10_bio->state);
758 /*
759 * Check if we can balance. We can balance on the whole

--- 1810 unchanged lines hidden (view full) ---

2570}
2571
2572static void handle_read_error(struct mddev *mddev, struct r10bio *r10_bio)
2573{
2574 int slot = r10_bio->read_slot;
2575 struct bio *bio;
2576 struct r10conf *conf = mddev->private;
2577 struct md_rdev *rdev = r10_bio->devs[slot].rdev;
750 best_slot = -1;
751 best_rdev = NULL;
752 best_dist = MaxSector;
753 best_good_sectors = 0;
754 do_balance = 1;
755 clear_bit(R10BIO_FailFast, &r10_bio->state);
756 /*
757 * Check if we can balance. We can balance on the whole

--- 1810 unchanged lines hidden (view full) ---

2568}
2569
2570static void handle_read_error(struct mddev *mddev, struct r10bio *r10_bio)
2571{
2572 int slot = r10_bio->read_slot;
2573 struct bio *bio;
2574 struct r10conf *conf = mddev->private;
2575 struct md_rdev *rdev = r10_bio->devs[slot].rdev;
2578 sector_t bio_last_sector;
2579
2580 /* we got a read error. Maybe the drive is bad. Maybe just
2581 * the block and we can fix it.
2582 * We freeze all other IO, and try reading the block from
2583 * other devices. When we find one, we re-write
2584 * and check it that fixes the read error.
2585 * This is all done synchronously while the array is
2586 * frozen.
2587 */
2588 bio = r10_bio->devs[slot].bio;
2576
2577 /* we got a read error. Maybe the drive is bad. Maybe just
2578 * the block and we can fix it.
2579 * We freeze all other IO, and try reading the block from
2580 * other devices. When we find one, we re-write
2581 * and check it that fixes the read error.
2582 * This is all done synchronously while the array is
2583 * frozen.
2584 */
2585 bio = r10_bio->devs[slot].bio;
2589 bio_last_sector = r10_bio->devs[slot].addr + rdev->data_offset + r10_bio->sectors;
2590 bio_put(bio);
2591 r10_bio->devs[slot].bio = NULL;
2592
2593 if (mddev->ro)
2594 r10_bio->devs[slot].bio = IO_BLOCKED;
2595 else if (!test_bit(FailFast, &rdev->flags)) {
2596 freeze_array(conf, 1);
2597 fix_read_error(conf, mddev, r10_bio);

--- 1229 unchanged lines hidden (view full) ---

3827 kfree(conf->mirrors);
3828 kfree(conf->mirrors_old);
3829 kfree(conf->mirrors_new);
3830 if (conf->bio_split)
3831 bioset_free(conf->bio_split);
3832 kfree(conf);
3833}
3834
2586 bio_put(bio);
2587 r10_bio->devs[slot].bio = NULL;
2588
2589 if (mddev->ro)
2590 r10_bio->devs[slot].bio = IO_BLOCKED;
2591 else if (!test_bit(FailFast, &rdev->flags)) {
2592 freeze_array(conf, 1);
2593 fix_read_error(conf, mddev, r10_bio);

--- 1229 unchanged lines hidden (view full) ---

3823 kfree(conf->mirrors);
3824 kfree(conf->mirrors_old);
3825 kfree(conf->mirrors_new);
3826 if (conf->bio_split)
3827 bioset_free(conf->bio_split);
3828 kfree(conf);
3829}
3830
3835static void raid10_quiesce(struct mddev *mddev, int state)
3831static void raid10_quiesce(struct mddev *mddev, int quiesce)
3836{
3837 struct r10conf *conf = mddev->private;
3838
3832{
3833 struct r10conf *conf = mddev->private;
3834
3839 switch(state) {
3840 case 1:
3835 if (quiesce)
3841 raise_barrier(conf, 0);
3836 raise_barrier(conf, 0);
3842 break;
3843 case 0:
3837 else
3844 lower_barrier(conf);
3838 lower_barrier(conf);
3845 break;
3846 }
3847}
3848
3849static int raid10_resize(struct mddev *mddev, sector_t sectors)
3850{
3851 /* Resize of 'far' arrays is not supported.
3852 * For 'near' and 'offset' arrays we can set the
3853 * number of sectors used to be an appropriate multiple
3854 * of the chunk size.

--- 718 unchanged lines hidden (view full) ---

4573}
4574
4575static int handle_reshape_read_error(struct mddev *mddev,
4576 struct r10bio *r10_bio)
4577{
4578 /* Use sync reads to get the blocks from somewhere else */
4579 int sectors = r10_bio->sectors;
4580 struct r10conf *conf = mddev->private;
3839}
3840
3841static int raid10_resize(struct mddev *mddev, sector_t sectors)
3842{
3843 /* Resize of 'far' arrays is not supported.
3844 * For 'near' and 'offset' arrays we can set the
3845 * number of sectors used to be an appropriate multiple
3846 * of the chunk size.

--- 718 unchanged lines hidden (view full) ---

4565}
4566
4567static int handle_reshape_read_error(struct mddev *mddev,
4568 struct r10bio *r10_bio)
4569{
4570 /* Use sync reads to get the blocks from somewhere else */
4571 int sectors = r10_bio->sectors;
4572 struct r10conf *conf = mddev->private;
4581 struct {
4582 struct r10bio r10_bio;
4583 struct r10dev devs[conf->copies];
4584 } on_stack;
4585 struct r10bio *r10b = &on_stack.r10_bio;
4573 struct r10bio *r10b;
4586 int slot = 0;
4587 int idx = 0;
4588 struct page **pages;
4589
4574 int slot = 0;
4575 int idx = 0;
4576 struct page **pages;
4577
4578 r10b = kmalloc(sizeof(*r10b) +
4579 sizeof(struct r10dev) * conf->copies, GFP_NOIO);
4580 if (!r10b) {
4581 set_bit(MD_RECOVERY_INTR, &mddev->recovery);
4582 return -ENOMEM;
4583 }
4584
4590 /* reshape IOs share pages from .devs[0].bio */
4591 pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
4592
4593 r10b->sector = r10_bio->sector;
4594 __raid10_find_phys(&conf->prev, r10b);
4595
4596 while (sectors) {
4597 int s = sectors;

--- 32 unchanged lines hidden (view full) ---

4630 if (slot == first_slot)
4631 break;
4632 }
4633 rcu_read_unlock();
4634 if (!success) {
4635 /* couldn't read this block, must give up */
4636 set_bit(MD_RECOVERY_INTR,
4637 &mddev->recovery);
4585 /* reshape IOs share pages from .devs[0].bio */
4586 pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
4587
4588 r10b->sector = r10_bio->sector;
4589 __raid10_find_phys(&conf->prev, r10b);
4590
4591 while (sectors) {
4592 int s = sectors;

--- 32 unchanged lines hidden (view full) ---

4625 if (slot == first_slot)
4626 break;
4627 }
4628 rcu_read_unlock();
4629 if (!success) {
4630 /* couldn't read this block, must give up */
4631 set_bit(MD_RECOVERY_INTR,
4632 &mddev->recovery);
4633 kfree(r10b);
4638 return -EIO;
4639 }
4640 sectors -= s;
4641 idx++;
4642 }
4634 return -EIO;
4635 }
4636 sectors -= s;
4637 idx++;
4638 }
4639 kfree(r10b);
4643 return 0;
4644}
4645
4646static void end_reshape_write(struct bio *bio)
4647{
4648 struct r10bio *r10_bio = get_resync_r10bio(bio);
4649 struct mddev *mddev = r10_bio->mddev;
4650 struct r10conf *conf = mddev->private;

--- 115 unchanged lines hidden ---
4640 return 0;
4641}
4642
4643static void end_reshape_write(struct bio *bio)
4644{
4645 struct r10bio *r10_bio = get_resync_r10bio(bio);
4646 struct mddev *mddev = r10_bio->mddev;
4647 struct r10conf *conf = mddev->private;

--- 115 unchanged lines hidden ---