@@ -42,6 +42,7 @@ const (
42
42
subtreeControl = "cgroup.subtree_control"
43
43
controllersFile = "cgroup.controllers"
44
44
killFile = "cgroup.kill"
45
+ typeFile = "cgroup.type"
45
46
defaultCgroup2Path = "/sys/fs/cgroup"
46
47
defaultSlice = "system.slice"
47
48
)
@@ -235,6 +236,35 @@ func setResources(path string, resources *Resources) error {
235
236
return nil
236
237
}
237
238
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
+
238
268
func (c * Manager ) RootControllers () ([]string , error ) {
239
269
b , err := os .ReadFile (filepath .Join (c .unifiedMountpoint , controllersFile ))
240
270
if err != nil {
0 commit comments