Skip to content

Commit bbe4f97

Browse files
authored
Merge pull request #46 from mdlayher/mdl-rewrite
vsock: rewrite on top of socket.Conn
2 parents 10d5918 + 6d7f2c5 commit bbe4f97

33 files changed

+539
-1548
lines changed

.builds/freebsd.yml

-17
This file was deleted.

.builds/go-1.10.yml

-23
This file was deleted.

.builds/go-1.11.yml

-23
This file was deleted.

.builds/go-stable.yml

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Linux Integration Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
jobs:
12+
build:
13+
strategy:
14+
matrix:
15+
go-version: [1.12, 1.17]
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: ${{ matrix.go-version }}
23+
id: go
24+
25+
- name: Check out code into the Go module directory
26+
uses: actions/checkout@v2
27+
28+
- name: Load the vhost_vsock kernel module
29+
run: sudo modprobe vhost_vsock
30+
31+
- name: Change the permissions of /dev/vsock for integration tests
32+
run: sudo chmod 666 /dev/vsock
33+
34+
- name: Run integration tests
35+
run: go test -v -race -run TestIntegration ./...
36+

.github/workflows/linux-test.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Linux Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
jobs:
12+
build:
13+
strategy:
14+
matrix:
15+
go-version: [1.12, 1.17]
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: ${{ matrix.go-version }}
23+
id: go
24+
25+
- name: Check out code into the Go module directory
26+
uses: actions/checkout@v2
27+
28+
- name: Run tests
29+
run: go test -v -race ./...

.github/workflows/macos-test.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: macOS Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
jobs:
12+
build:
13+
strategy:
14+
matrix:
15+
go-version: [1.12]
16+
runs-on: macos-latest
17+
18+
steps:
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: ${{ matrix.go-version }}
23+
id: go
24+
25+
- name: Check out code into the Go module directory
26+
uses: actions/checkout@v2
27+
28+
- name: Run tests
29+
run: go test -v -race ./...

.github/workflows/static-analysis.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Static Analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
jobs:
12+
build:
13+
strategy:
14+
matrix:
15+
go-version: [1.17]
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: ${{ matrix.go-version }}
23+
id: go
24+
25+
- name: Check out code into the Go module directory
26+
uses: actions/checkout@v2
27+
28+
- name: Install staticcheck
29+
run: go install honnef.co/go/tools/cmd/staticcheck@latest
30+
31+
- name: Print staticcheck version
32+
run: staticcheck -version
33+
34+
- name: Run staticcheck
35+
run: staticcheck ./...
36+
37+
- name: Run go vet
38+
run: go vet ./...

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# CHANGELOG
2+
3+
## Unreleased
4+
5+
## v1.0.0
6+
7+
**This is the first release of package vsock that only supports Go 1.12+.
8+
Users on older versions of Go must use an unstable release.**
9+
10+
- Initial stable commit!
11+
- [API change]: the `vsock.Dial` and `vsock.Listen` constructors now accept an
12+
optional `*vsock.Config` parameter to enable future expansion in v1.x.x
13+
without prompting further breaking API changes. Because `vsock.Config` has no
14+
options as of this release, `nil` may be passed in all call sites to fix
15+
existing code upon upgrading to v1.0.0.
16+
- [New API]: the `vsock.ListenContextID` function can be used to create a
17+
`*vsock.Listener` which is bound to an explicit context ID address, rather
18+
than inferring one automatically as `vsock.Listen` does.

LICENSE.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
MIT License
2-
===========
1+
# MIT License
32

4-
Copyright (C) 2017 Matt Layher
3+
Copyright (C) 2017-2022 Matt Layher
54

65
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
76

README.md

+14-23
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
1-
# vsock [![builds.sr.ht status](https://builds.sr.ht/~mdlayher/vsock.svg)](https://builds.sr.ht/~mdlayher/vsock?) [![GoDoc](https://godoc.org/github.com/mdlayher/vsock?status.svg)](https://godoc.org/github.com/mdlayher/vsock) [![Go Report Card](https://goreportcard.com/badge/github.com/mdlayher/vsock)](https://goreportcard.com/report/github.com/mdlayher/vsock)
1+
# vsock [![Test Status](https://github.com/mdlayher/vsock/workflows/Linux%20Test/badge.svg)](https://github.com/mdlayher/vsock/actions) [![Go Reference](https://pkg.go.dev/badge/github.com/mdlayher/vsock.svg)](https://pkg.go.dev/github.com/mdlayher/vsock) [![Go Report Card](https://goreportcard.com/badge/github.com/mdlayher/vsock)](https://goreportcard.com/report/github.com/mdlayher/vsock)
22

