From 695f8c50a7278780c2dff4ce4e6aae76f7e788f8 Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Fri, 7 Jan 2022 11:33:59 +0100 Subject: [PATCH] F #5530: redefine vm snapshots after migration (#1555) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: René Bayer Co-authored-by: René Bayer (cherry picked from commit 5dfe830feed89debd0e3cfd0ca9e01af26252e68) --- src/vmm_mad/remotes/kvm/migrate | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/vmm_mad/remotes/kvm/migrate b/src/vmm_mad/remotes/kvm/migrate index 3a59c5dd4b..8cd966a55c 100755 --- a/src/vmm_mad/remotes/kvm/migrate +++ b/src/vmm_mad/remotes/kvm/migrate @@ -102,7 +102,9 @@ VM_DIR="${XPATH_ELEMENTS[j++]}" # use "force-share" param for qemu >= 2.10 [ "$(get_qemu_img_version)" -ge 2010000 ] && QEMU_IMG_PARAM="-U" -# migration can't be done with domain snapshots, drop them first +# migration can't be done with domain snapshots, drop them first but save current snapshot for redefine +SNAP_CUR=$(virsh --connect $LIBVIRT_URI snapshot-current --name $DEPLOY_ID 2>/dev/null) + SNAPS=$(monitor_and_log \ "virsh --connect $LIBVIRT_URI snapshot-list $DEPLOY_ID --name 2>/dev/null" \ "Failed to get snapshots for $DEPLOY_ID") @@ -245,6 +247,22 @@ if [ $RC -ne 0 ]; then exit $RC fi +# redefine potential snapshots after live migration +if [ "$SHARED" = "YES" ] && [ -n "$SNAP_CUR" ]; then + UUID=$(virsh --connect $QEMU_PROTOCOL://$DEST_HOST/system dominfo $DEPLOY_ID | awk '/UUID:/ {print $2}') + DISK_PATH=$(virsh --connect $QEMU_PROTOCOL://$DEST_HOST/system domblklist $DEPLOY_ID | awk '/disk.0/ {print $2}') + DISK_DIR=$(dirname $DISK_PATH) + + for SNAPSHOT_MD_XML in $(ls ${DISK_DIR}/snap-*.xml 2>/dev/null); do + # replace uuid in the snapshot metadata xml + sed -i "s%[[:alnum:]-]*%$UUID%" $SNAPSHOT_MD_XML + + # redefine the snapshot using the xml metadata file + virsh --connect $QEMU_PROTOCOL://$DEST_HOST/system snapshot-create $DEPLOY_ID $SNAPSHOT_MD_XML --redefine > /dev/null || true + done + virsh --connect $QEMU_PROTOCOL://$DEST_HOST/system snapshot-current $DEPLOY_ID $SNAP_CUR +fi + # Synchronize VM time on background on remote host if [ "$SYNC_TIME" = "yes" ]; then SYNC_TIME_CMD=$(cat <