Skip to content

Commit

Permalink
save/restore directly on datastore
Browse files Browse the repository at this point in the history
Signed-off-by: kvaps <kvapss@gmail.com>
  • Loading branch information
kvaps committed Apr 24, 2019
1 parent 1e00f4b commit 42cc72c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 54 deletions.
25 changes: 9 additions & 16 deletions vmm/kvm/restore_linstor_un
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,19 @@ source ${DRIVER_PATH}/../../datastore/linstor_un/linstor_utils.sh

linstor_load_keys

# Load cleanup trap
trap linstor_cleanup_trap EXIT

# Attach diskless resource for DST_RES on DST_HOST
SRC_RES_HOSTS=$(linstor_get_hosts_for_res "$SRC_RES")
if ! [[ " $SRC_RES_HOSTS " =~ " $DST_HOST " ]]; then
linstor_exec_and_log \
"resource create -s $DISKLESS_POOL $DST_HOST $SRC_RES"
fi

ssh_exec_and_log "$DST_HOST" \
"$QEMU_IMG convert -O raw $SRC_DEV $SRC_PATH" \
"Error importing $SRC_DEV to $SRC_PATH on $DST_HOST"

linstor_exec_and_log \
"resource-definition delete $SRC_RES"

RECALCULATE_CMD=$(cat <<EOF
set -e -o pipefail
# extract the xml from the checkpoint
virsh --connect $LIBVIRT_URI save-image-dumpxml $SRC_PATH > $SRC_XML
virsh --connect $LIBVIRT_URI save-image-dumpxml $SRC_DEV > $SRC_XML
# Eeplace all occurrences of the DS_LOCATION/<DS_ID>/<VM_ID> with the specific
# DS_ID where the checkpoint is placed. This is done in case there was a
Expand All @@ -115,8 +105,8 @@ ssh_exec_and_log "$DST_HOST" "$RECALCULATE_CMD" \

function restore_domain {
ssh_exec_and_log "$DST_HOST" \
"virsh --connect $LIBVIRT_URI restore $SRC_PATH --xml $SRC_XML" \
"Could not restore from $SRC_PATH on $DST_HOST"
"virsh --connect $LIBVIRT_URI restore $SRC_DEV --xml $SRC_XML" \
"Could not restore from $SRC_DEV on $DST_HOST"
}

retry 3 restore_domain
Expand All @@ -125,8 +115,11 @@ if [ $? -ne 0 ]; then
exit 1
fi

ssh_exec_and_log_no_error "$DST_HOST" \
"rm $SRC_PATH $SRC_XML" \
"Could not remove $SRC_PATH or $SRC_XML on $DST_HOST"
ssh_exec_and_log "$DST_HOST" \
"virsh --connect $LIBVIRT_URI resume $DEPLOY_ID" \
"Could not resume $DEPLOY_ID on $DST_HOST"

linstor_exec_and_log \
"resource-definition delete $SRC_RES"

exit 0
63 changes: 25 additions & 38 deletions vmm/kvm/save_linstor_un
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,25 @@ source ${DRIVER_PATH}/../../datastore/linstor_un/linstor_utils.sh
linstor_load_keys

# Load cleanup trap
trap linstor_cleanup_trap EXIT

# Saving VM state to checkpoint file
SAVE_CMD=$(cat <<EOT
if [ -f "$DST_PATH" ]; then
epoch=\$(date +%s)
mv $DST_PATH $DST_PATH.\$epoch
fi
touch "$DST_PATH"
chmod 666 "$DST_PATH"
virsh --connect $LIBVIRT_URI save $DEPLOY_ID $DST_PATH
EOT
)

ssh_exec_and_log "$SRC_HOST" "$SAVE_CMD" \
"Could not save $DEPLOY_ID to $DST_PATH on $SRC_HOST"

ORIGINAL_SIZE_B="$($SSH $SRC_HOST $QEMU_IMG info $DST_PATH | \
$AWK -F'[ ()]+' '/^virtual size: / {print $4}')"
if [ -z "$ORIGINAL_SIZE_B" ]; then
error_message "Error getting $DST_PATH checkpoint size"
revert() {
$SSH $SRC_HOST virsh --connect $LIBVIRT_URI resume $DEPLOY_ID
linstor_cleanup_trap
}
trap revert EXIT

# Suspend VM
ssh_exec_and_log "$SRC_HOST" \
"virsh --connect $LIBVIRT_URI suspend $DEPLOY_ID" \
"Could not suspend $DEPLOY_ID on $SRC_HOST"

ORIGINAL_SIZE_K="$($SSH $SRC_HOST virsh --connect $LIBVIRT_URI dommemstat $DEPLOY_ID | \
$AWK '$1 == "rss" {print $2}')"

if [ -z "$ORIGINAL_SIZE_K" ]; then
error_message "Error getting checkpoint size"
ssh_exec_and_log_no_error "$SRC_HOST" \
"virsh --connect $LIBVIRT_URI resume $DEPLOY_ID" \
"Could not resume $DEPLOY_ID on $SRC_HOST"
exit -1
fi

Expand All @@ -127,7 +122,7 @@ linstor_exec_and_log \
"resource-definition create $DST_RES"
LINSTOR_CLEANUP_RD+=" $DST_RES"
linstor_exec_and_log \
"volume-definition create $VOL_CREATE_ARGS $DST_RES ${ORIGINAL_SIZE_B}B"
"volume-definition create $VOL_CREATE_ARGS $DST_RES ${ORIGINAL_SIZE_K}K"
linstor_exec_and_log \
"resource create $RES_CREATE_ARGS --storage-pool $STORAGE_POOL $NODE_LIST $DST_RES"

Expand All @@ -139,19 +134,11 @@ if ! [[ " $DST_RES_HOSTS " =~ " $SRC_HOST " ]]; then
LINSTOR_CLEANUP_RES+=" $SRC_HOST:$DST_RES"
fi

# Import checkpoint file
IMPORT_CMD=$(cat <<EOF
set -e -o pipefail
$QEMU_IMG convert -O raw $DST_PATH $DST_DEV
# remove original
$RM -f $DST_PATH
EOF
)
ssh_exec_and_log "$SRC_HOST" "$IMPORT_CMD" \
"Error importing $DST_PATH to $DST_DEV on $SRC_HOST"
# saving vm state
ssh_exec_and_log "$SRC_HOST" \
"virsh --connect $LIBVIRT_URI save $DEPLOY_ID $DST_DEV" \
"could not save $DEPLOY_ID to $DST_PATH on $SRC_HOST"

trap linstor_cleanup_trap EXIT
LINSTOR_CLEANUP_RD=
exit 0

0 comments on commit 42cc72c

Please sign in to comment.