From 8eb564dfb8fa8f5d0d6a17a6d78bf4294d2aa307 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Tue, 31 Mar 2026 11:57:11 +0800 Subject: [PATCH] kata-sys-util: handle ENOSYS gracefully in mount destination creation When using virtio-fs with nydusd's passthrough_fs, mkdir operations may return ENOSYS on certain filesystem configurations. This causes mount destination creation to fail unexpectedly. Handle ENOSYS errors gracefully alongside AlreadyExists by verifying the directory exists after the failed mkdir attempt, allowing the mount to proceed if the directory is already present. Signed-off-by: Alex Lyn --- src/libs/kata-sys-util/src/mount.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/libs/kata-sys-util/src/mount.rs b/src/libs/kata-sys-util/src/mount.rs index ce9f807fce..01e0ef284a 100644 --- a/src/libs/kata-sys-util/src/mount.rs +++ b/src/libs/kata-sys-util/src/mount.rs @@ -190,10 +190,20 @@ pub fn create_mount_destination, D: AsRef, R: AsRef>( .parent() .ok_or_else(|| Error::InvalidPath(dst.to_path_buf()))?; let mut builder = fs::DirBuilder::new(); - builder - .mode(MOUNT_DIR_PERM) - .recursive(true) - .create(parent)?; + builder.mode(MOUNT_DIR_PERM).recursive(true); + + // Try to create parent directory, but handle ENOSYS gracefully + // ENOSYS can occur on certain filesystems (e.g., virtio-fs) where mkdir is not fully supported + if let Err(e) = builder.create(parent) { + // If the error is ENOSYS or AlreadyExists, check if parent exists and continue + if e.kind() != std::io::ErrorKind::AlreadyExists && e.raw_os_error() != Some(libc::ENOSYS) { + return Err(e.into()); + } + // Verify parent exists + if !parent.exists() { + return Err(e.into()); + } + } if fs_type == "bind" { // The source and destination for bind mounting must be the same type: file or directory. @@ -207,11 +217,17 @@ pub fn create_mount_destination, D: AsRef, R: AsRef>( } } + // Try to create destination directory, but handle ENOSYS gracefully if let Err(e) = builder.create(dst) { - if e.kind() != std::io::ErrorKind::AlreadyExists { + if e.kind() != std::io::ErrorKind::AlreadyExists && e.raw_os_error() != Some(libc::ENOSYS) { return Err(e.into()); } + // If ENOSYS or AlreadyExists, check if dst exists and is a directory + if !dst.exists() || !dst.is_dir() { + return Err(Error::InvalidPath(dst.to_path_buf())); + } } + if !dst.is_dir() { Err(Error::InvalidPath(dst.to_path_buf())) } else {