Skip to content

Commit 6afccc1

Browse files
authored
Merge pull request #129 from superfly/0.18
support 0.18's new vsock API
2 parents e4d1f82 + d8b0fa4 commit 6afccc1

File tree

10 files changed

+105
-100
lines changed

10 files changed

+105
-100
lines changed

.buildkite/pipeline.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ steps:
4747
commands:
4848
- 'ln -s /var/lib/fc-ci/vmlinux.bin testdata/vmlinux'
4949
- 'ln -s /var/lib/fc-ci/rootfs.ext4 testdata/root-drive.img'
50-
- 'ln -s /usr/local/bin/firecracker-v0.17.0 testdata/firecracker'
51-
- 'ln -s /usr/local/bin/jailer-v0.17.0 testdata/jailer'
50+
- 'ln -s /usr/local/bin/firecracker-v0.18.0 testdata/firecracker'
51+
- 'ln -s /usr/local/bin/jailer-v0.18.0 testdata/jailer'
5252
- "DISABLE_ROOT_TESTS=true FC_TEST_TAP=fc-test-tap${BUILDKITE_BUILD_NUMBER} make test EXTRAGOARGS='-v -count=1'"
5353
agents:
5454
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
@@ -57,8 +57,8 @@ steps:
5757
commands:
5858
- 'ln -s /var/lib/fc-ci/vmlinux.bin testdata/vmlinux'
5959
- 'ln -s /var/lib/fc-ci/rootfs.ext4 testdata/root-drive.img'
60-
- 'cp /usr/local/bin/firecracker-v0.17.0 testdata/firecracker'
61-
- 'cp /usr/local/bin/jailer-v0.17.0 testdata/jailer'
60+
- 'cp /usr/local/bin/firecracker-v0.18.0 testdata/firecracker'
61+
- 'cp /usr/local/bin/jailer-v0.18.0 testdata/jailer'
6262
- 'make -C cni install CNI_BIN_ROOT=$(pwd)/testdata/bin'
6363
- "sudo FC_TEST_TAP=fc-root-tap${BUILDKITE_BUILD_NUMBER} make test EXTRAGOARGS='-v -count=1'"
6464
agents:

client/models/vsock.go

Lines changed: 28 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/operations/operations_client.go

Lines changed: 4 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/operations/put_guest_vsock_by_id_responses.go

Lines changed: 1 addition & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/swagger.yaml

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ swagger: "2.0"
22
info:
33
title: Firecracker API
44
description: RESTful public-facing API.
5-
The API is accessible through HTTP calls on specific URLs carrying JSON modeled data.
5+
The API is accessible through HTTP calls on specific URLs
6+
carrying JSON modeled data.
67
The transport medium is a Unix Domain Socket.
7-
version: 0.17.0
8+
version: 0.18.0
89
termsOfService: ""
910
contact:
1011
@@ -86,39 +87,6 @@ paths:
8687
schema:
8788
$ref: "#/definitions/Error"
8889

89-
/vsocks/{id}:
90-
put:
91-
summary: Creates new vsock with ID specified by the id parameter.
92-
description:
93-
If the vsock device with the specified ID already exists, its body will
94-
be updated based on the new input. May fail if update is not possible.
95-
operationId: putGuestVsockByID
96-
parameters:
97-
- name: id
98-
in: path
99-
description: The id of the vsock device
100-
required: true
101-
type: string
102-
- name: body
103-
in: body
104-
description: Guest vsock properties
105-
required: true
106-
schema:
107-
$ref: "#/definitions/Vsock"
108-
responses:
109-
201:
110-
description: Vsock created
111-
204:
112-
description: Vsock updated
113-
400:
114-
description: Vsock cannot be created due to bad input
115-
schema:
116-
$ref: "#/definitions/Error"
117-
default:
118-
description: Internal server error
119-
schema:
120-
$ref: "#/definitions/Error"
121-
12290
/drives/{drive_id}:
12391
put:
12492
summary: Creates or updates a drive.
@@ -385,6 +353,37 @@ paths:
385353
schema:
386354
$ref: "#/definitions/Error"
387355

