Skip to content

Commit

Permalink
nvme: introduce nvmet_target_{setup/cleanup} common code
Browse files Browse the repository at this point in the history
Almost all fabric tests have the identically code for
setting up and cleaning up the target side. Introduce
two new helpers.

Reviewed-by: Chaitanya Kulkarni <[email protected]>
Signed-off-by: Daniel Wagner <[email protected]>
[Shin'ichiro: added missing "--blkdev file" option in nvme/018]
Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
  • Loading branch information
igaw authored and kawasaki committed Aug 31, 2023
1 parent 76a03c7 commit a12281b
Show file tree
Hide file tree
Showing 34 changed files with 145 additions and 519 deletions.
14 changes: 3 additions & 11 deletions tests/nvme/003
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@ test() {

_setup_nvmet

local loop_dev
local port

port="$(_create_nvmet_port "${nvme_trtype}")"

loop_dev="$(losetup -f)"

_create_nvmet_subsystem "${def_subsysnqn}" "${loop_dev}"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
_nvmet_target_setup

_nvme_connect_subsys "${nvme_trtype}" nqn.2014-08.org.nvmexpress.discovery

Expand All @@ -46,9 +39,8 @@ test() {
fi

_nvme_disconnect_subsys nqn.2014-08.org.nvmexpress.discovery
_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_port "${port}"

_nvmet_target_cleanup

echo "Test complete"
}
21 changes: 3 additions & 18 deletions tests/nvme/004
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,8 @@ test() {

_setup_nvmet

local port
local loop_dev

port="$(_create_nvmet_port "${nvme_trtype}")"

truncate -s "${nvme_img_size}" "${def_file_path}"

loop_dev="$(losetup -f --show "${def_file_path}")"

_create_nvmet_subsystem "${def_subsysnqn}" "${loop_dev}" \
"${def_subsys_uuid}"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
_create_nvmet_host "${def_subsysnqn}" "${def_hostnqn}"
_nvmet_target_setup

_nvme_connect_subsys "${nvme_trtype}" "${def_subsysnqn}"

Expand All @@ -44,12 +33,8 @@ test() {
cat "/sys/block/${nvmedev}n1/wwid"

_nvme_disconnect_subsys ${def_subsysnqn}
_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_port "${port}"
_remove_nvmet_host "${def_hostnqn}"
losetup -d "$loop_dev"
rm "${def_file_path}"

_nvmet_target_cleanup

echo "Test complete"
}
20 changes: 2 additions & 18 deletions tests/nvme/005
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,9 @@ test() {

_setup_nvmet

local port
local loop_dev
local nvmedev

port="$(_create_nvmet_port "${nvme_trtype}")"

truncate -s "${nvme_img_size}" "${def_file_path}"

loop_dev="$(losetup -f --show "${def_file_path}")"

_create_nvmet_subsystem "${def_subsysnqn}" "${loop_dev}" \
"${def_subsys_uuid}"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
_create_nvmet_host "${def_subsysnqn}" "${def_hostnqn}"
_nvmet_target_setup

_nvme_connect_subsys "${nvme_trtype}" "${def_subsysnqn}"

Expand All @@ -43,13 +32,8 @@ test() {
echo 1 > "/sys/class/nvme/${nvmedev}/reset_controller"

_nvme_disconnect_ctrl "${nvmedev}"
_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_port "${port}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_host "${def_hostnqn}"

losetup -d "$loop_dev"
rm "${def_file_path}"
_nvmet_target_cleanup

echo "Test complete"
}
19 changes: 2 additions & 17 deletions tests/nvme/006
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,10 @@ test() {

_setup_nvmet

local port
local loop_dev

truncate -s "${nvme_img_size}" "${def_file_path}"
_nvmet_target_setup

loop_dev="$(losetup -f --show "${def_file_path}")"

_create_nvmet_subsystem "${def_subsysnqn}" "${loop_dev}" \
"${def_subsys_uuid}"
port="$(_create_nvmet_port "${nvme_trtype}")"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"

_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_port "${port}"

losetup -d "$loop_dev"

rm "${def_file_path}"
_nvmet_target_cleanup

echo "Test complete"
}
14 changes: 2 additions & 12 deletions tests/nvme/007
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,10 @@ test() {

_setup_nvmet

local port

truncate -s "${nvme_img_size}" "${def_file_path}"
_nvmet_target_setup --blkdev file

_create_nvmet_subsystem "${def_subsysnqn}" "${def_file_path}" \
"${def_subsys_uuid}"
port="$(_create_nvmet_port "${nvme_trtype}")"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"

_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_port "${port}"

rm "${def_file_path}"
_nvmet_target_cleanup

echo "Test complete"
}
21 changes: 2 additions & 19 deletions tests/nvme/008
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,9 @@ test() {

_setup_nvmet

local port
local nvmedev
local loop_dev

truncate -s "${nvme_img_size}" "${def_file_path}"

loop_dev="$(losetup -f --show "${def_file_path}")"

_create_nvmet_subsystem "${def_subsysnqn}" "${loop_dev}" \
"${def_subsys_uuid}"
port="$(_create_nvmet_port "${nvme_trtype}")"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
_create_nvmet_host "${def_subsysnqn}" "${def_hostnqn}"
_nvmet_target_setup

_nvme_connect_subsys "${nvme_trtype}" "${def_subsysnqn}"

Expand All @@ -42,14 +32,7 @@ test() {

_nvme_disconnect_subsys "${def_subsysnqn}"

_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_port "${port}"
_remove_nvmet_host "${def_hostnqn}"

losetup -d "${loop_dev}"

rm "${def_file_path}"
_nvmet_target_cleanup

echo "Test complete"
}
16 changes: 2 additions & 14 deletions tests/nvme/009
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ test() {

_setup_nvmet

local port
local nvmedev

truncate -s "${nvme_img_size}" "${def_file_path}"

_create_nvmet_subsystem "${def_subsysnqn}" "${def_file_path}" \
"${def_subsys_uuid}"
port="$(_create_nvmet_port "${nvme_trtype}")"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
_create_nvmet_host "${def_subsysnqn}" "${def_hostnqn}"
_nvmet_target_setup --blkdev file

_nvme_connect_subsys "${nvme_trtype}" "${def_subsysnqn}"

Expand All @@ -38,12 +31,7 @@ test() {

_nvme_disconnect_subsys "${def_subsysnqn}"

_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_port "${port}"
_remove_nvmet_host "${def_hostnqn}"

rm "${def_file_path}"
_nvmet_target_cleanup

echo "Test complete"
}
21 changes: 2 additions & 19 deletions tests/nvme/010
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,9 @@ test() {

_setup_nvmet

local port
local nvmedev
local loop_dev

truncate -s "${nvme_img_size}" "${def_file_path}"

loop_dev="$(losetup -f --show "${def_file_path}")"

_create_nvmet_subsystem "${def_subsysnqn}" "${loop_dev}" \
"${def_subsys_uuid}"
port="$(_create_nvmet_port "${nvme_trtype}")"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
_create_nvmet_host "${def_subsysnqn}" "${def_hostnqn}"
_nvmet_target_setup

_nvme_connect_subsys "${nvme_trtype}" "${def_subsysnqn}"

Expand All @@ -45,14 +35,7 @@ test() {

_nvme_disconnect_subsys "${def_subsysnqn}"

_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_port "${port}"
_remove_nvmet_host "${def_hostnqn}"

losetup -d "${loop_dev}"

rm "${def_file_path}"
_nvmet_target_cleanup

echo "Test complete"
}
16 changes: 2 additions & 14 deletions tests/nvme/011
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@ test() {

_setup_nvmet

local port
local nvmedev

truncate -s "${nvme_img_size}" "${def_file_path}"

_create_nvmet_subsystem "${def_subsysnqn}" "${def_file_path}" \
"${def_subsys_uuid}"
port="$(_create_nvmet_port "${nvme_trtype}")"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
_create_nvmet_host "${def_subsysnqn}" "${def_hostnqn}"
_nvmet_target_setup --blkdev file

_nvme_connect_subsys "${nvme_trtype}" "${def_subsysnqn}"

Expand All @@ -42,12 +35,7 @@ test() {

_nvme_disconnect_subsys "${def_subsysnqn}"

_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_port "${port}"
_remove_nvmet_host "${def_hostnqn}"

rm "${def_file_path}"
_nvmet_target_cleanup

echo "Test complete"
}
21 changes: 2 additions & 19 deletions tests/nvme/012
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,9 @@ test() {

_setup_nvmet

local port
local nvmedev
local loop_dev

truncate -s "${nvme_img_size}" "${def_file_path}"

loop_dev="$(losetup -f --show "${def_file_path}")"

_create_nvmet_subsystem "${def_subsysnqn}" "${loop_dev}" \
"${def_subsys_uuid}"
port="$(_create_nvmet_port "${nvme_trtype}")"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
_create_nvmet_host "${def_subsysnqn}" "${def_hostnqn}"
_nvmet_target_setup

_nvme_connect_subsys "${nvme_trtype}" "${def_subsysnqn}"

Expand All @@ -48,14 +38,7 @@ test() {

_nvme_disconnect_subsys "${def_subsysnqn}"

_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_port "${port}"
_remove_nvmet_host "${def_hostnqn}"

losetup -d "${loop_dev}"

rm "${def_file_path}"
_nvmet_target_cleanup

echo "Test complete"
}
16 changes: 2 additions & 14 deletions tests/nvme/013
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ test() {

_setup_nvmet

local port
local nvmedev

truncate -s "${nvme_img_size}" "${def_file_path}"

_create_nvmet_subsystem "${def_subsysnqn}" "${def_file_path}" \
"${def_subsys_uuid}"
port="$(_create_nvmet_port "${nvme_trtype}")"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
_create_nvmet_host "${def_subsysnqn}" "${def_hostnqn}"
_nvmet_target_setup --blkdev file

_nvme_connect_subsys "${nvme_trtype}" "${def_subsysnqn}"

Expand All @@ -44,12 +37,7 @@ test() {

_nvme_disconnect_subsys "${def_subsysnqn}"

_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_port "${port}"
_remove_nvmet_host "${def_hostnqn}"

rm "${def_file_path}"
_nvmet_target_cleanup

echo "Test complete"
}
21 changes: 2 additions & 19 deletions tests/nvme/014
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,12 @@ test() {

_setup_nvmet

local port
local nvmedev
local loop_dev
local size
local bs
local count

truncate -s "${nvme_img_size}" "${def_file_path}"

loop_dev="$(losetup -f --show "${def_file_path}")"

_create_nvmet_subsystem "${def_subsysnqn}" "${loop_dev}" \
"${def_subsys_uuid}"
port="$(_create_nvmet_port "${nvme_trtype}")"
_add_nvmet_subsys_to_port "${port}" "${def_subsysnqn}"
_create_nvmet_host "${def_subsysnqn}" "${def_hostnqn}"
_nvmet_target_setup

_nvme_connect_subsys "${nvme_trtype}" "${def_subsysnqn}"

Expand All @@ -54,14 +44,7 @@ test() {

_nvme_disconnect_subsys "${def_subsysnqn}"

_remove_nvmet_subsystem_from_port "${port}" "${def_subsysnqn}"
_remove_nvmet_subsystem "${def_subsysnqn}"
_remove_nvmet_port "${port}"
_remove_nvmet_host "${def_hostnqn}"

losetup -d "${loop_dev}"

rm "${def_file_path}"
_nvmet_target_cleanup

echo "Test complete"
}
Loading

0 comments on commit a12281b

Please sign in to comment.