Skip to content

Commit

Permalink
add option to use dd for swapfile creation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mancdaz authored and cloudnull committed May 27, 2015
1 parent a2a4bb6 commit ccb1676
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions scripts/bootstrap-aio.sh
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions scripts/scripts-library.sh
Expand Up @@ -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

Expand Down

0 comments on commit ccb1676

Please sign in to comment.