1
0
mirror of https://github.com/kata-containers/kata-containers.git synced 2025-04-29 12:14:48 +00:00

qmp: add dump-guest-memory support

By adding `dump-guest-memory` command, user can get kernel
memory dump when guest panic occurred.

Fixes: 

Signed-off-by: bin liu <bin@hyper.sh>
This commit is contained in:
bin liu 2020-10-19 17:09:12 +08:00
parent d7836877e9
commit b8cd705901
2 changed files with 31 additions and 1 deletions

View File

@ -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)
}

View File

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