diff --git a/functions b/functions index e679b0f9bc..fc87a5512d 100644 --- a/functions +++ b/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 }