Browse code

Add mount point to cgroup root when initializing cgroup paths for cpu.rt_runtime

PR https://github.com/docker/docker/pull/23430 introduced a couple more
flags including `--cpu-rt-runtime` to the docker daemon. It appears
recent changes or merge issues may have broken this. It currently does
not take the cgroup mount point into account when determining the cgroup
files to write values to. This breaks docker setting its own
`cpu.rt_runtime` for the daemon. This also means containers aren't able
to set theirs.

Also, the cgroups.FindCgroupMountpointAndRoot returns back a mount point
that includes the cgroup of the currently running container when docker
is run inside a docker container. this breaks the `--cpu-rt-runtime`
flag when running docker in docker. A fix has been placed here, but
potentially could be pulled up into libcontainer if this is a better
place for it.

Signed-off-by: Erik St. Martin <alakriti@gmail.com>

Erik St. Martin authored on 2017/03/15 05:09:09
Showing 1 changed files
... ...
@@ -1269,12 +1269,17 @@ func (daemon *Daemon) initCgroupsPath(path string) error {
1269 1269
 	// for the period and runtime as this limits what the children can be set to.
1270 1270
 	daemon.initCgroupsPath(filepath.Dir(path))
1271 1271
 
1272
-	_, root, err := cgroups.FindCgroupMountpointAndRoot("cpu")
1272
+	mnt, root, err := cgroups.FindCgroupMountpointAndRoot("cpu")
1273 1273
 	if err != nil {
1274 1274
 		return err
1275 1275
 	}
1276
+	// When docker is run inside docker, the root is based of the host cgroup.
1277
+	// Should this be handled in runc/libcontainer/cgroups ?
1278
+	if strings.HasPrefix(root, "/docker/") {
1279
+		root = "/"
1280
+	}
1276 1281
 
1277
-	path = filepath.Join(root, path)
1282
+	path = filepath.Join(mnt, root, path)
1278 1283
 	sysinfo := sysinfo.New(true)
1279 1284
 	if err := maybeCreateCPURealTimeFile(sysinfo.CPURealtimePeriod, daemon.configStore.CPURealtimePeriod, "cpu.rt_period_us", path); err != nil {
1280 1285
 		return err