runtime: add geust memory dump

When guest panic, dump guest kernel memory to host filesystem.
And also includes:
- hypervisor config
- hypervisor version
- and state of sandbox

Fixes: #1012

Signed-off-by: bin liu <bin@hyper.sh>
This commit is contained in:
bin liu
2020-10-21 14:09:14 +08:00
parent 5b065eb599
commit 40418f6d88
16 changed files with 345 additions and 46 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2020 Ant Financial
// Copyright (c) 2020 Ant Group
//
// SPDX-License-Identifier: Apache-2.0
//
@@ -6,7 +6,11 @@
package utils
import (
"fmt"
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"
)
@@ -31,3 +35,48 @@ func GzipAccepted(header http.Header) bool {
func String2Pointer(s string) *string {
return &s
}
// RunCommandFull returns the commands space-trimmed standard output and
// error on success. Note that if the command fails, the requested output will
// still be returned, along with an error.
func RunCommandFull(args []string, includeStderr bool) (string, error) {
cmd := exec.Command(args[0], args[1:]...)
var err error
var bytes []byte
if includeStderr {
bytes, err = cmd.CombinedOutput()
} else {
bytes, err = cmd.Output()
}
trimmed := strings.TrimSpace(string(bytes))
return trimmed, err
}
// RunCommand returns the commands space-trimmed standard output on success
func RunCommand(args []string) (string, error) {
return RunCommandFull(args, false)
}
// EnsureDir check if a directory exist, if not then create it
func EnsureDir(path string, mode os.FileMode) error {
if !filepath.IsAbs(path) {
return fmt.Errorf("Not an absolute path: %s", path)
}
if fi, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
if err = os.MkdirAll(path, mode); err != nil {
return err
}
} else {
return err
}
} else if !fi.IsDir() {
return fmt.Errorf("Not a directory: %s", path)
}
return nil
}