From ccb16763234a13fc204b91943e3d0c197545f2e9 Mon Sep 17 00:00:00 2001 From: Darren Birkett Date: Tue, 26 May 2015 12:23:34 +0100 Subject: [PATCH] add option to use dd for swapfile creation fallocate is faster than using dd to create a thick swapfile with zeros, but it is not supported on all filesystems (specifically ext3). This commit adds a fallback to using dd if fallocate fails Closes-Bug: #1458841 Change-Id: Ie4adf625d85f84a0d89a108ef0438622ab763b9d --- scripts/bootstrap-aio.sh | 8 ++++---- scripts/scripts-library.sh | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/bootstrap-aio.sh b/scripts/bootstrap-aio.sh index 980c52039c..ae5b08e253 100755 --- a/scripts/bootstrap-aio.sh +++ b/scripts/bootstrap-aio.sh @@ -200,9 +200,9 @@ mount -a || true if [ ! "$(swapon -s | grep -v Filename)" ]; then memory_kb=$(awk '/MemTotal/ {print $2}' /proc/meminfo) if [ "${memory_kb}" -lt "8388608" ]; then - swap_size="4G" + swap_size="4294967296" else - swap_size="8G" + swap_size="8589934592" fi loopback_create "/opt/swap.img" ${swap_size} thick swap # Ensure swap will be used on the host @@ -215,7 +215,7 @@ fi # Build the loopback drive for cinder to use CINDER="cinder.img" if ! vgs cinder-volumes; then - loopback_create "/opt/${CINDER}" 1000G thin rc + loopback_create "/opt/${CINDER}" 1073741824000 thin rc CINDER_DEVICE=$(losetup -a | awk -F: "/${CINDER}/ {print \$1}") pvcreate ${CINDER_DEVICE} pvscan @@ -234,7 +234,7 @@ if [ "${DEPLOY_SWIFT}" == "yes" ]; then # build the loopback drives for swift to use for SWIFT in swift1 swift2 swift3; do if ! grep "${SWIFT}" /proc/mounts > /dev/null; then - loopback_create "/opt/${SWIFT}.img" 1000G thin none + loopback_create "/opt/${SWIFT}.img" 1073741824000 thin none if ! grep -w "^/opt/${SWIFT}.img" /etc/fstab > /dev/null; then echo "/opt/${SWIFT}.img /srv/${SWIFT}.img xfs loop,noatime,nodiratime,nobarrier,logbufs=8 0 0" >> /etc/fstab fi diff --git a/scripts/scripts-library.sh b/scripts/scripts-library.sh index 8be5576787..fc9d247e95 100755 --- a/scripts/scripts-library.sh +++ b/scripts/scripts-library.sh @@ -142,9 +142,10 @@ function loopback_create() { if [ "${LOOP_FILE_TYPE}" = "thin" ]; then truncate -s ${LOOP_FILESIZE} ${LOOP_FILENAME} elif [ "${LOOP_FILE_TYPE}" = "thick" ]; then - fallocate -l ${LOOP_FILESIZE} ${LOOP_FILENAME} + fallocate -l ${LOOP_FILESIZE} ${LOOP_FILENAME} &> /dev/null || \ + dd if=/dev/zero of=${LOOP_FILENAME} bs=1M count=$(( ${LOOP_FILESIZE} / 1024 / 1024 )) else - exit_fail 'No valid option ${LOOP_FILE_TYPE} found.' + exit_fail "No valid option ${LOOP_FILE_TYPE} found." fi fi