mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 12:14:48 +00:00
qemu/qmp: Add netdev_add with chardev support
In order to be able to hotplug network devices such as vhost user net, we need to be able to define a previously declared chardev as a parameter of this new network device. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
cfdbc15148
commit
21504d31ff
16
qemu/qmp.go
16
qemu/qmp.go
@ -764,6 +764,22 @@ func (q *QMP) ExecuteNetdevAdd(ctx context.Context, netdevType, netdevID, ifname
|
|||||||
return q.executeCommand(ctx, "netdev_add", args, nil)
|
return q.executeCommand(ctx, "netdev_add", args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecuteNetdevChardevAdd adds a Net device to a QEMU instance
|
||||||
|
// using the netdev_add command. netdevID is the id of the device to add.
|
||||||
|
// Must be valid QMP identifier.
|
||||||
|
func (q *QMP) ExecuteNetdevChardevAdd(ctx context.Context, netdevType, netdevID, chardev string, queues int) error {
|
||||||
|
args := map[string]interface{}{
|
||||||
|
"type": netdevType,
|
||||||
|
"id": netdevID,
|
||||||
|
"chardev": chardev,
|
||||||
|
}
|
||||||
|
if queues > 1 {
|
||||||
|
args["queues"] = queues
|
||||||
|
}
|
||||||
|
|
||||||
|
return q.executeCommand(ctx, "netdev_add", args, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// ExecuteNetdevAddByFds adds a Net device to a QEMU instance
|
// ExecuteNetdevAddByFds adds a Net device to a QEMU instance
|
||||||
// using the netdev_add command by fds and vhostfds. netdevID is the id of the device to add.
|
// using the netdev_add command by fds and vhostfds. netdevID is the id of the device to add.
|
||||||
// Must be valid QMP identifier.
|
// Must be valid QMP identifier.
|
||||||
|
@ -425,6 +425,28 @@ func TestQMPNetdevAdd(t *testing.T) {
|
|||||||
<-disconnectedCh
|
<-disconnectedCh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks that the netdev_add command is correctly sent.
|
||||||
|
//
|
||||||
|
// We start a QMPLoop, send the netdev_add command and stop the loop.
|
||||||
|
//
|
||||||
|
// The netdev_add command should be correctly sent and the QMP loop should
|
||||||
|
// exit gracefully.
|
||||||
|
func TestQMPNetdevChardevAdd(t *testing.T) {
|
||||||
|
connectedCh := make(chan *QMPVersion)
|
||||||
|
disconnectedCh := make(chan struct{})
|
||||||
|
buf := newQMPTestCommandBuffer(t)
|
||||||
|
buf.AddCommand("netdev_add", nil, "return", nil)
|
||||||
|
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||||
|
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||||
|
q.version = checkVersion(t, connectedCh)
|
||||||
|
err := q.ExecuteNetdevChardevAdd(context.Background(), "tap", "br0", "chr0", 8)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error %v", err)
|
||||||
|
}
|
||||||
|
q.Shutdown()
|
||||||
|
<-disconnectedCh
|
||||||
|
}
|
||||||
|
|
||||||
// Checks that the netdev_add command with fds is correctly sent.
|
// Checks that the netdev_add command with fds is correctly sent.
|
||||||
//
|
//
|
||||||
// We start a QMPLoop, send the netdev_add command with fds and stop the loop.
|
// We start a QMPLoop, send the netdev_add command with fds and stop the loop.
|
||||||
|
Loading…
Reference in New Issue
Block a user