From 6766f71d62af10f8b59b5f829a49752775e9dabe Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Fri, 24 Jul 2020 15:44:34 -0700 Subject: [PATCH] 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 --- clean.sh | 2 ++ functions | 34 +++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/clean.sh b/clean.sh index cb0a8b4bef..4cebf1d9ea 100755 --- a/clean.sh +++ b/clean.sh @@ -145,3 +145,5 @@ done rm -rf ~/.config/openstack +# Clear any fstab entries made +sudo sed -i '/.*comment=devstack-.*/ d' /etc/fstab diff --git a/functions b/functions index cc1ca6cb25..e679b0f9bc 100644 --- a/functions +++ b/functions @@ -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 }