Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 3 | # 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 Genin | d470867 | 2014-10-31 15:01:29 -0400 | [diff] [blame] | 17 | # VOLUME_GROUP_NAME |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 18 | |
| 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 Griffith | 0b9e76f | 2015-01-21 13:46:59 -0700 | [diff] [blame] | 22 | # configure_cinder_backend_conf_lvm - called from configure_cinder() |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 23 | |
| 24 | |
| 25 | # Save trace setting |
| 26 | MY_XTRACE=$(set +o | grep xtrace) |
| 27 | set +o xtrace |
| 28 | |
| 29 | |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 30 | # TODO: resurrect backing device...need to know how to set values |
| 31 | #VOLUME_BACKING_DEVICE=${VOLUME_BACKING_DEVICE:-} |
| 32 | |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 33 | # Entry Points |
| 34 | # ------------ |
| 35 | |
Daniel Genin | d470867 | 2014-10-31 15:01:29 -0400 | [diff] [blame] | 36 | # cleanup_cinder_backend_lvm - Delete volume group and remove backing file |
| 37 | # cleanup_cinder_backend_lvm $be_name |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 38 | function cleanup_cinder_backend_lvm { |
| 39 | local be_name=$1 |
| 40 | |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 41 | # Campsite rule: leave behind a volume group at least as clean as we found it |
Daniel Genin | d470867 | 2014-10-31 15:01:29 -0400 | [diff] [blame] | 42 | clean_lvm_volume_group $VOLUME_GROUP_NAME-$be_name |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | # configure_cinder_backend_lvm - Set config files, create data dirs, etc |
Daniel Genin | d470867 | 2014-10-31 15:01:29 -0400 | [diff] [blame] | 46 | # configure_cinder_backend_lvm $be_name |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 47 | function configure_cinder_backend_lvm { |
| 48 | local be_name=$1 |
| 49 | |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 50 | iniset $CINDER_CONF $be_name volume_backend_name $be_name |
Mike Perez | a0126b6 | 2015-01-22 08:25:59 -0800 | [diff] [blame] | 51 | iniset $CINDER_CONF $be_name volume_driver "cinder.volume.drivers.lvm.LVMVolumeDriver" |
Daniel Genin | d470867 | 2014-10-31 15:01:29 -0400 | [diff] [blame] | 52 | iniset $CINDER_CONF $be_name volume_group $VOLUME_GROUP_NAME-$be_name |
Mike Perez | a0126b6 | 2015-01-22 08:25:59 -0800 | [diff] [blame] | 53 | iniset $CINDER_CONF $be_name iscsi_helper "tgtadm" |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 54 | |
| 55 | if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then |
| 56 | iniset $CINDER_CONF $be_name volume_clear none |
| 57 | fi |
| 58 | } |
| 59 | |
Daniel Genin | d470867 | 2014-10-31 15:01:29 -0400 | [diff] [blame] | 60 | # init_cinder_backend_lvm - Initialize volume group |
| 61 | # init_cinder_backend_lvm $be_name |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 62 | function init_cinder_backend_lvm { |
| 63 | local be_name=$1 |
| 64 | |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 65 | # Start with a clean volume group |
Daniel Genin | d470867 | 2014-10-31 15:01:29 -0400 | [diff] [blame] | 66 | init_lvm_volume_group $VOLUME_GROUP_NAME-$be_name $VOLUME_BACKING_FILE_SIZE |
Dean Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 67 | } |
| 68 | |
John Griffith | 0b9e76f | 2015-01-21 13:46:59 -0700 | [diff] [blame] | 69 | # configure_cinder_backend_conf_lvm - Sets device filter in /etc/cinder/lvm.conf |
| 70 | # init_cinder_backend_lvm |
| 71 | function 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 Griffith | c3c94ca | 2015-02-11 18:55:47 -0700 | [diff] [blame^] | 80 | echo_summary "Evaluate PV info for Cinder lvm.conf: $pv_info" |
John Griffith | 0b9e76f | 2015-01-21 13:46:59 -0700 | [diff] [blame] | 81 | IFS=';' read pv vg <<< $pv_info |
| 82 | for line in ${conf_entries}; do |
| 83 | IFS='=' read label group <<< $line |
| 84 | 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 Troyer | 0971833 | 2014-07-03 10:46:57 -0500 | [diff] [blame] | 99 | # Restore xtrace |
| 100 | $MY_XTRACE |
| 101 | |
| 102 | # mode: shell-script |
| 103 | # End: |