From 6db4136358dfce191d3779d43f4802cfcc75aeb9 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Thu, 26 Jun 2008 23:05:11 +0000 Subject: [PATCH] Update validation of safe mirror log type conversions in lvconvert. (brassow) --- WHATS_NEW | 1 + lib/metadata/mirror.c | 42 +++++++++++++++++++++++++++++++++--------- tools/lvconvert.c | 3 +++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 291c64295..b93ef0d4f 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.39 - ================================ + Update validation of safe mirror log type conversions in lvconvert. Fix lvconvert to disallow snapshot and mirror combinations. Fix reporting of LV fields alongside unallocated PV segments. Add --unquoted and --rows to reporting tools. diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c index 1e49d283c..e1a77b160 100644 --- a/lib/metadata/mirror.c +++ b/lib/metadata/mirror.c @@ -1140,6 +1140,8 @@ int remove_mirror_log(struct cmd_context *cmd, struct list *removable_pvs) { float sync_percent; + struct lvinfo info; + struct volume_group *vg = lv->vg; /* Unimplemented features */ if (list_size(&lv->segments) != 1) { @@ -1148,10 +1150,21 @@ int remove_mirror_log(struct cmd_context *cmd, } /* Had disk log, switch to core. */ - if (!lv_mirror_percent(cmd, lv, 0, &sync_percent, NULL)) { - log_error("Unable to determine mirror sync status."); + if (lv_info(cmd, lv, &info, 0, 0) && info.exists) { + if (!lv_mirror_percent(cmd, lv, 0, &sync_percent, NULL)) { + log_error("Unable to determine mirror sync status."); + return 0; + } + } else if (vg_is_clustered(vg)) { + log_error("Unable to convert the log of inactive " + "cluster mirror %s", lv->name); + return 0; + } else if (yes_no_prompt("Full resync required to convert " + "inactive mirror %s to core log. " + "Proceed? [y/n]: ")) + sync_percent = 0; + else return 0; - } if (sync_percent >= 100.0) init_mirror_in_sync(1); @@ -1269,12 +1282,9 @@ int attach_mirror_log(struct lv_segment *seg, struct logical_volume *log_lv) return add_seg_to_segs_using_this_lv(log_lv, seg); } -int add_mirror_log(struct cmd_context *cmd, - struct logical_volume *lv, - uint32_t log_count, - uint32_t region_size, - struct list *allocatable_pvs, - alloc_policy_t alloc) +int add_mirror_log(struct cmd_context *cmd, struct logical_volume *lv, + uint32_t log_count, uint32_t region_size, + struct list *allocatable_pvs, alloc_policy_t alloc) { struct alloc_handle *ah; const struct segment_type *segtype; @@ -1282,17 +1292,31 @@ int add_mirror_log(struct cmd_context *cmd, float sync_percent; int in_sync; struct logical_volume *log_lv; + struct lvinfo info; /* Unimplemented features */ if (log_count > 1) { log_error("log_count > 1 is not supported"); return 0; } + if (list_size(&lv->segments) != 1) { log_error("Multiple-segment mirror is not supported"); return 0; } + /* + * We are unable to convert the log of inactive cluster mirrors + * due to the inability to detect whether the mirror is active + * on remote nodes (even though it is inactive on this node) + */ + if (vg_is_clustered(lv->vg) && + !(lv_info(cmd, lv, &info, 0, 0) && info.exists)) { + log_error("Unable to convert the log of inactive " + "cluster mirror %s", lv->name); + return 0; + } + if (!(parallel_areas = build_parallel_areas_from_lv(cmd, lv))) return_0; diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 21724de15..d533bfc1c 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -508,6 +508,9 @@ static int lvconvert_mirrors(struct cmd_context * cmd, struct logical_volume * l } if (lp->mirrors == existing_mirrors) { + /* + * Convert Mirror log type + */ original_lv = _original_lv(lv); if (!first_seg(original_lv)->log_lv && !corelog) { if (!add_mirror_log(cmd, original_lv, 1,