systemd, cgroupsv2: not bind mount /sys/fs/cgroup/systemd

when running on a cgroups v2 system, do not bind mount
the named hierarchy /sys/fs/cgroup/systemd as it doesn't exist
anymore.  Instead bind mount the entire /sys/fs/cgroup.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2019-07-31 09:03:00 +02:00
parent a622f8d345
commit 223fe64dc0
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED
1 changed files with 34 additions and 16 deletions

View File

@ -466,6 +466,23 @@ func (c *Container) setupSystemd(mounts []spec.Mount, g generate.Generator) erro
g.AddMount(tmpfsMnt) g.AddMount(tmpfsMnt)
} }
unified, err := cgroups.IsCgroup2UnifiedMode()
if err != nil {
return err
}
g.RemoveMount("/sys/fs/cgroup")
if unified {
sourcePath := filepath.Join("/sys/fs/cgroup")
systemdMnt := spec.Mount{
Destination: "/sys/fs/cgroup",
Type: "bind",
Source: sourcePath,
Options: []string{"bind", "private", "rw"},
}
g.AddMount(systemdMnt)
} else {
// rootless containers have no write access to /sys/fs/cgroup, so don't // rootless containers have no write access to /sys/fs/cgroup, so don't
// add any mount into the container. // add any mount into the container.
if !rootless.IsRootless() { if !rootless.IsRootless() {
@ -473,10 +490,10 @@ func (c *Container) setupSystemd(mounts []spec.Mount, g generate.Generator) erro
if err != nil { if err != nil {
return err return err
} }
sourcePath := filepath.Join("/sys/fs/cgroup/systemd", cgroupPath) sourcePath := filepath.Join("/sys/fs/cgroup", cgroupPath)
systemdMnt := spec.Mount{ systemdMnt := spec.Mount{
Destination: "/sys/fs/cgroup/systemd", Destination: "/sys/fs/cgroup",
Type: "bind", Type: "bind",
Source: sourcePath, Source: sourcePath,
Options: []string{"bind", "private"}, Options: []string{"bind", "private"},
@ -484,13 +501,14 @@ func (c *Container) setupSystemd(mounts []spec.Mount, g generate.Generator) erro
g.AddMount(systemdMnt) g.AddMount(systemdMnt)
} else { } else {
systemdMnt := spec.Mount{ systemdMnt := spec.Mount{
Destination: "/sys/fs/cgroup/systemd", Destination: "/sys/fs/cgroup",
Type: "bind", Type: "bind",
Source: "/sys/fs/cgroup/systemd", Source: "/sys/fs/cgroup",
Options: []string{"bind", "nodev", "noexec", "nosuid"}, Options: []string{"bind", "nodev", "noexec", "nosuid"},
} }
g.AddMount(systemdMnt) g.AddMount(systemdMnt)
} }
}
return nil return nil
} }