Skip to content

Commit fa6c611

Browse files
committed
libpod: Remove cgroupsv1 support
Signed-off-by: Lokesh Mandvekar <[email protected]>
1 parent 9cb2e51 commit fa6c611

File tree

4 files changed

+18
-241
lines changed

4 files changed

+18
-241
lines changed

libpod/container_internal_linux.go

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package libpod
44

55
import (
6-
"errors"
76
"fmt"
87
"io/fs"
98
"os"
@@ -30,9 +29,7 @@ import (
3029
"golang.org/x/sys/unix"
3130
)
3231

33-
var (
34-
bindOptions = []string{define.TypeBind, "rprivate"}
35-
)
32+
var bindOptions = []string{define.TypeBind, "rprivate"}
3633

3734
func (c *Container) mountSHM(shmOptions string) error {
3835
contextType := "context"
@@ -267,11 +264,6 @@ func (c *Container) setupSystemd(mounts []spec.Mount, g generate.Generator) erro
267264
g.AddMount(tmpfsMnt)
268265
}
269266

270-
unified, err := cgroups.IsCgroup2UnifiedMode()
271-
if err != nil {
272-
return err
273-
}
274-
275267
hasCgroupNs := false
276268
for _, ns := range c.config.Spec.Linux.Namespaces {
277269
if ns.Type == spec.CgroupNamespace {
@@ -280,69 +272,25 @@ func (c *Container) setupSystemd(mounts []spec.Mount, g generate.Generator) erro
280272
}
281273
}
282274

283-
if unified {
284-
g.RemoveMount("/sys/fs/cgroup")
275+
g.RemoveMount("/sys/fs/cgroup")
285276

286-
var systemdMnt spec.Mount
287-
if hasCgroupNs {
288-
systemdMnt = spec.Mount{
289-
Destination: "/sys/fs/cgroup",
290-
Type: "cgroup",
291-
Source: "cgroup",
292-
Options: []string{"private", "rw"},
293-
}
294-
} else {
295-
systemdMnt = spec.Mount{
296-
Destination: "/sys/fs/cgroup",
297-
Type: define.TypeBind,
298-
Source: "/sys/fs/cgroup",
299-
Options: []string{define.TypeBind, "private", "rw"},
300-
}
277+
var systemdMnt spec.Mount
278+
if hasCgroupNs {
279+
systemdMnt = spec.Mount{
280+
Destination: "/sys/fs/cgroup",
281+
Type: "cgroup",
282+
Source: "cgroup",
283+
Options: []string{"private", "rw"},
301284
}
302-
g.AddMount(systemdMnt)
303285
} else {
304-
hasSystemdMount := MountExists(mounts, "/sys/fs/cgroup/systemd")
305-
if hasCgroupNs && !hasSystemdMount {
306-
return errors.New("cgroup namespace is not supported with cgroup v1 and systemd mode")
307-
}
308-
mountOptions := []string{define.TypeBind, "rprivate"}
309-
310-
if !hasSystemdMount {
311-
skipMount := hasSystemdMount
312-
var statfs unix.Statfs_t
313-
if err := unix.Statfs("/sys/fs/cgroup/systemd", &statfs); err != nil {
314-
if errors.Is(err, os.ErrNotExist) {
315-
// If the mount is missing on the host, we cannot bind mount it so
316-
// just skip it.
317-
skipMount = true
318-
}
319-
mountOptions = append(mountOptions, "nodev", "noexec", "nosuid")
320-
} else {
321-
if statfs.Flags&unix.MS_NODEV == unix.MS_NODEV {
322-
mountOptions = append(mountOptions, "nodev")
323-
}
324-
if statfs.Flags&unix.MS_NOEXEC == unix.MS_NOEXEC {
325-
mountOptions = append(mountOptions, "noexec")
326-
}
327-
if statfs.Flags&unix.MS_NOSUID == unix.MS_NOSUID {
328-
mountOptions = append(mountOptions, "nosuid")
329-
}
330-
if statfs.Flags&unix.MS_RDONLY == unix.MS_RDONLY {
331-
mountOptions = append(mountOptions, "ro")
332-
}
333-
}
334-
if !skipMount {
335-
systemdMnt := spec.Mount{
336-
Destination: "/sys/fs/cgroup/systemd",
337-
Type: define.TypeBind,
338-
Source: "/sys/fs/cgroup/systemd",
339-
Options: mountOptions,
340-
}
341-
g.AddMount(systemdMnt)
342-
g.AddLinuxMaskedPaths("/sys/fs/cgroup/systemd/release_agent")
343-
}
286+
systemdMnt = spec.Mount{
287+
Destination: "/sys/fs/cgroup",
288+
Type: define.TypeBind,
289+
Source: "/sys/fs/cgroup",
290+
Options: []string{define.TypeBind, "private", "rw"},
344291
}
345292
}
293+
g.AddMount(systemdMnt)
346294

347295
return nil
348296
}

libpod/info_linux.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ func (r *Runtime) setPlatformHostInfo(info *define.HostInfo) error {
5555
}
5656
info.Slirp4NetNS = define.SlirpInfo{}
5757

58-
cgroupVersion := "v1"
59-
if unified {
60-
cgroupVersion = "v2"
61-
}
58+
cgroupVersion := "v2"
6259
info.CgroupsVersion = cgroupVersion
6360

6461
slirp4netnsPath := r.config.Engine.NetworkCmdPath

libpod/runtime_linux.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ import (
1717

1818
func checkCgroups2UnifiedMode(runtime *Runtime) {
1919
unified, _ := cgroups.IsCgroup2UnifiedMode()
20-
// DELETE ON RHEL9
21-
if !unified {
22-
_, ok := os.LookupEnv("PODMAN_IGNORE_CGROUPSV1_WARNING")
23-
if !ok {
24-
logrus.Warn("Using cgroups-v1 which is deprecated in favor of cgroups-v2 with Podman v5 and will be removed in a future version. Set environment variable `PODMAN_IGNORE_CGROUPSV1_WARNING` to hide this warning.")
25-
}
26-
}
27-
// DELETE ON RHEL9
2820

2921
if unified && rootless.IsRootless() && !systemd.IsSystemdSessionValid(rootless.GetRootlessUID()) {
3022
// If user is rootless and XDG_RUNTIME_DIR is found, podman will not proceed with /tmp directory

pkg/specgen/generate/validate_linux.go

Lines changed: 2 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -3,171 +3,14 @@
33
package generate
44

55
import (
6-
"errors"
7-
"fmt"
86
"os"
97
"path/filepath"
10-
"reflect"
118

12-
"github.com/containers/podman/v5/pkg/rootless"
139
"github.com/containers/podman/v5/pkg/specgen"
14-
"github.com/opencontainers/runtime-spec/specs-go"
1510
"go.podman.io/common/pkg/cgroups"
16-
"go.podman.io/common/pkg/sysinfo"
1711
"go.podman.io/storage/pkg/fileutils"
1812
)
1913

20-
// Verify resource limits are sanely set when running on cgroup v1.
21-
func verifyContainerResourcesCgroupV1(s *specgen.SpecGenerator) ([]string, error) {
22-
warnings := []string{}
23-
24-
sysInfo := sysinfo.New(true)
25-
26-
// If ResourceLimits is nil, return without warning
27-
resourceNil := &specgen.SpecGenerator{}
28-
resourceNil.ResourceLimits = &specs.LinuxResources{}
29-
if s.ResourceLimits == nil || reflect.DeepEqual(s.ResourceLimits, resourceNil.ResourceLimits) {
30-
return nil, nil
31-
}
32-
33-
// Cgroups V1 rootless system does not support Resource limits
34-
if rootless.IsRootless() {
35-
s.ResourceLimits = nil
36-
return []string{"Resource limits are not supported and ignored on cgroups V1 rootless systems"}, nil
37-
}
38-
39-
if s.ResourceLimits.Unified != nil {
40-
return nil, errors.New("cannot use --cgroup-conf without cgroup v2")
41-
}
42-
43-
// Memory checks
44-
if s.ResourceLimits.Memory != nil {
45-
memory := s.ResourceLimits.Memory
46-
if memory.Limit != nil && !sysInfo.MemoryLimit {
47-
warnings = append(warnings, "Your kernel does not support memory limit capabilities or the cgroup is not mounted. Limitation discarded.")
48-
memory.Limit = nil
49-
memory.Swap = nil
50-
}
51-
if memory.Limit != nil && memory.Swap != nil && !sysInfo.SwapLimit {
52-
warnings = append(warnings, "Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.")
53-
memory.Swap = nil
54-
}
55-
if memory.Limit != nil && memory.Swap != nil && *memory.Swap < *memory.Limit {
56-
return warnings, errors.New("minimum memoryswap limit should be larger than memory limit, see usage")
57-
}
58-
if memory.Limit == nil && memory.Swap != nil {
59-
return warnings, errors.New("you should always set a memory limit when using a memoryswap limit, see usage")
60-
}
61-
if memory.Swappiness != nil {
62-
if !sysInfo.MemorySwappiness {
63-
warnings = append(warnings, "Your kernel does not support memory swappiness capabilities, or the cgroup is not mounted. Memory swappiness discarded.")
64-
memory.Swappiness = nil
65-
} else if *memory.Swappiness > 100 {
66-
return warnings, fmt.Errorf("invalid value: %v, valid memory swappiness range is 0-100", *memory.Swappiness)
67-
}
68-
}
69-
if memory.Reservation != nil && !sysInfo.MemoryReservation {
70-
warnings = append(warnings, "Your kernel does not support memory soft limit capabilities or the cgroup is not mounted. Limitation discarded.")
71-
memory.Reservation = nil
72-
}
73-
if memory.Limit != nil && memory.Reservation != nil && *memory.Limit < *memory.Reservation {
74-
return warnings, errors.New("minimum memory limit cannot be less than memory reservation limit, see usage")
75-
}
76-
if memory.DisableOOMKiller != nil && *memory.DisableOOMKiller && !sysInfo.OomKillDisable {
77-
warnings = append(warnings, "Your kernel does not support OomKillDisable. OomKillDisable discarded.")
78-
memory.DisableOOMKiller = nil
79-
}
80-
}
81-
82-
// Pids checks
83-
if s.ResourceLimits.Pids != nil {
84-
// TODO: Should this be 0, or checking that ResourceLimits.Pids
85-
// is set at all?
86-
if s.ResourceLimits.Pids.Limit >= 0 && !sysInfo.PidsLimit {
87-
warnings = append(warnings, "Your kernel does not support pids limit capabilities or the cgroup is not mounted. PIDs limit discarded.")
88-
s.ResourceLimits.Pids = nil
89-
}
90-
}
91-
92-
// CPU checks
93-
if s.ResourceLimits.CPU != nil {
94-
cpu := s.ResourceLimits.CPU
95-
if cpu.Shares != nil && !sysInfo.CPUShares {
96-
warnings = append(warnings, "Your kernel does not support CPU shares or the cgroup is not mounted. Shares discarded.")
97-
cpu.Shares = nil
98-
}
99-
if cpu.Period != nil && !sysInfo.CPUCfsPeriod {
100-
warnings = append(warnings, "Your kernel does not support CPU cfs period or the cgroup is not mounted. Period discarded.")
101-
cpu.Period = nil
102-
}
103-
if cpu.Period != nil && (*cpu.Period < 1000 || *cpu.Period > 1000000) {
104-
return warnings, errors.New("CPU cfs period cannot be less than 1ms (i.e. 1000) or larger than 1s (i.e. 1000000)")
105-
}
106-
if cpu.Quota != nil && !sysInfo.CPUCfsQuota {
107-
warnings = append(warnings, "Your kernel does not support CPU cfs quota or the cgroup is not mounted. Quota discarded.")
108-
cpu.Quota = nil
109-
}
110-
if cpu.Quota != nil && *cpu.Quota < 1000 {
111-
return warnings, errors.New("CPU cfs quota cannot be less than 1ms (i.e. 1000)")
112-
}
113-
if (cpu.Cpus != "" || cpu.Mems != "") && !sysInfo.Cpuset {
114-
warnings = append(warnings, "Your kernel does not support cpuset or the cgroup is not mounted. CPUset discarded.")
115-
cpu.Cpus = ""
116-
cpu.Mems = ""
117-
}
118-
119-
cpusAvailable, err := sysInfo.IsCpusetCpusAvailable(cpu.Cpus)
120-
if err != nil {
121-
return warnings, fmt.Errorf("invalid value %s for cpuset cpus", cpu.Cpus)
122-
}
123-
if !cpusAvailable {
124-
return warnings, fmt.Errorf("requested CPUs are not available - requested %s, available: %s", cpu.Cpus, sysInfo.Cpus)
125-
}
126-
127-
memsAvailable, err := sysInfo.IsCpusetMemsAvailable(cpu.Mems)
128-
if err != nil {
129-
return warnings, fmt.Errorf("invalid value %s for cpuset mems", cpu.Mems)
130-
}
131-
if !memsAvailable {
132-
return warnings, fmt.Errorf("requested memory nodes are not available - requested %s, available: %s", cpu.Mems, sysInfo.Mems)
133-
}
134-
}
135-
136-
// Blkio checks
137-
if s.ResourceLimits.BlockIO != nil {
138-
blkio := s.ResourceLimits.BlockIO
139-
if blkio.Weight != nil && !sysInfo.BlkioWeight {
140-
warnings = append(warnings, "Your kernel does not support Block I/O weight or the cgroup is not mounted. Weight discarded.")
141-
blkio.Weight = nil
142-
}
143-
if blkio.Weight != nil && (*blkio.Weight > 1000 || *blkio.Weight < 10) {
144-
return warnings, errors.New("range of blkio weight is from 10 to 1000")
145-
}
146-
if len(blkio.WeightDevice) > 0 && !sysInfo.BlkioWeightDevice {
147-
warnings = append(warnings, "Your kernel does not support Block I/O weight_device or the cgroup is not mounted. Weight-device discarded.")
148-
blkio.WeightDevice = nil
149-
}
150-
if len(blkio.ThrottleReadBpsDevice) > 0 && !sysInfo.BlkioReadBpsDevice {
151-
warnings = append(warnings, "Your kernel does not support BPS Block I/O read limit or the cgroup is not mounted. Block I/O BPS read limit discarded")
152-
blkio.ThrottleReadBpsDevice = nil
153-
}
154-
if len(blkio.ThrottleWriteBpsDevice) > 0 && !sysInfo.BlkioWriteBpsDevice {
155-
warnings = append(warnings, "Your kernel does not support BPS Block I/O write limit or the cgroup is not mounted. Block I/O BPS write limit discarded.")
156-
blkio.ThrottleWriteBpsDevice = nil
157-
}
158-
if len(blkio.ThrottleReadIOPSDevice) > 0 && !sysInfo.BlkioReadIOpsDevice {
159-
warnings = append(warnings, "Your kernel does not support IOPS Block read limit or the cgroup is not mounted. Block I/O IOPS read limit discarded.")
160-
blkio.ThrottleReadIOPSDevice = nil
161-
}
162-
if len(blkio.ThrottleWriteIOPSDevice) > 0 && !sysInfo.BlkioWriteIOpsDevice {
163-
warnings = append(warnings, "Your kernel does not support IOPS Block I/O write limit or the cgroup is not mounted. Block I/O IOPS write limit discarded.")
164-
blkio.ThrottleWriteIOPSDevice = nil
165-
}
166-
}
167-
168-
return warnings, nil
169-
}
170-
17114
// Verify resource limits are sanely set when running on cgroup v2.
17215
func verifyContainerResourcesCgroupV2(s *specgen.SpecGenerator) ([]string, error) {
17316
warnings := []string{}
@@ -225,12 +68,9 @@ func verifyContainerResourcesCgroupV2(s *specgen.SpecGenerator) ([]string, error
22568
// Verify resource limits are sanely set, removing any limits that are not
22669
// possible with the current cgroups config.
22770
func verifyContainerResources(s *specgen.SpecGenerator) ([]string, error) {
228-
cgroup2, err := cgroups.IsCgroup2UnifiedMode()
71+
_, err := cgroups.IsCgroup2UnifiedMode()
22972
if err != nil {
23073
return []string{}, err
23174
}
232-
if cgroup2 {
233-
return verifyContainerResourcesCgroupV2(s)
234-
}
235-
return verifyContainerResourcesCgroupV1(s)
75+
return verifyContainerResourcesCgroupV2(s)
23676
}

0 commit comments

Comments
 (0)