From f700a97beef89be2d759a1616a7364e92bc8ec77 Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Fri, 13 Jul 2018 12:05:19 -0500 Subject: [PATCH] qemu/qmp: implement function to hotplug vsock-pci Implement function to hotplug vsocks, vsocks are needed to communicate processes are running inside the VM with processes are running on the host. Signed-off-by: Julio Montes --- qemu/qemu.go | 3 +++ qemu/qmp.go | 10 ++++++++++ qemu/qmp_test.go | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/qemu/qemu.go b/qemu/qemu.go index 41381d80ee..e911364846 100644 --- a/qemu/qemu.go +++ b/qemu/qemu.go @@ -82,6 +82,9 @@ const ( // VirtioSerialPort is the serial port device driver. VirtioSerialPort = "virtserialport" + + // VHostVSockPCI is the vhost vsock pci driver. + VHostVSockPCI = "vhost-vsock-pci" ) // ObjectType is a string representing a qemu object type. diff --git a/qemu/qmp.go b/qemu/qmp.go index 37334e99e2..32a59ef04b 100644 --- a/qemu/qmp.go +++ b/qemu/qmp.go @@ -881,3 +881,13 @@ func (q *QMP) ExecHotplugMemory(ctx context.Context, qomtype, id, mempath string return err } + +// ExecutePCIVSockAdd adds a vhost-vsock-pci bus +func (q *QMP) ExecutePCIVSockAdd(ctx context.Context, id, guestCID string) error { + args := map[string]interface{}{ + "driver": VHostVSockPCI, + "id": id, + "guest-cid": guestCID, + } + return q.executeCommand(ctx, "device_add", args, nil) +} diff --git a/qemu/qmp_test.go b/qemu/qmp_test.go index f5b472d741..c87822ae8e 100644 --- a/qemu/qmp_test.go +++ b/qemu/qmp_test.go @@ -945,3 +945,20 @@ func TestExecHotplugMemory(t *testing.T) { q.Shutdown() <-disconnectedCh } + +// Checks vsock-pci hotplug +func TestExecutePCIVSockAdd(t *testing.T) { + connectedCh := make(chan *QMPVersion) + disconnectedCh := make(chan struct{}) + buf := newQMPTestCommandBuffer(t) + buf.AddCommand("device_add", nil, "return", nil) + cfg := QMPConfig{Logger: qmpTestLogger{}} + q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh) + checkVersion(t, connectedCh) + err := q.ExecutePCIVSockAdd(context.Background(), "vsock-pci0", "3") + if err != nil { + t.Fatalf("Unexpected error %v", err) + } + q.Shutdown() + <-disconnectedCh +}