1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-10 01:17:40 +03:00

B : properly manage undeployed states (LVM) ()

This commit is contained in:
Christian González 2021-05-26 11:28:49 +02:00 committed by GitHub
parent ed088ef826
commit 0bef8ee722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 198 additions and 250 deletions
share/pkgs/sudoers
src/tm_mad

View File

@ -1 +1 @@
oneadmin ALL=(ALL) NOPASSWD: ONE_CEPH, ONE_HA, ONE_MARKET oneadmin ALL=(ALL) NOPASSWD: ONE_CEPH, ONE_HA, ONE_MARKET, ONE_LVM

View File

@ -44,68 +44,51 @@ source ${DRIVER_PATH}/../../datastore/libfs.sh
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Set dst path and dir # Set dst path and dir
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
SRC_PATH=`arg_path $SRC` SRC_PATH=$(arg_path "$SRC")
SRC_HOST=`arg_host $SRC` SRC_HOST=$(arg_host "$SRC")
DST_PATH=`arg_path $DST` DST_PATH=$(arg_path "$DST")
DST_HOST=`arg_host $DST`
DISK_ID=$(echo $SRC_PATH|$AWK -F. '{print $NF}') DISK_ID=$(echo "$SRC_PATH"|$AWK -F. '{print $NF}')
DS_SYS_ID=$(echo $SRC_PATH|$AWK -F/ '{print $(NF-2)}') DS_SYS_ID=$(echo "$SRC_PATH"|$AWK -F/ '{print $(NF-2)}')
LV_NAME="lv-one-$VM_ID-$DISK_ID" LV_NAME="lv-one-$VM_ID-$DISK_ID"
VG_NAME="vg-one-$DS_SYS_ID" VG_NAME="vg-one-$DS_SYS_ID"
DEV="/dev/${VG_NAME}/${LV_NAME}" DEV="/dev/${VG_NAME}/${LV_NAME}"
#------------------------------------------------------------------------------- if is_undeployed "$VM_ID" "$SRC_HOST"; then
# Get VM information
#-------------------------------------------------------------------------------
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 $VM_ID| $XPATH \
'/VM/LCM_STATE' \
'/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME')
LCM_STATE="${XPATH_ELEMENTS[j++]}"
LAST_HOST="${XPATH_ELEMENTS[j++]}"
# Undeployed VM state
if [ "$LCM_STATE" = '67' ] || [ "$LCM_STATE" = '68' ]; then
# get BRIDGE_LIST from datastore # get BRIDGE_LIST from datastore
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x $DS_SYS_ID \ XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x "$DS_SYS_ID" \
| $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST ) | $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST )
if [ -n "$BRIDGE_LIST" ]; then if [ -n "$BRIDGE_LIST" ]; then
SRC_HOST=$(get_destination_host) SRC_HOST=$(get_destination_host)
elif [ -n "$LAST_HOST" ]; then
SRC_HOST=$LAST_HOST
else
log_error "Unknown last VM host nor BRIDGE_LIST"
exit -1
fi fi
ACTIVATE="$SUDO $LVCHANGE -ay "$DEV"" #else we assume that FE have access to LVM storage
DEACTIVATE="$SUDO $LVCHANGE -an "$DEV""
DUMP_CMD=$(cat <<EOF
set -e -o pipefail
$SUDO $LVCHANGE -ay $DEV > /dev/null 2>&1
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k}
$SUDO $LVCHANGE -an $DEV > /dev/null 2>&1
EOF
)
else
DUMP_CMD=$(cat <<EOF
set -e -o pipefail
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k}
EOF
)
fi fi
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Move the image back to the datastore # Move the image back to the datastore
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
DUMP_CMD=$(cat <<EOF
$ACTIVATE
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k}
$DEACTIVATE
EOF
)
log "Dumping $SRC to $DST" log "Dumping $SRC to $DST"
ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" \ ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" "Error dumping $SRC to $DST"
"Error dumping $SRC to $DST"
exit 0 exit 0

View File

