From 5e1b44b196c720bb0160722c490d6e2aba244a2a Mon Sep 17 00:00:00 2001 From: Andy Xie Date: Fri, 23 Mar 2018 17:47:21 +0800 Subject: [PATCH] add check for cpu cfs bandwidth in validate endpoint --- validate/validate.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/validate/validate.go b/validate/validate.go index c73311cf..b2db5580 100644 --- a/validate/validate.go +++ b/validate/validate.go @@ -22,6 +22,7 @@ import ( "io/ioutil" "log" "net/http" + "os" "path" "strings" @@ -133,6 +134,23 @@ func areCgroupsPresent(available map[string]int, desired []string) (bool, string return true, "" } +func validateCpuCfsBandwidth(available_cgroups map[string]int) string { + ok, _ := areCgroupsPresent(available_cgroups, []string{"cpu"}) + if !ok { + return "\tCpu cfs bandwidth status unknown: cpu cgroup not enabled.\n" + } + mnt, err := cgroups.FindCgroupMountpoint("cpu") + if err != nil { + return "\tCpu cfs bandwidth status unknown: cpu cgroup not mounted.\n" + } + _, err = os.Stat(path.Join(mnt, "cpu.cfs_period_us")) + if os.IsNotExist(err) { + return "\tCpu cfs bandwidth is disabled. Recompile kernel with \"CONFIG_CFS_BANDWIDTH\" enabled.\n" + } + + return "\tCpu cfs bandwidth is enabled.\n" +} + func validateMemoryAccounting(available_cgroups map[string]int) string { ok, _ := areCgroupsPresent(available_cgroups, []string{"memory"}) if !ok { @@ -181,6 +199,7 @@ func validateCgroups() (string, string) { out = fmt.Sprintf("Available cgroups: %v\n", available_cgroups) out += desc out += validateMemoryAccounting(available_cgroups) + out += validateCpuCfsBandwidth(available_cgroups) return Recommended, out }