File tree 5 files changed +32
-4
lines changed
5 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
48
48
49
49
### Changed
50
50
51
+ - [ #4309 ] ( https://github.com/firecracker-microvm/firecracker/pull/4309 ) : The
52
+ jailer's option ` --parent-cgroup ` will move the process to that cgroup if no
53
+ ` cgroup ` options are provided.
51
54
- Simplified and clarified the removal policy of deprecated API elements
52
55
to follow semantic versioning 2.0.0. For more information, please refer to
53
56
[ this GitHub discussion] ( https://github.com/firecracker-microvm/firecracker/discussions/4135 ) .
Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ jailer --id <id> \
46
46
the jailer will write all cgroup parameters specified through ` --cgroup ` in
47
47
` /sys/fs/cgroup/<controller_name>/all_uvms/external_uvms/<id> ` . By default, the
48
48
parent cgroup is ` exec-file ` .
49
+ If there are no ` --cgroup ` parameters specified and ` --group-version=2 ` was
50
+ passed, then the jailer will move the process to the specified cgroup.
49
51
- ` cgroup-version ` is used to select which type of cgroup hierarchy to use for
50
52
the creation of cgroups. The default value is "1" which means that cgroups
51
53
specified with the ` cgroup ` argument will be created within a v1 hierarchy.
Original file line number Diff line number Diff line change @@ -161,6 +161,16 @@ impl CgroupBuilder {
161
161
}
162
162
}
163
163
}
164
+
165
+ // Returns the path to the root of the hierarchy
166
+ pub fn get_v2_hierarchy_path ( & mut self ) -> Result < & PathBuf , JailerError > {
167
+ match self . hierarchies . entry ( "unified" . to_string ( ) ) {
168
+ Occupied ( entry) => Ok ( entry. into_mut ( ) ) ,
169
+ Vacant ( _entry) => Err ( JailerError :: CgroupHierarchyMissing (
170
+ "cgroupsv2 hierarchy missing" . to_string ( ) ,
171
+ ) ) ,
172
+ }
173
+ }
164
174
}
165
175
166
176
#[ derive( Debug ) ]
Original file line number Diff line number Diff line change @@ -233,11 +233,24 @@ impl Env {
233
233
. parse :: < u8 > ( )
234
234
. map_err ( |_| JailerError :: CgroupInvalidVersion ( cgroup_ver. to_string ( ) ) ) ?;
235
235
236
- let mut cgroup_builder = None ;
236
+ let cgroups_args: & [ String ] = arguments. multiple_values ( "cgroup" ) . unwrap_or_default ( ) ;
237
+
238
+ // If the --parent-cgroup exists, and we have no other cgroups,
239
+ // then the intent is to move the process to that cgroup.
240
+ // Only applies to cgroupsv2 since it's a unified hierarchy
241
+ if cgroups_args. is_empty ( ) && cgroup_ver == 2 {
242
+ let mut builder = CgroupBuilder :: new ( cgroup_ver) ?;
243
+ let cg_parent = builder. get_v2_hierarchy_path ( ) ?. join ( parent_cgroup) ;
244
+ let cg_parent_procs = cg_parent. join ( "cgroup.procs" ) ;
245
+ if cg_parent. exists ( ) {
246
+ fs:: write ( cg_parent_procs, std:: process:: id ( ) . to_string ( ) )
247
+ . map_err ( |_| JailerError :: CgroupWrite ( io:: Error :: last_os_error ( ) ) ) ?;
248
+ }
249
+ }
237
250
238
251
// cgroup format: <cgroup_controller>.<cgroup_property>=<value>,...
239
252
if let Some ( cgroups_args) = arguments. multiple_values ( "cgroup" ) {
240
- let builder = cgroup_builder . get_or_insert ( CgroupBuilder :: new ( cgroup_ver) ?) ;
253
+ let mut builder = CgroupBuilder :: new ( cgroup_ver) ?;
241
254
for cg in cgroups_args {
242
255
let aux: Vec < & str > = cg. split ( '=' ) . collect ( ) ;
243
256
if aux. len ( ) != 2 || aux[ 1 ] . is_empty ( ) {
Original file line number Diff line number Diff line change @@ -32,8 +32,6 @@ pub enum JailerError {
32
32
CgroupLineNotFound ( String , String ) ,
33
33
#[ error( "Cgroup invalid file: {0}" ) ]
34
34
CgroupInvalidFile ( String ) ,
35
- #[ error( "Expected value {0} for {2}. Current value: {1}" ) ]
36
- CgroupWrite ( String , String , String ) ,
37
35
#[ error( "Invalid format for cgroups: {0}" ) ]
38
36
CgroupFormat ( String ) ,
39
37
#[ error( "Hierarchy not found: {0}" ) ]
@@ -44,6 +42,8 @@ pub enum JailerError {
44
42
CgroupInvalidVersion ( String ) ,
45
43
#[ error( "Parent cgroup path is invalid. Path should not be absolute or contain '..' or '.'" ) ]
46
44
CgroupInvalidParentPath ( ) ,
45
+ #[ error( "Failed to write to cgroups file: {0}" ) ]
46
+ CgroupWrite ( io:: Error ) ,
47
47
#[ error( "Failed to change owner for {0:?}: {1}" ) ]
48
48
ChangeFileOwner ( PathBuf , io:: Error ) ,
49
49
#[ error( "Failed to chdir into chroot directory: {0}" ) ]
You can’t perform that action at this time.
0 commit comments