Support multi-file partitions for composite disk
This is a follow-up to 1fee0d8da6bb440127861e278a7dad09b7f506fd.
Bug: 190503456
Test: MicrodroidHostTestCases
Change-Id: If43bf3d10fc773877bba8b02a3088cd26a814ef9
diff --git a/virtualizationservice/src/composite.rs b/virtualizationservice/src/composite.rs
index 5f792fd..7b5a258 100644
--- a/virtualizationservice/src/composite.rs
+++ b/virtualizationservice/src/composite.rs
@@ -336,9 +336,9 @@
Ok((composite_image, files))
}
-/// Given the AIDL config containing a list of partitions, with a [`ParcelFileDescriptor`] for each
-/// partition, return the list of file descriptors which must be passed to the mk_cdisk child
-/// process and the composite disk image partition configuration for it.
+/// Given the AIDL config containing a list of partitions, with [`ParcelFileDescriptor`]s for each
+/// partition, return the list of file descriptors which must be passed to the composite disk image
+/// partition configuration for it.
fn convert_partitions(partitions: &[Partition]) -> Result<(Vec<PartitionInfo>, Vec<File>), Error> {
// File descriptors to pass to child process.
let mut files = vec![];
@@ -346,24 +346,27 @@
let partitions = partitions
.iter()
.map(|partition| {
- // TODO(b/187187765): This shouldn't be an Option.
- let file = partition
- .image
- .as_ref()
- .context("Invalid partition image file descriptor")?
- .as_ref()
- .try_clone()
- .context("Failed to clone partition image file descriptor")?;
- let size = get_partition_size(&file)?;
- let fd = file.as_raw_fd();
- files.push(file);
+ let image_files = partition
+ .images
+ .iter()
+ .map(|image| {
+ let file = image
+ .as_ref()
+ .try_clone()
+ .context("Failed to clone partition image file descriptor")?;
+
+ let size = get_partition_size(&file)?;
+ let fd = file.as_raw_fd();
+ let partition_info_file =
+ PartitionFileInfo { path: format!("/proc/self/fd/{}", fd).into(), size };
+ files.push(file);
+ Ok(partition_info_file)
+ })
+ .collect::<Result<Vec<_>, Error>>()?;
Ok(PartitionInfo {
label: partition.label.to_owned(),
- files: vec![PartitionFileInfo {
- path: format!("/proc/self/fd/{}", fd).into(),
- size,
- }],
+ files: image_files,
partition_type: ImagePartitionType::LinuxFilesystem,
writable: partition.writable,
})