33
Package `vsock` provides access to Linux VM sockets (`AF_VSOCK`) for
44
communication between a hypervisor and its virtual machines. MIT Licensed.
55

66
For more information about VM sockets, check out my blog about
7-
[Linux VM sockets in Go](https://medium.com/@mdlayher/linux-vm-sockets-in-go-ea11768e9e67).
7+
[Linux VM sockets in Go](https://mdlayher.com/blog/linux-vm-sockets-in-go/).
88

9-
## Go version support
10-
11-
This package supports varying levels of functionality depending on the version
12-
of Go used during compilation. The `Listener` and `Conn` types produced by this
13-
package are backed by non-blocking I/O, in order to integrate with Go's runtime
14-
network poller in Go 1.11+. Additional functionality is available starting in Go
15-
1.12+. The older Go 1.10 is only supported in a blocking-only mode.
9+
## Stability
1610

17-
A comprehensive list of functionality for supported Go versions can be found on
18-
[package vsock's GoDoc page](https://godoc.org/github.com/mdlayher/vsock#hdr-Go_version_support).
11+
See the [CHANGELOG](./CHANGELOG.md) file for a description of changes between
12+
releases.
1913

20-
## Stability
14+
This package has a stable v1 API and any future breaking changes will prompt
15+
the release of a new major version. Features and bug fixes will continue to
16+
occur in the v1.x.x series.
2117

22-
At this time, package `vsock` is in a pre-v1.0.0 state. Changes are being made
23-
which may impact the exported API of this package and others in its ecosystem.
18+
In order to reduce the maintenance burden, this package is only supported on
19+
Go 1.12+. Older versions of Go lack critical features and APIs which are
20+
necessary for this package to function correctly.
2421

25-
**If you depend on this package in your application, please use Go modules when
26-
building your application.**
22+
**If you depend on this package in your applications, please use Go modules.**
2723

2824
## Requirements
2925

26+
**It's possible these requirements are out of date. PRs are welcome.**
27+
3028
To make use of VM sockets with QEMU and virtio-vsock, you must have:
3129

3230
- a Linux hypervisor with kernel 4.8+
@@ -53,10 +51,3 @@ Check out the
5351
[QEMU wiki page on virtio-vsock](http://wiki.qemu-project.org/Features/VirtioVsock)
5452
for more details. More detail on setting up this environment will be provided
5553
in the future.
56-
57-
## Usage
58-
59-
To try out VM sockets and see an example of how they work, see
60-
[cmd/vscp](https://github.com/mdlayher/vsock/tree/master/cmd/vscp).
61-
This command shows usage of the `vsock.ListenStream` and `vsock.DialStream`
62-
APIs, and allows users to easily test VM sockets on their systems.

cmd/vscp/main.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ import (
1414
"time"
1515

1616
"github.com/mdlayher/vsock"
17-
"github.com/mdlayher/vsock/internal/vsutil"
1817
)
1918

20-
var (
21-
flagVerbose = flag.Bool("v", false, "enable verbose logging to stderr")
22-
)
19+
var flagVerbose = flag.Bool("v", false, "enable verbose logging to stderr")
2320

2421
func main() {
2522
var (
@@ -96,7 +93,9 @@ func receive(target string, port uint32, timeout time.Duration, checksum bool) {
9693

9794
logf("opening listener: %d", port)
9895

99-
l, err := vsock.Listen(port)
96+
// TODO(mdlayher): support vsock.Local binds for testing.
97+
98+
l, err := vsock.Listen(port, nil)
10099
if err != nil {
101100
fatalf("failed to listen: %v", err)
102101
}
@@ -106,7 +105,7 @@ func receive(target string, port uint32, timeout time.Duration, checksum bool) {
106105
log.Printf("receive: listening: %s", l.Addr())
107106

108107
// Accept a single connection, and receive stream from that connection.
109-
c, err := vsutil.Accept(l, timeout)
108+
c, err := l.Accept()
110109
if err != nil {
111110
fatalf("failed to accept: %v", err)
112111
}
@@ -173,7 +172,7 @@ func send(target string, cid, port uint32, checksum bool) {
173172
logf("dialing: %d.%d", cid, port)
174173

175174
// Dial a remote server and send a stream to that server.
176-
c, err := vsock.Dial(cid, port)
175+
c, err := vsock.Dial(cid, port, nil)
177176
if err != nil {
178177
fatalf("failed to dial: %v", err)
179178
}

0 commit comments

Comments
 (0)