1414
1515# CINDER_CONF
1616# DATA_DIR
17+ # VOLUME_GROUP_NAME
1718
1819# clean_cinder_backend_lvm - called from clean_cinder()
1920# configure_cinder_backend_lvm - called from configure_cinder()
@@ -25,157 +26,44 @@ MY_XTRACE=$(set +o | grep xtrace)
2526set +o xtrace
2627
2728
28- # Defaults
29- # --------
30-
31- # Name of the lvm volume groups to use/create for iscsi volumes
32- # This monkey-motion is for compatibility with icehouse-generation Grenade
33- # If ``VOLUME_GROUP`` is set, use it, otherwise we'll build a VG name based
34- # on ``VOLUME_GROUP_NAME`` that includes the backend name
35- # Grenade doesn't use ``VOLUME_GROUP2`` so it is left out
36- VOLUME_GROUP=${VOLUME_GROUP:- }
37- VOLUME_GROUP_NAME=${VOLUME_GROUP:- ${VOLUME_GROUP_NAME:- stack-volumes} }
38-
3929# TODO: resurrect backing device...need to know how to set values
4030# VOLUME_BACKING_DEVICE=${VOLUME_BACKING_DEVICE:-}
4131
42- VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:- volume-}
43-
44-
4532# Entry Points
4633# ------------
4734
48- # Compatibility for getting a volume group name from either ``VOLUME_GROUP``
49- # or from ``VOLUME_GROUP_NAME`` plus the backend name
50- function get_volume_group_name {
51- local be_name=$1
52-
53- # Again with the icehouse-generation compatibility
54- local volume_group_name=$VOLUME_GROUP_NAME
55- if [[ -z $VOLUME_GROUP ]]; then
56- volume_group_name+=" -$be_name "
57- fi
58- echo $volume_group_name
59- }
60-
35+ # cleanup_cinder_backend_lvm - Delete volume group and remove backing file
36+ # cleanup_cinder_backend_lvm $be_name
6137function cleanup_cinder_backend_lvm {
6238 local be_name=$1
6339
64- # Again with the icehouse-generation compatibility
65- local volume_group_name=$( get_volume_group_name $be_name )
66-
6740 # Campsite rule: leave behind a volume group at least as clean as we found it
68- _clean_lvm_lv ${volume_group_name} $VOLUME_NAME_PREFIX
69- _clean_lvm_backing_file ${volume_group_name} $DATA_DIR /${volume_group_name} -backing-file
41+ clean_lvm_volume_group $VOLUME_GROUP_NAME -$be_name
7042}
7143
7244# configure_cinder_backend_lvm - Set config files, create data dirs, etc
73- # configure_cinder_backend_lvm $name
45+ # configure_cinder_backend_lvm $be_name
7446function configure_cinder_backend_lvm {
7547 local be_name=$1
7648
77- # Again with the icehouse-generation compatibility
78- local volume_group_name=$( get_volume_group_name $be_name )
79-
8049 iniset $CINDER_CONF $be_name volume_backend_name $be_name
8150 iniset $CINDER_CONF $be_name volume_driver " cinder.volume.drivers.lvm.LVMISCSIDriver"
82- iniset $CINDER_CONF $be_name volume_group $volume_group_name
51+ iniset $CINDER_CONF $be_name volume_group $VOLUME_GROUP_NAME - $be_name
8352
8453 if [[ " $CINDER_SECURE_DELETE " == " False" ]]; then
8554 iniset $CINDER_CONF $be_name volume_clear none
8655 fi
8756}
8857
89-
58+ # init_cinder_backend_lvm - Initialize volume group
59+ # init_cinder_backend_lvm $be_name
9060function init_cinder_backend_lvm {
9161 local be_name=$1
9262
93- # Again with the icehouse-generation compatibility
94- local volume_group_name=$( get_volume_group_name $be_name )
95-
9663 # Start with a clean volume group
97- _create_cinder_volume_group ${volume_group_name} $DATA_DIR /${volume_group_name} -backing-file
98-
99- if is_fedora || is_suse; then
100- # service is not started by default
101- start_service tgtd
102- fi
103-
104- # Remove iscsi targets
105- sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
106- _clean_lvm_lv ${volume_group_name} $VOLUME_NAME_PREFIX
107- }
108-
109-
110- # _clean_lvm_lv removes all cinder LVM volumes
111- #
112- # Usage: _clean_lvm_lv volume-group-name $VOLUME_NAME_PREFIX
113- function _clean_lvm_lv {
114- local vg=$1
115- local lv_prefix=$2
116-
117- # Clean out existing volumes
118- local lv
119- for lv in $( sudo lvs --noheadings -o lv_name $vg 2> /dev/null) ; do
120- # lv_prefix prefixes the LVs we want
121- if [[ " ${lv# $lv_prefix } " != " $lv " ]]; then
122- sudo lvremove -f $vg /$lv
123- fi
124- done
125- }
126-
127- # _clean_lvm_backing_file() removes the backing file of the
128- # volume group used by cinder
129- #
130- # Usage: _clean_lvm_backing_file() volume-group-name backing-file-name
131- function _clean_lvm_backing_file {
132- local vg=$1
133- local backing_file=$2
134-
135- # if there is no logical volume left, it's safe to attempt a cleanup
136- # of the backing file
137- if [[ -z " $( sudo lvs --noheadings -o lv_name $vg 2> /dev/null) " ]]; then
138- # if the backing physical device is a loop device, it was probably setup by devstack
139- local vg_dev=$( sudo losetup -j $backing_file | awk -F' :' ' /backing-file/ { print $1}' )
140- if [[ -n " $vg_dev " ]] && [[ -e " $vg_dev " ]]; then
141- sudo losetup -d $vg_dev
142- rm -f $backing_file
143- fi
144- fi
64+ init_lvm_volume_group $VOLUME_GROUP_NAME -$be_name $VOLUME_BACKING_FILE_SIZE
14565}
14666
147- # _create_cinder_volume_group volume-group-name backing-file-name
148- function _create_cinder_volume_group {
149- # According to the ``CINDER_MULTI_LVM_BACKEND`` value, configure one or two default volumes
150- # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume
151- # service if it (they) does (do) not yet exist. If you don't wish to use a
152- # file backed volume group, create your own volume group called ``stack-volumes``
153- # and ``stack-volumes2`` before invoking ``stack.sh``.
154- #
155- # The two backing files are ``VOLUME_BACKING_FILE_SIZE`` in size, and they are stored in
156- # the ``DATA_DIR``.
157-
158- local vg_name=$1
159- local backing_file=$2
160-
161- if ! sudo vgs $vg_name ; then
162- # TODO: fix device handling
163- if [ -z " $VOLUME_BACKING_DEVICE " ]; then
164- # Only create if the file doesn't already exists
165- [[ -f $backing_file ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $backing_file
166- local vg_dev=` sudo losetup -f --show $backing_file `
167-
168- # Only create if the loopback device doesn't contain $VOLUME_GROUP
169- if ! sudo vgs $vg_name ; then
170- sudo vgcreate $vg_name $vg_dev
171- fi
172- else
173- sudo vgcreate $vg_name $VOLUME_BACKING_DEVICE
174- fi
175- fi
176- }
177-
178-
17967# Restore xtrace
18068$MY_XTRACE
18169
0 commit comments