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