mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-23 14:08:31 +00:00
agent: fix clippy for rustc 1.5
Fixes: #1461 Signed-off-by: Tim Zhang <tim@hyper.sh> Signed-off-by: Chelsea Mafrica <chelsea.e.mafrica@intel.com>
This commit is contained in:
parent
4f9b5fafcc
commit
2f67e831e3
@ -131,21 +131,21 @@ impl CgroupManager for Manager {
|
|||||||
|
|
||||||
// set block_io resources
|
// set block_io resources
|
||||||
if let Some(blkio) = &r.block_io {
|
if let Some(blkio) = &r.block_io {
|
||||||
set_block_io_resources(&cg, blkio, res)?;
|
set_block_io_resources(&cg, blkio, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set hugepages resources
|
// set hugepages resources
|
||||||
if !r.hugepage_limits.is_empty() {
|
if !r.hugepage_limits.is_empty() {
|
||||||
set_hugepages_resources(&cg, &r.hugepage_limits, res)?;
|
set_hugepages_resources(&cg, &r.hugepage_limits, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set network resources
|
// set network resources
|
||||||
if let Some(network) = &r.network {
|
if let Some(network) = &r.network {
|
||||||
set_network_resources(&cg, network, res)?;
|
set_network_resources(&cg, network, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set devices resources
|
// set devices resources
|
||||||
set_devices_resources(&cg, &r.devices, res)?;
|
set_devices_resources(&cg, &r.devices, res);
|
||||||
info!(sl!(), "resources after processed {:?}", res);
|
info!(sl!(), "resources after processed {:?}", res);
|
||||||
|
|
||||||
// apply resources
|
// apply resources
|
||||||
@ -241,7 +241,7 @@ fn set_network_resources(
|
|||||||
_cg: &cgroups::Cgroup,
|
_cg: &cgroups::Cgroup,
|
||||||
network: &LinuxNetwork,
|
network: &LinuxNetwork,
|
||||||
res: &mut cgroups::Resources,
|
res: &mut cgroups::Resources,
|
||||||
) -> Result<()> {
|
) {
|
||||||
info!(sl!(), "cgroup manager set network");
|
info!(sl!(), "cgroup manager set network");
|
||||||
|
|
||||||
// set classid
|
// set classid
|
||||||
@ -263,14 +263,13 @@ fn set_network_resources(
|
|||||||
|
|
||||||
res.network.update_values = true;
|
res.network.update_values = true;
|
||||||
res.network.priorities = priorities;
|
res.network.priorities = priorities;
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_devices_resources(
|
fn set_devices_resources(
|
||||||
_cg: &cgroups::Cgroup,
|
_cg: &cgroups::Cgroup,
|
||||||
device_resources: &[LinuxDeviceCgroup],
|
device_resources: &[LinuxDeviceCgroup],
|
||||||
res: &mut cgroups::Resources,
|
res: &mut cgroups::Resources,
|
||||||
) -> Result<()> {
|
) {
|
||||||
info!(sl!(), "cgroup manager set devices");
|
info!(sl!(), "cgroup manager set devices");
|
||||||
let mut devices = vec![];
|
let mut devices = vec![];
|
||||||
|
|
||||||
@ -294,15 +293,13 @@ fn set_devices_resources(
|
|||||||
|
|
||||||
res.devices.update_values = true;
|
res.devices.update_values = true;
|
||||||
res.devices.devices = devices;
|
res.devices.devices = devices;
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_hugepages_resources(
|
fn set_hugepages_resources(
|
||||||
_cg: &cgroups::Cgroup,
|
_cg: &cgroups::Cgroup,
|
||||||
hugepage_limits: &[LinuxHugepageLimit],
|
hugepage_limits: &[LinuxHugepageLimit],
|
||||||
res: &mut cgroups::Resources,
|
res: &mut cgroups::Resources,
|
||||||
) -> Result<()> {
|
) {
|
||||||
info!(sl!(), "cgroup manager set hugepage");
|
info!(sl!(), "cgroup manager set hugepage");
|
||||||
res.hugepages.update_values = true;
|
res.hugepages.update_values = true;
|
||||||
let mut limits = vec![];
|
let mut limits = vec![];
|
||||||
@ -315,15 +312,13 @@ fn set_hugepages_resources(
|
|||||||
limits.push(hr);
|
limits.push(hr);
|
||||||
}
|
}
|
||||||
res.hugepages.limits = limits;
|
res.hugepages.limits = limits;
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_block_io_resources(
|
fn set_block_io_resources(
|
||||||
_cg: &cgroups::Cgroup,
|
_cg: &cgroups::Cgroup,
|
||||||
blkio: &LinuxBlockIO,
|
blkio: &LinuxBlockIO,
|
||||||
res: &mut cgroups::Resources,
|
res: &mut cgroups::Resources,
|
||||||
) -> Result<()> {
|
) {
|
||||||
info!(sl!(), "cgroup manager set block io");
|
info!(sl!(), "cgroup manager set block io");
|
||||||
res.blkio.update_values = true;
|
res.blkio.update_values = true;
|
||||||
|
|
||||||
@ -350,8 +345,6 @@ fn set_block_io_resources(
|
|||||||
build_blk_io_device_throttle_resource(&blkio.throttle_read_iops_device);
|
build_blk_io_device_throttle_resource(&blkio.throttle_read_iops_device);
|
||||||
res.blkio.throttle_write_iops_device =
|
res.blkio.throttle_write_iops_device =
|
||||||
build_blk_io_device_throttle_resource(&blkio.throttle_write_iops_device);
|
build_blk_io_device_throttle_resource(&blkio.throttle_write_iops_device);
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_cpu_resources(cg: &cgroups::Cgroup, cpu: &LinuxCPU) -> Result<()> {
|
fn set_cpu_resources(cg: &cgroups::Cgroup, cpu: &LinuxCPU) -> Result<()> {
|
||||||
@ -417,7 +410,7 @@ fn set_memory_resources(cg: &cgroups::Cgroup, memory: &LinuxMemory, update: bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(swappiness) = memory.swappiness {
|
if let Some(swappiness) = memory.swappiness {
|
||||||
if swappiness >= 0 && swappiness <= 100 {
|
if (0..=100).contains(&swappiness) {
|
||||||
mem_controller.set_swappiness(swappiness as u64)?;
|
mem_controller.set_swappiness(swappiness as u64)?;
|
||||||
} else {
|
} else {
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
@ -1008,7 +1001,7 @@ impl Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_cpuset_path(&self, guest_cpuset: &str, container_cpuset: &str) -> Result<()> {
|
pub fn update_cpuset_path(&self, guest_cpuset: &str, container_cpuset: &str) -> Result<()> {
|
||||||
if guest_cpuset == "" {
|
if guest_cpuset.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
info!(sl!(), "update_cpuset_path to: {}", guest_cpuset);
|
info!(sl!(), "update_cpuset_path to: {}", guest_cpuset);
|
||||||
|
@ -130,7 +130,7 @@ fn register_memory_event_v2(
|
|||||||
// notify_on_oom returns channel on which you can expect event about OOM,
|
// notify_on_oom returns channel on which you can expect event about OOM,
|
||||||
// if process died without OOM this channel will be closed.
|
// if process died without OOM this channel will be closed.
|
||||||
fn notify_on_oom(cid: &str, dir: String) -> Result<Receiver<String>> {
|
fn notify_on_oom(cid: &str, dir: String) -> Result<Receiver<String>> {
|
||||||
if dir == "" {
|
if dir.is_empty() {
|
||||||
return Err(anyhow!("memory controller missing"));
|
return Err(anyhow!("memory controller missing"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ fn notify_on_oom(cid: &str, dir: String) -> Result<Receiver<String>> {
|
|||||||
|
|
||||||
// level is one of "low", "medium", or "critical"
|
// level is one of "low", "medium", or "critical"
|
||||||
fn notify_memory_pressure(cid: &str, dir: String, level: &str) -> Result<Receiver<String>> {
|
fn notify_memory_pressure(cid: &str, dir: String, level: &str) -> Result<Receiver<String>> {
|
||||||
if dir == "" {
|
if dir.is_empty() {
|
||||||
return Err(anyhow!("memory controller missing"));
|
return Err(anyhow!("memory controller missing"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ fn register_memory_event(
|
|||||||
|
|
||||||
let event_control_path = Path::new(&cg_dir).join("cgroup.event_control");
|
let event_control_path = Path::new(&cg_dir).join("cgroup.event_control");
|
||||||
let data;
|
let data;
|
||||||
if arg == "" {
|
if arg.is_empty() {
|
||||||
data = format!("{} {}", eventfd, event_file.as_raw_fd());
|
data = format!("{} {}", eventfd, event_file.as_raw_fd());
|
||||||
} else {
|
} else {
|
||||||
data = format!("{} {} {}", eventfd, event_file.as_raw_fd(), arg);
|
data = format!("{} {} {}", eventfd, event_file.as_raw_fd(), arg);
|
||||||
|
@ -1036,7 +1036,7 @@ fn update_namespaces(logger: &Logger, spec: &mut Spec, init_pid: RawFd) -> Resul
|
|||||||
TYPETONAME.get(namespace.r#type.as_str()).unwrap()
|
TYPETONAME.get(namespace.r#type.as_str()).unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
if namespace.path == "" {
|
if namespace.path.is_empty() {
|
||||||
namespace.path = ns_path;
|
namespace.path = ns_path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1048,7 +1048,7 @@ fn update_namespaces(logger: &Logger, spec: &mut Spec, init_pid: RawFd) -> Resul
|
|||||||
fn get_pid_namespace(logger: &Logger, linux: &Linux) -> Result<Option<RawFd>> {
|
fn get_pid_namespace(logger: &Logger, linux: &Linux) -> Result<Option<RawFd>> {
|
||||||
for ns in &linux.namespaces {
|
for ns in &linux.namespaces {
|
||||||
if ns.r#type == "pid" {
|
if ns.r#type == "pid" {
|
||||||
if ns.path == "" {
|
if ns.path.is_empty() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1076,7 +1076,7 @@ fn is_userns_enabled(linux: &Linux) -> bool {
|
|||||||
linux
|
linux
|
||||||
.namespaces
|
.namespaces
|
||||||
.iter()
|
.iter()
|
||||||
.any(|ns| ns.r#type == "user" && ns.path == "")
|
.any(|ns| ns.r#type == "user" && ns.path.is_empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_namespaces(linux: &Linux) -> Vec<LinuxNamespace> {
|
fn get_namespaces(linux: &Linux) -> Vec<LinuxNamespace> {
|
||||||
|
@ -70,12 +70,8 @@ fn rootfs(root: &str) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn network(_oci: &Spec) -> Result<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hostname(oci: &Spec) -> Result<()> {
|
fn hostname(oci: &Spec) -> Result<()> {
|
||||||
if oci.hostname.is_empty() || oci.hostname == "" {
|
if oci.hostname.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +308,6 @@ pub fn validate(conf: &Config) -> Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
rootfs(root).context("rootfs")?;
|
rootfs(root).context("rootfs")?;
|
||||||
network(oci).context("network")?;
|
|
||||||
hostname(oci).context("hostname")?;
|
hostname(oci).context("hostname")?;
|
||||||
security(oci).context("security")?;
|
security(oci).context("security")?;
|
||||||
usernamespace(oci).context("usernamespace")?;
|
usernamespace(oci).context("usernamespace")?;
|
||||||
|
@ -204,7 +204,7 @@ fn update_spec_device_list(device: &Device, spec: &mut Spec, devidx: &DevIndex)
|
|||||||
|
|
||||||
// If no container_path is provided, we won't be able to match and
|
// If no container_path is provided, we won't be able to match and
|
||||||
// update the device in the OCI spec device list. This is an error.
|
// update the device in the OCI spec device list. This is an error.
|
||||||
if device.container_path == "" {
|
if device.container_path.is_empty() {
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
"container_path cannot empty for device {:?}",
|
"container_path cannot empty for device {:?}",
|
||||||
device
|
device
|
||||||
@ -280,7 +280,7 @@ fn virtiommio_blk_device_handler(
|
|||||||
_sandbox: &Arc<Mutex<Sandbox>>,
|
_sandbox: &Arc<Mutex<Sandbox>>,
|
||||||
devidx: &DevIndex,
|
devidx: &DevIndex,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if device.vm_path == "" {
|
if device.vm_path.is_empty() {
|
||||||
return Err(anyhow!("Invalid path for virtio mmio blk device"));
|
return Err(anyhow!("Invalid path for virtio mmio blk device"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +300,7 @@ fn virtio_blk_device_handler(
|
|||||||
|
|
||||||
// When "Id (PCIAddr)" is not set, we allow to use the predicted "VmPath" passed from kata-runtime
|
// When "Id (PCIAddr)" is not set, we allow to use the predicted "VmPath" passed from kata-runtime
|
||||||
// Note this is a special code path for cloud-hypervisor when BDF information is not available
|
// Note this is a special code path for cloud-hypervisor when BDF information is not available
|
||||||
if device.id != "" {
|
if !device.id.is_empty() {
|
||||||
dev.vm_path = get_pci_device_name(sandbox, &device.id)?;
|
dev.vm_path = get_pci_device_name(sandbox, &device.id)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,7 +325,7 @@ fn virtio_nvdimm_device_handler(
|
|||||||
_sandbox: &Arc<Mutex<Sandbox>>,
|
_sandbox: &Arc<Mutex<Sandbox>>,
|
||||||
devidx: &DevIndex,
|
devidx: &DevIndex,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if device.vm_path == "" {
|
if device.vm_path.is_empty() {
|
||||||
return Err(anyhow!("Invalid path for nvdimm device"));
|
return Err(anyhow!("Invalid path for nvdimm device"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,15 +381,15 @@ fn add_device(
|
|||||||
info!(sl!(), "device-id: {}, device-type: {}, device-vm-path: {}, device-container-path: {}, device-options: {:?}",
|
info!(sl!(), "device-id: {}, device-type: {}, device-vm-path: {}, device-container-path: {}, device-options: {:?}",
|
||||||
device.id, device.field_type, device.vm_path, device.container_path, device.options);
|
device.id, device.field_type, device.vm_path, device.container_path, device.options);
|
||||||
|
|
||||||
if device.field_type == "" {
|
if device.field_type.is_empty() {
|
||||||
return Err(anyhow!("invalid type for device {:?}", device));
|
return Err(anyhow!("invalid type for device {:?}", device));
|
||||||
}
|
}
|
||||||
|
|
||||||
if device.id == "" && device.vm_path == "" {
|
if device.id.is_empty() && device.vm_path.is_empty() {
|
||||||
return Err(anyhow!("invalid ID and VM path for device {:?}", device));
|
return Err(anyhow!("invalid ID and VM path for device {:?}", device));
|
||||||
}
|
}
|
||||||
|
|
||||||
if device.container_path == "" {
|
if device.container_path.is_empty() {
|
||||||
return Err(anyhow!("invalid container path for device {:?}", device));
|
return Err(anyhow!("invalid container path for device {:?}", device));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,9 +436,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_update_device_cgroup() {
|
fn test_update_device_cgroup() {
|
||||||
let mut spec = Spec::default();
|
let mut spec = Spec {
|
||||||
|
linux: Some(Linux::default()),
|
||||||
spec.linux = Some(Linux::default());
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
update_device_cgroup(&mut spec).unwrap();
|
update_device_cgroup(&mut spec).unwrap();
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ use std::collections::HashMap;
|
|||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::iter::FromIterator;
|
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@ -380,7 +379,7 @@ fn mount_storage(logger: &Logger, storage: &Storage) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let options_vec = storage.options.to_vec();
|
let options_vec = storage.options.to_vec();
|
||||||
let options_vec = Vec::from_iter(options_vec.iter().map(String::as_str));
|
let options_vec = options_vec.iter().map(String::as_str).collect();
|
||||||
let (flags, options) = parse_mount_flags_and_options(options_vec);
|
let (flags, options) = parse_mount_flags_and_options(options_vec);
|
||||||
|
|
||||||
info!(logger, "mounting storage";
|
info!(logger, "mounting storage";
|
||||||
@ -506,7 +505,7 @@ pub fn get_mount_fs_type(mount_point: &str) -> Result<String> {
|
|||||||
// get_mount_fs_type_from_file returns the FS type corresponding to the passed mount point and
|
// get_mount_fs_type_from_file returns the FS type corresponding to the passed mount point and
|
||||||
// any error ecountered.
|
// any error ecountered.
|
||||||
pub fn get_mount_fs_type_from_file(mount_file: &str, mount_point: &str) -> Result<String> {
|
pub fn get_mount_fs_type_from_file(mount_file: &str, mount_point: &str) -> Result<String> {
|
||||||
if mount_point == "" {
|
if mount_point.is_empty() {
|
||||||
return Err(anyhow!("Invalid mount point {}", mount_point));
|
return Err(anyhow!("Invalid mount point {}", mount_point));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,7 +590,7 @@ pub fn get_cgroup_mounts(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if fields[0] == "" {
|
if fields[0].is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -798,7 +797,7 @@ mod tests {
|
|||||||
let src_filename: String;
|
let src_filename: String;
|
||||||
let dest_filename: String;
|
let dest_filename: String;
|
||||||
|
|
||||||
if d.src != "" {
|
if !d.src.is_empty() {
|
||||||
src = dir.path().join(d.src.to_string());
|
src = dir.path().join(d.src.to_string());
|
||||||
src_filename = src
|
src_filename = src
|
||||||
.to_str()
|
.to_str()
|
||||||
@ -808,7 +807,7 @@ mod tests {
|
|||||||
src_filename = "".to_owned();
|
src_filename = "".to_owned();
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.dest != "" {
|
if !d.dest.is_empty() {
|
||||||
dest = dir.path().join(d.dest.to_string());
|
dest = dir.path().join(d.dest.to_string());
|
||||||
dest_filename = dest
|
dest_filename = dest
|
||||||
.to_str()
|
.to_str()
|
||||||
@ -820,7 +819,7 @@ mod tests {
|
|||||||
|
|
||||||
// Create the mount directories
|
// Create the mount directories
|
||||||
for d in [src_filename.clone(), dest_filename.clone()].iter() {
|
for d in [src_filename.clone(), dest_filename.clone()].iter() {
|
||||||
if d == "" {
|
if d.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -840,7 +839,7 @@ mod tests {
|
|||||||
|
|
||||||
let msg = format!("{}: result: {:?}", msg, result);
|
let msg = format!("{}: result: {:?}", msg, result);
|
||||||
|
|
||||||
if d.error_contains == "" {
|
if d.error_contains.is_empty() {
|
||||||
assert!(result.is_ok(), msg);
|
assert!(result.is_ok(), msg);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
@ -958,7 +957,7 @@ mod tests {
|
|||||||
|
|
||||||
let msg = format!("{}: result: {:?}", msg, result);
|
let msg = format!("{}: result: {:?}", msg, result);
|
||||||
|
|
||||||
if d.error_contains == "" {
|
if d.error_contains.is_empty() {
|
||||||
assert!(result.is_ok(), msg);
|
assert!(result.is_ok(), msg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1066,7 +1065,7 @@ mod tests {
|
|||||||
// add more details if an assertion fails
|
// add more details if an assertion fails
|
||||||
let msg = format!("{}: result: {:?}", msg, result);
|
let msg = format!("{}: result: {:?}", msg, result);
|
||||||
|
|
||||||
if d.error_contains == "" {
|
if d.error_contains.is_empty() {
|
||||||
let fs_type = result.unwrap();
|
let fs_type = result.unwrap();
|
||||||
|
|
||||||
assert!(d.fs_type == fs_type, msg);
|
assert!(d.fs_type == fs_type, msg);
|
||||||
@ -1223,7 +1222,7 @@ mod tests {
|
|||||||
let result = get_cgroup_mounts(&logger, filename, false);
|
let result = get_cgroup_mounts(&logger, filename, false);
|
||||||
let msg = format!("{}: result: {:?}", msg, result);
|
let msg = format!("{}: result: {:?}", msg, result);
|
||||||
|
|
||||||
if d.error_contains != "" {
|
if !d.error_contains.is_empty() {
|
||||||
assert!(result.is_err(), msg);
|
assert!(result.is_err(), msg);
|
||||||
|
|
||||||
let error_msg = format!("{}", result.unwrap_err());
|
let error_msg = format!("{}", result.unwrap_err());
|
||||||
|
@ -58,7 +58,7 @@ impl Namespace {
|
|||||||
|
|
||||||
pub fn get_uts(mut self, hostname: &str) -> Self {
|
pub fn get_uts(mut self, hostname: &str) -> Self {
|
||||||
self.ns_type = NamespaceType::UTS;
|
self.ns_type = NamespaceType::UTS;
|
||||||
if hostname != "" {
|
if !hostname.is_empty() {
|
||||||
self.hostname = Some(String::from(hostname));
|
self.hostname = Some(String::from(hostname));
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
|
@ -513,7 +513,7 @@ impl Handle {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|to| to.address.as_str()) // Extract address field
|
.map(|to| to.address.as_str()) // Extract address field
|
||||||
.and_then(|addr| if addr.is_empty() { None } else { Some(addr) }) // Make sure it's not empty
|
.and_then(|addr| if addr.is_empty() { None } else { Some(addr) }) // Make sure it's not empty
|
||||||
.ok_or_else(|| nix::Error::Sys(nix::errno::Errno::EINVAL))?;
|
.ok_or(nix::Error::Sys(nix::errno::Errno::EINVAL))?;
|
||||||
|
|
||||||
let ip = IpAddr::from_str(&ip_address)
|
let ip = IpAddr::from_str(&ip_address)
|
||||||
.map_err(|e| anyhow!("Failed to parse IP {}: {:?}", ip_address, e))?;
|
.map_err(|e| anyhow!("Failed to parse IP {}: {:?}", ip_address, e))?;
|
||||||
@ -611,7 +611,7 @@ fn parse_mac_address(addr: &str) -> Result<[u8; 6]> {
|
|||||||
let v = u8::from_str_radix(
|
let v = u8::from_str_radix(
|
||||||
split
|
split
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| nix::Error::Sys(nix::errno::Errno::EINVAL))?,
|
.ok_or(nix::Error::Sys(nix::errno::Errno::EINVAL))?,
|
||||||
16,
|
16,
|
||||||
)?;
|
)?;
|
||||||
Ok(v)
|
Ok(v)
|
||||||
|
@ -310,7 +310,7 @@ impl agentService {
|
|||||||
"exec-id" => eid.clone(),
|
"exec-id" => eid.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if eid == "" {
|
if eid.is_empty() {
|
||||||
init = true;
|
init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1419,7 +1419,7 @@ fn find_process<'a>(
|
|||||||
.get_container(cid)
|
.get_container(cid)
|
||||||
.ok_or_else(|| anyhow!("Invalid container id"))?;
|
.ok_or_else(|| anyhow!("Invalid container id"))?;
|
||||||
|
|
||||||
if init || eid == "" {
|
if init || eid.is_empty() {
|
||||||
return ctr
|
return ctr
|
||||||
.processes
|
.processes
|
||||||
.get_mut(&ctr.init_process_pid)
|
.get_mut(&ctr.init_process_pid)
|
||||||
@ -1487,8 +1487,10 @@ fn update_container_namespaces(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// update pid namespace
|
// update pid namespace
|
||||||
let mut pid_ns = LinuxNamespace::default();
|
let mut pid_ns = LinuxNamespace {
|
||||||
pid_ns.r#type = NSTYPEPID.to_string();
|
r#type: NSTYPEPID.to_string(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
// Use shared pid ns if useSandboxPidns has been set in either
|
// Use shared pid ns if useSandboxPidns has been set in either
|
||||||
// the create_sandbox request or create_container request.
|
// the create_sandbox request or create_container request.
|
||||||
@ -1688,7 +1690,7 @@ fn setup_bundle(cid: &str, spec: &mut Spec) -> Result<PathBuf> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn load_kernel_module(module: &protocols::agent::KernelModule) -> Result<()> {
|
fn load_kernel_module(module: &protocols::agent::KernelModule) -> Result<()> {
|
||||||
if module.name == "" {
|
if module.name.is_empty() {
|
||||||
return Err(anyhow!("Kernel module name is empty"));
|
return Err(anyhow!("Kernel module name is empty"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1753,10 +1755,12 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_load_kernel_module() {
|
fn test_load_kernel_module() {
|
||||||
let mut m = protocols::agent::KernelModule::default();
|
let mut m = protocols::agent::KernelModule {
|
||||||
|
name: "module_not_exists".to_string(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
// case 1: module not exists
|
// case 1: module not exists
|
||||||
m.name = "module_not_exists".to_string();
|
|
||||||
let result = load_kernel_module(&m);
|
let result = load_kernel_module(&m);
|
||||||
assert!(result.is_err(), "load module should failed");
|
assert!(result.is_err(), "load module should failed");
|
||||||
|
|
||||||
|
@ -624,13 +624,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_dummy_opts() -> CreateOpts {
|
fn create_dummy_opts() -> CreateOpts {
|
||||||
let mut root = Root::default();
|
let root = Root {
|
||||||
root.path = String::from("/");
|
path: String::from("/"),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
let linux = Linux::default();
|
let spec = Spec {
|
||||||
let mut spec = Spec::default();
|
linux: Some(Linux::default()),
|
||||||
spec.root = Some(root);
|
root: Some(root),
|
||||||
spec.linux = Some(linux);
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
CreateOpts {
|
CreateOpts {
|
||||||
cgroup_name: "".to_string(),
|
cgroup_name: "".to_string(),
|
||||||
|
@ -51,7 +51,7 @@ impl Uevent {
|
|||||||
self.action == U_EVENT_ACTION_ADD
|
self.action == U_EVENT_ACTION_ADD
|
||||||
&& self.subsystem == "block"
|
&& self.subsystem == "block"
|
||||||
&& self.devpath.starts_with(PCI_ROOT_BUS_PATH)
|
&& self.devpath.starts_with(PCI_ROOT_BUS_PATH)
|
||||||
&& self.devname != ""
|
&& !self.devname.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_block_add_event(&self, sandbox: &Arc<Mutex<Sandbox>>) {
|
fn handle_block_add_event(&self, sandbox: &Arc<Mutex<Sandbox>>) {
|
||||||
|
Loading…
Reference in New Issue
Block a user