From 37d27227ecd659bf9e9a498c01b53ce0aa73d487 Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Mon, 28 Feb 2022 17:00:31 +0100 Subject: [PATCH] F #5653 ceph|fs_lvm/mv: skip when VM is unknown (#1816) (cherry picked from commit 3650f75379624f9d1b762a04d5afaf342d5f8469) --- src/tm_mad/ceph/mv | 107 ++++++++++++++++++++++++++++++++++++++++++- src/tm_mad/fs_lvm/mv | 9 +++- 2 files changed, 114 insertions(+), 2 deletions(-) mode change 120000 => 100755 src/tm_mad/ceph/mv diff --git a/src/tm_mad/ceph/mv b/src/tm_mad/ceph/mv deleted file mode 120000 index b940b651ae..0000000000 --- a/src/tm_mad/ceph/mv +++ /dev/null @@ -1 +0,0 @@ -../ssh/mv \ No newline at end of file diff --git a/src/tm_mad/ceph/mv b/src/tm_mad/ceph/mv new file mode 100755 index 0000000000..367e5fb399 --- /dev/null +++ b/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 vmid dsid +# +# - 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 </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 <