@@ -82,7 +82,29 @@ impl Cgroup {
8282 /// Create this control group.
8383 pub fn create ( & self ) -> Result < ( ) > {
8484 if self . hier . v2 ( ) {
85- create_v2_cgroup ( self . hier . root ( ) , & self . path , & self . specified_controllers )
85+ create_v2_cgroup (
86+ self . hier . root ( ) ,
87+ & self . path ,
88+ & self . specified_controllers ,
89+ true ,
90+ )
91+ } else {
92+ for subsystem in & self . subsystems {
93+ subsystem. to_controller ( ) . create ( ) ;
94+ }
95+ Ok ( ( ) )
96+ }
97+ }
98+
99+ /// Create this control group, don't enable subtree
100+ pub fn create_disabled ( & self ) -> Result < ( ) > {
101+ if self . hier . v2 ( ) {
102+ create_v2_cgroup (
103+ self . hier . root ( ) ,
104+ & self . path ,
105+ & self . specified_controllers ,
106+ false ,
107+ )
86108 } else {
87109 for subsystem in & self . subsystems {
88110 subsystem. to_controller ( ) . create ( ) ;
@@ -537,6 +559,7 @@ fn create_v2_cgroup(
537559 root : PathBuf ,
538560 path : & str ,
539561 specified_controllers : & Option < Vec < String > > ,
562+ enabled : bool ,
540563) -> Result < ( ) > {
541564 // controler list ["memory", "cpu"]
542565 let controllers = if let Some ( s_controllers) = specified_controllers. clone ( ) {
@@ -552,7 +575,9 @@ fn create_v2_cgroup(
552575 let mut fp = root;
553576
554577 // enable for root
555- enable_controllers ( & controllers, & fp) ;
578+ if enabled {
579+ enable_controllers ( & controllers, & fp) ;
580+ }
556581
557582 // path: "a/b/c"
558583 let elements = path. split ( '/' ) . collect :: < Vec < & str > > ( ) ;
@@ -567,7 +592,7 @@ fn create_v2_cgroup(
567592 }
568593 }
569594
570- if i < last_index {
595+ if enabled && i < last_index {
571596 // enable controllers for substree
572597 enable_controllers ( & controllers, & fp) ;
573598 }
0 commit comments