Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept on the usage of crit features for reading memory pages #69

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion checkpointctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ func show(cmd *cobra.Command, args []string) error {
files = append(
files,
filepath.Join(metadata.CheckpointDirectory, "pstree.img"),
// All core-*.img files
// All core-*.img, pagemap-*.img, mm-*.img, and pages-*.img files
filepath.Join(metadata.CheckpointDirectory, "core-"),
filepath.Join(metadata.CheckpointDirectory, "pagemap-"),
filepath.Join(metadata.CheckpointDirectory, "mm-"),
filepath.Join(metadata.CheckpointDirectory, "pages-"),
)
}

Expand Down
35 changes: 29 additions & 6 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import (

metadata "github.com/checkpoint-restore/checkpointctl/lib"
"github.com/checkpoint-restore/go-criu/v6/crit"
"github.com/checkpoint-restore/go-criu/v6/crit/images"
statsImg "github.com/checkpoint-restore/go-criu/v6/crit/images/stats"
"github.com/containers/storage/pkg/archive"
"github.com/olekukonko/tablewriter"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/xlab/treeprint"
)

var pageSize = os.Getpagesize()

type containerMetadata struct {
Name string `json:"name,omitempty"`
Attempt uint32 `json:"attempt,omitempty"`
Expand Down Expand Up @@ -176,14 +178,14 @@ func showContainerCheckpoints(tasks []task) error {

if psTree {
// The image files reside in a subdirectory called "checkpoint"
c := crit.New("", "", filepath.Join(tasks[0].outputDir, "checkpoint"), false, false)
c := crit.New(nil, nil, filepath.Join(tasks[0].outputDir, "checkpoint"), false, false)
// Get process tree with CRIT
psTree, err := c.ExplorePs()
if err != nil {
return fmt.Errorf("failed to get process tree: %w", err)
}

renderPsTree(psTree, ci.Name)
renderPsTree(psTree, ci.Name, tasks[0].outputDir)
}
}

Expand Down Expand Up @@ -236,7 +238,7 @@ func renderMounts(specDump *spec.Spec) {
table.Render()
}

func renderDumpStats(dumpStats *images.DumpStatsEntry) {
func renderDumpStats(dumpStats *statsImg.DumpStatsEntry) {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Freezing Time",
Expand All @@ -258,7 +260,7 @@ func renderDumpStats(dumpStats *images.DumpStatsEntry) {
table.Render()
}

func renderPsTree(psTree *crit.PsTree, containerName string) {
func renderPsTree(psTree *crit.PsTree, containerName, checkpointDir string) {
var tree treeprint.Tree
if containerName == "" {
containerName = "Container"
Expand All @@ -269,7 +271,13 @@ func renderPsTree(psTree *crit.PsTree, containerName string) {
// processes as child nodes of the branch.
var processNodes func(treeprint.Tree, *crit.PsTree)
processNodes = func(tree treeprint.Tree, root *crit.PsTree) {
node := tree.AddMetaBranch(root.PId, root.Comm)
// Try to retrieve the full command-line from memory pages
cmdline, err := getCmdline(checkpointDir, root.PID)
if err != nil || cmdline == "" {
cmdline = root.Comm
}

node := tree.AddMetaBranch(root.PID, cmdline)
for _, child := range root.Children {
processNodes(node, child)
}
Expand Down Expand Up @@ -408,3 +416,18 @@ func iterateTarArchive(archiveInput string, callback func(r *tar.Reader, header

return nil
}

func getCmdline(checkpointDir string, pid uint32) (cmdline string, err error) {
mr, err := crit.NewMemoryReader(filepath.Join(checkpointDir, metadata.CheckpointDirectory), pid, pageSize)
if err != nil {
return
}

buffer, err := mr.GetPsArgs()
if err != nil {
return
}

cmdline = strings.Join(strings.Split(buffer.String(), "\x00"), " ")
return
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/checkpoint-restore/checkpointctl
go 1.18

require (
github.com/checkpoint-restore/go-criu/v6 v6.3.0
github.com/checkpoint-restore/go-criu/v6 v6.3.1-0.20230616083337-4c639ba51621
github.com/containers/storage v1.46.1
github.com/olekukonko/tablewriter v0.0.5
github.com/opencontainers/runtime-spec v1.1.0-rc.2
Expand All @@ -23,7 +23,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)
15 changes: 6 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E=
github.com/checkpoint-restore/go-criu/v6 v6.3.0 h1:mIdrSO2cPNWQY1truPg6uHLXyKHk3Z5Odx4wjKOASzA=
github.com/checkpoint-restore/go-criu/v6 v6.3.0/go.mod h1:rrRTN/uSwY2X+BPRl/gkulo9gsKOSAeVp9/K2tv7xZI=
github.com/checkpoint-restore/go-criu/v6 v6.3.1-0.20230616083337-4c639ba51621 h1:Tc2lRrm+JMCwsbDH9WFZ3R8qF0S2J6AiJNxTfo+CyZg=
github.com/checkpoint-restore/go-criu/v6 v6.3.1-0.20230616083337-4c639ba51621/go.mod h1:uuIaCJCnWcRzK88xoScsiKHpwBlF8uChRbyhi/BZiZg=
github.com/cilium/ebpf v0.7.0/go.mod h1:/oI2+1shJiTGAMgl6/RgJr36Eo1jzrRcAWbcXO2usCA=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/containers/storage v1.46.1 h1:GcAe8J0Y6T2CF70fXPojUpnme6zXamuzGCrNujVtIGE=
Expand All @@ -23,7 +23,6 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/klauspost/compress v1.16.4 h1:91KN02FnsOYhuunwU4ssRe8lc2JosWmizWa91B5v1PU=
Expand Down Expand Up @@ -56,7 +55,6 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down Expand Up @@ -85,8 +83,8 @@ golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand All @@ -95,11 +93,10 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1N
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion test/checkpointctl.bats
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function teardown() {
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl show "$TEST_TMP_DIR2"/test.tar --stats
[ "$status" -eq 1 ]
[[ ${lines[6]} == *"Unknown magic"* ]]
[[ ${lines[6]} == *"unknown magic"* ]]
}

@test "Run checkpointctl show with tar file and --stats and valid stats-dump" {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading