From 5875c0fce53d45f4209f5b18813624fbc2ef809e Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 27 Nov 2001 20:03:45 +0000 Subject: [PATCH] o extra error checking --- lib/format1/import-extents.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/format1/import-extents.c b/lib/format1/import-extents.c index 0cb71f089..7bcd96341 100644 --- a/lib/format1/import-extents.c +++ b/lib/format1/import-extents.c @@ -82,6 +82,7 @@ static int _fill_lv_array(struct lv_map **lvs, struct lv_map *lvm; int i = 0; + memset(lvs, 0, sizeof(*lvs) * MAX_LV); list_iterate(lvh, &dl->lvds) { struct lvd_list *ll = list_item(lvh, struct lvd_list); @@ -95,7 +96,7 @@ static int _fill_lv_array(struct lv_map **lvs, lvm->stripes = ll->lvd.lv_stripes; lvm->stripe_size = ll->lvd.lv_stripesize; - lvs[i++] = lvm; + lvs[ll->lvd.lv_number] = lvm; } return 1; @@ -128,13 +129,15 @@ static int _fill_maps(struct hash_table *maps, struct volume_group *vg, if (lv_num == UNMAPPED_EXTENT) continue; - else if(lv_num > dl->pvd.lv_cur) { - log_err("invalid lv in extent map"); - return 0; - } else { lv_num--; lvm = lvms[lv_num]; + + if(!lvm) { + log_err("invalid lv in extent map"); + return 0; + } + le = e[i].le_num; if (le >= lvm->lv->le_count) { @@ -143,6 +146,12 @@ static int _fill_maps(struct hash_table *maps, struct volume_group *vg, return 0; } + if (lvm->map[le].pv) { + log_err("logical extent (%u) " + "already mapped.", le); + return 0; + } + lvm->map[le].pv = pv; lvm->map[le].pe = i; } @@ -205,7 +214,8 @@ static int _build_segments(struct pool *mem, struct lv_map *lvm) len = sizeof(*seg) * (stripes * sizeof(seg->area[0])); - for (le = 0; le < lvm->lv->le_count;) { + le = 0; + while (le < lvm->lv->le_count) { if (!(seg = pool_zalloc(mem, len))) { stack; return 0; -- 2.43.5