Lines Matching +full:rs +full:-

2  * Copyright (C) 2010-2011 Neil Brown
3 * Copyright (C) 2010-2018 Red Hat, Inc. All rights reserved.
15 #include "md-bitmap.h"
17 #include <linux/device-mapper.h>
20 #define MAX_RAID_DEVICES 253 /* md-raid kernel limit */
35 * The following flags are used by dm-raid.c to set up the array state.
44 * ti->len and give more flexibility in altering size and
50 * |--------- Physical Device ---------|
51 * |- meta_dev -|------ data_dev ------|
59 * Bits for establishing rs->ctr_flags
88 * Flags for rs->ctr_flags field.
170 * that both parity and q-syndrome are being written properly with
199 * Flags for rs->runtime_flags field
217 #define DISKS_ARRAY_ELEMS ((MAX_RAID_DEVICES + (sizeof(uint64_t) * 8 - 1)) / sizeof(uint64_t) / 8)
259 static void rs_config_backup(struct raid_set *rs, struct rs_layout *l) in rs_config_backup() argument
261 struct mddev *mddev = &rs->md; in rs_config_backup()
263 l->new_level = mddev->new_level; in rs_config_backup()
264 l->new_layout = mddev->new_layout; in rs_config_backup()
265 l->new_chunk_sectors = mddev->new_chunk_sectors; in rs_config_backup()
268 static void rs_config_restore(struct raid_set *rs, struct rs_layout *l) in rs_config_restore() argument
270 struct mddev *mddev = &rs->md; in rs_config_restore()
272 mddev->new_level = l->new_level; in rs_config_restore()
273 mddev->new_layout = l->new_layout; in rs_config_restore()
274 mddev->new_chunk_sectors = l->new_chunk_sectors; in rs_config_restore()
350 while (anf-- > __arg_name_flags) in dm_raid_arg_name_by_flag()
351 if (flag & anf->flag) in dm_raid_arg_name_by_flag()
352 return anf->name; in dm_raid_arg_name_by_flag()
360 /* Define correlation of raid456 journal cache modes and dm-raid target line parameters */
374 while (m--) in dm_raid_journal_mode_to_md()
378 return -EINVAL; in dm_raid_journal_mode_to_md()
381 /* Return dm-raid raid4/5/6 journal mode string for @mode */
386 while (m--) in md_journal_mode_to_dm_raid()
398 /* Return true, if raid set in @rs is raid0 */
399 static bool rs_is_raid0(struct raid_set *rs) in rs_is_raid0() argument
401 return !rs->md.level; in rs_is_raid0()
404 /* Return true, if raid set in @rs is raid1 */
405 static bool rs_is_raid1(struct raid_set *rs) in rs_is_raid1() argument
407 return rs->md.level == 1; in rs_is_raid1()
410 /* Return true, if raid set in @rs is raid10 */
411 static bool rs_is_raid10(struct raid_set *rs) in rs_is_raid10() argument
413 return rs->md.level == 10; in rs_is_raid10()
416 /* Return true, if raid set in @rs is level 6 */
417 static bool rs_is_raid6(struct raid_set *rs) in rs_is_raid6() argument
419 return rs->md.level == 6; in rs_is_raid6()
422 /* Return true, if raid set in @rs is level 4, 5 or 6 */
423 static bool rs_is_raid456(struct raid_set *rs) in rs_is_raid456() argument
425 return __within_range(rs->md.level, 4, 6); in rs_is_raid456()
428 /* Return true, if raid set in @rs is reshapable */
430 static bool rs_is_reshapable(struct raid_set *rs) in rs_is_reshapable() argument
432 return rs_is_raid456(rs) || in rs_is_reshapable()
433 (rs_is_raid10(rs) && !__is_raid10_far(rs->md.new_layout)); in rs_is_reshapable()
436 /* Return true, if raid set in @rs is recovering */
437 static bool rs_is_recovering(struct raid_set *rs) in rs_is_recovering() argument
439 return rs->md.recovery_cp < rs->md.dev_sectors; in rs_is_recovering()
442 /* Return true, if raid set in @rs is reshaping */
443 static bool rs_is_reshaping(struct raid_set *rs) in rs_is_reshaping() argument
445 return rs->md.reshape_position != MaxSector; in rs_is_reshaping()
455 return !rt->level; in rt_is_raid0()
461 return rt->level == 1; in rt_is_raid1()
467 return rt->level == 10; in rt_is_raid10()
473 return __within_range(rt->level, 4, 5); in rt_is_raid45()
479 return rt->level == 6; in rt_is_raid6()
485 return __within_range(rt->level, 4, 6); in rt_is_raid456()
489 /* Return valid ctr flags for the raid level of @rs */
490 static unsigned long __valid_flags(struct raid_set *rs) in __valid_flags() argument
492 if (rt_is_raid0(rs->raid_type)) in __valid_flags()
494 else if (rt_is_raid1(rs->raid_type)) in __valid_flags()
496 else if (rt_is_raid10(rs->raid_type)) in __valid_flags()
498 else if (rt_is_raid45(rs->raid_type)) in __valid_flags()
500 else if (rt_is_raid6(rs->raid_type)) in __valid_flags()
507 * Check for valid flags set on @rs
511 static int rs_check_for_valid_flags(struct raid_set *rs) in rs_check_for_valid_flags() argument
513 if (rs->ctr_flags & ~__valid_flags(rs)) { in rs_check_for_valid_flags()
514 rs->ti->error = "Invalid flags combination"; in rs_check_for_valid_flags()
515 return -EINVAL; in rs_check_for_valid_flags()
588 return -EINVAL; in raid10_name_to_format()
598 static int raid10_format_to_md_layout(struct raid_set *rs, in raid10_format_to_md_layout() argument
610 * -> disable it for now in the definition above in raid10_format_to_md_layout()
619 if (!test_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) in raid10_format_to_md_layout()
624 if (!test_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) in raid10_format_to_md_layout()
628 return -EINVAL; in raid10_format_to_md_layout()
637 if (rtp->level == 10) { in __got_raid10()
638 switch (rtp->algorithm) { in __got_raid10()
659 while (rtp-- > raid_types) in get_raid_type()
660 if (!strcasecmp(rtp->name, name)) in get_raid_type()
671 while (rtp-- > raid_types) { in get_raid_type_by_ll()
673 if (rtp->level == level && in get_raid_type_by_ll()
674 (__got_raid10(rtp, layout) || rtp->algorithm == layout)) in get_raid_type_by_ll()
682 static void rs_set_rdev_sectors(struct raid_set *rs) in rs_set_rdev_sectors() argument
684 struct mddev *mddev = &rs->md; in rs_set_rdev_sectors()
688 * raid10 sets rdev->sector to the device size, which in rs_set_rdev_sectors()
689 * is unintended in case of out-of-place reshaping in rs_set_rdev_sectors()
692 if (!test_bit(Journal, &rdev->flags)) in rs_set_rdev_sectors()
693 rdev->sectors = mddev->dev_sectors; in rs_set_rdev_sectors()
697 * Change bdev capacity of @rs in case of a disk add/remove reshape
699 static void rs_set_capacity(struct raid_set *rs) in rs_set_capacity() argument
701 struct gendisk *gendisk = dm_disk(dm_table_get_md(rs->ti->table)); in rs_set_capacity()
703 set_capacity_and_notify(gendisk, rs->md.array_sectors); in rs_set_capacity()
707 * Set the mddev properties in @rs to the current
710 static void rs_set_cur(struct raid_set *rs) in rs_set_cur() argument
712 struct mddev *mddev = &rs->md; in rs_set_cur()
714 mddev->new_level = mddev->level; in rs_set_cur()
715 mddev->new_layout = mddev->layout; in rs_set_cur()
716 mddev->new_chunk_sectors = mddev->chunk_sectors; in rs_set_cur()
720 * Set the mddev properties in @rs to the new
723 static void rs_set_new(struct raid_set *rs) in rs_set_new() argument
725 struct mddev *mddev = &rs->md; in rs_set_new()
727 mddev->level = mddev->new_level; in rs_set_new()
728 mddev->layout = mddev->new_layout; in rs_set_new()
729 mddev->chunk_sectors = mddev->new_chunk_sectors; in rs_set_new()
730 mddev->raid_disks = rs->raid_disks; in rs_set_new()
731 mddev->delta_disks = 0; in rs_set_new()
738 struct raid_set *rs; in raid_set_alloc() local
740 if (raid_devs <= raid_type->parity_devs) { in raid_set_alloc()
741 ti->error = "Insufficient number of devices"; in raid_set_alloc()
742 return ERR_PTR(-EINVAL); in raid_set_alloc()
745 rs = kzalloc(struct_size(rs, dev, raid_devs), GFP_KERNEL); in raid_set_alloc()
746 if (!rs) { in raid_set_alloc()
747 ti->error = "Cannot allocate raid context"; in raid_set_alloc()
748 return ERR_PTR(-ENOMEM); in raid_set_alloc()
751 mddev_init(&rs->md); in raid_set_alloc()
753 rs->raid_disks = raid_devs; in raid_set_alloc()
754 rs->delta_disks = 0; in raid_set_alloc()
756 rs->ti = ti; in raid_set_alloc()
757 rs->raid_type = raid_type; in raid_set_alloc()
758 rs->stripe_cache_entries = 256; in raid_set_alloc()
759 rs->md.raid_disks = raid_devs; in raid_set_alloc()
760 rs->md.level = raid_type->level; in raid_set_alloc()
761 rs->md.new_level = rs->md.level; in raid_set_alloc()
762 rs->md.layout = raid_type->algorithm; in raid_set_alloc()
763 rs->md.new_layout = rs->md.layout; in raid_set_alloc()
764 rs->md.delta_disks = 0; in raid_set_alloc()
765 rs->md.recovery_cp = MaxSector; in raid_set_alloc()
768 md_rdev_init(&rs->dev[i].rdev); in raid_set_alloc()
772 * rs->md.persistent in raid_set_alloc()
773 * rs->md.external in raid_set_alloc()
774 * rs->md.chunk_sectors in raid_set_alloc()
775 * rs->md.new_chunk_sectors in raid_set_alloc()
776 * rs->md.dev_sectors in raid_set_alloc()
779 return rs; in raid_set_alloc()
782 /* Free all @rs allocations */
783 static void raid_set_free(struct raid_set *rs) in raid_set_free() argument
787 if (rs->journal_dev.dev) { in raid_set_free()
788 md_rdev_clear(&rs->journal_dev.rdev); in raid_set_free()
789 dm_put_device(rs->ti, rs->journal_dev.dev); in raid_set_free()
792 for (i = 0; i < rs->raid_disks; i++) { in raid_set_free()
793 if (rs->dev[i].meta_dev) in raid_set_free()
794 dm_put_device(rs->ti, rs->dev[i].meta_dev); in raid_set_free()
795 md_rdev_clear(&rs->dev[i].rdev); in raid_set_free()
796 if (rs->dev[i].data_dev) in raid_set_free()
797 dm_put_device(rs->ti, rs->dev[i].data_dev); in raid_set_free()
800 kfree(rs); in raid_set_free()
805 * <meta_dev>: meta device name or '-' if missing
806 * <data_dev>: data device name or '-' if missing
809 * - -
810 * - <data_dev>
814 * <meta_dev> -
819 static int parse_dev_params(struct raid_set *rs, struct dm_arg_set *as) in parse_dev_params() argument
830 return -EINVAL; in parse_dev_params()
832 for (i = 0; i < rs->raid_disks; i++) { in parse_dev_params()
833 rs->dev[i].rdev.raid_disk = i; in parse_dev_params()
835 rs->dev[i].meta_dev = NULL; in parse_dev_params()
836 rs->dev[i].data_dev = NULL; in parse_dev_params()
842 rs->dev[i].rdev.data_offset = 0; in parse_dev_params()
843 rs->dev[i].rdev.new_data_offset = 0; in parse_dev_params()
844 rs->dev[i].rdev.mddev = &rs->md; in parse_dev_params()
848 return -EINVAL; in parse_dev_params()
850 if (strcmp(arg, "-")) { in parse_dev_params()
851 r = dm_get_device(rs->ti, arg, dm_table_get_mode(rs->ti->table), in parse_dev_params()
852 &rs->dev[i].meta_dev); in parse_dev_params()
854 rs->ti->error = "RAID metadata device lookup failure"; in parse_dev_params()
858 rs->dev[i].rdev.sb_page = alloc_page(GFP_KERNEL); in parse_dev_params()
859 if (!rs->dev[i].rdev.sb_page) { in parse_dev_params()
860 rs->ti->error = "Failed to allocate superblock page"; in parse_dev_params()
861 return -ENOMEM; in parse_dev_params()
867 return -EINVAL; in parse_dev_params()
869 if (!strcmp(arg, "-")) { in parse_dev_params()
870 if (!test_bit(In_sync, &rs->dev[i].rdev.flags) && in parse_dev_params()
871 (!rs->dev[i].rdev.recovery_offset)) { in parse_dev_params()
872 rs->ti->error = "Drive designated for rebuild not specified"; in parse_dev_params()
873 return -EINVAL; in parse_dev_params()
876 if (rs->dev[i].meta_dev) { in parse_dev_params()
877 rs->ti->error = "No data device supplied with metadata device"; in parse_dev_params()
878 return -EINVAL; in parse_dev_params()
884 r = dm_get_device(rs->ti, arg, dm_table_get_mode(rs->ti->table), in parse_dev_params()
885 &rs->dev[i].data_dev); in parse_dev_params()
887 rs->ti->error = "RAID device lookup failure"; in parse_dev_params()
891 if (rs->dev[i].meta_dev) { in parse_dev_params()
893 rs->dev[i].rdev.meta_bdev = rs->dev[i].meta_dev->bdev; in parse_dev_params()
895 rs->dev[i].rdev.bdev = rs->dev[i].data_dev->bdev; in parse_dev_params()
896 list_add_tail(&rs->dev[i].rdev.same_set, &rs->md.disks); in parse_dev_params()
897 if (!test_bit(In_sync, &rs->dev[i].rdev.flags)) in parse_dev_params()
901 if (rs->journal_dev.dev) in parse_dev_params()
902 list_add_tail(&rs->journal_dev.rdev.same_set, &rs->md.disks); in parse_dev_params()
905 rs->md.external = 0; in parse_dev_params()
906 rs->md.persistent = 1; in parse_dev_params()
907 rs->md.major_version = 2; in parse_dev_params()
908 } else if (rebuild && !rs->md.recovery_cp) { in parse_dev_params()
911 * is in-sync or not - we must assume it is not. Therefore, in parse_dev_params()
914 * Even if there is metadata, the on-disk information may in parse_dev_params()
915 * indicate that the array is not in-sync and it will then in parse_dev_params()
920 rs->ti->error = "Unable to rebuild drive while array is not in-sync"; in parse_dev_params()
921 return -EINVAL; in parse_dev_params()
929 * @rs
932 * Set rs->md.bitmap_info.chunksize (which really refers to 'region size').
933 * Ensure that (ti->len/region_size < 2^21) - required by MD bitmap.
935 * Returns: 0 on success, -EINVAL on failure.
937 static int validate_region_size(struct raid_set *rs, unsigned long region_size) in validate_region_size() argument
939 unsigned long min_region_size = rs->ti->len / (1 << 21); in validate_region_size()
941 if (rs_is_raid0(rs)) in validate_region_size()
959 * Validate user-supplied value. in validate_region_size()
961 if (region_size > rs->ti->len) { in validate_region_size()
962 rs->ti->error = "Supplied region size is too large"; in validate_region_size()
963 return -EINVAL; in validate_region_size()
969 rs->ti->error = "Supplied region size is too small"; in validate_region_size()
970 return -EINVAL; in validate_region_size()
974 rs->ti->error = "Region size is not a power of 2"; in validate_region_size()
975 return -EINVAL; in validate_region_size()
978 if (region_size < rs->md.chunk_sectors) { in validate_region_size()
979 rs->ti->error = "Region size is smaller than the chunk size"; in validate_region_size()
980 return -EINVAL; in validate_region_size()
987 rs->md.bitmap_info.chunksize = to_bytes(region_size); in validate_region_size()
994 * @rs
999 * Returns: 0 on success, -EINVAL on failure.
1001 static int validate_raid_redundancy(struct raid_set *rs) in validate_raid_redundancy() argument
1007 for (i = 0; i < rs->raid_disks; i++) in validate_raid_redundancy()
1008 if (!test_bit(FirstUse, &rs->dev[i].rdev.flags) && in validate_raid_redundancy()
1009 ((!test_bit(In_sync, &rs->dev[i].rdev.flags) || in validate_raid_redundancy()
1010 !rs->dev[i].rdev.sb_page))) in validate_raid_redundancy()
1013 switch (rs->md.level) { in validate_raid_redundancy()
1017 if (rebuild_cnt >= rs->md.raid_disks) in validate_raid_redundancy()
1023 if (rebuild_cnt > rs->raid_type->parity_devs) in validate_raid_redundancy()
1027 copies = raid10_md_layout_to_copies(rs->md.new_layout); in validate_raid_redundancy()
1030 return -EINVAL; in validate_raid_redundancy()
1050 raid_disks = min(rs->raid_disks, rs->md.raid_disks); in validate_raid_redundancy()
1051 if (__is_raid10_near(rs->md.new_layout)) { in validate_raid_redundancy()
1055 if ((!rs->dev[i].rdev.sb_page || in validate_raid_redundancy()
1056 !test_bit(In_sync, &rs->dev[i].rdev.flags)) && in validate_raid_redundancy()
1076 last_group_start = (raid_disks / group_size) - 1; in validate_raid_redundancy()
1081 if ((!rs->dev[i].rdev.sb_page || in validate_raid_redundancy()
1082 !test_bit(In_sync, &rs->dev[i].rdev.flags)) && in validate_raid_redundancy()
1089 return -EINVAL; in validate_raid_redundancy()
1095 return -EINVAL; in validate_raid_redundancy()
1113 * [max_write_behind <sectors>] See '-write-behind=' (man mdadm)
1119 * RAID10-only options:
1123 static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, in parse_raid_params() argument
1133 struct raid_type *rt = rs->raid_type; in parse_raid_params()
1136 num_raid_params--; /* Account for chunk_size argument */ in parse_raid_params()
1139 rs->ti->error = "Bad numerical argument given for chunk_size"; in parse_raid_params()
1140 return -EINVAL; in parse_raid_params()
1144 * First, parse the in-order required arguments in parse_raid_params()
1152 rs->ti->error = "Chunk size must be a power of 2"; in parse_raid_params()
1153 return -EINVAL; in parse_raid_params()
1155 rs->ti->error = "Chunk size value is too small"; in parse_raid_params()
1156 return -EINVAL; in parse_raid_params()
1159 rs->md.new_chunk_sectors = rs->md.chunk_sectors = value; in parse_raid_params()
1167 * - Device is reset when param is read. in parse_raid_params()
1169 * - No matching superblock found, resets device. in parse_raid_params()
1171 * - Failure noticed, resets device for bitmap replay. in parse_raid_params()
1173 * - Superblock is read and overrides recovery_offset. in parse_raid_params()
1178 for (i = 0; i < rs->raid_disks; i++) { in parse_raid_params()
1179 set_bit(In_sync, &rs->dev[i].rdev.flags); in parse_raid_params()
1180 rs->dev[i].rdev.recovery_offset = MaxSector; in parse_raid_params()
1189 rs->ti->error = "Not enough raid parameters given"; in parse_raid_params()
1190 return -EINVAL; in parse_raid_params()
1194 if (test_and_set_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) { in parse_raid_params()
1195 rs->ti->error = "Only one 'nosync' argument allowed"; in parse_raid_params()
1196 return -EINVAL; in parse_raid_params()
1201 if (test_and_set_bit(__CTR_FLAG_SYNC, &rs->ctr_flags)) { in parse_raid_params()
1202 rs->ti->error = "Only one 'sync' argument allowed"; in parse_raid_params()
1203 return -EINVAL; in parse_raid_params()
1208 if (test_and_set_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) { in parse_raid_params()
1209 rs->ti->error = "Only one 'raid10_use_new_sets' argument allowed"; in parse_raid_params()
1210 return -EINVAL; in parse_raid_params()
1218 rs->ti->error = "Wrong number of raid parameters given"; in parse_raid_params()
1219 return -EINVAL; in parse_raid_params()
1227 if (test_and_set_bit(__CTR_FLAG_RAID10_FORMAT, &rs->ctr_flags)) { in parse_raid_params()
1228 rs->ti->error = "Only one 'raid10_format' argument pair allowed"; in parse_raid_params()
1229 return -EINVAL; in parse_raid_params()
1232 rs->ti->error = "'raid10_format' is an invalid parameter for this RAID type"; in parse_raid_params()
1233 return -EINVAL; in parse_raid_params()
1237 rs->ti->error = "Invalid 'raid10_format' value given"; in parse_raid_params()
1248 if (test_and_set_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { in parse_raid_params()
1249 rs->ti->error = "Only one raid4/5/6 set journaling device allowed"; in parse_raid_params()
1250 return -EINVAL; in parse_raid_params()
1253 rs->ti->error = "'journal_dev' is an invalid parameter for this RAID type"; in parse_raid_params()
1254 return -EINVAL; in parse_raid_params()
1256 r = dm_get_device(rs->ti, arg, dm_table_get_mode(rs->ti->table), in parse_raid_params()
1257 &rs->journal_dev.dev); in parse_raid_params()
1259 rs->ti->error = "raid4/5/6 journal device lookup failure"; in parse_raid_params()
1262 jdev = &rs->journal_dev.rdev; in parse_raid_params()
1264 jdev->mddev = &rs->md; in parse_raid_params()
1265 jdev->bdev = rs->journal_dev.dev->bdev; in parse_raid_params()
1266 jdev->sectors = bdev_nr_sectors(jdev->bdev); in parse_raid_params()
1267 if (jdev->sectors < MIN_RAID456_JOURNAL_SPACE) { in parse_raid_params()
1268 rs->ti->error = "No space for raid4/5/6 journal"; in parse_raid_params()
1269 return -ENOSPC; in parse_raid_params()
1271 rs->journal_dev.mode = R5C_JOURNAL_MODE_WRITE_THROUGH; in parse_raid_params()
1272 set_bit(Journal, &jdev->flags); in parse_raid_params()
1280 if (!test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { in parse_raid_params()
1281 rs->ti->error = "raid4/5/6 'journal_mode' is invalid without 'journal_dev'"; in parse_raid_params()
1282 return -EINVAL; in parse_raid_params()
1284 if (test_and_set_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) { in parse_raid_params()
1285 rs->ti->error = "Only one raid4/5/6 'journal_mode' argument allowed"; in parse_raid_params()
1286 return -EINVAL; in parse_raid_params()
1290 rs->ti->error = "Invalid 'journal_mode' argument"; in parse_raid_params()
1293 rs->journal_dev.mode = r; in parse_raid_params()
1301 rs->ti->error = "Bad numerical argument given in raid params"; in parse_raid_params()
1302 return -EINVAL; in parse_raid_params()
1311 if (!__within_range(value, 0, rs->raid_disks - 1)) { in parse_raid_params()
1312 rs->ti->error = "Invalid rebuild index given"; in parse_raid_params()
1313 return -EINVAL; in parse_raid_params()
1316 if (test_and_set_bit(value, (void *) rs->rebuild_disks)) { in parse_raid_params()
1317 rs->ti->error = "rebuild for this index already given"; in parse_raid_params()
1318 return -EINVAL; in parse_raid_params()
1321 rd = rs->dev + value; in parse_raid_params()
1322 clear_bit(In_sync, &rd->rdev.flags); in parse_raid_params()
1323 clear_bit(Faulty, &rd->rdev.flags); in parse_raid_params()
1324 rd->rdev.recovery_offset = 0; in parse_raid_params()
1325 set_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags); in parse_raid_params()
1328 rs->ti->error = "write_mostly option is only valid for RAID1"; in parse_raid_params()
1329 return -EINVAL; in parse_raid_params()
1332 if (!__within_range(value, 0, rs->md.raid_disks - 1)) { in parse_raid_params()
1333 rs->ti->error = "Invalid write_mostly index given"; in parse_raid_params()
1334 return -EINVAL; in parse_raid_params()
1338 set_bit(WriteMostly, &rs->dev[value].rdev.flags); in parse_raid_params()
1339 set_bit(__CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags); in parse_raid_params()
1342 rs->ti->error = "max_write_behind option is only valid for RAID1"; in parse_raid_params()
1343 return -EINVAL; in parse_raid_params()
1346 if (test_and_set_bit(__CTR_FLAG_MAX_WRITE_BEHIND, &rs->ctr_flags)) { in parse_raid_params()
1347 rs->ti->error = "Only one max_write_behind argument pair allowed"; in parse_raid_params()
1348 return -EINVAL; in parse_raid_params()
1352 * In device-mapper, we specify things in sectors, but in parse_raid_params()
1356 rs->ti->error = "Max write-behind limit out of range"; in parse_raid_params()
1357 return -EINVAL; in parse_raid_params()
1360 rs->md.bitmap_info.max_write_behind = value / 2; in parse_raid_params()
1362 if (test_and_set_bit(__CTR_FLAG_DAEMON_SLEEP, &rs->ctr_flags)) { in parse_raid_params()
1363 rs->ti->error = "Only one daemon_sleep argument pair allowed"; in parse_raid_params()
1364 return -EINVAL; in parse_raid_params()
1367 rs->ti->error = "daemon sleep period out of range"; in parse_raid_params()
1368 return -EINVAL; in parse_raid_params()
1370 rs->md.bitmap_info.daemon_sleep = value; in parse_raid_params()
1373 if (test_and_set_bit(__CTR_FLAG_DATA_OFFSET, &rs->ctr_flags)) { in parse_raid_params()
1374 rs->ti->error = "Only one data_offset argument pair allowed"; in parse_raid_params()
1375 return -EINVAL; in parse_raid_params()
1380 rs->ti->error = "Bogus data_offset value"; in parse_raid_params()
1381 return -EINVAL; in parse_raid_params()
1383 rs->data_offset = value; in parse_raid_params()
1385 /* Define the +/-# of disks to add to/remove from the given raid set */ in parse_raid_params()
1386 if (test_and_set_bit(__CTR_FLAG_DELTA_DISKS, &rs->ctr_flags)) { in parse_raid_params()
1387 rs->ti->error = "Only one delta_disks argument pair allowed"; in parse_raid_params()
1388 return -EINVAL; in parse_raid_params()
1391 if (!__within_range(abs(value), 1, MAX_RAID_DEVICES - rt->minimal_devs)) { in parse_raid_params()
1392 rs->ti->error = "Too many delta_disk requested"; in parse_raid_params()
1393 return -EINVAL; in parse_raid_params()
1396 rs->delta_disks = value; in parse_raid_params()
1398 if (test_and_set_bit(__CTR_FLAG_STRIPE_CACHE, &rs->ctr_flags)) { in parse_raid_params()
1399 rs->ti->error = "Only one stripe_cache argument pair allowed"; in parse_raid_params()
1400 return -EINVAL; in parse_raid_params()
1404 rs->ti->error = "Inappropriate argument: stripe_cache"; in parse_raid_params()
1405 return -EINVAL; in parse_raid_params()
1409 rs->ti->error = "Bogus stripe cache entries value"; in parse_raid_params()
1410 return -EINVAL; in parse_raid_params()
1412 rs->stripe_cache_entries = value; in parse_raid_params()
1414 if (test_and_set_bit(__CTR_FLAG_MIN_RECOVERY_RATE, &rs->ctr_flags)) { in parse_raid_params()
1415 rs->ti->error = "Only one min_recovery_rate argument pair allowed"; in parse_raid_params()
1416 return -EINVAL; in parse_raid_params()
1420 rs->ti->error = "min_recovery_rate out of range"; in parse_raid_params()
1421 return -EINVAL; in parse_raid_params()
1423 rs->md.sync_speed_min = value; in parse_raid_params()
1425 if (test_and_set_bit(__CTR_FLAG_MAX_RECOVERY_RATE, &rs->ctr_flags)) { in parse_raid_params()
1426 rs->ti->error = "Only one max_recovery_rate argument pair allowed"; in parse_raid_params()
1427 return -EINVAL; in parse_raid_params()
1431 rs->ti->error = "max_recovery_rate out of range"; in parse_raid_params()
1432 return -EINVAL; in parse_raid_params()
1434 rs->md.sync_speed_max = value; in parse_raid_params()
1436 if (test_and_set_bit(__CTR_FLAG_REGION_SIZE, &rs->ctr_flags)) { in parse_raid_params()
1437 rs->ti->error = "Only one region_size argument pair allowed"; in parse_raid_params()
1438 return -EINVAL; in parse_raid_params()
1442 rs->requested_bitmap_chunk_sectors = value; in parse_raid_params()
1444 if (test_and_set_bit(__CTR_FLAG_RAID10_COPIES, &rs->ctr_flags)) { in parse_raid_params()
1445 rs->ti->error = "Only one raid10_copies argument pair allowed"; in parse_raid_params()
1446 return -EINVAL; in parse_raid_params()
1449 if (!__within_range(value, 2, rs->md.raid_disks)) { in parse_raid_params()
1450 rs->ti->error = "Bad value for 'raid10_copies'"; in parse_raid_params()
1451 return -EINVAL; in parse_raid_params()
1457 rs->ti->error = "Unable to parse RAID parameter"; in parse_raid_params()
1458 return -EINVAL; in parse_raid_params()
1462 if (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags) && in parse_raid_params()
1463 test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) { in parse_raid_params()
1464 rs->ti->error = "sync and nosync are mutually exclusive"; in parse_raid_params()
1465 return -EINVAL; in parse_raid_params()
1468 if (test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags) && in parse_raid_params()
1469 (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/nosync and rebuild are mutually exclusive"; in parse_raid_params()
1472 return -EINVAL; in parse_raid_params()
1475 if (write_mostly >= rs->md.raid_disks) { in parse_raid_params()
1476 rs->ti->error = "Can't set all raid1 devices to write_mostly"; in parse_raid_params()
1477 return -EINVAL; in parse_raid_params()
1480 if (rs->md.sync_speed_max && in parse_raid_params()
1481 rs->md.sync_speed_min > rs->md.sync_speed_max) { in parse_raid_params()
1482 rs->ti->error = "Bogus recovery rates"; in parse_raid_params()
1483 return -EINVAL; in parse_raid_params()
1486 if (validate_region_size(rs, region_size)) in parse_raid_params()
1487 return -EINVAL; in parse_raid_params()
1489 if (rs->md.chunk_sectors) in parse_raid_params()
1490 max_io_len = rs->md.chunk_sectors; in parse_raid_params()
1494 if (dm_set_target_max_io_len(rs->ti, max_io_len)) in parse_raid_params()
1495 return -EINVAL; in parse_raid_params()
1498 if (raid10_copies > rs->md.raid_disks) { in parse_raid_params()
1499 rs->ti->error = "Not enough devices to satisfy specification"; in parse_raid_params()
1500 return -EINVAL; in parse_raid_params()
1503 rs->md.new_layout = raid10_format_to_md_layout(rs, raid10_format, raid10_copies); in parse_raid_params()
1504 if (rs->md.new_layout < 0) { in parse_raid_params()
1505 rs->ti->error = "Error getting raid10 format"; in parse_raid_params()
1506 return rs->md.new_layout; in parse_raid_params()
1509 rt = get_raid_type_by_ll(10, rs->md.new_layout); in parse_raid_params()
1511 rs->ti->error = "Failed to recognize new raid10 layout"; in parse_raid_params()
1512 return -EINVAL; in parse_raid_params()
1515 if ((rt->algorithm == ALGORITHM_RAID10_DEFAULT || in parse_raid_params()
1516 rt->algorithm == ALGORITHM_RAID10_NEAR) && in parse_raid_params()
1517 test_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) { in parse_raid_params()
1518 rs->ti->error = "RAID10 format 'near' and 'raid10_use_near_sets' are incompatible"; in parse_raid_params()
1519 return -EINVAL; in parse_raid_params()
1523 rs->raid10_copies = raid10_copies; in parse_raid_params()
1526 rs->md.persistent = 0; in parse_raid_params()
1527 rs->md.external = 1; in parse_raid_params()
1530 return rs_check_for_valid_flags(rs); in parse_raid_params()
1534 static int rs_set_raid456_stripe_cache(struct raid_set *rs) in rs_set_raid456_stripe_cache() argument
1538 struct mddev *mddev = &rs->md; in rs_set_raid456_stripe_cache()
1539 uint32_t min_stripes = max(mddev->chunk_sectors, mddev->new_chunk_sectors) / 2; in rs_set_raid456_stripe_cache()
1540 uint32_t nr_stripes = rs->stripe_cache_entries; in rs_set_raid456_stripe_cache()
1542 if (!rt_is_raid456(rs->raid_type)) { in rs_set_raid456_stripe_cache()
1543 rs->ti->error = "Inappropriate raid level; cannot change stripe_cache size"; in rs_set_raid456_stripe_cache()
1544 return -EINVAL; in rs_set_raid456_stripe_cache()
1553 conf = mddev->private; in rs_set_raid456_stripe_cache()
1555 rs->ti->error = "Cannot change stripe_cache size on inactive RAID set"; in rs_set_raid456_stripe_cache()
1556 return -EINVAL; in rs_set_raid456_stripe_cache()
1560 if (conf->min_nr_stripes != nr_stripes) { in rs_set_raid456_stripe_cache()
1563 rs->ti->error = "Failed to set raid4/5/6 stripe cache size"; in rs_set_raid456_stripe_cache()
1573 /* Return # of data stripes as kept in mddev as of @rs (i.e. as of superblock) */
1574 static unsigned int mddev_data_stripes(struct raid_set *rs) in mddev_data_stripes() argument
1576 return rs->md.raid_disks - rs->raid_type->parity_devs; in mddev_data_stripes()
1579 /* Return # of data stripes of @rs (i.e. as of ctr) */
1580 static unsigned int rs_data_stripes(struct raid_set *rs) in rs_data_stripes() argument
1582 return rs->raid_disks - rs->raid_type->parity_devs; in rs_data_stripes()
1586 * Retrieve rdev->sectors from any valid raid device of @rs
1587 * to allow userpace to pass in arbitray "- -" device tupples.
1589 static sector_t __rdev_sectors(struct raid_set *rs) in __rdev_sectors() argument
1593 for (i = 0; i < rs->raid_disks; i++) { in __rdev_sectors()
1594 struct md_rdev *rdev = &rs->dev[i].rdev; in __rdev_sectors()
1596 if (!test_bit(Journal, &rdev->flags) && in __rdev_sectors()
1597 rdev->bdev && rdev->sectors) in __rdev_sectors()
1598 return rdev->sectors; in __rdev_sectors()
1605 static int _check_data_dev_sectors(struct raid_set *rs) in _check_data_dev_sectors() argument
1610 rdev_for_each(rdev, &rs->md) in _check_data_dev_sectors()
1611 if (!test_bit(Journal, &rdev->flags) && rdev->bdev) { in _check_data_dev_sectors()
1612 ds = min(ds, bdev_nr_sectors(rdev->bdev)); in _check_data_dev_sectors()
1613 if (ds < rs->md.dev_sectors) { in _check_data_dev_sectors()
1614 rs->ti->error = "Component device(s) too small"; in _check_data_dev_sectors()
1615 return -EINVAL; in _check_data_dev_sectors()
1622 /* Calculate the sectors per device and per array used for @rs */
1623 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
1628 struct mddev *mddev = &rs->md; in rs_set_dev_and_array_sectors()
1631 delta_disks = mddev->delta_disks; in rs_set_dev_and_array_sectors()
1632 data_stripes = mddev_data_stripes(rs); in rs_set_dev_and_array_sectors()
1634 delta_disks = rs->delta_disks; in rs_set_dev_and_array_sectors()
1635 data_stripes = rs_data_stripes(rs); in rs_set_dev_and_array_sectors()
1639 if (rt_is_raid1(rs->raid_type)) in rs_set_dev_and_array_sectors()
1641 else if (rt_is_raid10(rs->raid_type)) { in rs_set_dev_and_array_sectors()
1642 if (rs->raid10_copies < 2 || in rs_set_dev_and_array_sectors()
1644 rs->ti->error = "Bogus raid10 data copies or delta disks"; in rs_set_dev_and_array_sectors()
1645 return -EINVAL; in rs_set_dev_and_array_sectors()
1648 dev_sectors *= rs->raid10_copies; in rs_set_dev_and_array_sectors()
1653 if (sector_div(array_sectors, rs->raid10_copies)) in rs_set_dev_and_array_sectors()
1663 mddev->array_sectors = array_sectors; in rs_set_dev_and_array_sectors()
1664 mddev->dev_sectors = dev_sectors; in rs_set_dev_and_array_sectors()
1665 rs_set_rdev_sectors(rs); in rs_set_dev_and_array_sectors()
1667 return _check_data_dev_sectors(rs); in rs_set_dev_and_array_sectors()
1669 rs->ti->error = "Target length not divisible by number of data devices"; in rs_set_dev_and_array_sectors()
1670 return -EINVAL; in rs_set_dev_and_array_sectors()
1673 /* Setup recovery on @rs */
1674 static void rs_setup_recovery(struct raid_set *rs, sector_t dev_sectors) in rs_setup_recovery() argument
1677 if (rs_is_raid0(rs)) in rs_setup_recovery()
1678 rs->md.recovery_cp = MaxSector; in rs_setup_recovery()
1682 * ensure proper parity and Q-Syndrome in rs_setup_recovery()
1684 else if (rs_is_raid6(rs)) in rs_setup_recovery()
1685 rs->md.recovery_cp = dev_sectors; in rs_setup_recovery()
1691 rs->md.recovery_cp = test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags) in rs_setup_recovery()
1697 struct raid_set *rs = container_of(ws, struct raid_set, md.event_work); in do_table_event() local
1700 if (!rs_is_reshaping(rs)) { in do_table_event()
1701 if (rs_is_raid10(rs)) in do_table_event()
1702 rs_set_rdev_sectors(rs); in do_table_event()
1703 rs_set_capacity(rs); in do_table_event()
1705 dm_table_event(rs->ti->table); in do_table_event()
1709 * Make sure a valid takover (level switch) is being requested on @rs
1714 static int rs_check_takeover(struct raid_set *rs) in rs_check_takeover() argument
1716 struct mddev *mddev = &rs->md; in rs_check_takeover()
1719 if (rs->md.degraded) { in rs_check_takeover()
1720 rs->ti->error = "Can't takeover degraded raid set"; in rs_check_takeover()
1721 return -EPERM; in rs_check_takeover()
1724 if (rs_is_reshaping(rs)) { in rs_check_takeover()
1725 rs->ti->error = "Can't takeover reshaping raid set"; in rs_check_takeover()
1726 return -EPERM; in rs_check_takeover()
1729 switch (mddev->level) { in rs_check_takeover()
1731 /* raid0 -> raid1/5 with one disk */ in rs_check_takeover()
1732 if ((mddev->new_level == 1 || mddev->new_level == 5) && in rs_check_takeover()
1733 mddev->raid_disks == 1) in rs_check_takeover()
1736 /* raid0 -> raid10 */ in rs_check_takeover()
1737 if (mddev->new_level == 10 && in rs_check_takeover()
1738 !(rs->raid_disks % mddev->raid_disks)) in rs_check_takeover()
1741 /* raid0 with multiple disks -> raid4/5/6 */ in rs_check_takeover()
1742 if (__within_range(mddev->new_level, 4, 6) && in rs_check_takeover()
1743 mddev->new_layout == ALGORITHM_PARITY_N && in rs_check_takeover()
1744 mddev->raid_disks > 1) in rs_check_takeover()
1751 if (__is_raid10_offset(mddev->layout)) in rs_check_takeover()
1754 near_copies = __raid10_near_copies(mddev->layout); in rs_check_takeover()
1756 /* raid10* -> raid0 */ in rs_check_takeover()
1757 if (mddev->new_level == 0) { in rs_check_takeover()
1760 !(mddev->raid_disks % near_copies)) { in rs_check_takeover()
1761 mddev->raid_disks /= near_copies; in rs_check_takeover()
1762 mddev->delta_disks = mddev->raid_disks; in rs_check_takeover()
1768 __raid10_far_copies(mddev->layout) > 1) in rs_check_takeover()
1774 /* raid10_{near,far} -> raid1 */ in rs_check_takeover()
1775 if (mddev->new_level == 1 && in rs_check_takeover()
1776 max(near_copies, __raid10_far_copies(mddev->layout)) == mddev->raid_disks) in rs_check_takeover()
1779 /* raid10_{near,far} with 2 disks -> raid4/5 */ in rs_check_takeover()
1780 if (__within_range(mddev->new_level, 4, 5) && in rs_check_takeover()
1781 mddev->raid_disks == 2) in rs_check_takeover()
1786 /* raid1 with 2 disks -> raid4/5 */ in rs_check_takeover()
1787 if (__within_range(mddev->new_level, 4, 5) && in rs_check_takeover()
1788 mddev->raid_disks == 2) { in rs_check_takeover()
1789 mddev->degraded = 1; in rs_check_takeover()
1793 /* raid1 -> raid0 */ in rs_check_takeover()
1794 if (mddev->new_level == 0 && in rs_check_takeover()
1795 mddev->raid_disks == 1) in rs_check_takeover()
1798 /* raid1 -> raid10 */ in rs_check_takeover()
1799 if (mddev->new_level == 10) in rs_check_takeover()
1804 /* raid4 -> raid0 */ in rs_check_takeover()
1805 if (mddev->new_level == 0) in rs_check_takeover()
1808 /* raid4 -> raid1/5 with 2 disks */ in rs_check_takeover()
1809 if ((mddev->new_level == 1 || mddev->new_level == 5) && in rs_check_takeover()
1810 mddev->raid_disks == 2) in rs_check_takeover()
1813 /* raid4 -> raid5/6 with parity N */ in rs_check_takeover()
1814 if (__within_range(mddev->new_level, 5, 6) && in rs_check_takeover()
1815 mddev->layout == ALGORITHM_PARITY_N) in rs_check_takeover()
1820 /* raid5 with parity N -> raid0 */ in rs_check_takeover()
1821 if (mddev->new_level == 0 && in rs_check_takeover()
1822 mddev->layout == ALGORITHM_PARITY_N) in rs_check_takeover()
1825 /* raid5 with parity N -> raid4 */ in rs_check_takeover()
1826 if (mddev->new_level == 4 && in rs_check_takeover()
1827 mddev->layout == ALGORITHM_PARITY_N) in rs_check_takeover()
1830 /* raid5 with 2 disks -> raid1/4/10 */ in rs_check_takeover()
1831 if ((mddev->new_level == 1 || mddev->new_level == 4 || mddev->new_level == 10) && in rs_check_takeover()
1832 mddev->raid_disks == 2) in rs_check_takeover()
1835 /* raid5_* -> raid6_*_6 with Q-Syndrome N (e.g. raid5_ra -> raid6_ra_6 */ in rs_check_takeover()
1836 if (mddev->new_level == 6 && in rs_check_takeover()
1837 ((mddev->layout == ALGORITHM_PARITY_N && mddev->new_layout == ALGORITHM_PARITY_N) || in rs_check_takeover()
1838 … __within_range(mddev->new_layout, ALGORITHM_LEFT_ASYMMETRIC_6, ALGORITHM_RIGHT_SYMMETRIC_6))) in rs_check_takeover()
1843 /* raid6 with parity N -> raid0 */ in rs_check_takeover()
1844 if (mddev->new_level == 0 && in rs_check_takeover()
1845 mddev->layout == ALGORITHM_PARITY_N) in rs_check_takeover()
1848 /* raid6 with parity N -> raid4 */ in rs_check_takeover()
1849 if (mddev->new_level == 4 && in rs_check_takeover()
1850 mddev->layout == ALGORITHM_PARITY_N) in rs_check_takeover()
1853 /* raid6_*_n with Q-Syndrome N -> raid5_* */ in rs_check_takeover()
1854 if (mddev->new_level == 5 && in rs_check_takeover()
1855 ((mddev->layout == ALGORITHM_PARITY_N && mddev->new_layout == ALGORITHM_PARITY_N) || in rs_check_takeover()
1856 __within_range(mddev->new_layout, ALGORITHM_LEFT_ASYMMETRIC, ALGORITHM_RIGHT_SYMMETRIC))) in rs_check_takeover()
1864 rs->ti->error = "takeover not possible"; in rs_check_takeover()
1865 return -EINVAL; in rs_check_takeover()
1868 /* True if @rs requested to be taken over */
1869 static bool rs_takeover_requested(struct raid_set *rs) in rs_takeover_requested() argument
1871 return rs->md.new_level != rs->md.level; in rs_takeover_requested()
1875 static bool rs_is_layout_change(struct raid_set *rs, bool use_mddev) in rs_is_layout_change() argument
1877 return (use_mddev ? rs->md.delta_disks : rs->delta_disks) || in rs_is_layout_change()
1878 rs->md.new_layout != rs->md.layout || in rs_is_layout_change()
1879 rs->md.new_chunk_sectors != rs->md.chunk_sectors; in rs_is_layout_change()
1882 /* True if @rs is requested to reshape by ctr */
1883 static bool rs_reshape_requested(struct raid_set *rs) in rs_reshape_requested() argument
1886 struct mddev *mddev = &rs->md; in rs_reshape_requested()
1888 if (rs_takeover_requested(rs)) in rs_reshape_requested()
1891 if (rs_is_raid0(rs)) in rs_reshape_requested()
1894 change = rs_is_layout_change(rs, false); in rs_reshape_requested()
1897 if (rs_is_raid1(rs)) { in rs_reshape_requested()
1898 if (rs->delta_disks) in rs_reshape_requested()
1899 return !!rs->delta_disks; in rs_reshape_requested()
1902 mddev->raid_disks != rs->raid_disks; in rs_reshape_requested()
1905 if (rs_is_raid10(rs)) in rs_reshape_requested()
1907 !__is_raid10_far(mddev->new_layout) && in rs_reshape_requested()
1908 rs->delta_disks >= 0; in rs_reshape_requested()
1916 /* State flags for sb->flags */
1922 * Devices with this superblock should only ever be accessed via device-mapper.
1992 * up to 256 devices with the 1.9.0 on-disk metadata format
1994 __le64 extended_failed_devices[DISKS_ARRAY_ELEMS - 1];
2002 * Check for reshape constraints on raid set @rs:
2004 * - reshape function non-existent
2005 * - degraded set
2006 * - ongoing recovery
2007 * - ongoing reshape
2009 * Returns 0 if none or -EPERM if given constraint
2012 static int rs_check_reshape(struct raid_set *rs) in rs_check_reshape() argument
2014 struct mddev *mddev = &rs->md; in rs_check_reshape()
2016 if (!mddev->pers || !mddev->pers->check_reshape) in rs_check_reshape()
2017 rs->ti->error = "Reshape not supported"; in rs_check_reshape()
2018 else if (mddev->degraded) in rs_check_reshape()
2019 rs->ti->error = "Can't reshape degraded raid set"; in rs_check_reshape()
2020 else if (rs_is_recovering(rs)) in rs_check_reshape()
2021 rs->ti->error = "Convert request on recovering raid set prohibited"; in rs_check_reshape()
2022 else if (rs_is_reshaping(rs)) in rs_check_reshape()
2023 rs->ti->error = "raid set already reshaping!"; in rs_check_reshape()
2024 else if (!(rs_is_raid1(rs) || rs_is_raid10(rs) || rs_is_raid456(rs))) in rs_check_reshape()
2025 rs->ti->error = "Reshaping only supported for raid1/4/5/6/10"; in rs_check_reshape()
2029 return -EPERM; in rs_check_reshape()
2034 BUG_ON(!rdev->sb_page); in read_disk_sb()
2036 if (rdev->sb_loaded && !force_reload) in read_disk_sb()
2039 rdev->sb_loaded = 0; in read_disk_sb()
2041 if (!sync_page_io(rdev, 0, size, rdev->sb_page, REQ_OP_READ, true)) { in read_disk_sb()
2043 rdev->raid_disk); in read_disk_sb()
2044 md_error(rdev->mddev, rdev); in read_disk_sb()
2045 set_bit(Faulty, &rdev->flags); in read_disk_sb()
2046 return -EIO; in read_disk_sb()
2049 rdev->sb_loaded = 1; in read_disk_sb()
2056 failed_devices[0] = le64_to_cpu(sb->failed_devices); in sb_retrieve_failed_devices()
2057 memset(failed_devices + 1, 0, sizeof(sb->extended_failed_devices)); in sb_retrieve_failed_devices()
2059 if (le32_to_cpu(sb->compat_features) & FEATURE_FLAG_SUPPORTS_V190) { in sb_retrieve_failed_devices()
2060 int i = ARRAY_SIZE(sb->extended_failed_devices); in sb_retrieve_failed_devices()
2062 while (i--) in sb_retrieve_failed_devices()
2063 failed_devices[i+1] = le64_to_cpu(sb->extended_failed_devices[i]); in sb_retrieve_failed_devices()
2069 int i = ARRAY_SIZE(sb->extended_failed_devices); in sb_update_failed_devices()
2071 sb->failed_devices = cpu_to_le64(failed_devices[0]); in sb_update_failed_devices()
2072 while (i--) in sb_update_failed_devices()
2073 sb->extended_failed_devices[i] = cpu_to_le64(failed_devices[i+1]); in sb_update_failed_devices()
2087 struct raid_set *rs = container_of(mddev, struct raid_set, md); in super_sync() local
2090 if (!rdev->meta_bdev) in super_sync()
2093 BUG_ON(!rdev->sb_page); in super_sync()
2095 sb = page_address(rdev->sb_page); in super_sync()
2099 for (i = 0; i < rs->raid_disks; i++) in super_sync()
2100 if (!rs->dev[i].data_dev || test_bit(Faulty, &rs->dev[i].rdev.flags)) { in super_sync()
2108 sb->magic = cpu_to_le32(DM_RAID_MAGIC); in super_sync()
2109 sb->compat_features = cpu_to_le32(FEATURE_FLAG_SUPPORTS_V190); in super_sync()
2111 sb->num_devices = cpu_to_le32(mddev->raid_disks); in super_sync()
2112 sb->array_position = cpu_to_le32(rdev->raid_disk); in super_sync()
2114 sb->events = cpu_to_le64(mddev->events); in super_sync()
2116 sb->disk_recovery_offset = cpu_to_le64(rdev->recovery_offset); in super_sync()
2117 sb->array_resync_offset = cpu_to_le64(mddev->recovery_cp); in super_sync()
2119 sb->level = cpu_to_le32(mddev->level); in super_sync()
2120 sb->layout = cpu_to_le32(mddev->layout); in super_sync()
2121 sb->stripe_sectors = cpu_to_le32(mddev->chunk_sectors); in super_sync()
2128 sb->new_level = cpu_to_le32(mddev->new_level); in super_sync()
2129 sb->new_layout = cpu_to_le32(mddev->new_layout); in super_sync()
2130 sb->new_stripe_sectors = cpu_to_le32(mddev->new_chunk_sectors); in super_sync()
2132 sb->delta_disks = cpu_to_le32(mddev->delta_disks); in super_sync()
2135 sb->reshape_position = cpu_to_le64(mddev->reshape_position); in super_sync()
2136 if (le64_to_cpu(sb->reshape_position) != MaxSector) { in super_sync()
2138 sb->flags |= cpu_to_le32(SB_FLAG_RESHAPE_ACTIVE); in super_sync()
2140 if (mddev->delta_disks < 0 || mddev->reshape_backwards) in super_sync()
2141 sb->flags |= cpu_to_le32(SB_FLAG_RESHAPE_BACKWARDS); in super_sync()
2144 sb->flags &= ~(cpu_to_le32(SB_FLAG_RESHAPE_ACTIVE|SB_FLAG_RESHAPE_BACKWARDS)); in super_sync()
2147 sb->array_sectors = cpu_to_le64(mddev->array_sectors); in super_sync()
2148 sb->data_offset = cpu_to_le64(rdev->data_offset); in super_sync()
2149 sb->new_data_offset = cpu_to_le64(rdev->new_data_offset); in super_sync()
2150 sb->sectors = cpu_to_le64(rdev->sectors); in super_sync()
2151 sb->incompat_features = cpu_to_le32(0); in super_sync()
2154 memset(sb + 1, 0, rdev->sb_size - sizeof(*sb)); in super_sync()
2163 * Return: 1 if use rdev, 0 if use refdev, -Exxx otherwise
2172 r = read_disk_sb(rdev, rdev->sb_size, false); in super_load()
2176 sb = page_address(rdev->sb_page); in super_load()
2183 if ((sb->magic != cpu_to_le32(DM_RAID_MAGIC)) || in super_load()
2184 (!test_bit(In_sync, &rdev->flags) && !rdev->recovery_offset)) { in super_load()
2185 super_sync(rdev->mddev, rdev); in super_load()
2187 set_bit(FirstUse, &rdev->flags); in super_load()
2188 sb->compat_features = cpu_to_le32(FEATURE_FLAG_SUPPORTS_V190); in super_load()
2191 set_bit(MD_SB_CHANGE_DEVS, &rdev->mddev->sb_flags); in super_load()
2200 events_sb = le64_to_cpu(sb->events); in super_load()
2202 refsb = page_address(refdev->sb_page); in super_load()
2203 events_refsb = le64_to_cpu(refsb->events); in super_load()
2208 static int super_init_validation(struct raid_set *rs, struct md_rdev *rdev) in super_init_validation() argument
2212 struct mddev *mddev = &rs->md; in super_init_validation()
2220 sb = page_address(rdev->sb_page); in super_init_validation()
2221 events_sb = le64_to_cpu(sb->events); in super_init_validation()
2226 mddev->events = events_sb ? : 1; in super_init_validation()
2228 mddev->reshape_position = MaxSector; in super_init_validation()
2230 mddev->raid_disks = le32_to_cpu(sb->num_devices); in super_init_validation()
2231 mddev->level = le32_to_cpu(sb->level); in super_init_validation()
2232 mddev->layout = le32_to_cpu(sb->layout); in super_init_validation()
2233 mddev->chunk_sectors = le32_to_cpu(sb->stripe_sectors); in super_init_validation()
2239 if (le32_to_cpu(sb->compat_features) & FEATURE_FLAG_SUPPORTS_V190) { in super_init_validation()
2241 mddev->new_level = le32_to_cpu(sb->new_level); in super_init_validation()
2242 mddev->new_layout = le32_to_cpu(sb->new_layout); in super_init_validation()
2243 mddev->new_chunk_sectors = le32_to_cpu(sb->new_stripe_sectors); in super_init_validation()
2244 mddev->delta_disks = le32_to_cpu(sb->delta_disks); in super_init_validation()
2245 mddev->array_sectors = le64_to_cpu(sb->array_sectors); in super_init_validation()
2248 if (le32_to_cpu(sb->flags) & SB_FLAG_RESHAPE_ACTIVE) { in super_init_validation()
2249 if (test_bit(__CTR_FLAG_DELTA_DISKS, &rs->ctr_flags)) { in super_init_validation()
2251 return -EINVAL; in super_init_validation()
2254 if (mddev->delta_disks < 0 || in super_init_validation()
2255 (!mddev->delta_disks && (le32_to_cpu(sb->flags) & SB_FLAG_RESHAPE_BACKWARDS))) in super_init_validation()
2256 mddev->reshape_backwards = 1; in super_init_validation()
2258 mddev->reshape_backwards = 0; in super_init_validation()
2260 mddev->reshape_position = le64_to_cpu(sb->reshape_position); in super_init_validation()
2261 rs->raid_type = get_raid_type_by_ll(mddev->level, mddev->layout); in super_init_validation()
2268 struct raid_type *rt_cur = get_raid_type_by_ll(mddev->level, mddev->layout); in super_init_validation()
2269 struct raid_type *rt_new = get_raid_type_by_ll(mddev->new_level, mddev->new_layout); in super_init_validation()
2271 if (rs_takeover_requested(rs)) { in super_init_validation()
2274 rt_cur->name, rt_new->name); in super_init_validation()
2277 return -EINVAL; in super_init_validation()
2278 } else if (rs_reshape_requested(rs)) { in super_init_validation()
2280 if (mddev->layout != mddev->new_layout) { in super_init_validation()
2283 rt_cur->name, rt_new->name); in super_init_validation()
2286 le32_to_cpu(sb->layout), mddev->new_layout); in super_init_validation()
2288 if (mddev->chunk_sectors != mddev->new_chunk_sectors) in super_init_validation()
2290 mddev->chunk_sectors, mddev->new_chunk_sectors); in super_init_validation()
2291 if (rs->delta_disks) in super_init_validation()
2293 mddev->raid_disks, mddev->raid_disks + rs->delta_disks); in super_init_validation()
2294 if (rs_is_raid10(rs)) { in super_init_validation()
2296 raid10_md_layout_to_format(mddev->layout), in super_init_validation()
2297 raid10_md_layout_to_copies(mddev->layout)); in super_init_validation()
2299 raid10_md_layout_to_format(mddev->new_layout), in super_init_validation()
2300 raid10_md_layout_to_copies(mddev->new_layout)); in super_init_validation()
2302 return -EINVAL; in super_init_validation()
2308 if (!test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) in super_init_validation()
2309 mddev->recovery_cp = le64_to_cpu(sb->array_resync_offset); in super_init_validation()
2314 * 1) The raid set is brand new - in which case, all of the in super_init_validation()
2318 * and the new device needs to be rebuilt - in which in super_init_validation()
2328 if (test_bit(Journal, &rdev->flags)) in super_init_validation()
2331 if (test_bit(FirstUse, &r->flags)) in super_init_validation()
2334 if (!test_bit(In_sync, &r->flags)) { in super_init_validation()
2336 r->raid_disk); in super_init_validation()
2339 if (test_bit(FirstUse, &r->flags)) in super_init_validation()
2346 if (new_devs == rs->raid_disks || !rebuilds) { in super_init_validation()
2348 if (new_devs == rs->raid_disks) { in super_init_validation()
2350 set_bit(MD_ARRAY_FIRST_USE, &mddev->flags); in super_init_validation()
2352 new_devs != rs->delta_disks) { in super_init_validation()
2355 return -EINVAL; in super_init_validation()
2359 " a raid set with %u other first-time devices", in super_init_validation()
2361 return -EINVAL; in super_init_validation()
2366 return -EINVAL; in super_init_validation()
2367 } else if (!test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags) && rs_is_recovering(rs)) { in super_init_validation()
2368 DMERR("'rebuild' specified while raid set is not in-sync (recovery_cp=%llu)", in super_init_validation()
2369 (unsigned long long) mddev->recovery_cp); in super_init_validation()
2370 return -EINVAL; in super_init_validation()
2371 } else if (rs_is_reshaping(rs)) { in super_init_validation()
2373 (unsigned long long) mddev->reshape_position); in super_init_validation()
2374 return -EINVAL; in super_init_validation()
2384 if (test_bit(Journal, &rdev->flags) || in super_init_validation()
2385 !r->sb_page) in super_init_validation()
2387 sb2 = page_address(r->sb_page); in super_init_validation()
2388 sb2->failed_devices = 0; in super_init_validation()
2389 memset(sb2->extended_failed_devices, 0, sizeof(sb2->extended_failed_devices)); in super_init_validation()
2392 * Check for any device re-ordering. in super_init_validation()
2394 if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) { in super_init_validation()
2395 role = le32_to_cpu(sb2->array_position); in super_init_validation()
2399 if (role != r->raid_disk) { in super_init_validation()
2400 if (rs_is_raid10(rs) && __is_raid10_near(mddev->layout)) { in super_init_validation()
2401 if (mddev->raid_disks % __raid10_near_copies(mddev->layout) || in super_init_validation()
2402 rs->raid_disks % rs->raid10_copies) { in super_init_validation()
2403 rs->ti->error = in super_init_validation()
2405 return -EINVAL; in super_init_validation()
2408 sb2->array_position = cpu_to_le32(r->raid_disk); in super_init_validation()
2410 } else if (!(rs_is_raid10(rs) && rt_is_raid0(rs->raid_type)) && in super_init_validation()
2411 !(rs_is_raid0(rs) && rt_is_raid10(rs->raid_type)) && in super_init_validation()
2412 !rt_is_raid1(rs->raid_type)) { in super_init_validation()
2413 rs->ti->error = "Cannot change device positions in raid set"; in super_init_validation()
2414 return -EINVAL; in super_init_validation()
2417 DMINFO("raid device #%d now at position #%d", role, r->raid_disk); in super_init_validation()
2425 set_bit(Faulty, &r->flags); in super_init_validation()
2432 static int super_validate(struct raid_set *rs, struct md_rdev *rdev) in super_validate() argument
2434 struct mddev *mddev = &rs->md; in super_validate()
2437 if (rs_is_raid0(rs) || !rdev->sb_page || rdev->raid_disk < 0) in super_validate()
2440 sb = page_address(rdev->sb_page); in super_validate()
2443 * If mddev->events is not set, we know we have not yet initialized in super_validate()
2446 if (!mddev->events && super_init_validation(rs, rdev)) in super_validate()
2447 return -EINVAL; in super_validate()
2449 if (le32_to_cpu(sb->compat_features) && in super_validate()
2450 le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) { in super_validate()
2451 rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags"; in super_validate()
2452 return -EINVAL; in super_validate()
2455 if (sb->incompat_features) { in super_validate()
2456 rs->ti->error = "Unable to assemble array: No incompatible feature flags supported yet"; in super_validate()
2457 return -EINVAL; in super_validate()
2460 /* Enable bitmap creation on @rs unless no metadevs or raid0 or journaled raid4/5/6 set. */ in super_validate()
2461 …mddev->bitmap_info.offset = (rt_is_raid0(rs->raid_type) || rs->journal_dev.dev) ? 0 : to_sector(40… in super_validate()
2462 mddev->bitmap_info.default_offset = mddev->bitmap_info.offset; in super_validate()
2464 if (!test_and_clear_bit(FirstUse, &rdev->flags)) { in super_validate()
2470 if (le32_to_cpu(sb->compat_features) & FEATURE_FLAG_SUPPORTS_V190) in super_validate()
2471 rdev->sectors = le64_to_cpu(sb->sectors); in super_validate()
2473 rdev->recovery_offset = le64_to_cpu(sb->disk_recovery_offset); in super_validate()
2474 if (rdev->recovery_offset == MaxSector) in super_validate()
2475 set_bit(In_sync, &rdev->flags); in super_validate()
2477 * If no reshape in progress -> we're recovering single in super_validate()
2478 * disk(s) and have to set the device(s) to out-of-sync in super_validate()
2480 else if (!rs_is_reshaping(rs)) in super_validate()
2481 clear_bit(In_sync, &rdev->flags); /* Mandatory for recovery */ in super_validate()
2487 if (test_and_clear_bit(Faulty, &rdev->flags)) { in super_validate()
2488 rdev->recovery_offset = 0; in super_validate()
2489 clear_bit(In_sync, &rdev->flags); in super_validate()
2490 rdev->saved_raid_disk = rdev->raid_disk; in super_validate()
2493 /* Reshape support -> restore repective data offsets */ in super_validate()
2494 rdev->data_offset = le64_to_cpu(sb->data_offset); in super_validate()
2495 rdev->new_data_offset = le64_to_cpu(sb->new_data_offset); in super_validate()
2503 static int analyse_superblocks(struct dm_target *ti, struct raid_set *rs) in analyse_superblocks() argument
2507 struct mddev *mddev = &rs->md; in analyse_superblocks()
2511 if (test_bit(Journal, &rdev->flags)) in analyse_superblocks()
2514 if (!rdev->meta_bdev) in analyse_superblocks()
2518 rdev->sb_start = 0; in analyse_superblocks()
2519 rdev->sb_size = bdev_logical_block_size(rdev->meta_bdev); in analyse_superblocks()
2520 if (rdev->sb_size < sizeof(struct dm_raid_superblock) || rdev->sb_size > PAGE_SIZE) { in analyse_superblocks()
2522 return -EINVAL; in analyse_superblocks()
2534 if (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags)) in analyse_superblocks()
2551 if (rs_is_raid0(rs)) in analyse_superblocks()
2557 * mistakenly acting as if '- -' got passed into the constructor). in analyse_superblocks()
2562 rdev->raid_disk = rdev->saved_raid_disk = -1; in analyse_superblocks()
2574 rs->ti->error = "Unable to assemble array: Invalid superblocks"; in analyse_superblocks()
2575 if (super_validate(rs, freshest)) in analyse_superblocks()
2576 return -EINVAL; in analyse_superblocks()
2578 if (validate_raid_redundancy(rs)) { in analyse_superblocks()
2579 rs->ti->error = "Insufficient redundancy to activate array"; in analyse_superblocks()
2580 return -EINVAL; in analyse_superblocks()
2584 if (!test_bit(Journal, &rdev->flags) && in analyse_superblocks()
2586 super_validate(rs, rdev)) in analyse_superblocks()
2587 return -EINVAL; in analyse_superblocks()
2592 * Adjust data_offset and new_data_offset on all disk members of @rs
2599 static int rs_adjust_data_offsets(struct raid_set *rs) in rs_adjust_data_offsets() argument
2605 if (!test_bit(__CTR_FLAG_DATA_OFFSET, &rs->ctr_flags)) { in rs_adjust_data_offsets()
2606 if (!rs_is_reshapable(rs)) in rs_adjust_data_offsets()
2613 rdev = &rs->dev[0].rdev; in rs_adjust_data_offsets()
2615 if (rs->delta_disks < 0) { in rs_adjust_data_offsets()
2619 * - before reshape: data is at offset 0 and free space in rs_adjust_data_offsets()
2622 * - after reshape: data is at offset rs->data_offset != 0 on each component LV in rs_adjust_data_offsets()
2625 new_data_offset = rs->data_offset; in rs_adjust_data_offsets()
2627 } else if (rs->delta_disks > 0) { in rs_adjust_data_offsets()
2631 * - before reshape: data is at offset rs->data_offset != 0 and in rs_adjust_data_offsets()
2634 * - after reshape: data is at offset 0 on each component LV in rs_adjust_data_offsets()
2636 data_offset = rs->data_offset; in rs_adjust_data_offsets()
2643 * - or - (data offset != 0) in rs_adjust_data_offsets()
2645 * Changing RAID layout or chunk size -> toggle offsets in rs_adjust_data_offsets()
2647 * - before reshape: data is at offset rs->data_offset 0 and in rs_adjust_data_offsets()
2649 * -or- in rs_adjust_data_offsets()
2650 * data is at offset rs->data_offset != 0 and in rs_adjust_data_offsets()
2653 * - after reshape: data is at offset 0 if it was at offset != 0 in rs_adjust_data_offsets()
2658 data_offset = rs->data_offset ? rdev->data_offset : 0; in rs_adjust_data_offsets()
2659 new_data_offset = data_offset ? 0 : rs->data_offset; in rs_adjust_data_offsets()
2660 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in rs_adjust_data_offsets()
2666 if (rs->data_offset && in rs_adjust_data_offsets()
2667 bdev_nr_sectors(rdev->bdev) - rs->md.dev_sectors < MIN_FREE_RESHAPE_SPACE) { in rs_adjust_data_offsets()
2668 rs->ti->error = data_offset ? "No space for forward reshape" : in rs_adjust_data_offsets()
2670 return -ENOSPC; in rs_adjust_data_offsets()
2677 if (rs->md.recovery_cp < rs->md.dev_sectors) in rs_adjust_data_offsets()
2678 rs->md.recovery_cp += rs->dev[0].rdev.data_offset; in rs_adjust_data_offsets()
2681 rdev_for_each(rdev, &rs->md) { in rs_adjust_data_offsets()
2682 if (!test_bit(Journal, &rdev->flags)) { in rs_adjust_data_offsets()
2683 rdev->data_offset = data_offset; in rs_adjust_data_offsets()
2684 rdev->new_data_offset = new_data_offset; in rs_adjust_data_offsets()
2691 /* Userpace reordered disks -> adjust raid_disk indexes in @rs */
2692 static void __reorder_raid_disk_indexes(struct raid_set *rs) in __reorder_raid_disk_indexes() argument
2697 rdev_for_each(rdev, &rs->md) { in __reorder_raid_disk_indexes()
2698 if (!test_bit(Journal, &rdev->flags)) { in __reorder_raid_disk_indexes()
2699 rdev->raid_disk = i++; in __reorder_raid_disk_indexes()
2700 rdev->saved_raid_disk = rdev->new_raid_disk = -1; in __reorder_raid_disk_indexes()
2706 * Setup @rs for takeover by a different raid level
2708 static int rs_setup_takeover(struct raid_set *rs) in rs_setup_takeover() argument
2710 struct mddev *mddev = &rs->md; in rs_setup_takeover()
2712 unsigned int d = mddev->raid_disks = rs->raid_disks; in rs_setup_takeover()
2713 sector_t new_data_offset = rs->dev[0].rdev.data_offset ? 0 : rs->data_offset; in rs_setup_takeover()
2715 if (rt_is_raid10(rs->raid_type)) { in rs_setup_takeover()
2716 if (rs_is_raid0(rs)) { in rs_setup_takeover()
2717 /* Userpace reordered disks -> adjust raid_disk indexes */ in rs_setup_takeover()
2718 __reorder_raid_disk_indexes(rs); in rs_setup_takeover()
2720 /* raid0 -> raid10_far layout */ in rs_setup_takeover()
2721 mddev->layout = raid10_format_to_md_layout(rs, ALGORITHM_RAID10_FAR, in rs_setup_takeover()
2722 rs->raid10_copies); in rs_setup_takeover()
2723 } else if (rs_is_raid1(rs)) in rs_setup_takeover()
2724 /* raid1 -> raid10_near layout */ in rs_setup_takeover()
2725 mddev->layout = raid10_format_to_md_layout(rs, ALGORITHM_RAID10_NEAR, in rs_setup_takeover()
2726 rs->raid_disks); in rs_setup_takeover()
2728 return -EINVAL; in rs_setup_takeover()
2732 clear_bit(MD_ARRAY_FIRST_USE, &mddev->flags); in rs_setup_takeover()
2733 mddev->recovery_cp = MaxSector; in rs_setup_takeover()
2735 while (d--) { in rs_setup_takeover()
2736 rdev = &rs->dev[d].rdev; in rs_setup_takeover()
2738 if (test_bit(d, (void *) rs->rebuild_disks)) { in rs_setup_takeover()
2739 clear_bit(In_sync, &rdev->flags); in rs_setup_takeover()
2740 clear_bit(Faulty, &rdev->flags); in rs_setup_takeover()
2741 mddev->recovery_cp = rdev->recovery_offset = 0; in rs_setup_takeover()
2743 set_bit(MD_ARRAY_FIRST_USE, &mddev->flags); in rs_setup_takeover()
2746 rdev->new_data_offset = new_data_offset; in rs_setup_takeover()
2752 /* Prepare @rs for reshape */
2753 static int rs_prepare_reshape(struct raid_set *rs) in rs_prepare_reshape() argument
2756 struct mddev *mddev = &rs->md; in rs_prepare_reshape()
2758 if (rs_is_raid10(rs)) { in rs_prepare_reshape()
2759 if (rs->raid_disks != mddev->raid_disks && in rs_prepare_reshape()
2760 __is_raid10_near(mddev->layout) && in rs_prepare_reshape()
2761 rs->raid10_copies && in rs_prepare_reshape()
2762 rs->raid10_copies != __raid10_near_copies(mddev->layout)) { in rs_prepare_reshape()
2769 if (rs->raid_disks % rs->raid10_copies) { in rs_prepare_reshape()
2770 rs->ti->error = "Can't reshape raid10 mirror groups"; in rs_prepare_reshape()
2771 return -EINVAL; in rs_prepare_reshape()
2774 /* Userpace reordered disks to add/remove mirrors -> adjust raid_disk indexes */ in rs_prepare_reshape()
2775 __reorder_raid_disk_indexes(rs); in rs_prepare_reshape()
2776 mddev->layout = raid10_format_to_md_layout(rs, ALGORITHM_RAID10_NEAR, in rs_prepare_reshape()
2777 rs->raid10_copies); in rs_prepare_reshape()
2778 mddev->new_layout = mddev->layout; in rs_prepare_reshape()
2783 } else if (rs_is_raid456(rs)) in rs_prepare_reshape()
2786 else if (rs_is_raid1(rs)) { in rs_prepare_reshape()
2787 if (rs->delta_disks) { in rs_prepare_reshape()
2789 mddev->degraded = rs->delta_disks < 0 ? -rs->delta_disks : rs->delta_disks; in rs_prepare_reshape()
2793 mddev->raid_disks = rs->raid_disks; in rs_prepare_reshape()
2797 rs->ti->error = "Called with bogus raid type"; in rs_prepare_reshape()
2798 return -EINVAL; in rs_prepare_reshape()
2802 set_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags); in rs_prepare_reshape()
2803 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in rs_prepare_reshape()
2804 } else if (mddev->raid_disks < rs->raid_disks) in rs_prepare_reshape()
2806 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in rs_prepare_reshape()
2812 static sector_t _get_reshape_sectors(struct raid_set *rs) in _get_reshape_sectors() argument
2817 rdev_for_each(rdev, &rs->md) in _get_reshape_sectors()
2818 if (!test_bit(Journal, &rdev->flags)) { in _get_reshape_sectors()
2819 reshape_sectors = (rdev->data_offset > rdev->new_data_offset) ? in _get_reshape_sectors()
2820 rdev->data_offset - rdev->new_data_offset : in _get_reshape_sectors()
2821 rdev->new_data_offset - rdev->data_offset; in _get_reshape_sectors()
2825 return max(reshape_sectors, (sector_t) rs->data_offset); in _get_reshape_sectors()
2830 * - change raid layout
2831 * - change chunk size
2832 * - add disks
2833 * - remove disks
2835 static int rs_setup_reshape(struct raid_set *rs) in rs_setup_reshape() argument
2839 sector_t reshape_sectors = _get_reshape_sectors(rs); in rs_setup_reshape()
2840 struct mddev *mddev = &rs->md; in rs_setup_reshape()
2843 mddev->delta_disks = rs->delta_disks; in rs_setup_reshape()
2844 cur_raid_devs = mddev->raid_disks; in rs_setup_reshape()
2847 if (mddev->delta_disks && in rs_setup_reshape()
2848 mddev->layout != mddev->new_layout) { in rs_setup_reshape()
2849 DMINFO("Ignoring invalid layout change with delta_disks=%d", rs->delta_disks); in rs_setup_reshape()
2850 mddev->new_layout = mddev->layout; in rs_setup_reshape()
2856 * - in case of adding disk(s), array size has in rs_setup_reshape()
2862 * - in case of removing disk(s), array size in rs_setup_reshape()
2868 * - data_offset and new_data_offset are in rs_setup_reshape()
2876 if (rs->delta_disks > 0) { in rs_setup_reshape()
2878 for (d = cur_raid_devs; d < rs->raid_disks; d++) { in rs_setup_reshape()
2879 rdev = &rs->dev[d].rdev; in rs_setup_reshape()
2880 clear_bit(In_sync, &rdev->flags); in rs_setup_reshape()
2883 * save_raid_disk needs to be -1, or recovery_offset will be set to 0 in rs_setup_reshape()
2886 rdev->saved_raid_disk = -1; in rs_setup_reshape()
2887 rdev->raid_disk = d; in rs_setup_reshape()
2889 rdev->sectors = mddev->dev_sectors; in rs_setup_reshape()
2890 rdev->recovery_offset = rs_is_raid1(rs) ? 0 : MaxSector; in rs_setup_reshape()
2893 mddev->reshape_backwards = 0; /* adding disk(s) -> forward reshape */ in rs_setup_reshape()
2896 } else if (rs->delta_disks < 0) { in rs_setup_reshape()
2897 r = rs_set_dev_and_array_sectors(rs, rs->ti->len, true); in rs_setup_reshape()
2898 mddev->reshape_backwards = 1; /* removing disk(s) -> backward reshape */ in rs_setup_reshape()
2903 * Reshape layout (e.g. raid5_ls -> raid5_n) and/or chunk size: in rs_setup_reshape()
2905 * keeping number of disks and do layout change -> in rs_setup_reshape()
2909 * - free space upfront -> reshape forward in rs_setup_reshape()
2911 * - free space at the end -> reshape backward in rs_setup_reshape()
2920 * add disk(s) -> begin in rs_setup_reshape()
2921 * remove disk(s)-> end in rs_setup_reshape()
2923 mddev->reshape_backwards = rs->dev[0].rdev.data_offset ? 0 : 1; in rs_setup_reshape()
2930 if (!mddev->reshape_backwards) in rs_setup_reshape()
2931 rdev_for_each(rdev, &rs->md) in rs_setup_reshape()
2932 if (!test_bit(Journal, &rdev->flags)) in rs_setup_reshape()
2933 rdev->sectors += reshape_sectors; in rs_setup_reshape()
2941 * changes -> reset the latter.
2943 static void rs_reset_inconclusive_reshape(struct raid_set *rs) in rs_reset_inconclusive_reshape() argument
2945 if (!rs_is_reshaping(rs) && rs_is_layout_change(rs, true)) { in rs_reset_inconclusive_reshape()
2946 rs_set_cur(rs); in rs_reset_inconclusive_reshape()
2947 rs->md.delta_disks = 0; in rs_reset_inconclusive_reshape()
2948 rs->md.reshape_backwards = 0; in rs_reset_inconclusive_reshape()
2956 static void configure_discard_support(struct raid_set *rs) in configure_discard_support() argument
2960 struct dm_target *ti = rs->ti; in configure_discard_support()
2965 raid456 = rs_is_raid456(rs); in configure_discard_support()
2967 for (i = 0; i < rs->raid_disks; i++) { in configure_discard_support()
2968 if (!rs->dev[i].rdev.bdev || in configure_discard_support()
2969 !bdev_max_discard_sectors(rs->dev[i].rdev.bdev)) in configure_discard_support()
2975 DMERR("Set dm-raid.devices_handle_discard_safely=Y to override."); in configure_discard_support()
2981 ti->num_discard_bios = 1; in configure_discard_support()
3004 struct raid_set *rs = NULL; in raid_ctr() local
3015 ti->error = "No arguments"; in raid_ctr()
3016 return -EINVAL; in raid_ctr()
3021 ti->error = "Unrecognised raid_type"; in raid_ctr()
3022 return -EINVAL; in raid_ctr()
3026 if (dm_read_arg_group(_args, &as, &num_raid_params, &ti->error)) in raid_ctr()
3027 return -EINVAL; in raid_ctr()
3032 _args[1].max = (as_nrd.argc - 1) / 2; in raid_ctr()
3033 if (dm_read_arg(_args + 1, &as_nrd, &num_raid_devs, &ti->error)) in raid_ctr()
3034 return -EINVAL; in raid_ctr()
3037 ti->error = "Invalid number of supplied raid devices"; in raid_ctr()
3038 return -EINVAL; in raid_ctr()
3041 rs = raid_set_alloc(ti, rt, num_raid_devs); in raid_ctr()
3042 if (IS_ERR(rs)) in raid_ctr()
3043 return PTR_ERR(rs); in raid_ctr()
3045 r = parse_raid_params(rs, &as, num_raid_params); in raid_ctr()
3049 r = parse_dev_params(rs, &as); in raid_ctr()
3053 rs->md.sync_super = super_sync; in raid_ctr()
3061 r = rs_set_dev_and_array_sectors(rs, rs->ti->len, false); in raid_ctr()
3066 rs->array_sectors = rs->md.array_sectors; in raid_ctr()
3067 rs->dev_sectors = rs->md.dev_sectors; in raid_ctr()
3074 rs_config_backup(rs, &rs_layout); in raid_ctr()
3076 r = analyse_superblocks(ti, rs); in raid_ctr()
3080 /* All in-core metadata now as of current superblocks after calling analyse_superblocks() */ in raid_ctr()
3081 sb_array_sectors = rs->md.array_sectors; in raid_ctr()
3082 rdev_sectors = __rdev_sectors(rs); in raid_ctr()
3084 ti->error = "Invalid rdev size"; in raid_ctr()
3085 r = -EINVAL; in raid_ctr()
3090 reshape_sectors = _get_reshape_sectors(rs); in raid_ctr()
3091 if (rs->dev_sectors != rdev_sectors) { in raid_ctr()
3092 resize = (rs->dev_sectors != rdev_sectors - reshape_sectors); in raid_ctr()
3093 if (rs->dev_sectors > rdev_sectors - reshape_sectors) in raid_ctr()
3094 set_bit(RT_FLAG_RS_GROW, &rs->runtime_flags); in raid_ctr()
3097 INIT_WORK(&rs->md.event_work, do_table_event); in raid_ctr()
3098 ti->private = rs; in raid_ctr()
3099 ti->num_flush_bios = 1; in raid_ctr()
3100 ti->needs_bio_set_dev = true; in raid_ctr()
3103 rs_config_restore(rs, &rs_layout); in raid_ctr()
3111 if (test_bit(MD_ARRAY_FIRST_USE, &rs->md.flags)) { in raid_ctr()
3112 /* A new raid6 set has to be recovered to ensure proper parity and Q-Syndrome */ in raid_ctr()
3113 if (rs_is_raid6(rs) && in raid_ctr()
3114 test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) { in raid_ctr()
3115 ti->error = "'nosync' not allowed for new raid6 set"; in raid_ctr()
3116 r = -EINVAL; in raid_ctr()
3119 rs_setup_recovery(rs, 0); in raid_ctr()
3120 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in raid_ctr()
3121 rs_set_new(rs); in raid_ctr()
3122 } else if (rs_is_recovering(rs)) { in raid_ctr()
3125 } else if (rs_is_reshaping(rs)) { in raid_ctr()
3128 ti->error = "Can't resize a reshaping raid set"; in raid_ctr()
3129 r = -EPERM; in raid_ctr()
3132 /* skip setup rs */ in raid_ctr()
3133 } else if (rs_takeover_requested(rs)) { in raid_ctr()
3134 if (rs_is_reshaping(rs)) { in raid_ctr()
3135 ti->error = "Can't takeover a reshaping raid set"; in raid_ctr()
3136 r = -EPERM; in raid_ctr()
3141 if (test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { in raid_ctr()
3142 ti->error = "Can't takeover a journaled raid4/5/6 set"; in raid_ctr()
3143 r = -EPERM; in raid_ctr()
3155 r = rs_check_takeover(rs); in raid_ctr()
3159 r = rs_setup_takeover(rs); in raid_ctr()
3163 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in raid_ctr()
3165 rs_setup_recovery(rs, MaxSector); in raid_ctr()
3166 rs_set_new(rs); in raid_ctr()
3167 } else if (rs_reshape_requested(rs)) { in raid_ctr()
3169 clear_bit(RT_FLAG_RS_GROW, &rs->runtime_flags); in raid_ctr()
3177 if (test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { in raid_ctr()
3178 ti->error = "Can't reshape a journaled raid4/5/6 set"; in raid_ctr()
3179 r = -EPERM; in raid_ctr()
3183 /* Out-of-place space has to be available to allow for a reshape unless raid1! */ in raid_ctr()
3184 if (reshape_sectors || rs_is_raid1(rs)) { in raid_ctr()
3192 r = rs_prepare_reshape(rs); in raid_ctr()
3197 rs_setup_recovery(rs, MaxSector); in raid_ctr()
3199 rs_set_cur(rs); in raid_ctr()
3203 if (test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags)) { in raid_ctr()
3204 clear_bit(RT_FLAG_RS_GROW, &rs->runtime_flags); in raid_ctr()
3205 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in raid_ctr()
3206 rs_setup_recovery(rs, MaxSector); in raid_ctr()
3207 } else if (test_bit(RT_FLAG_RS_GROW, &rs->runtime_flags)) { in raid_ctr()
3212 r = rs_set_dev_and_array_sectors(rs, sb_array_sectors, false); in raid_ctr()
3216 …rs_setup_recovery(rs, rs->md.recovery_cp < rs->md.dev_sectors ? rs->md.recovery_cp : rs->md.dev_se… in raid_ctr()
3219 r = rs_set_dev_and_array_sectors(rs, rs->ti->len, false); in raid_ctr()
3223 if (sb_array_sectors > rs->array_sectors) in raid_ctr()
3224 set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); in raid_ctr()
3226 rs_set_cur(rs); in raid_ctr()
3230 r = rs_adjust_data_offsets(rs); in raid_ctr()
3235 rs_reset_inconclusive_reshape(rs); in raid_ctr()
3237 /* Start raid set read-only and assumed clean to change in raid_resume() */ in raid_ctr()
3238 rs->md.ro = 1; in raid_ctr()
3239 rs->md.in_sync = 1; in raid_ctr()
3242 set_bit(MD_RECOVERY_FROZEN, &rs->md.recovery); in raid_ctr()
3245 mddev_lock_nointr(&rs->md); in raid_ctr()
3246 r = md_run(&rs->md); in raid_ctr()
3247 rs->md.in_sync = 0; /* Assume already marked dirty */ in raid_ctr()
3249 ti->error = "Failed to run raid array"; in raid_ctr()
3250 mddev_unlock(&rs->md); in raid_ctr()
3254 r = md_start(&rs->md); in raid_ctr()
3256 ti->error = "Failed to start raid array"; in raid_ctr()
3257 mddev_unlock(&rs->md); in raid_ctr()
3261 /* If raid4/5/6 journal mode explicitly requested (only possible with journal dev) -> set it */ in raid_ctr()
3262 if (test_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) { in raid_ctr()
3263 r = r5c_journal_mode_set(&rs->md, rs->journal_dev.mode); in raid_ctr()
3265 ti->error = "Failed to set raid4/5/6 journal mode"; in raid_ctr()
3266 mddev_unlock(&rs->md); in raid_ctr()
3271 mddev_suspend(&rs->md); in raid_ctr()
3272 set_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags); in raid_ctr()
3275 if (rs_is_raid456(rs)) { in raid_ctr()
3276 r = rs_set_raid456_stripe_cache(rs); in raid_ctr()
3282 if (test_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags)) { in raid_ctr()
3283 r = rs_check_reshape(rs); in raid_ctr()
3288 rs_config_restore(rs, &rs_layout); in raid_ctr()
3290 if (rs->md.pers->start_reshape) { in raid_ctr()
3291 r = rs->md.pers->check_reshape(&rs->md); in raid_ctr()
3293 ti->error = "Reshape check failed"; in raid_ctr()
3300 configure_discard_support(rs); in raid_ctr()
3302 mddev_unlock(&rs->md); in raid_ctr()
3309 md_stop(&rs->md); in raid_ctr()
3311 raid_set_free(rs); in raid_ctr()
3318 struct raid_set *rs = ti->private; in raid_dtr() local
3320 md_stop(&rs->md); in raid_dtr()
3321 raid_set_free(rs); in raid_dtr()
3326 struct raid_set *rs = ti->private; in raid_map() local
3327 struct mddev *mddev = &rs->md; in raid_map()
3330 * If we're reshaping to add disk(s)), ti->len and in raid_map()
3331 * mddev->array_sectors will differ during the process in raid_map()
3332 * (ti->len > mddev->array_sectors), so we have to requeue in raid_map()
3333 * bios with addresses > mddev->array_sectors here or in raid_map()
3337 if (unlikely(bio_end_sector(bio) > mddev->array_sectors)) in raid_map()
3360 return __within_range(state, 0, ARRAY_SIZE(sync_strs) - 1) ? sync_strs[state] : "undef"; in sync_str()
3372 (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &recovery)))) { in decipher_sync_action()
3387 if (mddev->reshape_position != MaxSector) in decipher_sync_action()
3400 * 'a' = Alive but not in-sync raid set component _or_ alive raid4/5/6 'write_back' journal device
3401 * 'A' = Alive and in-sync raid set component _or_ alive raid4/5/6 'write_through' journal device
3402 * '-' = Non-existing device (i.e. uspace passed '- -' into the ctr)
3404 static const char *__raid_dev_status(struct raid_set *rs, struct md_rdev *rdev) in __raid_dev_status() argument
3406 if (!rdev->bdev) in __raid_dev_status()
3407 return "-"; in __raid_dev_status()
3408 else if (test_bit(Faulty, &rdev->flags)) in __raid_dev_status()
3410 else if (test_bit(Journal, &rdev->flags)) in __raid_dev_status()
3411 return (rs->journal_dev.mode == R5C_JOURNAL_MODE_WRITE_THROUGH) ? "A" : "a"; in __raid_dev_status()
3412 else if (test_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags) || in __raid_dev_status()
3413 (!test_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags) && in __raid_dev_status()
3414 !test_bit(In_sync, &rdev->flags))) in __raid_dev_status()
3420 /* Helper to return resync/reshape progress for @rs and runtime flags for raid set in sync / resync…
3421 static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery, in rs_get_progress() argument
3425 struct mddev *mddev = &rs->md; in rs_get_progress()
3427 clear_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3428 clear_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); in rs_get_progress()
3430 if (rs_is_raid0(rs)) { in rs_get_progress()
3432 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3436 r = mddev->recovery_cp; in rs_get_progress()
3438 r = mddev->curr_resync_completed; in rs_get_progress()
3446 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3463 set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); in rs_get_progress()
3471 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3476 * caused by components still set to in-sync by constructor. in rs_get_progress()
3478 set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); in rs_get_progress()
3489 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3491 if (!test_bit(Journal, &rdev->flags) && in rs_get_progress()
3492 !test_bit(In_sync, &rdev->flags)) { in rs_get_progress()
3493 clear_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
3502 /* Helper to return @dev name or "-" if !@dev */
3505 return dev ? dev->name : "-"; in __get_dev_name()
3511 struct raid_set *rs = ti->private; in raid_status() local
3512 struct mddev *mddev = &rs->md; in raid_status()
3513 struct r5conf *conf = rs_is_raid456(rs) ? mddev->private : NULL; in raid_status()
3514 int i, max_nr_stripes = conf ? conf->max_nr_stripes : 0; in raid_status()
3526 rt = get_raid_type_by_ll(mddev->new_level, mddev->new_layout); in raid_status()
3530 DMEMIT("%s %d ", rt->name, mddev->raid_disks); in raid_status()
3535 resync_max_sectors = test_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags) ? in raid_status()
3536 mddev->resync_max_sectors : mddev->dev_sectors; in raid_status()
3537 recovery = rs->md.recovery; in raid_status()
3539 progress = rs_get_progress(rs, recovery, state, resync_max_sectors); in raid_status()
3540 resync_mismatches = (mddev->last_sync_action && !strcasecmp(mddev->last_sync_action, "check")) ? in raid_status()
3541 atomic64_read(&mddev->resync_mismatches) : 0; in raid_status()
3543 /* HM FIXME: do we want another state char for raid0? It shows 'D'/'A'/'-' now */ in raid_status()
3544 for (i = 0; i < rs->raid_disks; i++) in raid_status()
3545 DMEMIT(__raid_dev_status(rs, &rs->dev[i].rdev)); in raid_status()
3548 * In-sync/Reshape ratio: in raid_status()
3549 * The in-sync ratio shows the progress of: in raid_status()
3550 * - Initializing the raid set in raid_status()
3551 * - Rebuilding a subset of devices of the raid set in raid_status()
3566 * See Documentation/admin-guide/device-mapper/dm-raid.rst for in raid_status()
3590 DMEMIT(" %llu", (unsigned long long) rs->dev[0].rdev.data_offset); in raid_status()
3595 DMEMIT(" %s", test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags) ? in raid_status()
3596 __raid_dev_status(rs, &rs->journal_dev.rdev) : "-"); in raid_status()
3606 for (i = 0; i < rs->raid_disks; i++) { in raid_status()
3607 rebuild_writemostly_count += (test_bit(i, (void *) rs->rebuild_disks) ? 2 : 0) + in raid_status()
3608 (test_bit(WriteMostly, &rs->dev[i].rdev.flags) ? 2 : 0); in raid_status()
3610 rebuild_writemostly_count -= (test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags) ? 2 : 0) + in raid_status()
3611 (test_bit(__CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags) ? 2 : 0); in raid_status()
3614 hweight32(rs->ctr_flags & CTR_FLAG_OPTIONS_NO_ARGS) + in raid_status()
3615 hweight32(rs->ctr_flags & CTR_FLAG_OPTIONS_ONE_ARG) * 2; in raid_status()
3618 DMEMIT("%s %u %u", rs->raid_type->name, raid_param_cnt, mddev->new_chunk_sectors); in raid_status()
3619 if (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags)) in raid_status()
3621 if (test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) in raid_status()
3623 if (test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags)) in raid_status()
3624 for (i = 0; i < rs->raid_disks; i++) in raid_status()
3625 if (test_bit(i, (void *) rs->rebuild_disks)) in raid_status()
3627 if (test_bit(__CTR_FLAG_DAEMON_SLEEP, &rs->ctr_flags)) in raid_status()
3629 mddev->bitmap_info.daemon_sleep); in raid_status()
3630 if (test_bit(__CTR_FLAG_MIN_RECOVERY_RATE, &rs->ctr_flags)) in raid_status()
3632 mddev->sync_speed_min); in raid_status()
3633 if (test_bit(__CTR_FLAG_MAX_RECOVERY_RATE, &rs->ctr_flags)) in raid_status()
3635 mddev->sync_speed_max); in raid_status()
3636 if (test_bit(__CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags)) in raid_status()
3637 for (i = 0; i < rs->raid_disks; i++) in raid_status()
3638 if (test_bit(WriteMostly, &rs->dev[i].rdev.flags)) in raid_status()
3640 rs->dev[i].rdev.raid_disk); in raid_status()
3641 if (test_bit(__CTR_FLAG_MAX_WRITE_BEHIND, &rs->ctr_flags)) in raid_status()
3643 mddev->bitmap_info.max_write_behind); in raid_status()
3644 if (test_bit(__CTR_FLAG_STRIPE_CACHE, &rs->ctr_flags)) in raid_status()
3647 if (test_bit(__CTR_FLAG_REGION_SIZE, &rs->ctr_flags)) in raid_status()
3649 (unsigned long long) to_sector(mddev->bitmap_info.chunksize)); in raid_status()
3650 if (test_bit(__CTR_FLAG_RAID10_COPIES, &rs->ctr_flags)) in raid_status()
3652 raid10_md_layout_to_copies(mddev->layout)); in raid_status()
3653 if (test_bit(__CTR_FLAG_RAID10_FORMAT, &rs->ctr_flags)) in raid_status()
3655 raid10_md_layout_to_format(mddev->layout)); in raid_status()
3656 if (test_bit(__CTR_FLAG_DELTA_DISKS, &rs->ctr_flags)) in raid_status()
3658 max(rs->delta_disks, mddev->delta_disks)); in raid_status()
3659 if (test_bit(__CTR_FLAG_DATA_OFFSET, &rs->ctr_flags)) in raid_status()
3661 (unsigned long long) rs->data_offset); in raid_status()
3662 if (test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) in raid_status()
3664 __get_dev_name(rs->journal_dev.dev)); in raid_status()
3665 if (test_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) in raid_status()
3667 md_journal_mode_to_dm_raid(rs->journal_dev.mode)); in raid_status()
3668 DMEMIT(" %d", rs->raid_disks); in raid_status()
3669 for (i = 0; i < rs->raid_disks; i++) in raid_status()
3670 DMEMIT(" %s %s", __get_dev_name(rs->dev[i].meta_dev), in raid_status()
3671 __get_dev_name(rs->dev[i].data_dev)); in raid_status()
3675 rt = get_raid_type_by_ll(mddev->new_level, mddev->new_layout); in raid_status()
3679 DMEMIT_TARGET_NAME_VERSION(ti->type); in raid_status()
3680 DMEMIT(",raid_type=%s,raid_disks=%d", rt->name, mddev->raid_disks); in raid_status()
3684 recovery = rs->md.recovery; in raid_status()
3688 for (i = 0; i < rs->raid_disks; i++) { in raid_status()
3690 DMEMIT(__raid_dev_status(rs, &rs->dev[i].rdev)); in raid_status()
3695 switch (rs->journal_dev.mode) { in raid_status()
3717 struct raid_set *rs = ti->private; in raid_message() local
3718 struct mddev *mddev = &rs->md; in raid_message()
3720 if (!mddev->pers || !mddev->pers->sync_request) in raid_message()
3721 return -EINVAL; in raid_message()
3724 set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); in raid_message()
3726 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); in raid_message()
3729 if (mddev->sync_thread) { in raid_message()
3730 set_bit(MD_RECOVERY_INTR, &mddev->recovery); in raid_message()
3731 md_unregister_thread(&mddev->sync_thread); in raid_message()
3734 } else if (decipher_sync_action(mddev, mddev->recovery) != st_idle) in raid_message()
3735 return -EBUSY; in raid_message()
3739 set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); in raid_message()
3742 set_bit(MD_RECOVERY_CHECK, &mddev->recovery); in raid_message()
3743 set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); in raid_message()
3744 set_bit(MD_RECOVERY_SYNC, &mddev->recovery); in raid_message()
3746 set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); in raid_message()
3747 set_bit(MD_RECOVERY_SYNC, &mddev->recovery); in raid_message()
3749 return -EINVAL; in raid_message()
3751 if (mddev->ro == 2) { in raid_message()
3753 * canceling read-auto mode in raid_message()
3755 mddev->ro = 0; in raid_message()
3756 if (!mddev->suspended && mddev->sync_thread) in raid_message()
3757 md_wakeup_thread(mddev->sync_thread); in raid_message()
3759 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); in raid_message()
3760 if (!mddev->suspended && mddev->thread) in raid_message()
3761 md_wakeup_thread(mddev->thread); in raid_message()
3769 struct raid_set *rs = ti->private; in raid_iterate_devices() local
3773 for (i = 0; !r && i < rs->raid_disks; i++) { in raid_iterate_devices()
3774 if (rs->dev[i].data_dev) { in raid_iterate_devices()
3775 r = fn(ti, rs->dev[i].data_dev, in raid_iterate_devices()
3777 rs->md.dev_sectors, data); in raid_iterate_devices()
3786 struct raid_set *rs = ti->private; in raid_io_hints() local
3787 unsigned int chunk_size_bytes = to_bytes(rs->md.chunk_sectors); in raid_io_hints()
3790 blk_limits_io_opt(limits, chunk_size_bytes * mddev_data_stripes(rs)); in raid_io_hints()
3795 struct raid_set *rs = ti->private; in raid_postsuspend() local
3797 if (!test_and_set_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags)) { in raid_postsuspend()
3799 if (!test_bit(MD_RECOVERY_FROZEN, &rs->md.recovery)) in raid_postsuspend()
3800 md_stop_writes(&rs->md); in raid_postsuspend()
3802 mddev_lock_nointr(&rs->md); in raid_postsuspend()
3803 mddev_suspend(&rs->md); in raid_postsuspend()
3804 mddev_unlock(&rs->md); in raid_postsuspend()
3808 static void attempt_restore_of_faulty_devices(struct raid_set *rs) in attempt_restore_of_faulty_devices() argument
3815 struct mddev *mddev = &rs->md; in attempt_restore_of_faulty_devices()
3819 if (!mddev->pers || !mddev->pers->hot_add_disk || !mddev->pers->hot_remove_disk) in attempt_restore_of_faulty_devices()
3824 for (i = 0; i < rs->raid_disks; i++) { in attempt_restore_of_faulty_devices()
3825 r = &rs->dev[i].rdev; in attempt_restore_of_faulty_devices()
3827 if (test_bit(Journal, &r->flags)) in attempt_restore_of_faulty_devices()
3830 if (test_bit(Faulty, &r->flags) && in attempt_restore_of_faulty_devices()
3831 r->meta_bdev && !read_disk_sb(r, r->sb_size, true)) { in attempt_restore_of_faulty_devices()
3834 rs->raid_type->name, i); in attempt_restore_of_faulty_devices()
3842 * '>= 0' - meaning we must call this function in attempt_restore_of_faulty_devices()
3845 flags = r->flags; in attempt_restore_of_faulty_devices()
3846 clear_bit(In_sync, &r->flags); /* Mandatory for hot remove. */ in attempt_restore_of_faulty_devices()
3847 if (r->raid_disk >= 0) { in attempt_restore_of_faulty_devices()
3848 if (mddev->pers->hot_remove_disk(mddev, r)) { in attempt_restore_of_faulty_devices()
3850 r->flags = flags; in attempt_restore_of_faulty_devices()
3854 r->raid_disk = r->saved_raid_disk = i; in attempt_restore_of_faulty_devices()
3856 clear_bit(Faulty, &r->flags); in attempt_restore_of_faulty_devices()
3857 clear_bit(WriteErrorSeen, &r->flags); in attempt_restore_of_faulty_devices()
3859 if (mddev->pers->hot_add_disk(mddev, r)) { in attempt_restore_of_faulty_devices()
3861 r->raid_disk = r->saved_raid_disk = -1; in attempt_restore_of_faulty_devices()
3862 r->flags = flags; in attempt_restore_of_faulty_devices()
3864 clear_bit(In_sync, &r->flags); in attempt_restore_of_faulty_devices()
3865 r->recovery_offset = 0; in attempt_restore_of_faulty_devices()
3876 rdev_for_each(r, &rs->md) { in attempt_restore_of_faulty_devices()
3877 if (test_bit(Journal, &r->flags)) in attempt_restore_of_faulty_devices()
3880 sb = page_address(r->sb_page); in attempt_restore_of_faulty_devices()
3891 static int __load_dirty_region_bitmap(struct raid_set *rs) in __load_dirty_region_bitmap() argument
3896 if (!rs_is_raid0(rs) && in __load_dirty_region_bitmap()
3897 !test_and_set_bit(RT_FLAG_RS_BITMAP_LOADED, &rs->runtime_flags)) { in __load_dirty_region_bitmap()
3898 r = md_bitmap_load(&rs->md); in __load_dirty_region_bitmap()
3907 static void rs_update_sbs(struct raid_set *rs) in rs_update_sbs() argument
3909 struct mddev *mddev = &rs->md; in rs_update_sbs()
3910 int ro = mddev->ro; in rs_update_sbs()
3912 set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); in rs_update_sbs()
3913 mddev->ro = 0; in rs_update_sbs()
3915 mddev->ro = ro; in rs_update_sbs()
3919 * Reshape changes raid algorithm of @rs to new one within personality
3920 * (e.g. raid6_zr -> raid6_nc), changes stripe size, adds/removes
3925 static int rs_start_reshape(struct raid_set *rs) in rs_start_reshape() argument
3928 struct mddev *mddev = &rs->md; in rs_start_reshape()
3929 struct md_personality *pers = mddev->pers; in rs_start_reshape()
3932 set_bit(MD_RECOVERY_WAIT, &mddev->recovery); in rs_start_reshape()
3934 r = rs_setup_reshape(rs); in rs_start_reshape()
3941 * May as well already kick the reshape off so that * pers->start_reshape() becomes optional. in rs_start_reshape()
3943 r = pers->check_reshape(mddev); in rs_start_reshape()
3945 rs->ti->error = "pers->check_reshape() failed"; in rs_start_reshape()
3953 if (pers->start_reshape) { in rs_start_reshape()
3954 r = pers->start_reshape(mddev); in rs_start_reshape()
3956 rs->ti->error = "pers->start_reshape() failed"; in rs_start_reshape()
3966 rs_update_sbs(rs); in rs_start_reshape()
3974 struct raid_set *rs = ti->private; in raid_preresume() local
3975 struct mddev *mddev = &rs->md; in raid_preresume()
3977 /* This is a resume after a suspend of the set -> it's already started. */ in raid_preresume()
3978 if (test_and_set_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags)) in raid_preresume()
3987 if (test_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags)) in raid_preresume()
3988 rs_update_sbs(rs); in raid_preresume()
3991 r = __load_dirty_region_bitmap(rs); in raid_preresume()
3996 if (test_bit(RT_FLAG_RS_GROW, &rs->runtime_flags)) { in raid_preresume()
3997 mddev->array_sectors = rs->array_sectors; in raid_preresume()
3998 mddev->dev_sectors = rs->dev_sectors; in raid_preresume()
3999 rs_set_rdev_sectors(rs); in raid_preresume()
4000 rs_set_capacity(rs); in raid_preresume()
4004 if (test_bit(RT_FLAG_RS_BITMAP_LOADED, &rs->runtime_flags) && mddev->bitmap && in raid_preresume()
4005 (test_bit(RT_FLAG_RS_GROW, &rs->runtime_flags) || in raid_preresume()
4006 (rs->requested_bitmap_chunk_sectors && in raid_preresume()
4007 mddev->bitmap_info.chunksize != to_bytes(rs->requested_bitmap_chunk_sectors)))) { in raid_preresume()
4008 int chunksize = to_bytes(rs->requested_bitmap_chunk_sectors) ?: mddev->bitmap_info.chunksize; in raid_preresume()
4010 r = md_bitmap_resize(mddev->bitmap, mddev->dev_sectors, chunksize, 0); in raid_preresume()
4015 /* Check for any resize/reshape on @rs and adjust/initiate */ in raid_preresume()
4017 set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); in raid_preresume()
4018 if (mddev->recovery_cp && mddev->recovery_cp < MaxSector) { in raid_preresume()
4019 set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); in raid_preresume()
4020 mddev->resync_min = mddev->recovery_cp; in raid_preresume()
4021 if (test_bit(RT_FLAG_RS_GROW, &rs->runtime_flags)) in raid_preresume()
4022 mddev->resync_max_sectors = mddev->dev_sectors; in raid_preresume()
4026 if (test_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags)) { in raid_preresume()
4028 rs_set_rdev_sectors(rs); in raid_preresume()
4030 r = rs_start_reshape(rs); in raid_preresume()
4042 struct raid_set *rs = ti->private; in raid_resume() local
4043 struct mddev *mddev = &rs->md; in raid_resume()
4045 if (test_and_set_bit(RT_FLAG_RS_RESUMED, &rs->runtime_flags)) { in raid_resume()
4051 attempt_restore_of_faulty_devices(rs); in raid_resume()
4054 if (test_and_clear_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags)) { in raid_resume()
4056 if (mddev->delta_disks < 0) in raid_resume()
4057 rs_set_capacity(rs); in raid_resume()
4060 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); in raid_resume()
4061 mddev->ro = 0; in raid_resume()
4062 mddev->in_sync = 0; in raid_resume()
4106 MODULE_ALIAS("dm-raid0");
4107 MODULE_ALIAS("dm-raid1");
4108 MODULE_ALIAS("dm-raid10");
4109 MODULE_ALIAS("dm-raid4");
4110 MODULE_ALIAS("dm-raid5");
4111 MODULE_ALIAS("dm-raid6");
4112 MODULE_AUTHOR("Neil Brown <dm-devel@redhat.com>");
4113 MODULE_AUTHOR("Heinz Mauelshagen <dm-devel@redhat.com>");