virtualizationmanager: use raw file instead of qcow
crosvm's qcow backend isn't as well maintained or optimized as its raw
file backend. The OS will lazily allocate blocks in the filesystem as
they are used since we are only setting the file length (i.e. ftruncate)
and not requesting it to be allocated eagerly (i.e. fallocate).
Anecdotally, for a freshly allocated encryptedstore disk, the raw
file actually uses less disk.
adb shell /apex/com.android.virt/bin/vm run-microdroid --storage /data/misc/virtualizationservice/foo
Before
$ adb shell du -b -h /data/misc/virtualizationservice/foo
4.9M /data/misc/virtualizationservice/foo
$ adb shell du -h /data/misc/virtualizationservice/foo
4.7M /data/misc/virtualizationservice/foo
After
$ adb shell du -b -h /data/misc/virtualizationservice/foo
10M /data/misc/virtualizationservice/foo
$ adb shell du -h /data/misc/virtualizationservice/foo
4.4M /data/misc/virtualizationservice/foo
Test: TH
Change-Id: I4e456314736d5a99b850904afc3f1047d6c2e885
diff --git a/encryptedstore/README.md b/encryptedstore/README.md
index 544d6eb..3d55d85 100644
--- a/encryptedstore/README.md
+++ b/encryptedstore/README.md
@@ -5,7 +5,7 @@
Any data written in encrypted storage is persisted and is available next time the VM is run.
Encrypted Storage is backed by a para-virtualized block device on the guest which is further
-backed by a qcow2 disk image in the host. The block device is formatted with an ext4 filesystem.
+backed by a disk image file in the host. The block device is formatted with an ext4 filesystem.
## Security
diff --git a/virtualizationmanager/src/aidl.rs b/virtualizationmanager/src/aidl.rs
index 0c4aa7c..28d47a4 100644
--- a/virtualizationmanager/src/aidl.rs
+++ b/virtualizationmanager/src/aidl.rs
@@ -67,7 +67,6 @@
IntoBinderResult,
};
use cstr::cstr;
-use disk::QcowFile;
use glob::glob;
use lazy_static::lazy_static;
use log::{debug, error, info, warn};
@@ -256,15 +255,17 @@
.context("failed to move cursor to start")
.or_service_specific_exception(-1)?;
image.set_len(0).context("Failed to reset a file").or_service_specific_exception(-1)?;
-
- let mut part = QcowFile::new(image, size_bytes)
- .context("Failed to create QCOW2 image")
+ // Set the file length. In most filesystems, this will not allocate any physical disk
+ // space, it will only change the logical size.
+ image
+ .set_len(size_bytes)
+ .context("Failed to extend file")
.or_service_specific_exception(-1)?;
match partition_type {
PartitionType::RAW => Ok(()),
- PartitionType::ANDROID_VM_INSTANCE => format_as_android_vm_instance(&mut part),
- PartitionType::ENCRYPTEDSTORE => format_as_encryptedstore(&mut part),
+ PartitionType::ANDROID_VM_INSTANCE => format_as_android_vm_instance(&mut image),
+ PartitionType::ENCRYPTEDSTORE => format_as_encryptedstore(&mut image),
_ => Err(Error::new(
ErrorKind::Unsupported,
format!("Unsupported partition type {:?}", partition_type),