Skip to content

Commit 0c93d41

Browse files
committed
criu: improve prepareCriuRestoreMounts
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]>
1 parent 8eb2f43 commit 0c93d41

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

libcontainer/criu_linux.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,6 @@ func (c *Container) prepareCriuRestoreMounts(mounts []*configs.Mount) error {
572572
tmpfs = append(tmpfs, m.Destination)
573573
}
574574
}
575-
// Now go through all mounts and create the mountpoints
576-
// if the mountpoints are not on a tmpfs, as CRIU will
577-
// restore the complete tmpfs content from its checkpoint.
578575
umounts := []string{}
579576
defer func() {
580577
for _, u := range umounts {
@@ -590,28 +587,32 @@ func (c *Container) prepareCriuRestoreMounts(mounts []*configs.Mount) error {
590587
})
591588
}
592589
}()
590+
// Now go through all mounts and create the required mountpoints.
593591
for _, m := range mounts {
594-
if !isPathInPrefixList(m.Destination, tmpfs) {
595-
if err := c.makeCriuRestoreMountpoints(m); err != nil {
592+
// If the mountpoint is on a tmpfs, skip it as CRIU will
593+
// restore the complete tmpfs content from its checkpoint.
594+
if isPathInPrefixList(m.Destination, tmpfs) {
595+
continue
596+
}
597+
if err := c.makeCriuRestoreMountpoints(m); err != nil {
598+
return err
599+
}
600+
// If the mount point is a bind mount, we need to mount
601+
// it now so that runc can create the necessary mount
602+
// points for mounts in bind mounts.
603+
// This also happens during initial container creation.
604+
// Without this CRIU restore will fail
605+
// See: https://github.com/opencontainers/runc/issues/2748
606+
// It is also not necessary to order the mount points
607+
// because during initial container creation mounts are
608+
// set up in the order they are configured.
609+
if m.Device == "bind" {
610+
if err := utils.WithProcfd(c.config.Rootfs, m.Destination, func(dstFd string) error {
611+
return mountViaFds(m.Source, nil, m.Destination, dstFd, "", unix.MS_BIND|unix.MS_REC, "")
612+
}); err != nil {
596613
return err
597614
}
598-
// If the mount point is a bind mount, we need to mount
599-
// it now so that runc can create the necessary mount
600-
// points for mounts in bind mounts.
601-
// This also happens during initial container creation.
602-
// Without this CRIU restore will fail
603-
// See: https://github.com/opencontainers/runc/issues/2748
604-
// It is also not necessary to order the mount points
605-
// because during initial container creation mounts are
606-
// set up in the order they are configured.
607-
if m.Device == "bind" {
608-
if err := utils.WithProcfd(c.config.Rootfs, m.Destination, func(dstFd string) error {
609-
return mountViaFds(m.Source, nil, m.Destination, dstFd, "", unix.MS_BIND|unix.MS_REC, "")
610-
}); err != nil {
611-
return err
612-
}
613-
umounts = append(umounts, m.Destination)
614-
}
615+
umounts = append(umounts, m.Destination)
615616
}
616617
}
617618
return nil

0 commit comments

Comments
 (0)