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 +}