Skip to content

Commit

Permalink
Merge pull request #2438 from YJDoc2/fix/duplicate-device-mounts
Browse files Browse the repository at this point in the history
Fix device duplication in rootfs preparation
  • Loading branch information
utam0k authored Oct 15, 2023
2 parents 93d6b11 + 54b1749 commit 1854870
Showing 1 changed file with 8 additions and 6 deletions.
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

0 comments on commit 1854870

Please sign in to comment.