Skip to content

Commit

Permalink
F #5653 ceph|fs_lvm/mv: skip when VM is unknown (#1816)
Browse files Browse the repository at this point in the history
  • Loading branch information
xorel committed Feb 28, 2022
1 parent 5024248 commit 3650f75
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/tm_mad/ceph/mv

This file was deleted.

106 changes: 106 additions & 0 deletions src/tm_mad/ceph/mv
@@ -0,0 +1,106 @@
#!/bin/bash

# -------------------------------------------------------------------------- #
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #

# MV <hostA:system_ds/disk.i|hostB:system_ds/disk.i> vmid dsid
# <hostA:system_ds/|hostB:system_ds/>
# - hostX is the target host to deploy the VM
# - system_ds is the path for the system datastore in the host
# - vmid is the id of the VM
# - dsid is the target datastore (0 is the system datastore)

SRC=$1
DST=$2

VMID=$3
DSID=$4

if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
fi

. $TMCOMMON

#-------------------------------------------------------------------------------
# Return if moving a disk, we will move them when moving the whole system_ds
# directory for the VM
#-------------------------------------------------------------------------------
SRC=$(fix_dir_slashes $SRC)
DST=$(fix_dir_slashes $DST)

SRC_PATH=$(arg_path $SRC)
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)

if [ "$(is_disk $DST_PATH)" -eq 1 ]; then
exit 0
fi

#Do not try to move any files in PROLOG_MIGRATE_UNKNOWN (60),
#PROLOG_MIGRATE_UNKNOWN_FAILURE (61) or UNKNOWN (16)
LCM_STATE=$(lcm_state "$VMID")

if [[ "$LCM_STATE" =~ ^(16|60|61)$ ]]; then
log "Not moving files from $SRC_HOST in FT mode or VM unknown"
exit 0
fi

# preserve .monitor content (if any)
MONITOR_CMD=$(cat <<EOF
if [ -r '${SRC_DIR}/.monitor' ]; then
cat '${SRC_DIR}/.monitor' 2>/dev/null || :
fi
EOF
)

MONITOR=$(ssh_monitor_and_log "$SRC_HOST" "$MONITOR_CMD" 'Get .monitor')

ssh_make_path "$DST_HOST" "$DST_PATH" "$MONITOR"

RANDOM_FILE=$(ssh "$DST_HOST" "mktemp -p \"$DST_DIR\"")
trap "ssh $DST_HOST \"rm -f $RANDOM_FILE\"" EXIT
if ssh "$SRC_HOST" "test -f $RANDOM_FILE"; then
log "Not moving $SRC to $DST, they are the same path"
exit 0
fi

log "Moving $SRC to $DST"

ssh_exec_and_log "$DST_HOST" "rm -rf '$DST_PATH'" \
"Error removing target path to prevent overwrite errors"

TAR_SSH=$(cat <<EOF
set -e -o pipefail
$TAR -C $SRC_DS_DIR --sparse -cf - $SRC_VM_DIR | $SSH $DST_HOST '$TAR -C $DST_DIR --sparse -xf -'
rm -rf $SRC_PATH
EOF
)

ssh_forward ssh_exec_and_log "$SRC_HOST" "$TAR_SSH" "Error copying disk directory to target host"

exit 0
9 changes: 8 additions & 1 deletion src/tm_mad/fs_lvm/mv
Expand Up @@ -79,9 +79,11 @@ if [ "$(is_disk "$SRC_PATH")" -eq 1 ]; then
DST_DEV="/dev/${DST_VG_NAME}/${LV_NAME}"

# skip deactivate for `onevm resume` (after stop or undeploy)
# or if VM is unknown
# 9(49) = PROLOG_RESUME(+FAILURE)
# 31(50) = PROLOG_UNDEPLOY(+FAILURE)
if ! [[ "$LCM_STATE" =~ ^(9|31|49|50)$ ]]; then
# 16 = UNKNOWN
if ! [[ "$LCM_STATE" =~ ^(9|16|31|49|50)$ ]]; then
# deactivate
CMD=$(cat <<EOF
set -ex -o pipefail
Expand Down Expand Up @@ -165,5 +167,10 @@ if [ "$SRC_PATH" == "$DST_PATH" ]; then
exit 0
fi

# Return if VM is unknown, assume SRC host failure
if [[ "$LCM_STATE" = "16" ]]; then
exit 0
fi

ssh_exec_and_log "$DST_HOST" "mv $SRC_PATH $DST_PATH" \
"Error moving VM files to another System DS: $SRC_PATH to $DST_PATH in $DST_HOST"

3 comments on commit 3650f75

@GitCop
Copy link

@GitCop GitCop commented on 3650f75 Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were the following issues with your Pull Request

  • Subject must be equal or less than 50

Guidelines are available at https://github.com/OpenNebula/one/blob/master/share/doc/dev/COMMIT_MESSAGES.md


This message was auto-generated by https://gitcop.com

@GitCop
Copy link

@GitCop GitCop commented on 3650f75 Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were the following issues with your Pull Request

  • Subject must be equal or less than 50

Guidelines are available at https://github.com/OpenNebula/one/blob/master/share/doc/dev/COMMIT_MESSAGES.md


This message was auto-generated by https://gitcop.com

@GitCop
Copy link

@GitCop GitCop commented on 3650f75 Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were the following issues with your Pull Request

  • Subject must be equal or less than 50

Guidelines are available at https://github.com/OpenNebula/one/blob/master/share/doc/dev/COMMIT_MESSAGES.md


This message was auto-generated by https://gitcop.com

Please sign in to comment.