Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix device duplication in rootfs preparation #2438

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions crates/libcontainer/src/rootfs/rootfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};
use nix::mount::MsFlags;
use oci_spec::runtime::{Linux, Spec};
use std::path::Path;
use std::{collections::HashSet, path::Path};

/// Holds information about rootfs
pub struct RootFS {
Expand Down Expand Up @@ -99,11 +99,13 @@ impl RootFS {

let devicer = Device::new();
if let Some(added_devices) = linux.devices() {
devicer.create_devices(
rootfs,
default_devices().iter().chain(added_devices),
bind_devices,
)
let mut path_set = HashSet::new();
let devices = default_devices();
added_devices.iter().for_each(|d| {
path_set.insert(d.path());
});
let default = devices.iter().filter(|d| !path_set.contains(d.path()));
devicer.create_devices(rootfs, added_devices.iter().chain(default), bind_devices)
} else {
devicer.create_devices(rootfs, &default_devices(), bind_devices)
}?;
Expand Down