From dcd90bc501677849ee50b430ea956be7392dffae Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Mon, 26 Mar 2012 20:32:58 +0000 Subject: [PATCH] Do not allow pvmove if some affected LVs are activated locally or on more nodes while others are activated exclusively. Current pvmove code can either use local mirror (for exclusive activation) or cmirror (for clustered LVs). Because the whole intenal pvmove LV is just segmented LV containing segments of several top-level LVs, code cannot properly handle situation if some segment need to be activated exclusively. Previously, it wrongly activated exclusive LV on all nodes (locing code allowed it) but now this is no lnger possible. If there is exclusively activated LV, pvmove is only possible if all affected LVs are aslo activated exclusively. (Note that in non-exclusive mode pvmove still activates LVs on other nodes during move.) # lvchange -aly vg_test/lv1 # lvchange -aey vg_test/lv2 # pvmove -i 1 /dev/sdc Error locking on node bar-01: Device or resource busy Error locking on node bar-03: Volume is busy on another node ... Failed to activate lv2 --- WHATS_NEW | 1 + tools/pvmove.c | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 93b6440e5..13cb12d72 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.96 - ================================ + Disallow pvmove for exclusive LV if some affected LVs are not exclusively activated. Remove unused and wrongly set cluster VG flag from clvmd lock query command. Fix pvmove for exclusively activated LV pvmove in clustered VG. (2.02.86) Always free hash table on update_pvid_to_vgid() in lvmetad. diff --git a/tools/pvmove.c b/tools/pvmove.c index 40ef0691e..9b9fe5908 100644 --- a/tools/pvmove.c +++ b/tools/pvmove.c @@ -175,13 +175,16 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd, const char *lv_name, struct dm_list *allocatable_pvs, alloc_policy_t alloc, - struct dm_list **lvs_changed) + struct dm_list **lvs_changed, + unsigned *exclusive) { struct logical_volume *lv_mirr, *lv; struct lv_list *lvl; uint32_t log_count = 0; int lv_found = 0; int lv_skipped = 0; + int lv_active_count = 0; + int lv_exclusive_count = 0; /* FIXME Cope with non-contiguous => splitting existing segments */ if (!(lv_mirr = lv_create_empty("pvmove%d", NULL, @@ -235,6 +238,14 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd, log_print("Skipping locked LV %s", lv->name); continue; } + + if (vg_is_clustered(vg)) { + if (lv_is_active_exclusive_locally(lv)) + lv_exclusive_count++; + else if (lv_is_active(lv)) + lv_active_count++; + } + if (!_insert_pvmove_mirrors(cmd, lv_mirr, source_pvl, lv, *lvs_changed)) return_NULL; @@ -255,6 +266,17 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd, return NULL; } + if (lv_exclusive_count) { + if (lv_active_count) { + log_error("Cannot move in clustered VG %s " + "if some LVs are activated " + "exclusively while others don't.", + vg->name); + return NULL; + } + *exclusive = 1; + } + if (!lv_add_mirrors(cmd, lv_mirr, 1, 1, 0, 0, log_count, allocatable_pvs, alloc, MIRROR_BY_SEG)) { log_error("Failed to convert pvmove LV to mirrored"); @@ -510,7 +532,7 @@ static int _set_up_pvmove(struct cmd_context *cmd, const char *pv_name, if (!(lv_mirr = _set_up_pvmove_lv(cmd, vg, source_pvl, lv_name, allocatable_pvs, alloc, - &lvs_changed))) + &lvs_changed, &exclusive))) goto_out; } -- 2.43.5