File tree Expand file tree Collapse file tree 6 files changed +73
-34
lines changed
Expand file tree Collapse file tree 6 files changed +73
-34
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,6 @@ phaul-test: $(TEST_BINARIES)
4040clean :
4141 @rm -f $(TEST_BINARIES )
4242 @rm -rf image
43- @rm -f rpc/rpc.proto stats/stats.proto
4443
4544rpc/rpc.proto :
4645 curl -sSL https://raw.githubusercontent.com/checkpoint-restore/criu/master/images/rpc.proto -o $@
Original file line number Diff line number Diff line change 1+ package magic
2+
3+ const (
4+ ImgCommonMagic = 0x54564319 /* Sarov (a.k.a. Arzamas-16) */
5+ ImgServiceMagic = 0x55105940 /* Zlatoust */
6+ StatsMagic = 0x57093306 /* Ostashkov */
7+
8+ PrimaryMagicOffset = 0x0
9+ SecondaryMagicOffset = 0x4
10+ SizeOffset = 0x8
11+ PayloadOffset = 0xC
12+ )
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ func (pc *Client) Migrate() error {
110110 return err
111111 }
112112
113- st , err := criuGetDumpStats (imgDir )
113+ st , err := stats . CriuGetDumpStats (imgDir )
114114 if err != nil {
115115 return err
116116 }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ package stats
2+
3+ const (
4+ StatsDump = "stats-dump"
5+ StatsRestore = "stats-restore"
6+ )
Original file line number Diff line number Diff line change 1+ package stats
2+
3+ import (
4+ "encoding/binary"
5+ "errors"
6+ "io/ioutil"
7+ "os"
8+ "path/filepath"
9+
10+ "github.com/checkpoint-restore/go-criu/v5/magic"
11+ "google.golang.org/protobuf/proto"
12+ )
13+
14+ func readStatisticsFile (imgDir * os.File , fileName string ) (* StatsEntry , error ) {
15+ buf , err := ioutil .ReadFile (filepath .Join (imgDir .Name (), fileName ))
16+ if err != nil {
17+ return nil , err
18+ }
19+
20+ if binary .LittleEndian .Uint32 (buf [magic .PrimaryMagicOffset :magic .SecondaryMagicOffset ]) != magic .ImgServiceMagic {
21+ return nil , errors .New ("Primary magic not found" )
22+ }
23+
24+ if binary .LittleEndian .Uint32 (buf [magic .SecondaryMagicOffset :magic .SizeOffset ]) != magic .StatsMagic {
25+ return nil , errors .New ("Secondary magic not found" )
26+ }
27+
28+ payloadSize := binary .LittleEndian .Uint32 (buf [magic .SizeOffset :magic .PayloadOffset ])
29+
30+ st := & StatsEntry {}
31+ if err := proto .Unmarshal (buf [magic .PayloadOffset :magic .PayloadOffset + payloadSize ], st ); err != nil {
32+ return nil , err
33+ }
34+
35+ return st , nil
36+ }
37+
38+ func CriuGetDumpStats (imgDir * os.File ) (* DumpStatsEntry , error ) {
39+ st , err := readStatisticsFile (imgDir , StatsDump )
40+ if err != nil {
41+ return nil , err
42+ }
43+
44+ return st .GetDump (), nil
45+ }
46+
47+ func CriuGetRestoreStats (imgDir * os.File ) (* RestoreStatsEntry , error ) {
48+ st , err := readStatisticsFile (imgDir , StatsRestore )
49+ if err != nil {
50+ return nil , err
51+ }
52+
53+ return st .GetRestore (), nil
54+ }
You can’t perform that action at this time.
0 commit comments