Skip to content

Commit e10e923

Browse files
committed
podman6: Remove cgroupsv1 support
Signed-off-by: Lokesh Mandvekar <[email protected]>
1 parent c8ebf54 commit e10e923

28 files changed

+190
-891
lines changed

cmd/podman/containers/unpause.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package containers
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"os"
87
"strings"
@@ -12,9 +11,7 @@ import (
1211
"github.com/containers/podman/v5/cmd/podman/utils"
1312
"github.com/containers/podman/v5/cmd/podman/validate"
1413
"github.com/containers/podman/v5/pkg/domain/entities"
15-
"github.com/containers/podman/v5/pkg/rootless"
1614
"github.com/spf13/cobra"
17-
"go.podman.io/common/pkg/cgroups"
1815
"go.podman.io/common/pkg/completion"
1916
)
2017

@@ -88,18 +85,9 @@ func init() {
8885
}
8986

9087
func unpause(_ *cobra.Command, args []string) error {
91-
var (
92-
errs utils.OutputErrors
93-
)
88+
var errs utils.OutputErrors
9489
args = utils.RemoveSlash(args)
9590

96-
if rootless.IsRootless() && !registry.IsRemote() {
97-
cgroupv2, _ := cgroups.IsCgroup2UnifiedMode()
98-
if !cgroupv2 {
99-
return errors.New("unpause is not supported for cgroupv1 rootless containers")
100-
}
101-
}
102-
10391
for _, cidFile := range unpauseCidFiles {
10492
content, err := os.ReadFile(cidFile)
10593
if err != nil {

cmd/podman/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ func main() {
5353
}
5454
logiface.SetLogger(logrusLogger{})
5555

56+
checkSupportedCgroups()
57+
5658
if filepath.Base(os.Args[0]) == registry.PodmanSh ||
5759
(len(os.Args[0]) > 0 && filepath.Base(os.Args[0][1:]) == registry.PodmanSh) {
5860
shell := strings.TrimPrefix(os.Args[0], "-")

cmd/podman/main_cgroups_linux.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//go:build linux
2+
3+
package main
4+
5+
import (
6+
"github.com/sirupsen/logrus"
7+
"go.podman.io/common/pkg/cgroups"
8+
)
9+
10+
func checkSupportedCgroups() {
11+
unified, err := cgroups.IsCgroup2UnifiedMode()
12+
if err != nil {
13+
logrus.Fatalf("Error determining cgroups mode")
14+
}
15+
if !unified {
16+
logrus.Fatalf("Cgroups v1 not supported")
17+
}
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build windows || darwin || freebsd
2+
3+
package main
4+
5+
import (
6+
"github.com/sirupsen/logrus"
7+
"go.podman.io/common/pkg/cgroups"
8+
)
9+
10+
func checkSupportedCgroups() {
11+
unified, _ := cgroups.IsCgroup2UnifiedMode()
12+
if !unified {
13+
logrus.Debugln("Non-linux environment. Non-fatal cgroups check")
14+
}
15+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ require (
192192
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
193193
tags.cncf.io/container-device-interface/specs-go v1.0.0 // indirect
194194
)
195+
195196
replace go.podman.io/common => github.com/lsm5/container-libs/common v0.0.0-20251023145256-2c7c0ea9cefe
196197

197198
replace go.podman.io/buildah => github.com/lsm5/buildah v0.0.0-20251023152205-884c02fbd526

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ github.com/linuxkit/virtsock v0.0.0-20241009230534-cb6a20cc0422 h1:XvRuyDDRvi+UD
237237
github.com/linuxkit/virtsock v0.0.0-20241009230534-cb6a20cc0422/go.mod h1:JLgfq4XMVbvfNlAXla/41lZnp21O72a/wWHGJefAvgQ=
238238
github.com/lsm5/container-libs/common v0.0.0-20251023145256-2c7c0ea9cefe h1:8qD/aUDCGvHUUVa5iEQmuuQ3Ldl4j3N52iXOSx2mfzc=
239239
github.com/lsm5/container-libs/common v0.0.0-20251023145256-2c7c0ea9cefe/go.mod h1:SYowhhZOMlSbIdVmx+qEwBRRcFMUr9EAgqRLWBZDb8s=
240+
github.com/lsm5/buildah v0.0.0-20251017145416-1c35ea0ae809 h1:Xl7p6J9gfYA7TX0Z7VTNygqpEq7MZdrLX+EhsUdUOPc=
241+
github.com/lsm5/buildah v0.0.0-20251017145416-1c35ea0ae809/go.mod h1:DOj6mclvkxcijXOmZTybYPZpuDv5ZyqoyjZSwfs/ikk=
240242
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0=
241243
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k=
242244
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=

libpod/container_internal.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ func (c *Container) waitForHealthy(ctx context.Context) error {
13611361
}
13621362

13631363
// Whether a container should use `all` when stopping
1364-
func (c *Container) stopWithAll() (bool, error) {
1364+
func (c *Container) stopWithAll() bool {
13651365
// If the container is running in a PID Namespace, then killing the
13661366
// primary pid is enough to kill the container. If it is not running in
13671367
// a pid namespace then the OCI Runtime needs to kill ALL processes in
@@ -1373,29 +1373,17 @@ func (c *Container) stopWithAll() (bool, error) {
13731373
if all {
13741374
if c.config.NoCgroups {
13751375
all = false
1376-
} else if rootless.IsRootless() {
1377-
// Only do this check if we need to
1378-
unified, err := cgroups.IsCgroup2UnifiedMode()
1379-
if err != nil {
1380-
return false, err
1381-
}
1382-
if !unified {
1383-
all = false
1384-
}
13851376
}
13861377
}
13871378

1388-
return all, nil
1379+
return all
13891380
}
13901381

13911382
// Internal, non-locking function to stop container
13921383
func (c *Container) stop(timeout uint) error {
13931384
logrus.Debugf("Stopping ctr %s (timeout %d)", c.ID(), timeout)
13941385

1395-
all, err := c.stopWithAll()
1396-
if err != nil {
1397-
return err
1398-
}
1386+
all := c.stopWithAll()
13991387

14001388
// OK, the following code looks a bit weird but we have to make sure we can stop
14011389
// containers with the restart policy always, to do this we have to set
@@ -1502,7 +1490,7 @@ func (c *Container) waitForConmonToExitAndSave() error {
15021490
// could open a pidfd on container PID1 before
15031491
// this to get the real exit code... But I'm not
15041492
// that dedicated.
1505-
all, _ := c.stopWithAll()
1493+
all := c.stopWithAll()
15061494
if err := c.ociRuntime.StopContainer(c, 0, all); err != nil {
15071495
logrus.Errorf("Error stopping container %s after Conmon exited prematurely: %v", c.ID(), err)
15081496
}

libpod/container_internal_linux.go

Lines changed: 17 additions & 77 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
}
@@ -385,16 +333,12 @@ func isRootlessCgroupSet(cgroup string) bool {
385333
}
386334

387335
func (c *Container) expectPodCgroup() (bool, error) {
388-
unified, err := cgroups.IsCgroup2UnifiedMode()
389-
if err != nil {
390-
return false, err
391-
}
392336
cgroupManager := c.CgroupManager()
393337
switch {
394338
case c.config.NoCgroups:
395339
return false, nil
396340
case cgroupManager == config.SystemdCgroupsManager:
397-
return !rootless.IsRootless() || unified, nil
341+
return true, nil
398342
case cgroupManager == config.CgroupfsCgroupsManager:
399343
return !rootless.IsRootless(), nil
400344
default:
@@ -404,10 +348,6 @@ func (c *Container) expectPodCgroup() (bool, error) {
404348

405349
// Get cgroup path in a format suitable for the OCI spec
406350
func (c *Container) getOCICgroupPath() (string, error) {
407-
unified, err := cgroups.IsCgroup2UnifiedMode()
408-
if err != nil {
409-
return "", err
410-
}
411351
cgroupManager := c.CgroupManager()
412352
switch {
413353
case c.config.NoCgroups:
@@ -425,7 +365,7 @@ func (c *Container) getOCICgroupPath() (string, error) {
425365
systemdCgroups := fmt.Sprintf("%s:libpod:%s", path.Base(c.config.CgroupParent), c.ID())
426366
logrus.Debugf("Setting Cgroups for container %s to %s", c.ID(), systemdCgroups)
427367
return systemdCgroups, nil
428-
case (rootless.IsRootless() && (cgroupManager == config.CgroupfsCgroupsManager || !unified)):
368+
case (rootless.IsRootless() && (cgroupManager == config.CgroupfsCgroupsManager)):
429369
if c.config.CgroupParent == "" || !isRootlessCgroupSet(c.config.CgroupParent) {
430370
return "", nil
431371
}

libpod/info_linux.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,8 @@ func (r *Runtime) setPlatformHostInfo(info *define.HostInfo) error {
3030
return fmt.Errorf("getting Seccomp profile path: %w", err)
3131
}
3232

33-
// Cgroups version
34-
unified, err := cgroups.IsCgroup2UnifiedMode()
35-
if err != nil {
36-
return fmt.Errorf("reading cgroups mode: %w", err)
37-
}
38-
3933
// Get Map of all available controllers
40-
availableControllers, err := cgroups.AvailableControllers(nil, unified)
34+
availableControllers, err := cgroups.AvailableControllers()
4135
if err != nil {
4236
return fmt.Errorf("getting available cgroup controllers: %w", err)
4337
}
@@ -55,12 +49,6 @@ func (r *Runtime) setPlatformHostInfo(info *define.HostInfo) error {
5549
}
5650
info.Slirp4NetNS = define.SlirpInfo{}
5751

58-
cgroupVersion := "v1"
59-
if unified {
60-
cgroupVersion = "v2"
61-
}
62-
info.CgroupsVersion = cgroupVersion
63-
6452
slirp4netnsPath := r.config.Engine.NetworkCmdPath
6553
if slirp4netnsPath == "" {
6654
slirp4netnsPath, _ = r.config.FindHelperBinary(slirp4netns.BinaryName, true)

libpod/runtime_linux.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,10 @@ import (
1212
"github.com/containers/podman/v5/pkg/rootless"
1313
"github.com/containers/podman/v5/pkg/systemd"
1414
"github.com/sirupsen/logrus"
15-
"go.podman.io/common/pkg/cgroups"
1615
)
1716

1817
func checkCgroups2UnifiedMode(runtime *Runtime) {
19-
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
28-
29-
if unified && rootless.IsRootless() && !systemd.IsSystemdSessionValid(rootless.GetRootlessUID()) {
18+
if rootless.IsRootless() && !systemd.IsSystemdSessionValid(rootless.GetRootlessUID()) {
3019
// If user is rootless and XDG_RUNTIME_DIR is found, podman will not proceed with /tmp directory
3120
// it will try to use existing XDG_RUNTIME_DIR
3221
// if current user has no write access to XDG_RUNTIME_DIR we will fail later

0 commit comments

Comments
 (0)