@ -41,94 +41,55 @@ source ${DRIVER_PATH}/../../datastore/libfs.sh
# Return if deleting a disk, we will delete them when removing the # Return if deleting a disk, we will delete them when removing the
# remote_system_ds directory for the VM (remotely) # remote_system_ds directory for the VM (remotely)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
DST_PATH=`arg_path $DST` DST_PATH=$(arg_path "$DST")
DST_HOST=`arg_host $DST` DST_HOST=$(arg_host "$DST")
DST_HOST_LVM="$DST_HOST"
if [ `is_disk $DST_PATH` -eq 1 ]; then if [ "$(is_disk "$DST_PATH")" -eq 1 ]; then
DS_SYS_ID=$(echo $DST_PATH | $AWK -F '/' '{print $(NF-2)}') DS_SYS_ID=$(echo "$DST_PATH" | $AWK -F '/' '{print $(NF-2)}')
else else
DS_SYS_ID=$(echo $DST_PATH | $AWK -F '/' '{print $(NF-1)}') DS_SYS_ID=$(echo "$DST_PATH" | $AWK -F '/' '{print $(NF-1)}')
fi fi
unset i j XPATH_ELEMENTS if is_undeployed "$VM_ID" "$DST_HOST"; then
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++]}" # get BRIDGE_LIST from datastore
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x "$DS_SYS_ID" \
| $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST )
if [ -n "$BRIDGE_LIST" ]; then # If BRIDGE_LIST is not defined FE must have access to LVM cluster
# Change DST_HOST to one of the BRIDGE_LIST to prevent DST_HOST_LVM=$(get_destination_host)
# 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
fi fi
# Activate device # Get DEV
ACTIVATE_CMD=$(cat <<EOF DEV=$($SSH "$DST_HOST" "readlink $DST_PATH 2> /dev/null | grep \"^/dev/\"")
set -ex -o pipefail
if [ -L "$DST_PATH" ]; then if [ -n "$DEV" ]; then
DEV=\$(readlink $DST_PATH)
if echo "\$DEV" | grep "^/dev/" &>/dev/null; then if [ "${ZERO_LVM_ON_DELETE}" = "yes" ]; then
# Activate device
ACTIVATE_CMD=$(cat <<EOF
set -ex -o pipefail
${SYNC} ${SYNC}
${SUDO} ${LVSCAN} ${SUDO} ${LVSCAN}
${SUDO} ${LVCHANGE} -ay "\${DEV}" ${SUDO} ${LVCHANGE} -ay "${DEV}"
fi
fi
EOF EOF
) )
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST_LVM" "$ACTIVATE_CMD" \
"Error activating disk $SRC_PATH"
# Zero space # It's separeted from ACTIVATE_CMD to avoid blocking while writing in the device
ZERO_CMD=$(cat <<EOF ssh_exec_and_log_no_error "$DST_HOST_LVM" "${DD} if=/dev/zero of=\"${DEV}\" bs=${DD_BLOCK_SIZE:-64k}" \
set -ex -o pipefail "Error cleaning $DST_PATH"
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 -ex -o pipefail
if [ -d "$DST_PATH" ]; then
rm -rf "$DST_PATH"
exit 0
fi fi
if [ -L "$DST_PATH" ]; then
DEV=\$(readlink $DST_PATH)
if echo "\$DEV" | grep "^/dev/" &>/dev/null; then
$SUDO $LVREMOVE -f "\$DEV"
fi
fi
rm -f "$DST_PATH" exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST_LVM" "$SUDO $LVREMOVE -f \"$DEV\"" \
EOF "Error deleting $DST_PATH"
)
if [ "${ZERO_LVM_ON_DELETE}" = "yes" ]; then
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
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 fi
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock" ssh_exec_and_log "$DST_HOST" "rm -rf \"$DST_PATH\"" \
exclusive "${LOCK}" 120 ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" \ "Error removing \"$DST_PATH\" from $DST_HOST"
"Error deleting $DST_PATH"

View File

