Spdk/scripts/vagrant/Vagrantfile
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

209 lines
8.7 KiB
Ruby

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
# Pick the right distro and bootstrap, default is fedora28
distro = ( ENV['SPDK_VAGRANT_DISTRO'] || "fedora28")
provider = (ENV['SPDK_VAGRANT_PROVIDER'] || "virtualbox")
case distro
when "centos7"
config.vm.box = "puppetlabs/centos-7.2-64-nocm"
config.ssh.insert_key = false
# Puppetlabs does not provide libvirt Box so we will use official one
config.vm.provider :libvirt do |libvirt|
config.vm.box = "centos/7"
end if Vagrant.has_plugin?('vagrant-libvirt')
when "ubuntu16"
if provider.eql?("libvirt")
# https://app.vagrantup.com/sjohnsen/boxes/ubuntu1604
config.vm.box = "sjohnsen/ubuntu1604"
else
# See: https://app.vagrantup.com/puppetlabs/boxes/ubuntu-16.04-64-nocm
config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm"
config.vm.box_version = "1.0.0"
end
when "ubuntu18"
if provider.eql?("libvirt")
# https://app.vagrantup.com/sjohnsen/boxes/ubuntu1804
config.vm.box = "sjohnsen/ubuntu1804"
else
# See: https://app.vagrantup.com/bento/boxes/ubuntu-18.04
config.vm.box = "bento/ubuntu-18.04"
config.vm.box_version = "201803.24.0"
end
when "fedora28"
#See: https://app.vagrantup.com/generic/boxes/fedora28
config.vm.box = "generic/fedora28"
when "fedora29"
#See: https://app.vagrantup.com/generic/boxes/fedora29
config.vm.box = "generic/fedora29"
when "fedora30"
#See: https://app.vagrantup.com/generic/boxes/fedora30
config.vm.box = "generic/fedora30"
when "freebsd11"
#See: https://app.vagrantup.com/generic/boxes/freebsd11
config.vm.box = "generic/freebsd11"
if File.file?(File.expand_path("~/vagrant_pkg.conf"))
config.vm.provision "file", source: "~/vagrant_pkg.conf", destination: "pkg.conf"
config.vm.provision "shell", inline: "sudo mv pkg.conf /usr/local/etc/pkg.conf"
config.vm.provision "shell", inline: "sudo chown root:wheel /usr/local/etc/pkg.conf"
config.vm.provision "shell", inline: "sudo chmod 644 /usr/local/etc/pkg.conf"
end
when "arch-linux"
#See: https://app.vagrantup.com/generic/boxes/arch
config.vm.box = "generic/arch"
else
"Invalid argument #{distro}"
abort("Invalid argument!")
end
config.vm.box_check_update = false
# Copy in the .gitconfig if it exists
if File.file?(File.expand_path("~/.gitconfig"))
config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"
end
# Copy the tsocks configuration file for use when installing some spdk test pool dependencies
if File.file?("/etc/tsocks.conf")
config.vm.provision "file", source: "/etc/tsocks.conf", destination: "tsocks.conf"
config.vm.provision "shell", inline: "sudo mv tsocks.conf /etc/tsocks.conf"
config.vm.provision "shell", inline: "sudo chown root:wheel /etc/tsocks.conf"
config.vm.provision "shell", inline: "sudo chmod 644 /etc/tsocks.conf"
end
# vagrant-cachier caches apt/yum etc to speed subsequent
# vagrant up
# to enable, run
# vagrant plugin install vagrant-cachier
#
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
end
if !(distro.include?("ubuntu"))
config.vm.network "private_network", type: "dhcp"
end
# use http proxy if avaiable
if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = ENV['http_proxy']
config.proxy.https = ENV['https_proxy']
config.proxy.no_proxy = "localhost,127.0.0.1"
end
vmcpu=(ENV['SPDK_VAGRANT_VMCPU'] || 2)
vmram=(ENV['SPDK_VAGRANT_VMRAM'] || 4096)
spdk_dir=(ENV['SPDK_DIR'] || "none")
vhost_host_dir=(ENV['VHOST_HOST_DIR'] || "none")
vhost_vm_dir=(ENV['VHOST_VM_DIR'] || "none")
vmemulator=(ENV['SPDK_QEMU_EMULATOR'] || "")
emulated_nvme_types=(ENV['NVME_DISKS_TYPE'] || "nvme").split(',')
nvme_namespaces=(ENV['NVME_DISKS_NAMESPACES'] || "").split(',')
nvme_file=(ENV['NVME_FILE'] || "").split(',')
config.ssh.forward_agent = true
config.ssh.forward_x11 = true
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--ioapic", "on"]
vb.memory = "#{vmram}"
vb.cpus = "#{vmcpu}"
nvme_disk=(ENV['NVME_FILE'] || "nvme_disk.img")
unless File.exist? (nvme_disk)
vb.customize ["createhd", "--filename", nvme_disk, "--variant", "Fixed", "--size", "1024"]
vb.customize ["storagectl", :id, "--name", "nvme", "--add", "pcie", "--controller", "NVMe", "--portcount", "1", "--bootable", "off"]
vb.customize ["storageattach", :id, "--storagectl", "nvme", "--type", "hdd", "--medium", nvme_disk, "--port", "0"]
end
#support for the SSE4.x instruction is required in some versions of VB.
vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"]
vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"]
end
# This setup was Tested on Fedora 27
# libvirt configuration need modern Qemu(tested on 2.10) & vagrant-libvirt in version 0.0.39+
# There are few limitation for SElinux - The file added outside libvirt must have proper SE ACL policy or setenforce 0
config.vm.provider "libvirt" do |libvirt, override|
libvirt.random_hostname = "1"
libvirt.disk_bus = "virtio"
if not vmemulator.empty?
libvirt.emulator_path = "#{vmemulator}"
end
# we put nvme_disk inside default pool to eliminate libvirt/SELinux Permissions Problems
# and to be able to run vagrant from user $HOME directory
# Loop to create all emulated disks set
emulated_nvme_types.each_with_index { |disk, index|
if ENV['NVME_FILE']
nvme_disk_id="#{disk}" + "-#{index}"
nvme_disk="#{nvme_file["#{index}".to_i]}"
else
nvme_disk="/var/lib/libvirt/images/nvme_disk.img"
end
unless File.exist? (nvme_disk)
puts "If run with libvirt provider please execute create_nvme_img.sh"
end
if disk == "nvme"
libvirt.qemuargs :value => "-drive"
libvirt.qemuargs :value => "format=raw,file=#{nvme_disk},if=none,id=#{nvme_disk_id}"
libvirt.qemuargs :value => "-device"
if nvme_namespaces["#{index}".to_i].nil?
libvirt.qemuargs :value => "nvme,drive=#{nvme_disk_id},serial=1234#{index}"
else
libvirt.qemuargs :value => "nvme,drive=#{nvme_disk_id},serial=1234#{index},namespaces=#{nvme_namespaces["#{index}".to_i]}"
end
elsif disk == "ocssd"
libvirt.qemuargs :value => "-drive"
libvirt.qemuargs :value => "format=raw,file=#{nvme_disk},if=none,id=#{nvme_disk_id}"
libvirt.qemuargs :value => "-device"
# create ocssd drive with special parameters
# lba_index=4 it is LBA namespace format, 4 means that block size is 4K and have 64B metadata
# lnum_lun, lnum_pln, lpgs_per_blk, lsecs_per_pg, lblks_per_pln this are parameters describing the device geometry
# we need to multiply these parameters by ourselves to have backend file minimal size:
# in our case: 4K * 8 * 2 * 1536 * 2 * 45 = 8640 MB
libvirt.qemuargs :value => "nvme,drive=#{nvme_disk_id},serial=deadbeef,oacs=0,namespaces=1,lver=2,lba_index=4,mdts=10,lnum_lun=8,lnum_pln=2,lpgs_per_blk=1536,lsecs_per_pg=2,lblks_per_pln=45,metadata=/var/lib/libvirt/images/ocssd_md,nsdatafile=/var/lib/libvirt/images/ocssd_blknvme.ns,laer_thread_sleep=3000,stride=4"
end
}
libvirt.driver = "kvm"
libvirt.graphics_type = "vnc"
libvirt.memory = "#{vmram}"
libvirt.cpus = "#{vmcpu}"
libvirt.video_type = "cirrus"
# Optional field if we want use other storage pools than default
# libvirt.storage_pool_name = "vm"
end
# rsync the spdk directory if provision hasn't happened yet
if ENV['COPY_SPDK_DIR'] == "1" && spdk_dir != "none"
config.vm.synced_folder "#{spdk_dir}", "/home/vagrant/spdk_repo/spdk", type: "rsync", rsync__auto: false
end
# provision the vm with all of the necessary spdk dependencies for running the autorun.sh tests
if ENV['DEPLOY_TEST_VM'] == "1" && spdk_dir != "none"
config.vm.provision "shell" do |setup|
setup.path = "#{spdk_dir}/test/common/config/vm_setup.sh"
setup.privileged = false
setup.args = ["-u", "-i"]
end
end
if vhost_host_dir != "none"
config.vm.synced_folder "#{vhost_host_dir}", "#{vhost_vm_dir}", type: "rsync", rsync__auto: false
config.vm.provision "shell", inline: "sudo mkdir -p /root/.ssh"
config.vm.provision "shell", inline: "sudo cp #{vhost_vm_dir}/spdk_vhost_id_rsa* /root/.ssh"
config.vm.provision "shell", inline: "sudo chmod 600 /root/.ssh/spdk_vhost_id_rsa"
end
# Copy in the user's tools if they exists
if File.directory?(File.expand_path("~/vagrant_tools"))
config.vm.synced_folder "~/vagrant_tools", "/home/vagrant/tools", type: "rsync", rsync__auto: false
end
end