feat: expose runtime directory-sharing devices with live share swap#216
Open
jlagedo wants to merge 2 commits into
Open
feat: expose runtime directory-sharing devices with live share swap#216jlagedo wants to merge 2 commits into
jlagedo wants to merge 2 commits into
Conversation
Add VZVirtualMachine.directorySharingDevices() and a runtime VirtioFileSystemDevice type with SetShare(), so a host can change which directories a guest sees on a running VM (macOS 12+) without recreating it. Apple supports this (VZVirtioFileSystemDevice.share is get/set on the runtime device, reachable via VZVirtualMachine.directorySharingDevices), but the binding only exposed the config-time setter. Mirrors the existing SocketDevices() pattern: NSArray -> ToPointerSlice -> wrap each pointer with the VM's serial dispatch queue. SetShare runs the mutation on that queue, as the framework requires. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Expose a Share() getter on the running file system device so the directory share set via SetShare (or at configuration time) can be read back, restoring get/set symmetry with the VZVirtioFileSystemDevice.share property. The getter reads on the VM's serial dispatch queue and reconstructs the concrete *SingleDirectoryShare or *MultipleDirectoryShare via Obj-C class introspection. Add integration tests covering the runtime directory-sharing API: - TestDirectorySharingDevices verifies a configured device is returned. - TestVirtioFileSystemDeviceSetShare boots a VM, asserts the reported share type, hot-swaps single -> multiple share at runtime, and verifies the guest sees the swapped-in content after remount. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds support for runtime directory sharing: reading the directory-sharing devices off a running
VirtualMachineand hot-swapping the directories a guest sees without recreating the VM.The Virtualization framework exposes
VZVirtioFileSystemDeviceas a live device on a started VM, with a read/writeshareproperty (macOS 12+). Until nowvzonly surfaced the configuration side (VirtioFileSystemDeviceConfiguration), so callers could set a share beforeStart()but never change it afterwards. This PR fills that gap.What's added
VirtualMachine.DirectorySharingDevices() []*VirtioFileSystemDeviceReturns the live directory-sharing devices on a running VM. Mirrors the existing
SocketDevices()/USBControllers()accessors. Returnsnilon macOS < 12.VirtioFileSystemDevice— the runtime device (distinct fromVirtioFileSystemDeviceConfiguration):SetShare(share DirectoryShare)— swaps the directory share on the running device. The mutation runs on the VM's serial dispatch queue, as the framework requires for allVZVirtualMachineinteractions.Share() DirectoryShare— reads back the current share (also on the VM queue), reconstructing the concrete*SingleDirectoryShare/*MultipleDirectorySharevia Obj-C class introspection. Restores get/set symmetry with the underlyingshareproperty.This lets a host add or remove the directories a guest sees while the VM keeps running.
Implementation notes
socket.go,usb.go): the device wrapper stores the VM'sdispatchQueueand embeds*pointer.VirtioSocketDevice. Only the value returned byShare()isretained on the C side and released via a Go finalizer, since it crosses the boundary as an owned object.dispatch_syncon the VM queue, consistent with the memory-balloon runtime device.Testing
make download_kernel && make test(run locally on Apple silicon, codesigned):TestDirectorySharingDevices— a configured file-system device is returned from a created VM.TestVirtioFileSystemDeviceSetShare— boots a VM with a single-directory share, assertsShare()reports*SingleDirectoryShare, mounts in-guest and sees the file; then hot-swaps to a multiple-directory share viaSetShare, assertsShare()now reports*MultipleDirectoryShare, remounts in-guest and verifies the swapped-in content is visible while the original file is gone.Existing
TestSingleDirectoryShare/TestMultipleDirectorySharecontinue to pass (no regression).go vet ./...is clean.Test plan
go build ./...go vet ./...make test(new + existing shared-directory tests pass, codesigned, real guest)🤖 Generated with Claude Code