Skip tests if scsi_debug module is already loaded and in use#218
Skip tests if scsi_debug module is already loaded and in use#218disgoel wants to merge 1 commit intolinux-blktests:masterfrom
Conversation
|
@disgoel Thanks for the idea. It is interesting for me, and I would like to think about it. When the scsi_debug is a loadable module, it makes sense that the scsi_debug is not loaded before running each of the test cases, probably. I wonder how the check can be done when the scsi_debug is built-in. I took a look in the commit, but it looks missing the implementation of _module_not_in_use() function, doesn't it? |
The function already exists. |
For built-in scsi_debug, the situation is actually more constrained than the modular case. Since the driver cannot be unloaded or reset, any existing scsi_debug devices mean the tests cannot obtain exclusive control. In that case, skipping the tests is still the correct and safest behavior. The intent of the check is not to distinguish built-in vs modular scsi_debug, but to ensure exclusive access. If that exclusivity cannot be guaranteed (either because the module is already in use or because the driver is built-in and active), the test should be skipped. |
Ah, I overlooked that function. Sorry. However, I'm not sure if that function really works for the purpose of this PR. The function checks /sys/module/scsi_debug/refcnt. But this refcnt value shows how many other modules depend on scsi_debug. IIUC, regardless of the number of scsi_debug devices, the refcnt value is zero. To check usage of scsi_debug, I think we need to check /sys/bus/pseudo/drivers/scsi_debug/add_host. |
|
I read your first explanation again, and I noticed that I had missed the point that the refcnt can be more than zero, when the scsi_debug device is opened by any user application. So, your code change will catch such case that the user creates any scsi_debug device and keeps the file open for an application before running blktests. And, this really happens in your test system. Now I see your point. _module_not_in_use() checks /sys/module/scsi_debug/refcnt. This sysfs attribute does not exists when scsi_debug is built-in. So this approach will not work for built-in scsi_debug. But still your change will add value for loadable scsi_debug case. As I noted in the above comment, another idea is to refer to the add_host attribute. However, when scsi_debug is loaded with default parameter, or scsi_debug is built-in, this add_host attribute has value "1", because scsi_debug creates the first device automatically. When add_host has value 1, we can not tell if this is the device created automatically, or the user created it. If the value is 2 or larger, we are sure that the user created their own device. So, I can think of two approaches:
I think either way is okay. Whichever, it adds value to blktests. |
|
Assuming the approach 1), it is rather odd to call _modules_not_in_use() in required() of each test case. Once _have_scsi_debug() is specified, it should imply "_modules_not_in_use scsi_debug". So I suggest to modify _have_scsi_debug to call "_modules_not_in_use scsi_debug". Some test cases call "_have_module scsi_debug" instead of "_have_scsi_debug". For those test cases, I suggest to introduce a new helper function "_have_loadable_scsi_debug" in common/scsi_debug. This helper function can call both "_have_module scsi_debug" and "_module_not_in_use scsi_debug". The test cases can call _have_loadable_scsi_debug instead of "_have_loadable_scsi_debug". I think this simplification can also be done when approach 2) is chosen. |
c547b1b to
576c698
Compare
|
@kawasaki sorry for the delay. I have refactored the patch to centralize the logic in common/scsi_debug as requested:
Verification: Confirmed that tests now correctly skip when the module is busy (refcnt > 0) or has extra hosts, and pass when the environment is clean. |
71b68c7 to
8c18df0
Compare
kawasaki
left a comment
There was a problem hiding this comment.
@disgoel Thank you for updating the patch. I agree with this fix concept. Please find my review comments and see if the comments make sense for you.
For your reference, I share a code change which reflects my review comments (link). I hope it helps to clarify my intents.
Also, I think some more test cases can be modified to use _have_loadable_scsi_debug or _have_scsi_debug. I created another code change to try it out (link). Please take a look in it also.
|
@disgoel Thanks again for your effort. I think this work is close to the merge. Before the merge, I would like to post your patch to the linux-block mailing list to get wider reviews and build up consensus. I can post the patch to the list on behalf of you with your authorship. Just in case this is not okay for you, please let me know. |
a2e0e51 to
637f9a8
Compare
|
@kawasaki Thank you for the detailed review and the reference code. I have updated the PR to address requested changes. Also updated the suggested test cases (block/009, md/002, etc.) to use the appropriate helper. I am completely fine with you posting the patch to the linux-block mailing list on my behalf with my authorship. I appreciate the help in getting this merged! |
Several tests across block/, scsi/, dm/, md/, zbd/, nvme/ require exclusive access to the scsi_debug module because they load, unload or reconfigure it. When scsi_debug is loadable and already loaded by the environment (e.g., by another driver or a previous setup), these tests fail with: modprobe: FATAL: Module scsi_debug is in use. Unloading scsi_debug failed scsi_debug 327680 4 To prevent the failures, check if scsi_debug already loaded. If so, skip the test cases which use scsi_debug. Instead of modifying common rc files—which would overskip unrelated tests, add "_module_not_in_use scsi_debug" call to the new helper function _have_loadable_scsi_debug() and call it only for the tests that actually depend on exclusive access to scsi_debug. Also, when scsi_debug is built-in and already additional hosts are created by the environment, the tests may break the hosts. To cover this built-in scsi_debug scenario, check the number of added hosts in _have_scsi_debug(). If the number of hosts is larger than 1, skip the test cases. Link: linux-blktests#218 Signed-off-by: Disha Goel <[email protected]> [Shin'ichiro: improved commit message] Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
|
@disgoel Thank you for updating the patch. While I did the final check of the patch, I noticed that it does not work as expected. Agrrr.
I created some patches to address these problems, which are available in the branch here. I will do some more testing and will post these as a series to linux-block. Your patch is here, in the series. I'm thinking to fold-in following two changes [1][2]. [1] kawasaki@11656fd Especially, [1] is the key difference. Could you check these changes? |
@kawasaki I have updated the PR with the final refactoring. I've switched to using the ${MODULES_TO_UNLOAD[*]} array check as suggested, which correctly identifies if scsi_debug was loaded by the test harness or pre-loaded by the system. I'm ready for these changes to be incorporated into your series for the mailing list. Thanks for the collaborative effort! |
Several tests across block/, scsi/, dm/, md/, zbd/, nvme/ require
exclusive access to the scsi_debug module because they load, unload
or reconfigure it. When scsi_debug is loadable and already loaded
by the environment (e.g., by another driver or a previous setup),
these tests fail with:
modprobe: FATAL: Module scsi_debug is in use.
Unloading scsi_debug failed
scsi_debug 327680 4
To prevent these failures, this patch introduces a new helper function
_have_loadable_scsi_debug(). It verifies if the module is already loaded
by checking the ${MODULES_TO_UNLOAD[*]} array. If the module exists but
is not in the array, it indicates the module was loaded before the test
started, and the test is skipped.
Additionally, for cases where scsi_debug is built-in, the environment may
have already created additional hosts. To prevent the tests from disrupting
these hosts, _have_scsi_debug() now checks the add_host attribute. If the
number of hosts is greater than 1, the test is skipped.
Signed-off-by: Disha Goel <[email protected]>
|
@disgoel Thanks for the response! I posted the patch series with your patch to linux-block list [3]. |
Several tests across block/, scsi/, dm/, md/, zbd/, nvme/ require
exclusive access to the scsi_debug module because they load, unload
or reconfigure it. When scsi_debug is loadable and already loaded
by the environment (e.g., by another driver or a previous setup),
these tests fail with:
modprobe: FATAL: Module scsi_debug is in use.
Unloading scsi_debug failed
scsi_debug 327680 4
To prevent these failures, this patch introduces a new helper function
_have_loadable_scsi_debug(). It verifies if the module is already loaded
by checking the ${MODULES_TO_UNLOAD[*]} array. If the module exists but
is not in the array, it indicates the module was loaded before the test
started, and the test is skipped.
Additionally, for cases where scsi_debug is built-in, the environment may
have already created additional hosts. To prevent the tests from disrupting
these hosts, _have_scsi_debug() now checks the add_host attribute. If the
number of hosts is greater than 1, the test is skipped.
Link: #218
Signed-off-by: Disha Goel <[email protected]>
Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
|
Now the change is in the master branch. Let me close this case. |
Several tests across block/, scsi/, dm/, md/, zbd/, nvme/ require exclusive access to the scsi_debug module because they load, unload or reconfigure it. When scsi_debug is already loaded by the environment (e.g., by another driver or a previous setup), these tests fail with:
Instead of modifying common rc files—which would overskip unrelated tests, this patch adds
_module_not_in_use scsi_debugonly to the tests that actually depend on exclusive access to scsi_debug.