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 <alex.lyn@antgroup.com>
This commit is contained in:
Alex Lyn
2026-03-31 14:48:31 +08:00
committed by Fabiano Fidêncio
parent 720a8688b4
commit edfe9ea403
2 changed files with 33 additions and 0 deletions

View File

@@ -69,6 +69,33 @@ pub trait ShareFs: Send + Sync {
) -> Result<()>;
async fn get_storages(&self) -> Result<Vec<Storage>>;
fn mounted_info_set(&self) -> Arc<Mutex<HashMap<String, MountedInfo>>>;
/// 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<String>;
/// Umount rafs from nydusd.
/// Called during container cleanup.
async fn umount_rafs(&self, mountpoint: &str) -> Result<()>;
}
#[derive(Debug, Clone)]

View File

@@ -256,4 +256,10 @@ impl ShareFs for ShareVirtioFsStandalone {
fn mounted_info_set(&self) -> Arc<Mutex<HashMap<String, MountedInfo>>> {
self.mounted_info_set.clone()
}
async fn stop(&self) -> Result<()> {
self.shutdown_virtiofsd()
.await
.context("failed to stop virtiofsd daemon")
}
}