1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-26 06:50:09 +03:00

B #1152: Activate LVM disks on reboot

This commit is contained in:
Vlastimil Holer 2018-01-31 16:54:50 +01:00 committed by Ruben S. Montero
parent 0c0aebd440
commit 17d5b31cb2
6 changed files with 88 additions and 1 deletions

View File

@ -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 \

View File

@ -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

74
src/tm_mad/fs_lvm/activate Executable file
View File

@ -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

View File

@ -107,6 +107,8 @@ CLONE_CMD=$(cat <<EOF
set -e -o pipefail
mkdir -p $DST_DIR
hostname -f >"${DST_DIR}/.host" || :
$QEMU_IMG convert -O raw "$SRC_PATH" "$DEV"
rm -f "$DST_PATH"
ln -s "$DEV" "$DST_PATH"

View File

@ -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" \

View File

@ -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 "$@"