Skip to content

Commit

Permalink
nvme: don't assume namespace id
Browse files Browse the repository at this point in the history
The tests assume that the namespace id is always 1. This might not be
correct in future (e.g. running real targets), thus harden the test by
using the uuid to lookup the correct namespace id.

The passthru test already do this, so it makes also sense to update the
other tests as well.

Signed-off-by: Daniel Wagner <[email protected]>
Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
  • Loading branch information
igaw authored and kawasaki committed Mar 29, 2024
1 parent beab01c commit e55c4e0
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 82 deletions.
7 changes: 3 additions & 4 deletions tests/nvme/010
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ test() {

_setup_nvmet

local nvmedev
local ns

_nvmet_target_setup

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

_run_fio_verify_io --size="${nvme_img_size}" \
--filename="/dev/${nvmedev}n1"
--filename="/dev/${ns}"

_nvme_disconnect_subsys

Expand Down
7 changes: 3 additions & 4 deletions tests/nvme/011
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ test() {

_setup_nvmet

local nvmedev
local ns

_nvmet_target_setup --blkdev file

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

_run_fio_verify_io --size="${nvme_img_size}" \
--filename="/dev/${nvmedev}n1"
--filename="$/dev/{ns}"

_nvme_disconnect_subsys

Expand Down
7 changes: 3 additions & 4 deletions tests/nvme/012
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ test() {

_setup_nvmet

local nvmedev
local ns

_nvmet_target_setup

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

if ! _xfs_run_fio_verify_io "/dev/${nvmedev}n1"; then
if ! _xfs_run_fio_verify_io "/dev/${ns}"; then
echo "FAIL: fio verify failed"
fi

Expand Down
7 changes: 3 additions & 4 deletions tests/nvme/013
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ test() {

_setup_nvmet

local nvmedev
local ns

_nvmet_target_setup --blkdev file

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

if ! _xfs_run_fio_verify_io "/dev/${nvmedev}n1"; then
if ! _xfs_run_fio_verify_io "$/dev/{ns}"; then
echo "FAIL: fio verify failed"
fi

Expand Down
13 changes: 6 additions & 7 deletions tests/nvme/014
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test() {

_setup_nvmet

local nvmedev
local ns
local size
local bs
local count
Expand All @@ -29,17 +29,16 @@ test() {

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

size="$(blockdev --getsize64 "/dev/${nvmedev}n1")"
bs="$(blockdev --getbsz "/dev/${nvmedev}n1")"
size="$(blockdev --getsize64 "/dev/${ns}")"
bs="$(blockdev --getbsz "/dev/${ns}")"
count=$((size / bs))

dd if=/dev/urandom of="/dev/${nvmedev}n1" \
dd if=/dev/urandom of="$/dev/{ns}" \
count="${count}" bs="${bs}" status=none

nvme flush "/dev/${nvmedev}" --namespace-id 1
nvme flush "/dev/${ns}"

_nvme_disconnect_subsys

Expand Down
13 changes: 6 additions & 7 deletions tests/nvme/015
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test() {

_setup_nvmet

local nvmedev
local ns
local size
local bs
local count
Expand All @@ -29,17 +29,16 @@ test() {

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

size="$(blockdev --getsize64 "/dev/${nvmedev}n1")"
bs="$(blockdev --getbsz "/dev/${nvmedev}n1")"
size="$(blockdev --getsize64 "/dev/${ns}")"
bs="$(blockdev --getbsz "/dev/${ns}")"
count=$((size / bs))

dd if=/dev/urandom of="/dev/${nvmedev}n1" \
dd if=/dev/urandom of="/dev/${ns}" \
count="${count}" bs="${bs}" status=none

nvme flush "/dev/${nvmedev}n1" --namespace-id 1
nvme flush "/dev/${ns}"

_nvme_disconnect_subsys

Expand Down
15 changes: 7 additions & 8 deletions tests/nvme/018
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@ test() {

_setup_nvmet

local nvmedev
local ns
local sectors
local bs

_nvmet_target_setup --blkdev file

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

local sectors
local bs
sectors="$(blockdev --getsz "/dev/${nvmedev}n1")"
bs="$(blockdev --getbsz "/dev/${nvmedev}n1")"
sectors="$(blockdev --getsz "/dev/${ns}")"
bs="$(blockdev --getbsz "/dev/${ns}")"

nvme read "/dev/${nvmedev}n1" --start-block "$sectors" \
nvme read "/dev/${ns}" --start-block "$sectors" \
--block-count 0 --data-size "$bs" &>"$FULL" \
&& echo "ERROR: nvme read for out of range LBA was not rejected"

Expand Down
8 changes: 3 additions & 5 deletions tests/nvme/019
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ test() {

_setup_nvmet

local nvmedev
local ns
local nblk_range="10,10,10,10,10,10,10,10,10,10"
local sblk_range="100,200,300,400,500,600,700,800,900,1000"

_nvmet_target_setup

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"

nvme dsm "/dev/${nvmedev}" --namespace-id 1 --ad \
ns=$(_find_nvme_ns "${def_subsys_uuid}")
nvme dsm "/dev/${ns}" --ad \
--slbs "${sblk_range}" --blocks "${nblk_range}"

_nvme_disconnect_subsys
Expand Down
7 changes: 3 additions & 4 deletions tests/nvme/020
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ test() {

_setup_nvmet

local nvmedev
local ns
local nblk_range="10,10,10,10,10,10,10,10,10,10"
local sblk_range="100,200,300,400,500,600,700,800,900,1000"

_nvmet_target_setup --blkdev file

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

nvme dsm "/dev/${nvmedev}" --namespace-id 1 --ad \
nvme dsm "/dev/${ns}" --ad \
--slbs "${sblk_range}" --blocks "${nblk_range}"

_nvme_disconnect_subsys
Expand Down
7 changes: 3 additions & 4 deletions tests/nvme/021
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ test() {

_setup_nvmet

local nvmedev
local ns

_nvmet_target_setup --blkdev file

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

if ! nvme list 2>> "$FULL" | grep -q "${nvmedev}n1"; then
if ! nvme list 2>> "$FULL" | grep -q "/dev/${ns}"; then
echo "ERROR: device not listed"
fi

Expand Down
8 changes: 3 additions & 5 deletions tests/nvme/023
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ test() {

_setup_nvmet

local nvmedev
local ns

_nvmet_target_setup

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

if ! nvme smart-log "/dev/${nvmedev}" --namespace-id 1 \
>> "$FULL" 2>&1; then
if ! nvme smart-log "/dev/${ns}" >> "$FULL" 2>&1; then
echo "ERROR: smart-log bdev-ns failed"
fi

Expand Down
9 changes: 4 additions & 5 deletions tests/nvme/024
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ test() {

_setup_nvmet

local nvmedev
local ns

_nvmet_target_setup --blkdev file

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns ${def_subsys_uuid})

if ! nvme smart-log "/dev/${nvmedev}" --namespace-id 1 \
>> "$FULL" 2>&1; then
if ! nvme smart-log "/dev/${ns}" >> "$FULL" 2>&1; then
echo "ERROR: smart-log file-ns failed"
fi

_nvme_disconnect_subsys >> "$FULL" 2>&1

_nvmet_target_cleanup
Expand Down
7 changes: 3 additions & 4 deletions tests/nvme/025
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ test() {

_setup_nvmet

local nvmedev
local ns

_nvmet_target_setup --blkdev file

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

if ! nvme effects-log "/dev/${nvmedev}" >> "$FULL" 2>&1; then
if ! nvme effects-log "/dev/${ns}" >> "$FULL" 2>&1; then
echo "ERROR: effects-log failed"
fi

Expand Down
8 changes: 3 additions & 5 deletions tests/nvme/026
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ test() {

_setup_nvmet

local nvmedev
local ns

_nvmet_target_setup --blkdev file

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"
ns=$(_find_nvme_ns "${def_subsys_uuid}")

if ! nvme ns-descs "/dev/${nvmedev}" --namespace-id 1 \
>> "$FULL" 2>&1; then
if ! nvme ns-descs "/dev/${ns}" >> "$FULL" 2>&1; then
echo "ERROR: ns-desc failed"
fi

Expand Down
7 changes: 2 additions & 5 deletions tests/nvme/029
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,12 @@ test() {

_setup_nvmet

local nvmedev
local reset_nr_hugepages=false

_nvmet_target_setup

_nvme_connect_subsys

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
_check_uuid "${nvmedev}"

# nvme-cli may fail to allocate linear memory for rather large IO buffers.
# Increase nr_hugepages to allow nvme-cli to try the linear memory allocation
# from HugeTLB pool.
Expand All @@ -72,7 +68,8 @@ test() {
reset_nr_hugepages=true
fi

local dev="/dev/${nvmedev}n1"
local dev
dev="/dev/$(_find_nvme_ns "${def_subsys_uuid}")"
test_user_io "$dev" 1 512 > "$FULL" 2>&1 || echo FAIL
test_user_io "$dev" 1 511 > "$FULL" 2>&1 || echo FAIL
test_user_io "$dev" 1 513 > "$FULL" 2>&1 || echo FAIL
Expand Down
4 changes: 3 additions & 1 deletion tests/nvme/040
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ test() {

local nvmedev
local fio_pid
local ns

_nvmet_target_setup

_nvme_connect_subsys
nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
ns=$(_find_nvme_ns "${def_subsys_uuid}")

# start fio job
echo "starting background fio"
_run_fio_rand_io --filename="/dev/${nvmedev}n1" \
_run_fio_rand_io --filename="/dev/${ns}" \
--group_reporting --ramp_time=5 \
--time_based --runtime=1d &> /dev/null &
fio_pid=$!
Expand Down
5 changes: 3 additions & 2 deletions tests/nvme/045
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test() {
local new_ctrlkey
local ctrldev
local rand_io_size
local ns

hostkey="$(nvme gen-dhchap-key -n ${def_subsysnqn} 2> /dev/null)"
if [ -z "$hostkey" ] ; then
Expand Down Expand Up @@ -100,10 +101,10 @@ test() {

echo "${new_hostkey}" > "${hostkey_file}"

nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
ns=$(_find_nvme_ns "${def_subsys_uuid}")

rand_io_size="$(_nvme_calc_rand_io_size 4m)"
_run_fio_rand_io --size="${rand_io_size}" --filename="/dev/${nvmedev}n1"
_run_fio_rand_io --size="${rand_io_size}" --filename="/dev/${ns}"

_nvme_disconnect_subsys
_nvmet_target_cleanup
Expand Down
Loading

0 comments on commit e55c4e0

Please sign in to comment.