From 13bd4c60ea35951f938a048c39959417f5eeca0b Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 19 Apr 2023 06:54:40 +0200 Subject: [PATCH] Always allocate --- run/disk.sh | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/run/disk.sh b/run/disk.sh index c296dbb..9db98e8 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -45,19 +45,17 @@ if [ -f "${DATA}" ]; then echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 84 fi + if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then + echo "ERROR: Could not allocate a file for the virtual disk." && exit 85 + fi + if [ "$ALLOCATE" = "Z" ]; then GB=$(( (REQ + 1073741823)/1073741824 )) - echo "INFO: Writing ${GB} GB of random data, please wait.." + echo "INFO: Preallocating ${GB} GB with random data, please wait.." dd if=/dev/urandom of="${DATA}" seek="${OLD_SIZE}" count="${REQ}" bs=1M iflag=count_bytes oflag=seek_bytes status=none - 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 @@ -90,19 +88,16 @@ if [ ! -f "${DATA}" ]; then echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 86 fi + if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then + rm -f "${DATA}" + echo "ERROR: Could not allocate a file for the virtual disk." && exit 87 + fi + if [ "$ALLOCATE" = "Z" ]; then - echo "INFO: Writing ${DISK_SIZE} of random data, please wait.." - + echo "INFO: Preallocating ${DISK_SIZE} with random data, please wait.." dd if=/dev/urandom of="${DATA}" count="${DATA_SIZE}" bs=1M iflag=count_bytes status=none - else - - if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then - rm -f "${DATA}" - echo "ERROR: Could not allocate a file for the virtual disk." && exit 87 - fi - fi fi