mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 04:04:45 +00:00
qemu/qmp: implement function to hotplug serial ports
Implement function to hotplug virtio serial ports, the serial ports are visible in the guest at the directory /dev/virtio-ports. Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
ca46f21f3f
commit
80ed88edb1
14
qemu/qmp.go
14
qemu/qmp.go
@ -986,3 +986,17 @@ func (q *QMP) ExecuteCharDevUnixSocketAdd(ctx context.Context, id, path string,
|
||||
}
|
||||
return q.executeCommand(ctx, "chardev-add", args, nil)
|
||||
}
|
||||
|
||||
// ExecuteVirtSerialPortAdd adds a virtserialport.
|
||||
// id is an identifier for the virtserialport, name is a name for the virtserialport and
|
||||
// it will be visible in the VM, chardev is the character device id previously added.
|
||||
func (q *QMP) ExecuteVirtSerialPortAdd(ctx context.Context, id, name, chardev string) error {
|
||||
args := map[string]interface{}{
|
||||
"driver": VirtioSerialPort,
|
||||
"id": id,
|
||||
"name": name,
|
||||
"chardev": chardev,
|
||||
}
|
||||
|
||||
return q.executeCommand(ctx, "device_add", args, nil)
|
||||
}
|
||||
|
@ -1057,3 +1057,20 @@ func TestExecuteCharDevUnixSocketAdd(t *testing.T) {
|
||||
q.Shutdown()
|
||||
<-disconnectedCh
|
||||
}
|
||||
|
||||
// Checks virtio serial port hotplug
|
||||
func TestExecuteVirtSerialPortAdd(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.ExecuteVirtSerialPortAdd(context.Background(), "foo", "foo.channel", "foo")
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %v", err)
|
||||
}
|
||||
q.Shutdown()
|
||||
<-disconnectedCh
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user