Clean up create_disk() a little
The create_disk() helper had some redundant checks and dead code. This refactors it to put all the stale cleanup at the top, and groups the new actions together with more relevant comments to make it easier to understand. Change-Id: I1f6218a1994e66786ed9a8065e30bcceec7b8956
This commit is contained in:
parent
aef50ed18c
commit
36a575b036
33
functions
33
functions
@ -759,16 +759,14 @@ function create_disk {
|
||||
local loopback_disk_size=${3}
|
||||
local key
|
||||
|
||||
# Create a loopback disk and format it to XFS.
|
||||
if [[ -e ${disk_image} ]]; then
|
||||
if egrep -q ${storage_data_dir} /proc/mounts; then
|
||||
sudo umount ${storage_data_dir}
|
||||
sudo rm -f ${disk_image}
|
||||
fi
|
||||
fi
|
||||
key=$(echo $disk_image | sed 's#/.##')
|
||||
key="devstack-$key"
|
||||
|
||||
sudo mkdir -p ${storage_data_dir}/drives/images
|
||||
destroy_disk $disk_image $storage_data_dir
|
||||
|
||||
# Create an empty file of the correct size (and ensure the
|
||||
# directory structure up to that path exists)
|
||||
sudo mkdir -p $(dirname ${disk_image})
|
||||
sudo truncate -s ${loopback_disk_size} ${disk_image}
|
||||
|
||||
# Make a fresh XFS filesystem. Use bigger inodes so xattr can fit in
|
||||
@ -778,16 +776,9 @@ function create_disk {
|
||||
# Swift and Ceph.
|
||||
sudo mkfs.xfs -f -i size=1024 ${disk_image}
|
||||
|
||||
# Unmount the target, if mounted
|
||||
if egrep -q $storage_data_dir /proc/mounts; then
|
||||
sudo umount $storage_data_dir
|
||||
fi
|
||||
|
||||
# Clear any old fstab rules, install a new one for this disk, and mount it
|
||||
key=$(echo $disk_image | sed 's#/.##')
|
||||
key="devstack-$key"
|
||||
sudo sed -i '/.*comment=$key.*/ d' /etc/fstab
|
||||
# Install a new loopback fstab entry for this disk image, and mount it
|
||||
echo "$disk_image $storage_data_dir xfs loop,noatime,nodiratime,logbufs=8,comment=$key 0 0" | sudo tee -a /etc/fstab
|
||||
sudo mkdir -p $storage_data_dir
|
||||
sudo mount -v $storage_data_dir
|
||||
}
|
||||
|
||||
@ -795,6 +786,10 @@ function create_disk {
|
||||
function destroy_disk {
|
||||
local disk_image=$1
|
||||
local storage_data_dir=$2
|
||||
local key
|
||||
|
||||
key=$(echo $disk_image | sed 's#/.##')
|
||||
key="devstack-$key"
|
||||
|
||||
# Unmount the target, if mounted
|
||||
if egrep -q $storage_data_dir /proc/mounts; then
|
||||
@ -802,10 +797,10 @@ function destroy_disk {
|
||||
fi
|
||||
|
||||
# Clear any fstab rules
|
||||
sed -i '/.*comment=$key.*/ d' /etc/fstab
|
||||
sudo sed -i '/.*comment=$key.*/ d' /etc/fstab
|
||||
|
||||
# Delete the file
|
||||
sudo rm $disk_image
|
||||
sudo rm -f $disk_image
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user