When creating raid5 or striped plexes, avoid falling out of bounds

when checking the given stripe size.

Also move the code a bit around to avoid duplication.

Approved by: joerg (mentor)
This commit is contained in:
Lukas Ertl 2004-02-04 22:29:52 +00:00
parent 0804ed5acc
commit 3a1ab63eb7

View File

@ -1281,7 +1281,9 @@ config_plex(int update)
int namedplexno; int namedplexno;
enum plexstate state = plex_init; /* state to set at end */ enum plexstate state = plex_init; /* state to set at end */
int preferme; /* set if we want to be preferred access */ int preferme; /* set if we want to be preferred access */
int stripesize;
stripesize = 0;
current_plex = -1; /* forget the previous plex */ current_plex = -1; /* forget the previous plex */
preferme = 0; /* nothing special yet */ preferme = 0; /* nothing special yet */
plexno = get_empty_plex(); /* allocate a plex */ plexno = get_empty_plex(); /* allocate a plex */
@ -1339,52 +1341,53 @@ config_plex(int update)
case kw_striped: case kw_striped:
{ {
int stripesize = sizespec(token[++parameter]);
plex->organization = plex_striped; plex->organization = plex_striped;
if (stripesize % DEV_BSIZE != 0) /* not a multiple of block size, */
throw_rude_remark(EINVAL, "plex %s: stripe size %d not a multiple of sector size", if (++parameter >= tokens) /* No stripe size specified. */
plex->name, stripesize = 0;
stripesize);
else else
plex->stripesize = stripesize / DEV_BSIZE; stripesize = sizespec(token[parameter]);
break; break;
} }
case kw_raid4: case kw_raid4:
{ {
int stripesize = sizespec(token[++parameter]);
plex->organization = plex_raid4; plex->organization = plex_raid4;
if (stripesize % DEV_BSIZE != 0) /* not a multiple of block size, */
throw_rude_remark(EINVAL, "plex %s: stripe size %d not a multiple of sector size", if (++parameter >= tokens) /* No stripe size specified. */
plex->name, stripesize = 0;
stripesize);
else else
plex->stripesize = stripesize / DEV_BSIZE; stripesize = sizespec(token[parameter]);
break; break;
} }
case kw_raid5: case kw_raid5:
{ {
int stripesize = sizespec(token[++parameter]);
plex->organization = plex_raid5; plex->organization = plex_raid5;
if (stripesize % DEV_BSIZE != 0) /* not a multiple of block size, */
throw_rude_remark(EINVAL, "plex %s: stripe size %d not a multiple of sector size", if (++parameter >= tokens) /* No stripe size specified. */
plex->name, stripesize = 0;
stripesize);
else else
plex->stripesize = stripesize / DEV_BSIZE; stripesize = sizespec(token[parameter]);
break; break;
} }
default: default:
throw_rude_remark(EINVAL, "Invalid plex organization"); throw_rude_remark(EINVAL, "Invalid plex organization");
} }
if (isstriped(plex) if (isstriped(plex)) {
&& (plex->stripesize == 0)) /* didn't specify a valid stripe size */ if (stripesize == 0) /* didn't specify a valid stripe size */
throw_rude_remark(EINVAL, "Need a stripe size parameter"); throw_rude_remark(EINVAL, "Need a stripe size parameter");
else if (stripesize % DEV_BSIZE != 0)
throw_rude_remark(EINVAL, "plex %s: stripe size %d not a multiple of sector size",
plex->name,
stripesize);
else
plex->stripesize = stripesize / DEV_BSIZE;
}
break; break;
/* /*