@@ -82,7 +82,29 @@ impl Cgroup {
82
82
/// Create this control group.
83
83
pub fn create ( & self ) -> Result < ( ) > {
84
84
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
+ )
86
108
} else {
87
109
for subsystem in & self . subsystems {
88
110
subsystem. to_controller ( ) . create ( ) ;
@@ -208,12 +230,10 @@ impl Cgroup {
208
230
p. push ( path) ;
209
231
}
210
232
x. enter ( p. as_ref ( ) )
233
+ } else if path. as_os_str ( ) != "" {
234
+ x. enter ( path)
211
235
} else {
212
- if path. as_os_str ( ) != "" {
213
- x. enter ( path)
214
- } else {
215
- x
216
- }
236
+ x
217
237
}
218
238
} )
219
239
. collect :: < Vec < _ > > ( ) ;
@@ -537,6 +557,7 @@ fn create_v2_cgroup(
537
557
root : PathBuf ,
538
558
path : & str ,
539
559
specified_controllers : & Option < Vec < String > > ,
560
+ enabled : bool ,
540
561
) -> Result < ( ) > {
541
562
// controler list ["memory", "cpu"]
542
563
let controllers = if let Some ( s_controllers) = specified_controllers. clone ( ) {
@@ -552,7 +573,9 @@ fn create_v2_cgroup(
552
573
let mut fp = root;
553
574
554
575
// enable for root
555
- enable_controllers ( & controllers, & fp) ;
576
+ if enabled {
577
+ enable_controllers ( & controllers, & fp) ;
578
+ }
556
579
557
580
// path: "a/b/c"
558
581
let elements = path. split ( '/' ) . collect :: < Vec < & str > > ( ) ;
@@ -567,7 +590,7 @@ fn create_v2_cgroup(
567
590
}
568
591
}
569
592
570
- if i < last_index {
593
+ if enabled && i < last_index {
571
594
// enable controllers for substree
572
595
enable_controllers ( & controllers, & fp) ;
573
596
}
0 commit comments