mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
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 <kolyshkin@gmail.com>
(cherry picked from commit ce3cd4234c)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -519,11 +519,9 @@ func (c *Container) restoreNetwork(req *criurpc.CriuReq, criuOpts *CriuOpts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// isPathInPrefixList is a small function for CRIU restore to make sure
|
func isOnTmpfs(path string, mounts []*configs.Mount) bool {
|
||||||
// mountpoints, which are on a tmpfs, are not created in the roofs.
|
for _, m := range mounts {
|
||||||
func isPathInPrefixList(path string, prefix []string) bool {
|
if m.Device == "tmpfs" && strings.HasPrefix(path, m.Destination+"/") {
|
||||||
for _, p := range prefix {
|
|
||||||
if strings.HasPrefix(path, p+"/") {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -537,14 +535,6 @@ func isPathInPrefixList(path string, prefix []string) bool {
|
|||||||
// This function also creates missing mountpoints as long as they
|
// This function also creates missing mountpoints as long as they
|
||||||
// are not on top of a tmpfs, as CRIU will restore tmpfs content anyway.
|
// are not on top of a tmpfs, as CRIU will restore tmpfs content anyway.
|
||||||
func (c *Container) prepareCriuRestoreMounts(mounts []*configs.Mount) error {
|
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{}
|
umounts := []string{}
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, u := range umounts {
|
for _, u := range umounts {
|
||||||
@@ -572,7 +562,7 @@ func (c *Container) prepareCriuRestoreMounts(mounts []*configs.Mount) error {
|
|||||||
}
|
}
|
||||||
// If the mountpoint is on a tmpfs, skip it as CRIU will
|
// If the mountpoint is on a tmpfs, skip it as CRIU will
|
||||||
// restore the complete tmpfs content from its checkpoint.
|
// restore the complete tmpfs content from its checkpoint.
|
||||||
if isPathInPrefixList(m.Destination, tmpfs) {
|
if isOnTmpfs(m.Destination, mounts) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, err := createMountpoint(c.config.Rootfs, mountEntry{Mount: m}); err != nil {
|
if _, err := createMountpoint(c.config.Rootfs, mountEntry{Mount: m}); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user