mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-20 00:48:04 +00:00
Merge pull request #3532 from egernst/stable-backport-lints
stable-2.3: backport lint fixes from main
This commit is contained in:
commit
52dd41dacb
@ -35,17 +35,9 @@ use crate::log_child;
|
|||||||
// struct is populated from the content in the /proc/<pid>/mountinfo file.
|
// struct is populated from the content in the /proc/<pid>/mountinfo file.
|
||||||
#[derive(std::fmt::Debug)]
|
#[derive(std::fmt::Debug)]
|
||||||
pub struct Info {
|
pub struct Info {
|
||||||
id: i32,
|
|
||||||
parent: i32,
|
|
||||||
major: i32,
|
|
||||||
minor: i32,
|
|
||||||
root: String,
|
|
||||||
mount_point: String,
|
mount_point: String,
|
||||||
opts: String,
|
|
||||||
optional: String,
|
optional: String,
|
||||||
fstype: String,
|
fstype: String,
|
||||||
source: String,
|
|
||||||
vfs_opts: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const MOUNTINFOFORMAT: &str = "{d} {d} {d}:{d} {} {} {} {}";
|
const MOUNTINFOFORMAT: &str = "{d} {d} {d}:{d} {} {} {} {}";
|
||||||
@ -112,6 +104,7 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[cfg(not(test))]
|
||||||
pub fn mount<
|
pub fn mount<
|
||||||
P1: ?Sized + NixPath,
|
P1: ?Sized + NixPath,
|
||||||
P2: ?Sized + NixPath,
|
P2: ?Sized + NixPath,
|
||||||
@ -124,21 +117,42 @@ pub fn mount<
|
|||||||
flags: MsFlags,
|
flags: MsFlags,
|
||||||
data: Option<&P4>,
|
data: Option<&P4>,
|
||||||
) -> std::result::Result<(), nix::Error> {
|
) -> std::result::Result<(), nix::Error> {
|
||||||
#[cfg(not(test))]
|
mount::mount(source, target, fstype, flags, data)
|
||||||
return mount::mount(source, target, fstype, flags, data);
|
|
||||||
#[cfg(test)]
|
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn mount<
|
||||||
|
P1: ?Sized + NixPath,
|
||||||
|
P2: ?Sized + NixPath,
|
||||||
|
P3: ?Sized + NixPath,
|
||||||
|
P4: ?Sized + NixPath,
|
||||||
|
>(
|
||||||
|
_source: Option<&P1>,
|
||||||
|
_target: &P2,
|
||||||
|
_fstype: Option<&P3>,
|
||||||
|
_flags: MsFlags,
|
||||||
|
_data: Option<&P4>,
|
||||||
|
) -> std::result::Result<(), nix::Error> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
#[cfg(not(test))]
|
||||||
pub fn umount2<P: ?Sized + NixPath>(
|
pub fn umount2<P: ?Sized + NixPath>(
|
||||||
target: &P,
|
target: &P,
|
||||||
flags: MntFlags,
|
flags: MntFlags,
|
||||||
) -> std::result::Result<(), nix::Error> {
|
) -> std::result::Result<(), nix::Error> {
|
||||||
#[cfg(not(test))]
|
mount::umount2(target, flags)
|
||||||
return mount::umount2(target, flags);
|
}
|
||||||
#[cfg(test)]
|
|
||||||
return Ok(());
|
#[inline(always)]
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn umount2<P: ?Sized + NixPath>(
|
||||||
|
_target: &P,
|
||||||
|
_flags: MntFlags,
|
||||||
|
) -> std::result::Result<(), nix::Error> {
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_rootfs(
|
pub fn init_rootfs(
|
||||||
@ -450,14 +464,20 @@ fn mount_cgroups(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
fn pivot_root<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
|
fn pivot_root<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
|
||||||
new_root: &P1,
|
new_root: &P1,
|
||||||
put_old: &P2,
|
put_old: &P2,
|
||||||
) -> anyhow::Result<(), nix::Error> {
|
) -> anyhow::Result<(), nix::Error> {
|
||||||
#[cfg(not(test))]
|
unistd::pivot_root(new_root, put_old)
|
||||||
return unistd::pivot_root(new_root, put_old);
|
}
|
||||||
#[cfg(test)]
|
|
||||||
return Ok(());
|
#[cfg(test)]
|
||||||
|
fn pivot_root<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
|
||||||
|
_new_root: &P1,
|
||||||
|
_put_old: &P2,
|
||||||
|
) -> anyhow::Result<(), nix::Error> {
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pivot_rootfs<P: ?Sized + NixPath + std::fmt::Debug>(path: &P) -> Result<()> {
|
pub fn pivot_rootfs<P: ?Sized + NixPath + std::fmt::Debug>(path: &P) -> Result<()> {
|
||||||
@ -535,7 +555,20 @@ fn parse_mount_table() -> Result<Vec<Info>> {
|
|||||||
for (_index, line) in reader.lines().enumerate() {
|
for (_index, line) in reader.lines().enumerate() {
|
||||||
let line = line?;
|
let line = line?;
|
||||||
|
|
||||||
let (id, parent, major, minor, root, mount_point, opts, optional) = scan_fmt!(
|
//Example mountinfo format:
|
||||||
|
// id
|
||||||
|
// | / parent
|
||||||
|
// | | / major:minor
|
||||||
|
// | | | / root
|
||||||
|
// | | | | / mount_point
|
||||||
|
// | | | | | / opts
|
||||||
|
// | | | | | | / optional
|
||||||
|
// | | | | | | | / fstype
|
||||||
|
// | | | | | | | | / source
|
||||||
|
// | | | | | | | | | / vfs_opts
|
||||||
|
// 22 96 0:21 / /sys rw,nosuid,nodev,noexec,relatime shared:2 - sysfs sysfs rw,seclabel
|
||||||
|
|
||||||
|
let (_id, _parent, _major, _minor, _root, mount_point, _opts, optional) = scan_fmt!(
|
||||||
&line,
|
&line,
|
||||||
MOUNTINFOFORMAT,
|
MOUNTINFOFORMAT,
|
||||||
i32,
|
i32,
|
||||||
@ -550,7 +583,7 @@ fn parse_mount_table() -> Result<Vec<Info>> {
|
|||||||
|
|
||||||
let fields: Vec<&str> = line.split(" - ").collect();
|
let fields: Vec<&str> = line.split(" - ").collect();
|
||||||
if fields.len() == 2 {
|
if fields.len() == 2 {
|
||||||
let (fstype, source, vfs_opts) =
|
let (fstype, _source, _vfs_opts) =
|
||||||
scan_fmt!(fields[1], "{} {} {}", String, String, String)?;
|
scan_fmt!(fields[1], "{} {} {}", String, String, String)?;
|
||||||
|
|
||||||
let mut optional_new = String::new();
|
let mut optional_new = String::new();
|
||||||
@ -559,17 +592,9 @@ fn parse_mount_table() -> Result<Vec<Info>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let info = Info {
|
let info = Info {
|
||||||
id,
|
|
||||||
parent,
|
|
||||||
major,
|
|
||||||
minor,
|
|
||||||
root,
|
|
||||||
mount_point,
|
mount_point,
|
||||||
opts,
|
|
||||||
optional: optional_new,
|
optional: optional_new,
|
||||||
fstype,
|
fstype,
|
||||||
source,
|
|
||||||
vfs_opts,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
infos.push(info);
|
infos.push(info);
|
||||||
@ -582,11 +607,15 @@ fn parse_mount_table() -> Result<Vec<Info>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[cfg(not(test))]
|
||||||
fn chroot<P: ?Sized + NixPath>(path: &P) -> Result<(), nix::Error> {
|
fn chroot<P: ?Sized + NixPath>(path: &P) -> Result<(), nix::Error> {
|
||||||
#[cfg(not(test))]
|
unistd::chroot(path)
|
||||||
return unistd::chroot(path);
|
}
|
||||||
#[cfg(test)]
|
|
||||||
return Ok(());
|
#[inline(always)]
|
||||||
|
#[cfg(test)]
|
||||||
|
fn chroot<P: ?Sized + NixPath>(_path: &P) -> Result<(), nix::Error> {
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ms_move_root(rootfs: &str) -> Result<bool> {
|
pub fn ms_move_root(rootfs: &str) -> Result<bool> {
|
||||||
@ -1382,7 +1411,7 @@ mod tests {
|
|||||||
|
|
||||||
for (i, t) in tests.iter().enumerate() {
|
for (i, t) in tests.iter().enumerate() {
|
||||||
// Create a string containing details of the test
|
// Create a string containing details of the test
|
||||||
let msg = format!("test[{}]: {:?}", i, t);
|
let msg = format!("test[{}]: {:?}", i, t.name);
|
||||||
|
|
||||||
// if is_symlink, then should be prepare the softlink environment
|
// if is_symlink, then should be prepare the softlink environment
|
||||||
if t.symlink_path != "" {
|
if t.symlink_path != "" {
|
||||||
|
@ -5,30 +5,22 @@
|
|||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use nix::mount::{self, MsFlags};
|
use nix::mount::{self, MsFlags};
|
||||||
use protocols::types::{Interface, Route};
|
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
const KATA_GUEST_SANDBOX_DNS_FILE: &str = "/run/kata-containers/sandbox/resolv.conf";
|
const KATA_GUEST_SANDBOX_DNS_FILE: &str = "/run/kata-containers/sandbox/resolv.conf";
|
||||||
const GUEST_DNS_FILE: &str = "/etc/resolv.conf";
|
const GUEST_DNS_FILE: &str = "/etc/resolv.conf";
|
||||||
|
|
||||||
// Network fully describes a sandbox network with its interfaces, routes and dns
|
// Network describes a sandbox network, includings its dns
|
||||||
// related information.
|
// related information.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Network {
|
pub struct Network {
|
||||||
ifaces: HashMap<String, Interface>,
|
|
||||||
routes: Vec<Route>,
|
|
||||||
dns: Vec<String>,
|
dns: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Network {
|
impl Network {
|
||||||
pub fn new() -> Network {
|
pub fn new() -> Network {
|
||||||
Network {
|
Network { dns: Vec::new() }
|
||||||
ifaces: HashMap::new(),
|
|
||||||
routes: Vec::new(),
|
|
||||||
dns: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_dns(&mut self, dns: String) {
|
pub fn set_dns(&mut self, dns: String) {
|
||||||
|
@ -240,7 +240,6 @@ pub(crate) fn spawn_test_watcher(sandbox: Arc<Mutex<Sandbox>>, uev: Uevent) {
|
|||||||
if matcher.is_match(&uev) {
|
if matcher.is_match(&uev) {
|
||||||
let (_, sender) = watch.take().unwrap();
|
let (_, sender) = watch.take().unwrap();
|
||||||
let _ = sender.send(uev.clone());
|
let _ = sender.send(uev.clone());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -86,7 +86,6 @@ mod tests {
|
|||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
struct BufWriter {
|
struct BufWriter {
|
||||||
data: Arc<Mutex<Vec<u8>>>,
|
data: Arc<Mutex<Vec<u8>>>,
|
||||||
slow_write: bool,
|
|
||||||
write_delay: Duration,
|
write_delay: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +93,6 @@ mod tests {
|
|||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
BufWriter {
|
BufWriter {
|
||||||
data: Arc::new(Mutex::new(Vec::<u8>::new())),
|
data: Arc::new(Mutex::new(Vec::<u8>::new())),
|
||||||
slow_write: false,
|
|
||||||
write_delay: Duration::new(0, 0),
|
write_delay: Duration::new(0, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,45 +171,35 @@ mod tests {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct TestData {
|
struct TestData {
|
||||||
reader_value: String,
|
reader_value: String,
|
||||||
result: io::Result<u64>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let tests = &[
|
let tests = &[
|
||||||
TestData {
|
TestData {
|
||||||
reader_value: "".into(),
|
reader_value: "".into(),
|
||||||
result: Ok(0),
|
|
||||||
},
|
},
|
||||||
TestData {
|
TestData {
|
||||||
reader_value: "a".into(),
|
reader_value: "a".into(),
|
||||||
result: Ok(1),
|
|
||||||
},
|
},
|
||||||
TestData {
|
TestData {
|
||||||
reader_value: "foo".into(),
|
reader_value: "foo".into(),
|
||||||
result: Ok(3),
|
|
||||||
},
|
},
|
||||||
TestData {
|
TestData {
|
||||||
reader_value: "b".repeat(BUF_SIZE - 1),
|
reader_value: "b".repeat(BUF_SIZE - 1),
|
||||||
result: Ok((BUF_SIZE - 1) as u64),
|
|
||||||
},
|
},
|
||||||
TestData {
|
TestData {
|
||||||
reader_value: "c".repeat(BUF_SIZE),
|
reader_value: "c".repeat(BUF_SIZE),
|
||||||
result: Ok((BUF_SIZE) as u64),
|
|
||||||
},
|
},
|
||||||
TestData {
|
TestData {
|
||||||
reader_value: "d".repeat(BUF_SIZE + 1),
|
reader_value: "d".repeat(BUF_SIZE + 1),
|
||||||
result: Ok((BUF_SIZE + 1) as u64),
|
|
||||||
},
|
},
|
||||||
TestData {
|
TestData {
|
||||||
reader_value: "e".repeat((2 * BUF_SIZE) - 1),
|
reader_value: "e".repeat((2 * BUF_SIZE) - 1),
|
||||||
result: Ok(((2 * BUF_SIZE) - 1) as u64),
|
|
||||||
},
|
},
|
||||||
TestData {
|
TestData {
|
||||||
reader_value: "f".repeat(2 * BUF_SIZE),
|
reader_value: "f".repeat(2 * BUF_SIZE),
|
||||||
result: Ok((2 * BUF_SIZE) as u64),
|
|
||||||
},
|
},
|
||||||
TestData {
|
TestData {
|
||||||
reader_value: "g".repeat((2 * BUF_SIZE) + 1),
|
reader_value: "g".repeat((2 * BUF_SIZE) + 1),
|
||||||
result: Ok(((2 * BUF_SIZE) + 1) as u64),
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user