-
Notifications
You must be signed in to change notification settings - Fork 764
[applevz] Basic vm functionality #4653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4653 +/- ##
==========================================
+ Coverage 87.64% 87.65% +0.02%
==========================================
Files 254 254
Lines 14158 14170 +12
==========================================
+ Hits 12408 12420 +12
Misses 1750 1750 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements basic virtual machine functionality for the AppleVZ backend using the Apple Virtualization Framework. It enables creation, starting, stopping, and suspending of VMs with proper state management and memory handling across the Objective-C++/C++ boundary.
Changes:
- Implemented core VM lifecycle operations (start, shutdown, suspend) and state management for AppleVZ
- Added Objective-C++ bridge code with proper memory management using CFError and toll-free bridged types
- Extended qemu-img utilities to support raw image format conversion and format detection for resize operations
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/platform/backends/applevz/applevz_virtual_machine.cpp | Core VM implementation with lifecycle management and state transitions |
| src/platform/backends/applevz/applevz_bridge.mm | Objective-C++ bridge providing VM operations interface to C++ code |
| src/platform/backends/applevz/cf_error.h | Custom CFError wrapper with RAII semantics for memory management |
| src/platform/backends/applevz/applevz_wrapper.cpp | C++ wrapper layer delegating to bridge functions |
| src/platform/backends/qemu/qemu_img_utils.cpp | Added raw conversion and image format detection capabilities |
| tests/unit/applevz/test_applevz_virtual_machine.cpp | Comprehensive unit tests for VM state transitions and operations |
| tests/unit/qemu/test_qemu_img_utils.cpp | Updated tests for resize with format detection and raw conversion |
| include/multipass/virtual_machine.h | Added fmt formatter for VM state enum |
Comments suppressed due to low confidence (1)
src/platform/backends/applevz/applevz_bridge.mm:1
- The log message uses '>' instead of the expected '->' used in other log messages in this file. This should be '->>' for consistency with the logging pattern used elsewhere.
/*
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Many of these operations can be performed asynchronously, but Multipass is not so we block until the operation has finished.
Keep ObjCpp code in the bridge and return custom Cpp types for objects that need to be accessed outside the bridge. This helps maintain memory safety and reference counting.
We prefer to contain logic in the VM class so it can be properly tested.
e4917fe to
9be4d92
Compare
This PR implement the creation of virtual machines as well as some of the basic functions for manipulating the state of a virtual machine using the Apple Virtualization Framework. This includes:
start()shutdown(ShutdownPolicy shutdown_policy)suspend()to memory for nowAll Objective-C++ code, other helper functions needed to perform these actions, and unit tests for these functions are also included.
On top of being able to manually manage memory, Objective-C uses Automatic Reference Counting (ARC) where the system reference counting to automatically insert appropriate memory management method calls for you at compile-time. However, in order for objects to persist across the Objective-C/C++ boundary, we must use some types from the
CoreFoundationlibrary instead of theFoundationlibrary, i.e.,CFErrorRefoverNSError, also known as Toll-Free Bridged Types. This allows us to control who owns the object and avoids having ARC and the Objective-C memory management system release memory before we are done with it. There are several macros that are used to tell the compiler about the ownership semantics of an object, but we mainly use:__bridge; for objects such as theVMHandlewhich were declared on the C++ side and where we don't want ownership to transfer when casting thestd::shared_ptr<void>to virtualization framework virtual machine type;VZVirtualMachine.__bridge_retained: for objects that were created on the Objective-C side and for which we want to persist even after the block in which they were created finishes. We are responsible for manually freeing this type of object, so care must be taken in order when using this macro to prevent memory leaks. The use of this macro here is limited to returning errors from the Objective-C side to the C++ side through the use of the custom C++ type;CFError, which automatically callsCFReleasewhen destructed.The other unique memory management mechanism that is used is the
autoreleasepoolblock. This is used in special circumstances when a large number of temporary autoreleased object. Theautoreleasepoolsends anautoreleasemessage to all objects in that block which are immediately released instead of at the end of the current event-loop iteration. This prevents temporary objects from unnecessarily accumulating and causing excessive overhead.Additional reading:
MULTI-2258
MULTI-2260
MULTI-2261
MULTI-2266
MULTI-2267
MULTI-2268