mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-02 01:18:26 +03:00
Change alloc_areas to pe_ranges and allow suppression of availability checks.
This commit is contained in:
parent
1c31f23f56
commit
eabaa3398b
@ -1,5 +1,6 @@
|
||||
Version 2.00.21 -
|
||||
=============================
|
||||
Change alloc_areas to pe_ranges and allow suppression of availability checks.
|
||||
Add dev_size column to pvs.
|
||||
Add report columns for in-kernel device number.
|
||||
|
||||
|
@ -146,7 +146,7 @@ int import_pool_pvs(const struct format_type *fmt, struct volume_group *vg,
|
||||
}
|
||||
pl->pv = pvl->pv;
|
||||
pvl->mdas = NULL;
|
||||
pvl->alloc_areas = NULL;
|
||||
pvl->pe_ranges = NULL;
|
||||
list_add(pvs, &pvl->list);
|
||||
}
|
||||
|
||||
|
@ -265,7 +265,7 @@ struct name_list {
|
||||
char *name;
|
||||
};
|
||||
|
||||
struct alloc_area {
|
||||
struct pe_range {
|
||||
struct list list;
|
||||
uint32_t start; /* PEs */
|
||||
uint32_t count; /* PEs */
|
||||
@ -275,7 +275,7 @@ struct pv_list {
|
||||
struct list list;
|
||||
struct physical_volume *pv;
|
||||
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 {
|
||||
|
@ -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)
|
||||
{
|
||||
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) {
|
||||
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)) {
|
||||
stack;
|
||||
return 0;
|
||||
|
@ -418,7 +418,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
|
||||
*/
|
||||
if (lp->pv_count) {
|
||||
if (!(pvh = create_pv_list(cmd->mem, vg,
|
||||
lp->pv_count, lp->pvs))) {
|
||||
lp->pv_count, lp->pvs, 1))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
@ -351,7 +351,7 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
|
||||
if (lp->argc)
|
||||
log_print("Ignoring PVs on command line when reducing");
|
||||
} else if (!(pvh = lp->argc ? create_pv_list(cmd->mem, vg, lp->argc,
|
||||
lp->argv) : &vg->pvs)) {
|
||||
lp->argv, 1) : &vg->pvs)) {
|
||||
stack;
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ static struct list *_get_allocatable_pvs(struct cmd_context *cmd, int argc,
|
||||
|
||||
if (argc) {
|
||||
if (!(allocatable_pvs = create_pv_list(cmd->mem, vg, argc,
|
||||
argv))) {
|
||||
argv, 1))) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -694,40 +694,40 @@ char *default_vgname(struct cmd_context *cmd)
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
/* Ensure no overlap with existing areas */
|
||||
list_iterate_items(aa, alloc_areas) {
|
||||
if (((start < aa->start) && (start + count - 1 >= aa->start)) ||
|
||||
((start >= aa->start) &&
|
||||
(aa->start + aa->count - 1) >= start)) {
|
||||
list_iterate_items(per, pe_ranges) {
|
||||
if (((start < per->start) && (start + count - 1 >= per->start))
|
||||
|| ((start >= per->start) &&
|
||||
(per->start + per->count - 1) >= start)) {
|
||||
log_error("Overlapping PE ranges detected (%" PRIu32
|
||||
"-%" PRIu32 ", %" PRIu32 "-%" PRIu32 ")",
|
||||
start, start + count - 1, aa->start,
|
||||
aa->start + aa->count - 1);
|
||||
start, start + count - 1, per->start,
|
||||
per->start + per->count - 1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(aa = pool_alloc(mem, sizeof(*aa)))) {
|
||||
if (!(per = pool_alloc(mem, sizeof(*per)))) {
|
||||
log_error("Allocation of list failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
aa->start = start;
|
||||
aa->count = count;
|
||||
list_add(alloc_areas, &aa->list);
|
||||
per->start = start;
|
||||
per->count = count;
|
||||
list_add(pe_ranges, &per->list);
|
||||
|
||||
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)
|
||||
{
|
||||
char *endptr;
|
||||
@ -735,7 +735,7 @@ static int _parse_pes(struct pool *mem, char *c, struct list *alloc_areas,
|
||||
|
||||
/* Default to whole PV */
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
@ -785,7 +785,7 @@ static int _parse_pes(struct pool *mem, char *c, struct list *alloc_areas,
|
||||
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;
|
||||
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,
|
||||
char *colon, struct list *r)
|
||||
char *colon, int allocatable_only, struct list *r)
|
||||
{
|
||||
const char *pvname;
|
||||
struct pv_list *new_pvl;
|
||||
struct list *alloc_areas;
|
||||
struct list *pe_ranges;
|
||||
|
||||
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);
|
||||
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);
|
||||
return;
|
||||
}
|
||||
@ -824,24 +825,24 @@ static void _create_pv_entry(struct pool *mem, struct pv_list *pvl,
|
||||
|
||||
memcpy(new_pvl, pvl, sizeof(*new_pvl));
|
||||
|
||||
if (!(alloc_areas = pool_alloc(mem, sizeof(*alloc_areas)))) {
|
||||
log_error("Allocation of alloc_areas list failed");
|
||||
if (!(pe_ranges = pool_alloc(mem, sizeof(*pe_ranges)))) {
|
||||
log_error("Allocation of pe_ranges list failed");
|
||||
return;
|
||||
}
|
||||
list_init(alloc_areas);
|
||||
list_init(pe_ranges);
|
||||
|
||||
/* Specify which physical extents may be used for allocation */
|
||||
if (!_parse_pes(mem, colon, alloc_areas, pvl->pv->pe_count)) {
|
||||
/* Determine selected physical extents */
|
||||
if (!_parse_pes(mem, colon, pe_ranges, pvl->pv->pe_count)) {
|
||||
stack;
|
||||
return;
|
||||
}
|
||||
new_pvl->alloc_areas = alloc_areas;
|
||||
new_pvl->pe_ranges = pe_ranges;
|
||||
|
||||
list_add(r, &new_pvl->list);
|
||||
}
|
||||
|
||||
struct list *create_pv_list(struct pool *mem,
|
||||
struct volume_group *vg, int argc, char **argv)
|
||||
struct list *create_pv_list(struct pool *mem, struct volume_group *vg, int argc,
|
||||
char **argv, int allocatable_only)
|
||||
{
|
||||
struct list *r;
|
||||
struct pv_list *pvl;
|
||||
@ -870,7 +871,8 @@ struct list *create_pv_list(struct pool *mem,
|
||||
list_iterate_items(pvl, &vg->pvs) {
|
||||
if (str_list_match_item(&pvl->pv->tags,
|
||||
tagname)) {
|
||||
_create_pv_entry(mem, pvl, NULL, r);
|
||||
_create_pv_entry(mem, pvl, NULL,
|
||||
allocatable_only, r);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@ -892,7 +894,7 @@ struct list *create_pv_list(struct pool *mem,
|
||||
"Volume Group \"%s\"", pvname, vg->name);
|
||||
return NULL;
|
||||
}
|
||||
_create_pv_entry(mem, pvl, colon, r);
|
||||
_create_pv_entry(mem, pvl, colon, allocatable_only, r);
|
||||
}
|
||||
|
||||
if (list_empty(r))
|
||||
|
@ -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
|
||||
* lvcreate/extend.
|
||||
*/
|
||||
struct list *create_pv_list(struct pool *mem,
|
||||
struct volume_group *vg, int argc, char **argv);
|
||||
struct list *create_pv_list(struct pool *mem, struct volume_group *vg, int argc,
|
||||
char **argv, int allocatable_only);
|
||||
|
||||
struct list *clone_pv_list(struct pool *mem, struct list *pvs);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user