From 1d2ebf628184dd530ee16a2a2f67b5dc0116252e Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 5 May 2004 18:49:21 +0000 Subject: [PATCH] Push lv_create & alloc policy up to tool level. --- WHATS_NEW | 2 ++ lib/metadata/lv_manip.c | 62 ++++++----------------------------------- lib/metadata/metadata.h | 21 ++------------ tools/lvcreate.c | 43 ++++++++++++++++++++++------ tools/lvresize.c | 3 +- 5 files changed, 50 insertions(+), 81 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 50794f87d..9daf0f035 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -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. diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index eb284fb3e..b182f2c33 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -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) { diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index cebf1367a..b22fd164a 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -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); diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 2fb8a6c90..8a18f72e2 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -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"); diff --git a/tools/lvresize.c b/tools/lvresize.c index f329561a5..e39f9b3f2 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -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; }