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

F #2352 #2359 #2981 #3130 #3233: Fix fs_lvm cleanup and offline migration issues (#3201)

Signed-off-by: kvaps <kvapss@gmail.com>
This commit is contained in:
kvaps 2019-04-17 14:00:04 +02:00 committed by Ruben S. Montero
parent aa9ed53e5c
commit 99ded0f884
2 changed files with 99 additions and 54 deletions

View File

@ -44,64 +44,93 @@ source ${DRIVER_PATH}/../../datastore/libfs.sh
DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
DS_SYS_ID=$(echo $DST_PATH | grep -E '\/disk\.[[:digit:]]+$' | $AWK -F '/' '{print $(NF-2)}')
if [ `is_disk $DST_PATH` -eq 1 ]; then
DS_SYS_ID=$(echo $DST_PATH | $AWK -F '/' '{print $(NF-2)}')
else
DS_SYS_ID=$(echo $DST_PATH | $AWK -F '/' '{print $(NF-1)}')
fi
unset i j XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VM_ID | $XPATH \
'/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME')
LAST_HOST="${XPATH_ELEMENTS[j++]}"
# Change DST_HOST to one of the BRIDGE_LIST to prevent
# running on frontend for undeployed VMs
if [ "$LAST_HOST" != "$DST_HOST" ]; then
unset i j XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onedatastore show -x $DS_SYS_ID | $XPATH \
/DATASTORE/TEMPLATE/BRIDGE_LIST)
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
if [ -n "$BRIDGE_LIST" ]; then
DST_HOST=$(get_destination_host)
fi
fi
# Activate device
ACTIVATE_CMD=$(cat <<EOF
set -ex -o pipefail
if [ -L "$DST_PATH" ]; then
DEV=\$(readlink $DST_PATH)
if echo "\$DEV" | grep "^/dev/" &>/dev/null; then
${SUDO} ${SYNC}
${SUDO} ${LVSCAN}
${SUDO} ${LVCHANGE} -ay "\${DEV}"
fi
fi
EOF
)
# Zero space
ZERO_CMD=$(cat <<EOF
set -x
DEV=\$(readlink $DST_PATH)
if echo "\$DEV" | grep "^/dev/" &>/dev/null; then
${DD} if=/dev/zero of="\${DEV}" bs=${DD_BLOCK_SIZE:-64k} || :
set -ex -o pipefail
if [ -L "$DST_PATH" ]; then
DEV=\$(readlink $DST_PATH)
if echo "\$DEV" | grep "^/dev/" &>/dev/null; then
${DD} if=/dev/zero of="\${DEV}" bs=${DD_BLOCK_SIZE:-64k} || :
fi
fi
EOF
)
# Delete the device if it's a clone (LVM snapshot)
DELETE_CMD=$(cat <<EOF
set -x
DEV=\$(readlink $DST_PATH)
set -ex -o pipefail
if [ -d "$DST_PATH" ]; then
rm -rf "$DST_PATH"
else
rm -f $DST_PATH
if [ -z "\$DEV" ]; then
exit 0
fi
exit 0
fi
if [ -L "$DST_PATH" ]; then
DEV=\$(readlink $DST_PATH)
if echo "\$DEV" | grep "^/dev/" &>/dev/null; then
$SUDO $LVREMOVE -f \$DEV
$SUDO $LVREMOVE -f "\$DEV"
fi
fi
rm -f "$DST_PATH"
EOF
)
if [ -n "${DS_SYS_ID}" ]; then
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onedatastore show -x $DS_SYS_ID | $XPATH \
/DATASTORE/TEMPLATE/BRIDGE_LIST)
unset i
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
# Change DST_HOST to one of the BRIDGE_LIST to prevent
# running on frontend for undeployed VMs
if [ -n "$BRIDGE_LIST" ]; then
DST_HOST=$(get_destination_host)
fi
if [ "${ZERO_LVM_ON_DELETE}" = "yes" ]; then
ssh_exec_and_log "$DST_HOST" "$ZERO_CMD" "Error cleaning $DST_PATH"
fi
if [ "${ZERO_LVM_ON_DELETE}" = "yes" ]; then
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" \
"Error deleting $DST_PATH"
else
ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" "Error deleting $DST_PATH"
exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST" "$ACTIVATE_CMD" \
"Error activating disk $SRC_PATH"
ssh_exec_and_log "$DST_HOST" "$ZERO_CMD" "Error cleaning $DST_PATH"
fi
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" \
"Error deleting $DST_PATH"
hup_collectd $DST_HOST

View File

@ -56,21 +56,19 @@ DST_PATH=`arg_path $DST`
SRC_HOST=`arg_host $SRC`
DST_HOST=`arg_host $DST`
SRC_DIR=`dirname $SRC_PATH`
DST_DIR=`dirname $DST_PATH`
SRC_DS_DIR=`dirname $SRC_PATH`
SRC_VM_DIR=`basename $SRC_PATH`
SRC_DS_SYS_ID=$(echo $SRC_DS_DIR | $AWK -F '/' '{print $(NF-1)}')
DST_DS_SYS_ID=$(echo $DST_DIR | $AWK -F '/' '{print $(NF-1)}')
# Activate the disk in the target host
if [ `is_disk $DST_PATH` -eq 1 ]; then
if [ `is_disk $SRC_PATH` -eq 1 ]; then
#---------------------------------------------------------------------------
# Get Image information
#---------------------------------------------------------------------------
DISK_ID=${SRC_VM_DIR##*.}
SRC_DS_SYS_ID=$(echo $SRC_DIR | $AWK -F '/' '{print $(NF-1)}')
DST_DS_SYS_ID=$(echo $DST_DIR | $AWK -F '/' '{print $(NF-1)}')
DISK_ID=${SRC_PATH##*.}
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
@ -79,15 +77,9 @@ if [ `is_disk $DST_PATH` -eq 1 ]; then
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VMID | $XPATH \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TYPE )
/VM/LCM_STATE )
TYPE="${XPATH_ELEMENTS[j++]}"
####
if [ "${TYPE}" != "BLOCK" ]; then
exit 0
fi
LCM_STATE="${XPATH_ELEMENTS[j++]}"
LV_NAME="lv-one-${VMID}-${DISK_ID}"
SRC_VG_NAME="vg-one-${SRC_DS_SYS_ID}"
@ -95,6 +87,30 @@ if [ `is_disk $DST_PATH` -eq 1 ]; then
DST_VG_NAME="vg-one-${DST_DS_SYS_ID}"
DST_DEV="/dev/${DST_VG_NAME}/${LV_NAME}"
# for prolog operation skip deactivate
if ! [[ "$LCM_STATE" =~ ^(31|50)$ ]]; then
# deactivate
CMD=$(cat <<EOF
set -ex -o pipefail
if [ -b "${SRC_DEV}" ]; then
${SUDO} ${SYNC}
${SUDO} ${LVSCAN}
${SUDO} ${LVCHANGE} -an "${SRC_DEV}"
fi
rm -f "${SRC_DIR}/.host" || :
EOF
)
LOCK="tm-fs_lvm-${SRC_DS_SYS_ID}.lock"
exclusive "${LOCK}" 120 ssh_exec_and_log "${SRC_HOST}" "${CMD}" \
"Error deactivating disk ${SRC_PATH}"
fi
# for stop + undeploy operation we got nothing to do
if [[ "$LCM_STATE" =~ ^(10|30|41|42)$ ]]; then
exit 0
fi
# copy volume between datastores
if [ "${SRC_PATH}" != "${DST_PATH}" ]; then
# create new volume