Skip to content

Commit 0ec83bb

Browse files
authored
Merge pull request #97 from rst0git/optimize-stats-rpc
Optimize stats and rpc
2 parents 367faeb + 0609ce9 commit 0ec83bb

File tree

14 files changed

+991
-404
lines changed

14 files changed

+991
-404
lines changed

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ all: build
77
lint:
88
golangci-lint run ./...
99

10-
build:
10+
build: rpc/rpc.pb.go stats/stats.pb.go
1111
$(GO) build -v ./...
1212
# Build crit binary
1313
$(MAKE) -C crit bin/crit
@@ -21,6 +21,18 @@ coverage:
2121
codecov:
2222
$(MAKE) -C test codecov
2323

24+
rpc/rpc.proto:
25+
curl -sSL https://raw.githubusercontent.com/checkpoint-restore/criu/master/images/rpc.proto -o $@
26+
27+
rpc/rpc.pb.go: rpc/rpc.proto
28+
protoc --go_out=. --go_opt=M$^=rpc/ $^
29+
30+
stats/stats.proto:
31+
curl -sSL https://raw.githubusercontent.com/checkpoint-restore/criu/master/images/stats.proto -o $@
32+
33+
stats/stats.pb.go: stats/stats.proto
34+
protoc --go_out=. --go_opt=M$^=stats/ $^
35+
2436
vendor:
2537
GO111MODULE=on $(GO) mod tidy
2638
GO111MODULE=on $(GO) mod vendor

