To test nvme target driver with various transports, _setup_nvmet() loads the nvmet module along with other required modules based on the test conditions. The loaded modules are unloaded by _cleanup_nvmet() following the same logic as _setup_nvmet(). However, this module load by _cleanup_nvmet() does not work as expected because it unloads the modules regardless of module load status at test case start. For example, when the nvmet and nvme-loop modules are already loaded at the beginning of nvme/060 test case run for rdma transport. In this case, _nvmet_setup() loads the nvmet-rdma module, which has a dependency on the nvmet module. At the end of nvme/060, _cleanup_nvmet() attempts to unload both the nvmet-rdma and nvmet modules. While the nvmet-rdma module is successfully unloaded, the nvmet module fails to unload because it is still used by the nvme-loop module. This results in the following error message: modprobe with --wait option succeeded but still nvmet has references To prevent the module unload failures, unload modules only when the modules were loaded during the test. For that purpose, replace "modprobe" commands in _nvmet_setup() with calls to _load_module(). This ensures that only modules not already loaded are recorded in the global MODULES_TO_UNLOAD array. Afterward, the recorded modules will be automatically unloaded after the test case completes. Also drop calls to _patient_rmmod() in _nvmet_cleanup(), which are no longer necessary. Signed-off-by: Shin'ichiro Kawasaki --- common/nvme | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/common/nvme b/common/nvme index a419cd3..64f1828 100644 --- a/common/nvme +++ b/common/nvme @@ -213,13 +213,7 @@ _cleanup_nvmet() { if [[ "${nvme_trtype}" == "fc" ]]; then _nvme_fcloop_del_lport "${def_local_wwnn}" "${def_local_wwpn}" - _patient_rmmod nvme-fcloop fi - _patient_rmmod nvme-"${nvme_trtype}" - if [[ "${nvme_trtype}" != "loop" ]]; then - _patient_rmmod nvmet-"${nvme_trtype}" - fi - _patient_rmmod nvmet if [[ "${nvme_trtype}" == "rdma" ]]; then stop_soft_rdma fi @@ -240,11 +234,11 @@ _setup_nvmet() { return fi - modprobe -q nvmet + _load_module nvmet if [[ "${nvme_trtype}" != "loop" ]]; then - modprobe -q nvmet-"${nvme_trtype}" + _load_module nvmet-"${nvme_trtype}" fi - modprobe -q nvme-"${nvme_trtype}" + _load_module nvme-"${nvme_trtype}" if [[ "${nvme_trtype}" == "rdma" ]]; then start_soft_rdma for i in $(rdma_network_interfaces) @@ -263,7 +257,7 @@ _setup_nvmet() { done fi if [[ "${nvme_trtype}" = "fc" ]]; then - modprobe -q nvme-fcloop + _load_module nvme-fcloop _nvme_fcloop_add_lport "${def_local_wwnn}" "${def_local_wwpn}" fi } -- 2.53.0