From 8754687b55a2957b6a58b1d79cc891df3c3764b4 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 1 Apr 2025 14:53:35 -0700 Subject: [PATCH] libpod: move linux-specific code to _linux.go This fixes a few "unused" linter warnings on freebsd. Signed-off-by: Kir Kolyshkin --- libpod/container_inspect.go | 35 ------------------------------- libpod/container_inspect_linux.go | 35 +++++++++++++++++++++++++++++++ libpod/oci_conmon_linux.go | 5 +++++ libpod/oci_util.go | 5 ----- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go index 111a88764b..5d759ecc22 100644 --- a/libpod/container_inspect.go +++ b/libpod/container_inspect.go @@ -11,7 +11,6 @@ import ( "github.com/containers/podman/v5/libpod/driver" "github.com/containers/podman/v5/pkg/signal" "github.com/containers/podman/v5/pkg/util" - "github.com/containers/storage/types" "github.com/docker/go-units" spec "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" @@ -491,17 +490,6 @@ func (c *Container) generateInspectContainerConfig(spec *spec.Spec) *define.Insp return ctrConfig } -func generateIDMappings(idMappings types.IDMappingOptions) *define.InspectIDMappings { - var inspectMappings define.InspectIDMappings - for _, uid := range idMappings.UIDMap { - inspectMappings.UIDMap = append(inspectMappings.UIDMap, fmt.Sprintf("%d:%d:%d", uid.ContainerID, uid.HostID, uid.Size)) - } - for _, gid := range idMappings.GIDMap { - inspectMappings.GIDMap = append(inspectMappings.GIDMap, fmt.Sprintf("%d:%d:%d", gid.ContainerID, gid.HostID, gid.Size)) - } - return &inspectMappings -} - // Generate the InspectContainerHostConfig struct for the HostConfig field of // Inspect. func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, namedVolumes []*ContainerNamedVolume, mounts []spec.Mount) (*define.InspectContainerHostConfig, error) { @@ -659,29 +647,6 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named return hostConfig, nil } -// Return true if the container is running in the host's PID NS. -func (c *Container) inHostPidNS() (bool, error) { - if c.config.PIDNsCtr != "" { - return false, nil - } - ctrSpec, err := c.specFromState() - if err != nil { - return false, err - } - if ctrSpec.Linux != nil { - // Locate the spec's PID namespace. - // If there is none, it's pid=host. - // If there is one and it has a path, it's "ns:". - // If there is no path, it's default - the empty string. - for _, ns := range ctrSpec.Linux.Namespaces { - if ns.Type == spec.PIDNamespace { - return false, nil - } - } - } - return true, nil -} - func (c *Container) GetDevices(priv bool, ctrSpec spec.Spec, deviceNodes map[string]string) ([]define.InspectDevice, error) { devices := []define.InspectDevice{} if ctrSpec.Linux != nil && !priv { diff --git a/libpod/container_inspect_linux.go b/libpod/container_inspect_linux.go index c407a7ebe2..e8fd37c05c 100644 --- a/libpod/container_inspect_linux.go +++ b/libpod/container_inspect_linux.go @@ -10,6 +10,7 @@ import ( "github.com/containers/common/pkg/config" "github.com/containers/podman/v5/libpod/define" "github.com/containers/podman/v5/pkg/util" + "github.com/containers/storage/types" "github.com/moby/sys/capability" spec "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" @@ -309,3 +310,37 @@ func (c *Container) platformInspectContainerHostConfig(ctrSpec *spec.Spec, hostC return nil } + +func generateIDMappings(idMappings types.IDMappingOptions) *define.InspectIDMappings { + var inspectMappings define.InspectIDMappings + for _, uid := range idMappings.UIDMap { + inspectMappings.UIDMap = append(inspectMappings.UIDMap, fmt.Sprintf("%d:%d:%d", uid.ContainerID, uid.HostID, uid.Size)) + } + for _, gid := range idMappings.GIDMap { + inspectMappings.GIDMap = append(inspectMappings.GIDMap, fmt.Sprintf("%d:%d:%d", gid.ContainerID, gid.HostID, gid.Size)) + } + return &inspectMappings +} + +// Return true if the container is running in the host's PID NS. +func (c *Container) inHostPidNS() (bool, error) { + if c.config.PIDNsCtr != "" { + return false, nil + } + ctrSpec, err := c.specFromState() + if err != nil { + return false, err + } + if ctrSpec.Linux != nil { + // Locate the spec's PID namespace. + // If there is none, it's pid=host. + // If there is one and it has a path, it's "ns:". + // If there is no path, it's default - the empty string. + for _, ns := range ctrSpec.Linux.Namespaces { + if ns.Type == spec.PIDNamespace { + return false, nil + } + } + } + return true, nil +} diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go index 22ad3b5697..93dd53f77c 100644 --- a/libpod/oci_conmon_linux.go +++ b/libpod/oci_conmon_linux.go @@ -164,6 +164,11 @@ func (r *ConmonOCIRuntime) withContainerSocketLabel(ctr *Container, closure func return err } +// Create systemd unit name for cgroup scopes. +func createUnitName(prefix string, name string) string { + return fmt.Sprintf("%s-%s.scope", prefix, name) +} + // moveConmonToCgroupAndSignal gets a container's cgroupParent and moves the conmon process to that cgroup // it then signals for conmon to start by sending nonce data down the start fd func (r *ConmonOCIRuntime) moveConmonToCgroupAndSignal(ctr *Container, cmd *exec.Cmd, startFd *os.File) error { diff --git a/libpod/oci_util.go b/libpod/oci_util.go index 292f59a117..8b20af70cf 100644 --- a/libpod/oci_util.go +++ b/libpod/oci_util.go @@ -27,11 +27,6 @@ type ociError struct { Msg string `json:"msg,omitempty"` } -// Create systemd unit name for cgroup scopes -func createUnitName(prefix string, name string) string { - return fmt.Sprintf("%s-%s.scope", prefix, name) -} - // Bind ports to keep them closed on the host func bindPorts(ports []types.PortMapping) ([]*os.File, error) { var files []*os.File