Rename payload metadata partition

/dev/block/by-name/metadata is used by others as well.

Renamed it as payload-metadata.

Bug: 191097666
Test: MicrodroidHostTestCases
Change-Id: I873ee2acbe38772e59c96b3904023ac0d1573621
This commit is contained in:
Jooyung Han 2021-07-06 20:48:38 +09:00
parent 9900f3d733
commit 14e5a8e3bc
8 changed files with 17 additions and 16 deletions

View File

@ -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. 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. And APEXes and an APK are following as separate partitions.
For now, the order of partitions are important. For now, the order of partitions are important.

View File

@ -10,6 +10,7 @@ rust_library {
prefer_rlib: true, prefer_rlib: true,
edition: "2018", edition: "2018",
rustlibs: [ rustlibs: [
"libanyhow",
"libmicrodroid_metadata_proto_rust", "libmicrodroid_metadata_proto_rust",
"libprotobuf", "libprotobuf",
], ],

View File

@ -18,15 +18,15 @@
//! 4 bytes : size(N) in big endian //! 4 bytes : size(N) in big endian
//! N bytes : protobuf message for Metadata //! N bytes : protobuf message for Metadata
use anyhow::Result;
use protobuf::Message; use protobuf::Message;
use std::io;
use std::io::Read; use std::io::Read;
use std::io::Write; use std::io::Write;
pub use microdroid_metadata::metadata::{ApexPayload, ApkPayload, Metadata}; pub use microdroid_metadata::metadata::{ApexPayload, ApkPayload, Metadata};
/// Reads a metadata from a reader /// Reads a metadata from a reader
pub fn read_metadata<T: Read>(mut r: T) -> io::Result<Metadata> { pub fn read_metadata<T: Read>(mut r: T) -> Result<Metadata> {
let mut buf = [0u8; 4]; let mut buf = [0u8; 4];
r.read_exact(&mut buf)?; r.read_exact(&mut buf)?;
let size = i32::from_be_bytes(buf); let size = i32::from_be_bytes(buf);
@ -34,9 +34,10 @@ pub fn read_metadata<T: Read>(mut r: T) -> io::Result<Metadata> {
} }
/// Writes a metadata to a writer /// Writes a metadata to a writer
pub fn write_metadata<T: Write>(metadata: &Metadata, mut w: T) -> io::Result<()> { pub fn write_metadata<T: Write>(metadata: &Metadata, mut w: T) -> Result<()> {
let mut buf = Vec::new(); let mut buf = Vec::new();
metadata.write_to_writer(&mut buf)?; metadata.write_to_writer(&mut buf)?;
w.write_all(&(buf.len() as i32).to_be_bytes())?; w.write_all(&(buf.len() as i32).to_be_bytes())?;
w.write_all(&buf) w.write_all(&buf)?;
Ok(())
} }

View File

@ -302,7 +302,7 @@ Result<void> MakePayload(const Config& config, const std::string& metadata_file,
// put metadata at the first partition // put metadata at the first partition
partitions.push_back(MultipleImagePartition{ partitions.push_back(MultipleImagePartition{
.label = "metadata", .label = "payload-metadata",
.image_file_paths = {metadata_file}, .image_file_paths = {metadata_file},
.type = kLinuxFilesystem, .type = kLinuxFilesystem,
.read_only = true, .read_only = true,

View File

@ -6,7 +6,7 @@ type apkdmverity_exec, exec_type, file_type, system_file_type;
# allow domain transition from init # allow domain transition from init
init_daemon_domain(apkdmverity) 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. # a /dev/vd* block device file.
allow apkdmverity block_device:dir r_dir_perms; allow apkdmverity block_device:dir r_dir_perms;
allow apkdmverity block_device:lnk_file r_file_perms; allow apkdmverity block_device:lnk_file r_file_perms;

View File

@ -6,8 +6,7 @@ type microdroid_manager_exec, exec_type, file_type, system_file_type;
# allow domain transition from init # allow domain transition from init
init_daemon_domain(microdroid_manager) init_daemon_domain(microdroid_manager)
# microdroid_manager accesses /dev/block/by-name/metadata which points to # microdroid_manager accesses a virtual disk block device to read VM payload
# a /dev/vd* block device file.
allow microdroid_manager block_device:dir r_dir_perms; allow microdroid_manager block_device:dir r_dir_perms;
allow microdroid_manager block_device:lnk_file r_file_perms; allow microdroid_manager block_device:lnk_file r_file_perms;
allow microdroid_manager vd_device:blk_file r_file_perms; allow microdroid_manager vd_device:blk_file r_file_perms;

View File

@ -12,17 +12,17 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // 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 log::info;
use microdroid_metadata::{read_metadata, Metadata}; use microdroid_metadata::{read_metadata, Metadata};
use std::fs::File; 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 /// loads payload metadata from /dev/block/by-name/paylaod-metadata
pub fn load() -> io::Result<Metadata> { pub fn load() -> Result<Metadata> {
info!("loading payload metadata..."); info!("loading payload metadata...");
read_metadata(File::open(METADATA_PATH)?) read_metadata(File::open(PAYLOAD_METADATA_PATH)?)
} }

View File

@ -158,7 +158,7 @@ pub fn make_payload_disk(
// put metadata at the first partition // put metadata at the first partition
let mut partitions = vec![Partition { let mut partitions = vec![Partition {
label: "metadata".to_owned(), label: "payload-metadata".to_owned(),
paths: vec![metadata_path], paths: vec![metadata_path],
writable: false, writable: false,
}]; }];