Spdk/scripts/vagrant/create_nvme_img.sh
Maciej Wawryk ff231506d3 scripts/vagrant: Add more NVMe emulation options
Current scripts/vagrant allow us to create only a single file for
emulating NVMe with single namespace.
This patch allow to create multiple emulated drives with multiple namespaces.
This patch also allows to emulate OCSSD disks which are used in OCF tests.

Change-Id: Ia7a4667bd405ba18235e72bcdf608270002b5242
Signed-off-by: Maciej Wawryk <maciejx.wawryk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/466555
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: Seth Howell <seth.howell@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
2019-11-18 13:15:17 +00:00

66 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
SYSTEM=$(uname -s)
size="1024M"
name="nvme_disk.img"
type="nvme"
function usage() {
echo "Usage: ${0##*/} [-s <disk_size>] [-n <backing file name>]"
echo "-s <disk_size> with postfix e.g. 2G default: 1024M"
echo "-n <backing file name> default: nvme_disk.img"
echo "-t <type> default: nvme available: ocssd"
}
while getopts "s:n:t:h-:" opt; do
case "${opt}" in
-)
echo " Invalid argument: $OPTARG"
usage
exit 1
;;
s)
size=$OPTARG
;;
n)
name=$OPTARG
;;
t)
type=$OPTARG
;;
h)
usage
exit 0
;;
*)
echo " Invalid argument: $OPTARG"
usage
exit 1
;;
esac
done
if [ ! "${SYSTEM}" = "FreeBSD" ]; then
WHICH_OS=$(lsb_release -i | awk '{print $3}')
nvme_disk="/var/lib/libvirt/images/$name"
case $type in
"nvme")
qemu-img create -f raw $nvme_disk ${size}
;;
"ocssd")
fallocate -l ${size} $nvme_disk
touch /var/lib/libvirt/images/ocssd_md
;;
*)
echo "We support only nvme and ocssd disks types"
exit 1
;;
esac
#Change SE Policy on Fedora
if [ $WHICH_OS == "Fedora" ]; then
sudo chcon -t svirt_image_t $nvme_disk
fi
chmod 777 $nvme_disk
chown qemu:qemu $nvme_disk
fi