Get odrefresh in composd working.
composd now keeps track of the running instance of the CompOS VM and
will proxy compilation requests to it. (I was going to return an
ICompOsService, but mixing RPC and normal binder isn't allowed.) This
avoids giving odrefresh any access to vsock_socket at all.
pvm_exec now connects to composd rather than directly to the VM if a
magic CID value is specified. (It also logs errors more volubly, which
was helpful.)
Modify pvm_exec
Bug: 186126194
Test: Run composd_cmd, artifacts generated
Change-Id: If80cf53287bd1bac9c97c992da7e121b1a64aaaa
diff --git a/compos/composd/src/service.rs b/compos/composd/src/service.rs
index 7fc9ab0..e3a1be0 100644
--- a/compos/composd/src/service.rs
+++ b/compos/composd/src/service.rs
@@ -17,20 +17,26 @@
//! Implementation of IIsolatedCompilationService, called from system server when compilation is
//! desired.
-use crate::compos_instance::CompOsInstance;
+use crate::instance_manager::InstanceManager;
use crate::odrefresh;
use android_system_composd::aidl::android::system::composd::IIsolatedCompilationService::{
BnIsolatedCompilationService, IIsolatedCompilationService,
};
use android_system_composd::binder::{self, BinderFeatures, Interface, Status, Strong};
use anyhow::{bail, Context, Result};
+use compos_aidl_interface::aidl::com::android::compos::{
+ CompilationResult::CompilationResult, FdAnnotation::FdAnnotation,
+};
use log::{error, info};
use std::ffi::CString;
-pub struct IsolatedCompilationService {}
+#[derive(Default)]
+pub struct IsolatedCompilationService {
+ instance_manager: InstanceManager,
+}
pub fn new_binder() -> Strong<dyn IIsolatedCompilationService> {
- let service = IsolatedCompilationService {};
+ let service = IsolatedCompilationService::default();
BnIsolatedCompilationService::new_binder(service, BinderFeatures::default())
}
@@ -38,8 +44,18 @@
impl IIsolatedCompilationService for IsolatedCompilationService {
fn runForcedCompile(&self) -> binder::Result<()> {
+ // TODO - check caller is system or shell/root?
to_binder_result(self.do_run_forced_compile())
}
+
+ fn compile(
+ &self,
+ args: &[String],
+ fd_annotation: &FdAnnotation,
+ ) -> binder::Result<CompilationResult> {
+ // TODO - check caller is odrefresh
+ to_binder_result(self.do_compile(args, fd_annotation))
+ }
}
fn to_binder_result<T>(result: Result<T>) -> binder::Result<T> {
@@ -53,16 +69,26 @@
fn do_run_forced_compile(&self) -> Result<()> {
info!("runForcedCompile");
- // TODO: Create instance if need be, handle instance failure, prevent
- // multiple instances running
- let comp_os = CompOsInstance::start_current_instance().context("Starting CompOS")?;
+ let comp_os = self.instance_manager.start_current_instance().context("Starting CompOS")?;
- let exit_code = odrefresh::run_forced_compile(comp_os.cid())?;
+ let exit_code = odrefresh::run_forced_compile()?;
if exit_code != odrefresh::ExitCode::CompilationSuccess {
bail!("Unexpected odrefresh result: {:?}", exit_code);
}
+ // The instance is needed until odrefresh is finished
+ drop(comp_os);
+
Ok(())
}
+
+ fn do_compile(
+ &self,
+ args: &[String],
+ fd_annotation: &FdAnnotation,
+ ) -> Result<CompilationResult> {
+ let compos = self.instance_manager.get_running_service()?;
+ compos.compile(args, fd_annotation).context("Compiling")
+ }
}