From 11fa540377beed8b80c146db43331a7929feb3e9 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 28 Apr 2017 10:18:24 -0700 Subject: [PATCH] scripts: add a vagrant setup Signed-off-by: Jim Harris Change-Id: I074c779d1736733b6864dfbcab529151e01fa4b7 --- README.md | 23 ++++++++++++ scripts/vagrant/README.md | 26 ++++++++++++++ scripts/vagrant/Vagrantfile | 70 +++++++++++++++++++++++++++++++++++++ scripts/vagrant/build.sh | 51 +++++++++++++++++++++++++++ scripts/vagrant/env.sh | 7 ++++ scripts/vagrant/update.sh | 44 +++++++++++++++++++++++ 6 files changed, 221 insertions(+) create mode 100644 scripts/vagrant/README.md create mode 100644 scripts/vagrant/Vagrantfile create mode 100644 scripts/vagrant/build.sh create mode 100644 scripts/vagrant/env.sh create mode 100644 scripts/vagrant/update.sh diff --git a/README.md b/README.md index 87ccc78009..4f62efc5c2 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,29 @@ FreeBSD: ./configure --with-dpdk=./dpdk/x86_64-native-bsdapp-clang gmake +Vagrant +======= + +A [Vagrant](https://www.vagrantup.com/downloads.html) setup is also provided +to create a Linux VM with a virtual NVMe controller to get up and running +quickly. Currently this has only been tested on MacOS with the +[VirtualBox](https://www.virtualbox.org/wiki/Downloads) provider. The +[VirtualBox Extension Pack](https://www.virtualbox.org/wiki/Downloads) must +also be installed for NVMe support. + +Download DPDK as a subdirectory in the SPDK repository as described above. +You do *not* need to build DPDK - the Vagrant scripts will do this for you. +If you are behind a corporate firewall, set http_proxy and https_proxy in +your environment before running the following steps. + + 1) vagrant up + 2) vagrant ssh + 3) cd /spdk + 4) sudo examples/nvme/hello_world/hello_world + +Additional details on the Vagrant setup can be found in +[scripts/vagrant/README.md](scripts/vagrant/README.md). + Advanced Build Options ====================== diff --git a/scripts/vagrant/README.md b/scripts/vagrant/README.md new file mode 100644 index 0000000000..34f736db2e --- /dev/null +++ b/scripts/vagrant/README.md @@ -0,0 +1,26 @@ +Introduction +============ + +This is a vagrant environment for SPDK with support +for Ubuntu 16.04 and Centos 7.2. + +The VM builds SPDK and DPDK from source which can be located at /spdk and /dpdk. + +VM Configuration +================ + +This vagrant environment creates a VM based on environment variables found in ./env.sh +To use, edit env.sh then + source ./env.sh + vagrant up + +By default, the VM created is/has: +- Ubuntu 16.04 +- 2 vCPUs +- 4G of RAM +- 2 NICs (1 x NAT - host access, 1 x private network) + +Providers +========= + +Currently only the Virtualbox provider is supported. diff --git a/scripts/vagrant/Vagrantfile b/scripts/vagrant/Vagrantfile new file mode 100644 index 0000000000..b707b1f616 --- /dev/null +++ b/scripts/vagrant/Vagrantfile @@ -0,0 +1,70 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure(2) do |config| + + # Pick the right distro and bootstrap, default is ubuntu1604 + distro = ( ENV['SPDK_VAGRANT_DISTRO'] || "ubuntu1604") + if distro == 'centos7' + config.vm.box = "puppetlabs/centos-7.2-64-nocm" + config.ssh.insert_key = false + else + config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm" + end + config.vm.box_check_update = false + + config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"update.sh") + config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"build.sh") + config.vm.provision :shell, inline: "/spdk/scripts/setup.sh", run: "always" + + # Copy in the .gitconfig if it exists + if File.file?(File.expand_path("~/.gitconfig")) + config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig" + 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 + + config.vm.network "private_network", type: "dhcp" + + # 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) + + 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}" + + # rsync the vpp directory if provision hasn't happened yet + unless File.exist? (".vagrant/machines/default/virtualbox/action_provision") + config.vm.synced_folder "../../", "/spdk", type: "rsync", rsync__auto: false + end + + nvme_disk = 'nvme.vdi' + 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 +end diff --git a/scripts/vagrant/build.sh b/scripts/vagrant/build.sh new file mode 100644 index 0000000000..b4f7f96601 --- /dev/null +++ b/scripts/vagrant/build.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +SPDK_DIR=/spdk +DPDK_DIR=$SPDK_DIR/dpdk + +SUDOCMD="sudo -H -u vagrant" +echo 0:$0 +echo 1:$1 +echo 2:$2 +echo SUDOCMD: $SUDOCMD + +# Figure out what system we are running on +if [ -f /etc/lsb-release ];then + . /etc/lsb-release +elif [ -f /etc/redhat-release ];then + sudo yum install -y redhat-lsb + DISTRIB_ID=`lsb_release -si` + DISTRIB_RELEASE=`lsb_release -sr` + DISTRIB_CODENAME=`lsb_release -sc` + DISTRIB_DESCRIPTION=`lsb_release -sd` +fi +KERNEL_OS=`uname -o` +KERNEL_MACHINE=`uname -m` +KERNEL_RELEASE=`uname -r` +KERNEL_VERSION=`uname -v` + +echo KERNEL_OS: $KERNEL_OS +echo KERNEL_MACHINE: $KERNEL_MACHINE +echo KERNEL_RELEASE: $KERNEL_RELEASE +echo KERNEL_VERSION: $KERNEL_VERSION +echo DISTRIB_ID: $DISTRIB_ID +echo DISTRIB_RELEASE: $DISTRIB_RELEASE +echo DISTRIB_CODENAME: $DISTRIB_CODENAME +echo DISTRIB_DESCRIPTION: $DISTRIB_DESCRIPTION + +if [ -f /etc/lsb-release ]; then + apt-get install -y gcc g++ make libcunit1-dev libaio-dev libssl-dev +elif [ -f /etc/redhat-release ]; then + # Add EPEL repository for CUnit-devel + yum --enablerepo=extras install epel-release + yum install -y gcc gcc-c++ CUnit-devel libaio-devel openssl-devel +fi + +cd $DPDK_DIR +$SUDOCMD make -j2 install T=x86_64-native-linuxapp-gcc DESTDIR=. + +cd $SPDK_DIR +$SUDOCMD ./configure --with-dpdk=$DPDK_DIR/x86_64-native-linuxapp-gcc --enable-debug +$SUDOCMD make -j2 +# Bind virtual NVMe controller to uio_pci_generic +sudo scripts/setup.sh diff --git a/scripts/vagrant/env.sh b/scripts/vagrant/env.sh new file mode 100644 index 0000000000..bcdcf0a9bf --- /dev/null +++ b/scripts/vagrant/env.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# centos7 also supported +export SPDK_VAGRANT_DISTRO="ubuntu1604" + +export SPDK_VAGRANT_VMCPU=4 +export SPDK_VAGRANT_VMRAM=4096 diff --git a/scripts/vagrant/update.sh b/scripts/vagrant/update.sh new file mode 100644 index 0000000000..020893de5f --- /dev/null +++ b/scripts/vagrant/update.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Make sure that we get the hugepages we need on provision boot +# Note: The package install should take care of this at the end +# But sometimes after all the work of provisioning, we can't +# get the requested number of hugepages without rebooting. +# So do it here just in case +sysctl -w vm.nr_hugepages=1024 +HUGEPAGES=`sysctl -n vm.nr_hugepages` +if [ $HUGEPAGES != 1024 ]; then + echo "ERROR: Unable to get 1024 hugepages, only got $HUGEPAGES. Cannot finish." + exit +fi + +# Figure out what system we are running on +if [ -f /etc/lsb-release ];then + . /etc/lsb-release +elif [ -f /etc/redhat-release ];then + yum install -y redhat-lsb + DISTRIB_ID=`lsb_release -si` + DISTRIB_RELEASE=`lsb_release -sr` + DISTRIB_CODENAME=`lsb_release -sc` + DISTRIB_DESCRIPTION=`lsb_release -sd` +fi + +# Do initial setup for the system +if [ $DISTRIB_ID == "Ubuntu" ]; then + + export DEBIAN_PRIORITY=critical + export DEBIAN_FRONTEND=noninteractive + export DEBCONF_NONINTERACTIVE_SEEN=true + APT_OPTS="--assume-yes --no-install-suggests --no-install-recommends -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\"" + + # Standard update + upgrade dance + apt-get update ${APT_OPTS} + apt-get upgrade ${APT_OPTS} + + # Install useful but non-mandatory tools + apt-get install -y gdb git +elif [ $DISTRIB_ID == "CentOS" ]; then + # Standard update + upgrade dance + yum check-update + yum update -y +fi