Kaynağa Gözat

do not create init-dir if not needed

commit 56f77d5ade945b3b8816a6c8acb328b7c6dce9a7
added support for cpu-rt-period and cpu-rt-runtime,
but always initialized the cgroup path, even if not
used.

As a result, containers failed to start on a
read-only filesystem.

This patch only creates the cgroup path if
one of these options is set.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 8 yıl önce
ebeveyn
işleme
f285d5b3e8
1 değiştirilmiş dosya ile 12 ekleme ve 3 silme
  1. 12 3
      daemon/daemon_unix.go

+ 12 - 3
daemon/daemon_unix.go

@@ -1190,6 +1190,12 @@ func (daemon *Daemon) initCgroupsPath(path string) error {
 		return nil
 	}
 
+	if daemon.configStore.CPURealtimePeriod == 0 && daemon.configStore.CPURealtimeRuntime == 0 {
+		return nil
+	}
+
+	// Recursively create cgroup to ensure that the system and all parent cgroups have values set
+	// for the period and runtime as this limits what the children can be set to.
 	daemon.initCgroupsPath(filepath.Dir(path))
 
 	_, root, err := cgroups.FindCgroupMountpointAndRoot("cpu")
@@ -1199,15 +1205,18 @@ func (daemon *Daemon) initCgroupsPath(path string) error {
 
 	path = filepath.Join(root, path)
 	sysinfo := sysinfo.New(true)
-	if err := os.MkdirAll(path, 0755); err != nil && !os.IsExist(err) {
-		return err
-	}
 	if sysinfo.CPURealtimePeriod && daemon.configStore.CPURealtimePeriod != 0 {
+		if err := os.MkdirAll(path, 0755); err != nil && !os.IsExist(err) {
+			return err
+		}
 		if err := ioutil.WriteFile(filepath.Join(path, "cpu.rt_period_us"), []byte(strconv.FormatInt(daemon.configStore.CPURealtimePeriod, 10)), 0700); err != nil {
 			return err
 		}
 	}
 	if sysinfo.CPURealtimeRuntime && daemon.configStore.CPURealtimeRuntime != 0 {
+		if err := os.MkdirAll(path, 0755); err != nil && !os.IsExist(err) {
+			return err
+		}
 		if err := ioutil.WriteFile(filepath.Join(path, "cpu.rt_runtime_us"), []byte(strconv.FormatInt(daemon.configStore.CPURealtimeRuntime, 10)), 0700); err != nil {
 			return err
 		}