shared_dir.rs0.00%
1
// Copyright 2025 Google LLC2
//3
// Licensed under the Apache License, Version 2.0 (the "License");4
// you may not use this file except in compliance with the License.5
// You may obtain a copy of the License at6
//7
// https://www.apache.org/licenses/LICENSE-2.08
//9
// Unless required by applicable law or agreed to in writing, software10
// distributed under the License is distributed on an "AS IS" BASIS,11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12
// See the License for the specific language governing permissions and13
// limitations under the License.14
15
use std::cmp::min;16
use std::path::Path;17
use std::sync::Arc;18
19
use serde::Deserialize;20
use serde_aco::Help;21
22
use crate::fuse::passthrough::Passthrough;23
use crate::virtio::Result;24
use crate::virtio::dev::DevParam;25
use crate::virtio::dev::fs::{Fs, FsConfig};26
27
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Help)]28
pub struct SharedDirParam {29
/// Mount tag seen by the guest.30
pub tag: String,31
/// Path to the shared dir.32
pub path: Box<Path>,33
/// Size of memory region for DAX in bytes.34
/// 0 means no DAX. [default: 0]35
#[serde(default)]36
pub dax_window: usize,37
}38
39
impl DevParam for SharedDirParam {40
type Device = Fs<Passthrough>;41
42
fn build(self, name: impl Into<Arc<str>>) -> Result<Fs<Passthrough>> {43
let passthrough = Passthrough::new(self.path)?;44
let mut config = FsConfig {45
tag: [0; 36],46
num_request_queues: 1,47
notify_buf_size: 0,48
};49
let tag_size = min(config.tag.len(), self.tag.len());50
config.tag[0..tag_size].copy_from_slice(&self.tag.as_bytes()[0..tag_size]);51
Fs::new(name, passthrough, config, self.dax_window)52
}53
}54