@ -47,39 +47,30 @@ source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
#-------------------------------------------------------------------------------- #--------------------------------------------------------------------------------
SRC=`fix_dir_slashes $SRC` SRC=$(fix_dir_slashes "$SRC")
DST=`fix_dir_slashes $DST` DST=$(fix_dir_slashes "$DST")
SRC_PATH=`arg_path $SRC` SRC_PATH=$(arg_path "$SRC")
DST_PATH=`arg_path $DST` DST_PATH=$(arg_path "$DST")
SRC_HOST=`arg_host $SRC` SRC_HOST=$(arg_host "$SRC")
DST_HOST=`arg_host $DST` DST_HOST=$(arg_host "$DST")
SRC_DIR=`dirname $SRC_PATH` SRC_DIR=$(dirname "$SRC_PATH")
DST_DIR=`dirname $DST_PATH` DST_DIR=$(dirname "$DST_PATH")
# Activate the disk in the target host # Activate the disk in the target host
if [ `is_disk $SRC_PATH` -eq 1 ]; then if [ "$(is_disk "$SRC_PATH")" -eq 1 ]; then
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Get Image information # Get Image information
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
SRC_DS_SYS_ID=$(echo $SRC_DIR | $AWK -F '/' '{print $(NF-1)}') SRC_DS_SYS_ID=$(echo "$SRC_DIR" | $AWK -F '/' '{print $(NF-1)}')
DST_DS_SYS_ID=$(echo $DST_DIR | $AWK -F '/' '{print $(NF-1)}') DST_DS_SYS_ID=$(echo "$DST_DIR" | $AWK -F '/' '{print $(NF-1)}')
DISK_ID=${SRC_PATH##*.} DISK_ID=${SRC_PATH##*.}
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" LCM_STATE=$(lcm_state "$VMID")
unset i j XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VMID | $XPATH \
/VM/LCM_STATE )
LCM_STATE="${XPATH_ELEMENTS[j++]}"
LV_NAME="lv-one-${VMID}-${DISK_ID}" LV_NAME="lv-one-${VMID}-${DISK_ID}"
SRC_VG_NAME="vg-one-${SRC_DS_SYS_ID}" SRC_VG_NAME="vg-one-${SRC_DS_SYS_ID}"

View File

