From bdc7574fd56835828a29a383b477c7dcce2e5e94 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Tue, 19 May 2009 09:51:02 +0000 Subject: [PATCH] If pvmove fails activating mirror volume, try restore to previous state. pvmove now keep suspended devices if temporary mirror creation fails. We can try to restore previous state if it is first attempt to activate pvmove (code basically run the same code as --abort automatically). --- WHATS_NEW | 1 + test/t-pvmove-basic.sh | 5 +++++ tools/pvmove.c | 20 ++++++++++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 98ff0b60f..d5c8a4bb7 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.46 - ================================ + Fix pvmove to revert operation if temporary mirror creation fails. Fix metadata export for VG with missing PVs. Add vgimportclone and install it and the man page by default. Force max_lv restriction only for newly created LV. diff --git a/test/t-pvmove-basic.sh b/test/t-pvmove-basic.sh index 1875d7e8a..e5b35f5fb 100755 --- a/test/t-pvmove-basic.sh +++ b/test/t-pvmove-basic.sh @@ -370,3 +370,8 @@ vgcreate $vg $devs lvcreate -l4 -n $lv1 $vg $dev1 pvmove $dev1 +#COMM "pvmove fails activating mirror, properly restores state before pvmove" +dmsetup create "$vg-pvmove0" --notable +not pvmove -i 1 $dev2 +test $(dmsetup info --noheadings -c -o suspended "$vg-$lv1") = "Active" +dmsetup remove "$vg-pvmove0" diff --git a/tools/pvmove.c b/tools/pvmove.c index d760802a4..3e12ec10d 100644 --- a/tools/pvmove.c +++ b/tools/pvmove.c @@ -274,6 +274,10 @@ static int _activate_lv(struct cmd_context *cmd, struct logical_volume *lv_mirr, return activate_lv(cmd, lv_mirr); } +static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg, + struct logical_volume *lv_mirr, + struct dm_list *lvs_changed); + static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg, struct logical_volume *lv_mirr, struct dm_list *lvs_changed, unsigned flags) @@ -315,12 +319,16 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg, /* FIXME: Add option to use a log */ if (first_time) { if (!_activate_lv(cmd, lv_mirr, exclusive)) { - if (!test_mode()) - log_error("ABORTING: Temporary mirror " - "activation failed. " - "Run pvmove --abort."); - /* FIXME Resume using *original* metadata here! */ - resume_lvs(cmd, lvs_changed); + if (test_mode()) + goto out; + + /* + * Nothing changed yet, try to revert pvmove. + */ + log_error("Temporary pvmove mirror activation failed."); + if (!_finish_pvmove(cmd, vg, lv_mirr, lvs_changed)) + log_error("ABORTING: Restoring original configuration " + "before pvmove failed. Run pvmove --abort."); goto out; } } else if (!resume_lv(cmd, lv_mirr)) { -- 2.43.5