Add vsock support for MacOS VM#60
Open
Fred78290 wants to merge 4 commits into
Open
Conversation
Author
|
@SuperQ Done |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds macOS (darwin) support and introduces context-aware dialing while tightening build constraints so non-implemented platforms use stubs.
Changes:
- Exclude darwin from the
!linux“others” build-tagged files and add darwin-specific conn/listener implementations. - Add
DialWithContextand threadcontext.Contextthrough the internaldialimplementations. - Add darwin-specific tests for
opErrorbehavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| vsock_others_test.go | Updates build tags to exclude darwin from the non-linux test stub. |
| vsock_others.go | Updates build tags and removes local errUnimplemented definition. |
| vsock_darwin_test.go | Adds darwin test coverage for opError normalization. |
| vsock.go | Adds DialWithContext, threads context into dial, and relocates errUnimplemented. |
| listener_darwin.go | Introduces a darwin net.Listener implementation using mdlayher/socket. |
| fd_darwin.go | Adds darwin implementations of contextID and isErrno. |
| conn_linux.go | Updates Linux dial to accept a context and use it for Connect. |
| conn_darwin.go | Adds darwin dial implementation using VSOCK sockets. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+10
to
+20
| func contextID() (uint32, error) { | ||
| if fd, err := unix.Socket(unix.AF_VSOCK, unix.SOCK_STREAM, 0); err != nil { | ||
| return 2, nil | ||
| } else { | ||
| defer unix.Close(fd) | ||
|
|
||
| cid, err := unix.IoctlGetInt(fd, unix.IOCTL_VM_SOCKETS_GET_LOCAL_CID) | ||
|
|
||
| return uint32(cid), err | ||
| } | ||
| } |
Comment on lines
183
to
+198
| func Dial(contextID, port uint32, cfg *Config) (*Conn, error) { | ||
| c, err := dial(contextID, port, cfg) | ||
| return dial(context.Background(), contextID, port, cfg) | ||
| } | ||
|
|
||
| // DialWithContext connects to the address on the named network using | ||
| // the provided context. | ||
| // | ||
| // The provided Context must be non-nil. If the context expires before | ||
| // the connection is complete, an error is returned. Once successfully | ||
| // connected, any expiration of the context will not affect the | ||
| // connection. | ||
| // | ||
| // See func Dial for a description of the contextID and port | ||
| // parameters. | ||
| func DialWithContext(ctx context.Context, contextID, port uint32, cfg *Config) (*Conn, error) { | ||
| c, err := dial(ctx, contextID, port, cfg) |
Comment on lines
+54
to
+55
| // listen is the entry point for Listen on Linux. | ||
| func listen(cid, port uint32, _ *Config) (*Listener, error) { |
Comment on lines
+90
to
+91
| // fileListener is the entry point for FileListener on Linux. | ||
| func fileListener(f *os.File) (*Listener, error) { |
Comment on lines
+118
to
+119
| // All errors should wrapped with os.SyscallError. | ||
| return nil, os.NewSyscallError("listen", unix.EINVAL) |
| // methods. | ||
| type conn = socket.Conn | ||
|
|
||
| // dial is the entry point for Dial on Linux. |
Comment on lines
+22
to
+33
| // isErrno determines if an error a matches UNIX error number. | ||
| func isErrno(err error, errno int) bool { | ||
| switch errno { | ||
| case ebadf: | ||
| return err == unix.EBADF | ||
| case enotconn: | ||
| return err == unix.ENOTCONN | ||
| default: | ||
| panicf("vsock: isErrno called with unhandled error number parameter: %d", errno) | ||
| return false | ||
| } | ||
| } |
Comment on lines
+190
to
+193
| // The provided Context must be non-nil. If the context expires before | ||
| // the connection is complete, an error is returned. Once successfully | ||
| // connected, any expiration of the context will not affect the | ||
| // connection. |
| // | ||
| // See func Dial for a description of the contextID and port | ||
| // parameters. | ||
| func DialWithContext(ctx context.Context, contextID, port uint32, cfg *Config) (*Conn, error) { |
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.
Since MacOS 13, it is able to virtualize MacOS with vsock support in the guest with Virtualization framework.
This PR propose to enable vsock support inside MacOS VM.
VSock on host is not yet available.