reload destination -> target and module fixes

This commit is contained in:
Robin Appelman 2025-10-31 22:40:04 +01:00
commit 5e5ee227fc
10 changed files with 69 additions and 42 deletions

View file

@ -11,7 +11,7 @@ use std::fs::{File, create_dir_all, remove_file};
use std::io::{Error as IoError, ErrorKind};
use std::path::{Path, PathBuf};
use thiserror::Error;
use tracing::{error, info};
use tracing::{debug, error, info};
pub struct NetNs {
name: NamespaceName,
@ -21,7 +21,6 @@ pub struct NetNs {
impl NetNs {
/// Create a new named network namespace that will be removed when dropped
pub fn new(name: NamespaceName) -> Result<Self, NamespaceError> {
info!(%name, "creating network namespace");
let parent = Path::new("/var/run/netns");
create_dir_all(parent).map_err(NamespaceError::Parent)?;
let path = parent.join(&name);
@ -29,6 +28,7 @@ impl NetNs {
match File::create_new(&path) {
Ok(_) => {}
Err(e) if e.kind() == ErrorKind::AlreadyExists => {
info!(%name, "using existing network namespace");
return Ok(NetNs {
name: name.clone(),
path,
@ -36,6 +36,7 @@ impl NetNs {
}
Err(e) => return Err(NamespaceError::from_create(path.clone(), e)),
}
info!(%name, "creating network namespace");
let ns = create_network_namespace(move |ns| {
bind_namespace(&ns, &path)?;
@ -52,6 +53,7 @@ impl NetNs {
}
fn bind_namespace(namespace: &Path, path: &Path) -> Result<(), NamespaceError> {
debug!(namespace = %namespace.display(), path = %path.display(), "mounting namespace");
mount(
Some(namespace.as_os_str()),
path.as_os_str(),