Lines Matching full: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);
241 static void put_all_bios(struct r1conf *conf, struct r1bio *r1_bio) in put_all_bios() argument
245 for (i = 0; i < conf->raid_disks * 2; i++) { in put_all_bios()
255 struct r1conf *conf = r1_bio->mddev->private; in free_r1bio() local
257 put_all_bios(conf, r1_bio); in free_r1bio()
258 mempool_free(r1_bio, &conf->r1bio_pool); in free_r1bio()
263 struct r1conf *conf = r1_bio->mddev->private; in put_buf() local
267 for (i = 0; i < conf->raid_disks * 2; i++) { in put_buf()
270 rdev_dec_pending(conf->mirrors[i].rdev, r1_bio->mddev); in put_buf()
273 mempool_free(r1_bio, &conf->r1buf_pool); in put_buf()
275 lower_barrier(conf, sect); in put_buf()
282 struct r1conf *conf = mddev->private; in reschedule_retry() local
286 spin_lock_irqsave(&conf->device_lock, flags); in reschedule_retry()
287 list_add(&r1_bio->retry_list, &conf->retry_list); in reschedule_retry()
288 atomic_inc(&conf->nr_queued[idx]); in reschedule_retry()
289 spin_unlock_irqrestore(&conf->device_lock, flags); in reschedule_retry()
291 wake_up(&conf->wait_barrier); in reschedule_retry()
315 struct r1conf *conf = r1_bio->mddev->private; in raid_end_bio_io() local
330 allow_barrier(conf, r1_bio->sector); in raid_end_bio_io()
340 struct r1conf *conf = r1_bio->mddev->private; in update_head_pos() local
342 conf->mirrors[disk].head_position = in update_head_pos()
352 struct r1conf *conf = r1_bio->mddev->private; in find_bio_disk() local
353 int raid_disks = conf->raid_disks; in find_bio_disk()
369 struct r1conf *conf = r1_bio->mddev->private; in raid1_end_read_request() local
370 struct md_rdev *rdev = conf->mirrors[r1_bio->read_disk].rdev; in raid1_end_read_request()
390 spin_lock_irqsave(&conf->device_lock, flags); in raid1_end_read_request()
391 if (r1_bio->mddev->degraded == conf->raid_disks || in raid1_end_read_request()
392 (r1_bio->mddev->degraded == conf->raid_disks-1 && in raid1_end_read_request()
395 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_end_read_request()
400 rdev_dec_pending(rdev, conf->mddev); in raid1_end_read_request()
406 mdname(conf->mddev), in raid1_end_read_request()
451 struct r1conf *conf = r1_bio->mddev->private; in raid1_end_write_request() local
454 struct md_rdev *rdev = conf->mirrors[mirror].rdev; in raid1_end_write_request()
468 conf->mddev->recovery); in raid1_end_write_request()
554 rdev_dec_pending(rdev, conf->mddev); in raid1_end_write_request()
599 static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sectors) in read_balance() argument
631 if ((conf->mddev->recovery_cp < this_sector + sectors) || in read_balance()
632 (mddev_is_clustered(conf->mddev) && in read_balance()
633 md_cluster_ops->area_resyncing(conf->mddev, READ, this_sector, in read_balance()
639 for (disk = 0 ; disk < conf->raid_disks * 2 ; disk++) { in read_balance()
646 rdev = rcu_dereference(conf->mirrors[disk].rdev); in read_balance()
713 dist = abs(this_sector - conf->mirrors[disk].head_position); in read_balance()
719 if (conf->mirrors[disk].next_seq_sect == this_sector in read_balance()
722 struct raid1_info *mirror = &conf->mirrors[disk]; in read_balance()
777 rdev = rcu_dereference(conf->mirrors[best_disk].rdev); in read_balance()
783 if (conf->mirrors[best_disk].next_seq_sect != this_sector) in read_balance()
784 conf->mirrors[best_disk].seq_start = this_sector; in read_balance()
786 conf->mirrors[best_disk].next_seq_sect = this_sector + sectors; in read_balance()
794 static void flush_bio_list(struct r1conf *conf, struct bio *bio) in flush_bio_list() argument
797 md_bitmap_unplug(conf->mddev->bitmap); in flush_bio_list()
798 wake_up(&conf->wait_barrier); in flush_bio_list()
818 static void flush_pending_writes(struct r1conf *conf) in flush_pending_writes() argument
823 spin_lock_irq(&conf->device_lock); in flush_pending_writes()
825 if (conf->pending_bio_list.head) { in flush_pending_writes()
829 bio = bio_list_get(&conf->pending_bio_list); in flush_pending_writes()
830 spin_unlock_irq(&conf->device_lock); in flush_pending_writes()
843 flush_bio_list(conf, bio); in flush_pending_writes()
846 spin_unlock_irq(&conf->device_lock); in flush_pending_writes()
873 static int raise_barrier(struct r1conf *conf, sector_t sector_nr) in raise_barrier() argument
877 spin_lock_irq(&conf->resync_lock); in raise_barrier()
880 wait_event_lock_irq(conf->wait_barrier, in raise_barrier()
881 !atomic_read(&conf->nr_waiting[idx]), in raise_barrier()
882 conf->resync_lock); in raise_barrier()
885 atomic_inc(&conf->barrier[idx]); in raise_barrier()
887 * In raise_barrier() we firstly increase conf->barrier[idx] then in raise_barrier()
888 * check conf->nr_pending[idx]. In _wait_barrier() we firstly in raise_barrier()
889 * increase conf->nr_pending[idx] then check conf->barrier[idx]. in raise_barrier()
890 * A memory barrier here to make sure conf->nr_pending[idx] won't in raise_barrier()
891 * be fetched before conf->barrier[idx] is increased. Otherwise in raise_barrier()
898 * B: while conf->nr_pending[idx] is not 0, meaning regular I/O in raise_barrier()
900 * C: while conf->barrier[idx] >= RESYNC_DEPTH, meaning reaches in raise_barrier()
903 wait_event_lock_irq(conf->wait_barrier, in raise_barrier()
904 (!conf->array_frozen && in raise_barrier()
905 !atomic_read(&conf->nr_pending[idx]) && in raise_barrier()
906 atomic_read(&conf->barrier[idx]) < RESYNC_DEPTH) || in raise_barrier()
907 test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery), in raise_barrier()
908 conf->resync_lock); in raise_barrier()
910 if (test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { in raise_barrier()
911 atomic_dec(&conf->barrier[idx]); in raise_barrier()
912 spin_unlock_irq(&conf->resync_lock); in raise_barrier()
913 wake_up(&conf->wait_barrier); in raise_barrier()
917 atomic_inc(&conf->nr_sync_pending); in raise_barrier()
918 spin_unlock_irq(&conf->resync_lock); in raise_barrier()
923 static void lower_barrier(struct r1conf *conf, sector_t sector_nr) in lower_barrier() argument
927 BUG_ON(atomic_read(&conf->barrier[idx]) <= 0); in lower_barrier()
929 atomic_dec(&conf->barrier[idx]); in lower_barrier()
930 atomic_dec(&conf->nr_sync_pending); in lower_barrier()
931 wake_up(&conf->wait_barrier); in lower_barrier()
934 static bool _wait_barrier(struct r1conf *conf, int idx, bool nowait) in _wait_barrier() argument
939 * We need to increase conf->nr_pending[idx] very early here, in _wait_barrier()
941 * conf->nr_pending[idx] to be 0. Then we can avoid holding in _wait_barrier()
942 * conf->resync_lock when there is no barrier raised in same in _wait_barrier()
946 atomic_inc(&conf->nr_pending[idx]); in _wait_barrier()
948 * In _wait_barrier() we firstly increase conf->nr_pending[idx], then in _wait_barrier()
949 * check conf->barrier[idx]. In raise_barrier() we firstly increase in _wait_barrier()
950 * conf->barrier[idx], then check conf->nr_pending[idx]. A memory in _wait_barrier()
951 * barrier is necessary here to make sure conf->barrier[idx] won't be in _wait_barrier()
952 * fetched before conf->nr_pending[idx] is increased. Otherwise there in _wait_barrier()
959 * here. If during we check conf->barrier[idx], the array is in _wait_barrier()
960 * frozen (conf->array_frozen is 1), and chonf->barrier[idx] is in _wait_barrier()
966 if (!READ_ONCE(conf->array_frozen) && in _wait_barrier()
967 !atomic_read(&conf->barrier[idx])) in _wait_barrier()
971 * After holding conf->resync_lock, conf->nr_pending[idx] in _wait_barrier()
974 * raise_barrer() might be waiting for conf->nr_pending[idx] in _wait_barrier()
977 spin_lock_irq(&conf->resync_lock); in _wait_barrier()
978 atomic_inc(&conf->nr_waiting[idx]); in _wait_barrier()
979 atomic_dec(&conf->nr_pending[idx]); in _wait_barrier()
984 wake_up(&conf->wait_barrier); in _wait_barrier()
991 wait_event_lock_irq(conf->wait_barrier, in _wait_barrier()
992 !conf->array_frozen && in _wait_barrier()
993 !atomic_read(&conf->barrier[idx]), in _wait_barrier()
994 conf->resync_lock); in _wait_barrier()
995 atomic_inc(&conf->nr_pending[idx]); in _wait_barrier()
998 atomic_dec(&conf->nr_waiting[idx]); in _wait_barrier()
999 spin_unlock_irq(&conf->resync_lock); in _wait_barrier()
1003 static bool wait_read_barrier(struct r1conf *conf, sector_t sector_nr, bool nowait) in wait_read_barrier() argument
1013 * conf->barrier[idx] here, memory barrier is unnecessary as well. in wait_read_barrier()
1015 atomic_inc(&conf->nr_pending[idx]); in wait_read_barrier()
1017 if (!READ_ONCE(conf->array_frozen)) in wait_read_barrier()
1020 spin_lock_irq(&conf->resync_lock); in wait_read_barrier()
1021 atomic_inc(&conf->nr_waiting[idx]); in wait_read_barrier()
1022 atomic_dec(&conf->nr_pending[idx]); in wait_read_barrier()
1027 wake_up(&conf->wait_barrier); in wait_read_barrier()
1035 wait_event_lock_irq(conf->wait_barrier, in wait_read_barrier()
1036 !conf->array_frozen, in wait_read_barrier()
1037 conf->resync_lock); in wait_read_barrier()
1038 atomic_inc(&conf->nr_pending[idx]); in wait_read_barrier()
1041 atomic_dec(&conf->nr_waiting[idx]); in wait_read_barrier()
1042 spin_unlock_irq(&conf->resync_lock); in wait_read_barrier()
1046 static bool wait_barrier(struct r1conf *conf, sector_t sector_nr, bool nowait) in wait_barrier() argument
1050 return _wait_barrier(conf, idx, nowait); in wait_barrier()
1053 static void _allow_barrier(struct r1conf *conf, int idx) in _allow_barrier() argument
1055 atomic_dec(&conf->nr_pending[idx]); in _allow_barrier()
1056 wake_up(&conf->wait_barrier); in _allow_barrier()
1059 static void allow_barrier(struct r1conf *conf, sector_t sector_nr) in allow_barrier() argument
1063 _allow_barrier(conf, idx); in allow_barrier()
1066 /* conf->resync_lock should be held */
1067 static int get_unqueued_pending(struct r1conf *conf) in get_unqueued_pending() argument
1071 ret = atomic_read(&conf->nr_sync_pending); in get_unqueued_pending()
1073 ret += atomic_read(&conf->nr_pending[idx]) - in get_unqueued_pending()
1074 atomic_read(&conf->nr_queued[idx]); in get_unqueued_pending()
1079 static void freeze_array(struct r1conf *conf, int extra) in freeze_array() argument
1092 * Every flying I/O contributes to a conf->nr_pending[idx], idx is the in freeze_array()
1094 * normal I/O are queued, sum of all conf->nr_pending[] will match sum in freeze_array()
1095 * of all conf->nr_queued[]. But normal I/O failure is an exception, in freeze_array()
1101 * get_unqueued_pendings(conf) gets equal to extra. For in freeze_array()
1104 spin_lock_irq(&conf->resync_lock); in freeze_array()
1105 conf->array_frozen = 1; in freeze_array()
1106 raid1_log(conf->mddev, "wait freeze"); in freeze_array()
1108 conf->wait_barrier, in freeze_array()
1109 get_unqueued_pending(conf) == extra, in freeze_array()
1110 conf->resync_lock, in freeze_array()
1111 flush_pending_writes(conf)); in freeze_array()
1112 spin_unlock_irq(&conf->resync_lock); in freeze_array()
1114 static void unfreeze_array(struct r1conf *conf) in unfreeze_array() argument
1117 spin_lock_irq(&conf->resync_lock); in unfreeze_array()
1118 conf->array_frozen = 0; in unfreeze_array()
1119 spin_unlock_irq(&conf->resync_lock); in unfreeze_array()
1120 wake_up(&conf->wait_barrier); in unfreeze_array()
1175 struct r1conf *conf = mddev->private; in raid1_unplug() local
1179 spin_lock_irq(&conf->device_lock); in raid1_unplug()
1180 bio_list_merge(&conf->pending_bio_list, &plug->pending); in raid1_unplug()
1181 spin_unlock_irq(&conf->device_lock); in raid1_unplug()
1182 wake_up(&conf->wait_barrier); in raid1_unplug()
1190 flush_bio_list(conf, bio); in raid1_unplug()
1206 struct r1conf *conf = mddev->private; in alloc_r1bio() local
1209 r1_bio = mempool_alloc(&conf->r1bio_pool, GFP_NOIO); in alloc_r1bio()
1211 memset(r1_bio->bios, 0, conf->raid_disks * sizeof(r1_bio->bios[0])); in alloc_r1bio()
1219 struct r1conf *conf = mddev->private; in raid1_read_request() local
1241 rdev = rcu_dereference(conf->mirrors[r1_bio->read_disk].rdev); in raid1_read_request()
1253 if (!wait_read_barrier(conf, bio->bi_iter.bi_sector, in raid1_read_request()
1269 rdisk = read_balance(conf, r1_bio, &max_sectors); in raid1_read_request()
1282 mirror = conf->mirrors + rdisk; in raid1_read_request()
1303 gfp, &conf->bio_split); in raid1_read_request()
1340 struct r1conf *conf = mddev->private; in raid1_write_request() local
1362 prepare_to_wait(&conf->wait_barrier, in raid1_write_request()
1370 finish_wait(&conf->wait_barrier, &w); in raid1_write_request()
1378 if (!wait_barrier(conf, bio->bi_iter.bi_sector, in raid1_write_request()
1398 disks = conf->raid_disks * 2; in raid1_write_request()
1404 struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); in raid1_write_request()
1421 if (i < conf->raid_disks) in raid1_write_request()
1478 rdev_dec_pending(conf->mirrors[j].rdev, mddev); in raid1_write_request()
1480 allow_barrier(conf, bio->bi_iter.bi_sector); in raid1_write_request()
1488 wait_barrier(conf, bio->bi_iter.bi_sector, false); in raid1_write_request()
1503 GFP_NOIO, &conf->bio_split); in raid1_write_request()
1520 struct md_rdev *rdev = conf->mirrors[i].rdev; in raid1_write_request()
1565 conf->raid_disks - mddev->degraded > 1) in raid1_write_request()
1585 spin_lock_irqsave(&conf->device_lock, flags); in raid1_write_request()
1586 bio_list_add(&conf->pending_bio_list, mbio); in raid1_write_request()
1587 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_write_request()
1595 wake_up(&conf->wait_barrier); in raid1_write_request()
1628 struct r1conf *conf = mddev->private; in raid1_status() local
1631 seq_printf(seq, " [%d/%d] [", conf->raid_disks, in raid1_status()
1632 conf->raid_disks - mddev->degraded); in raid1_status()
1634 for (i = 0; i < conf->raid_disks; i++) { in raid1_status()
1635 struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); in raid1_status()
1661 struct r1conf *conf = mddev->private; in raid1_error() local
1664 spin_lock_irqsave(&conf->device_lock, flags); in raid1_error()
1667 (conf->raid_disks - mddev->degraded) == 1) { in raid1_error()
1671 conf->recovery_disabled = mddev->recovery_disabled; in raid1_error()
1672 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_error()
1680 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_error()
1690 mdname(mddev), conf->raid_disks - mddev->degraded); in raid1_error()
1693 static void print_conf(struct r1conf *conf) in print_conf() argument
1697 pr_debug("RAID1 conf printout:\n"); in print_conf()
1698 if (!conf) { in print_conf()
1699 pr_debug("(!conf)\n"); in print_conf()
1702 pr_debug(" --- wd:%d rd:%d\n", conf->raid_disks - conf->mddev->degraded, in print_conf()
1703 conf->raid_disks); in print_conf()
1706 for (i = 0; i < conf->raid_disks; i++) { in print_conf()
1707 struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); in print_conf()
1717 static void close_sync(struct r1conf *conf) in close_sync() argument
1722 _wait_barrier(conf, idx, false); in close_sync()
1723 _allow_barrier(conf, idx); in close_sync()
1726 mempool_exit(&conf->r1buf_pool); in close_sync()
1732 struct r1conf *conf = mddev->private; in raid1_spare_active() local
1743 spin_lock_irqsave(&conf->device_lock, flags); in raid1_spare_active()
1744 for (i = 0; i < conf->raid_disks; i++) { in raid1_spare_active()
1745 struct md_rdev *rdev = conf->mirrors[i].rdev; in raid1_spare_active()
1746 struct md_rdev *repl = conf->mirrors[conf->raid_disks + i].rdev; in raid1_spare_active()
1775 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_spare_active()
1777 print_conf(conf); in raid1_spare_active()
1783 struct r1conf *conf = mddev->private; in raid1_add_disk() local
1788 int last = conf->raid_disks - 1; in raid1_add_disk()
1790 if (mddev->recovery_disabled == conf->recovery_disabled) in raid1_add_disk()
1805 rdev->saved_raid_disk < conf->raid_disks && in raid1_add_disk()
1806 conf->mirrors[rdev->saved_raid_disk].rdev == NULL) in raid1_add_disk()
1810 p = conf->mirrors + mirror; in raid1_add_disk()
1823 conf->fullsync = 1; in raid1_add_disk()
1828 p[conf->raid_disks].rdev == NULL) { in raid1_add_disk()
1834 conf->fullsync = 1; in raid1_add_disk()
1835 rcu_assign_pointer(p[conf->raid_disks].rdev, rdev); in raid1_add_disk()
1839 print_conf(conf); in raid1_add_disk()
1845 struct r1conf *conf = mddev->private; in raid1_remove_disk() local
1848 struct raid1_info *p = conf->mirrors + number; in raid1_remove_disk()
1851 p = conf->mirrors + conf->raid_disks + number; in raid1_remove_disk()
1853 print_conf(conf); in raid1_remove_disk()
1864 mddev->recovery_disabled != conf->recovery_disabled && in raid1_remove_disk()
1865 mddev->degraded < conf->raid_disks) { in raid1_remove_disk()
1879 if (conf->mirrors[conf->raid_disks + number].rdev) { in raid1_remove_disk()
1885 conf->mirrors[conf->raid_disks + number].rdev; in raid1_remove_disk()
1886 freeze_array(conf, 0); in raid1_remove_disk()
1895 unfreeze_array(conf); in raid1_remove_disk()
1900 conf->mirrors[conf->raid_disks + number].rdev = NULL; in raid1_remove_disk()
1901 unfreeze_array(conf); in raid1_remove_disk()
1909 print_conf(conf); in raid1_remove_disk()
1966 struct r1conf *conf = mddev->private; in end_sync_write() local
1969 struct md_rdev *rdev = conf->mirrors[find_bio_disk(r1_bio, bio)].rdev; in end_sync_write()
1980 !is_badblock(conf->mirrors[r1_bio->read_disk].rdev, in end_sync_write()
2023 struct r1conf *conf = mddev->private; in fix_sync_read_error() local
2031 rdev = conf->mirrors[r1_bio->read_disk].rdev; in fix_sync_read_error()
2057 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2066 if (d == conf->raid_disks * 2) in fix_sync_read_error()
2080 for (d = 0; d < conf->raid_disks * 2; d++) { in fix_sync_read_error()
2081 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2088 conf->recovery_disabled = in fix_sync_read_error()
2106 d = conf->raid_disks * 2; in fix_sync_read_error()
2110 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2121 d = conf->raid_disks * 2; in fix_sync_read_error()
2125 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2150 struct r1conf *conf = mddev->private; in process_checks() local
2157 for (i = 0; i < conf->raid_disks * 2; i++) { in process_checks()
2165 bio_reset(b, conf->mirrors[i].rdev->bdev, REQ_OP_READ); in process_checks()
2168 conf->mirrors[i].rdev->data_offset; in process_checks()
2176 for (primary = 0; primary < conf->raid_disks * 2; primary++) in process_checks()
2180 rdev_dec_pending(conf->mirrors[primary].rdev, mddev); in process_checks()
2184 for (i = 0; i < conf->raid_disks * 2; i++) { in process_checks()
2218 rdev_dec_pending(conf->mirrors[i].rdev, mddev); in process_checks()
2228 struct r1conf *conf = mddev->private; in sync_request_write() local
2230 int disks = conf->raid_disks * 2; in sync_request_write()
2252 if (test_bit(Faulty, &conf->mirrors[i].rdev->flags)) { in sync_request_write()
2258 if (test_bit(FailFast, &conf->mirrors[i].rdev->flags)) in sync_request_write()
2263 md_sync_acct(conf->mirrors[i].rdev->bdev, bio_sectors(wbio)); in sync_request_write()
2279 static void fix_read_error(struct r1conf *conf, int read_disk, in fix_read_error() argument
2282 struct mddev *mddev = conf->mddev; in fix_read_error()
2298 rdev = rcu_dereference(conf->mirrors[d].rdev); in fix_read_error()
2308 conf->tmppage, REQ_OP_READ, false)) in fix_read_error()
2316 if (d == conf->raid_disks * 2) in fix_read_error()
2322 struct md_rdev *rdev = conf->mirrors[read_disk].rdev; in fix_read_error()
2331 d = conf->raid_disks * 2; in fix_read_error()
2334 rdev = rcu_dereference(conf->mirrors[d].rdev); in fix_read_error()
2340 conf->tmppage, WRITE); in fix_read_error()
2348 d = conf->raid_disks * 2; in fix_read_error()
2351 rdev = rcu_dereference(conf->mirrors[d].rdev); in fix_read_error()
2357 conf->tmppage, READ)) { in fix_read_error()
2377 struct r1conf *conf = mddev->private; in narrow_write_error() local
2378 struct md_rdev *rdev = conf->mirrors[i].rdev; in narrow_write_error()
2443 static void handle_sync_write_finished(struct r1conf *conf, struct r1bio *r1_bio) in handle_sync_write_finished() argument
2447 for (m = 0; m < conf->raid_disks * 2 ; m++) { in handle_sync_write_finished()
2448 struct md_rdev *rdev = conf->mirrors[m].rdev; in handle_sync_write_finished()
2459 md_error(conf->mddev, rdev); in handle_sync_write_finished()
2463 md_done_sync(conf->mddev, s, 1); in handle_sync_write_finished()
2466 static void handle_write_finished(struct r1conf *conf, struct r1bio *r1_bio) in handle_write_finished() argument
2471 for (m = 0; m < conf->raid_disks * 2 ; m++) in handle_write_finished()
2473 struct md_rdev *rdev = conf->mirrors[m].rdev; in handle_write_finished()
2477 rdev_dec_pending(rdev, conf->mddev); in handle_write_finished()
2485 md_error(conf->mddev, in handle_write_finished()
2486 conf->mirrors[m].rdev); in handle_write_finished()
2490 rdev_dec_pending(conf->mirrors[m].rdev, in handle_write_finished()
2491 conf->mddev); in handle_write_finished()
2494 spin_lock_irq(&conf->device_lock); in handle_write_finished()
2495 list_add(&r1_bio->retry_list, &conf->bio_end_io_list); in handle_write_finished()
2497 atomic_inc(&conf->nr_queued[idx]); in handle_write_finished()
2498 spin_unlock_irq(&conf->device_lock); in handle_write_finished()
2503 wake_up(&conf->wait_barrier); in handle_write_finished()
2504 md_wakeup_thread(conf->mddev->thread); in handle_write_finished()
2512 static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio) in handle_read_error() argument
2514 struct mddev *mddev = conf->mddev; in handle_read_error()
2532 rdev = conf->mirrors[r1_bio->read_disk].rdev; in handle_read_error()
2535 freeze_array(conf, 1); in handle_read_error()
2536 fix_read_error(conf, r1_bio->read_disk, in handle_read_error()
2538 unfreeze_array(conf); in handle_read_error()
2545 rdev_dec_pending(rdev, conf->mddev); in handle_read_error()
2546 allow_barrier(conf, r1_bio->sector); in handle_read_error()
2559 struct r1conf *conf = mddev->private; in raid1d() local
2560 struct list_head *head = &conf->retry_list; in raid1d()
2566 if (!list_empty_careful(&conf->bio_end_io_list) && in raid1d()
2569 spin_lock_irqsave(&conf->device_lock, flags); in raid1d()
2571 list_splice_init(&conf->bio_end_io_list, &tmp); in raid1d()
2572 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1d()
2578 atomic_dec(&conf->nr_queued[idx]); in raid1d()
2590 flush_pending_writes(conf); in raid1d()
2592 spin_lock_irqsave(&conf->device_lock, flags); in raid1d()
2594 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1d()
2600 atomic_dec(&conf->nr_queued[idx]); in raid1d()
2601 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1d()
2604 conf = mddev->private; in raid1d()
2608 handle_sync_write_finished(conf, r1_bio); in raid1d()
2613 handle_write_finished(conf, r1_bio); in raid1d()
2615 handle_read_error(conf, r1_bio); in raid1d()
2626 static int init_resync(struct r1conf *conf) in init_resync() argument
2631 BUG_ON(mempool_initialized(&conf->r1buf_pool)); in init_resync()
2633 return mempool_init(&conf->r1buf_pool, buffs, r1buf_pool_alloc, in init_resync()
2634 r1buf_pool_free, conf->poolinfo); in init_resync()
2637 static struct r1bio *raid1_alloc_init_r1buf(struct r1conf *conf) in raid1_alloc_init_r1buf() argument
2639 struct r1bio *r1bio = mempool_alloc(&conf->r1buf_pool, GFP_NOIO); in raid1_alloc_init_r1buf()
2644 for (i = conf->poolinfo->raid_disks; i--; ) { in raid1_alloc_init_r1buf()
2667 struct r1conf *conf = mddev->private; in raid1_sync_request() local
2682 if (!mempool_initialized(&conf->r1buf_pool)) in raid1_sync_request()
2683 if (init_resync(conf)) in raid1_sync_request()
2697 conf->fullsync = 0; in raid1_sync_request()
2700 close_sync(conf); in raid1_sync_request()
2703 conf->cluster_sync_low = 0; in raid1_sync_request()
2704 conf->cluster_sync_high = 0; in raid1_sync_request()
2712 conf->fullsync == 0) { in raid1_sync_request()
2720 !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { in raid1_sync_request()
2730 if (atomic_read(&conf->nr_waiting[idx])) in raid1_sync_request()
2738 mddev_is_clustered(mddev) && (sector_nr + 2 * RESYNC_SECTORS > conf->cluster_sync_high)); in raid1_sync_request()
2741 if (raise_barrier(conf, sector_nr)) in raid1_sync_request()
2744 r1_bio = raid1_alloc_init_r1buf(conf); in raid1_sync_request()
2763 for (i = 0; i < conf->raid_disks * 2; i++) { in raid1_sync_request()
2767 rdev = rcu_dereference(conf->mirrors[i].rdev); in raid1_sync_request()
2770 if (i < conf->raid_disks) in raid1_sync_request()
2835 for (i = 0 ; i < conf->raid_disks * 2 ; i++) in raid1_sync_request()
2837 struct md_rdev *rdev = conf->mirrors[i].rdev; in raid1_sync_request()
2852 conf->recovery_disabled = mddev->recovery_disabled; in raid1_sync_request()
2898 !conf->fullsync && in raid1_sync_request()
2905 for (i = 0 ; i < conf->raid_disks * 2; i++) { in raid1_sync_request()
2928 conf->cluster_sync_high < sector_nr + nr_sectors) { in raid1_sync_request()
2929 conf->cluster_sync_low = mddev->curr_resync_completed; in raid1_sync_request()
2930 conf->cluster_sync_high = conf->cluster_sync_low + CLUSTER_RESYNC_WINDOW_SECTORS; in raid1_sync_request()
2933 conf->cluster_sync_low, in raid1_sync_request()
2934 conf->cluster_sync_high); in raid1_sync_request()
2942 for (i = 0; i < conf->raid_disks * 2 && read_targets; i++) { in raid1_sync_request()
2973 struct r1conf *conf; in setup_conf() local
2979 conf = kzalloc(sizeof(struct r1conf), GFP_KERNEL); in setup_conf()
2980 if (!conf) in setup_conf()
2983 conf->nr_pending = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
2985 if (!conf->nr_pending) in setup_conf()
2988 conf->nr_waiting = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
2990 if (!conf->nr_waiting) in setup_conf()
2993 conf->nr_queued = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
2995 if (!conf->nr_queued) in setup_conf()
2998 conf->barrier = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
3000 if (!conf->barrier) in setup_conf()
3003 conf->mirrors = kzalloc(array3_size(sizeof(struct raid1_info), in setup_conf()
3006 if (!conf->mirrors) in setup_conf()
3009 conf->tmppage = alloc_page(GFP_KERNEL); in setup_conf()
3010 if (!conf->tmppage) in setup_conf()
3013 conf->poolinfo = kzalloc(sizeof(*conf->poolinfo), GFP_KERNEL); in setup_conf()
3014 if (!conf->poolinfo) in setup_conf()
3016 conf->poolinfo->raid_disks = mddev->raid_disks * 2; in setup_conf()
3017 err = mempool_init(&conf->r1bio_pool, NR_RAID_BIOS, r1bio_pool_alloc, in setup_conf()
3018 rbio_pool_free, conf->poolinfo); in setup_conf()
3022 err = bioset_init(&conf->bio_split, BIO_POOL_SIZE, 0, 0); in setup_conf()
3026 conf->poolinfo->mddev = mddev; in setup_conf()
3029 spin_lock_init(&conf->device_lock); in setup_conf()
3036 disk = conf->mirrors + mddev->raid_disks + disk_idx; in setup_conf()
3038 disk = conf->mirrors + disk_idx; in setup_conf()
3046 conf->raid_disks = mddev->raid_disks; in setup_conf()
3047 conf->mddev = mddev; in setup_conf()
3048 INIT_LIST_HEAD(&conf->retry_list); in setup_conf()
3049 INIT_LIST_HEAD(&conf->bio_end_io_list); in setup_conf()
3051 spin_lock_init(&conf->resync_lock); in setup_conf()
3052 init_waitqueue_head(&conf->wait_barrier); in setup_conf()
3054 bio_list_init(&conf->pending_bio_list); in setup_conf()
3055 conf->recovery_disabled = mddev->recovery_disabled - 1; in setup_conf()
3058 for (i = 0; i < conf->raid_disks * 2; i++) { in setup_conf()
3060 disk = conf->mirrors + i; in setup_conf()
3062 if (i < conf->raid_disks && in setup_conf()
3063 disk[conf->raid_disks].rdev) { in setup_conf()
3070 disk[conf->raid_disks].rdev; in setup_conf()
3071 disk[conf->raid_disks].rdev = NULL; in setup_conf()
3082 conf->fullsync = 1; in setup_conf()
3087 conf->thread = md_register_thread(raid1d, mddev, "raid1"); in setup_conf()
3088 if (!conf->thread) in setup_conf()
3091 return conf; in setup_conf()
3094 if (conf) { in setup_conf()
3095 mempool_exit(&conf->r1bio_pool); in setup_conf()
3096 kfree(conf->mirrors); in setup_conf()
3097 safe_put_page(conf->tmppage); in setup_conf()
3098 kfree(conf->poolinfo); in setup_conf()
3099 kfree(conf->nr_pending); in setup_conf()
3100 kfree(conf->nr_waiting); in setup_conf()
3101 kfree(conf->nr_queued); in setup_conf()
3102 kfree(conf->barrier); in setup_conf()
3103 bioset_exit(&conf->bio_split); in setup_conf()
3104 kfree(conf); in setup_conf()
3112 struct r1conf *conf; in raid1_run() local
3135 conf = setup_conf(mddev); in raid1_run()
3137 conf = mddev->private; in raid1_run()
3139 if (IS_ERR(conf)) in raid1_run()
3140 return PTR_ERR(conf); in raid1_run()
3153 for (i = 0; i < conf->raid_disks; i++) in raid1_run()
3154 if (conf->mirrors[i].rdev == NULL || in raid1_run()
3155 !test_bit(In_sync, &conf->mirrors[i].rdev->flags) || in raid1_run()
3156 test_bit(Faulty, &conf->mirrors[i].rdev->flags)) in raid1_run()
3161 if (conf->raid_disks - mddev->degraded < 1) { in raid1_run()
3166 if (conf->raid_disks - mddev->degraded == 1) in raid1_run()
3179 mddev->thread = conf->thread; in raid1_run()
3180 conf->thread = NULL; in raid1_run()
3181 mddev->private = conf; in raid1_run()
3194 raid1_free(mddev, conf); in raid1_run()
3200 struct r1conf *conf = priv; in raid1_free() local
3202 mempool_exit(&conf->r1bio_pool); in raid1_free()
3203 kfree(conf->mirrors); in raid1_free()
3204 safe_put_page(conf->tmppage); in raid1_free()
3205 kfree(conf->poolinfo); in raid1_free()
3206 kfree(conf->nr_pending); in raid1_free()
3207 kfree(conf->nr_waiting); in raid1_free()
3208 kfree(conf->nr_queued); in raid1_free()
3209 kfree(conf->barrier); in raid1_free()
3210 bioset_exit(&conf->bio_split); in raid1_free()
3211 kfree(conf); in raid1_free()
3247 * 2/ resize conf->mirrors in raid1_reshape()
3251 * Then resize conf->mirrors and swap in the new r1bio pool. in raid1_reshape()
3259 struct r1conf *conf = mddev->private; in raid1_reshape() local
3283 if (raid_disks < conf->raid_disks) { in raid1_reshape()
3285 for (d= 0; d < conf->raid_disks; d++) in raid1_reshape()
3286 if (conf->mirrors[d].rdev) in raid1_reshape()
3313 freeze_array(conf, 0); in raid1_reshape()
3316 oldpool = conf->r1bio_pool; in raid1_reshape()
3317 conf->r1bio_pool = newpool; in raid1_reshape()
3319 for (d = d2 = 0; d < conf->raid_disks; d++) { in raid1_reshape()
3320 struct md_rdev *rdev = conf->mirrors[d].rdev; in raid1_reshape()
3332 kfree(conf->mirrors); in raid1_reshape()
3333 conf->mirrors = newmirrors; in raid1_reshape()
3334 kfree(conf->poolinfo); in raid1_reshape()
3335 conf->poolinfo = newpoolinfo; in raid1_reshape()
3337 spin_lock_irqsave(&conf->device_lock, flags); in raid1_reshape()
3338 mddev->degraded += (raid_disks - conf->raid_disks); in raid1_reshape()
3339 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_reshape()
3340 conf->raid_disks = mddev->raid_disks = raid_disks; in raid1_reshape()
3343 unfreeze_array(conf); in raid1_reshape()
3355 struct r1conf *conf = mddev->private; in raid1_quiesce() local
3358 freeze_array(conf, 0); in raid1_quiesce()
3360 unfreeze_array(conf); in raid1_quiesce()
3369 struct r1conf *conf; in raid1_takeover() local
3373 conf = setup_conf(mddev); in raid1_takeover()
3374 if (!IS_ERR(conf)) { in raid1_takeover()
3376 conf->array_frozen = 1; in raid1_takeover()
3380 return conf; in raid1_takeover()