summaryrefslogtreecommitdiffstats
path: root/super-intel.c
diff options
context:
space:
mode:
authorMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2023-05-29 15:52:33 +0200
committerJes Sorensen <jes@trained-monkey.org>2023-09-01 17:36:45 +0200
commit9bc426fa1f236b8cad518431574a54fc60718739 (patch)
treeb3931d82288cd9be04a830c5c5a15adc55e883b0 /super-intel.c
parentimsm: Fix possible segfault in check_no_platform() (diff)
downloadmdadm-9bc426fa1f236b8cad518431574a54fc60718739.tar.xz
mdadm-9bc426fa1f236b8cad518431574a54fc60718739.zip
imsm: move sum_extents calculations to merge_extents()
This logic is only used by merge_extents() code, there is no need to pass it as parameter. Move it up. Add proper description. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Diffstat (limited to '')
-rw-r--r--super-intel.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/super-intel.c b/super-intel.c
index 4ef33d31..26b20313 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -6882,21 +6882,31 @@ static unsigned long long find_size(struct extent *e, int *idx, int num_extents)
return end - base_start;
}
-static unsigned long long merge_extents(struct intel_super *super, int sum_extents)
+/** merge_extents() - analyze extents and get max common free size.
+ * @super: Intel metadata, not NULL.
+ *
+ * Build a composite disk with all known extents and generate a new maxsize
+ * given the "all disks in an array must share a common start offset"
+ * constraint.
+ *
+ * Return: Max free space or 0 on failure.
+ */
+static unsigned long long merge_extents(struct intel_super *super)
{
- /* build a composite disk with all known extents and generate a new
- * 'maxsize' given the "all disks in an array must share a common start
- * offset" constraint
- */
- struct extent *e = xcalloc(sum_extents, sizeof(*e));
+ struct extent *e;
struct dl *dl;
int i, j;
- int start_extent;
+ int start_extent, sum_extents = 0;
unsigned long long pos;
unsigned long long start = 0;
unsigned long long maxsize;
unsigned long reserve;
+ for (dl = super->disks; dl; dl = dl->next)
+ if (dl->e)
+ sum_extents += dl->extent_cnt;
+ e = xcalloc(sum_extents, sizeof(struct extent));
+
/* coalesce and sort all extents. also, check to see if we need to
* reserve space between member arrays
*/
@@ -7555,13 +7565,7 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level,
return 0;
}
- /* count total number of extents for merge */
- i = 0;
- for (dl = super->disks; dl; dl = dl->next)
- if (dl->e)
- i += dl->extent_cnt;
-
- maxsize = merge_extents(super, i);
+ maxsize = merge_extents(super);
if (mpb->num_raid_devs > 0 && size && size != maxsize)
pr_err("attempting to create a second volume with size less then remaining space.\n");
@@ -7615,7 +7619,6 @@ static imsm_status_t imsm_get_free_size(struct intel_super *super,
struct imsm_super *mpb = super->anchor;
struct dl *dl;
int i;
- int extent_cnt;
struct extent *e;
unsigned long long maxsize;
unsigned long long minsize;
@@ -7624,7 +7627,6 @@ static imsm_status_t imsm_get_free_size(struct intel_super *super,
/* find the largest common start free region of the possible disks */
used = 0;
- extent_cnt = 0;
cnt = 0;
for (dl = super->disks; dl; dl = dl->next) {
dl->raiddisk = -1;
@@ -7645,11 +7647,10 @@ static imsm_status_t imsm_get_free_size(struct intel_super *super,
;
dl->e = e;
dl->extent_cnt = i;
- extent_cnt += i;
cnt++;
}
- maxsize = merge_extents(super, extent_cnt);
+ maxsize = merge_extents(super);
minsize = size;
if (size == 0)
/* chunk is in K */