Transition to Rust 2018

Signed-off-by: Levente Kurusa <lkurusa@acm.org>
This commit is contained in:
Levente Kurusa
2018-12-23 16:31:05 +01:00
parent b5e0706d6a
commit 01a3c22829
18 changed files with 96 additions and 96 deletions

View File

@@ -6,10 +6,10 @@ use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {
use crate::{
BlkIoResources, ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem,
};
@@ -48,7 +48,7 @@ pub struct IoService {
/// How many items were synchronously transferred.
pub sync: u64,
/// How many items were asynchronously transferred.
pub async: u64,
pub r#async: u64,
/// Total number of items transferred.
pub total: u64,
}
@@ -77,7 +77,7 @@ fn parse_io_service(s: String) -> Result<Vec<IoService>> {
read: read_val.parse::<u64>().unwrap(),
write: write_val.parse::<u64>().unwrap(),
sync: sync_val.parse::<u64>().unwrap(),
async: async_val.parse::<u64>().unwrap(),
r#async: async_val.parse::<u64>().unwrap(),
total: total_val.parse::<u64>().unwrap(),
}),
_ => None,
@@ -695,9 +695,9 @@ impl BlkIoController {
#[cfg(test)]
mod test {
use blkio::{parse_blkio_data, BlkIoData};
use blkio::{parse_io_service, parse_io_service_total, IoService};
use error::*;
use crate::blkio::{parse_blkio_data, BlkIoData};
use crate::blkio::{parse_io_service, parse_io_service_total, IoService};
use crate::error::*;
static TEST_VALUE: &str = "\
8:32 Read 4280320
@@ -773,7 +773,7 @@ Total 61823067136
read: 4280320,
write: 0,
sync: 4280320,
async: 0,
r#async: 0,
total: 4280320,
},
IoService {
@@ -782,7 +782,7 @@ Total 61823067136
read: 5705479168,
write: 56096055296,
sync: 11213923328,
async: 50587611136,
r#async: 50587611136,
total: 61801534464,
},
IoService {
@@ -791,7 +791,7 @@ Total 61823067136
read: 10059776,
write: 0,
sync: 10059776,
async: 0,
r#async: 0,
total: 10059776,
},
IoService {
@@ -800,7 +800,7 @@ Total 61823067136
read: 7192576,
write: 0,
sync: 7192576,
async: 0,
r#async: 0,
total: 7192576,
}
]

View File

@@ -1,8 +1,8 @@
//! This module handles cgroup operations. Start here!
use error::*;
use crate::error::*;
use {CgroupPid, ControllIdentifier, Controller, Hierarchy, Resources, Subsystem};
use crate::{CgroupPid, ControllIdentifier, Controller, Hierarchy, Resources, Subsystem};
use std::convert::From;
use std::path::Path;

View File

