Lines Matching full:ms

46 	struct mirror_set *ms;  member
94 struct mirror_set *ms = context; in wakeup_mirrord() local
96 queue_work(ms->kmirrord_wq, &ms->kmirrord_work); in wakeup_mirrord()
101 struct mirror_set *ms = from_timer(ms, t, timer); in delayed_wake_fn() local
103 clear_bit(0, &ms->timer_pending); in delayed_wake_fn()
104 wakeup_mirrord(ms); in delayed_wake_fn()
107 static void delayed_wake(struct mirror_set *ms) in delayed_wake() argument
109 if (test_and_set_bit(0, &ms->timer_pending)) in delayed_wake()
112 ms->timer.expires = jiffies + HZ / 5; in delayed_wake()
113 add_timer(&ms->timer); in delayed_wake()
121 static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw) in queue_bio() argument
127 bl = (rw == WRITE) ? &ms->writes : &ms->reads; in queue_bio()
128 spin_lock_irqsave(&ms->lock, flags); in queue_bio()
131 spin_unlock_irqrestore(&ms->lock, flags); in queue_bio()
134 wakeup_mirrord(ms); in queue_bio()
139 struct mirror_set *ms = context; in dispatch_bios() local
143 queue_bio(ms, bio, WRITE); in dispatch_bios()
173 static struct mirror *get_default_mirror(struct mirror_set *ms) in get_default_mirror() argument
175 return &ms->mirror[atomic_read(&ms->default_mirror)]; in get_default_mirror()
180 struct mirror_set *ms = m->ms; in set_default_mirror() local
181 struct mirror *m0 = &(ms->mirror[0]); in set_default_mirror()
183 atomic_set(&ms->default_mirror, m - m0); in set_default_mirror()
186 static struct mirror *get_valid_mirror(struct mirror_set *ms) in get_valid_mirror() argument
190 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++) in get_valid_mirror()
213 struct mirror_set *ms = m->ms; in fail_mirror() local
216 ms->leg_failure = 1; in fail_mirror()
228 if (!errors_handled(ms)) in fail_mirror()
231 if (m != get_default_mirror(ms)) in fail_mirror()
234 if (!ms->in_sync && !keep_log(ms)) { in fail_mirror()
244 new = get_valid_mirror(ms); in fail_mirror()
251 schedule_work(&ms->trigger_event); in fail_mirror()
256 struct mirror_set *ms = ti->private; in mirror_flush() local
266 .client = ms->io_client, in mirror_flush()
269 for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++) { in mirror_flush()
276 dm_io(&io_req, ms->nr_mirrors, io, &error_bits); in mirror_flush()
278 for (i = 0; i < ms->nr_mirrors; i++) in mirror_flush()
280 fail_mirror(ms->mirror + i, in mirror_flush()
299 struct mirror_set *ms = dm_rh_region_context(reg); in recovery_complete() local
305 fail_mirror(get_default_mirror(ms), DM_RAID1_SYNC_ERROR); in recovery_complete()
315 for (m = 0; m < ms->nr_mirrors; m++) { in recovery_complete()
316 if (&ms->mirror[m] == get_default_mirror(ms)) in recovery_complete()
319 fail_mirror(ms->mirror + m, in recovery_complete()
328 static void recover(struct mirror_set *ms, struct dm_region *reg) in recover() argument
335 sector_t region_size = dm_rh_get_region_size(ms->rh); in recover()
338 m = get_default_mirror(ms); in recover()
340 from.sector = m->offset + dm_rh_region_to_sector(ms->rh, key); in recover()
341 if (key == (ms->nr_regions - 1)) { in recover()
346 from.count = ms->ti->len & (region_size - 1); in recover()
353 for (i = 0, dest = to; i < ms->nr_mirrors; i++) { in recover()
354 if (&ms->mirror[i] == get_default_mirror(ms)) in recover()
357 m = ms->mirror + i; in recover()
359 dest->sector = m->offset + dm_rh_region_to_sector(ms->rh, key); in recover()
365 if (!errors_handled(ms)) in recover()
368 dm_kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to, in recover()
372 static void reset_ms_flags(struct mirror_set *ms) in reset_ms_flags() argument
376 ms->leg_failure = 0; in reset_ms_flags()
377 for (m = 0; m < ms->nr_mirrors; m++) { in reset_ms_flags()
378 atomic_set(&(ms->mirror[m].error_count), 0); in reset_ms_flags()
379 ms->mirror[m].error_type = 0; in reset_ms_flags()
383 static void do_recovery(struct mirror_set *ms) in do_recovery() argument
386 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in do_recovery()
391 dm_rh_recovery_prepare(ms->rh); in do_recovery()
396 while ((reg = dm_rh_recovery_start(ms->rh))) in do_recovery()
397 recover(ms, reg); in do_recovery()
402 if (!ms->in_sync && in do_recovery()
403 (log->type->get_sync_count(log) == ms->nr_regions)) { in do_recovery()
405 dm_table_event(ms->ti->table); in do_recovery()
406 ms->in_sync = 1; in do_recovery()
407 reset_ms_flags(ms); in do_recovery()
414 static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector) in choose_mirror() argument
416 struct mirror *m = get_default_mirror(ms); in choose_mirror()
422 if (m-- == ms->mirror) in choose_mirror()
423 m += ms->nr_mirrors; in choose_mirror()
424 } while (m != get_default_mirror(ms)); in choose_mirror()
431 struct mirror *default_mirror = get_default_mirror(m->ms); in default_ok()
436 static int mirror_available(struct mirror_set *ms, struct bio *bio) in mirror_available() argument
438 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_available()
439 region_t region = dm_rh_bio_to_region(ms->rh, bio); in mirror_available()
442 return choose_mirror(ms, bio->bi_iter.bi_sector) ? 1 : 0; in mirror_available()
454 return m->offset + dm_target_offset(m->ms->ti, bio->bi_iter.bi_sector); in map_sector()
471 static void hold_bio(struct mirror_set *ms, struct bio *bio) in hold_bio() argument
477 spin_lock_irq(&ms->lock); in hold_bio()
479 if (atomic_read(&ms->suspend)) { in hold_bio()
480 spin_unlock_irq(&ms->lock); in hold_bio()
485 if (dm_noflush_suspending(ms->ti)) in hold_bio()
497 bio_list_add(&ms->holds, bio); in hold_bio()
498 spin_unlock_irq(&ms->lock); in hold_bio()
519 if (likely(default_ok(m)) || mirror_available(m->ms, bio)) { in read_callback()
523 queue_bio(m->ms, bio, bio_data_dir(bio)); in read_callback()
542 .client = m->ms->io_client, in read_async_bio()
550 static inline int region_in_sync(struct mirror_set *ms, region_t region, in region_in_sync() argument
553 int state = dm_rh_get_state(ms->rh, region, may_block); in region_in_sync()
557 static void do_reads(struct mirror_set *ms, struct bio_list *reads) in do_reads() argument
564 region = dm_rh_bio_to_region(ms->rh, bio); in do_reads()
565 m = get_default_mirror(ms); in do_reads()
570 if (likely(region_in_sync(ms, region, 1))) in do_reads()
571 m = choose_mirror(ms, bio->bi_iter.bi_sector); in do_reads()
598 struct mirror_set *ms; in write_callback() local
602 ms = bio_get_m(bio)->ms; in write_callback()
626 for (i = 0; i < ms->nr_mirrors; i++) in write_callback()
628 fail_mirror(ms->mirror + i, DM_RAID1_WRITE_ERROR); in write_callback()
635 spin_lock_irqsave(&ms->lock, flags); in write_callback()
636 if (!ms->failures.head) in write_callback()
638 bio_list_add(&ms->failures, bio); in write_callback()
639 spin_unlock_irqrestore(&ms->lock, flags); in write_callback()
641 wakeup_mirrord(ms); in write_callback()
644 static void do_write(struct mirror_set *ms, struct bio *bio) in do_write() argument
656 .client = ms->io_client, in do_write()
665 for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++) in do_write()
672 bio_set_m(bio, get_default_mirror(ms)); in do_write()
674 BUG_ON(dm_io(&io_req, ms->nr_mirrors, io, NULL)); in do_write()
677 static void do_writes(struct mirror_set *ms, struct bio_list *writes) in do_writes() argument
683 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in do_writes()
704 region = dm_rh_bio_to_region(ms->rh, bio); in do_writes()
712 state = dm_rh_get_state(ms->rh, region, 1); in do_writes()
736 spin_lock_irq(&ms->lock); in do_writes()
737 bio_list_merge(&ms->writes, &requeue); in do_writes()
738 spin_unlock_irq(&ms->lock); in do_writes()
739 delayed_wake(ms); in do_writes()
747 dm_rh_inc_pending(ms->rh, &sync); in do_writes()
748 dm_rh_inc_pending(ms->rh, &nosync); in do_writes()
755 ms->log_failure = dm_rh_flush(ms->rh) ? 1 : ms->log_failure; in do_writes()
760 if (unlikely(ms->log_failure) && errors_handled(ms)) { in do_writes()
761 spin_lock_irq(&ms->lock); in do_writes()
762 bio_list_merge(&ms->failures, &sync); in do_writes()
763 spin_unlock_irq(&ms->lock); in do_writes()
764 wakeup_mirrord(ms); in do_writes()
767 do_write(ms, bio); in do_writes()
770 dm_rh_delay(ms->rh, bio); in do_writes()
773 if (unlikely(ms->leg_failure) && errors_handled(ms) && !keep_log(ms)) { in do_writes()
774 spin_lock_irq(&ms->lock); in do_writes()
775 bio_list_add(&ms->failures, bio); in do_writes()
776 spin_unlock_irq(&ms->lock); in do_writes()
777 wakeup_mirrord(ms); in do_writes()
779 map_bio(get_default_mirror(ms), bio); in do_writes()
785 static void do_failures(struct mirror_set *ms, struct bio_list *failures) in do_failures() argument
810 if (!ms->log_failure) { in do_failures()
811 ms->in_sync = 0; in do_failures()
812 dm_rh_mark_nosync(ms->rh, bio); in do_failures()
828 if (unlikely(!get_valid_mirror(ms) || (keep_log(ms) && ms->log_failure))) in do_failures()
830 else if (errors_handled(ms) && !keep_log(ms)) in do_failures()
831 hold_bio(ms, bio); in do_failures()
839 struct mirror_set *ms = in trigger_event() local
842 dm_table_event(ms->ti->table); in trigger_event()
850 struct mirror_set *ms = container_of(work, struct mirror_set, in do_mirror() local
855 spin_lock_irqsave(&ms->lock, flags); in do_mirror()
856 reads = ms->reads; in do_mirror()
857 writes = ms->writes; in do_mirror()
858 failures = ms->failures; in do_mirror()
859 bio_list_init(&ms->reads); in do_mirror()
860 bio_list_init(&ms->writes); in do_mirror()
861 bio_list_init(&ms->failures); in do_mirror()
862 spin_unlock_irqrestore(&ms->lock, flags); in do_mirror()
864 dm_rh_update_states(ms->rh, errors_handled(ms)); in do_mirror()
865 do_recovery(ms); in do_mirror()
866 do_reads(ms, &reads); in do_mirror()
867 do_writes(ms, &writes); in do_mirror()
868 do_failures(ms, &failures); in do_mirror()
879 struct mirror_set *ms = in alloc_context() local
880 kzalloc(struct_size(ms, mirror, nr_mirrors), GFP_KERNEL); in alloc_context()
882 if (!ms) { in alloc_context()
887 spin_lock_init(&ms->lock); in alloc_context()
888 bio_list_init(&ms->reads); in alloc_context()
889 bio_list_init(&ms->writes); in alloc_context()
890 bio_list_init(&ms->failures); in alloc_context()
891 bio_list_init(&ms->holds); in alloc_context()
893 ms->ti = ti; in alloc_context()
894 ms->nr_mirrors = nr_mirrors; in alloc_context()
895 ms->nr_regions = dm_sector_div_up(ti->len, region_size); in alloc_context()
896 ms->in_sync = 0; in alloc_context()
897 ms->log_failure = 0; in alloc_context()
898 ms->leg_failure = 0; in alloc_context()
899 atomic_set(&ms->suspend, 0); in alloc_context()
900 atomic_set(&ms->default_mirror, DEFAULT_MIRROR); in alloc_context()
902 ms->io_client = dm_io_client_create(); in alloc_context()
903 if (IS_ERR(ms->io_client)) { in alloc_context()
905 kfree(ms); in alloc_context()
909 ms->rh = dm_region_hash_create(ms, dispatch_bios, wakeup_mirrord, in alloc_context()
911 ms->ti->begin, MAX_RECOVERY, in alloc_context()
912 dl, region_size, ms->nr_regions); in alloc_context()
913 if (IS_ERR(ms->rh)) { in alloc_context()
915 dm_io_client_destroy(ms->io_client); in alloc_context()
916 kfree(ms); in alloc_context()
920 return ms; in alloc_context()
923 static void free_context(struct mirror_set *ms, struct dm_target *ti, in free_context() argument
927 dm_put_device(ti, ms->mirror[m].dev); in free_context()
929 dm_io_client_destroy(ms->io_client); in free_context()
930 dm_region_hash_destroy(ms->rh); in free_context()
931 kfree(ms); in free_context()
934 static int get_mirror(struct mirror_set *ms, struct dm_target *ti, in get_mirror() argument
948 &ms->mirror[mirror].dev); in get_mirror()
954 ms->mirror[mirror].ms = ms; in get_mirror()
955 atomic_set(&(ms->mirror[mirror].error_count), 0); in get_mirror()
956 ms->mirror[mirror].error_type = 0; in get_mirror()
957 ms->mirror[mirror].offset = offset; in get_mirror()
1000 static int parse_features(struct mirror_set *ms, unsigned argc, char **argv, in parse_features() argument
1004 struct dm_target *ti = ms->ti; in parse_features()
1029 ms->features |= DM_RAID1_HANDLE_ERRORS; in parse_features()
1031 ms->features |= DM_RAID1_KEEP_LOG; in parse_features()
1041 if (!errors_handled(ms) && keep_log(ms)) { in parse_features()
1065 struct mirror_set *ms; in mirror_ctr() local
1091 ms = alloc_context(nr_mirrors, dl->type->get_region_size(dl), ti, dl); in mirror_ctr()
1092 if (!ms) { in mirror_ctr()
1099 r = get_mirror(ms, ti, m, argv); in mirror_ctr()
1101 free_context(ms, ti, m); in mirror_ctr()
1108 ti->private = ms; in mirror_ctr()
1110 r = dm_set_target_max_io_len(ti, dm_rh_get_region_size(ms->rh)); in mirror_ctr()
1118 ms->kmirrord_wq = alloc_workqueue("kmirrord", WQ_MEM_RECLAIM, 0); in mirror_ctr()
1119 if (!ms->kmirrord_wq) { in mirror_ctr()
1124 INIT_WORK(&ms->kmirrord_work, do_mirror); in mirror_ctr()
1125 timer_setup(&ms->timer, delayed_wake_fn, 0); in mirror_ctr()
1126 ms->timer_pending = 0; in mirror_ctr()
1127 INIT_WORK(&ms->trigger_event, trigger_event); in mirror_ctr()
1129 r = parse_features(ms, argc, argv, &args_used); in mirror_ctr()
1151 ms->kcopyd_client = dm_kcopyd_client_create(&dm_kcopyd_throttle); in mirror_ctr()
1152 if (IS_ERR(ms->kcopyd_client)) { in mirror_ctr()
1153 r = PTR_ERR(ms->kcopyd_client); in mirror_ctr()
1157 wakeup_mirrord(ms); in mirror_ctr()
1161 destroy_workqueue(ms->kmirrord_wq); in mirror_ctr()
1163 free_context(ms, ti, ms->nr_mirrors); in mirror_ctr()
1169 struct mirror_set *ms = (struct mirror_set *) ti->private; in mirror_dtr() local
1171 del_timer_sync(&ms->timer); in mirror_dtr()
1172 flush_workqueue(ms->kmirrord_wq); in mirror_dtr()
1173 flush_work(&ms->trigger_event); in mirror_dtr()
1174 dm_kcopyd_client_destroy(ms->kcopyd_client); in mirror_dtr()
1175 destroy_workqueue(ms->kmirrord_wq); in mirror_dtr()
1176 free_context(ms, ti, ms->nr_mirrors); in mirror_dtr()
1186 struct mirror_set *ms = ti->private; in mirror_map() local
1187 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_map()
1195 bio_record->write_region = dm_rh_bio_to_region(ms->rh, bio); in mirror_map()
1196 queue_bio(ms, bio, rw); in mirror_map()
1200 r = log->type->in_sync(log, dm_rh_bio_to_region(ms->rh, bio), 0); in mirror_map()
1211 queue_bio(ms, bio, rw); in mirror_map()
1219 m = choose_mirror(ms, bio->bi_iter.bi_sector); in mirror_map()
1235 struct mirror_set *ms = (struct mirror_set *) ti->private; in mirror_end_io() local
1247 dm_rh_dec(ms->rh, bio_record->write_region); in mirror_end_io()
1279 if (default_ok(m) || mirror_available(ms, bio)) { in mirror_end_io()
1286 queue_bio(ms, bio, rw); in mirror_end_io()
1300 struct mirror_set *ms = (struct mirror_set *) ti->private; in mirror_presuspend() local
1301 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_presuspend()
1306 atomic_set(&ms->suspend, 1); in mirror_presuspend()
1311 * a chance to be added in the hold list because ms->suspend in mirror_presuspend()
1314 spin_lock_irq(&ms->lock); in mirror_presuspend()
1315 holds = ms->holds; in mirror_presuspend()
1316 bio_list_init(&ms->holds); in mirror_presuspend()
1317 spin_unlock_irq(&ms->lock); in mirror_presuspend()
1320 hold_bio(ms, bio); in mirror_presuspend()
1326 dm_rh_stop_recovery(ms->rh); in mirror_presuspend()
1329 !dm_rh_recovery_in_flight(ms->rh)); in mirror_presuspend()
1341 flush_workqueue(ms->kmirrord_wq); in mirror_presuspend()
1346 struct mirror_set *ms = ti->private; in mirror_postsuspend() local
1347 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_postsuspend()
1356 struct mirror_set *ms = ti->private; in mirror_resume() local
1357 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_resume()
1359 atomic_set(&ms->suspend, 0); in mirror_resume()
1363 dm_rh_start_recovery(ms->rh); in mirror_resume()
1396 struct mirror_set *ms = (struct mirror_set *) ti->private; in mirror_status() local
1397 struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); in mirror_status()
1402 DMEMIT("%d ", ms->nr_mirrors); in mirror_status()
1403 for (m = 0; m < ms->nr_mirrors; m++) { in mirror_status()
1404 DMEMIT("%s ", ms->mirror[m].dev->name); in mirror_status()
1405 buffer[m] = device_status_char(&(ms->mirror[m])); in mirror_status()
1411 (unsigned long long)ms->nr_regions, buffer); in mirror_status()
1420 DMEMIT("%d", ms->nr_mirrors); in mirror_status()
1421 for (m = 0; m < ms->nr_mirrors; m++) in mirror_status()
1422 DMEMIT(" %s %llu", ms->mirror[m].dev->name, in mirror_status()
1423 (unsigned long long)ms->mirror[m].offset); in mirror_status()
1425 num_feature_args += !!errors_handled(ms); in mirror_status()
1426 num_feature_args += !!keep_log(ms); in mirror_status()
1429 if (errors_handled(ms)) in mirror_status()
1431 if (keep_log(ms)) in mirror_status()
1439 DMEMIT(",nr_mirrors=%d", ms->nr_mirrors); in mirror_status()
1440 for (m = 0; m < ms->nr_mirrors; m++) { in mirror_status()
1441 DMEMIT(",mirror_device_%d=%s", m, ms->mirror[m].dev->name); in mirror_status()
1443 m, device_status_char(&(ms->mirror[m]))); in mirror_status()
1446 DMEMIT(",handle_errors=%c", errors_handled(ms) ? 'y' : 'n'); in mirror_status()
1447 DMEMIT(",keep_log=%c", keep_log(ms) ? 'y' : 'n'); in mirror_status()
1459 struct mirror_set *ms = ti->private; in mirror_iterate_devices() local
1463 for (i = 0; !ret && i < ms->nr_mirrors; i++) in mirror_iterate_devices()
1464 ret = fn(ti, ms->mirror[i].dev, in mirror_iterate_devices()
1465 ms->mirror[i].offset, ti->len, data); in mirror_iterate_devices()