Run rustfmt

This commit is contained in:
Hidehito Yabuuchi
2018-10-04 00:45:43 +09:00
committed by Levente Kurusa
parent 5660656e3a
commit 2149e1c0c4
21 changed files with 1208 additions and 737 deletions
+47 -33
View File
@@ -1,14 +1,17 @@
//! This module contains the implementation of the `net_prio` cgroup subsystem.
//!
//!
//! See the Kernel's documentation for more information about this subsystem, found at:
//! [Documentation/cgroup-v1/net_prio.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/net_prio.txt)
use std::path::PathBuf;
use std::io::{BufReader, BufRead, Write, Read};
use std::fs::File;
use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader, Read, Write};
use std::path::PathBuf;
use {CgroupError, NetworkResources, Controllers, Controller, Resources, ControllIdentifier, Subsystem};
use CgroupError::*;
use {
CgroupError, ControllIdentifier, Controller, Controllers, NetworkResources, Resources,
Subsystem,
};
/// A controller that allows controlling the `net_prio` subsystem of a Cgroup.
///
@@ -22,10 +25,18 @@ pub struct NetPrioController {
}
impl Controller for NetPrioController {
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 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, res: &Resources) -> Result<(), CgroupError> {
/* get the resources that apply to this controller */
@@ -55,7 +66,7 @@ impl<'a> From<&'a Subsystem> for &'a NetPrioController {
_ => {
assert_eq!(1, 0);
::std::mem::uninitialized()
},
}
}
}
}
@@ -89,38 +100,41 @@ impl NetPrioController {
/// A map of priorities for each network interface.
pub fn ifpriomap(&self) -> Result<HashMap<String, u64>, CgroupError> {
self.open_path("net_prio.ifpriomap", false) .and_then(|file| {
let bf = BufReader::new(file);
bf.lines().fold(Ok(HashMap::new()), |acc, line| {
if acc.is_err() {
acc
} else {
let mut acc = acc.unwrap();
let l = line.unwrap();
let mut sp = l.split_whitespace();
let ifname = sp.nth(0);
let ifprio = sp.nth(1);
if ifname.is_none() || ifprio.is_none() {
Err(CgroupError::ParseError)
self.open_path("net_prio.ifpriomap", false)
.and_then(|file| {
let bf = BufReader::new(file);
bf.lines().fold(Ok(HashMap::new()), |acc, line| {
if acc.is_err() {
acc
} else {
let ifname = ifname.unwrap();
let ifprio = ifprio.unwrap().trim().parse();
if ifprio.is_err() {
let mut acc = acc.unwrap();
let l = line.unwrap();
let mut sp = l.split_whitespace();
let ifname = sp.nth(0);
let ifprio = sp.nth(1);
if ifname.is_none() || ifprio.is_none() {
Err(CgroupError::ParseError)
} else {
acc.insert(ifname.to_string(), ifprio.unwrap());
Ok(acc)
let ifname = ifname.unwrap();
let ifprio = ifprio.unwrap().trim().parse();
if ifprio.is_err() {
Err(CgroupError::ParseError)
} else {
acc.insert(ifname.to_string(), ifprio.unwrap());
Ok(acc)
}
}
}
}
})
})
})
}
/// Set the priority of the network traffic on `eif` to be `prio`.
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)
})
self.open_path("net_prio.ifpriomap", true)
.and_then(|mut file| {
file.write_all(format!("{} {}", eif, prio).as_ref())
.map_err(CgroupError::WriteError)
})
}
}