diff --git a/lib/cinder b/lib/cinder index 880af1fd40..958c7f05ac 100644 --- a/lib/cinder +++ b/lib/cinder @@ -372,15 +372,9 @@ function init_cinder { if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then local be be_name be_type - local has_lvm=0 for be in ${CINDER_ENABLED_BACKENDS//,/ }; do be_type=${be%%:*} be_name=${be##*:} - - if [[ $be_type == 'lvm' ]]; then - has_lvm=1 - fi - if type init_cinder_backend_${be_type} >/dev/null 2>&1; then # Always init the default volume group for lvm. if [[ "$be_type" == "lvm" ]]; then @@ -391,17 +385,6 @@ function init_cinder { done fi - # Keep it simple, set a marker if there's an LVM backend - # use the created VG's to setup lvm filters - if [[ $has_lvm == 1 ]]; then - # Order matters here, not only obviously to make - # sure the VG's are created, but also some distros - # do some customizations to lvm.conf on init, we - # want to make sure we copy those over - sudo cp /etc/lvm/lvm.conf /etc/cinder/lvm.conf - configure_cinder_backend_conf_lvm - fi - mkdir -p $CINDER_STATE_PATH/volumes create_cinder_cache_dir } diff --git a/lib/cinder_backends/lvm b/lib/cinder_backends/lvm index 52fc6fbf63..f210578339 100644 --- a/lib/cinder_backends/lvm +++ b/lib/cinder_backends/lvm @@ -19,7 +19,6 @@ # clean_cinder_backend_lvm - called from clean_cinder() # configure_cinder_backend_lvm - called from configure_cinder() # init_cinder_backend_lvm - called from init_cinder() -# configure_cinder_backend_conf_lvm - called from configure_cinder() # Save trace setting @@ -66,36 +65,6 @@ function init_cinder_backend_lvm { init_lvm_volume_group $VOLUME_GROUP_NAME-$be_name $VOLUME_BACKING_FILE_SIZE } -# configure_cinder_backend_conf_lvm - Sets device filter in /etc/cinder/lvm.conf -# init_cinder_backend_lvm -function configure_cinder_backend_conf_lvm { - local filter_suffix='"r/.*/" ]' - local filter_string="filter = [ " - local conf_entries=$(grep volume_group /etc/cinder/cinder.conf | sed "s/ //g") - local pv - local vg - local line - - for pv_info in $(sudo pvs --noheadings -o name,vg_name --separator ';'); do - echo_summary "Evaluate PV info for Cinder lvm.conf: $pv_info" - IFS=';' read pv vg <<< "$pv_info" - for line in ${conf_entries}; do - IFS='=' read label group <<< "$line" - group=$(echo $group|sed "s/^ *//g") - if [[ "$vg" == "$group" ]]; then - new="\"a$pv/\", " - filter_string=$filter_string$new - fi - done - done - filter_string=$filter_string$filter_suffix - - # FIXME(jdg): Possible odd case that the lvm.conf file has been modified - # and doesn't have a filter entry to search/replace. For devstack don't - # know that we care, but could consider adding a check and add - sudo sed -i "s#^[ \t]*filter.*# $filter_string#g" /etc/cinder/lvm.conf - echo "set LVM filter_strings: $filter_string" -} # Restore xtrace $MY_XTRACE diff --git a/lib/lvm b/lib/lvm index 39eed00675..d0322c76b3 100644 --- a/lib/lvm +++ b/lib/lvm @@ -138,6 +138,31 @@ function init_default_lvm_volume_group { 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 diff --git a/stack.sh b/stack.sh index eac7eec724..ee1b985eab 100755 --- a/stack.sh +++ b/stack.sh @@ -1316,6 +1316,15 @@ service_check # Prepare bash completion for OSC openstack complete | sudo tee /etc/bash_completion.d/osc.bash_completion > /dev/null +# If cinder is configured, set global_filter for PV devices +if is_service_enabled cinder; then + if is_ubuntu; then + echo_summary "Configuring lvm.conf global device filter" + set_lvm_filter + else + echo_summary "Skip setting lvm filters for non Ubuntu systems" + fi +fi # Fin # ===