diff --git a/qemu/qmp.go b/qemu/qmp.go index fc3f1e3f3a..53ba105a8e 100644 --- a/qemu/qmp.go +++ b/qemu/qmp.go @@ -268,7 +268,7 @@ func (q *QMP) readLoop(fromVMCh chan<- []byte) { for scanner.Scan() { line := scanner.Bytes() if q.cfg.Logger.V(1) { - q.cfg.Logger.Infof("%s", string(line)) + q.cfg.Logger.Infof("read from QMP: %s", string(line)) } // Since []byte channel type transfer slice info(include slice underlying array pointer, len, cap) @@ -1654,3 +1654,14 @@ func (q *QMP) ExecQomGet(ctx context.Context, path, property string) (interface{ return response, nil } + +// ExecuteDumpGuestMemory dump guest memory to host +func (q *QMP) ExecuteDumpGuestMemory(ctx context.Context, protocol string, paging bool, format string) error { + args := map[string]interface{}{ + "protocol": protocol, + "paging": paging, + "format": format, + } + + return q.executeCommand(ctx, "dump-guest-memory", args, nil) +} diff --git a/qemu/qmp_test.go b/qemu/qmp_test.go index 14bfd24921..60457453cb 100644 --- a/qemu/qmp_test.go +++ b/qemu/qmp_test.go @@ -1794,3 +1794,22 @@ func TestExecQomGet(t *testing.T) { q.Shutdown() <-disconnectedCh } + +// Checks dump-guest-memory +func TestExecuteDumpGuestMemory(t *testing.T) { + connectedCh := make(chan *QMPVersion) + disconnectedCh := make(chan struct{}) + buf := newQMPTestCommandBuffer(t) + buf.AddCommand("dump-guest-memory", nil, "return", nil) + cfg := QMPConfig{Logger: qmpTestLogger{}} + q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh) + checkVersion(t, connectedCh) + + err := q.ExecuteDumpGuestMemory(context.Background(), "file:/tmp/dump.xxx.yyy", false, "elf") + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + q.Shutdown() + <-disconnectedCh +}