From de317b8e01c227dfbf50c66e736606383801dfd2 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Mon, 1 Jun 2009 14:23:38 +0000 Subject: [PATCH] Fix log allocation segfault (fix previous commits). If there is no free area for log, code should break the loop. (Otherwise it uses uninitializes areas later.) Easily reproducible using lvconvert --repair - kill device with log - run lvconvert --repair vg/lv (with no PV usable for log) --- lib/metadata/lv_manip.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 68092a813..fcfd30d15 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -1124,6 +1124,13 @@ static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc, if ((contiguous || cling) && (preferred_count < ix_offset)) break; + log_needs_allocating = (ah->log_count && !ah->log_area.len) ? + 1 : 0; + + if (ix + ix_offset < ah->area_count + + (log_needs_allocating ? ah->log_count : 0)) + break; + /* sort the areas so we allocate from the biggest */ if (ix > 1) qsort(areas + ix_offset, ix, sizeof(*areas), @@ -1136,9 +1143,6 @@ static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc, * FIXME decide which PV to use at top of function instead */ - log_needs_allocating = (ah->log_count && !ah->log_area.len) ? - 1 : 0; - too_small_for_log_count = 0; if (!log_needs_allocating) { -- 2.43.5