Allocate each VM an instance_id
Introduce a 64 bytes' long instance_id. When the VM is created, this is
requested from virtualization service, which randomly allocates it.
While it does that, it also logs the user & the package name.
The app persists this allocated instance_id in a file `instance_id` in
its directory for the vm instance (along with instance.img &
storage.img). When the VirtualMachine is run, this is an input into the
VM via DT.
This patch modifies Compos & vm binary to work with the instance_id.
flagging: instance_id allocation request is conditional to flag build
time flag llpvm_changes, no file `instance_id` is created if the flag is
off. `instanceId` is all 0s if the flag is off.
Bug: 291213394
Test: atest MicrodroidHostTest
Test: atest MicrodroidTests
Test: atest ComposHostTestCases
Test: Look for instance_id logged by VS
Change-Id: Ie8e25b9510e27362d4580c55c1bd557143ff7d0e
diff --git a/vm/src/main.rs b/vm/src/main.rs
index 355e193..063f992 100644
--- a/vm/src/main.rs
+++ b/vm/src/main.rs
@@ -22,6 +22,8 @@
CpuTopology::CpuTopology, IVirtualizationService::IVirtualizationService,
PartitionType::PartitionType, VirtualMachineAppConfig::DebugLevel::DebugLevel,
};
+#[cfg(not(llpvm_changes))]
+use anyhow::anyhow;
use anyhow::{Context, Error};
use binder::{ProcessState, Strong};
use clap::{Args, Parser};
@@ -162,6 +164,11 @@
/// Path to the instance image. Created if not exists.
instance: PathBuf,
+ /// Path to file containing instance_id. Required iff llpvm feature is enabled.
+ #[cfg(llpvm_changes)]
+ #[arg(long = "instance-id-file")]
+ instance_id: PathBuf,
+
/// Path to VM config JSON within APK (e.g. assets/vm_config.json)
#[arg(long)]
config_path: Option<String>,
@@ -192,6 +199,27 @@
fn extra_apks(&self) -> &[PathBuf] {
&[]
}
+
+ #[cfg(llpvm_changes)]
+ fn instance_id(&self) -> Result<PathBuf, Error> {
+ Ok(self.instance_id.clone())
+ }
+
+ #[cfg(not(llpvm_changes))]
+ fn instance_id(&self) -> Result<PathBuf, Error> {
+ Err(anyhow!("LLPVM feature is disabled, --instance_id flag not supported"))
+ }
+
+ #[cfg(llpvm_changes)]
+ fn set_instance_id(&mut self, instance_id_file: PathBuf) -> Result<(), Error> {
+ self.instance_id = instance_id_file;
+ Ok(())
+ }
+
+ #[cfg(not(llpvm_changes))]
+ fn set_instance_id(&mut self, _: PathBuf) -> Result<(), Error> {
+ Err(anyhow!("LLPVM feature is disabled, --instance_id flag not supported"))
+ }
}
#[derive(Args, Default)]