mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 20:54:26 +00:00
runtime-rs: Enhance flexibility of virtio-fs config
support more and flexible options for inline virtiofs. Fixes: #7091 Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
parent
355a24e0e1
commit
347385b4ee
@ -67,6 +67,9 @@ pub struct ShareFsDeviceConfig {
|
|||||||
|
|
||||||
/// queue_num: queue number
|
/// queue_num: queue number
|
||||||
pub queue_num: u64,
|
pub queue_num: u64,
|
||||||
|
|
||||||
|
/// options: virtiofs device's config options.
|
||||||
|
pub options: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -157,7 +157,11 @@ impl DragonballInner {
|
|||||||
.context("insert vsock")
|
.context("insert vsock")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_inline_virtiofs_args(&self, fs_cfg: &mut FsDeviceConfigInfo) -> Result<()> {
|
fn parse_inline_virtiofs_args(
|
||||||
|
&self,
|
||||||
|
fs_cfg: &mut FsDeviceConfigInfo,
|
||||||
|
options: &mut Vec<String>,
|
||||||
|
) -> Result<()> {
|
||||||
let mut debug = false;
|
let mut debug = false;
|
||||||
let mut opt_list = String::new();
|
let mut opt_list = String::new();
|
||||||
|
|
||||||
@ -169,8 +173,8 @@ impl DragonballInner {
|
|||||||
sl!(),
|
sl!(),
|
||||||
"args: {:?}", &self.config.shared_fs.virtio_fs_extra_args
|
"args: {:?}", &self.config.shared_fs.virtio_fs_extra_args
|
||||||
);
|
);
|
||||||
let args = &self.config.shared_fs.virtio_fs_extra_args;
|
let mut args = self.config.shared_fs.virtio_fs_extra_args.clone();
|
||||||
let _ = go_flag::parse_args_with_warnings::<String, _, _>(args, None, |flags| {
|
let _ = go_flag::parse_args_with_warnings::<String, _, _>(&args, None, |flags| {
|
||||||
flags.add_flag("d", &mut debug);
|
flags.add_flag("d", &mut debug);
|
||||||
flags.add_flag("thread-pool-size", &mut fs_cfg.thread_pool_size);
|
flags.add_flag("thread-pool-size", &mut fs_cfg.thread_pool_size);
|
||||||
flags.add_flag("drop-sys-resource", &mut fs_cfg.drop_sys_resource);
|
flags.add_flag("drop-sys-resource", &mut fs_cfg.drop_sys_resource);
|
||||||
@ -178,6 +182,9 @@ impl DragonballInner {
|
|||||||
})
|
})
|
||||||
.with_context(|| format!("parse args: {:?}", args))?;
|
.with_context(|| format!("parse args: {:?}", args))?;
|
||||||
|
|
||||||
|
// more options parsed for inline virtio-fs' custom config
|
||||||
|
args.append(options);
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
warn!(
|
warn!(
|
||||||
sl!(),
|
sl!(),
|
||||||
@ -202,6 +209,7 @@ impl DragonballInner {
|
|||||||
"xattr" => fs_cfg.xattr = true,
|
"xattr" => fs_cfg.xattr = true,
|
||||||
"no_xattr" => fs_cfg.xattr = false,
|
"no_xattr" => fs_cfg.xattr = false,
|
||||||
"cache_symlinks" => {} // inline virtiofs always cache symlinks
|
"cache_symlinks" => {} // inline virtiofs always cache symlinks
|
||||||
|
"no_readdir" => fs_cfg.no_readdir = true,
|
||||||
"trace" => warn!(
|
"trace" => warn!(
|
||||||
sl!(),
|
sl!(),
|
||||||
"Inline virtiofs \"-o trace\" option not supported yet, ignored."
|
"Inline virtiofs \"-o trace\" option not supported yet, ignored."
|
||||||
@ -234,16 +242,25 @@ impl DragonballInner {
|
|||||||
xattr: true,
|
xattr: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
self.do_add_fs_device(&config.fs_type, &mut fs_cfg)
|
|
||||||
|
let mut options = config.options.clone();
|
||||||
|
self.do_add_fs_device(&config.fs_type, &mut fs_cfg, &mut options)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_add_fs_device(&self, fs_type: &str, fs_cfg: &mut FsDeviceConfigInfo) -> Result<()> {
|
fn do_add_fs_device(
|
||||||
|
&self,
|
||||||
|
fs_type: &str,
|
||||||
|
fs_cfg: &mut FsDeviceConfigInfo,
|
||||||
|
options: &mut Vec<String>,
|
||||||
|
) -> Result<()> {
|
||||||
match fs_type {
|
match fs_type {
|
||||||
VIRTIO_FS => {
|
VIRTIO_FS => {
|
||||||
fs_cfg.mode = String::from("vhostuser");
|
fs_cfg.mode = String::from("vhostuser");
|
||||||
}
|
}
|
||||||
INLINE_VIRTIO_FS => {
|
INLINE_VIRTIO_FS => {
|
||||||
self.parse_inline_virtiofs_args(fs_cfg)?;
|
// All parameters starting with --patch-fs do not need to be processed, these are the parameters required by patch fs
|
||||||
|
options.retain(|x| !x.starts_with("--patch-fs"));
|
||||||
|
self.parse_inline_virtiofs_args(fs_cfg, options)?;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
@ -311,8 +328,12 @@ mod tests {
|
|||||||
"--drop-sys-resource".to_string(),
|
"--drop-sys-resource".to_string(),
|
||||||
"-d".to_string(),
|
"-d".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let mut options: Vec<String> = Vec::new();
|
||||||
dragonball.config.shared_fs.virtio_fs_cache = "auto".to_string();
|
dragonball.config.shared_fs.virtio_fs_cache = "auto".to_string();
|
||||||
dragonball.parse_inline_virtiofs_args(&mut fs_cfg).unwrap();
|
dragonball
|
||||||
|
.parse_inline_virtiofs_args(&mut fs_cfg, &mut options)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert!(!fs_cfg.no_open);
|
assert!(!fs_cfg.no_open);
|
||||||
assert!(fs_cfg.xattr);
|
assert!(fs_cfg.xattr);
|
||||||
|
@ -56,6 +56,7 @@ pub(crate) async fn prepare_virtiofs(
|
|||||||
fs_type: fs_type.to_string(),
|
fs_type: fs_type.to_string(),
|
||||||
queue_size: 0,
|
queue_size: 0,
|
||||||
queue_num: 0,
|
queue_num: 0,
|
||||||
|
options: vec![],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
h.add_device(DeviceType::ShareFs(share_fs_device))
|
h.add_device(DeviceType::ShareFs(share_fs_device))
|
||||||
|
Loading…
Reference in New Issue
Block a user