diff options
author | Doug Rabson <dfr@rabson.org> | 2022-08-27 14:39:44 +0100 |
---|---|---|
committer | Doug Rabson <dfr@rabson.org> | 2022-09-05 10:17:50 +0100 |
commit | b3989be76851fc1aa0c29e579681be1ed56dafab (patch) | |
tree | 2ac6890441279757dbb7e584933c597dc4302f95 /libpod | |
parent | a148c16225241aaf25a36980973f8e4bcf08a647 (diff) | |
download | podman-b3989be76851fc1aa0c29e579681be1ed56dafab.tar.gz podman-b3989be76851fc1aa0c29e579681be1ed56dafab.tar.bz2 podman-b3989be76851fc1aa0c29e579681be1ed56dafab.zip |
libpod: Move getRootNetNsDepCtr to container_internal_common.go
[NO NEW TESTS NEEDED]
Signed-off-by: Doug Rabson <dfr@rabson.org>
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_internal_common.go | 28 | ||||
-rw-r--r-- | libpod/container_internal_freebsd.go | 30 | ||||
-rw-r--r-- | libpod/container_internal_linux.go | 28 |
3 files changed, 28 insertions, 58 deletions
diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go index d3e37802f..c5a6d4ff3 100644 --- a/libpod/container_internal_common.go +++ b/libpod/container_internal_common.go @@ -1567,3 +1567,31 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti return criuStatistics, runtimeRestoreDuration, c.save() } + +// Retrieves a container's "root" net namespace container dependency. +func (c *Container) getRootNetNsDepCtr() (depCtr *Container, err error) { + containersVisited := map[string]int{c.config.ID: 1} + nextCtr := c.config.NetNsCtr + for nextCtr != "" { + // Make sure we aren't in a loop + if _, visited := containersVisited[nextCtr]; visited { + return nil, errors.New("loop encountered while determining net namespace container") + } + containersVisited[nextCtr] = 1 + + depCtr, err = c.runtime.state.Container(nextCtr) + if err != nil { + return nil, fmt.Errorf("error fetching dependency %s of container %s: %w", c.config.NetNsCtr, c.ID(), err) + } + // This should never happen without an error + if depCtr == nil { + break + } + nextCtr = depCtr.config.NetNsCtr + } + + if depCtr == nil { + return nil, errors.New("unexpected error depCtr is nil without reported error from runtime state") + } + return depCtr, nil +} diff --git a/libpod/container_internal_freebsd.go b/libpod/container_internal_freebsd.go index b9ffbadf1..c8dbb8e15 100644 --- a/libpod/container_internal_freebsd.go +++ b/libpod/container_internal_freebsd.go @@ -190,43 +190,13 @@ func (c *Container) addNetworkContainer(g *generate.Generator, ctr string) error return nil } -// Retrieves a container's "root" net namespace container dependency. -func (c *Container) getRootNetNsDepCtr() (depCtr *Container, err error) { - containersVisited := map[string]int{c.config.ID: 1} - nextCtr := c.config.NetNsCtr - for nextCtr != "" { - // Make sure we aren't in a loop - if _, visited := containersVisited[nextCtr]; visited { - return nil, errors.New("loop encountered while determining net namespace container") - } - containersVisited[nextCtr] = 1 - - depCtr, err = c.runtime.state.Container(nextCtr) - if err != nil { - return nil, fmt.Errorf("error fetching dependency %s of container %s: %w", c.config.NetNsCtr, c.ID(), err) - } - // This should never happen without an error - if depCtr == nil { - break - } - nextCtr = depCtr.config.NetNsCtr - } - - if depCtr == nil { - return nil, errors.New("unexpected error depCtr is nil without reported error from runtime state") - } - return depCtr, nil -} - // Ensure standard bind mounts are mounted into all root directories (including chroot directories) func (c *Container) mountIntoRootDirs(mountName string, mountPath string) error { c.state.BindMounts[mountName] = mountPath for _, chrootDir := range c.config.ChrootDirs { c.state.BindMounts[filepath.Join(chrootDir, mountName)] = mountPath - logrus.Debugf("bind chrootDir=%s, mountName=%s", chrootDir, mountName) } - // TODO: copy the file return nil } diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index c6d2116d4..b2a77c9bb 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -343,34 +343,6 @@ func (c *Container) addNamespaceContainer(g *generate.Generator, ns LinuxNS, ctr return nil } -// Retrieves a container's "root" net namespace container dependency. -func (c *Container) getRootNetNsDepCtr() (depCtr *Container, err error) { - containersVisited := map[string]int{c.config.ID: 1} - nextCtr := c.config.NetNsCtr - for nextCtr != "" { - // Make sure we aren't in a loop - if _, visited := containersVisited[nextCtr]; visited { - return nil, errors.New("loop encountered while determining net namespace container") - } - containersVisited[nextCtr] = 1 - - depCtr, err = c.runtime.state.Container(nextCtr) - if err != nil { - return nil, fmt.Errorf("error fetching dependency %s of container %s: %w", c.config.NetNsCtr, c.ID(), err) - } - // This should never happen without an error - if depCtr == nil { - break - } - nextCtr = depCtr.config.NetNsCtr - } - - if depCtr == nil { - return nil, errors.New("unexpected error depCtr is nil without reported error from runtime state") - } - return depCtr, nil -} - // Ensure standard bind mounts are mounted into all root directories (including chroot directories) func (c *Container) mountIntoRootDirs(mountName string, mountPath string) error { c.state.BindMounts[mountName] = mountPath |