Spdk/scripts/vagrant/create_nvme_img.sh
Tomasz Zawadzki 7d97822f17 vagrant: preallocate nvme images by default
Added preallocation option for raw NVMe disk images.
It matches qemu-img option for raw images.

By default raw images are created with "off" option,
resulting in increased size of the disk image as it is used.

Using "falloc" option preallocates the full size of the disk,
but does not write zeroes to it, compared to "full" option.

This will make sure that in CI, a device used during test
is never exhaused due to lack of host space.

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: Ie1c30909dc87552a6d6c385d0ad80905ce68ff9d
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11243
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2022-01-27 19:36:38 +00:00

72 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
SYSTEM=$(uname -s)
size="1024M"
nvme_disk="/var/lib/libvirt/images/nvme_disk.img"
preallocation="falloc"
function usage() {
echo "Usage: ${0##*/} [-s <disk_size>] [-n <backing file name>]"
echo "-s <disk_size> with postfix e.g. 2G default: 1024M"
echo " for OCSSD default: 9G"
echo "-n <backing file name> backing file path with name"
echo " default: /var/lib/libvirt/images/nvme_disk.img"
echo "-p <mode> allowed values:[off, falloc, full]"
echo " default: falloc"
}
while getopts "s:n:p:t:h-:" opt; do
case "${opt}" in
-)
echo " Invalid argument: $OPTARG"
usage
exit 1
;;
s)
size=$OPTARG
;;
n)
nvme_disk=$OPTARG
;;
p)
preallocation=$OPTARG
;;
h)
usage
exit 0
;;
*)
echo " Invalid argument: $OPTARG"
usage
exit 1
;;
esac
done
if [ "${SYSTEM}" != "Linux" ]; then
echo "This script supports only Linux OS" >&2
exit 2
fi
WHICH_OS=$(lsb_release -i | awk '{print $3}')
qemu-img create -f raw "$nvme_disk" -o preallocation="$preallocation" $size
case $WHICH_OS in
"Fedora")
qemu_user_group="qemu:qemu"
# Change SE Policy
sudo chcon -t svirt_image_t "$nvme_disk"
;;
"Ubuntu")
qemu_user_group="libvirt-qemu:kvm"
;;
*)
# That's just a wild guess for now
# TODO: needs improvement for other distros
qemu_user_group="libvirt-qemu:kvm"
;;
esac
chmod 777 "$nvme_disk"
chown $qemu_user_group "$nvme_disk"