Skip to content

cleanup(pkg/driver): use unix where available.#353

Closed
FedeDP wants to merge 1 commit intomainfrom
cleanup/use_unix
Closed

cleanup(pkg/driver): use unix where available.#353
FedeDP wants to merge 1 commit intomainfrom
cleanup/use_unix

Conversation

@FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Nov 22, 2023

What type of PR is this?

/kind cleanup

Any specific area of the project related to this PR?

/area library

What this PR does / why we need it:

Small cleanups on top of #343 : use unix golang library where available.
NOTE: reimplementing insmod or modprobe in go, instead of executing it through an exec.Command is pretty convoluted since they do quite lot of things.
See for example how is that implemented in this library: https://github.com/pmorjan/kmod/tree/master
Also, that library itself does not help us much since the job is still pretty complex.
I'd avoid the risk of introducing bugs reimplementing ourselves 2 of the most widely used bash utilities.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
@poiana
Copy link
Contributor

poiana commented Nov 22, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

printer.Logger.Info("Check if kernel module is still loaded.")
lsmodCmdArgs := fmt.Sprintf(`lsmod | cut -d' ' -f1 | grep -qx %q`, kmodName)
_, err = exec.Command("bash", "-c", lsmodCmdArgs).Output() //nolint:gosec // false positive
f, err := os.Open("/proc/modules")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using lsmod, manually scan /proc/modules.

for i := 0; i < maxRmmodWait; i++ {
printer.Logger.Info("Kernel module is still loaded.")
printer.Logger.Info("Trying to unload it with 'rmmod'.")
if err = unix.DeleteModule(kmodName, 0); err == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of calling rmmod directly, just use unit.DeleteModule.

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 22, 2023

/close

This is not worth the trouble IMHO.

@poiana poiana closed this Nov 22, 2023
@poiana
Copy link
Contributor

poiana commented Nov 22, 2023

@FedeDP: Closed this PR.

Details

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants