2020-05-04 20:46:48 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package fs2
|
|
|
|
|
|
|
|
import (
|
2021-07-02 08:43:15 +00:00
|
|
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
2020-05-04 20:46:48 +00:00
|
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
|
|
|
)
|
|
|
|
|
2021-06-18 20:46:09 +00:00
|
|
|
func isCpusetSet(r *configs.Resources) bool {
|
|
|
|
return r.CpusetCpus != "" || r.CpusetMems != ""
|
2020-08-10 17:43:49 +00:00
|
|
|
}
|
|
|
|
|
2021-06-18 20:46:09 +00:00
|
|
|
func setCpuset(dirPath string, r *configs.Resources) error {
|
|
|
|
if !isCpusetSet(r) {
|
2020-08-10 17:43:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-06-18 20:46:09 +00:00
|
|
|
if r.CpusetCpus != "" {
|
2021-07-02 08:43:15 +00:00
|
|
|
if err := cgroups.WriteFile(dirPath, "cpuset.cpus", r.CpusetCpus); err != nil {
|
2020-05-04 20:46:48 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2021-06-18 20:46:09 +00:00
|
|
|
if r.CpusetMems != "" {
|
2021-07-02 08:43:15 +00:00
|
|
|
if err := cgroups.WriteFile(dirPath, "cpuset.mems", r.CpusetMems); err != nil {
|
2020-05-04 20:46:48 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|