From 5660656e3a4bbee8ac86da281ae167c4991d36c5 Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Mon, 1 Oct 2018 18:29:29 +0900 Subject: [PATCH] Use self short-hand --- src/blkio.rs | 30 +++++++++++++++--------------- src/cgroup.rs | 14 +++++++------- src/cpu.rs | 24 ++++++++++++------------ src/cpuacct.rs | 14 +++++++------- src/cpuset.rs | 34 +++++++++++++++++----------------- src/devices.rs | 20 ++++++++++---------- src/freezer.rs | 16 ++++++++-------- src/hierarchies.rs | 8 ++++---- src/hugetlb.rs | 22 +++++++++++----------- src/lib.rs | 40 ++++++++++++++++++++-------------------- src/memory.rs | 30 +++++++++++++++--------------- src/net_cls.rs | 14 +++++++------- src/net_prio.rs | 16 ++++++++-------- src/perf_event.rs | 10 +++++----- src/pid.rs | 18 +++++++++--------- src/rdma.rs | 14 +++++++------- 16 files changed, 162 insertions(+), 162 deletions(-) diff --git a/src/blkio.rs b/src/blkio.rs index 1d42111..7036f1d 100644 --- a/src/blkio.rs +++ b/src/blkio.rs @@ -256,12 +256,12 @@ pub struct BlkIo { } impl Controller for BlkIoController { - fn control_type(self: &Self) -> Controllers { Controllers::BlkIo } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::BlkIo } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, res: &Resources) -> Result<(), CgroupError> { /* get the resources that apply to this controller */ let res: &BlkIoResources = &res.blkio; @@ -343,7 +343,7 @@ impl BlkIoController { /// Gathers statistics about and reports the state of the block devices used by the control /// group's tasks. - pub fn blkio(self: &Self) -> BlkIo { + pub fn blkio(&self) -> BlkIo { BlkIo { io_merged: self.open_path("blkio.io_merged", false) .and_then(read_string_from) @@ -519,21 +519,21 @@ impl BlkIoController { /// Set the leaf weight on the control group's tasks, i.e., how are they weighted against the /// descendant control groups' tasks. - pub fn set_leaf_weight(self: &Self, w: u64) -> Result<(), CgroupError> { + pub fn set_leaf_weight(&self, w: u64) -> Result<(), CgroupError> { self.open_path("blkio.leaf_weight", true).and_then(|mut file| { file.write_all(w.to_string().as_ref()).map_err(CgroupError::WriteError) }) } /// Same as `set_leaf_weight()`, but settable per each block device. - pub fn set_leaf_weight_for_device(self: &Self, d: String) -> Result<(), CgroupError> { + pub fn set_leaf_weight_for_device(&self, d: String) -> Result<(), CgroupError> { self.open_path("blkio.leaf_weight_device", true).and_then(|mut file| { file.write_all(d.as_ref()).map_err(CgroupError::WriteError) }) } /// Reset the statistics the kernel has gathered so far and start fresh. - pub fn reset_stats(self: &Self) -> Result<(), CgroupError> { + pub fn reset_stats(&self) -> Result<(), CgroupError> { self.open_path("blkio.leaf_weight_device", true).and_then(|mut file| { file.write_all("1".to_string().as_ref()).map_err(CgroupError::WriteError) }) @@ -541,7 +541,7 @@ impl BlkIoController { /// Throttle the bytes per second rate of read operation affecting the block device /// `major:minor` to `bps`. - pub fn throttle_read_bps_for_device(self: &Self, major: u64, minor: u64, bps: u64) -> Result<(), CgroupError> { + pub fn throttle_read_bps_for_device(&self, major: u64, minor: u64, bps: u64) -> Result<(), CgroupError> { self.open_path("blkio.throttle.read_bps_device", true).and_then(|mut file| { file.write_all(format!("{}:{} {}", major, minor, bps).to_string().as_ref()).map_err(CgroupError::WriteError) }) @@ -549,14 +549,14 @@ impl BlkIoController { /// Throttle the I/O operations per second rate of read operation affecting the block device /// `major:minor` to `bps`. - pub fn throttle_read_iops_for_device(self: &Self, major: u64, minor: u64, iops: u64) -> Result<(), CgroupError> { + pub fn throttle_read_iops_for_device(&self, major: u64, minor: u64, iops: u64) -> Result<(), CgroupError> { self.open_path("blkio.throttle.read_iops_device", true).and_then(|mut file| { file.write_all(format!("{}:{} {}", major, minor, iops).to_string().as_ref()).map_err(CgroupError::WriteError) }) } /// Throttle the bytes per second rate of write operation affecting the block device /// `major:minor` to `bps`. - pub fn throttle_write_bps_for_device(self: &Self, major: u64, minor: u64, bps: u64) -> Result<(), CgroupError> { + pub fn throttle_write_bps_for_device(&self, major: u64, minor: u64, bps: u64) -> Result<(), CgroupError> { self.open_path("blkio.throttle.write_bps_device", true).and_then(|mut file| { file.write_all(format!("{}:{} {}", major, minor, bps).to_string().as_ref()).map_err(CgroupError::WriteError) }) @@ -564,21 +564,21 @@ impl BlkIoController { /// Throttle the I/O operations per second rate of write operation affecting the block device /// `major:minor` to `bps`. - pub fn throttle_write_iops_for_device(self: &Self, major: u64, minor: u64, iops: u64) -> Result<(), CgroupError> { + pub fn throttle_write_iops_for_device(&self, major: u64, minor: u64, iops: u64) -> Result<(), CgroupError> { self.open_path("blkio.throttle.write_iops_device", true).and_then(|mut file| { file.write_all(format!("{}:{} {}", major, minor, iops).to_string().as_ref()).map_err(CgroupError::WriteError) }) } /// Set the weight of the control group's tasks. - pub fn set_weight(self: &Self, w: u64) -> Result<(), CgroupError> { + pub fn set_weight(&self, w: u64) -> Result<(), CgroupError> { self.open_path("blkio.leaf_weight", true).and_then(|mut file| { file.write_all(w.to_string().as_ref()).map_err(CgroupError::WriteError) }) } /// Same as `set_weight()`, but settable per each block device. - pub fn set_weight_for_device(self: &Self, major: u64, minor: u64, weight: u64) -> Result<(), CgroupError> { + pub fn set_weight_for_device(&self, major: u64, minor: u64, weight: u64) -> Result<(), CgroupError> { self.open_path("blkio.weight_device", true).and_then(|mut file| { file.write_all(format!("{}:{} {}", major, minor, weight).as_ref()) .map_err(CgroupError::WriteError) diff --git a/src/cgroup.rs b/src/cgroup.rs index affc001..7e46f0f 100644 --- a/src/cgroup.rs +++ b/src/cgroup.rs @@ -28,7 +28,7 @@ pub struct Cgroup<'b> { impl<'b> Cgroup<'b> { /// Create this control group. - fn create(self: &Self) { + fn create(&self) { for subsystem in &self.subsystems { subsystem.to_controller().create(); } @@ -68,7 +68,7 @@ impl<'b> Cgroup<'b> { } /// The list of subsystems that this control group supports. - pub fn subsystems(self: &Self) -> &Vec { + pub fn subsystems(&self) -> &Vec { &self.subsystems } @@ -78,7 +78,7 @@ impl<'b> Cgroup<'b> { /// system call will fail if there are any descendants. Thus, one should check whether it was /// actually removed, and remove the descendants first if not. In the future, this behavior /// will change. - pub fn delete(self: Self) { + pub fn delete(self) { self.subsystems.into_iter().for_each(|sub| { match sub { Subsystem::Pid(pidc) => pidc.delete(), @@ -99,7 +99,7 @@ impl<'b> Cgroup<'b> { } /// Apply a set of resource limits to the control group. - pub fn apply(self: &Self, res: &Resources) -> Result<(), CgroupError> { + pub fn apply(&self, res: &Resources) -> Result<(), CgroupError> { self.subsystems.iter().try_fold((), |_, e| e.to_controller().apply(res)) } @@ -133,18 +133,18 @@ impl<'b> Cgroup<'b> { /// /// Note that this means that the task will be moved back to the root control group in the /// hierarchy and any rules applied to that control group will _still_ apply to the task. - pub fn remove_task(self: &Self, pid: CgroupPid) { + pub fn remove_task(&self, pid: CgroupPid) { let _ = self.hier.root_control_group().add_task(pid); } /// Attach a task to the control group. - pub fn add_task(self: &Self, pid: CgroupPid) -> Result<(), CgroupError> { + pub fn add_task(&self, pid: CgroupPid) -> Result<(), CgroupError> { self.subsystems().iter().try_for_each(|sub| sub.to_controller().add_task(&pid)) } /// Returns an Iterator that can be used to iterate over the tasks that are currently in the /// control group. - pub fn tasks(self: &Self) -> Vec { + pub fn tasks(&self) -> Vec { /* Collect the tasks from all subsystems */ let mut v = self.subsystems().iter() .map(|x| x.to_controller().tasks()) diff --git a/src/cpu.rs b/src/cpu.rs index 5a2a232..eb6ccf7 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -30,12 +30,12 @@ pub struct Cpu { } impl Controller for CpuController { - fn control_type(self: &Self) -> Controllers { Controllers::Cpu} - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::Cpu} + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, res: &Resources) -> Result<(), CgroupError> { /* get the resources that apply to this controller */ let res: &CpuResources = &res.cpu; @@ -100,7 +100,7 @@ impl CpuController { } /// Returns CPU time statistics based on the processes in the control group. - pub fn cpu(self: &Self) -> Cpu { + pub fn cpu(&self) -> Cpu { Cpu { stat: self.open_path("cpu.stat", false).and_then(|mut file| { let mut s = String::new(); @@ -119,7 +119,7 @@ impl CpuController { /// For example, setting control group `A`'s `shares` to `100`, and control group `B`'s /// `shares` to `200` ensures that control group `B` receives twice as much as CPU bandwidth. /// (Assuming both `A` and `B` are of the same parent) - pub fn set_shares(self: &Self, shares: u64) -> Result<(), CgroupError> { + pub fn set_shares(&self, shares: u64) -> Result<(), CgroupError> { self.open_path("cpu.shares", true).and_then(|mut file| { file.write_all(shares.to_string().as_ref()).map_err(CgroupError::WriteError) }) @@ -127,14 +127,14 @@ impl CpuController { /// Retrieve the CPU bandwidth that this control group (relative to other control groups and /// this control group's parent) can use. - pub fn shares(self: &Self) -> Result { + pub fn shares(&self) -> Result { self.open_path("cpu.shares", false) .and_then(read_u64_from) } /// Specify a period (when using the CFS scheduler) of time in microseconds for how often this /// control group's access to the CPU should be reallocated. - pub fn set_cfs_period(self: &Self, us: u64) -> Result<(), CgroupError> { + pub fn set_cfs_period(&self, us: u64) -> Result<(), CgroupError> { self.open_path("cpu.cfs_period_us", true).and_then(|mut file| { file.write_all(us.to_string().as_ref()).map_err(CgroupError::WriteError) }) @@ -142,14 +142,14 @@ impl CpuController { /// Retrieve the period of time of how often this cgroup's access to the CPU should be /// reallocated in microseconds. - pub fn cfs_period(self: &Self) -> Result { + pub fn cfs_period(&self) -> Result { self.open_path("cpu.cfs_period_us", false) .and_then(read_u64_from) } /// Specify a quota (when using the CFS scheduler) of time in microseconds for which all tasks /// in this control group can run during one period (see: `set_cfs_period()`). - pub fn set_cfs_quota(self: &Self, us: u64) -> Result<(), CgroupError> { + pub fn set_cfs_quota(&self, us: u64) -> Result<(), CgroupError> { self.open_path("cpu.cfs_quota_us", true).and_then(|mut file| { file.write_all(us.to_string().as_ref()).map_err(CgroupError::WriteError) }) @@ -157,7 +157,7 @@ impl CpuController { /// Retrieve the quota of time for which all tasks in this cgroup can run during one period, in /// microseconds. - pub fn cfs_quota(self: &Self) -> Result { + pub fn cfs_quota(&self) -> Result { self.open_path("cpu.cfs_quota_us", false) .and_then(read_u64_from) } diff --git a/src/cpuacct.rs b/src/cpuacct.rs index 31d9997..53d5a82 100644 --- a/src/cpuacct.rs +++ b/src/cpuacct.rs @@ -50,12 +50,12 @@ pub struct CpuAcct { } impl Controller for CpuAcctController { - fn control_type(self: &Self) -> Controllers { Controllers::CpuAcct } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::CpuAcct } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, _res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, _res: &Resources) -> Result<(), CgroupError> { Ok(()) } } @@ -113,7 +113,7 @@ impl CpuAcctController { } /// Gathers the statistics that are available in the control group into a `CpuAcct` structure. - pub fn cpuacct(self: &Self) -> CpuAcct { + pub fn cpuacct(&self) -> CpuAcct { CpuAcct { stat: self.open_path("cpuacct.stat", false) .and_then(|file| read_string_from(file)).unwrap_or("".to_string()), @@ -138,7 +138,7 @@ impl CpuAcctController { } /// Reset the statistics the kernel has gathered about the control group. - pub fn reset(self: &Self) -> Result<(), CgroupError> { + pub fn reset(&self) -> Result<(), CgroupError> { self.open_path("cpuacct.usage", true).and_then(|mut file| { file.write_all(b"0").map_err(CgroupError::WriteError) }) diff --git a/src/cpuset.rs b/src/cpuset.rs index 1d9718c..d39a3c4 100644 --- a/src/cpuset.rs +++ b/src/cpuset.rs @@ -77,12 +77,12 @@ pub struct CpuSet { } impl Controller for CpuSetController { - fn control_type(self: &Self) -> Controllers { Controllers::CpuSet } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::CpuSet } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, res: &Resources) -> Result<(), CgroupError> { /* get the resources that apply to this controller */ let res: &CpuResources = &res.cpu; @@ -181,7 +181,7 @@ impl CpuSetController { /// Returns the statistics gathered by the kernel for this control group. See the struct for /// more information on what information this entails. - pub fn cpuset(self: &Self) -> CpuSet { + pub fn cpuset(&self) -> CpuSet { CpuSet { cpu_exclusive: { self.open_path("cpuset.cpu_exclusive", false).and_then(|file| { @@ -250,7 +250,7 @@ impl CpuSetController { /// Control whether the CPUs selected via `set_cpus()` should be exclusive to this control /// group or not. - pub fn set_cpu_exclusive(self: &Self, b: bool) -> Result<(), CgroupError> { + pub fn set_cpu_exclusive(&self, b: bool) -> Result<(), CgroupError> { self.open_path("cpuset.cpu_exclusive", true).and_then(|mut file| { if b { file.write_all(b"1").map_err(CgroupError::WriteError) @@ -262,7 +262,7 @@ impl CpuSetController { /// Control whether the memory nodes selected via `set_memss()` should be exclusive to this control /// group or not. - pub fn set_mem_exclusive(self: &Self, b: bool) -> Result<(), CgroupError> { + pub fn set_mem_exclusive(&self, b: bool) -> Result<(), CgroupError> { self.open_path("cpuset.mem_exclusive", true).and_then(|mut file| { if b { file.write_all(b"1").map_err(CgroupError::WriteError) @@ -276,7 +276,7 @@ impl CpuSetController { /// /// Syntax is a comma separated list of CPUs, with an additional extension that ranges can /// be represented via dashes. - pub fn set_cpus(self: &Self, cpus: &String) -> Result<(), CgroupError> { + pub fn set_cpus(&self, cpus: &String) -> Result<(), CgroupError> { self.open_path("cpuset.cpus", true).and_then(|mut file| { file.write_all(cpus.as_ref()).map_err(CgroupError::WriteError) }) @@ -285,7 +285,7 @@ impl CpuSetController { /// Set the memory nodes that the tasks in this control group can use. /// /// Syntax is the same as with `set_cpus()`. - pub fn set_mems(self: &Self, mems: &String) -> Result<(), CgroupError> { + pub fn set_mems(&self, mems: &String) -> Result<(), CgroupError> { self.open_path("cpuset.mems", true).and_then(|mut file| { file.write_all(mems.as_ref()).map_err(CgroupError::WriteError) }) @@ -296,7 +296,7 @@ impl CpuSetController { /// /// Note that some kernel allocations, most notably those that are made in interrupt handlers /// may disregard this. - pub fn set_hardwall(self: &Self, b: bool) -> Result<(), CgroupError> { + pub fn set_hardwall(&self, b: bool) -> Result<(), CgroupError> { self.open_path("cpuset.mem_hardwall", true).and_then(|mut file| { if b { file.write_all(b"1").map_err(CgroupError::WriteError) @@ -308,7 +308,7 @@ impl CpuSetController { /// Controls whether the kernel should attempt to rebalance the load between the CPUs specified in the /// `cpus` field of this control group. - pub fn set_load_balancing(self: &Self, b: bool) -> Result<(), CgroupError> { + pub fn set_load_balancing(&self, b: bool) -> Result<(), CgroupError> { self.open_path("cpuset.sched_load_balance", true).and_then(|mut file| { if b { file.write_all(b"1").map_err(CgroupError::WriteError) @@ -321,7 +321,7 @@ impl CpuSetController { /// Contorl how much effort the kernel should invest in rebalacing the control group. /// /// See @CpuSet 's similar field for more information. - pub fn set_rebalance_relax_domain_level(self: &Self, i: i64) -> Result<(), CgroupError> { + pub fn set_rebalance_relax_domain_level(&self, i: i64) -> Result<(), CgroupError> { self.open_path("cpuset.sched_relax_domain_level", true).and_then(|mut file| { file.write_all(i.to_string().as_ref()).map_err(CgroupError::WriteError) }) @@ -329,7 +329,7 @@ impl CpuSetController { /// Control whether when using `set_mems()` the existing memory used by the tasks should be /// migrated over to the now-selected nodes. - pub fn set_memory_migration(self: &Self, b: bool) -> Result<(), CgroupError> { + pub fn set_memory_migration(&self, b: bool) -> Result<(), CgroupError> { self.open_path("cpuset.memory_migrate", true).and_then(|mut file| { if b { file.write_all(b"1").map_err(CgroupError::WriteError) @@ -341,7 +341,7 @@ impl CpuSetController { /// Control whether filesystem buffers should be evenly split across the nodes selected via /// `set_mems()`. - pub fn set_memory_spread_page(self: &Self, b: bool) -> Result<(), CgroupError> { + pub fn set_memory_spread_page(&self, b: bool) -> Result<(), CgroupError> { self.open_path("cpuset.memory_spread_page", true).and_then(|mut file| { if b { file.write_all(b"1").map_err(CgroupError::WriteError) @@ -353,7 +353,7 @@ impl CpuSetController { /// Control whether the kernel's slab cache for file I/O should be evenly split across the /// nodes selected via `set_mems()`. - pub fn set_memory_spread_slab(self: &Self, b: bool) -> Result<(), CgroupError> { + pub fn set_memory_spread_slab(&self, b: bool) -> Result<(), CgroupError> { self.open_path("cpuset.memory_spread_slab", true).and_then(|mut file| { if b { file.write_all(b"1").map_err(CgroupError::WriteError) @@ -368,7 +368,7 @@ impl CpuSetController { /// /// Note: This will fail with `InvalidOperation` if the current congrol group is not the root /// control group. - pub fn set_enable_memory_pressure(self: &Self, b: bool) -> Result<(), CgroupError> { + pub fn set_enable_memory_pressure(&self, b: bool) -> Result<(), CgroupError> { if !self.path_exists("cpuset.memory_pressure_enabled") { return Err(CgroupError::InvalidOperation); } diff --git a/src/devices.rs b/src/devices.rs index 2d0481f..e15fed0 100644 --- a/src/devices.rs +++ b/src/devices.rs @@ -34,7 +34,7 @@ impl Default for DeviceType { impl DeviceType { /// Convert a DeviceType into the character that the kernel recognizes. - pub fn to_char(self: &Self) -> char { + pub fn to_char(&self) -> char { match self { DeviceType::All => 'a', DeviceType::Char => 'c', @@ -67,7 +67,7 @@ pub enum DevicePermissions { impl DevicePermissions { /// Convert a DevicePermissions into the character that the kernel recognizes. - pub fn to_char(self: &Self) -> char { + pub fn to_char(&self) -> char { match self { DevicePermissions::Read => 'r', DevicePermissions::Write => 'w', @@ -124,12 +124,12 @@ impl DevicePermissions { } impl Controller for DevicesController { - fn control_type(self: &Self) -> Controllers { Controllers::Devices } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::Devices } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, res: &Resources) -> Result<(), CgroupError> { /* get the resources that apply to this controller */ let res: &DeviceResources = &res.devices; @@ -182,7 +182,7 @@ impl DevicesController { /// /// When `-1` is passed as `major` or `minor`, the kernel interprets that value as "any", /// meaning that it will match any device. - pub fn allow_device(self: &Self, devtype: DeviceType, major: i64, minor: i64, perm: &Vec) -> Result<(), CgroupError> { + pub fn allow_device(&self, devtype: DeviceType, major: i64, minor: i64, perm: &Vec) -> Result<(), CgroupError> { let perms = perm.iter().map(DevicePermissions::to_char).collect::(); let minor = if minor == -1 { "*".to_string() } else { format!("{}", minor) }; let major = if major == -1 { "*".to_string() } else { format!("{}", major) }; @@ -196,7 +196,7 @@ impl DevicesController { /// /// When `-1` is passed as `major` or `minor`, the kernel interprets that value as "any", /// meaning that it will match any device. - pub fn deny_device(self: &Self, devtype: DeviceType, major: i64, minor: i64, perm: &Vec) -> Result<(), CgroupError> { + pub fn deny_device(&self, devtype: DeviceType, major: i64, minor: i64, perm: &Vec) -> Result<(), CgroupError> { let perms = perm.iter().map(DevicePermissions::to_char).collect::(); let minor = if minor == -1 { "*".to_string() } else { format!("{}", minor) }; let major = if major == -1 { "*".to_string() } else { format!("{}", major) }; @@ -207,7 +207,7 @@ impl DevicesController { } /// Get the current list of allowed devices. - pub fn allowed_devices(self: &Self) -> Result, CgroupError> { + pub fn allowed_devices(&self) -> Result, CgroupError> { self.open_path("devices.list", false).and_then(|mut file| { let mut s = String::new(); let res = file.read_to_string(&mut s); diff --git a/src/freezer.rs b/src/freezer.rs index f223b04..44725c3 100644 --- a/src/freezer.rs +++ b/src/freezer.rs @@ -32,12 +32,12 @@ pub enum FreezerState { } impl Controller for FreezerController { - fn control_type(self: &Self) -> Controllers { Controllers::Freezer } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::Freezer } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, _res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, _res: &Resources) -> Result<(), CgroupError> { Ok(()) } } @@ -74,21 +74,21 @@ impl FreezerController { } /// Freezes the processes in the control group. - pub fn freeze(self: &Self) -> Result<(), CgroupError> { + pub fn freeze(&self) -> Result<(), CgroupError> { self.open_path("freezer.state", true).and_then(|mut file| { file.write_all("FROZEN".to_string().as_ref()).map_err(CgroupError::WriteError) }) } /// Thaws, that is, unfreezes the processes in the control group. - pub fn thaw(self: &Self) -> Result<(), CgroupError> { + pub fn thaw(&self) -> Result<(), CgroupError> { self.open_path("freezer.state", true).and_then(|mut file| { file.write_all("THAWED".to_string().as_ref()).map_err(CgroupError::WriteError) }) } /// Retrieve the state of processes in the control group. - pub fn state(self: &Self) -> Result { + pub fn state(&self) -> Result { self.open_path("freezer.state", false).and_then(|mut file| { let mut s = String::new(); let res = file.read_to_string(&mut s); diff --git a/src/hierarchies.rs b/src/hierarchies.rs index 500ae72..3f305db 100644 --- a/src/hierarchies.rs +++ b/src/hierarchies.rs @@ -32,7 +32,7 @@ pub struct V1 { } impl Hierarchy for V1 { - fn subsystems(self: &Self) -> Vec { + fn subsystems(&self) -> Vec { let mut subs = vec![]; if self.check_support(Controllers::Pids) { subs.push(Subsystem::Pid(PidController::new(self.root()))); @@ -77,11 +77,11 @@ impl Hierarchy for V1 { subs } - fn root_control_group(self: &Self) -> Cgroup { + fn root_control_group(&self) -> Cgroup { Cgroup::load(self, "".to_string()) } - fn check_support(self: &Self, sub: Controllers) -> bool { + fn check_support(&self, sub: Controllers) -> bool { let root = self.root().read_dir().unwrap(); for entry in root { if let Ok(entry) = entry { @@ -93,7 +93,7 @@ impl Hierarchy for V1 { return false; } - fn root(self: &Self) -> PathBuf { + fn root(&self) -> PathBuf { PathBuf::from(self.mount_point.clone()) } } diff --git a/src/hugetlb.rs b/src/hugetlb.rs index 4cc4006..db63844 100644 --- a/src/hugetlb.rs +++ b/src/hugetlb.rs @@ -21,12 +21,12 @@ pub struct HugeTlbController { } impl Controller for HugeTlbController { - fn control_type(self: &Self) -> Controllers { Controllers::HugeTlb } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::HugeTlb } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, res: &Resources) -> Result<(), CgroupError> { /* get the resources that apply to this controller */ let res: &HugePageResources = &res.hugepages; @@ -82,41 +82,41 @@ impl HugeTlbController { } /// Whether the system supports `hugetlb_size` hugepages. - pub fn size_supported(self: &Self, _hugetlb_size: String) -> bool { + pub fn size_supported(&self, _hugetlb_size: String) -> bool { /* TODO */ true } /// Check how many times has the limit of `hugetlb_size` hugepages been hit. - pub fn failcnt(self: &Self, hugetlb_size: &String) -> Result { + pub fn failcnt(&self, hugetlb_size: &String) -> Result { self.open_path(&format!("hugetlb.{}.failcnt", hugetlb_size), false) .and_then(read_u64_from) } /// Get the limit (in bytes) of how much memory can be backed by hugepages of a certain size /// (`hugetlb_size`). - pub fn limit_in_bytes(self: &Self, hugetlb_size: &String) -> Result { + pub fn limit_in_bytes(&self, hugetlb_size: &String) -> Result { self.open_path(&format!("hugetlb.{}.limit_in_bytes", hugetlb_size), false) .and_then(read_u64_from) } /// Get the current usage of memory that is backed by hugepages of a certain size /// (`hugetlb_size`). - pub fn usage_in_bytes(self: &Self, hugetlb_size: &String) -> Result { + pub fn usage_in_bytes(&self, hugetlb_size: &String) -> Result { self.open_path(&format!("hugetlb.{}.usage_in_bytes", hugetlb_size), false) .and_then(read_u64_from) } /// Get the maximum observed usage of memory that is backed by hugepages of a certain size /// (`hugetlb_size`). - pub fn max_usage_in_bytes(self: &Self, hugetlb_size: &String) -> Result { + pub fn max_usage_in_bytes(&self, hugetlb_size: &String) -> Result { self.open_path(&format!("hugetlb.{}.max_usage_in_bytes", hugetlb_size), false) .and_then(read_u64_from) } /// Set the limit (in bytes) of how much memory can be backed by hugepages of a certain size /// (`hugetlb_size`). - pub fn set_limit_in_bytes(self: &Self, hugetlb_size: &String, limit: u64) -> Result<(), CgroupError> { + pub fn set_limit_in_bytes(&self, hugetlb_size: &String, limit: u64) -> Result<(), CgroupError> { self.open_path(&format!("hugetlb.{}.limit_in_bytes", hugetlb_size), false) .and_then(|mut file| { file.write_all(limit.to_string().as_ref()).map_err(CgroupError::WriteError) diff --git a/src/lib.rs b/src/lib.rs index 8a3036c..35cb6a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -134,7 +134,7 @@ pub enum Controllers { } impl Controllers { - pub fn to_string(self: &Self) -> String { + pub fn to_string(&self) -> String { match self { Controllers::Pids => return "pids".to_string(), Controllers::Mem => return "memory".to_string(), @@ -159,25 +159,25 @@ impl Controllers { pub trait Controller { /// Apply a set of resources to the Controller, invoking its internal functions to pass the /// kernel the information. - fn apply(self: &Self, res: &Resources) -> Result<(), CgroupError>; + fn apply(&self, res: &Resources) -> Result<(), CgroupError>; /* meta stuff */ #[doc(hidden)] - fn control_type(self: &Self) -> Controllers; + fn control_type(&self) -> Controllers; #[doc(hidden)] - fn get_path<'a>(self: &'a Self) -> &'a PathBuf; + fn get_path(&self) -> &PathBuf; #[doc(hidden)] - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf; + fn get_path_mut(&mut self) -> &mut PathBuf; #[doc(hidden)] - fn get_base<'a>(self: &'a Self) -> &'a PathBuf; + fn get_base(&self) -> &PathBuf; #[doc(hidden)] - fn verify_path(self: &Self) -> bool { + fn verify_path(&self) -> bool { self.get_path().starts_with(self.get_base()) } /// Create this controller - fn create(self: &Self) { + fn create(&self) { if self.verify_path() { match ::std::fs::create_dir(self.get_path()) { Ok(_) => (), @@ -187,19 +187,19 @@ pub trait Controller { } /// Does this controller already exist? - fn exists(self: &Self) -> bool { + fn exists(&self) -> bool { self.get_path().exists() } /// Delete the controller. - fn delete(self: &Self) { + fn delete(&self) { if self.get_path().exists() { let _ = ::std::fs::remove_dir(self.get_path()); } } #[doc(hidden)] - fn open_path(self: &Self, p: &str, w: bool) -> Result { + fn open_path(&self, p: &str, w: bool) -> Result { let mut path = self.get_path().clone(); path.push(p); @@ -221,7 +221,7 @@ pub trait Controller { } #[doc(hidden)] - fn path_exists(self: &Self, p: &str) -> bool { + fn path_exists(&self, p: &str) -> bool { if !self.verify_path() { return false; } @@ -230,14 +230,14 @@ pub trait Controller { } /// Attach a task to this controller. - fn add_task(self: &Self, pid: &CgroupPid) -> Result<(), CgroupError> { + fn add_task(&self, pid: &CgroupPid) -> Result<(), CgroupError> { self.open_path("tasks", true).and_then(|mut file| { file.write_all(pid.pid.to_string().as_ref()).map_err(CgroupError::WriteError) }) } /// Get the list of tasks that this controller has. - fn tasks(self: &Self) -> Vec { + fn tasks(&self) -> Vec { self.open_path("tasks", false).and_then(|file| { let bf = BufReader::new(file); let mut v = Vec::new(); @@ -261,19 +261,19 @@ pub trait ControllIdentifier { /// implemented as well). pub trait Hierarchy { /// Returns what subsystems are supported by the hierarchy. - fn subsystems(self: &Self) -> Vec; + fn subsystems(&self) -> Vec; /// Returns the root directory of the hierarchy. - fn root(self: &Self) -> PathBuf; + fn root(&self) -> PathBuf; /// Return a handle to the root control group in the hierarchy. - fn root_control_group(self: &Self) -> Cgroup; + fn root_control_group(&self) -> Cgroup; /// Checks whether a certain subsystem is supported in the hierarchy. /// /// This is an internal function and should not be used. #[doc(hidden)] - fn check_support(self: &Self, sub: Controllers) -> bool; + fn check_support(&self, sub: Controllers) -> bool; } /// Resource limits for the memory subsystem. @@ -495,7 +495,7 @@ impl<'a> From<&'a std::process::Child> for CgroupPid { impl Subsystem { - fn enter(self: Self, path: &String) -> Self { + fn enter(self, path: &String) -> Self { match self { Subsystem::Pid(cont) => Subsystem::Pid({ let mut c = cont.clone(); @@ -565,7 +565,7 @@ impl Subsystem { } } - fn to_controller(self: &Self) -> &dyn Controller { + fn to_controller(&self) -> &dyn Controller { match self { Subsystem::Pid(cont) => cont, Subsystem::Mem(cont) => cont, diff --git a/src/memory.rs b/src/memory.rs index 68d9f47..3aae959 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -317,12 +317,12 @@ pub struct Kmem { } impl Controller for MemController { - fn control_type(self: &Self) -> Controllers { Controllers::Mem } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::Mem } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, res: &Resources) -> Result<(), CgroupError> { /* get the resources that apply to this controller */ let memres: &MemoryResources = &res.memory; @@ -355,7 +355,7 @@ impl MemController { /// /// See the individual fields for more explanation, and as always, remember to consult the /// kernel Documentation and/or sources. - pub fn memory_stat(self: &Self) -> Memory { + pub fn memory_stat(&self) -> Memory { Memory { fail_cnt: self.open_path("memory.failcnt", false) .and_then(read_u64_from).unwrap_or(0), @@ -392,7 +392,7 @@ impl MemController { } /// Gathers information about the kernel memory usage of the control group's tasks. - pub fn kmem_stat(self: &Self) -> Kmem { + pub fn kmem_stat(&self) -> Kmem { Kmem { fail_cnt: self.open_path("memory.kmem.failcnt", false) .and_then(read_u64_from).unwrap_or(0), @@ -409,7 +409,7 @@ impl MemController { /// Gathers information about the control group's kernel memory usage where said memory is /// TCP-related. - pub fn kmem_tcp_stat(self: &Self) -> Tcp { + pub fn kmem_tcp_stat(&self) -> Tcp { Tcp { fail_cnt: self.open_path("memory.kmem.tcp.failcnt", false) .and_then(read_u64_from).unwrap_or(0), @@ -424,7 +424,7 @@ impl MemController { /// Gathers information about the memory usage of the control group including the swap usage /// (if any). - pub fn memswap(self: &Self) -> MemSwap { + pub fn memswap(&self) -> MemSwap { MemSwap { fail_cnt: self.open_path("memory.memsw.failcnt", false) .and_then(read_u64_from).unwrap_or(0), @@ -438,28 +438,28 @@ impl MemController { } /// Set the memory usage limit of the control group, in bytes. - pub fn set_limit(self: &Self, limit: u64) -> Result<(), CgroupError> { + pub fn set_limit(&self, limit: u64) -> Result<(), CgroupError> { self.open_path("memory.limit_in_bytes", true).and_then(|mut file| { file.write_all(limit.to_string().as_ref()).map_err(CgroupError::WriteError) }) } /// Set the kernel memory limit of the control group, in bytes. - pub fn set_kmem_limit(self: &Self, limit: u64) -> Result<(), CgroupError> { + pub fn set_kmem_limit(&self, limit: u64) -> Result<(), CgroupError> { self.open_path("memory.kmem.limit_in_bytes", true).and_then(|mut file| { file.write_all(limit.to_string().as_ref()).map_err(CgroupError::WriteError) }) } /// Set the memory+swap limit of the control group, in bytes. - pub fn set_memswap_limit(self: &Self, limit: u64) -> Result<(), CgroupError> { + pub fn set_memswap_limit(&self, limit: u64) -> Result<(), CgroupError> { self.open_path("memory.memsw.limit_in_bytes", true).and_then(|mut file| { file.write_all(limit.to_string().as_ref()).map_err(CgroupError::WriteError) }) } /// Set how much kernel memory can be used for TCP-related buffers by the control group. - pub fn set_tcp_limit(self: &Self, limit: u64) -> Result<(), CgroupError> { + pub fn set_tcp_limit(&self, limit: u64) -> Result<(), CgroupError> { self.open_path("memory.kmem.tcp.limit_in_bytes", true).and_then(|mut file| { file.write_all(limit.to_string().as_ref()).map_err(CgroupError::WriteError) }) @@ -470,7 +470,7 @@ impl MemController { /// /// This limit is enforced when the system is nearing OOM conditions. Contrast this with the /// hard limit, which is _always_ enforced. - pub fn set_soft_limit(self: &Self, limit: u64) -> Result<(), CgroupError> { + pub fn set_soft_limit(&self, limit: u64) -> Result<(), CgroupError> { self.open_path("memory.soft_limit_in_bytes", true).and_then(|mut file| { file.write_all(limit.to_string().as_ref()).map_err(CgroupError::WriteError) }) @@ -481,7 +481,7 @@ impl MemController { /// group. /// /// Note that a value of zero does not imply that the process will not be swapped out. - pub fn set_swappiness(self: &Self, swp: u64) -> Result<(), CgroupError> { + pub fn set_swappiness(&self, swp: u64) -> Result<(), CgroupError> { self.open_path("memory.swappiness", true).and_then(|mut file| { file.write_all(swp.to_string().as_ref()).map_err(CgroupError::WriteError) }) diff --git a/src/net_cls.rs b/src/net_cls.rs index a96e41e..0f9ef38 100644 --- a/src/net_cls.rs +++ b/src/net_cls.rs @@ -21,12 +21,12 @@ pub struct NetClsController { } impl Controller for NetClsController { - fn control_type(self: &Self) -> Controllers { Controllers::NetCls } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::NetCls } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, res: &Resources) -> Result<(), CgroupError> { /* get the resources that apply to this controller */ let res: &NetworkResources = &res.network; @@ -80,7 +80,7 @@ impl NetClsController { } /// Set the network class id of the outgoing packets of the control group's tasks. - pub fn set_class(self: &Self, class: u64) -> Result<(), CgroupError> { + pub fn set_class(&self, class: u64) -> Result<(), CgroupError> { self.open_path("net_cls.classid", true).and_then(|mut file| { let s = format!("{:#08X}", class); file.write_all(s.as_ref()).map_err(CgroupError::WriteError) @@ -88,7 +88,7 @@ impl NetClsController { } /// Get the network class id of the outgoing packets of the control group's tasks. - pub fn get_class(self: &Self) -> Result { + pub fn get_class(&self) -> Result { self.open_path("net_cls.classid", false).and_then(|file| { read_u64_from(file) }) diff --git a/src/net_prio.rs b/src/net_prio.rs index 2fc1e21..9b16962 100644 --- a/src/net_prio.rs +++ b/src/net_prio.rs @@ -22,12 +22,12 @@ pub struct NetPrioController { } impl Controller for NetPrioController { - fn control_type(self: &Self) -> Controllers { Controllers::NetPrio } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::NetPrio } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, res: &Resources) -> Result<(), CgroupError> { /* get the resources that apply to this controller */ let res: &NetworkResources = &res.network; @@ -81,14 +81,14 @@ impl NetPrioController { } /// Retrieves the current priority of the emitted packets. - pub fn prio_idx(self: &Self) -> u64 { + pub fn prio_idx(&self) -> u64 { self.open_path("net_prio.prioidx", false) .and_then(read_u64_from) .unwrap_or(0) } /// A map of priorities for each network interface. - pub fn ifpriomap(self: &Self) -> Result, CgroupError> { + pub fn ifpriomap(&self) -> Result, CgroupError> { self.open_path("net_prio.ifpriomap", false) .and_then(|file| { let bf = BufReader::new(file); bf.lines().fold(Ok(HashMap::new()), |acc, line| { @@ -118,7 +118,7 @@ impl NetPrioController { } /// Set the priority of the network traffic on `eif` to be `prio`. - pub fn set_if_prio(self: &Self, eif: &String, prio: u64) -> Result<(), CgroupError> { + pub fn set_if_prio(&self, eif: &String, prio: u64) -> Result<(), CgroupError> { self.open_path("net_prio.ifpriomap", true).and_then(|mut file| { file.write_all(format!("{} {}", eif, prio).as_ref()).map_err(CgroupError::WriteError) }) diff --git a/src/perf_event.rs b/src/perf_event.rs index bf80729..78fe793 100644 --- a/src/perf_event.rs +++ b/src/perf_event.rs @@ -17,12 +17,12 @@ pub struct PerfEventController { } impl Controller for PerfEventController { - fn control_type(self: &Self) -> Controllers { Controllers::PerfEvent } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::PerfEvent } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, _res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, _res: &Resources) -> Result<(), CgroupError> { Ok(()) } } diff --git a/src/pid.rs b/src/pid.rs index 3b7c610..f535444 100644 --- a/src/pid.rs +++ b/src/pid.rs @@ -33,12 +33,12 @@ impl Default for PidMax { } impl Controller for PidController { - fn control_type(self: &Self) -> Controllers { Controllers::Pids } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::Pids } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, res: &Resources) -> Result<(), CgroupError> { /* get the resources that apply to this controller */ let pidres: &PidResources = &res.pid; @@ -105,7 +105,7 @@ impl PidController { } /// The number of times `fork` failed because the limit was hit. - pub fn get_pid_events(self: &Self) -> Result { + pub fn get_pid_events(&self) -> Result { self.open_path("pids.events", false).and_then(|mut file| { let mut string = String::new(); match file.read_to_string(&mut string) { @@ -124,12 +124,12 @@ impl PidController { } /// The number of processes currently. - pub fn get_pid_current(self: &Self) -> Result { + pub fn get_pid_current(&self) -> Result { self.open_path("pids.current", false).and_then(read_u64_from) } /// The maximum number of processes that can exist at one time in the control group. - pub fn get_pid_max(self: &Self) -> Result { + pub fn get_pid_max(&self) -> Result { self.open_path("pids.max", false).and_then(|mut file| { let mut string = String::new(); let res = file.read_to_string(&mut string); @@ -152,7 +152,7 @@ impl PidController { /// Note that if `get_pid_current()` returns a higher number than what you /// are about to set (`max_pid`), then no processess will be killed. Additonally, attaching /// extra processes to a control group disregards the limit. - pub fn set_pid_max(self: &Self, max_pid: PidMax) -> Result<(), CgroupError> { + pub fn set_pid_max(&self, max_pid: PidMax) -> Result<(), CgroupError> { self.open_path("pids.max", true).and_then(|mut file| { let string_to_write = match max_pid { PidMax::Max => "max".to_string(), diff --git a/src/rdma.rs b/src/rdma.rs index 74fde9a..b973818 100644 --- a/src/rdma.rs +++ b/src/rdma.rs @@ -19,12 +19,12 @@ pub struct RdmaController { } impl Controller for RdmaController { - fn control_type(self: &Self) -> Controllers { Controllers::Rdma } - fn get_path<'a>(self: &'a Self) -> &'a PathBuf { &self.path } - fn get_path_mut<'a>(self: &'a mut Self) -> &'a mut PathBuf { &mut self.path } - fn get_base<'a>(self: &'a Self) -> &'a PathBuf { &self.base } + fn control_type(&self) -> Controllers { Controllers::Rdma } + fn get_path(&self) -> &PathBuf { &self.path } + fn get_path_mut(&mut self) -> &mut PathBuf { &mut self.path } + fn get_base(&self) -> &PathBuf { &self.base } - fn apply(self: &Self, _res: &Resources) -> Result<(), CgroupError> { + fn apply(&self, _res: &Resources) -> Result<(), CgroupError> { Ok(()) } } @@ -69,13 +69,13 @@ impl RdmaController { } /// Returns the current usage of RDMA/IB specific resources. - pub fn current(self: &Self) -> Result { + pub fn current(&self) -> Result { self.open_path("rdma.current", false) .and_then(read_string_from) } /// Set a maximum usage for each RDMA/IB resource. - pub fn set_max(self: &Self, max: &String) -> Result<(), CgroupError> { + pub fn set_max(&self, max: &String) -> Result<(), CgroupError> { self.open_path("rdma.max", true).and_then(|mut file| { file.write_all(max.as_ref()).map_err(CgroupError::WriteError) })