From e40d124e14b921a48677e3785b066c31e43f3c95 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 22 Apr 2005 15:43:02 +0000 Subject: [PATCH] set_lv_segment_area_pv/lv --- WHATS_NEW | 1 + lib/format1/import-extents.c | 4 +--- lib/format_pool/import_export.c | 14 ++++++-------- lib/format_text/import_vsn1.c | 9 ++------- lib/metadata/lv_alloc.h | 5 +++++ lib/metadata/lv_manip.c | 33 +++++++++++++++++++++------------ lib/metadata/mirror.c | 11 +++++------ 7 files changed, 41 insertions(+), 36 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 9174d95b0..0f5aac540 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.01.10 - ================================ + Tidy lv_segment interface. Initial pv_segment support. vgchange --physicalextentsize Internal snapshot restructuring. diff --git a/lib/format1/import-extents.c b/lib/format1/import-extents.c index 6ce0d7f53..d93c89532 100644 --- a/lib/format1/import-extents.c +++ b/lib/format1/import-extents.c @@ -224,9 +224,7 @@ static int _read_linear(struct cmd_context *cmd, struct lv_map *lvm) seg->area_len = 0; seg->stripe_size = 0; - seg->area[0].type = AREA_PV; - seg->area[0].u.pv.pv = lvm->map[le].pv; - seg->area[0].u.pv.pe = lvm->map[le].pe; + set_lv_segment_area_pv(seg, 0, lvm->map[le].pv, lvm->map[le].pe); do { seg->len++; diff --git a/lib/format_pool/import_export.c b/lib/format_pool/import_export.c index ec4d157b8..21a0262d5 100644 --- a/lib/format_pool/import_export.c +++ b/lib/format_pool/import_export.c @@ -218,13 +218,14 @@ static int _add_stripe_seg(struct pool *mem, log_error("Unable to allocate striped lv_segment structure"); return 0; } - if(usp->striping & (usp->striping - 1)) { + if (usp->striping & (usp->striping - 1)) { log_error("Stripe size must be a power of 2"); return 0; } seg->stripe_size = usp->striping; seg->status |= 0; seg->le += *le_cur; + seg->lv = lv; /* add the subpool type to the segment tag list */ str_list_add(mem, &seg->tags, _cvt_sptype(usp->type)); @@ -239,13 +240,12 @@ static int _add_stripe_seg(struct pool *mem, seg->area_len = (usp->devs[j].blocks) / POOL_PE_SIZE; seg->len += seg->area_len; *le_cur += seg->area_len; - seg->lv = lv; - seg->area[j].type = AREA_PV; - seg->area[j].u.pv.pv = usp->devs[j].pv; - seg->area[j].u.pv.pe = 0; + set_lv_segment_area_pv(seg, j, usp->devs[j].pv, 0); } + list_add(&lv->segments, &seg->list); + return 1; } @@ -280,9 +280,7 @@ static int _add_linear_seg(struct pool *mem, seg->area_len = (usp->devs[j].blocks) / POOL_PE_SIZE; seg->len = seg->area_len; *le_cur += seg->len; - seg->area[0].type = AREA_PV; - seg->area[0].u.pv.pv = usp->devs[j].pv; - seg->area[0].u.pv.pe = 0; + set_lv_segment_area_pv(seg, 0, usp->devs[j].pv, 0); list_add(&lv->segments, &seg->list); } return 1; diff --git a/lib/format_text/import_vsn1.c b/lib/format_text/import_vsn1.c index e5d4213bf..cc06d19a5 100644 --- a/lib/format_text/import_vsn1.c +++ b/lib/format_text/import_vsn1.c @@ -369,19 +369,14 @@ int text_import_areas(struct lv_segment *seg, const struct config_node *sn, /* FIXME Cope if LV not yet read in */ if ((pv = hash_lookup(pv_hash, cv->v.str))) { - seg->area[s].type = AREA_PV; - seg->area[s].u.pv.pv = pv; - seg->area[s].u.pv.pe = cv->next->v.i; + set_lv_segment_area_pv(seg, s, pv, cv->next->v.i); /* * Adjust extent counts in the pv and vg. */ pv->pe_alloc_count += seg->area_len; seg->lv->vg->free_count -= seg->area_len; - } else if ((lv1 = find_lv(seg->lv->vg, cv->v.str))) { - seg->area[s].type = AREA_LV; - seg->area[s].u.lv.lv = lv1; - seg->area[s].u.lv.le = cv->next->v.i; + set_lv_segment_area_lv(seg, s, lv1, cv->next->v.i); } else { log_error("Couldn't find volume '%s' " "for segment '%s'.", diff --git a/lib/metadata/lv_alloc.h b/lib/metadata/lv_alloc.h index 2fa62e0b9..5c77943cf 100644 --- a/lib/metadata/lv_alloc.h +++ b/lib/metadata/lv_alloc.h @@ -20,4 +20,9 @@ struct lv_segment *alloc_lv_segment(struct pool *mem, uint32_t num_areas); struct lv_segment *alloc_snapshot_seg(struct logical_volume *lv, uint32_t allocated); +void set_lv_segment_area_pv(struct lv_segment *seg, uint32_t area_num, + struct physical_volume *pv, uint32_t pe); +void set_lv_segment_area_lv(struct lv_segment *seg, uint32_t area_num, + struct logical_volume *lv, uint32_t le); + #endif diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index ce6dbffcd..d0d63a2d7 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -77,6 +77,23 @@ struct lv_segment *alloc_lv_segment(struct pool *mem, uint32_t num_areas) return seg; } +void set_lv_segment_area_pv(struct lv_segment *seg, uint32_t area_num, + struct physical_volume *pv, uint32_t pe) +{ + seg->area[area_num].type = AREA_PV; + seg->area[area_num].u.pv.pv = pv; + seg->area[area_num].u.pv.pe = pe; + seg->area[area_num].u.pv.pvseg = NULL; +} + +void set_lv_segment_area_lv(struct lv_segment *seg, uint32_t area_num, + struct logical_volume *lv, uint32_t le) +{ + seg->area[area_num].type = AREA_LV; + seg->area[area_num].u.lv.lv = lv; + seg->area[area_num].u.lv.le = le; +} + static int _alloc_parallel_area(struct logical_volume *lv, uint32_t area_count, uint32_t stripe_size, struct segment_type *segtype, @@ -113,9 +130,7 @@ static int _alloc_parallel_area(struct logical_volume *lv, uint32_t area_count, for (s = 0; s < area_count; s++) { struct pv_area *pva = areas[s]; - seg->area[s].type = AREA_PV; - seg->area[s].u.pv.pv = pva->map->pvl->pv; - seg->area[s].u.pv.pe = pva->start; + set_lv_segment_area_pv(seg, s, pva->map->pvl->pv, pva->start); consume_pv_area(pva, area_len); } @@ -241,9 +256,7 @@ static int _alloc_linear_area(struct logical_volume *lv, uint32_t *ix, seg->len = count; seg->area_len = count; seg->stripe_size = 0; - seg->area[0].type = AREA_PV; - seg->area[0].u.pv.pv = map->pvl->pv; - seg->area[0].u.pv.pe = pva->start; + set_lv_segment_area_pv(seg, 0, map->pvl->pv, pva->start); list_add(&lv->segments, &seg->list); @@ -280,12 +293,8 @@ static int _alloc_mirrored_area(struct logical_volume *lv, uint32_t *ix, seg->stripe_size = 0; seg->extents_copied = 0u; /* FIXME Remove AREA_PV restriction here? */ - seg->area[0].type = AREA_PV; - seg->area[0].u.pv.pv = mirrored_pv; - seg->area[0].u.pv.pe = mirrored_pe; - seg->area[1].type = AREA_PV; - seg->area[1].u.pv.pv = map->pvl->pv; - seg->area[1].u.pv.pe = pva->start; + set_lv_segment_area_pv(seg, 0, mirrored_pv, mirrored_pe); + set_lv_segment_area_pv(seg, 1, map->pvl->pv, pva->start); list_add(&lv->segments, &seg->list); consume_pv_area(pva, count); diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c index 3e6fb064e..c5e5f9ce7 100644 --- a/lib/metadata/mirror.c +++ b/lib/metadata/mirror.c @@ -19,6 +19,7 @@ #include "segtype.h" #include "display.h" #include "activate.h" +#include "lv_alloc.h" /* * Replace any LV segments on given PV with temporary mirror. @@ -153,9 +154,7 @@ int insert_pvmove_mirrors(struct cmd_context *cmd, "temporary LV for pvmove."); return 0; } - seg->area[s].type = AREA_LV; - seg->area[s].u.lv.lv = lv_mirr; - seg->area[s].u.lv.le = start_le; + set_lv_segment_area_lv(seg, s, lv_mirr, start_le); extent_count += seg->area_len; @@ -225,9 +224,9 @@ int remove_pvmove_mirrors(struct volume_group *vg, else c = 0; - seg->area[s].type = AREA_PV; - seg->area[s].u.pv.pv = mir_seg->area[c].u.pv.pv; - seg->area[s].u.pv.pe = mir_seg->area[c].u.pv.pe; + set_lv_segment_area_pv(seg, s, + mir_seg->area[c].u.pv.pv, + mir_seg->area[c].u.pv.pe); /* Replace mirror with old area */ if (!