Skip to content

Commit b14a95a

Browse files
committed
common/nvme: unload nvme modules only when loaded
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. Reviewed-by: Daniel Wagner <[email protected]> Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent 31a07ec commit b14a95a

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

common/nvme

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,7 @@ _cleanup_nvmet() {
213213

214214
if [[ "${nvme_trtype}" == "fc" ]]; then
215215
_nvme_fcloop_del_lport "${def_local_wwnn}" "${def_local_wwpn}"
216-
_patient_rmmod nvme-fcloop
217216
fi
218-
_patient_rmmod nvme-"${nvme_trtype}"
219-
if [[ "${nvme_trtype}" != "loop" ]]; then
220-
_patient_rmmod nvmet-"${nvme_trtype}"
221-
fi
222-
_patient_rmmod nvmet
223217
if [[ "${nvme_trtype}" == "rdma" ]]; then
224218
stop_soft_rdma
225219
fi
@@ -240,11 +234,11 @@ _setup_nvmet() {
240234
return
241235
fi
242236

243-
modprobe -q nvmet
237+
_load_module nvmet
244238
if [[ "${nvme_trtype}" != "loop" ]]; then
245-
modprobe -q nvmet-"${nvme_trtype}"
239+
_load_module nvmet-"${nvme_trtype}"
246240
fi
247-
modprobe -q nvme-"${nvme_trtype}"
241+
_load_module nvme-"${nvme_trtype}"
248242
if [[ "${nvme_trtype}" == "rdma" ]]; then
249243
start_soft_rdma
250244
for i in $(rdma_network_interfaces)
@@ -263,7 +257,7 @@ _setup_nvmet() {
263257
done
264258
fi
265259
if [[ "${nvme_trtype}" = "fc" ]]; then
266-
modprobe -q nvme-fcloop
260+
_load_module nvme-fcloop
267261
_nvme_fcloop_add_lport "${def_local_wwnn}" "${def_local_wwpn}"
268262
fi
269263
}

0 commit comments

Comments
 (0)