4bf861c76c
A while back I added an lvm.conf file with a device filter setting to try and clean up the LVM hangs in the gate: (commit 0b9e76f280208b5b5ad54bb6fbc4133e63037286) It turns out this wasn't the real problem, the real problem is that on an LVS/VGS command LVM will attempt to open and read all potential block devices in /dev to see if they have LVM data on them. I initially thought the local filter would keep that from happening, as it turns out the local filter only limits what's returned AFTER the actual scan process. In order to keep the scan from happening at all, either a global_filter needs to be used or lvmetad needs to be running and enabled. There are situations in gate tests where /dev/sdX devices are created and deleted and the result is that we hit situations where LVM tries to open up devices to check them even if they've been removed. The result is we have a blocking open call from LVM that takes approx 60 seconds to time out and fail. Ubuntu won't have a version of lvmetad until Vivid, so for now that just leaves the global_filter as an option. This patch adds the filter routine to the end of stack.sh. We don't want to put the routine in lib/cinder_backend/lvm like we had it because now we have to set the global filter for all LVM commands on the system. So we put this as one of the last steps in stack.sh and run it if Cinder is enabled. This way we can query PV's on the system regardless of what other services may be running and using LVM and make sure that all of their devices are added to the filter as well. Also, make sure we only set this for Ubuntu as Fedora/RHEL variants utilize lvmetad. This patch also removes the old change that set the local filter. DocImpact Should add this to recommended config for Cinder on systems that don't have lvmetad, and recommend lvmetad for those that do. Change-Id: I5d5c48e188cbb9b4208096736807f082bce524e8 Closes-Bug: #1373513
172 lines
5.0 KiB
Plaintext
172 lines
5.0 KiB
Plaintext
# lib/lvm
|
|
# Configure the default LVM volume group used by Cinder and Nova
|
|
|
|
# Dependencies:
|
|
#
|
|
# - ``functions`` file
|
|
# - ``cinder`` configurations
|
|
|
|
# DATA_DIR
|
|
|
|
# clean_default_volume_group - called from clean()
|
|
# configure_default_volume_group - called from configure()
|
|
# init_default_volume_group - called from init()
|
|
|
|
|
|
# Save trace setting
|
|
MY_XTRACE=$(set +o | grep xtrace)
|
|
set +o xtrace
|
|
|
|
|
|
# Defaults
|
|
# --------
|
|
# Name of the lvm volume groups to use/create for iscsi volumes
|
|
# This monkey-motion is for compatibility with icehouse-generation Grenade
|
|
# If ``VOLUME_GROUP`` is set, use it, otherwise we'll build a VG name based
|
|
# on ``VOLUME_GROUP_NAME`` that includes the backend name
|
|
# Grenade doesn't use ``VOLUME_GROUP2`` so it is left out
|
|
VOLUME_GROUP_NAME=${VOLUME_GROUP:-${VOLUME_GROUP_NAME:-stack-volumes}}
|
|
DEFAULT_VOLUME_GROUP_NAME=$VOLUME_GROUP_NAME-default
|
|
|
|
# Backing file name is of the form $VOLUME_GROUP$BACKING_FILE_SUFFIX
|
|
BACKING_FILE_SUFFIX=-backing-file
|
|
|
|
|
|
# Entry Points
|
|
# ------------
|
|
|
|
# _clean_lvm_volume_group removes all default LVM volumes
|
|
#
|
|
# Usage: clean_lvm_volume_group $vg
|
|
function _clean_lvm_volume_group {
|
|
local vg=$1
|
|
|
|
# Clean out existing volumes
|
|
sudo lvremove -f $vg
|
|
}
|
|
|
|
# _clean_lvm_backing_file() removes the backing file of the
|
|
# volume group
|
|
#
|
|
# Usage: _clean_lvm_backing_file() $backing_file
|
|
function _clean_lvm_backing_file {
|
|
local backing_file=$1
|
|
|
|
# if the backing physical device is a loop device, it was probably setup by devstack
|
|
if [[ -n "$backing_file" ]] && [[ -e "$backing_file" ]]; then
|
|
local vg_dev=$(sudo losetup -j $backing_file | awk -F':' '/'$BACKING_FILE_SUFFIX'/ { print $1}')
|
|
sudo losetup -d $vg_dev
|
|
rm -f $backing_file
|
|
fi
|
|
}
|
|
|
|
# clean_lvm_volume_group() cleans up the volume group and removes the
|
|
# backing file
|
|
#
|
|
# Usage: clean_lvm_volume_group $vg
|
|
function clean_lvm_volume_group {
|
|
local vg=$1
|
|
|
|
_clean_lvm_volume_group $vg
|
|
# 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 2>/dev/null)" ]]; then
|
|
_clean_lvm_backing_file $DATA_DIR/$vg$BACKING_FILE_SUFFIX
|
|
fi
|
|
}
|
|
|
|
|
|
# _create_volume_group creates default volume group
|
|
#
|
|
# Usage: _create_lvm_volume_group() $vg $size
|
|
function _create_lvm_volume_group {
|
|
local vg=$1
|
|
local size=$2
|
|
|
|
local backing_file=$DATA_DIR/$vg$BACKING_FILE_SUFFIX
|
|
if ! sudo vgs $vg; then
|
|
# Only create if the file doesn't already exists
|
|
[[ -f $backing_file ]] || truncate -s $size $backing_file
|
|
local vg_dev=`sudo losetup -f --show $backing_file`
|
|
|
|
# Only create volume group if it doesn't already exist
|
|
if ! sudo vgs $vg; then
|
|
sudo vgcreate $vg $vg_dev
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# init_lvm_volume_group() initializes the volume group creating the backing
|
|
# file if necessary
|
|
#
|
|
# Usage: init_lvm_volume_group() $vg
|
|
function init_lvm_volume_group {
|
|
local vg=$1
|
|
local size=$2
|
|
|
|
# Start the lvmetad and tgtd services
|
|
if is_fedora || is_suse; then
|
|
# services is not started by default
|
|
start_service lvm2-lvmetad
|
|
start_service tgtd
|
|
fi
|
|
|
|
# Start with a clean volume group
|
|
_create_lvm_volume_group $vg $size
|
|
|
|
# Remove iscsi targets
|
|
sudo tgtadm --op show --mode target | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
|
|
|
|
_clean_lvm_volume_group $vg
|
|
}
|
|
|
|
# Sentinal value to ensure that init of default lvm volume group is
|
|
# only performed once across calls of init_default_lvm_volume_group.
|
|
_DEFAULT_LVM_INIT=${_DEFAULT_LVM_INIT:-0}
|
|
|
|
# init_default_lvm_volume_group() initializes a default volume group
|
|
# intended to be shared between cinder and nova. It is idempotent;
|
|
# the init of the default volume group is guaranteed to be performed
|
|
# only once so that either or both of the dependent services can
|
|
# safely call this function.
|
|
#
|
|
# Usage: init_default_lvm_volume_group()
|
|
function init_default_lvm_volume_group {
|
|
if [[ "$_DEFAULT_LVM_INIT" = "0" ]]; then
|
|
init_lvm_volume_group $DEFAULT_VOLUME_GROUP_NAME $VOLUME_BACKING_FILE_SIZE
|
|
_DEFAULT_LVM_INIT=1
|
|
fi
|
|
}
|
|
|
|
# set_lvm_filter() Gather all devices configured for LVM and
|
|
# use them to build a global device filter
|
|
# set_lvm_filter() Create a device filter
|
|
# and add to /etc/lvm.conf. Note this uses
|
|
# all current PV's in use by LVM on the
|
|
# system to build it's filter.
|
|
#
|
|
# Usage: set_lvm_filter()
|
|
function set_lvm_filter {
|
|
local filter_suffix='"r|.*|" ]'
|
|
local filter_string="global_filter = [ "
|
|
local pv
|
|
local vg
|
|
local line
|
|
|
|
for pv_info in $(sudo pvs --noheadings -o name); do
|
|
pv=$(echo -e "${pv_info}" | sed 's/ //g' | sed 's/\/dev\///g')
|
|
new="\"a|$pv|\", "
|
|
filter_string=$filter_string$new
|
|
done
|
|
filter_string=$filter_string$filter_suffix
|
|
|
|
sudo sed -i "/# global_filter = \[*\]/a\ $global_filter$filter_string" /etc/lvm/lvm.conf
|
|
echo_summary "set lvm.conf device global_filter to: $filter_string"
|
|
}
|
|
|
|
# Restore xtrace
|
|
$MY_XTRACE
|
|
|
|
# mode: shell-script
|
|
# End:
|