Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/firecracker/swagger/firecracker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,12 @@ definitions:
description:
Is block read only.
This field is required for virtio-block config and should be omitted for vhost-user-block configuration.
threaded:
type: boolean
description:
Whether to process requests on a dedicated worker thread.
This field is supported only for virtio-block configuration.
default: false
path_on_host:
type: string
description:
Expand Down
1 change: 1 addition & 0 deletions src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ pub(crate) mod tests {
cache_type: custom_block_cfg.cache_type,

is_read_only: Some(custom_block_cfg.is_read_only),
threaded: false,
path_on_host: Some(
block_files
.last()
Expand Down
1 change: 1 addition & 0 deletions src/vmm/src/device_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ pub(crate) mod tests {
is_root_device: is_root,
cache_type: CacheType::Unsafe,
is_read_only: Some(false),
threaded: false,
path_on_host: Some(f.as_path().to_str().unwrap().to_string()),
rate_limiter: None,
file_engine_type: None,
Expand Down
1 change: 1 addition & 0 deletions src/vmm/src/device_manager/pci_mngr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ mod tests {
"is_root_device": true,
"cache_type": "Unsafe",
"is_read_only": true,
"threaded": false,
"path_on_host": "{}",
"rate_limiter": null,
"io_engine": "Sync",
Expand Down
1 change: 1 addition & 0 deletions src/vmm/src/device_manager/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ mod tests {
"is_root_device": true,
"cache_type": "Unsafe",
"is_read_only": true,
"threaded": false,
"path_on_host": "{}",
"rate_limiter": null,
"io_engine": "Sync",
Expand Down
9 changes: 7 additions & 2 deletions src/vmm/src/devices/virtio/block/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use vmm_sys_util::eventfd::EventFd;
use super::BlockError;
use super::persist::{BlockConstructorArgs, BlockState};
use super::vhost_user::device::{VhostUserBlock, VhostUserBlockConfig};
use super::virtio::VirtioBlockError;
use super::virtio::device::{VirtioBlock, VirtioBlockConfig};
use crate::devices::virtio::ActivateError;
use crate::devices::virtio::device::{VirtioDevice, VirtioDeviceType};
Expand Down Expand Up @@ -118,10 +119,14 @@ impl Block {

pub(crate) fn spawn_worker(
&mut self,
_seccomp_filter: Option<Arc<BpfProgram>>,
seccomp_filter: Option<Arc<BpfProgram>>,
) -> Result<(), BlockError> {
match self {
Self::Virtio(_) | Self::VhostUser(_) => Ok(()),
Self::Virtio(b) if b.config.threaded => b
.spawn_worker(seccomp_filter.ok_or(BlockError::MissingSeccompFilter)?)
.map_err(BlockError::VirtioBackend),
Self::Virtio(_) => Ok(()),
Self::VhostUser(_) => Ok(()),
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/vmm/src/devices/virtio/block/vhost_user/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ impl TryFrom<&BlockDeviceConfig> for VhostUserBlockConfig {
type Error = VhostUserBlockError;

fn try_from(value: &BlockDeviceConfig) -> Result<Self, Self::Error> {
if value.threaded {
return Err(VhostUserBlockError::Config);
}

if let (Some(socket), None, None, None, None) = (
&value.socket,
&value.is_read_only,
Expand Down Expand Up @@ -97,6 +101,7 @@ impl From<VhostUserBlockConfig> for BlockDeviceConfig {
cache_type: value.cache_type,

is_read_only: None,
threaded: false,
path_on_host: None,
rate_limiter: None,
file_engine_type: None,
Expand Down Expand Up @@ -428,6 +433,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: None,
threaded: false,
path_on_host: None,
rate_limiter: None,
file_engine_type: None,
Expand All @@ -443,6 +449,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(true),
threaded: false,
path_on_host: Some("path".to_string()),
rate_limiter: None,
file_engine_type: Some(FileEngineType::Sync),
Expand All @@ -458,6 +465,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(true),
threaded: false,
path_on_host: Some("path".to_string()),
rate_limiter: None,
file_engine_type: Some(FileEngineType::Sync),
Expand Down
9 changes: 9 additions & 0 deletions src/vmm/src/devices/virtio/block/virtio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ pub struct VirtioBlockConfig {
/// If set to true, the drive is opened in read-only mode. Otherwise, the
/// drive is opened as read-write.
pub is_read_only: bool,
/// If set to true, process requests on a dedicated worker thread.
#[serde(default)]
pub threaded: bool,
/// Path of the backing file on the host
pub path_on_host: String,
/// Rate Limiter for I/O operations.
Expand All @@ -210,6 +213,7 @@ impl TryFrom<&BlockDeviceConfig> for VirtioBlockConfig {
cache_type: value.cache_type,

is_read_only: value.is_read_only.unwrap_or(false),
threaded: value.threaded,
path_on_host: path_on_host.clone(),
rate_limiter: value.rate_limiter,
file_engine_type: value.file_engine_type.unwrap_or_default(),
Expand All @@ -229,6 +233,7 @@ impl From<VirtioBlockConfig> for BlockDeviceConfig {
cache_type: value.cache_type,

is_read_only: Some(value.is_read_only),
threaded: value.threaded,
path_on_host: Some(value.path_on_host),
rate_limiter: value.rate_limiter,
file_engine_type: Some(value.file_engine_type),
Expand Down Expand Up @@ -832,6 +837,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(true),
threaded: false,
path_on_host: Some("path".to_string()),
rate_limiter: None,
file_engine_type: Default::default(),
Expand All @@ -847,6 +853,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: None,
threaded: false,
path_on_host: None,
rate_limiter: None,
file_engine_type: Default::default(),
Expand All @@ -862,6 +869,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(true),
threaded: false,
path_on_host: Some("path".to_string()),
rate_limiter: None,
file_engine_type: Default::default(),
Expand Down Expand Up @@ -1970,6 +1978,7 @@ mod tests {
for threaded in [false, true] {
let mut block = default_block(engine);
if threaded {
block.config.threaded = true;
block.spawn_worker(Arc::new(vec![])).unwrap();
}

Expand Down
6 changes: 6 additions & 0 deletions src/vmm/src/devices/virtio/block/virtio/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub struct VirtioBlockState {
pub virtio_state: VirtioDeviceState,
rate_limiter_state: RateLimiterState,
file_engine_type: FileEngineTypeState,
#[serde(default)]
threaded: bool,
}

impl Persist<'_> for VirtioBlock {
Expand Down Expand Up @@ -91,6 +93,7 @@ impl Persist<'_> for VirtioBlock {
virtio_state,
rate_limiter_state: self.rate_limiter().save(),
file_engine_type: FileEngineTypeState::from(self.file_engine_type()),
threaded: self.config.threaded,
}
}

Expand All @@ -108,6 +111,7 @@ impl Persist<'_> for VirtioBlock {
is_root_device: state.root_device,
cache_type: state.cache_type,
is_read_only,
threaded: state.threaded,
path_on_host: state.disk_path.clone(),
rate_limiter: rate_limiter_config.into_option(),
file_engine_type: state.file_engine_type.into(),
Expand Down Expand Up @@ -178,6 +182,7 @@ mod tests {
is_root_device: false,
partuuid: None,
is_read_only: false,
threaded: false,
cache_type: CacheType::Writeback,
rate_limiter: None,
file_engine_type: FileEngineType::default(),
Expand Down Expand Up @@ -219,6 +224,7 @@ mod tests {
is_root_device: false,
partuuid: None,
is_read_only: false,
threaded: false,
cache_type: CacheType::Unsafe,
rate_limiter: None,
file_engine_type: FileEngineType::default(),
Expand Down
1 change: 1 addition & 0 deletions src/vmm/src/devices/virtio/block/virtio/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn default_block_with_path(path: String, file_engine_type: FileEngineType) -
is_root_device: false,
partuuid: None,
is_read_only: false,
threaded: false,
cache_type: CacheType::Unsafe,
// Rate limiting is enabled but with a high operation rate (10 million ops/s).
rate_limiter: Some(RateLimiterConfig {
Expand Down
1 change: 1 addition & 0 deletions src/vmm/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(tmp_file.as_path().to_str().unwrap().to_string()),
rate_limiter: Some(RateLimiterConfig::default()),
file_engine_type: None,
Expand Down
21 changes: 21 additions & 0 deletions src/vmm/src/vmm_config/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ pub struct BlockDeviceConfig {
/// If set to true, the drive is opened in read-only mode. Otherwise, the
/// drive is opened as read-write.
pub is_read_only: Option<bool>,
/// If set to true, process requests on a dedicated worker thread.
#[serde(default)]
pub threaded: bool,
/// Path of the drive.
pub path_on_host: Option<String>,
/// Rate Limiter for I/O operations.
Expand Down Expand Up @@ -208,6 +211,7 @@ mod tests {
partuuid: self.partuuid.clone(),
is_root_device: self.is_root_device,
is_read_only: self.is_read_only,
threaded: self.threaded,
cache_type: self.cache_type,

path_on_host: self.path_on_host.clone(),
Expand Down Expand Up @@ -237,6 +241,7 @@ mod tests {
cache_type: CacheType::Writeback,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path),
rate_limiter: None,
file_engine_type: None,
Expand Down Expand Up @@ -271,6 +276,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(true),
threaded: false,
path_on_host: Some(dummy_path),
rate_limiter: None,
file_engine_type: None,
Expand Down Expand Up @@ -303,6 +309,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(true),
threaded: false,
path_on_host: Some(dummy_path),
rate_limiter: None,
file_engine_type: None,
Expand Down Expand Up @@ -332,6 +339,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_1),
rate_limiter: None,
file_engine_type: None,
Expand All @@ -348,6 +356,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_2),
rate_limiter: None,
file_engine_type: None,
Expand Down Expand Up @@ -375,6 +384,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_1),
rate_limiter: None,
file_engine_type: None,
Expand All @@ -391,6 +401,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_2),
rate_limiter: None,
file_engine_type: None,
Expand All @@ -407,6 +418,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_3),
rate_limiter: None,
file_engine_type: None,
Expand Down Expand Up @@ -448,6 +460,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_1),
rate_limiter: None,
file_engine_type: None,
Expand All @@ -464,6 +477,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_2),
rate_limiter: None,
file_engine_type: None,
Expand All @@ -480,6 +494,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_3),
rate_limiter: None,
file_engine_type: None,
Expand Down Expand Up @@ -522,6 +537,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_1.clone()),
rate_limiter: None,
file_engine_type: None,
Expand All @@ -538,6 +554,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_2.clone()),
rate_limiter: None,
file_engine_type: None,
Expand Down Expand Up @@ -610,6 +627,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_1),
rate_limiter: None,
file_engine_type: None,
Expand All @@ -626,6 +644,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(dummy_path_2),
rate_limiter: None,
file_engine_type: None,
Expand All @@ -652,6 +671,7 @@ mod tests {
cache_type: CacheType::Unsafe,

is_read_only: Some(true),
threaded: false,
path_on_host: Some(dummy_file.as_path().to_str().unwrap().to_string()),
rate_limiter: None,
file_engine_type: Some(FileEngineType::Sync),
Expand Down Expand Up @@ -682,6 +702,7 @@ mod tests {
cache_type: CacheType::default(),

is_read_only: Some(true),
threaded: false,
path_on_host: Some(backing_file.as_path().to_str().unwrap().to_string()),
rate_limiter: None,
file_engine_type: None,
Expand Down
1 change: 1 addition & 0 deletions src/vmm/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ fn test_preboot_load_snap_disallowed_after_boot_resources() {
cache_type: CacheType::Unsafe,

is_read_only: Some(false),
threaded: false,
path_on_host: Some(tmp_file),
rate_limiter: None,
file_engine_type: None,
Expand Down
Loading
Loading