Make create_disk() persistent

Right now a system configured with the ceph plugin will not survive
a reboot because the backing disk we create and mount isn't mounted
at startup, preventing ceph from starting and the rest of nova/glance
from working.

This makes create_disk() idempotently write an fstab rule for the
disk we make, and adds a destroy_disk() handler for cleanup.

Change-Id: I50cd4234f51a335af25be756bd2459dca5aa343c
This commit is contained in:
Dan Smith 2020-07-24 15:44:34 -07:00
parent 47f76acbba
commit 6766f71d62
2 changed files with 31 additions and 5 deletions

View File

@ -145,3 +145,5 @@ done
rm -rf ~/.config/openstack
# Clear any fstab entries made
sudo sed -i '/.*comment=devstack-.*/ d' /etc/fstab

View File

@ -751,12 +751,13 @@ if ! function_exists echo_nolog; then
fi
# create_disk - Create backing disk
# create_disk - Create, configure, and mount a backing disk
function create_disk {
local node_number
local disk_image=${1}
local storage_data_dir=${2}
local loopback_disk_size=${3}
local key
# Create a loopback disk and format it to XFS.
if [[ -e ${disk_image} ]]; then
@ -777,11 +778,34 @@ function create_disk {
# Swift and Ceph.
sudo mkfs.xfs -f -i size=1024 ${disk_image}
# Mount the disk with mount options to make it as efficient as possible
if ! egrep -q ${storage_data_dir} /proc/mounts; then
sudo mount -t xfs -o loop,noatime,nodiratime,logbufs=8 \
${disk_image} ${storage_data_dir}
# 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
echo "$disk_image $storage_data_dir xfs loop,noatime,nodiratime,logbufs=8,comment=$key 0 0" | sudo tee -a /etc/fstab
sudo mount -v $storage_data_dir
}
# Unmount, de-configure, and destroy a backing disk
function destroy_disk {
local disk_image=$1
local storage_data_dir=$2
# Unmount the target, if mounted
if egrep -q $storage_data_dir /proc/mounts; then
sudo umount $storage_data_dir
fi
# Clear any fstab rules
sed -i '/.*comment=$key.*/ d' /etc/fstab
# Delete the file
sudo rm $disk_image
}