Lines Matching refs:conf
46 static void allow_barrier(struct r1conf *conf, sector_t sector_nr);
47 static void lower_barrier(struct r1conf *conf, sector_t sector_nr);
239 static void put_all_bios(struct r1conf *conf, struct r1bio *r1_bio) in put_all_bios() argument
243 for (i = 0; i < conf->raid_disks * 2; i++) { in put_all_bios()
253 struct r1conf *conf = r1_bio->mddev->private; in free_r1bio() local
255 put_all_bios(conf, r1_bio); in free_r1bio()
256 mempool_free(r1_bio, &conf->r1bio_pool); in free_r1bio()
261 struct r1conf *conf = r1_bio->mddev->private; in put_buf() local
265 for (i = 0; i < conf->raid_disks * 2; i++) { in put_buf()
268 rdev_dec_pending(conf->mirrors[i].rdev, r1_bio->mddev); in put_buf()
271 mempool_free(r1_bio, &conf->r1buf_pool); in put_buf()
273 lower_barrier(conf, sect); in put_buf()
280 struct r1conf *conf = mddev->private; in reschedule_retry() local
284 spin_lock_irqsave(&conf->device_lock, flags); in reschedule_retry()
285 list_add(&r1_bio->retry_list, &conf->retry_list); in reschedule_retry()
286 atomic_inc(&conf->nr_queued[idx]); in reschedule_retry()
287 spin_unlock_irqrestore(&conf->device_lock, flags); in reschedule_retry()
289 wake_up(&conf->wait_barrier); in reschedule_retry()
311 struct r1conf *conf = r1_bio->mddev->private; in raid_end_bio_io() local
329 allow_barrier(conf, sector); in raid_end_bio_io()
337 struct r1conf *conf = r1_bio->mddev->private; in update_head_pos() local
339 conf->mirrors[disk].head_position = in update_head_pos()
349 struct r1conf *conf = r1_bio->mddev->private; in find_bio_disk() local
350 int raid_disks = conf->raid_disks; in find_bio_disk()
366 struct r1conf *conf = r1_bio->mddev->private; in raid1_end_read_request() local
367 struct md_rdev *rdev = conf->mirrors[r1_bio->read_disk].rdev; in raid1_end_read_request()
387 spin_lock_irqsave(&conf->device_lock, flags); in raid1_end_read_request()
388 if (r1_bio->mddev->degraded == conf->raid_disks || in raid1_end_read_request()
389 (r1_bio->mddev->degraded == conf->raid_disks-1 && in raid1_end_read_request()
392 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_end_read_request()
397 rdev_dec_pending(rdev, conf->mddev); in raid1_end_read_request()
403 mdname(conf->mddev), in raid1_end_read_request()
450 struct r1conf *conf = r1_bio->mddev->private; in raid1_end_write_request() local
453 struct md_rdev *rdev = conf->mirrors[mirror].rdev; in raid1_end_write_request()
467 conf->mddev->recovery); in raid1_end_write_request()
550 rdev_dec_pending(rdev, conf->mddev); in raid1_end_write_request()
581 static void update_read_sectors(struct r1conf *conf, int disk, in update_read_sectors() argument
584 struct raid1_info *info = &conf->mirrors[disk]; in update_read_sectors()
592 static int choose_first_rdev(struct r1conf *conf, struct r1bio *r1_bio, in choose_first_rdev() argument
599 for (disk = 0 ; disk < conf->raid_disks * 2 ; disk++) { in choose_first_rdev()
606 rdev = conf->mirrors[disk].rdev; in choose_first_rdev()
613 update_read_sectors(conf, disk, this_sector, read_len); in choose_first_rdev()
628 static int choose_bb_rdev(struct r1conf *conf, struct r1bio *r1_bio, in choose_bb_rdev() argument
636 for (disk = 0 ; disk < conf->raid_disks * 2 ; disk++) { in choose_bb_rdev()
644 rdev = conf->mirrors[disk].rdev; in choose_bb_rdev()
661 update_read_sectors(conf, best_disk, this_sector, best_len); in choose_bb_rdev()
667 static int choose_slow_rdev(struct r1conf *conf, struct r1bio *r1_bio, in choose_slow_rdev() argument
675 for (disk = 0 ; disk < conf->raid_disks * 2 ; disk++) { in choose_slow_rdev()
683 rdev = conf->mirrors[disk].rdev; in choose_slow_rdev()
694 update_read_sectors(conf, disk, this_sector, read_len); in choose_slow_rdev()
710 update_read_sectors(conf, bb_disk, this_sector, bb_read_len); in choose_slow_rdev()
716 static bool is_sequential(struct r1conf *conf, int disk, struct r1bio *r1_bio) in is_sequential() argument
719 return conf->mirrors[disk].next_seq_sect == r1_bio->sector || in is_sequential()
720 conf->mirrors[disk].head_position == r1_bio->sector; in is_sequential()
727 static bool should_choose_next(struct r1conf *conf, int disk) in should_choose_next() argument
729 struct raid1_info *mirror = &conf->mirrors[disk]; in should_choose_next()
769 static int choose_best_rdev(struct r1conf *conf, struct r1bio *r1_bio) in choose_best_rdev() argument
780 for (disk = 0 ; disk < conf->raid_disks * 2 ; disk++) { in choose_best_rdev()
788 rdev = conf->mirrors[disk].rdev; in choose_best_rdev()
797 dist = abs(r1_bio->sector - conf->mirrors[disk].head_position); in choose_best_rdev()
800 if (is_sequential(conf, disk, r1_bio)) { in choose_best_rdev()
801 if (!should_choose_next(conf, disk)) in choose_best_rdev()
841 (READ_ONCE(conf->nonrot_disks) || ctl.min_pending == 0)) in choose_best_rdev()
865 static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, in read_balance() argument
872 if (raid1_should_read_first(conf->mddev, r1_bio->sector, in read_balance()
874 return choose_first_rdev(conf, r1_bio, max_sectors); in read_balance()
876 disk = choose_best_rdev(conf, r1_bio); in read_balance()
879 update_read_sectors(conf, disk, r1_bio->sector, in read_balance()
889 disk = choose_bb_rdev(conf, r1_bio, max_sectors); in read_balance()
893 return choose_slow_rdev(conf, r1_bio, max_sectors); in read_balance()
896 static void wake_up_barrier(struct r1conf *conf) in wake_up_barrier() argument
898 if (wq_has_sleeper(&conf->wait_barrier)) in wake_up_barrier()
899 wake_up(&conf->wait_barrier); in wake_up_barrier()
902 static void flush_bio_list(struct r1conf *conf, struct bio *bio) in flush_bio_list() argument
905 raid1_prepare_flush_writes(conf->mddev); in flush_bio_list()
906 wake_up_barrier(conf); in flush_bio_list()
917 static void flush_pending_writes(struct r1conf *conf) in flush_pending_writes() argument
922 spin_lock_irq(&conf->device_lock); in flush_pending_writes()
924 if (conf->pending_bio_list.head) { in flush_pending_writes()
928 bio = bio_list_get(&conf->pending_bio_list); in flush_pending_writes()
929 spin_unlock_irq(&conf->device_lock); in flush_pending_writes()
942 flush_bio_list(conf, bio); in flush_pending_writes()
945 spin_unlock_irq(&conf->device_lock); in flush_pending_writes()
972 static int raise_barrier(struct r1conf *conf, sector_t sector_nr) in raise_barrier() argument
976 spin_lock_irq(&conf->resync_lock); in raise_barrier()
979 wait_event_lock_irq(conf->wait_barrier, in raise_barrier()
980 !atomic_read(&conf->nr_waiting[idx]), in raise_barrier()
981 conf->resync_lock); in raise_barrier()
984 atomic_inc(&conf->barrier[idx]); in raise_barrier()
1002 wait_event_lock_irq(conf->wait_barrier, in raise_barrier()
1003 (!conf->array_frozen && in raise_barrier()
1004 !atomic_read(&conf->nr_pending[idx]) && in raise_barrier()
1005 atomic_read(&conf->barrier[idx]) < RESYNC_DEPTH) || in raise_barrier()
1006 test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery), in raise_barrier()
1007 conf->resync_lock); in raise_barrier()
1009 if (test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { in raise_barrier()
1010 atomic_dec(&conf->barrier[idx]); in raise_barrier()
1011 spin_unlock_irq(&conf->resync_lock); in raise_barrier()
1012 wake_up(&conf->wait_barrier); in raise_barrier()
1016 atomic_inc(&conf->nr_sync_pending); in raise_barrier()
1017 spin_unlock_irq(&conf->resync_lock); in raise_barrier()
1022 static void lower_barrier(struct r1conf *conf, sector_t sector_nr) in lower_barrier() argument
1026 BUG_ON(atomic_read(&conf->barrier[idx]) <= 0); in lower_barrier()
1028 atomic_dec(&conf->barrier[idx]); in lower_barrier()
1029 atomic_dec(&conf->nr_sync_pending); in lower_barrier()
1030 wake_up(&conf->wait_barrier); in lower_barrier()
1033 static bool _wait_barrier(struct r1conf *conf, int idx, bool nowait) in _wait_barrier() argument
1045 atomic_inc(&conf->nr_pending[idx]); in _wait_barrier()
1065 if (!READ_ONCE(conf->array_frozen) && in _wait_barrier()
1066 !atomic_read(&conf->barrier[idx])) in _wait_barrier()
1076 spin_lock_irq(&conf->resync_lock); in _wait_barrier()
1077 atomic_inc(&conf->nr_waiting[idx]); in _wait_barrier()
1078 atomic_dec(&conf->nr_pending[idx]); in _wait_barrier()
1083 wake_up_barrier(conf); in _wait_barrier()
1090 wait_event_lock_irq(conf->wait_barrier, in _wait_barrier()
1091 !conf->array_frozen && in _wait_barrier()
1092 !atomic_read(&conf->barrier[idx]), in _wait_barrier()
1093 conf->resync_lock); in _wait_barrier()
1094 atomic_inc(&conf->nr_pending[idx]); in _wait_barrier()
1097 atomic_dec(&conf->nr_waiting[idx]); in _wait_barrier()
1098 spin_unlock_irq(&conf->resync_lock); in _wait_barrier()
1102 static bool wait_read_barrier(struct r1conf *conf, sector_t sector_nr, bool nowait) in wait_read_barrier() argument
1114 atomic_inc(&conf->nr_pending[idx]); in wait_read_barrier()
1116 if (!READ_ONCE(conf->array_frozen)) in wait_read_barrier()
1119 spin_lock_irq(&conf->resync_lock); in wait_read_barrier()
1120 atomic_inc(&conf->nr_waiting[idx]); in wait_read_barrier()
1121 atomic_dec(&conf->nr_pending[idx]); in wait_read_barrier()
1126 wake_up_barrier(conf); in wait_read_barrier()
1134 wait_event_lock_irq(conf->wait_barrier, in wait_read_barrier()
1135 !conf->array_frozen, in wait_read_barrier()
1136 conf->resync_lock); in wait_read_barrier()
1137 atomic_inc(&conf->nr_pending[idx]); in wait_read_barrier()
1140 atomic_dec(&conf->nr_waiting[idx]); in wait_read_barrier()
1141 spin_unlock_irq(&conf->resync_lock); in wait_read_barrier()
1145 static bool wait_barrier(struct r1conf *conf, sector_t sector_nr, bool nowait) in wait_barrier() argument
1149 return _wait_barrier(conf, idx, nowait); in wait_barrier()
1152 static void _allow_barrier(struct r1conf *conf, int idx) in _allow_barrier() argument
1154 atomic_dec(&conf->nr_pending[idx]); in _allow_barrier()
1155 wake_up_barrier(conf); in _allow_barrier()
1158 static void allow_barrier(struct r1conf *conf, sector_t sector_nr) in allow_barrier() argument
1162 _allow_barrier(conf, idx); in allow_barrier()
1166 static int get_unqueued_pending(struct r1conf *conf) in get_unqueued_pending() argument
1170 ret = atomic_read(&conf->nr_sync_pending); in get_unqueued_pending()
1172 ret += atomic_read(&conf->nr_pending[idx]) - in get_unqueued_pending()
1173 atomic_read(&conf->nr_queued[idx]); in get_unqueued_pending()
1178 static void freeze_array(struct r1conf *conf, int extra) in freeze_array() argument
1203 spin_lock_irq(&conf->resync_lock); in freeze_array()
1204 conf->array_frozen = 1; in freeze_array()
1205 mddev_add_trace_msg(conf->mddev, "raid1 wait freeze"); in freeze_array()
1207 conf->wait_barrier, in freeze_array()
1208 get_unqueued_pending(conf) == extra, in freeze_array()
1209 conf->resync_lock, in freeze_array()
1210 flush_pending_writes(conf)); in freeze_array()
1211 spin_unlock_irq(&conf->resync_lock); in freeze_array()
1213 static void unfreeze_array(struct r1conf *conf) in unfreeze_array() argument
1216 spin_lock_irq(&conf->resync_lock); in unfreeze_array()
1217 conf->array_frozen = 0; in unfreeze_array()
1218 spin_unlock_irq(&conf->resync_lock); in unfreeze_array()
1219 wake_up(&conf->wait_barrier); in unfreeze_array()
1275 struct r1conf *conf = mddev->private; in raid1_unplug() local
1279 spin_lock_irq(&conf->device_lock); in raid1_unplug()
1280 bio_list_merge(&conf->pending_bio_list, &plug->pending); in raid1_unplug()
1281 spin_unlock_irq(&conf->device_lock); in raid1_unplug()
1282 wake_up_barrier(conf); in raid1_unplug()
1290 flush_bio_list(conf, bio); in raid1_unplug()
1306 struct r1conf *conf = mddev->private; in alloc_r1bio() local
1309 r1_bio = mempool_alloc(&conf->r1bio_pool, GFP_NOIO); in alloc_r1bio()
1311 memset(r1_bio->bios, 0, conf->raid_disks * sizeof(r1_bio->bios[0])); in alloc_r1bio()
1319 struct r1conf *conf = mddev->private; in raid1_read_request() local
1339 if (!wait_read_barrier(conf, bio->bi_iter.bi_sector, in raid1_read_request()
1355 rdisk = read_balance(conf, r1_bio, &max_sectors); in raid1_read_request()
1361 conf->mirrors[r1_bio->read_disk].rdev->bdev, in raid1_read_request()
1366 mirror = conf->mirrors + rdisk; in raid1_read_request()
1385 gfp, &conf->bio_split); in raid1_read_request()
1429 struct r1conf *conf = mddev->private; in wait_blocked_rdev() local
1430 int disks = conf->raid_disks * 2; in wait_blocked_rdev()
1435 struct md_rdev *rdev = conf->mirrors[i].rdev; in wait_blocked_rdev()
1464 struct r1conf *conf = mddev->private; in raid1_write_request() local
1483 prepare_to_wait(&conf->wait_barrier, in raid1_write_request()
1491 finish_wait(&conf->wait_barrier, &w); in raid1_write_request()
1499 if (!wait_barrier(conf, bio->bi_iter.bi_sector, in raid1_write_request()
1524 disks = conf->raid_disks * 2; in raid1_write_request()
1527 struct md_rdev *rdev = conf->mirrors[i].rdev; in raid1_write_request()
1539 if (i < conf->raid_disks) in raid1_write_request()
1607 GFP_NOIO, &conf->bio_split); in raid1_write_request()
1629 struct md_rdev *rdev = conf->mirrors[i].rdev; in raid1_write_request()
1678 conf->raid_disks - mddev->degraded > 1) in raid1_write_request()
1687 spin_lock_irqsave(&conf->device_lock, flags); in raid1_write_request()
1688 bio_list_add(&conf->pending_bio_list, mbio); in raid1_write_request()
1689 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_write_request()
1697 wake_up_barrier(conf); in raid1_write_request()
1702 rdev_dec_pending(conf->mirrors[k].rdev, mddev); in raid1_write_request()
1741 struct r1conf *conf = mddev->private; in raid1_status() local
1746 seq_printf(seq, " [%d/%d] [", conf->raid_disks, in raid1_status()
1747 conf->raid_disks - mddev->degraded); in raid1_status()
1748 for (i = 0; i < conf->raid_disks; i++) { in raid1_status()
1749 struct md_rdev *rdev = READ_ONCE(conf->mirrors[i].rdev); in raid1_status()
1775 struct r1conf *conf = mddev->private; in raid1_error() local
1778 spin_lock_irqsave(&conf->device_lock, flags); in raid1_error()
1781 (conf->raid_disks - mddev->degraded) == 1) { in raid1_error()
1785 conf->recovery_disabled = mddev->recovery_disabled; in raid1_error()
1786 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_error()
1794 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_error()
1804 mdname(mddev), conf->raid_disks - mddev->degraded); in raid1_error()
1807 static void print_conf(struct r1conf *conf) in print_conf() argument
1812 if (!conf) { in print_conf()
1816 pr_debug(" --- wd:%d rd:%d\n", conf->raid_disks - conf->mddev->degraded, in print_conf()
1817 conf->raid_disks); in print_conf()
1819 lockdep_assert_held(&conf->mddev->reconfig_mutex); in print_conf()
1820 for (i = 0; i < conf->raid_disks; i++) { in print_conf()
1821 struct md_rdev *rdev = conf->mirrors[i].rdev; in print_conf()
1830 static void close_sync(struct r1conf *conf) in close_sync() argument
1835 _wait_barrier(conf, idx, false); in close_sync()
1836 _allow_barrier(conf, idx); in close_sync()
1839 mempool_exit(&conf->r1buf_pool); in close_sync()
1845 struct r1conf *conf = mddev->private; in raid1_spare_active() local
1856 spin_lock_irqsave(&conf->device_lock, flags); in raid1_spare_active()
1857 for (i = 0; i < conf->raid_disks; i++) { in raid1_spare_active()
1858 struct md_rdev *rdev = conf->mirrors[i].rdev; in raid1_spare_active()
1859 struct md_rdev *repl = conf->mirrors[conf->raid_disks + i].rdev; in raid1_spare_active()
1888 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_spare_active()
1890 print_conf(conf); in raid1_spare_active()
1894 static bool raid1_add_conf(struct r1conf *conf, struct md_rdev *rdev, int disk, in raid1_add_conf() argument
1897 struct raid1_info *info = conf->mirrors + disk; in raid1_add_conf()
1900 info += conf->raid_disks; in raid1_add_conf()
1907 WRITE_ONCE(conf->nonrot_disks, conf->nonrot_disks + 1); in raid1_add_conf()
1918 static bool raid1_remove_conf(struct r1conf *conf, int disk) in raid1_remove_conf() argument
1920 struct raid1_info *info = conf->mirrors + disk; in raid1_remove_conf()
1929 rdev->mddev->recovery_disabled != conf->recovery_disabled && in raid1_remove_conf()
1930 rdev->mddev->degraded < conf->raid_disks) in raid1_remove_conf()
1934 WRITE_ONCE(conf->nonrot_disks, conf->nonrot_disks - 1); in raid1_remove_conf()
1942 struct r1conf *conf = mddev->private; in raid1_add_disk() local
1947 int last = conf->raid_disks - 1; in raid1_add_disk()
1949 if (mddev->recovery_disabled == conf->recovery_disabled) in raid1_add_disk()
1961 rdev->saved_raid_disk < conf->raid_disks && in raid1_add_disk()
1962 conf->mirrors[rdev->saved_raid_disk].rdev == NULL) in raid1_add_disk()
1966 p = conf->mirrors + mirror; in raid1_add_disk()
1972 raid1_add_conf(conf, rdev, mirror, false); in raid1_add_disk()
1977 conf->fullsync = 1; in raid1_add_disk()
1981 p[conf->raid_disks].rdev == NULL && repl_slot < 0) in raid1_add_disk()
1989 raid1_add_conf(conf, rdev, repl_slot, true); in raid1_add_disk()
1991 conf->fullsync = 1; in raid1_add_disk()
1994 print_conf(conf); in raid1_add_disk()
2000 struct r1conf *conf = mddev->private; in raid1_remove_disk() local
2003 struct raid1_info *p = conf->mirrors + number; in raid1_remove_disk()
2005 if (unlikely(number >= conf->raid_disks)) in raid1_remove_disk()
2009 number += conf->raid_disks; in raid1_remove_disk()
2010 p = conf->mirrors + number; in raid1_remove_disk()
2013 print_conf(conf); in raid1_remove_disk()
2015 if (!raid1_remove_conf(conf, number)) { in raid1_remove_disk()
2020 if (number < conf->raid_disks && in raid1_remove_disk()
2021 conf->mirrors[conf->raid_disks + number].rdev) { in raid1_remove_disk()
2027 conf->mirrors[conf->raid_disks + number].rdev; in raid1_remove_disk()
2028 freeze_array(conf, 0); in raid1_remove_disk()
2037 unfreeze_array(conf); in raid1_remove_disk()
2042 conf->mirrors[conf->raid_disks + number].rdev = NULL; in raid1_remove_disk()
2043 unfreeze_array(conf); in raid1_remove_disk()
2051 print_conf(conf); in raid1_remove_disk()
2108 struct r1conf *conf = mddev->private; in end_sync_write() local
2109 struct md_rdev *rdev = conf->mirrors[find_bio_disk(r1_bio, bio)].rdev; in end_sync_write()
2119 !rdev_has_badblock(conf->mirrors[r1_bio->read_disk].rdev, in end_sync_write()
2160 struct r1conf *conf = mddev->private; in fix_sync_read_error() local
2168 rdev = conf->mirrors[r1_bio->read_disk].rdev; in fix_sync_read_error()
2194 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2203 if (d == conf->raid_disks * 2) in fix_sync_read_error()
2217 for (d = 0; d < conf->raid_disks * 2; d++) { in fix_sync_read_error()
2218 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2225 conf->recovery_disabled = in fix_sync_read_error()
2243 d = conf->raid_disks * 2; in fix_sync_read_error()
2247 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2258 d = conf->raid_disks * 2; in fix_sync_read_error()
2262 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2287 struct r1conf *conf = mddev->private; in process_checks() local
2294 for (i = 0; i < conf->raid_disks * 2; i++) { in process_checks()
2302 bio_reset(b, conf->mirrors[i].rdev->bdev, REQ_OP_READ); in process_checks()
2305 conf->mirrors[i].rdev->data_offset; in process_checks()
2313 for (primary = 0; primary < conf->raid_disks * 2; primary++) in process_checks()
2317 rdev_dec_pending(conf->mirrors[primary].rdev, mddev); in process_checks()
2321 for (i = 0; i < conf->raid_disks * 2; i++) { in process_checks()
2355 rdev_dec_pending(conf->mirrors[i].rdev, mddev); in process_checks()
2365 struct r1conf *conf = mddev->private; in sync_request_write() local
2367 int disks = conf->raid_disks * 2; in sync_request_write()
2389 if (test_bit(Faulty, &conf->mirrors[i].rdev->flags)) { in sync_request_write()
2395 if (test_bit(FailFast, &conf->mirrors[i].rdev->flags)) in sync_request_write()
2400 md_sync_acct(conf->mirrors[i].rdev->bdev, bio_sectors(wbio)); in sync_request_write()
2416 static void fix_read_error(struct r1conf *conf, struct r1bio *r1_bio) in fix_read_error() argument
2421 struct mddev *mddev = conf->mddev; in fix_read_error()
2422 struct md_rdev *rdev = conf->mirrors[read_disk].rdev; in fix_read_error()
2439 rdev = conf->mirrors[d].rdev; in fix_read_error()
2447 conf->tmppage, REQ_OP_READ, false)) in fix_read_error()
2455 if (d == conf->raid_disks * 2) in fix_read_error()
2461 struct md_rdev *rdev = conf->mirrors[read_disk].rdev; in fix_read_error()
2470 d = conf->raid_disks * 2; in fix_read_error()
2472 rdev = conf->mirrors[d].rdev; in fix_read_error()
2477 conf->tmppage, REQ_OP_WRITE); in fix_read_error()
2484 d = conf->raid_disks * 2; in fix_read_error()
2486 rdev = conf->mirrors[d].rdev; in fix_read_error()
2491 conf->tmppage, REQ_OP_READ)) { in fix_read_error()
2510 struct r1conf *conf = mddev->private; in narrow_write_error() local
2511 struct md_rdev *rdev = conf->mirrors[i].rdev; in narrow_write_error()
2576 static void handle_sync_write_finished(struct r1conf *conf, struct r1bio *r1_bio) in handle_sync_write_finished() argument
2580 for (m = 0; m < conf->raid_disks * 2 ; m++) { in handle_sync_write_finished()
2581 struct md_rdev *rdev = conf->mirrors[m].rdev; in handle_sync_write_finished()
2592 md_error(conf->mddev, rdev); in handle_sync_write_finished()
2596 md_done_sync(conf->mddev, s, 1); in handle_sync_write_finished()
2599 static void handle_write_finished(struct r1conf *conf, struct r1bio *r1_bio) in handle_write_finished() argument
2604 for (m = 0; m < conf->raid_disks * 2 ; m++) in handle_write_finished()
2606 struct md_rdev *rdev = conf->mirrors[m].rdev; in handle_write_finished()
2610 rdev_dec_pending(rdev, conf->mddev); in handle_write_finished()
2618 md_error(conf->mddev, in handle_write_finished()
2619 conf->mirrors[m].rdev); in handle_write_finished()
2623 rdev_dec_pending(conf->mirrors[m].rdev, in handle_write_finished()
2624 conf->mddev); in handle_write_finished()
2627 spin_lock_irq(&conf->device_lock); in handle_write_finished()
2628 list_add(&r1_bio->retry_list, &conf->bio_end_io_list); in handle_write_finished()
2630 atomic_inc(&conf->nr_queued[idx]); in handle_write_finished()
2631 spin_unlock_irq(&conf->device_lock); in handle_write_finished()
2636 wake_up(&conf->wait_barrier); in handle_write_finished()
2637 md_wakeup_thread(conf->mddev->thread); in handle_write_finished()
2645 static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio) in handle_read_error() argument
2647 struct mddev *mddev = conf->mddev; in handle_read_error()
2666 rdev = conf->mirrors[r1_bio->read_disk].rdev; in handle_read_error()
2669 freeze_array(conf, 1); in handle_read_error()
2670 fix_read_error(conf, r1_bio); in handle_read_error()
2671 unfreeze_array(conf); in handle_read_error()
2678 rdev_dec_pending(rdev, conf->mddev); in handle_read_error()
2685 allow_barrier(conf, sector); in handle_read_error()
2693 struct r1conf *conf = mddev->private; in raid1d() local
2694 struct list_head *head = &conf->retry_list; in raid1d()
2700 if (!list_empty_careful(&conf->bio_end_io_list) && in raid1d()
2703 spin_lock_irqsave(&conf->device_lock, flags); in raid1d()
2705 list_splice_init(&conf->bio_end_io_list, &tmp); in raid1d()
2706 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1d()
2712 atomic_dec(&conf->nr_queued[idx]); in raid1d()
2724 flush_pending_writes(conf); in raid1d()
2726 spin_lock_irqsave(&conf->device_lock, flags); in raid1d()
2728 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1d()
2734 atomic_dec(&conf->nr_queued[idx]); in raid1d()
2735 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1d()
2738 conf = mddev->private; in raid1d()
2742 handle_sync_write_finished(conf, r1_bio); in raid1d()
2747 handle_write_finished(conf, r1_bio); in raid1d()
2749 handle_read_error(conf, r1_bio); in raid1d()
2760 static int init_resync(struct r1conf *conf) in init_resync() argument
2765 BUG_ON(mempool_initialized(&conf->r1buf_pool)); in init_resync()
2767 return mempool_init(&conf->r1buf_pool, buffs, r1buf_pool_alloc, in init_resync()
2768 r1buf_pool_free, conf->poolinfo); in init_resync()
2771 static struct r1bio *raid1_alloc_init_r1buf(struct r1conf *conf) in raid1_alloc_init_r1buf() argument
2773 struct r1bio *r1bio = mempool_alloc(&conf->r1buf_pool, GFP_NOIO); in raid1_alloc_init_r1buf()
2778 for (i = conf->poolinfo->raid_disks; i--; ) { in raid1_alloc_init_r1buf()
2801 struct r1conf *conf = mddev->private; in raid1_sync_request() local
2816 if (!mempool_initialized(&conf->r1buf_pool)) in raid1_sync_request()
2817 if (init_resync(conf)) in raid1_sync_request()
2830 conf->fullsync = 0; in raid1_sync_request()
2833 close_sync(conf); in raid1_sync_request()
2836 conf->cluster_sync_low = 0; in raid1_sync_request()
2837 conf->cluster_sync_high = 0; in raid1_sync_request()
2845 conf->fullsync == 0) { in raid1_sync_request()
2853 !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { in raid1_sync_request()
2863 if (atomic_read(&conf->nr_waiting[idx])) in raid1_sync_request()
2872 (sector_nr + 2 * RESYNC_SECTORS > conf->cluster_sync_high)); in raid1_sync_request()
2874 if (raise_barrier(conf, sector_nr)) in raid1_sync_request()
2877 r1_bio = raid1_alloc_init_r1buf(conf); in raid1_sync_request()
2895 for (i = 0; i < conf->raid_disks * 2; i++) { in raid1_sync_request()
2899 rdev = conf->mirrors[i].rdev; in raid1_sync_request()
2902 if (i < conf->raid_disks) in raid1_sync_request()
2966 for (i = 0 ; i < conf->raid_disks * 2 ; i++) in raid1_sync_request()
2968 struct md_rdev *rdev = conf->mirrors[i].rdev; in raid1_sync_request()
2983 conf->recovery_disabled = mddev->recovery_disabled; in raid1_sync_request()
3029 !conf->fullsync && in raid1_sync_request()
3036 for (i = 0 ; i < conf->raid_disks * 2; i++) { in raid1_sync_request()
3059 conf->cluster_sync_high < sector_nr + nr_sectors) { in raid1_sync_request()
3060 conf->cluster_sync_low = mddev->curr_resync_completed; in raid1_sync_request()
3061 conf->cluster_sync_high = conf->cluster_sync_low + CLUSTER_RESYNC_WINDOW_SECTORS; in raid1_sync_request()
3064 conf->cluster_sync_low, in raid1_sync_request()
3065 conf->cluster_sync_high); in raid1_sync_request()
3073 for (i = 0; i < conf->raid_disks * 2 && read_targets; i++) { in raid1_sync_request()
3104 struct r1conf *conf; in setup_conf() local
3110 conf = kzalloc(sizeof(struct r1conf), GFP_KERNEL); in setup_conf()
3111 if (!conf) in setup_conf()
3114 conf->nr_pending = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
3116 if (!conf->nr_pending) in setup_conf()
3119 conf->nr_waiting = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
3121 if (!conf->nr_waiting) in setup_conf()
3124 conf->nr_queued = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
3126 if (!conf->nr_queued) in setup_conf()
3129 conf->barrier = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
3131 if (!conf->barrier) in setup_conf()
3134 conf->mirrors = kzalloc(array3_size(sizeof(struct raid1_info), in setup_conf()
3137 if (!conf->mirrors) in setup_conf()
3140 conf->tmppage = alloc_page(GFP_KERNEL); in setup_conf()
3141 if (!conf->tmppage) in setup_conf()
3144 conf->poolinfo = kzalloc(sizeof(*conf->poolinfo), GFP_KERNEL); in setup_conf()
3145 if (!conf->poolinfo) in setup_conf()
3147 conf->poolinfo->raid_disks = mddev->raid_disks * 2; in setup_conf()
3148 err = mempool_init(&conf->r1bio_pool, NR_RAID_BIOS, r1bio_pool_alloc, in setup_conf()
3149 rbio_pool_free, conf->poolinfo); in setup_conf()
3153 err = bioset_init(&conf->bio_split, BIO_POOL_SIZE, 0, 0); in setup_conf()
3157 conf->poolinfo->mddev = mddev; in setup_conf()
3160 spin_lock_init(&conf->device_lock); in setup_conf()
3161 conf->raid_disks = mddev->raid_disks; in setup_conf()
3165 if (disk_idx >= conf->raid_disks || disk_idx < 0) in setup_conf()
3168 if (!raid1_add_conf(conf, rdev, disk_idx, in setup_conf()
3172 conf->mddev = mddev; in setup_conf()
3173 INIT_LIST_HEAD(&conf->retry_list); in setup_conf()
3174 INIT_LIST_HEAD(&conf->bio_end_io_list); in setup_conf()
3176 spin_lock_init(&conf->resync_lock); in setup_conf()
3177 init_waitqueue_head(&conf->wait_barrier); in setup_conf()
3179 bio_list_init(&conf->pending_bio_list); in setup_conf()
3180 conf->recovery_disabled = mddev->recovery_disabled - 1; in setup_conf()
3183 for (i = 0; i < conf->raid_disks * 2; i++) { in setup_conf()
3185 disk = conf->mirrors + i; in setup_conf()
3187 if (i < conf->raid_disks && in setup_conf()
3188 disk[conf->raid_disks].rdev) { in setup_conf()
3195 disk[conf->raid_disks].rdev; in setup_conf()
3196 disk[conf->raid_disks].rdev = NULL; in setup_conf()
3207 conf->fullsync = 1; in setup_conf()
3212 rcu_assign_pointer(conf->thread, in setup_conf()
3214 if (!conf->thread) in setup_conf()
3217 return conf; in setup_conf()
3220 if (conf) { in setup_conf()
3221 mempool_exit(&conf->r1bio_pool); in setup_conf()
3222 kfree(conf->mirrors); in setup_conf()
3223 safe_put_page(conf->tmppage); in setup_conf()
3224 kfree(conf->poolinfo); in setup_conf()
3225 kfree(conf->nr_pending); in setup_conf()
3226 kfree(conf->nr_waiting); in setup_conf()
3227 kfree(conf->nr_queued); in setup_conf()
3228 kfree(conf->barrier); in setup_conf()
3229 bioset_exit(&conf->bio_split); in setup_conf()
3230 kfree(conf); in setup_conf()
3253 struct r1conf *conf; in raid1_run() local
3274 conf = setup_conf(mddev); in raid1_run()
3276 conf = mddev->private; in raid1_run()
3278 if (IS_ERR(conf)) in raid1_run()
3279 return PTR_ERR(conf); in raid1_run()
3288 for (i = 0; i < conf->raid_disks; i++) in raid1_run()
3289 if (conf->mirrors[i].rdev == NULL || in raid1_run()
3290 !test_bit(In_sync, &conf->mirrors[i].rdev->flags) || in raid1_run()
3291 test_bit(Faulty, &conf->mirrors[i].rdev->flags)) in raid1_run()
3296 if (conf->raid_disks - mddev->degraded < 1) { in raid1_run()
3297 md_unregister_thread(mddev, &conf->thread); in raid1_run()
3301 if (conf->raid_disks - mddev->degraded == 1) in raid1_run()
3314 rcu_assign_pointer(mddev->thread, conf->thread); in raid1_run()
3315 rcu_assign_pointer(conf->thread, NULL); in raid1_run()
3316 mddev->private = conf; in raid1_run()
3329 struct r1conf *conf = priv; in raid1_free() local
3331 mempool_exit(&conf->r1bio_pool); in raid1_free()
3332 kfree(conf->mirrors); in raid1_free()
3333 safe_put_page(conf->tmppage); in raid1_free()
3334 kfree(conf->poolinfo); in raid1_free()
3335 kfree(conf->nr_pending); in raid1_free()
3336 kfree(conf->nr_waiting); in raid1_free()
3337 kfree(conf->nr_queued); in raid1_free()
3338 kfree(conf->barrier); in raid1_free()
3339 bioset_exit(&conf->bio_split); in raid1_free()
3340 kfree(conf); in raid1_free()
3390 struct r1conf *conf = mddev->private; in raid1_reshape() local
3414 if (raid_disks < conf->raid_disks) { in raid1_reshape()
3416 for (d= 0; d < conf->raid_disks; d++) in raid1_reshape()
3417 if (conf->mirrors[d].rdev) in raid1_reshape()
3444 freeze_array(conf, 0); in raid1_reshape()
3447 oldpool = conf->r1bio_pool; in raid1_reshape()
3448 conf->r1bio_pool = newpool; in raid1_reshape()
3450 for (d = d2 = 0; d < conf->raid_disks; d++) { in raid1_reshape()
3451 struct md_rdev *rdev = conf->mirrors[d].rdev; in raid1_reshape()
3463 kfree(conf->mirrors); in raid1_reshape()
3464 conf->mirrors = newmirrors; in raid1_reshape()
3465 kfree(conf->poolinfo); in raid1_reshape()
3466 conf->poolinfo = newpoolinfo; in raid1_reshape()
3468 spin_lock_irqsave(&conf->device_lock, flags); in raid1_reshape()
3469 mddev->degraded += (raid_disks - conf->raid_disks); in raid1_reshape()
3470 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_reshape()
3471 conf->raid_disks = mddev->raid_disks = raid_disks; in raid1_reshape()
3474 unfreeze_array(conf); in raid1_reshape()
3486 struct r1conf *conf = mddev->private; in raid1_quiesce() local
3489 freeze_array(conf, 0); in raid1_quiesce()
3491 unfreeze_array(conf); in raid1_quiesce()
3500 struct r1conf *conf; in raid1_takeover() local
3504 conf = setup_conf(mddev); in raid1_takeover()
3505 if (!IS_ERR(conf)) { in raid1_takeover()
3507 conf->array_frozen = 1; in raid1_takeover()
3511 return conf; in raid1_takeover()