mirror of
https://github.com/kata-containers/kata-containers.git
synced 2026-07-01 14:38:33 +00:00
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:
committed by
Fabiano Fidêncio
parent
720a8688b4
commit
edfe9ea403
@@ -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)]
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user