@@ -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 ( ) ;
@@ -208,12 +230,10 @@ impl Cgroup {
208230 p. push ( path) ;
209231 }
210232 x. enter ( p. as_ref ( ) )
233+ } else if path. as_os_str ( ) != "" {
234+ x. enter ( path)
211235 } else {
212- if path. as_os_str ( ) != "" {
213- x. enter ( path)
214- } else {
215- x
216- }
236+ x
217237 }
218238 } )
219239 . collect :: < Vec < _ > > ( ) ;
@@ -537,6 +557,7 @@ fn create_v2_cgroup(
537557 root : PathBuf ,
538558 path : & str ,
539559 specified_controllers : & Option < Vec < String > > ,
560+ enabled : bool ,
540561) -> Result < ( ) > {
541562 // controler list ["memory", "cpu"]
542563 let controllers = if let Some ( s_controllers) = specified_controllers. clone ( ) {
@@ -552,7 +573,9 @@ fn create_v2_cgroup(
552573 let mut fp = root;
553574
554575 // enable for root
555- enable_controllers ( & controllers, & fp) ;
576+ if enabled {
577+ enable_controllers ( & controllers, & fp) ;
578+ }
556579
557580 // path: "a/b/c"
558581 let elements = path. split ( '/' ) . collect :: < Vec < & str > > ( ) ;
@@ -567,7 +590,7 @@ fn create_v2_cgroup(
567590 }
568591 }
569592
570- if i < last_index {
593+ if enabled && i < last_index {
571594 // enable controllers for substree
572595 enable_controllers ( & controllers, & fp) ;
573596 }
0 commit comments