1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

B #2438 Try blockcopy, fsfreeze or suspend first in ssh/cpds (#2528)

This commit is contained in:
Jan Orel 2018-10-23 12:25:44 +02:00 committed by Tino Vázquez
parent 92d1ff6b11
commit c0f3bd79a7

View File

@ -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 <<EOF
touch ${SRC_TEMP_PATH}
if ! virsh -c ${LIBVIRT_URI} blockcopy ${DEPLOY_ID} ${DISK_TARGET} ${SRC_TEMP_PATH} --wait --finish; then
set -e -o pipefail
if virsh -c ${LIBVIRT_URI} domfsfreeze ${DEPLOY_ID}; then
trap "virsh -c ${LIBVIRT_URI} domfsthaw ${DEPLOY_ID}" EXIT TERM INT HUP
$CP $SRC_PATH $SRC_TEMP_PATH
elif virsh -c ${LIBVIRT_URI} suspend ${DEPLOY_ID}; then
trap "virsh -c ${LIBVIRT_URI} resume ${DEPLOY_ID}" EXIT TERM INT HUP
$CP $SRC_PATH $SRC_TEMP_PATH
else
echo "Could not domfsfreeze or suspend domain" >&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"