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
143 changes: 142 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions resources/seccomp/aarch64-unknown-linux-musl.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@
"syscall": "lseek",
"comment": "Used by the block device"
},
{
"syscall": "preadv",
"comment": "Used by the imago VMDK disk image backend"
},
{
"syscall": "pwritev",
"comment": "Used by the imago VMDK disk image backend"
},
{
"syscall": "mremap",
"comment": "Used for re-allocating large memory regions, for example vectors"
Expand Down
8 changes: 8 additions & 0 deletions resources/seccomp/x86_64-unknown-linux-musl.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@
"syscall": "lseek",
"comment": "Used by the block device"
},
{
"syscall": "preadv",
"comment": "Used by the imago VMDK disk image backend"
},
{
"syscall": "pwritev",
"comment": "Used by the imago VMDK disk image backend"
},
{
"syscall": "mremap",
"comment": "Used for re-allocating large memory regions, for example vectors"
Expand Down
2 changes: 2 additions & 0 deletions src/vmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ vm-memory = { version = "0.17.1", features = [
vm-superio = "0.8.1"
vmm-sys-util = { version = "0.15.0", features = ["with-serde"] }
zerocopy = { version = "0.8.40" }
imago = { git = "https://gitlab.com/hreitz/imago", tag = "v0.2.2", features = ["sync-wrappers"] }
tokio = { version = "1", features = ["rt"] }

[target.'cfg(target_arch = "aarch64")'.dependencies]
vm-fdt = "0.3.0"
Expand Down
38 changes: 30 additions & 8 deletions src/vmm/src/devices/virtio/block/virtio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,31 @@ impl DiskProperties {
file_engine_type: FileEngineType,
) -> Result<Self, VirtioBlockError> {
let mut disk_image = Self::open_file(&disk_image_path, is_disk_read_only)?;
let disk_size = Self::file_size(&disk_image_path, &mut disk_image)?;
let image_id = Self::build_disk_image_id(&disk_image);

// Detect disk format and create the appropriate engine.
let format = block_io::detect_disk_format(&disk_image)
.map_err(|e| VirtioBlockError::BackingFile(e, disk_image_path.clone()))?;

let (file_engine, disk_size) = match format {
block_io::DiskImageFormat::Vmdk => {
// VMDK images are always read-only; the VmdkFileEngine enforces this.
let vmdk_engine = block_io::VmdkFileEngine::from_file(disk_image)
.map_err(|e| VirtioBlockError::FileEngine(block_io::BlockIoError::Vmdk(e)))?;
let disk_size = vmdk_engine.disk_size();
(FileEngine::Vmdk(vmdk_engine), disk_size)
}
block_io::DiskImageFormat::Raw => {
let disk_size = Self::file_size(&disk_image_path, &mut disk_image)?;
let engine = FileEngine::from_file(disk_image, file_engine_type)
.map_err(VirtioBlockError::FileEngine)?;
(engine, disk_size)
}
};

Ok(Self {
file_path: disk_image_path,
file_engine: FileEngine::from_file(disk_image, file_engine_type)
.map_err(VirtioBlockError::FileEngine)?,
file_engine,
nsectors: disk_size >> SECTOR_SHIFT,
image_id,
})
Expand All @@ -118,10 +136,11 @@ impl DiskProperties {
let disk_size = Self::file_size(&disk_image_path, &mut disk_image)?;

self.image_id = Self::build_disk_image_id(&disk_image);
self.file_engine
let engine_disk_size = self
.file_engine
.update_file_path(disk_image)
.map_err(VirtioBlockError::FileEngine)?;
self.nsectors = disk_size >> SECTOR_SHIFT;
self.nsectors = engine_disk_size.unwrap_or(disk_size) >> SECTOR_SHIFT;
self.file_path = disk_image_path;

Ok(())
Expand Down Expand Up @@ -271,7 +290,7 @@ macro_rules! unwrap_async_file_engine_or_return {
($file_engine: expr) => {
match $file_engine {
FileEngine::Async(engine) => engine,
FileEngine::Sync(_) => {
FileEngine::Sync(_) | FileEngine::Vmdk(_) => {
error!("The block device doesn't use an async IO engine");
return;
}
Expand All @@ -290,6 +309,8 @@ impl VirtioBlock {
config.file_engine_type,
)?;

let is_read_only = config.is_read_only;

let rate_limiter = config
.rate_limiter
.map(RateLimiterConfig::try_into)
Expand All @@ -303,7 +324,7 @@ impl VirtioBlock {
avail_features |= 1u64 << VIRTIO_BLK_F_FLUSH;
}

if config.is_read_only {
if is_read_only {
avail_features |= 1u64 << VIRTIO_BLK_F_RO;
};

Expand All @@ -329,7 +350,7 @@ impl VirtioBlock {
partuuid: config.partuuid,
cache_type: config.cache_type,
root_device: config.is_root_device,
read_only: config.is_read_only,
read_only: is_read_only,

disk: disk_properties,
rate_limiter,
Expand Down Expand Up @@ -559,6 +580,7 @@ impl VirtioBlock {
match self.disk.file_engine {
FileEngine::Sync(_) => FileEngineType::Sync,
FileEngine::Async(_) => FileEngineType::Async,
FileEngine::Vmdk(_) => FileEngineType::Sync,
}
}

Expand Down
Loading