Lines Matching full:conf
67 static void allow_barrier(struct r10conf *conf);
68 static void lower_barrier(struct r10conf *conf);
69 static int _enough(struct r10conf *conf, int previous, int ignore);
70 static int enough(struct r10conf *conf, int ignore);
75 static void end_reshape(struct r10conf *conf);
83 #define cmd_before(conf, cmd) \ argument
85 write_sequnlock_irq(&(conf)->resync_lock); \
88 #define cmd_after(conf) write_seqlock_irq(&(conf)->resync_lock) argument
90 #define wait_event_barrier_cmd(conf, cond, cmd) \ argument
91 wait_event_cmd((conf)->wait_barrier, cond, cmd_before(conf, cmd), \
92 cmd_after(conf))
94 #define wait_event_barrier(conf, cond) \ argument
95 wait_event_barrier_cmd(conf, cond, NULL_CMD)
108 struct r10conf *conf = data; in r10bio_pool_alloc() local
109 int size = offsetof(struct r10bio, devs[conf->geo.raid_disks]); in r10bio_pool_alloc()
133 struct r10conf *conf = data; in r10buf_pool_alloc() local
140 r10_bio = r10bio_pool_alloc(gfp_flags, conf); in r10buf_pool_alloc()
144 if (test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery) || in r10buf_pool_alloc()
145 test_bit(MD_RECOVERY_RESHAPE, &conf->mddev->recovery)) in r10buf_pool_alloc()
146 nalloc = conf->copies; /* resync */ in r10buf_pool_alloc()
151 if (!conf->have_replacement) in r10buf_pool_alloc()
168 if (!conf->have_replacement) in r10buf_pool_alloc()
191 &conf->mddev->recovery)) { in r10buf_pool_alloc()
225 rbio_pool_free(r10_bio, conf); in r10buf_pool_alloc()
231 struct r10conf *conf = data; in r10buf_pool_free() local
236 for (j = conf->copies; j--; ) { in r10buf_pool_free()
256 rbio_pool_free(r10bio, conf); in r10buf_pool_free()
259 static void put_all_bios(struct r10conf *conf, struct r10bio *r10_bio) in put_all_bios() argument
263 for (i = 0; i < conf->geo.raid_disks; i++) { in put_all_bios()
277 struct r10conf *conf = r10_bio->mddev->private; in free_r10bio() local
279 put_all_bios(conf, r10_bio); in free_r10bio()
280 mempool_free(r10_bio, &conf->r10bio_pool); in free_r10bio()
285 struct r10conf *conf = r10_bio->mddev->private; in put_buf() local
287 mempool_free(r10_bio, &conf->r10buf_pool); in put_buf()
289 lower_barrier(conf); in put_buf()
292 static void wake_up_barrier(struct r10conf *conf) in wake_up_barrier() argument
294 if (wq_has_sleeper(&conf->wait_barrier)) in wake_up_barrier()
295 wake_up(&conf->wait_barrier); in wake_up_barrier()
302 struct r10conf *conf = mddev->private; in reschedule_retry() local
304 spin_lock_irqsave(&conf->device_lock, flags); in reschedule_retry()
305 list_add(&r10_bio->retry_list, &conf->retry_list); in reschedule_retry()
306 conf->nr_queued ++; in reschedule_retry()
307 spin_unlock_irqrestore(&conf->device_lock, flags); in reschedule_retry()
310 wake_up(&conf->wait_barrier); in reschedule_retry()
323 struct r10conf *conf = r10_bio->mddev->private; in raid_end_bio_io() local
333 allow_barrier(conf); in raid_end_bio_io()
343 struct r10conf *conf = r10_bio->mddev->private; in update_head_pos() local
345 conf->mirrors[r10_bio->devs[slot].devnum].head_position = in update_head_pos()
352 static int find_bio_disk(struct r10conf *conf, struct r10bio *r10_bio, in find_bio_disk() argument
358 for (slot = 0; slot < conf->geo.raid_disks; slot++) { in find_bio_disk()
382 struct r10conf *conf = r10_bio->mddev->private; in raid10_end_read_request() local
408 if (!_enough(conf, test_bit(R10BIO_Previous, &r10_bio->state), in raid10_end_read_request()
414 rdev_dec_pending(rdev, conf->mddev); in raid10_end_read_request()
420 mdname(conf->mddev), in raid10_end_read_request()
453 struct r10conf *conf = r10_bio->mddev->private; in raid10_end_write_request() local
461 dev = find_bio_disk(conf, r10_bio, bio, &slot, &repl); in raid10_end_write_request()
464 rdev = conf->mirrors[dev].replacement; in raid10_end_write_request()
468 rdev = conf->mirrors[dev].rdev; in raid10_end_write_request()
551 rdev_dec_pending(rdev, conf->mddev); in raid10_end_write_request()
644 static void raid10_find_phys(struct r10conf *conf, struct r10bio *r10bio) in raid10_find_phys() argument
646 struct geom *geo = &conf->geo; in raid10_find_phys()
648 if (conf->reshape_progress != MaxSector && in raid10_find_phys()
649 ((r10bio->sector >= conf->reshape_progress) != in raid10_find_phys()
650 conf->mddev->reshape_backwards)) { in raid10_find_phys()
652 geo = &conf->prev; in raid10_find_phys()
659 static sector_t raid10_find_virt(struct r10conf *conf, sector_t sector, int dev) in raid10_find_virt() argument
662 /* Never use conf->prev as this is only called during resync in raid10_find_virt()
665 struct geom *geo = &conf->geo; in raid10_find_virt()
723 static struct md_rdev *read_balance(struct r10conf *conf, in read_balance() argument
737 struct geom *geo = &conf->geo; in read_balance()
739 raid10_find_phys(conf, r10_bio); in read_balance()
755 if ((conf->mddev->recovery_cp < MaxSector in read_balance()
756 && (this_sector + sectors >= conf->next_resync)) || in read_balance()
757 (mddev_is_clustered(conf->mddev) && in read_balance()
758 md_cluster_ops->area_resyncing(conf->mddev, READ, this_sector, in read_balance()
762 for (slot = 0; slot < conf->copies ; slot++) { in read_balance()
772 rdev = rcu_dereference(conf->mirrors[disk].replacement); in read_balance()
782 rdev = rcu_dereference(conf->mirrors[disk].rdev); in read_balance()
850 conf->mirrors[disk].head_position); in read_balance()
858 if (slot >= conf->copies) { in read_balance()
879 static void flush_pending_writes(struct r10conf *conf) in flush_pending_writes() argument
884 spin_lock_irq(&conf->device_lock); in flush_pending_writes()
886 if (conf->pending_bio_list.head) { in flush_pending_writes()
890 bio = bio_list_get(&conf->pending_bio_list); in flush_pending_writes()
891 spin_unlock_irq(&conf->device_lock); in flush_pending_writes()
905 raid1_prepare_flush_writes(conf->mddev->bitmap); in flush_pending_writes()
906 wake_up(&conf->wait_barrier); in flush_pending_writes()
917 spin_unlock_irq(&conf->device_lock); in flush_pending_writes()
942 static void raise_barrier(struct r10conf *conf, int force) in raise_barrier() argument
944 write_seqlock_irq(&conf->resync_lock); in raise_barrier()
946 if (WARN_ON_ONCE(force && !conf->barrier)) in raise_barrier()
950 wait_event_barrier(conf, force || !conf->nr_waiting); in raise_barrier()
953 WRITE_ONCE(conf->barrier, conf->barrier + 1); in raise_barrier()
956 wait_event_barrier(conf, !atomic_read(&conf->nr_pending) && in raise_barrier()
957 conf->barrier < RESYNC_DEPTH); in raise_barrier()
959 write_sequnlock_irq(&conf->resync_lock); in raise_barrier()
962 static void lower_barrier(struct r10conf *conf) in lower_barrier() argument
966 write_seqlock_irqsave(&conf->resync_lock, flags); in lower_barrier()
967 WRITE_ONCE(conf->barrier, conf->barrier - 1); in lower_barrier()
968 write_sequnlock_irqrestore(&conf->resync_lock, flags); in lower_barrier()
969 wake_up(&conf->wait_barrier); in lower_barrier()
972 static bool stop_waiting_barrier(struct r10conf *conf) in stop_waiting_barrier() argument
978 if (!conf->barrier) in stop_waiting_barrier()
987 if (atomic_read(&conf->nr_pending) && bio_list && in stop_waiting_barrier()
992 thread = rcu_dereference_protected(conf->mddev->thread, true); in stop_waiting_barrier()
999 WARN_ON_ONCE(atomic_read(&conf->nr_pending) == 0); in stop_waiting_barrier()
1006 static bool wait_barrier_nolock(struct r10conf *conf) in wait_barrier_nolock() argument
1008 unsigned int seq = read_seqbegin(&conf->resync_lock); in wait_barrier_nolock()
1010 if (READ_ONCE(conf->barrier)) in wait_barrier_nolock()
1013 atomic_inc(&conf->nr_pending); in wait_barrier_nolock()
1014 if (!read_seqretry(&conf->resync_lock, seq)) in wait_barrier_nolock()
1017 if (atomic_dec_and_test(&conf->nr_pending)) in wait_barrier_nolock()
1018 wake_up_barrier(conf); in wait_barrier_nolock()
1023 static bool wait_barrier(struct r10conf *conf, bool nowait) in wait_barrier() argument
1027 if (wait_barrier_nolock(conf)) in wait_barrier()
1030 write_seqlock_irq(&conf->resync_lock); in wait_barrier()
1031 if (conf->barrier) { in wait_barrier()
1036 conf->nr_waiting++; in wait_barrier()
1037 raid10_log(conf->mddev, "wait barrier"); in wait_barrier()
1038 wait_event_barrier(conf, stop_waiting_barrier(conf)); in wait_barrier()
1039 conf->nr_waiting--; in wait_barrier()
1041 if (!conf->nr_waiting) in wait_barrier()
1042 wake_up(&conf->wait_barrier); in wait_barrier()
1046 atomic_inc(&conf->nr_pending); in wait_barrier()
1047 write_sequnlock_irq(&conf->resync_lock); in wait_barrier()
1051 static void allow_barrier(struct r10conf *conf) in allow_barrier() argument
1053 if ((atomic_dec_and_test(&conf->nr_pending)) || in allow_barrier()
1054 (conf->array_freeze_pending)) in allow_barrier()
1055 wake_up_barrier(conf); in allow_barrier()
1058 static void freeze_array(struct r10conf *conf, int extra) in freeze_array() argument
1072 write_seqlock_irq(&conf->resync_lock); in freeze_array()
1073 conf->array_freeze_pending++; in freeze_array()
1074 WRITE_ONCE(conf->barrier, conf->barrier + 1); in freeze_array()
1075 conf->nr_waiting++; in freeze_array()
1076 wait_event_barrier_cmd(conf, atomic_read(&conf->nr_pending) == in freeze_array()
1077 conf->nr_queued + extra, flush_pending_writes(conf)); in freeze_array()
1078 conf->array_freeze_pending--; in freeze_array()
1079 write_sequnlock_irq(&conf->resync_lock); in freeze_array()
1082 static void unfreeze_array(struct r10conf *conf) in unfreeze_array() argument
1085 write_seqlock_irq(&conf->resync_lock); in unfreeze_array()
1086 WRITE_ONCE(conf->barrier, conf->barrier - 1); in unfreeze_array()
1087 conf->nr_waiting--; in unfreeze_array()
1088 wake_up(&conf->wait_barrier); in unfreeze_array()
1089 write_sequnlock_irq(&conf->resync_lock); in unfreeze_array()
1106 struct r10conf *conf = mddev->private; in raid10_unplug() local
1110 spin_lock_irq(&conf->device_lock); in raid10_unplug()
1111 bio_list_merge(&conf->pending_bio_list, &plug->pending); in raid10_unplug()
1112 spin_unlock_irq(&conf->device_lock); in raid10_unplug()
1113 wake_up_barrier(conf); in raid10_unplug()
1122 wake_up_barrier(conf); in raid10_unplug()
1140 static bool regular_request_wait(struct mddev *mddev, struct r10conf *conf, in regular_request_wait() argument
1144 if (!wait_barrier(conf, bio->bi_opf & REQ_NOWAIT)) { in regular_request_wait()
1149 bio->bi_iter.bi_sector < conf->reshape_progress && in regular_request_wait()
1150 bio->bi_iter.bi_sector + sectors > conf->reshape_progress) { in regular_request_wait()
1151 allow_barrier(conf); in regular_request_wait()
1156 raid10_log(conf->mddev, "wait reshape"); in regular_request_wait()
1157 wait_event(conf->wait_barrier, in regular_request_wait()
1158 conf->reshape_progress <= bio->bi_iter.bi_sector || in regular_request_wait()
1159 conf->reshape_progress >= bio->bi_iter.bi_sector + in regular_request_wait()
1161 wait_barrier(conf, false); in regular_request_wait()
1169 struct r10conf *conf = mddev->private; in raid10_read_request() local
1184 * we must use the one in conf. in raid10_read_request()
1197 err_rdev = rcu_dereference(conf->mirrors[disk].rdev); in raid10_read_request()
1208 if (!regular_request_wait(mddev, conf, bio, r10_bio->sectors)) in raid10_read_request()
1210 rdev = read_balance(conf, r10_bio, &max_sectors); in raid10_read_request()
1227 gfp, &conf->bio_split); in raid10_read_request()
1229 allow_barrier(conf); in raid10_read_request()
1231 wait_barrier(conf, false); in raid10_read_request()
1271 struct r10conf *conf = mddev->private; in raid10_write_one_disk() local
1277 rdev = conf->mirrors[devnum].replacement; in raid10_write_one_disk()
1281 rdev = conf->mirrors[devnum].rdev; in raid10_write_one_disk()
1284 rdev = conf->mirrors[devnum].rdev; in raid10_write_one_disk()
1297 &conf->mirrors[devnum].rdev->flags) in raid10_write_one_disk()
1298 && enough(conf, devnum)) in raid10_write_one_disk()
1302 if (conf->mddev->gendisk) in raid10_write_one_disk()
1303 trace_block_bio_remap(mbio, disk_devt(conf->mddev->gendisk), in raid10_write_one_disk()
1310 if (!raid1_add_bio_to_plug(mddev, mbio, raid10_unplug, conf->copies)) { in raid10_write_one_disk()
1311 spin_lock_irqsave(&conf->device_lock, flags); in raid10_write_one_disk()
1312 bio_list_add(&conf->pending_bio_list, mbio); in raid10_write_one_disk()
1313 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10_write_one_disk()
1340 struct r10conf *conf = mddev->private; in wait_blocked_dev() local
1346 for (i = 0; i < conf->copies; i++) { in wait_blocked_dev()
1349 rdev = dereference_rdev_and_rrdev(&conf->mirrors[i], &rrdev); in wait_blocked_dev()
1392 allow_barrier(conf); in wait_blocked_dev()
1393 raid10_log(conf->mddev, "%s wait rdev %d blocked", in wait_blocked_dev()
1396 wait_barrier(conf, false); in wait_blocked_dev()
1404 struct r10conf *conf = mddev->private; in raid10_write_request() local
1420 prepare_to_wait(&conf->wait_barrier, in raid10_write_request()
1427 finish_wait(&conf->wait_barrier, &w); in raid10_write_request()
1431 if (!regular_request_wait(mddev, conf, bio, sectors)) in raid10_write_request()
1435 ? (bio->bi_iter.bi_sector < conf->reshape_safe && in raid10_write_request()
1436 bio->bi_iter.bi_sector + sectors > conf->reshape_progress) in raid10_write_request()
1437 : (bio->bi_iter.bi_sector + sectors > conf->reshape_safe && in raid10_write_request()
1438 bio->bi_iter.bi_sector < conf->reshape_progress))) { in raid10_write_request()
1440 mddev->reshape_position = conf->reshape_progress; in raid10_write_request()
1445 allow_barrier(conf); in raid10_write_request()
1449 raid10_log(conf->mddev, "wait reshape metadata"); in raid10_write_request()
1453 conf->reshape_safe = mddev->reshape_position; in raid10_write_request()
1467 raid10_find_phys(conf, r10_bio); in raid10_write_request()
1474 for (i = 0; i < conf->copies; i++) { in raid10_write_request()
1478 rdev = dereference_rdev_and_rrdev(&conf->mirrors[d], &rrdev); in raid10_write_request()
1529 GFP_NOIO, &conf->bio_split); in raid10_write_request()
1531 allow_barrier(conf); in raid10_write_request()
1533 wait_barrier(conf, false); in raid10_write_request()
1542 for (i = 0; i < conf->copies; i++) { in raid10_write_request()
1553 struct r10conf *conf = mddev->private; in __make_request() local
1556 r10_bio = mempool_alloc(&conf->r10bio_pool, GFP_NOIO); in __make_request()
1566 conf->geo.raid_disks); in __make_request()
1576 struct r10conf *conf = r10bio->mddev->private; in raid_end_discard_bio() local
1581 allow_barrier(conf); in raid_end_discard_bio()
1599 struct r10conf *conf = r10_bio->mddev->private; in raid10_end_discard_request() local
1610 dev = find_bio_disk(conf, r10_bio, bio, &slot, &repl); in raid10_end_discard_request()
1612 rdev = conf->mirrors[dev].replacement; in raid10_end_discard_request()
1620 rdev = conf->mirrors[dev].rdev; in raid10_end_discard_request()
1624 rdev_dec_pending(rdev, conf->mddev); in raid10_end_discard_request()
1635 struct r10conf *conf = mddev->private; in raid10_handle_discard() local
1636 struct geom *geo = &conf->geo; in raid10_handle_discard()
1661 wait_barrier(conf, false); in raid10_handle_discard()
1698 split = bio_split(bio, split_size, GFP_NOIO, &conf->bio_split); in raid10_handle_discard()
1700 allow_barrier(conf); in raid10_handle_discard()
1703 wait_barrier(conf, false); in raid10_handle_discard()
1708 split = bio_split(bio, split_size, GFP_NOIO, &conf->bio_split); in raid10_handle_discard()
1710 allow_barrier(conf); in raid10_handle_discard()
1714 wait_barrier(conf, false); in raid10_handle_discard()
1744 r10_bio = mempool_alloc(&conf->r10bio_pool, GFP_NOIO); in raid10_handle_discard()
1775 rdev = dereference_rdev_and_rrdev(&conf->mirrors[disk], &rrdev); in raid10_handle_discard()
1835 struct md_rdev *rdev = conf->mirrors[disk].rdev; in raid10_handle_discard()
1849 struct md_rdev *rrdev = conf->mirrors[disk].replacement; in raid10_handle_discard()
1871 wait_barrier(conf, false); in raid10_handle_discard()
1879 allow_barrier(conf); in raid10_handle_discard()
1885 struct r10conf *conf = mddev->private; in raid10_make_request() local
1886 sector_t chunk_mask = (conf->geo.chunk_mask & conf->prev.chunk_mask); in raid10_make_request()
1907 && (conf->geo.near_copies < conf->geo.raid_disks in raid10_make_request()
1908 || conf->prev.near_copies < in raid10_make_request()
1909 conf->prev.raid_disks))) in raid10_make_request()
1916 wake_up_barrier(conf); in raid10_make_request()
1922 struct r10conf *conf = mddev->private; in raid10_status() local
1925 if (conf->geo.near_copies < conf->geo.raid_disks) in raid10_status()
1927 if (conf->geo.near_copies > 1) in raid10_status()
1928 seq_printf(seq, " %d near-copies", conf->geo.near_copies); in raid10_status()
1929 if (conf->geo.far_copies > 1) { in raid10_status()
1930 if (conf->geo.far_offset) in raid10_status()
1931 seq_printf(seq, " %d offset-copies", conf->geo.far_copies); in raid10_status()
1933 seq_printf(seq, " %d far-copies", conf->geo.far_copies); in raid10_status()
1934 if (conf->geo.far_set_size != conf->geo.raid_disks) in raid10_status()
1935 seq_printf(seq, " %d devices per set", conf->geo.far_set_size); in raid10_status()
1937 seq_printf(seq, " [%d/%d] [", conf->geo.raid_disks, in raid10_status()
1938 conf->geo.raid_disks - mddev->degraded); in raid10_status()
1940 for (i = 0; i < conf->geo.raid_disks; i++) { in raid10_status()
1941 struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); in raid10_status()
1953 static int _enough(struct r10conf *conf, int previous, int ignore) in _enough() argument
1959 disks = conf->prev.raid_disks; in _enough()
1960 ncopies = conf->prev.near_copies; in _enough()
1962 disks = conf->geo.raid_disks; in _enough()
1963 ncopies = conf->geo.near_copies; in _enough()
1968 int n = conf->copies; in _enough()
1974 (rdev = rcu_dereference(conf->mirrors[this].rdev)) && in _enough()
1989 static int enough(struct r10conf *conf, int ignore) in enough() argument
1996 return _enough(conf, 0, ignore) && in enough()
1997 _enough(conf, 1, ignore); in enough()
2017 struct r10conf *conf = mddev->private; in raid10_error() local
2020 spin_lock_irqsave(&conf->device_lock, flags); in raid10_error()
2022 if (test_bit(In_sync, &rdev->flags) && !enough(conf, rdev->raid_disk)) { in raid10_error()
2026 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10_error()
2038 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10_error()
2042 mdname(mddev), conf->geo.raid_disks - mddev->degraded); in raid10_error()
2045 static void print_conf(struct r10conf *conf) in print_conf() argument
2050 pr_debug("RAID10 conf printout:\n"); in print_conf()
2051 if (!conf) { in print_conf()
2052 pr_debug("(!conf)\n"); in print_conf()
2055 pr_debug(" --- wd:%d rd:%d\n", conf->geo.raid_disks - conf->mddev->degraded, in print_conf()
2056 conf->geo.raid_disks); in print_conf()
2060 for (i = 0; i < conf->geo.raid_disks; i++) { in print_conf()
2061 rdev = conf->mirrors[i].rdev; in print_conf()
2070 static void close_sync(struct r10conf *conf) in close_sync() argument
2072 wait_barrier(conf, false); in close_sync()
2073 allow_barrier(conf); in close_sync()
2075 mempool_exit(&conf->r10buf_pool); in close_sync()
2081 struct r10conf *conf = mddev->private; in raid10_spare_active() local
2090 for (i = 0; i < conf->geo.raid_disks; i++) { in raid10_spare_active()
2091 tmp = conf->mirrors + i; in raid10_spare_active()
2118 spin_lock_irqsave(&conf->device_lock, flags); in raid10_spare_active()
2120 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10_spare_active()
2122 print_conf(conf); in raid10_spare_active()
2128 struct r10conf *conf = mddev->private; in raid10_add_disk() local
2132 int last = conf->geo.raid_disks - 1; in raid10_add_disk()
2140 if (rdev->saved_raid_disk < 0 && !_enough(conf, 1, -1)) in raid10_add_disk()
2150 rdev->saved_raid_disk < conf->geo.raid_disks && in raid10_add_disk()
2151 conf->mirrors[rdev->saved_raid_disk].rdev == NULL) in raid10_add_disk()
2156 p = &conf->mirrors[mirror]; in raid10_add_disk()
2175 conf->fullsync = 1; in raid10_add_disk()
2181 p = &conf->mirrors[repl_slot]; in raid10_add_disk()
2189 conf->fullsync = 1; in raid10_add_disk()
2193 print_conf(conf); in raid10_add_disk()
2199 struct r10conf *conf = mddev->private; in raid10_remove_disk() local
2205 print_conf(conf); in raid10_remove_disk()
2208 p = conf->mirrors + number; in raid10_remove_disk()
2227 number < conf->geo.raid_disks && in raid10_remove_disk()
2228 enough(conf, -1)) { in raid10_remove_disk()
2257 print_conf(conf); in raid10_remove_disk()
2263 struct r10conf *conf = r10_bio->mddev->private; in __end_sync_read() local
2272 &conf->mirrors[d].rdev->corrected_errors); in __end_sync_read()
2277 rdev_dec_pending(conf->mirrors[d].rdev, conf->mddev); in __end_sync_read()
2290 struct r10conf *conf = r10_bio->mddev->private; in end_sync_read() local
2291 int d = find_bio_disk(conf, r10_bio, bio, NULL, NULL); in end_sync_read()
2335 struct r10conf *conf = mddev->private; in end_sync_write() local
2343 d = find_bio_disk(conf, r10_bio, bio, &slot, &repl); in end_sync_write()
2345 rdev = conf->mirrors[d].replacement; in end_sync_write()
2347 rdev = conf->mirrors[d].rdev; in end_sync_write()
2388 struct r10conf *conf = mddev->private; in sync_request_write() local
2397 for (i=0; i<conf->copies; i++) in sync_request_write()
2401 if (i == conf->copies) in sync_request_write()
2412 for (i=0 ; i < conf->copies ; i++) { in sync_request_write()
2426 rdev = conf->mirrors[d].rdev; in sync_request_write()
2460 bio_reset(tbio, conf->mirrors[d].rdev->bdev, REQ_OP_WRITE); in sync_request_write()
2471 atomic_inc(&conf->mirrors[d].rdev->nr_pending); in sync_request_write()
2473 md_sync_acct(conf->mirrors[d].rdev->bdev, bio_sectors(tbio)); in sync_request_write()
2475 if (test_bit(FailFast, &conf->mirrors[d].rdev->flags)) in sync_request_write()
2477 tbio->bi_iter.bi_sector += conf->mirrors[d].rdev->data_offset; in sync_request_write()
2484 for (i = 0; i < conf->copies; i++) { in sync_request_write()
2495 md_sync_acct(conf->mirrors[d].replacement->bdev, in sync_request_write()
2527 struct r10conf *conf = mddev->private; in fix_recovery_read_error() local
2545 rdev = conf->mirrors[dr].rdev; in fix_recovery_read_error()
2553 rdev = conf->mirrors[dw].rdev; in fix_recovery_read_error()
2575 if (rdev != conf->mirrors[dw].rdev) { in fix_recovery_read_error()
2577 struct md_rdev *rdev2 = conf->mirrors[dw].rdev; in fix_recovery_read_error()
2585 conf->mirrors[dw].recovery_disabled in fix_recovery_read_error()
2602 struct r10conf *conf = mddev->private; in recovery_request_write() local
2629 atomic_inc(&conf->mirrors[d].rdev->nr_pending); in recovery_request_write()
2630 md_sync_acct(conf->mirrors[d].rdev->bdev, bio_sectors(wbio)); in recovery_request_write()
2634 atomic_inc(&conf->mirrors[d].replacement->nr_pending); in recovery_request_write()
2635 md_sync_acct(conf->mirrors[d].replacement->bdev, in recovery_request_write()
2709 static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10bio *r10_bio) in fix_read_error() argument
2720 rdev = conf->mirrors[d].rdev; in fix_read_error()
2755 rdev = rcu_dereference(conf->mirrors[d].rdev); in fix_read_error()
2767 conf->tmppage, in fix_read_error()
2775 if (sl == conf->copies) in fix_read_error()
2786 rdev = conf->mirrors[dn].rdev; in fix_read_error()
2805 sl = conf->copies; in fix_read_error()
2808 rdev = rcu_dereference(conf->mirrors[d].rdev); in fix_read_error()
2819 s, conf->tmppage, REQ_OP_WRITE) in fix_read_error()
2839 sl = conf->copies; in fix_read_error()
2842 rdev = rcu_dereference(conf->mirrors[d].rdev); in fix_read_error()
2853 s, conf->tmppage, REQ_OP_READ)) { in fix_read_error()
2890 struct r10conf *conf = mddev->private; in narrow_write_error() local
2891 struct md_rdev *rdev = conf->mirrors[r10_bio->devs[i].devnum].rdev; in narrow_write_error()
2951 struct r10conf *conf = mddev->private; in handle_read_error() local
2969 freeze_array(conf, 1); in handle_read_error()
2970 fix_read_error(conf, mddev, r10_bio); in handle_read_error()
2971 unfreeze_array(conf); in handle_read_error()
2982 allow_barrier(conf); in handle_read_error()
2985 static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio) in handle_write_completed() argument
2998 for (m = 0; m < conf->copies; m++) { in handle_write_completed()
3000 rdev = conf->mirrors[dev].rdev; in handle_write_completed()
3014 md_error(conf->mddev, rdev); in handle_write_completed()
3016 rdev = conf->mirrors[dev].replacement; in handle_write_completed()
3031 md_error(conf->mddev, rdev); in handle_write_completed()
3037 for (m = 0; m < conf->copies; m++) { in handle_write_completed()
3040 rdev = conf->mirrors[dev].rdev; in handle_write_completed()
3046 rdev_dec_pending(rdev, conf->mddev); in handle_write_completed()
3050 md_error(conf->mddev, rdev); in handle_write_completed()
3051 rdev_dec_pending(rdev, conf->mddev); in handle_write_completed()
3054 rdev = conf->mirrors[dev].replacement; in handle_write_completed()
3060 rdev_dec_pending(rdev, conf->mddev); in handle_write_completed()
3064 spin_lock_irq(&conf->device_lock); in handle_write_completed()
3065 list_add(&r10_bio->retry_list, &conf->bio_end_io_list); in handle_write_completed()
3066 conf->nr_queued++; in handle_write_completed()
3067 spin_unlock_irq(&conf->device_lock); in handle_write_completed()
3072 wake_up(&conf->wait_barrier); in handle_write_completed()
3073 md_wakeup_thread(conf->mddev->thread); in handle_write_completed()
3088 struct r10conf *conf = mddev->private; in raid10d() local
3089 struct list_head *head = &conf->retry_list; in raid10d()
3094 if (!list_empty_careful(&conf->bio_end_io_list) && in raid10d()
3097 spin_lock_irqsave(&conf->device_lock, flags); in raid10d()
3099 while (!list_empty(&conf->bio_end_io_list)) { in raid10d()
3100 list_move(conf->bio_end_io_list.prev, &tmp); in raid10d()
3101 conf->nr_queued--; in raid10d()
3104 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10d()
3120 flush_pending_writes(conf); in raid10d()
3122 spin_lock_irqsave(&conf->device_lock, flags); in raid10d()
3124 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10d()
3129 conf->nr_queued--; in raid10d()
3130 spin_unlock_irqrestore(&conf->device_lock, flags); in raid10d()
3133 conf = mddev->private; in raid10d()
3136 handle_write_completed(conf, r10_bio); in raid10d()
3155 static int init_resync(struct r10conf *conf) in init_resync() argument
3160 BUG_ON(mempool_initialized(&conf->r10buf_pool)); in init_resync()
3161 conf->have_replacement = 0; in init_resync()
3162 for (i = 0; i < conf->geo.raid_disks; i++) in init_resync()
3163 if (conf->mirrors[i].replacement) in init_resync()
3164 conf->have_replacement = 1; in init_resync()
3165 ret = mempool_init(&conf->r10buf_pool, buffs, in init_resync()
3166 r10buf_pool_alloc, r10buf_pool_free, conf); in init_resync()
3169 conf->next_resync = 0; in init_resync()
3173 static struct r10bio *raid10_alloc_init_r10buf(struct r10conf *conf) in raid10_alloc_init_r10buf() argument
3175 struct r10bio *r10bio = mempool_alloc(&conf->r10buf_pool, GFP_NOIO); in raid10_alloc_init_r10buf()
3181 if (test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery) || in raid10_alloc_init_r10buf()
3182 test_bit(MD_RECOVERY_RESHAPE, &conf->mddev->recovery)) in raid10_alloc_init_r10buf()
3183 nalloc = conf->copies; /* resync */ in raid10_alloc_init_r10buf()
3206 static void raid10_set_cluster_sync_high(struct r10conf *conf) in raid10_set_cluster_sync_high() argument
3223 chunks = conf->geo.raid_disks / conf->geo.near_copies; in raid10_set_cluster_sync_high()
3224 if (conf->geo.raid_disks % conf->geo.near_copies == 0) in raid10_set_cluster_sync_high()
3228 window_size = (chunks + extra_chunk) * conf->mddev->chunk_sectors; in raid10_set_cluster_sync_high()
3236 conf->cluster_sync_high = conf->cluster_sync_low + window_size; in raid10_set_cluster_sync_high()
3274 struct r10conf *conf = mddev->private; in raid10_sync_request() local
3283 sector_t chunk_mask = conf->geo.chunk_mask; in raid10_sync_request()
3297 conf->fullsync == 0) { in raid10_sync_request()
3302 if (!mempool_initialized(&conf->r10buf_pool)) in raid10_sync_request()
3303 if (init_resync(conf)) in raid10_sync_request()
3312 conf->cluster_sync_low = 0; in raid10_sync_request()
3313 conf->cluster_sync_high = 0; in raid10_sync_request()
3325 end_reshape(conf); in raid10_sync_request()
3326 close_sync(conf); in raid10_sync_request()
3334 else for (i = 0; i < conf->geo.raid_disks; i++) { in raid10_sync_request()
3336 raid10_find_virt(conf, mddev->curr_resync, i); in raid10_sync_request()
3342 if ((!mddev->bitmap || conf->fullsync) in raid10_sync_request()
3343 && conf->have_replacement in raid10_sync_request()
3349 for (i = 0; i < conf->geo.raid_disks; i++) { in raid10_sync_request()
3351 rcu_dereference(conf->mirrors[i].replacement); in raid10_sync_request()
3357 conf->fullsync = 0; in raid10_sync_request()
3360 close_sync(conf); in raid10_sync_request()
3368 if (chunks_skipped >= conf->geo.raid_disks) { in raid10_sync_request()
3377 conf->mirrors[error_disk].recovery_disabled = in raid10_sync_request()
3395 if (conf->geo.near_copies < conf->geo.raid_disks && in raid10_sync_request()
3403 if (conf->nr_waiting) in raid10_sync_request()
3427 for (i = 0 ; i < conf->geo.raid_disks; i++) { in raid10_sync_request()
3433 struct raid10_info *mirror = &conf->mirrors[i]; in raid10_sync_request()
3454 sect = raid10_find_virt(conf, sector_nr, i); in raid10_sync_request()
3472 !conf->fullsync) { in raid10_sync_request()
3486 r10_bio = raid10_alloc_init_r10buf(conf); in raid10_sync_request()
3488 raise_barrier(conf, rb2 != NULL); in raid10_sync_request()
3498 raid10_find_phys(conf, r10_bio); in raid10_sync_request()
3504 for (j = 0; j < conf->geo.raid_disks; j++) { in raid10_sync_request()
3506 conf->mirrors[j].rdev); in raid10_sync_request()
3517 for (j=0; j<conf->copies;j++) { in raid10_sync_request()
3522 rcu_dereference(conf->mirrors[d].rdev); in raid10_sync_request()
3558 for (k=0; k<conf->copies; k++) in raid10_sync_request()
3561 BUG_ON(k == conf->copies); in raid10_sync_request()
3602 if (j == conf->copies) { in raid10_sync_request()
3610 for (k = 0; k < conf->copies; k++) in raid10_sync_request()
3657 for (; j < conf->copies; j++) { in raid10_sync_request()
3659 if (conf->mirrors[d].rdev && in raid10_sync_request()
3661 &conf->mirrors[d].rdev->flags)) in raid10_sync_request()
3691 (sector_nr + 2 * RESYNC_SECTORS > conf->cluster_sync_high)); in raid10_sync_request()
3695 !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, in raid10_sync_request()
3703 r10_bio = raid10_alloc_init_r10buf(conf); in raid10_sync_request()
3708 raise_barrier(conf, 0); in raid10_sync_request()
3709 conf->next_resync = sector_nr; in raid10_sync_request()
3714 raid10_find_phys(conf, r10_bio); in raid10_sync_request()
3717 for (i = 0; i < conf->copies; i++) { in raid10_sync_request()
3729 rdev = rcu_dereference(conf->mirrors[d].rdev); in raid10_sync_request()
3759 rdev = rcu_dereference(conf->mirrors[d].replacement); in raid10_sync_request()
3784 for (i=0; i<conf->copies; i++) { in raid10_sync_request()
3787 rdev_dec_pending(conf->mirrors[d].rdev, in raid10_sync_request()
3792 conf->mirrors[d].replacement, in raid10_sync_request()
3828 if (conf->cluster_sync_high < sector_nr + nr_sectors) { in raid10_sync_request()
3829 conf->cluster_sync_low = mddev->curr_resync_completed; in raid10_sync_request()
3830 raid10_set_cluster_sync_high(conf); in raid10_sync_request()
3833 conf->cluster_sync_low, in raid10_sync_request()
3834 conf->cluster_sync_high); in raid10_sync_request()
3841 for (i = 0; i < conf->geo.raid_disks; i++) { in raid10_sync_request()
3847 sect_va1 = raid10_find_virt(conf, sector_nr, i); in raid10_sync_request()
3849 if (conf->cluster_sync_high < sect_va1 + nr_sectors) { in raid10_sync_request()
3855 sect_va2 = raid10_find_virt(conf, in raid10_sync_request()
3858 if (conf->cluster_sync_low == 0 || in raid10_sync_request()
3859 conf->cluster_sync_low > sect_va2) in raid10_sync_request()
3860 conf->cluster_sync_low = sect_va2; in raid10_sync_request()
3864 raid10_set_cluster_sync_high(conf); in raid10_sync_request()
3866 conf->cluster_sync_low, in raid10_sync_request()
3867 conf->cluster_sync_high); in raid10_sync_request()
3911 struct r10conf *conf = mddev->private; in raid10_size() local
3914 raid_disks = min(conf->geo.raid_disks, in raid10_size()
3915 conf->prev.raid_disks); in raid10_size()
3917 sectors = conf->dev_sectors; in raid10_size()
3919 size = sectors >> conf->geo.chunk_shift; in raid10_size()
3920 sector_div(size, conf->geo.far_copies); in raid10_size()
3922 sector_div(size, conf->geo.near_copies); in raid10_size()
3924 return size << conf->geo.chunk_shift; in raid10_size()
3927 static void calc_sectors(struct r10conf *conf, sector_t size) in calc_sectors() argument
3930 * actually be used, and set conf->dev_sectors and in calc_sectors()
3931 * conf->stride in calc_sectors()
3934 size = size >> conf->geo.chunk_shift; in calc_sectors()
3935 sector_div(size, conf->geo.far_copies); in calc_sectors()
3936 size = size * conf->geo.raid_disks; in calc_sectors()
3937 sector_div(size, conf->geo.near_copies); in calc_sectors()
3940 size = size * conf->copies; in calc_sectors()
3945 size = DIV_ROUND_UP_SECTOR_T(size, conf->geo.raid_disks); in calc_sectors()
3947 conf->dev_sectors = size << conf->geo.chunk_shift; in calc_sectors()
3949 if (conf->geo.far_offset) in calc_sectors()
3950 conf->geo.stride = 1 << conf->geo.chunk_shift; in calc_sectors()
3952 sector_div(size, conf->geo.far_copies); in calc_sectors()
3953 conf->geo.stride = size << conf->geo.chunk_shift; in calc_sectors()
4014 static void raid10_free_conf(struct r10conf *conf) in raid10_free_conf() argument
4016 if (!conf) in raid10_free_conf()
4019 mempool_exit(&conf->r10bio_pool); in raid10_free_conf()
4020 kfree(conf->mirrors); in raid10_free_conf()
4021 kfree(conf->mirrors_old); in raid10_free_conf()
4022 kfree(conf->mirrors_new); in raid10_free_conf()
4023 safe_put_page(conf->tmppage); in raid10_free_conf()
4024 bioset_exit(&conf->bio_split); in raid10_free_conf()
4025 kfree(conf); in raid10_free_conf()
4030 struct r10conf *conf = NULL; in setup_conf() local
4050 conf = kzalloc(sizeof(struct r10conf), GFP_KERNEL); in setup_conf()
4051 if (!conf) in setup_conf()
4055 conf->mirrors = kcalloc(mddev->raid_disks + max(0, -mddev->delta_disks), in setup_conf()
4058 if (!conf->mirrors) in setup_conf()
4061 conf->tmppage = alloc_page(GFP_KERNEL); in setup_conf()
4062 if (!conf->tmppage) in setup_conf()
4065 conf->geo = geo; in setup_conf()
4066 conf->copies = copies; in setup_conf()
4067 err = mempool_init(&conf->r10bio_pool, NR_RAID_BIOS, r10bio_pool_alloc, in setup_conf()
4068 rbio_pool_free, conf); in setup_conf()
4072 err = bioset_init(&conf->bio_split, BIO_POOL_SIZE, 0, 0); in setup_conf()
4076 calc_sectors(conf, mddev->dev_sectors); in setup_conf()
4078 conf->prev = conf->geo; in setup_conf()
4079 conf->reshape_progress = MaxSector; in setup_conf()
4081 if (setup_geo(&conf->prev, mddev, geo_old) != conf->copies) { in setup_conf()
4085 conf->reshape_progress = mddev->reshape_position; in setup_conf()
4086 if (conf->prev.far_offset) in setup_conf()
4087 conf->prev.stride = 1 << conf->prev.chunk_shift; in setup_conf()
4090 conf->prev.stride = conf->dev_sectors; in setup_conf()
4092 conf->reshape_safe = conf->reshape_progress; in setup_conf()
4093 spin_lock_init(&conf->device_lock); in setup_conf()
4094 INIT_LIST_HEAD(&conf->retry_list); in setup_conf()
4095 INIT_LIST_HEAD(&conf->bio_end_io_list); in setup_conf()
4097 seqlock_init(&conf->resync_lock); in setup_conf()
4098 init_waitqueue_head(&conf->wait_barrier); in setup_conf()
4099 atomic_set(&conf->nr_pending, 0); in setup_conf()
4102 rcu_assign_pointer(conf->thread, in setup_conf()
4104 if (!conf->thread) in setup_conf()
4107 conf->mddev = mddev; in setup_conf()
4108 return conf; in setup_conf()
4111 raid10_free_conf(conf); in setup_conf()
4115 static void raid10_set_io_opt(struct r10conf *conf) in raid10_set_io_opt() argument
4117 int raid_disks = conf->geo.raid_disks; in raid10_set_io_opt()
4119 if (!(conf->geo.raid_disks % conf->geo.near_copies)) in raid10_set_io_opt()
4120 raid_disks /= conf->geo.near_copies; in raid10_set_io_opt()
4121 blk_queue_io_opt(conf->mddev->queue, (conf->mddev->chunk_sectors << 9) * in raid10_set_io_opt()
4127 struct r10conf *conf; in raid10_run() local
4139 conf = setup_conf(mddev); in raid10_run()
4140 if (IS_ERR(conf)) in raid10_run()
4141 return PTR_ERR(conf); in raid10_run()
4142 mddev->private = conf; in raid10_run()
4144 conf = mddev->private; in raid10_run()
4145 if (!conf) in raid10_run()
4148 rcu_assign_pointer(mddev->thread, conf->thread); in raid10_run()
4149 rcu_assign_pointer(conf->thread, NULL); in raid10_run()
4151 if (mddev_is_clustered(conf->mddev)) { in raid10_run()
4166 raid10_set_io_opt(conf); in raid10_run()
4175 if (disk_idx >= conf->geo.raid_disks && in raid10_run()
4176 disk_idx >= conf->prev.raid_disks) in raid10_run()
4178 disk = conf->mirrors + disk_idx; in raid10_run()
4206 if (!enough(conf, -1)) { in raid10_run()
4212 if (conf->reshape_progress != MaxSector) { in raid10_run()
4214 if (conf->geo.far_copies != 1 && in raid10_run()
4215 conf->geo.far_offset == 0) in raid10_run()
4217 if (conf->prev.far_copies != 1 && in raid10_run()
4218 conf->prev.far_offset == 0) in raid10_run()
4224 i < conf->geo.raid_disks in raid10_run()
4225 || i < conf->prev.raid_disks; in raid10_run()
4228 disk = conf->mirrors + i; in raid10_run()
4243 conf->fullsync = 1; in raid10_run()
4249 conf->fullsync = 1; in raid10_run()
4259 mdname(mddev), conf->geo.raid_disks - mddev->degraded, in raid10_run()
4260 conf->geo.raid_disks); in raid10_run()
4264 mddev->dev_sectors = conf->dev_sectors; in raid10_run()
4273 if (conf->reshape_progress != MaxSector) { in raid10_run()
4276 before_length = ((1 << conf->prev.chunk_shift) * in raid10_run()
4277 conf->prev.far_copies); in raid10_run()
4278 after_length = ((1 << conf->geo.chunk_shift) * in raid10_run()
4279 conf->geo.far_copies); in raid10_run()
4286 conf->offset_diff = min_offset_diff; in raid10_run()
4302 raid10_free_conf(conf); in raid10_run()
4315 struct r10conf *conf = mddev->private; in raid10_quiesce() local
4318 raise_barrier(conf, 0); in raid10_quiesce()
4320 lower_barrier(conf); in raid10_quiesce()
4337 struct r10conf *conf = mddev->private; in raid10_resize() local
4343 if (conf->geo.far_copies > 1 && !conf->geo.far_offset) in raid10_resize()
4362 calc_sectors(conf, sectors); in raid10_resize()
4363 mddev->dev_sectors = conf->dev_sectors; in raid10_resize()
4371 struct r10conf *conf; in raid10_takeover_raid0() local
4391 conf = setup_conf(mddev); in raid10_takeover_raid0()
4392 if (!IS_ERR(conf)) { in raid10_takeover_raid0()
4400 return conf; in raid10_takeover_raid0()
4441 struct r10conf *conf = mddev->private; in raid10_check_reshape() local
4444 if (conf->geo.far_copies != 1 && !conf->geo.far_offset) in raid10_check_reshape()
4447 if (setup_geo(&geo, mddev, geo_start) != conf->copies) in raid10_check_reshape()
4458 if (!enough(conf, -1)) in raid10_check_reshape()
4461 kfree(conf->mirrors_new); in raid10_check_reshape()
4462 conf->mirrors_new = NULL; in raid10_check_reshape()
4465 conf->mirrors_new = in raid10_check_reshape()
4469 if (!conf->mirrors_new) in raid10_check_reshape()
4488 static int calc_degraded(struct r10conf *conf) in calc_degraded() argument
4496 for (i = 0; i < conf->prev.raid_disks; i++) { in calc_degraded()
4497 struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); in calc_degraded()
4508 if (conf->geo.raid_disks == conf->prev.raid_disks) in calc_degraded()
4512 for (i = 0; i < conf->geo.raid_disks; i++) { in calc_degraded()
4513 struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); in calc_degraded()
4522 if (conf->geo.raid_disks <= conf->prev.raid_disks) in calc_degraded()
4548 struct r10conf *conf = mddev->private; in raid10_start_reshape() local
4556 if (setup_geo(&new, mddev, geo_start) != conf->copies) in raid10_start_reshape()
4559 before_length = ((1 << conf->prev.chunk_shift) * in raid10_start_reshape()
4560 conf->prev.far_copies); in raid10_start_reshape()
4561 after_length = ((1 << conf->geo.chunk_shift) * in raid10_start_reshape()
4562 conf->geo.far_copies); in raid10_start_reshape()
4587 conf->offset_diff = min_offset_diff; in raid10_start_reshape()
4588 spin_lock_irq(&conf->device_lock); in raid10_start_reshape()
4589 if (conf->mirrors_new) { in raid10_start_reshape()
4590 memcpy(conf->mirrors_new, conf->mirrors, in raid10_start_reshape()
4591 sizeof(struct raid10_info)*conf->prev.raid_disks); in raid10_start_reshape()
4593 kfree(conf->mirrors_old); in raid10_start_reshape()
4594 conf->mirrors_old = conf->mirrors; in raid10_start_reshape()
4595 conf->mirrors = conf->mirrors_new; in raid10_start_reshape()
4596 conf->mirrors_new = NULL; in raid10_start_reshape()
4598 setup_geo(&conf->geo, mddev, geo_start); in raid10_start_reshape()
4603 spin_unlock_irq(&conf->device_lock); in raid10_start_reshape()
4609 conf->reshape_progress = size; in raid10_start_reshape()
4611 conf->reshape_progress = 0; in raid10_start_reshape()
4612 conf->reshape_safe = conf->reshape_progress; in raid10_start_reshape()
4613 spin_unlock_irq(&conf->device_lock); in raid10_start_reshape()
4620 newsize = raid10_size(mddev, 0, conf->geo.raid_disks); in raid10_start_reshape()
4662 conf->prev.raid_disks) in raid10_start_reshape()
4670 } else if (rdev->raid_disk >= conf->prev.raid_disks in raid10_start_reshape()
4680 spin_lock_irq(&conf->device_lock); in raid10_start_reshape()
4681 mddev->degraded = calc_degraded(conf); in raid10_start_reshape()
4682 spin_unlock_irq(&conf->device_lock); in raid10_start_reshape()
4683 mddev->raid_disks = conf->geo.raid_disks; in raid10_start_reshape()
4684 mddev->reshape_position = conf->reshape_progress; in raid10_start_reshape()
4699 conf->reshape_checkpoint = jiffies; in raid10_start_reshape()
4706 spin_lock_irq(&conf->device_lock); in raid10_start_reshape()
4707 conf->geo = conf->prev; in raid10_start_reshape()
4708 mddev->raid_disks = conf->geo.raid_disks; in raid10_start_reshape()
4712 conf->reshape_progress = MaxSector; in raid10_start_reshape()
4713 conf->reshape_safe = MaxSector; in raid10_start_reshape()
4715 spin_unlock_irq(&conf->device_lock); in raid10_start_reshape()
4780 * (conf->offset_diff - always positive) allows a bit of slack, in reshape_request()
4790 struct r10conf *conf = mddev->private; in reshape_request() local
4806 conf->reshape_progress < raid10_size(mddev, 0, 0)) { in reshape_request()
4808 - conf->reshape_progress); in reshape_request()
4810 conf->reshape_progress > 0) in reshape_request()
4811 sector_nr = conf->reshape_progress; in reshape_request()
4828 next = first_dev_address(conf->reshape_progress - 1, in reshape_request()
4829 &conf->geo); in reshape_request()
4834 safe = last_dev_address(conf->reshape_safe - 1, in reshape_request()
4835 &conf->prev); in reshape_request()
4837 if (next + conf->offset_diff < safe) in reshape_request()
4840 last = conf->reshape_progress - 1; in reshape_request()
4841 sector_nr = last & ~(sector_t)(conf->geo.chunk_mask in reshape_request()
4842 & conf->prev.chunk_mask); in reshape_request()
4849 next = last_dev_address(conf->reshape_progress, &conf->geo); in reshape_request()
4854 safe = first_dev_address(conf->reshape_safe, &conf->prev); in reshape_request()
4859 if (next > safe + conf->offset_diff) in reshape_request()
4862 sector_nr = conf->reshape_progress; in reshape_request()
4863 last = sector_nr | (conf->geo.chunk_mask in reshape_request()
4864 & conf->prev.chunk_mask); in reshape_request()
4871 time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { in reshape_request()
4873 wait_barrier(conf, false); in reshape_request()
4874 mddev->reshape_position = conf->reshape_progress; in reshape_request()
4877 - conf->reshape_progress; in reshape_request()
4879 mddev->curr_resync_completed = conf->reshape_progress; in reshape_request()
4880 conf->reshape_checkpoint = jiffies; in reshape_request()
4886 allow_barrier(conf); in reshape_request()
4889 conf->reshape_safe = mddev->reshape_position; in reshape_request()
4890 allow_barrier(conf); in reshape_request()
4893 raise_barrier(conf, 0); in reshape_request()
4896 r10_bio = raid10_alloc_init_r10buf(conf); in reshape_request()
4898 raise_barrier(conf, 1); in reshape_request()
4904 rdev = read_balance(conf, r10_bio, &max_sectors); in reshape_request()
4912 mempool_free(r10_bio, &conf->r10buf_pool); in reshape_request()
4930 if (mddev_is_clustered(mddev) && conf->cluster_sync_high <= sector_nr) { in reshape_request()
4934 conf->cluster_sync_low = sector_nr; in reshape_request()
4935 conf->cluster_sync_high = sector_nr + CLUSTER_RESYNC_WINDOW_SECTORS; in reshape_request()
4944 if (sb_reshape_pos < conf->cluster_sync_low) in reshape_request()
4945 conf->cluster_sync_low = sb_reshape_pos; in reshape_request()
4948 md_cluster_ops->resync_info_update(mddev, conf->cluster_sync_low, in reshape_request()
4949 conf->cluster_sync_high); in reshape_request()
4953 __raid10_find_phys(&conf->geo, r10_bio); in reshape_request()
4959 for (s = 0; s < conf->copies*2; s++) { in reshape_request()
4964 rdev2 = rcu_dereference(conf->mirrors[d].replacement); in reshape_request()
4967 rdev2 = rcu_dereference(conf->mirrors[d].rdev); in reshape_request()
5013 lower_barrier(conf); in reshape_request()
5019 conf->reshape_progress -= sectors_done; in reshape_request()
5021 conf->reshape_progress += sectors_done; in reshape_request()
5036 struct r10conf *conf = mddev->private; in reshape_request_write() local
5050 for (s = 0; s < conf->copies*2; s++) { in reshape_request_write()
5056 rdev = rcu_dereference(conf->mirrors[d].replacement); in reshape_request_write()
5059 rdev = rcu_dereference(conf->mirrors[d].rdev); in reshape_request_write()
5076 static void end_reshape(struct r10conf *conf) in end_reshape() argument
5078 if (test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) in end_reshape()
5081 spin_lock_irq(&conf->device_lock); in end_reshape()
5082 conf->prev = conf->geo; in end_reshape()
5083 md_finish_reshape(conf->mddev); in end_reshape()
5085 conf->reshape_progress = MaxSector; in end_reshape()
5086 conf->reshape_safe = MaxSector; in end_reshape()
5087 spin_unlock_irq(&conf->device_lock); in end_reshape()
5089 if (conf->mddev->queue) in end_reshape()
5090 raid10_set_io_opt(conf); in end_reshape()
5091 conf->fullsync = 0; in end_reshape()
5096 struct r10conf *conf = mddev->private; in raid10_update_reshape_pos() local
5102 conf->reshape_progress = mddev->reshape_position; in raid10_update_reshape_pos()
5112 struct r10conf *conf = mddev->private; in handle_reshape_read_error() local
5118 r10b = kmalloc(struct_size(r10b, devs, conf->copies), GFP_NOIO); in handle_reshape_read_error()
5128 __raid10_find_phys(&conf->prev, r10b); in handle_reshape_read_error()
5141 struct md_rdev *rdev = rcu_dereference(conf->mirrors[d].rdev); in handle_reshape_read_error()
5162 if (slot >= conf->copies) in handle_reshape_read_error()
5186 struct r10conf *conf = mddev->private; in end_reshape_write() local
5192 d = find_bio_disk(conf, r10_bio, bio, &slot, &repl); in end_reshape_write()
5194 rdev = conf->mirrors[d].replacement; in end_reshape_write()
5197 rdev = conf->mirrors[d].rdev; in end_reshape_write()
5220 struct r10conf *conf = mddev->private; in raid10_finish_reshape() local
5234 for (d = conf->geo.raid_disks ; in raid10_finish_reshape()
5235 d < conf->geo.raid_disks - mddev->delta_disks; in raid10_finish_reshape()
5237 struct md_rdev *rdev = rcu_dereference(conf->mirrors[d].rdev); in raid10_finish_reshape()
5240 rdev = rcu_dereference(conf->mirrors[d].replacement); in raid10_finish_reshape()
5247 mddev->chunk_sectors = 1 << conf->geo.chunk_shift; in raid10_finish_reshape()