From c0f3bd79a77e8c1ccc2150bf3395095beac4c5ad Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Tue, 23 Oct 2018 12:25:44 +0200 Subject: [PATCH] B #2438 Try blockcopy, fsfreeze or suspend first in ssh/cpds (#2528) --- src/tm_mad/ssh/cpds | 77 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/src/tm_mad/ssh/cpds b/src/tm_mad/ssh/cpds index ae542c4b8b..c48bf58cb1 100755 --- a/src/tm_mad/ssh/cpds +++ b/src/tm_mad/ssh/cpds @@ -22,6 +22,7 @@ # - host is the target host to deploy the VM # - remote_system_ds is the path for the system datastore in the host # - snapid is the snapshot id. "-1" for none +# - dsid is the target datastore SRC=$1 DST=$2 @@ -35,14 +36,86 @@ else TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh fi +DRIVER_PATH=$(dirname $0) + . $TMCOMMON +. ${DRIVER_PATH}/../../etc/vmm/kvm/kvmrc + +#------------------------------------------------------------------------------- +# Get Image information +#------------------------------------------------------------------------------- + +DISK_ID=$(basename ${SRC} | cut -d. -f2) + +XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" + +unset i j XPATH_ELEMENTS + +while IFS= read -r -d '' element; do + XPATH_ELEMENTS[i++]="$element" +done < <(onevm show -x $VMID| $XPATH \ + /VM/DEPLOY_ID \ + /VM/LCM_STATE \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TARGET) + +DEPLOY_ID="${XPATH_ELEMENTS[j++]}" +LCM_STATE="${XPATH_ELEMENTS[j++]}" +DISK_TARGET="${XPATH_ELEMENTS[j++]}" + +#------------------------------------------------------------------------------- +# Set src path +#------------------------------------------------------------------------------- + +SRC_PATH=`arg_path $SRC` +SRC_HOST=`arg_host $SRC` +SRC_TEMP_PATH=$(mktemp -u ${SRC_PATH}.XXXXXXXX) + +if [ "${SNAP_ID}" != "-1" ]; then + SRC="${SRC}.snap/${SNAP_ID}" +fi #------------------------------------------------------------------------------- # Move the image back to the datastore #------------------------------------------------------------------------------- +# For current image of the running VMs, don't touch the image directly, +# but export the content via blockcopy. If that's not possible (old QEMU), +# domfsfreeze or suspend the domain before. -if [ "${SNAP_ID}" != "-1" ]; then - SRC="${SRC}.snap/${SNAP_ID}" +if [ "${LCM_STATE}" = '26' ] && [ "${SNAP_ID}" = '-1' ]; then + log "VM is running, trying blockcopy, fsfreeze, suspend" + + CPDS_CMD_EXPORT=$(cat <&2 + exit 1 + fi +fi +EOF +) + + CPDS_CMD_ERR="Error creating export for domain ${DEPLOY_ID} of disk ${DISK_TARGET} at ${SRC_TEMP_PATH}" + + # Always try delete temp export + trap "ssh_exec_and_log $SRC_HOST \"$RM ${SRC_TEMP_PATH}\"" EXIT TERM INT HUP + + if ssh_exec_and_log_no_error $SRC_HOST "$CPDS_CMD_EXPORT" "$CPDS_CMD_ERR"; then + # Export creation succeeded, point SRC there + SRC="${SRC_HOST}:${SRC_TEMP_PATH}" + else + log_error "Exporting failed" + exit 1 + fi fi log "Moving $SRC to datastore as $DST"