diff options
author | Heinz Mauelshagen <heinzm@redhat.com> | 2016-05-19 12:49:29 -0400 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2016-06-13 14:40:28 -0400 |
commit | 676fa5ad6e96e5704b0f2d5bb56ea115c807eef4 (patch) | |
tree | a78ad1408ad500091ff167bd8dd92abad6ed1d3a /drivers/md/dm-raid.c | |
parent | ad51d7f1d1731f0fd62690edda706288bc965abb (diff) |
dm raid: use rt_is_raid*() in all appropriate checks
Make use if raid type rt_is_*() bool functions for simplification and
consistency reasons.
Signed-off-by: Heinz Mauelshagen <heinzm@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md/dm-raid.c')
-rw-r--r-- | drivers/md/dm-raid.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c index 668398dfba32..719612440dfc 100644 --- a/drivers/md/dm-raid.c +++ b/drivers/md/dm-raid.c | |||
@@ -260,6 +260,12 @@ static bool rt_is_raid6(struct raid_type *rt) | |||
260 | { | 260 | { |
261 | return rt->level == 6; | 261 | return rt->level == 6; |
262 | } | 262 | } |
263 | |||
264 | /* Return true, if raid type in @rt is raid4/5/6 */ | ||
265 | static bool rt_is_raid456(struct raid_type *rt) | ||
266 | { | ||
267 | return _in_range(rt->level, 4, 6); | ||
268 | } | ||
263 | /* END: raid level bools */ | 269 | /* END: raid level bools */ |
264 | 270 | ||
265 | /* | 271 | /* |
@@ -723,7 +729,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, | |||
723 | * First, parse the in-order required arguments | 729 | * First, parse the in-order required arguments |
724 | * "chunk_size" is the only argument of this type. | 730 | * "chunk_size" is the only argument of this type. |
725 | */ | 731 | */ |
726 | if (rs->raid_type->level == 1) { | 732 | if (rt_is_raid1(rs->raid_type)) { |
727 | if (value) | 733 | if (value) |
728 | DMERR("Ignoring chunk size parameter for RAID 1"); | 734 | DMERR("Ignoring chunk size parameter for RAID 1"); |
729 | value = 0; | 735 | value = 0; |
@@ -788,7 +794,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, | |||
788 | if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_RAID10_FORMAT))) { | 794 | if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_RAID10_FORMAT))) { |
789 | if (_test_and_set_flag(CTR_FLAG_RAID10_FORMAT, &rs->ctr_flags)) | 795 | if (_test_and_set_flag(CTR_FLAG_RAID10_FORMAT, &rs->ctr_flags)) |
790 | return ti_error_einval(rs->ti, "Only one raid10_format argument pair allowed"); | 796 | return ti_error_einval(rs->ti, "Only one raid10_format argument pair allowed"); |
791 | if (rs->raid_type->level != 10) | 797 | if (!rt_is_raid10(rs->raid_type)) |
792 | return ti_error_einval(rs->ti, "'raid10_format' is an invalid parameter for this RAID type"); | 798 | return ti_error_einval(rs->ti, "'raid10_format' is an invalid parameter for this RAID type"); |
793 | if (strcmp("near", arg) && | 799 | if (strcmp("near", arg) && |
794 | strcmp("far", arg) && | 800 | strcmp("far", arg) && |
@@ -817,7 +823,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, | |||
817 | rd->rdev.recovery_offset = 0; | 823 | rd->rdev.recovery_offset = 0; |
818 | _set_flag(CTR_FLAG_REBUILD, &rs->ctr_flags); | 824 | _set_flag(CTR_FLAG_REBUILD, &rs->ctr_flags); |
819 | } else if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_WRITE_MOSTLY))) { | 825 | } else if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_WRITE_MOSTLY))) { |
820 | if (rs->raid_type->level != 1) | 826 | if (!rt_is_raid1(rs->raid_type)) |
821 | return ti_error_einval(rs->ti, "write_mostly option is only valid for RAID1"); | 827 | return ti_error_einval(rs->ti, "write_mostly option is only valid for RAID1"); |
822 | 828 | ||
823 | if (!_in_range(value, 0, rs->md.raid_disks - 1)) | 829 | if (!_in_range(value, 0, rs->md.raid_disks - 1)) |
@@ -826,7 +832,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, | |||
826 | set_bit(WriteMostly, &rs->dev[value].rdev.flags); | 832 | set_bit(WriteMostly, &rs->dev[value].rdev.flags); |
827 | _set_flag(CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags); | 833 | _set_flag(CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags); |
828 | } else if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_MAX_WRITE_BEHIND))) { | 834 | } else if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_MAX_WRITE_BEHIND))) { |
829 | if (rs->raid_type->level != 1) | 835 | if (!rt_is_raid1(rs->raid_type)) |
830 | return ti_error_einval(rs->ti, "max_write_behind option is only valid for RAID1"); | 836 | return ti_error_einval(rs->ti, "max_write_behind option is only valid for RAID1"); |
831 | 837 | ||
832 | if (_test_and_set_flag(CTR_FLAG_MAX_WRITE_BEHIND, &rs->ctr_flags)) | 838 | if (_test_and_set_flag(CTR_FLAG_MAX_WRITE_BEHIND, &rs->ctr_flags)) |
@@ -856,7 +862,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, | |||
856 | */ | 862 | */ |
857 | value /= 2; | 863 | value /= 2; |
858 | 864 | ||
859 | if (!_in_range(rs->raid_type->level, 4, 6)) | 865 | if (!rt_is_raid456(rs->raid_type)) |
860 | return ti_error_einval(rs->ti, "Inappropriate argument: stripe_cache"); | 866 | return ti_error_einval(rs->ti, "Inappropriate argument: stripe_cache"); |
861 | if (raid5_set_cache_size(&rs->md, (int)value)) | 867 | if (raid5_set_cache_size(&rs->md, (int)value)) |
862 | return ti_error_einval(rs->ti, "Bad stripe_cache size"); | 868 | return ti_error_einval(rs->ti, "Bad stripe_cache size"); |
@@ -903,7 +909,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, | |||
903 | if (dm_set_target_max_io_len(rs->ti, max_io_len)) | 909 | if (dm_set_target_max_io_len(rs->ti, max_io_len)) |
904 | return -EINVAL; | 910 | return -EINVAL; |
905 | 911 | ||
906 | if (rs->raid_type->level == 10) { | 912 | if (rt_is_raid10(rs->raid_type)) { |
907 | if (raid10_copies > rs->md.raid_disks) | 913 | if (raid10_copies > rs->md.raid_disks) |
908 | return ti_error_einval(rs->ti, "Not enough devices to satisfy specification"); | 914 | return ti_error_einval(rs->ti, "Not enough devices to satisfy specification"); |
909 | 915 | ||
@@ -921,7 +927,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, | |||
921 | rs->md.layout = raid10_format_to_md_layout(raid10_format, | 927 | rs->md.layout = raid10_format_to_md_layout(raid10_format, |
922 | raid10_copies); | 928 | raid10_copies); |
923 | rs->md.new_layout = rs->md.layout; | 929 | rs->md.new_layout = rs->md.layout; |
924 | } else if ((!rs->raid_type->level || rs->raid_type->level > 1) && | 930 | } else if (!rt_is_raid1(rs->raid_type) && |
925 | sector_div(sectors_per_dev, | 931 | sector_div(sectors_per_dev, |
926 | (rs->md.raid_disks - rs->raid_type->parity_devs))) | 932 | (rs->md.raid_disks - rs->raid_type->parity_devs))) |
927 | return ti_error_einval(rs->ti, "Target length not divisible by number of data devices"); | 933 | return ti_error_einval(rs->ti, "Target length not divisible by number of data devices"); |
@@ -1142,7 +1148,7 @@ static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev) | |||
1142 | } | 1148 | } |
1143 | 1149 | ||
1144 | /* We can only change the number of devices in RAID1 right now */ | 1150 | /* We can only change the number of devices in RAID1 right now */ |
1145 | if ((rs->raid_type->level != 1) && | 1151 | if (!rt_is_raid1(rs->raid_type) && |
1146 | (le32_to_cpu(sb->num_devices) != mddev->raid_disks)) { | 1152 | (le32_to_cpu(sb->num_devices) != mddev->raid_disks)) { |
1147 | DMERR("Reshaping arrays not yet supported. (device count change)"); | 1153 | DMERR("Reshaping arrays not yet supported. (device count change)"); |
1148 | return -EINVAL; | 1154 | return -EINVAL; |
@@ -1206,7 +1212,7 @@ static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev) | |||
1206 | if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) { | 1212 | if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) { |
1207 | role = le32_to_cpu(sb2->array_position); | 1213 | role = le32_to_cpu(sb2->array_position); |
1208 | if (role != r->raid_disk) { | 1214 | if (role != r->raid_disk) { |
1209 | if (rs->raid_type->level != 1) | 1215 | if (!rt_is_raid1(rs->raid_type)) |
1210 | return ti_error_einval(rs->ti, "Cannot change device " | 1216 | return ti_error_einval(rs->ti, "Cannot change device " |
1211 | "positions in RAID array"); | 1217 | "positions in RAID array"); |
1212 | DMINFO("RAID1 device #%d now at position #%d", | 1218 | DMINFO("RAID1 device #%d now at position #%d", |
@@ -1243,7 +1249,7 @@ static int super_validate(struct raid_set *rs, struct md_rdev *rdev) | |||
1243 | } | 1249 | } |
1244 | 1250 | ||
1245 | /* Enable bitmap creation for RAID levels != 0 */ | 1251 | /* Enable bitmap creation for RAID levels != 0 */ |
1246 | mddev->bitmap_info.offset = (rs->raid_type->level) ? to_sector(4096) : 0; | 1252 | mddev->bitmap_info.offset = rt_is_raid0(rs->raid_type) ? 0 : to_sector(4096); |
1247 | rdev->mddev->bitmap_info.default_offset = mddev->bitmap_info.offset; | 1253 | rdev->mddev->bitmap_info.default_offset = mddev->bitmap_info.offset; |
1248 | 1254 | ||
1249 | if (!test_bit(FirstUse, &rdev->flags)) { | 1255 | if (!test_bit(FirstUse, &rdev->flags)) { |
@@ -1564,7 +1570,7 @@ static void raid_status(struct dm_target *ti, status_type_t type, | |||
1564 | case STATUSTYPE_INFO: | 1570 | case STATUSTYPE_INFO: |
1565 | DMEMIT("%s %d ", rs->raid_type->name, rs->md.raid_disks); | 1571 | DMEMIT("%s %d ", rs->raid_type->name, rs->md.raid_disks); |
1566 | 1572 | ||
1567 | if (rs->raid_type->level) { | 1573 | if (!rt_is_raid0(rs->raid_type)) { |
1568 | if (test_bit(MD_RECOVERY_RUNNING, &rs->md.recovery)) | 1574 | if (test_bit(MD_RECOVERY_RUNNING, &rs->md.recovery)) |
1569 | sync = rs->md.curr_resync_completed; | 1575 | sync = rs->md.curr_resync_completed; |
1570 | else | 1576 | else |
@@ -1887,7 +1893,7 @@ static void raid_resume(struct dm_target *ti) | |||
1887 | { | 1893 | { |
1888 | struct raid_set *rs = ti->private; | 1894 | struct raid_set *rs = ti->private; |
1889 | 1895 | ||
1890 | if (rs->raid_type->level) { | 1896 | if (!rt_is_raid0(rs->raid_type)) { |
1891 | set_bit(MD_CHANGE_DEVS, &rs->md.flags); | 1897 | set_bit(MD_CHANGE_DEVS, &rs->md.flags); |
1892 | 1898 | ||
1893 | if (!rs->bitmap_loaded) { | 1899 | if (!rs->bitmap_loaded) { |