-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathrc
More file actions
603 lines (494 loc) · 12.9 KB
/
rc
File metadata and controls
603 lines (494 loc) · 12.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+
# Copyright (C) 2018 Johannes Thumshirn
#
# Test specific to NVMe devices
. common/rc
. common/nvme
. common/multipath-over-rdma
_NVMET_TRTYPES_is_valid() {
local type
for type in $NVMET_TRTYPES; do
case $type in
loop | rdma | tcp | fc)
;;
*)
SKIP_REASONS+=("Invalid NVMET_TRTYPE value: $type")
return 1
;;
esac
done
return 0
}
_set_nvme_trtype() {
local index=$1
local -a types
read -r -a types <<< "$NVMET_TRTYPES"
if [[ -z $index ]]; then
echo ${#types[@]}
return
fi
nvme_trtype=${types[index]}
COND_DESC="tr=${nvme_trtype}"
}
_set_nvmet_blkdev_type() {
local index=$1
local -a types
read -r -a types <<< "$NVMET_BLKDEV_TYPES"
if [[ -z $index ]]; then
echo ${#types[@]}
return
fi
nvmet_blkdev_type=${types[index]}
COND_DESC="bd=${nvmet_blkdev_type}"
}
group_setup() {
if [[ -n "${nvme_target_control}" ]]; then
NVMET_TRTYPES="$(${nvme_target_control} config --show-trtype)"
NVMET_BLKDEV_TYPES="$(${nvme_target_control} config --show-blkdev-type)"
fi
}
group_requires() {
_have_root
_NVMET_TRTYPES_is_valid
_have_nvme_cli_with_json_support
}
group_device_requires() {
_require_test_dev_is_nvme
}
_require_test_dev_is_nvme_pci() {
if [[ ! "$(readlink --canonicalize "$TEST_DEV_SYSFS/device")" =~ devices/pci ]]; then
SKIP_REASONS+=("$TEST_DEV is not a PCI NVMe device")
return 1
fi
return 0
}
_require_test_dev_is_not_nvme_multipath() {
if [[ "$(readlink --canonicalize "$TEST_DEV_SYSFS/device")" =~ /nvme-subsystem/ ]]; then
SKIP_REASONS+=("$TEST_DEV is a NVMe multipath device")
return 1
fi
return 0
}
_nvme_dev_support_native_multipath() {
if [[ "$(readlink --canonicalize "$TEST_DEV_SYSFS/device")" =~ /nvme-subsystem/ ]]; then
return 0
fi
return 1
}
_nvme_get_pci_from_dev_sysfs() {
if _nvme_dev_support_native_multipath; then
readlink --canonicalize "$TEST_DEV_SYSFS"/multipath/nvme*c*n*/device | \
grep -Eo '[0-9a-f]{4,5}:[0-9a-f]{2}:[0-9a-f]{2}\.[0-9a-f]' | \
tail -1
else
_get_pci_dev_from_blkdev
fi
}
_require_test_dev_support_sed() {
if ! nvme sed discover "$TEST_DEV" &> /dev/null; then
SKIP_REASONS+=("$TEST_DEV doesn't support SED operations")
return 1
fi
if nvme sed discover "$TEST_DEV" | grep -q "Locking Supported.*: yes"; then
return 0
fi
SKIP_REASONS+=("$TEST_DEV doesn't support SED operations")
return 1
}
_require_nvme_cli_auth() {
if ! nvme gen-dhchap-key --nqn nvmf-test-subsys > /dev/null 2>&1 ; then
SKIP_REASONS+=("nvme gen-dhchap-key command missing")
return 1
fi
return 0
}
_require_nvme_cli_tls() {
if ! nvme gen-tls-key --subsysnqn nvmf-test-subsys > /dev/null 2>&1; then
SKIP_REASONS+=("nvme gen-tls-key command missing")
return 1
fi
return 0
}
_require_nvme_cli_sed() {
if ! nvme sed help &> /dev/null; then
SKIP_REASONS+=("nvme doesn't support sed plugin")
return 1
fi
return 0
}
_require_kernel_nvme_fabrics_feature() {
local feature="$1"
_have_driver nvme-fabrics || return 1
if ! [[ -r /dev/nvme-fabrics ]]; then
SKIP_REASONS+=("/dev/nvme-fabrics not available")
return 1;
fi
if ! grep -qe "${feature}" /dev/nvme-fabrics; then
SKIP_REASONS+=("nvme-fabrics does not support ${feature}")
return 1;
fi
return 0
}
_require_kernel_nvme_target() {
if [[ -n "${nvme_target_control}" ]]; then
SKIP_REASONS+=("Linux kernel soft target not available")
return 1;
fi
return 0
}
_require_remote_nvme_target() {
if [ -z "${nvme_target_control}" ]; then
SKIP_REASONS+=("Remote target required but NVME_TARGET_CONTROL is not set")
return 1
fi
return 0
}
_test_dev_nvme_ctrl() {
echo "/dev/char/$(cat "${TEST_DEV_SYSFS}/device/dev")"
}
_test_dev_nvme_nsid() {
cat "${TEST_DEV_SYSFS}/nsid"
}
_nvme_get_ctrl_list() {
local subsys
local c
subsys=$(readlink "${TEST_DEV_SYSFS}/device/subsystem")
case $subsys in
*/nvme)
readlink --canonicalize "${TEST_DEV_SYSFS}/device"
;;
*/nvme-subsystem)
for c in "${TEST_DEV_SYSFS}"/device/nvme*; do
[[ -L "$c" ]] || continue
[[ -f "$c/dev" ]] && readlink --canonicalize "$c"
done
;;
esac
}
_nvme_calc_rand_io_size() {
local img_size_mb
local io_size_kb
img_size_mb="$(convert_to_mb "$1")"
io_size_kb="$(((img_size_mb * 1024) / $(nproc)))"
echo "${io_size_kb}k"
}
_nvme_discover() {
local trtype="$1"
local port="$2"
local traddr="$def_traddr"
local trsvcid="$def_trsvcid"
ARGS=(--transport "${trtype}")
ARGS+=(--hostnqn="${def_hostnqn}")
ARGS+=(--hostid="${def_hostid}")
if [[ "${trtype}" = "fc" ]]; then
ARGS+=(--traddr "$(_fc_traddr "$port")")
ARGS+=(--host-traddr "$(_fc_host_traddr "$port")")
elif [[ "${trtype}" != "loop" ]]; then
ARGS+=(--traddr "${traddr}" --trsvcid "${trsvcid}")
fi
nvme discover "${ARGS[@]}"
}
_remove_nvmet_allow_hosts() {
local nvmet_subsystem="$1"
local nvmet_hostnqn="$2"
local cfs_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
rm "${cfs_path}/allowed_hosts/${nvmet_hostnqn}"
}
_create_nvmet_passthru() {
local nvmet_subsystem="$1"
local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
local passthru_path="${subsys_path}/passthru"
mkdir -p "${subsys_path}"
echo 0 > "${subsys_path}/attr_allow_any_host"
_test_dev_nvme_ctrl > "${passthru_path}/device_path"
echo 1 > "${passthru_path}/enable"
if [[ -f "${passthru_path}/clear_ids" ]]; then
echo 1 > "${passthru_path}/clear_ids"
fi
}
_remove_nvmet_passhtru() {
local nvmet_subsystem="$1"
local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
local passthru_path="${subsys_path}/passthru"
echo 0 > "${passthru_path}/enable"
rm -f "${subsys_path}"/allowed_hosts/*
rmdir "${subsys_path}"
}
_set_nvmet_hostkey() {
local nvmet_hostnqn="$1"
local nvmet_hostkey="$2"
local cfs_path="${NVMET_CFS}/hosts/${nvmet_hostnqn}"
echo "${nvmet_hostkey}" > \
"${cfs_path}/dhchap_key"
}
_set_nvmet_ctrlkey() {
local nvmet_hostnqn="$1"
local nvmet_ctrlkey="$2"
local cfs_path="${NVMET_CFS}/hosts/${nvmet_hostnqn}"
echo "${nvmet_ctrlkey}" > \
"${cfs_path}/dhchap_ctrl_key"
}
_set_nvmet_hash() {
local nvmet_hostnqn="$1"
local nvmet_hash="$2"
local cfs_path="${NVMET_CFS}/hosts/${nvmet_hostnqn}"
echo "${nvmet_hash}" > \
"${cfs_path}/dhchap_hash"
}
_set_nvmet_dhgroup() {
local nvmet_hostnqn="$1"
local nvmet_dhgroup="$2"
local cfs_path="${NVMET_CFS}/hosts/${nvmet_hostnqn}"
echo "${nvmet_dhgroup}" > \
"${cfs_path}/dhchap_dhgroup"
}
_enable_nvmet_ns() {
local subsysnqn="${def_subsysnqn}"
local nsid="${1:-1}"
cfs_path="${NVMET_CFS}/subsystems/${subsysnqn}"
ns_path="${cfs_path}/namespaces/${nsid}"
echo 1 > "${ns_path}/enable"
}
_disable_nvmet_ns() {
local subsysnqn="${def_subsysnqn}"
local nsid="${1:-1}"
cfs_path="${NVMET_CFS}/subsystems/${subsysnqn}"
ns_path="${cfs_path}/namespaces/${nsid}"
echo 0 > "${ns_path}/enable"
}
_set_nvmet_ns_uuid() {
local subsysnqn="${def_subsysnqn}"
local nsid="${1:-1}"
local uuid="${2:-$(uuidgen)}"
cfs_path="${NVMET_CFS}/subsystems/${subsysnqn}"
ns_path="${cfs_path}/namespaces/${nsid}"
printf "%s" "${uuid}" > "${ns_path}/device_uuid"
}
_find_nvme_passthru_loop_dev() {
local subsys=$1
local nsid
local dev
dev=$(_find_nvme_dev "${subsys}")
nsid=$(_test_dev_nvme_nsid)
echo "/dev/${dev}n${nsid}"
}
_nvmet_passthru_target_setup() {
local subsysnqn="$def_subsysnqn"
local port
while [[ $# -gt 0 ]]; do
case $1 in
--subsysnqn)
subsysnqn="$2"
shift 2
;;
*)
echo "WARNING: unknown argument: $1"
shift
;;
esac
done
_create_nvmet_passthru "${subsysnqn}"
port="$(_create_nvmet_port)"
_add_nvmet_subsys_to_port "${port}" "${subsysnqn}"
_create_nvmet_host "${subsysnqn}" "${def_hostnqn}"
}
_nvmet_passthru_target_connect() {
local subsysnqn="$def_subsysnqn"
local timeout="5"
local count="0"
while [[ $# -gt 0 ]]; do
case $1 in
--subsysnqn)
subsysnqn="$2"
shift 2
;;
*)
echo "WARNING: unknown argument: $1"
shift
;;
esac
done
_nvme_connect_subsys --subsysnqn "${subsysnqn}" --no-wait || return
nsdev=$(_find_nvme_passthru_loop_dev "${subsysnqn}")
# The following tests can race with the creation
# of the device so ensure the block device exists
# before continuing
while [ ! -b "${nsdev}" ]; do
sleep 1
if ((++count >= timeout)); then
return 1
fi
done
echo "${nsdev}"
}
_nvmet_passthru_target_cleanup() {
local subsysnqn="$def_subsysnqn"
local ports
local port
while [[ $# -gt 0 ]]; do
case $1 in
--subsysnqn)
subsysnqn="$2"
shift 2
;;
*)
echo "WARNING: unknown argument: $1"
shift
;;
esac
done
if [[ -n "${nvme_target_control}" ]]; then
eval "${nvme_target_control}" cleanup \
--subsysnqn "${subsysnqn}" \
> /dev/null
return
fi
_get_nvmet_ports "${subsysnqn}" ports
for port in "${ports[@]}"; do
_remove_nvmet_subsystem_from_port "${port}" "${subsysnqn}"
_remove_nvmet_port "${port}"
done
_remove_nvmet_passhtru "${subsysnqn}"
_remove_nvmet_host "${def_hostnqn}"
}
_discovery_genctr() {
local port=${1}
_nvme_discover "${nvme_trtype}" "${port}" |
sed -n -e 's/^.*Generation counter \([0-9]\+\).*$/\1/p'
}
_check_genctr() {
local last=$1
local port=$2
local msg=$3
local genctr
genctr=$(_discovery_genctr "$port")
if (( "${genctr}" <= "${last}" )); then
echo "Generation counter not incremented when ${msg} (${genctr} <= ${last})"
fi
echo "${genctr}"
}
_check_uuid() {
local nvmedev=$1
local nr_nsid=0
for ns in "/sys/block/${nvmedev}n"* ; do
[ -e "${ns}/wwid" ] || continue
nr_nsid=$((nr_nsid + 1))
[ -e "${ns}/uuid" ] || continue
uuid=$(cat "${ns}/uuid")
wwid=$(cat "${ns}/wwid")
if [ "${uuid}" != "${wwid#uuid.}" ]; then
echo "UUID ${uuid} mismatch (wwid ${wwid})"
return 1
elif [ "${uuid}" != "${def_subsys_uuid}" ]; then
echo "UUID ${uuid} mismatch with ${def_subsys_uuid})"
return 1
fi
done
if [ $nr_nsid -eq 0 ] ; then
echo "No namespaces found"
return 1
fi
}
declare -A NS_DEV_FAULT_INJECT_SAVE
declare -A CTRL_DEV_FAULT_INJECT_SAVE
ns_dev_passthru_logging=off
ctrl_dev_passthru_logging=off
_nvme_passthru_logging_setup()
{
ctrl_dev_passthru_logging=$(cat /sys/class/nvme/"$2"/passthru_err_log_enabled)
ns_dev_passthru_logging=$(cat /sys/class/nvme/"$2"/"$1"/passthru_err_log_enabled)
_nvme_disable_passthru_admin_error_logging "$2"
_nvme_disable_passthru_io_error_logging "$1" "$2"
}
_nvme_passthru_logging_cleanup()
{
echo "$ctrl_dev_passthru_logging" > /sys/class/nvme/"$2"/passthru_err_log_enabled
echo "$ns_dev_passthru_logging" > /sys/class/nvme/"$2"/"$1"/passthru_err_log_enabled
}
_nvme_err_inject_setup()
{
local a
for a in /sys/kernel/debug/"$1"/fault_inject/*; do
NS_DEV_FAULT_INJECT_SAVE[${a}]=$(<"${a}")
done
for a in /sys/kernel/debug/"$2"/fault_inject/*; do
CTRL_DEV_FAULT_INJECT_SAVE[${a}]=$(<"${a}")
done
}
_nvme_err_inject_cleanup()
{
local a
for a in /sys/kernel/debug/"$1"/fault_inject/*; do
echo "${NS_DEV_FAULT_INJECT_SAVE[${a}]}" > "${a}"
done
for a in /sys/kernel/debug/"$2"/fault_inject/*; do
echo "${CTRL_DEV_FAULT_INJECT_SAVE[${a}]}" > "${a}"
done
}
_nvme_enable_err_inject()
{
echo "$2" > /sys/kernel/debug/"$1"/fault_inject/verbose
echo "$3" > /sys/kernel/debug/"$1"/fault_inject/probability
echo "$4" > /sys/kernel/debug/"$1"/fault_inject/dont_retry
echo "$5" > /sys/kernel/debug/"$1"/fault_inject/status
echo "$6" > /sys/kernel/debug/"$1"/fault_inject/times
}
_nvme_disable_err_inject()
{
echo 0 > /sys/kernel/debug/"$1"/fault_inject/probability
echo 0 > /sys/kernel/debug/"$1"/fault_inject/times
}
_nvme_enable_passthru_admin_error_logging()
{
echo on > /sys/class/nvme/"$1"/passthru_err_log_enabled
}
_nvme_enable_passthru_io_error_logging()
{
echo on > /sys/class/nvme/"$2"/"$1"/passthru_err_log_enabled
}
_nvme_disable_passthru_admin_error_logging()
{
echo off > /sys/class/nvme/"$1"/passthru_err_log_enabled
}
_nvme_disable_passthru_io_error_logging()
{
echo off > /sys/class/nvme/"$2"/"$1"/passthru_err_log_enabled
}
_nvme_reset_ctrl() {
echo 1 > /sys/class/nvme/"$1"/reset_controller
}
_nvme_delete_ctrl() {
echo 1 > /sys/class/nvme/"$1"/delete_controller
}
# Check whether the version of the fio is greater than or equal to $1.$2.$3
_have_tlshd_ver() {
_have_program tlshd || return $?
if _compare_three_version_numbers \
"$(tlshd --version |& sed 's/.*utils \([0-9^.]*\).*/\1/')" \
"$1" "$2" "$3"; then
SKIP_REASONS+=("tlshd version is older than ${1}.${2}.${3}")
return 1
fi
return 0
}
_have_systemd_tlshd_service() {
_have_tlshd_ver 1 0 0
if ! _have_systemctl_unit tlshd; then
SKIP_REASONS+=("Install ktls-utils for tlshd")
fi
}
_have_libnvme_ver() {
local ver
_have_program nvme || return $?
ver="$(nvme --version | grep libnvme | cut --delimiter ' ' --fields 3 | sed 's/-.*//')"
if _compare_three_version_numbers "$ver" "$1" "$2" "$3"; then
SKIP_REASONS+=("libnvme version is older than ${1}.${2}.${3:-0}")
return 1
fi
return 0
}
_nvme_ctrl_tls_key() {
local ctrl="$1"
cat /sys/class/nvme/"$ctrl"/tls_key 2>/dev/null
}