linuxkit / virtsock

Go bindings for virtio and Hyper-V sockets
Other
88 stars 30 forks source link
golang hyper-v hyperkit linuxkit socket virtio virtiovsock

This repository contains Go bindings and sample code for Hyper-V sockets and virtio sockets(VSOCK).

Organisation

Building

By default the Go sample code is build in a container. Simply type make.

If you want to build binaries on a local system use make build-binaries.

Testing

There are several examples and tests written both in Go and in C. The C code is Hyper-V sockets specific while the Go code also works with virtio sockets and HyperKit. The respective READMEs contain instructions on how to run the tests, but the simplest way is to use LinuxKit.

Assuming you have LinuxKit installed, the make target make linuxkit will build a custom Linux image which can be booted on HyperKit or on Windows. The custom Linux image contains the test binaries.

macOS

Boot the Linux VM:

linuxkit run hvtest

This should create a directory called ./hvtest-state.

Run the server in the VM and client on the host:

linux$ sock_stress -s vsock -v 1
macos$ ./bin/sock_stress.darwin -c vsock://3 -m hyperkit:./hvtest-state -v 1

Run the server on the host and the client inside the VM:

macos$ ./bin/sock_stress.darwin -s vsock -m hyperkit:./hvtest-state -v 1
linux$ sock_stress -c vsock://2 -v 1

Windows

On Windows we currently only support the server to be run inside the VM and the host connecting to it. In the future we will support running the server on the host as well.

For Linux guests on Windows there are two different implmentations, one in the LinuxKit 4.9.x kernels and one in 4.14.x upstream kernels. They require different protocols to be used. The sock_stress and vsudd programs automatically detect which version to use.

Boot the Linux VM (from an elevated powershell):

linuxkit run -name hvtest hvtest-efi.iso

Run the server in the VM and client on the host:

linux$ sock_stress -v 1 -s hvsock
win$ sock_stress -v 1 -c hvsock://<VM ID>

(where <VM ID> is from the output of: (get-vm hvtest).Id)

Run the server on the host and the client inside the VM:

win$ sock_stress -v 1 -s hvsock
linux$ sock_stress -v 1 -c hvsock://parent

Note: This may fail on the client with receiving unexpected EOFs (see below).

Known limitations