1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

Push lv_create & alloc policy up to tool level.

This commit is contained in:
Alasdair Kergon 2004-05-05 18:49:21 +00:00
parent 21b28f0217
commit 9bc733b76c
5 changed files with 50 additions and 81 deletions

View File

@ -1,5 +1,7 @@
Version 2.00.16 -
=============================
Push lv_create & alloc policy up to tool level.
Fix pvdisplay return code.
Detect invalid LV names in arg lists.
Reporting uses line-at-a-time output.
lvm2 format sets unlimited_vols format flag.

View File

@ -425,7 +425,7 @@ static int _alloc_next_free(struct logical_volume *lv,
*/
static int _allocate(struct volume_group *vg, struct logical_volume *lv,
struct list *allocatable_pvs, uint32_t allocated,
struct segment_type *segtype,
alloc_policy_t alloc, struct segment_type *segtype,
uint32_t stripes, uint32_t stripe_size, uint32_t mirrors,
struct physical_volume *mirrored_pv, uint32_t mirrored_pe,
uint32_t status)
@ -453,10 +453,10 @@ static int _allocate(struct volume_group *vg, struct logical_volume *lv,
else if (mirrored_pv)
r = _alloc_mirrored(lv, pvms, allocated, segtype, mirrored_pv,
mirrored_pe);
else if (lv->alloc == ALLOC_CONTIGUOUS)
else if (alloc == ALLOC_CONTIGUOUS)
r = _alloc_contiguous(lv, pvms, allocated);
else if (lv->alloc == ALLOC_NEXT_FREE || lv->alloc == ALLOC_DEFAULT)
else if (alloc == ALLOC_NEXT_FREE || alloc == ALLOC_DEFAULT)
r = _alloc_next_free(lv, pvms, allocated);
else {
@ -587,7 +587,8 @@ int lv_extend(struct format_instance *fid,
uint32_t stripes, uint32_t stripe_size,
uint32_t mirrors, uint32_t extents,
struct physical_volume *mirrored_pv, uint32_t mirrored_pe,
uint32_t status, struct list *allocatable_pvs)
uint32_t status, struct list *allocatable_pvs,
alloc_policy_t alloc)
{
uint32_t old_le_count = lv->le_count;
uint64_t old_size = lv->size;
@ -595,9 +596,9 @@ int lv_extend(struct format_instance *fid,
lv->le_count += extents;
lv->size += (uint64_t) extents *lv->vg->extent_size;
if (!_allocate(lv->vg, lv, allocatable_pvs, old_le_count, segtype,
stripes, stripe_size, mirrors, mirrored_pv, mirrored_pe,
status)) {
if (!_allocate(lv->vg, lv, allocatable_pvs, old_le_count, alloc,
segtype, stripes, stripe_size, mirrors, mirrored_pv,
mirrored_pe, status)) {
lv->le_count = old_le_count;
lv->size = old_size;
stack;
@ -618,53 +619,6 @@ int lv_extend(struct format_instance *fid,
return 1;
}
struct logical_volume *lv_create(struct format_instance *fid,
const char *name,
uint32_t status,
alloc_policy_t alloc,
struct segment_type *segtype,
uint32_t stripes,
uint32_t stripe_size,
uint32_t mirrors,
uint32_t extents,
struct volume_group *vg,
struct list *allocatable_pvs)
{
struct logical_volume *lv;
if (!extents) {
log_error("Unable to create logical volume %s with no extents",
name);
return NULL;
}
if (vg->free_count < extents) {
log_error("Insufficient free extents (%u) in volume group %s: "
"%u required", vg->free_count, vg->name, extents);
return NULL;
}
if (stripes > list_size(allocatable_pvs)) {
log_error("Number of stripes (%u) must not exceed "
"number of physical volumes (%d)", stripes,
list_size(allocatable_pvs));
return NULL;
}
if (!(lv = lv_create_empty(fid, name, "lvol%d", status, alloc, vg))) {
stack;
return NULL;
}
if (!lv_extend(fid, lv, segtype, stripes, stripe_size, mirrors,
extents, NULL, 0u, 0u, allocatable_pvs)) {
stack;
return NULL;
}
return lv;
}
int lv_reduce(struct format_instance *fi,
struct logical_volume *lv, uint32_t extents)
{

View File

@ -395,22 +395,7 @@ int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
int vg_extend(struct format_instance *fi, struct volume_group *vg,
int pv_count, char **pv_names);
/*
* Create a new LV within a given volume group.
*
*/
struct logical_volume *lv_create(struct format_instance *fi,
const char *name,
uint32_t status,
alloc_policy_t alloc,
struct segment_type *segtype,
uint32_t stripes,
uint32_t stripe_size,
uint32_t mirrors,
uint32_t extents,
struct volume_group *vg,
struct list *allocatable_pvs);
/* Manipulate LVs */
struct logical_volume *lv_create_empty(struct format_instance *fi,
const char *name,
const char *name_format,
@ -418,7 +403,6 @@ struct logical_volume *lv_create_empty(struct format_instance *fi,
alloc_policy_t alloc,
struct volume_group *vg);
/* Manipulate LVs */
int lv_reduce(struct format_instance *fi,
struct logical_volume *lv, uint32_t extents);
@ -428,7 +412,8 @@ int lv_extend(struct format_instance *fid,
uint32_t stripes, uint32_t stripe_size,
uint32_t mirrors, uint32_t extents,
struct physical_volume *mirrored_pv, uint32_t mirrored_pe,
uint32_t status, struct list *allocatable_pvs);
uint32_t status, struct list *allocatable_pvs,
alloc_policy_t alloc);
/* lv must be part of vg->lvs */
int lv_remove(struct volume_group *vg, struct logical_volume *lv);

View File

@ -188,15 +188,16 @@ static int _read_stripe_params(struct lvcreate_params *lp,
lp->stripes = 1;
/* Default is striped */
if (!(lp->segtype = get_segtype_from_string(cmd, "striped"))) {
stack;
return 0;
}
if (arg_count(cmd, stripes_ARG)) {
lp->stripes = arg_uint_value(cmd, stripes_ARG, 1);
if (lp->stripes == 1)
log_print("Redundant stripes argument: default is 1");
else if (!(lp->segtype = get_segtype_from_string(cmd,
"striped"))) {
stack;
return 0;
}
}
if (arg_count(cmd, stripesize_ARG)) {
@ -475,10 +476,36 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
status |= LVM_WRITE;
}
if (!(lv = lv_create(vg->fid, lp->lv_name, status, alloc, lp->segtype,
lp->stripes, lp->stripe_size, lp->mirrors,
lp->extents, vg, pvh)))
if (!lp->extents) {
log_error("Unable to create logical volume %s with no extents",
lp->lv_name);
return 0;
}
if (vg->free_count < lp->extents) {
log_error("Insufficient free extents (%u) in volume group %s: "
"%u required", vg->free_count, vg->name, lp->extents);
return 0;
}
if (lp->stripes > list_size(pvh)) {
log_error("Number of stripes (%u) must not exceed "
"number of physical volumes (%d)", lp->stripes,
list_size(pvh));
return 0;
}
if (!(lv = lv_create_empty(vg->fid, lp->lv_name, "lvol%d",
status, alloc, vg))) {
stack;
return 0;
}
if (!lv_extend(vg->fid, lv, lp->segtype, lp->stripes, lp->stripe_size,
lp->mirrors, lp->extents, NULL, 0u, 0u, pvh, alloc)) {
stack;
return 0;
}
if (lp->read_ahead) {
log_verbose("Setting read ahead sectors");

View File

@ -362,7 +362,8 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
}
if (!lv_extend(vg->fid, lv, segtype, stripes, ssize, 0u,
extents - lv->le_count, NULL, 0u, 0u, pvh))
extents - lv->le_count, NULL, 0u, 0u, pvh,
lv->alloc))
goto error;
}