-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Refactor/improve prepareCriuRestoreMounts #4765
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
Conversation
1. Replace the big "if !" block with the if block and continue, simplifying the code flow. 2. Move comments closer to the code, improving readability. This commit is best reviewed with --ignore-all-space or similar. Signed-off-by: Kir Kolyshkin <[email protected]>
It makes sense to ignore cgroup mounts much early in the code, saving some time on unnecessary operations. Signed-off-by: Kir Kolyshkin <[email protected]>
Since its code is now trivial, and it is only called from a single place, it does not make sense to have it as a separate function. Signed-off-by: Kir Kolyshkin <[email protected]>
Instead of generating a list of tmpfs mount and have a special function to check whether the path is in the list, let's go over the list of mounts directly. This simplifies the code and improves readability. Signed-off-by: Kir Kolyshkin <[email protected]>
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.
LGTM
Sorry I didn't see this before. Don't hesitate to ping the next time! :)
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.
Pull Request Overview
This PR refactors the prepareCriuRestoreMounts
function to improve readability and performance while maintaining the same behavior. The changes streamline the mount preparation logic during CRIU restore operations.
- Removes helper functions
makeCriuRestoreMountpoints
andisPathInPrefixList
- Inlines mount creation logic directly into the main function
- Replaces the two-pass approach with a single pass through mounts
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
if strings.HasPrefix(path, p+"/") { | ||
func isOnTmpfs(path string, mounts []*configs.Mount) bool { | ||
for _, m := range mounts { | ||
if m.Device == "tmpfs" && strings.HasPrefix(path, m.Destination+"/") { |
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 string comparison logic has changed from the original isPathInPrefixList
function. The original checked for path
starting with p+"/"
but this checks for path
starting with m.Destination+"/"
. This could miss cases where path
exactly equals m.Destination
(without the trailing slash), which the original logic would have caught since it also checked path == p
.
if m.Device == "tmpfs" && strings.HasPrefix(path, m.Destination+"/") { | |
if m.Device == "tmpfs" && (path == m.Destination || strings.HasPrefix(path, m.Destination+"/")) { |
Copilot uses AI. Check for mistakes.
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.
which the original logic would have caught since it also checked
path == p
.
In which line?
@cyphar Perhaps we should consider backporting this change to the release-1.x branches, even though it's primarily a code refactor. This would help avoid potential merge conflicts and inconveniences when integrating future changes to this file. |
When we hit a case of a cherry-pick not working, I'd be fine with the backport. |
@rata I've hit it with a backport, we should backport it imho. |
This makes
prepareCriuRestoreMounts
more readable, smaller, and slightly faster.Split to 4 commits for easier review.
Should not change behavior in any way.
Covered by existing tests in
tests/integration/checkpoint.bats
.