From ce3cd4234c9cd90f8109a33ab86f3456c2edf947 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 13 May 2025 20:00:06 -0700 Subject: [PATCH] criu: simplify isOnTmpfs check in prepareCriuRestoreMounts 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 --- libcontainer/criu_linux.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/libcontainer/criu_linux.go b/libcontainer/criu_linux.go index 92a93e75f..a86e53fd7 100644 --- a/libcontainer/criu_linux.go +++ b/libcontainer/criu_linux.go @@ -523,11 +523,9 @@ func (c *Container) restoreNetwork(req *criurpc.CriuReq, criuOpts *CriuOpts) { } } -// isPathInPrefixList is a small function for CRIU restore to make sure -// mountpoints, which are on a tmpfs, are not created in the roofs. -func isPathInPrefixList(path string, prefix []string) bool { - for _, p := range prefix { - 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+"/") { return true } } @@ -541,14 +539,6 @@ func isPathInPrefixList(path string, prefix []string) bool { // This function also creates missing mountpoints as long as they // are not on top of a tmpfs, as CRIU will restore tmpfs content anyway. func (c *Container) prepareCriuRestoreMounts(mounts []*configs.Mount) error { - // First get a list of a all tmpfs mounts - tmpfs := []string{} - for _, m := range mounts { - switch m.Device { - case "tmpfs": - tmpfs = append(tmpfs, m.Destination) - } - } umounts := []string{} defer func() { for _, u := range umounts { @@ -576,7 +566,7 @@ func (c *Container) prepareCriuRestoreMounts(mounts []*configs.Mount) error { } // If the mountpoint is on a tmpfs, skip it as CRIU will // restore the complete tmpfs content from its checkpoint. - if isPathInPrefixList(m.Destination, tmpfs) { + if isOnTmpfs(m.Destination, mounts) { continue } if _, err := createMountpoint(c.config.Rootfs, mountEntry{Mount: m}); err != nil {