Merge "On unstack, cleanup LVM setup for Cinder"

This commit is contained in:
Jenkins 2013-06-19 11:08:09 +00:00 committed by Gerrit Code Review
commit 222dad34cf
2 changed files with 28 additions and 15 deletions

View File

@ -63,7 +63,7 @@ cleanup_nova
cleanup_quantum cleanup_quantum
cleanup_swift cleanup_swift
# cinder doesn't clean up the volume group as it might be used elsewhere... # cinder doesn't always clean up the volume group as it might be used elsewhere...
# clean it up if it is a loop device # clean it up if it is a loop device
VG_DEV=$(sudo losetup -j $DATA_DIR/${VOLUME_GROUP}-backing-file | awk -F':' '/backing-file/ { print $1}') VG_DEV=$(sudo losetup -j $DATA_DIR/${VOLUME_GROUP}-backing-file | awk -F':' '/backing-file/ { print $1}')
if [[ -n "$VG_DEV" ]]; then if [[ -n "$VG_DEV" ]]; then

View File

@ -67,27 +67,43 @@ CINDER_SECURE_DELETE=`trueorfalse True $CINDER_SECURE_DELETE`
CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60} CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60}
# Name of the lvm volume groups to use/create for iscsi volumes # Name of the lvm volume groups to use/create for iscsi volumes
# VOLUME_GROUP2 is used only if CINDER_MULTI_LVM_BACKEND = True
VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes} VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
# VOLUME_GROUP2 is used only if CINDER_MULTI_LVM_BACKEND = True
VOLUME_GROUP2=${VOLUME_GROUP2:-stack-volumes2} VOLUME_GROUP2=${VOLUME_GROUP2:-stack-volumes2}
VOLUME_BACKING_FILE2=${VOLUME_BACKING_FILE2:-$DATA_DIR/${VOLUME_GROUP2}-backing-file}
VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-} VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
# Functions # Functions
# --------- # ---------
# _cleanup_lvm removes all cinder volumes and the backing file of the
# _clean_volume_group removes all cinder volumes from the specified volume group # volume group used by cinder
# _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX # _cleanup_lvm $VOLUME_GROUP $VOLUME_NAME_PREFIX
function _clean_volume_group() { function _cleanup_lvm() {
local vg=$1 local vg=$1
local vg_prefix=$2 local lv_prefix=$2
# Clean out existing volumes # Clean out existing volumes
for lv in `sudo lvs --noheadings -o lv_name $vg`; do for lv in `sudo lvs --noheadings -o lv_name $vg`; do
# vg_prefix prefixes the LVs we want # lv_prefix prefixes the LVs we want
if [[ "${lv#$vg_prefix}" != "$lv" ]]; then if [[ "${lv#$lv_prefix}" != "$lv" ]]; then
sudo lvremove -f $vg/$lv sudo lvremove -f $vg/$lv
fi fi
done done
# if there is no logical volume left, it's safe to attempt a cleanup
# of the backing file
if [ -z "`sudo lvs --noheadings -o lv_name $vg`" ]; then
# if the backing physical device is a loop device, it was probably setup by devstack
VG_DEV=$(sudo losetup -j $DATA_DIR/${vg}-backing-file | awk -F':' '/backing-file/ { print $1}')
if [[ -n "$VG_DEV" ]]; then
sudo losetup -d $VG_DEV
rm -f $DATA_DIR/${vg}-backing-file
fi
fi
} }
# cleanup_cinder() - Remove residual data files, anything left over from previous # cleanup_cinder() - Remove residual data files, anything left over from previous
@ -127,9 +143,10 @@ function cleanup_cinder() {
fi fi
# Campsite rule: leave behind a volume group at least as clean as we found it # Campsite rule: leave behind a volume group at least as clean as we found it
_clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX _cleanup_lvm $VOLUME_GROUP $VOLUME_NAME_PREFIX
if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
_clean_volume_group $VOLUME_GROUP2 $VOLUME_NAME_PREFIX _cleanup_lvm $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
fi fi
} }
@ -318,8 +335,6 @@ create_cinder_volume_group() {
# ``/opt/stack/data``. # ``/opt/stack/data``.
if ! sudo vgs $VOLUME_GROUP; then if ! sudo vgs $VOLUME_GROUP; then
VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
# Only create if the file doesn't already exists # Only create if the file doesn't already exists
[[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
@ -334,8 +349,6 @@ create_cinder_volume_group() {
#set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled #set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled
if ! sudo vgs $VOLUME_GROUP2; then if ! sudo vgs $VOLUME_GROUP2; then
VOLUME_BACKING_FILE2=${VOLUME_BACKING_FILE2:-$DATA_DIR/${VOLUME_GROUP2}-backing-file}
# Only create if the file doesn't already exists # Only create if the file doesn't already exists
[[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2 [[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2