@ -35,32 +35,59 @@ fi
DRIVER_PATH=$(dirname $0) DRIVER_PATH=$(dirname $0)
source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
source $TMCOMMON source $TMCOMMON
source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
source ${DRIVER_PATH}/../../datastore/libfs.sh
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Set dst path and dir # Set dst path and dir
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
SRC_PATH=`arg_path $SRC` SRC_PATH=$(arg_path "$SRC")
SRC_HOST=`arg_host $SRC` SRC_HOST=$(arg_host "$SRC")
DST_PATH=`arg_path $DST` DST_PATH=$(arg_path "$DST")
DST_HOST=`arg_host $DST`
DISK_ID=$(echo $SRC_PATH|$AWK -F. '{print $NF}') DISK_ID=$(echo "$SRC_PATH"|$AWK -F. '{print $NF}')
DS_SYS_ID=$(echo $SRC_PATH|$AWK -F/ '{print $(NF-2)}') DS_SYS_ID=$(echo "$SRC_PATH"|$AWK -F/ '{print $(NF-2)}')
LV_NAME="lv-one-$VM_ID-$DISK_ID" LV_NAME="lv-one-$VM_ID-$DISK_ID"
VG_NAME="vg-one-$DS_SYS_ID" VG_NAME="vg-one-$DS_SYS_ID"
DEV="/dev/${VG_NAME}/${LV_NAME}" DEV="/dev/${VG_NAME}/${LV_NAME}"
DUMP_CMD=$(cat <<EOF if is_undeployed "$VM_ID" "$SRC_HOST"; then
set -e -o pipefail
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k} # get BRIDGE_LIST from datastore
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x "$DS_SYS_ID" \
| $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST )
if [ -n "$BRIDGE_LIST" ]; then
SRC_HOST=$(get_destination_host)
fi
# we assume that FE have access to LVM storage
DUMP_CMD=$(cat <<EOF
set -e -o pipefail
$SUDO $LVCHANGE -ay $DEV > /dev/null 2>&1
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k}
$SUDO $LVCHANGE -an $DEV > /dev/null 2>&1
EOF EOF
) )
else
DUMP_CMD=$(cat <<EOF
set -e -o pipefail
$DD if=$DEV of=$DST_PATH bs=${DD_BLOCK_SIZE:-64k}
EOF
)
fi
#-------------------------------------------------------------------------------
# Move the image back to the datastore
#-------------------------------------------------------------------------------
log "Dumping $SRC to $DST"
ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" "Error dumping $SRC to $DST"
DELETE_CMD=$(cat <<EOF DELETE_CMD=$(cat <<EOF
set -e -o pipefail set -e -o pipefail
@ -68,14 +95,6 @@ DELETE_CMD=$(cat <<EOF
EOF EOF
) )
#-------------------------------------------------------------------------------
# Move the image back to the datastore
#-------------------------------------------------------------------------------
log "Dumping $SRC to $DST"
ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" \
"Error dumping $SRC to $DST"
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock" LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
exclusive "${LOCK}" 120 ssh_exec_and_log "$SRC_HOST" "$DELETE_CMD" \ exclusive "${LOCK}" 120 ssh_exec_and_log "$SRC_HOST" "$DELETE_CMD" \
"Error dumping $SRC to $DST" "Error dumping $SRC to $DST"

View File

@ -42,14 +42,13 @@ source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Set dst path and dir # Set dst path and dir
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
SRC_PATH=`arg_path $SRC` SRC_PATH=$(arg_path "$SRC")
SRC_HOST=`arg_host $SRC` SRC_HOST=$(arg_host "$SRC")
DST_PATH=`arg_path $DST` DST_PATH=$(arg_path "$DST")
DST_HOST=`arg_host $DST`
DISK_ID=$(echo $SRC_PATH|$AWK -F. '{print $NF}') DISK_ID=$(echo "$SRC_PATH"|$AWK -F. '{print $NF}')
DS_SYS_ID=$(echo $SRC_PATH|$AWK -F/ '{print $(NF-2)}') DS_SYS_ID=$(echo "$SRC_PATH"|$AWK -F/ '{print $(NF-2)}')
LV_NAME="lv-one-$VM_ID-$DISK_ID" LV_NAME="lv-one-$VM_ID-$DISK_ID"
VG_NAME="vg-one-$DS_SYS_ID" VG_NAME="vg-one-$DS_SYS_ID"
@ -59,34 +58,19 @@ DEV="/dev/${VG_NAME}/${LV_NAME}"
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Get VM information # Get VM information
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
unset i j XPATH_ELEMENTS if is_undeployed "$VM_ID" "$SRC_HOST"; then
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VM_ID| $XPATH \
'/VM/LCM_STATE' \
'/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME')
LCM_STATE="${XPATH_ELEMENTS[j++]}"
LAST_HOST="${XPATH_ELEMENTS[j++]}"
# HOTPLUG_SAVEAS_UNDEPLOYED || HOTPLUG_SAVEAS_STOPPED (i.e VM not present in HV node)
if [ "$LCM_STATE" = '67' ] || [ "$LCM_STATE" = '68' ]; then
# get BRIDGE_LIST from datastore # get BRIDGE_LIST from datastore
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x $DS_SYS_ID \ XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x "$DS_SYS_ID" \
| $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST ) | $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST )
if [ -n "$BRIDGE_LIST" ]; then if [ -n "$BRIDGE_LIST" ]; then
SRC_HOST=$(get_destination_host) SRC_HOST=$(get_destination_host)
elif [ -n "$LAST_HOST" ]; then
SRC_HOST=$LAST_HOST
else
log_error "Unknown last VM host nor BRIDGE_LIST"
exit -1
fi fi
# else we assume that FE have access to LVM storage
ACTIVATE="$SUDO $LVCHANGE -ay $DEV > /dev/null 2>&1" ACTIVATE="$SUDO $LVCHANGE -ay $DEV > /dev/null 2>&1"
DEACTIVATE="$SUDO $LVCHANGE -an $DEV > /dev/null 2>&1" DEACTIVATE="$SUDO $LVCHANGE -an $DEV > /dev/null 2>&1"
fi fi
@ -97,31 +81,20 @@ fi
log "Dumping $SRC to $DST" log "Dumping $SRC to $DST"
# Copy from possibly remote host to possible remote host if [ -n "$ACTIVATE" ]; then
if [ "$(fix_dir_slashes $DST_HOST)" != "$DST_PATH" ]; then
# TODO, this branch is not used. Remove it or leave just in case?
DUMP_CMD=$(cat <<EOF DUMP_CMD=$(cat <<EOF
set -e -o pipefail $SSH "$SRC_HOST" "$ACTIVATE; $DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse; $DEACTIVATE" | \
$ACTIVATE
$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse | $SSH "$DST_HOST" "cat - > $DST_PATH"
$DEACTIVATE
EOF
)
ssh_forward ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" "Error dumping $SRC to $DST"
else # Copy from possibly remote host to local
DUMP_CMD=$(cat <<EOF
if [ -n "$ACTIVATE" ]; then
$SSH "$SRC_HOST" "$ACTIVATE; $DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse; $DEACTIVATE" | \
cat - > "$DST_PATH" cat - > "$DST_PATH"
else
$SSH "$SRC_HOST" "$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse" | cat - > "$DST_PATH"
fi
EOF EOF
) )
else
multiline_exec_and_log "$DUMP_CMD" "Error dumping $SRC to $DST" DUMP_CMD=$(cat <<EOF
$SSH "$SRC_HOST" "$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse" | cat - > "$DST_PATH"
EOF
)
fi fi
multiline_exec_and_log "$DUMP_CMD" "Error dumping $SRC to $DST"
exit 0 exit 0