crit/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ update-proto:
1717
rm ./images/*.proto || true
1818
git clone --depth 1 --branch master https://github.com/checkpoint-restore/criu criu-temp
1919
cp criu-temp/images/*.proto ./images/
20-
rm -rf criu-temp
20+
# rpc.proto is not an image and it is used only to communicate criu-service and swrk.
21+
rm -rf criu-temp images/rpc.proto
2122
# To prevent namespace conflict with proto files
2223
# in github.com/letsencrypt/boulder, we prepend
2324
# a prefix to the filenames.

features.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package criu
33
import (
44
"fmt"
55

6-
"github.com/checkpoint-restore/go-criu/v6/crit/images"
6+
"github.com/checkpoint-restore/go-criu/v6/rpc"
77
)
88

99
// Feature checking in go-criu is based on the libcriu feature checking function.
@@ -26,9 +26,9 @@ import (
2626
// Available features will be set to true when the function
2727
// returns successfully. Missing features will be set to false.
2828

29-
func (c *Criu) FeatureCheck(features *images.CriuFeatures) (*images.CriuFeatures, error) {
29+
func (c *Criu) FeatureCheck(features *rpc.CriuFeatures) (*rpc.CriuFeatures, error) {
3030
resp, err := c.doSwrkWithResp(
31-
images.CriuReqType_FEATURE_CHECK,
31+
rpc.CriuReqType_FEATURE_CHECK,
3232
nil,
3333
nil,
3434
features,
@@ -37,7 +37,7 @@ func (c *Criu) FeatureCheck(features *images.CriuFeatures) (*images.CriuFeatures
3737
return nil, err
3838
}
3939

40-
if resp.GetType() != images.CriuReqType_FEATURE_CHECK {
40+
if resp.GetType() != rpc.CriuReqType_FEATURE_CHECK {
4141
return nil, fmt.Errorf("Unexpected CRIU RPC response")
4242
}
4343

main.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strconv"
99
"syscall"
1010

11-
"github.com/checkpoint-restore/go-criu/v6/crit/images"
11+
"github.com/checkpoint-restore/go-criu/v6/rpc"
1212
"google.golang.org/protobuf/proto"
1313
)
1414

@@ -86,7 +86,7 @@ func (c *Criu) sendAndRecv(reqB []byte) ([]byte, int, error) {
8686
return respB, n, nil
8787
}
8888

89-
func (c *Criu) doSwrk(reqType images.CriuReqType, opts *images.CriuOpts, nfy Notify) error {
89+
func (c *Criu) doSwrk(reqType rpc.CriuReqType, opts *rpc.CriuOpts, nfy Notify) error {
9090
resp, err := c.doSwrkWithResp(reqType, opts, nfy, nil)
9191
if err != nil {
9292
return err
@@ -99,10 +99,10 @@ func (c *Criu) doSwrk(reqType images.CriuReqType, opts *images.CriuOpts, nfy Not
9999
return nil
100100
}
101101

102-
func (c *Criu) doSwrkWithResp(reqType images.CriuReqType, opts *images.CriuOpts, nfy Notify, features *images.CriuFeatures) (*images.CriuResp, error) {
103-
var resp *images.CriuResp
102+
func (c *Criu) doSwrkWithResp(reqType rpc.CriuReqType, opts *rpc.CriuOpts, nfy Notify, features *rpc.CriuFeatures) (*rpc.CriuResp, error) {
103+
var resp *rpc.CriuResp
104104

105-
req := images.CriuReq{
105+
req := rpc.CriuReq{
106106
Type: &reqType,
107107
Opts: opts,
108108
}
@@ -135,7 +135,7 @@ func (c *Criu) doSwrkWithResp(reqType images.CriuReqType, opts *images.CriuOpts,
135135
return nil, err
136136
}
137137

138-
resp = &images.CriuResp{}
138+
resp = &rpc.CriuResp{}
139139
err = proto.Unmarshal(respB[:respS], resp)
140140
if err != nil {
141141
return nil, err
@@ -147,7 +147,7 @@ func (c *Criu) doSwrkWithResp(reqType images.CriuReqType, opts *images.CriuOpts,
147147
}
148148

149149
respType := resp.GetType()
150-
if respType != images.CriuReqType_NOTIFY {
150+
if respType != rpc.CriuReqType_NOTIFY {
151151
break
152152
}
153153
if nfy == nil {
@@ -182,7 +182,7 @@ func (c *Criu) doSwrkWithResp(reqType images.CriuReqType, opts *images.CriuOpts,
182182
return resp, err
183183
}
184184

185-
req = images.CriuReq{
185+
req = rpc.CriuReq{
186186
Type: &respType,
187187
NotifySuccess: proto.Bool(true),
188188
}
@@ -192,28 +192,28 @@ func (c *Criu) doSwrkWithResp(reqType images.CriuReqType, opts *images.CriuOpts,
192192
}
193193

194194
// Dump dumps a process
195-
func (c *Criu) Dump(opts *images.CriuOpts, nfy Notify) error {
196-
return c.doSwrk(images.CriuReqType_DUMP, opts, nfy)
195+
func (c *Criu) Dump(opts *rpc.CriuOpts, nfy Notify) error {
196+
return c.doSwrk(rpc.CriuReqType_DUMP, opts, nfy)
197197
}
198198

199199
// Restore restores a process
200-
func (c *Criu) Restore(opts *images.CriuOpts, nfy Notify) error {
201-
return c.doSwrk(images.CriuReqType_RESTORE, opts, nfy)
200+
func (c *Criu) Restore(opts *rpc.CriuOpts, nfy Notify) error {
201+
return c.doSwrk(rpc.CriuReqType_RESTORE, opts, nfy)
202202
}
203203

204204
// PreDump does a pre-dump
205-
func (c *Criu) PreDump(opts *images.CriuOpts, nfy Notify) error {
206-
return c.doSwrk(images.CriuReqType_PRE_DUMP, opts, nfy)
205+
func (c *Criu) PreDump(opts *rpc.CriuOpts, nfy Notify) error {
206+
return c.doSwrk(rpc.CriuReqType_PRE_DUMP, opts, nfy)
207207
}
208208

209209
// StartPageServer starts the page server
210-
func (c *Criu) StartPageServer(opts *images.CriuOpts) error {
211-
return c.doSwrk(images.CriuReqType_PAGE_SERVER, opts, nil)
210+
func (c *Criu) StartPageServer(opts *rpc.CriuOpts) error {
211+
return c.doSwrk(rpc.CriuReqType_PAGE_SERVER, opts, nil)
212212
}
213213

214214
// StartPageServerChld starts the page server and returns PID and port
215-
func (c *Criu) StartPageServerChld(opts *images.CriuOpts) (int, int, error) {
216-
resp, err := c.doSwrkWithResp(images.CriuReqType_PAGE_SERVER_CHLD, opts, nil, nil)
215+
func (c *Criu) StartPageServerChld(opts *rpc.CriuOpts) (int, int, error) {
216+
resp, err := c.doSwrkWithResp(rpc.CriuReqType_PAGE_SERVER_CHLD, opts, nil, nil)
217217
if err != nil {
218218
return 0, 0, err
219219
}
@@ -224,12 +224,12 @@ func (c *Criu) StartPageServerChld(opts *images.CriuOpts) (int, int, error) {
224224
// GetCriuVersion executes the VERSION RPC call and returns the version
225225
// as an integer. Major * 10000 + Minor * 100 + SubLevel
226226
func (c *Criu) GetCriuVersion() (int, error) {
227-
resp, err := c.doSwrkWithResp(images.CriuReqType_VERSION, nil, nil, nil)
227+
resp, err := c.doSwrkWithResp(rpc.CriuReqType_VERSION, nil, nil, nil)
228228
if err != nil {
229229
return 0, err
230230
}
231231

232-
if resp.GetType() != images.CriuReqType_VERSION {
232+
if resp.GetType() != rpc.CriuReqType_VERSION {
233233
return 0, fmt.Errorf("Unexpected CRIU RPC response")
234234
}
235235

phaul/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/checkpoint-restore/go-criu/v6"
88
"github.com/checkpoint-restore/go-criu/v6/crit"
99
"github.com/checkpoint-restore/go-criu/v6/crit/images"
10+
"github.com/checkpoint-restore/go-criu/v6/rpc"
1011
"google.golang.org/protobuf/proto"
1112
)
1213

@@ -57,10 +58,10 @@ func isLastIter(iter int, stats *images.DumpStatsEntry, prevStats *images.DumpSt
5758
// Migrate function
5859
func (pc *Client) Migrate() error {
5960
criu := criu.MakeCriu()
60-
psi := images.CriuPageServerInfo{
61+
psi := rpc.CriuPageServerInfo{
6162
Fd: proto.Int32(int32(pc.cfg.Memfd)),
6263
}
63-
opts := &images.CriuOpts{
64+
opts := &rpc.CriuOpts{
6465
Pid: proto.Int32(int32(pc.cfg.Pid)),
6566
LogLevel: proto.Int32(4),
6667
LogFile: proto.String("pre-dump.log"),

phaul/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"path/filepath"
88

99
"github.com/checkpoint-restore/go-criu/v6"
10-
"github.com/checkpoint-restore/go-criu/v6/crit/images"
10+
"github.com/checkpoint-restore/go-criu/v6/rpc"
1111
"golang.org/x/sys/unix"
1212
"google.golang.org/protobuf/proto"
1313
)
@@ -37,10 +37,10 @@ func MakePhaulServer(c Config) (*Server, error) {
3737
// StartIter phaul.Remote methods
3838
func (s *Server) StartIter() error {
3939
fmt.Printf("S: start iter\n")
40-
psi := images.CriuPageServerInfo{
40+
psi := rpc.CriuPageServerInfo{
4141
Fd: proto.Int32(int32(s.cfg.Memfd)),
4242
}
43-
opts := &images.CriuOpts{
43+
opts := &rpc.CriuOpts{
4444
LogLevel: proto.Int32(4),
4545
LogFile: proto.String("ps.log"),
4646
Ps: &psi,

0 commit comments

Comments
 (0)