356+
/vsocks/{id}:
357+
put:
358+
summary: Creates new vsock with ID specified by the id parameter.
359+
description:
360+
If the vsock device with the specified ID already exists, its body will
361+
be updated based on the new input. May fail if update is not possible.
362+
operationId: putGuestVsockByID
363+
parameters:
364+
- name: id
365+
in: path
366+
description: The id of the vsock device
367+
required: true
368+
type: string
369+
- name: body
370+
in: body
371+
description: Guest vsock properties
372+
required: true
373+
schema:
374+
$ref: "#/definitions/Vsock"
375+
responses:
376+
204:
377+
description: Vsock created/updated
378+
400:
379+
description: Vsock cannot be created due to bad input
380+
schema:
381+
$ref: "#/definitions/Error"
382+
default:
383+
description: Internal server error
384+
schema:
385+
$ref: "#/definitions/Error"
386+
388387
definitions:
389388
BootSource:
390389
type: object
@@ -644,14 +643,30 @@ definitions:
644643
format: int64
645644
description: The amount of milliseconds it takes for the bucket to refill.
646645
minimum: 0
646+
647647
Vsock:
648648
type: object
649+
description:
650+
Defines a vsock device, backed by a set of Unix Domain Sockets, on the host side.
651+
For host-initiated connections, Firecracker will be listening on the Unix socket
652+
identified by the path `uds_path`. Firecracker will create this socket, bind and
653+
listen on it. Host-initiated connections will be performed by connection to this
654+
socket and issuing a connection forwarding request to the desired guest-side vsock
655+
port (i.e. `CONNECT 52\n`, to connect to port 52).
656+
For guest-initiated connections, Firecracker will expect host software to be
657+
bound and listening on Unix sockets at `uds_path_<PORT>`.
658+
E.g. "/path/to/host_vsock.sock_52" for port number 52.
649659
required:
650-
- id
660+
- vsock_id
661+
- guest_cid
662+
- uds_path
651663
properties:
652-
id:
664+
vsock_id:
653665
type: string
654666
guest_cid:
655667
type: integer
656668
minimum: 3
657669
description: Guest Vsock CID
670+
uds_path:
671+
type: string
672+
description: Path to UNIX domain socket, used to proxy vsock connections.

fctesting/firecracker_mock_client.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firecracker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ type PutGuestVsockByIDOpt func(*ops.PutGuestVsockByIDParams)
189189

190190
// PutGuestVsockByID is a wrapper for the swagger generated client to make
191191
// calling of the API easier.
192-
func (f *Client) PutGuestVsockByID(ctx context.Context, vsockID string, vsock *models.Vsock, opts ...PutGuestVsockByIDOpt) (*ops.PutGuestVsockByIDCreated, *ops.PutGuestVsockByIDNoContent, error) {
192+
func (f *Client) PutGuestVsockByID(ctx context.Context, vsock *models.Vsock, opts ...PutGuestVsockByIDOpt) (*ops.PutGuestVsockByIDNoContent, error) {
193193
params := ops.NewPutGuestVsockByIDParams()
194194
params.SetContext(ctx)
195-
params.SetID(vsockID)
195+
params.SetID(StringValue(vsock.VsockID))
196196
params.SetBody(vsock)
197197
for _, opt := range opts {
198198
opt(params)

handlers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ func TestHandlers(t *testing.T) {
592592
{
593593
Handler: AddVsocksHandler,
594594
Client: fctesting.MockClient{
595-
PutGuestVsockByIDFn: func(params *ops.PutGuestVsockByIDParams) (*ops.PutGuestVsockByIDCreated, *ops.PutGuestVsockByIDNoContent, error) {
595+
PutGuestVsockByIDFn: func(params *ops.PutGuestVsockByIDParams) (*ops.PutGuestVsockByIDNoContent, error) {
596596
called = AddVsocksHandler.Name
597-
return &ops.PutGuestVsockByIDCreated{}, &ops.PutGuestVsockByIDNoContent{}, nil
597+
return &ops.PutGuestVsockByIDNoContent{}, nil
598598
},
599599
},
600600
Config: Config{

machine.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ type RateLimiterSet struct {
222222
// VsockDevice represents a vsock connection between the host and the guest
223223
// microVM.
224224
type VsockDevice struct {
225+
// ID defines the vsock's device ID for firecracker.
226+
ID string
225227
// Path defines the filesystem path of the vsock device on the host.
226228
Path string
227229
// CID defines the 32-bit Context Identifier for the vsock device. See
@@ -731,11 +733,12 @@ func (m *Machine) attachDrive(ctx context.Context, dev models.Drive) error {
731733
// addVsock adds a vsock to the instance
732734
func (m *Machine) addVsock(ctx context.Context, dev VsockDevice) error {
733735
vsockCfg := models.Vsock{
734-
GuestCid: int64(dev.CID),
735-
ID: &dev.Path,
736+
GuestCid: Int64(int64(dev.CID)),
737+
UdsPath: &dev.Path,
738+
VsockID: &dev.ID,
736739
}
737740

738-
resp, _, err := m.client.PutGuestVsockByID(ctx, dev.Path, &vsockCfg)
741+
resp, err := m.client.PutGuestVsockByID(ctx, &vsockCfg)
739742
if err != nil {
740743
return err
741744
}

machine_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,11 @@ func testAttachSecondaryDrive(ctx context.Context, t *testing.T, m *Machine) {
561561
}
562562

563563
func testAttachVsock(ctx context.Context, t *testing.T, m *Machine) {
564+
timestamp := strconv.Itoa(int(time.Now().UnixNano()))
564565
dev := VsockDevice{
566+
ID: "1",
565567
CID: 3,
566-
Path: "foo",
568+
Path: timestamp + ".vsock",
567569
}
568570
err := m.addVsock(ctx, dev)
569571
if err != nil {

0 commit comments

Comments
 (0)