From 8b973997a428a1f595a4c8e3fa02788983ac16e9 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 31 Jul 2020 17:52:09 -0700 Subject: [PATCH 1/2] libct: criuNsToKey doesn't have to be a method Signed-off-by: Kir Kolyshkin --- libcontainer/container_linux.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index ce62ea48..321d7c8e 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -852,7 +852,7 @@ func (c *linuxContainer) criuSupportsExtNS(t configs.NamespaceType) bool { return c.checkCriuVersion(minVersion) == nil } -func (c *linuxContainer) criuNsToKey(t configs.NamespaceType) string { +func criuNsToKey(t configs.NamespaceType) string { return "extRoot" + strings.Title(configs.NsName(t)) + "NS" } @@ -872,7 +872,7 @@ func (c *linuxContainer) handleCheckpointingExternalNamespaces(rpcOpts *criurpc. if err := unix.Stat(nsPath, &ns); err != nil { return err } - criuExternal := fmt.Sprintf("%s[%d]:%s", configs.NsName(t), ns.Ino, c.criuNsToKey(t)) + criuExternal := fmt.Sprintf("%s[%d]:%s", configs.NsName(t), ns.Ino, criuNsToKey(t)) rpcOpts.External = append(rpcOpts.External, criuExternal) return nil @@ -897,7 +897,7 @@ func (c *linuxContainer) handleRestoringExternalNamespaces(rpcOpts *criurpc.Criu return fmt.Errorf("Requested network namespace %v does not exist", nsPath) } inheritFd := new(criurpc.InheritFd) - inheritFd.Key = proto.String(c.criuNsToKey(t)) + inheritFd.Key = proto.String(criuNsToKey(t)) // The offset of four is necessary because 0, 1, 2 and 3 is already // used by stdin, stdout, stderr, 'criu swrk' socket. inheritFd.Fd = proto.Int32(int32(4 + len(*extraFiles))) From e54d1e471547f43a630ee2d682ab48ff9d665aa7 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 31 Jul 2020 17:55:09 -0700 Subject: [PATCH 2/2] libct: initialize inheritFD in place Signed-off-by: Kir Kolyshkin --- libcontainer/container_linux.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 321d7c8e..8dc70bb2 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -896,11 +896,12 @@ func (c *linuxContainer) handleRestoringExternalNamespaces(rpcOpts *criurpc.Criu logrus.Errorf("If a specific network namespace is defined it must exist: %s", err) return fmt.Errorf("Requested network namespace %v does not exist", nsPath) } - inheritFd := new(criurpc.InheritFd) - inheritFd.Key = proto.String(criuNsToKey(t)) - // The offset of four is necessary because 0, 1, 2 and 3 is already - // used by stdin, stdout, stderr, 'criu swrk' socket. - inheritFd.Fd = proto.Int32(int32(4 + len(*extraFiles))) + inheritFd := &criurpc.InheritFd{ + Key: proto.String(criuNsToKey(t)), + // The offset of four is necessary because 0, 1, 2 and 3 are + // already used by stdin, stdout, stderr, 'criu swrk' socket. + Fd: proto.Int32(int32(4 + len(*extraFiles))), + } rpcOpts.InheritFd = append(rpcOpts.InheritFd, inheritFd) // All open FDs need to be transferred to CRIU via extraFiles *extraFiles = append(*extraFiles, nsFd)