Skip to contentSkip to conversation

DM RAID: Restructure conditional

PATCH Superseded Jonathan Brassow 1 participant 3 messages Jun 26, 2012 – Jul 24, 2012 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DM RAID: Restructure conditional

dm-raid: For code clarity, change 'if' conditional to 'switch' conditional

In preparation for RAID10 addition to dm-raid, we change an 'if' conditional to a 'switch' conditional to make it easier to see what is being checked for each RAID type.

drivers/md/dm-raid.c +19 -6
Index: linux-upstream/drivers/md/dm-raid.c
===================================================================
@@ -422,13 +422,26 @@ static int parse_raid_params(struct raid
 
 		if (!strcasecmp(key, "rebuild")) {
 			rebuild_cnt++;
-			if (((rs->raid_type->level != 1) &&
-			     (rebuild_cnt > rs->raid_type->parity_devs)) ||
-			    ((rs->raid_type->level == 1) &&
-			     (rebuild_cnt > (rs->md.raid_disks - 1)))) {
-				rs->ti->error = "Too many rebuild devices specified for given RAID type";
-				return -EINVAL;
+			rs->ti->error = NULL;
+
+			switch (rs->raid_type->level) {
+			case 1:
+				if (rebuild_cnt >= rs->md.raid_disks)
+					rs->ti->error = "Too many rebuild devices specified";
+				break;
+			case 4:
+			case 5:
+			case 6:
+				if (rebuild_cnt > rs->raid_type->parity_devs)
+					rs->ti->error = "Too many rebuild devices specified for given RAID type";
+				break;
+			default:
+				DMERR("The rebuild parameter is not supported for %s", rs->raid_type->name);
+				rs->ti->error = "Rebuild not supported for this RAID type";
 			}
+			if (rs->ti->error)
+				return -EINVAL;
+
 			if (value > rs->md.raid_disks) {
 				rs->ti->error = "Invalid rebuild index given";
 				return -EINVAL;
#1 lore raw

PATCH v2 1/1 DM RAID: Restructure conditional

Version 2 in response to minor conflicts found with existing patches in linux-next

brassow

dm-raid: For code clarity, change 'if' conditional to 'switch' conditional

In preparation for RAID10 addition to dm-raid, we change an 'if' conditional to a 'switch' conditional to make it easier to see what is being checked for each RAID type.

drivers/md/dm-raid.c +19 -6
Index: linux-upstream/drivers/md/dm-raid.c
===================================================================
@@ -423,13 +423,26 @@ static int parse_raid_params(struct raid
 
 		if (!strcasecmp(key, "rebuild")) {
 			rebuild_cnt++;
-			if (((rs->raid_type->level != 1) &&
-			     (rebuild_cnt > rs->raid_type->parity_devs)) ||
-			    ((rs->raid_type->level == 1) &&
-			     (rebuild_cnt > (rs->md.raid_disks - 1)))) {
-				rs->ti->error = "Too many rebuild devices specified for given RAID type";
-				return -EINVAL;
+			rs->ti->error = NULL;
+
+			switch (rs->raid_type->level) {
+			case 1:
+				if (rebuild_cnt >= rs->md.raid_disks)
+					rs->ti->error = "Too many rebuild devices specified";
+				break;
+			case 4:
+			case 5:
+			case 6:
+				if (rebuild_cnt > rs->raid_type->parity_devs)
+					rs->ti->error = "Too many rebuild devices specified for given RAID type";
+				break;
+			default:
+				DMERR("The rebuild parameter is not supported for %s", rs->raid_type->name);
+				rs->ti->error = "Rebuild not supported for this RAID type";
 			}
+			if (rs->ti->error)
+				return -EINVAL;
+
 			if (value > rs->md.raid_disks) {
 				rs->ti->error = "Invalid rebuild index given";
 				return -EINVAL;
#2 lore raw

PATCH v3 1/1 DM RAID: Restructure conditional

In reply to Jonathan Brassow

Minor update to this patch so that we don't ever set 'ti->error' to NULL...

brassow

dm-raid: For code clarity, change 'if' conditional to 'switch' conditional

In preparation for RAID10 addition to dm-raid, we change an 'if' conditional to a 'switch' conditional to make it easier to see what is being checked for each RAID type.

drivers/md/dm-raid.c +18 -5
Index: linux-upstream/drivers/md/dm-raid.c
===================================================================
@@ -423,11 +423,24 @@ static int parse_raid_params(struct raid
 
 		if (!strcasecmp(key, "rebuild")) {
 			rebuild_cnt++;
-			if (((rs->raid_type->level != 1) &&
-			     (rebuild_cnt > rs->raid_type->parity_devs)) ||
-			    ((rs->raid_type->level == 1) &&
-			     (rebuild_cnt > (rs->md.raid_disks - 1)))) {
-				rs->ti->error = "Too many rebuild devices specified for given RAID type";
+			switch (rs->raid_type->level) {
+			case 1:
+				if (rebuild_cnt >= rs->md.raid_disks) {
+					rs->ti->error = "Too many rebuild devices specified";
+					return -EINVAL;
+				}
+				break;
+			case 4:
+			case 5:
+			case 6:
+				if (rebuild_cnt > rs->raid_type->parity_devs) {
+					rs->ti->error = "Too many rebuild devices specified for given RAID type";
+					return -EINVAL;
+				}
+				break;
+			default:
+				DMERR("The rebuild parameter is not supported for %s", rs->raid_type->name);
+				rs->ti->error = "Rebuild not supported for this RAID type";
 				return -EINVAL;
 			}
 			if (value > rs->md.raid_disks) {