diff --git a/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_fs.rs b/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_fs.rs index d2d3cc762b..0a97845e71 100644 --- a/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_fs.rs +++ b/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_fs.rs @@ -67,6 +67,9 @@ pub struct ShareFsDeviceConfig { /// queue_num: queue number pub queue_num: u64, + + /// options: virtiofs device's config options. + pub options: Vec, } #[derive(Debug, Clone)] diff --git a/src/runtime-rs/crates/hypervisor/src/dragonball/inner_device.rs b/src/runtime-rs/crates/hypervisor/src/dragonball/inner_device.rs index 94861536cd..10e13b5787 100644 --- a/src/runtime-rs/crates/hypervisor/src/dragonball/inner_device.rs +++ b/src/runtime-rs/crates/hypervisor/src/dragonball/inner_device.rs @@ -157,7 +157,11 @@ impl DragonballInner { .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, + ) -> Result<()> { let mut debug = false; let mut opt_list = String::new(); @@ -169,8 +173,8 @@ impl DragonballInner { sl!(), "args: {:?}", &self.config.shared_fs.virtio_fs_extra_args ); - let args = &self.config.shared_fs.virtio_fs_extra_args; - let _ = go_flag::parse_args_with_warnings::(args, None, |flags| { + let mut args = self.config.shared_fs.virtio_fs_extra_args.clone(); + let _ = go_flag::parse_args_with_warnings::(&args, None, |flags| { flags.add_flag("d", &mut debug); flags.add_flag("thread-pool-size", &mut fs_cfg.thread_pool_size); flags.add_flag("drop-sys-resource", &mut fs_cfg.drop_sys_resource); @@ -178,6 +182,9 @@ impl DragonballInner { }) .with_context(|| format!("parse args: {:?}", args))?; + // more options parsed for inline virtio-fs' custom config + args.append(options); + if debug { warn!( sl!(), @@ -202,6 +209,7 @@ impl DragonballInner { "xattr" => fs_cfg.xattr = true, "no_xattr" => fs_cfg.xattr = false, "cache_symlinks" => {} // inline virtiofs always cache symlinks + "no_readdir" => fs_cfg.no_readdir = true, "trace" => warn!( sl!(), "Inline virtiofs \"-o trace\" option not supported yet, ignored." @@ -234,16 +242,25 @@ impl DragonballInner { xattr: true, ..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, + ) -> Result<()> { match fs_type { VIRTIO_FS => { fs_cfg.mode = String::from("vhostuser"); } 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!( @@ -311,8 +328,12 @@ mod tests { "--drop-sys-resource".to_string(), "-d".to_string(), ]; + + let mut options: Vec = Vec::new(); 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.xattr); diff --git a/src/runtime-rs/crates/resource/src/share_fs/share_virtio_fs.rs b/src/runtime-rs/crates/resource/src/share_fs/share_virtio_fs.rs index 81ab8b7fd1..9a5676bdfc 100644 --- a/src/runtime-rs/crates/resource/src/share_fs/share_virtio_fs.rs +++ b/src/runtime-rs/crates/resource/src/share_fs/share_virtio_fs.rs @@ -56,6 +56,7 @@ pub(crate) async fn prepare_virtiofs( fs_type: fs_type.to_string(), queue_size: 0, queue_num: 0, + options: vec![], }, }; h.add_device(DeviceType::ShareFs(share_fs_device))