Revert "libvmclient: Take VmCallback in VmInstance::start()"
Revert submission 3408863
Reason for revert: Likely culprit for b/391356639 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.
Reverted changes: /q/submissionid:3408863
Change-Id: Id9436b9557e0fd4cbc94df9f22ba35132619aa91
diff --git a/libs/libavf/src/lib.rs b/libs/libavf/src/lib.rs
index 50c5e2e..6532ace 100644
--- a/libs/libavf/src/lib.rs
+++ b/libs/libavf/src/lib.rs
@@ -373,7 +373,7 @@
let console_in = get_file_from_fd(console_in_fd);
let log = get_file_from_fd(log_fd);
- match VmInstance::create(service.as_ref(), &config, console_out, console_in, log, None) {
+ match VmInstance::create(service.as_ref(), &config, console_out, console_in, log, None, None) {
Ok(vm) => {
// SAFETY: `vm_ptr` is assumed to be a valid, non-null pointer to a mutable raw pointer.
// `vm` is the only reference here and `vm_ptr` takes ownership.
@@ -398,7 +398,7 @@
// SAFETY: `vm` is assumed to be a valid, non-null pointer returned by
// `AVirtualMachine_createRaw`. It's the only reference to the object.
let vm = unsafe { &*vm };
- match vm.start(None) {
+ match vm.start() {
Ok(_) => 0,
Err(e) => {
error!("AVirtualMachine_start failed: {e:?}");
diff --git a/libs/libcompos_common/compos_client.rs b/libs/libcompos_common/compos_client.rs
index c2b4936..6872582 100644
--- a/libs/libcompos_common/compos_client.rs
+++ b/libs/libcompos_common/compos_client.rs
@@ -148,14 +148,19 @@
// Let logs go to logcat.
let (console_fd, log_fd) = (None, None);
+ let callback = Box::new(Callback {});
let instance = VmInstance::create(
- service, &config, console_fd, /* console_in_fd */ None, log_fd,
+ service,
+ &config,
+ console_fd,
+ /* console_in_fd */ None,
+ log_fd,
/* dump_dt */ None,
+ Some(callback),
)
.context("Failed to create VM")?;
- let callback = Box::new(Callback {});
- instance.start(Some(callback))?;
+ instance.start()?;
let ready = instance.wait_until_ready(TIMEOUTS.vm_max_time_to_ready);
if ready == Err(VmWaitError::Finished) && debug_level != DebugLevel::NONE {
diff --git a/libs/libservice_vm_manager/src/lib.rs b/libs/libservice_vm_manager/src/lib.rs
index 77e7a4a..0f322bb 100644
--- a/libs/libservice_vm_manager/src/lib.rs
+++ b/libs/libservice_vm_manager/src/lib.rs
@@ -152,7 +152,7 @@
let vsock_listener = VsockListener::bind_with_cid_port(VMADDR_CID_HOST, vm_type.port())?;
// Starts the service VM.
- vm.start(None).context("Failed to start service VM")?;
+ vm.start().context("Failed to start service VM")?;
info!("Service VM started");
// Accepts the connection from the service VM.
@@ -245,7 +245,8 @@
let console_in = None;
let log = Some(android_log_fd()?);
let dump_dt = None;
- VmInstance::create(service.as_ref(), &config, console_out, console_in, log, dump_dt)
+ let callback = None;
+ VmInstance::create(service.as_ref(), &config, console_out, console_in, log, dump_dt, callback)
.context("Failed to create service VM")
}
diff --git a/libs/libvmclient/src/lib.rs b/libs/libvmclient/src/lib.rs
index 2c6abb5..8dd3cd3 100644
--- a/libs/libvmclient/src/lib.rs
+++ b/libs/libvmclient/src/lib.rs
@@ -209,6 +209,7 @@
console_in: Option<File>,
log: Option<File>,
dump_dt: Option<File>,
+ callback: Option<Box<dyn VmCallback + Send + Sync>>,
) -> BinderResult<Self> {
let console_out = console_out.map(ParcelFileDescriptor::new);
let console_in = console_in.map(ParcelFileDescriptor::new);
@@ -225,19 +226,20 @@
let cid = vm.getCid()?;
+ // Register callback before starting VM, in case it dies immediately.
let state = Arc::new(Monitor::new(VmState::default()));
+ let callback = BnVirtualMachineCallback::new_binder(
+ VirtualMachineCallback { state: state.clone(), client_callback: callback },
+ BinderFeatures::default(),
+ );
+ vm.registerCallback(&callback)?;
let death_recipient = wait_for_binder_death(&mut vm.as_binder(), state.clone())?;
Ok(Self { vm, cid, state, _death_recipient: death_recipient })
}
/// Starts the VM.
- pub fn start(&self, callback: Option<Box<dyn VmCallback + Send + Sync>>) -> BinderResult<()> {
- let callback = BnVirtualMachineCallback::new_binder(
- VirtualMachineCallback { state: self.state.clone(), client_callback: callback },
- BinderFeatures::default(),
- );
- self.vm.registerCallback(&callback)?;
+ pub fn start(&self) -> BinderResult<()> {
self.vm.start()
}