diff --git a/microdroid/payload/README.md b/microdroid/payload/README.md index b76eead7..35502c17 100644 --- a/microdroid/payload/README.md +++ b/microdroid/payload/README.md @@ -7,7 +7,7 @@ mounts/activates APK/APEXes and executes a binary within the APK. Payload disk has 1 + N(number of APEX/APK payloads) partitions. -The first partition is a "metadata" partition which describes other partitions. +The first partition is a "payload-metadata" partition which describes other partitions. And APEXes and an APK are following as separate partitions. For now, the order of partitions are important. diff --git a/microdroid/payload/metadata/Android.bp b/microdroid/payload/metadata/Android.bp index d3ec625d..e4c7692d 100644 --- a/microdroid/payload/metadata/Android.bp +++ b/microdroid/payload/metadata/Android.bp @@ -10,6 +10,7 @@ rust_library { prefer_rlib: true, edition: "2018", rustlibs: [ + "libanyhow", "libmicrodroid_metadata_proto_rust", "libprotobuf", ], diff --git a/microdroid/payload/metadata/src/lib.rs b/microdroid/payload/metadata/src/lib.rs index 9c97411e..eb9d90d0 100644 --- a/microdroid/payload/metadata/src/lib.rs +++ b/microdroid/payload/metadata/src/lib.rs @@ -18,15 +18,15 @@ //! 4 bytes : size(N) in big endian //! N bytes : protobuf message for Metadata +use anyhow::Result; use protobuf::Message; -use std::io; use std::io::Read; use std::io::Write; pub use microdroid_metadata::metadata::{ApexPayload, ApkPayload, Metadata}; /// Reads a metadata from a reader -pub fn read_metadata(mut r: T) -> io::Result { +pub fn read_metadata(mut r: T) -> Result { let mut buf = [0u8; 4]; r.read_exact(&mut buf)?; let size = i32::from_be_bytes(buf); @@ -34,9 +34,10 @@ pub fn read_metadata(mut r: T) -> io::Result { } /// Writes a metadata to a writer -pub fn write_metadata(metadata: &Metadata, mut w: T) -> io::Result<()> { +pub fn write_metadata(metadata: &Metadata, mut w: T) -> Result<()> { let mut buf = Vec::new(); metadata.write_to_writer(&mut buf)?; w.write_all(&(buf.len() as i32).to_be_bytes())?; - w.write_all(&buf) + w.write_all(&buf)?; + Ok(()) } diff --git a/microdroid/payload/mk_payload.cc b/microdroid/payload/mk_payload.cc index c31dcff4..b27683c7 100644 --- a/microdroid/payload/mk_payload.cc +++ b/microdroid/payload/mk_payload.cc @@ -302,7 +302,7 @@ Result MakePayload(const Config& config, const std::string& metadata_file, // put metadata at the first partition partitions.push_back(MultipleImagePartition{ - .label = "metadata", + .label = "payload-metadata", .image_file_paths = {metadata_file}, .type = kLinuxFilesystem, .read_only = true, diff --git a/microdroid/sepolicy/system/private/apkdmverity.te b/microdroid/sepolicy/system/private/apkdmverity.te index c6160bef..8974a1d5 100644 --- a/microdroid/sepolicy/system/private/apkdmverity.te +++ b/microdroid/sepolicy/system/private/apkdmverity.te @@ -6,7 +6,7 @@ type apkdmverity_exec, exec_type, file_type, system_file_type; # allow domain transition from init init_daemon_domain(apkdmverity) -# apkdmverity accesses /dev/block/by-name/metadata which points to +# apkdmverity accesses "payload metadata disk" which points to # a /dev/vd* block device file. allow apkdmverity block_device:dir r_dir_perms; allow apkdmverity block_device:lnk_file r_file_perms; diff --git a/microdroid/sepolicy/system/private/microdroid_manager.te b/microdroid/sepolicy/system/private/microdroid_manager.te index 81a68399..53c63ae9 100644 --- a/microdroid/sepolicy/system/private/microdroid_manager.te +++ b/microdroid/sepolicy/system/private/microdroid_manager.te @@ -6,8 +6,7 @@ type microdroid_manager_exec, exec_type, file_type, system_file_type; # allow domain transition from init init_daemon_domain(microdroid_manager) -# microdroid_manager accesses /dev/block/by-name/metadata which points to -# a /dev/vd* block device file. +# microdroid_manager accesses a virtual disk block device to read VM payload allow microdroid_manager block_device:dir r_dir_perms; allow microdroid_manager block_device:lnk_file r_file_perms; allow microdroid_manager vd_device:blk_file r_file_perms; diff --git a/microdroid_manager/src/metadata.rs b/microdroid_manager/src/metadata.rs index 81d9cc4b..86a9e3ed 100644 --- a/microdroid_manager/src/metadata.rs +++ b/microdroid_manager/src/metadata.rs @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Payload metadata from /dev/block/by-name/metadata +//! Payload metadata from /dev/block/by-name/payload-metadata +use anyhow::Result; use log::info; use microdroid_metadata::{read_metadata, Metadata}; use std::fs::File; -use std::io; -const METADATA_PATH: &str = "/dev/block/by-name/metadata"; +const PAYLOAD_METADATA_PATH: &str = "/dev/block/by-name/payload-metadata"; -/// loads payload metadata from /dev/block/by-name/metadata -pub fn load() -> io::Result { +/// loads payload metadata from /dev/block/by-name/paylaod-metadata +pub fn load() -> Result { info!("loading payload metadata..."); - read_metadata(File::open(METADATA_PATH)?) + read_metadata(File::open(PAYLOAD_METADATA_PATH)?) } diff --git a/virtualizationservice/src/payload.rs b/virtualizationservice/src/payload.rs index 18e7de51..76c55de5 100644 --- a/virtualizationservice/src/payload.rs +++ b/virtualizationservice/src/payload.rs @@ -158,7 +158,7 @@ pub fn make_payload_disk( // put metadata at the first partition let mut partitions = vec![Partition { - label: "metadata".to_owned(), + label: "payload-metadata".to_owned(), paths: vec![metadata_path], writable: false, }];