From a555cdda96c88e2840fadf01d28515dad838e4b8 Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Fri, 8 Nov 2024 19:29:51 +0000 Subject: [PATCH] crosvm_control: add crosvm_client_resume_vm_full api The crosvm_client_resume_vm function actually just resumes vcpus of the VM. This is a little bit counter intuitive, but since crosvm_control library provide api and abi stable interface, we can't change the implementation without potentially breaking existing clients. Instead, this patch adds a new crosvm_client_resume_vm_full function which performs a "full" resume of the vm. BUG=b:360102915 TEST=tools/presubmit Change-Id: I28d9a338f24716a62655ba0f7e2db41c148ca0f8 Signed-off-by: Nikita Ioffe Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5999729 Commit-Queue: Daniel Verkamp Reviewed-by: Daniel Verkamp --- crosvm_control/src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crosvm_control/src/lib.rs b/crosvm_control/src/lib.rs index 28f04d252d..48a83ea720 100644 --- a/crosvm_control/src/lib.rs +++ b/crosvm_control/src/lib.rs @@ -114,6 +114,9 @@ pub unsafe extern "C" fn crosvm_client_suspend_vm(socket_path: *const c_char) -> /// Resumes the crosvm instance whose control socket is listening on `socket_path`. /// +/// Note: this function just resumes vcpus of the vm. If you need to perform a full resume, call +/// crosvm_client_resume_vm_full. +/// /// The function returns true on success or false if an error occurred. /// /// # Safety @@ -133,6 +136,29 @@ pub unsafe extern "C" fn crosvm_client_resume_vm(socket_path: *const c_char) -> .unwrap_or(false) } +/// Resumes the crosvm instance whose control socket is listening on `socket_path`. +/// +/// Note: unlike crosvm_client_resume_vm, this function resumes both vcpus and devices. +/// +/// The function returns true on success or false if an error occurred. +/// +/// # Safety +/// +/// Function is unsafe due to raw pointer usage - a null pointer could be passed in. Usage of +/// !raw_pointer.is_null() checks should prevent unsafe behavior but the caller should ensure no +/// null pointers are passed. +#[no_mangle] +pub unsafe extern "C" fn crosvm_client_resume_vm_full(socket_path: *const c_char) -> bool { + catch_unwind(|| { + if let Some(socket_path) = validate_socket_path(socket_path) { + vms_request(&VmRequest::ResumeVm, socket_path).is_ok() + } else { + false + } + }) + .unwrap_or(false) +} + /// Creates an RT vCPU for the crosvm instance whose control socket is listening on `socket_path`. /// /// The function returns true on success or false if an error occurred.