Skip to content

Commit 0f2bd53

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 <[email protected]>
1 parent 8a14673 commit 0f2bd53

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-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+
/* It's used only when you know what you're doing */
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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ use std::result;
1818
use std::sync::Arc;
1919
use std::thread::JoinHandle;
2020

21+
use imago::PermissiveImplicitOpenGate;
2122
use imago::{
22-
file::File as ImagoFile, qcow2::Qcow2, raw::Raw, DynStorage, Storage, StorageOpenOptions,
23-
SyncFormatAccess,
23+
file::File as ImagoFile, qcow2::Qcow2, raw::Raw, vmdk::Vmdk, DynStorage, FormatDriverBuilder,
24+
Storage, StorageOpenOptions, SyncFormatAccess,
2425
};
2526
use log::{error, warn};
2627
use utils::eventfd::{EventFd, EFD_NONBLOCK};
@@ -240,6 +241,13 @@ impl Block {
240241
)?;
241242
SyncFormatAccess::new(raw)?
242243
}
244+
ImageType::Vmdk => {
245+
let vmdk = Vmdk::<Box<dyn DynStorage>, Arc<imago::FormatAccess<_>>>::builder(
246+
Box::new(file),
247+
)
248+
.open_sync(PermissiveImplicitOpenGate::default())?;
249+
SyncFormatAccess::new(vmdk)?
250+
}
243251
};
244252

245253
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)