Skip to content

Commit 2c510f4

Browse files
committed
Add support for readonly FLAT/ZERO VMDK format
Currently, it's mainly used for EROFS to merge hundreds of sub-blobs (container image layers) into one block device to avoid having too many block devices (and it would even be impossible for virtio-mmio since legacy IRQs is much limited in libkrun). Why VMDK is useful? Since it seems to be the only standard and simple way to support one-single block device that consists of a collection of multiple file parts among popular virtualization products such as QEMU and VirtualBox. Update the `krun_add_disk2` API to specify the VMDK format: - KRUN_DISK_FORMAT_VMDK Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent 8a14673 commit 2c510f4

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/libkrun.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ int32_t krun_add_disk(uint32_t ctx_id, const char *block_id, const char *disk_pa
167167
/* Supported disk image formats */
168168
#define KRUN_DISK_FORMAT_RAW 0
169169
#define KRUN_DISK_FORMAT_QCOW2 1
170+
/* Note: Only supports FLAT/ZERO formats without delta links */
171+
#define KRUN_DISK_FORMAT_VMDK 2
172+
170173
/**
171174
* Adds a disk image to be used as a general partition for the microVM. The supported
172175
* image formats are: "raw" and "qcow2".

src/devices/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ arch = { path = "../arch" }
3838
utils = { path = "../utils" }
3939
polly = { path = "../polly" }
4040
rutabaga_gfx = { path = "../rutabaga_gfx", features = ["virgl_renderer", "virgl_renderer_next"], optional = true }
41-
imago = { version = "0.1.5", features = ["sync-wrappers", "vm-memory"] }
41+
imago = { features = ["sync-wrappers", "vm-memory"], git = "https://gitlab.com/hreitz/imago.git", branch = "main" }
4242

4343
[target.'cfg(target_os = "macos")'.dependencies]
4444
hvf = { path = "../hvf" }

src/devices/src/virtio/block/device.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use std::sync::Arc;
1919
use std::thread::JoinHandle;
2020

2121
use imago::{
22-
file::File as ImagoFile, qcow2::Qcow2, raw::Raw, DynStorage, Storage, StorageOpenOptions,
23-
SyncFormatAccess,
22+
file::File as ImagoFile, qcow2::Qcow2, raw::Raw, vmdk::Vmdk, DynStorage, FormatDriverBuilder,
23+
PermissiveImplicitOpenGate, Storage, StorageOpenOptions, SyncFormatAccess,
2424
};
2525
use log::{error, warn};
2626
use utils::eventfd::{EventFd, EFD_NONBLOCK};
@@ -240,6 +240,13 @@ impl Block {
240240
)?;
241241
SyncFormatAccess::new(raw)?
242242
}
243+
ImageType::Vmdk => {
244+
let vmdk = Vmdk::<Box<dyn DynStorage>, Arc<imago::FormatAccess<_>>>::builder(
245+
Box::new(file),
246+
)
247+
.open_sync(PermissiveImplicitOpenGate::default())?;
248+
SyncFormatAccess::new(vmdk)?
249+
}
243250
};
244251

245252
let disk_image = Arc::new(disk_image);

src/devices/src/virtio/block/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ pub enum Error {
3838
pub enum ImageType {
3939
Raw,
4040
Qcow2,
41+
Vmdk,
4142
}

src/libkrun/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ pub unsafe extern "C" fn krun_add_disk2(
703703
let format = match disk_format {
704704
0 => ImageType::Raw,
705705
1 => ImageType::Qcow2,
706+
2 => ImageType::Vmdk,
706707
_ => {
707708
// Do not continue if the user cannot specify a valid disk format
708709
return -libc::EINVAL;

0 commit comments

Comments
 (0)