mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 20:24:31 +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: #152 Signed-off-by: bin liu <bin@hyper.sh>
This commit is contained in:
parent
d7836877e9
commit
b8cd705901
13
qemu/qmp.go
13
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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user