diff --git a/install.sh b/install.sh index 352ba81fc5..bcb5e07f8e 100755 --- a/install.sh +++ b/install.sh @@ -940,7 +940,8 @@ TM_SHARED_FILES="src/tm_mad/shared/clone \ src/tm_mad/shared/cpds \ src/tm_mad/shared/resize" -TM_FS_LVM_FILES="src/tm_mad/fs_lvm/clone \ +TM_FS_LVM_FILES="src/tm_mad/fs_lvm/activate \ + src/tm_mad/fs_lvm/clone \ src/tm_mad/fs_lvm/context \ src/tm_mad/fs_lvm/ln \ src/tm_mad/fs_lvm/monitor \ diff --git a/share/etc/cron.d/opennebula-node b/share/etc/cron.d/opennebula-node new file mode 100644 index 0000000000..d7163c52ee --- /dev/null +++ b/share/etc/cron.d/opennebula-node @@ -0,0 +1,4 @@ +SHELL=/bin/bash + +# activate LVM volumes on reboot +@reboot oneadmin test -x /var/tmp/one/tm/fs_lvm/activate && /var/tmp/one/tm/fs_lvm/activate >/dev/null 2>&1 diff --git a/src/tm_mad/fs_lvm/activate b/src/tm_mad/fs_lvm/activate new file mode 100755 index 0000000000..6b5f113fbd --- /dev/null +++ b/src/tm_mad/fs_lvm/activate @@ -0,0 +1,74 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2018, 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. # +#--------------------------------------------------------------------------- # + +# This script is used for one-shot LVM volumes activation +# in case of virtualization host reboot. + +TIMEOUT=${TIMEOUT:-90} # wait time for VG one to be ready +HOSTNAME=$(hostname -f) + +if [ -z "${ONE_LOCATION}" ]; then + DATASTORES=${DATASTORES:-/var/lib/one/datastores} +else + DATASTORES=${DATASTORES:-${ONE_LOCATION}/var/datastores} +fi + +# check for LVM utils +PATH="${PATH}:/sbin:/bin:/usr/sbin:/usr/bin" which vgdisplay >/dev/null 2>&1 +if [ $? -ne 0 ]; then + exit 0 +fi + +# wait for any VG named vg-one- +while true; do + sudo -n lvscan >/dev/null 2>&1 + if sudo -n vgdisplay -C 2>/dev/null | grep -q vg-one-; then + break + fi + + TIMEOUT=$((TIMEOUT - 30)) + + if [ ${TIMEOUT} -ge 0 ]; then + sleep 30 + else + exit 1 + fi +done + +# list directories of the virtual machines originally running on this host +DIRS=$(find -L "${DATASTORES}" \ + -name .host \ + -type f \ + -exec grep -lxF "${HOSTNAME}" {} \; \ + | xargs dirname) + +for DIR in ${DIRS}; do + for DISK in $(ls "${DIR}/disk."*); do + DEVICE=$(readlink "${DISK}" 2>/dev/null) + + # disk symlink resolves and target file/device doesn't + # exist yet, but lvs knows about it -> activate + if [ -n "${DEVICE}" ] && ! [ -e "${DEVICE}" ]; then + if sudo -n lvs "${DEVICE}" >/dev/null 2>&1; then + sudo -n lvchange -ay "${DEVICE}" >/dev/null 2>&1 + fi + fi + done +done + +exit 0 diff --git a/src/tm_mad/fs_lvm/clone b/src/tm_mad/fs_lvm/clone index 0a22ad28f0..9a4b32ba0b 100755 --- a/src/tm_mad/fs_lvm/clone +++ b/src/tm_mad/fs_lvm/clone @@ -107,6 +107,8 @@ CLONE_CMD=$(cat <"${DST_DIR}/.host" || : + $QEMU_IMG convert -O raw "$SRC_PATH" "$DEV" rm -f "$DST_PATH" ln -s "$DEV" "$DST_PATH" diff --git a/src/tm_mad/fs_lvm/mv b/src/tm_mad/fs_lvm/mv index 6f94aeca2e..43b79df7fc 100755 --- a/src/tm_mad/fs_lvm/mv +++ b/src/tm_mad/fs_lvm/mv @@ -61,6 +61,8 @@ if [ `is_disk $DST_PATH` -eq 1 ]; then $SUDO $LVSCAN $SUDO $LVCHANGE -ay \$DEVICE fi + + hostname -f >"${DST_DIR}/.host" || : EOF ) ssh_exec_and_log "$DST_HOST" "$CMD" \ diff --git a/src/tm_mad/fs_lvm/postmigrate b/src/tm_mad/fs_lvm/postmigrate index d151cf3025..18894385fa 100755 --- a/src/tm_mad/fs_lvm/postmigrate +++ b/src/tm_mad/fs_lvm/postmigrate @@ -60,4 +60,8 @@ EOF ssh_exec_and_log $SRC_HOST "$CMD" \ "Error running fs_lvm postmigrate" +ssh_exec_and_log "${DST_HOST}" \ + "hostname -f >\"${DST_PATH}/.host\" || :" + "Error modifying .host after fs_lvm postmigrate" + migrate_other "$@"