mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Replace &String with &str
This commit is contained in:
committed by
Levente Kurusa
parent
751dbc7244
commit
dd621eae4e
@@ -309,7 +309,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, cpus: &String) -> Result<()> {
|
||||
pub fn set_cpus(&self, cpus: &str) -> Result<()> {
|
||||
self.open_path("cpuset.cpus", true).and_then(|mut file| {
|
||||
file.write_all(cpus.as_ref())
|
||||
.map_err(|e| Error::with_cause(WriteFailed, e))
|
||||
@@ -319,7 +319,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, mems: &String) -> Result<()> {
|
||||
pub fn set_mems(&self, mems: &str) -> Result<()> {
|
||||
self.open_path("cpuset.mems", true).and_then(|mut file| {
|
||||
file.write_all(mems.as_ref())
|
||||
.map_err(|e| Error::with_cause(WriteFailed, e))
|
||||
|
||||
@@ -94,7 +94,7 @@ impl DevicePermissions {
|
||||
}
|
||||
|
||||
/// Checks whether the string is a valid descriptor of DevicePermissions.
|
||||
pub fn is_valid(s: &String) -> bool {
|
||||
pub fn is_valid(s: &str) -> bool {
|
||||
if s == "" {
|
||||
return false;
|
||||
}
|
||||
@@ -116,18 +116,18 @@ impl DevicePermissions {
|
||||
}
|
||||
|
||||
/// Convert a string into DevicePermissions.
|
||||
///
|
||||
/// NOTE: This function makes no effort in verifying the String.
|
||||
pub fn from_string(s: &String) -> Vec<DevicePermissions> {
|
||||
pub fn from_str(s: &str) -> Result<Vec<DevicePermissions>> {
|
||||
let mut v = Vec::new();
|
||||
if s == "" {
|
||||
return v;
|
||||
return Ok(v);
|
||||
}
|
||||
for e in s.chars() {
|
||||
v.push(DevicePermissions::from_char(e).unwrap());
|
||||
let perm = DevicePermissions::from_char(e)
|
||||
.ok_or_else(|| Error::new(ParseError))?;
|
||||
v.push(perm);
|
||||
}
|
||||
|
||||
v
|
||||
Ok(v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ impl DevicesController {
|
||||
acc, ls, devtype, major, minor, &ls[3]);
|
||||
Err(Error::new(ParseError))
|
||||
} else {
|
||||
let access = DevicePermissions::from_string(&ls[3]);
|
||||
let access = DevicePermissions::from_str(&ls[3])?;
|
||||
let mut acc = acc.unwrap();
|
||||
acc.push(DeviceResource {
|
||||
allow: true,
|
||||
|
||||
@@ -94,34 +94,34 @@ impl HugeTlbController {
|
||||
}
|
||||
|
||||
/// Whether the system supports `hugetlb_size` hugepages.
|
||||
pub fn size_supported(&self, _hugetlb_size: String) -> bool {
|
||||
pub fn size_supported(&self, _hugetlb_size: &str) -> bool {
|
||||
// TODO
|
||||
true
|
||||
}
|
||||
|
||||
/// Check how many times has the limit of `hugetlb_size` hugepages been hit.
|
||||
pub fn failcnt(&self, hugetlb_size: &String) -> Result<u64> {
|
||||
pub fn failcnt(&self, hugetlb_size: &str) -> Result<u64> {
|
||||
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, hugetlb_size: &String) -> Result<u64> {
|
||||
pub fn limit_in_bytes(&self, hugetlb_size: &str) -> Result<u64> {
|
||||
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, hugetlb_size: &String) -> Result<u64> {
|
||||
pub fn usage_in_bytes(&self, hugetlb_size: &str) -> Result<u64> {
|
||||
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, hugetlb_size: &String) -> Result<u64> {
|
||||
pub fn max_usage_in_bytes(&self, hugetlb_size: &str) -> Result<u64> {
|
||||
self.open_path(
|
||||
&format!("hugetlb.{}.max_usage_in_bytes", hugetlb_size),
|
||||
false,
|
||||
@@ -130,7 +130,7 @@ impl HugeTlbController {
|
||||
|
||||
/// 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, hugetlb_size: &String, limit: u64) -> Result<()> {
|
||||
pub fn set_limit_in_bytes(&self, hugetlb_size: &str, limit: u64) -> Result<()> {
|
||||
self.open_path(&format!("hugetlb.{}.limit_in_bytes", hugetlb_size), true)
|
||||
.and_then(|mut file| {
|
||||
file.write_all(limit.to_string().as_ref())
|
||||
|
||||
@@ -133,7 +133,7 @@ impl NetPrioController {
|
||||
}
|
||||
|
||||
/// Set the priority of the network traffic on `eif` to be `prio`.
|
||||
pub fn set_if_prio(&self, eif: &String, prio: u64) -> Result<()> {
|
||||
pub fn set_if_prio(&self, eif: &str, prio: u64) -> Result<()> {
|
||||
self.open_path("net_prio.ifpriomap", true)
|
||||
.and_then(|mut file| {
|
||||
file.write_all(format!("{} {}", eif, prio).as_ref())
|
||||
|
||||
@@ -86,7 +86,7 @@ impl RdmaController {
|
||||
}
|
||||
|
||||
/// Set a maximum usage for each RDMA/IB resource.
|
||||
pub fn set_max(&self, max: &String) -> Result<()> {
|
||||
pub fn set_max(&self, max: &str) -> Result<()> {
|
||||
self.open_path("rdma.max", true).and_then(|mut file| {
|
||||
file.write_all(max.as_ref())
|
||||
.map_err(|e| Error::with_cause(WriteFailed, e))
|
||||
|
||||
Reference in New Issue
Block a user