xref: /spdk/test/spdkcli/vhost.sh (revision 2d590e74b469760b9a6ec4d06e1f559c96e3a101)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2018 Intel Corporation
4#  All rights reserved.
5#
6testdir=$(readlink -f $(dirname $0))
7rootdir=$(readlink -f $testdir/../..)
8source $rootdir/test/common/autotest_common.sh
9source $rootdir/test/spdkcli/common.sh
10
11MATCH_FILE="spdkcli_vhost.test"
12SPDKCLI_BRANCH="/"
13
14sample_aio=$SPDK_TEST_STORAGE/sample_aio
15sample_aio2=$SPDK_TEST_STORAGE/sample_aio2
16
17trap 'cleanup' EXIT
18timing_enter run_vhost_tgt
19run_vhost_tgt
20timing_exit run_vhost_tgt
21
22timing_enter spdkcli_create_bdevs_config
23$spdkcli_job "'/bdevs/malloc create 40 512 Malloc0' 'Malloc0' True
24'/bdevs/malloc create 32 512 Malloc1' 'Malloc1' True
25'/bdevs/malloc create 32 512 Malloc2' 'Malloc2' True
26'/bdevs/malloc create 32 4096 Malloc3' 'Malloc3' True
27'/bdevs/malloc create 32 4096 Malloc4' 'Malloc4' True
28'/bdevs/malloc create 32 4096 Malloc5' 'Malloc5' True
29'/bdevs/error create Malloc1' 'EE_Malloc1' True
30'/bdevs/error create Malloc4' 'EE_Malloc4' True
31'/bdevs/null create null_bdev0 32 512' 'null_bdev0' True
32'/bdevs/null create null_bdev1 32 512' 'null_bdev1' True
33"
34dd if=/dev/zero of="$sample_aio" bs=2048 count=5000
35dd if=/dev/zero of="$sample_aio2" bs=2048 count=5000
36$spdkcli_job "'/bdevs/aio create sample0 $sample_aio 512' 'sample0' True
37'/bdevs/aio create sample1 $sample_aio2 512' 'sample1' True
38"
39trtype=$($rootdir/scripts/gen_nvme.sh | jq -r '.config[].params | select(.name=="Nvme0").trtype')
40traddr=$($rootdir/scripts/gen_nvme.sh | jq -r '.config[].params | select(.name=="Nvme0").traddr')
41$spdkcli_job "'/bdevs/nvme create Nvme0 $trtype $traddr' 'Nvme0' True
42'/bdevs/split_disk bdev_split_create Nvme0n1 4' 'Nvme0n1p0' True
43"
44timing_exit spdkcli_create_bdevs_config
45
46timing_enter spdkcli_create_lvols_config
47$spdkcli_job "'/lvol_stores create lvs0 Malloc0' 'lvs0' True
48'/lvol_stores create lvs1 Malloc5' 'lvs1' True
49'/bdevs/logical_volume create lvol0 16 lvs0' 'lvs0/lvol0' True
50'/bdevs/logical_volume create lvol1 16 lvs0' 'lvs0/lvol1' True
51"
52timing_exit spdkcli_create_lvols_config
53
54timing_enter spdkcli_check_match_details
55$rootdir/scripts/spdkcli.py /lvol_stores/lvs0 show_details | jq -r -S '.' > $testdir/match_files/spdkcli_details_lvs.test
56$rootdir/test/app/match/match $testdir/match_files/spdkcli_details_lvs.test.match
57rm -f $testdir/match_files/spdkcli_details_lvs.test
58timing_exit spdkcli_check_match_details
59
60timing_enter spdkcli_create_vhosts_config
61$spdkcli_job "'vhost/block create vhost_blk1 Nvme0n1p0' 'Nvme0n1p0' True
62'vhost/block create vhost_blk2 Nvme0n1p1 0x1 readonly' 'Nvme0n1p1' True
63'vhost/scsi create vhost_scsi1' 'vhost_scsi1' True
64'vhost/scsi create vhost_scsi2' 'vhost_scsi2' True
65'vhost/scsi/vhost_scsi1 add_lun 0 Malloc2' 'Malloc2' True
66'vhost/scsi/vhost_scsi2 add_lun 0 Malloc3' 'Malloc3' True
67'vhost/scsi/vhost_scsi2 add_lun 1 Nvme0n1p2' 'Nvme0n1p2' True
68'vhost/scsi/vhost_scsi2 add_lun 2 Nvme0n1p3' 'Nvme0n1p3' True
69'vhost/scsi/vhost_scsi1 set_coalescing 20 1000000' '' True
70"
71timing_exit spdkcli_create_vhosts_config
72
73timing_enter spdkcli_check_match
74check_match
75timing_exit spdkcli_check_match
76
77timing_enter spdkcli_save_config
78$spdkcli_job "'save_config $testdir/config.json'
79'save_subsystem_config $testdir/config_bdev.json bdev'
80'save_subsystem_config $testdir/config_vhost_scsi.json vhost_scsi'
81'save_subsystem_config $testdir/config_vhost_blk.json vhost_blk'
82"
83timing_exit spdkcli_save_config
84
85timing_enter spdkcli_check_match_details
86$rootdir/scripts/spdkcli.py vhost/scsi/vhost_scsi1/Target_0 show_details | jq -r -S '.' > $testdir/match_files/spdkcli_details_vhost_target.test
87$rootdir/test/app/match/match $testdir/match_files/spdkcli_details_vhost_target.test.match
88rm -f $testdir/match_files/spdkcli_details_vhost_target.test
89
90$rootdir/scripts/spdkcli.py bdevs/split_disk/Nvme0n1p0 show_details | jq -r -S '.' > $testdir/match_files/spdkcli_details_vhost.test
91$rootdir/test/app/match/match $testdir/match_files/spdkcli_details_vhost.test.match
92rm -f $testdir/match_files/spdkcli_details_vhost.test
93
94$rootdir/scripts/spdkcli.py vhost/scsi/vhost_scsi1 show_details | jq -r -S '.' > $testdir/match_files/spdkcli_details_vhost_ctrl.test
95$rootdir/test/app/match/match $testdir/match_files/spdkcli_details_vhost_ctrl.test.match
96rm -f $testdir/match_files/spdkcli_details_vhost_ctrl.test
97timing_exit spdkcli_check_match_details
98
99timing_enter spdkcli_clear_config
100$spdkcli_job "'vhost/scsi/vhost_scsi2 remove_target 2' 'Nvme0n1p3'
101'vhost/scsi/vhost_scsi2 remove_target 1' 'Nvme0n1p2'
102'vhost/scsi/vhost_scsi2 remove_target 0' 'Malloc3'
103'vhost/scsi/vhost_scsi1 remove_target 0' 'Malloc2'
104'vhost/scsi delete vhost_scsi2' 'vhost_scsi2'
105'vhost/scsi delete vhost_scsi1' 'vhost_scsi1'
106'vhost/block delete vhost_blk2' 'vhost_blk2'
107'vhost/block delete vhost_blk1' 'vhost_blk1'
108'/bdevs/split_disk bdev_split_delete Nvme0n1' 'Nvme0n1p0'
109'/bdevs/aio delete sample0' 'sample0'
110'/bdevs/aio delete_all' 'sample1'
111'/bdevs/nvme delete Nvme0' 'Nvme0'
112'/bdevs/null delete null_bdev0' 'null_bdev0'
113'/bdevs/null delete_all' 'null_bdev1'
114'/bdevs/logical_volume delete lvs0/lvol0' 'lvs0/lvol0'
115'/bdevs/logical_volume delete_all' 'lvs0/lvol1'
116'/lvol_stores delete lvs0' 'lvs0'
117'/lvol_stores delete_all' 'lvs1'
118'/bdevs/error delete EE_Malloc1' 'EE_Malloc1'
119'/bdevs/error delete_all' 'EE_Malloc4'
120'/bdevs/malloc delete Malloc0' 'Malloc0'
121'/bdevs/malloc delete_all' 'Malloc1'
122"
123timing_exit spdkcli_clear_config
124
125timing_enter spdkcli_load_config
126$spdkcli_job "'load_config $testdir/config.json'
127'/lvol_stores create lvs0 Malloc0' 'lvs0' True
128'/lvol_stores create lvs1 Malloc5' 'lvs1' True
129'/bdevs/logical_volume create lvol0 16 lvs0' 'lvs0/lvol0' True
130'/bdevs/logical_volume create lvol1 16 lvs0' 'lvs0/lvol1' True
131"
132check_match
133$spdk_clear_config_py clear_config
134# FIXME: remove this sleep when NVMe driver will be fixed to wait for reset to complete
135sleep 2
136$spdkcli_job "'load_subsystem_config $testdir/config_bdev.json'
137'load_subsystem_config $testdir/config_vhost_scsi.json'
138'load_subsystem_config $testdir/config_vhost_blk.json'
139'/lvol_stores create lvs0 Malloc0' 'lvs0' True
140'/lvol_stores create lvs1 Malloc5' 'lvs1' True
141'/bdevs/logical_volume create lvol0 16 lvs0' 'lvs0/lvol0' True
142'/bdevs/logical_volume create lvol1 16 lvs0' 'lvs0/lvol1' True
143"
144check_match
145$spdk_clear_config_py clear_config
146rm -f $testdir/config.json
147rm -f $testdir/config_bdev.json
148rm -f $testdir/config_vhost_scsi.json
149rm -f $testdir/config_vhost_blk.json
150rm -f "$sample_aio" "$sample_aio2"
151timing_exit spdkcli_load_config
152
153killprocess $vhost_tgt_pid
154