Lines Matching full:rs
59 * Bits for establishing rs->ctr_flags
88 * Flags for rs->ctr_flags field.
199 * Flags for rs->runtime_flags field
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()
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()
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()
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()
598 static int raid10_format_to_md_layout(struct raid_set *rs, in raid10_format_to_md_layout() argument
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()
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()
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()
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()
730 mddev->raid_disks = rs->raid_disks; in rs_set_new()
738 struct raid_set *rs; in raid_set_alloc() local
745 rs = kzalloc(struct_size(rs, dev, raid_devs), GFP_KERNEL); in raid_set_alloc()
746 if (!rs) { 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()
819 static int parse_dev_params(struct raid_set *rs, struct dm_arg_set *as) in parse_dev_params() argument
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()
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()
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()
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()
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()
920 rs->ti->error = "Unable to rebuild drive while array is not in-sync"; in parse_dev_params()
929 * @rs
932 * Set rs->md.bitmap_info.chunksize (which really refers to 'region size').
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()
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()
969 rs->ti->error = "Supplied region size is too small"; in validate_region_size()
974 rs->ti->error = "Region size is not a power of 2"; 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()
987 rs->md.bitmap_info.chunksize = to_bytes(region_size); in validate_region_size()
994 * @rs
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()
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()
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()
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()
1139 rs->ti->error = "Bad numerical argument given for chunk_size"; in parse_raid_params()
1152 rs->ti->error = "Chunk size must be a power of 2"; in parse_raid_params()
1155 rs->ti->error = "Chunk size value is too small"; in parse_raid_params()
1159 rs->md.new_chunk_sectors = rs->md.chunk_sectors = value; 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()
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()
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()
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()
1218 rs->ti->error = "Wrong number of raid parameters given"; 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()
1232 rs->ti->error = "'raid10_format' is an invalid parameter for this RAID type"; 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()
1253 rs->ti->error = "'journal_dev' is an invalid parameter for this RAID type"; 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()
1268 rs->ti->error = "No space for raid4/5/6 journal"; in parse_raid_params()
1271 rs->journal_dev.mode = R5C_JOURNAL_MODE_WRITE_THROUGH; 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()
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()
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()
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()
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()
1321 rd = rs->dev + value; 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()
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()
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()
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()
1356 rs->ti->error = "Max write-behind limit out of range"; 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()
1367 rs->ti->error = "daemon sleep period out of range"; 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()
1380 rs->ti->error = "Bogus data_offset value"; in parse_raid_params()
1383 rs->data_offset = value; 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()
1392 rs->ti->error = "Too many delta_disk requested"; 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()
1404 rs->ti->error = "Inappropriate argument: stripe_cache"; in parse_raid_params()
1409 rs->ti->error = "Bogus stripe cache entries value"; 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()
1420 rs->ti->error = "min_recovery_rate out of range"; 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()
1431 rs->ti->error = "max_recovery_rate out of range"; 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()
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()
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()
1457 rs->ti->error = "Unable to parse RAID parameter"; 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()
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()
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()
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()
1486 if (validate_region_size(rs, region_size)) 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()
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()
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()
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()
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()
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()
1555 rs->ti->error = "Cannot change stripe_cache size on inactive RAID set"; 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
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()
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()
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()
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()
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()
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()
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()
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()
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()
1724 if (rs_is_reshaping(rs)) { in rs_check_takeover()
1725 rs->ti->error = "Can't takeover reshaping raid set"; in rs_check_takeover()
1738 !(rs->raid_disks % mddev->raid_disks)) in rs_check_takeover()
1864 rs->ti->error = "takeover not possible"; 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()
1908 rs->delta_disks >= 0; in rs_reshape_requested()
2002 * Check for reshape constraints on raid set @rs:
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()
2017 rs->ti->error = "Reshape not supported"; 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()
2087 struct raid_set *rs = container_of(mddev, struct raid_set, md); in super_sync() local
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()
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()
2249 if (test_bit(__CTR_FLAG_DELTA_DISKS, &rs->ctr_flags)) { in super_init_validation()
2261 rs->raid_type = get_raid_type_by_ll(mddev->level, mddev->layout); in super_init_validation()
2271 if (rs_takeover_requested(rs)) { in super_init_validation()
2278 } else if (rs_reshape_requested(rs)) { 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()
2308 if (!test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_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()
2352 new_devs != rs->delta_disks) { in super_init_validation()
2367 } else if (!test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags) && rs_is_recovering(rs)) { in super_init_validation()
2371 } else if (rs_is_reshaping(rs)) { in super_init_validation()
2400 if (rs_is_raid10(rs) && __is_raid10_near(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()
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()
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()
2446 if (!mddev->events && super_init_validation(rs, rdev)) in super_validate()
2451 rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags"; in super_validate()
2456 rs->ti->error = "Unable to assemble array: No incompatible feature flags supported yet"; 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()
2480 else if (!rs_is_reshaping(rs)) 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()
2534 if (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags)) in analyse_superblocks()
2551 if (rs_is_raid0(rs)) 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()
2578 if (validate_raid_redundancy(rs)) { in analyse_superblocks()
2579 rs->ti->error = "Insufficient redundancy to activate array"; in analyse_superblocks()
2586 super_validate(rs, rdev)) 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()
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()
2636 data_offset = rs->data_offset; in rs_adjust_data_offsets()
2647 * - before reshape: data is at offset rs->data_offset 0 and in rs_adjust_data_offsets()
2650 * data is at offset rs->data_offset != 0 and 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()
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()
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()
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()
2718 __reorder_raid_disk_indexes(rs); 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()
2725 mddev->layout = raid10_format_to_md_layout(rs, ALGORITHM_RAID10_NEAR, in rs_setup_takeover()
2726 rs->raid_disks); 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()
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()
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()
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()
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()
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()
2825 return max(reshape_sectors, (sector_t) rs->data_offset); in _get_reshape_sectors()
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()
2849 DMINFO("Ignoring invalid layout change with delta_disks=%d", rs->delta_disks); 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()
2890 rdev->recovery_offset = rs_is_raid1(rs) ? 0 : MaxSector; 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()
2923 mddev->reshape_backwards = rs->dev[0].rdev.data_offset ? 0 : 1; in rs_setup_reshape()
2931 rdev_for_each(rdev, &rs->md) in rs_setup_reshape()
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()
3004 struct raid_set *rs = NULL; in raid_ctr() local
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()
3081 sb_array_sectors = rs->md.array_sectors; in raid_ctr()
3082 rdev_sectors = __rdev_sectors(rs); 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()
3103 rs_config_restore(rs, &rs_layout); in raid_ctr()
3111 if (test_bit(MD_ARRAY_FIRST_USE, &rs->md.flags)) { in raid_ctr()
3113 if (rs_is_raid6(rs) && in raid_ctr()
3114 test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) { 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()
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()
3141 if (test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { 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()
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()
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()
3250 mddev_unlock(&rs->md); in raid_ctr()
3254 r = md_start(&rs->md); in raid_ctr()
3257 mddev_unlock(&rs->md); 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()
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()
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()
3404 static const char *__raid_dev_status(struct raid_set *rs, struct md_rdev *rdev) in __raid_dev_status() argument
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()
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()
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()
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()
3493 clear_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); in rs_get_progress()
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()
3535 resync_max_sectors = test_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags) ? 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()
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()
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()
3630 if (test_bit(__CTR_FLAG_MIN_RECOVERY_RATE, &rs->ctr_flags)) in raid_status()
3633 if (test_bit(__CTR_FLAG_MAX_RECOVERY_RATE, &rs->ctr_flags)) 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()
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()
3650 if (test_bit(__CTR_FLAG_RAID10_COPIES, &rs->ctr_flags)) in raid_status()
3653 if (test_bit(__CTR_FLAG_RAID10_FORMAT, &rs->ctr_flags)) 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()
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()
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()
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()
3834 rs->raid_type->name, i); in attempt_restore_of_faulty_devices()
3876 rdev_for_each(r, &rs->md) { 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()
3919 * Reshape changes raid algorithm of @rs to new one within personality
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()
3934 r = rs_setup_reshape(rs); in rs_start_reshape()
3945 rs->ti->error = "pers->check_reshape() failed"; 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()
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()
4015 /* Check for any resize/reshape on @rs and adjust/initiate */ in raid_preresume()
4021 if (test_bit(RT_FLAG_RS_GROW, &rs->runtime_flags)) 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()
4057 rs_set_capacity(rs); in raid_resume()