nvme: add re-authentication running concurrently with reset
Sagi Grimberg
maintainerPATCH 1/1 nvme: add re-authentication running concurrently with reset
when re-authentication with new host-key and/or ctrl-key there is an async work that is scheduled async. A controller reset should be mutual exclusive with the re-authentication work. Add a test that triggers re-authentication and immediately resets the controller.
--- tests/nvme/046 | 112 +++++++++++++++++++++++++++++++++++++++++++++ tests/nvme/046.out | 23 ++++++++++ 2 files changed, 135 insertions(+) create mode 100755 tests/nvme/046 create mode 100644 tests/nvme/046.out
tests/nvme/046 new file +112 -0
@@ -0,0 +1,112 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2022 Sagi Grimberg <[email protected]> +# +# Test re-authentication and reset running in parallel + +. tests/nvme/rc + +DESCRIPTION="Test re-authentication concurrently with reset" +QUICK=1 + +requires() { + _nvme_requires + _have_loop + _have_kernel_option NVME_AUTH + _have_kernel_option NVME_TARGET_AUTH + _require_nvme_trtype_is_fabrics + _require_nvme_cli_auth + _have_driver dh_generic +} + + +test() { + local port + local subsys_name="blktests-subsystem-1" + local hostid + local hostnqn + local file_path="${TMPDIR}/img" + local hostkey + local new_hostkey + local ctrlkey + local new_ctrlkey + local ctrldev + + echo "Running ${TEST_NAME}" + + hostid="$(uuidgen)" + if [ -z "$hostid" ] ; then + echo "uuidgen failed" + return 1 + fi + hostnqn="nqn.2014-08.org.nvmexpress:uuid:${hostid}" + + hostkey="$(nvme gen-dhchap-key -n ${subsys_name} 2> /dev/null)" + if [ -z "$hostkey" ] ; then + echo "failed to generate host key" + return 1 + fi + + ctrlkey="$(nvme gen-dhchap-key -n ${subsys_name} 2> /dev/null)" + if [ -z "$ctrlkey" ] ; then + echo "failed to generate ctrl key" + return 1 + fi + + _setup_nvmet + + truncate -s 512M "${file_path}" + + _create_nvmet_subsystem "${subsys_name}" "${file_path}" + port="$(_create_nvmet_port "${nvme_trtype}")" + _add_nvmet_subsys_to_port "${port}" "${subsys_name}" + _create_nvmet_host "${subsys_name}" "${hostnqn}" "${hostkey}" "${ctrlkey}" + + _set_nvmet_dhgroup "${hostnqn}" "ffdhe2048" + + _nvme_connect_subsys "${nvme_trtype}" "${subsys_name}" \ + "${def_traddr}" "${def_trsvcid}" \ + "${hostnqn}" "${hostid}" \ + "${hostkey}" "${ctrlkey}" + + udevadm settle + + ctrldev=$(_find_nvme_dev "${subsys_name}") + if [ -z "$ctrldev" ] ; then + echo "nvme controller not found" + fi + + hostkey_file="/sys/class/nvme/${ctrldev}/dhchap_secret" + ctrlkey_file="/sys/class/nvme/${ctrldev}/dhchap_ctrl_secret" + + for ((i = 0; i < 10; i++)); do + echo "Re-authenticate with new host key (iteration $i)" + new_hostkey="$(nvme gen-dhchap-key -n ${subsys_name} 2> /dev/null)" + _set_nvmet_hostkey "${hostnqn}" "${new_hostkey}" + echo "${new_hostkey}" > "${hostkey_file}" + _nvme_reset_ctrl $ctrldev + + echo "Re-authenticate with new ctrl key (iteration $i)" + new_ctrlkey="$(nvme gen-dhchap-key -n ${subsys_name} 2> /dev/null)" + _set_nvmet_ctrlkey "${hostnqn}" "${new_ctrlkey}" + echo "${new_ctrlkey}" > "${ctrlkey_file}" + _nvme_reset_ctrl $ctrldev + done + + nvmedev=$(_find_nvme_dev "${subsys_name}") + + _run_fio_rand_io --size=8m --filename="/dev/${nvmedev}n1" + + _nvme_disconnect_subsys "${subsys_name}" + + _remove_nvmet_subsystem_from_port "${port}" "${subsys_name}" + _remove_nvmet_subsystem "${subsys_name}" + + _remove_nvmet_port "${port}" + + _remove_nvmet_host "${hostnqn}" + + rm "${file_path}" + + echo "Test complete" +}
tests/nvme/046.out new file +23 -0
@@ -0,0 +1,23 @@ +Running nvme/046 +Re-authenticate with new host key (iteration 0) +Re-authenticate with new ctrl key (iteration 0) +Re-authenticate with new host key (iteration 1) +Re-authenticate with new ctrl key (iteration 1) +Re-authenticate with new host key (iteration 2) +Re-authenticate with new ctrl key (iteration 2) +Re-authenticate with new host key (iteration 3) +Re-authenticate with new ctrl key (iteration 3) +Re-authenticate with new host key (iteration 4) +Re-authenticate with new ctrl key (iteration 4) +Re-authenticate with new host key (iteration 5) +Re-authenticate with new ctrl key (iteration 5) +Re-authenticate with new host key (iteration 6) +Re-authenticate with new ctrl key (iteration 6) +Re-authenticate with new host key (iteration 7) +Re-authenticate with new ctrl key (iteration 7) +Re-authenticate with new host key (iteration 8) +Re-authenticate with new ctrl key (iteration 8) +Re-authenticate with new host key (iteration 9) +Re-authenticate with new ctrl key (iteration 9) +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Test complete
Signature · 1 line
2.34.1
Quoted 7 lines · Sagi Grimberg
when re-authentication with new host-key and/or ctrl-key there is an async work that is scheduled async. A controller reset should be mutual exclusive with the re-authentication work. Add a test that triggers re-authentication and immediately resets the controller.
Signed-off-by Sagi Grimberg <[email protected]>---
Looks good.
-ck
Quoted 6 lines · Sagi Grimberg
when re-authentication with new host-key and/or ctrl-key there is an async work that is scheduled async. A controller reset should be mutual exclusive with the re-authentication work. Add a test that triggers re-authentication and immediately resets the controller.
Signed-off-by Sagi Grimberg <[email protected]>
Thanks. I believe that this test case checks fix of a problem found during your work on "nvme: fixes, cleanups and enhancements to the dhchap-auth host code".
I have some nit comments. Other than these, the patch looks good for me.
- Shellcheck have a couple of complaints:
$ make check
shellcheck -x -e SC2119 -f gcc check new common/* \
tests/*/rc tests/*/[0-9]*[0-9]
tests/nvme/046:87:20: note: Double quote to prevent globbing and word splitting. [SC2086]
tests/nvme/046:93:20: note: Double quote to prevent globbing and word splitting. [SC2086]
make: *** [Makefile:21: check] Error 1- The test() function lists all local variables except "hostkey_file", "ctrlkey_file" and "nvvmedev". A bit better to declare those three also.
- It would be a bit better for linux-nvme readers to have subject prefix "[PATCH blktests]" to clarify it is not the patch for linux, but for blktests.
Signature · 1 line
Shin'ichiro Kawasaki