master - allocation: misc fixes for percent/raid rounding
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=13c3f53f55288fcd2dbab1cfc0dd30380521e1cf Commit: 13c3f53f55288fcd2dbab1cfc0dd30380521e1cf Parent: 294671fa629fb1d2e3580a411cc3ada3acce6626 Author: Alasdair G Kergon <[email protected]> AuthorDate: Sat Feb 22 00:26:01 2014 +0000 Committer: Alasdair G Kergon <[email protected]> CommitterDate: Sat Feb 22 00:26:01 2014 +0000
allocation: misc fixes for percent/raid rounding
Several fixes for the recent changes that treat allocation percentages as upper limits.
Improve messages to make it easier to see what is happening. Fix some cases that failed with errors when they didn't need to. Fix crashes when first_seg() returns NULL.
Remove a couple of log_errors that were actually debugging messages.
--- lib/display/display.c | 7 +++ lib/display/display.h | 2 + lib/metadata/lv.c | 19 ++++++--- lib/metadata/lv_manip.c | 97 ++++++++++++++++++++++++++++----------------- lib/metadata/thin_manip.c | 4 +- tools/lvcreate.c | 19 ++++++--- 6 files changed, 96 insertions(+), 52 deletions(-)
lib/display/display.c +7 -0
@@ -182,6 +182,13 @@ alloc_policy_t get_alloc_from_string(const char *str)return ALLOC_INVALID ; } +static const char *_percent_types[7 ] = {"NONE" ,"VGS" ,"FREE" ,"LVS" ,"PVS" ,"ORIGIN" }; + +const char *get_percent_string (percent_type_t def) +{ +return _percent_types[def]; +} +#define BASE_UNKNOWN 0#define BASE_SHARED 1#define BASE_1024 8
lib/display/display.h +2 -0
@@ -64,6 +64,8 @@ const char *get_alloc_string(alloc_policy_t alloc);char alloc_policy_char (alloc_policy_t alloc);alloc_policy_t get_alloc_from_string (const char *str); +const char *get_percent_string (percent_type_t def); +char yes_no_prompt (const char *prompt, ...) __attribute__ ((format (printf,1 ,2 )));#endif
lib/metadata/lv.c +12 -7
@@ -393,9 +393,13 @@ uint64_t lv_size(const struct logical_volume *lv) static int _lv_mimage_in_sync(const struct logical_volume *lv) { percent_t percent; - struct lv_segment *mirror_seg = find_mirror_seg(first_seg(lv)); + struct lv_segment *seg = first_seg(lv); + struct lv_segment *mirror_seg; - if (!(lv->status & MIRROR_IMAGE) || !mirror_seg) + if (seg) + mirror_seg = find_mirror_seg(seg); + + if (!(lv->status & MIRROR_IMAGE) || !seg || !mirror_seg) return_0; if (!lv_mirror_percent(lv->vg->cmd, mirror_seg->lv, 0, &percent,
@@ -410,7 +414,7 @@ static int _lv_raid_image_in_sync(const struct logical_volume *lv)unsigned s;percent_t percent;char *raid_health; -struct lv_segment *raid_seg; +struct lv_segment *seg, *raid_seg =NULL ;/* * If the LV is not active locally,
@@ -424,7 +428,8 @@ static int _lv_raid_image_in_sync(const struct logical_volume *lv)return 0 ; } - raid_seg =get_only_segment_using_this_lv (first_seg (lv)->lv); +if ((seg =first_seg (lv))) + raid_seg =get_only_segment_using_this_lv (seg->lv);if (!raid_seg) {log_error ("Failed to find RAID segment for %s" , lv->name);return 0 ;
@@ -472,7 +477,7 @@ static int _lv_raid_healthy(const struct logical_volume *lv) {unsigned s;char *raid_health; -struct lv_segment *raid_seg; +struct lv_segment *seg, *raid_seg =NULL ;/* * If the LV is not active locally,
@@ -488,8 +493,8 @@ static int _lv_raid_healthy(const struct logical_volume *lv)if (lv->status &RAID ) raid_seg =first_seg (lv); -else - raid_seg =get_only_segment_using_this_lv (first_seg (lv)->lv); +else if ((seg =first_seg (lv))) + raid_seg =get_only_segment_using_this_lv (seg->lv);if (!raid_seg) {log_error ("Failed to find RAID segment for %s" , lv->name);
lib/metadata/lv_manip.c +60 -37
251 lines not on this page · raw message
lib/metadata/thin_manip.c +3 -1
@@ -140,7 +140,9 @@ int detach_thin_external_origin(struct lv_segment *seg)int lv_is_merging_thin_snapshot (const struct logical_volume *lv) { -return (first_seg (lv)->status &MERGING ) ?1 :0 ; +struct lv_segment *seg =first_seg (lv); + +return (seg && seg->status &MERGING ) ?1 :0 ; }/*
tools/lvcreate.c +12 -7
@@ -363,21 +363,19 @@ static int _update_extents_params(struct volume_group *vg, }else lp->pvh = &vg->pvs; -if (lcp->percent) - lp->approx_alloc =1 ;switch (lcp->percent) {case PERCENT_VG : - lp->extents =percent_of_extents (lp->extents, vg->extent_count,0 ); + extents =percent_of_extents (lp->extents, vg->extent_count,0 );break ;case PERCENT_FREE : - lp->extents =percent_of_extents (lp->extents, vg->free_count,0 ); + extents =percent_of_extents (lp->extents, vg->free_count,0 );break ;case PERCENT_PVS :if (lcp->pv_count) { pv_extent_count =pv_list_extents_free (lp->pvh); - lp->extents =percent_of_extents (lp->extents, pv_extent_count,0 ); + extents =percent_of_extents (lp->extents, pv_extent_count,0 ); }else - lp->extents =percent_of_extents (lp->extents, vg->extent_count,0 ); + extents =percent_of_extents (lp->extents, vg->extent_count,0 );break ;case PERCENT_LV : log_error("Please express size as %%VG, %%PVS, or "
@@ -394,12 +392,19 @@ static int _update_extents_params(struct volume_group *vg,log_error (INTERNAL_ERROR "Couldn't find origin volume." );return 0 ; } - lp->extents =percent_of_extents (lp->extents, origin->le_count,0 ); + extents =percent_of_extents (lp->extents, origin->le_count,0 );break ;case PERCENT_NONE : + extents = lp->extents;break ; } +if (lcp->percent) { + lp->approx_alloc =1 ; +log_verbose ("Converted %" PRIu32"%%%s into %" PRIu32" extents." , lp->extents,get_percent_string (lcp->percent), extents); + lp->extents = extents; + } +if (lp->snapshot && lp->origin && lp->extents) {if (!lp->chunk_size) {log_error (INTERNAL_ERROR "Missing snapshot chunk size." );