@@ -37,6 +37,8 @@ use crate::cgroup::Cgroup;
3737/// See `proc(5)` for format details.
3838#[ derive( Debug , PartialEq , Eq , Hash , Clone ) ]
3939pub struct Mountinfo {
40+ /// Mount root directory of the file system.
41+ pub mount_root : PathBuf ,
4042 /// Mount pathname relative to the process's root.
4143 pub mount_point : PathBuf ,
4244 /// Filesystem type (main type with optional sub-type).
@@ -57,6 +59,7 @@ pub(crate) fn parse_mountinfo_for_line(line: &str) -> Option<Mountinfo> {
5759 return None ;
5860 }
5961 let mount_point = PathBuf :: from ( s0_values[ 4 ] ) ;
62+ let mount_root = PathBuf :: from ( s0_values[ 3 ] ) ;
6063 let fs_type_values: Vec < _ > = s1_values[ 0 ] . trim ( ) . split ( '.' ) . collect ( ) ;
6164 let fs_type = match fs_type_values. len ( ) {
6265 1 => ( fs_type_values[ 0 ] . to_string ( ) , None ) ,
@@ -69,6 +72,7 @@ pub(crate) fn parse_mountinfo_for_line(line: &str) -> Option<Mountinfo> {
6972
7073 let super_opts: Vec < String > = s1_values[ 2 ] . trim ( ) . split ( ',' ) . map ( String :: from) . collect ( ) ;
7174 Some ( Mountinfo {
75+ mount_root,
7276 mount_point,
7377 fs_type,
7478 super_opts,
@@ -123,47 +127,53 @@ impl Hierarchy for V1 {
123127 // The cgroup writeback feature requires cooperation between memcgs and blkcgs
124128 // To avoid exceptions, we should add_task for blkcg before memcg(push BlkIo before Mem)
125129 // For more Information: https://www.alibabacloud.com/help/doc-detail/155509.htm
126- if let Some ( root) = self . get_mount_point ( Controllers :: BlkIo ) {
127- subs. push ( Subsystem :: BlkIo ( BlkIoController :: new ( root, false ) ) ) ;
130+ if let Some ( ( point , root) ) = self . get_mount_point ( Controllers :: BlkIo ) {
131+ subs. push ( Subsystem :: BlkIo ( BlkIoController :: new ( point , root, false ) ) ) ;
128132 }
129- if let Some ( root) = self . get_mount_point ( Controllers :: Mem ) {
130- subs. push ( Subsystem :: Mem ( MemController :: new ( root, false ) ) ) ;
133+ if let Some ( ( point , root) ) = self . get_mount_point ( Controllers :: Mem ) {
134+ subs. push ( Subsystem :: Mem ( MemController :: new ( point , root, false ) ) ) ;
131135 }
132- if let Some ( root) = self . get_mount_point ( Controllers :: Pids ) {
133- subs. push ( Subsystem :: Pid ( PidController :: new ( root, false ) ) ) ;
136+ if let Some ( ( point , root) ) = self . get_mount_point ( Controllers :: Pids ) {
137+ subs. push ( Subsystem :: Pid ( PidController :: new ( point , root, false ) ) ) ;
134138 }
135- if let Some ( root) = self . get_mount_point ( Controllers :: CpuSet ) {
136- subs. push ( Subsystem :: CpuSet ( CpuSetController :: new ( root, false ) ) ) ;
139+ if let Some ( ( point , root) ) = self . get_mount_point ( Controllers :: CpuSet ) {
140+ subs. push ( Subsystem :: CpuSet ( CpuSetController :: new ( point , root, false ) ) ) ;
137141 }
138- if let Some ( root) = self . get_mount_point ( Controllers :: CpuAcct ) {
139- subs. push ( Subsystem :: CpuAcct ( CpuAcctController :: new ( root) ) ) ;
142+ if let Some ( ( point , root) ) = self . get_mount_point ( Controllers :: CpuAcct ) {
143+ subs. push ( Subsystem :: CpuAcct ( CpuAcctController :: new ( point , root) ) ) ;
140144 }
141- if let Some ( root) = self . get_mount_point ( Controllers :: Cpu ) {
142- subs. push ( Subsystem :: Cpu ( CpuController :: new ( root, false ) ) ) ;
145+ if let Some ( ( point , root) ) = self . get_mount_point ( Controllers :: Cpu ) {
146+ subs. push ( Subsystem :: Cpu ( CpuController :: new ( point , root, false ) ) ) ;
143147 }
144- if let Some ( root) = self . get_mount_point ( Controllers :: Devices ) {
145- subs. push ( Subsystem :: Devices ( DevicesController :: new ( root) ) ) ;
148+ if let Some ( ( point , root) ) = self . get_mount_point ( Controllers :: Devices ) {
149+ subs. push ( Subsystem :: Devices ( DevicesController :: new ( point , root) ) ) ;
146150 }
147- if let Some ( root) = self . get_mount_point ( Controllers :: Freezer ) {
148- subs. push ( Subsystem :: Freezer ( FreezerController :: new ( root, false ) ) ) ;
151+ if let Some ( ( point, root) ) = self . get_mount_point ( Controllers :: Freezer ) {
152+ subs. push ( Subsystem :: Freezer ( FreezerController :: new (
153+ point, root, false ,
154+ ) ) ) ;
149155 }
150- if let Some ( root) = self . get_mount_point ( Controllers :: NetCls ) {
151- subs. push ( Subsystem :: NetCls ( NetClsController :: new ( root) ) ) ;
156+ if let Some ( ( point , root) ) = self . get_mount_point ( Controllers :: NetCls ) {
157+ subs. push ( Subsystem :: NetCls ( NetClsController :: new ( point , root) ) ) ;
152158 }
153- if let Some ( root) = self . get_mount_point ( Controllers :: PerfEvent ) {
154- subs. push ( Subsystem :: PerfEvent ( PerfEventController :: new ( root) ) ) ;
159+ if let Some ( ( point , root) ) = self . get_mount_point ( Controllers :: PerfEvent ) {
160+ subs. push ( Subsystem :: PerfEvent ( PerfEventController :: new ( point , root) ) ) ;
155161 }
156- if let Some ( root) = self . get_mount_point ( Controllers :: NetPrio ) {
157- subs. push ( Subsystem :: NetPrio ( NetPrioController :: new ( root) ) ) ;
162+ if let Some ( ( point , root) ) = self . get_mount_point ( Controllers :: NetPrio ) {
163+ subs. push ( Subsystem :: NetPrio ( NetPrioController :: new ( point , root) ) ) ;
158164 }
159- if let Some ( root) = self . get_mount_point ( Controllers :: HugeTlb ) {
160- subs. push ( Subsystem :: HugeTlb ( HugeTlbController :: new ( root, false ) ) ) ;
165+ if let Some ( ( point, root) ) = self . get_mount_point ( Controllers :: HugeTlb ) {
166+ subs. push ( Subsystem :: HugeTlb ( HugeTlbController :: new (
167+ point, root, false ,
168+ ) ) ) ;
161169 }
162- if let Some ( root) = self . get_mount_point ( Controllers :: Rdma ) {
163- subs. push ( Subsystem :: Rdma ( RdmaController :: new ( root) ) ) ;
170+ if let Some ( ( point , root) ) = self . get_mount_point ( Controllers :: Rdma ) {
171+ subs. push ( Subsystem :: Rdma ( RdmaController :: new ( point , root) ) ) ;
164172 }
165- if let Some ( root) = self . get_mount_point ( Controllers :: Systemd ) {
166- subs. push ( Subsystem :: Systemd ( SystemdController :: new ( root, false ) ) ) ;
173+ if let Some ( ( point, root) ) = self . get_mount_point ( Controllers :: Systemd ) {
174+ subs. push ( Subsystem :: Systemd ( SystemdController :: new (
175+ point, root, false ,
176+ ) ) ) ;
167177 }
168178
169179 subs
@@ -218,29 +228,51 @@ impl Hierarchy for V2 {
218228 for s in controller_list {
219229 match s {
220230 "cpu" => {
221- subs. push ( Subsystem :: Cpu ( CpuController :: new ( self . root ( ) , true ) ) ) ;
231+ subs. push ( Subsystem :: Cpu ( CpuController :: new (
232+ self . root ( ) ,
233+ PathBuf :: from ( "" ) ,
234+ true ,
235+ ) ) ) ;
222236 }
223237 "io" => {
224- subs. push ( Subsystem :: BlkIo ( BlkIoController :: new ( self . root ( ) , true ) ) ) ;
238+ subs. push ( Subsystem :: BlkIo ( BlkIoController :: new (
239+ self . root ( ) ,
240+ PathBuf :: from ( "" ) ,
241+ true ,
242+ ) ) ) ;
225243 }
226244 "cpuset" => {
227- subs. push ( Subsystem :: CpuSet ( CpuSetController :: new ( self . root ( ) , true ) ) ) ;
245+ subs. push ( Subsystem :: CpuSet ( CpuSetController :: new (
246+ self . root ( ) ,
247+ PathBuf :: from ( "" ) ,
248+ true ,
249+ ) ) ) ;
228250 }
229251 "memory" => {
230- subs. push ( Subsystem :: Mem ( MemController :: new ( self . root ( ) , true ) ) ) ;
252+ subs. push ( Subsystem :: Mem ( MemController :: new (
253+ self . root ( ) ,
254+ PathBuf :: from ( "" ) ,
255+ true ,
256+ ) ) ) ;
231257 }
232258 "pids" => {
233- subs. push ( Subsystem :: Pid ( PidController :: new ( self . root ( ) , true ) ) ) ;
259+ subs. push ( Subsystem :: Pid ( PidController :: new (
260+ self . root ( ) ,
261+ PathBuf :: from ( "" ) ,
262+ true ,
263+ ) ) ) ;
234264 }
235265 "freezer" => {
236266 subs. push ( Subsystem :: Freezer ( FreezerController :: new (
237267 self . root ( ) ,
268+ PathBuf :: from ( "" ) ,
238269 true ,
239270 ) ) ) ;
240271 }
241272 "hugetlb" => {
242273 subs. push ( Subsystem :: HugeTlb ( HugeTlbController :: new (
243274 self . root ( ) ,
275+ PathBuf :: from ( "" ) ,
244276 true ,
245277 ) ) ) ;
246278 }
@@ -275,10 +307,10 @@ impl V1 {
275307 }
276308 }
277309
278- pub fn get_mount_point ( & self , controller : Controllers ) -> Option < PathBuf > {
310+ pub fn get_mount_point ( & self , controller : Controllers ) -> Option < ( PathBuf , PathBuf ) > {
279311 self . mountinfo . iter ( ) . find_map ( |m| {
280312 if m. fs_type . 0 == "cgroup" && m. super_opts . contains ( & controller. to_string ( ) ) {
281- return Some ( m. mount_point . clone ( ) ) ;
313+ return Some ( ( m. mount_point . to_owned ( ) , m . mount_root . to_owned ( ) ) ) ;
282314 }
283315 None
284316 } )
@@ -337,19 +369,19 @@ mod tests {
337369 fn test_parse_mount ( ) {
338370 let mountinfo = vec ! [
339371 ( "29 26 0:26 / /sys/fs/cgroup/cpuset,cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:10 - cgroup cgroup rw,cpuset,cpu,cpuacct" ,
340- Mountinfo { mount_point: PathBuf :: from( "/sys/fs/cgroup/cpuset,cpu,cpuacct" ) , fs_type: ( "cgroup" . to_string( ) , None ) , super_opts: vec![
372+ Mountinfo { mount_root : PathBuf :: from ( "/" ) , mount_point: PathBuf :: from( "/sys/fs/cgroup/cpuset,cpu,cpuacct" ) , fs_type: ( "cgroup" . to_string( ) , None ) , super_opts: vec![
341373 "rw" . to_string( ) ,
342374 "cpuset" . to_string( ) ,
343375 "cpu" . to_string( ) ,
344376 "cpuacct" . to_string( ) ,
345377 ] } ) ,
346378 ( "121 1731 0:42 / /shm rw,nosuid,nodev,noexec,relatime shared:68 master:66 - tmpfs shm rw,size=65536k" ,
347- Mountinfo { mount_point: PathBuf :: from( "/shm" ) , fs_type: ( "tmpfs" . to_string( ) , None ) , super_opts: vec![
379+ Mountinfo { mount_root : PathBuf :: from ( "/" ) , mount_point: PathBuf :: from( "/shm" ) , fs_type: ( "tmpfs" . to_string( ) , None ) , super_opts: vec![
348380 "rw" . to_string( ) ,
349381 "size=65536k" . to_string( ) ,
350382 ] } ) ,
351383 ( "121 1731 0:42 / /shm rw,nosuid,nodev,noexec,relatime shared:68 master:66 - tmpfs.123 shm rw,size=65536k" ,
352- Mountinfo { mount_point: PathBuf :: from( "/shm" ) , fs_type: ( "tmpfs" . to_string( ) , Some ( "123" . to_string( ) ) ) , super_opts: vec![
384+ Mountinfo { mount_root : PathBuf :: from ( "/" ) , mount_point: PathBuf :: from( "/shm" ) , fs_type: ( "tmpfs" . to_string( ) , Some ( "123" . to_string( ) ) ) , super_opts: vec![
353385 "rw" . to_string( ) ,
354386 "size=65536k" . to_string( ) ,
355387 ] } ) ,
0 commit comments