Skip to content

Commit

Permalink
Add setup to emulate NVMe device
Browse files Browse the repository at this point in the history
The setup allows to create and emulate in the provisioned nodes an NVMe
device. This can be particularly useful for testing scenarios with
NVMe like NVMe passthrough.

Added in the gocli provision the new flag nvme in order to pass the size for the NVMe device to
the vm.sh script.

Signed-off-by: Alice Frosi <[email protected]>
  • Loading branch information
alicefr committed Sep 2, 2021
1 parent 576bc8c commit 1f367dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cluster-provision/centos8/scripts/vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ KERNEL_ARGS=""
NEXT_DISK=""
BLOCK_DEV=""
BLOCK_DEV_SIZE=""

NVME_DISK="nvme.img"
NVME_DEV_SIZE=""
NVME_QEMU_ARGS=""
while true; do
case "$1" in
-m | --memory ) MEMORY="$2"; shift 2 ;;
Expand All @@ -20,6 +22,7 @@ while true; do
-n | --next-disk ) NEXT_DISK="$2"; shift 2 ;;
-b | --block-device ) BLOCK_DEV="$2"; shift 2 ;;
-s | --block-device-size ) BLOCK_DEV_SIZE="$2"; shift 2 ;;
-t | --nvme-device-size ) NVME_DEV_SIZE="$2"; shift 2 ;;
-- ) shift; break ;;
* ) break ;;
esac
Expand Down Expand Up @@ -108,6 +111,13 @@ if [ -n "${BLOCK_DEV}" ]; then
block_dev_arg="-drive format=qcow2,file=${BLOCK_DEV},if=virtio,cache=unsafe"
fi

if [ -n "${NVME_DEV_SIZE}" ]; then
echo "Create disk image for nvme emulation"
qemu-img create $NVME_DISK -f raw ${NVME_DEV_SIZE}
NVME_QEMU_ARG="-drive file=$NVME_DISK,format=raw,id=NVME1,if=none -device nvme,drive=NVME1,serial=nvme-1"
fi


exec qemu-system-x86_64 -enable-kvm -drive format=qcow2,file=${next},if=virtio,cache=unsafe ${block_dev_arg} \
-device virtio-net-pci,netdev=network0,mac=52:55:00:d1:55:${n} \
-netdev tap,id=network0,ifname=tap${n},script=no,downscript=no \
Expand All @@ -119,4 +129,4 @@ exec qemu-system-x86_64 -enable-kvm -drive format=qcow2,file=${next},if=virtio,c
-serial pty -M q35,accel=kvm,kernel_irqchip=split \
-device intel-iommu,intremap=on,caching-mode=on -soundhw hda \
-uuid $(cat /proc/sys/kernel/random/uuid) \
${QEMU_ARGS}
${QEMU_ARGS} ${NVME_QEMU_ARG}
12 changes: 12 additions & 0 deletions cluster-provision/gocli/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func NewRunCommand() *cobra.Command {
run.Flags().String("container-org", "kubevirtci", "the organization at the registry to pull the container from")
run.Flags().String("container-suffix", "", "Override container suffix stored at the cli binary")
run.Flags().String("gpu", "", "pci address of a GPU to assign to a node")
run.Flags().String("nvme", "", "size of the emulate NVMe disk to pass to the node")
run.Flags().Bool("run-etcd-on-memory", false, "configure etcd to run on RAM memory, etcd data will not be persistent")
run.Flags().String("etcd-capacity", "512M", "set etcd data mount size.\nthis flag takes affect only when 'run-etcd-on-memory' is specified")

Expand Down Expand Up @@ -243,6 +244,14 @@ func run(cmd *cobra.Command, args []string) (retErr error) {
}
resource.MustParse(etcdDataMountSize)

nvmeDiskSize, err := cmd.Flags().GetString("nvme")
if err != nil {
return err
}
if nvmeDiskSize != "" {
resource.MustParse(nvmeDiskSize)
}

cli, err = client.NewEnvClient()
if err != nil {
return err
Expand Down Expand Up @@ -489,6 +498,9 @@ func run(cmd *cobra.Command, args []string) (retErr error) {
if len(kernelArgs) > 0 {
additionalArgs = append(additionalArgs, "--additional-kernel-args", shellescape.Quote(kernelArgs))
}
if len(nvmeDiskSize) > 0 {
additionalArgs = append(additionalArgs, fmt.Sprintf("--nvme-device-size %s", nvmeDiskSize))
}

blockDev := ""
if cephEnabled {
Expand Down

0 comments on commit 1f367dc

Please sign in to comment.