1 JSON_DIR
=$
(readlink
-f $
(dirname ${BASH_SOURCE[0]}))
2 SPDK_BUILD_DIR
=$JSON_DIR/..
/..
/
3 source $JSON_DIR/..
/common
/autotest_common.sh
4 source $JSON_DIR/..
/nvmf
/common.sh
6 spdk_rpc_py
="$SPDK_BUILD_DIR/scripts/rpc.py -s /var/tmp/spdk.sock"
7 spdk_clear_config_py
="$JSON_DIR/clear_config.py -s /var/tmp/spdk.sock"
8 initiator_rpc_py
="$SPDK_BUILD_DIR/scripts/rpc.py -s /var/tmp/virtio.sock"
9 initiator_clear_config_py
="$JSON_DIR/clear_config.py -s /var/tmp/virtio.sock"
10 base_json_config
=$JSON_DIR/base_config.json
11 last_json_config
=$JSON_DIR/last_config.json
12 full_config
=$JSON_DIR/full_config.json
13 base_bdevs
=$JSON_DIR/bdevs_base.txt
14 last_bdevs
=$JSON_DIR/bdevs_last.txt
15 null_json_config
=$JSON_DIR/null_json_config.json
17 function run_spdk_tgt
() {
18 echo "Running spdk target"
19 $SPDK_BUILD_DIR/app
/spdk_tgt
/spdk_tgt
-m 0x1 -p 0 -s 4096 --wait-for-rpc &
22 echo "Waiting for app to run..."
23 waitforlisten
$spdk_tgt_pid
24 echo "spdk_tgt started - pid=$spdk_tgt_pid but waits for subsystem initialization"
29 function load_nvme
() {
30 echo '{"subsystems": [' > nvme_config.json
31 $SPDK_BUILD_DIR/scripts
/gen_nvme.sh
--json >> nvme_config.json
32 echo ']}' >> nvme_config.json
33 $rpc_py load_config
< nvme_config.json
37 function run_initiator
() {
38 $SPDK_BUILD_DIR/app
/spdk_tgt
/spdk_tgt
-m 0x2 -p 0 -g -u -s 1024 -r /var
/tmp
/virtio.sock
--wait-for-rpc &
40 waitforlisten
$virtio_pid /var
/tmp
/virtio.sock
43 function upload_vhost
() {
44 $rpc_py construct_split_vbdev Nvme0n1
8
45 $rpc_py construct_vhost_scsi_controller sample1
46 $rpc_py add_vhost_scsi_lun sample1
0 Nvme0n1p3
47 $rpc_py add_vhost_scsi_lun sample1
1 Nvme0n1p4
48 $rpc_py set_vhost_controller_coalescing sample1
1 100
49 $rpc_py construct_vhost_blk_controller sample2 Nvme0n1p5
50 $rpc_py construct_vhost_nvme_controller sample3
16
51 $rpc_py add_vhost_nvme_ns sample3 Nvme0n1p6
54 function kill_targets
() {
55 if [ ! -z $virtio_pid ]; then
56 killprocess
$virtio_pid
58 if [ ! -z $spdk_tgt_pid ]; then
59 killprocess
$spdk_tgt_pid
63 # Compare two JSON files.
65 # NOTE: Order of objects in JSON can change by just doing loads -> dumps so all JSON objects (not arrays) are sorted by
66 # config_filter.py script. Sorted output is used to compare JSON output.
70 local tmp_file_1
=$
(mktemp
${1}.XXX
)
71 local tmp_file_2
=$
(mktemp
${2}.XXX
)
74 cat $1 |
$JSON_DIR/config_filter.py
-method "sort" > $tmp_file_1
75 cat $2 |
$JSON_DIR/config_filter.py
-method "sort" > $tmp_file_2
77 if ! diff -u $tmp_file_1 $tmp_file_2; then
81 rm $tmp_file_1 $tmp_file_2
85 # This function test if json config was properly saved and loaded.
86 # 1. Get a list of bdevs and save it to the file "base_bdevs".
87 # 2. Save only configuration of the running spdk_tgt to the file "base_json_config"
88 # (global parameters are not saved).
89 # 3. Clear configuration of the running spdk_tgt.
90 # 4. Save only configuration of the running spdk_tgt to the file "null_json_config"
91 # (global parameters are not saved).
92 # 5. Check if configuration of the running spdk_tgt is cleared by checking
93 # if the file "null_json_config" doesn't have any configuration.
94 # 6. Load the file "base_json_config" to the running spdk_tgt.
95 # 7. Get a list of bdevs and save it to the file "last_bdevs".
96 # 8. Save only configuration of the running spdk_tgt to the file "last_json_config".
97 # 9. Check if the file "base_json_config" matches the file "last_json_config".
98 # 10. Check if the file "base_bdevs" matches the file "last_bdevs".
99 # 11. Remove all files.
100 function test_json_config
() {
101 $rpc_py get_bdevs | jq
'.|sort_by(.name)' > $base_bdevs
102 $rpc_py save_config
> $full_config
103 $JSON_DIR/config_filter.py
-method "delete_global_parameters" < $full_config > $base_json_config
104 $clear_config_py clear_config
105 $rpc_py save_config |
$JSON_DIR/config_filter.py
-method "delete_global_parameters" > $null_json_config
106 if [ "[]" != "$(jq '.subsystems | map(select(.config != null)) | map(select(.config != []))' $null_json_config)" ]; then
107 echo "Config has not been cleared"
110 $rpc_py load_config
< $base_json_config
111 $rpc_py get_bdevs | jq
'.|sort_by(.name)' > $last_bdevs
112 $rpc_py save_config |
$JSON_DIR/config_filter.py
-method "delete_global_parameters" > $last_json_config
114 json_diff
$base_json_config $last_json_config
115 json_diff
$base_bdevs $last_bdevs
116 remove_config_files_after_test_json_config
119 function remove_config_files_after_test_json_config
() {
120 rm -f $last_bdevs $base_bdevs
121 rm -f $last_json_config $base_json_config
122 rm -f $full_config $null_json_config
125 function create_pmem_bdev_subsytem_config
() {
126 $rpc_py create_pmem_pool
/tmp
/pool_file1
128 512
127 $rpc_py construct_pmem_bdev
-n pmem1
/tmp
/pool_file1
130 function clear_pmem_bdev_subsystem_config
() {
131 $clear_config_py clear_config
132 $rpc_py delete_pmem_pool
/tmp
/pool_file1
135 function create_rbd_bdev_subsystem_config
() {
137 $rpc_py construct_rbd_bdev
$RBD_POOL $RBD_NAME 4096
140 function clear_rbd_bdev_subsystem_config
() {
141 $clear_config_py clear_config
145 function create_bdev_subsystem_config
() {
146 $rpc_py construct_split_vbdev Nvme0n1
2
147 $rpc_py construct_null_bdev Null0
32 512
148 $rpc_py construct_malloc_bdev
128 512 --name Malloc0
149 $rpc_py construct_malloc_bdev
64 4096 --name Malloc1
150 $rpc_py construct_malloc_bdev
8 1024 --name Malloc2
151 if [ $SPDK_TEST_CRYPTO -eq 1 ]; then
152 $rpc_py construct_malloc_bdev
8 1024 --name Malloc3
153 if [ $
(lspci
-d:37c8 |
wc -l) -eq 0 ]; then
154 $rpc_py construct_crypto_bdev
-b Malloc3
-c CryMalloc3
-d crypto_aesni_mb
-k 0123456789123456
156 $rpc_py construct_crypto_bdev
-b Malloc3
-c CryMalloc3
-d crypto_qat
-k 0123456789123456
159 $rpc_py construct_error_bdev Malloc2
160 if [ $
(uname
-s) = Linux
]; then
161 dd if=/dev
/zero of
=/tmp
/sample_aio bs
=2048 count
=5000
162 $rpc_py construct_aio_bdev
/tmp
/sample_aio aio_disk
1024
164 $rpc_py construct_lvol_store
-c 1048576 Nvme0n1p0 lvs_test
165 $rpc_py construct_lvol_bdev
-l lvs_test lvol0
32
166 $rpc_py construct_lvol_bdev
-l lvs_test
-t lvol1
32
167 $rpc_py snapshot_lvol_bdev lvs_test
/lvol0 snapshot0
168 $rpc_py clone_lvol_bdev lvs_test
/snapshot0 clone0
171 function create_nvmf_subsystem_config
() {
173 RDMA_IP_LIST
=$
(get_available_rdma_ips
)
174 NVMF_FIRST_TARGET_IP
=$
(echo "$RDMA_IP_LIST" |
head -n 1)
175 if [ -z $NVMF_FIRST_TARGET_IP ]; then
176 echo "Error: no NIC for nvmf test"
180 bdevs
="$($rpc_py construct_malloc_bdev 64 512) "
181 bdevs
+="$($rpc_py construct_malloc_bdev 64 512)"
182 $rpc_py nvmf_subsystem_create nqn
.2016-06.io.spdk
:cnode1
-a -s SPDK00000000000001
183 for bdev
in $bdevs; do
184 $rpc_py nvmf_subsystem_add_ns nqn
.2016-06.io.spdk
:cnode1
$bdev
186 $rpc_py nvmf_subsystem_add_listener nqn
.2016-06.io.spdk
:cnode1
-t RDMA
-a $NVMF_FIRST_TARGET_IP -s "$NVMF_PORT"
189 function clear_nvmf_subsystem_config
() {
190 $clear_config_py clear_config
193 function clear_bdev_subsystem_config
() {
194 $rpc_py destroy_lvol_bdev lvs_test
/clone0
195 $rpc_py destroy_lvol_bdev lvs_test
/lvol0
196 $rpc_py destroy_lvol_bdev lvs_test
/snapshot0
197 $rpc_py destroy_lvol_store
-l lvs_test
198 $clear_config_py clear_config
199 if [ $
(uname
-s) = Linux
]; then
200 rm -f /tmp
/sample_aio
204 # In this test, target is spdk_tgt or virtio_initiator.
205 # 1. Save current spdk config to full_config
206 # and save only global parameters to the file "base_json_config".
207 # 2. Exit the running spdk target.
208 # 3. Start the spdk target and wait for loading config.
209 # 4. Load global parameters and configuration to the spdk target from the file full_config.
210 # 5. Save json config to the file "full_config".
211 # 6. Save only global parameters to the file "last_json_config".
212 # 7. Check if the file "base_json_config" matches the file "last_json_config".
213 # 8. Delete all files.
214 function test_global_params
() {
216 $rpc_py save_config
> $full_config
217 $JSON_DIR/config_filter.py
-method "delete_configs" < $full_config > $base_json_config
218 if [ $target == "spdk_tgt" ]; then
219 killprocess
$spdk_tgt_pid
221 elif [ $target == "virtio_initiator" ]; then
222 killprocess
$virtio_pid
225 echo "Target is not specified for test_global_params"
228 $rpc_py load_config
< $full_config
229 $rpc_py save_config
> $full_config
230 $JSON_DIR/config_filter.py
-method "delete_configs" < $full_config > $last_json_config
232 json_diff
$base_json_config $last_json_config
233 rm $base_json_config $last_json_config
237 function on_error_exit
() {
239 echo "Error on $1 - $2"
240 remove_config_files_after_test_json_config
241 rpc_py
="$spdk_rpc_py"
242 clear_config_py
="$spdk_clear_config_py"
243 clear_bdev_subsystem_config