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
diff --git a/functions b/functions
index cc1ca6c..e679b0f 100644
--- a/functions
+++ b/functions
@@ -751,12 +751,13 @@
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 @@
# 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
}