blob: 52fc6fbf63b05bda6111f04777b046f27e32d1f0 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Dean Troyer09718332014-07-03 10:46:57 -05003# lib/cinder_backends/lvm
4# Configure the LVM backend
5
6# Enable with:
7#
8# CINDER_ENABLED_BACKENDS+=,lvm:lvmname
9
10# Dependencies:
11#
12# - ``functions`` file
13# - ``cinder`` configurations
14
15# CINDER_CONF
16# DATA_DIR
Daniel Genind4708672014-10-31 15:01:29 -040017# VOLUME_GROUP_NAME
Dean Troyer09718332014-07-03 10:46:57 -050018
19# clean_cinder_backend_lvm - called from clean_cinder()
20# configure_cinder_backend_lvm - called from configure_cinder()
21# init_cinder_backend_lvm - called from init_cinder()
John Griffith0b9e76f2015-01-21 13:46:59 -070022# configure_cinder_backend_conf_lvm - called from configure_cinder()
Dean Troyer09718332014-07-03 10:46:57 -050023
24
25# Save trace setting
26MY_XTRACE=$(set +o | grep xtrace)
27set +o xtrace
28
29
Dean Troyer09718332014-07-03 10:46:57 -050030# TODO: resurrect backing device...need to know how to set values
31#VOLUME_BACKING_DEVICE=${VOLUME_BACKING_DEVICE:-}
32
Dean Troyer09718332014-07-03 10:46:57 -050033# Entry Points
34# ------------
35
Daniel Genind4708672014-10-31 15:01:29 -040036# cleanup_cinder_backend_lvm - Delete volume group and remove backing file
37# cleanup_cinder_backend_lvm $be_name
Dean Troyer09718332014-07-03 10:46:57 -050038function cleanup_cinder_backend_lvm {
39 local be_name=$1
40
Dean Troyer09718332014-07-03 10:46:57 -050041 # Campsite rule: leave behind a volume group at least as clean as we found it
Daniel Genind4708672014-10-31 15:01:29 -040042 clean_lvm_volume_group $VOLUME_GROUP_NAME-$be_name
Dean Troyer09718332014-07-03 10:46:57 -050043}
44
45# configure_cinder_backend_lvm - Set config files, create data dirs, etc
Daniel Genind4708672014-10-31 15:01:29 -040046# configure_cinder_backend_lvm $be_name
Dean Troyer09718332014-07-03 10:46:57 -050047function configure_cinder_backend_lvm {
48 local be_name=$1
49
Dean Troyer09718332014-07-03 10:46:57 -050050 iniset $CINDER_CONF $be_name volume_backend_name $be_name
Mike Pereza0126b62015-01-22 08:25:59 -080051 iniset $CINDER_CONF $be_name volume_driver "cinder.volume.drivers.lvm.LVMVolumeDriver"
Daniel Genind4708672014-10-31 15:01:29 -040052 iniset $CINDER_CONF $be_name volume_group $VOLUME_GROUP_NAME-$be_name
Mike Pereza0126b62015-01-22 08:25:59 -080053 iniset $CINDER_CONF $be_name iscsi_helper "tgtadm"
Dean Troyer09718332014-07-03 10:46:57 -050054
55 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
56 iniset $CINDER_CONF $be_name volume_clear none
57 fi
58}
59
Daniel Genind4708672014-10-31 15:01:29 -040060# init_cinder_backend_lvm - Initialize volume group
61# init_cinder_backend_lvm $be_name
Dean Troyer09718332014-07-03 10:46:57 -050062function init_cinder_backend_lvm {
63 local be_name=$1
64
Dean Troyer09718332014-07-03 10:46:57 -050065 # Start with a clean volume group
Daniel Genind4708672014-10-31 15:01:29 -040066 init_lvm_volume_group $VOLUME_GROUP_NAME-$be_name $VOLUME_BACKING_FILE_SIZE
Dean Troyer09718332014-07-03 10:46:57 -050067}
68
John Griffith0b9e76f2015-01-21 13:46:59 -070069# configure_cinder_backend_conf_lvm - Sets device filter in /etc/cinder/lvm.conf
70# init_cinder_backend_lvm
71function configure_cinder_backend_conf_lvm {
72 local filter_suffix='"r/.*/" ]'
73 local filter_string="filter = [ "
74 local conf_entries=$(grep volume_group /etc/cinder/cinder.conf | sed "s/ //g")
75 local pv
76 local vg
77 local line
78
79 for pv_info in $(sudo pvs --noheadings -o name,vg_name --separator ';'); do
John Griffithc3c94ca2015-02-11 18:55:47 -070080 echo_summary "Evaluate PV info for Cinder lvm.conf: $pv_info"
Andreas Scheuring15d40a52015-02-26 09:08:09 +010081 IFS=';' read pv vg <<< "$pv_info"
John Griffith0b9e76f2015-01-21 13:46:59 -070082 for line in ${conf_entries}; do
Andreas Scheuring15d40a52015-02-26 09:08:09 +010083 IFS='=' read label group <<< "$line"
John Griffith0b9e76f2015-01-21 13:46:59 -070084 group=$(echo $group|sed "s/^ *//g")
85 if [[ "$vg" == "$group" ]]; then
86 new="\"a$pv/\", "
87 filter_string=$filter_string$new
88 fi
89 done
90 done
91 filter_string=$filter_string$filter_suffix
92
93 # FIXME(jdg): Possible odd case that the lvm.conf file has been modified
94 # and doesn't have a filter entry to search/replace. For devstack don't
95 # know that we care, but could consider adding a check and add
96 sudo sed -i "s#^[ \t]*filter.*# $filter_string#g" /etc/cinder/lvm.conf
97 echo "set LVM filter_strings: $filter_string"
98}
Dean Troyer09718332014-07-03 10:46:57 -050099# Restore xtrace
100$MY_XTRACE
101
102# mode: shell-script
103# End: