diff options
author | Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | 2023-05-29 15:52:34 +0200 |
---|---|---|
committer | Jes Sorensen <jes@trained-monkey.org> | 2023-09-01 17:36:45 +0200 |
commit | 5f027b9357c011ca0421400e258a777d97f18d17 (patch) | |
tree | b845a04d3829e065a2b58c11578d87f2cb757317 /super-intel.c | |
parent | imsm: move sum_extents calculations to merge_extents() (diff) | |
download | mdadm-5f027b9357c011ca0421400e258a777d97f18d17.tar.xz mdadm-5f027b9357c011ca0421400e258a777d97f18d17.zip |
imsm: imsm_get_free_size() refactor.
Move minsize calculations up. Add error message if free size is too small.
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Diffstat (limited to 'super-intel.c')
-rw-r--r-- | super-intel.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/super-intel.c b/super-intel.c index 26b20313..16a30ba7 100644 --- a/super-intel.c +++ b/super-intel.c @@ -7600,7 +7600,7 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level, * @super: &intel_super pointer, not NULL. * @raiddisks: number of raid disks. * @size: requested size, could be 0 (means max size). - * @chunk: requested chunk. + * @chunk: requested chunk size in KiB. * @freesize: pointer for returned size value. * * Return: &IMSM_STATUS_OK or &IMSM_STATUS_ERROR. @@ -7620,14 +7620,15 @@ static imsm_status_t imsm_get_free_size(struct intel_super *super, struct dl *dl; int i; struct extent *e; + int cnt = 0; + int used = 0; unsigned long long maxsize; - unsigned long long minsize; - int cnt; - int used; + unsigned long long minsize = size; + + if (minsize == 0) + minsize = chunk * 2; /* find the largest common start free region of the possible disks */ - used = 0; - cnt = 0; for (dl = super->disks; dl; dl = dl->next) { dl->raiddisk = -1; @@ -7651,14 +7652,14 @@ static imsm_status_t imsm_get_free_size(struct intel_super *super, } maxsize = merge_extents(super); - minsize = size; - if (size == 0) - /* chunk is in K */ - minsize = chunk * 2; + if (maxsize < minsize) { + pr_err("imsm: Free space is %llu but must be equal or larger than %llu.\n", + maxsize, minsize); + return IMSM_STATUS_ERROR; + } - if (cnt < raiddisks || (super->orom && used && used != raiddisks) || - maxsize < minsize || maxsize == 0) { - pr_err("not enough devices with space to create array.\n"); + if (cnt < raiddisks || (super->orom && used && used != raiddisks)) { + pr_err("imsm: Not enough devices with space to create array.\n"); return IMSM_STATUS_ERROR; } |