forked from affo/devstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlvm
More file actions
143 lines (114 loc) · 4.05 KB
/
lvm
File metadata and controls
143 lines (114 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# 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 with a clean volume group
_create_lvm_volume_group $vg $size
if is_fedora || is_suse; then
# service is not started by default
start_service tgtd
fi
# 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
}
# Restore xtrace
$MY_XTRACE
# mode: shell-script
# End: