0. 配置
HUGEMEM=2048 ./scripts/setup.sh
1.启动vhost application:
./app/vhost/vhost -S /var/tmp -s 1024 -m 0x3 &
2. 创建SPDK bdev
(注意:SPDK bdev是SPDK中对多种存储后端(storage backend)的抽象。 这些存储后端(storage backend)包括:ceph RBD,ramdisk,NVMe,iSCSI,逻辑卷,甚至是virtio)。这里就体现了SPDK block device layer的概念。
2.1 创建基于physical NVMe的spdk nvme bdev
这里要求运行qemu的Host上插有physical NVME SSD。
./scripts/rpc.py bdev_nvme_attach_controller -b Nvme0 -t pcie -a 0000:01:00.0
./scripts/rpc.py vhost_scsi_controller_add_target vhost.0 0 Nvme0n1
2.2 创建基于ramdisk的spdk bdev Malloc0 (vhost-scsi)
./scripts/rpc.py bdev_malloc_create -b Malloc0 128 4096
首先创建一个 vhost-scsi控制器。QEMU 通过 /var/tmp/vhost.0
来使用。--cpumask
参数标识绑定的CPU core ID,如下:
./scripts/rpc.py vhost_create_scsi_controller --cpumask 0x1 vhost.0
将 Malloc0
绑定到vhost.0 vhost-scsi 控制器,如下:
./scripts/rpc.py vhost_scsi_controller_add_target vhost.0 1 Malloc0
2.2 创建基于ramdisk的spdk bdev Malloc1 (vhost-blk)
同样,首先创建一个名为Malloc1的SPDK block device,如下:
./scripts/rpc.py bdev_malloc_create -b Malloc1 64 512
再创建一个vhost-blk 设备用于暴露Malloc1,QEMU 通过/var/tmp/vhost.1
使用。如下:
./scripts/rpc.py vhost_create_blk_controller --cpumask 0x2 vhost.1 Malloc1
3. 启动qemu VM
qemu-system-x86_64 \
--enable-kvm \
-cpu host -smp 2 \
-m 1G -object memory-backend-file,id=mem0,size=1G,mem-path=/dev/hugepages,share=on -numa node,memdev=mem0 \
-drive file=guest_os_image.qcow2,if=none,id=disk \
-device ide-hd,drive=disk,bootindex=0 \
-chardev socket,id=spdk_vhost_scsi0,path=/var/tmp/vhost.0 \
-device vhost-user-scsi-pci,id=scsi0,chardev=spdk_vhost_scsi0,num_queues=4 \
-chardev socket,id=spdk_vhost_blk0,path=/var/tmp/vhost.1 \
-device vhost-user-blk-pci,chardev=spdk_vhost_blk0,num-queues=4
来源:oschina
链接:https://my.oschina.net/u/4301161/blog/4291190