Add full preallocation (writing zeroes)

This commit is contained in:
Kroese 2023-04-19 03:55:32 +02:00 committed by GitHub
parent 9b9d8285fe
commit e65ab41b7c

View File

@ -45,12 +45,22 @@ if [ -f "${DATA}" ]; then
echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 84
fi
if [ "$ALLOCATE" = "F" ]; then
GB=$(( (REQ + 1073741823)/1073741824 ))
echo "INFO: Writing ${GB} GB of zeroes, please wait.."
dd if=/dev/zero of="${DATA}" seek="{OLD_SIZE}" count="${REQ}" bs=1M iflag=count_bytes oflag=seek_bytes
else
if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
echo "ERROR: Could not allocate a file for the virtual disk." && exit 85
fi
fi
fi
fi
if [ "$DATA_SIZE" -lt "$OLD_SIZE" ]; then
@ -82,11 +92,9 @@ if [ ! -f "${DATA}" ]; then
if [ "$ALLOCATE" = "F" ]; then
MB=$(( (DATA_SIZE + 1048575)/1048576 ))
echo "INFO: Writing ${DISK_SIZE} of zeroes, please wait.."
echo "INFO: Writing ${MB} MB of zeroes, please wait.."
dd if=/dev/zero of="${DATA}" count="${MB}" bs=1M
truncate -s "${DATA_SIZE}" "${DATA}"
dd if=/dev/zero of="${DATA}" count="${DATA_SIZE}" bs=1M iflag=count_bytes
else
@ -103,19 +111,18 @@ if [ ! -f "${DATA}" ]; then
echo "ERROR: Virtual disk does not exist ($DATA)" && exit 88
fi
# Format as BTRFS filesystem
mkfs.btrfs -q -L data -d single -m dup "${DATA}" > /dev/null
fi
# Check the filesize
SIZE=$(stat -c%s "${DATA}")
if [[ SIZE -ne DATA_SIZE ]]; then
rm -f "${DATA}"
echo "ERROR: Virtual disk has the wrong size: ${SIZE}" && exit 89
fi
# Format as BTRFS filesystem
mkfs.btrfs -q -L data -d single -m dup "${DATA}" > /dev/null
fi
AGENT="${STORAGE}/${BASE}.agent"
[ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}") || AGENT_VERSION=1