View File

@ -47,39 +47,30 @@ source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
#-------------------------------------------------------------------------------- #--------------------------------------------------------------------------------
SRC=`fix_dir_slashes $SRC` SRC=$(fix_dir_slashes "$SRC")
DST=`fix_dir_slashes $DST` DST=$(fix_dir_slashes "$DST")
SRC_PATH=`arg_path $SRC` SRC_PATH=$(arg_path "$SRC")
DST_PATH=`arg_path $DST` DST_PATH=$(arg_path "$DST")
SRC_HOST=`arg_host $SRC` SRC_HOST=$(arg_host "$SRC")
DST_HOST=`arg_host $DST` DST_HOST=$(arg_host "$DST")
SRC_DIR=`dirname $SRC_PATH` SRC_DIR=$(dirname "$SRC_PATH")
DST_DIR=`dirname $DST_PATH` DST_DIR=$(dirname "$DST_PATH")
# Activate the disk in the target host # Activate the disk in the target host
if [ `is_disk $SRC_PATH` -eq 1 ]; then if [ "$(is_disk "$SRC_PATH")" -eq 1 ]; then
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Get Image information # Get Image information
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
SRC_DS_SYS_ID=$(echo $SRC_DIR | $AWK -F '/' '{print $(NF-1)}') SRC_DS_SYS_ID=$(echo "$SRC_DIR" | $AWK -F '/' '{print $(NF-1)}')
DST_DS_SYS_ID=$(echo $DST_DIR | $AWK -F '/' '{print $(NF-1)}') DST_DS_SYS_ID=$(echo "$DST_DIR" | $AWK -F '/' '{print $(NF-1)}')
DISK_ID=${SRC_PATH##*.} DISK_ID=${SRC_PATH##*.}
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" LCM_STATE=$(lcm_state "$VMID")
unset i j XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VMID | $XPATH \
/VM/LCM_STATE )
LCM_STATE="${XPATH_ELEMENTS[j++]}"
LV_NAME="lv-one-${VMID}-${DISK_ID}" LV_NAME="lv-one-${VMID}-${DISK_ID}"
SRC_VG_NAME="vg-one-${SRC_DS_SYS_ID}" SRC_VG_NAME="vg-one-${SRC_DS_SYS_ID}"
@ -112,6 +103,8 @@ EOF
# 10(41) = EPILOG_STOP(+FAILURE) # 10(41) = EPILOG_STOP(+FAILURE)
# 30(42) = EPILOG_UNDEPLOY(+FAILURE) # 30(42) = EPILOG_UNDEPLOY(+FAILURE)
if [[ "$LCM_STATE" =~ ^(10|30|41|42)$ ]]; then if [[ "$LCM_STATE" =~ ^(10|30|41|42)$ ]]; then
# After managing LV deactivation on hosts, transfer normal files
"$(dirname "$0")"/../ssh/mv "$@"
exit 0 exit 0
fi fi
@ -168,4 +161,4 @@ EOF
fi fi
# After managing LV de/activation on different hosts, transfer normal files # After managing LV de/activation on different hosts, transfer normal files
$(dirname "$0")/../ssh/mv "$@" "$(dirname "$0")"/../ssh/mv "$@"

View File

