From 5ebc58c2ccdfefc8cb22ee4099e1f68fe7fc036b Mon Sep 17 00:00:00 2001 From: Stanislav Petrov Date: Mon, 28 Oct 2024 17:18:47 +0300 Subject: [PATCH] Remove exit and oom from persist dir --- libpod/container_internal.go | 20 +++++++------------- libpod/oci.go | 3 +++ libpod/oci_conmon_common.go | 9 +++++++++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/libpod/container_internal.go b/libpod/container_internal.go index c7efd18e4b..17094b8604 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -153,6 +153,10 @@ func (c *Container) oomFilePath() (string, error) { return c.ociRuntime.OOMFilePath(c) } +func (c *Container) persistDir() (string, error) { + return c.ociRuntime.PersistDir(c) +} + // Wait for the container's exit file to appear. // When it does, update our state based on it. func (c *Container) waitForExitFileAndSync() error { @@ -757,22 +761,12 @@ func (c *Container) removeConmonFiles() error { return fmt.Errorf("removing container %s winsz file: %w", c.ID(), err) } - // Remove the exit file so we don't leak memory in tmpfs - exitFile, err := c.exitFilePath() - if err != nil { - return err - } - if err := os.Remove(exitFile); err != nil && !os.IsNotExist(err) { - return fmt.Errorf("removing container %s exit file: %w", c.ID(), err) - } - - // Remove the oom file - oomFile, err := c.oomFilePath() + persistDir, err := c.persistDir() if err != nil { return err } - if err := os.Remove(oomFile); err != nil && !errors.Is(err, fs.ErrNotExist) { - return fmt.Errorf("removing container %s oom file: %w", c.ID(), err) + if err := os.RemoveAll(persistDir); err != nil && !errors.Is(err, fs.ErrNotExist) { + return fmt.Errorf("removing container %s persist dir with exit & oom files: %w", c.ID(), err) } return nil diff --git a/libpod/oci.go b/libpod/oci.go index e0d7406339..d3661e9443 100644 --- a/libpod/oci.go +++ b/libpod/oci.go @@ -141,6 +141,9 @@ type OCIRuntime interface { //nolint:interfacebloat // exec session in the given container. // TODO: Probably should be made internal. ExecAttachSocketPath(ctr *Container, sessionID string) (string, error) + + // PersistDir is the path to a container's dir for oom & exit files. + PersistDir(ctr *Container) (string, error) // ExitFilePath is the path to a container's exit file. // All runtime implementations must create an exit file when containers // exit, containing the exit code of the container (as a string). diff --git a/libpod/oci_conmon_common.go b/libpod/oci_conmon_common.go index 8aa103fb49..544e99c3df 100644 --- a/libpod/oci_conmon_common.go +++ b/libpod/oci_conmon_common.go @@ -848,6 +848,15 @@ func (r *ConmonOCIRuntime) AttachSocketPath(ctr *Container) (string, error) { return filepath.Join(ctr.bundlePath(), "attach"), nil } +// PersistDir returns the persit dir containing oom & exit files for containers. +func (r *ConmonOCIRuntime) PersistDir(ctr *Container) (string, error) { + if ctr == nil { + return "", fmt.Errorf("must provide a valid container to get persist dir: %w", define.ErrInvalidArg) + } + + return filepath.Join(r.persistDir, ctr.ID()), nil +} + // ExitFilePath is the path to a container's exit file. func (r *ConmonOCIRuntime) ExitFilePath(ctr *Container) (string, error) { if ctr == nil {