From edfe9ea403781256b8f9703c6819a97bfceb8e85 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Tue, 31 Mar 2026 14:48:31 +0800 Subject: [PATCH] runtime-rs: refine ShareFs abstraction with lifecycle and Nydus traits Refactor the `ShareFs` trait to improve modularity and support standalone Nydus mode: (1) Added `stop()` method to manage daemon teardown. (2) Introduced a dedicated trait for Nydus-specific data-plane operations. This refactoring cleans up the `ShareFs` trait by consolidating daemon lifecycle handling and isolating Nydus-specific extensions, paving the way for cleaner standalone Nydus implementation. Signed-off-by: Alex Lyn --- .../crates/resource/src/share_fs/mod.rs | 27 +++++++++++++++++++ .../share_fs/share_virtio_fs_standalone.rs | 6 +++++ 2 files changed, 33 insertions(+) diff --git a/src/runtime-rs/crates/resource/src/share_fs/mod.rs b/src/runtime-rs/crates/resource/src/share_fs/mod.rs index 84caf5c233..43995e51e3 100644 --- a/src/runtime-rs/crates/resource/src/share_fs/mod.rs +++ b/src/runtime-rs/crates/resource/src/share_fs/mod.rs @@ -69,6 +69,33 @@ pub trait ShareFs: Send + Sync { ) -> Result<()>; async fn get_storages(&self) -> Result>; fn mounted_info_set(&self) -> Arc>>; + + /// Stop the share fs daemon process (e.g., virtiofsd, nydusd). + /// Called during sandbox cleanup before cleaning up mounts. + /// Default implementation does nothing for inline modes that don't manage external daemons. + async fn stop(&self) -> Result<()> { + Ok(()) + } +} + +/// Trait for nydus-specific data-plane operations (standalone nydusd mode). +/// This trait is implemented by ShareVirtioFsNydus and provides operations +/// that are specific to the nydusd daemon's rafs mount capabilities. +#[async_trait] +pub trait NydusShareFs: Send + Sync { + /// Mount rafs with nydusd native overlay support. + /// Returns the mount point path within the nydusd namespace. + async fn mount_rafs( + &self, + cid: &str, + rafs_meta: &str, + config: &str, + overlay_config: &str, + ) -> Result; + + /// Umount rafs from nydusd. + /// Called during container cleanup. + async fn umount_rafs(&self, mountpoint: &str) -> Result<()>; } #[derive(Debug, Clone)] diff --git a/src/runtime-rs/crates/resource/src/share_fs/share_virtio_fs_standalone.rs b/src/runtime-rs/crates/resource/src/share_fs/share_virtio_fs_standalone.rs index 8e8cbd5b6d..abd95618ec 100644 --- a/src/runtime-rs/crates/resource/src/share_fs/share_virtio_fs_standalone.rs +++ b/src/runtime-rs/crates/resource/src/share_fs/share_virtio_fs_standalone.rs @@ -256,4 +256,10 @@ impl ShareFs for ShareVirtioFsStandalone { fn mounted_info_set(&self) -> Arc>> { self.mounted_info_set.clone() } + + async fn stop(&self) -> Result<()> { + self.shutdown_virtiofsd() + .await + .context("failed to stop virtiofsd daemon") + } }