Skip to content

Commit 36a575b

Browse files
committed
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
1 parent aef50ed commit 36a575b

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

‎functions‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -759,16 +759,14 @@ function create_disk {
759759
local loopback_disk_size=${3}
760760
local key
761761

762-
# Create a loopback disk and format it to XFS.
763-
if [[ -e ${disk_image} ]]; then
764-
if egrep -q ${storage_data_dir} /proc/mounts; then
765-
sudo umount ${storage_data_dir}
766-
sudo rm -f ${disk_image}
767-
fi
768-
fi
762+
key=$(echo $disk_image | sed 's#/.##')
763+
key="devstack-$key"
769764

770-
sudo mkdir -p ${storage_data_dir}/drives/images
765+
destroy_disk $disk_image $storage_data_dir
771766

767+
# Create an empty file of the correct size (and ensure the
768+
# directory structure up to that path exists)
769+
sudo mkdir -p $(dirname ${disk_image})
772770
sudo truncate -s ${loopback_disk_size} ${disk_image}
773771

774772
# Make a fresh XFS filesystem. Use bigger inodes so xattr can fit in
@@ -778,34 +776,31 @@ function create_disk {
778776
# Swift and Ceph.
779777
sudo mkfs.xfs -f -i size=1024 ${disk_image}
780778

781-
# Unmount the target, if mounted
782-
if egrep -q $storage_data_dir /proc/mounts; then
783-
sudo umount $storage_data_dir
784-
fi
785-
786-
# Clear any old fstab rules, install a new one for this disk, and mount it
787-
key=$(echo $disk_image | sed 's#/.##')
788-
key="devstack-$key"
789-
sudo sed -i '/.*comment=$key.*/ d' /etc/fstab
779+
# Install a new loopback fstab entry for this disk image, and mount it
790780
echo "$disk_image $storage_data_dir xfs loop,noatime,nodiratime,logbufs=8,comment=$key 0 0" | sudo tee -a /etc/fstab
781+
sudo mkdir -p $storage_data_dir
791782
sudo mount -v $storage_data_dir
792783
}
793784

794785
# Unmount, de-configure, and destroy a backing disk
795786
function destroy_disk {
796787
local disk_image=$1
797788
local storage_data_dir=$2
789+
local key
790+
791+
key=$(echo $disk_image | sed 's#/.##')
792+
key="devstack-$key"
798793

799794
# Unmount the target, if mounted
800795
if egrep -q $storage_data_dir /proc/mounts; then
801796
sudo umount $storage_data_dir
802797
fi
803798

804799
# Clear any fstab rules
805-
sed -i '/.*comment=$key.*/ d' /etc/fstab
800+
sudo sed -i '/.*comment=$key.*/ d' /etc/fstab
806801

807802
# Delete the file
808-
sudo rm $disk_image
803+
sudo rm -f $disk_image
809804
}
810805

811806

0 commit comments

Comments
 (0)