mirror of
https://github.com/containers/podman.git
synced 2025-06-05 14:06:01 +08:00
util: drop IsCgroup2UnifiedMode and use it from cgroups
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
|
"github.com/containers/libpod/pkg/cgroups"
|
||||||
"github.com/containers/libpod/pkg/namespaces"
|
"github.com/containers/libpod/pkg/namespaces"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
@ -112,7 +113,7 @@ func getRuntime(ctx context.Context, c *cliconfig.PodmanCommand, renumber bool,
|
|||||||
if c.Flags().Changed("cgroup-manager") {
|
if c.Flags().Changed("cgroup-manager") {
|
||||||
options = append(options, libpod.WithCgroupManager(c.GlobalFlags.CGroupManager))
|
options = append(options, libpod.WithCgroupManager(c.GlobalFlags.CGroupManager))
|
||||||
} else {
|
} else {
|
||||||
unified, err := util.IsCgroup2UnifiedMode()
|
unified, err := cgroups.IsCgroup2UnifiedMode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
|
"github.com/containers/libpod/pkg/cgroups"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/containers/libpod/pkg/tracing"
|
"github.com/containers/libpod/pkg/tracing"
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
@ -31,7 +32,7 @@ func init() {
|
|||||||
cgroupManager = runtimeConfig.CgroupManager
|
cgroupManager = runtimeConfig.CgroupManager
|
||||||
}
|
}
|
||||||
cgroupHelp := "Cgroup manager to use (cgroupfs or systemd)"
|
cgroupHelp := "Cgroup manager to use (cgroupfs or systemd)"
|
||||||
cgroupv2, _ := util.IsCgroup2UnifiedMode()
|
cgroupv2, _ := cgroups.IsCgroup2UnifiedMode()
|
||||||
if rootless.IsRootless() && !cgroupv2 {
|
if rootless.IsRootless() && !cgroupv2 {
|
||||||
cgroupManager = ""
|
cgroupManager = ""
|
||||||
cgroupHelp = "Cgroup manager is not supported in rootless mode"
|
cgroupHelp = "Cgroup manager is not supported in rootless mode"
|
||||||
|
@ -5,9 +5,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/shared/parse"
|
"github.com/containers/libpod/cmd/podman/shared/parse"
|
||||||
|
"github.com/containers/libpod/pkg/cgroups"
|
||||||
cc "github.com/containers/libpod/pkg/spec"
|
cc "github.com/containers/libpod/pkg/spec"
|
||||||
"github.com/containers/libpod/pkg/sysinfo"
|
"github.com/containers/libpod/pkg/sysinfo"
|
||||||
"github.com/containers/libpod/pkg/util"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -78,7 +78,7 @@ func addWarning(warnings []string, msg string) []string {
|
|||||||
func verifyContainerResources(config *cc.CreateConfig, update bool) ([]string, error) {
|
func verifyContainerResources(config *cc.CreateConfig, update bool) ([]string, error) {
|
||||||
warnings := []string{}
|
warnings := []string{}
|
||||||
|
|
||||||
cgroup2, err := util.IsCgroup2UnifiedMode()
|
cgroup2, err := cgroups.IsCgroup2UnifiedMode()
|
||||||
if err != nil || cgroup2 {
|
if err != nil || cgroup2 {
|
||||||
return warnings, err
|
return warnings, err
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
|
"github.com/containers/libpod/pkg/cgroups"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/containers/libpod/pkg/util"
|
|
||||||
pmount "github.com/containers/storage/pkg/mount"
|
pmount "github.com/containers/storage/pkg/mount"
|
||||||
"github.com/docker/docker/oci/caps"
|
"github.com/docker/docker/oci/caps"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
@ -350,7 +350,7 @@ func (config *CreateConfig) createConfigToOCISpec(runtime *libpod.Runtime, userM
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rootless.IsRootless() {
|
if rootless.IsRootless() {
|
||||||
cgroup2, err := util.IsCgroup2UnifiedMode()
|
cgroup2, err := cgroups.IsCgroup2UnifiedMode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -11,33 +11,9 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
_cgroup2SuperMagic = 0x63677270
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
isUnifiedOnce sync.Once
|
|
||||||
isUnified bool
|
|
||||||
isUnifiedErr error
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsCgroup2UnifiedMode returns whether we are running in cgroup 2 unified mode.
|
|
||||||
func IsCgroup2UnifiedMode() (bool, error) {
|
|
||||||
isUnifiedOnce.Do(func() {
|
|
||||||
var st syscall.Statfs_t
|
|
||||||
if err := syscall.Statfs("/sys/fs/cgroup", &st); err != nil {
|
|
||||||
isUnified, isUnifiedErr = false, err
|
|
||||||
} else {
|
|
||||||
isUnified, isUnifiedErr = st.Type == _cgroup2SuperMagic, nil
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return isUnified, isUnifiedErr
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRootlessRuntimeDir returns the runtime directory when running as non root
|
// GetRootlessRuntimeDir returns the runtime directory when running as non root
|
||||||
func GetRootlessRuntimeDir() (string, error) {
|
func GetRootlessRuntimeDir() (string, error) {
|
||||||
var rootlessRuntimeDirError error
|
var rootlessRuntimeDirError error
|
||||||
|
Reference in New Issue
Block a user