1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-04 09:18:36 +03:00

Change alloc_areas to pe_ranges and allow suppression of availability checks.

This commit is contained in:
Alasdair Kergon 2004-08-17 21:55:23 +00:00
parent 1c31f23f56
commit eabaa3398b
9 changed files with 45 additions and 42 deletions

View File

@ -1,5 +1,6 @@
Version 2.00.21 - Version 2.00.21 -
============================= =============================
Change alloc_areas to pe_ranges and allow suppression of availability checks.
Add dev_size column to pvs. Add dev_size column to pvs.
Add report columns for in-kernel device number. Add report columns for in-kernel device number.

View File

@ -146,7 +146,7 @@ int import_pool_pvs(const struct format_type *fmt, struct volume_group *vg,
} }
pl->pv = pvl->pv; pl->pv = pvl->pv;
pvl->mdas = NULL; pvl->mdas = NULL;
pvl->alloc_areas = NULL; pvl->pe_ranges = NULL;
list_add(pvs, &pvl->list); list_add(pvs, &pvl->list);
} }

View File

@ -265,7 +265,7 @@ struct name_list {
char *name; char *name;
}; };
struct alloc_area { struct pe_range {
struct list list; struct list list;
uint32_t start; /* PEs */ uint32_t start; /* PEs */
uint32_t count; /* PEs */ uint32_t count; /* PEs */
@ -275,7 +275,7 @@ struct pv_list {
struct list list; struct list list;
struct physical_volume *pv; struct physical_volume *pv;
struct list *mdas; /* Metadata areas */ struct list *mdas; /* Metadata areas */
struct list *alloc_areas; /* Areas we may allocate from */ struct list *pe_ranges; /* Ranges of PEs e.g. for allocation */
}; };
struct lv_list { struct lv_list {

View File

@ -206,13 +206,13 @@ static int _create_areas(struct pool *mem, struct pv_map *pvm, uint32_t start,
static int _create_allocatable_areas(struct pool *mem, struct pv_map *pvm) static int _create_allocatable_areas(struct pool *mem, struct pv_map *pvm)
{ {
struct list *alloc_areas, *aah; struct list *alloc_areas, *aah;
struct alloc_area *aa; struct pe_range *aa;
alloc_areas = pvm->pvl->alloc_areas; alloc_areas = pvm->pvl->pe_ranges;
if (alloc_areas) { if (alloc_areas) {
list_iterate(aah, alloc_areas) { list_iterate(aah, alloc_areas) {
aa = list_item(aah, struct alloc_area); aa = list_item(aah, struct pe_range);
if (!_create_areas(mem, pvm, aa->start, aa->count)) { if (!_create_areas(mem, pvm, aa->start, aa->count)) {
stack; stack;
return 0; return 0;

View File

@ -418,7 +418,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
*/ */
if (lp->pv_count) { if (lp->pv_count) {
if (!(pvh = create_pv_list(cmd->mem, vg, if (!(pvh = create_pv_list(cmd->mem, vg,
lp->pv_count, lp->pvs))) { lp->pv_count, lp->pvs, 1))) {
stack; stack;
return 0; return 0;
} }

View File

@ -351,7 +351,7 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
if (lp->argc) if (lp->argc)
log_print("Ignoring PVs on command line when reducing"); log_print("Ignoring PVs on command line when reducing");
} else if (!(pvh = lp->argc ? create_pv_list(cmd->mem, vg, lp->argc, } else if (!(pvh = lp->argc ? create_pv_list(cmd->mem, vg, lp->argc,
lp->argv) : &vg->pvs)) { lp->argv, 1) : &vg->pvs)) {
stack; stack;
return ECMD_FAILED; return ECMD_FAILED;
} }

View File

@ -92,7 +92,7 @@ static struct list *_get_allocatable_pvs(struct cmd_context *cmd, int argc,
if (argc) { if (argc) {
if (!(allocatable_pvs = create_pv_list(cmd->mem, vg, argc, if (!(allocatable_pvs = create_pv_list(cmd->mem, vg, argc,
argv))) { argv, 1))) {
stack; stack;
return NULL; return NULL;
} }

View File

@ -694,40 +694,40 @@ char *default_vgname(struct cmd_context *cmd)
return pool_strdup(cmd->mem, vg_path); return pool_strdup(cmd->mem, vg_path);
} }
static int _add_alloc_area(struct pool *mem, struct list *alloc_areas, static int _add_pe_range(struct pool *mem, struct list *pe_ranges,
uint32_t start, uint32_t count) uint32_t start, uint32_t count)
{ {
struct alloc_area *aa; struct pe_range *per;
log_debug("Adding alloc area: start PE %" PRIu32 " length %" PRIu32, log_debug("Adding PE range: start PE %" PRIu32 " length %" PRIu32,
start, count); start, count);
/* Ensure no overlap with existing areas */ /* Ensure no overlap with existing areas */
list_iterate_items(aa, alloc_areas) { list_iterate_items(per, pe_ranges) {
if (((start < aa->start) && (start + count - 1 >= aa->start)) || if (((start < per->start) && (start + count - 1 >= per->start))
((start >= aa->start) && || ((start >= per->start) &&
(aa->start + aa->count - 1) >= start)) { (per->start + per->count - 1) >= start)) {
log_error("Overlapping PE ranges detected (%" PRIu32 log_error("Overlapping PE ranges detected (%" PRIu32
"-%" PRIu32 ", %" PRIu32 "-%" PRIu32 ")", "-%" PRIu32 ", %" PRIu32 "-%" PRIu32 ")",
start, start + count - 1, aa->start, start, start + count - 1, per->start,
aa->start + aa->count - 1); per->start + per->count - 1);
return 0; return 0;
} }
} }
if (!(aa = pool_alloc(mem, sizeof(*aa)))) { if (!(per = pool_alloc(mem, sizeof(*per)))) {
log_error("Allocation of list failed"); log_error("Allocation of list failed");
return 0; return 0;
} }
aa->start = start; per->start = start;
aa->count = count; per->count = count;
list_add(alloc_areas, &aa->list); list_add(pe_ranges, &per->list);
return 1; return 1;
} }
static int _parse_pes(struct pool *mem, char *c, struct list *alloc_areas, static int _parse_pes(struct pool *mem, char *c, struct list *pe_ranges,
uint32_t size) uint32_t size)
{ {
char *endptr; char *endptr;
@ -735,7 +735,7 @@ static int _parse_pes(struct pool *mem, char *c, struct list *alloc_areas,
/* Default to whole PV */ /* Default to whole PV */
if (!c) { if (!c) {
if (!_add_alloc_area(mem, alloc_areas, UINT32_C(0), size)) { if (!_add_pe_range(mem, pe_ranges, UINT32_C(0), size)) {
stack; stack;
return 0; return 0;
} }
@ -785,7 +785,7 @@ static int _parse_pes(struct pool *mem, char *c, struct list *alloc_areas,
return 0; return 0;
} }
if (!_add_alloc_area(mem, alloc_areas, start, end - start + 1)) { if (!_add_pe_range(mem, pe_ranges, start, end - start + 1)) {
stack; stack;
return 0; return 0;
} }
@ -800,19 +800,20 @@ static int _parse_pes(struct pool *mem, char *c, struct list *alloc_areas,
} }
static void _create_pv_entry(struct pool *mem, struct pv_list *pvl, static void _create_pv_entry(struct pool *mem, struct pv_list *pvl,
char *colon, struct list *r) char *colon, int allocatable_only, struct list *r)
{ {
const char *pvname; const char *pvname;
struct pv_list *new_pvl; struct pv_list *new_pvl;
struct list *alloc_areas; struct list *pe_ranges;
pvname = dev_name(pvl->pv->dev); pvname = dev_name(pvl->pv->dev);
if (!(pvl->pv->status & ALLOCATABLE_PV)) { if (allocatable_only && !(pvl->pv->status & ALLOCATABLE_PV)) {
log_error("Physical volume %s not allocatable", pvname); log_error("Physical volume %s not allocatable", pvname);
return; return;
} }
if (pvl->pv->pe_count == pvl->pv->pe_alloc_count) { if (allocatable_only &&
(pvl->pv->pe_count == pvl->pv->pe_alloc_count)) {
log_err("No free extents on physical volume \"%s\"", pvname); log_err("No free extents on physical volume \"%s\"", pvname);
return; return;
} }
@ -824,24 +825,24 @@ static void _create_pv_entry(struct pool *mem, struct pv_list *pvl,
memcpy(new_pvl, pvl, sizeof(*new_pvl)); memcpy(new_pvl, pvl, sizeof(*new_pvl));
if (!(alloc_areas = pool_alloc(mem, sizeof(*alloc_areas)))) { if (!(pe_ranges = pool_alloc(mem, sizeof(*pe_ranges)))) {
log_error("Allocation of alloc_areas list failed"); log_error("Allocation of pe_ranges list failed");
return; return;
} }
list_init(alloc_areas); list_init(pe_ranges);
/* Specify which physical extents may be used for allocation */ /* Determine selected physical extents */
if (!_parse_pes(mem, colon, alloc_areas, pvl->pv->pe_count)) { if (!_parse_pes(mem, colon, pe_ranges, pvl->pv->pe_count)) {
stack; stack;
return; return;
} }
new_pvl->alloc_areas = alloc_areas; new_pvl->pe_ranges = pe_ranges;
list_add(r, &new_pvl->list); list_add(r, &new_pvl->list);
} }
struct list *create_pv_list(struct pool *mem, struct list *create_pv_list(struct pool *mem, struct volume_group *vg, int argc,
struct volume_group *vg, int argc, char **argv) char **argv, int allocatable_only)
{ {
struct list *r; struct list *r;
struct pv_list *pvl; struct pv_list *pvl;
@ -870,7 +871,8 @@ struct list *create_pv_list(struct pool *mem,
list_iterate_items(pvl, &vg->pvs) { list_iterate_items(pvl, &vg->pvs) {
if (str_list_match_item(&pvl->pv->tags, if (str_list_match_item(&pvl->pv->tags,
tagname)) { tagname)) {
_create_pv_entry(mem, pvl, NULL, r); _create_pv_entry(mem, pvl, NULL,
allocatable_only, r);
} }
} }
continue; continue;
@ -892,7 +894,7 @@ struct list *create_pv_list(struct pool *mem,
"Volume Group \"%s\"", pvname, vg->name); "Volume Group \"%s\"", pvname, vg->name);
return NULL; return NULL;
} }
_create_pv_entry(mem, pvl, colon, r); _create_pv_entry(mem, pvl, colon, allocatable_only, r);
} }
if (list_empty(r)) if (list_empty(r))

View File

@ -74,8 +74,8 @@ const char *extract_vgname(struct cmd_context *cmd, const char *lv_name);
* Builds a list of pv's from the names in argv. Used in * Builds a list of pv's from the names in argv. Used in
* lvcreate/extend. * lvcreate/extend.
*/ */
struct list *create_pv_list(struct pool *mem, struct list *create_pv_list(struct pool *mem, struct volume_group *vg, int argc,
struct volume_group *vg, int argc, char **argv); char **argv, int allocatable_only);
struct list *clone_pv_list(struct pool *mem, struct list *pvs); struct list *clone_pv_list(struct pool *mem, struct list *pvs);