]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | #!/usr/bin/env bash |
2 | ||
3 | set -e | |
11fdf7f2 | 4 | |
9f95a23c TL |
5 | testdir=$(readlink -f $(dirname $0)) |
6 | rootdir=$(readlink -f $testdir/../../..) | |
7 | source $rootdir/test/common/autotest_common.sh | |
8 | source $rootdir/test/vhost/common.sh | |
9 | ||
10 | PLUGIN_DIR=$rootdir/examples/bdev/fio_plugin | |
11fdf7f2 TL |
11 | FIO_PATH="/usr/src/fio" |
12 | virtio_bdevs="" | |
13 | virtio_with_unmap="" | |
14 | os_image="/home/sys_sgsw/vhost_vm_image.qcow2" | |
15 | #different linux distributions have different versions of targetcli that have different names for ramdisk option | |
16 | targetcli_rd_name="" | |
17 | kernel_vhost_disk="naa.5012345678901234" | |
18 | ||
19 | function usage() | |
20 | { | |
21 | [[ ! -z $2 ]] && ( echo "$2"; echo ""; ) | |
22 | echo "Script for running vhost initiator tests." | |
23 | echo "Usage: $(basename $1) [-h|--help] [--fiobin=PATH]" | |
24 | echo "-h, --help Print help and exit" | |
25 | echo " --vm_image=PATH Path to VM image used in these tests [default=$os_image]" | |
26 | echo " --fiopath=PATH Path to fio directory on host [default=$FIO_PATH]" | |
27 | } | |
28 | ||
29 | while getopts 'h-:' optchar; do | |
30 | case "$optchar" in | |
31 | -) | |
32 | case "$OPTARG" in | |
33 | help) usage $0 && exit 0 ;; | |
34 | fiopath=*) FIO_PATH="${OPTARG#*=}" ;; | |
35 | vm_image=*) os_image="${OPTARG#*=}" ;; | |
36 | *) usage $0 echo "Invalid argument '$OPTARG'" && exit 1 ;; | |
37 | esac | |
38 | ;; | |
39 | h) usage $0 && exit 0 ;; | |
40 | *) usage $0 "Invalid argument '$optchar'" && exit 1 ;; | |
41 | esac | |
42 | done | |
43 | ||
9f95a23c TL |
44 | vhosttestinit |
45 | ||
46 | source $testdir/autotest.config | |
47 | PLUGIN_DIR=$rootdir/examples/bdev/fio_plugin | |
48 | RPC_PY="$rootdir/scripts/rpc.py -s $(get_vhost_dir)/rpc.sock" | |
11fdf7f2 TL |
49 | |
50 | if [ ! -x $FIO_PATH ]; then | |
51 | error "Invalid path of fio binary" | |
52 | fi | |
53 | ||
54 | if [[ $EUID -ne 0 ]]; then | |
55 | echo "INFO: Go away user come back as root" | |
56 | exit 1 | |
57 | fi | |
58 | ||
59 | if targetcli ls backstores | grep ramdisk ; then | |
60 | targetcli_rd_name="ramdisk" | |
61 | elif targetcli ls backstores | grep rd_mcp ; then | |
62 | targetcli_rd_name="rd_mcp" | |
63 | else | |
64 | error "targetcli: cannot create a ramdisk.\ | |
65 | Neither backstores/ramdisk nor backstores/rd_mcp is available" | |
66 | fi | |
67 | ||
68 | function remove_kernel_vhost() | |
69 | { | |
9f95a23c TL |
70 | if targetcli "/vhost/$kernel_vhost_disk ls"; then |
71 | targetcli "/vhost delete $kernel_vhost_disk" | |
72 | fi | |
73 | if targetcli "/backstores/$targetcli_rd_name/ramdisk ls"; then | |
74 | targetcli "/backstores/$targetcli_rd_name delete ramdisk" | |
75 | fi | |
11fdf7f2 TL |
76 | } |
77 | ||
9f95a23c TL |
78 | trap 'rm -f *.state $rootdir/spdk.tar.gz $rootdir/fio.tar.gz $(get_vhost_dir)/Virtio0;\ |
79 | remove_kernel_vhost; error_exit "${FUNCNAME}""${LINENO}"' ERR SIGTERM SIGABRT | |
11fdf7f2 | 80 | function run_spdk_fio() { |
9f95a23c | 81 | fio_bdev --ioengine=spdk_bdev "$@" --spdk_mem=1024 --spdk_single_seg=1 |
11fdf7f2 TL |
82 | } |
83 | ||
84 | function create_bdev_config() | |
85 | { | |
86 | local vbdevs | |
87 | ||
88 | if [ -z "$($RPC_PY get_bdevs | jq '.[] | select(.name=="Nvme0n1")')" ]; then | |
89 | error "Nvme0n1 bdev not found!" | |
90 | fi | |
91 | ||
92 | $RPC_PY construct_split_vbdev Nvme0n1 6 | |
93 | ||
94 | $RPC_PY construct_vhost_scsi_controller naa.Nvme0n1_scsi0.0 | |
95 | $RPC_PY add_vhost_scsi_lun naa.Nvme0n1_scsi0.0 0 Nvme0n1p0 | |
96 | $RPC_PY add_vhost_scsi_lun naa.Nvme0n1_scsi0.0 1 Nvme0n1p1 | |
97 | $RPC_PY add_vhost_scsi_lun naa.Nvme0n1_scsi0.0 2 Nvme0n1p2 | |
98 | $RPC_PY add_vhost_scsi_lun naa.Nvme0n1_scsi0.0 3 Nvme0n1p3 | |
99 | ||
100 | $RPC_PY construct_vhost_blk_controller naa.Nvme0n1_blk0.0 Nvme0n1p4 | |
101 | $RPC_PY construct_vhost_blk_controller naa.Nvme0n1_blk1.0 Nvme0n1p5 | |
102 | ||
103 | $RPC_PY construct_malloc_bdev 128 512 --name Malloc0 | |
104 | $RPC_PY construct_vhost_scsi_controller naa.Malloc0.0 | |
105 | $RPC_PY add_vhost_scsi_lun naa.Malloc0.0 0 Malloc0 | |
106 | ||
107 | $RPC_PY construct_malloc_bdev 128 4096 --name Malloc1 | |
108 | $RPC_PY construct_vhost_scsi_controller naa.Malloc1.0 | |
109 | $RPC_PY add_vhost_scsi_lun naa.Malloc1.0 0 Malloc1 | |
110 | ||
9f95a23c | 111 | vbdevs=$(discover_bdevs $rootdir $testdir/bdev.conf) |
11fdf7f2 TL |
112 | virtio_bdevs=$(jq -r '[.[].name] | join(":")' <<< $vbdevs) |
113 | virtio_with_unmap=$(jq -r '[.[] | select(.supported_io_types.unmap==true).name] | |
114 | | join(":")' <<< $vbdevs) | |
115 | } | |
116 | ||
9f95a23c TL |
117 | timing_enter vhost_run |
118 | vhost_run | |
119 | timing_exit vhost_run | |
11fdf7f2 TL |
120 | |
121 | timing_enter create_bdev_config | |
122 | create_bdev_config | |
123 | timing_exit create_bdev_config | |
124 | ||
125 | timing_enter run_spdk_fio | |
9f95a23c TL |
126 | run_spdk_fio $testdir/bdev.fio --filename=$virtio_bdevs --section=job_randwrite --section=job_randrw \ |
127 | --section=job_write --section=job_rw --spdk_conf=$testdir/bdev.conf | |
11fdf7f2 TL |
128 | report_test_completion "vhost_run_spdk_fio" |
129 | timing_exit run_spdk_fio | |
130 | ||
131 | timing_enter run_spdk_fio_unmap | |
9f95a23c TL |
132 | run_spdk_fio $testdir/bdev.fio --filename=$virtio_with_unmap --spdk_conf=$testdir/bdev.conf \ |
133 | --spdk_conf=$testdir/bdev.conf | |
11fdf7f2 TL |
134 | timing_exit run_spdk_fio_unmap |
135 | ||
136 | timing_enter create_kernel_vhost | |
137 | targetcli "/backstores/$targetcli_rd_name create name=ramdisk size=1GB" | |
138 | targetcli "/vhost create $kernel_vhost_disk" | |
139 | targetcli "/vhost/$kernel_vhost_disk/tpg1/luns create /backstores/$targetcli_rd_name/ramdisk" | |
140 | timing_exit create_kernel_vhost | |
141 | ||
142 | timing_enter setup_vm | |
143 | vm_no="0" | |
144 | vm_setup --disk-type=spdk_vhost_scsi --force=$vm_no --os=$os_image \ | |
145 | --disks="Nvme0n1_scsi0:Malloc0:Malloc1:$kernel_vhost_disk,kernel_vhost:Virtio0,virtio:\ | |
146 | Nvme0n1_blk0,spdk_vhost_blk:Nvme0n1_blk1,spdk_vhost_blk" \ | |
147 | --queue_num=8 --memory=6144 | |
148 | vm_run $vm_no | |
149 | ||
150 | timing_enter vm_wait_for_boot | |
9f95a23c | 151 | vm_wait_for_boot 300 $vm_no |
11fdf7f2 TL |
152 | timing_exit vm_wait_for_boot |
153 | ||
154 | timing_enter vm_scp_spdk | |
9f95a23c TL |
155 | touch $rootdir/spdk.tar.gz |
156 | tar --exclude="spdk.tar.gz" --exclude="*.o" --exclude="*.d" --exclude=".git" -C $rootdir -zcf $rootdir/spdk.tar.gz . | |
157 | vm_scp $vm_no $rootdir/spdk.tar.gz "127.0.0.1:/root" | |
11fdf7f2 TL |
158 | vm_ssh $vm_no "mkdir -p /root/spdk; tar -zxf /root/spdk.tar.gz -C /root/spdk --strip-components=1" |
159 | ||
9f95a23c TL |
160 | touch $rootdir/fio.tar.gz |
161 | tar --exclude="fio.tar.gz" --exclude="*.o" --exclude="*.d" --exclude=".git" -C $FIO_PATH -zcf $rootdir/fio.tar.gz . | |
162 | vm_scp $vm_no $rootdir/fio.tar.gz "127.0.0.1:/root" | |
11fdf7f2 TL |
163 | vm_ssh $vm_no "rm -rf /root/fio_src; mkdir -p /root/fio_src; tar -zxf /root/fio.tar.gz -C /root/fio_src --strip-components=1" |
164 | timing_exit vm_scp_spdk | |
165 | ||
166 | timing_enter vm_build_spdk | |
167 | nproc=$(vm_ssh $vm_no "nproc") | |
168 | vm_ssh $vm_no " cd /root/fio_src ; make clean ; make -j${nproc} ; make install" | |
169 | vm_ssh $vm_no " cd spdk ; ./configure --with-fio=/root/fio_src ; make clean ; make -j${nproc}" | |
170 | timing_exit vm_build_spdk | |
171 | ||
172 | vm_ssh $vm_no "/root/spdk/scripts/setup.sh" | |
173 | vbdevs=$(vm_ssh $vm_no ". /root/spdk/test/common/autotest_common.sh && discover_bdevs /root/spdk \ | |
174 | /root/spdk/test/vhost/initiator/bdev_pci.conf") | |
175 | virtio_bdevs=$(jq -r '[.[].name] | join(":")' <<< $vbdevs) | |
176 | virtio_with_unmap=$(jq -r '[.[] | select(.supported_io_types.unmap==true).name] | |
177 | | join(":")' <<< $vbdevs) | |
178 | timing_exit setup_vm | |
179 | ||
180 | timing_enter run_spdk_fio_pci | |
181 | vm_ssh $vm_no "LD_PRELOAD=/root/spdk/examples/bdev/fio_plugin/fio_plugin /root/fio_src/fio --ioengine=spdk_bdev \ | |
182 | /root/spdk/test/vhost/initiator/bdev.fio --filename=$virtio_bdevs --section=job_randwrite \ | |
183 | --section=job_randrw --section=job_write --section=job_rw \ | |
184 | --spdk_conf=/root/spdk/test/vhost/initiator/bdev_pci.conf --spdk_mem=1024 --spdk_single_seg=1" | |
185 | timing_exit run_spdk_fio_pci | |
186 | ||
187 | timing_enter run_spdk_fio_pci_unmap | |
188 | vm_ssh $vm_no "LD_PRELOAD=/root/spdk/examples/bdev/fio_plugin/fio_plugin /root/fio_src/fio --ioengine=spdk_bdev \ | |
189 | /root/spdk/test/vhost/initiator/bdev.fio --filename=$virtio_with_unmap \ | |
190 | --spdk_conf=/root/spdk/test/vhost/initiator/bdev_pci.conf --spdk_mem=1024 --spdk_single_seg=1" | |
191 | timing_exit run_spdk_fio_pci_unmap | |
192 | ||
193 | timing_enter vm_shutdown_all | |
194 | vm_shutdown_all | |
195 | timing_exit vm_shutdown_all | |
196 | ||
9f95a23c | 197 | rm -f *.state $rootdir/spdk.tar.gz $rootdir/fio.tar.gz $(get_vhost_dir)/Virtio0 |
11fdf7f2 TL |
198 | timing_enter remove_kernel_vhost |
199 | remove_kernel_vhost | |
200 | timing_exit remove_kernel_vhost | |
201 | ||
202 | $RPC_PY delete_nvme_controller Nvme0 | |
203 | ||
9f95a23c TL |
204 | timing_enter vhost_kill |
205 | vhost_kill | |
206 | timing_exit vhost_kill | |
207 | ||
208 | vhosttestfini |