xref: /spdk/test/nvmf/host/dma.sh (revision c680e3a05b1a903c18bf3f75b732765607126f45)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2021 Intel Corporation
4#  All rights reserved.
5#
6
7testdir=$(readlink -f $(dirname $0))
8rootdir=$(readlink -f $testdir/../../..)
9source $rootdir/test/common/autotest_common.sh
10source $rootdir/test/nvmf/common.sh
11
12if [ "$TEST_TRANSPORT" != "rdma" ]; then
13	exit 0
14fi
15
16MALLOC_BDEV_SIZE=256
17MALLOC_BLOCK_SIZE=512
18subsystem="0"
19
20function gen_malloc_json() {
21	jq . <<- JSON
22		{
23		  "subsystems": [
24		    {
25		      "subsystem": "bdev",
26		      "config": [
27		        {
28		          "method": "bdev_malloc_create",
29		          "params": {
30		            "name": "Malloc0",
31		            "num_blocks": 131072,
32		            "block_size": 512,
33		            "uuid": "e1c24cb1-dd44-4be6-8d67-de92a332013f",
34		            "optimal_io_boundary": 2
35		          }
36		        },
37		        {
38		          "method": "bdev_wait_for_examine"
39		        }
40		      ]
41		    }
42		  ]
43		}
44	JSON
45}
46
47function gen_lvol_nvme_json() {
48	local subsystem=$1
49
50	jq . <<- JSON
51		{
52		  "subsystems": [
53		    {
54		      "subsystem": "bdev",
55		      "config": [
56		        {
57		          "method": "bdev_nvme_attach_controller",
58		          "params": {
59		            "name": "Nvme${subsystem}",
60		            "trtype": "$TEST_TRANSPORT",
61		            "adrfam": "IPv4",
62		            "traddr": "$NVMF_FIRST_TARGET_IP",
63		            "trsvcid": "$NVMF_PORT",
64		            "subnqn": "nqn.2016-06.io.spdk:cnode${subsystem}"
65		          }
66		        },
67		        {
68		          "method": "bdev_lvol_create_lvstore",
69		          "params": {
70		            "bdev_name": "Nvme${subsystem}n1",
71		            "lvs_name": "lvs${subsystem}"
72		          }
73		        },
74		        {
75		          "method": "bdev_lvol_create",
76		          "params": {
77		            "lvol_name": "lvol${subsystem}",
78		            "size": 134217728,
79		            "thin_provision": true,
80		            "lvs_name": "lvs${subsystem}"
81		          }
82		        },
83		        {
84		          "method": "bdev_wait_for_examine"
85		        }
86		      ]
87		    }
88		  ]
89		}
90	JSON
91}
92
93nvmftestinit
94nvmfappstart -m 0x3
95
96$rpc_py nvmf_create_transport $NVMF_TRANSPORT_OPTS
97$rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE -b Malloc0
98$rpc_py nvmf_create_subsystem nqn.2016-06.io.spdk:cnode$subsystem -a -s SPDK00000000000001
99$rpc_py nvmf_subsystem_add_ns nqn.2016-06.io.spdk:cnode$subsystem Malloc0
100$rpc_py nvmf_subsystem_add_listener nqn.2016-06.io.spdk:cnode$subsystem -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT
101
102# test memory translation
103# test_dma doesn't use RPC, but we change the sock path since nvmf target is already using the default RPC sock
104"$rootdir/test/dma/test_dma/test_dma" -q 16 -o 4096 -w randrw -M 70 -t 5 -m 0xc --json <(gen_nvmf_target_json $subsystem) -b "Nvme${subsystem}n1" -f -x translate -r /var/tmp/dma.sock
105
106# test data pull/push with split against local malloc
107"$rootdir/test/dma/test_dma/test_dma" -q 16 -o 4096 -w randrw -M 70 -t 5 -m 0xc --json <(gen_malloc_json) -b "Malloc0" -x pull_push -r /var/tmp/dma.sock
108
109# test memzero with logical volumes. All clusters are unallocated, read should trigger memzero
110"$rootdir/test/dma/test_dma/test_dma" -q 16 -o 4096 -w randread -M 70 -t 5 -m 0xc --json <(gen_lvol_nvme_json $subsystem) -b "lvs${subsystem}/lvol${subsystem}" -f -x memzero -r /var/tmp/dma.sock
111
112# clear blob metadata
113$rootdir/build/examples/perf -q 16 -o 4096 -w write -t 1 -r "trtype:$TEST_TRANSPORT adrfam:IPV4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT"
114
115# test memory translation with logical volumes
116"$rootdir/test/dma/test_dma/test_dma" -q 16 -o 4096 -w randrw -M 70 -t 5 -m 0xc --json <(gen_lvol_nvme_json $subsystem) -b "lvs${subsystem}/lvol${subsystem}" -f -x translate -r /var/tmp/dma.sock
117
118trap - SIGINT SIGTERM EXIT
119
120nvmftestfini
121