use lazy unmount for namespaces

This commit is contained in:
Robin Appelman 2025-10-31 22:40:04 +01:00
commit 645a6e9978

View file

@ -6,7 +6,7 @@ use crate::daemon::namespace::raw::{
NamespaceSetupError, create_network_namespace,
};
use nix::errno::Errno;
use nix::mount::{MsFlags, mount, umount};
use nix::mount::{MsFlags, mount, umount2, MntFlags};
use std::fs::{File, create_dir_all, remove_file};
use std::io::{Error as IoError, ErrorKind};
use std::path::{Path, PathBuf};
@ -77,7 +77,7 @@ impl Drop for NetNs {
fn drop(&mut self) {
let name = self.path.file_name().unwrap().to_str().unwrap();
info!(name, "deleting network namespace");
if let Err(error) = umount(&self.path) {
if let Err(error) = umount2(&self.path, MntFlags::MNT_DETACH) {
error!(%error, path = %self.path.display(), "Failed to unmount network namespace");
}
if let Err(error) = remove_file(&self.path) {