rustjail: Allow container devices in subdirectories

Many device nodes go directly under /dev, however some are conventionally
placed in subdirectories under /dev.  For example /dev/vfio/vfio or
/dev/pts/ptmx.

Currently, attempting to pass such a device into a Kata container will fail
because mknod() will get an ENOENT because the parent directory is missing
(or an equivalent error for bind_dev()).

Correct that by making subdirectories as necessary in create_devices().

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2021-10-13 16:59:58 +11:00
parent 9891efc61f
commit 175f9b06e9

View File

@ -853,6 +853,9 @@ fn create_devices(devices: &[LinuxDevice], bind: bool) -> Result<()> {
let msg = format!("{} is not a valid device path", dev.path); let msg = format!("{} is not a valid device path", dev.path);
anyhow!(msg) anyhow!(msg)
})?; })?;
if let Some(dir) = path.parent() {
fs::create_dir_all(dir).context(format!("Creating container device {:?}", dev))?;
}
op(dev, path).context(format!("Creating container device {:?}", dev))?; op(dev, path).context(format!("Creating container device {:?}", dev))?;
} }
stat::umask(old); stat::umask(old);