From 15e35a737ccc648f08e968c3b8fbb0b4dfc4bbee Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 6 Nov 2001 11:19:33 +0000 Subject: [PATCH] o lv_reduce o pv_maps wasn't taking a list of acceptable pvs --- lib/metadata/lv_manip.c | 51 +++++++++++++++++++++++++++++++++-------- lib/metadata/metadata.h | 9 +++++++- lib/metadata/pv_map.c | 18 +++++++-------- lib/metadata/pv_map.h | 3 ++- 4 files changed, 59 insertions(+), 22 deletions(-) diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index def14b87d..046ee21c8 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -44,8 +44,10 @@ static int _alloc_area(struct logical_volume *lv, uint32_t index, return count; } -static int _alloc_striped(struct logical_volume *lv, struct list *pvms) +static int _alloc_striped(struct logical_volume *lv, + struct list *pvms, uint32_t allocated) { + /* FIXME: finish */ log_err("striped allocation not implemented yet."); return 0; } @@ -55,12 +57,12 @@ static int _alloc_striped(struct logical_volume *lv, struct list *pvms) * for the biggest area, or the first area that * can complete the allocation. */ -static int _alloc_contiguous(struct logical_volume *lv, struct list *pvms) +static int _alloc_contiguous(struct logical_volume *lv, + struct list *pvms, uint32_t allocated) { struct list *tmp1, *tmp2; struct pv_map *pvm; struct pv_area *pva, *biggest; - uint32_t allocated = 0; list_iterate (tmp1, pvms) { pvm = list_item(tmp1, struct pv_map); @@ -94,12 +96,12 @@ static int _alloc_contiguous(struct logical_volume *lv, struct list *pvms) * Areas just get allocated in order until the lv * is full. */ -static int _alloc_simple(struct logical_volume *lv, struct list *pvms) +static int _alloc_simple(struct logical_volume *lv, + struct list *pvms, uint32_t allocated) { struct list *tmp1, *tmp2; struct pv_map *pvm; struct pv_area *pva; - uint32_t allocated = 0; list_iterate (tmp1, pvms) { pvm = list_item(tmp1, struct pv_map); @@ -132,7 +134,7 @@ struct logical_volume *lv_create(struct io_space *ios, uint32_t stripe_size, uint32_t extents, struct volume_group *vg, - struct pv_list *acceptable_pvs) + struct list *acceptable_pvs) { struct lv_list *ll = NULL; struct logical_volume *lv; @@ -191,19 +193,19 @@ struct logical_volume *lv_create(struct io_space *ios, * Build the sets of available areas on * the pv's. */ - if (!(pvms = create_pv_maps(scratch, vg))) { + if (!(pvms = create_pv_maps(scratch, vg, acceptable_pvs))) { log_err("couldn't create extent mappings"); goto bad; } if (stripes > 1) - r = _alloc_striped(lv, pvms); + r = _alloc_striped(lv, pvms, 0u); else if (status & ALLOC_CONTIGUOUS) - r = _alloc_contiguous(lv, pvms); + r = _alloc_contiguous(lv, pvms, 0u); else - r = _alloc_simple(lv, pvms); + r = _alloc_simple(lv, pvms, 0u); if (!r) { log_err("Extent allocation failed."); @@ -224,3 +226,32 @@ struct logical_volume *lv_create(struct io_space *ios, pool_destroy(scratch); return NULL; } + +int lv_reduce(struct io_space *ios, + struct logical_volume *lv, uint32_t extents) +{ + if (extents % lv->stripes) { + log_err("For a striped volume you must reduce by a " + "multiple of the number of stripes"); + return 0; + } + + if (lv->le_count <= extents) { + log_err("Attempt to reduce by too many extents, " + "there would be nothing left of the logical volume."); + return 0; + } + + /* Hmmm ... I think all we need to do is ... */ + lv->le_count -= extents; + return 1; +} + +int lv_extend(struct io_space *ios, + struct logical_volume *lv, uint32_t extents, + struct list *allocatable_pvs) +{ + /* FIXME: finish */ + log_err("not implemented"); + return 0; +} diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index 7eb557997..37d81d0b4 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -219,7 +219,14 @@ struct logical_volume *lv_create(struct io_space *ios, uint32_t stripe_size, uint32_t extents, struct volume_group *vg, - struct pv_list *acceptable_pvs); + struct list *acceptable_pvs); + +int lv_reduce(struct io_space *ios, + struct logical_volume *lv, + uint32_t extents); + +int lv_extend(struct io_space *ios, struct logical_volume *lv, + uint32_t extents, struct list *allocatable_pvs); int vg_extend(struct io_space *ios, struct volume_group *vg, int pv_count, char **pv_names); diff --git a/lib/metadata/pv_map.c b/lib/metadata/pv_map.c index 0ff7a81d0..2b4e09311 100644 --- a/lib/metadata/pv_map.c +++ b/lib/metadata/pv_map.c @@ -8,14 +8,13 @@ #include "log.h" -static int _create_maps(struct pool *mem, struct volume_group *vg, - struct list *maps) +static int _create_maps(struct pool *mem, struct list *pvs, struct list *maps) { struct list *tmp; struct physical_volume *pv; struct pv_map *pvm; - list_iterate(tmp, &vg->pvs) { + list_iterate(tmp, pvs) { pv = &(list_item(tmp, struct pv_list)->pv); if (!(pvm = pool_zalloc(mem, sizeof(*pvm)))) { @@ -63,11 +62,9 @@ static int _fill_bitsets(struct volume_group *vg, struct list *maps) break; } - if (pvmh == maps) { - log_err("couldn't find pv specified " - "in extent map !"); - return 0; - } + /* not all pvs are necc. in the list */ + if (pvmh == maps) + continue; bit_set(pvm->allocated_extents, pes->pe); } @@ -138,7 +135,8 @@ static int _create_all_areas(struct pool *mem, struct list *maps) return 1; } -struct list *create_pv_maps(struct pool *mem, struct volume_group *vg) +struct list *create_pv_maps(struct pool *mem, struct volume_group *vg, + struct list *pvs) { struct list *maps = pool_zalloc(mem, sizeof(*maps)); @@ -149,7 +147,7 @@ struct list *create_pv_maps(struct pool *mem, struct volume_group *vg) list_init(maps); - if (!_create_maps(mem, vg, maps)) { + if (!_create_maps(mem, pvs, maps)) { log_err("couldn't create pv maps."); goto bad; } diff --git a/lib/metadata/pv_map.h b/lib/metadata/pv_map.h index d8180eb73..5cfe2685d 100644 --- a/lib/metadata/pv_map.h +++ b/lib/metadata/pv_map.h @@ -34,6 +34,7 @@ struct pv_map { struct list list; }; -struct list *create_pv_maps(struct pool *mem, struct volume_group *vg); +struct list *create_pv_maps(struct pool *mem, + struct volume_group *vg, struct list *pvs); #endif