imsm: fix default chunk in the !orom case

Set a valid default in the !orom case, otherwise we segfault, or
otherwise fail.

Cc: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
Dan Williams 2011-07-19 06:52:29 +10:00 committed by NeilBrown
parent ca0748fa49
commit cd9d1ac715
2 changed files with 20 additions and 27 deletions

View File

@ -167,21 +167,6 @@ static inline int fls(int x)
return r; return r;
} }
/**
* imsm_orom_default_chunk - return the largest chunk size supported via orom
* @orom: orom pointer from find_imsm_orom
*/
static inline int imsm_orom_default_chunk(const struct imsm_orom *orom)
{
int fs = fls(orom->sss);
if (!fs)
return 0;
return min(512, (1 << fs));
}
enum sys_dev_type { enum sys_dev_type {
SYS_DEV_UNKNOWN = 0, SYS_DEV_UNKNOWN = 0,
SYS_DEV_SAS, SYS_DEV_SAS,
@ -189,7 +174,6 @@ enum sys_dev_type {
SYS_DEV_MAX SYS_DEV_MAX
}; };
struct sys_dev { struct sys_dev {
enum sys_dev_type type; enum sys_dev_type type;
char *path; char *path;

View File

@ -4915,6 +4915,15 @@ static int is_raid_level_supported(const struct imsm_orom *orom, int level, int
return 0; return 0;
} }
static int imsm_default_chunk(const struct imsm_orom *orom)
{
/* up to 512 if the plaform supports it, otherwise the platform max.
* 128 if no platform detected
*/
int fs = max(7, orom ? fls(orom->sss) : 0);
return min(512, (1 << fs));
}
#define pr_vrb(fmt, arg...) (void) (verbose && fprintf(stderr, Name fmt, ##arg)) #define pr_vrb(fmt, arg...) (void) (verbose && fprintf(stderr, Name fmt, ##arg))
/* /*
@ -4943,15 +4952,16 @@ validate_geometry_imsm_orom(struct intel_super *super, int level, int layout,
level, raiddisks, raiddisks > 1 ? "s" : ""); level, raiddisks, raiddisks > 1 ? "s" : "");
return 0; return 0;
} }
if (super->orom && level != 1) {
if (chunk && (*chunk == 0 || *chunk == UnSet)) if (chunk && (*chunk == 0 || *chunk == UnSet))
*chunk = imsm_orom_default_chunk(super->orom); *chunk = imsm_default_chunk(super->orom);
else if (chunk && !imsm_orom_has_chunk(super->orom, *chunk)) {
pr_vrb(": platform does not support a chunk size of: " if (super->orom && chunk && !imsm_orom_has_chunk(super->orom, *chunk)) {
"%d\n", *chunk); pr_vrb(": platform does not support a chunk size of: "
return 0; "%d\n", *chunk);
} return 0;
} }
if (layout != imsm_level_to_layout(level)) { if (layout != imsm_level_to_layout(level)) {
if (level == 5) if (level == 5)
pr_vrb(": imsm raid 5 only supports the left-asymmetric layout\n"); pr_vrb(": imsm raid 5 only supports the left-asymmetric layout\n");
@ -5301,9 +5311,8 @@ static void default_geometry_imsm(struct supertype *st, int *level, int *layout,
if (level && layout && *layout == UnSet) if (level && layout && *layout == UnSet)
*layout = imsm_level_to_layout(*level); *layout = imsm_level_to_layout(*level);
if (chunk && (*chunk == UnSet || *chunk == 0) && if (chunk && (*chunk == UnSet || *chunk == 0))
super && super->orom) *chunk = imsm_default_chunk(super->orom);
*chunk = imsm_orom_default_chunk(super->orom);
} }
static void handle_missing(struct intel_super *super, struct imsm_dev *dev); static void handle_missing(struct intel_super *super, struct imsm_dev *dev);