xref: /cloud-hypervisor/docs/vhost-user-blk-testing.md (revision fa22cb0be515cecb5c510a69cc263d903f346129)
19c7215d6SYang Zhong# How to test vhost-user-blk with SPDK
29c7215d6SYang Zhong
39c7215d6SYang ZhongThe purpose of this document is to illustrate how to test vhost-user-blk in Cloud Hypervisor with SPDK as the backend.
49c7215d6SYang Zhong
59c7215d6SYang Zhong## Framework
69c7215d6SYang Zhong
79c7215d6SYang ZhongIt's a simple test to validate the block read/write between VM and block backend.
89c7215d6SYang Zhong```
99c7215d6SYang Zhong             +----+----------+          +-------------+-----------+
109c7215d6SYang Zhong             |    |          |          |             |           |
119c7215d6SYang Zhong             |    |vhost-user|----------| vhost-user  |    dpdk   |
129c7215d6SYang Zhong             |    |blk device|          | port 1      |           |
139c7215d6SYang Zhong             |    |          |          |             |           |
149c7215d6SYang Zhong             |    +----------+          +-------------+-----------+
159c7215d6SYang Zhong             |               |          |                         |
169c7215d6SYang Zhong             |      vm       |          |           spdk          |
179c7215d6SYang Zhong             |               |          |                         |
189c7215d6SYang Zhong          +--+----------------------------------------------------+--+
199c7215d6SYang Zhong          |  |                  hugepages                         |  |
209c7215d6SYang Zhong          |  +----------------------------------------------------+  |
219c7215d6SYang Zhong          |                                                          |
229c7215d6SYang Zhong          |                       host                               |
239c7215d6SYang Zhong          |                                                          |
249c7215d6SYang Zhong          +----------------------------------------------------------+
259c7215d6SYang Zhong```
269c7215d6SYang Zhong## Prerequisites
279c7215d6SYang Zhong
289c7215d6SYang ZhongPrior to running the test, the following steps need to be performed.
299c7215d6SYang Zhong- Enable hugepages
309c7215d6SYang Zhong- Install SPDK
319c7215d6SYang Zhong
329c7215d6SYang ZhongHere are some good references for detailing them.
339c7215d6SYang Zhong- spdk
349c7215d6SYang Zhong	* https://spdk.io/doc/
359c7215d6SYang Zhong
369c7215d6SYang Zhong## Test environment
379c7215d6SYang Zhong
38db66cb6eSBo ChenThe below test environment is based on Ubuntu release (20.04.1 LTS), as for other system, please check related documents.
39db66cb6eSBo ChenThis test runs with multiple queue (MQ) support enabled, using 4 queues defined for both SPDK and the virtual machine.
40db66cb6eSBo ChenHere are the detailed instructions.
419c7215d6SYang Zhong
42db66cb6eSBo Chen### The hugepages settings on the host
43db66cb6eSBo ChenAllocate enough persistent huge pages (e.g. 2GiB) on the host:
44db66cb6eSBo Chen
45db66cb6eSBo Chen```bash
46db66cb6eSBo Chen# Assume the default hugepage size is 2MiB
47db66cb6eSBo Chenecho 1024 | sudo tee /proc/sys/vm/nr_hugepages
48db66cb6eSBo Chen# Confirm the value of "Hugepagesize" and "HugePages_Total"
49db66cb6eSBo Chencat /proc/meminfo | grep -i huge
50db66cb6eSBo Chen```
519c7215d6SYang Zhong
529c7215d6SYang Zhong### Download the SPDK code
53db66cb6eSBo Chen```bash
549c7215d6SYang Zhonggit clone https://github.com/spdk/spdk
559c7215d6SYang Zhongcd spdk
569c7215d6SYang Zhonggit submodule update --init
57db66cb6eSBo Chen```
589c7215d6SYang Zhong
599c7215d6SYang Zhong### Create the build dep
609c7215d6SYang Zhong
61db66cb6eSBo Chen```bash
62db66cb6eSBo Chen./scripts/pkgdep.sh
63db66cb6eSBo Chen```
64db66cb6eSBo Chen
65db66cb6eSBo Chen### Build SPDK
66db66cb6eSBo Chen```bash
679c7215d6SYang Zhong./configure
689c7215d6SYang Zhongmake
69db66cb6eSBo Chen```
709c7215d6SYang Zhong
71db66cb6eSBo Chen### Set the SPDK environment
72be79a803SZiye Yang
73be79a803SZiye YangRun SPDK vhost target with 2 CPU cores, i.e., core 0 and 1.
74db66cb6eSBo Chen```bash
759c7215d6SYang Zhongsudo HUGEMEM=2048 scripts/setup.sh
76db66cb6eSBo Chensudo ./build/bin/vhost -S /var/tmp -s 1024 -m 0x3 &
77db66cb6eSBo Chen```
789c7215d6SYang Zhong
799c7215d6SYang Zhong### Create 512M block device
80be79a803SZiye Yang
81be79a803SZiye YangCreate a 512M (first parameter) block device with 512 bytes (second parameter) block size.
82db66cb6eSBo Chen```bash
839c7215d6SYang Zhongsudo scripts/rpc.py bdev_malloc_create 512 512 -b Malloc0
849c7215d6SYang Zhongsudo scripts/rpc.py vhost_create_blk_controller --cpumask 0x1 vhost.1 Malloc0
85db66cb6eSBo Chen```
869c7215d6SYang Zhong
87db66cb6eSBo Chen### Launch the VM
889c7215d6SYang Zhong
899c7215d6SYang ZhongVMs run in client mode. They connect to the socket created by the `dpdkvhostuser` in the SPDK backend.
909c7215d6SYang Zhong```bash
919c7215d6SYang Zhong# From the test terminal. We need to create one vhost-user-blk device for the --disk.
929c7215d6SYang Zhong./cloud-hypervisor \
939c7215d6SYang Zhong        --cpus boot=4 \
9417ad86afSAlyssa Ross        --memory size=1024M,hugepages=on,shared=true \
959c7215d6SYang Zhong        --kernel linux/arch/x86/boot/compressed/vmlinux.bin \
96a3342bdbSSebastien Boeuf        --cmdline "console=ttyS0 root=/dev/vda1 rw iommu=off" \
97*fa22cb0bSRavi kumar Veeramally        --disk path=images/focal-server-cloudimg-amd64.raw vhost_user=true,socket=/var/tmp/vhost.1,num_queues=4,queue_size=128 \
989c7215d6SYang Zhong        --console off \
999c7215d6SYang Zhong        --serial tty \
1009c7215d6SYang Zhong        --rng
1019c7215d6SYang Zhong```
1029c7215d6SYang Zhong
1039c7215d6SYang Zhong```bash
1049c7215d6SYang Zhong# How to test the vhost-user-blk device with SPDK backend
1059c7215d6SYang Zhonglogin in guest
1069c7215d6SYang Zhong
1079c7215d6SYang Zhong# Use lsblk command to find out vhost-user-blk device
1089c7215d6SYang Zhonglsblk
1099c7215d6SYang ZhongNAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
110a3342bdbSSebastien Boeufvda     252:0    0  2.2G  0 disk
111a3342bdbSSebastien Boeuf├─vda1  252:1    0  2.1G  0 part /
112a3342bdbSSebastien Boeuf├─vda14 252:14   0    4M  0 part
113a3342bdbSSebastien Boeuf└─vda15 252:15   0  106M  0 part /boot/efi
1149c7215d6SYang Zhongvdb    253:16   0  512M  0 disk
1159c7215d6SYang Zhong
1169c7215d6SYang ZhongThe vhost-user-blk device is /dev/vdb
1179c7215d6SYang Zhong
1189c7215d6SYang Zhong# How to do simple read/write test
1199c7215d6SYang Zhongdd if=/dev/vdb of=/dev/null bs=2M iflag=direct
1209c7215d6SYang Zhongdd of=/dev/vdb if=/dev/zero bs=2M oflag=direct count=256
1219c7215d6SYang Zhong
1229c7215d6SYang ZhongIf you want to do fio test, please install fio binary into guest. The detailed info is not listed here.
123