Skip to content

Commit 66888fb

Browse files
kolyshkinlifubang
authored andcommitted
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]> (cherry picked from commit ce3cd42) Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 8559d3e commit 66888fb

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
@@ -519,11 +519,9 @@ func (c *Container) restoreNetwork(req *criurpc.CriuReq, criuOpts *CriuOpts) {
519519
}
520520
}
521521

522-
// isPathInPrefixList is a small function for CRIU restore to make sure
523-
// mountpoints, which are on a tmpfs, are not created in the roofs.
524-
func isPathInPrefixList(path string, prefix []string) bool {
525-
for _, p := range prefix {
526-
if strings.HasPrefix(path, p+"/") {
522+
func isOnTmpfs(path string, mounts []*configs.Mount) bool {
523+
for _, m := range mounts {
524+
if m.Device == "tmpfs" && strings.HasPrefix(path, m.Destination+"/") {
527525
return true
528526
}
529527
}
@@ -537,14 +535,6 @@ func isPathInPrefixList(path string, prefix []string) bool {
537535
// This function also creates missing mountpoints as long as they
538536
// are not on top of a tmpfs, as CRIU will restore tmpfs content anyway.
539537
func (c *Container) prepareCriuRestoreMounts(mounts []*configs.Mount) error {
540-
// First get a list of a all tmpfs mounts
541-
tmpfs := []string{}
542-
for _, m := range mounts {
543-
switch m.Device {
544-
case "tmpfs":
545-
tmpfs = append(tmpfs, m.Destination)
546-
}
547-
}
548538
umounts := []string{}
549539
defer func() {
550540
for _, u := range umounts {
@@ -572,7 +562,7 @@ func (c *Container) prepareCriuRestoreMounts(mounts []*configs.Mount) error {
572562
}
573563
// If the mountpoint is on a tmpfs, skip it as CRIU will
574564
// restore the complete tmpfs content from its checkpoint.
575-
if isPathInPrefixList(m.Destination, tmpfs) {
565+
if isOnTmpfs(m.Destination, mounts) {
576566
continue
577567
}
578568
if _, err := createMountpoint(c.config.Rootfs, mountEntry{Mount: m}); err != nil {

0 commit comments

Comments
 (0)