Skip to content

Commit b123969

Browse files
committed
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 <[email protected]>
1 parent 3e4024c commit b123969

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

libcontainer/criu_linux.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,9 @@ func (c *Container) restoreNetwork(req *criurpc.CriuReq, criuOpts *CriuOpts) {
523523
}
524524
}
525525

526-
// isPathInPrefixList is a small function for CRIU restore to make sure
527-
// mountpoints, which are on a tmpfs, are not created in the roofs.
528-
func isPathInPrefixList(path string, prefix []string) bool {
529-
for _, p := range prefix {
530-
if strings.HasPrefix(path, p+"/") {
526+
func isOnTmpfs(path string, mounts []*configs.Mount) bool {
527+
for _, m := range mounts {
528+
if m.Device == "tmpfs" && strings.HasPrefix(path, m.Destination+"/") {
531529
return true
532530
}
533531
}
@@ -541,14 +539,6 @@ func isPathInPrefixList(path string, prefix []string) bool {
541539
// This function also creates missing mountpoints as long as they
542540
// are not on top of a tmpfs, as CRIU will restore tmpfs content anyway.
543541
func (c *Container) prepareCriuRestoreMounts(mounts []*configs.Mount) error {
544-
// First get a list of a all tmpfs mounts
545-
tmpfs := []string{}
546-
for _, m := range mounts {
547-
switch m.Device {
548-
case "tmpfs":
549-
tmpfs = append(tmpfs, m.Destination)
550-
}
551-
}
552542
umounts := []string{}
553543
defer func() {
554544
for _, u := range umounts {
@@ -576,7 +566,7 @@ func (c *Container) prepareCriuRestoreMounts(mounts []*configs.Mount) error {
576566
}
577567
// If the mountpoint is on a tmpfs, skip it as CRIU will
578568
// restore the complete tmpfs content from its checkpoint.
579-
if isPathInPrefixList(m.Destination, tmpfs) {
569+
if isOnTmpfs(m.Destination, mounts) {
580570
continue
581571
}
582572
if _, err := createMountpoint(c.config.Rootfs, mountEntry{Mount: m}); err != nil {

0 commit comments

Comments
 (0)