Skip to content
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

initContainer: Use unix.Mount syscall instead of mount external command #1277

Conversation

angiglesias
Copy link

Use golang unix syscalls package to perform mount operations instead of invoking in a shell the mount command.
Performing this operation programmatically should provide more observability debugging the code. It also reduces dependencies on external commands that may change or break functionality between versions.

@angiglesias angiglesias marked this pull request as ready for review March 21, 2023 19:32
@softwarefactory-project-zuul
Copy link

Build failed.
https://softwarefactory-project.io/zuul/t/local/buildset/2e1925e7c4e346ad9c56ea8359e3523c

✔️ unit-test SUCCESS in 8m 50s
unit-test-migration-path-for-coreos-toolbox FAILURE in 2m 52s
✔️ unit-test-restricted SUCCESS in 7m 55s
✔️ system-test-fedora-rawhide SUCCESS in 15m 09s
✔️ system-test-fedora-38 SUCCESS in 13m 39s
✔️ system-test-fedora-37 SUCCESS in 13m 43s
✔️ system-test-fedora-36 SUCCESS in 13m 56s

@angiglesias angiglesias force-pushed the fixes/use-native-mount-syscall branch from 759775f to 12389c1 Compare March 24, 2023 08:06
@softwarefactory-project-zuul
Copy link

Build failed.
https://softwarefactory-project.io/zuul/t/local/buildset/662641e5133540f29a1cf7d1b8927959

✔️ unit-test SUCCESS in 8m 38s
✔️ unit-test-migration-path-for-coreos-toolbox SUCCESS in 2m 59s
unit-test-restricted RETRY_LIMIT in 7m 20s
system-test-fedora-rawhide RETRY_LIMIT in 8m 14s
✔️ system-test-fedora-38 SUCCESS in 15m 42s
system-test-fedora-37 RETRY_LIMIT in 8m 12s
system-test-fedora-36 RETRY_LIMIT in 8m 14s

@angiglesias angiglesias force-pushed the fixes/use-native-mount-syscall branch from 12389c1 to d5b3b30 Compare March 24, 2023 17:08
@softwarefactory-project-zuul
Copy link

Build succeeded.
https://softwarefactory-project.io/zuul/t/local/buildset/04163f225fb842dcb3fce42c63e6f2eb

✔️ unit-test SUCCESS in 9m 24s
✔️ unit-test-migration-path-for-coreos-toolbox SUCCESS in 3m 39s
✔️ unit-test-restricted SUCCESS in 8m 22s
✔️ system-test-fedora-rawhide SUCCESS in 17m 32s
✔️ system-test-fedora-38 SUCCESS in 16m 08s
✔️ system-test-fedora-37 SUCCESS in 16m 06s
✔️ system-test-fedora-36 SUCCESS in 16m 26s

Copy link
Member

@debarshiray debarshiray left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, @angiglesias ! Was there an immediate problem that inspired you to make this change?

In principle, it will be good to use the mount(2) system call through golang.org/x/sys/unix, instead of going through the mount(8) command, but it's not that simple a replacement. :)

For example, I think Podman makes mistakes using the mount(2) system call, which leads to #1073 There's this pitfall that mount(2) doesn't propagate the mount flags to existing sub-mounts when performing a recursive bind mount. Notice how the bug can't be reproduced when the bind mounts are handled by mount(8) instead of Podman.

A good example of using mount(2) to do bind mounts is the bind_mount() function in bwrap(1). Especially the part where it works around the mount flags not getting applying to existing sub-mounts for recursive bind mounts.

So, before we change how bind mounts are done in Toolbx itself, we first need to solve #1073 so that we know what we are doing. Then, if we implement a replacement for mount --rbind in Toolbx itself, we would need good test coverage for it.

@debarshiray
Copy link
Member

Also, please squash the two commits into one, because we don't want to break the tests between commits.

@angiglesias
Copy link
Author

Thanks for working on this, @angiglesias ! Was there an immediate problem that inspired you to make this change?

In principle, it will be good to use the mount(2) system call through golang.org/x/sys/unix, instead of going through the mount(8) command, but it's not that simple a replacement. :)

For example, I think Podman makes mistakes using the mount(2) system call, which leads to #1073 There's this pitfall that mount(2) doesn't propagate the mount flags to existing sub-mounts when performing a recursive bind mount. Notice how the bug can't be reproduced when the bind mounts are handled by mount(8) instead of Podman.

A good example of using mount(2) to do bind mounts is the bind_mount() function in bwrap(1). Especially the part where it works around the mount flags not getting applying to existing sub-mounts for recursive bind mounts.

So, before we change how bind mounts are done in Toolbx itself, we first need to solve #1073 so that we know what we are doing. Then, if we implement a replacement for mount --rbind in Toolbx itself, we would need good test coverage for it.

While I was investigating #1001 I thought it would be easier to debug the program reducing shell invocations to utilities such as mount using programmatic alternatives when possible. For the mounts, as the syscall is available through the already imported golang.org/x/sys/unix seemed a reasonable change. I didn't know the problems mentioned in those issues, I'll take a careful look, thanks!

@angiglesias angiglesias force-pushed the fixes/use-native-mount-syscall branch from d5b3b30 to 078a5cc Compare April 4, 2023 22:22
Use golang unix syscalls package to perform mount operations instead of
invoking in a shell the mount command.
Performing this operation programmatically should provide more
observability debugging the code. It also reduces dependencies on external
commands that may change or break functionality between versions.

Signed-off-by: Angel Iglesias <[email protected]>
@angiglesias angiglesias force-pushed the fixes/use-native-mount-syscall branch from 078a5cc to 7d63981 Compare April 4, 2023 22:22
@softwarefactory-project-zuul
Copy link

Build succeeded.
https://softwarefactory-project.io/zuul/t/local/buildset/c109b4b4226e4ef6a72c9be909989894

✔️ unit-test SUCCESS in 9m 09s
✔️ unit-test-migration-path-for-coreos-toolbox SUCCESS in 3m 09s
✔️ unit-test-restricted SUCCESS in 8m 09s
✔️ system-test-fedora-rawhide SUCCESS in 20m 14s
✔️ system-test-fedora-38 SUCCESS in 19m 31s
✔️ system-test-fedora-37 SUCCESS in 19m 00s
✔️ system-test-fedora-36 SUCCESS in 19m 07s

Copy link
Member

@debarshiray debarshiray left a comment

Choose a reason for hiding this comment

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

Thanks for squashing the commits, @angiglesias ! Did you manage to find some time for a more complete replacement of the mount(8) command using the mount(2) system call and/or a solution for #1073 and/or increasing our test coverage so that we can be sure that we are not regressing anything when we make changes?

@debarshiray
Copy link
Member

I am going to close this because this still doesn't have a complete replacement of the mount(8) command using mount(2) nor does it increase our test coverage so that we can be sure that we are not regressing anything when we make the change.

Please feel free to submit a new merge request when you have some updates.

@debarshiray
Copy link
Member

Thanks for playing with Toolbox @angiglesias !

@debarshiray debarshiray closed this Oct 4, 2023
@angiglesias
Copy link
Author

@debarshiray hey sorry for the unresponsiviness! I will try to find a moment to redo this PR properly to address those issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants