Skip to content

Conversation

kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented May 14, 2025

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.

kolyshkin added 4 commits May 20, 2025 16:56
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]>
Copy link
Member

@rata rata left a 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! :)

Copy link

@Copilot Copilot AI left a 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 and isPathInPrefixList
  • 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+"/") {
Copy link
Preview

Copilot AI Aug 14, 2025

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.

Suggested change
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.

Copy link
Member

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?

@lifubang lifubang merged commit d2e86c0 into opencontainers:main Aug 24, 2025
31 checks passed
@lifubang
Copy link
Member

@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.

@rata
Copy link
Member

rata commented Aug 27, 2025

When we hit a case of a cherry-pick not working, I'd be fine with the backport.

@kolyshkin kolyshkin added the backport/1.3-done A PR in main branch which has been backported to release-1.3 label Aug 28, 2025
@kolyshkin
Copy link
Contributor Author

1.3 backport: #4871
1.2 backport: #4872

@kolyshkin kolyshkin added the backport/1.2-done A PR in main branch which has been backported to release-1.2 label Aug 28, 2025
@cyphar
Copy link
Member

cyphar commented Aug 28, 2025

@rata I've hit it with a backport, we should backport it imho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/checkpoint-restore backport/1.2-done A PR in main branch which has been backported to release-1.2 backport/1.3-done A PR in main branch which has been backported to release-1.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants