-
Notifications
You must be signed in to change notification settings - Fork 55
modprobe: don't attempt to remove an already removed module #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for the patch Jan, at a glance the patch looks great. Some tests would be appreciated - sadly we don't have any @lucasdemarchi the help/manual for |
|
Thanks for pointer, I'll have a look if I can add some test. |
|
Just a small update: I haven't found a good way so far to make the test work (at least not with |
d2dfc1a to
c2ecd12
Compare
|
@evelikov I've added a test that goes the way of using real /sys, with a custom check for loaded modules. What do you think about this approach? |
evelikov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a handful of comments - would be great to have them addressed, but are non blocking.
Overall I love the idea of test_spawn_and_wait4_prog even if the name is a bit long-winded.
Off the top of my head, we could convert all test_spawn users to it, merge the two while keeping the shorter name... Although that's completely orthogonal and should be done as follow-up.
Thanks again for the fix
P.S. While I have commit access to the repo, Lucas does the merge/push to both github and kernel.org. He's busy recently so your patience is appreciated 🙇
testsuite/meson.build
Outdated
| 'test-loaded', | ||
| 'test-modinfo', | ||
| 'test-modprobe', | ||
| 'test-modprobe-remove-holders', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: lets move the extra test to the existing test-modprobe.c
| @@ -0,0 +1,88 @@ | |||
| // SPDX-License-Identifier: LGPL-2.1-or-later | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing relevant copyright blurb - either personal or employer.
| ERR("failed trying to remove module and holders: %d\n", ret); | ||
| goto cleanup; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT modprobe will error out if the module(s) are already loaded and similarly, if remove fails we'll also get an error.
Thus we don't need to create kmod context and/or check if the modules are loaded afterwards, right? Or am I missing something.
testsuite/testsuite.c
Outdated
| const char *msg; | ||
|
|
||
| pid = fork(); | ||
| if (pid < 0) { \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray \
testsuite/testsuite.c
Outdated
| } | ||
|
|
||
| if (pid == 0) | ||
| test_spawn_prog(prog, args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: return test_spawn_prog...
testsuite/testsuite.c
Outdated
| msg = "exited with"; | ||
| goto print_error; | ||
| } | ||
| return WEXITSTATUS(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: here and below return err;
testsuite/testsuite.c
Outdated
| goto print_error; | ||
| } | ||
| return WEXITSTATUS(err); | ||
| } else if (WIFSIGNALED(err)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: no need for an else after return. Namely:
}
if (WIFSIGNALED(err)) {
testsuite/testsuite.c
Outdated
| return WTERMSIG(err); | ||
| } | ||
|
|
||
| return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return 0 is unreachable right? Let's remove it unless the compiler complains.
testsuite/testsuite.c
Outdated
| print_error: | ||
| ERR("%s %s %d\n", prog, msg, ret); | ||
| while (*args) { | ||
| LOG(" args: %s\n", *args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: let's make this a small helper function. I think we want ERR for both program and args.
About to thinker with it myself, but for the sake of posterity - what happens if we don't have the real /sys? Note that it's breaking the tests/CI which expect self-contained environment. Aside: there are some trivial clang-format errors. |
|
Adding a dummy Namely: the ld preload shims are not properly managing the relevant sysfs files:
Would be awesome to have a proper test and it depends if/how much time you have to shave this yak. Personally, I would be fine with landing the fix alone and worrying about the rest/test at a later stage. |
In a scenario like following:
# lsmod | grep -e bnx2i -e cnic
bnx2i 94208 0
libiscsi 94208 1 bnx2i
cnic 90112 1 bnx2i
uio 32768 1 cnic
scsi_transport_iscsi 196608 2 bnx2i,libiscsi
# modprobe -v --remove --remove-holders cnic
rmmod bnx2i
rmmod cnic
rmmod libiscsi
rmmod cnic
modprobe: ERROR: libkmod/libkmod-module.c:856 kmod_module_remove_module()
could not remove 'cnic': No such file or directory
modprobe attempts to remove cnic module twice and propagates that error
to the user with a message as well as an exit code.
Add a check to avoid attempts to remove modules that are already gone.
Signed-off-by: Jan Stancek <jstancek@redhat.com>
c2ecd12 to
fd68288
Compare
OK, so that approach is a no-go for CI.
I've gone back to just modprobe fix here, and leave tests for a separate PR. Thanks for code comments, and scheding some light on how tests work. From what I've gathered I can't load module "for real" and need test infrastructure enhanced to work with refcnt, holders, etc. |
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
|
FTR the CI failure is unrelated (Debian bullseye repos have moved) and will be resolved with #395. |
In a scenario like following:
lsmod | grep -e bnx2i -e cnic
bnx2i 94208 0
libiscsi 94208 1 bnx2i
cnic 90112 1 bnx2i
uio 32768 1 cnic
scsi_transport_iscsi 196608 2 bnx2i,libiscsi
modprobe -v --remove --remove-holders cnic
rmmod bnx2i
rmmod cnic
rmmod libiscsi
rmmod cnic
modprobe: ERROR: libkmod/libkmod-module.c:856 kmod_module_remove_module()
could not remove 'cnic': No such file or directory
modprobe attempts to remove cnic module twice and propagates that error to the user with a message as well as an exit code.
Add a check to avoid attempts to remove modules that are already gone.
Signed-off-by: Jan Stancek jstancek@redhat.com