Lines Matching refs:conf
45 static void allow_barrier(struct r1conf *conf, sector_t sector_nr);
46 static void lower_barrier(struct r1conf *conf, sector_t sector_nr);
220 static void put_all_bios(struct r1conf *conf, struct r1bio *r1_bio) in put_all_bios() argument
224 for (i = 0; i < conf->raid_disks * 2; i++) { in put_all_bios()
234 struct r1conf *conf = r1_bio->mddev->private; in free_r1bio() local
236 put_all_bios(conf, r1_bio); in free_r1bio()
237 mempool_free(r1_bio, &conf->r1bio_pool); in free_r1bio()
242 struct r1conf *conf = r1_bio->mddev->private; in put_buf() local
246 for (i = 0; i < conf->raid_disks * 2; i++) { in put_buf()
249 rdev_dec_pending(conf->mirrors[i].rdev, r1_bio->mddev); in put_buf()
252 mempool_free(r1_bio, &conf->r1buf_pool); in put_buf()
254 lower_barrier(conf, sect); in put_buf()
261 struct r1conf *conf = mddev->private; in reschedule_retry() local
265 spin_lock_irqsave(&conf->device_lock, flags); in reschedule_retry()
266 list_add(&r1_bio->retry_list, &conf->retry_list); in reschedule_retry()
267 atomic_inc(&conf->nr_queued[idx]); in reschedule_retry()
268 spin_unlock_irqrestore(&conf->device_lock, flags); in reschedule_retry()
270 wake_up(&conf->wait_barrier); in reschedule_retry()
282 struct r1conf *conf = r1_bio->mddev->private; in call_bio_endio() local
292 allow_barrier(conf, r1_bio->sector); in call_bio_endio()
316 struct r1conf *conf = r1_bio->mddev->private; in update_head_pos() local
318 conf->mirrors[disk].head_position = in update_head_pos()
328 struct r1conf *conf = r1_bio->mddev->private; in find_bio_disk() local
329 int raid_disks = conf->raid_disks; in find_bio_disk()
345 struct r1conf *conf = r1_bio->mddev->private; in raid1_end_read_request() local
346 struct md_rdev *rdev = conf->mirrors[r1_bio->read_disk].rdev; in raid1_end_read_request()
366 spin_lock_irqsave(&conf->device_lock, flags); in raid1_end_read_request()
367 if (r1_bio->mddev->degraded == conf->raid_disks || in raid1_end_read_request()
368 (r1_bio->mddev->degraded == conf->raid_disks-1 && in raid1_end_read_request()
371 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_end_read_request()
376 rdev_dec_pending(rdev, conf->mddev); in raid1_end_read_request()
383 mdname(conf->mddev), in raid1_end_read_request()
428 struct r1conf *conf = r1_bio->mddev->private; in raid1_end_write_request() local
431 struct md_rdev *rdev = conf->mirrors[mirror].rdev; in raid1_end_write_request()
443 conf->mddev->recovery); in raid1_end_write_request()
532 rdev_dec_pending(rdev, conf->mddev); in raid1_end_write_request()
577 static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sectors) in read_balance() argument
609 if ((conf->mddev->recovery_cp < this_sector + sectors) || in read_balance()
610 (mddev_is_clustered(conf->mddev) && in read_balance()
611 md_cluster_ops->area_resyncing(conf->mddev, READ, this_sector, in read_balance()
617 for (disk = 0 ; disk < conf->raid_disks * 2 ; disk++) { in read_balance()
624 rdev = rcu_dereference(conf->mirrors[disk].rdev); in read_balance()
691 dist = abs(this_sector - conf->mirrors[disk].head_position); in read_balance()
697 if (conf->mirrors[disk].next_seq_sect == this_sector in read_balance()
700 struct raid1_info *mirror = &conf->mirrors[disk]; in read_balance()
755 rdev = rcu_dereference(conf->mirrors[best_disk].rdev); in read_balance()
761 if (conf->mirrors[best_disk].next_seq_sect != this_sector) in read_balance()
762 conf->mirrors[best_disk].seq_start = this_sector; in read_balance()
764 conf->mirrors[best_disk].next_seq_sect = this_sector + sectors; in read_balance()
774 struct r1conf *conf = mddev->private; in raid1_congested() local
778 conf->pending_count >= max_queued_requests) in raid1_congested()
782 for (i = 0; i < conf->raid_disks * 2; i++) { in raid1_congested()
783 struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); in raid1_congested()
802 static void flush_bio_list(struct r1conf *conf, struct bio *bio) in flush_bio_list() argument
805 md_bitmap_unplug(conf->mddev->bitmap); in flush_bio_list()
806 wake_up(&conf->wait_barrier); in flush_bio_list()
825 static void flush_pending_writes(struct r1conf *conf) in flush_pending_writes() argument
830 spin_lock_irq(&conf->device_lock); in flush_pending_writes()
832 if (conf->pending_bio_list.head) { in flush_pending_writes()
836 bio = bio_list_get(&conf->pending_bio_list); in flush_pending_writes()
837 conf->pending_count = 0; in flush_pending_writes()
838 spin_unlock_irq(&conf->device_lock); in flush_pending_writes()
851 flush_bio_list(conf, bio); in flush_pending_writes()
854 spin_unlock_irq(&conf->device_lock); in flush_pending_writes()
881 static int raise_barrier(struct r1conf *conf, sector_t sector_nr) in raise_barrier() argument
885 spin_lock_irq(&conf->resync_lock); in raise_barrier()
888 wait_event_lock_irq(conf->wait_barrier, in raise_barrier()
889 !atomic_read(&conf->nr_waiting[idx]), in raise_barrier()
890 conf->resync_lock); in raise_barrier()
893 atomic_inc(&conf->barrier[idx]); in raise_barrier()
911 wait_event_lock_irq(conf->wait_barrier, in raise_barrier()
912 (!conf->array_frozen && in raise_barrier()
913 !atomic_read(&conf->nr_pending[idx]) && in raise_barrier()
914 atomic_read(&conf->barrier[idx]) < RESYNC_DEPTH) || in raise_barrier()
915 test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery), in raise_barrier()
916 conf->resync_lock); in raise_barrier()
918 if (test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { in raise_barrier()
919 atomic_dec(&conf->barrier[idx]); in raise_barrier()
920 spin_unlock_irq(&conf->resync_lock); in raise_barrier()
921 wake_up(&conf->wait_barrier); in raise_barrier()
925 atomic_inc(&conf->nr_sync_pending); in raise_barrier()
926 spin_unlock_irq(&conf->resync_lock); in raise_barrier()
931 static void lower_barrier(struct r1conf *conf, sector_t sector_nr) in lower_barrier() argument
935 BUG_ON(atomic_read(&conf->barrier[idx]) <= 0); in lower_barrier()
937 atomic_dec(&conf->barrier[idx]); in lower_barrier()
938 atomic_dec(&conf->nr_sync_pending); in lower_barrier()
939 wake_up(&conf->wait_barrier); in lower_barrier()
942 static void _wait_barrier(struct r1conf *conf, int idx) in _wait_barrier() argument
952 atomic_inc(&conf->nr_pending[idx]); in _wait_barrier()
972 if (!READ_ONCE(conf->array_frozen) && in _wait_barrier()
973 !atomic_read(&conf->barrier[idx])) in _wait_barrier()
983 spin_lock_irq(&conf->resync_lock); in _wait_barrier()
984 atomic_inc(&conf->nr_waiting[idx]); in _wait_barrier()
985 atomic_dec(&conf->nr_pending[idx]); in _wait_barrier()
990 wake_up(&conf->wait_barrier); in _wait_barrier()
992 wait_event_lock_irq(conf->wait_barrier, in _wait_barrier()
993 !conf->array_frozen && in _wait_barrier()
994 !atomic_read(&conf->barrier[idx]), in _wait_barrier()
995 conf->resync_lock); in _wait_barrier()
996 atomic_inc(&conf->nr_pending[idx]); in _wait_barrier()
997 atomic_dec(&conf->nr_waiting[idx]); in _wait_barrier()
998 spin_unlock_irq(&conf->resync_lock); in _wait_barrier()
1001 static void wait_read_barrier(struct r1conf *conf, sector_t sector_nr) in wait_read_barrier() argument
1012 atomic_inc(&conf->nr_pending[idx]); in wait_read_barrier()
1014 if (!READ_ONCE(conf->array_frozen)) in wait_read_barrier()
1017 spin_lock_irq(&conf->resync_lock); in wait_read_barrier()
1018 atomic_inc(&conf->nr_waiting[idx]); in wait_read_barrier()
1019 atomic_dec(&conf->nr_pending[idx]); in wait_read_barrier()
1024 wake_up(&conf->wait_barrier); in wait_read_barrier()
1026 wait_event_lock_irq(conf->wait_barrier, in wait_read_barrier()
1027 !conf->array_frozen, in wait_read_barrier()
1028 conf->resync_lock); in wait_read_barrier()
1029 atomic_inc(&conf->nr_pending[idx]); in wait_read_barrier()
1030 atomic_dec(&conf->nr_waiting[idx]); in wait_read_barrier()
1031 spin_unlock_irq(&conf->resync_lock); in wait_read_barrier()
1034 static void wait_barrier(struct r1conf *conf, sector_t sector_nr) in wait_barrier() argument
1038 _wait_barrier(conf, idx); in wait_barrier()
1041 static void _allow_barrier(struct r1conf *conf, int idx) in _allow_barrier() argument
1043 atomic_dec(&conf->nr_pending[idx]); in _allow_barrier()
1044 wake_up(&conf->wait_barrier); in _allow_barrier()
1047 static void allow_barrier(struct r1conf *conf, sector_t sector_nr) in allow_barrier() argument
1051 _allow_barrier(conf, idx); in allow_barrier()
1055 static int get_unqueued_pending(struct r1conf *conf) in get_unqueued_pending() argument
1059 ret = atomic_read(&conf->nr_sync_pending); in get_unqueued_pending()
1061 ret += atomic_read(&conf->nr_pending[idx]) - in get_unqueued_pending()
1062 atomic_read(&conf->nr_queued[idx]); in get_unqueued_pending()
1067 static void freeze_array(struct r1conf *conf, int extra) in freeze_array() argument
1092 spin_lock_irq(&conf->resync_lock); in freeze_array()
1093 conf->array_frozen = 1; in freeze_array()
1094 raid1_log(conf->mddev, "wait freeze"); in freeze_array()
1096 conf->wait_barrier, in freeze_array()
1097 get_unqueued_pending(conf) == extra, in freeze_array()
1098 conf->resync_lock, in freeze_array()
1099 flush_pending_writes(conf)); in freeze_array()
1100 spin_unlock_irq(&conf->resync_lock); in freeze_array()
1102 static void unfreeze_array(struct r1conf *conf) in unfreeze_array() argument
1105 spin_lock_irq(&conf->resync_lock); in unfreeze_array()
1106 conf->array_frozen = 0; in unfreeze_array()
1107 spin_unlock_irq(&conf->resync_lock); in unfreeze_array()
1108 wake_up(&conf->wait_barrier); in unfreeze_array()
1170 struct r1conf *conf = mddev->private; in raid1_unplug() local
1174 spin_lock_irq(&conf->device_lock); in raid1_unplug()
1175 bio_list_merge(&conf->pending_bio_list, &plug->pending); in raid1_unplug()
1176 conf->pending_count += plug->pending_cnt; in raid1_unplug()
1177 spin_unlock_irq(&conf->device_lock); in raid1_unplug()
1178 wake_up(&conf->wait_barrier); in raid1_unplug()
1186 flush_bio_list(conf, bio); in raid1_unplug()
1202 struct r1conf *conf = mddev->private; in alloc_r1bio() local
1205 r1_bio = mempool_alloc(&conf->r1bio_pool, GFP_NOIO); in alloc_r1bio()
1207 memset(r1_bio->bios, 0, conf->raid_disks * sizeof(r1_bio->bios[0])); in alloc_r1bio()
1215 struct r1conf *conf = mddev->private; in raid1_read_request() local
1237 rdev = rcu_dereference(conf->mirrors[r1_bio->read_disk].rdev); in raid1_read_request()
1249 wait_read_barrier(conf, bio->bi_iter.bi_sector); in raid1_read_request()
1261 rdisk = read_balance(conf, r1_bio, &max_sectors); in raid1_read_request()
1274 mirror = conf->mirrors + rdisk; in raid1_read_request()
1295 gfp, &conf->bio_split); in raid1_read_request()
1329 struct r1conf *conf = mddev->private; in raid1_write_request() local
1346 prepare_to_wait(&conf->wait_barrier, in raid1_write_request()
1354 finish_wait(&conf->wait_barrier, &w); in raid1_write_request()
1362 wait_barrier(conf, bio->bi_iter.bi_sector); in raid1_write_request()
1367 if (conf->pending_count >= max_queued_requests) { in raid1_write_request()
1370 wait_event(conf->wait_barrier, in raid1_write_request()
1371 conf->pending_count < max_queued_requests); in raid1_write_request()
1384 disks = conf->raid_disks * 2; in raid1_write_request()
1390 struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); in raid1_write_request()
1398 if (i < conf->raid_disks) in raid1_write_request()
1455 rdev_dec_pending(conf->mirrors[j].rdev, mddev); in raid1_write_request()
1457 allow_barrier(conf, bio->bi_iter.bi_sector); in raid1_write_request()
1460 wait_barrier(conf, bio->bi_iter.bi_sector); in raid1_write_request()
1466 GFP_NOIO, &conf->bio_split); in raid1_write_request()
1508 struct md_rdev *rdev = conf->mirrors[i].rdev; in raid1_write_request()
1524 conf->mirrors[i].rdev->data_offset); in raid1_write_request()
1525 bio_set_dev(mbio, conf->mirrors[i].rdev->bdev); in raid1_write_request()
1528 if (test_bit(FailFast, &conf->mirrors[i].rdev->flags) && in raid1_write_request()
1529 !test_bit(WriteMostly, &conf->mirrors[i].rdev->flags) && in raid1_write_request()
1530 conf->raid_disks - mddev->degraded > 1) in raid1_write_request()
1541 mbio->bi_disk = (void *)conf->mirrors[i].rdev; in raid1_write_request()
1552 spin_lock_irqsave(&conf->device_lock, flags); in raid1_write_request()
1553 bio_list_add(&conf->pending_bio_list, mbio); in raid1_write_request()
1554 conf->pending_count++; in raid1_write_request()
1555 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_write_request()
1563 wake_up(&conf->wait_barrier); in raid1_write_request()
1596 struct r1conf *conf = mddev->private; in raid1_status() local
1599 seq_printf(seq, " [%d/%d] [", conf->raid_disks, in raid1_status()
1600 conf->raid_disks - mddev->degraded); in raid1_status()
1602 for (i = 0; i < conf->raid_disks; i++) { in raid1_status()
1603 struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); in raid1_status()
1614 struct r1conf *conf = mddev->private; in raid1_error() local
1623 spin_lock_irqsave(&conf->device_lock, flags); in raid1_error()
1625 && (conf->raid_disks - mddev->degraded) == 1) { in raid1_error()
1632 conf->recovery_disabled = mddev->recovery_disabled; in raid1_error()
1633 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_error()
1640 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_error()
1650 mdname(mddev), conf->raid_disks - mddev->degraded); in raid1_error()
1653 static void print_conf(struct r1conf *conf) in print_conf() argument
1658 if (!conf) { in print_conf()
1662 pr_debug(" --- wd:%d rd:%d\n", conf->raid_disks - conf->mddev->degraded, in print_conf()
1663 conf->raid_disks); in print_conf()
1666 for (i = 0; i < conf->raid_disks; i++) { in print_conf()
1668 struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); in print_conf()
1678 static void close_sync(struct r1conf *conf) in close_sync() argument
1683 _wait_barrier(conf, idx); in close_sync()
1684 _allow_barrier(conf, idx); in close_sync()
1687 mempool_exit(&conf->r1buf_pool); in close_sync()
1693 struct r1conf *conf = mddev->private; in raid1_spare_active() local
1704 spin_lock_irqsave(&conf->device_lock, flags); in raid1_spare_active()
1705 for (i = 0; i < conf->raid_disks; i++) { in raid1_spare_active()
1706 struct md_rdev *rdev = conf->mirrors[i].rdev; in raid1_spare_active()
1707 struct md_rdev *repl = conf->mirrors[conf->raid_disks + i].rdev; in raid1_spare_active()
1736 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_spare_active()
1738 print_conf(conf); in raid1_spare_active()
1744 struct r1conf *conf = mddev->private; in raid1_add_disk() local
1749 int last = conf->raid_disks - 1; in raid1_add_disk()
1751 if (mddev->recovery_disabled == conf->recovery_disabled) in raid1_add_disk()
1766 rdev->saved_raid_disk < conf->raid_disks && in raid1_add_disk()
1767 conf->mirrors[rdev->saved_raid_disk].rdev == NULL) in raid1_add_disk()
1771 p = conf->mirrors + mirror; in raid1_add_disk()
1784 conf->fullsync = 1; in raid1_add_disk()
1789 p[conf->raid_disks].rdev == NULL) { in raid1_add_disk()
1795 conf->fullsync = 1; in raid1_add_disk()
1796 rcu_assign_pointer(p[conf->raid_disks].rdev, rdev); in raid1_add_disk()
1802 print_conf(conf); in raid1_add_disk()
1808 struct r1conf *conf = mddev->private; in raid1_remove_disk() local
1811 struct raid1_info *p = conf->mirrors + number; in raid1_remove_disk()
1814 p = conf->mirrors + conf->raid_disks + number; in raid1_remove_disk()
1816 print_conf(conf); in raid1_remove_disk()
1827 mddev->recovery_disabled != conf->recovery_disabled && in raid1_remove_disk()
1828 mddev->degraded < conf->raid_disks) { in raid1_remove_disk()
1842 if (conf->mirrors[conf->raid_disks + number].rdev) { in raid1_remove_disk()
1848 conf->mirrors[conf->raid_disks + number].rdev; in raid1_remove_disk()
1849 freeze_array(conf, 0); in raid1_remove_disk()
1858 unfreeze_array(conf); in raid1_remove_disk()
1863 conf->mirrors[conf->raid_disks + number].rdev = NULL; in raid1_remove_disk()
1864 unfreeze_array(conf); in raid1_remove_disk()
1872 print_conf(conf); in raid1_remove_disk()
1929 struct r1conf *conf = mddev->private; in end_sync_write() local
1932 struct md_rdev *rdev = conf->mirrors[find_bio_disk(r1_bio, bio)].rdev; in end_sync_write()
1943 !is_badblock(conf->mirrors[r1_bio->read_disk].rdev, in end_sync_write()
1986 struct r1conf *conf = mddev->private; in fix_sync_read_error() local
1994 rdev = conf->mirrors[r1_bio->read_disk].rdev; in fix_sync_read_error()
2020 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2029 if (d == conf->raid_disks * 2) in fix_sync_read_error()
2044 for (d = 0; d < conf->raid_disks * 2; d++) { in fix_sync_read_error()
2045 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2052 conf->recovery_disabled = in fix_sync_read_error()
2070 d = conf->raid_disks * 2; in fix_sync_read_error()
2074 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2085 d = conf->raid_disks * 2; in fix_sync_read_error()
2089 rdev = conf->mirrors[d].rdev; in fix_sync_read_error()
2114 struct r1conf *conf = mddev->private; in process_checks() local
2121 for (i = 0; i < conf->raid_disks * 2; i++) { in process_checks()
2132 conf->mirrors[i].rdev->data_offset; in process_checks()
2133 bio_set_dev(b, conf->mirrors[i].rdev->bdev); in process_checks()
2141 for (primary = 0; primary < conf->raid_disks * 2; primary++) in process_checks()
2145 rdev_dec_pending(conf->mirrors[primary].rdev, mddev); in process_checks()
2149 for (i = 0; i < conf->raid_disks * 2; i++) { in process_checks()
2183 rdev_dec_pending(conf->mirrors[i].rdev, mddev); in process_checks()
2193 struct r1conf *conf = mddev->private; in sync_request_write() local
2195 int disks = conf->raid_disks * 2; in sync_request_write()
2217 if (test_bit(Faulty, &conf->mirrors[i].rdev->flags)) { in sync_request_write()
2223 if (test_bit(FailFast, &conf->mirrors[i].rdev->flags)) in sync_request_write()
2228 md_sync_acct(conf->mirrors[i].rdev->bdev, bio_sectors(wbio)); in sync_request_write()
2244 static void fix_read_error(struct r1conf *conf, int read_disk, in fix_read_error() argument
2247 struct mddev *mddev = conf->mddev; in fix_read_error()
2263 rdev = rcu_dereference(conf->mirrors[d].rdev); in fix_read_error()
2273 conf->tmppage, REQ_OP_READ, 0, false)) in fix_read_error()
2281 if (d == conf->raid_disks * 2) in fix_read_error()
2287 struct md_rdev *rdev = conf->mirrors[read_disk].rdev; in fix_read_error()
2296 d = conf->raid_disks * 2; in fix_read_error()
2299 rdev = rcu_dereference(conf->mirrors[d].rdev); in fix_read_error()
2305 conf->tmppage, WRITE); in fix_read_error()
2314 d = conf->raid_disks * 2; in fix_read_error()
2317 rdev = rcu_dereference(conf->mirrors[d].rdev); in fix_read_error()
2323 conf->tmppage, READ)) { in fix_read_error()
2343 struct r1conf *conf = mddev->private; in narrow_write_error() local
2344 struct md_rdev *rdev = conf->mirrors[i].rdev; in narrow_write_error()
2410 static void handle_sync_write_finished(struct r1conf *conf, struct r1bio *r1_bio) in handle_sync_write_finished() argument
2414 for (m = 0; m < conf->raid_disks * 2 ; m++) { in handle_sync_write_finished()
2415 struct md_rdev *rdev = conf->mirrors[m].rdev; in handle_sync_write_finished()
2426 md_error(conf->mddev, rdev); in handle_sync_write_finished()
2430 md_done_sync(conf->mddev, s, 1); in handle_sync_write_finished()
2433 static void handle_write_finished(struct r1conf *conf, struct r1bio *r1_bio) in handle_write_finished() argument
2438 for (m = 0; m < conf->raid_disks * 2 ; m++) in handle_write_finished()
2440 struct md_rdev *rdev = conf->mirrors[m].rdev; in handle_write_finished()
2444 rdev_dec_pending(rdev, conf->mddev); in handle_write_finished()
2452 md_error(conf->mddev, in handle_write_finished()
2453 conf->mirrors[m].rdev); in handle_write_finished()
2457 rdev_dec_pending(conf->mirrors[m].rdev, in handle_write_finished()
2458 conf->mddev); in handle_write_finished()
2461 spin_lock_irq(&conf->device_lock); in handle_write_finished()
2462 list_add(&r1_bio->retry_list, &conf->bio_end_io_list); in handle_write_finished()
2464 atomic_inc(&conf->nr_queued[idx]); in handle_write_finished()
2465 spin_unlock_irq(&conf->device_lock); in handle_write_finished()
2470 wake_up(&conf->wait_barrier); in handle_write_finished()
2471 md_wakeup_thread(conf->mddev->thread); in handle_write_finished()
2479 static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio) in handle_read_error() argument
2481 struct mddev *mddev = conf->mddev; in handle_read_error()
2499 rdev = conf->mirrors[r1_bio->read_disk].rdev; in handle_read_error()
2502 freeze_array(conf, 1); in handle_read_error()
2503 fix_read_error(conf, r1_bio->read_disk, in handle_read_error()
2505 unfreeze_array(conf); in handle_read_error()
2512 rdev_dec_pending(rdev, conf->mddev); in handle_read_error()
2513 allow_barrier(conf, r1_bio->sector); in handle_read_error()
2526 struct r1conf *conf = mddev->private; in raid1d() local
2527 struct list_head *head = &conf->retry_list; in raid1d()
2533 if (!list_empty_careful(&conf->bio_end_io_list) && in raid1d()
2536 spin_lock_irqsave(&conf->device_lock, flags); in raid1d()
2538 list_splice_init(&conf->bio_end_io_list, &tmp); in raid1d()
2539 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1d()
2545 atomic_dec(&conf->nr_queued[idx]); in raid1d()
2557 flush_pending_writes(conf); in raid1d()
2559 spin_lock_irqsave(&conf->device_lock, flags); in raid1d()
2561 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1d()
2567 atomic_dec(&conf->nr_queued[idx]); in raid1d()
2568 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1d()
2571 conf = mddev->private; in raid1d()
2575 handle_sync_write_finished(conf, r1_bio); in raid1d()
2580 handle_write_finished(conf, r1_bio); in raid1d()
2582 handle_read_error(conf, r1_bio); in raid1d()
2593 static int init_resync(struct r1conf *conf) in init_resync() argument
2598 BUG_ON(mempool_initialized(&conf->r1buf_pool)); in init_resync()
2600 return mempool_init(&conf->r1buf_pool, buffs, r1buf_pool_alloc, in init_resync()
2601 r1buf_pool_free, conf->poolinfo); in init_resync()
2604 static struct r1bio *raid1_alloc_init_r1buf(struct r1conf *conf) in raid1_alloc_init_r1buf() argument
2606 struct r1bio *r1bio = mempool_alloc(&conf->r1buf_pool, GFP_NOIO); in raid1_alloc_init_r1buf()
2611 for (i = conf->poolinfo->raid_disks; i--; ) { in raid1_alloc_init_r1buf()
2634 struct r1conf *conf = mddev->private; in raid1_sync_request() local
2649 if (!mempool_initialized(&conf->r1buf_pool)) in raid1_sync_request()
2650 if (init_resync(conf)) in raid1_sync_request()
2664 conf->fullsync = 0; in raid1_sync_request()
2667 close_sync(conf); in raid1_sync_request()
2670 conf->cluster_sync_low = 0; in raid1_sync_request()
2671 conf->cluster_sync_high = 0; in raid1_sync_request()
2679 conf->fullsync == 0) { in raid1_sync_request()
2687 !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { in raid1_sync_request()
2697 if (atomic_read(&conf->nr_waiting[idx])) in raid1_sync_request()
2705 mddev_is_clustered(mddev) && (sector_nr + 2 * RESYNC_SECTORS > conf->cluster_sync_high)); in raid1_sync_request()
2708 if (raise_barrier(conf, sector_nr)) in raid1_sync_request()
2711 r1_bio = raid1_alloc_init_r1buf(conf); in raid1_sync_request()
2730 for (i = 0; i < conf->raid_disks * 2; i++) { in raid1_sync_request()
2734 rdev = rcu_dereference(conf->mirrors[i].rdev); in raid1_sync_request()
2737 if (i < conf->raid_disks) in raid1_sync_request()
2802 for (i = 0 ; i < conf->raid_disks * 2 ; i++) in raid1_sync_request()
2804 struct md_rdev *rdev = conf->mirrors[i].rdev; in raid1_sync_request()
2819 conf->recovery_disabled = mddev->recovery_disabled; in raid1_sync_request()
2865 !conf->fullsync && in raid1_sync_request()
2872 for (i = 0 ; i < conf->raid_disks * 2; i++) { in raid1_sync_request()
2895 conf->cluster_sync_high < sector_nr + nr_sectors) { in raid1_sync_request()
2896 conf->cluster_sync_low = mddev->curr_resync_completed; in raid1_sync_request()
2897 conf->cluster_sync_high = conf->cluster_sync_low + CLUSTER_RESYNC_WINDOW_SECTORS; in raid1_sync_request()
2900 conf->cluster_sync_low, in raid1_sync_request()
2901 conf->cluster_sync_high); in raid1_sync_request()
2909 for (i = 0; i < conf->raid_disks * 2 && read_targets; i++) { in raid1_sync_request()
2940 struct r1conf *conf; in setup_conf() local
2946 conf = kzalloc(sizeof(struct r1conf), GFP_KERNEL); in setup_conf()
2947 if (!conf) in setup_conf()
2950 conf->nr_pending = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
2952 if (!conf->nr_pending) in setup_conf()
2955 conf->nr_waiting = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
2957 if (!conf->nr_waiting) in setup_conf()
2960 conf->nr_queued = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
2962 if (!conf->nr_queued) in setup_conf()
2965 conf->barrier = kcalloc(BARRIER_BUCKETS_NR, in setup_conf()
2967 if (!conf->barrier) in setup_conf()
2970 conf->mirrors = kzalloc(array3_size(sizeof(struct raid1_info), in setup_conf()
2973 if (!conf->mirrors) in setup_conf()
2976 conf->tmppage = alloc_page(GFP_KERNEL); in setup_conf()
2977 if (!conf->tmppage) in setup_conf()
2980 conf->poolinfo = kzalloc(sizeof(*conf->poolinfo), GFP_KERNEL); in setup_conf()
2981 if (!conf->poolinfo) in setup_conf()
2983 conf->poolinfo->raid_disks = mddev->raid_disks * 2; in setup_conf()
2984 err = mempool_init(&conf->r1bio_pool, NR_RAID_BIOS, r1bio_pool_alloc, in setup_conf()
2985 rbio_pool_free, conf->poolinfo); in setup_conf()
2989 err = bioset_init(&conf->bio_split, BIO_POOL_SIZE, 0, 0); in setup_conf()
2993 conf->poolinfo->mddev = mddev; in setup_conf()
2996 spin_lock_init(&conf->device_lock); in setup_conf()
3003 disk = conf->mirrors + mddev->raid_disks + disk_idx; in setup_conf()
3005 disk = conf->mirrors + disk_idx; in setup_conf()
3013 conf->raid_disks = mddev->raid_disks; in setup_conf()
3014 conf->mddev = mddev; in setup_conf()
3015 INIT_LIST_HEAD(&conf->retry_list); in setup_conf()
3016 INIT_LIST_HEAD(&conf->bio_end_io_list); in setup_conf()
3018 spin_lock_init(&conf->resync_lock); in setup_conf()
3019 init_waitqueue_head(&conf->wait_barrier); in setup_conf()
3021 bio_list_init(&conf->pending_bio_list); in setup_conf()
3022 conf->pending_count = 0; in setup_conf()
3023 conf->recovery_disabled = mddev->recovery_disabled - 1; in setup_conf()
3026 for (i = 0; i < conf->raid_disks * 2; i++) { in setup_conf()
3028 disk = conf->mirrors + i; in setup_conf()
3030 if (i < conf->raid_disks && in setup_conf()
3031 disk[conf->raid_disks].rdev) { in setup_conf()
3038 disk[conf->raid_disks].rdev; in setup_conf()
3039 disk[conf->raid_disks].rdev = NULL; in setup_conf()
3050 conf->fullsync = 1; in setup_conf()
3055 conf->thread = md_register_thread(raid1d, mddev, "raid1"); in setup_conf()
3056 if (!conf->thread) in setup_conf()
3059 return conf; in setup_conf()
3062 if (conf) { in setup_conf()
3063 mempool_exit(&conf->r1bio_pool); in setup_conf()
3064 kfree(conf->mirrors); in setup_conf()
3065 safe_put_page(conf->tmppage); in setup_conf()
3066 kfree(conf->poolinfo); in setup_conf()
3067 kfree(conf->nr_pending); in setup_conf()
3068 kfree(conf->nr_waiting); in setup_conf()
3069 kfree(conf->nr_queued); in setup_conf()
3070 kfree(conf->barrier); in setup_conf()
3071 bioset_exit(&conf->bio_split); in setup_conf()
3072 kfree(conf); in setup_conf()
3080 struct r1conf *conf; in raid1_run() local
3104 conf = setup_conf(mddev); in raid1_run()
3106 conf = mddev->private; in raid1_run()
3108 if (IS_ERR(conf)) in raid1_run()
3109 return PTR_ERR(conf); in raid1_run()
3126 for (i = 0; i < conf->raid_disks; i++) in raid1_run()
3127 if (conf->mirrors[i].rdev == NULL || in raid1_run()
3128 !test_bit(In_sync, &conf->mirrors[i].rdev->flags) || in raid1_run()
3129 test_bit(Faulty, &conf->mirrors[i].rdev->flags)) in raid1_run()
3134 if (conf->raid_disks - mddev->degraded < 1) { in raid1_run()
3139 if (conf->raid_disks - mddev->degraded == 1) in raid1_run()
3152 mddev->thread = conf->thread; in raid1_run()
3153 conf->thread = NULL; in raid1_run()
3154 mddev->private = conf; in raid1_run()
3176 raid1_free(mddev, conf); in raid1_run()
3182 struct r1conf *conf = priv; in raid1_free() local
3184 mempool_exit(&conf->r1bio_pool); in raid1_free()
3185 kfree(conf->mirrors); in raid1_free()
3186 safe_put_page(conf->tmppage); in raid1_free()
3187 kfree(conf->poolinfo); in raid1_free()
3188 kfree(conf->nr_pending); in raid1_free()
3189 kfree(conf->nr_waiting); in raid1_free()
3190 kfree(conf->nr_queued); in raid1_free()
3191 kfree(conf->barrier); in raid1_free()
3192 bioset_exit(&conf->bio_split); in raid1_free()
3193 kfree(conf); in raid1_free()
3241 struct r1conf *conf = mddev->private; in raid1_reshape() local
3265 if (raid_disks < conf->raid_disks) { in raid1_reshape()
3267 for (d= 0; d < conf->raid_disks; d++) in raid1_reshape()
3268 if (conf->mirrors[d].rdev) in raid1_reshape()
3295 freeze_array(conf, 0); in raid1_reshape()
3298 oldpool = conf->r1bio_pool; in raid1_reshape()
3299 conf->r1bio_pool = newpool; in raid1_reshape()
3301 for (d = d2 = 0; d < conf->raid_disks; d++) { in raid1_reshape()
3302 struct md_rdev *rdev = conf->mirrors[d].rdev; in raid1_reshape()
3314 kfree(conf->mirrors); in raid1_reshape()
3315 conf->mirrors = newmirrors; in raid1_reshape()
3316 kfree(conf->poolinfo); in raid1_reshape()
3317 conf->poolinfo = newpoolinfo; in raid1_reshape()
3319 spin_lock_irqsave(&conf->device_lock, flags); in raid1_reshape()
3320 mddev->degraded += (raid_disks - conf->raid_disks); in raid1_reshape()
3321 spin_unlock_irqrestore(&conf->device_lock, flags); in raid1_reshape()
3322 conf->raid_disks = mddev->raid_disks = raid_disks; in raid1_reshape()
3325 unfreeze_array(conf); in raid1_reshape()
3337 struct r1conf *conf = mddev->private; in raid1_quiesce() local
3340 freeze_array(conf, 0); in raid1_quiesce()
3342 unfreeze_array(conf); in raid1_quiesce()
3351 struct r1conf *conf; in raid1_takeover() local
3355 conf = setup_conf(mddev); in raid1_takeover()
3356 if (!IS_ERR(conf)) { in raid1_takeover()
3358 conf->array_frozen = 1; in raid1_takeover()
3362 return conf; in raid1_takeover()