Lines Matching +full:rs +full:-
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2010-2011 Neil Brown
4 * Copyright (C) 2010-2018 Red Hat, Inc. All rights reserved.
16 #include "md-bitmap.h"
18 #include <linux/device-mapper.h>
21 #define MAX_RAID_DEVICES 253 /* md-raid kernel limit */
36 * The following flags are used by dm-raid to set up the array state.
45 * ti->len and give more flexibility in altering size and
51 * |--------- Physical Device ---------|
52 * |- meta_dev -|------ data_dev ------|
60 * Bits for establishing rs->ctr_flags
89 * Flags for rs->ctr_flags field.
171 * that both parity and q-syndrome are being written properly with
200 * Flags for rs->runtime_flags field
219 #define DISKS_ARRAY_ELEMS ((MAX_RAID_DEVICES + (sizeof(uint64_t) * 8 - 1)) / sizeof(uint64_t) / 8)
261 static void rs_config_backup(struct raid_set *rs, struct rs_layout *l) in rs_config_backup() argument
263 struct mddev *mddev = &rs->md; in rs_config_backup()
265 l->new_level = mddev->new_level; in rs_config_backup()
266 l->new_layout = mddev->new_layout; in rs_config_backup()
267 l->new_chunk_sectors = mddev->new_chunk_sectors; in rs_config_backup()
270 static void rs_config_restore(struct raid_set *rs, struct rs_layout *l) in rs_config_restore() argument
272 struct mddev *mddev = &rs->md; in rs_config_restore()
274 mddev->new_level = l->new_level; in rs_config_restore()
275 mddev->new_layout = l->new_layout; in rs_config_restore()
276 mddev->new_chunk_sectors = l->new_chunk_sectors; in rs_config_restore()
352 while (anf-- > __arg_name_flags) in dm_raid_arg_name_by_flag()
353 if (flag & anf->flag) in dm_raid_arg_name_by_flag()
354 return anf->name; in dm_raid_arg_name_by_flag()
362 /* Define correlation of raid456 journal cache modes and dm-raid target line parameters */
376 while (m--) in dm_raid_journal_mode_to_md()
380 return -EINVAL; in dm_raid_journal_mode_to_md()
383 /* Return dm-raid raid4/5/6 journal mode string for @mode */
388 while (m--) in md_journal_mode_to_dm_raid()
400 /* Return true, if raid set in @rs is raid0 */
401 static bool rs_is_raid0(struct raid_set *rs) in rs_is_raid0() argument
403 return !rs->md.level; in rs_is_raid0()
406 /* Return true, if raid set in @rs is raid1 */
407 static bool rs_is_raid1(struct raid_set *rs) in rs_is_raid1() argument
409 return rs->md.level == 1; in rs_is_raid1()
412 /* Return true, if raid set in @rs is raid10 */
413 static bool rs_is_raid10(struct raid_set *rs) in rs_is_raid10() argument
415 return rs->md.level == 10; in rs_is_raid10()
418 /* Return true, if raid set in @rs is level 6 */
419 static bool rs_is_raid6(struct raid_set *rs) in rs_is_raid6() argument
421 return rs->md.level == 6; in rs_is_raid6()
424 /* Return true, if raid set in @rs is level 4, 5 or 6 */
425 static bool rs_is_raid456(struct raid_set *rs) in rs_is_raid456() argument
427 return __within_range(rs->md.level, 4, 6); in rs_is_raid456()
430 /* Return true, if raid set in @rs is reshapable */
432 static bool rs_is_reshapable(struct raid_set *rs) in rs_is_reshapable() argument
434 return rs_is_raid456(rs) || in rs_is_reshapable()
435 (rs_is_raid10(rs) && !__is_raid10_far(rs->md.new_layout)); in rs_is_reshapable()
438 /* Return true, if raid set in @rs is recovering */
439 static bool rs_is_recovering(struct raid_set *rs) in rs_is_recovering() argument
441 return rs->md.recovery_cp < rs->md.dev_sectors; in rs_is_recovering()
444 /* Return true, if raid set in @rs is reshaping */
445 static bool rs_is_reshaping(struct raid_set *rs) in rs_is_reshaping() argument
447 return rs->md.reshape_position != MaxSector; in rs_is_reshaping()
457 return !rt->level; in rt_is_raid0()
463 return rt->level == 1; in rt_is_raid1()
469 return rt->level == 10; in rt_is_raid10()
475 return __within_range(rt->level, 4, 5); in rt_is_raid45()
481 return rt->level == 6; in rt_is_raid6()
487 return __within_range(rt->level, 4, 6); in rt_is_raid456()
491 /* Return valid ctr flags for the raid level of @rs */
492 static unsigned long __valid_flags(struct raid_set *rs) in __valid_flags() argument
494 if (rt_is_raid0(rs->raid_type)) in __valid_flags()
496 else if (rt_is_raid1(rs->raid_type)) in __valid_flags()
498 else if (rt_is_raid10(rs->raid_type)) in __valid_flags()
500 else if (rt_is_raid45(rs->raid_type)) in __valid_flags()
502 else if (rt_is_raid6(rs->raid_type)) in __valid_flags()
509 * Check for valid flags set on @rs
513 static int rs_check_for_valid_flags(struct raid_set *rs) in rs_check_for_valid_flags() argument
515 if (rs->ctr_flags & ~__valid_flags(rs)) { in rs_check_for_valid_flags()
516 rs->ti->error = "Invalid flags combination"; in rs_check_for_valid_flags()
517 return -EINVAL; in rs_check_for_valid_flags()
590 return -EINVAL; in raid10_name_to_format()
600 static int raid10_format_to_md_layout(struct raid_set *rs, in raid10_format_to_md_layout() argument
612 * -> disable it for now in the definition above in raid10_format_to_md_layout()
621 if (!test_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) in raid10_format_to_md_layout()
626 if (!test_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) in raid10_format_to_md_layout()
630 return -EINVAL; in raid10_format_to_md_layout()
639 if (rtp->level == 10) { in __got_raid10()
640 switch (rtp->algorithm) { in __got_raid10()
661 while (rtp-- > raid_types) in get_raid_type()
662 if (!strcasecmp(rtp->name, name)) in get_raid_type()
673 while (rtp-- > raid_types) { in get_raid_type_by_ll()
675 if (rtp->level == level && in get_raid_type_by_ll()
676 (__got_raid10(rtp, layout) || rtp->algorithm == layout)) in get_raid_type_by_ll()
684 static void rs_set_rdev_sectors(struct raid_set *rs) in rs_set_rdev_sectors() argument
686 struct mddev *mddev = &rs->md; in rs_set_rdev_sectors()
690 * raid10 sets rdev->sector to the device size, which in rs_set_rdev_sectors()
691 * is unintended in case of out-of-place reshaping in rs_set_rdev_sectors()
694 if (!test_bit(Journal, &rdev->flags)) in rs_set_rdev_sectors()
695 rdev->sectors = mddev->dev_sectors; in rs_set_rdev_sectors()
699 * Change bdev capacity of @rs in case of a disk add/remove reshape
701 static void rs_set_capacity(struct raid_set *rs) in rs_set_capacity() argument
703 struct gendisk *gendisk = dm_disk(dm_table_get_md(rs->ti->table)); in rs_set_capacity()
705 set_capacity_and_notify(gendisk, rs->md.array_sectors); in rs_set_capacity()
709 * Set the mddev properties in @rs to the current
712 static void rs_set_cur(struct raid_set *rs) in rs_set_cur() argument
714 struct mddev *mddev = &rs->md; in rs_set_cur()
716 mddev->new_level = mddev->level; in rs_set_cur()
717 mddev->new_layout = mddev->layout; in rs_set_cur()
718 mddev->new_chunk_sectors = mddev->chunk_sectors; in rs_set_cur()
722 * Set the mddev properties in @rs to the new
725 static void rs_set_new(struct raid_set *rs) in rs_set_new() argument
727 struct mddev *mddev = &rs->md; in rs_set_new()
729 mddev->level = mddev->new_level; in rs_set_new()
730 mddev->layout = mddev->new_layout; in rs_set_new()
731 mddev->chunk_sectors = mddev->new_chunk_sectors; in rs_set_new()
732 mddev->raid_disks = rs->raid_disks; in rs_set_new()
733 mddev->delta_disks = 0; in rs_set_new()
740 struct raid_set *rs; in raid_set_alloc() local
742 if (raid_devs <= raid_type->parity_devs) { in raid_set_alloc()
743 ti->error = "Insufficient number of devices"; in raid_set_alloc()
744 return ERR_PTR(-EINVAL); in raid_set_alloc()
747 rs = kzalloc(struct_size(rs, dev, raid_devs), GFP_KERNEL); in raid_set_alloc()
748 if (!rs) { in raid_set_alloc()
749 ti->error = "Cannot allocate raid context"; in raid_set_alloc()
750 return ERR_PTR(-ENOMEM); in raid_set_alloc()
753 if (mddev_init(&rs->md)) { in raid_set_alloc()
754 kfree(rs); in raid_set_alloc()
755 ti->error = "Cannot initialize raid context"; in raid_set_alloc()
756 return ERR_PTR(-ENOMEM); in raid_set_alloc()
759 rs->raid_disks = raid_devs; in raid_set_alloc()
760 rs->delta_disks = 0; in raid_set_alloc()
762 rs->ti = ti; in raid_set_alloc()
763 rs->raid_type = raid_type; in raid_set_alloc()
764 rs->stripe_cache_entries = 256; in raid_set_alloc()
765 rs->md.raid_disks = raid_devs; in raid_set_alloc()
766 rs->md.level = raid_type->level; in raid_set_alloc()
767 rs->md.new_level = rs->md.level; in raid_set_alloc()
768 rs->md.layout = raid_type->algorithm; in raid_set_alloc()
769 rs->md.new_layout = rs->md.layout; in raid_set_alloc()
770 rs->md.delta_disks = 0; in raid_set_alloc()
771 rs->md.recovery_cp = MaxSector; in raid_set_alloc()
774 md_rdev_init(&rs->dev[i].rdev); in raid_set_alloc()
778 * rs->md.persistent in raid_set_alloc()
779 * rs->md.external in raid_set_alloc()
780 * rs->md.chunk_sectors in raid_set_alloc()
781 * rs->md.new_chunk_sectors in raid_set_alloc()
782 * rs->md.dev_sectors in raid_set_alloc()
785 return rs; in raid_set_alloc()
788 /* Free all @rs allocations */
789 static void raid_set_free(struct raid_set *rs) in raid_set_free() argument
793 if (rs->journal_dev.dev) { in raid_set_free()
794 md_rdev_clear(&rs->journal_dev.rdev); in raid_set_free()
795 dm_put_device(rs->ti, rs->journal_dev.dev); in raid_set_free()
798 for (i = 0; i < rs->raid_disks; i++) { in raid_set_free()
799 if (rs->dev[i].meta_dev) in raid_set_free()
800 dm_put_device(rs->ti, rs->dev[i].meta_dev); in raid_set_free()
801 md_rdev_clear(&rs->dev[i].rdev); in raid_set_free()
802 if (rs->dev[i].data_dev) in raid_set_free()
803 dm_put_device(rs->ti, rs->dev[i].data_dev); in raid_set_free()
806 mddev_destroy(&rs->md); in raid_set_free()
807 kfree(rs); in raid_set_free()
812 * <meta_dev>: meta device name or '-' if missing
813 * <data_dev>: data device name or '-' if missing
816 * - -
817 * - <data_dev>
821 * <meta_dev> -
826 static int parse_dev_params(struct raid_set *rs, struct dm_arg_set *as) in parse_dev_params() argument
837 return -EINVAL; in parse_dev_params()
839 for (i = 0; i < rs->raid_disks; i++) { in parse_dev_params()
840 rs->dev[i].rdev.raid_disk = i; in parse_dev_params()
842 rs->dev[i].meta_dev = NULL; in parse_dev_params()
843 rs->dev[i].data_dev = NULL; in parse_dev_params()
849 rs->dev[i].rdev.data_offset = 0; in parse_dev_params()
850 rs->dev[i].rdev.new_data_offset = 0; in parse_dev_params()
851 rs->dev[i].rdev.mddev = &rs->md; in parse_dev_params()
855 return -EINVAL; in parse_dev_params()
857 if (strcmp(arg, "-")) { in parse_dev_params()
858 r = dm_get_device(rs->ti, arg, dm_table_get_mode(rs->ti->table), in parse_dev_params()
859 &rs->dev[i].meta_dev); in parse_dev_params()
861 rs->ti->error = "RAID metadata device lookup failure"; in parse_dev_params()
865 rs->dev[i].rdev.sb_page = alloc_page(GFP_KERNEL); in parse_dev_params()
866 if (!rs->dev[i].rdev.sb_page) { in parse_dev_params()
867 rs->ti->error = "Failed to allocate superblock page"; in parse_dev_params()
868 return -ENOMEM; in parse_dev_params()
874 return -EINVAL; in parse_dev_params()
876 if (!strcmp(arg, "-")) { in parse_dev_params()
877 if (!test_bit(In_sync, &rs->dev[i].rdev.flags) && in parse_dev_params()
878 (!rs->dev[i].rdev.recovery_offset)) { in parse_dev_params()
879 rs->ti->error = "Drive designated for rebuild not specified"; in parse_dev_params()
880 return -EINVAL; in parse_dev_params()
883 if (rs->dev[i].meta_dev) { in parse_dev_params()
884 rs->ti->error = "No data device supplied with metadata device"; in parse_dev_params()
885 return -EINVAL; in parse_dev_params()
891 r = dm_get_device(rs->ti, arg, dm_table_get_mode(rs->ti->table), in parse_dev_params()
892 &rs->dev[i].data_dev); in parse_dev_params()
894 rs->ti->error = "RAID device lookup failure"; in parse_dev_params()
898 if (rs->dev[i].meta_dev) { in parse_dev_params()
900 rs->dev[i].rdev.meta_bdev = rs->dev[i].meta_dev->bdev; in parse_dev_params()
902 rs->dev[i].rdev.bdev = rs->dev[i].data_dev->bdev; in parse_dev_params()
903 list_add_tail(&rs->dev[i].rdev.same_set, &rs->md.disks); in parse_dev_params()
904 if (!test_bit(In_sync, &rs->dev[i].rdev.flags)) in parse_dev_params()
908 if (rs->journal_dev.dev) in parse_dev_params()
909 list_add_tail(&rs->journal_dev.rdev.same_set, &rs->md.disks); in parse_dev_params()
912 rs->md.external = 0; in parse_dev_params()
913 rs->md.persistent = 1; in parse_dev_params()
914 rs->md.major_version = 2; in parse_dev_params()
915 } else if (rebuild && !rs->md.recovery_cp) { in parse_dev_params()
918 * is in-sync or not - we must assume it is not. Therefore, in parse_dev_params()
921 * Even if there is metadata, the on-disk information may in parse_dev_params()
922 * indicate that the array is not in-sync and it will then in parse_dev_params()
927 rs->ti->error = "Unable to rebuild drive while array is not in-sync"; in parse_dev_params()
928 return -EINVAL; in parse_dev_params()
936 * @rs
939 * Set rs->md.bitmap_info.chunksize (which really refers to 'region size').
940 * Ensure that (ti->len/region_size < 2^21) - required by MD bitmap.
942 * Returns: 0 on success, -EINVAL on failure.
944 static int validate_region_size(struct raid_set *rs, unsigned long region_size) in validate_region_size() argument
946 unsigned long min_region_size = rs->ti->len / (1 << 21); in validate_region_size()
948 if (rs_is_raid0(rs)) in validate_region_size()
966 * Validate user-supplied value. in validate_region_size()
968 if (region_size > rs->ti->len) { in validate_region_size()
969 rs->ti->error = "Supplied region size is too large"; in validate_region_size()
970 return -EINVAL; in validate_region_size()
976 rs->ti->error = "Supplied region size is too small"; in validate_region_size()
977 return -EINVAL; in validate_region_size()
981 rs->ti->error = "Region size is not a power of 2"; in validate_region_size()
982 return -EINVAL; in validate_region_size()
985 if (region_size < rs->md.chunk_sectors) { in validate_region_size()
986 rs->ti->error = "Region size is smaller than the chunk size"; in validate_region_size()
987 return -EINVAL; in validate_region_size()
994 rs->md.bitmap_info.chunksize = to_bytes(region_size); in validate_region_size()
1001 * @rs
1006 * Returns: 0 on success, -EINVAL on failure.
1008 static int validate_raid_redundancy(struct raid_set *rs) in validate_raid_redundancy() argument
1014 for (i = 0; i < rs->raid_disks; i++) in validate_raid_redundancy()
1015 if (!test_bit(FirstUse, &rs->dev[i].rdev.flags) && in validate_raid_redundancy()
1016 ((!test_bit(In_sync, &rs->dev[i].rdev.flags) || in validate_raid_redundancy()
1017 !rs->dev[i].rdev.sb_page))) in validate_raid_redundancy()
1020 switch (rs->md.level) { in validate_raid_redundancy()
1024 if (rebuild_cnt >= rs->md.raid_disks) in validate_raid_redundancy()
1030 if (rebuild_cnt > rs->raid_type->parity_devs) in validate_raid_redundancy()
1034 copies = raid10_md_layout_to_copies(rs->md.new_layout); in validate_raid_redundancy()
1037 return -EINVAL; in validate_raid_redundancy()
1057 raid_disks = min(rs->raid_disks, rs->md.raid_disks); in validate_raid_redundancy()
1058 if (__is_raid10_near(rs->md.new_layout)) { in validate_raid_redundancy()
1062 if ((!rs->dev[i].rdev.sb_page || in validate_raid_redundancy()
1063 !test_bit(In_sync, &rs->dev[i].rdev.flags)) && in validate_raid_redundancy()
1083 last_group_start = (raid_disks / group_size) - 1; in validate_raid_redundancy()
1088 if ((!rs->dev[i].rdev.sb_page || in validate_raid_redundancy()
1089 !test_bit(In_sync, &rs->dev[i].rdev.flags)) && in validate_raid_redundancy()
1096 return -EINVAL; in validate_raid_redundancy()
1102 return -EINVAL; in validate_raid_redundancy()
1120 * [max_write_behind <sectors>] See '-write-behind=' (man mdadm)
1126 * RAID10-only options:
1130 static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, in parse_raid_params() argument
1140 struct raid_type *rt = rs->raid_type; in parse_raid_params()
1143 num_raid_params--; /* Account for chunk_size argument */ in parse_raid_params()
1146 rs->ti->error = "Bad numerical argument given for chunk_size"; in parse_raid_params()
1147 return -EINVAL; in parse_raid_params()
1151 * First, parse the in-order required arguments in parse_raid_params()
1159 rs->ti->error = "Chunk size must be a power of 2"; in parse_raid_params()
1160 return -EINVAL; in parse_raid_params()
1162 rs->ti->error = "Chunk size value is too small"; in parse_raid_params()
1163 return -EINVAL; in parse_raid_params()
1166 rs->md.new_chunk_sectors = rs->md.chunk_sectors = value; in parse_raid_params()
1174 * - Device is reset when param is read. in parse_raid_params()
1176 * - No matching superblock found, resets device. in parse_raid_params()
1178 * - Failure noticed, resets device for bitmap replay. in parse_raid_params()
1180 * - Superblock is read and overrides recovery_offset. in parse_raid_params()
1185 for (i = 0; i < rs->raid_disks; i++) { in parse_raid_params()
1186 set_bit(In_sync, &rs->dev[i].rdev.flags); in parse_raid_params()
1187 rs->dev[i].rdev.recovery_offset = MaxSector; in parse_raid_params()
1196 rs->ti->error = "Not enough raid parameters given"; in parse_raid_params()
1197 return -EINVAL; in parse_raid_params()
1201 if (test_and_set_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) { in parse_raid_params()
1202 rs->ti->error = "Only one 'nosync' argument allowed"; in parse_raid_params()
1203 return -EINVAL; in parse_raid_params()
1208 if (test_and_set_bit(__CTR_FLAG_SYNC, &rs->ctr_flags)) { in parse_raid_params()
1209 rs->ti->error = "Only one 'sync' argument allowed"; in parse_raid_params()
1210 return -EINVAL; in parse_raid_params()
1215 if (test_and_set_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) { in parse_raid_params()
1216 rs->ti->error = "Only one 'raid10_use_new_sets' argument allowed"; in parse_raid_params()
1217 return -EINVAL; in parse_raid_params()
1225 rs->ti->error = "Wrong number of raid parameters given"; in parse_raid_params()
1226 return -EINVAL; in parse_raid_params()
1234 if (test_and_set_bit(__CTR_FLAG_RAID10_FORMAT, &rs->ctr_flags)) { in parse_raid_params()
1235 rs->ti->error = "Only one 'raid10_format' argument pair allowed"; in parse_raid_params()
1236 return -EINVAL; in parse_raid_params()
1239 rs->ti->error = "'raid10_format' is an invalid parameter for this RAID type"; in parse_raid_params()
1240 return -EINVAL; in parse_raid_params()
1244 rs->ti->error = "Invalid 'raid10_format' value given"; in parse_raid_params()
1255 if (test_and_set_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { in parse_raid_params()
1256 rs->ti->error = "Only one raid4/5/6 set journaling device allowed"; in parse_raid_params()
1257 return -EINVAL; in parse_raid_params()
1260 rs->ti->error = "'journal_dev' is an invalid parameter for this RAID type"; in parse_raid_params()
1261 return -EINVAL; in parse_raid_params()
1263 r = dm_get_device(rs->ti, arg, dm_table_get_mode(rs->ti->table), in parse_raid_params()
1264 &rs->journal_dev.dev); in parse_raid_params()
1266 rs->ti->error = "raid4/5/6 journal device lookup failure"; in parse_raid_params()
1269 jdev = &rs->journal_dev.rdev; in parse_raid_params()
1271 jdev->mddev = &rs->md; in parse_raid_params()
1272 jdev->bdev = rs->journal_dev.dev->bdev; in parse_raid_params()
1273 jdev->sectors = bdev_nr_sectors(jdev->bdev); in parse_raid_params()
1274 if (jdev->sectors < MIN_RAID456_JOURNAL_SPACE) { in parse_raid_params()
1275 rs->ti->error = "No space for raid4/5/6 journal"; in parse_raid_params()
1276 return -ENOSPC; in parse_raid_params()
1278 rs->journal_dev.mode = R5C_JOURNAL_MODE_WRITE_THROUGH; in parse_raid_params()
1279 set_bit(Journal, &jdev->flags); in parse_raid_params()
1287 if (!test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { in parse_raid_params()
1288 rs->ti->error = "raid4/5/6 'journal_mode' is invalid without 'journal_dev'"; in parse_raid_params()
1289 return -EINVAL; in parse_raid_params()
1291 if (test_and_set_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) { in parse_raid_params()
1292 rs->ti->error = "Only one raid4/5/6 'journal_mode' argument allowed"; in parse_raid_params()
1293 return -EINVAL; in parse_raid_params()
1297 rs->ti->error = "Invalid 'journal_mode' argument"; in parse_raid_params()
1300 rs->journal_dev.mode = r; in parse_raid_params()
1308 rs->ti->error = "Bad numerical argument given in raid params"; in parse_raid_params()
1309 return -EINVAL; in parse_raid_params()
1318 if (!__within_range(value, 0, rs->raid_disks - 1)) { in parse_raid_params()
1319 rs->ti->error = "Invalid rebuild index given"; in parse_raid_params()
1320 return -EINVAL; in parse_raid_params()
1323 if (test_and_set_bit(value, (void *) rs->rebuild_disks)) { in parse_raid_params()
1324 rs->ti->error = "rebuild for this index already given"; in parse_raid_params()
1325 return -EINVAL; in parse_raid_params()
1328 rd = rs->dev + value; in parse_raid_params()
1329 clear_bit(In_sync, &rd->rdev.flags); in parse_raid_params()
1330 clear_bit(Faulty, &rd->rdev.flags); in parse_raid_params()
1331 rd->rdev.recovery_offset = 0; in parse_raid_params()
1332 set_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags); in parse_raid_params()
1335 rs->ti->error = "write_mostly option is only valid for RAID1"; in parse_raid_params()
1336 return -EINVAL; in parse_raid_params()
1339 if (!__within_range(value, 0, rs->md.raid_disks - 1)) { in parse_raid_params()
1340 rs->ti->error = "Invalid write_mostly index given"; in parse_raid_params()
1341 return -EINVAL; in parse_raid_params()
1345 set_bit(WriteMostly, &rs->dev[value].rdev.flags); in parse_raid_params()
1346 set_bit(__CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags); in parse_raid_params()
1349 rs->ti->error = "max_write_behind option is only valid for RAID1"; in parse_raid_params()
1350 return -EINVAL; in parse_raid_params()
1353 if (test_and_set_bit(__CTR_FLAG_MAX_WRITE_BEHIND, &rs->ctr_flags)) { in parse_raid_params()
1354 rs->ti->error = "Only one max_write_behind argument pair allowed"; in parse_raid_params()
1355 return -EINVAL; in parse_raid_params()
1359 * In device-mapper, we specify things in sectors, but in parse_raid_params()
1363 rs->ti->error = "Max write-behind limit out of range"; in parse_raid_params()
1364 return -EINVAL; in parse_raid_params()
1367 rs->md.bitmap_info.max_write_behind = value / 2; in parse_raid_params()
1369 if (test_and_set_bit(__CTR_FLAG_DAEMON_SLEEP, &rs->ctr_flags)) { in parse_raid_params()
1370 rs->ti->error = "Only one daemon_sleep argument pair allowed"; in parse_raid_params()
1371 return -EINVAL; in parse_raid_params()
1374 rs->ti->error = "daemon sleep period out of range"; in parse_raid_params()
1375 return -EINVAL; in parse_raid_params()
1377 rs->md.bitmap_info.daemon_sleep = value; in parse_raid_params()
1380 if (test_and_set_bit(__CTR_FLAG_DATA_OFFSET, &rs->ctr_flags)) { in parse_raid_params()
1381 rs->ti->error = "Only one data_offset argument pair allowed"; in parse_raid_params()
1382 return -EINVAL; in parse_raid_params()
1387 rs->ti->error = "Bogus data_offset value"; in parse_raid_params()
1388 return -EINVAL; in parse_raid_params()
1390 rs->data_offset = value; in parse_raid_params()
1392 /* Define the +/-# of disks to add to/remove from the given raid set */ in parse_raid_params()
1393 if (test_and_set_bit(__CTR_FLAG_DELTA_DISKS, &rs->ctr_flags)) { in parse_raid_params()
1394 rs->ti->error = "Only one delta_disks argument pair allowed"; in parse_raid_params()
1395 return -EINVAL; in parse_raid_params()
1398 if (!__within_range(abs(value), 1, MAX_RAID_DEVICES - rt->minimal_devs)) { in parse_raid_params()
1399 rs->ti->error = "Too many delta_disk requested"; in parse_raid_params()
1400 return -EINVAL; in parse_raid_params()
1403 rs->delta_disks = value; in parse_raid_params()
1405 if (test_and_set_bit(__CTR_FLAG_STRIPE_CACHE, &rs->ctr_flags)) { in parse_raid_params()
1406 rs->ti->error = "Only one stripe_cache argument pair allowed"; in parse_raid_params()
1407 return -EINVAL; in parse_raid_params()
1411 rs->ti->error = "Inappropriate argument: stripe_cache"; in parse_raid_params()
1412 return -EINVAL; in parse_raid_params()
1416 rs->ti->error = "Bogus stripe cache entries value"; in parse_raid_params()
1417 return -EINVAL; in parse_raid_params()
1419 rs->stripe_cache_entries = value; in parse_raid_params()
1421 if (test_and_set_bit(__CTR_FLAG_MIN_RECOVERY_RATE, &rs->ctr_flags)) { in parse_raid_params()
1422 rs->ti->error = "Only one min_recovery_rate argument pair allowed"; in parse_raid_params()
1423 return -EINVAL; in parse_raid_params()
1427 rs->ti->error = "min_recovery_rate out of range"; in parse_raid_params()
1428 return -EINVAL; in parse_raid_params()
1430 rs->md.sync_speed_min = value; in parse_raid_params()
1432 if (test_and_set_bit(__CTR_FLAG_MAX_RECOVERY_RATE, &rs->ctr_flags)) { in parse_raid_params()
1433 rs->ti->error = "Only one max_recovery_rate argument pair allowed"; in parse_raid_params()
1434 return -EINVAL; in parse_raid_params()
1438 rs->ti->error = "max_recovery_rate out of range"; in parse_raid_params()
1439 return -EINVAL; in parse_raid_params()
1441 rs->md.sync_speed_max = value; in parse_raid_params()
1443 if (test_and_set_bit(__CTR_FLAG_REGION_SIZE, &rs->ctr_flags)) { in parse_raid_params()
1444 rs->ti->error = "Only one region_size argument pair allowed"; in parse_raid_params()
1445 return -EINVAL; in parse_raid_params()
1449 rs->requested_bitmap_chunk_sectors = value; in parse_raid_params()
1451 if (test_and_set_bit(__CTR_FLAG_RAID10_COPIES, &rs->ctr_flags)) { in parse_raid_params()
1452 rs->ti->error = "Only one raid10_copies argument pair allowed"; in parse_raid_params()
1453 return -EINVAL; in parse_raid_params()
1456 if (!__within_range(value, 2, rs->md.raid_disks)) { in parse_raid_params()
1457 rs->ti->error = "Bad value for 'raid10_copies'"; in parse_raid_params()
1458 return -EINVAL; in parse_raid_params()
1464 rs->ti->error = "Unable to parse RAID parameter"; in parse_raid_params()
1465 return -EINVAL; in parse_raid_params()
1469 if (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags) && in parse_raid_params()
1470 test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) { in parse_raid_params()
1471 rs->ti->error = "sync and nosync are mutually exclusive"; in parse_raid_params()
1472 return -EINVAL; in parse_raid_params()
1475 if (test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags) && in parse_raid_params()
1476 (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags) || in parse_raid_params()
1477 test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags))) { in parse_raid_params()
1478 rs->ti->error = "sync/nosync and rebuild are mutually exclusive"; in parse_raid_params()
1479 return -EINVAL; in parse_raid_params()
1482 if (write_mostly >= rs->md.raid_disks) { in parse_raid_params()
1483 rs->ti->error = "Can't set all raid1 devices to write_mostly"; in parse_raid_params()
1484 return -EINVAL; in parse_raid_params()
1487 if (rs->md.sync_speed_max && in parse_raid_params()
1488 rs->md.sync_speed_min > rs->md.sync_speed_max) { in parse_raid_params()
1489 rs->ti->error = "Bogus recovery rates"; in parse_raid_params()
1490 return -EINVAL; in parse_raid_params()
1493 if (validate_region_size(rs, region_size)) in parse_raid_params()
1494 return -EINVAL; in parse_raid_params()
1496 if (rs->md.chunk_sectors) in parse_raid_params()
1497 max_io_len = rs->md.chunk_sectors; in parse_raid_params()
1501 if (dm_set_target_max_io_len(rs->ti, max_io_len)) in parse_raid_params()
1502 return -EINVAL; in parse_raid_params()
1505 if (raid10_copies > rs->md.raid_disks) { in parse_raid_params()
1506 rs->ti->error = "Not enough devices to satisfy specification"; in parse_raid_params()
1507 return -EINVAL; in parse_raid_params()
1510 rs->md.new_layout = raid10_format_to_md_layout(rs, raid10_format, raid10_copies); in parse_raid_params()
1511 if (rs->md.new_layout < 0) { in parse_raid_params()
1512 rs->ti->error = "Error getting raid10 format"; in parse_raid_params()
1513 return rs->md.new_layout; in parse_raid_params()
1516 rt = get_raid_type_by_ll(10, rs->md.new_layout); in parse_raid_params()
1518 rs->ti->error = "Failed to recognize new raid10 layout"; in parse_raid_params()
1519 return -EINVAL; in parse_raid_params()
1522 if ((rt->algorithm == ALGORITHM_RAID10_DEFAULT || in parse_raid_params()
1523 rt->algorithm == ALGORITHM_RAID10_NEAR) && in parse_raid_params()
1524 test_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) { in parse_raid_params()
1525 rs->ti->error = "RAID10 format 'near' and 'raid10_use_near_sets' are incompatible"; in parse_raid_params()
1526 return -EINVAL; in parse_raid_params()
1530 rs->raid10_copies = raid10_copies; in parse_raid_params()
1533 rs->md.persistent = 0; in parse_raid_params()
1534 rs->md.external = 1; in parse_raid_params()
1537 return rs_check_for_valid_flags(rs); in parse_raid_params()
1541 static int rs_set_raid456_stripe_cache(struct raid_set *rs) in rs_set_raid456_stripe_cache() argument
1545 struct mddev *mddev = &rs->md; in rs_set_raid456_stripe_cache()
1546 uint32_t min_stripes = max(mddev->chunk_sectors, mddev->new_chunk_sectors) / 2; in rs_set_raid456_stripe_cache()
1547 uint32_t nr_stripes = rs->stripe_cache_entries; in rs_set_raid456_stripe_cache()
1549 if (!rt_is_raid456(rs->raid_type)) { in rs_set_raid456_stripe_cache()
1550 rs->ti->error = "Inappropriate raid level; cannot change stripe_cache size"; in rs_set_raid456_stripe_cache()
1551 return -EINVAL; in rs_set_raid456_stripe_cache()
1560 conf = mddev->private; in rs_set_raid456_stripe_cache()
1562 rs->ti->error = "Cannot change stripe_cache size on inactive RAID set"; in rs_set_raid456_stripe_cache()
1563 return -EINVAL; in rs_set_raid456_stripe_cache()
1567 if (conf->min_nr_stripes != nr_stripes) { in rs_set_raid456_stripe_cache()
1570 rs->ti->error = "Failed to set raid4/5/6 stripe cache size"; in rs_set_raid456_stripe_cache()
1580 /* Return # of data stripes as kept in mddev as of @rs (i.e. as of superblock) */
1581 static unsigned int mddev_data_stripes(struct raid_set *rs) in mddev_data_stripes() argument
1583 return rs->md.raid_disks - rs->raid_type->parity_devs; in mddev_data_stripes()
1586 /* Return # of data stripes of @rs (i.e. as of ctr) */
1587 static unsigned int rs_data_stripes(struct raid_set *rs) in rs_data_stripes() argument
1589 return rs->raid_disks - rs->raid_type->parity_devs; in rs_data_stripes()
1593 * Retrieve rdev->sectors from any valid raid device of @rs
1594 * to allow userpace to pass in arbitray "- -" device tupples.
1596 static sector_t __rdev_sectors(struct raid_set *rs) in __rdev_sectors() argument
1600 for (i = 0; i < rs->raid_disks; i++) { in __rdev_sectors()
1601 struct md_rdev *rdev = &rs->dev[i].rdev; in __rdev_sectors()
1603 if (!test_bit(Journal, &rdev->flags) && in __rdev_sectors()
1604 rdev->bdev && rdev->sectors) in __rdev_sectors()
1605 return rdev->sectors; in __rdev_sectors()
1612 static int _check_data_dev_sectors(struct raid_set *rs) in _check_data_dev_sectors() argument
1617 rdev_for_each(rdev, &rs->md) in _check_data_dev_sectors()
1618 if (!test_bit(Journal, &rdev->flags) && rdev->bdev) { in _check_data_dev_sectors()
1619 ds = min(ds, bdev_nr_sectors(rdev->bdev)); in _check_data_dev_sectors()
1620 if (ds < rs->md.dev_sectors) { in _check_data_dev_sectors()
1621 rs->ti->error = "Component device(s) too small"; in _check_data_dev_sectors()
1622 return -EINVAL; in _check_data_dev_sectors()
1630 static sector_t _get_reshape_sectors(struct raid_set *rs) in _get_reshape_sectors() argument
1635 rdev_for_each(rdev, &rs->md) in _get_reshape_sectors()
1636 if (!test_bit(Journal, &rdev->flags)) { in _get_reshape_sectors()
1637 reshape_sectors = (rdev->data_offset > rdev->new_data_offset) ? in _get_reshape_sectors()
1638 rdev->data_offset - rdev->new_data_offset : in _get_reshape_sectors()
1639 rdev->new_data_offset - rdev->data_offset; in _get_reshape_sectors()
1643 return max(reshape_sectors, (sector_t) rs->data_offset); in _get_reshape_sectors()
1646 /* Calculate the sectors per device and per array used for @rs */
1647 static int rs_set_dev_and_array_sectors(struct raid_set *rs, sector_t sectors, bool use_mddev) in rs_set_dev_and_array_sectors() argument
1652 struct mddev *mddev = &rs->md; in rs_set_dev_and_array_sectors()
1655 delta_disks = mddev->delta_disks; in rs_set_dev_and_array_sectors()
1656 data_stripes = mddev_data_stripes(rs); in rs_set_dev_and_array_sectors()
1658 delta_disks = rs->delta_disks; in rs_set_dev_and_array_sectors()
1659 data_stripes = rs_data_stripes(rs); in rs_set_dev_and_array_sectors()
1663 if (rt_is_raid1(rs->raid_type)) in rs_set_dev_and_array_sectors()
1665 else if (rt_is_raid10(rs->raid_type)) { in rs_set_dev_and_array_sectors()
1666 if (rs->raid10_copies < 2 || in rs_set_dev_and_array_sectors()
1668 rs->ti->error = "Bogus raid10 data copies or delta disks"; in rs_set_dev_and_array_sectors()
1669 return -EINVAL; in rs_set_dev_and_array_sectors()
1672 dev_sectors *= rs->raid10_copies; in rs_set_dev_and_array_sectors()
1676 array_sectors = (data_stripes + delta_disks) * (dev_sectors - _get_reshape_sectors(rs)); in rs_set_dev_and_array_sectors()
1677 if (sector_div(array_sectors, rs->raid10_copies)) in rs_set_dev_and_array_sectors()
1685 array_sectors = (data_stripes + delta_disks) * (dev_sectors - _get_reshape_sectors(rs)); in rs_set_dev_and_array_sectors()
1687 mddev->array_sectors = array_sectors; in rs_set_dev_and_array_sectors()
1688 mddev->dev_sectors = dev_sectors; in rs_set_dev_and_array_sectors()
1689 rs_set_rdev_sectors(rs); in rs_set_dev_and_array_sectors()
1691 return _check_data_dev_sectors(rs); in rs_set_dev_and_array_sectors()
1693 rs->ti->error = "Target length not divisible by number of data devices"; in rs_set_dev_and_array_sectors()
1694 return -EINVAL; in rs_set_dev_and_array_sectors()
1697 /* Setup recovery on @rs */
1698 static void rs_setup_recovery(struct raid_set *rs, sector_t dev_sectors) in rs_setup_recovery() argument
1701 if (rs_is_raid0(rs)) in rs_setup_recovery()
1702 rs->md.recovery_cp = MaxSector; in rs_setup_recovery()
1706 * ensure proper parity and Q-Syndrome in rs_setup_recovery()
1708 else if (rs_is_raid6(rs)) in rs_setup_recovery()
1709 rs->md.recovery_cp = dev_sectors; in rs_setup_recovery()
1715 rs->md.recovery_cp = test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags) in rs_setup_recovery()
1721 struct raid_set *rs = container_of(ws, struct raid_set, md.event_work); in do_table_event() local
1726 if (!rs_is_reshaping(rs) && in do_table_event()
1727 rs->array_sectors > rs->md.array_sectors && in do_table_event()
1728 !rs->md.delta_disks && in do_table_event()
1729 rs->md.raid_disks == rs->raid_disks) { in do_table_event()
1730 /* The raid10 personality doesn't provide proper device sizes -> correct. */ in do_table_event()
1731 if (rs_is_raid10(rs)) in do_table_event()
1732 rs_set_rdev_sectors(rs); in do_table_event()
1734 rs->md.array_sectors = rs->array_sectors; in do_table_event()
1735 rs_set_capacity(rs); in do_table_event()
1738 dm_table_event(rs->ti->table); in do_table_event()
1742 * Make sure a valid takover (level switch) is being requested on @rs
1747 static int rs_check_takeover(struct raid_set *rs) in rs_check_takeover() argument
1749 struct mddev *mddev = &rs->md; in rs_check_takeover()
1752 if (rs->md.degraded) { in rs_check_takeover()
1753 rs->ti->error = "Can't takeover degraded raid set"; in rs_check_takeover()
1754 return -EPERM; in rs_check_takeover()
1757 if (rs_is_reshaping(rs)) { in rs_check_takeover()
1758 rs->ti->error = "Can't takeover reshaping raid set"; in rs_check_takeover()
1759 return -EPERM; in rs_check_takeover()
1762 switch (mddev->level) { in rs_check_takeover()
1764 /* raid0 -> raid1/5 with one disk */ in rs_check_takeover()
1765 if ((mddev->new_level == 1 || mddev->new_level == 5) && in rs_check_takeover()
1766 mddev->raid_disks == 1) in rs_check_takeover()
1769 /* raid0 -> raid10 */ in rs_check_takeover()
1770 if (mddev->new_level == 10 && in rs_check_takeover()
1771 !(rs->raid_disks % mddev->raid_disks)) in rs_check_takeover()
1774 /* raid0 with multiple disks -> raid4/5/6 */ in rs_check_takeover()
1775 if (__within_range(mddev->new_level, 4, 6) && in rs_check_takeover()
1776 mddev->new_layout == ALGORITHM_PARITY_N && in rs_check_takeover()
1777 mddev->raid_disks > 1) in rs_check_takeover()
1784 if (__is_raid10_offset(mddev->layout)) in rs_check_takeover()
1787 near_copies = __raid10_near_copies(mddev->layout); in rs_check_takeover()
1789 /* raid10* -> raid0 */ in rs_check_takeover()
1790 if (mddev->new_level == 0) { in rs_check_takeover()
1793 !(mddev->raid_disks % near_copies)) { in rs_check_takeover()
1794 mddev->raid_disks /= near_copies; in rs_check_takeover()
1795 mddev->delta_disks = mddev->raid_disks; in rs_check_takeover()
1801 __raid10_far_copies(mddev->layout) > 1) in rs_check_takeover()
1807 /* raid10_{near,far} -> raid1 */ in rs_check_takeover()
1808 if (mddev->new_level == 1 && in rs_check_takeover()
1809 max(near_copies, __raid10_far_copies(mddev->layout)) == mddev->raid_disks) in rs_check_takeover()
1812 /* raid10_{near,far} with 2 disks -> raid4/5 */ in rs_check_takeover()
1813 if (__within_range(mddev->new_level, 4, 5) && in rs_check_takeover()
1814 mddev->raid_disks == 2) in rs_check_takeover()
1819 /* raid1 with 2 disks -> raid4/5 */ in rs_check_takeover()
1820 if (__within_range(mddev->new_level, 4, 5) && in rs_check_takeover()
1821 mddev->raid_disks == 2) { in rs_check_takeover()
1822 mddev->degraded = 1; in rs_check_takeover()
1826 /* raid1 -> raid0 */ in rs_check_takeover()
1827 if (mddev->new_level == 0 && in rs_check_takeover()
1828 mddev->raid_disks == 1) in rs_check_takeover()
1831 /* raid1 -> raid10 */ in rs_check_takeover()
1832 if (mddev->new_level == 10) in rs_check_takeover()
1837 /* raid4 -> raid0 */ in rs_check_takeover()
1838 if (mddev->new_level == 0) in rs_check_takeover()
1841 /* raid4 -> raid1/5 with 2 disks */ in rs_check_takeover()
1842 if ((mddev->new_level == 1 || mddev->new_level == 5) && in rs_check_takeover()
1843 mddev->raid_disks == 2) in rs_check_takeover()
1846 /* raid4 -> raid5/6 with parity N */ in rs_check_takeover()
1847 if (__within_range(mddev->new_level, 5, 6) && in rs_check_takeover()
1848 mddev->layout == ALGORITHM_PARITY_N) in rs_check_takeover()
1853 /* raid5 with parity N -> raid0 */ in rs_check_takeover()
1854 if (mddev->new_level == 0 && in rs_check_takeover()
1855 mddev->layout == ALGORITHM_PARITY_N) in rs_check_takeover()
1858 /* raid5 with parity N -> raid4 */ in rs_check_takeover()
1859 if (mddev->new_level == 4 && in rs_check_takeover()
1860 mddev->layout == ALGORITHM_PARITY_N) in rs_check_takeover()
1863 /* raid5 with 2 disks -> raid1/4/10 */ in rs_check_takeover()
1864 if ((mddev->new_level == 1 || mddev->new_level == 4 || mddev->new_level == 10) && in rs_check_takeover()
1865 mddev->raid_disks == 2) in rs_check_takeover()
1868 /* raid5_* -> raid6_*_6 with Q-Syndrome N (e.g. raid5_ra -> raid6_ra_6 */ in rs_check_takeover()
1869 if (mddev->new_level == 6 && in rs_check_takeover()
1870 ((mddev->layout == ALGORITHM_PARITY_N && mddev->new_layout == ALGORITHM_PARITY_N) || in rs_check_takeover()
1871 … __within_range(mddev->new_layout, ALGORITHM_LEFT_ASYMMETRIC_6, ALGORITHM_RIGHT_SYMMETRIC_6))) in rs_check_takeover()
1876 /* raid6 with parity N -> raid0 */ in rs_check_takeover()
1877 if (mddev->new_level == 0 && in rs_check_takeover()
1878 mddev->layout == ALGORITHM_PARITY_N) in rs_check_takeover()
1881 /* raid6 with parity N -> raid4 */ in rs_check_takeover()
1882 if (mddev->new_level == 4 && in rs_check_takeover()
1883 mddev->layout == ALGORITHM_PARITY_N) in rs_check_takeover()
1886 /* raid6_*_n with Q-Syndrome N -> raid5_* */ in rs_check_takeover()
1887 if (mddev->new_level == 5 && in rs_check_takeover()
1888 ((mddev->layout == ALGORITHM_PARITY_N && mddev->new_layout == ALGORITHM_PARITY_N) || in rs_check_takeover()
1889 __within_range(mddev->new_layout, ALGORITHM_LEFT_ASYMMETRIC, ALGORITHM_RIGHT_SYMMETRIC))) in rs_check_takeover()
1897 rs->ti->error = "takeover not possible"; in rs_check_takeover()
1898 return -EINVAL; in rs_check_takeover()
1901 /* True if @rs requested to be taken over */
1902 static bool rs_takeover_requested(struct raid_set *rs) in rs_takeover_requested() argument
1904 return rs->md.new_level != rs->md.level; in rs_takeover_requested()
1908 static bool rs_is_layout_change(struct raid_set *rs, bool use_mddev) in rs_is_layout_change() argument
1910 return (use_mddev ? rs->md.delta_disks : rs->delta_disks) || in rs_is_layout_change()
1911 rs->md.new_layout != rs->md.layout || in rs_is_layout_change()
1912 rs->md.new_chunk_sectors != rs->md.chunk_sectors; in rs_is_layout_change()
1915 /* True if @rs is requested to reshape by ctr */
1916 static bool rs_reshape_requested(struct raid_set *rs) in rs_reshape_requested() argument
1919 struct mddev *mddev = &rs->md; in rs_reshape_requested()
1921 if (rs_takeover_requested(rs)) in rs_reshape_requested()
1924 if (rs_is_raid0(rs)) in rs_reshape_requested()
1927 change = rs_is_layout_change(rs, false); in rs_reshape_requested()
1930 if (rs_is_raid1(rs)) { in rs_reshape_requested()
1931 if (rs->delta_disks) in rs_reshape_requested()
1932 return !!rs->delta_disks; in rs_reshape_requested()
1935 mddev->raid_disks != rs->raid_disks; in rs_reshape_requested()
1938 if (rs_is_raid10(rs)) in rs_reshape_requested()
1940 !__is_raid10_far(mddev->new_layout) && in rs_reshape_requested()
1941 rs->delta_disks >= 0; in rs_reshape_requested()
1949 /* State flags for sb->flags */
1955 * Devices with this superblock should only ever be accessed via device-mapper.
2025 * up to 256 devices with the 1.9.0 on-disk metadata format
2027 __le64 extended_failed_devices[DISKS_ARRAY_ELEMS - 1];
2035 * Check for reshape constraints on raid set @rs:
2037 * - reshape function non-existent
2038 * - degraded set
2039 * - ongoing recovery
2040 * - ongoing reshape
2042 * Returns 0 if none or -EPERM if given constraint
2045 static int rs_check_reshape(struct raid_set *rs) in rs_check_reshape() argument
2047 struct mddev *mddev = &rs->md; in rs_check_reshape()
2049 if (!mddev->pers || !mddev->pers->check_reshape) in rs_check_reshape()
2050 rs->ti->error = "Reshape not supported"; in rs_check_reshape()
2051 else if (mddev->degraded) in rs_check_reshape()
2052 rs->ti->error = "Can't reshape degraded raid set"; in rs_check_reshape()
2053 else if (rs_is_recovering(rs)) in rs_check_reshape()
2054 rs->ti->error = "Convert request on recovering raid set prohibited"; in rs_check_reshape()
2055 else if (rs_is_reshaping(rs)) in rs_check_reshape()
2056 rs->ti->error = "raid set already reshaping!"; in rs_check_reshape()
2057 else if (!(rs_is_raid1(rs) || rs_is_raid10(rs) || rs_is_raid456(rs))) in rs_check_reshape()
2058 rs->ti->error = "Reshaping only supported for raid1/4/5/6/10"; in rs_check_reshape()
2062 return -EPERM; in rs_check_reshape()
2067 BUG_ON(!rdev->sb_page); in read_disk_sb()
2069 if (rdev->sb_loaded && !force_reload) in read_disk_sb()
2072 rdev->sb_loaded = 0; in read_disk_sb()
2074 if (!sync_page_io(rdev, 0, size, rdev->sb_page, REQ_OP_READ, true)) { in read_disk_sb()
2076 rdev->raid_disk); in read_disk_sb()
2077 md_error(rdev->mddev, rdev); in read_disk_sb()
2078 set_bit(Faulty, &rdev->flags); in read_disk_sb()
2079 return -EIO; in read_disk_sb()
2082 rdev->sb_loaded = 1; in read_disk_sb()
2089 failed_devices[0] = le64_to_cpu(sb->failed_devices); in sb_retrieve_failed_devices()
2090 memset(failed_devices + 1, 0, sizeof(sb->extended_failed_devices)); in sb_retrieve_failed_devices()
2092 if (le32_to_cpu(sb->compat_features) & FEATURE_FLAG_SUPPORTS_V190) { in sb_retrieve_failed_devices()
2093 int i = ARRAY_SIZE(sb->extended_failed_devices); in sb_retrieve_failed_devices()
2095 while (i--) in sb_retrieve_failed_devices()
2096 failed_devices[i+1] = le64_to_cpu(sb->extended_failed_devices[i]); in sb_retrieve_failed_devices()
2102 int i = ARRAY_SIZE(sb->extended_failed_devices); in sb_update_failed_devices()
2104 sb->failed_devices = cpu_to_le64(failed_devices[0]); in sb_update_failed_devices()
2105 while (i--) in sb_update_failed_devices()
2106 sb->extended_failed_devices[i] = cpu_to_le64(failed_devices[i+1]); in sb_update_failed_devices()
2120 struct raid_set *rs = container_of(mddev, struct raid_set, md); in super_sync() local
2123 if (!rdev->meta_bdev) in super_sync()
2126 BUG_ON(!rdev->sb_page); in super_sync()
2128 sb = page_address(rdev->sb_page); in super_sync()
2132 for (i = 0; i < rs->raid_disks; i++) in super_sync()
2133 if (!rs->dev[i].data_dev || test_bit(Faulty, &rs->dev[i].rdev.flags)) { in super_sync()
2141 sb->magic = cpu_to_le32(DM_RAID_MAGIC); in super_sync()
2142 sb->compat_features = cpu_to_le32(FEATURE_FLAG_SUPPORTS_V190); in super_sync()
2144 sb->num_devices = cpu_to_le32(mddev->raid_disks); in super_sync()
2145 sb->array_position = cpu_to_le32(rdev->raid_disk); in super_sync()
2147 sb->events = cpu_to_le64(mddev->events); in super_sync()
2149 sb->disk_recovery_offset = cpu_to_le64(rdev->recovery_offset); in super_sync()
2150 sb->array_resync_offset = cpu_to_le64(mddev->recovery_cp); in super_sync()
2152 sb->level = cpu_to_le32(mddev->level); in super_sync()
2153 sb->layout = cpu_to_le32(mddev->layout); in super_sync()
2154 sb->stripe_sectors = cpu_to_le32(mddev->chunk_sectors); in super_sync()
2161 sb->new_level = cpu_to_le32(mddev->new_level); in super_sync()
2162 sb->new_layout = cpu_to_le32(mddev->new_layout); in super_sync()
2163 sb->new_stripe_sectors = cpu_to_le32(mddev->new_chunk_sectors); in super_sync()
2165 sb->delta_disks = cpu_to_le32(mddev->delta_disks); in super_sync()
2168 sb->reshape_position = cpu_to_le64(mddev->reshape_position); in super_sync()
2169 if (le64_to_cpu(sb->reshape_position) != MaxSector) { in super_sync()
2171 sb->flags |= cpu_to_le32(SB_FLAG_RESHAPE_ACTIVE); in super_sync()
2173 if (mddev->delta_disks < 0 || mddev->reshape_backwards) in super_sync()
2174 sb->flags |= cpu_to_le32(SB_FLAG_RESHAPE_BACKWARDS); in super_sync()
2177 sb->flags &= ~(cpu_to_le32(SB_FLAG_RESHAPE_ACTIVE|SB_FLAG_RESHAPE_BACKWARDS)); in super_sync()
2180 sb->array_sectors = cpu_to_le64(mddev->array_sectors); in super_sync()
2181 sb->data_offset = cpu_to_le64(rdev->data_offset); in super_sync()
2182 sb->new_data_offset = cpu_to_le64(rdev->new_data_offset); in super_sync()
2183 sb->sectors = cpu_to_le64(rdev->sectors); in super_sync()
2184 sb->incompat_features = cpu_to_le32(0); in super_sync()
2187 memset(sb + 1, 0, rdev->sb_size - sizeof(*sb)); in super_sync()
2196 * Return: 1 if use rdev, 0 if use refdev, -Exxx otherwise
2205 r = read_disk_sb(rdev, rdev->sb_size, false); in super_load()
2209 sb = page_address(rdev->sb_page); in super_load()
2216 if ((sb->magic != cpu_to_le32(DM_RAID_MAGIC)) || in super_load()
2217 (!test_bit(In_sync, &rdev->flags) && !rdev->recovery_offset)) { in super_load()
2218 super_sync(rdev->mddev, rdev); in super_load()
2220 set_bit(FirstUse, &rdev->flags); in super_load()
2221 sb->compat_features = cpu_to_le32(FEATURE_FLAG_SUPPORTS_V190); in super_load()
2224 set_bit(MD_SB_CHANGE_DEVS, &rdev->mddev->sb_flags); in super_load()
2233 events_sb = le64_to_cpu(sb->events); in super_load()
2235 refsb = page_address(refdev->sb_page); in super_load()
2236 events_refsb = le64_to_cpu(refsb->events); in super_load()
2241 static int super_init_validation(struct raid_set *rs, struct md_rdev *rdev) in super_init_validation() argument
2244 struct mddev *mddev = &rs->md; in super_init_validation()
2252 sb = page_address(rdev->sb_page); in super_init_validation()
2253 events_sb = le64_to_cpu(sb->events); in super_init_validation()
2258 mddev->events = events_sb ? : 1; in super_init_validation()
2260 mddev->reshape_position = MaxSector; in super_init_validation()
2262 mddev->raid_disks = le32_to_cpu(sb->num_devices); in super_init_validation()
2263 mddev->level = le32_to_cpu(sb->level); in super_init_validation()
2264 mddev->layout = le32_to_cpu(sb->layout); in super_init_validation()
2265 mddev->chunk_sectors = le32_to_cpu(sb->stripe_sectors); in super_init_validation()
2271 if (le32_to_cpu(sb->compat_features) & FEATURE_FLAG_SUPPORTS_V190) { in super_init_validation()
2273 mddev->new_level = le32_to_cpu(sb->new_level); in super_init_validation()
2274 mddev->new_layout = le32_to_cpu(sb->new_layout); in super_init_validation()
2275 mddev->new_chunk_sectors = le32_to_cpu(sb->new_stripe_sectors); in super_init_validation()
2276 mddev->delta_disks = le32_to_cpu(sb->delta_disks); in super_init_validation()
2277 mddev->array_sectors = le64_to_cpu(sb->array_sectors); in super_init_validation()
2280 if (le32_to_cpu(sb->flags) & SB_FLAG_RESHAPE_ACTIVE) { in super_init_validation()
2281 if (test_bit(__CTR_FLAG_DELTA_DISKS, &rs->ctr_flags)) { in super_init_validation()
2283 return -EINVAL; in super_init_validation()
2286 if (mddev->delta_disks < 0 || in super_init_validation()
2287 (!mddev->delta_disks && (le32_to_cpu(sb->flags) & SB_FLAG_RESHAPE_BACKWARDS))) in super_init_validation()
2288 mddev->reshape_backwards = 1; in super_init_validation()
2290 mddev->reshape_backwards = 0; in super_init_validation()
2292 mddev->reshape_position = le64_to_cpu(sb->reshape_position); in super_init_validation()
2293 rs->raid_type = get_raid_type_by_ll(mddev->level, mddev->layout); in super_init_validation()
2300 struct raid_type *rt_cur = get_raid_type_by_ll(mddev->level, mddev->layout); in super_init_validation()
2301 struct raid_type *rt_new = get_raid_type_by_ll(mddev->new_level, mddev->new_layout); in super_init_validation()
2303 if (rs_takeover_requested(rs)) { in super_init_validation()
2306 rt_cur->name, rt_new->name); in super_init_validation()
2309 return -EINVAL; in super_init_validation()
2310 } else if (rs_reshape_requested(rs)) { in super_init_validation()
2312 if (mddev->layout != mddev->new_layout) { in super_init_validation()
2315 rt_cur->name, rt_new->name); in super_init_validation()
2318 le32_to_cpu(sb->layout), mddev->new_layout); in super_init_validation()
2320 if (mddev->chunk_sectors != mddev->new_chunk_sectors) in super_init_validation()
2322 mddev->chunk_sectors, mddev->new_chunk_sectors); in super_init_validation()
2323 if (rs->delta_disks) in super_init_validation()
2325 mddev->raid_disks, mddev->raid_disks + rs->delta_disks); in super_init_validation()
2326 if (rs_is_raid10(rs)) { in super_init_validation()
2328 raid10_md_layout_to_format(mddev->layout), in super_init_validation()
2329 raid10_md_layout_to_copies(mddev->layout)); in super_init_validation()
2331 raid10_md_layout_to_format(mddev->new_layout), in super_init_validation()
2332 raid10_md_layout_to_copies(mddev->new_layout)); in super_init_validation()
2334 return -EINVAL; in super_init_validation()
2340 if (!test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) in super_init_validation()
2341 mddev->recovery_cp = le64_to_cpu(sb->array_resync_offset); in super_init_validation()
2346 * 1) The raid set is brand new - in which case, all of the in super_init_validation()
2350 * and the new device needs to be rebuilt - in which in super_init_validation()
2359 if (test_bit(Journal, &rdev->flags)) in super_init_validation()
2362 if (test_bit(FirstUse, &r->flags)) in super_init_validation()
2365 if (!test_bit(In_sync, &r->flags)) { in super_init_validation()
2367 r->raid_disk); in super_init_validation()
2370 if (test_bit(FirstUse, &r->flags)) in super_init_validation()
2375 if (new_devs == rs->raid_disks || !rebuilds) { in super_init_validation()
2377 if (new_devs == rs->raid_disks) { in super_init_validation()
2379 set_bit(MD_ARRAY_FIRST_USE, &mddev->flags); in super_init_validation()
2381 new_devs != rs->delta_disks) { in super_init_validation()
2384 return -EINVAL; in super_init_validation()
2388 " a raid set with %u other first-time devices", in super_init_validation()
2390 return -EINVAL; in super_init_validation()
2395 return -EINVAL; in super_init_validation()
2396 } else if (!test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags) && rs_is_recovering(rs)) { in super_init_validation()
2397 DMERR("'rebuild' specified while raid set is not in-sync (recovery_cp=%llu)", in super_init_validation()
2398 (unsigned long long) mddev->recovery_cp); in super_init_validation()
2399 return -EINVAL; in super_init_validation()
2400 } else if (rs_is_reshaping(rs)) { in super_init_validation()
2402 (unsigned long long) mddev->reshape_position); in super_init_validation()
2403 return -EINVAL; in super_init_validation()
2413 if (test_bit(Journal, &rdev->flags) || in super_init_validation()
2414 !r->sb_page) in super_init_validation()
2416 sb2 = page_address(r->sb_page); in super_init_validation()
2417 sb2->failed_devices = 0; in super_init_validation()
2418 memset(sb2->extended_failed_devices, 0, sizeof(sb2->extended_failed_devices)); in super_init_validation()
2421 * Check for any device re-ordering. in super_init_validation()
2423 if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) { in super_init_validation()
2424 role = le32_to_cpu(sb2->array_position); in super_init_validation()
2428 if (role != r->raid_disk) { in super_init_validation()
2429 if (rs_is_raid10(rs) && __is_raid10_near(mddev->layout)) { in super_init_validation()
2430 if (mddev->raid_disks % __raid10_near_copies(mddev->layout) || in super_init_validation()
2431 rs->raid_disks % rs->raid10_copies) { in super_init_validation()
2432 rs->ti->error = in super_init_validation()
2434 return -EINVAL; in super_init_validation()
2437 sb2->array_position = cpu_to_le32(r->raid_disk); in super_init_validation()
2439 } else if (!(rs_is_raid10(rs) && rt_is_raid0(rs->raid_type)) && in super_init_validation()
2440 !(rs_is_raid0(rs) && rt_is_raid10(rs->raid_type)) && in super_init_validation()
2441 !rt_is_raid1(rs->raid_type)) { in super_init_validation()
2442 rs->ti->error = "Cannot change device positions in raid set"; in super_init_validation()
2443 return -EINVAL; in super_init_validation()
2446 DMINFO("raid device #%d now at position #%d", role, r->raid_disk); in super_init_validation()
2454 set_bit(Faulty, &r->flags); in super_init_validation()
2461 static int super_validate(struct raid_set *rs, struct md_rdev *rdev) in super_validate() argument
2463 struct mddev *mddev = &rs->md; in super_validate()
2466 if (rs_is_raid0(rs) || !rdev->sb_page || rdev->raid_disk < 0) in super_validate()
2469 sb = page_address(rdev->sb_page); in super_validate()
2472 * If mddev->events is not set, we know we have not yet initialized in super_validate()
2475 if (!mddev->events && super_init_validation(rs, rdev)) in super_validate()
2476 return -EINVAL; in super_validate()
2478 if (le32_to_cpu(sb->compat_features) && in super_validate()
2479 le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) { in super_validate()
2480 rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags"; in super_validate()
2481 return -EINVAL; in super_validate()
2484 if (sb->incompat_features) { in super_validate()
2485 rs->ti->error = "Unable to assemble array: No incompatible feature flags supported yet"; in super_validate()
2486 return -EINVAL; in super_validate()
2489 /* Enable bitmap creation on @rs unless no metadevs or raid0 or journaled raid4/5/6 set. */ in super_validate()
2490 …mddev->bitmap_info.offset = (rt_is_raid0(rs->raid_type) || rs->journal_dev.dev) ? 0 : to_sector(40… in super_validate()
2491 mddev->bitmap_info.default_offset = mddev->bitmap_info.offset; in super_validate()
2493 if (!test_and_clear_bit(FirstUse, &rdev->flags)) { in super_validate()
2499 if (le32_to_cpu(sb->compat_features) & FEATURE_FLAG_SUPPORTS_V190) in super_validate()
2500 rdev->sectors = le64_to_cpu(sb->sectors); in super_validate()
2502 rdev->recovery_offset = le64_to_cpu(sb->disk_recovery_offset); in super_validate()
2503 if (rdev->recovery_offset == MaxSector) in super_validate()
2504 set_bit(In_sync, &rdev->flags); in super_validate()
2506 * If no reshape in progress -> we're recovering single in super_validate()
2507 * disk(s) and have to set the device(s) to out-of-sync in super_validate()
2509 else if (!rs_is_reshaping(rs)) in super_validate()
2510 clear_bit(In_sync, &rdev->flags); /* Mandatory for recovery */ in super_validate()
2516 if (test_and_clear_bit(Faulty, &rdev->flags)) { in super_validate()
2517 rdev->recovery_offset = 0; in super_validate()
2518 clear_bit(In_sync, &rdev->flags); in super_validate()
2519 rdev->saved_raid_disk = rdev->raid_disk; in super_validate()
2522 /* Reshape support -> restore respective data offsets */ in super_validate()
2523 rdev->data_offset = le64_to_cpu(sb->data_offset); in super_validate()
2524 rdev->new_data_offset = le64_to_cpu(sb->new_data_offset); in super_validate()
2532 static int analyse_superblocks(struct dm_target *ti, struct raid_set *rs) in analyse_superblocks() argument
2536 struct mddev *mddev = &rs->md; in analyse_superblocks()
2540 if (test_bit(Journal, &rdev->flags)) in analyse_superblocks()
2543 if (!rdev->meta_bdev) in analyse_superblocks()
2547 rdev->sb_start = 0; in analyse_superblocks()
2548 rdev->sb_size = bdev_logical_block_size(rdev->meta_bdev); in analyse_superblocks()
2549 if (rdev->sb_size < sizeof(struct dm_raid_superblock) || rdev->sb_size > PAGE_SIZE) { in analyse_superblocks()
2551 return -EINVAL; in analyse_superblocks()
2563 if (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags)) in analyse_superblocks()
2580 if (rs_is_raid0(rs)) in analyse_superblocks()
2586 * mistakenly acting as if '- -' got passed into the constructor). in analyse_superblocks()
2591 rdev->raid_disk = rdev->saved_raid_disk = -1; in analyse_superblocks()
2603 rs->ti->error = "Unable to assemble array: Invalid superblocks"; in analyse_superblocks()
2604 if (super_validate(rs, freshest)) in analyse_superblocks()
2605 return -EINVAL; in analyse_superblocks()
2607 if (validate_raid_redundancy(rs)) { in analyse_superblocks()
2608 rs->ti->error = "Insufficient redundancy to activate array"; in analyse_superblocks()
2609 return -EINVAL; in analyse_superblocks()
2613 if (!test_bit(Journal, &rdev->flags) && in analyse_superblocks()
2615 super_validate(rs, rdev)) in analyse_superblocks()
2616 return -EINVAL; in analyse_superblocks()
2621 * Adjust data_offset and new_data_offset on all disk members of @rs
2628 static int rs_adjust_data_offsets(struct raid_set *rs) in rs_adjust_data_offsets() argument
2634 if (!test_bit(__CTR_FLAG_DATA_OFFSET, &rs->ctr_flags)) { in rs_adjust_data_offsets()
2635 if (!rs_is_reshapable(rs)) in rs_adjust_data_offsets()
2642 rdev = &rs->dev[0].rdev; in rs_adjust_data_offsets()
2644 if (rs->delta_disks < 0) { in rs_adjust_data_offsets()
2648 * - before reshape: data is at offset 0 and free space in rs_adjust_data_offsets()
2651 * - after reshape: data is at offset rs->data_offset != 0 on each component LV in rs_adjust_data_offsets()
2654 new_data_offset = rs->data_offset; in rs_adjust_data_offsets()
2656 } else if (rs->delta_disks > 0) { in rs_adjust_data_offsets()
2660 * - before reshape: data is at offset rs->data_offset != 0 and in rs_adjust_data_offsets()
2663 * - after reshape: data is at offset 0 on each component LV in rs_adjust_data_offsets()
2665 data_offset = rs->data_offset; in rs_adjust_data_offsets()
2672 * - or - (data offset != 0) in rs_adjust_data_offsets()
2674 * Changing RAID layout or chunk size -> toggle offsets in rs_adjust_data_offsets()
2676 * - before reshape: data is at offset rs->data_offset 0 and in rs_adjust_data_offsets()
2678 * -or- in rs_adjust_data_offsets()
2679 * data is at offset rs->data_offset != 0 and in rs_adjust_data_offsets()
2682 * - after reshape: data is at offset 0 if it was at offset != 0 in rs_adjust_data_offsets()
2687 data_offset = rs->data_offset ? rdev->data_offset : 0; in rs_adjust_data_offsets()
2688 new_data_offset = data_offset ? 0 : rs->data_offset; in rs_adjust_data_offsets()
2689 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in rs_adjust_data_offsets()
2695 if (rs->data_offset && in rs_adjust_data_offsets()
2696 bdev_nr_sectors(rdev->bdev) - rs->md.dev_sectors < MIN_FREE_RESHAPE_SPACE) { in rs_adjust_data_offsets()
2697 rs->ti->error = data_offset ? "No space for forward reshape" : in rs_adjust_data_offsets()
2699 return -ENOSPC; in rs_adjust_data_offsets()
2706 if (rs->md.recovery_cp < rs->md.dev_sectors) in rs_adjust_data_offsets()
2707 rs->md.recovery_cp += rs->dev[0].rdev.data_offset; in rs_adjust_data_offsets()
2710 rdev_for_each(rdev, &rs->md) { in rs_adjust_data_offsets()
2711 if (!test_bit(Journal, &rdev->flags)) { in rs_adjust_data_offsets()
2712 rdev->data_offset = data_offset; in rs_adjust_data_offsets()
2713 rdev->new_data_offset = new_data_offset; in rs_adjust_data_offsets()
2720 /* Userpace reordered disks -> adjust raid_disk indexes in @rs */
2721 static void __reorder_raid_disk_indexes(struct raid_set *rs) in __reorder_raid_disk_indexes() argument
2726 rdev_for_each(rdev, &rs->md) { in __reorder_raid_disk_indexes()
2727 if (!test_bit(Journal, &rdev->flags)) { in __reorder_raid_disk_indexes()
2728 rdev->raid_disk = i++; in __reorder_raid_disk_indexes()
2729 rdev->saved_raid_disk = rdev->new_raid_disk = -1; in __reorder_raid_disk_indexes()
2735 * Setup @rs for takeover by a different raid level
2737 static int rs_setup_takeover(struct raid_set *rs) in rs_setup_takeover() argument
2739 struct mddev *mddev = &rs->md; in rs_setup_takeover()
2741 unsigned int d = mddev->raid_disks = rs->raid_disks; in rs_setup_takeover()
2742 sector_t new_data_offset = rs->dev[0].rdev.data_offset ? 0 : rs->data_offset; in rs_setup_takeover()
2744 if (rt_is_raid10(rs->raid_type)) { in rs_setup_takeover()
2745 if (rs_is_raid0(rs)) { in rs_setup_takeover()
2746 /* Userpace reordered disks -> adjust raid_disk indexes */ in rs_setup_takeover()
2747 __reorder_raid_disk_indexes(rs); in rs_setup_takeover()
2749 /* raid0 -> raid10_far layout */ in rs_setup_takeover()
2750 mddev->layout = raid10_format_to_md_layout(rs, ALGORITHM_RAID10_FAR, in rs_setup_takeover()
2751 rs->raid10_copies); in rs_setup_takeover()
2752 } else if (rs_is_raid1(rs)) in rs_setup_takeover()
2753 /* raid1 -> raid10_near layout */ in rs_setup_takeover()
2754 mddev->layout = raid10_format_to_md_layout(rs, ALGORITHM_RAID10_NEAR, in rs_setup_takeover()
2755 rs->raid_disks); in rs_setup_takeover()
2757 return -EINVAL; in rs_setup_takeover()
2761 clear_bit(MD_ARRAY_FIRST_USE, &mddev->flags); in rs_setup_takeover()
2762 mddev->recovery_cp = MaxSector; in rs_setup_takeover()
2764 while (d--) { in rs_setup_takeover()
2765 rdev = &rs->dev[d].rdev; in rs_setup_takeover()
2767 if (test_bit(d, (void *) rs->rebuild_disks)) { in rs_setup_takeover()
2768 clear_bit(In_sync, &rdev->flags); in rs_setup_takeover()
2769 clear_bit(Faulty, &rdev->flags); in rs_setup_takeover()
2770 mddev->recovery_cp = rdev->recovery_offset = 0; in rs_setup_takeover()
2772 set_bit(MD_ARRAY_FIRST_USE, &mddev->flags); in rs_setup_takeover()
2775 rdev->new_data_offset = new_data_offset; in rs_setup_takeover()
2781 /* Prepare @rs for reshape */
2782 static int rs_prepare_reshape(struct raid_set *rs) in rs_prepare_reshape() argument
2785 struct mddev *mddev = &rs->md; in rs_prepare_reshape()
2787 if (rs_is_raid10(rs)) { in rs_prepare_reshape()
2788 if (rs->raid_disks != mddev->raid_disks && in rs_prepare_reshape()
2789 __is_raid10_near(mddev->layout) && in rs_prepare_reshape()
2790 rs->raid10_copies && in rs_prepare_reshape()
2791 rs->raid10_copies != __raid10_near_copies(mddev->layout)) { in rs_prepare_reshape()
2798 if (rs->raid_disks % rs->raid10_copies) { in rs_prepare_reshape()
2799 rs->ti->error = "Can't reshape raid10 mirror groups"; in rs_prepare_reshape()
2800 return -EINVAL; in rs_prepare_reshape()
2803 /* Userpace reordered disks to add/remove mirrors -> adjust raid_disk indexes */ in rs_prepare_reshape()
2804 __reorder_raid_disk_indexes(rs); in rs_prepare_reshape()
2805 mddev->layout = raid10_format_to_md_layout(rs, ALGORITHM_RAID10_NEAR, in rs_prepare_reshape()
2806 rs->raid10_copies); in rs_prepare_reshape()
2807 mddev->new_layout = mddev->layout; in rs_prepare_reshape()
2812 } else if (rs_is_raid456(rs)) in rs_prepare_reshape()
2815 else if (rs_is_raid1(rs)) { in rs_prepare_reshape()
2816 if (rs->delta_disks) { in rs_prepare_reshape()
2818 mddev->degraded = rs->delta_disks < 0 ? -rs->delta_disks : rs->delta_disks; in rs_prepare_reshape()
2822 mddev->raid_disks = rs->raid_disks; in rs_prepare_reshape()
2826 rs->ti->error = "Called with bogus raid type"; in rs_prepare_reshape()
2827 return -EINVAL; in rs_prepare_reshape()
2831 set_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags); in rs_prepare_reshape()
2832 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in rs_prepare_reshape()
2833 } else if (mddev->raid_disks < rs->raid_disks) in rs_prepare_reshape()
2835 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in rs_prepare_reshape()
2842 * - change raid layout
2843 * - change chunk size
2844 * - add disks
2845 * - remove disks
2847 static int rs_setup_reshape(struct raid_set *rs) in rs_setup_reshape() argument
2851 sector_t reshape_sectors = _get_reshape_sectors(rs); in rs_setup_reshape()
2852 struct mddev *mddev = &rs->md; in rs_setup_reshape()
2855 mddev->delta_disks = rs->delta_disks; in rs_setup_reshape()
2856 cur_raid_devs = mddev->raid_disks; in rs_setup_reshape()
2859 if (mddev->delta_disks && in rs_setup_reshape()
2860 mddev->layout != mddev->new_layout) { in rs_setup_reshape()
2861 DMINFO("Ignoring invalid layout change with delta_disks=%d", rs->delta_disks); in rs_setup_reshape()
2862 mddev->new_layout = mddev->layout; in rs_setup_reshape()
2868 * - in case of adding disk(s), array size has in rs_setup_reshape()
2874 * - in case of removing disk(s), array size in rs_setup_reshape()
2880 * - data_offset and new_data_offset are in rs_setup_reshape()
2888 if (rs->delta_disks > 0) { in rs_setup_reshape()
2890 for (d = cur_raid_devs; d < rs->raid_disks; d++) { in rs_setup_reshape()
2891 rdev = &rs->dev[d].rdev; in rs_setup_reshape()
2892 clear_bit(In_sync, &rdev->flags); in rs_setup_reshape()
2895 * save_raid_disk needs to be -1, or recovery_offset will be set to 0 in rs_setup_reshape()
2898 rdev->saved_raid_disk = -1; in rs_setup_reshape()
2899 rdev->raid_disk = d; in rs_setup_reshape()
2901 rdev->sectors = mddev->dev_sectors; in rs_setup_reshape()
2902 rdev->recovery_offset = rs_is_raid1(rs) ? 0 : MaxSector; in rs_setup_reshape()
2905 mddev->reshape_backwards = 0; /* adding disk(s) -> forward reshape */ in rs_setup_reshape()
2908 } else if (rs->delta_disks < 0) { in rs_setup_reshape()
2909 r = rs_set_dev_and_array_sectors(rs, rs->ti->len, true); in rs_setup_reshape()
2910 mddev->reshape_backwards = 1; /* removing disk(s) -> backward reshape */ in rs_setup_reshape()
2915 * Reshape layout (e.g. raid5_ls -> raid5_n) and/or chunk size: in rs_setup_reshape()
2917 * keeping number of disks and do layout change -> in rs_setup_reshape()
2921 * - free space upfront -> reshape forward in rs_setup_reshape()
2923 * - free space at the end -> reshape backward in rs_setup_reshape()
2932 * add disk(s) -> begin in rs_setup_reshape()
2933 * remove disk(s)-> end in rs_setup_reshape()
2935 mddev->reshape_backwards = rs->dev[0].rdev.data_offset ? 0 : 1; in rs_setup_reshape()
2942 if (!mddev->reshape_backwards) in rs_setup_reshape()
2943 rdev_for_each(rdev, &rs->md) in rs_setup_reshape()
2944 if (!test_bit(Journal, &rdev->flags)) in rs_setup_reshape()
2945 rdev->sectors += reshape_sectors; in rs_setup_reshape()
2953 * changes -> reset the latter.
2955 static void rs_reset_inconclusive_reshape(struct raid_set *rs) in rs_reset_inconclusive_reshape() argument
2957 if (!rs_is_reshaping(rs) && rs_is_layout_change(rs, true)) { in rs_reset_inconclusive_reshape()
2958 rs_set_cur(rs); in rs_reset_inconclusive_reshape()
2959 rs->md.delta_disks = 0; in rs_reset_inconclusive_reshape()
2960 rs->md.reshape_backwards = 0; in rs_reset_inconclusive_reshape()
2968 static void configure_discard_support(struct raid_set *rs) in configure_discard_support() argument
2972 struct dm_target *ti = rs->ti; in configure_discard_support()
2977 raid456 = rs_is_raid456(rs); in configure_discard_support()
2979 for (i = 0; i < rs->raid_disks; i++) { in configure_discard_support()
2980 if (!rs->dev[i].rdev.bdev || in configure_discard_support()
2981 !bdev_max_discard_sectors(rs->dev[i].rdev.bdev)) in configure_discard_support()
2987 DMERR("Set dm-raid.devices_handle_discard_safely=Y to override."); in configure_discard_support()
2993 ti->num_discard_bios = 1; in configure_discard_support()
3016 struct raid_set *rs = NULL; in raid_ctr() local
3027 ti->error = "No arguments"; in raid_ctr()
3028 return -EINVAL; in raid_ctr()
3033 ti->error = "Unrecognised raid_type"; in raid_ctr()
3034 return -EINVAL; in raid_ctr()
3038 if (dm_read_arg_group(_args, &as, &num_raid_params, &ti->error)) in raid_ctr()
3039 return -EINVAL; in raid_ctr()
3044 _args[1].max = (as_nrd.argc - 1) / 2; in raid_ctr()
3045 if (dm_read_arg(_args + 1, &as_nrd, &num_raid_devs, &ti->error)) in raid_ctr()
3046 return -EINVAL; in raid_ctr()
3049 ti->error = "Invalid number of supplied raid devices"; in raid_ctr()
3050 return -EINVAL; in raid_ctr()
3053 rs = raid_set_alloc(ti, rt, num_raid_devs); in raid_ctr()
3054 if (IS_ERR(rs)) in raid_ctr()
3055 return PTR_ERR(rs); in raid_ctr()
3057 r = parse_raid_params(rs, &as, num_raid_params); in raid_ctr()
3061 r = parse_dev_params(rs, &as); in raid_ctr()
3065 rs->md.sync_super = super_sync; in raid_ctr()
3073 r = rs_set_dev_and_array_sectors(rs, rs->ti->len, false); in raid_ctr()
3078 rs->array_sectors = rs->md.array_sectors; in raid_ctr()
3079 rs->dev_sectors = rs->md.dev_sectors; in raid_ctr()
3086 rs_config_backup(rs, &rs_layout); in raid_ctr()
3088 r = analyse_superblocks(ti, rs); in raid_ctr()
3092 /* All in-core metadata now as of current superblocks after calling analyse_superblocks() */ in raid_ctr()
3093 sb_array_sectors = rs->md.array_sectors; in raid_ctr()
3094 rdev_sectors = __rdev_sectors(rs); in raid_ctr()
3096 ti->error = "Invalid rdev size"; in raid_ctr()
3097 r = -EINVAL; in raid_ctr()
3102 reshape_sectors = _get_reshape_sectors(rs); in raid_ctr()
3103 if (rs->dev_sectors != rdev_sectors) { in raid_ctr()
3104 resize = (rs->dev_sectors != rdev_sectors - reshape_sectors); in raid_ctr()
3105 if (rs->dev_sectors > rdev_sectors - reshape_sectors) in raid_ctr()
3106 set_bit(RT_FLAG_RS_GROW, &rs->runtime_flags); in raid_ctr()
3109 INIT_WORK(&rs->md.event_work, do_table_event); in raid_ctr()
3110 ti->private = rs; in raid_ctr()
3111 ti->num_flush_bios = 1; in raid_ctr()
3112 ti->needs_bio_set_dev = true; in raid_ctr()
3115 rs_config_restore(rs, &rs_layout); in raid_ctr()
3123 if (test_bit(MD_ARRAY_FIRST_USE, &rs->md.flags)) { in raid_ctr()
3124 /* A new raid6 set has to be recovered to ensure proper parity and Q-Syndrome */ in raid_ctr()
3125 if (rs_is_raid6(rs) && in raid_ctr()
3126 test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) { in raid_ctr()
3127 ti->error = "'nosync' not allowed for new raid6 set"; in raid_ctr()
3128 r = -EINVAL; in raid_ctr()
3131 rs_setup_recovery(rs, 0); in raid_ctr()
3132 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in raid_ctr()
3133 rs_set_new(rs); in raid_ctr()
3134 } else if (rs_is_recovering(rs)) { in raid_ctr()
3137 } else if (rs_is_reshaping(rs)) { in raid_ctr()
3140 ti->error = "Can't resize a reshaping raid set"; in raid_ctr()
3141 r = -EPERM; in raid_ctr()
3144 /* skip setup rs */ in raid_ctr()
3145 } else if (rs_takeover_requested(rs)) { in raid_ctr()
3146 if (rs_is_reshaping(rs)) { in raid_ctr()
3147 ti->error = "Can't takeover a reshaping raid set"; in raid_ctr()
3148 r = -EPERM; in raid_ctr()
3153 if (test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { in raid_ctr()
3154 ti->error = "Can't takeover a journaled raid4/5/6 set"; in raid_ctr()
3155 r = -EPERM; in raid_ctr()
3167 r = rs_check_takeover(rs); in raid_ctr()
3171 r = rs_setup_takeover(rs); in raid_ctr()
3175 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in raid_ctr()
3177 rs_setup_recovery(rs, MaxSector); in raid_ctr()
3178 rs_set_new(rs); in raid_ctr()
3179 } else if (rs_reshape_requested(rs)) { in raid_ctr()
3181 clear_bit(RT_FLAG_RS_GROW, &rs->runtime_flags); in raid_ctr()
3189 if (test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { in raid_ctr()
3190 ti->error = "Can't reshape a journaled raid4/5/6 set"; in raid_ctr()
3191 r = -EPERM; in raid_ctr()
3195 /* Out-of-place space has to be available to allow for a reshape unless raid1! */ in raid_ctr()
3196 if (reshape_sectors || rs_is_raid1(rs)) { in raid_ctr()
3204 r = rs_prepare_reshape(rs); in raid_ctr()
3209 rs_setup_recovery(rs, MaxSector); in raid_ctr()
3211 rs_set_cur(rs); in raid_ctr()
3215 if (test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags)) { in raid_ctr()
3216 clear_bit(RT_FLAG_RS_GROW, &rs->runtime_flags); in raid_ctr()
3217 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in raid_ctr()
3218 rs_setup_recovery(rs, MaxSector); in raid_ctr()
3219 } else if (test_bit(RT_FLAG_RS_GROW, &rs->runtime_flags)) { in raid_ctr()
3224 r = rs_set_dev_and_array_sectors(rs, sb_array_sectors, false); in raid_ctr()
3228 …rs_setup_recovery(rs, rs->md.recovery_cp < rs->md.dev_sectors ? rs->md.recovery_cp : rs->md.dev_se… in raid_ctr()
3231 r = rs_set_dev_and_array_sectors(rs, rs->ti->len, false); in raid_ctr()
3235 if (sb_array_sectors > rs->array_sectors) in raid_ctr()
3236 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in raid_ctr()
3238 rs_set_cur(rs); in raid_ctr()
3242 r = rs_adjust_data_offsets(rs); in raid_ctr()
3247 rs_reset_inconclusive_reshape(rs); in raid_ctr()
3249 /* Start raid set read-only and assumed clean to change in raid_resume() */ in raid_ctr()
3250 rs->md.ro = 1; in raid_ctr()
3251 rs->md.in_sync = 1; in raid_ctr()
3254 mddev_suspend_and_lock_nointr(&rs->md); in raid_ctr()
3257 md_frozen_sync_thread(&rs->md); in raid_ctr()
3259 r = md_run(&rs->md); in raid_ctr()
3260 rs->md.in_sync = 0; /* Assume already marked dirty */ in raid_ctr()
3262 ti->error = "Failed to run raid array"; in raid_ctr()
3263 mddev_unlock(&rs->md); in raid_ctr()
3267 r = md_start(&rs->md); in raid_ctr()
3269 ti->error = "Failed to start raid array"; in raid_ctr()
3273 /* If raid4/5/6 journal mode explicitly requested (only possible with journal dev) -> set it */ in raid_ctr()
3274 if (test_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) { in raid_ctr()
3275 r = r5c_journal_mode_set(&rs->md, rs->journal_dev.mode); in raid_ctr()
3277 ti->error = "Failed to set raid4/5/6 journal mode"; in raid_ctr()
3282 set_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags); in raid_ctr()
3285 if (rs_is_raid456(rs)) { in raid_ctr()
3286 r = rs_set_raid456_stripe_cache(rs); in raid_ctr()
3292 if (test_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags)) { in raid_ctr()
3293 r = rs_check_reshape(rs); in raid_ctr()
3298 rs_config_restore(rs, &rs_layout); in raid_ctr()
3300 if (rs->md.pers->start_reshape) { in raid_ctr()
3301 r = rs->md.pers->check_reshape(&rs->md); in raid_ctr()
3303 ti->error = "Reshape check failed"; in raid_ctr()
3310 configure_discard_support(rs); in raid_ctr()
3312 mddev_unlock(&rs->md); in raid_ctr()
3316 md_stop(&rs->md); in raid_ctr()
3317 mddev_unlock(&rs->md); in raid_ctr()
3319 raid_set_free(rs); in raid_ctr()
3326 struct raid_set *rs = ti->private; in raid_dtr() local
3328 mddev_lock_nointr(&rs->md); in raid_dtr()
3329 md_stop(&rs->md); in raid_dtr()
3330 mddev_unlock(&rs->md); in raid_dtr()
3332 if (work_pending(&rs->md.event_work)) in raid_dtr()
3333 flush_work(&rs->md.event_work); in raid_dtr()
3334 raid_set_free(rs); in raid_dtr()
3339 struct raid_set *rs = ti->private; in raid_map() local
3340 struct mddev *mddev = &rs->md; in raid_map()
3343 * If we're reshaping to add disk(s), ti->len and in raid_map()
3344 * mddev->array_sectors will differ during the process in raid_map()
3345 * (ti->len > mddev->array_sectors), so we have to requeue in raid_map()
3346 * bios with addresses > mddev->array_sectors here or in raid_map()
3350 if (unlikely(bio_has_data(bio) && bio_end_sector(bio) > mddev->array_sectors)) in raid_map()
3374 return __within_range(state, 0, ARRAY_SIZE(sync_strs) - 1) ? sync_strs[state] : "undef"; in sync_str()
3386 (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &recovery)))) { in decipher_sync_action()
3401 if (mddev->reshape_position != MaxSector) in decipher_sync_action()
3414 * 'a' = Alive but not in-sync raid set component _or_ alive raid4/5/6 'write_back' journal device
3415 * 'A' = Alive and in-sync raid set component _or_ alive raid4/5/6 'write_through' journal device
3416 * '-' = Non-existing device (i.e. uspace passed '- -' into the ctr)
3418 static const char *__raid_dev_status(struct raid_set *rs, struct md_rdev *rdev) in __raid_dev_status() argument
3420 if (!rdev->bdev) in __raid_dev_status()
3421 return "-"; in __raid_dev_status()
3422 else if (test_bit(Faulty, &rdev->flags)) in __raid_dev_status()
3424 else if (test_bit(Journal, &rdev->flags)) in __raid_dev_status()
3425 return (rs->journal_dev.mode == R5C_JOURNAL_MODE_WRITE_THROUGH) ? "A" : "a"; in __raid_dev_status()
3426 else if (test_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags) || in __raid_dev_status()
3427 (!test_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags) && in __raid_dev_status()
3428 !test_bit(In_sync, &rdev->flags))) in __raid_dev_status()
3434 /* Helper to return resync/reshape progress for @rs and runtime flags for raid set in sync / resync…
3435 static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery, in rs_get_progress() argument
3439 struct mddev *mddev = &rs->md; in rs_get_progress()
3441 clear_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3442 clear_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); in rs_get_progress()
3444 if (rs_is_raid0(rs)) { in rs_get_progress()
3446 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3450 r = mddev->recovery_cp; in rs_get_progress()
3452 r = mddev->curr_resync_completed; in rs_get_progress()
3460 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3477 set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); in rs_get_progress()
3485 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3490 * caused by components still set to in-sync by constructor. in rs_get_progress()
3492 set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); in rs_get_progress()
3503 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3505 if (!test_bit(Journal, &rdev->flags) && in rs_get_progress()
3506 !test_bit(In_sync, &rdev->flags)) { in rs_get_progress()
3507 clear_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3516 /* Helper to return @dev name or "-" if !@dev */
3519 return dev ? dev->name : "-"; in __get_dev_name()
3525 struct raid_set *rs = ti->private; in raid_status() local
3526 struct mddev *mddev = &rs->md; in raid_status()
3527 struct r5conf *conf = rs_is_raid456(rs) ? mddev->private : NULL; in raid_status()
3528 int i, max_nr_stripes = conf ? conf->max_nr_stripes : 0; in raid_status()
3540 rt = get_raid_type_by_ll(mddev->new_level, mddev->new_layout); in raid_status()
3544 DMEMIT("%s %d ", rt->name, mddev->raid_disks); in raid_status()
3549 resync_max_sectors = test_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags) ? in raid_status()
3550 mddev->resync_max_sectors : mddev->dev_sectors; in raid_status()
3551 recovery = rs->md.recovery; in raid_status()
3553 progress = rs_get_progress(rs, recovery, state, resync_max_sectors); in raid_status()
3554 resync_mismatches = mddev->last_sync_action == ACTION_CHECK ? in raid_status()
3555 atomic64_read(&mddev->resync_mismatches) : 0; in raid_status()
3557 /* HM FIXME: do we want another state char for raid0? It shows 'D'/'A'/'-' now */ in raid_status()
3558 for (i = 0; i < rs->raid_disks; i++) in raid_status()
3559 DMEMIT(__raid_dev_status(rs, &rs->dev[i].rdev)); in raid_status()
3562 * In-sync/Reshape ratio: in raid_status()
3563 * The in-sync ratio shows the progress of: in raid_status()
3564 * - Initializing the raid set in raid_status()
3565 * - Rebuilding a subset of devices of the raid set in raid_status()
3580 * See Documentation/admin-guide/device-mapper/dm-raid.rst for in raid_status()
3604 DMEMIT(" %llu", (unsigned long long) rs->dev[0].rdev.data_offset); in raid_status()
3609 DMEMIT(" %s", test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags) ? in raid_status()
3610 __raid_dev_status(rs, &rs->journal_dev.rdev) : "-"); in raid_status()
3620 for (i = 0; i < rs->raid_disks; i++) { in raid_status()
3621 rebuild_writemostly_count += (test_bit(i, (void *) rs->rebuild_disks) ? 2 : 0) + in raid_status()
3622 (test_bit(WriteMostly, &rs->dev[i].rdev.flags) ? 2 : 0); in raid_status()
3624 rebuild_writemostly_count -= (test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags) ? 2 : 0) + in raid_status()
3625 (test_bit(__CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags) ? 2 : 0); in raid_status()
3628 hweight32(rs->ctr_flags & CTR_FLAG_OPTIONS_NO_ARGS) + in raid_status()
3629 hweight32(rs->ctr_flags & CTR_FLAG_OPTIONS_ONE_ARG) * 2; in raid_status()
3632 DMEMIT("%s %u %u", rs->raid_type->name, raid_param_cnt, mddev->new_chunk_sectors); in raid_status()
3633 if (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags)) in raid_status()
3635 if (test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) in raid_status()
3637 if (test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags)) in raid_status()
3638 for (i = 0; i < rs->raid_disks; i++) in raid_status()
3639 if (test_bit(i, (void *) rs->rebuild_disks)) in raid_status()
3641 if (test_bit(__CTR_FLAG_DAEMON_SLEEP, &rs->ctr_flags)) in raid_status()
3643 mddev->bitmap_info.daemon_sleep); in raid_status()
3644 if (test_bit(__CTR_FLAG_MIN_RECOVERY_RATE, &rs->ctr_flags)) in raid_status()
3646 mddev->sync_speed_min); in raid_status()
3647 if (test_bit(__CTR_FLAG_MAX_RECOVERY_RATE, &rs->ctr_flags)) in raid_status()
3649 mddev->sync_speed_max); in raid_status()
3650 if (test_bit(__CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags)) in raid_status()
3651 for (i = 0; i < rs->raid_disks; i++) in raid_status()
3652 if (test_bit(WriteMostly, &rs->dev[i].rdev.flags)) in raid_status()
3654 rs->dev[i].rdev.raid_disk); in raid_status()
3655 if (test_bit(__CTR_FLAG_MAX_WRITE_BEHIND, &rs->ctr_flags)) in raid_status()
3657 mddev->bitmap_info.max_write_behind); in raid_status()
3658 if (test_bit(__CTR_FLAG_STRIPE_CACHE, &rs->ctr_flags)) in raid_status()
3661 if (test_bit(__CTR_FLAG_REGION_SIZE, &rs->ctr_flags)) in raid_status()
3663 (unsigned long long) to_sector(mddev->bitmap_info.chunksize)); in raid_status()
3664 if (test_bit(__CTR_FLAG_RAID10_COPIES, &rs->ctr_flags)) in raid_status()
3666 raid10_md_layout_to_copies(mddev->layout)); in raid_status()
3667 if (test_bit(__CTR_FLAG_RAID10_FORMAT, &rs->ctr_flags)) in raid_status()
3669 raid10_md_layout_to_format(mddev->layout)); in raid_status()
3670 if (test_bit(__CTR_FLAG_DELTA_DISKS, &rs->ctr_flags)) in raid_status()
3672 max(rs->delta_disks, mddev->delta_disks)); in raid_status()
3673 if (test_bit(__CTR_FLAG_DATA_OFFSET, &rs->ctr_flags)) in raid_status()
3675 (unsigned long long) rs->data_offset); in raid_status()
3676 if (test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) in raid_status()
3678 __get_dev_name(rs->journal_dev.dev)); in raid_status()
3679 if (test_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) in raid_status()
3681 md_journal_mode_to_dm_raid(rs->journal_dev.mode)); in raid_status()
3682 DMEMIT(" %d", rs->raid_disks); in raid_status()
3683 for (i = 0; i < rs->raid_disks; i++) in raid_status()
3684 DMEMIT(" %s %s", __get_dev_name(rs->dev[i].meta_dev), in raid_status()
3685 __get_dev_name(rs->dev[i].data_dev)); in raid_status()
3689 rt = get_raid_type_by_ll(mddev->new_level, mddev->new_layout); in raid_status()
3693 DMEMIT_TARGET_NAME_VERSION(ti->type); in raid_status()
3694 DMEMIT(",raid_type=%s,raid_disks=%d", rt->name, mddev->raid_disks); in raid_status()
3698 recovery = rs->md.recovery; in raid_status()
3702 for (i = 0; i < rs->raid_disks; i++) { in raid_status()
3704 DMEMIT(__raid_dev_status(rs, &rs->dev[i].rdev)); in raid_status()
3709 switch (rs->journal_dev.mode) { in raid_status()
3731 struct raid_set *rs = ti->private; in raid_message() local
3732 struct mddev *mddev = &rs->md; in raid_message()
3735 if (!mddev->pers || !mddev->pers->sync_request) in raid_message()
3736 return -EINVAL; in raid_message()
3738 if (test_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags) || in raid_message()
3739 test_bit(RT_FLAG_RS_FROZEN, &rs->runtime_flags)) in raid_message()
3740 return -EBUSY; in raid_message()
3758 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); in raid_message()
3759 if (decipher_sync_action(mddev, mddev->recovery) != st_idle) in raid_message()
3760 return -EBUSY; in raid_message()
3764 set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); in raid_message()
3767 set_bit(MD_RECOVERY_CHECK, &mddev->recovery); in raid_message()
3768 set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); in raid_message()
3769 set_bit(MD_RECOVERY_SYNC, &mddev->recovery); in raid_message()
3771 set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); in raid_message()
3772 set_bit(MD_RECOVERY_SYNC, &mddev->recovery); in raid_message()
3774 return -EINVAL; in raid_message()
3776 if (mddev->ro == 2) { in raid_message()
3778 * canceling read-auto mode in raid_message()
3780 mddev->ro = 0; in raid_message()
3781 if (!mddev->suspended) in raid_message()
3782 md_wakeup_thread(mddev->sync_thread); in raid_message()
3784 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); in raid_message()
3785 if (!mddev->suspended) in raid_message()
3786 md_wakeup_thread(mddev->thread); in raid_message()
3794 struct raid_set *rs = ti->private; in raid_iterate_devices() local
3798 for (i = 0; !r && i < rs->raid_disks; i++) { in raid_iterate_devices()
3799 if (rs->dev[i].data_dev) { in raid_iterate_devices()
3800 r = fn(ti, rs->dev[i].data_dev, in raid_iterate_devices()
3802 rs->md.dev_sectors, data); in raid_iterate_devices()
3811 struct raid_set *rs = ti->private; in raid_io_hints() local
3812 unsigned int chunk_size_bytes = to_bytes(rs->md.chunk_sectors); in raid_io_hints()
3814 limits->io_min = chunk_size_bytes; in raid_io_hints()
3815 limits->io_opt = chunk_size_bytes * mddev_data_stripes(rs); in raid_io_hints()
3820 struct raid_set *rs = ti->private; in raid_presuspend() local
3821 struct mddev *mddev = &rs->md; in raid_presuspend()
3827 set_bit(RT_FLAG_RS_FROZEN, &rs->runtime_flags); in raid_presuspend()
3837 if (mddev->pers && mddev->pers->prepare_suspend) in raid_presuspend()
3838 mddev->pers->prepare_suspend(mddev); in raid_presuspend()
3843 struct raid_set *rs = ti->private; in raid_presuspend_undo() local
3845 clear_bit(RT_FLAG_RS_FROZEN, &rs->runtime_flags); in raid_presuspend_undo()
3850 struct raid_set *rs = ti->private; in raid_postsuspend() local
3852 if (!test_and_set_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags)) { in raid_postsuspend()
3857 md_stop_writes(&rs->md); in raid_postsuspend()
3858 mddev_suspend(&rs->md, false); in raid_postsuspend()
3862 static void attempt_restore_of_faulty_devices(struct raid_set *rs) in attempt_restore_of_faulty_devices() argument
3869 struct mddev *mddev = &rs->md; in attempt_restore_of_faulty_devices()
3873 if (!mddev->pers || !mddev->pers->hot_add_disk || !mddev->pers->hot_remove_disk) in attempt_restore_of_faulty_devices()
3878 for (i = 0; i < rs->raid_disks; i++) { in attempt_restore_of_faulty_devices()
3879 r = &rs->dev[i].rdev; in attempt_restore_of_faulty_devices()
3881 if (test_bit(Journal, &r->flags)) in attempt_restore_of_faulty_devices()
3884 if (test_bit(Faulty, &r->flags) && in attempt_restore_of_faulty_devices()
3885 r->meta_bdev && !read_disk_sb(r, r->sb_size, true)) { in attempt_restore_of_faulty_devices()
3888 rs->raid_type->name, i); in attempt_restore_of_faulty_devices()
3896 * '>= 0' - meaning we must call this function in attempt_restore_of_faulty_devices()
3899 flags = r->flags; in attempt_restore_of_faulty_devices()
3900 clear_bit(In_sync, &r->flags); /* Mandatory for hot remove. */ in attempt_restore_of_faulty_devices()
3901 if (r->raid_disk >= 0) { in attempt_restore_of_faulty_devices()
3902 if (mddev->pers->hot_remove_disk(mddev, r)) { in attempt_restore_of_faulty_devices()
3904 r->flags = flags; in attempt_restore_of_faulty_devices()
3908 r->raid_disk = r->saved_raid_disk = i; in attempt_restore_of_faulty_devices()
3910 clear_bit(Faulty, &r->flags); in attempt_restore_of_faulty_devices()
3911 clear_bit(WriteErrorSeen, &r->flags); in attempt_restore_of_faulty_devices()
3913 if (mddev->pers->hot_add_disk(mddev, r)) { in attempt_restore_of_faulty_devices()
3915 r->raid_disk = r->saved_raid_disk = -1; in attempt_restore_of_faulty_devices()
3916 r->flags = flags; in attempt_restore_of_faulty_devices()
3918 clear_bit(In_sync, &r->flags); in attempt_restore_of_faulty_devices()
3919 r->recovery_offset = 0; in attempt_restore_of_faulty_devices()
3930 rdev_for_each(r, &rs->md) { in attempt_restore_of_faulty_devices()
3931 if (test_bit(Journal, &r->flags)) in attempt_restore_of_faulty_devices()
3934 sb = page_address(r->sb_page); in attempt_restore_of_faulty_devices()
3945 static int __load_dirty_region_bitmap(struct raid_set *rs) in __load_dirty_region_bitmap() argument
3950 if (!rs_is_raid0(rs) && in __load_dirty_region_bitmap()
3951 !test_and_set_bit(RT_FLAG_RS_BITMAP_LOADED, &rs->runtime_flags)) { in __load_dirty_region_bitmap()
3952 struct mddev *mddev = &rs->md; in __load_dirty_region_bitmap()
3954 r = mddev->bitmap_ops->load(mddev); in __load_dirty_region_bitmap()
3963 static void rs_update_sbs(struct raid_set *rs) in rs_update_sbs() argument
3965 struct mddev *mddev = &rs->md; in rs_update_sbs()
3966 int ro = mddev->ro; in rs_update_sbs()
3968 set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); in rs_update_sbs()
3969 mddev->ro = 0; in rs_update_sbs()
3971 mddev->ro = ro; in rs_update_sbs()
3975 * Reshape changes raid algorithm of @rs to new one within personality
3976 * (e.g. raid6_zr -> raid6_nc), changes stripe size, adds/removes
3981 static int rs_start_reshape(struct raid_set *rs) in rs_start_reshape() argument
3984 struct mddev *mddev = &rs->md; in rs_start_reshape()
3985 struct md_personality *pers = mddev->pers; in rs_start_reshape()
3988 set_bit(MD_RECOVERY_WAIT, &mddev->recovery); in rs_start_reshape()
3990 r = rs_setup_reshape(rs); in rs_start_reshape()
3997 * May as well already kick the reshape off so that * pers->start_reshape() becomes optional. in rs_start_reshape()
3999 r = pers->check_reshape(mddev); in rs_start_reshape()
4001 rs->ti->error = "pers->check_reshape() failed"; in rs_start_reshape()
4009 if (pers->start_reshape) { in rs_start_reshape()
4010 r = pers->start_reshape(mddev); in rs_start_reshape()
4012 rs->ti->error = "pers->start_reshape() failed"; in rs_start_reshape()
4022 rs_update_sbs(rs); in rs_start_reshape()
4030 struct raid_set *rs = ti->private; in raid_preresume() local
4031 struct mddev *mddev = &rs->md; in raid_preresume()
4033 /* This is a resume after a suspend of the set -> it's already started. */ in raid_preresume()
4034 if (test_and_set_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags)) in raid_preresume()
4038 if (!test_bit(RT_FLAG_RS_GROW, &rs->runtime_flags) && in raid_preresume()
4039 rs->array_sectors != mddev->array_sectors) in raid_preresume()
4040 rs_set_capacity(rs); in raid_preresume()
4048 if (test_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags)) in raid_preresume()
4049 rs_update_sbs(rs); in raid_preresume()
4052 r = __load_dirty_region_bitmap(rs); in raid_preresume()
4057 if (test_bit(RT_FLAG_RS_GROW, &rs->runtime_flags)) { in raid_preresume()
4058 mddev->array_sectors = rs->array_sectors; in raid_preresume()
4059 mddev->dev_sectors = rs->dev_sectors; in raid_preresume()
4060 rs_set_rdev_sectors(rs); in raid_preresume()
4061 rs_set_capacity(rs); in raid_preresume()
4065 if (test_bit(RT_FLAG_RS_BITMAP_LOADED, &rs->runtime_flags) && mddev->bitmap && in raid_preresume()
4066 (test_bit(RT_FLAG_RS_GROW, &rs->runtime_flags) || in raid_preresume()
4067 (rs->requested_bitmap_chunk_sectors && in raid_preresume()
4068 mddev->bitmap_info.chunksize != to_bytes(rs->requested_bitmap_chunk_sectors)))) { in raid_preresume()
4069 int chunksize = to_bytes(rs->requested_bitmap_chunk_sectors) ?: mddev->bitmap_info.chunksize; in raid_preresume()
4071 r = mddev->bitmap_ops->resize(mddev, mddev->dev_sectors, in raid_preresume()
4077 /* Check for any resize/reshape on @rs and adjust/initiate */ in raid_preresume()
4078 if (mddev->recovery_cp && mddev->recovery_cp < MaxSector) { in raid_preresume()
4079 set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); in raid_preresume()
4080 mddev->resync_min = mddev->recovery_cp; in raid_preresume()
4081 if (test_bit(RT_FLAG_RS_GROW, &rs->runtime_flags)) in raid_preresume()
4082 mddev->resync_max_sectors = mddev->dev_sectors; in raid_preresume()
4086 if (test_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags)) { in raid_preresume()
4088 rs_set_rdev_sectors(rs); in raid_preresume()
4090 r = rs_start_reshape(rs); in raid_preresume()
4102 struct raid_set *rs = ti->private; in raid_resume() local
4103 struct mddev *mddev = &rs->md; in raid_resume()
4105 if (test_and_set_bit(RT_FLAG_RS_RESUMED, &rs->runtime_flags)) { in raid_resume()
4112 attempt_restore_of_faulty_devices(rs); in raid_resume()
4116 if (test_and_clear_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags)) { in raid_resume()
4118 if (mddev->delta_disks < 0) in raid_resume()
4119 rs_set_capacity(rs); in raid_resume()
4122 WARN_ON_ONCE(!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)); in raid_resume()
4123 WARN_ON_ONCE(rcu_dereference_protected(mddev->sync_thread, in raid_resume()
4124 lockdep_is_held(&mddev->reconfig_mutex))); in raid_resume()
4125 clear_bit(RT_FLAG_RS_FROZEN, &rs->runtime_flags); in raid_resume()
4126 mddev->ro = 0; in raid_resume()
4127 mddev->in_sync = 0; in raid_resume()
4157 MODULE_ALIAS("dm-raid0");
4158 MODULE_ALIAS("dm-raid1");
4159 MODULE_ALIAS("dm-raid10");
4160 MODULE_ALIAS("dm-raid4");
4161 MODULE_ALIAS("dm-raid5");
4162 MODULE_ALIAS("dm-raid6");
4163 MODULE_AUTHOR("Neil Brown <dm-devel@lists.linux.dev>");
4164 MODULE_AUTHOR("Heinz Mauelshagen <dm-devel@lists.linux.dev>");