diff options
author | Frederick Mayle <fmayle@google.com> | 2024-04-23 18:55:41 -0700 |
---|---|---|
committer | Frederick Mayle <fmayle@google.com> | 2024-04-25 13:04:55 -0700 |
commit | b601a7aeaf2790b0ecf9444ecbd10caa6fad2b8d (patch) | |
tree | 6279d2cb81d11dcd58a5e5464bffba8ebf8d432b /host/libs/vm_manager/crosvm_manager.cpp | |
parent | 5f933bd71909b14816adc0131572296b39d430b5 (diff) | |
download | cuttlefish-b601a7aeaf2790b0ecf9444ecbd10caa6fad2b8d.tar.gz |
use `crosvm resume` to detect RESTORE_COMPLETE
Instead of waiting for logcat output, run the `crosvm resume` command to
block until the vCPUs have begun.
CvdBootStateMachine starts a thread to run that command. When the
command completes, it notifies the other CvdBootStateMachine thread via
a pipe, which then sends a value to the `--daemon` parent indicating
that the restore is complete (using the same mechanism as for a normal
boot complete).
Bug: 333111958
Test: m && (stop_cvd; launch_cvd --noresume --enable-sandbox=false --daemon) && snapshot_util_cvd --subcmd=snapshot_take --auto_suspend --force --snapshot_path=$HOME/cf-snapshot && stop_cvd && launch_cvd --snapshot_path=$HOME/cf-snapshot
Change-Id: Ia515c0485a7d6ec5cda611a7423674422b9f28d5
Diffstat (limited to 'host/libs/vm_manager/crosvm_manager.cpp')
-rw-r--r-- | host/libs/vm_manager/crosvm_manager.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/host/libs/vm_manager/crosvm_manager.cpp b/host/libs/vm_manager/crosvm_manager.cpp index c26da188e..899e39653 100644 --- a/host/libs/vm_manager/crosvm_manager.cpp +++ b/host/libs/vm_manager/crosvm_manager.cpp @@ -880,5 +880,32 @@ Result<std::vector<MonitorCommand>> CrosvmManager::StartCommands( return commands; } +Result<void> CrosvmManager::WaitForRestoreComplete() const { + auto instance = CF_EXPECT(CuttlefishConfig::Get())->ForDefaultInstance(); + + // Wait for the control socket to exist. It is created early in crosvm's + // startup sequence, but the process may not even have been exec'd by CF at + // this point. + while (!FileExists(instance.CrosvmSocketPath())) { + usleep(50000); // 50 ms, arbitrarily chosen + } + + // Ask crosvm to resume the VM. crosvm promises to not complete this command + // until the vCPUs are started (even if it was never suspended to begin + // with). + auto infop = CF_EXPECT(Execute( + std::vector<std::string>{ + instance.crosvm_binary(), + "resume", + instance.CrosvmSocketPath(), + "--full", + }, + SubprocessOptions(), WEXITED)); + CF_EXPECT_EQ(infop.si_code, CLD_EXITED); + CF_EXPECTF(infop.si_status == 0, "crosvm resume returns non zero code {}", + infop.si_status); + return {}; +} + } // namespace vm_manager } // namespace cuttlefish |