xref: /spdk/test/spdkcli/vhost.sh (revision dc93bd859ba915d3e5993c0ce4b9332984c6dea2)
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 False' 'vhost_scsi1' True
64'vhost/scsi create vhost_scsi2 True' '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'vhost/scsi/vhost_scsi2 start vhost_scsi2' 'vhost_scsi2' True
71"
72timing_exit spdkcli_create_vhosts_config
73
74timing_enter spdkcli_check_match
75check_match
76timing_exit spdkcli_check_match
77
78timing_enter spdkcli_save_config
79$spdkcli_job "'save_config $testdir/config.json'
80'save_subsystem_config $testdir/config_bdev.json bdev'
81'save_subsystem_config $testdir/config_vhost_scsi.json vhost_scsi'
82'save_subsystem_config $testdir/config_vhost_blk.json vhost_blk'
83"
84timing_exit spdkcli_save_config
85
86timing_enter spdkcli_check_match_details
87$rootdir/scripts/spdkcli.py vhost/scsi/vhost_scsi1/Target_0 show_details | jq -r -S '.' > $testdir/match_files/spdkcli_details_vhost_target.test
88$rootdir/test/app/match/match $testdir/match_files/spdkcli_details_vhost_target.test.match
89rm -f $testdir/match_files/spdkcli_details_vhost_target.test
90
91$rootdir/scripts/spdkcli.py bdevs/split_disk/Nvme0n1p0 show_details | jq -r -S '.' > $testdir/match_files/spdkcli_details_vhost.test
92$rootdir/test/app/match/match $testdir/match_files/spdkcli_details_vhost.test.match
93rm -f $testdir/match_files/spdkcli_details_vhost.test
94
95$rootdir/scripts/spdkcli.py vhost/scsi/vhost_scsi1 show_details | jq -r -S '.' > $testdir/match_files/spdkcli_details_vhost_ctrl.test
96$rootdir/test/app/match/match $testdir/match_files/spdkcli_details_vhost_ctrl.test.match
97rm -f $testdir/match_files/spdkcli_details_vhost_ctrl.test
98timing_exit spdkcli_check_match_details
99
100timing_enter spdkcli_clear_config
101$spdkcli_job "'vhost/scsi/vhost_scsi2 remove_target 2' 'Nvme0n1p3'
102'vhost/scsi/vhost_scsi2 remove_target 1' 'Nvme0n1p2'
103'vhost/scsi/vhost_scsi2 remove_target 0' 'Malloc3'
104'vhost/scsi/vhost_scsi1 remove_target 0' 'Malloc2'
105'vhost/scsi delete vhost_scsi2' 'vhost_scsi2'
106'vhost/scsi delete vhost_scsi1' 'vhost_scsi1'
107'vhost/block delete vhost_blk2' 'vhost_blk2'
108'vhost/block delete vhost_blk1' 'vhost_blk1'
109'/bdevs/split_disk bdev_split_delete Nvme0n1' 'Nvme0n1p0'
110'/bdevs/aio delete sample0' 'sample0'
111'/bdevs/aio delete_all' 'sample1'
112'/bdevs/nvme delete Nvme0' 'Nvme0'
113'/bdevs/null delete null_bdev0' 'null_bdev0'
114'/bdevs/null delete_all' 'null_bdev1'
115'/bdevs/logical_volume delete lvs0/lvol0' 'lvs0/lvol0'
116'/bdevs/logical_volume delete_all' 'lvs0/lvol1'
117'/lvol_stores delete lvs0' 'lvs0'
118'/lvol_stores delete_all' 'lvs1'
119'/bdevs/error delete EE_Malloc1' 'EE_Malloc1'
120'/bdevs/error delete_all' 'EE_Malloc4'
121'/bdevs/malloc delete Malloc0' 'Malloc0'
122'/bdevs/malloc delete_all' 'Malloc1'
123"
124timing_exit spdkcli_clear_config
125
126# Make sure we wait long enough for the nvme ctrl to disappear, otherwise
127# we are at risk of hitting -EPERM while loading bdev configuration.
128xtrace_disable_per_cmd wait_for_all_nvme_ctrls_to_detach
129
130timing_enter spdkcli_load_config
131$spdkcli_job "'load_config $testdir/config.json'
132'/lvol_stores create lvs0 Malloc0' 'lvs0' True
133'/lvol_stores create lvs1 Malloc5' 'lvs1' True
134'/bdevs/logical_volume create lvol0 16 lvs0' 'lvs0/lvol0' True
135'/bdevs/logical_volume create lvol1 16 lvs0' 'lvs0/lvol1' True
136"
137check_match
138$spdk_clear_config_py clear_config
139
140# Make sure we wait long enough for the nvme ctrl to disappear, otherwise
141# we are at risk of hitting -EPERM while loading bdev configuration.
142xtrace_disable_per_cmd wait_for_all_nvme_ctrls_to_detach
143
144$spdkcli_job "'load_subsystem_config $testdir/config_bdev.json'
145'load_subsystem_config $testdir/config_vhost_scsi.json'
146'load_subsystem_config $testdir/config_vhost_blk.json'
147'/lvol_stores create lvs0 Malloc0' 'lvs0' True
148'/lvol_stores create lvs1 Malloc5' 'lvs1' True
149'/bdevs/logical_volume create lvol0 16 lvs0' 'lvs0/lvol0' True
150'/bdevs/logical_volume create lvol1 16 lvs0' 'lvs0/lvol1' True
151"
152check_match
153$spdk_clear_config_py clear_config
154rm -f $testdir/config.json
155rm -f $testdir/config_bdev.json
156rm -f $testdir/config_vhost_scsi.json
157rm -f $testdir/config_vhost_blk.json
158rm -f "$sample_aio" "$sample_aio2"
159timing_exit spdkcli_load_config
160
161killprocess $vhost_tgt_pid
162