mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 20:54:26 +00:00
qmp: add hotplug memory
It adds size of MiB memory to the guest. Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
e66a9b481b
commit
54caf7810b
35
qemu/qmp.go
35
qemu/qmp.go
@ -846,3 +846,38 @@ func (q *QMP) ExecSetMigrateArguments(ctx context.Context, url string) error {
|
|||||||
|
|
||||||
return q.executeCommand(ctx, "migrate", args, nil)
|
return q.executeCommand(ctx, "migrate", args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecHotplugMemory adds size of MiB memory to the guest
|
||||||
|
func (q *QMP) ExecHotplugMemory(ctx context.Context, qomtype, id, mempath string, size int) error {
|
||||||
|
args := map[string]interface{}{
|
||||||
|
"qom-type": qomtype,
|
||||||
|
"id": id,
|
||||||
|
"props": map[string]interface{}{"size": uint64(size) << 20},
|
||||||
|
}
|
||||||
|
if mempath != "" {
|
||||||
|
args["mem-path"] = mempath
|
||||||
|
}
|
||||||
|
err := q.executeCommand(ctx, "object-add", args, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
q.cfg.Logger.Errorf("Unable to hotplug memory device: %v", err)
|
||||||
|
err = q.executeCommand(ctx, "object-del", map[string]interface{}{"id": id}, nil)
|
||||||
|
if err != nil {
|
||||||
|
q.cfg.Logger.Warningf("Unable to clean up memory object: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
args = map[string]interface{}{
|
||||||
|
"driver": "pc-dimm",
|
||||||
|
"id": "dimm" + id,
|
||||||
|
"memdev": id,
|
||||||
|
}
|
||||||
|
err = q.executeCommand(ctx, "device_add", args, nil)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@ -927,3 +927,21 @@ func TestExecSetMigrateArguments(t *testing.T) {
|
|||||||
q.Shutdown()
|
q.Shutdown()
|
||||||
<-disconnectedCh
|
<-disconnectedCh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks hotplug memory
|
||||||
|
func TestExecHotplugMemory(t *testing.T) {
|
||||||
|
connectedCh := make(chan *QMPVersion)
|
||||||
|
disconnectedCh := make(chan struct{})
|
||||||
|
buf := newQMPTestCommandBuffer(t)
|
||||||
|
buf.AddCommand("object-add", nil, "return", nil)
|
||||||
|
buf.AddCommand("device_add", nil, "return", nil)
|
||||||
|
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||||
|
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||||
|
checkVersion(t, connectedCh)
|
||||||
|
err := q.ExecHotplugMemory(context.Background(), "memory-backend-ram", "mem0", "", 128)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error: %v\n", err)
|
||||||
|
}
|
||||||
|
q.Shutdown()
|
||||||
|
<-disconnectedCh
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user