@@ -42,6 +42,7 @@ const (
4242 subtreeControl = "cgroup.subtree_control"
4343 controllersFile = "cgroup.controllers"
4444 killFile = "cgroup.kill"
45+ typeFile = "cgroup.type"
4546 defaultCgroup2Path = "/sys/fs/cgroup"
4647 defaultSlice = "system.slice"
4748)
@@ -235,6 +236,35 @@ func setResources(path string, resources *Resources) error {
235236 return nil
236237}
237238
239+ // CgroupType represents the types a cgroup can be.
240+ type CgroupType string
241+
242+ const (
243+ Domain CgroupType = "domain"
244+ Threaded CgroupType = "threaded"
245+ )
246+
247+ func (c * Manager ) GetType () (CgroupType , error ) {
248+ val , err := os .ReadFile (filepath .Join (c .path , typeFile ))
249+ if err != nil {
250+ return "" , err
251+ }
252+ trimmed := strings .TrimSpace (string (val ))
253+ return CgroupType (trimmed ), nil
254+ }
255+
256+ func (c * Manager ) SetType (cgType CgroupType ) error {
257+ // NOTE: We could abort if cgType != Threaded here as currently
258+ // it's not possible to revert back to domain, but not sure
259+ // it's worth being that opinionated, especially if that may
260+ // ever change.
261+ v := Value {
262+ filename : typeFile ,
263+ value : string (cgType ),
264+ }
265+ return writeValues (c .path , []Value {v })
266+ }
267+
238268func (c * Manager ) RootControllers () ([]string , error ) {
239269 b , err := os .ReadFile (filepath .Join (c .unifiedMountpoint , controllersFile ))
240270 if err != nil {
0 commit comments