compsvc: Notify VS when we're ready
Once our server socket is listening, notify virtualizationservice that
we're ready.
Modify clients to wait for ready instead of sleeping.
Bug: 186126194
Test: Manually run compos_key_cmd, compos_verify_key
Change-Id: Ibaff4bf22de9de2aa4faff9e81b24c779643b78c
diff --git a/compos/common/compos_client.rs b/compos/common/compos_client.rs
index 6600f6f..c525f40 100644
--- a/compos/common/compos_client.rs
+++ b/compos/common/compos_client.rs
@@ -106,10 +106,7 @@
vm.start()?;
- let cid = vm_state.wait_for_start()?;
-
- // TODO: Use onPayloadReady to avoid this
- thread::sleep(Duration::from_secs(3));
+ let cid = vm_state.wait_until_ready()?;
Ok(VmInstance { service, vm, cid })
}
@@ -214,7 +211,7 @@
self.state_ready.notify_all();
}
- fn set_started(&self, cid: i32) {
+ fn set_ready(&self, cid: i32) {
let mut state = self.mutex.lock().unwrap();
if state.has_died {
return;
@@ -224,10 +221,10 @@
self.state_ready.notify_all();
}
- fn wait_for_start(&self) -> Result<i32> {
+ fn wait_until_ready(&self) -> Result<i32> {
let (state, result) = self
.state_ready
- .wait_timeout_while(self.mutex.lock().unwrap(), Duration::from_secs(10), |state| {
+ .wait_timeout_while(self.mutex.lock().unwrap(), Duration::from_secs(20), |state| {
state.cid.is_none() && !state.has_died
})
.unwrap();
@@ -255,7 +252,6 @@
cid: i32,
stream: Option<&ParcelFileDescriptor>,
) -> BinderResult<()> {
- self.0.set_started(cid);
if let Some(pfd) = stream {
if let Err(e) = start_logging(pfd) {
warn!("Can't log vm output: {}", e);
@@ -266,7 +262,7 @@
}
fn onPayloadReady(&self, cid: i32) -> BinderResult<()> {
- // TODO: Use this to trigger vsock connection
+ self.0.set_ready(cid);
log::info!("VM payload ready, cid = {}", cid);
Ok(())
}