@@ -53,9 +53,9 @@
//! .done()
//! .build();
//! ```
use error::*;
use crate::error::*;
use {pid, BlkIoDeviceResource, BlkIoDeviceThrottleResource, Cgroup, DeviceResource, Hierarchy, HugePageResource, NetworkPriority, Resources};
use crate::{pid, BlkIoDeviceResource, BlkIoDeviceThrottleResource, Cgroup, DeviceResource, Hierarchy, HugePageResource, NetworkPriority, Resources};
macro_rules! gen_setter {
($res:ident, $cont:ident, $func:ident, $name:ident, $ty:ty) => {
@@ -215,9 +215,9 @@ impl<'a> DeviceResourceBuilder<'a> {
pub fn device(mut self,
major: i64,
minor: i64,
devtype: ::devices::DeviceType,
devtype: crate::devices::DeviceType,
allow: bool,
access: Vec<::devices::DevicePermissions>)
access: Vec<crate::devices::DevicePermissions>)
-> DeviceResourceBuilder<'a> {
self.cgroup.resources.devices.update_values = true;
self.cgroup.resources.devices.devices.push(DeviceResource {

View File

@@ -7,10 +7,10 @@ use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {
use crate::{
ControllIdentifier, ControllerInternal, Controllers, CpuResources, Resources, Subsystem,
};

View File

@@ -6,10 +6,10 @@ use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
use crate::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
/// A controller that allows controlling the `cpuacct` subsystem of a Cgroup.
///

View File

@@ -6,10 +6,10 @@ use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {
use crate::{
ControllIdentifier, ControllerInternal, Controllers, CpuResources, Resources, Subsystem,
};
@@ -427,7 +427,7 @@ impl CpuSetController {
#[cfg(test)]
mod tests {
use cpuset;
use crate::cpuset;
#[test]
fn test_parse_range() {
let test_cases = vec![

View File

@@ -5,10 +5,10 @@
use std::io::{Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {
use crate::{
ControllIdentifier, ControllerInternal, Controllers, DeviceResource, DeviceResources,
Resources, Subsystem,
};

View File

@@ -5,10 +5,10 @@
use std::io::{Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
use crate::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
/// A controller that allows controlling the `freezer` subsystem of a Cgroup.
///

View File

@@ -8,22 +8,22 @@ use std::io::BufRead;
use std::io::BufReader;
use std::path::{Path, PathBuf};
use blkio::BlkIoController;
use cpu::CpuController;
use cpuacct::CpuAcctController;
use cpuset::CpuSetController;
use devices::DevicesController;
use freezer::FreezerController;
use hugetlb::HugeTlbController;
use memory::MemController;
use net_cls::NetClsController;
use net_prio::NetPrioController;
use perf_event::PerfEventController;
use pid::PidController;
use rdma::RdmaController;
use {Controllers, Hierarchy, Subsystem};
use crate::blkio::BlkIoController;
use crate::cpu::CpuController;
use crate::cpuacct::CpuAcctController;
use crate::cpuset::CpuSetController;
use crate::devices::DevicesController;
use crate::freezer::FreezerController;
use crate::hugetlb::HugeTlbController;
use crate::memory::MemController;
use crate::net_cls::NetClsController;
use crate::net_prio::NetPrioController;
use crate::perf_event::PerfEventController;
use crate::pid::PidController;
use crate::rdma::RdmaController;
use crate::{Controllers, Hierarchy, Subsystem};
use cgroup::Cgroup;
use crate::cgroup::Cgroup;
/// The standard, original cgroup implementation. Often referred to as "cgroupv1".
pub struct V1 {

View File

@@ -6,10 +6,10 @@ use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {
use crate::{
ControllIdentifier, ControllerInternal, Controllers, HugePageResources, Resources,
Subsystem,
};

View File

@@ -23,22 +23,22 @@ pub mod pid;
pub mod rdma;
pub mod cgroup_builder;
use blkio::BlkIoController;
use cpu::CpuController;
use cpuacct::CpuAcctController;
use cpuset::CpuSetController;
use devices::DevicesController;
use error::*;
use freezer::FreezerController;
use hugetlb::HugeTlbController;
use memory::MemController;
use net_cls::NetClsController;
use net_prio::NetPrioController;
use perf_event::PerfEventController;
use pid::PidController;
use rdma::RdmaController;
use crate::blkio::BlkIoController;
use crate::cpu::CpuController;
use crate::cpuacct::CpuAcctController;
use crate::cpuset::CpuSetController;
use crate::devices::DevicesController;
use crate::error::*;
use crate::freezer::FreezerController;
use crate::hugetlb::HugeTlbController;
use crate::memory::MemController;
use crate::net_cls::NetClsController;
use crate::net_prio::NetPrioController;
use crate::perf_event::PerfEventController;
use crate::pid::PidController;
use crate::rdma::RdmaController;
pub use cgroup::Cgroup;
pub use crate::cgroup::Cgroup;
/// Contains all the subsystems that are available in this crate.
#[derive(Debug)]
@@ -160,7 +160,7 @@ mod sealed {
}
}
pub(crate) use sealed::ControllerInternal;
pub(crate) use crate::sealed::ControllerInternal;
/// A Controller is a subsystem attached to the control group.
///
@@ -347,13 +347,13 @@ pub struct DeviceResource {
/// If true, access to the device is allowed, otherwise it's denied.
pub allow: bool,
/// `'c'` for character device, `'b'` for block device; or `'a'` for all devices.
pub devtype: ::devices::DeviceType,
pub devtype: crate::devices::DeviceType,
/// The major number of the device.
pub major: i64,
/// The minor number of the device.
pub minor: i64,
/// Sequence of `'r'`, `'w'` or `'m'`, each denoting read, write or mknod permissions.
pub access: Vec<::devices::DevicePermissions>,
pub access: Vec<crate::devices::DevicePermissions>,
}
/// Limit the usage of devices for the control group's tasks.

View File

@@ -6,10 +6,10 @@ use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {
use crate::{
ControllIdentifier, ControllerInternal, Controllers, MemoryResources, Resources, Subsystem,
};
@@ -85,7 +85,7 @@ pub struct NumaStat {
fn parse_numa_stat(s: String) -> Result<NumaStat> {
// Parse the number of nodes
let nodes = (s.split_whitespace().collect::<Vec<_>>().len() - 8) / 8;
let _nodes = (s.split_whitespace().collect::<Vec<_>>().len() - 8) / 8;
let mut ls = s.lines();
let total_line = ls.next().unwrap();
let file_line = ls.next().unwrap();
@@ -697,7 +697,7 @@ fn read_string_from(mut file: File) -> Result<String> {
#[cfg(test)]
mod tests {
use memory::{
use crate::memory::{
parse_memory_stat, parse_numa_stat, parse_oom_control, MemoryStat, NumaStat, OomControl,
};

View File

@@ -6,10 +6,10 @@ use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {
use crate::{
ControllIdentifier, ControllerInternal, Controllers, NetworkResources, Resources,
Subsystem,
};

View File

@@ -7,10 +7,10 @@ use std::fs::File;
use std::io::{BufRead, BufReader, Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {
use crate::{
ControllIdentifier, ControllerInternal, Controllers, NetworkResources, Resources,
Subsystem,
};

View File

@@ -4,9 +4,9 @@
//! [tools/perf/Documentation/perf-record.txt](https://raw.githubusercontent.com/torvalds/linux/master/tools/perf/Documentation/perf-record.txt)
use std::path::PathBuf;
use error::*;
use crate::error::*;
use {ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
use crate::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
/// A controller that allows controlling the `perf_event` subsystem of a Cgroup.
///

View File

@@ -6,10 +6,10 @@ use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {
use crate::{
ControllIdentifier, ControllerInternal, Controllers, PidResources, Resources, Subsystem,
};

View File

@@ -6,10 +6,10 @@ use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use error::*;
use error::ErrorKind::*;
use crate::error::*;
use crate::error::ErrorKind::*;
use {ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
use crate::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
/// A controller that allows controlling the `rdma` subsystem of a Cgroup.
///

View File

@@ -12,7 +12,7 @@ use cgroups::cgroup_builder::*;
#[test]
pub fn test_cpu_res_build() {
let v1 = ::hierarchies::V1::new();
let v1 = crate::hierarchies::V1::new();
let cg: Cgroup = CgroupBuilder::new("test_cpu_res_build", &v1)
.cpu()
.shares(85)
@@ -30,7 +30,7 @@ pub fn test_cpu_res_build() {
#[test]
pub fn test_memory_res_build() {
let v1 = ::hierarchies::V1::new();
let v1 = crate::hierarchies::V1::new();
let cg: Cgroup = CgroupBuilder::new("test_memory_res_build", &v1)
.memory()
.kernel_memory_limit(128 * 1024 * 1024)
@@ -51,7 +51,7 @@ pub fn test_memory_res_build() {
#[test]
pub fn test_pid_res_build() {
let v1 = ::hierarchies::V1::new();
let v1 = crate::hierarchies::V1::new();
let cg: Cgroup = CgroupBuilder::new("test_pid_res_build", &v1)
.pid()
.maximum_number_of_processes(PidMax::Value(123))
@@ -70,7 +70,7 @@ pub fn test_pid_res_build() {
#[test]
#[ignore] // ignore this test for now, not sure why my kernel doesn't like it
pub fn test_devices_res_build() {
let v1 = ::hierarchies::V1::new();
let v1 = crate::hierarchies::V1::new();
let cg: Cgroup = CgroupBuilder::new("test_devices_res_build", &v1)
.devices()
.device(1, 6, DeviceType::Char, true,
@@ -96,7 +96,7 @@ pub fn test_devices_res_build() {
#[test]
pub fn test_network_res_build() {
let v1 = ::hierarchies::V1::new();
let v1 = crate::hierarchies::V1::new();
let cg: Cgroup = CgroupBuilder::new("test_network_res_build", &v1)
.network()
.class_id(1337)
@@ -113,7 +113,7 @@ pub fn test_network_res_build() {
#[test]
pub fn test_hugepages_res_build() {
let v1 = ::hierarchies::V1::new();
let v1 = crate::hierarchies::V1::new();
let cg: Cgroup = CgroupBuilder::new("test_hugepages_res_build", &v1)
.hugepages()
.limit("2MB".to_string(), 4 * 2 * 1024 * 1024)
@@ -130,7 +130,7 @@ pub fn test_hugepages_res_build() {
#[test]
pub fn test_blkio_res_build() {
let v1 = ::hierarchies::V1::new();
let v1 = crate::hierarchies::V1::new();
let cg: Cgroup = CgroupBuilder::new("test_blkio_res_build", &v1)
.blkio()
.weight(100)