Skip to content

Commit 7fd46d6

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

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+493
-2371
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 {

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,5 @@ 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+
196+
replace go.podman.io/common => github.com/lsm5/container-libs/common podman6-no-cgv1

go.sum

Lines changed: 194 additions & 630 deletions
Large diffs are not rendered by default.

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

libpod/runtime_pod_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (p *Pod) removePodCgroup() error {
122122
// hard - instead, just log errors.
123123
conmonCgroupPath := filepath.Join(p.state.CgroupPath, "conmon")
124124
conmonCgroup, err := cgroups.Load(conmonCgroupPath)
125-
if err != nil && err != cgroups.ErrCgroupDeleted && err != cgroups.ErrCgroupV1Rootless {
125+
if err != nil && err != cgroups.ErrCgroupDeleted {
126126
return fmt.Errorf("retrieving pod %s conmon cgroup: %w", p.ID(), err)
127127
}
128128
if err == nil {
@@ -131,7 +131,7 @@ func (p *Pod) removePodCgroup() error {
131131
}
132132
}
133133
cgroup, err := cgroups.Load(p.state.CgroupPath)
134-
if err != nil && err != cgroups.ErrCgroupDeleted && err != cgroups.ErrCgroupV1Rootless {
134+
if err != nil && err != cgroups.ErrCgroupDeleted {
135135
return fmt.Errorf("retrieving pod %s cgroup: %w", p.ID(), err)
136136
}
137137
if err == nil {

pkg/domain/infra/runtime_libpod.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/containers/podman/v5/pkg/util"
2121
"github.com/sirupsen/logrus"
2222
flag "github.com/spf13/pflag"
23-
"go.podman.io/common/pkg/cgroups"
2423
"go.podman.io/storage/pkg/idtools"
2524
"go.podman.io/storage/types"
2625
)
@@ -182,14 +181,6 @@ func getRuntime(ctx context.Context, fs *flag.FlagSet, opts *engineOpts) (*libpo
182181

183182
if fs.Changed("cgroup-manager") {
184183
options = append(options, libpod.WithCgroupManager(cfg.ContainersConf.Engine.CgroupManager))
185-
} else {
186-
unified, err := cgroups.IsCgroup2UnifiedMode()
187-
if err != nil {
188-
return nil, err
189-
}
190-
if rootless.IsRootless() && !unified {
191-
options = append(options, libpod.WithCgroupManager("cgroupfs"))
192-
}
193184
}
194185

195186
// TODO flag to set libpod static dir?

0 commit comments

Comments
 (0)