@ -35,57 +35,62 @@ fi
DRIVER_PATH=$(dirname $0) DRIVER_PATH=$(dirname $0)
source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf source ${DRIVER_PATH}/../../etc/tm/fs_lvm/fs_lvm.conf
source ${DRIVER_PATH}/../../datastore/libfs.sh
source $TMCOMMON source $TMCOMMON
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Set dst path and dir # Set dst path and dir
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
SRC_PATH=`arg_path $SRC` SRC_PATH=$(arg_path "$SRC")
SRC_HOST=`arg_host $SRC` SRC_HOST=$(arg_host "$SRC")
DST_PATH=`arg_path $DST` DST_PATH=$(arg_path "$DST")
DST_HOST=`arg_host $DST`
DISK_ID=$(echo $SRC_PATH|$AWK -F. '{print $NF}') DISK_ID=$(echo "$SRC_PATH"|$AWK -F. '{print $NF}')
DS_SYS_ID=$(echo $SRC_PATH|$AWK -F/ '{print $(NF-2)}') DS_SYS_ID=$(echo "$SRC_PATH"|$AWK -F/ '{print $(NF-2)}')
LV_NAME="lv-one-$VM_ID-$DISK_ID" LV_NAME="lv-one-$VM_ID-$DISK_ID"
VG_NAME="vg-one-$DS_SYS_ID" VG_NAME="vg-one-$DS_SYS_ID"
DEV="/dev/${VG_NAME}/${LV_NAME}" DEV="/dev/${VG_NAME}/${LV_NAME}"
if is_undeployed "$VM_ID" "$SRC_HOST"; then
# get BRIDGE_LIST from datastore
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x "$DS_SYS_ID" \
| $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST )
if [ -n "$BRIDGE_LIST" ]; then
SRC_HOST=$(get_destination_host)
fi
# else we assume that FE have access to LVM storage
ACTIVATE="$SUDO $LVCHANGE -ay $DEV > /dev/null 2>&1"
DEACTIVATE="$SUDO $LVCHANGE -an $DEV > /dev/null 2>&1"
fi
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Move the image back to the datastore # Move the image back to the datastore
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
log "Dumping $SRC to $DST" log "Dumping $SRC to $DST"
# Copy from possibly remote host to possible remote host if [ -n "$ACTIVATE" ]; then
if [ "$(fix_dir_slashes $DST_HOST)" != "$DST_PATH" ]; then
DUMP_CMD=$(cat <<EOF DUMP_CMD=$(cat <<EOF
set -e -o pipefail $SSH "$SRC_HOST" "$ACTIVATE; $DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse; $DEACTIVATE" | \
$ACTIVATE
$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse | $SSH "$DST_HOST" "cat - > $DST_PATH"
$DEACTIVATE
EOF
)
ssh_forward ssh_exec_and_log "$SRC_HOST" "$DUMP_CMD" "Error dumping $SRC to $DST"
else # Copy from possibly remote host to local
DUMP_CMD=$(cat <<EOF
set -e -o pipefail
if [ -n "$ACTIVATE" ]; then
$SSH "$SRC_HOST" "$ACTIVATE; $DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse; $DEACTIVATE" | \
cat - > "$DST_PATH" cat - > "$DST_PATH"
else
$SSH "$SRC_HOST" "$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse" | cat - > "$DST_PATH"
fi
EOF EOF
) )
multiline_exec_and_log "$DUMP_CMD" "Error dumping $SRC to $DST" else
DUMP_CMD=$(cat <<EOF
$SSH "$SRC_HOST" "$DD if=\"$DEV\" bs=${DD_BLOCK_SIZE:-64k} conv=sparse" | cat - > "$DST_PATH"
EOF
)
fi fi
multiline_exec_and_log "$DUMP_CMD" "Error dumping $SRC to $DST"
DELETE_CMD=$(cat <<EOF DELETE_CMD=$(cat <<EOF
set -e -o pipefail set -e -o pipefail
$SUDO $LVREMOVE -f $DEV $SUDO $LVREMOVE -f $DEV
@ -94,6 +99,6 @@ EOF
LOCK="tm-fs_lvm-${DS_SYS_ID}.lock" LOCK="tm-fs_lvm-${DS_SYS_ID}.lock"
exclusive "${LOCK}" 120 ssh_exec_and_log "$SRC_HOST" "$DELETE_CMD" \ exclusive "${LOCK}" 120 ssh_exec_and_log "$SRC_HOST" "$DELETE_CMD" \
"Error removing $DEV" "Error dumping $SRC to $DST"
exit 0 exit 0

View File

@ -117,6 +117,29 @@ function lcm_state
echo $LCM_STATE echo $LCM_STATE
} }
# Check if the VM is undeployed/stopped
function is_undeployed
{
XPATH="${ONE_LOCAL_VAR}/remotes/datastore/xpath.rb --stdin"
unset i XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x "${1:-$VMID}" | $XPATH \
'/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME' )
LAST_HOST="${XPATH_ELEMENTS[0]}"
CURRENT_HOST="$2"
if [ "$LAST_HOST" != "$CURRENT_HOST" ]; then
return 0
fi
return 1
}
function migrate_other function migrate_other
{ {