mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-11 12:52:23 +00:00
Merge pull request #5690 from yipengyin/fix-virtiofsd
runtime-rs: fix standalone share fs
This commit is contained in:
commit
bb4be2a666
@ -35,7 +35,7 @@ pub const DEFAULT_VHOST_USER_STORE_PATH: &str = "/var/run/vhost-user";
|
|||||||
pub const DEFAULT_BLOCK_NVDIMM_MEM_OFFSET: u64 = 0;
|
pub const DEFAULT_BLOCK_NVDIMM_MEM_OFFSET: u64 = 0;
|
||||||
|
|
||||||
pub const DEFAULT_SHARED_FS_TYPE: &str = "virtio-fs";
|
pub const DEFAULT_SHARED_FS_TYPE: &str = "virtio-fs";
|
||||||
pub const DEFAULT_VIRTIO_FS_CACHE_MODE: &str = "none";
|
pub const DEFAULT_VIRTIO_FS_CACHE_MODE: &str = "never";
|
||||||
pub const DEFAULT_VIRTIO_FS_DAX_SIZE_MB: u32 = 1024;
|
pub const DEFAULT_VIRTIO_FS_DAX_SIZE_MB: u32 = 1024;
|
||||||
pub const DEFAULT_SHARED_9PFS_SIZE_MB: u32 = 128 * 1024;
|
pub const DEFAULT_SHARED_9PFS_SIZE_MB: u32 = 128 * 1024;
|
||||||
pub const MIN_SHARED_9PFS_SIZE_MB: u32 = 4 * 1024;
|
pub const MIN_SHARED_9PFS_SIZE_MB: u32 = 4 * 1024;
|
||||||
|
@ -864,7 +864,7 @@ impl SharedFsInfo {
|
|||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let l = ["none", "auto", "always"];
|
let l = ["never", "auto", "always"];
|
||||||
|
|
||||||
if !l.contains(&self.virtio_fs_cache.as_str()) {
|
if !l.contains(&self.virtio_fs_cache.as_str()) {
|
||||||
return Err(eother!(
|
return Err(eother!(
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
use std::{collections::HashMap, process::Stdio, sync::Arc};
|
use std::{collections::HashMap, process::Stdio, sync::Arc};
|
||||||
|
|
||||||
|
use crate::share_fs::share_virtio_fs::{
|
||||||
|
prepare_virtiofs, FS_TYPE_VIRTIO_FS, KATA_VIRTIO_FS_DEV_TYPE, MOUNT_GUEST_TAG,
|
||||||
|
};
|
||||||
|
use crate::share_fs::{KATA_GUEST_SHARE_DIR, VIRTIO_FS};
|
||||||
use agent::Storage;
|
use agent::Storage;
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@ -28,7 +32,6 @@ use super::{
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ShareVirtioFsStandaloneConfig {
|
pub struct ShareVirtioFsStandaloneConfig {
|
||||||
id: String,
|
id: String,
|
||||||
jail_root: String,
|
|
||||||
|
|
||||||
// virtio_fs_daemon is the virtio-fs vhost-user daemon path
|
// virtio_fs_daemon is the virtio-fs vhost-user daemon path
|
||||||
pub virtio_fs_daemon: String,
|
pub virtio_fs_daemon: String,
|
||||||
@ -56,7 +59,6 @@ impl ShareVirtioFsStandalone {
|
|||||||
inner: Arc::new(RwLock::new(ShareVirtioFsStandaloneInner::default())),
|
inner: Arc::new(RwLock::new(ShareVirtioFsStandaloneInner::default())),
|
||||||
config: ShareVirtioFsStandaloneConfig {
|
config: ShareVirtioFsStandaloneConfig {
|
||||||
id: id.to_string(),
|
id: id.to_string(),
|
||||||
jail_root: "".to_string(),
|
|
||||||
virtio_fs_daemon: config.virtio_fs_daemon.clone(),
|
virtio_fs_daemon: config.virtio_fs_daemon.clone(),
|
||||||
virtio_fs_cache: config.virtio_fs_cache.clone(),
|
virtio_fs_cache: config.virtio_fs_cache.clone(),
|
||||||
virtio_fs_extra_args: config.virtio_fs_extra_args.clone(),
|
virtio_fs_extra_args: config.virtio_fs_extra_args.clone(),
|
||||||
@ -69,14 +71,21 @@ impl ShareVirtioFsStandalone {
|
|||||||
fn virtiofsd_args(&self, sock_path: &str) -> Result<Vec<String>> {
|
fn virtiofsd_args(&self, sock_path: &str) -> Result<Vec<String>> {
|
||||||
let source_path = get_host_ro_shared_path(&self.config.id);
|
let source_path = get_host_ro_shared_path(&self.config.id);
|
||||||
ensure_dir_exist(&source_path)?;
|
ensure_dir_exist(&source_path)?;
|
||||||
|
let shared_dir = source_path
|
||||||
|
.to_str()
|
||||||
|
.ok_or_else(|| anyhow!("convert source path {:?} to str failed", source_path))?;
|
||||||
|
|
||||||
let mut args: Vec<String> = vec![
|
let mut args: Vec<String> = vec![
|
||||||
String::from("-f"),
|
String::from("--socket-path"),
|
||||||
format!("--socket-path={}", sock_path),
|
String::from(sock_path),
|
||||||
String::from("-o"),
|
String::from("--shared-dir"),
|
||||||
format!("source={}", source_path.to_str().unwrap()),
|
String::from(shared_dir),
|
||||||
String::from("-o"),
|
String::from("--cache"),
|
||||||
format!("cache={}", self.config.virtio_fs_cache),
|
self.config.virtio_fs_cache.clone(),
|
||||||
|
String::from("--sandbox"),
|
||||||
|
String::from("none"),
|
||||||
|
String::from("--seccomp"),
|
||||||
|
String::from("none"),
|
||||||
];
|
];
|
||||||
|
|
||||||
if !self.config.virtio_fs_extra_args.is_empty() {
|
if !self.config.virtio_fs_extra_args.is_empty() {
|
||||||
@ -87,8 +96,8 @@ impl ShareVirtioFsStandalone {
|
|||||||
Ok(args)
|
Ok(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn setup_virtiofsd(&self) -> Result<()> {
|
async fn setup_virtiofsd(&self, h: &dyn Hypervisor) -> Result<()> {
|
||||||
let sock_path = generate_sock_path(&self.config.jail_root);
|
let sock_path = generate_sock_path(&h.get_jailer_root().await?);
|
||||||
let args = self.virtiofsd_args(&sock_path).context("virtiofsd args")?;
|
let args = self.virtiofsd_args(&sock_path).context("virtiofsd args")?;
|
||||||
|
|
||||||
let mut cmd = Command::new(&self.config.virtio_fs_daemon);
|
let mut cmd = Command::new(&self.config.virtio_fs_daemon);
|
||||||
@ -163,8 +172,11 @@ impl ShareFs for ShareVirtioFsStandalone {
|
|||||||
self.share_fs_mount.clone()
|
self.share_fs_mount.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn setup_device_before_start_vm(&self, _h: &dyn Hypervisor) -> Result<()> {
|
async fn setup_device_before_start_vm(&self, h: &dyn Hypervisor) -> Result<()> {
|
||||||
self.setup_virtiofsd().await.context("setup virtiofsd")?;
|
prepare_virtiofs(h, VIRTIO_FS, &self.config.id, &h.get_jailer_root().await?)
|
||||||
|
.await
|
||||||
|
.context("prepare virtiofs")?;
|
||||||
|
self.setup_virtiofsd(h).await.context("setup virtiofsd")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +185,20 @@ impl ShareFs for ShareVirtioFsStandalone {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_storages(&self) -> Result<Vec<Storage>> {
|
async fn get_storages(&self) -> Result<Vec<Storage>> {
|
||||||
Ok(vec![])
|
let mut storages: Vec<Storage> = Vec::new();
|
||||||
|
|
||||||
|
let shared_volume: Storage = Storage {
|
||||||
|
driver: String::from(KATA_VIRTIO_FS_DEV_TYPE),
|
||||||
|
driver_options: Vec::new(),
|
||||||
|
source: String::from(MOUNT_GUEST_TAG),
|
||||||
|
fs_type: String::from(FS_TYPE_VIRTIO_FS),
|
||||||
|
fs_group: None,
|
||||||
|
options: vec![String::from("nodev")],
|
||||||
|
mount_point: String::from(KATA_GUEST_SHARE_DIR),
|
||||||
|
};
|
||||||
|
|
||||||
|
storages.push(shared_volume);
|
||||||
|
Ok(storages)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mounted_info_set(&self) -> Arc<Mutex<HashMap<String, MountedInfo>>> {
|
fn mounted_info_set(&self) -> Arc<Mutex<HashMap<String, MountedInfo>>> {
|
||||||
|
Loading…
Reference in New Issue
Block a user